Commit 099b2942 authored by Benjamin 'Albsi' Albsmeier's avatar Benjamin 'Albsi' Albsmeier
Browse files

input now prints mappings - axis don't work

parent 185dbdfd
...@@ -17,31 +17,25 @@ victim_mass : 1 ...@@ -17,31 +17,25 @@ victim_mass : 1
map_load_timer : 0 map_load_timer : 0
test_ui : false test_ui : false
mapGenDebug : false mapGenDebug : false
move_up_key1 : w
move_up_key2 : up
move_up_controller_axis : left_y_positiv
move_down_key1 : s
move_down_key2 : down
move_down_controller_axis : left_y_negativ
move_left_key1 : a move_left_key1 : a
move_left_key2 : left move_left_key2 : left
move_left_controller_axis : left_x_positiv move_left_controller_axis : leftx_positiv
move_right_key1 : d move_right_key1 : d
move_right_key2 : right move_right_key2 : right
move_right_controller_axis : left_x_negativ move_right_controller_axis : leftx_negativ
beam_normal_mouse_button : left beam_normal_mouse_button : left
beam_normal_controller_axis : trigger_left beam_normal_controller_axis : triggerleft
beam_inverse_mouse_button : right beam_inverse_mouse_button : right
beam_inverse_controller_axis : trigger_right beam_inverse_controller_axis : TRIGGERRIGHT
place_item_key1 : Space place_item_key1 : Space
place_item_mouse_button : Middle place_item_mouse_button : Middle
place_item_controller_button : A place_item_controller_button : A
test_key1 : t test_key1 : t
test_key2 : h test_key2 : p
test_mouse_button : middel test_mouse_button : middle
test_controller_button : back test_controller_button : back
test_controller_axis : right_y_positiv test_controller_axis : righty_positiv
exit_key1 : f12 state_switch_key1 : Escape
exit_controller_button : home
state_switch_key : Escape
state_switch_controller_button : START state_switch_controller_button : START
button_click_mouse_button : left
button_click_controller_button : a
...@@ -74,9 +74,36 @@ namespace gdw{ ...@@ -74,9 +74,36 @@ namespace gdw{
/**needs to be called at the end of every game loop*/ /**needs to be called at the end of every game loop*/
void reset(); void reset();
/***/ /**it sets the name for a mapping to add a key, button or axis
*
* use it in the settings.main or settings.user:
*
* https://wiki.libsdl.org/SDL_Keycode?highlight=%28%5CbCategoryEnum%5Cb%29%7C%28CategoryKeyboard%29
* use the 'Key Name'
* key1: <name>_key1 : <key>
* example: test_key1 : t
* key2: <name>_key2 : <key>
* example: test_key2 : t
*
* use 'left', 'middle', 'right', 'mouse4' or 'mouse5'
* mouse button: <name>_mouse_button : <button>
* example: test_mouse_button : left
*
* https://wiki.libsdl.org/SDL_GameControllerButton?highlight=%28%5CbCategoryGameController%5Cb%29%7C%28CategoryEnum%29
* without 'SDL_CONTROLLER_BUTTON_' use for the dpad 'up', 'down', 'left' or 'right'
* controller button: <name>_controller_button : <button>
* example: test_controller_button: start
*
* https://wiki.libsdl.org/SDL_GameControllerAxis?highlight=%28%5CbCategoryGameController%5Cb%29%7C%28CategoryEnum%29
* without 'SDL_CONTROLLER_AXIS_'
* controller axis: <name>_controller_axis : <axis> + '_positiv' or '_negativ' (ignored if trigger)
* example: test_controller_axis : leftx_positiv
*/
bool addMapping(std::string name); bool addMapping(std::string name);
/**prints the mapping*/
void printMapping();
/**Returns true every frame, as long as it is down - NOT FOR MULTI CONTROLLER*/ /**Returns true every frame, as long as it is down - NOT FOR MULTI CONTROLLER*/
bool isPressed(std::string id); bool isPressed(std::string id);
...@@ -158,6 +185,7 @@ namespace gdw{ ...@@ -158,6 +185,7 @@ namespace gdw{
float controllerAxis(SDL_GameControllerAxis axis, int nr = 0); float controllerAxis(SDL_GameControllerAxis axis, int nr = 0);
// //
std::string getMouseButtonName(int id);
SDL_Keycode getKeyCodeByMapping(std::string id, int nr); SDL_Keycode getKeyCodeByMapping(std::string id, int nr);
int getMButtonCodeByMapping(std::string id); int getMButtonCodeByMapping(std::string id);
SDL_GameControllerButton getCButtonCodeByMapping(std::string id); SDL_GameControllerButton getCButtonCodeByMapping(std::string id);
......
...@@ -28,7 +28,7 @@ namespace gdw { ...@@ -28,7 +28,7 @@ namespace gdw {
game_input_manager::game_input_manager(engine& engine):engine_(engine) { game_input_manager::game_input_manager(engine& engine):engine_(engine) {
auto& input = engine_.input(); auto& input = engine_.input();
//input.addMapping("test"); input.addMapping("test");
input.addMapping("move_left"); input.addMapping("move_left");
input.addMapping("move_right"); input.addMapping("move_right");
input.addMapping("place_item"); input.addMapping("place_item");
...@@ -85,9 +85,10 @@ namespace gdw { ...@@ -85,9 +85,10 @@ namespace gdw {
constexpr float rotation_speed = 7.f; constexpr float rotation_speed = 7.f;
constexpr float turn_rate_modifier = 4.5f; constexpr float turn_rate_modifier = 4.5f;
/*if (input.isPressed("test")){ if (input.isPressed("test")){
log << "input test pressed" << std::endl; //log << "input test pressed" << std::endl;
}*/ input.printMapping();
}
/*if (input.isDown("test")){ /*if (input.isDown("test")){
log << "pos: x:" << input.positionX() << " y:" << input.positionY() << std::endl; log << "pos: x:" << input.positionX() << " y:" << input.positionY() << std::endl;
......
...@@ -267,6 +267,31 @@ namespace gdw{ ...@@ -267,6 +267,31 @@ namespace gdw{
return ok; return ok;
} }
void input::printMapping(){
log << "input: print mappings:" << std::endl;
for(auto it:mappings_){
log << "input: name: " << it.first << std::endl;
if(it.second.keyCode1 != 0)log << "input: key1: " << SDL_GetKeyName(it.second.keyCode1) << std::endl;
if(it.second.keyCode2 != 0)log << "input: key2: " << SDL_GetKeyName(it.second.keyCode2) << std::endl;
if(it.second.mbuttonCode != -1)log << "input: mouse button: " << getMouseButtonName(it.second.mbuttonCode) << std::endl;
if(it.second.cbuttonCode != -1)log << "input: controller button: " << SDL_GameControllerGetStringForButton(it.second.cbuttonCode) << std::endl;
if(it.second.caxisCode != -1)log << "input: controller axis: " << SDL_GameControllerGetStringForAxis(it.second.caxisCode) << std::endl;
if(it.second.negativAxis)log << "input: negativ axis" << std::endl;
}
}
std::string input::getMouseButtonName(int id){
switch(id){
case SDL_BUTTON_LEFT: return "left";
case SDL_BUTTON_RIGHT: return "right";
case SDL_BUTTON_MIDDLE: return "middle";
case SDL_BUTTON_X1: return "mouse4";
case SDL_BUTTON_X2: return "mouse5";
}
return "none";
}
int input::getKeyCodeByMapping(std::string id, int nr){ int input::getKeyCodeByMapping(std::string id, int nr){
auto it = mappings_.find(id); auto it = mappings_.find(id);
if(it == mappings_.end())return 0; if(it == mappings_.end())return 0;
...@@ -330,7 +355,8 @@ namespace gdw{ ...@@ -330,7 +355,8 @@ namespace gdw{
} }
SDL_GameControllerAxis input::getCAxisFromName(std::string name){ SDL_GameControllerAxis input::getCAxisFromName(std::string name){
return SDL_GameControllerGetAxisFromString(name.c_str()); //return SDL_GameControllerGetAxisFromString(name.c_str());
return SDL_CONTROLLER_AXIS_INVALID;
} }
controllerCursor input::getCCursorFromName(std::string name){ controllerCursor input::getCCursorFromName(std::string name){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment