diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/input.cc | 43 | ||||
-rw-r--r-- | src/client/keyboard.cc | 22 | ||||
-rw-r--r-- | src/client/keyboard.h | 4 |
3 files changed, 53 insertions, 16 deletions
diff --git a/src/client/input.cc b/src/client/input.cc index 044ebc2..2f09d5b 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -104,10 +104,21 @@ void func_ui_chat(std::string const &args) } } -void func_ui_view(std::string const &args) +void func_view_next(std::string const &args) { if (core::application()->connected() && core::localcontrol()) { - render::Camera::next_mode(); + render::Camera::view_next(); + local_roll = 0; + local_pitch = 0; + local_direction = 0; + audio::play("ui/view"); + } +} + +void func_view_prev(std::string const &args) +{ + if (core::application()->connected() && core::localcontrol()) { + render::Camera::view_previous(); local_roll = 0; local_pitch = 0; local_direction = 0; @@ -227,9 +238,6 @@ void init() func = core::Func::add("ui_chat", func_ui_chat); func->set_info("toggle chatbox on or of"); - func = core::Func::add("ui_view", func_ui_view); - func->set_info("switch camera view"); - func = core::Func::add("ui_control",func_ui_control); func->set_info("toggle mouse control"); @@ -251,6 +259,12 @@ void init() func = core::Func::add("unbindall", func_unbind); func->set_info("unbind all keys"); + func = core::Func::add("view_next", func_view_next); + func->set_info("switch to next view"); + + func = core::Func::add("view_prev", func_view_prev); + func->set_info("switch to previous view"); + func = core::Func::add("screenshot", func_screenshot); func->set_info("make a screenshot"); @@ -406,8 +420,21 @@ Key::Modifier convert_SDL_modifier(int const sdlmodifier) void key_pressed(Key *key) { - if ((key->sym() == SDLK_ESCAPE) || (key->bind(Key::None).compare("ui_console") == 0)) { - console()->toggle(); + if (key->sym() == SDLK_ESCAPE) { + if (chat::visible()) { + chat::toggle(); + } else { + local_direction = 0.0f; + local_pitch = 0.0f; + local_roll = 0.0f; + + render::Camera::set_direction(0.0f); + render::Camera::set_pitch(0.0f); + + console()->toggle(); + } + + } else if (key->bind(Key::None).compare("ui_console") == 0) { local_direction = 0.0f; local_pitch = 0.0f; local_roll = 0.0f; @@ -415,6 +442,8 @@ void key_pressed(Key *key) render::Camera::set_direction(0.0f); render::Camera::set_pitch(0.0f); + console()->toggle(); + } else if (console()->visible()) { // send key events to the console if (key->sym() < 512) diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc index e0c5642..791e6df 100644 --- a/src/client/keyboard.cc +++ b/src/client/keyboard.cc @@ -52,6 +52,7 @@ Keyboard::Keyboard() add_action("+control", Action::None, "enable mouse control while pressed"); // ------------------ KEYS + Key *key = 0; add_key("backspace", SDLK_BACKSPACE); add_key("tab", SDLK_TAB); @@ -113,15 +114,18 @@ Keyboard::Keyboard() add_key("k", SDLK_k, 'k'); add_key("l", SDLK_l, 'l'); add_key("m", SDLK_m, 'm'); - add_key("n", SDLK_n, 'n', "target_next"); + key = add_key("n", SDLK_n, 'n', "target_next"); + key->assign(Key::Shift, "target_prev"); add_key("o", SDLK_o, 'o'); - add_key("p", SDLK_p, 'p', "target_prev"); + add_key("p", SDLK_p, 'p'); add_key("q", SDLK_q, 'q'); add_key("r", SDLK_r, 'r'); add_key("s", SDLK_s, 's'); add_key("t", SDLK_t, 't', "ui_chat"); add_key("u", SDLK_u, 'u'); - add_key("v", SDLK_v, 'v', "ui_view"); + key = add_key("v", SDLK_v, 'v', "view_next"); + key->assign(Key::Shift, "view_prev"); + add_key("w", SDLK_w, 'w'); add_key("x", SDLK_x, 'x'); add_key("y", SDLK_y, 'y'); @@ -423,14 +427,18 @@ void Keyboard::unbindall() } } -void Keyboard::add_key(const char *name, const unsigned int keysym, const char ascii, const char *bind) +Key * Keyboard::add_key(const char *name, const unsigned int keysym, const char ascii, const char *bind) { - keys[keysym] = new Key(name, keysym, ascii, bind); + Key *newkey = new Key(name, keysym, ascii, bind); + keys[keysym] = newkey; + return newkey; } -void Keyboard::add_action(const char *name, Action::Identifier action, const char *info) +Action * Keyboard::add_action(const char *name, Action::Identifier action, const char *info) { - actions.push_back(new Action(name, action, info)); + Action *newaction = new Action(name, action, info); + actions.push_back(newaction); + return newaction; } void Keyboard::list_actions() diff --git a/src/client/keyboard.h b/src/client/keyboard.h index 2841495..87a67c4 100644 --- a/src/client/keyboard.h +++ b/src/client/keyboard.h @@ -70,9 +70,9 @@ public: inline iterator end() { return keys.end(); } private: - void add_key(const char *name, const unsigned int keysym, const char ascii=0, const char *bind=0); + Key *add_key(const char *name, const unsigned int keysym, const char ascii=0, const char *bind=0); - void add_action(const char *name, Action::Identifier action, const char *info = 0); + Action *add_action(const char *name, Action::Identifier action, const char *info = 0); std::map<unsigned int, Key *> keys; std::list<Action *> actions; |