public override void Build(UIComponent parent, U.UBuilder builder) { // Capacity 4 will fit color tags and modifier string and localised text var text = new StringBuilder(capacity: 4); var modifierStrings = new List <string>(capacity: 3); text.Append(UConst.GetKeyboardShortcutColorTagOpener()); if (this.shift_) { modifierStrings.Add(Translation.Options.Get("Shortcut.Modifier:Shift")); } if (this.ctrl_) { modifierStrings.Add(Translation.Options.Get("Shortcut.Modifier:Ctrl")); } if (this.alt_) { modifierStrings.Add(Translation.Options.Get("Shortcut.Modifier:Alt")); } text.Append(string.Join("+", modifierStrings.ToArray())); text.Append(UConst.KEYBOARD_SHORTCUT_CLOSING_TAG + " "); text.Append(this.localizedText_); builder.Label_( parent, t: text.ToString(), stack: UStackMode.NewRowBelow, processMarkup: true); }
public override void Build(UIComponent parent, U.UBuilder builder) { StringBuilder text = new StringBuilder(); List <string> keybindStrings = this.keybindSetting_.ToLocalizedStringList(); bool firstShortcut = true; // tracking | separators between multiple keybinds foreach (string keybindStr in keybindStrings) { if (!firstShortcut) { text.Append("| "); } else { firstShortcut = false; } text.Append(UConst.GetKeyboardShortcutColorTagOpener()); text.Append(keybindStr); text.Append(UConst.KEYBOARD_SHORTCUT_CLOSING_TAG); } text.Append(" "); text.Append(this.localizedText_); builder.Label <U.ULabel>( parent, t: text.ToString(), stack: UStackMode.NewRowBelow, processMarkup: true); }
public void Should_DynamicallyReplaceAndColorize_SingleValue_Having_OneReplacement() { string testString = "[[Page Down]] To switch underground view"; string[] replacements = new[] { "Key_X" }; string expected = $"{UConst.GetKeyboardShortcutColorTagOpener()}Key_X{UConst.KEYBOARD_SHORTCUT_CLOSING_TAG} To switch underground view"; string result = UIUtil.ColorizeDynamicKeybinds(testString, replacements); Assert.AreEqual(expected, result); }
public override void Build(UIComponent parent, U.UBuilder builder) { // Capacity 9 will fit all modifiers and separators and the text StringBuilder text = new StringBuilder(capacity: 9); text.Append(UConst.GetKeyboardShortcutColorTagOpener()); if (this.shift_) { text.Append(Translation.Options.Get("Shortcut.Modifier:Shift")); text.Append("+"); } if (this.ctrl_) { text.Append(Translation.Options.Get("Shortcut.Modifier:Ctrl")); text.Append("+"); } if (this.alt_) { text.Append(Translation.Options.Get("Shortcut.Modifier:Alt")); text.Append("+"); } text.Append(TranslationForMouseButton(this.button_)); text.Append(UConst.KEYBOARD_SHORTCUT_CLOSING_TAG + " "); text.Append(this.localizedText_); builder.Label <U.ULabel>( parent, t: text.ToString(), stack: UStackMode.NewRowBelow, processMarkup: true); }