diff --git a/abstractAppState.h b/abstractAppState.h index 80005ce..dd9b347 100644 --- a/abstractAppState.h +++ b/abstractAppState.h @@ -4,6 +4,7 @@ #include "key.h" #include +#include namespace battleship{ enum class AppStateTypes {GUI_STATE,IN_GAME_STATE,ACTIVE_STATE}; @@ -22,10 +23,10 @@ namespace battleship{ virtual void update(){} virtual void onAction(Mapping::Bind, bool){} virtual void onAnalog(Mapping::Bind, double){} - /* - virtual void onRawKeyPress(irr::SEvent::SKeyInput){} - virtual void onRawMousePress(irr::SEvent::SMouseInput){} - */ + virtual void onRawKeyPress(vb01::u8){} + virtual void onRawMousePress(vb01::u8){} + virtual void onRawJoystickAxis(vb01::u8, float){} + virtual void onRawJoystickKeyPress(vb01::u8){} private: bool attached = false; std::vector attachedKeys; diff --git a/eventListener.cpp b/eventListener.cpp index 589b221..b00bff2 100644 --- a/eventListener.cpp +++ b/eventListener.cpp @@ -97,28 +97,24 @@ namespace battleship{ } } - /* - for(int i=0;i<350;i++){ - if(glfwGetKey(window,i)) - a->onRawKeyButton(i); - else if(glfwGetMouseButton(window,i)) - a->onRawMouseButton(i); + for(int i = 0; i < 350; i++){ + if(glfwGetKey(window, i)) + a->onRawKeyPress(i); + else if(glfwGetMouseButton(window, i)) + a->onRawMousePress(i); } - */ glfwSetCursorPosCallback(window,foo); - /* if(glfwJoystickPresent(GLFW_JOYSTICK_1)){ - for(int i=0;ionRawJoystickAxis(i,axis[i]); + for(int i = 0; i < numAxis; i++) + if(abs(axis[i]) == 1) + a->onRawJoystickAxis(i, axis[i]); - for(int i=0;ionRawJoystickButton(i); + a->onRawJoystickKeyPress(i); } - */ } } } diff --git a/guiAppState.cpp b/guiAppState.cpp index 5389d31..c5ee85c 100755 --- a/guiAppState.cpp +++ b/guiAppState.cpp @@ -205,20 +205,22 @@ namespace battleship{ } } - /* - void GuiAppState::onRawKeyPress(SEvent::SKeyInput event){ - updateControlsListbox(event.Key); + void GuiAppState::onRawKeyPress(u8 trigger){ + Button *button = nullptr; + + for(Button *b : buttons) + if(b->getTrigger() == trigger){ + button = b; + break; + } + + if(button) + button->onClick(); } - void GuiAppState::onRawMousePress(SEvent::SMouseInput event){ - int trigger=0; - if(event.isMiddlePressed()) - trigger=1; - else if(event.isRightPressed()) - trigger=2; + void GuiAppState::onRawMousePress(u8 trigger){ updateControlsListbox(trigger); } - */ Textbox* GuiAppState::getOpenTextbox() { Textbox* t = nullptr; diff --git a/guiAppState.h b/guiAppState.h index bdc5ce6..c1a1378 100755 --- a/guiAppState.h +++ b/guiAppState.h @@ -45,10 +45,8 @@ namespace battleship{ private: virtual void onAction(Mapping::Bind, bool); virtual void onAnalog(Mapping::Bind, double); - /* - virtual void onRawKeyPress(irr::SEvent::SKeyInput); - virtual void onRawMousePress(irr::SEvent::SMouseInput); - */ + virtual void onRawKeyPress(vb01::u8); + virtual void onRawMousePress(vb01::u8); vb01Gui::Textbox* getOpenTextbox(); vb01Gui::Listbox* getOpenListbox(); void attachBindKeys(); diff --git a/util.cpp b/util.cpp index e058ec3..12c62b3 100755 --- a/util.cpp +++ b/util.cpp @@ -18,7 +18,7 @@ namespace battleship{ class SpButton : public Button { public: - SpButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) { + SpButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_S, separate) { this->state = state; } @@ -35,7 +35,7 @@ namespace battleship{ class PlayButton : public Button { public: - PlayButton(Listbox **difficulties, Listbox **factions, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) { + PlayButton(Listbox **difficulties, Listbox **factions, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_P, separate) { this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE)); this->lengths[0]=lengths[0]; this->lengths[1]=lengths[1]; @@ -74,7 +74,7 @@ namespace battleship{ class ReturnButton : public Button { public: - ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", -1, separate) { + ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, PATH + "Fonts/batang.ttf", GLFW_KEY_B, separate) { this->state = state; } @@ -93,7 +93,6 @@ namespace battleship{ }; GameManager *gm = GameManager::getSingleton(); - //IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp"); Vector2 pos(gm->getWidth() / 8, gm->getHeight() / 8); difficulties.push_back("Easy"); difficulties.push_back("Medium"); @@ -112,9 +111,11 @@ namespace battleship{ Listbox *playerFaction = new Listbox(Vector2(pos.x + 110, pos.y), Vector2(100, 20), factions, 2, font); Listbox **difficultyListboxes=new Listbox*[1]; Listbox **factionListboxes=new Listbox*[2]; + difficultyListboxes[0]=cpuDifficulty; factionListboxes[0]=playerFaction; factionListboxes[1]=cpuFaction; + int lengths[]{1,2}; PlayButton *playButton = new PlayButton(difficultyListboxes, factionListboxes, lengths, Vector2(50, gm->getHeight() - 150), Vector2(140, 50), "Play", true); ReturnButton *returnButton = new ReturnButton(state, Vector2(200, gm->getHeight() - 150), Vector2(140, 50), "Back", true);