/// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event data.</param> private void onButtonPressed(object sender, ButtonPressedEventArgs e) { //only when player is ready shall we start process button event if (!StardewWrap.isPlayerReady()) { return; } buttonPressed(e.Button); }
/// <summary> /// SMAPI raise trigger when its value is above about 0.2 but Stardew process trigger 0~0.2 as swap item. if trigger need to be binded, we need our way to track its events. /// But this way the game will not receive any trigger event in "normal" state. /// </summary> private void overrideTrigger() { var padState = StardewWrap.GetRealGamePadState(); if (padState.Triggers.Left > 0) { if (StardewWrap.isPlayerReady()) { //this.Monitor.Log($"left:{padState.Triggers.Left}, {Helper.Input.IsSuppressed(SButton.LeftTrigger)}", LogLevel.Debug); if (padState.Triggers.Left > m_threshold && !m_leftTriggerOn) { m_leftTriggerOn = true; buttonPressed(SButton.LeftTrigger); } Helper.Input.Suppress(SButton.LeftTrigger); } } else if (m_lastLeft != 0) { //this.Monitor.Log($"left:{padState.Triggers.Left}, {Helper.Input.IsSuppressed(SButton.LeftTrigger)}", LogLevel.Debug); m_leftTriggerOn = false; Helper.Input.Suppress(SButton.LeftTrigger); } m_lastLeft = padState.Triggers.Left; if (padState.Triggers.Right > 0) { if (StardewWrap.isPlayerReady()) { if (padState.Triggers.Right > 0.1 && !m_rightTriggerOn) { m_rightTriggerOn = true; buttonPressed(SButton.RightTrigger); } Helper.Input.Suppress(SButton.RightTrigger); } } else if (m_lastRight != 0) { //this.Monitor.Log($"left:{padState.Triggers.Left}, {Helper.Input.IsSuppressed(SButton.LeftTrigger)}", LogLevel.Debug); m_rightTriggerOn = false; Helper.Input.Suppress(SButton.RightTrigger); } m_lastRight = padState.Triggers.Right; }
/********* ** Private methods *********/ /// <summary>The method invoked when the player presses a controller, keyboard, or mouse button.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event data.</param> private void inputEvents_ButtonPressed(object sender, EventArgsInput e) { #if DEBUG this.Monitor.Log($"Pressed {e.Button}."); #endif //only when player is ready shall we start process button event if (!StardewWrap.isPlayerReady()) { return; } //if current key is modify key, mark the key if (isModifyKey(e.Button)) { m_modify = e.Button; e.SuppressButton(); return; } //not modify key. Now check if the key combination is in the config CmdCfg cfg = findCmdCfg(e.Button); if (cfg == null) { return; } //old command must finished before new command could be created, but record the key to see if we can invoke it later if ((m_curCmd != null && !m_curCmd.isFinish) || StardewWrap.isPlayerBusy()) { m_lastActionButtion = e.Button; return; } //now create the command m_cmdcfg = cfg; m_curCmd = Command.create(m_cmdcfg.cmd); if (m_curCmd == null) { m_cmdcfg = null; return; } //command is there so just overide and execute it m_curCmd.exec(m_cmdcfg.par); e.SuppressButton(); }
private void inputEvents_ButtonReleased(object sender, EventArgsInput e) { #if DEBUG this.Monitor.Log($"Released {e.Button}."); #endif //only when player is ready shall we start process button event if (!StardewWrap.isPlayerReady()) { return; } //if modify key released, mark m_modify as none and stop current command if necessary if (isModifyKey(e.Button)) { if (m_modify == e.Button) { m_modify = SButton.None; } if (m_cmdcfg != null && e.Button == m_cmdcfg.modifyKey) { stopCmd(); } e.SuppressButton(); return; } //it's action key, mark released if (m_lastActionButtion == e.Button) { m_lastActionButtion = SButton.None; } //try to end active command if (m_cmdcfg != null && e.Button == m_cmdcfg.key) { stopCmd(); } e.SuppressButton(); }