started to add a gui window for key mapping

This commit is contained in:
Lendemor 2018-01-05 19:42:10 +01:00
parent 78073bac45
commit 80543e3f82
6 changed files with 80 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include "imgui/imgui.h"
#include "tools/loader.h"
#include "editor.h"
#include "keymapper.h"
#include "tools/loadingthread.h"
Engine::Engine() :
@ -67,6 +68,7 @@ void Engine::createWindow(std::string title,
m_renderer->initGL(w, h);
m_sparrowshell = new SparrowShell(m_window);
m_editor = new Editor();
m_keymapper = new KeyMapper();
m_loadingThread = LoadingThread::init();
}
@ -180,12 +182,14 @@ void Engine::setScene(std::string scene)
previous_scene->getRootObject()->removeChild(m_sparrowshell);
previous_scene->getRootObject()->removeChild(m_editor);
previous_scene->getRootObject()->removeChild(m_keymapper);
m_renderer->setScene(new_scene);
m_renderer->resizeGL(m_window->getSize().x, m_window->getSize().y);
new_scene->getRootObject()->addChild(m_sparrowshell);
new_scene->getRootObject()->addChild(m_editor);
new_scene->getRootObject()->addChild(m_keymapper);
}
void Engine::enablePhysicsDebug()

View File

@ -9,6 +9,7 @@ class SceneTree;
class SparrowShell;
class PhysicsDebugNode;
class Editor;
class KeyMapper;
class LoadingThread;
namespace sf
@ -54,6 +55,7 @@ public:
SparrowShell* getShell() const {return m_sparrowshell;}
PhysicsDebugNode* getPhysicsDebug() const {return m_physicsDebugNode;}
Editor* getEditor() const {return m_editor;}
KeyMapper* getKeyMapper() const{return m_keymapper;}
LoadingThread* getLoadingThread() const {return m_loadingThread;}
SceneTree* getScene() const;
@ -81,6 +83,7 @@ private:
PhysicsDebugNode *m_physicsDebugNode;
SparrowRenderer* m_renderer;
Editor* m_editor;
KeyMapper* m_keymapper;
LoadingThread* m_loadingThread;
void update();

46
src/keymapper.cpp Normal file
View File

@ -0,0 +1,46 @@
#include "keymapper.h"
#include <imgui/imgui.h>
#include "engine.h"
#include "SparrowInput/input.h"
#include <iostream>
KeyMapper::KeyMapper() :
m_enabled(false)
{
}
void KeyMapper::update()
{
if(m_enabled)
gui();
}
void KeyMapper::gui()
{
std::vector<std::string> contexts = getEngine().getInput()->getContextsList();
std::vector<std::string> types_binding = {"pressed","released","hold"};
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);
ImGui::PushItemWidth(100);
ImGui::Combo("",&(b.type),types_binding);
ImGui::PopItemWidth();
}
ImGui::End();
}
void KeyMapper::toggle()
{
m_enabled = !m_enabled;
if(m_enabled){
m_keysmap = getEngine().getInput()->getKeysMap();
}
}

20
src/keymapper.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef KEYMAPPER_H
#define KEYMAPPER_H
#include "scene/containernode.h"
#include "SparrowInput/keybindings.h"
class KeyMapper : public ContainerNode
{
bool m_enabled;
int m_selected_context;
IKeysMap m_keysmap;
void gui();
public:
KeyMapper();
void update();
void toggle();
};
#endif // KEYMAPPER_H

View File

@ -10,6 +10,7 @@
#include "SparrowSerializer/Version.h"
#include "tools/utils.h"
#include "editor.h"
#include "keymapper.h"
#define LUA_DEFINE(var) S[#var]=var
#define LUA_SET_FUN(var) m_script.set_function(#var,&ScriptNode::var,this);this->functions_name.push_back(#var);
@ -29,6 +30,7 @@ ScriptNode::ScriptNode()
LUA_SET_FUN(rendering);
LUA_SET_FUN(resourcePackEditor);
LUA_SET_FUN(editor);
LUA_SET_FUN(keymapper);
m_script.new_usertype<Engine>("Engine",
"time",&Engine::getTime
@ -118,3 +120,7 @@ void ScriptNode::resourcePackEditor(){
void ScriptNode::editor(){
this->getEngine().getEditor()->toggleEditor();
}
void ScriptNode::keymapper(){
this->getEngine().getKeyMapper()->toggle();
}

View File

@ -28,6 +28,7 @@ public:
void rendering();
void resourcePackEditor();
void editor();
void keymapper();
};
#endif // SCRIPTNODE_H