diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-04-28 15:28:18 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-04-28 15:28:18 -0400 |
commit | 18380eb2e6443c2736b4958b01e7ba2fe2cfa318 (patch) | |
tree | 32a32d9061613445702f05ff64f42206ee27848f /src | |
parent | cbfec643e85c2ca6516195bec8df77c33525a87f (diff) |
ui menu fix
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.cpp | 1 | ||||
-rw-r--r-- | src/ui_menu.cpp | 86 | ||||
-rw-r--r-- | src/window.cpp | 1 | ||||
-rw-r--r-- | src/world.cpp | 4 |
4 files changed, 50 insertions, 42 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index dc7aa77..970904b 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -40,6 +40,7 @@ void Engine::init(void) { systems.add<AttackSystem>(); systems.add<UISystem>(); + systems.add<SDLReceiver>(); systems.configure(); diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp index b49f0e9..08d45e7 100644 --- a/src/ui_menu.cpp +++ b/src/ui_menu.cpp @@ -9,10 +9,38 @@ #include <fstream> -extern vec2 offset; - static Menu* currentMenu = nullptr; +void SDLReceiver::receive(const MainSDLEvent& mse) +{ + switch (mse.event.type) { + case SDL_QUIT: + game::endGame(); + return; + break; + case SDL_MOUSEMOTION: + //ui::premouse.x = e.motion.x; + //ui::premouse.y = e.motion.y; + break; + case SDL_MOUSEBUTTONUP: + if (mse.event.button.button & SDL_BUTTON_LEFT) + clicked = true; + break; + case SDL_KEYUP: + if (currentMenu != nullptr && mse.event.key.keysym.sym == SDLK_ESCAPE) { + currentMenu->gotoParent(); + return; + } + break; + default: + break; + } +} + +bool SDLReceiver::clicked = false; + +extern vec2 offset; + static Menu pauseMenu; static Menu optionsMenu; static Menu controlsMenu; @@ -216,10 +244,6 @@ namespace ui { auto& SCREEN_WIDTH = game::SCREEN_WIDTH; auto& SCREEN_HEIGHT = game::SCREEN_HEIGHT; - SDL_Event e; - - bool clicked = false; - Render::useShader(&Render::textShader); game::config::update(); @@ -230,31 +254,6 @@ namespace ui { mouse.y = (offset.y+SCREEN_HEIGHT/2)-ui::premouse.y; //custom event polling for menu's so all other events are ignored - while(SDL_PollEvent(&e)) { - switch (e.type) { - case SDL_QUIT: - game::endGame(); - return; - break; - case SDL_MOUSEMOTION: - premouse.x=e.motion.x; - premouse.y=e.motion.y; - break; - case SDL_MOUSEBUTTONUP: - if (e.button.button & SDL_BUTTON_LEFT) { - clicked = true; - } - break; - case SDL_KEYUP: - if (SDL_KEY == SDLK_ESCAPE) { - currentMenu->gotoParent(); - return; - } - break; - default:break; - } - } - static float cMult = 1.0f; static const ColorTex back (Color(0, 0, 0, 204)); @@ -283,18 +282,21 @@ namespace ui { cMult = 0.6f; //if the mouse is over the button and clicks - if (clicked) { - switch(m.member) { - case 0: //normal button - m.button.func(); - break; - case -1: - currentMenu = m.child; - break; - case -2: - currentMenu->gotoParent(); - default:break; + if (SDLReceiver::clicked) { + switch (m.member) { + case 0: //normal button + m.button.func(); + break; + case -1: + currentMenu = m.child; + break; + case -2: + currentMenu->gotoParent(); + default: + break; } + + SDLReceiver::clicked = false; } } diff --git a/src/window.cpp b/src/window.cpp index 7d8f8e7..df584be 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -35,6 +35,7 @@ WindowSystem::WindowSystem(void) } Mix_AllocateChannels(8); atexit(Mix_Quit); + atexit(Mix_CloseAudio); // create the SDL window object window = SDL_CreateWindow(WINDOW_TITLE, diff --git a/src/world.cpp b/src/world.cpp index e87d6d0..29f77a2 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -562,6 +562,10 @@ WorldSystem::WorldSystem(void) WorldSystem::~WorldSystem(void) { +} + +void WorldSystem::die(void) +{ // SDL2_mixer's object if (bgmObj != nullptr) Mix_FreeMusic(bgmObj); |