//////////////////////////////////////////////////////////////////////////////// // // Module: ctrls.cpp // Author: Tom Hicks // Creation: 09-01-2003 // LastEdit: 06-19-2005 // Editors: Tom Hicks // // Purpose: // To implement a system for managing a bindable control scheme. // // Summary of Methods: // ControlSchemeClass // void LoadDefaultControlScheme(); // -Loads the default control scheme // void ClearControlScheme(); // -Clears the control scheme // void Unbind(uint8 key); // -Removes key from all control lists. // // Summary of Properties: // ControlSchemeClass // -list forward; // A list of the VKeys associated with forward. // -list backward; // A list of the VKeys associated with backward. // -list lookLeft; // A list of the VKeys associated with turning left. // -list lookRight; // A list of the VKeys associated with turning right. // -list lookUp; // A list of the VKeys associated with looking up. // -list lookDown; // A list of the VKeys associated with looking down. // -list moveLeft; // A list of the VKeys associated with strafing left. // -list moveRight; // A list of the VKeys associated with strafing right. // -list moveUp; // A list of the VKeys associated with jumping. // -list moveDown; // A list of the VKeys associated with crouching. // -list firePrimary; // A list of the VKeys associated with activating the primary ability of the active item. // -list fireSecondary; // A list of the VKeys associated with activating the secondary ablilty of the active item. // -list weaponNext; // A list of the VKeys associated with switching to the next item. // -list weaponPrev; // A list of the VKeys associated with switching to the previous item. // -list toggleLights; // A list of the VKeys associated with turning lighting on and off. // -list toggleFPS; // A list of the VKeys associated with turning the FPS display on and off. // -list toggleConsole; // A list of the VKeys associated with toggling the display of the console. // -list toggleMouseLook; // A list of the VKeys associated with toggling mouse look. // -list quickMouseLook; // A list of the VKeys associated with temporarily switching the mouse look mode. // -list rollLeft; // A list of the VKeys associated with rolling left. // -list rollRight; // A list of the VKeys associated with rolling right. // //////////////////////////////////////////////////////////////////////////////// #include "../include/ctrls.h" namespace OpenArena{ void ControlSchemeClass::LoadDefaultControlScheme() { forward.Insert(OpenArena::KEY_LBUTTON); backward.Insert(OpenArena::KEY_RBUTTON); lookLeft.Insert(OpenArena::KEY_LEFT); lookRight.Insert(OpenArena::KEY_RIGHT); lookUp.Insert(OpenArena::KEY_UP); lookDown.Insert(OpenArena::KEY_DOWN); moveLeft.Insert(OpenArena::KEY_S); moveRight.Insert(OpenArena::KEY_D); moveUp.Insert(OpenArena::KEY_SPACE); moveDown.Insert(OpenArena::KEY_A); firePrimary.Insert(OpenArena::KEY_F); fireSecondary.Insert(OpenArena::KEY_G); weaponNext.Insert(OpenArena::KEY_T); weaponPrev.Insert(OpenArena::KEY_R); toggleLights.Insert(OpenArena::KEY_L); toggleFPS.Insert(OpenArena::KEY_P); toggleConsole.Insert(OpenArena::KEY_OEM_3); toggleMouseLook.Insert(OpenArena::KEY_M); quickMouseLook.Insert(OpenArena::KEY_Q); rollLeft.Insert(OpenArena::KEY_W); rollRight.Insert(OpenArena::KEY_E); } void ControlSchemeClass::ClearControlScheme() { backward.Clear(); firePrimary.Clear(); fireSecondary.Clear(); forward.Clear(); lookDown.Clear(); lookUp.Clear(); lookRight.Clear(); lookLeft.Clear(); moveDown.Clear(); moveUp.Clear(); moveLeft.Clear(); moveRight.Clear(); quickMouseLook.Clear(); toggleConsole.Clear(); toggleFPS.Clear(); toggleLights.Clear(); toggleMouseLook.Clear(); weaponNext.Clear(); weaponPrev.Clear(); } void ControlSchemeClass::Unbind(uint8 key) { backward.Remove(key); firePrimary.Remove(key); fireSecondary.Remove(key); forward.Remove(key); lookDown.Remove(key); lookUp.Remove(key); lookRight.Remove(key); lookLeft.Remove(key); moveDown.Remove(key); moveUp.Remove(key); moveRight.Remove(key); quickMouseLook.Remove(key); toggleConsole.Remove(key); toggleFPS.Remove(key); toggleLights.Remove(key); toggleMouseLook.Remove(key); weaponNext.Remove(key); weaponPrev.Remove(key); } bool ControlSchemeClass::Bind(uint32 action, uint8 key) { switch(action) { case CTRLS_FORWARD: { Unbind(key); forward.Insert(key); return true; } case CTRLS_BACKWARD: { Unbind(key); backward.Insert(key); return true; } case CTRLS_LOOKLEFT: { Unbind(key); lookLeft.Insert(key); return true; } case CTRLS_LOOKRIGHT: { Unbind(key); lookRight.Insert(key); return true; } case CTRLS_LOOKUP: { Unbind(key); lookUp.Insert(key); return true; } case CTRLS_LOOKDOWN: { Unbind(key); lookDown.Insert(key); return true; } case CTRLS_MOVELEFT: { Unbind(key); moveLeft.Insert(key); return true; } case CTRLS_MOVERIGHT: { Unbind(key); moveRight.Insert(key); return true; } case CTRLS_MOVEUP: { Unbind(key); moveUp.Insert(key); return true; } case CTRLS_MOVEDOWN: { Unbind(key); moveDown.Insert(key); return true; } case CTRLS_ROLLLEFT: { Unbind(key); rollLeft.Insert(key); return true; } case CTRLS_ROLLRIGHT: { Unbind(key); rollRight.Insert(key); return true; } case CTRLS_FIREPRIMARY: { Unbind(key); firePrimary.Insert(key); return true; } case CTRLS_FIRESECONDARY: { Unbind(key); fireSecondary.Insert(key); return true; } case CTRLS_WEAPONNEXT: { Unbind(key); weaponNext.Insert(key); return true; } case CTRLS_WEAPONPREV: { Unbind(key); weaponPrev.Insert(key); return true; } case CTRLS_TOGGLE_LIGHTS: { Unbind(key); toggleLights.Insert(key); return true; } case CTRLS_TOGGLE_FPS: { Unbind(key); toggleFPS.Insert(key); return true; } case CTRLS_TOGGLE_CONSOLE: { Unbind(key); toggleConsole.Insert(key); return true; } case CTRLS_TOGGLE_MOUSELOOK: { Unbind(key); toggleMouseLook.Insert(key); return true; } case CTRLS_QUICKMOUSELOOK: { Unbind(key); quickMouseLook.Insert(key); return true; } default: return false; } } };