コード例 #1
0
        /// <summary>
        /// Add a second key under the first key, using same row background as the
        /// previous key editor.
        /// </summary>
        /// <param name="keybind"></param>
        /// <param name="editable1">Whether main key binding is editable or readonly</param>
        /// <param name="editable2">Whether alt key binding is editable or readonly</param>
        protected void AddAlternateKeybindUI(string title, KeybindSetting keybind,
                                             bool editable1, bool editable2)
        {
            var settingsRow = keybindUi_.CreateRowPanel();

            if (uiRowCount_ % 2 == 1)
            {
                // color the panel but do not increment uiRowCount
                settingsRow.backgroundSprite = null;
            }

            keybindUi_.CreateLabel(settingsRow, title, 0.45f);
            if (editable1)
            {
                keybindUi_.CreateKeybindButton(settingsRow, keybind, keybind.Key, 0.2f);
            }
            else
            {
                keybindUi_.CreateKeybindText(settingsRow, keybind.Key, 0.25f);
            }

            if (editable2)
            {
                keybindUi_.CreateKeybindButton(settingsRow, keybind, keybind.AlternateKey, 0.2f);
            }
            else
            {
                keybindUi_.CreateKeybindText(settingsRow, keybind.AlternateKey, 0.25f);
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a row in the current panel with the label and the button
        /// which will prompt user to press a new key.
        /// </summary>
        /// <param name="label">Localized label</param>
        /// <param name="keybind">The setting to edit</param>
        protected void AddKeybindRowUI(string label, KeybindSetting keybind)
        {
            var settingsRow = keybindUi_.CreateRowPanel();

            if (uiRowCount_++ % 2 == 1)
            {
                settingsRow.backgroundSprite = null;
            }

            keybindUi_.CreateLabel(settingsRow, label, 0.6f);
            keybindUi_.CreateKeybindButton(settingsRow, keybind, keybind.Key, 0.3f);
        }
コード例 #3
0
ファイル: KeybindUI.cs プロジェクト: me22/TMPE
        /// <summary>
        /// Add X button to the right of another button
        /// </summary>
        /// <param name="parent">The panel to host the new button.</param>
        /// <param name="editKey">The key to be cleared on click.</param>
        /// <param name="alignTo">Align X button to the right of this.</param>
        /// <param name="setting">KeybindSetting to notify that key was cleared.</param>
        private static void AddXButton(UIPanel parent,
                                       SavedInputKey editKey,
                                       UIButton alignTo,
                                       KeybindSetting setting)
        {
            UIButton btnX = parent.AddUIComponent <UIButton>();

            btnX.autoSize        = false;
            btnX.size            = new Vector2(ROW_HEIGHT, ROW_HEIGHT);
            btnX.normalBgSprite  = "buttonclose";
            btnX.hoveredBgSprite = "buttonclosehover";
            btnX.pressedBgSprite = "buttonclosepressed";
            btnX.eventClicked   += (component, eventParam) => {
                editKey.value = SavedInputKey.Empty;
                alignTo.text  = Keybind.ToLocalizedString(editKey);
                setting.NotifyKeyChanged();
            };
        }
コード例 #4
0
ファイル: KeybindUI.cs プロジェクト: me22/TMPE
        public void CreateKeybindButton(UIPanel parent, KeybindSetting setting, SavedInputKey editKey,
                                        float widthFraction)
        {
            var btn = parent.AddUIComponent <UIButton>();

            btn.size             = new Vector2(ROW_WIDTH * widthFraction, ROW_HEIGHT);
            btn.text             = Keybind.ToLocalizedString(editKey);
            btn.hoveredTextColor = new Color32(128, 128, 255, 255); // darker blue
            btn.pressedTextColor = new Color32(192, 192, 255, 255); // lighter blue
            btn.normalBgSprite   = "ButtonMenu";

            btn.eventKeyDown   += OnBindingKeyDown;
            btn.eventMouseDown += OnBindingMouseDown;
            btn.objectUserData
                = new KeybindSetting.Editable {
                Target = setting, TargetKey = editKey
                };

            AddXButton(parent, editKey, btn, setting);
        }