home *** CD-ROM | disk | FTP | other *** search
- #include "InputCCmds.h"
-
- #include "Input.h"
- #include "Tokenizer.h"
-
- CCmdInputBind::CCmdInputBind():CCmd("input.bind"){
- usageStr="input.bind [key] [action]";
- infoStr="binds a action to a key";
- }
-
- CCmdInputBind::~CCmdInputBind(){
- if(console!=NULL)
- console->unregisterCCmd(this);
- }
-
- bool CCmdInputBind::exec(int argc, char* argv[]){
- if(argc==2){
- int key=Input::getKeyForString(argv[0]);
- if(key==-1){ // no key -> try mouseButton
- int button=Input::getMouseButtonForString(argv[0]);
- if(button==-1){ // no button -> failure
- console->print("'%s' is not a valid key\n", argv[0]);
- return false;
- }else{
-
- int action=Input::getActionForString(argv[1]);
-
- if(action!=-1){
- Input::mouse.buttons[button].action=(action_t)action;
- console->print("%s bound to %s.\n", argv[1], argv[0]);
- return true;
- }else{
- Input::mouse.buttons[button].consoleString=newString(argv[1]); // deleted in shutdownInput()
- console->print("%s bound to %s.\n", argv[1], argv[0]);
- return true;
- }
-
- }
- }
-
- int action=Input::getActionForString(argv[1]);
-
- if(action!=-1){
- Input::keyMap[key].action=(action_t)action;
- console->print("%s bound to %s.\n", argv[1], argv[0]);
- return true;
- }else{
- Input::keyMap[key].consoleString=newString(argv[1]);
- console->print("%s bound to %s.\n", argv[1], argv[0]);
- return true;
- }
- }else{
- console->print("usage: %s\n", usageStr);
- return false;
- }
- }
-
- CCmdInputUnbind::CCmdInputUnbind():CCmd("input.unbind"){
- usageStr="input.unbind [key] or input.unbind all";
- infoStr="unbinds a key/mousebutton (or all keys)";
- }
-
- CCmdInputUnbind::~CCmdInputUnbind(){
- if(console!=NULL)
- console->unregisterCCmd(this);
- }
-
- bool CCmdInputUnbind::exec(int argc, char* argv[]){
- if(argc==1){
- if(streq(argv[0], "all")){
- int i;
- for(i=0;i<SDLK_LAST;i++){ // unbind all keys
- Input::keyMap[i].action=NO_ACTION;
- if(Input::keyMap[i].consoleString!=NULL){
- delete[] Input::keyMap[i].consoleString;
- Input::keyMap[i].consoleString=NULL;
- }
- }
- for(i=0;i<NUM_MOUSE_BUTTONS;i++){ // and all mouse buttons
- Input::mouse.buttons[i].action=NO_ACTION;
- if(Input::mouse.buttons[i].consoleString!=NULL){
- delete[] Input::mouse.buttons[i].consoleString;
- Input::mouse.buttons[i].consoleString=NULL;
- }
- }
- console->print("ALL unbound.\n");
- return true;
- }
-
- // unbind ONE key/button
- int key=Input::getKeyForString(argv[0]);
- if(key==-1){ // no key -> try mouseButton
- int button=Input::getMouseButtonForString(argv[0]);
- if(button==-1){ // no button -> failure
- console->print("'%s' is not a valid key\n", argv[0]);
- return false;
- }else{
- if(Input::mouse.buttons[button].action!=NO_ACTION){
- Input::mouse.buttons[button].action=NO_ACTION;
- }
- if(Input::mouse.buttons[button].consoleString!=NULL){
- delete[] Input::mouse.buttons[button].consoleString;
- Input::mouse.buttons[button].consoleString=NULL;
- }
- console->print("%s unbound.\n", argv[0]);
- return true;
- }
- }else{ // unbind key
- Input::keyMap[key].action=NO_ACTION;
- if(Input::keyMap[key].consoleString!=NULL){
- delete[] Input::keyMap[key].consoleString;
- Input::keyMap[key].consoleString=NULL;
- }
- console->print("%s unbound.\n", argv[0]);
- return true;
- }
- }else{
- console->print("usage: %s\n", usageStr);
- return false;
- }
- }
-
-
- CCmdInputBindlist::CCmdInputBindlist():CCmd("input.bindlist"){
- usageStr="input.bindlist";
- infoStr="gives a list with all current bindings";
- }
-
- CCmdInputBindlist::~CCmdInputBindlist(){
- if(console!=NULL)
- console->unregisterCCmd(this);
- }
-
- bool CCmdInputBindlist::exec(int argc, char* argv[]){
- if(argc==0){
- console->print("This will be included in the next release...\n"); // TODO
- return true;
- }else{
- console->print("usage: %s\n", usageStr);
- return false;
- }
- }
-
- CCmdInputGrabMouse::CCmdInputGrabMouse():CCmd("input.grabMouse"){
- usageStr="input.grabMouse";
- infoStr="grabs input focus";
- }
-
- CCmdInputGrabMouse::~CCmdInputGrabMouse(){
- if(console!=NULL)
- console->unregisterCCmd(this);
- }
-
- bool CCmdInputGrabMouse::exec(int argc, char* argv[]){
- if(argc==0){
- Input::grabInput();
- Input::hideMouseCursor();
- return true;
- }else{
- console->print("usage: %s\n", usageStr);
- return false;
- }
- }
-
- CCmdInputFreeMouse::CCmdInputFreeMouse():CCmd("input.freeMouse"){
- usageStr="input.freeMouse";
- infoStr="frees input focus";
- }
-
- CCmdInputFreeMouse::~CCmdInputFreeMouse(){
- if(console!=NULL)
- console->unregisterCCmd(this);
- }
-
- bool CCmdInputFreeMouse::exec(int argc, char* argv[]){
- if(argc==0){
- Input::freeInput();
- Input::showMouseCursor();
- return true;
- }else{
- console->print("usage: %s\n", usageStr);
- return false;
- }
- }
-
-
-