private static bool IsAlreadyBound(Shortcut target, InputKey inputKey, out List <Shortcut> currentAssigned)
        {
            currentAssigned = new List <Shortcut>();
            if (inputKey == 0)
            {
                return(false);
            }

            foreach (Shortcut shortcut in Shortcut.shortcuts)
            {
                if (shortcut.name != target.name && shortcut.inputKey == inputKey)
                {
                    currentAssigned.Add(shortcut);
                }
            }
            return(currentAssigned.Count > 0);
        }
 private void RefreshBindableInputs()
 {
     foreach (UIComponent current in component.GetComponentsInChildren <UIComponent>())
     {
         UITextComponent uITextComponent = current.Find <UITextComponent>("Binding");
         if (uITextComponent != null)
         {
             Shortcut shortcut = uITextComponent.objectUserData as Shortcut;
             if (shortcut != null)
             {
                 uITextComponent.text = SavedInputKey.ToLocalizedString("KEYNAME", shortcut.inputKey);
             }
         }
         UILabel uILabel = current.Find <UILabel>("Name");
         if (uILabel != null)
         {
             uILabel.text = Locale.Get("KEYMAPPING", uILabel.stringUserData);
         }
     }
 }
Beispiel #3
0
        public static void ParseEvent(Event e)
        {
            List <Shortcut> toTrigger = new List <Shortcut>();

            foreach (Shortcut shortcut in shortcuts)
            {
                if (Shortcut.IsPressed(shortcut.inputKey, e))
                {
                    toTrigger.Add(shortcut);
                }
            }

            if (toTrigger.Count == 0)
            {
                return;
            }

            UIComponent[] components = GameObject.FindObjectsOfType <UIComponent>();

            for (int i = 0; i < components.Length; i++)
            {
                foreach (Shortcut shortcut in toTrigger)
                {
                    bool isButton = components[i] is UIButton || components[i] is UIMultiStateButton || components[i] is UICheckBox;
                    if (components[i].name != shortcut.component || !isButton || (shortcut.onlyVisible && !components[i].isVisible))
                    {
                        continue;
                    }

                    if (shortcut.usePath && (string.Join(">", GetUIComponentPath(components[i])) != string.Join(">", shortcut.path)))
                    {
                        continue;
                    }

                    SimulateClick(components[i]);
                    e.Use();
                }
            }
        }
Beispiel #4
0
        public static void LoadShorcuts()
        {
            DebugUtils.Log("LoadShorcuts");
            Shortcut[] shortcuts = new Shortcut[0];
            try
            {
                // Creating setting file
                if (!((Dictionary <string, SettingsFile>) typeof(GameSettings).GetField("m_SettingsFiles", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(GameSettings.instance)).ContainsKey(MoreShortcuts.settingsFileName))
                {
                    GameSettings.AddSettingsFile(new SettingsFile[] { new SettingsFile()
                                                                      {
                                                                          fileName = MoreShortcuts.settingsFileName
                                                                      } });
                }

                if (!m_savedShortcuts.value.IsNullOrWhiteSpace())
                {
                    shortcuts = m_xmlSerializer.Deserialize(new StringReader(m_savedShortcuts.value)) as Shortcut[];
                    if (shortcuts != null)
                    {
                        DebugUtils.Log("Loaded " + shortcuts.Length + " shortcuts");
                    }
                    else
                    {
                        shortcuts = new Shortcut[0];
                    }
                }
            }
            catch (Exception e)
            {
                DebugUtils.Log("Could load/create the setting file.");
                DebugUtils.LogException(e);
            }

            Shortcut.shortcuts = new List <Shortcut>(shortcuts);
        }
 private void OnDestroy()
 {
     instance         = null;
     m_EditingBinding = null;
     m_components.Clear();
 }
Beispiel #6
0
        public void OnGUI()
        {
            try
            {
                if (m_panel == null)
                {
                    Init();
                    if (m_panel == null)
                    {
                        return;
                    }
                }

                Event e = Event.current;

                if (!GUI.UIShortcutModal.instance.isVisible &&
                    !(UIView.activeComponent is UITextField && UIView.activeComponent.isEnabled) &&
                    (UIView.activeComponent == null || UIView.activeComponent.name != "Binding"))
                {
                    Shortcut.ParseEvent(e);
                }

                UIComponent hovered = UIInput.hoveredComponent;

                if (disableCapture ||
                    GUI.UIShortcutModal.instance.isVisible ||
                    !IsCaptureKeyDown(e) ||
                    hovered == null)
                {
                    HidePanel();
                    return;
                }

                if (m_panel.isVisible && !m_panelIsModal && UIView.ModalInputCount() != 0)
                {
                    UIView.PushModal(m_panel);
                    m_panelIsModal = true;
                }

                if (hovered == m_panel)
                {
                    return;
                }

                UIComponent component = hovered;

                while (component != null)
                {
                    if (component is UIButton || component is UIMultiStateButton || component is UICheckBox)
                    {
                        m_panel.absolutePosition = component.absolutePosition;
                        m_panel.size             = component.size;
                        ShowPanel();

                        m_panel.tooltip = "Click to add a shortcut to\n" + component.name;

                        m_component = component;
                        return;
                    }
                    component = component.parent;
                }

                HidePanel();
            }
            catch (Exception e)
            {
                DebugUtils.Log("OnGUI failed");
                DebugUtils.LogException(e);
            }
        }