diff --git a/apps/freeablo/fagui/guimanager.cpp b/apps/freeablo/fagui/guimanager.cpp index 21f89b42b..876bdb82a 100644 --- a/apps/freeablo/fagui/guimanager.cpp +++ b/apps/freeablo/fagui/guimanager.cpp @@ -11,11 +11,26 @@ #include #include +#include + +#include +#include + +#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() @@ -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(pyhotkey[0])); + hotkey.shift = boost::python::extract(pyhotkey[1]); + hotkey.ctrl = boost::python::extract(pyhotkey[2]); + hotkey.alt = boost::python::extract(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) { @@ -52,6 +131,9 @@ 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; @@ -59,6 +141,7 @@ namespace FAGui void initGui() { initfreeablo(); + Input::Hotkey::initpythonwrapper(); FARender::Renderer* renderer = FARender::Renderer::get(); diff --git a/apps/freeablo/main.cpp b/apps/freeablo/main.cpp index c501fff5e..f6bf58ee2 100644 --- a/apps/freeablo/main.cpp +++ b/apps/freeablo/main.cpp @@ -25,6 +25,8 @@ #include #include +#include + namespace bpo = boost::program_options; namespace bfs = boost::filesystem; namespace bpt = boost::property_tree; @@ -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; } } @@ -371,14 +418,13 @@ void runGameLoop(const bpo::variables_map& variables) std::pair destination = player->mPos.current(); - bpt::ptree hotkeypt; + //bpt::ptree hotkeypt; Misc::readIni("resources/hotkeys.ini", hotkeypt); - - quit_key = hotkeypt.get("Hotkeys.quit"); - noclip_key = hotkeypt.get("Hotkeys.noclip"); - changelvldwn_key = hotkeypt.get("Hotkeys.changelvldwn"); - changelvlup_key = hotkeypt.get("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) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index d41e26980..7b60ebea7 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -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}") diff --git a/components/input/common.cpp b/components/input/common.cpp new file mode 100644 index 000000000..b642805c0 --- /dev/null +++ b/components/input/common.cpp @@ -0,0 +1,343 @@ +#include +#include +#include +#include "common.h" + +namespace Input +{ + Key convertRocketKeyToAscii(int rocketk) + { + Key key; + + switch(rocketk) + { + RTACASE2(BACK, BACKSPACE); + RTACASE(TAB); + RTACASE(CLEAR); + RTACASE(RETURN); + RTACASE(PAUSE); + RTACASE(ESCAPE); + RTACASE(SPACE); + RTACASE2(OEM_7, QUOTEDBL); + RTACASE2(OEM_PLUS, PLUS); + RTACASE2(OEM_COMMA, COMMA); + RTACASE2(OEM_MINUS, MINUS); + RTACASE2(OEM_PERIOD, PERIOD); + RTACASE2(OEM_2, SLASH); + RTACASE(0); + RTACASE(1); + RTACASE(2); + RTACASE(3); + RTACASE(4); + RTACASE(5); + RTACASE(6); + RTACASE(7); + RTACASE(8); + RTACASE(9); + RTACASE2(OEM_1, SEMICOLON); + RTACASE2(OEM_NEC_EQUAL, EQUALS); + + RTACASE2(OEM_4, LEFTBRACKET); + RTACASE2(OEM_5, BACKSLASH); + RTACASE2(OEM_6, RIGHTBRACKET); + RTACASE2(OEM_3, BACKQUOTE); + RTACASE2(A, a); + RTACASE2(B, b); + RTACASE2(C, c); + RTACASE2(D, d); + RTACASE2(E, e); + RTACASE2(F, f); + RTACASE2(G, g); + RTACASE2(H, h); + RTACASE2(I, i); + RTACASE2(J, j); + RTACASE2(K, k); + RTACASE2(L, l); + RTACASE2(M, m); + RTACASE2(N, n); + RTACASE2(O, o); + RTACASE2(P, p); + RTACASE2(Q, q); + RTACASE2(R, r); + RTACASE2(S, s); + RTACASE2(T, t); + RTACASE2(U, u); + RTACASE2(V, v); + RTACASE2(W, w); + RTACASE2(X, x); + RTACASE2(Y, y); + RTACASE2(Z, z); + RTACASE(DELETE); + + RTACASE2(DECIMAL, KP_PERIOD); + RTACASE2(DIVIDE, KP_DIVIDE); + RTACASE2(MULTIPLY, KP_MULTIPLY); + RTACASE2(SUBTRACT, KP_MINUS); + RTACASE2(ADD, KP_PLUS); + RTACASE2(NUMPADENTER, KP_ENTER); + + RTACASE(UP); + RTACASE(DOWN); + RTACASE(RIGHT); + RTACASE(LEFT); + RTACASE(INSERT); + RTACASE(HOME); + RTACASE(END); + RTACASE2(PRIOR, PAGEUP); + RTACASE2(NEXT, PAGEDOWN); + + RTACASE(F1); + RTACASE(F2); + RTACASE(F3); + RTACASE(F4); + RTACASE(F5); + RTACASE(F6); + RTACASE(F7); + RTACASE(F8); + RTACASE(F9); + RTACASE(F10); + RTACASE(F11); + RTACASE(F12); + RTACASE(F13); + RTACASE(F14); + RTACASE(F15); + + RTACASE2(CAPITAL, CAPSLOCK); + RTACASE(RSHIFT); + RTACASE(LSHIFT); + RTACASE2(RCONTROL, RCTRL); + RTACASE2(LCONTROL, LCTRL); + RTACASE2(RMENU, RALT); + RTACASE2(LMENU, LALT); + + RTACASE2(NUMPAD0, KP0); + RTACASE2(NUMPAD1, KP1); + RTACASE2(NUMPAD2, KP2); + RTACASE2(NUMPAD3, KP3); + RTACASE2(NUMPAD4, KP4); + RTACASE2(NUMPAD5, KP5); + RTACASE2(NUMPAD6, KP6); + RTACASE2(NUMPAD7, KP7); + RTACASE2(NUMPAD8, KP8); + RTACASE2(NUMPAD9, KP9); + + RTACASE(NUMLOCK); + RTACASE2(SCROLL, SCROLLOCK); + + default: + { + key = KEY_UNDEF; + break; + } + } + + return key; + + } + + int convertAsciiToRocketKey(int asciik) + { + int key; + + switch(asciik) + { + ATRCASE2(BACKSPACE, BACK); + ATRCASE(TAB); + ATRCASE(CLEAR); + ATRCASE(RETURN); + ATRCASE(PAUSE); + ATRCASE(ESCAPE); + ATRCASE(SPACE); + ATRCASE2(QUOTEDBL, OEM_7); + ATRCASE2(PLUS, OEM_PLUS); + ATRCASE2(COMMA, OEM_COMMA); + ATRCASE2(MINUS, OEM_MINUS); + ATRCASE2(PERIOD, OEM_PERIOD); + ATRCASE2(SLASH, OEM_2); + ATRCASE(0); + ATRCASE(1); + ATRCASE(2); + ATRCASE(3); + ATRCASE(4); + ATRCASE(5); + ATRCASE(6); + ATRCASE(7); + ATRCASE(8); + ATRCASE(9); + ATRCASE2(SEMICOLON, OEM_1); + ATRCASE2(EQUALS, OEM_NEC_EQUAL); + + ATRCASE2(LEFTBRACKET, OEM_4); + ATRCASE2(BACKSLASH, OEM_5); + ATRCASE2(RIGHTBRACKET, OEM_6); + ATRCASE2(BACKQUOTE, OEM_3); + ATRCASE2(a, A); + ATRCASE2(b, B); + ATRCASE2(c, C); + ATRCASE2(d, D); + ATRCASE2(e, E); + ATRCASE2(f, F); + ATRCASE2(g, G); + ATRCASE2(h, H); + ATRCASE2(i, I); + ATRCASE2(j, J); + ATRCASE2(k, K); + ATRCASE2(l, L); + ATRCASE2(m, M); + ATRCASE2(n, N); + ATRCASE2(o, O); + ATRCASE2(p, P); + ATRCASE2(q, Q); + ATRCASE2(r, R); + ATRCASE2(s, S); + ATRCASE2(t, T); + ATRCASE2(u, U); + ATRCASE2(v, V); + ATRCASE2(w, W); + ATRCASE2(x, X); + ATRCASE2(y, Y); + ATRCASE2(z, Z); + ATRCASE(DELETE); + + ATRCASE2(KP_PERIOD, DECIMAL); + ATRCASE2(KP_DIVIDE, DIVIDE); + ATRCASE2(KP_MULTIPLY, MULTIPLY); + ATRCASE2(KP_MINUS, SUBTRACT); + ATRCASE2(KP_PLUS, ADD); + ATRCASE2(KP_ENTER, NUMPADENTER); + + ATRCASE(UP); + ATRCASE(DOWN); + ATRCASE(RIGHT); + ATRCASE(LEFT); + ATRCASE(INSERT); + ATRCASE(HOME); + ATRCASE(END); + ATRCASE2(PAGEUP, PRIOR); + ATRCASE2(PAGEDOWN, NEXT); + + ATRCASE(F1); + ATRCASE(F2); + ATRCASE(F3); + ATRCASE(F4); + ATRCASE(F5); + ATRCASE(F6); + ATRCASE(F7); + ATRCASE(F8); + ATRCASE(F9); + ATRCASE(F10); + ATRCASE(F11); + ATRCASE(F12); + ATRCASE(F13); + ATRCASE(F14); + ATRCASE(F15); + + ATRCASE2(CAPSLOCK, CAPITAL); + ATRCASE(RSHIFT); + ATRCASE(LSHIFT); + ATRCASE2(RCTRL, RCONTROL); + ATRCASE2(LCTRL, LCONTROL); + ATRCASE2(RALT, RMENU); + ATRCASE2(LALT, LMENU); + + ATRCASE2(KP0, NUMPAD0); + ATRCASE2(KP1, NUMPAD1); + ATRCASE2(KP2, NUMPAD2); + ATRCASE2(KP3, NUMPAD3); + ATRCASE2(KP4, NUMPAD4); + ATRCASE2(KP5, NUMPAD5); + ATRCASE2(KP6, NUMPAD6); + ATRCASE2(KP7, NUMPAD7); + ATRCASE2(KP8, NUMPAD8); + ATRCASE2(KP9, NUMPAD9); + + ATRCASE(NUMLOCK); + ATRCASE2(SCROLLOCK, SCROLL); + + default: + { + key = KEY_UNDEF; + break; + } + } + + return key; + + } + + std::string getHotkeyName(Hotkey key) + { + std::string hotkeyname; + if (key.shift) + { + hotkeyname += "SHIFT + "; + } + if (key.ctrl) + { + hotkeyname += "CTRL + "; + } + if (key.alt) + { + hotkeyname += "ALT + "; + } + + switch(key.key) + { + case Input::KEY_F1: hotkeyname += "F1"; break; + case Input::KEY_F2: hotkeyname += "F2"; break; + case Input::KEY_F3: hotkeyname += "F3"; break; + case Input::KEY_F4: hotkeyname += "F4"; break; + case Input::KEY_F5: hotkeyname += "F5"; break; + case Input::KEY_F6: hotkeyname += "F6"; break; + case Input::KEY_F7: hotkeyname += "F7"; break; + case Input::KEY_F8: hotkeyname += "F8"; break; + case Input::KEY_F9: hotkeyname += "F9"; break; + case Input::KEY_F10: hotkeyname += "F10"; break; + case Input::KEY_F11: hotkeyname += "F11"; break; + case Input::KEY_F12: hotkeyname += "F12"; break; + case Input::KEY_F13: hotkeyname += "F13"; break; + case Input::KEY_F14: hotkeyname += "F14"; break; + case Input::KEY_F15: hotkeyname += "F15"; break; + + case Input::KEY_BACKSPACE: hotkeyname += "BACKSPACE"; break; + case Input::KEY_TAB: hotkeyname += "TAB"; break; + case Input::KEY_CLEAR: hotkeyname += "CLEAR"; break; + case Input::KEY_SPACE: hotkeyname += "SPACE"; break; + case Input::KEY_DELETE: hotkeyname += "DELETE"; break; + + case Input::KEY_KP0: hotkeyname += "KP0"; break; + case Input::KEY_KP1: hotkeyname += "KP1"; break; + case Input::KEY_KP2: hotkeyname += "KP2"; break; + case Input::KEY_KP3: hotkeyname += "KP3"; break; + case Input::KEY_KP4: hotkeyname += "KP4"; break; + case Input::KEY_KP5: hotkeyname += "KP5"; break; + case Input::KEY_KP6: hotkeyname += "KP6"; break; + case Input::KEY_KP7: hotkeyname += "KP7"; break; + case Input::KEY_KP8: hotkeyname += "KP8"; break; + case Input::KEY_KP9: hotkeyname += "KP9"; break; + case Input::KEY_KP_PERIOD: hotkeyname += "KP_PERIOD"; break; + case Input::KEY_KP_DIVIDE: hotkeyname += "KP_DIVIDE"; break; + case Input::KEY_KP_MULTIPLY: hotkeyname += "KP_MULTIPLY"; break; + case Input::KEY_KP_MINUS: hotkeyname += "KP_MINUS"; break; + case Input::KEY_KP_PLUS: hotkeyname += "KP_PLUS"; break; + case Input::KEY_KP_EQUALS: hotkeyname += "KP_EQUALS"; break; + + case Input::KEY_UP: hotkeyname += "UP"; break; + case Input::KEY_DOWN: hotkeyname += "DOWN"; break; + case Input::KEY_RIGHT: hotkeyname += "RIGHT"; break; + case Input::KEY_LEFT: hotkeyname += "LEFT"; break; + case Input::KEY_INSERT: hotkeyname += "INSERT"; break; + case Input::KEY_HOME: hotkeyname += "HOME"; break; + case Input::KEY_END: hotkeyname += "END"; break; + case Input::KEY_PAGEUP: hotkeyname += "PAGEUP"; break; + case Input::KEY_PAGEDOWN: hotkeyname += "PAGEDOWN"; break; + + default: + { + hotkeyname += std::toupper(char(key.key)); + } + } + + return hotkeyname; + } +} diff --git a/components/input/common.h b/components/input/common.h new file mode 100644 index 000000000..7d1d36bf9 --- /dev/null +++ b/components/input/common.h @@ -0,0 +1,25 @@ +#ifndef COMMON_H +#define COMMON_H + +#include "keys.h" +#include "hotkey.h" + +namespace rci = Rocket::Core::Input; + +namespace Input +{ + #define RTACASE2(val1, val2) case rci::KI_##val1: key = KEY_##val2; break + #define RTACASE(val) case rci::KI_##val: key = KEY_##val; break; + + Key convertRocketKeyToAscii(int rocketk); + + #define ATRCASE2(val1, val2) case KEY_##val1: key = rci::KI_##val2; break; + #define ATRCASE(val) case KEY_##val: key = rci::KI_##val; break; + + int convertAsciiToRocketKey(int asciik); + + std::string getHotkeyName(Hotkey key); +} + +#endif /* COMMON_H */ + diff --git a/components/input/hotkey.cpp b/components/input/hotkey.cpp new file mode 100644 index 000000000..8d9731b64 --- /dev/null +++ b/components/input/hotkey.cpp @@ -0,0 +1,76 @@ +#include "hotkey.h" +#include +#include +#include + + +namespace Input +{ + Hotkey::Hotkey() + { + key = 0; + shift = false; + ctrl = false; + alt = false; + } + + Hotkey::Hotkey(const char *name, bpt::ptree hotkeypt) + { + std::string sname = name; + + key = hotkeypt.get(sname + ".key"); + shift = hotkeypt.get(sname + ".shift"); + ctrl = hotkeypt.get(sname + ".ctrl"); + alt = hotkeypt.get(sname + ".alt"); + } + + Hotkey::Hotkey(int nkey, bool nshift, bool nctrl, bool nalt) + { + key = nkey; + shift = nshift; + ctrl = nctrl; + alt = nalt; + } + + bool Hotkey::operator==(const Hotkey &other) + { + if (key == other.key && shift == other.shift && ctrl == other.ctrl && alt == other.alt) + { + return true; + } + else + { + return false; + } + } + + void Hotkey::save(const char *name, bpt::ptree hotkeypt) + { + std::string sname = name; + + hotkeypt.put(sname + ".key", key); + hotkeypt.put(sname + ".shift", int(shift)); + hotkeypt.put(sname + ".ctrl", int(ctrl)); + hotkeypt.put(sname + ".alt", int(alt)); + bpt::write_ini("resources/hotkeys.ini", hotkeypt); + } + + BOOST_PYTHON_MODULE(hotkey) + { + boost::python::class_("Hotkey") + .def(boost::python::init()) + .def(boost::python::init()) + .def("__eq__", &Hotkey::operator==) + .def("save", &Hotkey::save) + .def_readwrite("key", &Hotkey::key) + .def_readwrite("shift", &Hotkey::shift) + .def_readwrite("ctrl", &Hotkey::ctrl) + .def_readwrite("alt", &Hotkey::alt); + } + + void Hotkey::initpythonwrapper() + { + inithotkey(); + } + +} diff --git a/components/input/hotkey.h b/components/input/hotkey.h new file mode 100644 index 000000000..bb594f28e --- /dev/null +++ b/components/input/hotkey.h @@ -0,0 +1,26 @@ +#ifndef HOTKEY_H +#define HOTKEY_H + +#include + +namespace bpt = boost::property_tree; + +namespace Input +{ + class Hotkey + { + public: + int key; + bool shift, ctrl, alt; + + Hotkey(); + Hotkey(const char *name, bpt::ptree hotkeypt); + Hotkey(int nkey, bool nshift, bool nctrl, bool nalt); + bool operator==(const Hotkey &other); + void save(const char *name, bpt::ptree hotkeypt); + static void initpythonwrapper(); + }; +} + +#endif /* HOTKEY_H */ + diff --git a/components/input/inputmanager.h b/components/input/inputmanager.h index 58ab9d614..9eb439bf8 100644 --- a/components/input/inputmanager.h +++ b/components/input/inputmanager.h @@ -7,7 +7,7 @@ #include #include - #include +#include #include #include "keys.h" diff --git a/resources/gui/changehotkey.rml b/resources/gui/changehotkey.rml new file mode 100644 index 000000000..4cffdad97 --- /dev/null +++ b/resources/gui/changehotkey.rml @@ -0,0 +1,129 @@ + + + + + + + + +
+
+
+
+ +
diff --git a/resources/gui/changehotkeyerrormsg.rml b/resources/gui/changehotkeyerrormsg.rml new file mode 100644 index 000000000..e8402334a --- /dev/null +++ b/resources/gui/changehotkeyerrormsg.rml @@ -0,0 +1,53 @@ + + + + + + + + +
+
+
+ +
diff --git a/resources/gui/hotkeymenu.rml b/resources/gui/hotkeymenu.rml new file mode 100644 index 000000000..a1d7ec450 --- /dev/null +++ b/resources/gui/hotkeymenu.rml @@ -0,0 +1,101 @@ + + + + + + + + +
+ +
+ +
diff --git a/resources/gui/pausemenu.rml b/resources/gui/pausemenu.rml index b4be76333..4160ecb69 100644 --- a/resources/gui/pausemenu.rml +++ b/resources/gui/pausemenu.rml @@ -57,6 +57,7 @@ def onLoad(document): {"text": 'OPTIONS (placeholder)'}, {"text": 'NEW GAME (placeholder)'}, {"text": 'LOAD GAME (placeholder)'}, + {"text": 'HOTKEYS', "strFunc": "showHotkeys", "func": showHotkeys}, {"text": 'QUIT', "func": freeablo.quit} ] @@ -71,6 +72,11 @@ def onKeyDown(event, document): if not pauseMenu.onKeyDown(event): docmanage.manager.onKeyDown(event) +def showHotkeys(): + docmanage.manager.loadDoc("resources/gui/hotkeymenu.rml") + docmanage.manager.hideDoc("resources/gui/pausemenu.rml") + docmanage.manager.showDoc("resources/gui/hotkeymenu.rml") + diff --git a/resources/hotkeys.ini b/resources/hotkeys.ini index a4b9d29c4..1e0f1a29d 100644 --- a/resources/hotkeys.ini +++ b/resources/hotkeys.ini @@ -1,5 +1,20 @@ -[Hotkeys] -quit=113 -noclip=110 -changelvldwn=112 -changelvlup=111 +[Quit] +key=113 +shift=0 +ctrl=0 +alt=0 +[Noclip] +key=110 +shift=0 +ctrl=0 +alt=0 +[Changelvlup] +key=111 +shift=0 +ctrl=0 +alt=0 +[Changelvldwn] +key=112 +shift=0 +ctrl=0 +alt=0 diff --git a/resources/python/docmanage.py b/resources/python/docmanage.py index 8a52b12f0..a8a80491e 100644 --- a/resources/python/docmanage.py +++ b/resources/python/docmanage.py @@ -21,7 +21,8 @@ def __init__(self): self.docs = {} self.paused = False self.pauseHiddenDocs = [] - self.pauseHandle = context.LoadDocument('resources/gui/pausemenu.rml') + self.pauseHandle = "resources/gui/pausemenu.rml" + self.loadDoc(self.pauseHandle) def showDoc(self, docpath): handle = self.docs[docpath] @@ -40,9 +41,23 @@ def toggleDoc(self, docpath): self.showDoc(docpath) def loadDoc(self, docpath): - context = rocket.contexts['default'] - newHandle = {"doc": context.LoadDocument(docpath), "visible": False} - self.docs[docpath] = newHandle + if not docpath in self.docs: + context = rocket.contexts['default'] + newHandle = {"doc": context.LoadDocument(docpath), "visible": False} + self.docs[docpath] = newHandle + + def reloadDoc(self, docpath): + self.closeDoc(docpath) + self.loadDoc(docpath) + + def getDoc(self, docpath): + handle = self.docs[docpath] + return handle["doc"] + + def closeDoc(self, docpath): + handle = self.docs[docpath] + handle["doc"].Close() + del self.docs[docpath] def pause(self): for docpath in self.docs: @@ -52,11 +67,11 @@ def pause(self): self.pauseHiddenDocs.append(docpath) self.paused = True - self.pauseHandle.Show() + self.toggleDoc(self.pauseHandle) freeablo.pause() def unpause(self): - self.pauseHandle.Hide() + self.toggleDoc(self.pauseHandle) for docpath in self.pauseHiddenDocs: self.toggleDoc(docpath) diff --git a/resources/python/menu.py b/resources/python/menu.py index 6690db332..4e483e59e 100644 --- a/resources/python/menu.py +++ b/resources/python/menu.py @@ -32,7 +32,8 @@ def __init__(self, doc, selfName, containerId, entries, fmtSelected, fmtNotSelec menuHtmlStr = "" for i, val in enumerate(self.entries): - onclick = (val["strFunc"]+"()") if "strFunc" in val else "" + args = val["args"] if "args" in val else "" + onclick = (val["strFunc"]+"({0})").format(args) if "strFunc" in val else "" entryStr = '' % (i, selfName, i, selfName) entryStr += self.fmtNotSelected % val["text"] entryStr += '
' @@ -67,7 +68,8 @@ def activate(self): freeablo.playSound("sfx/items/titlslct.wav") currentEntry = self.entries[self.current] if("func" in currentEntry): - currentEntry["func"]() + currentEntry["func"](currentEntry["args"]) if "args" in currentEntry \ + else currentEntry["func"]() def onKeyDown(self, event): if event.parameters['key_identifier'] == rocket.key_identifier.DOWN: