public static bool IsKeyUp(SavedInputKey @this)
 {
     int num = @this.value;
     var keyCode = (KeyCode) (num & MASK_KEY);
     return keyCode != KeyCode.None && Input.GetKeyUp(keyCode) &&
            (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) ==
            ((num & MASK_CONTROL) != 0) &&
            (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) == ((num & MASK_SHIFT) != 0) &&
            (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) == ((num & MASK_ALT) != 0);
 }
Example #2
0
        private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter evParam)
        {
            try {
                // This will only work if the user clicked the modify button
                // otherwise no effect
                if (!currentlyEditedBinding_.HasValue || Keybind.IsModifierKey(evParam.keycode))
                {
                    return;
                }

                evParam.Use();                               // Consume the event
                var editedBinding = currentlyEditedBinding_; // will be nulled by closing modal
                UIView.PopModal();

                var keybindButton = evParam.source as UIButton;
                var inputKey      = SavedInputKey.Encode(evParam.keycode, evParam.control, evParam.shift, evParam.alt);
                var editable      = (KeybindSetting.Editable)evParam.source.objectUserData;
                var category      = editable.Target.Category;

                if (evParam.keycode != KeyCode.Escape)
                {
                    // Check the key conflict
                    var maybeConflict = FindConflict(editedBinding.Value, inputKey, category);
                    if (maybeConflict != string.Empty)
                    {
                        var message = Translation.Options.Get("Keybinds.Dialog.Text:Keybind conflict")
                                      + "\n\n" + maybeConflict;
                        Log.Info($"Keybind conflict: {message}");
                        Prompt.Warning("Key Conflict", message);
                    }
                    else
                    {
                        editedBinding.Value.TargetKey.value = inputKey;
                        editedBinding.Value.Target.NotifyKeyChanged();
                    }
                }

                keybindButton.text      = Keybind.ToLocalizedString(editedBinding.Value.TargetKey);
                currentlyEditedBinding_ = null;
            } catch (Exception e) { Log.Error($"{e}"); }
        }
Example #3
0
        public Settings(
            float panelPosX,
            float panelPosY,
            bool brushShapesOpen,
            bool brushEditOpen,
            bool brushOptionsOpen,
            bool showTreeMeshData,
            TreeSorting sorting,
            SortingOrder sortingOrder,
            FilterStyle filterStyle,
            IEnumerable <Brush> forestBrushes,
            string selectedBrush,
            SavedInputKey toggleTool,
            bool keepTreesInNewBrush,
            bool ignoreVanillaTrees,
            bool showInfoTooltip
            )
        {
            this.PanelPosX           = panelPosX;
            this.PanelPosY           = panelPosY;
            this.BrushShapesOpen     = brushShapesOpen;
            this.BrushEditOpen       = brushEditOpen;
            this.BrushOptionsOpen    = brushOptionsOpen;
            this.ShowTreeMeshData    = showTreeMeshData;
            this.Sorting             = sorting;
            this.SortingOrder        = sortingOrder;
            this.FilterStyle         = filterStyle;
            this.ToggleTool          = toggleTool;
            this.KeepTreesInNewBrush = keepTreesInNewBrush;
            this.IgnoreVanillaTrees  = ignoreVanillaTrees;
            this.ShowInfoTooltip     = showInfoTooltip;

            this.Brushes = forestBrushes.ToList();
            if (this.Brushes.Count == 0)
            {
                var defaultBrush = Brush.Default();
                this.Brushes.Add(defaultBrush);
            }

            this.SelectBrush(selectedBrush);
        }
Example #4
0
        /// <summary>
        /// Returns shortcut as a string in user's language. Modify for special handling.
        /// </summary>
        /// <param name="k">The key</param>
        /// <returns>The shortcut, example: "Ctrl + Alt + H"</returns>
        public static string ToLocalizedString(SavedInputKey k)
        {
            if (k.value == SavedInputKey.Empty)
            {
                return(Translation.Options.Get("Keybind:None"));
            }

            switch (k.Key)
            {
            case KeyCode.Mouse0:
                return(Translation.Options.Get("Shortcut:Click"));

            case KeyCode.Mouse1:
                return(Translation.Options.Get("Shortcut:RightClick"));

            case KeyCode.Mouse2:
                return(Translation.Options.Get("Shortcut:MiddleClick"));
            }

            return(k.ToLocalizedString("KEYNAME"));
        }
Example #5
0
 private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (m_EditingBinding != null && !IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         var keycode  = p.keycode;
         var inputKey = p.keycode == KeyCode.Escape
             ? m_EditingBinding.value
             : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             inputKey = SavedInputKey.Empty;
         }
         m_EditingBinding.value = inputKey;
         var uITextComponent = p.source as UITextComponent;
         uITextComponent.text     = m_EditingBinding.ToLocalizedString("KEYNAME");
         m_EditingBinding         = null;
         m_EditingBindingCategory = string.Empty;
     }
 }
Example #6
0
        internal UIComponent AddKeymapping(string label, SavedInputKey savedInputKey)
        {
            UIPanel uipanel = base.component.AttachUIComponent(UITemplateManager.GetAsGameObject(kKeyBindingTemplate)) as UIPanel;
            int     num     = this.count;

            this.count = num + 1;
            if (num % 2 == 1)
            {
                uipanel.backgroundSprite = null;
            }
            UILabel  uilabel  = uipanel.Find <UILabel>("Name");
            UIButton uibutton = uipanel.Find <UIButton>("Binding");

            uibutton.eventKeyDown          += this.OnBindingKeyDown;
            uibutton.eventMouseDown        += this.OnBindingMouseDown;
            uilabel.text                    = label;
            uibutton.text                   = savedInputKey.ToLocalizedString("KEYNAME");
            uibutton.objectUserData         = savedInputKey;
            uipanel.eventVisibilityChanged += (_, __) => RefreshBindableInputs();
            return(uibutton);
        }
        private void AddShortcut(int i, string name, SavedInputKey shortcut)
        {
            //Source: OptionsKeymappingPanel.CreateBindableInputs
            const string keyBindingTemplate = "KeyBindingTemplate";
            var          pnl = (UIPanel)this.AttachUIComponent(UITemplateManager.GetAsGameObject(keyBindingTemplate));

            if (i % 2 == 0)
            {
                pnl.backgroundSprite = string.Empty;
            }
            var lbl = pnl.Find <UILabel>("Name");

            lbl.text = name;

            var btn = pnl.Find <UIButton>("Binding");

            btn.objectUserData  = shortcut;
            btn.text            = shortcut.ToLocalizedString("KEYNAME");
            btn.eventKeyDown   += OnBindingKeyDown;
            btn.eventMouseDown += OnBindingMouseDown;
        }
Example #8
0
 // Token: 0x06000030 RID: 48 RVA: 0x00003A8C File Offset: 0x00001C8C
 private void RefreshBindableInputs()
 {
     foreach (UIComponent uicomponent in base.component.GetComponentsInChildren <UIComponent>())
     {
         UITextComponent uitextComponent = uicomponent.Find <UITextComponent>("Binding");
         if (uitextComponent != null)
         {
             SavedInputKey savedInputKey = uitextComponent.objectUserData as SavedInputKey;
             if (savedInputKey != null)
             {
                 uitextComponent.text = savedInputKey.ToLocalizedString("KEYNAME");
             }
         }
         UILabel uilabel = uicomponent.Find <UILabel>("Name");
         if (uilabel != null)
         {
             //uilabel.text = Locale.Get("KEYMAPPING", uilabel.stringUserData);
             uilabel.text = uilabel.stringUserData;
         }
     }
 }
        protected void AddKeymapping(string label, SavedInputKey savedInputKey, string legacySaveFileName)
        {
            savedInputKey.value = savedInputKey.value;
            UIPanel uIPanel = component.AttachUIComponent(UITemplateManager.GetAsGameObject(kKeyBindingTemplate)) as UIPanel;

            uIPanel.name = legacySaveFileName;
            if (count++ % 2 == 1)
            {
                uIPanel.backgroundSprite = null;
            }

            UILabel  uILabel  = uIPanel.Find <UILabel>("Name");
            UIButton uIButton = uIPanel.Find <UIButton>("Binding");

            uIButton.eventKeyDown   += new KeyPressHandler(this.OnBindingKeyDown);
            uIButton.eventMouseDown += new MouseEventHandler(this.OnBindingMouseDown);

            if (File.Exists(KeyBindingsManager.BindingsConfigPath))
            {
                var    lines = new List <string>(File.ReadAllLines(KeyBindingsManager.BindingsConfigPath));
                string line  = "########";
                foreach (string l in lines)
                {
                    if (l.Contains(legacySaveFileName))
                    {
                        line = l; break;
                    }
                }
                if (line != "########")
                {
                    lines.Remove(line);
                    KeyBindingsManager.RewriteCfgLines(lines);
                }
            }

            uILabel.text            = label;
            uIButton.text           = savedInputKey.ToLocalizedString("KEYNAME");
            uIButton.objectUserData = savedInputKey;
        }
Example #10
0
        /// <summary>
        /// register a custom button .
        /// </summary>
        /// <param name="name">game object name for button</param>
        /// <param name="groupName">the group under which button will be added. use null to addd to the default gorup.</param>
        /// <param name="spritefile">full path to the file that contains 4 40x40x button sprites(see example)</param>
        /// <param name="onToggle">call-back for when the button is activated/deactivated</param>
        /// <param name="onToolChanged">call-back for when any active tool changes.</param>
        /// <param name="activationKey">hot key to trigger the button</param>
        /// <param name="activeKeys">hotkey->active dictionary. turns off these hotkeys in other mods while active</param>
        /// <returns>wrapper for the button which you can use to change the its state.</returns>
        public static UUICustomButton RegisterCustomButton(
            string name, string groupName, string tooltip, string spritefile,
            Action <bool> onToggle, Action <ToolBase> onToolChanged,
            SavedInputKey activationKey, IEnumerable <SavedInputKey> activeKeys)
        {
            var activeKeys2 = new Dictionary <SavedInputKey, Func <bool> >();

            foreach (var key in activeKeys)
            {
                activeKeys2[key] = null;
            }

            return(RegisterCustomButton(
                       name: name,
                       groupName: groupName,
                       tooltip: tooltip,
                       spritefile: spritefile,
                       onToggle: onToggle,
                       onToolChanged: onToolChanged,
                       activationKey: activationKey,
                       activeKeys: activeKeys2));
        }
Example #11
0
        public static Settings Default()
        {
            var defaultBrush = Brush.Default();

            return(new Settings(
                       200f,
                       100f,
                       false,
                       false,
                       false,
                       true,
                       TreeSorting.Name,
                       SortingOrder.Ascending,
                       FilterStyle.AND,
                       Enumerable.Empty <Brush>(),
                       string.Empty,
                       new SavedInputKey("toggleTool", Constants.ModName, SavedInputKey.Encode(KeyCode.B, false, false, true), true),
                       false,
                       false,
                       true
                       ));
        }
Example #12
0
        private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
        {
            if (this.m_EditingBinding != null && !this.IsModifierKey(p.keycode))
            {
                p.Use();
                UIView.PopModal();
                KeyCode  keycode  = p.keycode;
                InputKey inputKey = (p.keycode == KeyCode.Escape) ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
                if (p.keycode == KeyCode.Backspace)
                {
                    inputKey = SavedInputKey.Empty;
                }
                this.m_EditingBinding.value = inputKey;
                UITextComponent uITextComponent = p.source as UITextComponent;
                uITextComponent.text = this.m_EditingBinding.ToLocalizedString("KEYNAME");

                UserMod.SaveSettings();

                this.m_EditingBinding         = null;
                this.m_EditingBindingCategory = string.Empty;
            }
        }
Example #13
0
 private void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter p)
 {
     if (EditBinding == null)
     {
         p.Use();
         EditBinding = (SavedInputKey)p.source.objectUserData;
         var button = p.source as UIButton;
         button.buttonsMask = UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle | UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 | UIMouseButton.Special3;
         button.text        = Locale.Get("KEYMAPPING_PRESSANYKEY");
         p.source.Focus();
         UIView.PushModal(p.source);
     }
     else if (!IsUnbindableMouseButton(p.buttons))
     {
         p.Use();
         UIView.PopModal();
         EditBinding.value = SavedInputKey.Encode(ButtonToKeycode(p.buttons), Utility.CtrlIsPressed, Utility.ShiftIsPressed, Utility.AltIsPressed);
         var button = p.source as UIButton;
         button.text        = EditBinding.ToLocalizedString("KEYNAME");
         button.buttonsMask = UIMouseButton.Left;
         EditBinding        = null;
     }
 }
        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);
        }
 protected void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (this.m_EditingBinding != null && !this.IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         KeyCode  keycode  = p.keycode;
         InputKey inputKey = (p.keycode == KeyCode.Escape) ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             KeyBindingsManager.instance.GetBindingFromName(comp.parent.name).SetEmpty();
             inputKey = SavedInputKey.Empty;
         }
         else
         {
             KeyBindingsManager.instance.GetBindingFromName(comp.parent.name).ApplySavedInput(keycode, p.control, p.shift, p.alt);
         }
         this.m_EditingBinding.value = inputKey;
         UITextComponent uITextComponent = p.source as UITextComponent;
         uITextComponent.text          = this.m_EditingBinding.ToLocalizedString("KEYNAME");
         this.m_EditingBinding         = null;
         this.m_EditingBindingCategory = string.Empty;
     }
 }
Example #16
0
        // register hotkeys
        public static void Register(
            Action onToggle,
            SavedInputKey activationKey,
            Dictionary <SavedInputKey, Func <bool> > activeKeys)
        {
            try {
                if (activationKey != null && onToggle != null)
                {
                    MainPanel.Instance.CustomHotkeys[activationKey] = onToggle;
                }

                if (activeKeys != null)
                {
                    foreach (var pair in activeKeys)
                    {
                        Assertion.AssertNotNull(pair.Key, "hotkey cannot be null in 'activeKeys'");
                        Assertion.AssertNotNull(pair.Value, "IsActive cannot be null in 'activeKeys'");
                        MainPanel.Instance.CustomActiveHotkeys[pair.Key] = pair.Value;
                    }
                }
            } catch (Exception ex) {
                Log.Exception(ex);
            }
        }
Example #17
0
 public void Awake()
 {
     this.m_buildElevationUp       = new SavedInputKey(Settings.buildElevationUp, Settings.gameSettingsFile, DefaultSettings.buildElevationUp, true);
     this.m_buildElevationDown     = new SavedInputKey(Settings.buildElevationDown, Settings.gameSettingsFile, DefaultSettings.buildElevationDown, true);
     UIInput.eventProcessKeyEvent += new UIInput.ProcessKeyEventHandler(this.ProcessKeyEvent);
 }
        protected override void OnToolGUI(UnityEngine.Event e)
        {
            if (!m_toolController.IsInsideUI && e.type == UnityEngine.EventType.MouseDown)
            {
                if (e.button == 0)
                {
                    m_mouseLeftDown = true;
                    m_endPosition = m_mousePosition;
                }
                else if (e.button == 1)
                {
                    //begin mod
                    if (m_mode == TerrainTool.Mode.Shift || m_mode == TerrainTool.Mode.Soften || isDitch)
                        //end mod
                        m_mouseRightDown = true;
                    else if (m_mode == TerrainTool.Mode.Level || m_mode == TerrainTool.Mode.Slope)
                    {
                        m_startPosition = m_mousePosition;
                    }
                }
            }
            else if (e.type == UnityEngine.EventType.MouseUp)
            {
                if (e.button == 0)
                {
                    m_mouseLeftDown = false;
                    if (!m_mouseRightDown)
                        m_strokeEnded = true;
                }
                else if (e.button == 1)
                {
                    m_mouseRightDown = false;
                    if (!m_mouseLeftDown)
                        m_strokeEnded = true;
                }
            }
            if (m_UndoKey == null)
            {
                m_UndoKey = (SavedInputKey)typeof(TerrainTool).GetField("m_UndoKey", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
            }

            if (!m_UndoKey.IsPressed(e) || m_undoRequest || (m_mouseLeftDown || m_mouseRightDown) || !IsUndoAvailable())
                return;
            Undo();
        }
Example #19
0
 public SavedInputKey(string name, string fileName, KeyCode key, bool control, bool shift, bool alt, bool autoUpdate) : base(name, fileName, autoUpdate)
 {
     this.m_Value = SavedInputKey.Encode(key, control, shift, alt);
 }
Example #20
0
 public static void Dispose()
 {
     m_UndoKey  = null;
     m_sizeMode = SizeMode.Single;
 }
 public static void Dispose()
 {
     m_UndoKey = null;
     m_sizeMode = SizeMode.Single;
 }
Example #22
0
 /// <summary>
 /// Returns shortcut as a string in user's language. Modify for special handling.
 /// </summary>
 /// <param name="k">The key</param>
 /// <returns>The shortcut, example: "Ctrl + Alt + H"</returns>
 public static string ToLocalizedString(SavedInputKey k)
 {
     return(k.ToLocalizedString("KEYNAME"));
 }
        private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter e)
        {
            var key = e.keycode;

            if (_editingBinding == null || KeyHelper.IsModifierKey(key))
            {
                return;
            }

            e.Use();
            UIView.PopModal();

            InputKey newKey;

            switch (key)
            {
            case KeyCode.Backspace:
                newKey = SavedInputKey.Empty;
                break;

            case KeyCode.Escape:
                newKey = _editingBinding.value;
                break;

            default:
                newKey = SavedInputKey.Encode(key, e.control, e.shift, e.alt);
                break;
            }

            if (IsAlreadyBound(_editingBinding, newKey, out var currentAssigned))
            {
                var text = currentAssigned.Count <= 1
          ? (
                    Locale.Exists("KEYMAPPING", currentAssigned[0].name)
              ? Locale.Get("KEYMAPPING", currentAssigned[0].name)
              : Options.GetShortcutName(currentAssigned[0].name)
                    )
          : Locale.Get("KEYMAPPING_MULTIPLE");
                var message = StringUtils.SafeFormat(Locale.Get("CONFIRM_REBINDKEY", "Message"),
                                                     SavedInputKey.ToLocalizedString("KEYNAME", newKey), text);

                ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, (c, ret) =>
                {
                    var btn = (UIButton)comp;
                    if (ret == 1)
                    {
                        _editingBinding.value = newKey;
                        foreach (var asigned in currentAssigned)
                        {
                            asigned.value = SavedInputKey.Empty;
                        }
                        UpdateKeyBinding(newKey, btn, false);
                        RefreshKeyMapping();
                    }
                    _editingBinding = null;
                    btn.text        = ((SavedInputKey)btn.objectUserData).ToLocalizedString("KEYNAME");
                });
            }
            else
            {
                UpdateKeyBinding(newKey, (UIButton)comp, false);
            }
        }
        private static void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter p)
        {
            if (m_EditingBinding == null)
            {
                p.Use();
                m_EditingBinding = (Shortcut)p.source.objectUserData;
                UIButton uIButton = p.source as UIButton;
                uIButton.buttonsMask = (UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle | UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 | UIMouseButton.Special3);
                uIButton.text        = "Press any key";
                p.source.Focus();
                UIView.PushModal(p.source);
            }
            else if (!IsUnbindableMouseButton(p.buttons))
            {
                p.Use();
                UIView.PopModal();
                InputKey        inputKey = SavedInputKey.Encode(ButtonToKeycode(p.buttons), IsControlDown(), IsShiftDown(), IsAltDown());
                List <Shortcut> currentAssigned;
                if (!IsAlreadyBound(m_EditingBinding, inputKey, out currentAssigned))
                {
                    if (m_EditingBinding.inputKey != inputKey)
                    {
                        m_EditingBinding.inputKey = inputKey;
                        Shortcut.SaveShorcuts();
                    }

                    UIButton uIButton = p.source as UIButton;
                    uIButton.text        = SavedInputKey.ToLocalizedString("KEYNAME", m_EditingBinding.inputKey);
                    uIButton.buttonsMask = UIMouseButton.Left;
                    m_EditingBinding     = null;
                }
                else
                {
                    string arg     = (currentAssigned.Count <= 1) ? Locale.Get("KEYMAPPING", currentAssigned[0].name) : Locale.Get("KEYMAPPING_MULTIPLE");
                    string message = string.Format(Locale.Get("CONFIRM_REBINDKEY", "Message"), SavedInputKey.ToLocalizedString("KEYNAME", inputKey), arg);
                    ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, delegate(UIComponent c, int ret)
                    {
                        if (ret == 1)
                        {
                            m_EditingBinding.inputKey = inputKey;

                            for (int i = 0; i < currentAssigned.Count; i++)
                            {
                                currentAssigned[i].inputKey = 0;
                            }
                            Shortcut.SaveShorcuts();
                            RefreshKeyMapping();
                        }
                        UIButton uIButton    = p.source as UIButton;
                        uIButton.text        = SavedInputKey.ToLocalizedString("KEYNAME", m_EditingBinding.inputKey);
                        uIButton.buttonsMask = UIMouseButton.Left;
                        m_EditingBinding     = null;
                    });
                }
            }
        }
Example #25
0
        /// <summary>
        /// MouseDown event handler to handle mouse clicks; primarily used to prime hotkey entry.
        /// </summary>
        /// <param name="mouseEvent">Mouse button event parameter</param>
        public void OnMouseDown(UIMouseEventParameter mouseEvent)
        {
            // Use the event.
            mouseEvent.Use();

            // Check to see if we're already primed for hotkey entry.
            if (isPrimed)
            {
                // We were already primed; is this a bindable mouse button?
                if (mouseEvent.buttons == UIMouseButton.Left || mouseEvent.buttons == UIMouseButton.Right)
                {
                    // Not a bindable mouse button - set the button text and cancel priming.
                    button.text = SavedInputKey.ToLocalizedString("KEYNAME", ModSettings.CurrentHotkey);
                    UIView.PopModal();
                    isPrimed = false;
                }
                else
                {
                    // Bindable mouse button - do keybinding as if this was a keystroke.
                    KeyCode mouseCode;

                    switch (mouseEvent.buttons)
                    {
                    // Convert buttons to keycodes (we don't bother with left and right buttons as they're non-bindable).
                    case UIMouseButton.Middle:
                        mouseCode = KeyCode.Mouse2;
                        break;

                    case UIMouseButton.Special0:
                        mouseCode = KeyCode.Mouse3;
                        break;

                    case UIMouseButton.Special1:
                        mouseCode = KeyCode.Mouse4;
                        break;

                    case UIMouseButton.Special2:
                        mouseCode = KeyCode.Mouse5;
                        break;

                    case UIMouseButton.Special3:
                        mouseCode = KeyCode.Mouse6;
                        break;

                    default:
                        // No valid button pressed: exit without doing anything.
                        return;
                    }

                    // We got a valid mouse button key - apply settings and save.
                    ApplyKey(SavedInputKey.Encode(mouseCode, IsControlDown(), IsShiftDown(), IsAltDown()));
                }
            }
            else
            {
                // We weren't already primed - set our text and focus the button.
                button.buttonsMask = (UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle | UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 | UIMouseButton.Special3);
                button.text        = Translations.Translate("KEY_PRS");
                button.Focus();

                // Prime for new keybinding entry.
                isPrimed = true;
                UIView.PushModal(button);
            }
        }
 public KeyBindingInfo(string name, SavedInputKey key)
 {
     this.m_name = name;
     ApplySavedInput(key);
 }
        private static void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
        {
            if (m_EditingBinding != null && !IsModifierKey(p.keycode))
            {
                p.Use();
                UIView.PopModal();
                KeyCode  keycode  = p.keycode;
                InputKey inputKey = (p.keycode == KeyCode.Escape) ? (InputKey)m_EditingBinding.inputKey : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
                if (p.keycode == KeyCode.Backspace)
                {
                    inputKey = 0;
                }
                List <Shortcut> currentAssigned;
                if (!IsAlreadyBound(m_EditingBinding, inputKey, out currentAssigned))
                {
                    if (m_EditingBinding.inputKey != inputKey)
                    {
                        m_EditingBinding.inputKey = inputKey;
                        Shortcut.SaveShorcuts();
                    }

                    UITextComponent uITextComponent = p.source as UITextComponent;
                    uITextComponent.text = SavedInputKey.ToLocalizedString("KEYNAME", inputKey);
                    m_EditingBinding     = null;
                }
                else
                {
                    string arg     = (currentAssigned.Count <= 1) ? currentAssigned[0].name : Locale.Get("KEYMAPPING_MULTIPLE");
                    string message = string.Format(Locale.Get("CONFIRM_REBINDKEY", "Message"), SavedInputKey.ToLocalizedString("KEYNAME", inputKey), arg);
                    ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, delegate(UIComponent c, int ret)
                    {
                        if (ret == 1)
                        {
                            for (int i = 0; i < currentAssigned.Count; i++)
                            {
                                currentAssigned[i].inputKey = 0;
                            }
                        }

                        m_EditingBinding.inputKey = inputKey;
                        Shortcut.SaveShorcuts();
                        RefreshKeyMapping();

                        UITextComponent uITextComponent = p.source as UITextComponent;
                        uITextComponent.text            = SavedInputKey.ToLocalizedString("KEYNAME", m_EditingBinding.inputKey);
                        m_EditingBinding = null;
                    });
                }
            }
        }
Example #28
0
        private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
        {
            if (!((SavedValue)this.m_EditingBinding != (SavedValue)null) || this.IsModifierKey(p.keycode))
            {
                return;
            }
            p.Use();
            UIView.PopModal();
            KeyCode  keycode  = p.keycode;
            InputKey inputKey = p.keycode == KeyCode.Escape ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);

            if (p.keycode == KeyCode.Backspace)
            {
                inputKey = SavedInputKey.Empty;
            }
            this.m_EditingBinding.value        = inputKey;
            (p.source as UITextComponent).text = this.m_EditingBinding.ToLocalizedString("KEYNAME");
            this.m_EditingBinding = (SavedInputKey)null;
        }
Example #29
0
        static bool Prefix(
            CameraController __instance,
            float multiplier,

            ref Vector3 ___m_velocity,
            ref Vector2 ___m_angleVelocity,
            ref float ___m_zoomVelocity,

            SavedInputKey ___m_cameraMoveLeft,
            SavedInputKey ___m_cameraMoveRight,
            SavedInputKey ___m_cameraMoveForward,
            SavedInputKey ___m_cameraMoveBackward,

            SavedInputKey ___m_cameraRotateLeft,
            SavedInputKey ___m_cameraRotateRight,
            SavedInputKey ___m_cameraRotateUp,
            SavedInputKey ___m_cameraRotateDown,

            SavedInputKey ___m_cameraZoomAway,
            SavedInputKey ___m_cameraZoomCloser
            )
        {
            if (App.Instance.IsDive)
            {
                return(false);
            }

            var delta        = Vector3.zero;
            var analogAction = SteamController.GetAnalogAction(SteamController.AnalogInput.CameraScroll);

            if (analogAction.sqrMagnitude > 0.0001f)
            {
                delta.x = analogAction.x;
                delta.z = analogAction.y;
                __instance.ClearTarget();
            }

            if (___m_cameraMoveLeft.IsPressed())
            {
                delta.x -= 1f;
                __instance.ClearTarget();
            }
            if (___m_cameraMoveRight.IsPressed())
            {
                delta.x += 1f;
                __instance.ClearTarget();
            }
            if (___m_cameraMoveForward.IsPressed())
            {
                delta.z += 1f;
                __instance.ClearTarget();
            }
            if (___m_cameraMoveBackward.IsPressed())
            {
                delta.z -= 1f;
                __instance.ClearTarget();
            }

            if (__instance.m_analogController)
            {
                float num  = UnityEngine.Input.GetAxis("Horizontal") * __instance.m_GamepadMotionZoomScalar.x;
                float num2 = UnityEngine.Input.GetAxis("Vertical") * __instance.m_GamepadMotionZoomScalar.z;
                if (num != 0f)
                {
                    delta.x = num;
                }
                if (num2 != 0f)
                {
                    delta.z = num2;
                }
            }
            ___m_velocity += delta * multiplier * Time.deltaTime;

            var rotDelta = Vector2.zero;

            if (!__instance.m_freeCamera)
            {
                if (___m_cameraRotateLeft.IsPressed())
                {
                    rotDelta.x += 200f;
                }
                if (___m_cameraRotateRight.IsPressed())
                {
                    rotDelta.x -= 200f;
                }
                if (___m_cameraRotateUp.IsPressed())
                {
                    rotDelta.y += 200f;
                }
                if (___m_cameraRotateDown.IsPressed())
                {
                    rotDelta.y -= 200f;
                }
            }
            ___m_angleVelocity += rotDelta * multiplier * Time.deltaTime;
            float num3 = 0f;

            if (___m_cameraZoomCloser.IsPressed() || SteamController.GetDigitalAction(SteamController.DigitalInput.ZoomIn))
            {
                num3 -= 50f;
            }
            if (___m_cameraZoomAway.IsPressed() || SteamController.GetDigitalAction(SteamController.DigitalInput.ZoomOut))
            {
                num3 += 50f;
            }
            ___m_zoomVelocity += num3 * multiplier * Time.deltaTime;
            return(false);
        }
Example #30
0
 private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (this.m_EditingBinding != null && !this.IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         KeyCode  keycode  = p.keycode;
         InputKey inputKey = (p.keycode == KeyCode.Escape) ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             inputKey = SavedInputKey.Empty;
         }
         List <SavedInputKey> currentAssigned;
         if (!this.IsAlreadyBound(this.m_EditingBinding, inputKey, this.m_EditingBindingCategory, out currentAssigned))
         {
             this.m_EditingBinding.value = inputKey;
             UITextComponent uITextComponent = p.source as UITextComponent;
             uITextComponent.text          = this.m_EditingBinding.ToLocalizedString("KEYNAME");
             this.m_EditingBinding         = null;
             this.m_EditingBindingCategory = string.Empty;
         }
         else
         {
             string arg     = (currentAssigned.Count <= 1) ? Locale.Get("KEYMAPPING", currentAssigned[0].name) : Locale.Get("KEYMAPPING_MULTIPLE");
             string message = string.Format(Locale.Get("CONFIRM_REBINDKEY", "Message"), SavedInputKey.ToLocalizedString("KEYNAME", inputKey), arg);
             ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, delegate(UIComponent c, int ret)
             {
                 if (ret == 1)
                 {
                     this.m_EditingBinding.value = inputKey;
                     for (int i = 0; i < currentAssigned.Count; i++)
                     {
                         currentAssigned[i].value = SavedInputKey.Empty;
                     }
                     this.RefreshKeyMapping();
                 }
                 UITextComponent uITextComponent2 = p.source as UITextComponent;
                 uITextComponent2.text            = this.m_EditingBinding.ToLocalizedString("KEYNAME");
                 this.m_EditingBinding            = null;
                 this.m_EditingBindingCategory    = string.Empty;
             });
         }
     }
 }
Example #31
0
        void Start()
        {
            controller = FindObjectOfType<CameraController>();
            camera = controller.GetComponent<Camera>();
            originalFieldOfView = camera.fieldOfView;

            config = Configuration.Deserialize(configPath);
            if (config == null)
            {
                config = new Configuration();
            }

            SaveConfig();

            mainCameraPosition = gameObject.transform.position;
            mainCameraOrientation = gameObject.transform.rotation;

            cameraMoveLeft = new SavedInputKey(Settings.cameraMoveLeft, Settings.gameSettingsFile, DefaultSettings.cameraMoveLeft, true);
            cameraMoveRight = new SavedInputKey(Settings.cameraMoveRight, Settings.gameSettingsFile, DefaultSettings.cameraMoveRight, true);
            cameraMoveForward = new SavedInputKey(Settings.cameraMoveForward, Settings.gameSettingsFile, DefaultSettings.cameraMoveForward, true);
            cameraMoveBackward = new SavedInputKey(Settings.cameraMoveBackward, Settings.gameSettingsFile, DefaultSettings.cameraMoveBackward, true);
            cameraZoomCloser = new SavedInputKey(Settings.cameraZoomCloser, Settings.gameSettingsFile, DefaultSettings.cameraZoomCloser, true);
            cameraZoomAway = new SavedInputKey(Settings.cameraZoomAway, Settings.gameSettingsFile, DefaultSettings.cameraZoomAway, true);

            mainCameraPosition = gameObject.transform.position;
            mainCameraOrientation = gameObject.transform.rotation;
            rotationY = -instance.transform.localEulerAngles.x;

            var gameObjects = FindObjectsOfType<GameObject>();
            foreach (var go in gameObjects)
            {
                var tmp = go.GetComponent("HideUI");
                if (tmp != null)
                {
                    hideUIComponent = tmp;
                    break;
                }
            }

            checkedForHideUI = true;

            ui = FPSCameraUI.Instance;
        }
Example #32
0
        /// <summary>
        /// KeyDown event handler to record the new hotkey.
        /// </summary>
        /// <param name="keyEvent">Keypress event parameter</param>
        public void OnKeyDown(UIKeyEventParameter keyEvent)
        {
            Logging.Message("keydown ", isPrimed.ToString());

            // Only do this if we're primed and the keypress isn't a modifier key.
            if (isPrimed && !IsModifierKey(keyEvent.keycode))
            {
                // Variables.
                InputKey inputKey;

                // Use the event.
                keyEvent.Use();

                // If escape was entered, we don't change the code.
                if (keyEvent.keycode == KeyCode.Escape)
                {
                    inputKey = ModSettings.CurrentHotkey;
                }
                else
                {
                    // If backspace was pressed, then we blank the input; otherwise, encode the keypress.
                    inputKey = (keyEvent.keycode == KeyCode.Backspace) ? SavedInputKey.Empty : SavedInputKey.Encode(keyEvent.keycode, keyEvent.control, keyEvent.shift, keyEvent.alt);
                }

                // Apply our new key.
                ApplyKey(inputKey);
            }
        }
Example #33
0
 public Shortcut(string fileName, string name, string labelKey, InputKey key, Action action = null)
 {
     LabelKey = labelKey;
     InputKey = new SavedInputKey(name, fileName, key, true);
     Action   = action;
 }
Example #34
0
        public static bool IsEmpty(InputKey sample)
        {
            var noKey = SavedInputKey.Encode(KeyCode.None, false, false, false);

            return(sample == SavedInputKey.Empty || sample == noKey);
        }