From cc00129542c82cdcff7686feef08d2d84cf152c3 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 12 May 2013 02:33:08 +1000 Subject: [PATCH] Implemented the splash screen and config file --- client/scene_manager.cpp | 17 +++++- client/singleton.hpp | 31 +++++++++++ client/splash.cpp | 65 +++++++++-------------- client/splash.hpp | 28 +++++----- rsc/config.cfg | 16 ++++++ rsc/graphics/fonts/pokemon_dark_font.bmp | Bin 0 -> 66614 bytes 6 files changed, 104 insertions(+), 53 deletions(-) create mode 100644 client/singleton.hpp create mode 100644 rsc/config.cfg create mode 100644 rsc/graphics/fonts/pokemon_dark_font.bmp diff --git a/client/scene_manager.cpp b/client/scene_manager.cpp index d2651da..01000d7 100644 --- a/client/scene_manager.cpp +++ b/client/scene_manager.cpp @@ -1,5 +1,8 @@ #include "scene_manager.hpp" +#include "singleton.hpp" +#include "config_utility.hpp" + #include //------------------------- @@ -36,7 +39,19 @@ void SceneManager::Init() { if (SDL_Init(SDL_INIT_VIDEO)) throw(std::runtime_error("Failed to initialize SDL")); - BaseScene::SetScreen(800, 600); + GetSingletonPtr()->Load("rsc\\config.cfg"); + + //set the screen from the config file + int flags = SDL_HWSURFACE|SDL_DOUBLEBUF; + if (GetSingletonPtr()->Boolean("screen.f")) { + flags |= SDL_FULLSCREEN; + } + BaseScene::SetScreen( + GetSingletonPtr()->Integer("screen.w"), + GetSingletonPtr()->Integer("screen.h"), + 0, + flags + ); } void SceneManager::Proc() { diff --git a/client/singleton.hpp b/client/singleton.hpp new file mode 100644 index 0000000..e741a33 --- /dev/null +++ b/client/singleton.hpp @@ -0,0 +1,31 @@ +#ifndef SINGLETON_HPP_ +#define SINGLETON_HPP_ + +/* +template +class Singleton { +public: + static T* GetSingletonPtr() { + return &singleton; + } + static T& GetSingletonRef() { + return singleton; + } +private: + Singleton(); + ~Singleton(); + Singleton(const Singleton&); + Singleton& operator=(const Singleton&); + Singleton(Singleton&&); + Singleton& operator=(Singleton&&); + static T singleton; +}; +*/ + +template +T* GetSingletonPtr() { + static T t; + return &t; +} + +#endif diff --git a/client/splash.cpp b/client/splash.cpp index ddd3917..dc6ac12 100644 --- a/client/splash.cpp +++ b/client/splash.cpp @@ -12,58 +12,43 @@ Splash::Splash() { #ifdef DEBUG cout << "entering Splash" << endl; #endif + loaded = false; + start = clock(); + configUtil = GetSingletonPtr(); + surfaceMgr = GetSingletonPtr(); + + logo = new Image(surfaceMgr->Load("logo", configUtil->String("logos") + "/krstudios.bmp")); } Splash::~Splash() { + delete logo; + surfaceMgr->Free("logo"); #ifdef DEBUG cout << "leaving Splash" << endl; #endif } -//------------------------- -//Frame loop -//------------------------- +void Splash::RunFrame() { + //skip any event handling here -void Splash::FrameStart() { - // -} + //draw the logo in the middle of the screen + int x = (GetScreen()->w - logo->GetClipW()) / 2; + int y = (GetScreen()->h - logo->GetClipH()) / 2; -void Splash::FrameEnd() { - // -} + logo->DrawTo(GetScreen(),x,y); + SDL_Flip(GetScreen()); -void Splash::Update() { - // -} + if (!loaded) { + LoadResources(); + } -void Splash::Render(SDL_Surface* const screen) { - // -} - -//------------------------- -//Event handlers -//------------------------- - -void Splash::MouseMotion(SDL_MouseMotionEvent const& motion) { - // -} - -void Splash::MouseButtonDown(SDL_MouseButtonEvent const& button) { - // -} - -void Splash::MouseButtonUp(SDL_MouseButtonEvent const& button) { - // -} - -void Splash::KeyDown(SDL_KeyboardEvent const& key) { - switch(key.keysym.sym) { - case SDLK_ESCAPE: - QuitEvent(); - break; + if (clock() - start > CLOCKS_PER_SEC*3) { + SetNextScene(SceneList::MAINMENU); } } -void Splash::KeyUp(SDL_KeyboardEvent const& key) { - // -} +void Splash::LoadResources() { + //load the resources during the splash screen + //TODO + loaded = true; +} \ No newline at end of file diff --git a/client/splash.hpp b/client/splash.hpp index 9522c11..6288ecd 100644 --- a/client/splash.hpp +++ b/client/splash.hpp @@ -3,25 +3,29 @@ #include "base_scene.hpp" +#include "singleton.hpp" +#include "config_utility.hpp" +#include "surface_manager.hpp" +#include "image.hpp" + +#include + class Splash : public BaseScene { public: - /* Public access members */ Splash(); virtual ~Splash(); protected: - /* Frame loop */ - virtual void FrameStart(); - virtual void FrameEnd(); - virtual void Update(); - virtual void Render(SDL_Surface* const); + virtual void RunFrame(); - /* Event handlers */ - virtual void MouseMotion(SDL_MouseMotionEvent const&); - virtual void MouseButtonDown(SDL_MouseButtonEvent const&); - virtual void MouseButtonUp(SDL_MouseButtonEvent const&); - virtual void KeyDown(SDL_KeyboardEvent const&); - virtual void KeyUp(SDL_KeyboardEvent const&); + void LoadResources(); + + bool loaded; + time_t start; + + ConfigUtility* configUtil; + SurfaceManager* surfaceMgr; + Image* logo; }; #endif diff --git a/rsc/config.cfg b/rsc/config.cfg new file mode 100644 index 0000000..9fe6af0 --- /dev/null +++ b/rsc/config.cfg @@ -0,0 +1,16 @@ +#configuration of the program +ip = 127.0.0.1 +port = 2000 +screen.w = 800 +screen.h = 600 +screen.f = false + +#directories +fonts = rsc\graphics\fonts +logos = rsc\graphics\logos +sprites = rsc\graphics\sprites +tilesets = rsc\graphics\tilesets + +#debugging +debug = true +avatar = elliot2.bmp diff --git a/rsc/graphics/fonts/pokemon_dark_font.bmp b/rsc/graphics/fonts/pokemon_dark_font.bmp new file mode 100644 index 0000000000000000000000000000000000000000..97b23e0aba2af180d7b4dca6d86b64f6cae49cdd GIT binary patch literal 66614 zcmeHOJ96a66~siWK}%HhrBzq+m;AR`2deugZNwd;ls(nBy9M#u!2Aq!;fy0L@wkO2ZP zPLLV0K-R~+J+1>}giMebvOw0Z!?2rs$N(836J&-gkQGICkRCEXM#u!2Aq!;fI{b8N z4;dgMWP;3)1+sQShcde!68}cX1eqZVWZhcpdt3*|2$>)=WPz+(+e44*02v_@WQHt| zb)#hLaUCEdWP;3)1+s2*O+BsyWQ0tR8L~jujmo*lb%2bJ2{J<#$hy(I^tcX?5i&t$ z$O2j05)5mP>i`)c6J&-gkhPo8|J3!6=zN64zZtSX)^6%MNDmnxBV>ZikOi`C%Qp15 z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