예제 #1
0
        /// <summary>
        /// Harmony prefix patch to cancel the zoning tool when it's active and the escape key is pressed.
        /// </summary>
        /// <returns>True (continue on to game method) if the zoning tool isn't already active, false (pre-empt game method) otherwise</returns>
        public static bool Prefix()
        {
            // Is the zoning tool active?
            if (BOBTool.IsActiveTool)
            {
                // Yes; toggle tool status and return false (pre-empt original method).
                BOBTool.ToggleTool();
                return(false);
            }

            // Tool not active - don't do anything, just go on to game code.
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Look for keypress to activate tool.
        /// </summary>
        /// <param name="realTimeDelta"></param>
        /// <param name="simulationTimeDelta"></param>
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            // Don't do anything if not active.
            if (operating)
            {
                // Has hotkey been pressed?
                if (savedKey.Key != KeyCode.None && Input.GetKey(savedKey.Key))
                {
                    // Check modifier keys according to settings.
                    bool altPressed   = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt) || Input.GetKey(KeyCode.AltGr);
                    bool ctrlPressed  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
                    bool shiftPressed = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

                    // Modifiers have to *exactly match* settings, e.g. "alt-E" should not trigger on "ctrl-alt-E".
                    bool altOkay   = altPressed == savedKey.Alt;
                    bool ctrlOkay  = ctrlPressed == savedKey.Control;
                    bool shiftOkay = shiftPressed == savedKey.Shift;

                    // Process keystroke.
                    if (altOkay && ctrlOkay && shiftOkay)
                    {
                        // Only process if we're not already doing so.
                        if (!processed)
                        {
                            // Set processed flag.
                            processed = true;

                            // Toggle tool status.
                            BOBTool.ToggleTool();
                        }
                    }
                    else
                    {
                        // Relevant keys aren't pressed anymore; this keystroke is over, so reset and continue.
                        processed = false;
                    }
                }
                else
                {
                    // Relevant keys aren't pressed anymore; this keystroke is over, so reset and continue.
                    processed = false;
                }
            }
        }