From ce5947043e84cedaacf933e59f3d4ef55c276e76 Mon Sep 17 00:00:00 2001 From: Exairnous Date: Sat, 22 Nov 2014 01:35:41 +0000 Subject: [PATCH 1/8] created initial hotkeys submenu for pause menu --- resources/gui/hotkeymenu.rml | 104 +++++++++++++++++++++++++++++++++++ resources/gui/pausemenu.rml | 18 +++++- 2 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 resources/gui/hotkeymenu.rml diff --git a/resources/gui/hotkeymenu.rml b/resources/gui/hotkeymenu.rml new file mode 100644 index 000000000..90b420213 --- /dev/null +++ b/resources/gui/hotkeymenu.rml @@ -0,0 +1,104 @@ + + + + + + + + +
+ +
+ +
diff --git a/resources/gui/pausemenu.rml b/resources/gui/pausemenu.rml index b7bd33c5c..163f10c15 100644 --- a/resources/gui/pausemenu.rml +++ b/resources/gui/pausemenu.rml @@ -40,14 +40,22 @@ import rocket import freeablo from menu import Menu +context = rocket.contexts['default'] +doc = None pauseMenu = None +paused = False def onLoad(document): + document.id = "pausemenu" + global doc + doc = document + entries = [ {"text": 'SAVE GAME (placeholder)'}, - {"text": 'OPTIONS (placeholder)'}, - {"text": 'NEW GAME (placeholder)'}, {"text": 'LOAD GAME (placeholder)'}, + {"text": 'NEW GAME (placeholder)'}, + {"text": 'OPTIONS (placeholder)'}, + {"text": 'HOTKEYS', "strFunc": "showHotkeys", "func": showHotkeys}, {"text": 'QUIT', "strFunc": 'freeablo.quit', "func": freeablo.quit} ] @@ -62,6 +70,12 @@ def onKeyDown(event, document): if not pauseMenu.onKeyDown(event): document.baseKeyDown(event, document) +def showHotkeys(): + doc.Hide() + hotkeys = context.LoadDocument('resources/gui/hotkeymenu.rml') + hotkeys.Show() + print("is_shown", hotkeys.is_shown) + From da3b15320a9d9a7d9cf6a7098adeb8610e56d16b Mon Sep 17 00:00:00 2001 From: Exairnous Date: Wed, 31 Dec 2014 18:14:57 +0000 Subject: [PATCH 2/8] Initial form of hotkeys gui --- apps/freeablo/fagui/guimanager.cpp | 127 ++++++ apps/freeablo/main.cpp | 213 +++++---- components/input/common.cpp | 598 +++++++++++++++++++++++++ components/input/inputmanager.h | 2 +- resources/gui/changehotkey.rml | 162 +++++++ resources/gui/changehotkeyerrormsg.rml | 60 +++ resources/gui/hotkeymenu.rml | 42 +- resources/gui/pausemenu.rml | 5 +- resources/hotkeys.ini | 29 +- resources/python/menu.py | 3 +- 10 files changed, 1137 insertions(+), 104 deletions(-) create mode 100644 components/input/common.cpp create mode 100644 resources/gui/changehotkey.rml create mode 100644 resources/gui/changehotkeyerrormsg.rml diff --git a/apps/freeablo/fagui/guimanager.cpp b/apps/freeablo/fagui/guimanager.cpp index fc4050bc8..4b494b8f6 100644 --- a/apps/freeablo/fagui/guimanager.cpp +++ b/apps/freeablo/fagui/guimanager.cpp @@ -10,10 +10,24 @@ #include #include +#include + +#include +#include + +//#include extern bool done; // TODO: handle this better extern bool paused; // TODO: handle this better extern int changeLevel; // TODO: handle this better +extern int quit_key[]; // TODO: handle this better +extern int noclip_key[]; // TODO: handle this better +extern int changelvldwn_key[]; // TODO: handle this better +extern int changelvlup_key[]; // TODO: handle this better + +namespace bpt = boost::property_tree; + +extern bpt::ptree hotkeypt; namespace FAGui { @@ -38,6 +52,116 @@ namespace FAGui paused = false; showIngameGui(); } + + 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; + boost::python::list quit; + boost::python::list noclip; + boost::python::list changelvlup; + boost::python::list changelvldwn; + + quit.append(Input::convertAsciiToRocketKey(quit_key[0])); + noclip.append(Input::convertAsciiToRocketKey(noclip_key[0])); + changelvlup.append(Input::convertAsciiToRocketKey(changelvlup_key[0])); + changelvldwn.append(Input::convertAsciiToRocketKey(changelvldwn_key[0])); + + for (int i=1; i<5; i++) + { + + quit.append(quit_key[i]); + noclip.append(noclip_key[i]); + changelvlup.append(changelvlup_key[i]); + changelvldwn.append(changelvldwn_key[i]); + } + + hotkeys.append(quit); + hotkeys.append(noclip); + hotkeys.append(changelvlup); + hotkeys.append(changelvldwn); + + return hotkeys; + } + + void setHotkey(boost::python::list hotkey) + { + std::string function = boost::python::extract(hotkey[0]); + boost::python::list pykeys = boost::python::extract(hotkey[1]); + int keys [5]; + + boost::python::ssize_t n = boost::python::len(pykeys); + for(boost::python::ssize_t i=0;i(pykeys[i]); + //std::cout << keys[i] << std::endl; + } + keys[0] = Input::convertRocketKeyToAscii(keys[0]); + //std::cout << keys[0] << std::endl; + + if (function == "quit") + { + for (int i=0; i<5; i++) + { + quit_key[i] = keys[i]; + } + hotkeypt.put("Quit.key", quit_key[0]); + hotkeypt.put("Quit.shift", quit_key[1]); + hotkeypt.put("Quit.ctrl", quit_key[2]); + hotkeypt.put("Quit.alt", quit_key[3]); + hotkeypt.put("Quit.super", quit_key[4]); + bpt::write_ini("resources/hotkeys.ini", hotkeypt); + } + if (function == "noclip") + { + for (int i=0; i<5; i++) + { + noclip_key[i] = keys[i]; + } + hotkeypt.put("Noclip.key", noclip_key[0]); + hotkeypt.put("Noclip.shift", noclip_key[1]); + hotkeypt.put("Noclip.ctrl", noclip_key[2]); + hotkeypt.put("Noclip.alt", noclip_key[3]); + hotkeypt.put("Noclip.super", noclip_key[4]); + bpt::write_ini("resources/hotkeys.ini", hotkeypt); + } + if (function == "changelvlup") + { + for (int i=0; i<5 ; i++) + { + changelvlup_key[i] = keys[i]; + } + hotkeypt.put("Changelvlup.key", changelvlup_key[0]); + hotkeypt.put("Changelvlup.shift", changelvlup_key[1]); + hotkeypt.put("Changelvlup.ctrl", changelvlup_key[2]); + hotkeypt.put("Changelvlup.alt", changelvlup_key[3]); + hotkeypt.put("Changelvlup.super", changelvlup_key[4]); + bpt::write_ini("resources/hotkeys.ini", hotkeypt); + } + if (function == "changelvldwn") + { + for (int i=0; i<5; i++) + { + changelvldwn_key[i] = keys[i]; + } + hotkeypt.put("Changelvldwn.key", changelvldwn_key[0]); + hotkeypt.put("Changelvldwn.shift", changelvldwn_key[1]); + hotkeypt.put("Changelvldwn.ctrl", changelvldwn_key[2]); + hotkeypt.put("Changelvldwn.alt", changelvldwn_key[3]); + hotkeypt.put("Changelvldwn.super", changelvldwn_key[4]); + bpt::write_ini("resources/hotkeys.ini", hotkeypt); + } + } BOOST_PYTHON_MODULE(freeablo) { @@ -45,6 +169,9 @@ namespace FAGui boost::python::def("pause", &pauseGame); boost::python::def("unpause", &unpauseGame); boost::python::def("startGame", &startGame); + boost::python::def("getHotkeyNames", &getHotkeyNames); + boost::python::def("getHotkeys", &getHotkeys); + boost::python::def("setHotkey", &setHotkey); } Rocket::Core::ElementDocument* ingameUi = NULL; diff --git a/apps/freeablo/main.cpp b/apps/freeablo/main.cpp index be7891bf2..c0f2aa946 100644 --- a/apps/freeablo/main.cpp +++ b/apps/freeablo/main.cpp @@ -31,29 +31,96 @@ bool paused = false; bool noclip = false; int changeLevel = 0; -int quit_key; -int noclip_key; -int changelvldwn_key; -int changelvlup_key; +int hotkey [5]; + +int quit_key [5]; +int noclip_key [5]; +int changelvldwn_key [5]; +int changelvlup_key [5]; + +bpt::ptree hotkeypt; void keyPress(Input::Key key) { - if (key == quit_key) + switch(key) + { + case Input::KEY_RSHIFT: hotkey[1] = 1; return; + case Input::KEY_LSHIFT: hotkey[1] = 1; return; + case Input::KEY_RCTRL: hotkey[2] = 1; return; + case Input::KEY_LCTRL: hotkey[2] = 1; return; + case Input::KEY_RALT: hotkey[3] = 1; return; + case Input::KEY_LALT: hotkey[3] = 1; return; + case Input::KEY_RSUPER: hotkey[4] = 1; return; + case Input::KEY_LSUPER: hotkey[4] = 1; return; + default: + { + hotkey[0] = key; + break; + } + } + + int check = 0; + + while(check<5) + { + //std::cout << "key " << hotkey[check] << " " << changelvldwn_key[check] << std::endl; + check++; + } + check = 0; + + while(check<5 && hotkey[check]==quit_key[check]) + { + //std::cout << "key " << quit_key[check] << std::endl; + check++; + } + if (check == 5) { done = true; + return; } - else if (key == noclip_key) + check = 0; + + while(check<5 && hotkey[check]==noclip_key[check]) + { + check++; + } + if (check == 5) { noclip = !noclip; + return; } - else if (key == changelvldwn_key) + check = 0; + + while(check<5 && hotkey[check]==changelvlup_key[check]) { - changeLevel = 1; + check++; } - else if (key == changelvlup_key) + if (check == 5) { changeLevel = -1; + return; + } + check = 0; + + while(check<5 && hotkey[check]==changelvldwn_key[check]) + { + check++; } + if (check == 5) + { + changeLevel = 1; + return; + } + check = 0; +} + +void keyRelease(Input::Key key) +{ + hotkey[0] = 0; + hotkey[1] = 0; + hotkey[2] = 0; + hotkey[3] = 0; + hotkey[4] = 0; } size_t xClick = 0, yClick = 0; @@ -82,38 +149,49 @@ void mouseMove(size_t x, size_t y) yClick = y; } -void setLevel(size_t dLvl, const DiabloExe::DiabloExe& exe, FAWorld::World& world, FARender::Renderer& renderer, Level::Level* level) +void setLevel(size_t levelNum, const DiabloExe::DiabloExe& exe, FAWorld::World& world, FARender::Renderer& renderer, Level::Level* level) { world.clear(); renderer.setLevel(level); world.setLevel(*level, exe); - if(dLvl == 0) + if(levelNum == 0) world.addNpcs(exe); } -Level::Level* getLevel(size_t dLvl, const DiabloExe::DiabloExe& exe) +Level::Level* getLevel(size_t levelNum, const DiabloExe::DiabloExe& exe) { - if(dLvl == 0) + switch(levelNum) { - Level::Dun sector1("levels/towndata/sector1s.dun"); - Level::Dun sector2("levels/towndata/sector2s.dun"); - Level::Dun sector3("levels/towndata/sector3s.dun"); - Level::Dun sector4("levels/towndata/sector4s.dun"); + case 0: + { + Level::Dun sector1("levels/towndata/sector1s.dun"); + Level::Dun sector2("levels/towndata/sector2s.dun"); + Level::Dun sector3("levels/towndata/sector3s.dun"); + Level::Dun sector4("levels/towndata/sector4s.dun"); - return new Level::Level(Level::Dun::getTown(sector1, sector2, sector3, sector4), "levels/towndata/town.til", - "levels/towndata/town.min", "levels/towndata/town.sol", "levels/towndata/town.cel", std::make_pair(25,29), std::make_pair(75,68), std::map()); - } - else if(dLvl < 9) - { - return FALevelGen::generate(100, 100, dLvl, exe); - } - else - { - std::cerr << "level not supported yet" << std::endl; - exit(1); - return NULL; + return new Level::Level(Level::Dun::getTown(sector1, sector2, sector3, sector4), "levels/towndata/town.til", + "levels/towndata/town.min", "levels/towndata/town.sol", "levels/towndata/town.cel", std::make_pair(25,29), std::make_pair(75,68), std::map()); + + break; + } + + case 1: + { + return FALevelGen::generate(100, 100, levelNum, exe, "levels/l1data/l1.cel"); + break; + } + + case 2: + case 3: + case 4: + { + std::cerr << "level not supported yet" << std::endl; + break; + } } + + return NULL; } /** @@ -127,7 +205,7 @@ bool parseOptions(int argc, char** argv, bpo::variables_map& variables) desc.add_options() ("help,h", "Print help") // -1 represents the main menu - ("level,l", bpo::value()->default_value(-1), "Level number to load (0-16)"); + ("level,l", bpo::value()->default_value(-1), "Level number to load (0-4)"); try { @@ -141,8 +219,8 @@ bool parseOptions(int argc, char** argv, bpo::variables_map& variables) bpo::notify(variables); - const int32_t dLvl = variables["level"].as(); - if(dLvl > 16) + const int32_t levelNum = variables["level"].as(); + if(levelNum > 4) throw bpo::validation_error( bpo::validation_error::invalid_option_value, "level"); } @@ -232,38 +310,6 @@ bool loadSettings(StartupSettings& settings) return true; } -void playLevelMusic(int32_t currentLevel, FARender::Renderer& renderer) -{ - switch(currentLevel) - { - case 0: - { - renderer.playMusic("music/dtowne.wav"); - break; - } - case 1: case 2: case 3: case 4: - { - renderer.playMusic("music/dlvla.wav"); - break; - } - case 5: case 6: case 7: case 8: - { - renderer.playMusic("music/dlvlb.wav"); - break; - } - case 9: case 10: case 11: case 12: - { - renderer.playMusic("music/dlvlc.wav"); - break; - } - case 13: case 14: case 15: case 16: - { - renderer.playMusic("music/dlvld.wav"); - break; - } - } -} - void run(const bpo::variables_map& variables); void runGameLoop(const bpo::variables_map& variables); @@ -303,14 +349,14 @@ void runGameLoop(const bpo::variables_map& variables) while(!FARender::Renderer::get()) {} FARender::Renderer& renderer = *FARender::Renderer::get(); - Input::InputManager input(&keyPress, NULL, &mouseClick, &mouseRelease, &mouseMove, renderer.getRocketContext()); + Input::InputManager input(&keyPress, &keyRelease, &mouseClick, &mouseRelease, &mouseMove, renderer.getRocketContext()); DiabloExe::DiabloExe exe; FAWorld::World world; FALevelGen::FAsrand(time(NULL)); - std::vector levels(9); + std::vector levels(5); int32_t currentLevel = variables["level"].as(); @@ -335,29 +381,43 @@ void runGameLoop(const bpo::variables_map& variables) player->mPos = FAWorld::Position(level->upStairsPos().first, level->upStairsPos().second); FAGui::showIngameGui(); - - playLevelMusic(currentLevel, renderer); } else { renderer.setLevel(NULL); paused = true; FAGui::showMainMenu(); - renderer.playMusic("music/dintro.wav"); } boost::posix_time::ptime last = boost::posix_time::microsec_clock::local_time(); std::pair destination = player->mPos.current(); - 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[0] = hotkeypt.get("Quit.key"); + quit_key[1] = hotkeypt.get("Quit.shift"); + quit_key[2] = hotkeypt.get("Quit.ctrl"); + quit_key[3] = hotkeypt.get("Quit.alt"); + quit_key[4] = hotkeypt.get("Quit.super"); + + noclip_key[0] = hotkeypt.get("Noclip.key"); + noclip_key[1] = hotkeypt.get("Noclip.shift"); + noclip_key[2] = hotkeypt.get("Noclip.ctrl"); + noclip_key[3] = hotkeypt.get("Noclip.alt"); + noclip_key[4] = hotkeypt.get("Noclip.super"); + + changelvlup_key[0] = hotkeypt.get("Changelvlup.key"); + changelvlup_key[1] = hotkeypt.get("Changelvlup.shift"); + changelvlup_key[2] = hotkeypt.get("Changelvlup.ctrl"); + changelvlup_key[3] = hotkeypt.get("Changelvlup.alt"); + changelvlup_key[4] = hotkeypt.get("Changelvlup.super"); + + changelvldwn_key[0] = hotkeypt.get("Changelvldwn.key"); + changelvldwn_key[1] = hotkeypt.get("Changelvldwn.shift"); + changelvldwn_key[2] = hotkeypt.get("Changelvldwn.ctrl"); + changelvldwn_key[3] = hotkeypt.get("Changelvldwn.alt"); + changelvldwn_key[4] = hotkeypt.get("Changelvldwn.super"); // Main game logic loop while(!done) @@ -394,7 +454,7 @@ void runGameLoop(const bpo::variables_map& variables) currentLevel = tmp; if(levels[currentLevel] == NULL) - levels[currentLevel] = getLevel(currentLevel, exe); + levels[currentLevel] = getLevel(currentLevel == 0 ? 0 : 1, exe); level = levels[currentLevel]; @@ -407,7 +467,6 @@ void runGameLoop(const bpo::variables_map& variables) setLevel(currentLevel, exe, world, renderer, level); - playLevelMusic(currentLevel, renderer); } changeLevel = 0; diff --git a/components/input/common.cpp b/components/input/common.cpp new file mode 100644 index 000000000..172905b00 --- /dev/null +++ b/components/input/common.cpp @@ -0,0 +1,598 @@ +#include +#include +#include +#include "keys.h" +//#include "common.h" + +namespace rci = Rocket::Core::Input; + +/* namespace Input +{ + + Key convertRocketKey(int rocketk) + { + Key key; + + switch(rocketk) + { + case rci::KI_BACK: key = KEY_BACKSPACE; break; + case rci::KI_TAB: key = KEY_TAB; break; + case rci::KI_CLEAR: key = KEY_CLEAR; break; + case rci::KI_RETURN: key = KEY_RETURN; break; + case rci::KI_PAUSE: key = KEY_PAUSE; break; + case rci::KI_ESCAPE: key = KEY_ESCAPE; break; + case rci::KI_SPACE: key = KEY_SPACE; break; + case rci::KI_OEM_8: KEY_QUOTEDBL + case rci::KEY_HASH KEY_HASH + case rci::KEY_DOLLAR KEY_DOLLAR + case rci::KEY_AMPERSAND KEY_AMPERSAND + case rci::KEY_QUOTE KEY_QUOTE + case rci::KEY_LEFTPAREN KEY_LEFTPAREN + case rci::KEY_RIGHTPAREN KEY_RIGHTPAREN + case rci::KEY_ASTERISK KEY_ASTERISK + + case rci::KI_SPACE: key = KEY_SPACE; break; + case rci::KI_0: key = KEY_0; break; + case rci::KI_1: key = KEY_1; break; + case rci::KI_2: key = KEY_2; break; + case rci::KI_3: key = KEY_3; break; + case rci::KI_4: key = KEY_4; break; + case rci::KI_5: key = KEY_5; break; + case rci::KI_6: key = KEY_6; break; + case rci::KI_7: key = KEY_7; break; + case rci::KI_8: key = KEY_8; break; + case rci::KI_9: key = KEY_9; break; + + case rci::KI_A: key = KEY_a; break; + case rci::KI_B: key = KEY_b; break; + case rci::KI_C: key = KEY_c; break; + case rci::KI_D: key = KEY_d; break; + case rci::KI_E: key = KEY_e; break; + case rci::KI_F: key = KEY_f; break; + case rci::KI_G: key = KEY_g; break; + case rci::KI_H: key = KEY_h; break; + case rci::KI_I: key = KEY_i; break; + case rci::KI_J: key = KEY_j; break; + case rci::KI_K: key = KEY_k; break; + case rci::KI_L: key = KEY_l; break; + case rci::KI_M: key = KEY_m; break; + case rci::KI_N: key = KEY_n; break; + case rci::KI_O: key = KEY_o; break; + case rci::KI_P: key = KEY_p; break; + case rci::KI_Q: key = KEY_q; break; + case rci::KI_R: key = KEY_r; break; + case rci::KI_S: key = KEY_s; break; + case rci::KI_T: key = KEY_t; break; + case rci::KI_U: key = KEY_u; break; + case rci::KI_V: key = KEY_v; break; + case rci::KI_W: key = KEY_w; break; + case rci::KI_X: key = KEY_x; break; + case rci::KI_Y: key = KEY_y; break; + case rci::KI_Z: key = KEY_z; break; + + case rci::KI_OEM_1: key = KEY_SEMICOLON + case rci::KI_OEM_PLUS: key = KEY_PLUS + case rci::KI_OEM_COMMA: key = KEY_COMMA + case rci::KI_OEM_MINUS: key = KEY_MINUS + case rci::KI_OEM_PERIODK: key = KEY_PERIOD + case rci::KI_OEM_2: key = KEY_QUESTION + case rci::KI_OEM_3: key = + + case rci::KI_OEM_4: key = + case rci::KI_OEM_5: key = + case rci::KI_OEM_6: key = + case rci::KI_OEM_7: key = + case rci::KI_OEM_8: key = + + case rci::KI_OEM_102: key = +: key = + case rci::KI_NUMPAD0: key = + case rci::KI_NUMPAD1: key = + case rci::KI_NUMPAD2: key = + case rci::KI_NUMPAD3: key = + case rci::KI_NUMPAD4: key = + case rci::KI_NUMPAD5: key = + case rci::KI_NUMPAD6: key = + case rci::KI_NUMPAD7: key = + case rci::KI_NUMPAD8: key = + case rci::KI_NUMPAD9: key = + case rci::KI_NUMPADENTER: key = + case rci::KI_MULTIPLY: key = + case rci::KI_ADD: key = + case rci::KI_SEPARATOR: key = + case rci::KI_SUBTRACT: key = + case rci::KI_DECIMAL: key = + case rci::KI_DIVIDE: key = + + case rci::KI_OEM_NEC_EQUAL: key = + + case rci::KI_BACK: key = + case rci::KI_TAB: key = + + case rci::KI_CLEAR: key = + case rci::KI_RETURN: key = + + case rci::KI_PAUSE: key = + case rci::KI_CAPITAL: key = + + case rci::KI_KANA = 75, + case rci::KI_HANGUL = 76, + case rci::KI_JUNJA = 77, + case rci::KI_FINAL = 78, + case rci::KI_HANJA = 79, + case rci::KI_KANJI = 80, + + case rci::KI_ESCAPE = 81, + + case rci::KI_CONVERT = 82, + case rci::KI_NONCONVERT = 83, + case rci::KI_ACCEPT = 84, + case rci::KI_MODECHANGE = 85, + + case rci::KI_PRIOR = 86, + case rci::KI_NEXT = 87, + case rci::KI_END = 88, + case rci::KI_HOME = 89, + case rci::KI_LEFT = 90, + case rci::KI_UP = 91, + case rci::KI_RIGHT = 92, + case rci::KI_DOWN = 93, + case rci::KI_SELECT = 94, + case rci::KI_PRINT = 95, + case rci::KI_EXECUTE = 96, + case rci::KI_SNAPSHOT = 97, + case rci::KI_INSERT = 98, + case rci::KI_DELETE = 99, + case rci::KI_HELP = 100, + + case rci::KI_LWIN = 101, + case rci::KI_RWIN = 102, + case rci::KI_APPS = 103, + + case rci::KI_POWER = 104, + case rci::KI_SLEEP = 105, + case rci::KI_WAKE = 106, + + case rci::KI_F1 = 107, + case rci::KI_F2 = 108, + case rci::KI_F3 = 109, + case rci::KI_F4 = 110, + case rci::KI_F5 = 111, + case rci::KI_F6 = 112, + case rci::KI_F7 = 113, + case rci::KI_F8 = 114, + case rci::KI_F9 = 115, + case rci::KI_F10 = 116, + case rci::KI_F11 = 117, + case rci::KI_F12 = 118, + case rci::KI_F13 = 119, + case rci::KI_F14 = 120, + case rci::KI_F15 = 121, + case rci::KI_F16 = 122, + case rci::KI_F17 = 123, + case rci::KI_F18 = 124, + case rci::KI_F19 = 125, + case rci::KI_F20 = 126, + case rci::KI_F21 = 127, + case rci::KI_F22 = 128, + case rci::KI_F23 = 129, + case rci::KI_F24 = 130, + + case rci::KI_NUMLOCK = 131, + case rci::KI_SCROLL = 132, + + case rci::KI_OEM_FJ_JISHO = 133, + case rci::KI_OEM_FJ_MASSHOU = 134, + case rci::KI_OEM_FJ_TOUROKU = 135, + case rci::KI_OEM_FJ_LOYA = 136, + case rci::KI_OEM_FJ_ROYA = 137, + + case rci::KI_LSHIFT = 138, + case rci::KI_RSHIFT = 139, + case rci::KI_LCONTROL = 140, + case rci::KI_RCONTROL = 141, + case rci::KI_LMENU = 142, + case rci::KI_RMENU = 143, + + case rci::KI_BROWSER_BACK = 144, + case rci::KI_BROWSER_FORWARD = 145, + case rci::KI_BROWSER_REFRESH = 146, + case rci::KI_BROWSER_STOP = 147, + case rci::KI_BROWSER_SEARCH = 148, + case rci::KI_BROWSER_FAVORITES = 149, + case rci::KI_BROWSER_HOME = 150, + + case rci::KI_VOLUME_MUTE = 151, + case rci::KI_VOLUME_DOWN = 152, + case rci::KI_VOLUME_UP = 153, + case rci::KI_MEDIA_NEXT_TRACK = 154, + case rci::KI_MEDIA_PREV_TRACK = 155, + case rci::KI_MEDIA_STOP = 156, + case rci::KI_MEDIA_PLAY_PAUSE = 157, + case rci::KI_LAUNCH_MAIL = 158, + case rci::KI_LAUNCH_MEDIA_SELECT = 159, + case rci::KI_LAUNCH_APP1 = 160, + case rci::KI_LAUNCH_APP2 = 161, + + case rci::KI_OEM_AX = 162, + case rci::KI_ICO_HELP = 163, + case rci::KI_ICO_00 = 164, + + case rci::KI_PROCESSKEY = 165, + + case rci::KI_ICO_CLEAR = 166, + + case rci::KI_ATTN = 167, + case rci::KI_CRSEL = 168, + case rci::KI_EXSEL = 169, + case rci::KI_EREOF = 170, + case rci::KI_PLAY = 171, + case rci::KI_ZOOM = 172, + case rci::KI_PA1 = 173, + case rci::KI_OEM_CLEAR = 174, + + case rci::KI_LMETA = 175, + case rci::KI_RMETA = 176 + default: + { + key = KEY_UNDEF; + break; + } + } + } +}*/ + +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) + { + 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); + + RTACASE2(RMETA, RSUPER); + RTACASE2(LMETA, LSUPER); + + default: + { + key = KEY_UNDEF; + break; + } + } + + return key; + + } + + #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 rocketk) + { + int key; + + switch(rocketk) + { + 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); + + ATRCASE2(RSUPER, RMETA); + ATRCASE2(LSUPER, LMETA); + + default: + { + key = KEY_UNDEF; + break; + } + } + + return key; + + } + + std::string getHotkeyName(int key []) + { + std::string hotkeyname; + if (key[1]) + { + hotkeyname += "SHIFT + "; + } + if (key[2]) + { + hotkeyname += "CTRL + "; + } + if (key[3]) + { + hotkeyname += "ALT + "; + } + if (key[4]) + { + hotkeyname += "META + "; + } + + switch(key[0]) + { + 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[0])); + } + } + + return hotkeyname; + } +} diff --git a/components/input/inputmanager.h b/components/input/inputmanager.h index e1f7aea8f..fcc8cb7d8 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..7583149ee --- /dev/null +++ b/resources/gui/changehotkey.rml @@ -0,0 +1,162 @@ + + + + + + + + +
+ +
+ +
diff --git a/resources/gui/changehotkeyerrormsg.rml b/resources/gui/changehotkeyerrormsg.rml new file mode 100644 index 000000000..b35370085 --- /dev/null +++ b/resources/gui/changehotkeyerrormsg.rml @@ -0,0 +1,60 @@ + + + + + + + + +
+ +
+ +
diff --git a/resources/gui/hotkeymenu.rml b/resources/gui/hotkeymenu.rml index 90b420213..2e76be5ea 100644 --- a/resources/gui/hotkeymenu.rml +++ b/resources/gui/hotkeymenu.rml @@ -43,18 +43,21 @@ from menu import Menu context = rocket.contexts['default'] doc = None hotkeyMenu = None -hotkeySet = [None, False] -newHotkey = None +#hotkeySet = [None, False] +#newHotkey = None def onLoad(document): + document.id = "hotkeymenu" global doc doc = document + hotkeynames = freeablo.getHotkeyNames() + entries = [ - {"text": 'Quit = Q', "strFunc": "setHotkey", "func": setHotkey}, - {"text": 'Noclip = (placeholder)'}, - {"text": 'Change Level Up = (placeholder)'}, - {"text": 'Change Level Down (placeholder)'}, + {"text": 'Quit = {0}'.format(hotkeynames[0]), "strFunc": "changeHotkey", "func": changeHotkey, "args": "'quit'"}, + {"text": 'Noclip = {0}'.format(hotkeynames[1]), "strFunc": "changeHotkey", "func": changeHotkey, "args": "'noclip'"}, + {"text": 'Change Level Up = {0}'.format(hotkeynames[2]), "strFunc": "changeHotkey", "func": changeHotkey, "args": "'changelvlup'"}, + {"text": 'Change Level Down = {0}'.format(hotkeynames[3]), "strFunc": "changeHotkey", "func": changeHotkey, "args": "'changelvldwn'"}, {"text": 'Previous', "strFunc": "showPause", "func": showPause} ] @@ -65,15 +68,20 @@ def onLoad(document): hotkeyMenu = Menu(document, 'hotkeyMenu', 'innerMenuContainer', entries, fmtSelected, fmtNotSelected) -def onKeyDown(event, document): - global newHotkey +#def onKeyDown(event, document): + #global newHotkey - hotkeyMenu.onKeyDown(event) - if hotkeySet[1]: - newHotkey = event.parameters['key_identifier'] - print(hotkeySet, newHotkey) - + #hotkeyMenu.onKeyDown(event) + #if hotkeySet[1]: + #newHotkey = event.parameters['key_identifier'] + #print(hotkeySet, newHotkey) +def changeHotkey(func): + global doc + doc.Close() + changeHotkey = context.LoadDocument('resources/gui/changehotkey.rml') + changeHotkey.func = func + changeHotkey.Show() def showPause(): global doc @@ -83,11 +91,11 @@ def showPause(): pausemenu = context.documents["pausemenu"] pausemenu.Show() -def setHotkey(): - global hotkeySet +#def setHotkey(): + #global hotkeySet - hotkeySet[0] = "quit" - hotkeySet[1] = True + #hotkeySet[0] = "quit" + #hotkeySet[1] = True diff --git a/resources/gui/pausemenu.rml b/resources/gui/pausemenu.rml index 163f10c15..b87d60116 100644 --- a/resources/gui/pausemenu.rml +++ b/resources/gui/pausemenu.rml @@ -52,9 +52,9 @@ def onLoad(document): entries = [ {"text": 'SAVE GAME (placeholder)'}, - {"text": 'LOAD GAME (placeholder)'}, - {"text": 'NEW GAME (placeholder)'}, {"text": 'OPTIONS (placeholder)'}, + {"text": 'NEW GAME (placeholder)'}, + {"text": 'LOAD GAME (placeholder)'}, {"text": 'HOTKEYS', "strFunc": "showHotkeys", "func": showHotkeys}, {"text": 'QUIT', "strFunc": 'freeablo.quit', "func": freeablo.quit} ] @@ -74,7 +74,6 @@ def showHotkeys(): doc.Hide() hotkeys = context.LoadDocument('resources/gui/hotkeymenu.rml') hotkeys.Show() - print("is_shown", hotkeys.is_shown) diff --git a/resources/hotkeys.ini b/resources/hotkeys.ini index a4b9d29c4..74ebec670 100644 --- a/resources/hotkeys.ini +++ b/resources/hotkeys.ini @@ -1,5 +1,24 @@ -[Hotkeys] -quit=113 -noclip=110 -changelvldwn=112 -changelvlup=111 +[Quit] +key=113 +shift=0 +ctrl=0 +alt=0 +super=0 +[Noclip] +key=110 +shift=0 +ctrl=0 +alt=0 +super=0 +[Changelvlup] +key=111 +shift=0 +ctrl=0 +alt=0 +super=0 +[Changelvldwn] +key=112 +shift=0 +ctrl=0 +alt=0 +super=0 diff --git a/resources/python/menu.py b/resources/python/menu.py index 206e9d6b1..6dd319664 100644 --- a/resources/python/menu.py +++ b/resources/python/menu.py @@ -31,7 +31,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, onclick) entryStr += self.fmtNotSelected % val["text"] entryStr += '
' From 6f8b8c3aa3b44ba44579eccb0fff496fe72aa0ea Mon Sep 17 00:00:00 2001 From: Exairnous Date: Thu, 1 Jan 2015 03:23:46 +0000 Subject: [PATCH 3/8] fixed main so it is up to date with master --- apps/freeablo/main.cpp | 97 ++++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 36 deletions(-) diff --git a/apps/freeablo/main.cpp b/apps/freeablo/main.cpp index c0f2aa946..c140b5ae9 100644 --- a/apps/freeablo/main.cpp +++ b/apps/freeablo/main.cpp @@ -149,49 +149,38 @@ void mouseMove(size_t x, size_t y) yClick = y; } -void setLevel(size_t levelNum, const DiabloExe::DiabloExe& exe, FAWorld::World& world, FARender::Renderer& renderer, Level::Level* level) +void setLevel(size_t dLvl, const DiabloExe::DiabloExe& exe, FAWorld::World& world, FARender::Renderer& renderer, Level::Level* level) { world.clear(); renderer.setLevel(level); world.setLevel(*level, exe); - if(levelNum == 0) + if(dLvl == 0) world.addNpcs(exe); } -Level::Level* getLevel(size_t levelNum, const DiabloExe::DiabloExe& exe) +Level::Level* getLevel(size_t dLvl, const DiabloExe::DiabloExe& exe) { - switch(levelNum) + if(dLvl == 0) { - case 0: - { - Level::Dun sector1("levels/towndata/sector1s.dun"); - Level::Dun sector2("levels/towndata/sector2s.dun"); - Level::Dun sector3("levels/towndata/sector3s.dun"); - Level::Dun sector4("levels/towndata/sector4s.dun"); - - return new Level::Level(Level::Dun::getTown(sector1, sector2, sector3, sector4), "levels/towndata/town.til", - "levels/towndata/town.min", "levels/towndata/town.sol", "levels/towndata/town.cel", std::make_pair(25,29), std::make_pair(75,68), std::map()); - - break; - } + Level::Dun sector1("levels/towndata/sector1s.dun"); + Level::Dun sector2("levels/towndata/sector2s.dun"); + Level::Dun sector3("levels/towndata/sector3s.dun"); + Level::Dun sector4("levels/towndata/sector4s.dun"); - case 1: - { - return FALevelGen::generate(100, 100, levelNum, exe, "levels/l1data/l1.cel"); - break; - } - - case 2: - case 3: - case 4: - { - std::cerr << "level not supported yet" << std::endl; - break; - } + return new Level::Level(Level::Dun::getTown(sector1, sector2, sector3, sector4), "levels/towndata/town.til", + "levels/towndata/town.min", "levels/towndata/town.sol", "levels/towndata/town.cel", std::make_pair(25,29), std::make_pair(75,68), std::map()); + } + else if(dLvl < 9) + { + return FALevelGen::generate(100, 100, dLvl, exe); + } + else + { + std::cerr << "level not supported yet" << std::endl; + exit(1); + return NULL; } - - return NULL; } /** @@ -205,7 +194,7 @@ bool parseOptions(int argc, char** argv, bpo::variables_map& variables) desc.add_options() ("help,h", "Print help") // -1 represents the main menu - ("level,l", bpo::value()->default_value(-1), "Level number to load (0-4)"); + ("level,l", bpo::value()->default_value(-1), "Level number to load (0-16)"); try { @@ -219,8 +208,8 @@ bool parseOptions(int argc, char** argv, bpo::variables_map& variables) bpo::notify(variables); - const int32_t levelNum = variables["level"].as(); - if(levelNum > 4) + const int32_t dLvl = variables["level"].as(); + if(dLvl > 16) throw bpo::validation_error( bpo::validation_error::invalid_option_value, "level"); } @@ -310,6 +299,38 @@ bool loadSettings(StartupSettings& settings) return true; } +void playLevelMusic(int32_t currentLevel, FARender::Renderer& renderer) +{ + switch(currentLevel) + { + case 0: + { + renderer.playMusic("music/dtowne.wav"); + break; + } + case 1: case 2: case 3: case 4: + { + renderer.playMusic("music/dlvla.wav"); + break; + } + case 5: case 6: case 7: case 8: + { + renderer.playMusic("music/dlvlb.wav"); + break; + } + case 9: case 10: case 11: case 12: + { + renderer.playMusic("music/dlvlc.wav"); + break; + } + case 13: case 14: case 15: case 16: + { + renderer.playMusic("music/dlvld.wav"); + break; + } + } +} + void run(const bpo::variables_map& variables); void runGameLoop(const bpo::variables_map& variables); @@ -356,7 +377,7 @@ void runGameLoop(const bpo::variables_map& variables) FALevelGen::FAsrand(time(NULL)); - std::vector levels(5); + std::vector levels(9); int32_t currentLevel = variables["level"].as(); @@ -381,12 +402,15 @@ void runGameLoop(const bpo::variables_map& variables) player->mPos = FAWorld::Position(level->upStairsPos().first, level->upStairsPos().second); FAGui::showIngameGui(); + + playLevelMusic(currentLevel, renderer); } else { renderer.setLevel(NULL); paused = true; FAGui::showMainMenu(); + renderer.playMusic("music/dintro.wav"); } boost::posix_time::ptime last = boost::posix_time::microsec_clock::local_time(); @@ -454,7 +478,7 @@ void runGameLoop(const bpo::variables_map& variables) currentLevel = tmp; if(levels[currentLevel] == NULL) - levels[currentLevel] = getLevel(currentLevel == 0 ? 0 : 1, exe); + levels[currentLevel] = getLevel(currentLevel, exe); level = levels[currentLevel]; @@ -467,6 +491,7 @@ void runGameLoop(const bpo::variables_map& variables) setLevel(currentLevel, exe, world, renderer, level); + playLevelMusic(currentLevel, renderer); } changeLevel = 0; From 4d1a13ed9317eaacae507676a1fde525b1326ad5 Mon Sep 17 00:00:00 2001 From: Exairnous Date: Tue, 10 Feb 2015 18:53:58 +0000 Subject: [PATCH 4/8] added a hotkey class and changed most functions to use it. I am unable to wrap it for python though, so you can't actually set any hotkeys. This problem will be fixed in future commits. --- apps/freeablo/fagui/guimanager.cpp | 112 ++++-------- apps/freeablo/main.cpp | 113 ++++-------- components/input/common.cpp | 265 ++--------------------------- components/input/common.h | 25 +++ components/input/hotkey.cpp | 69 ++++++++ components/input/hotkey.h | 25 +++ resources/gui/changehotkey.rml | 24 ++- 7 files changed, 212 insertions(+), 421 deletions(-) create mode 100644 components/input/common.h create mode 100644 components/input/hotkey.cpp create mode 100644 components/input/hotkey.h diff --git a/apps/freeablo/fagui/guimanager.cpp b/apps/freeablo/fagui/guimanager.cpp index 4b494b8f6..9b5b82504 100644 --- a/apps/freeablo/fagui/guimanager.cpp +++ b/apps/freeablo/fagui/guimanager.cpp @@ -10,20 +10,21 @@ #include #include -#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 int quit_key[]; // TODO: handle this better -extern int noclip_key[]; // TODO: handle this better -extern int changelvldwn_key[]; // TODO: handle this better -extern int changelvlup_key[]; // 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; @@ -67,99 +68,47 @@ namespace FAGui boost::python::list getHotkeys() { boost::python::list hotkeys; - boost::python::list quit; - boost::python::list noclip; - boost::python::list changelvlup; - boost::python::list changelvldwn; - - quit.append(Input::convertAsciiToRocketKey(quit_key[0])); - noclip.append(Input::convertAsciiToRocketKey(noclip_key[0])); - changelvlup.append(Input::convertAsciiToRocketKey(changelvlup_key[0])); - changelvldwn.append(Input::convertAsciiToRocketKey(changelvldwn_key[0])); + 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); - for (int i=1; i<5; i++) - { - - quit.append(quit_key[i]); - noclip.append(noclip_key[i]); - changelvlup.append(changelvlup_key[i]); - changelvldwn.append(changelvldwn_key[i]); - } - - hotkeys.append(quit); - hotkeys.append(noclip); - hotkeys.append(changelvlup); - hotkeys.append(changelvldwn); + hotkeys.append(pquit_key); + hotkeys.append(pnoclip_key); + hotkeys.append(pchangelvlup_key); + hotkeys.append(pchangelvldwn_key); return hotkeys; } - void setHotkey(boost::python::list hotkey) + void setHotkey(std::string function, Input::Hotkey hotkey) { - std::string function = boost::python::extract(hotkey[0]); - boost::python::list pykeys = boost::python::extract(hotkey[1]); - int keys [5]; - - boost::python::ssize_t n = boost::python::len(pykeys); - for(boost::python::ssize_t i=0;i(pykeys[i]); - //std::cout << keys[i] << std::endl; - } - keys[0] = Input::convertRocketKeyToAscii(keys[0]); - //std::cout << keys[0] << std::endl; + hotkey.key = Input::convertRocketKeyToAscii(hotkey.key); if (function == "quit") { - for (int i=0; i<5; i++) - { - quit_key[i] = keys[i]; - } - hotkeypt.put("Quit.key", quit_key[0]); - hotkeypt.put("Quit.shift", quit_key[1]); - hotkeypt.put("Quit.ctrl", quit_key[2]); - hotkeypt.put("Quit.alt", quit_key[3]); - hotkeypt.put("Quit.super", quit_key[4]); - bpt::write_ini("resources/hotkeys.ini", hotkeypt); + quit_key = hotkey; + quit_key.save("Quit", hotkeypt); } if (function == "noclip") { - for (int i=0; i<5; i++) - { - noclip_key[i] = keys[i]; - } - hotkeypt.put("Noclip.key", noclip_key[0]); - hotkeypt.put("Noclip.shift", noclip_key[1]); - hotkeypt.put("Noclip.ctrl", noclip_key[2]); - hotkeypt.put("Noclip.alt", noclip_key[3]); - hotkeypt.put("Noclip.super", noclip_key[4]); - bpt::write_ini("resources/hotkeys.ini", hotkeypt); + noclip_key = hotkey; + noclip_key.save("Noclip", hotkeypt); } if (function == "changelvlup") { - for (int i=0; i<5 ; i++) - { - changelvlup_key[i] = keys[i]; - } - hotkeypt.put("Changelvlup.key", changelvlup_key[0]); - hotkeypt.put("Changelvlup.shift", changelvlup_key[1]); - hotkeypt.put("Changelvlup.ctrl", changelvlup_key[2]); - hotkeypt.put("Changelvlup.alt", changelvlup_key[3]); - hotkeypt.put("Changelvlup.super", changelvlup_key[4]); - bpt::write_ini("resources/hotkeys.ini", hotkeypt); + changelvlup_key = hotkey; + changelvlup_key.save("Changelvlup", hotkeypt); } if (function == "changelvldwn") { - for (int i=0; i<5; i++) - { - changelvldwn_key[i] = keys[i]; - } - hotkeypt.put("Changelvldwn.key", changelvldwn_key[0]); - hotkeypt.put("Changelvldwn.shift", changelvldwn_key[1]); - hotkeypt.put("Changelvldwn.ctrl", changelvldwn_key[2]); - hotkeypt.put("Changelvldwn.alt", changelvldwn_key[3]); - hotkeypt.put("Changelvldwn.super", changelvldwn_key[4]); - bpt::write_ini("resources/hotkeys.ini", hotkeypt); + changelvldwn_key = hotkey; + changelvldwn_key.save("Changelvldwn", hotkeypt); } } @@ -179,6 +128,7 @@ namespace FAGui void initGui() { initfreeablo(); + Input::inithotkey(); FARender::Renderer* renderer = FARender::Renderer::get(); ingameUi = renderer->getRocketContext()->LoadDocument("resources/gui/bottommenu.rml"); mainMenu = renderer->getRocketContext()->LoadDocument("resources/gui/mainmenu.rml"); diff --git a/apps/freeablo/main.cpp b/apps/freeablo/main.cpp index c140b5ae9..d4e4d8da1 100644 --- a/apps/freeablo/main.cpp +++ b/apps/freeablo/main.cpp @@ -22,6 +22,8 @@ #include #include +#include + namespace bpo = boost::program_options; namespace bfs = boost::filesystem; namespace bpt = boost::property_tree; @@ -31,12 +33,14 @@ bool paused = false; bool noclip = false; int changeLevel = 0; -int hotkey [5]; +Input::Hotkey hotkey; + +Input::InputManager *inputmanager; -int quit_key [5]; -int noclip_key [5]; -int changelvldwn_key [5]; -int changelvlup_key [5]; +Input::Hotkey quit_key; +Input::Hotkey noclip_key; +Input::Hotkey changelvldwn_key; +Input::Hotkey changelvlup_key; bpt::ptree hotkeypt; @@ -44,83 +48,55 @@ void keyPress(Input::Key key) { switch(key) { - case Input::KEY_RSHIFT: hotkey[1] = 1; return; - case Input::KEY_LSHIFT: hotkey[1] = 1; return; - case Input::KEY_RCTRL: hotkey[2] = 1; return; - case Input::KEY_LCTRL: hotkey[2] = 1; return; - case Input::KEY_RALT: hotkey[3] = 1; return; - case Input::KEY_LALT: hotkey[3] = 1; return; - case Input::KEY_RSUPER: hotkey[4] = 1; return; - case Input::KEY_LSUPER: hotkey[4] = 1; return; + case Input::KEY_RSHIFT:; + case Input::KEY_LSHIFT: hotkey.shift = true; return; + case Input::KEY_RCTRL:; + case Input::KEY_LCTRL: hotkey.ctrl = true; return; + case Input::KEY_RALT:; + case Input::KEY_LALT: hotkey.alt = true; return; + case Input::KEY_RSUPER:; + case Input::KEY_LSUPER: hotkey.super = true; return; default: { - hotkey[0] = key; + hotkey.key = key; + uint32_t modifiers = inputmanager->getModifiers(); + std::cout << "modifiers = " << modifiers << std::endl; break; } } - int check = 0; - - while(check<5) - { - //std::cout << "key " << hotkey[check] << " " << changelvldwn_key[check] << std::endl; - check++; - } - check = 0; - - while(check<5 && hotkey[check]==quit_key[check]) - { - //std::cout << "key " << quit_key[check] << std::endl; - check++; - } - if (check == 5) + if (hotkey == quit_key) { done = true; return; } - check = 0; - while(check<5 && hotkey[check]==noclip_key[check]) - { - check++; - } - if (check == 5) + if (hotkey == noclip_key) { noclip = !noclip; return; } - check = 0; - - while(check<5 && hotkey[check]==changelvlup_key[check]) - { - check++; - } - if (check == 5) + + if (hotkey == changelvlup_key) { changeLevel = -1; return; } - check = 0; - while(check<5 && hotkey[check]==changelvldwn_key[check]) - { - check++; - } - if (check == 5) + if (hotkey == changelvldwn_key) { changeLevel = 1; return; } - check = 0; } void keyRelease(Input::Key key) { - hotkey[0] = 0; - hotkey[1] = 0; - hotkey[2] = 0; - hotkey[3] = 0; - hotkey[4] = 0; + hotkey.key = 0; + hotkey.shift = false; + hotkey.ctrl = false; + hotkey.alt = false; + hotkey.super = false; } size_t xClick = 0, yClick = 0; @@ -371,6 +347,7 @@ void runGameLoop(const bpo::variables_map& variables) FARender::Renderer& renderer = *FARender::Renderer::get(); Input::InputManager input(&keyPress, &keyRelease, &mouseClick, &mouseRelease, &mouseMove, renderer.getRocketContext()); + inputmanager = &input; DiabloExe::DiabloExe exe; FAWorld::World world; @@ -419,29 +396,11 @@ void runGameLoop(const bpo::variables_map& variables) Misc::readIni("resources/hotkeys.ini", hotkeypt); - quit_key[0] = hotkeypt.get("Quit.key"); - quit_key[1] = hotkeypt.get("Quit.shift"); - quit_key[2] = hotkeypt.get("Quit.ctrl"); - quit_key[3] = hotkeypt.get("Quit.alt"); - quit_key[4] = hotkeypt.get("Quit.super"); - - noclip_key[0] = hotkeypt.get("Noclip.key"); - noclip_key[1] = hotkeypt.get("Noclip.shift"); - noclip_key[2] = hotkeypt.get("Noclip.ctrl"); - noclip_key[3] = hotkeypt.get("Noclip.alt"); - noclip_key[4] = hotkeypt.get("Noclip.super"); - - changelvlup_key[0] = hotkeypt.get("Changelvlup.key"); - changelvlup_key[1] = hotkeypt.get("Changelvlup.shift"); - changelvlup_key[2] = hotkeypt.get("Changelvlup.ctrl"); - changelvlup_key[3] = hotkeypt.get("Changelvlup.alt"); - changelvlup_key[4] = hotkeypt.get("Changelvlup.super"); - - changelvldwn_key[0] = hotkeypt.get("Changelvldwn.key"); - changelvldwn_key[1] = hotkeypt.get("Changelvldwn.shift"); - changelvldwn_key[2] = hotkeypt.get("Changelvldwn.ctrl"); - changelvldwn_key[3] = hotkeypt.get("Changelvldwn.alt"); - changelvldwn_key[4] = hotkeypt.get("Changelvldwn.super"); + quit_key = Input::Hotkey("Quit", hotkeypt); + noclip_key = Input::Hotkey("Noclip", hotkeypt); + changelvlup_key = Input::Hotkey("Changelvlup", hotkeypt); + changelvldwn_key = Input::Hotkey("Changelvldwn", hotkeypt); + //Input::inithotkey(); // Main game logic loop while(!done) diff --git a/components/input/common.cpp b/components/input/common.cpp index 172905b00..64af1e53d 100644 --- a/components/input/common.cpp +++ b/components/input/common.cpp @@ -1,252 +1,10 @@ #include #include #include -#include "keys.h" -//#include "common.h" - -namespace rci = Rocket::Core::Input; - -/* namespace Input -{ - - Key convertRocketKey(int rocketk) - { - Key key; - - switch(rocketk) - { - case rci::KI_BACK: key = KEY_BACKSPACE; break; - case rci::KI_TAB: key = KEY_TAB; break; - case rci::KI_CLEAR: key = KEY_CLEAR; break; - case rci::KI_RETURN: key = KEY_RETURN; break; - case rci::KI_PAUSE: key = KEY_PAUSE; break; - case rci::KI_ESCAPE: key = KEY_ESCAPE; break; - case rci::KI_SPACE: key = KEY_SPACE; break; - case rci::KI_OEM_8: KEY_QUOTEDBL - case rci::KEY_HASH KEY_HASH - case rci::KEY_DOLLAR KEY_DOLLAR - case rci::KEY_AMPERSAND KEY_AMPERSAND - case rci::KEY_QUOTE KEY_QUOTE - case rci::KEY_LEFTPAREN KEY_LEFTPAREN - case rci::KEY_RIGHTPAREN KEY_RIGHTPAREN - case rci::KEY_ASTERISK KEY_ASTERISK - - case rci::KI_SPACE: key = KEY_SPACE; break; - case rci::KI_0: key = KEY_0; break; - case rci::KI_1: key = KEY_1; break; - case rci::KI_2: key = KEY_2; break; - case rci::KI_3: key = KEY_3; break; - case rci::KI_4: key = KEY_4; break; - case rci::KI_5: key = KEY_5; break; - case rci::KI_6: key = KEY_6; break; - case rci::KI_7: key = KEY_7; break; - case rci::KI_8: key = KEY_8; break; - case rci::KI_9: key = KEY_9; break; - - case rci::KI_A: key = KEY_a; break; - case rci::KI_B: key = KEY_b; break; - case rci::KI_C: key = KEY_c; break; - case rci::KI_D: key = KEY_d; break; - case rci::KI_E: key = KEY_e; break; - case rci::KI_F: key = KEY_f; break; - case rci::KI_G: key = KEY_g; break; - case rci::KI_H: key = KEY_h; break; - case rci::KI_I: key = KEY_i; break; - case rci::KI_J: key = KEY_j; break; - case rci::KI_K: key = KEY_k; break; - case rci::KI_L: key = KEY_l; break; - case rci::KI_M: key = KEY_m; break; - case rci::KI_N: key = KEY_n; break; - case rci::KI_O: key = KEY_o; break; - case rci::KI_P: key = KEY_p; break; - case rci::KI_Q: key = KEY_q; break; - case rci::KI_R: key = KEY_r; break; - case rci::KI_S: key = KEY_s; break; - case rci::KI_T: key = KEY_t; break; - case rci::KI_U: key = KEY_u; break; - case rci::KI_V: key = KEY_v; break; - case rci::KI_W: key = KEY_w; break; - case rci::KI_X: key = KEY_x; break; - case rci::KI_Y: key = KEY_y; break; - case rci::KI_Z: key = KEY_z; break; - - case rci::KI_OEM_1: key = KEY_SEMICOLON - case rci::KI_OEM_PLUS: key = KEY_PLUS - case rci::KI_OEM_COMMA: key = KEY_COMMA - case rci::KI_OEM_MINUS: key = KEY_MINUS - case rci::KI_OEM_PERIODK: key = KEY_PERIOD - case rci::KI_OEM_2: key = KEY_QUESTION - case rci::KI_OEM_3: key = - - case rci::KI_OEM_4: key = - case rci::KI_OEM_5: key = - case rci::KI_OEM_6: key = - case rci::KI_OEM_7: key = - case rci::KI_OEM_8: key = - - case rci::KI_OEM_102: key = -: key = - case rci::KI_NUMPAD0: key = - case rci::KI_NUMPAD1: key = - case rci::KI_NUMPAD2: key = - case rci::KI_NUMPAD3: key = - case rci::KI_NUMPAD4: key = - case rci::KI_NUMPAD5: key = - case rci::KI_NUMPAD6: key = - case rci::KI_NUMPAD7: key = - case rci::KI_NUMPAD8: key = - case rci::KI_NUMPAD9: key = - case rci::KI_NUMPADENTER: key = - case rci::KI_MULTIPLY: key = - case rci::KI_ADD: key = - case rci::KI_SEPARATOR: key = - case rci::KI_SUBTRACT: key = - case rci::KI_DECIMAL: key = - case rci::KI_DIVIDE: key = - - case rci::KI_OEM_NEC_EQUAL: key = - - case rci::KI_BACK: key = - case rci::KI_TAB: key = - - case rci::KI_CLEAR: key = - case rci::KI_RETURN: key = - - case rci::KI_PAUSE: key = - case rci::KI_CAPITAL: key = - - case rci::KI_KANA = 75, - case rci::KI_HANGUL = 76, - case rci::KI_JUNJA = 77, - case rci::KI_FINAL = 78, - case rci::KI_HANJA = 79, - case rci::KI_KANJI = 80, - - case rci::KI_ESCAPE = 81, - - case rci::KI_CONVERT = 82, - case rci::KI_NONCONVERT = 83, - case rci::KI_ACCEPT = 84, - case rci::KI_MODECHANGE = 85, - - case rci::KI_PRIOR = 86, - case rci::KI_NEXT = 87, - case rci::KI_END = 88, - case rci::KI_HOME = 89, - case rci::KI_LEFT = 90, - case rci::KI_UP = 91, - case rci::KI_RIGHT = 92, - case rci::KI_DOWN = 93, - case rci::KI_SELECT = 94, - case rci::KI_PRINT = 95, - case rci::KI_EXECUTE = 96, - case rci::KI_SNAPSHOT = 97, - case rci::KI_INSERT = 98, - case rci::KI_DELETE = 99, - case rci::KI_HELP = 100, - - case rci::KI_LWIN = 101, - case rci::KI_RWIN = 102, - case rci::KI_APPS = 103, - - case rci::KI_POWER = 104, - case rci::KI_SLEEP = 105, - case rci::KI_WAKE = 106, - - case rci::KI_F1 = 107, - case rci::KI_F2 = 108, - case rci::KI_F3 = 109, - case rci::KI_F4 = 110, - case rci::KI_F5 = 111, - case rci::KI_F6 = 112, - case rci::KI_F7 = 113, - case rci::KI_F8 = 114, - case rci::KI_F9 = 115, - case rci::KI_F10 = 116, - case rci::KI_F11 = 117, - case rci::KI_F12 = 118, - case rci::KI_F13 = 119, - case rci::KI_F14 = 120, - case rci::KI_F15 = 121, - case rci::KI_F16 = 122, - case rci::KI_F17 = 123, - case rci::KI_F18 = 124, - case rci::KI_F19 = 125, - case rci::KI_F20 = 126, - case rci::KI_F21 = 127, - case rci::KI_F22 = 128, - case rci::KI_F23 = 129, - case rci::KI_F24 = 130, - - case rci::KI_NUMLOCK = 131, - case rci::KI_SCROLL = 132, - - case rci::KI_OEM_FJ_JISHO = 133, - case rci::KI_OEM_FJ_MASSHOU = 134, - case rci::KI_OEM_FJ_TOUROKU = 135, - case rci::KI_OEM_FJ_LOYA = 136, - case rci::KI_OEM_FJ_ROYA = 137, - - case rci::KI_LSHIFT = 138, - case rci::KI_RSHIFT = 139, - case rci::KI_LCONTROL = 140, - case rci::KI_RCONTROL = 141, - case rci::KI_LMENU = 142, - case rci::KI_RMENU = 143, - - case rci::KI_BROWSER_BACK = 144, - case rci::KI_BROWSER_FORWARD = 145, - case rci::KI_BROWSER_REFRESH = 146, - case rci::KI_BROWSER_STOP = 147, - case rci::KI_BROWSER_SEARCH = 148, - case rci::KI_BROWSER_FAVORITES = 149, - case rci::KI_BROWSER_HOME = 150, - - case rci::KI_VOLUME_MUTE = 151, - case rci::KI_VOLUME_DOWN = 152, - case rci::KI_VOLUME_UP = 153, - case rci::KI_MEDIA_NEXT_TRACK = 154, - case rci::KI_MEDIA_PREV_TRACK = 155, - case rci::KI_MEDIA_STOP = 156, - case rci::KI_MEDIA_PLAY_PAUSE = 157, - case rci::KI_LAUNCH_MAIL = 158, - case rci::KI_LAUNCH_MEDIA_SELECT = 159, - case rci::KI_LAUNCH_APP1 = 160, - case rci::KI_LAUNCH_APP2 = 161, - - case rci::KI_OEM_AX = 162, - case rci::KI_ICO_HELP = 163, - case rci::KI_ICO_00 = 164, - - case rci::KI_PROCESSKEY = 165, - - case rci::KI_ICO_CLEAR = 166, - - case rci::KI_ATTN = 167, - case rci::KI_CRSEL = 168, - case rci::KI_EXSEL = 169, - case rci::KI_EREOF = 170, - case rci::KI_PLAY = 171, - case rci::KI_ZOOM = 172, - case rci::KI_PA1 = 173, - case rci::KI_OEM_CLEAR = 174, - - case rci::KI_LMETA = 175, - case rci::KI_RMETA = 176 - default: - { - key = KEY_UNDEF; - break; - } - } - } -}*/ +#include "common.h" 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) { Key key; @@ -380,14 +138,11 @@ namespace Input } - #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 rocketk) + int convertAsciiToRocketKey(int asciik) { int key; - switch(rocketk) + switch(asciik) { ATRCASE2(BACKSPACE, BACK); ATRCASE(TAB); @@ -516,27 +271,27 @@ namespace Input } - std::string getHotkeyName(int key []) + std::string getHotkeyName(Hotkey key) { std::string hotkeyname; - if (key[1]) + if (key.shift) { hotkeyname += "SHIFT + "; } - if (key[2]) + if (key.ctrl) { hotkeyname += "CTRL + "; } - if (key[3]) + if (key.alt) { hotkeyname += "ALT + "; } - if (key[4]) + if (key.super) { hotkeyname += "META + "; } - switch(key[0]) + switch(key.key) { case Input::KEY_F1: hotkeyname += "F1"; break; case Input::KEY_F2: hotkeyname += "F2"; break; @@ -589,7 +344,7 @@ namespace Input default: { - hotkeyname += std::toupper(char(key[0])); + hotkeyname += std::toupper(char(key.key)); } } 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..23f02e1c7 --- /dev/null +++ b/components/input/hotkey.cpp @@ -0,0 +1,69 @@ +#include "hotkey.h" +#include +#include +#include + + +namespace Input +{ + Hotkey::Hotkey(){} + + 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"); + super = hotkeypt.get(sname + ".super"); + } + + Hotkey::Hotkey(int nkey, bool nshift, bool nctrl, bool nalt, bool nsuper) + { + key = nkey; + shift = nshift; + ctrl = nctrl; + alt = nalt; + super = nsuper; + } + + bool Hotkey::operator==(const Hotkey &other) + { + if (key == other.key && shift == other.shift && ctrl == other.ctrl && alt == other.alt && super == other.super) + { + 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", shift); + hotkeypt.put(sname + ".ctrl", ctrl); + hotkeypt.put(sname + ".alt", alt); + hotkeypt.put(sname + ".super", super); + bpt::write_ini("resources/hotkeys.ini", hotkeypt); + } + + BOOST_PYTHON_MODULE(hotkey) + { + boost::python::class_("Hotkey") + .def(boost::python::init()) + .def(boost::python::init()) + .def(boost::python::self == boost::python::self) + .def("save", &Hotkey::save) + .def_readwrite("key", &Hotkey::key) + .def_readwrite("shift", &Hotkey::shift) + .def_readwrite("ctrl", &Hotkey::ctrl) + .def_readwrite("alt", &Hotkey::alt) + .def_readwrite("super", &Hotkey::super); + } + +} diff --git a/components/input/hotkey.h b/components/input/hotkey.h new file mode 100644 index 000000000..01b9877f6 --- /dev/null +++ b/components/input/hotkey.h @@ -0,0 +1,25 @@ +#ifndef HOTKEY_H +#define HOTKEY_H + +#include + +namespace bpt = boost::property_tree; + +namespace Input +{ + class Hotkey + { + public: + int key; + bool shift, ctrl, alt, super; + + Hotkey(); + Hotkey(const char *name, bpt::ptree hotkeypt); + Hotkey(int nkey, bool nshift, bool nctrl, bool nalt, bool nsuper); + bool operator==(const Hotkey &other); + void save(const char *name, bpt::ptree hotkeypt); + }; +} + +#endif /* HOTKEY_H */ + diff --git a/resources/gui/changehotkey.rml b/resources/gui/changehotkey.rml index 7583149ee..c35a4b488 100644 --- a/resources/gui/changehotkey.rml +++ b/resources/gui/changehotkey.rml @@ -30,10 +30,14 @@ diff --git a/resources/hotkeys.ini b/resources/hotkeys.ini index 74ebec670..1e0f1a29d 100644 --- a/resources/hotkeys.ini +++ b/resources/hotkeys.ini @@ -3,22 +3,18 @@ key=113 shift=0 ctrl=0 alt=0 -super=0 [Noclip] key=110 shift=0 ctrl=0 alt=0 -super=0 [Changelvlup] key=111 shift=0 ctrl=0 alt=0 -super=0 [Changelvldwn] key=112 shift=0 ctrl=0 alt=0 -super=0 diff --git a/resources/python/menu.py b/resources/python/menu.py index 6dd319664..921a8f5b3 100644 --- a/resources/python/menu.py +++ b/resources/python/menu.py @@ -68,7 +68,8 @@ def onKeyDown(self, event): elif event.parameters['key_identifier'] == rocket.key_identifier.RETURN: currentEntry = self.entries[self.current] if("func" in currentEntry): - currentEntry["func"]() + currentEntry["func"](currentEntry["args"]) if "args" in currentEntry \ + else currentEntry["func"]() return True return False From c6745f71046a80f44be98e7e4a8e3bd8c294aaee Mon Sep 17 00:00:00 2001 From: Exairnous Date: Fri, 3 Apr 2015 03:56:39 +0000 Subject: [PATCH 6/8] fixed crash on key press --- apps/freeablo/main.cpp | 5 ++--- components/CMakeLists.txt | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/freeablo/main.cpp b/apps/freeablo/main.cpp index 2ca361d59..ece19c2b0 100644 --- a/apps/freeablo/main.cpp +++ b/apps/freeablo/main.cpp @@ -36,8 +36,6 @@ bool paused = false; bool noclip = false; int changeLevel = 0; -Input::InputManager *inputmanager; - Input::Hotkey quit_key; Input::Hotkey noclip_key; Input::Hotkey changelvldwn_key; @@ -65,8 +63,9 @@ void keyPress(Input::Key key) Input::Hotkey hotkey; hotkey.key = key; + Input::InputManager& input = *Input::InputManager::get(); - uint32_t modifiers = inputmanager->getModifiers(); + uint32_t modifiers = input.getModifiers(); switch(modifiers) { diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 5e1a32acc..f91d95909 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -58,7 +58,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}") From 734270c330c0809ab9653d6c1f72810aa628c404 Mon Sep 17 00:00:00 2001 From: Exairnous Date: Wed, 8 Apr 2015 14:59:24 +0000 Subject: [PATCH 7/8] updated error message when changing hotkeys and cleaned up code --- apps/freeablo/fagui/guimanager.cpp | 4 +- apps/freeablo/main.cpp | 8 +-- resources/gui/changehotkey.rml | 74 +++++++++++--------------- resources/gui/changehotkeyerrormsg.rml | 43 +++++++-------- resources/gui/hotkeymenu.rml | 44 ++++++++------- resources/gui/pausemenu.rml | 16 ++---- resources/python/docmanage.py | 21 ++++++-- 7 files changed, 103 insertions(+), 107 deletions(-) diff --git a/apps/freeablo/fagui/guimanager.cpp b/apps/freeablo/fagui/guimanager.cpp index 3734f1a5d..bd25fd55a 100644 --- a/apps/freeablo/fagui/guimanager.cpp +++ b/apps/freeablo/fagui/guimanager.cpp @@ -93,7 +93,9 @@ namespace FAGui 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; diff --git a/apps/freeablo/main.cpp b/apps/freeablo/main.cpp index ece19c2b0..c0dd2b491 100644 --- a/apps/freeablo/main.cpp +++ b/apps/freeablo/main.cpp @@ -54,7 +54,9 @@ void keyPress(Input::Key key) case Input::KEY_RALT:; case Input::KEY_LALT:; case Input::KEY_RSUPER:; - case Input::KEY_LSUPER: return; + case Input::KEY_LSUPER:; + case Input::KEY_NUMLOCK:; + case Input::KEY_SCROLLOCK: return; default: { break; @@ -419,9 +421,9 @@ 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 = Input::Hotkey("Quit", hotkeypt); noclip_key = Input::Hotkey("Noclip", hotkeypt); changelvlup_key = Input::Hotkey("Changelvlup", hotkeypt); diff --git a/resources/gui/changehotkey.rml b/resources/gui/changehotkey.rml index 1046f4d02..8d87e3fa0 100644 --- a/resources/gui/changehotkey.rml +++ b/resources/gui/changehotkey.rml @@ -6,39 +6,41 @@ font-family: FreeMono; font-size: 24; text-align: center; - background-color: rgba(0,0,0,255); - height: 100%; - width: 100%; - #height: 25%; - #width: 25%; - #left: 37%; - #top: 37%; } div#topContainer { - position:absolute; - top: 50%; + position: absolute; + top: 280px; } + + span#smlogo + { + icon-decorator: faanim; + icon-animfile: /ui_art/smlogo.pcx&trans=0,255,0&vanim=154; + icon-playtime: 0.8; - div#menuContainer + display: inline-block; + width: 390px; + height: 154px; + } + + div#innerTopContainer { position: absolute; - top: -50px; + top: 200px; } @@ -128,11 +121,8 @@ def showHotkeys(): onkeyup="onKeyUp(event, document)" onload="onLoad(document)">
- +
+
diff --git a/resources/gui/changehotkeyerrormsg.rml b/resources/gui/changehotkeyerrormsg.rml index b35370085..8ae2d0024 100644 --- a/resources/gui/changehotkeyerrormsg.rml +++ b/resources/gui/changehotkeyerrormsg.rml @@ -6,55 +6,52 @@ font-family: FreeMono; font-size: 24; text-align: center; - background-color: rgba(255 ,0,0,255); - height: 100%; - width: 100%; - #height: 25%; - #width: 25%; - #left: 37%; - #top: 37%; } div#topContainer { - position:absolute; - top: 50%; + position: absolute; + top: 280px; } - - div#menuContainer + + div#innerTopContainer { position: absolute; - top: -50px; + top: 250px; }
- +
diff --git a/resources/gui/hotkeymenu.rml b/resources/gui/hotkeymenu.rml index a7795bed0..ea90fa44f 100644 --- a/resources/gui/hotkeymenu.rml +++ b/resources/gui/hotkeymenu.rml @@ -17,19 +17,26 @@ span#smlogo { - icon-decorator: image; - icon-image-src: /ui_art/smlogo.pcx; - icon-image-t-end: 154px; - + icon-decorator: faanim; + icon-animfile: /ui_art/smlogo.pcx&trans=0,255,0&vanim=154; + icon-playtime: 0.8; + display: inline-block; width: 390px; height: 154px; } - img.pentagon + span.pentagon { + icon-decorator: faanim; + icon-playtime: 0.3; + icon-animfile: /data/PentSpin.cel; + position: relative; + display: inline-block; top: 16px; + width: 48px; + height: 48px; } @@ -38,17 +45,12 @@ import rocket import freeablo +import docmanage from menu import Menu -context = rocket.contexts['default'] -doc = None hotkeyMenu = None def onLoad(document): - document.id = "hotkeymenu" - global doc - doc = document - hotkeynames = freeablo.getHotkeyNames() entries = [ @@ -59,8 +61,8 @@ def onLoad(document): {"text": 'Previous', "strFunc": "showPause", "func": showPause} ] - fmtSelected = ' %s ' - fmtNotSelected = ' %s ' + fmtSelected = ' %s ' + fmtNotSelected = '