Пример #1
0
 private bool TryGetTextPhrase(LabelContentID contentID, out string textPhrase) {
     IColoredTextList content;
     if (_contentLookup.TryGetValue(contentID, out content)) {
         if (content.List.Count == Constants.Zero) {
             D.Warn("{0} content for ID {1} is empty.", GetType().Name, contentID.GetValueName());
         }
         textPhrase = ConstructTextPhrase(contentID, content);
         return true;
     }
     textPhrase = string.Empty;
     return false;
 }
Пример #2
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;
        }
Пример #3
0
 /// <summary>
 /// Gets the text for this specific <c>LabelContentID</c>.
 /// </summary>
 /// <param name="contentID">The content identifier.</param>
 /// <returns></returns>
 public string GetText(LabelContentID contentID) {
     string textPhrase = string.Empty;
     if (!TryGetTextPhrase(contentID, out textPhrase)) {
         D.Warn("{0} found no content for ID {1}.", GetType().Name, contentID.GetValueName());
     }
     return textPhrase;
 }
Пример #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>
        /// 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;
        }
Пример #6
0
 protected string GetDefaultPhrase(LabelContentID contentID) {
     string defaultPhrase;
     if (!_defaultPhraseLookup.TryGetValue(contentID, out defaultPhrase)) {
         D.Warn("{0} reports no defaultPhrase for {1} found.", GetType().Name, contentID.GetValueName());
         defaultPhrase = "DefaultPhrase {0}";
     }
     return defaultPhrase;
 }
Пример #7
0
 /// <summary>
 /// Gets the numerical format for this contentID.
 /// </summary>
 /// <param name="contentID">The content identifier.</param>
 /// <returns></returns>
 protected string GetFormat(LabelContentID contentID) {
     string valueFormat;
     if (!_defaultNumberFormatLookup.TryGetValue(contentID, out valueFormat)) {
         D.Warn("{0} reports no default numerical format for {1} found.", GetType().Name, contentID.GetValueName());
         valueFormat = "{0}";
     }
     return valueFormat;
 }