moved menu states into separate directory
This commit is contained in:
@@ -34,6 +34,14 @@ BEGIN_ENUM(LogLevel)
|
||||
}
|
||||
END_ENUM(LogLevel)
|
||||
|
||||
BEGIN_ENUM(FontJustification)
|
||||
{
|
||||
DECL_ENUM_ELEMENT(FontJustificationRight),
|
||||
DECL_ENUM_ELEMENT(FontJustificationCenter),
|
||||
DECL_ENUM_ELEMENT(FontJustificationLeft)
|
||||
}
|
||||
END_ENUM(FontJustification)
|
||||
|
||||
|
||||
}
|
||||
#endif /* _ENGINEENUMS_H */
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
#include "OverlayBase.h"
|
||||
#include "ModelBase.h"
|
||||
|
||||
namespace Engine {
|
||||
|
||||
void OverlayManager::InitOverlays() {
|
||||
std::map<unsigned int, std::list<OverlayBasePtr> >::iterator map_iter = mOverlays.begin();
|
||||
|
||||
if (map_iter == mOverlays.end())
|
||||
return;
|
||||
|
||||
while (map_iter != mOverlays.end()) {
|
||||
std::list<OverlayBasePtr>::iterator list_iter = map_iter->second.begin();
|
||||
|
||||
while (list_iter != map_iter->second.end()) {
|
||||
(*list_iter)->Init ();
|
||||
list_iter++;
|
||||
}
|
||||
|
||||
map_iter ++;
|
||||
}
|
||||
}
|
||||
|
||||
void OverlayManager::Draw () {
|
||||
ModelBase *model = EngineGetModel();
|
||||
assert (model);
|
||||
|
||||
std::map<unsigned int, std::list<OverlayBasePtr> >::iterator map_iter = mOverlays.find(model->mGameState);
|
||||
|
||||
if (map_iter == mOverlays.end())
|
||||
return;
|
||||
|
||||
std::list<OverlayBasePtr>::iterator list_iter = map_iter->second.begin();
|
||||
|
||||
while (list_iter != map_iter->second.end()) {
|
||||
(*list_iter)->Draw ();
|
||||
list_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
void OverlayManager::Register (OverlayBasePtr overlay, unsigned int game_state) {
|
||||
LogDebug ("Adding overlay 0x%x state: %u", &overlay, game_state);
|
||||
|
||||
mOverlays[game_state].push_back(overlay);
|
||||
}
|
||||
|
||||
/* Input forwarding for the overlays */
|
||||
bool OverlayManager::SendKeyDown (const SDL_keysym &keysym) {
|
||||
ModelBase *model = EngineGetModel();
|
||||
assert (model);
|
||||
|
||||
std::map<unsigned int, std::list<OverlayBasePtr> >::iterator map_iter = mOverlays.find(model->mGameState);
|
||||
|
||||
if (map_iter == mOverlays.end())
|
||||
return false;
|
||||
|
||||
std::list<OverlayBasePtr>::iterator list_iter = map_iter->second.begin();
|
||||
|
||||
while (list_iter != map_iter->second.end()) {
|
||||
if ((*list_iter)->OnKeyDown (keysym))
|
||||
return true;
|
||||
|
||||
list_iter++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OverlayManager::SendKeyUp (const SDL_keysym &keysym) {
|
||||
ModelBase *model = EngineGetModel();
|
||||
assert (model);
|
||||
|
||||
std::map<unsigned int, std::list<OverlayBasePtr> >::iterator map_iter = mOverlays.find(model->mGameState);
|
||||
|
||||
if (map_iter == mOverlays.end())
|
||||
return false;
|
||||
|
||||
std::list<OverlayBasePtr>::iterator list_iter = map_iter->second.begin();
|
||||
|
||||
while (list_iter != map_iter->second.end()) {
|
||||
if ((*list_iter)->OnKeyUp (keysym))
|
||||
return true;
|
||||
|
||||
list_iter++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OverlayManager::SendMouseButtonUp (Uint8 button, Uint16 xpos, Uint16 ypos) {
|
||||
ModelBase *model = EngineGetModel();
|
||||
assert (model);
|
||||
|
||||
std::map<unsigned int, std::list<OverlayBasePtr> >::iterator map_iter = mOverlays.find(model->mGameState);
|
||||
|
||||
if (map_iter == mOverlays.end())
|
||||
return false;
|
||||
|
||||
std::list<OverlayBasePtr>::iterator list_iter = map_iter->second.begin();
|
||||
|
||||
while (list_iter != map_iter->second.end()) {
|
||||
if ((*list_iter)->OnMouseButtonUp (button, xpos, ypos))
|
||||
return true;
|
||||
|
||||
list_iter++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OverlayManager::SendMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos) {
|
||||
ModelBase *model = EngineGetModel();
|
||||
assert (model);
|
||||
|
||||
std::map<unsigned int, std::list<OverlayBasePtr> >::iterator map_iter = mOverlays.find(model->mGameState);
|
||||
|
||||
if (map_iter == mOverlays.end())
|
||||
return false;
|
||||
|
||||
std::list<OverlayBasePtr>::iterator list_iter = map_iter->second.begin();
|
||||
|
||||
while (list_iter != map_iter->second.end()) {
|
||||
if ((*list_iter)->OnMouseButtonDown (button, xpos, ypos))
|
||||
return true;
|
||||
|
||||
list_iter++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+13
-3
@@ -12,12 +12,22 @@ namespace Engine {
|
||||
class ModelBase;
|
||||
|
||||
/** \brief Base class for user-interfaces
|
||||
*
|
||||
* An Overlay is something that is displayed above the game graphics e.g.
|
||||
* such as a health indicator for the player or the user interface such as
|
||||
* the menu or the console. The member function OverlayBase::Draw() is used
|
||||
* for drawing and also receives input such as key press events and mouse
|
||||
* button events.
|
||||
*
|
||||
* The function OverlayBase::Init() is called by the OverlayManager class and
|
||||
* allows the OverlayBase to load its ressources.
|
||||
*/
|
||||
class OverlayBase {
|
||||
public:
|
||||
OverlayBase () {};
|
||||
virtual ~OverlayBase() {};
|
||||
|
||||
/** \brief This function gets called by the OverlayManager class */
|
||||
virtual void Init() {};
|
||||
|
||||
virtual bool OnKeyDown (const SDL_keysym &keysym) { return false; };
|
||||
@@ -25,22 +35,22 @@ class OverlayBase {
|
||||
virtual bool OnMouseButtonUp (Uint8 button, Uint16 xpos, Uint16 ypos) { return false; };
|
||||
virtual bool OnMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos) { return false; };
|
||||
|
||||
/** \brief Draws the content of the Overlay */
|
||||
virtual void Draw () = 0;
|
||||
|
||||
void _strange_function_for_vtable () {};
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<OverlayBase> OverlayBasePtr;
|
||||
|
||||
/** \brief Takes care of all OverlayBase classes and proxies input and drawing with regard to the current game state of ModelBase
|
||||
*
|
||||
* \node You need to set the ModelBase pointer manually by calling OverlayManager::SetModel()!
|
||||
* \note You need to set the ModelBase pointer manually by calling OverlayManager::SetModel()!
|
||||
*/
|
||||
class OverlayManager {
|
||||
public:
|
||||
/** \brief Calls OverlayBase::Init() for all registered Overlays */
|
||||
void InitOverlays();
|
||||
|
||||
/** \brief Draws the Overlays associated with the current game state */
|
||||
void Draw();
|
||||
void Register (OverlayBasePtr overlay, unsigned int game_state);
|
||||
|
||||
|
||||
@@ -371,6 +371,14 @@ void SelectFont (const char* font) {
|
||||
ViewInstance->SelectFont(font);
|
||||
}
|
||||
|
||||
void SetFontJustification (FontJustification justification) {
|
||||
if (!ViewInstance) {
|
||||
LogError ("Cannot select font: View not yet initialized!");
|
||||
return;
|
||||
}
|
||||
ViewInstance->SetFontJustification (justification);
|
||||
}
|
||||
|
||||
unsigned int GetWindowWidth() {
|
||||
return ViewInstance->GetWindowWidth ();
|
||||
}
|
||||
|
||||
+1
-6
@@ -2,6 +2,7 @@
|
||||
#define _VIEWBASE_H
|
||||
|
||||
#include "Engine.h"
|
||||
#include "EngineEnums.h"
|
||||
#include "OverlayBase.h"
|
||||
|
||||
// forward declarations for the OGLFT fonts
|
||||
@@ -11,12 +12,6 @@ namespace OGLFT {
|
||||
|
||||
namespace Engine {
|
||||
|
||||
enum FontJustification {
|
||||
FontJustificationRight = 0,
|
||||
FontJustificationCenter,
|
||||
FontJustificationLeft
|
||||
};
|
||||
|
||||
class Module;
|
||||
class ModelBase;
|
||||
class CameraBase;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
#ifndef _VIEWGLOBAL_H
|
||||
#define _VIEWGLOBAL_H
|
||||
|
||||
#include "EngineEnums.h"
|
||||
|
||||
namespace Engine {
|
||||
|
||||
/** \brief Draws the given string at the given position using the current
|
||||
* OpenGL transformations */
|
||||
void DrawGLString (float x, float y, const char* str);
|
||||
void SelectFont (const char* font);
|
||||
void SetFontJustification (FontJustification justification);
|
||||
|
||||
unsigned int GetWindowWidth();
|
||||
unsigned int GetWindowHeight();
|
||||
|
||||
Reference in New Issue
Block a user