示例#1
0
        /// <summary>
        /// Constructs and returns a text phrase by taking the base content (determined by the lineKey) and inserting colored elements of text.
        /// </summary>
        /// <param name="contentID">The line key.</param>
        /// <param name="content">The colored text elements.</param>
        /// <returns></returns>
        private string ConstructTextPhrase(LabelContentID contentID, IColoredTextList content) {
            string phraseFormat;
            if (_phraseFormatLookup.TryGetValue(contentID, out phraseFormat)) {
                var textElements = content.TextElements;
                D.Log("PhraseFormat = {0}, TextElements = {1}.", phraseFormat, textElements.Concatenate());
                string textPhrase = phraseFormat.Inject(textElements);
                return textPhrase;
            }

            string warn = "No format found for {0}.".Inject(contentID.GetValueName());
            D.Warn(warn);
            return warn;
        }
示例#2
0
 private bool IsEqual(IColoredTextList contentA, IColoredTextList contentB) {
     return contentA.List.OrderBy(c => c.Text).SequenceEqual(contentB.List.OrderBy(c => c.Text));
 }
示例#3
0
        /// <summary>
        /// Only used to populate the initial LabelText, this method adds the content and format.
        /// </summary>
        /// <param name="contentID">The content identifier.</param>
        /// <param name="content">The content.</param>
        /// <param name="phraseFormat">The phrase as a string.Format for insertion of content.</param>
        public void Add(LabelContentID contentID, IColoredTextList content, string phraseFormat) {
            D.Assert(!_contentLookup.ContainsKey(contentID), "ContentID {0} already present.".Inject(contentID.GetValueName()));
            D.Assert(!_phraseFormatLookup.ContainsKey(contentID), "ContentID {0} already present.".Inject(contentID.GetValueName()));

            _contentLookup.Add(contentID, content);
            _phraseFormatLookup.Add(contentID, phraseFormat);
            IsChanged = true;
        }
示例#4
0
        /// <summary>
        /// Only used to update existing content, this method changes the content 
        /// and returns true if it is different from what already exists.
        /// </summary>
        /// <param name="contentID">The content identifier.</param>
        /// <param name="content">The content.</param>
        /// <returns></returns>
        public bool TryUpdate(LabelContentID contentID, IColoredTextList content) {
            D.Assert(_contentLookup.ContainsKey(contentID), "Missing ContentID: {0}.".Inject(contentID.GetValueName()));
            D.Assert(_phraseFormatLookup.ContainsKey(contentID), "Missing ContentID: {0}.".Inject(contentID.GetValueName()));

            IColoredTextList existingContent = _contentLookup[contentID];
            if (IsEqual(existingContent, content)) {
                //D.Log("{0} content update not needed. ContentID: {1}, Content: [{2}].", GetType().Name, contentID.GetName(), content);
                return false;
            }
            //D.Log("{0} content being updated. ContentID: {1}, Content: [{2}].", GetType().Name, contentID.GetName(), content);
            _contentLookup.Remove(contentID);
            _contentLookup.Add(contentID, content);
            IsChanged = true;
            return true;
        }
示例#5
0
 /// <summary>
 /// Adds the specified key and text list to this DebugHudText.
 /// </summary>
 /// <param name="lineKey">The line key.</param>
 /// <param name="textList">The text list.</param>
 /// <exception cref="ArgumentException" >Attempting to add a line key that is already present.</exception>
 public void Add(DebugHudLineKeys lineKey, IColoredTextList textList) {
     _textLine.Add(lineKey, textList);
     D.Log("DebugHudText.Add() called. Content = {0}.", textList.List[0].TextWithEmbeddedColor);
     //_data[lineKey] = textList;
     IsDirty = true;
 }
示例#6
0
 /// <summary>
 /// Replaces any existing list of text elements for this lineKey with the provided list. If no such list already
 /// exists, the new textElements list is simply added.
 /// </summary>
 /// <param name="lineKey">The line key.</param>
 /// <param name="textList">The text elements.</param>
 public void Replace(DebugHudLineKeys lineKey, IColoredTextList textList) {
     if (_textLine.ContainsKey(lineKey)) {
         _textLine.Remove(lineKey);
     }
     Add(lineKey, textList);
 }
示例#7
0
 /// <summary>
 /// Tries to update the content identified by <c>contentID</c>. Returns <c>true</c> if
 /// <c>content</c> is not empty.
 /// </summary>
 /// <param name="contentID">The content identifier.</param>
 /// <param name="content">The content.</param>
 /// <returns></returns>
 protected abstract bool TryUpdateContent(LabelContentID contentID, out IColoredTextList content);
示例#8
0
        /// <summary>
        /// Constructs and returns a line of text by taking the base content (determined by the lineKey) and inserting colored elements of text.
        /// </summary>
        /// <param name="lineKey">The line key.</param>
        /// <param name="coloredTextList">The colored text elements.</param>
        /// <returns></returns>
        private string ConstructTextLine(DebugHudLineKeys lineKey, IColoredTextList coloredTextList) {
            IList<string> textElements = new List<string>();
            foreach (var ct in coloredTextList.List) {
                textElements.Add(ct.TextWithEmbeddedColor);
                //D.Log("ConstructTextLine called. ColoredTextElement = {0}".Inject(ct.TextWithEmbeddedColor));
            }

            string baseText;
            if (_baseDisplayLineContent.TryGetValue(lineKey, out baseText)) {
                //D.Log("BaseText = {0}", baseText);
                //D.Log("Text Elements = {0}", textElements.Concatenate<string>(Constants.Comma));
                string colorEmbeddedLineText = baseText.Inject(textElements.ToArray<string>());
                return colorEmbeddedLineText;
            }

            string warn = "No LineKey {0} found.".Inject(lineKey.GetName());
            D.Warn(warn);
            return warn;
        }
示例#9
0
 /// <summary>
 /// Adds the specified key and text list to this GuiCursorHudText.
 /// </summary>
 /// <param name="lineKey">The line key.</param>
 /// <param name="textList">The text list.</param>
 /// <exception cref="ArgumentException" >Attempting to add a line key that is already present.</exception>
 public void Add(GuiHudLineKeys lineKey, IColoredTextList textList) {
     _textLine.Add(lineKey, textList);
     //_data[lineKey] = textList;
     IsDirty = true;
 }
示例#10
0
 protected override bool TryUpdateContent(LabelContentID contentID, out IColoredTextList content) {
     return _publisher.TryUpdateLabelTextContent(DisplayTargetID.CursorHud, contentID, out content);
 }
示例#11
0
 public abstract bool TryUpdateLabelTextContent(DisplayTargetID displayTgtID, LabelContentID contentID, AElementItemReport[] elementReports, out IColoredTextList content);
示例#12
0
 private bool IsEqual(IColoredTextList textListA, IColoredTextList textListB) {
     if (textListA.List.Except(textListB.List).Any()) {
         return false;
     }
     return true;
 }
示例#13
0
 /// <summary>
 /// Adds or replaces any existing list of text elements for this lineKey with the provided list. 
 /// If the existing list and the provided list are identical, this method does nothing.
 /// </summary>
 /// <param name="lineKey">The line key.</param>
 /// <param name="textList">The list of text elements.</param>
 public void Add(GuiHudLineKeys lineKey, IColoredTextList textList) {
     if (_textLineLookup.ContainsKey(lineKey)) {
         IColoredTextList existingList = _textLineLookup[lineKey];
         if (IsEqual(textList, existingList)) {
             //D.Warn("{0} key {1} has identical content [{2}].", GetType().Name, lineKey.GetName(), textList.List.Concatenate());
             return;
         }
         _textLineLookup.Remove(lineKey);
         D.Log("Removing {0} HUD line [{1}].", lineKey.GetValueName(), existingList.List.Concatenate());
     }
     D.Log("Adding {0} HUD line [{1}].", lineKey.GetValueName(), textList.List.Concatenate());
     _textLineLookup.Add(lineKey, textList);
     //_data[lineKey] = textList;
     IsDirty = true;
 }