diff options
Diffstat (limited to 'src/client/input.cc')
-rw-r--r-- | src/client/input.cc | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/src/client/input.cc b/src/client/input.cc index 3d9caa5..8075058 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -11,6 +11,7 @@ #include "client/chat.h" #include "client/console.h" #include "client/keyboard.h" +#include "client/targets.h" #include "client/video.h" #include "render/camera.h" #include "math/functions.h" @@ -21,7 +22,7 @@ namespace client { -core::Cvar *cl_mousecontrol = 0; +core::Cvar *input_mousecontrol = 0; namespace input { @@ -31,7 +32,7 @@ namespace input Keyboard *keyboard = 0; //bool free_control = true; -bool cl_mousecontrol_override = false; + // local controls float local_direction = 0.0f; @@ -51,7 +52,9 @@ float mouse_direction = 0; // true if the mouse is in the deadzone bool mouse_deadzone = false; + // true if the mouse has control +bool mouse_control_override = false; bool mouse_control = false; const float thruster_offset = 0.05f; @@ -71,13 +74,13 @@ void func_ui_control(std::string const &args) if (!core::localcontrol()) return; - if (cl_mousecontrol->value() > 0) { - (*cl_mousecontrol) = 0.0f; + if (input_mousecontrol->value() > 0) { + (*input_mousecontrol) = 0.0f; } else { - (*cl_mousecontrol) = 1.0f; + (*input_mousecontrol) = 1.0f; } - if (!cl_mousecontrol->value()) { + if (!input_mousecontrol->value()) { local_direction = 0.0f; local_pitch = 0.0f; local_roll = 0.0f; @@ -169,8 +172,8 @@ void init() SDL_WM_GrabInput(SDL_GRAB_ON); // SDL_EnableUNICODE(1); - cl_mousecontrol = core::Cvar::get("cl_mousecontrol", "1", core::Cvar::Archive); - cl_mousecontrol->set_info("[bool] set mouse control on or off"); + input_mousecontrol = core::Cvar::get("input_mousecontrol", "1", core::Cvar::Archive); + input_mousecontrol->set_info("[bool] enable or disable mouse control"); core::Func *func = 0; @@ -181,10 +184,10 @@ void init() func->set_info("toggle chatbox on or of"); func = core::Func::add("ui_view", func_ui_view); - func->set_info("switch view mode"); + func->set_info("switch camera view"); func = core::Func::add("ui_control",func_ui_control); - func->set_info("toggle mouse control on or off"); + func->set_info("toggle mouse control"); func = core::Func::add("list_keys", func_list_keys); func->set_info("list keyboard key names"); @@ -251,7 +254,7 @@ void action_press(std::string const &action) /* -- mouse control ------------------------------- */ } else if (action.compare("+control") == 0) { - cl_mousecontrol_override = true; + mouse_control_override = true; /* -- directional control ------------------------- */ } else if (action.compare("+left") == 0) { @@ -299,8 +302,8 @@ void action_release(std::string const &action) /* -- mouse control ------------------------------- */ } else if (action.compare("+control") == 0) { - cl_mousecontrol_override = false; - if (!cl_mousecontrol->value()) { + mouse_control_override = false; + if (!input_mousecontrol->value()) { local_direction = 0.0f; local_pitch = 0.0f; local_roll = 0.0f; @@ -357,8 +360,8 @@ void frame(float seconds) mouse_x = video::width / 2; mouse_y = video::height / 2; render::Camera::reset(); - cl_mousecontrol_override = false; - + mouse_control_override = false; + targets::reset(); render::reset(); } @@ -379,6 +382,7 @@ void frame(float seconds) break; case SDL_MOUSEBUTTONDOWN: + // override for gui mouse down key = keyboard->press(512 + event.button.button); pressed = true; break; @@ -411,8 +415,10 @@ void frame(float seconds) if (keysym.mod & KMOD_CAPS) capslock = true; else capslock = false; if ((keysym.mod & KMOD_LSHIFT) || (keysym.mod & KMOD_RSHIFT)) capslock != capslock; */ - // console key is always captured - if (key->bind().compare("ui_console") == 0) { + // FIXME console key is always captured + // FIXME ESC should escape to gui + + if ((key->sym() == SDLK_ESCAPE) || (key->bind().compare("ui_console") == 0)) { console()->toggle(); local_direction = 0.0f; local_pitch = 0.0f; @@ -433,15 +439,22 @@ void frame(float seconds) } else if (core::application()->connected() && core::localcontrol()) { - char c = key->bind().c_str()[0]; - if (c == '+' || c == '-') { - // action bind - action_press(key->bind()); + if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover()) { + // hovering target selected + targets::select_target(targets::hover()); - } else if (c) { - // normal bind - core::cmd() << key->bind() << "\n"; + } else { + char c = key->bind().c_str()[0]; + if (c == '+' || c == '-') { + // action bind + action_press(key->bind()); + + } else if (c) { + // normal bind + core::cmd() << key->bind() << "\n"; + } } + } else if (core::application()->connected()) { char c = key->bind().c_str()[0]; @@ -470,7 +483,7 @@ void frame(float seconds) if (core::application()->connected() && core::localcontrol()) { - mouse_control = !console()->visible() && ((cl_mousecontrol->value() > 0) || cl_mousecontrol_override); + mouse_control = !console()->visible() && ((input_mousecontrol->value() > 0) || mouse_control_override); if (mouse_control) { // the mouse will not react if it is in the deadzone |