public bool GetActionKey(ActionKeys ak)
        {
            bool outAction = false;

            mActionKeys.TryGetValue((int)ak, out outAction);
            return(outAction);
        }
 public void SetActionKey(ActionKeys ak, bool val)
 {
     if (!mActionKeys.ContainsKey((int)ak))
     {
         mActionKeys.Add((int)ak, false);
     }
     mActionKeys[(int)ak] = val;
 }
Exemple #3
0
        static void OnUpdate(UnityModManager.ModEntry modEntry, float dt)
        {
            //
            //detect key
            if (WaitingForKey != ActionKeys.None)
            {
                foreach (KeyCode keySearch in System.Enum.GetValues(typeof(KeyCode)))
                {
                    if (Input.GetKeyDown(keySearch))
                    {
                        if (!keySearch.ToString().StartsWith("Mouse"))
                        {
                            KeyCode setKey = keySearch;
                            //clear key
                            if (setKey == KeyCode.Backspace)
                            {
                                setKey = KeyCode.None;
                            }
                            try
                            {
                                Log("Key waiting for = " + keySearch.ToString());
                                Dictionary <ActionKeys, KeyCode> keydict = Settings.actionList.Zip(Settings.keyList, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v);
                                keydict[WaitingForKey] = setKey;
                                Settings.actionList.Clear();
                                Settings.keyList.Clear();
                                Settings.actionList = keydict.Keys.ToList <ActionKeys>();
                                Settings.keyList    = keydict.Values.ToList <KeyCode>();
                                keydict.Clear();
                            }
                            catch (System.Exception e)
                            {
                                Error(e.ToString());
                            }
                            WaitingForKey = ActionKeys.None;
                        }
                    }
                }
            }
            else
            //keyReaction
            {
                if (!IsVisibleUI)
                {
                    Dictionary <ActionKeys, KeyCode> keydict = Settings.actionList.Zip(Settings.keyList, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v);

                    foreach (KeyValuePair <ActionKeys, KeyCode> entry in keydict)
                    {
                        if (Input.GetKeyDown(entry.Value))
                        {
                            funcDict[entry.Key]();
                        }
                    }

                    keydict.Clear();
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// 检查是否包含给定的操作(复数)
        /// </summary>
        public virtual IList <bool> CheckAction(IList <string> actionkeys)
        {
            if (this.ActionKeys.Count == 0 && this.ActionKey != null)
            {
                DeserialRolePurview();
            }

            return(ActionKeys.Select(o => ActionKeys.Contains(o)).ToList());
        }
Exemple #5
0
        /// <summary>
        /// 检查是否包含给定的操作
        /// </summary>
        public virtual bool CheckAction(string actionKey)
        {
            if (this.ActionKeys.Count == 0 && this.ActionKey != null)
            {
                DeserialRolePurview();
            }

            return(ActionKeys.Contains(actionKey));
        }
Exemple #6
0
        private void DisplayUnits()
        {
            var selected = Unit.GetAllSelected();

            units.Clear();
            units.AddRange(selected);

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

            UI.Label($"Selected: {(units.Count == 1 ? units[0].Name : (units.Count + " units"))}.");
            UI.Label("Available actions:");

            scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.ExpandHeight(false));

            int index = 0;

            foreach (var action in units.Count != 1 ? UnitAction.MergeActions(units) : units[0].GetAllActions())
            {
                if (UI.Button($"{action.Name} [{ActionKeys.Get(index)}]") || Input.GetKeyDown(ActionKeys.Get(index)))
                {
                    if (units.Count == 1)
                    {
                        string error = action.Run(units[0], null);
                        if (error != null)
                        {
                            Debug.LogWarning($"Action error: {error}");
                        }
                    }
                    else
                    {
                        foreach (var unit in units)
                        {
                            string error = action.Run(unit, null);
                            if (error != null)
                            {
                                Debug.LogWarning($"Action error: {error}");
                            }
                        }
                    }
                }
                index++;
            }

            GUILayout.EndScrollView();

            if (units.Count == 1)
            {
                DisplaySingleUnit(units[0]);
            }
        }
Exemple #7
0
            internal bool CheckPressed(ActionKeys key)
            {

                if (GamePadMappings.Any(x => x.Key == key))
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (gamepadState[i].IsConnected)
                        {
                            KeyValuePair<ActionKeys, Buttons> found = GamePadMappings.FirstOrDefault(x => x.Key == key);

                            Buttons mapping = found.Value;
                            if (gamepadState[i].IsButtonDown(mapping))
                            {
                                return true;
                            }
                        }
                    }
                }

                if (KeyboardMappings.ContainsKey(key))
                {
                    var keyToCheck = KeyboardMappings[key];
                    if (keyboardState.IsKeyDown(keyToCheck))
                    {
                        return true;
                    }
                }

                if (MouseButtonsMappings.ContainsKey(key))
                {
                    MouseButtons mouseButtonToCheck = MouseButtonsMappings[key];

                    if (mouseButtonToCheck == MouseButtons.LeftClick &&
                        mouseState.LeftButton == ButtonState.Pressed) return true;


                    if (mouseButtonToCheck == MouseButtons.MiddleClick &&
                        mouseState.MiddleButton == ButtonState.Pressed) return true;


                    if (mouseButtonToCheck == MouseButtons.RightClick &&
                        mouseState.RightButton == ButtonState.Pressed) return true;

                    if (mouseButtonToCheck == MouseButtons.MouseWheelUp && ScrollPos > LastScrollPos) return true;
                    if (mouseButtonToCheck == MouseButtons.MouseWheelDown && ScrollPos < LastScrollPos) return true;
                }

                return false;
            }
Exemple #8
0
        private static void OnGUI(UnityModManager.ModEntry modEntry)
        {
            if (Settings.actionList == null)
            {
                Dictionary <ActionKeys, KeyCode> _keydict = new Dictionary <ActionKeys, KeyCode>
                {
                    { ActionKeys.SendPatientHome, KeyCode.R },
                    { ActionKeys.SendPatientTreatment, KeyCode.T },
                    { ActionKeys.PromoteStaff, KeyCode.Y },
                    { ActionKeys.FireStaff, KeyCode.F },
                    { ActionKeys.EditRoomItems, KeyCode.I },
                    { ActionKeys.EditRoom, KeyCode.E },
                    { ActionKeys.CopyRoom, KeyCode.C },
                    { ActionKeys.SellRoom, KeyCode.S }
                };
                Settings.actionList = _keydict.Keys.ToList <ActionKeys>();
                Settings.keyList    = _keydict.Values.ToList <KeyCode>();
                _keydict.Clear();
            }

            Dictionary <ActionKeys, KeyCode> keydict = Settings.actionList.Zip(Settings.keyList, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v);

            foreach (KeyValuePair <ActionKeys, KeyCode> entry in keydict)
            {
                GUILayout.BeginHorizontal();
                //GUI.skin.label.CalcSize()
                GUILayout.Label($"Key for action {entry.Key.ToString()}", GUILayout.Width(240.0f));
                if (GUILayout.Button(entry.Value.ToString(), GUILayout.Width(120.0f)))
                {
                    WaitingForKey = entry.Key;
                }
                GUILayout.EndHorizontal();
            }

            keydict.Clear();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Enable logging ", GUILayout.ExpandWidth(false));
            Settings.EnableLogging = (GUILayout.Toggle((Settings.EnableLogging ? 1 : 0) != 0, "", GUILayout.ExpandWidth(false)) ? 1 : 0) != 0;
            GUILayout.EndHorizontal();
        }
Exemple #9
0
        /// <summary>
        /// Execute desired action
        /// </summary>
        /// <param name="desiredAction"></param>
        private void MediaPlayerAction(ActionKeys desiredAction)
        {
            string searchText = SearchBox.Text;

            SearchBox.Text = string.Empty;

            // Remove action indicators from string (ie. !p, !s, etc)
            if (desiredAction == ActionKeys.Play || desiredAction == ActionKeys.Remove)
            {
                int startIndexOfSong = searchText.IndexOf(" ") + 1;
                searchText = searchText.Substring(startIndexOfSong);
            }

            switch (desiredAction)
            {
            case ActionKeys.Play:
                Task.Run(() => _musicPlayer.PlaySongAsync(searchText));
                break;

            case ActionKeys.Remove:
                _musicPlayer.RemoveSongFromQueue(searchText);
                break;

            case ActionKeys.Skip:
                _musicPlayer.SkipSong();
                break;

            case ActionKeys.Repeat:
                _musicPlayer.Repeat();
                break;

            case ActionKeys.Loop:
                _musicPlayer.Loop();
                break;
            }

            return;
        }
Exemple #10
0
        /// <summary>
        /// Recieve user input in search box upon 'Enter'
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SearchBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                // Disable 'Ding' sound from textbox
                e.Handled          = true;
                e.SuppressKeyPress = true;

                // Obtain corresponding enum to desired action
                ActionKeys desiredAction = FindDesiredAction(SearchBox.Text);

                // Set warning if no corresponding action is found
                if (desiredAction == ActionKeys.NoAction)
                {
                    Display(MainInfo, "Invalid action key. Please try again.", Color.Red);
                    SearchBox.Text = string.Empty;
                    return;
                }

                // Execute action
                MediaPlayerAction(desiredAction);
                return;
            }
        }
Exemple #11
0
 public bool IsPressed(ActionKeys key)
 {
     return(newState.CheckPressed(key));
 }
Exemple #12
0
 public bool JustReleased(ActionKeys key)
 {
     return(oldState.CheckPressed(key) && !newState.CheckPressed(key));
 }
Exemple #13
0
 public bool JustPressed(ActionKeys key)
 {
     return(!oldState.CheckPressed(key) && newState.CheckPressed(key));
 }
Exemple #14
0
 public static void UnRegisterKeyDownEvent(ActionKeys k, OnKeyDownEvent e)
 {
     actionEvents[k] -= e;
 }
 internal bool CheckPressed(ActionKeys key) => states.ContainsKey(key) && states[key];
Exemple #16
0
 public bool JustReleased(ActionKeys key, ShiftKeys shift)
 {
     return(newState.ShiftPressed(shift) && ((oldState.CheckPressed(key) && !newState.CheckPressed(key))));
 }
Exemple #17
0
 public bool IsPressed(ActionKeys key, ShiftKeys shift)
 {
     return(newState.ShiftPressed(shift) && (newState.CheckPressed(key)));
 }
Exemple #18
0
 public static void RegisterKeyDownEvent(ActionKeys k ,OnKeyDownEvent e)
 {
     if (!actionEvents.ContainsKey(k))
     actionEvents[k] = e;
       else
     actionEvents[k] += e;
 }