Skip to content

Commit

Permalink
Merge pull request #110 from Exairnous/keybindings-gui
Browse files Browse the repository at this point in the history
Keybindings gui
  • Loading branch information
wheybags committed Jul 11, 2015
2 parents cb76993 + 8bd8534 commit d82e3be
Show file tree
Hide file tree
Showing 15 changed files with 956 additions and 31 deletions.
83 changes: 83 additions & 0 deletions apps/freeablo/fagui/guimanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,26 @@

#include <iostream>
#include <boost/python.hpp>
#include <input/common.h>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>

#include "input/hotkey.h"

extern bool done; // TODO: handle this better
extern bool paused; // TODO: handle this better
extern int changeLevel; // TODO: handle this better

extern Input::Hotkey quit_key; // TODO: handle this better
extern Input::Hotkey noclip_key; // TODO: handle this better
extern Input::Hotkey changelvldwn_key; // TODO: handle this better
extern Input::Hotkey changelvlup_key; // TODO: handle this better

namespace bpt = boost::property_tree;

extern bpt::ptree hotkeypt;

namespace FAGui
{
void quitGame()
Expand Down Expand Up @@ -44,6 +59,70 @@ namespace FAGui
{
Engine::ThreadManager::get()->playSound(path);
}

boost::python::list getHotkeyNames()
{
boost::python::list hotkeynames;

hotkeynames.append(Input::getHotkeyName(quit_key));
hotkeynames.append(Input::getHotkeyName(noclip_key));
hotkeynames.append(Input::getHotkeyName(changelvlup_key));
hotkeynames.append(Input::getHotkeyName(changelvldwn_key));
return hotkeynames;
}

boost::python::list getHotkeys()
{
boost::python::list hotkeys;
Input::Hotkey pquit_key = quit_key;
Input::Hotkey pnoclip_key = noclip_key;
Input::Hotkey pchangelvlup_key = changelvlup_key;
Input::Hotkey pchangelvldwn_key = changelvldwn_key;

pquit_key.key = Input::convertAsciiToRocketKey(quit_key.key);
pnoclip_key.key = Input::convertAsciiToRocketKey(noclip_key.key);
pchangelvlup_key.key = Input::convertAsciiToRocketKey(changelvlup_key.key);
pchangelvldwn_key.key = Input::convertAsciiToRocketKey(changelvldwn_key.key);

hotkeys.append(pquit_key);
hotkeys.append(pnoclip_key);
hotkeys.append(pchangelvlup_key);
hotkeys.append(pchangelvldwn_key);

return hotkeys;
}

void setHotkey(std::string function, boost::python::list pyhotkey)
{
Input::Hotkey hotkey;
hotkey.key = Input::convertRocketKeyToAscii(boost::python::extract<int>(pyhotkey[0]));
hotkey.shift = boost::python::extract<bool>(pyhotkey[1]);
hotkey.ctrl = boost::python::extract<bool>(pyhotkey[2]);
hotkey.alt = boost::python::extract<bool>(pyhotkey[3]);

bpt::write_ini("resources/hotkeys.ini", hotkeypt);

if (function == "quit")
{
quit_key = hotkey;
quit_key.save("Quit", hotkeypt);
}
if (function == "noclip")
{
noclip_key = hotkey;
noclip_key.save("Noclip", hotkeypt);
}
if (function == "changelvlup")
{
changelvlup_key = hotkey;
changelvlup_key.save("Changelvlup", hotkeypt);
}
if (function == "changelvldwn")
{
changelvldwn_key = hotkey;
changelvldwn_key.save("Changelvldwn", hotkeypt);
}
}

BOOST_PYTHON_MODULE(freeablo)
{
Expand All @@ -52,13 +131,17 @@ namespace FAGui
boost::python::def("unpause", &unpauseGame);
boost::python::def("startGame", &startGame);
boost::python::def("playSound", &playSound);
boost::python::def("getHotkeyNames", &getHotkeyNames);
boost::python::def("getHotkeys", &getHotkeys);
boost::python::def("setHotkey", &setHotkey);
}

Rocket::Core::ElementDocument* ingameUi = NULL;
Rocket::Core::ElementDocument* mainMenu = NULL;
void initGui()
{
initfreeablo();
Input::Hotkey::initpythonwrapper();

FARender::Renderer* renderer = FARender::Renderer::get();

Expand Down
80 changes: 63 additions & 17 deletions apps/freeablo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <misc/fareadini.h>
#include <boost/property_tree/ptree.hpp>

#include <input/hotkey.h>

namespace bpo = boost::program_options;
namespace bfs = boost::filesystem;
namespace bpt = boost::property_tree;
Expand All @@ -34,28 +36,73 @@ bool paused = false;
bool noclip = false;
int changeLevel = 0;

int quit_key;
int noclip_key;
int changelvldwn_key;
int changelvlup_key;
Input::Hotkey quit_key;
Input::Hotkey noclip_key;
Input::Hotkey changelvldwn_key;
Input::Hotkey changelvlup_key;

bpt::ptree hotkeypt;

void keyPress(Input::Key key)
{
if (key == quit_key)
switch(key)
{
case Input::KEY_RSHIFT:;
case Input::KEY_LSHIFT:;
case Input::KEY_RCTRL:;
case Input::KEY_LCTRL:;
case Input::KEY_RALT:;
case Input::KEY_LALT:;
case Input::KEY_RSUPER:;
case Input::KEY_LSUPER:;
case Input::KEY_NUMLOCK:;
case Input::KEY_SCROLLOCK: return;
default:
{
break;
}
}

Input::Hotkey hotkey;
hotkey.key = key;
Input::InputManager& input = *Input::InputManager::get();

uint32_t modifiers = input.getModifiers();

switch(modifiers)
{
case 0: break;
case 1: hotkey.ctrl = true; break;
case 2: hotkey.alt = true; break;
case 3: hotkey.ctrl = true; hotkey.alt = true; break;
case 4: hotkey.shift = true; break;
case 5: hotkey.ctrl = true; hotkey.shift = true; break;
case 6: hotkey.alt = true; hotkey.shift = true; break;
case 7: hotkey.ctrl = true; hotkey.alt = true; hotkey.shift = true; break;
}

if (hotkey == quit_key)
{
done = true;
return;
}
else if (key == noclip_key)

if (hotkey == noclip_key)
{
noclip = !noclip;
return;
}
else if (key == changelvldwn_key)

if (hotkey == changelvlup_key)
{
changeLevel = 1;
changeLevel = -1;
return;
}
else if (key == changelvlup_key)

if (hotkey == changelvldwn_key)
{
changeLevel = -1;
changeLevel = 1;
return;
}
}

Expand Down Expand Up @@ -371,14 +418,13 @@ void runGameLoop(const bpo::variables_map& variables)

std::pair<size_t, size_t> destination = player->mPos.current();

bpt::ptree hotkeypt;
//bpt::ptree hotkeypt;
Misc::readIni("resources/hotkeys.ini", hotkeypt);

quit_key = hotkeypt.get<int>("Hotkeys.quit");
noclip_key = hotkeypt.get<int>("Hotkeys.noclip");
changelvldwn_key = hotkeypt.get<int>("Hotkeys.changelvldwn");
changelvlup_key = hotkeypt.get<int>("Hotkeys.changelvlup");


quit_key = Input::Hotkey("Quit", hotkeypt);
noclip_key = Input::Hotkey("Noclip", hotkeypt);
changelvlup_key = Input::Hotkey("Changelvlup", hotkeypt);
changelvldwn_key = Input::Hotkey("Changelvldwn", hotkeypt);

// Main game logic loop
while(!done)
Expand Down
5 changes: 5 additions & 0 deletions components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ target_link_libraries(Render Cel Levels ${SDL2_LIBRARY} ${SDL2IMAGE_LIBRARY} ${O
set_target_properties(Render PROPERTIES COMPILE_FLAGS "${FA_COMPILER_FLAGS}")

add_library(Input
input/common.cpp
input/common.h
input/hotkey.cpp
input/hotkey.h
input/inputmanager.h
input/keys.h
input/sdl2backend.cpp)
set_target_properties(Input PROPERTIES COMPILE_FLAGS "${FA_COMPILER_FLAGS}")

Expand Down
Loading

0 comments on commit d82e3be

Please sign in to comment.