Ejemplo n.º 1
0
        void BindHotkeyPref(HotkeyDefinition hd, Widget template)
        {
            var key = template.Clone() as Widget;

            key.Id        = hd.Name;
            key.IsVisible = () => true;

            key.Get <LabelWidget>("FUNCTION").GetText = () => hd.Description + ":";

            var remapButton = key.Get <ButtonWidget>("HOTKEY");

            WidgetUtils.TruncateButtonToTooltip(remapButton, modData.Hotkeys[hd.Name].GetValue().DisplayString());

            remapButton.IsHighlighted = () => selectedHotkeyDefinition == hd;

            var hotkeyValidColor   = ChromeMetrics.Get <Color>("HotkeyColor");
            var hotkeyInvalidColor = ChromeMetrics.Get <Color>("HotkeyColorInvalid");

            remapButton.GetColor = () =>
            {
                return(hd.HasDuplicates ? hotkeyInvalidColor : hotkeyValidColor);
            };

            if (selectedHotkeyDefinition == hd)
            {
                selectedHotkeyButton  = remapButton;
                hotkeyEntryWidget.Key = modData.Hotkeys[hd.Name].GetValue();
                ValidateHotkey();
            }

            remapButton.OnClick = () =>
            {
                selectedHotkeyDefinition = hd;
                selectedHotkeyButton     = remapButton;
                hotkeyEntryWidget.Key    = modData.Hotkeys[hd.Name].GetValue();
                ValidateHotkey();
                hotkeyEntryWidget.TakeKeyboardFocus();
            };

            hotkeyList.AddChild(key);
        }
Ejemplo n.º 2
0
        public HotkeyDialogLogic(Widget widget, Action onSave, HotkeyDefinition hotkeyDefinition, HotkeyManager hotkeyManager)
        {
            panel           = widget;
            this.onSave     = onSave;
            definition      = hotkeyDefinition;
            manager         = hotkeyManager;
            currentHotkey   = manager[definition.Name].GetValue();
            hotkeyEntry     = panel.Get <HotkeyEntryWidget>("HOTKEY_ENTRY");
            resetButton     = panel.Get <ButtonWidget>("RESET_BUTTON");
            clearButton     = panel.Get <ButtonWidget>("CLEAR_BUTTON");
            cancelButton    = panel.Get <ButtonWidget>("CANCEL_BUTTON");
            duplicateNotice = panel.Get <LabelWidget>("DUPLICATE_NOTICE");
            defaultNotice   = panel.Get <LabelWidget>("DEFAULT_NOTICE");
            originalNotice  = panel.Get <LabelWidget>("ORIGINAL_NOTICE");

            panel.Get <LabelWidget>("HOTKEY_LABEL").GetText = () => hotkeyDefinition.Description + ":";

            duplicateNotice.TextColor = ChromeMetrics.Get <Color>("NoticeErrorColor");
            duplicateNotice.GetText   = () =>
            {
                return((duplicateHotkey != null) ? duplicateNotice.Text.F(duplicateHotkey.Description) : duplicateNotice.Text);
            };
            defaultNotice.TextColor  = ChromeMetrics.Get <Color>("NoticeInfoColor");
            originalNotice.TextColor = ChromeMetrics.Get <Color>("NoticeInfoColor");
            originalNotice.Text      = originalNotice.Text.F(hotkeyDefinition.Default.DisplayString());

            resetButton.OnClick  = Reset;
            clearButton.OnClick  = Clear;
            cancelButton.OnClick = Cancel;

            hotkeyEntry.Key         = currentHotkey;
            hotkeyEntry.IsValid     = () => isValid;
            hotkeyEntry.OnTakeFocus = OnHotkeyEntryTakeFocus;
            hotkeyEntry.OnLoseFocus = OnHotkeyEntryLoseFocus;
            hotkeyEntry.OnEscape    = Cancel;
            hotkeyEntry.OnReturn    = Cancel;
            hotkeyEntry.TakeKeyboardFocus();

            Validate();
            isFirstValidation = false;
        }
Ejemplo n.º 3
0
        void Validate()
        {
            isValidating = true;

            duplicateHotkey = manager.GetFirstDuplicate(definition.Name, hotkeyEntry.Key, definition);
            isValid         = duplicateHotkey == null;

            duplicateNotice.Visible = !isValid;
            clearButton.Disabled    = !hotkeyEntry.Key.IsValid();

            if (hotkeyEntry.Key == definition.Default || (!hotkeyEntry.Key.IsValid() && !definition.Default.IsValid()))
            {
                defaultNotice.Visible  = !duplicateNotice.Visible;
                originalNotice.Visible = false;
                resetButton.Disabled   = true;
            }
            else
            {
                defaultNotice.Visible  = false;
                originalNotice.Visible = !duplicateNotice.Visible;
                resetButton.Disabled   = false;
            }

            if (isValid && !isFirstValidation)
            {
                currentHotkey = hotkeyEntry.Key;
                hotkeyEntry.YieldKeyboardFocus();
                Save();
            }
            else
            {
                hotkeyEntry.TakeKeyboardFocus();
            }

            isValidating = false;
        }