From 59ea9fffec01a6cc3fbf147aa311bfaa9abaa933 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 22 Jul 2008 13:14:35 +0000 Subject: list_actions, renamed thruster actions --- src/client/input.cc | 96 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 33 deletions(-) (limited to 'src/client/input.cc') diff --git a/src/client/input.cc b/src/client/input.cc index dc40b8f..775f03a 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -59,9 +59,6 @@ bool mouse_control = false; const float thruster_offset = 0.05f; -// small hack to prevent two sounds triggered by the scrollwheel -bool singleclick = true; - //--- engine functions -------------------------------------------- void func_screenshot(std::string const & args) @@ -114,16 +111,42 @@ void func_ui_view(std::string const &args) } } -void func_list_keys(std::string const &args) +void func_list_actions(std::string const &args) { if (keyboard) - keyboard->list_keys(); + keyboard->list_actions(); + else + con_warn << "Keyboard handler not installed!" << std::endl; +} + +void func_list_keys(std::string const &args) +{ + if (keyboard) { + std::stringstream argstr(args); + std::string keyname; + if (argstr >> keyname) { + keyboard->list_bind(keyname); + } else { + keyboard->list_keys(); + } + } else { + con_warn << "Keyboard handler not installed!" << std::endl; + } } void func_list_binds(std::string const &args) { - if (keyboard) - keyboard->list_binds(); + if (keyboard) { + std::stringstream argstr(args); + std::string keyname; + if (argstr >> keyname) { + keyboard->list_bind(keyname); + } else { + keyboard->list_binds(); + } + } else { + con_warn << "Keyboard handler not installed!" << std::endl; + } } void func_bind(std::string const &args) @@ -134,28 +157,36 @@ void func_bind(std::string const &args) if (argstr >> keyname) { if (args.size() > keyname.size()+1) { keyboard->bind(keyname, args.substr(keyname.size()+1)); - return; + } else { + keyboard->list_bind(keyname); } + return; } - } + core::Func *func = core::Func::find("bind"); + con_print << "bind " << func->info() << std::endl; - core::Func *func = core::Func::find("bind"); - con_print << "bind " << func->info() << std::endl; + } else { + con_warn << "Keyboard handler not installed!" << std::endl; + } } void func_unbind(std::string const &args) { if (keyboard) { + std::stringstream argstr(args); std::string keyname; if (argstr >> keyname) { keyboard->unbind(keyname); return; } - } - core::Func *func = core::Func::find("unbind"); - con_print << "unbind " << func->info() << std::endl; + core::Func *func = core::Func::find("unbind"); + con_print << "unbind " << func->info() << std::endl; + + } else { + con_warn << "Keyboard handler not installed!" << std::endl; + } } //--- input functions --------------------------------------------- @@ -189,11 +220,14 @@ void init() func = core::Func::add("ui_control",func_ui_control); func->set_info("toggle mouse control"); + func = core::Func::add("list_actions", func_list_actions); + func->set_info("list key action names"); + func = core::Func::add("list_keys", func_list_keys); - func->set_info("list keyboard key names"); + func->set_info("list key names"); func = core::Func::add("list_binds",func_list_binds); - func->set_info("list keyboard binds"); + func->set_info("list keyb binds"); func = core::Func::add("bind", (core::FuncPtr) func_bind); func->set_info("[key] [str] bind a command to a key"); @@ -214,6 +248,7 @@ void shutdown() { con_print << "^BShutting down input..." << std::endl; + core::Func::remove("list_actions"); core::Func::remove("list_keys"); core::Func::remove("list_binds"); @@ -241,19 +276,11 @@ void shutdown() void action_press(std::string const &action) { /* -- thruster ------------------------------------ */ - if (action.compare("+thrust") == 0) { - if (local_thrust < 1.0f && singleclick) { - //audio::play("ui/thruster"); - singleclick = false; - } + if (action.compare("+thrustup") == 0) { local_thrust += thruster_offset; - } else if (action.compare("-thrust") == 0) { - if (local_thrust > 0.0f && singleclick) { - //audio::play("ui/thruster"); - singleclick = false; - } + } else if (action.compare("+thrustdown") == 0) { local_thrust -= 2.0f * thruster_offset; /* -- mouse control ------------------------------- */ @@ -298,10 +325,10 @@ void action_press(std::string const &action) void action_release(std::string const &action) { /* -- thruster ------------------------------------ */ - if (action.compare("+thrust") == 0) { + if (action.compare("+thrustup") == 0) { - } else if (action.compare("-thrust") == 0) { + } else if (action.compare("+thrustdown") == 0) { /* -- mouse control ------------------------------- */ @@ -372,7 +399,6 @@ void frame(float seconds) SDL_Event event; Key *key = 0; bool pressed = false; - singleclick = true; while (SDL_PollEvent(&event)) { pressed = false; @@ -450,7 +476,7 @@ void frame(float seconds) } else { // FIXME modifier char c = key->bind(Key::None).c_str()[0]; - if (c == '+' || c == '-') { + if (c == '+') { // action bind action_press(key->bind(Key::None)); @@ -464,7 +490,7 @@ void frame(float seconds) // FIXME modifier char c = key->bind(Key::None).c_str()[0]; - if (c && c != '+' && c != '-') { + if (c && c != '+') { // normal bind core::cmd() << key->bind(Key::None) << "\n"; } @@ -475,7 +501,7 @@ void frame(float seconds) if (core::application()->connected() && core::localcontrol() && !console()->visible() && !chat::visible()) { // FIXME modifier (note: mmmmm, modifier could be released by now) char c = key->bind(Key::None).c_str()[0]; - if (c == '+' || c == '-') { + if (c == '+') { // action bind action_release(key->bind(Key::None)); } @@ -586,8 +612,12 @@ void frame(float seconds) math::clamp(local_direction, -1.0f, 1.0f); math::clamp(local_pitch, -1.0f, 1.0f); - math::clamp(local_thrust, 0.0f, 1.0f); math::clamp(local_roll, -1.0f, 1.0f); + math::clamp(local_thrust, 0.0f, 1.0f); + if (local_thrust < 0.01f) + local_thrust = 0.0f; + else if (local_thrust > 0.99f) + local_thrust = 1.0f; core::localcontrol()->set_thrust(local_thrust); core::localcontrol()->set_direction(local_direction); -- cgit v1.2.3