added mapping between numerical value and text value for keymapping
This commit is contained in:
parent
80543e3f82
commit
40e21b291e
@ -3,11 +3,97 @@
|
||||
#include <imgui/imgui.h>
|
||||
#include "engine.h"
|
||||
#include "SparrowInput/input.h"
|
||||
#include "defaultkeysmap.h"
|
||||
#include <iostream>
|
||||
|
||||
KeyMapper::KeyMapper() :
|
||||
m_enabled(false)
|
||||
{
|
||||
// mapping between action numerical value and text value
|
||||
m_actions_list[DefaultKeysMap::MAIN_ACTION] = "Main Action";
|
||||
m_actions_list[DefaultKeysMap::SECONDARY_ACTION] = "Secondary Action";
|
||||
m_actions_list[DefaultKeysMap::TERTIARY_ACTION] = "Tertiary Action";
|
||||
m_actions_list[DefaultKeysMap::MOVE_FORWARD] = "Move Forward";
|
||||
m_actions_list[DefaultKeysMap::MOVE_BACKWARD] = "Move Backward";
|
||||
m_actions_list[DefaultKeysMap::STRAFE_LEFT] = "Strafe Left";
|
||||
m_actions_list[DefaultKeysMap::STRAFE_RIGHT] = "Strafe Right";
|
||||
m_actions_list[DefaultKeysMap::RUN] = "Run";
|
||||
m_actions_list[DefaultKeysMap::MAIN_ACTION_HOLD] = "Main Action Hold";
|
||||
m_actions_list[DefaultKeysMap::SECONDARY_ACTION_HOLD] = "Secondary Action Hold";
|
||||
m_actions_list[DefaultKeysMap::JUMP] = "Jump";
|
||||
m_actions_list[DefaultKeysMap::TOGGLE_NOCLIP] = "Toggle NoClip";
|
||||
m_actions_list[DefaultKeysMap::TOGGLE_PHYSICS_DEBUG] = "Toggle Physics Debug";
|
||||
m_actions_list[DefaultKeysMap::TOGGLE_CONSOLE] = "Toggle Console";
|
||||
m_actions_list[DefaultKeysMap::MOVE_CURSOR_LEFT] = "Move Cursor Left";
|
||||
m_actions_list[DefaultKeysMap::MOVE_CURSOR_RIGHT] = "Move Cursor Right";
|
||||
m_actions_list[DefaultKeysMap::HISTORY_UP] = "History Up";
|
||||
m_actions_list[DefaultKeysMap::HISTORY_DOWN] = "History Down";
|
||||
m_actions_list[DefaultKeysMap::TOGGLE_MOUSE_CURSOR] = "Toggle Mouse Cursor";
|
||||
m_actions_list[DefaultKeysMap::EXIT_GAME] = "Exit Game";
|
||||
m_actions_list[DefaultKeysMap::LEFT_CLICK] = "Left Click";
|
||||
|
||||
|
||||
// mapping between mouse numerical value and text value
|
||||
m_mouse_buttons[sf::Mouse::Left] = "Mouse Left";
|
||||
m_mouse_buttons[sf::Mouse::Middle] = "Mouse Middle";
|
||||
m_mouse_buttons[sf::Mouse::Right] = "Mouse Left";
|
||||
m_mouse_buttons[sf::Mouse::XButton1] = "Mouse Extra 1";
|
||||
m_mouse_buttons[sf::Mouse::XButton2] = "Mouse Extra 2";
|
||||
|
||||
// mapping between keyboard numerical value and text value
|
||||
m_keyboard_keys[sf::Keyboard::A] = "A";
|
||||
m_keyboard_keys[sf::Keyboard::Z] = "Z";
|
||||
m_keyboard_keys[sf::Keyboard::E] = "E";
|
||||
m_keyboard_keys[sf::Keyboard::R] = "R";
|
||||
m_keyboard_keys[sf::Keyboard::T] = "T";
|
||||
m_keyboard_keys[sf::Keyboard::Y] = "Y";
|
||||
m_keyboard_keys[sf::Keyboard::U] = "U";
|
||||
m_keyboard_keys[sf::Keyboard::I] = "I";
|
||||
m_keyboard_keys[sf::Keyboard::O] = "O";
|
||||
m_keyboard_keys[sf::Keyboard::P] = "P";
|
||||
|
||||
m_keyboard_keys[sf::Keyboard::Q] = "Q";
|
||||
m_keyboard_keys[sf::Keyboard::S] = "S";
|
||||
m_keyboard_keys[sf::Keyboard::D] = "D";
|
||||
m_keyboard_keys[sf::Keyboard::F] = "F";
|
||||
m_keyboard_keys[sf::Keyboard::G] = "G";
|
||||
m_keyboard_keys[sf::Keyboard::H] = "H";
|
||||
m_keyboard_keys[sf::Keyboard::J] = "J";
|
||||
m_keyboard_keys[sf::Keyboard::K] = "K";
|
||||
m_keyboard_keys[sf::Keyboard::L] = "L";
|
||||
m_keyboard_keys[sf::Keyboard::M] = "M";
|
||||
|
||||
m_keyboard_keys[sf::Keyboard::W] = "W";
|
||||
m_keyboard_keys[sf::Keyboard::X] = "X";
|
||||
m_keyboard_keys[sf::Keyboard::C] = "C";
|
||||
m_keyboard_keys[sf::Keyboard::V] = "V";
|
||||
m_keyboard_keys[sf::Keyboard::B] = "B";
|
||||
m_keyboard_keys[sf::Keyboard::N] = "N";
|
||||
|
||||
m_keyboard_keys[sf::Keyboard::F1] = "F1";
|
||||
m_keyboard_keys[sf::Keyboard::F2] = "F2";
|
||||
m_keyboard_keys[sf::Keyboard::F3] = "F3";
|
||||
m_keyboard_keys[sf::Keyboard::F4] = "F4";
|
||||
m_keyboard_keys[sf::Keyboard::F5] = "F5";
|
||||
m_keyboard_keys[sf::Keyboard::F6] = "F6";
|
||||
m_keyboard_keys[sf::Keyboard::F7] = "F7";
|
||||
m_keyboard_keys[sf::Keyboard::F8] = "F8";
|
||||
m_keyboard_keys[sf::Keyboard::F9] = "F9";
|
||||
m_keyboard_keys[sf::Keyboard::F10] = "F10";
|
||||
m_keyboard_keys[sf::Keyboard::F11] = "F11";
|
||||
m_keyboard_keys[sf::Keyboard::F12] = "F12";
|
||||
|
||||
m_keyboard_keys[sf::Keyboard::Left] = "Arrow Left";
|
||||
m_keyboard_keys[sf::Keyboard::Right] = "Arrow Right";
|
||||
m_keyboard_keys[sf::Keyboard::Up] = "Arrow Up";
|
||||
m_keyboard_keys[sf::Keyboard::Down] = "Arrow Down";
|
||||
|
||||
|
||||
m_keyboard_keys[sf::Keyboard::Escape]= "Escape";
|
||||
m_keyboard_keys[sf::Keyboard::Space] = "Space";
|
||||
m_keyboard_keys[sf::Keyboard::LShift]= "Left Shift";
|
||||
m_keyboard_keys[sf::Keyboard::LControl] = "Left Control";
|
||||
|
||||
}
|
||||
|
||||
void KeyMapper::update()
|
||||
@ -23,13 +109,29 @@ void KeyMapper::gui()
|
||||
|
||||
ImGui::Begin("KeyMapper");
|
||||
ImGui::Combo("Context",&m_selected_context,contexts);
|
||||
for (Binding b : m_keysmap.data()){
|
||||
ImGui::Text("%d",b.action);
|
||||
ImGui::SameLine(50);
|
||||
ImGui::Text("%d",b.key);
|
||||
ImGui::SameLine(100);
|
||||
for(unsigned int i = 0;i<m_keysmap.data().size();i++)
|
||||
{
|
||||
Binding& b = m_keysmap.data()[i];
|
||||
std::string action_label;
|
||||
if(m_actions_list.count(b.action.action))
|
||||
action_label = m_actions_list[b.action.action];
|
||||
else
|
||||
action_label = "Unknown Action";
|
||||
|
||||
std::string key_label;
|
||||
if (b.action.source == input::MOUSE && m_mouse_buttons.count(b.key))
|
||||
key_label = m_mouse_buttons[b.key];
|
||||
else if(b.action.source == input::KEYBOARD && m_keyboard_keys.count(b.key))
|
||||
key_label = m_keyboard_keys[b.key];
|
||||
else
|
||||
key_label = "UNDEFINED";
|
||||
|
||||
ImGui::Text("%s",action_label.data());
|
||||
ImGui::SameLine(200);
|
||||
ImGui::Text("%s", key_label.data());
|
||||
ImGui::SameLine(300);
|
||||
ImGui::PushItemWidth(100);
|
||||
ImGui::Combo("",&(b.type),types_binding);
|
||||
ImGui::Combo("",&b.type,types_binding);
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
ImGui::End();
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "scene/containernode.h"
|
||||
#include "SparrowInput/keybindings.h"
|
||||
#include <map>
|
||||
|
||||
class KeyMapper : public ContainerNode
|
||||
{
|
||||
@ -10,6 +11,10 @@ class KeyMapper : public ContainerNode
|
||||
int m_selected_context;
|
||||
IKeysMap m_keysmap;
|
||||
|
||||
std::map<int,std::string> m_mouse_buttons;
|
||||
std::map<int,std::string> m_keyboard_keys;
|
||||
std::map<int,std::string> m_actions_list;
|
||||
|
||||
void gui();
|
||||
public:
|
||||
KeyMapper();
|
||||
|
Loading…
x
Reference in New Issue
Block a user