change keybindings with keymapper : DONE
This commit is contained in:
parent
40e21b291e
commit
d7cd7f09ba
@ -7,7 +7,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
KeyMapper::KeyMapper() :
|
KeyMapper::KeyMapper() :
|
||||||
m_enabled(false)
|
m_enabled(false),
|
||||||
|
m_waiting_for_input(-1)
|
||||||
{
|
{
|
||||||
// mapping between action numerical value and text value
|
// mapping between action numerical value and text value
|
||||||
m_actions_list[DefaultKeysMap::MAIN_ACTION] = "Main Action";
|
m_actions_list[DefaultKeysMap::MAIN_ACTION] = "Main Action";
|
||||||
@ -36,7 +37,7 @@ KeyMapper::KeyMapper() :
|
|||||||
// mapping between mouse numerical value and text value
|
// mapping between mouse numerical value and text value
|
||||||
m_mouse_buttons[sf::Mouse::Left] = "Mouse Left";
|
m_mouse_buttons[sf::Mouse::Left] = "Mouse Left";
|
||||||
m_mouse_buttons[sf::Mouse::Middle] = "Mouse Middle";
|
m_mouse_buttons[sf::Mouse::Middle] = "Mouse Middle";
|
||||||
m_mouse_buttons[sf::Mouse::Right] = "Mouse Left";
|
m_mouse_buttons[sf::Mouse::Right] = "Mouse Right";
|
||||||
m_mouse_buttons[sf::Mouse::XButton1] = "Mouse Extra 1";
|
m_mouse_buttons[sf::Mouse::XButton1] = "Mouse Extra 1";
|
||||||
m_mouse_buttons[sf::Mouse::XButton2] = "Mouse Extra 2";
|
m_mouse_buttons[sf::Mouse::XButton2] = "Mouse Extra 2";
|
||||||
|
|
||||||
@ -108,10 +109,10 @@ void KeyMapper::gui()
|
|||||||
std::vector<std::string> types_binding = {"pressed","released","hold"};
|
std::vector<std::string> types_binding = {"pressed","released","hold"};
|
||||||
|
|
||||||
ImGui::Begin("KeyMapper");
|
ImGui::Begin("KeyMapper");
|
||||||
ImGui::Combo("Context",&m_selected_context,contexts);
|
std::vector<Binding>& keys = m_keysmap.data();
|
||||||
for(unsigned int i = 0;i<m_keysmap.data().size();i++)
|
for(unsigned int i = 0;i<m_keysmap.data().size();i++)
|
||||||
{
|
{
|
||||||
Binding& b = m_keysmap.data()[i];
|
Binding& b = keys[i];
|
||||||
std::string action_label;
|
std::string action_label;
|
||||||
if(m_actions_list.count(b.action.action))
|
if(m_actions_list.count(b.action.action))
|
||||||
action_label = m_actions_list[b.action.action];
|
action_label = m_actions_list[b.action.action];
|
||||||
@ -128,12 +129,67 @@ void KeyMapper::gui()
|
|||||||
|
|
||||||
ImGui::Text("%s",action_label.data());
|
ImGui::Text("%s",action_label.data());
|
||||||
ImGui::SameLine(200);
|
ImGui::SameLine(200);
|
||||||
ImGui::Text("%s", key_label.data());
|
ImGui::PushID(action_label.data());
|
||||||
ImGui::SameLine(300);
|
if(m_waiting_for_input == i)
|
||||||
|
ImGui::Button("...",ImVec2(100,30));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(ImGui::Button(key_label.data(),ImVec2(100,30)))
|
||||||
|
m_waiting_for_input = i;
|
||||||
|
}
|
||||||
|
ImGui::SameLine(400);
|
||||||
ImGui::PushItemWidth(100);
|
ImGui::PushItemWidth(100);
|
||||||
ImGui::Combo("",&b.type,types_binding);
|
if(ImGui::BeginCombo("Type :",types_binding[b.type].data()))
|
||||||
|
{
|
||||||
|
for(unsigned int j = 0;j < types_binding.size();j++)
|
||||||
|
{
|
||||||
|
bool is_selected = (b.type == j);
|
||||||
|
if(ImGui::Selectable(types_binding[j].data(),is_selected))
|
||||||
|
b.type = j;
|
||||||
|
if(is_selected)
|
||||||
|
ImGui::SetItemDefaultFocus();
|
||||||
|
}
|
||||||
|
ImGui::EndCombo();
|
||||||
|
}
|
||||||
|
ImGui::PopID();
|
||||||
ImGui::PopItemWidth();
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::Separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*if(ImGui::Button("Test 1"))
|
||||||
|
std::cout << "Test 1" << std::endl;
|
||||||
|
|
||||||
|
if(ImGui::Button("Test 1"))
|
||||||
|
std::cout << "Test 2" << std::endl;*/
|
||||||
|
|
||||||
|
if(m_waiting_for_input != -1)
|
||||||
|
{
|
||||||
|
ImGuiIO io = ImGui::GetIO();
|
||||||
|
for(int i = sf::Keyboard::A ; i < sf::Keyboard::KeyCount;i++)
|
||||||
|
{
|
||||||
|
if(io.KeysDown[i])
|
||||||
|
{
|
||||||
|
keys[m_waiting_for_input].key = i;
|
||||||
|
keys[m_waiting_for_input].action.source = input::KEYBOARD;
|
||||||
|
m_waiting_for_input = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int j = sf::Mouse::Left; j < sf::Mouse::ButtonCount;j++)
|
||||||
|
{
|
||||||
|
if(io.MouseDown[j])
|
||||||
|
{
|
||||||
|
keys[m_waiting_for_input].key = j;
|
||||||
|
keys[m_waiting_for_input].action.source = input::MOUSE;
|
||||||
|
m_waiting_for_input = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//apply
|
||||||
|
if(ImGui::Button("Apply changes"))
|
||||||
|
getEngine().getInput()->setKeysMap(m_keysmap);
|
||||||
|
//save
|
||||||
|
|
||||||
|
//load
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "scene/containernode.h"
|
#include "scene/containernode.h"
|
||||||
#include "SparrowInput/keybindings.h"
|
#include "SparrowInput/keybindings.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
class KeyMapper : public ContainerNode
|
class KeyMapper : public ContainerNode
|
||||||
{
|
{
|
||||||
@ -14,6 +15,7 @@ class KeyMapper : public ContainerNode
|
|||||||
std::map<int,std::string> m_mouse_buttons;
|
std::map<int,std::string> m_mouse_buttons;
|
||||||
std::map<int,std::string> m_keyboard_keys;
|
std::map<int,std::string> m_keyboard_keys;
|
||||||
std::map<int,std::string> m_actions_list;
|
std::map<int,std::string> m_actions_list;
|
||||||
|
int m_waiting_for_input;
|
||||||
|
|
||||||
void gui();
|
void gui();
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user