diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index bd14469..cc8740b 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp @@ -295,6 +295,53 @@ bool isConfirmEvent(const SDL_Event& event) { return false; } + +bool Menu::IsActive() { + return running; +} +void Menu::Draw(SDL_Renderer* target) { + placeButtons(); + drawSelf(); + SDL_RenderPresent(target); +} +void Menu::ProcessInput(const SDL_Event& event, bool &processed) { + if ( event.type == SDL_QUIT ) { + Config::getInstance()->setShuttingDown(5); + running = false; + processed = true; + } + + if (isUpEvent(event)) { + marked--; + if (marked<0) { + marked = buttons.size(); //not -1, since exit is after the last element in the list + } + } + + if (isDownEvent(event)) { + marked++; + if (marked> (int)buttons.size()) { + marked = 0; + } + } + + if (isEscapeEvent(event) && isSubmenu) { + running = false; + } + + if (isConfirmEvent(event)) { + if (marked < (int)buttons.size()) { + buttons.at(marked)->doAction(); + if (buttons.at(marked)->isPopOnRun()) { + running = false; + } + } + if (marked == (int)buttons.size()) { + running = false; + } + } +} + void Menu::run() { running = true; bool bMouseUp = false; diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h index ea03c46..d893ddb 100644 --- a/source/code/MenuSystem.h +++ b/source/code/MenuSystem.h @@ -30,6 +30,7 @@ http://blockattack.net #include #include "Libs/NFont.h" #include "sago/SagoSprite.hpp" +#include "sago/GameStateInterface.hpp" #include //The ButtonGfx object hold common media for all buttons, so we can reskin them by only changeing one pointer @@ -83,7 +84,7 @@ public: }; -class Menu +class Menu : public sago::GameStateInterface { private: std::vector buttons; //Vector holder the buttons @@ -101,12 +102,17 @@ public: Menu(SDL_Renderer *screen,bool isSubmenu); Menu(SDL_Renderer *screen); Menu(SDL_Renderer *screen, const std::string& title, bool isSubmenu); - + virtual ~Menu() {} + //Add a button to the menu void addButton(Button *b); //Run the menu void run(); + + bool IsActive() override; + void Draw(SDL_Renderer* target) override; + void ProcessInput(const SDL_Event& event, bool &processed) override; }; class FileMenu