From f3ec4d4d8e453c16e7e7db3f44bf15ce32c49fe1 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 12 Jun 2013 19:15:37 +1000 Subject: [PATCH] Splash screen loads and displays correctly --- client/scene_manager.cpp | 4 +++ client/splash_screen.cpp | 68 +++++++++++++++++++--------------------- client/splash_screen.hpp | 26 +++++++++------ 3 files changed, 52 insertions(+), 46 deletions(-) diff --git a/client/scene_manager.cpp b/client/scene_manager.cpp index a5267cc..59374ba 100644 --- a/client/scene_manager.cpp +++ b/client/scene_manager.cpp @@ -137,6 +137,10 @@ void SceneManager::Proc() { void SceneManager::Quit() { //clean up the services + netUtil->Close(); + surfaceMgr->FreeAll(); + + //delete the services configUtil = ServiceLocator::Set(nullptr); surfaceMgr = ServiceLocator::Set(nullptr); netUtil = ServiceLocator::Set(nullptr); diff --git a/client/splash_screen.cpp b/client/splash_screen.cpp index b80ba8b..11c45a2 100644 --- a/client/splash_screen.cpp +++ b/client/splash_screen.cpp @@ -12,9 +12,11 @@ SplashScreen::SplashScreen() { #ifdef DEBUG cout << "entering SplashScreen" << endl; #endif + logo.SetSurface(surfaceMgr->Load("splash-logo", configUtil->String("logos") + "/krstudios.bmp")); } SplashScreen::~SplashScreen() { + surfaceMgr->Free("splash-logo"); #ifdef DEBUG cout << "leaving SplashScreen" << endl; #endif @@ -24,46 +26,40 @@ SplashScreen::~SplashScreen() { //Frame loop //------------------------- -void SplashScreen::FrameStart() { - // -} +void SplashScreen::RunFrame(double delta) { + HandleEvents(); + if (!loaded) { + //never repeat this + loaded = true; -void SplashScreen::Update(double delta) { - // -} + //quick draw + RenderFrame(); -void SplashScreen::FrameEnd() { - // -} + LoadResources(); + } -void SplashScreen::Render(SDL_Surface* const screen) { - // -} - -//------------------------- -//Event handlers -//------------------------- - -void SplashScreen::MouseMotion(SDL_MouseMotionEvent const& motion) { - // -} - -void SplashScreen::MouseButtonDown(SDL_MouseButtonEvent const& button) { - // -} - -void SplashScreen::MouseButtonUp(SDL_MouseButtonEvent const& button) { - // -} - -void SplashScreen::KeyDown(SDL_KeyboardEvent const& key) { - switch(key.keysym.sym) { - case SDLK_ESCAPE: - QuitEvent(); - break; + if (Clock::now() - start > std::chrono::duration(1)) { + SetNextScene(SceneList::MAINMENU); } } -void SplashScreen::KeyUp(SDL_KeyboardEvent const& key) { - // +void SplashScreen::RenderFrame() { + SDL_FillRect(GetScreen(), 0, 0); + int x = (GetScreen()->w - logo.GetClipW()) / 2; + int y = (GetScreen()->h - logo.GetClipH()) / 2; + logo.DrawTo(GetScreen(), x, y); + SDL_Flip(GetScreen()); +} + +void SplashScreen::LoadResources() { + //standard + surfaceMgr->Load("font", configUtil->String("fonts") + "/pokemon_dark_font.bmp"); + surfaceMgr->Load("button", configUtil->String("interface") + "/button.bmp"); + + //debugging + surfaceMgr->Load("elliot", configUtil->String("sprites") + "/elliot2.bmp"); + surfaceMgr->Load("coa", configUtil->String("sprites") + "/coa2.bmp"); + surfaceMgr->Load("flower", configUtil->String("sprites") + "/aniflower.bmp"); + surfaceMgr->Load("terrain", configUtil->String("tilesets") + "/terrain.bmp"); + //TODO } diff --git a/client/splash_screen.hpp b/client/splash_screen.hpp index 13eca79..0fdd562 100644 --- a/client/splash_screen.hpp +++ b/client/splash_screen.hpp @@ -2,6 +2,14 @@ #define SPLASHSCREEN_HPP_ #include "base_scene.hpp" +#include "service_locator.hpp" +#include "defines.hpp" + +#include "config_utility.hpp" +#include "surface_manager.hpp" +#include "image.hpp" + +#include class SplashScreen : public BaseScene { public: @@ -11,17 +19,15 @@ public: protected: /* Frame loop */ - void FrameStart(); - void Update(double delta); - void FrameEnd(); - void Render(SDL_Surface* const); + void RunFrame(double delta); + void RenderFrame(); + void LoadResources(); - /* Event handlers */ - void MouseMotion(SDL_MouseMotionEvent const&); - void MouseButtonDown(SDL_MouseButtonEvent const&); - void MouseButtonUp(SDL_MouseButtonEvent const&); - void KeyDown(SDL_KeyboardEvent const&); - void KeyUp(SDL_KeyboardEvent const&); + bool loaded = false; + ConfigUtility* configUtil = ServiceLocator::Get(); + SurfaceManager* surfaceMgr = ServiceLocator::Get(); + Image logo; + Clock::time_point start = Clock::now(); }; #endif