Exemple #1
0
 private static void UnbindKey(KeyBindString keyBind)
 {
     unboundKeys.Add(new KeyBind(keyBind));          //keep track of what has been unbound
     if (keyBind.keyBind2.primary != KeyCode.Escape) //do not unbind Esc key so player can still exit on fatal error
     {
         keyBind.keyBind2.primary = KeyCode.None;    //unbind key
     }
     if (keyBind.keyBind2.secondary != KeyCode.Escape)
     {
         keyBind.keyBind2.secondary = KeyCode.None; //unbind key
     }
 }
Exemple #2
0
        public void Start()
        {
            buttonGray    = (Texture)GameDatabase.Instance.GetTexture("001ControlLock/ToolbarButton", false);
            buttonRed     = (Texture)GameDatabase.Instance.GetTexture("001ControlLock/ToolbarButtonRed", false);
            buttonYellow  = (Texture)GameDatabase.Instance.GetTexture("001ControlLock/ToolbarButtonYellow", false);
            buttonCreated = false;
            lockedMods    = new List <string>();
            unboundKeys   = new List <KeyBind>();
            allKeys       = new List <KeyBindString>();
            allKeys       = GetKeyList();
            Debug.Log("ControlLock V1.5 Started");
            DoNotDestroy.DontDestroyOnLoad(this); //never unload this class so we persist across scenes.
            ConfigNode controlLockNode = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/001ControlLock/LockedKeys.cfg");

            if (controlLockNode.nodes.Count > 0)
            {
                for (int i = 1; i <= controlLockNode.nodes.Count; i++)     //under normal contions, this should find no nodes, but if we crashed rebind our keys
                {
                    ConfigNode    key      = controlLockNode.nodes[i - 1]; //nodes is a 0 index list, so first node is zero position
                    string        kbStr    = key.GetValue("KeyBind");
                    KeyBindString kbMaster = allKeys.Find(kb3 => kb3.keyBindString == kbStr);
                    kbMaster.keyBind2.primary   = (KeyCode)Enum.Parse(typeof(KeyCode), key.GetValue("Key1"));
                    kbMaster.keyBind2.secondary = (KeyCode)Enum.Parse(typeof(KeyCode), key.GetValue("Key2"));
                }
                GameSettings.SaveSettings(); //this will only be hit if there are nodes in the file, means we crashed so need to save our settings back
            }
            GameEvents.onGameSceneLoadRequested.Add(SceneSwitch);
            if (ToolbarManager.ToolbarAvailable) //check if toolbar available, load if it is
            {
                //Debug.Log("Make button3");
                CLBtn             = ToolbarManager.Instance.add("CtrlLock", "CLButton");
                CLBtn.TexturePath = "001ControlLock/ToolbarButton";
                CLBtn.ToolTip     = "Control Lock";
                CLBtn.OnClick    += (e) =>
                {
                    if (e.MouseButton == 0)
                    {
                        ToolbarClick();
                    }
                    if (e.MouseButton == 1)
                    {
                        showKeysWindow = !showKeysWindow;
                    }
                };
            }
            else
            {
                StartCoroutine(AddButtons());//GameEvents.onGUIApplicationLauncherReady.Add(AddButtons);
                //GameEvents.onGUIApplicationLauncherUnreadifying.Add(RemoveButtons);
            }
            settings = LoadSettings();
        }
Exemple #3
0
 public KeyBind(KeyBindString kb)
 {
     keyBind    = kb.keyBindString;
     mainBind   = kb.keyBind2.primary;
     secondBind = kb.keyBind2.secondary;
 }