public bool IsBound(Buttons button, InfiniminerShared.MouseButton mb) { if (mouseBinds.ContainsKey(mb) && mouseBinds[mb] == button) { return(true); } return(false); }
//If overwrite is true then the previous entry for that button will be removed public bool BindKey(Buttons button, string key, bool overwrite) { try { //Key bind Keys actualKey = (Keys)Enum.Parse(typeof(Keys), key, true); if (Enum.IsDefined(typeof(Keys), actualKey)) { keyBinds.Add(actualKey, (Buttons)button); return(true); } } catch { } try { //Mouse bind InfiniminerShared.MouseButton actualMB = (InfiniminerShared.MouseButton)Enum.Parse(typeof(InfiniminerShared.MouseButton), key, true); if (Enum.IsDefined(typeof(InfiniminerShared.MouseButton), actualMB)) { mouseBinds.Add(actualMB, (Buttons)button); return(true); } } catch { } //Special cases if (key.Equals("control", StringComparison.OrdinalIgnoreCase) || key.Equals("ctrl", StringComparison.OrdinalIgnoreCase)) { specialKeyBinds.Add(SpecialKeys.Control, (Buttons)button); return(true); } if (key.Equals("shift", StringComparison.OrdinalIgnoreCase)) { specialKeyBinds.Add(SpecialKeys.Shift, (Buttons)button); return(true); } if (key.Equals("alt", StringComparison.OrdinalIgnoreCase)) { specialKeyBinds.Add(SpecialKeys.Alt, (Buttons)button); return(true); } return(false); }
public bool IsBound(Buttons button, Keys theKey) { if (keyBinds.ContainsKey(theKey) && keyBinds[theKey] == button) { return(true); } else if ((theKey == Keys.LeftAlt || theKey == Keys.RightAlt) && specialKeyBinds.ContainsKey(SpecialKeys.Alt) && specialKeyBinds[SpecialKeys.Alt] == button) { return(true); } else if ((theKey == Keys.LeftShift || theKey == Keys.RightShift) && specialKeyBinds.ContainsKey(SpecialKeys.Shift) && specialKeyBinds[SpecialKeys.Shift] == button) { return(true); } else if ((theKey == Keys.LeftControl || theKey == Keys.RightControl) && specialKeyBinds.ContainsKey(SpecialKeys.Control) && specialKeyBinds[SpecialKeys.Control] == button) { return(true); } return(false); }
public bool IsPressed(Buttons button) { KeyboardState state = Keyboard.GetState(); foreach (Keys key in keyBinds.Keys) { if (keyBinds[key] == button) { if (state.IsKeyDown(key)) { return(true); } } } MouseState ms = Mouse.GetState(); foreach (InfiniminerShared.MouseButton mb in mouseBinds.Keys) { if (mouseBinds[mb] == button) { switch (mb) { case MouseButton.LeftButton: if (ms.LeftButton == ButtonState.Pressed) { return(true); } break; case MouseButton.MiddleButton: if (ms.MiddleButton == ButtonState.Pressed) { return(true); } break; case MouseButton.RightButton: if (ms.RightButton == ButtonState.Pressed) { return(true); } break; } } } foreach (SpecialKeys key in specialKeyBinds.Keys) { if (specialKeyBinds[key] == button) { switch (key) { case SpecialKeys.Alt: if (state.IsKeyDown(Keys.LeftAlt) || state.IsKeyDown(Keys.RightAlt)) { return(true); } break; case SpecialKeys.Control: if (state.IsKeyDown(Keys.LeftControl) || state.IsKeyDown(Keys.RightControl)) { return(true); } break; case SpecialKeys.Shift: if (state.IsKeyDown(Keys.LeftShift) || state.IsKeyDown(Keys.RightShift)) { return(true); } break; } } } return(false); }
private void HandleInput(Buttons input) { switch (input) { case Buttons.Fire: if (_P.playerToolCooldown <= 0) { switch (_P.playerTools[_P.playerToolSelected]) { // Disabled as everyone speed-mines now. //case PlayerTools.Pickaxe: // if (_P.playerClass != PlayerClass.Miner) // _P.FirePickaxe(); // break; case PlayerTools.ConstructionGun: _P.FireConstructionGun(_P.playerBlocks[_P.playerBlockSelected]); //, !(button == MouseButton.LeftButton));//_P.FireConstructionGun(_P.playerBlocks[_P.playerBlockSelected]); break; case PlayerTools.DeconstructionGun: _P.FireDeconstructionGun(); break; case PlayerTools.Detonator: _P.PlaySound(InfiniminerSound.ClickHigh); _P.FireDetonator(); break; case PlayerTools.ProspectingRadar: _P.FireRadar(); break; } } break; case Buttons.Jump: { Vector3 footPosition = _P.playerPosition + new Vector3(0f, -1.5f, 0f); if (_P.blockEngine.SolidAtPointForPlayer(footPosition) && _P.playerVelocity.Y == 0) { _P.playerVelocity.Y = JUMPVELOCITY; float amountBelowSurface = ((ushort)footPosition.Y) + 1 - footPosition.Y; _P.playerPosition.Y += amountBelowSurface + 0.01f; } } break; case Buttons.ToolUp: _P.PlaySound(InfiniminerSound.ClickLow); _P.playerToolSelected += 1; if (_P.playerToolSelected >= _P.playerTools.Length) { _P.playerToolSelected = 0; } break; case Buttons.ToolDown: _P.PlaySound(InfiniminerSound.ClickLow); _P.playerToolSelected -= 1; if (_P.playerToolSelected < 0) { _P.playerToolSelected = _P.playerTools.Length; } break; case Buttons.Tool1: _P.playerToolSelected = 0; _P.PlaySound(InfiniminerSound.ClickLow); if (_P.playerToolSelected >= _P.playerTools.Length) { _P.playerToolSelected = _P.playerTools.Length - 1; } break; case Buttons.Tool2: _P.playerToolSelected = 1; _P.PlaySound(InfiniminerSound.ClickLow); if (_P.playerToolSelected >= _P.playerTools.Length) { _P.playerToolSelected = _P.playerTools.Length - 1; } break; case Buttons.Tool3: _P.playerToolSelected = 2; _P.PlaySound(InfiniminerSound.ClickLow); if (_P.playerToolSelected >= _P.playerTools.Length) { _P.playerToolSelected = _P.playerTools.Length - 1; } break; case Buttons.Tool4: _P.playerToolSelected = 3; _P.PlaySound(InfiniminerSound.ClickLow); if (_P.playerToolSelected >= _P.playerTools.Length) { _P.playerToolSelected = _P.playerTools.Length - 1; } break; case Buttons.Tool5: _P.playerToolSelected = 4; _P.PlaySound(InfiniminerSound.ClickLow); if (_P.playerToolSelected >= _P.playerTools.Length) { _P.playerToolSelected = _P.playerTools.Length - 1; } break; case Buttons.BlockUp: if (_P.playerTools[_P.playerToolSelected] == PlayerTools.ConstructionGun) { _P.PlaySound(InfiniminerSound.ClickLow); _P.playerBlockSelected += 1; if (_P.playerBlockSelected >= _P.playerBlocks.Length) { _P.playerBlockSelected = 0; } } break; case Buttons.BlockDown: if (_P.playerTools[_P.playerToolSelected] == PlayerTools.ConstructionGun) { _P.PlaySound(InfiniminerSound.ClickLow); _P.playerBlockSelected -= 1; if (_P.playerBlockSelected < 0) { _P.playerBlockSelected = _P.playerBlocks.Length - 1; } } break; case Buttons.Deposit: if (_P.AtBankTerminal()) { _P.DepositOre(); _P.PlaySound(InfiniminerSound.ClickHigh); } break; case Buttons.Withdraw: if (_P.AtBankTerminal()) { _P.WithdrawOre(); _P.PlaySound(InfiniminerSound.ClickHigh); } break; case Buttons.Ping: { NetBuffer msgBuffer = _P.netClient.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlayerPing); msgBuffer.Write(_P.playerMyId); _P.netClient.SendMessage(msgBuffer, NetChannel.ReliableUnordered); } break; case Buttons.ChangeClass: nextState = "Infiniminer.States.ClassSelectionState"; break; case Buttons.ChangeTeam: nextState = "Infiniminer.States.TeamSelectionState"; break; case Buttons.SayAll: _P.chatMode = ChatMessageType.SayAll; startChat = DateTime.Now; break; case Buttons.SayTeam: _P.chatMode = _P.playerTeam == PlayerTeam.Red ? ChatMessageType.SayRedTeam : ChatMessageType.SayBlueTeam; startChat = DateTime.Now; break; } }