Beispiel #1
0
 /// <summary>
 /// Gets a new, updated or simply existing GuiCursorHudText instance containing 
 /// the text used by the GuiCursorHud display.
 /// </summary>
 /// <param name="intelLevel">The intel level.</param>
 /// <returns></returns>
 public GuiHudText GetHudText(IntelLevel intelLevel) {        // OPTIMIZE Detect individual data property changes and replace them individually
     if (_guiCursorHudText == null || _guiCursorHudText.IntelLevel != intelLevel || _data.IsChanged) {
         // don't have the right version of GuiCursorHudText so make one
         _guiCursorHudText = GuiHudTextFactory.MakeInstance(intelLevel, _data);
         _data.AcceptChanges();   // once we make a new one from current data, it is no longer dirty, if it ever was
     }
     else {
         // we have the right clean version so simply update the values that routinely change
         UpdateGuiCursorHudText(intelLevel, GuiHudLineKeys.Distance);
         if (intelLevel == IntelLevel.OutOfDate) {
             UpdateGuiCursorHudText(IntelLevel.OutOfDate, GuiHudLineKeys.IntelState);
         }
         if (_optionalKeys != null) {
             UpdateGuiCursorHudText(intelLevel, _optionalKeys);
         }
     }
     return _guiCursorHudText;
 }
        /// <summary>
        /// Makes or acquires an instance of GuiCursorHudText for the IntelLevel.
        /// </summary>
        /// <param name="currentSpeed">Current speed of the game object. Can be zero.</param>
        /// <returns></returns>
        public GuiHudText MakeInstance(float currentSpeed) {
            if (_guiCursorHudTextCache == null) {
                _guiCursorHudTextCache = new Dictionary<IntelLevel, GuiHudText>();
            }

            if (_data.IsDirty) {
                _guiCursorHudTextCache.Clear();
                _data.IsDirty = false;
            }

            if (_guiCursorHudTextCache.ContainsKey(IntelLevel)) {
                return _guiCursorHudTextCache[IntelLevel];
            }

            IList<GuiHudLineKeys> keys;
            if (_hudLineKeyLookup.TryGetValue(IntelLevel, out keys)) {
                GuiHudText guiCursorHudText = new GuiHudText(IntelLevel);

                IColoredTextList textList;
                foreach (GuiHudLineKeys key in keys) {
                    textList = MakeInstance(key, currentSpeed);
                    guiCursorHudText.Add(key, textList);
                }
                //_guiCursorHudTextCache[intelLevel] = guiCursorHudText;  
                _guiCursorHudTextCache.Add(IntelLevel, guiCursorHudText);   // .Add() throws exception if key already has another value
                return guiCursorHudText;
            }
            D.Error("{0} {1} Key is not present in Lookup.", typeof(IntelLevel), IntelLevel);
            return null;
        }