fysxasteroids/asteroids/View.h

172 lines
4.8 KiB
C
Raw Normal View History

2010-04-05 23:38:59 +02:00
#ifndef _VIEW_H
#define _VIEW_H
#include "ViewBase.h"
#include "OverlayBase.h"
2010-04-05 23:38:59 +02:00
#include "mathlib.h"
#include "Sprite.h"
#include "EntityBase.h"
#include "SimpleConsoleOverlay.h"
#include "AsteroidsEnums.h"
2010-04-05 23:38:59 +02:00
namespace asteroids {
struct ShipEntity;
struct AsteroidEntity;
struct RocketEntity;
struct BackgroundStar {
vector3d position;
};
/** \brief Performs the actual drawing based on Camera and Model
*
* This View also takes care of the drawn user interface. There are different
* view states that are drawn by the member functions with signatures
* DrawUi{ViewStateName}(). Different view states can be pushed onto and
* popped from the mViewStateStack which allows non-linear arrangement
* of different ViewStates in menus.
2010-04-05 23:38:59 +02:00
*/
class View : public Engine::ViewBase {
public:
virtual ~View() {};
2011-02-12 17:04:44 +01:00
/** \brief Pushes the given state onto mViewStateStack */
void PushViewState (const ViewState state) {
Engine::LogDebug ("Pushing ViewState %s", GetStringViewState(state));
mViewStateStack.push(state);
// Fire the view state change event to properly clear the IMGUI state
Engine::EventBasePtr changeviewstate_event (new Engine::EventBase());
changeviewstate_event->mEventType = EventChangeViewState;
QueueEvent (changeviewstate_event);
}
/** \brief Returns the current ViewState */
ViewState GetViewState () {
return mViewStateStack.top();
}
/** \brief Removes the top element of the current ViewState stack */
void PopViewState () {
// Warning: you must not query for an invalid enum with
// GetStringENUM_NAME!
std::string popped_name = GetStringViewState(mViewStateStack.top());
mViewStateStack.pop();
std::string current_name ("None");
if (mViewStateStack.size() > 0)
current_name = GetStringViewState(mViewStateStack.top());
2011-03-15 10:21:26 +01:00
Engine::LogDebug("Popped ViewState: %s current %s remaining: %u",
popped_name.c_str(), current_name.c_str(), mViewStateStack.size());
2011-02-12 17:04:44 +01:00
if (mViewStateStack.size() == 0) {
Engine::LogDebug ("No ViewState on the stack! Quitting.");
Engine::RunCommand("quit");
}
2011-02-12 17:04:44 +01:00
// Fire the view state change event to properly clear the IMGUI state
Engine::EventBasePtr changeviewstate_event (new Engine::EventBase());
changeviewstate_event->mEventType = EventChangeViewState;
QueueEvent (changeviewstate_event);
}
2010-04-05 23:38:59 +02:00
protected:
/** \brief Initializes the system */
virtual int OnInit (int argc, char* argv[]);
virtual void OnDestroy ();
2010-04-05 23:38:59 +02:00
/** \brief Updates the camera for further drawing */
virtual void UpdateCamera ();
private:
void DrawUi();
2010-11-13 18:45:15 +01:00
void DrawPageTitle(const std::string &title);
void DrawUiMainMenu();
void DrawUiGameRunning();
void DrawUiGameOver();
2011-03-22 23:01:44 +01:00
void DrawUiLevelIntro();
void DrawUiLevelComplete();
void DrawUiGamePaused();
void DrawUiPlayerDied();
2011-03-15 10:21:26 +01:00
void DrawHighscoreEntry(float x, float y, float entry_width,
const std::string &name, unsigned int points);
void DrawUiHighscore();
void DrawUiOptions();
void DrawUiEnterPlayername();
2011-03-15 10:21:26 +01:00
void DrawUiCredits();
2011-01-02 18:25:20 +01:00
void DrawUiEditor();
virtual void Draw ();
2010-04-05 23:38:59 +02:00
virtual void DrawWorld ();
2011-01-02 18:25:20 +01:00
void DrawEntities();
2010-04-05 23:38:59 +02:00
void DrawStars ();
void DrawEntity (Engine::EntityBase *entity);
void DrawShip (ShipEntity *ship);
void DrawAsteroid (AsteroidEntity *asteroid);
void DrawRocket (RocketEntity *asteroid);
void DrawShipPart (Engine::EntityBase *entity);
std::vector<BackgroundStar> mBackgroundStars;
std::vector<unsigned int> mShipPartsEntityIds;
/** \brief The ViewState stack that is used for non-linear menus */
std::stack<ViewState> mViewStateStack;
/** \brief Removes all elements of the ViewState stack */
void ResetViewState() {
Engine::LogDebug ("Resetting ViewState stack");
while (mViewStateStack.size())
mViewStateStack.pop();
// Fire the view state change event to properly clear the IMGUI state
Engine::EventBasePtr changeviewstate_event (new Engine::EventBase());
changeviewstate_event->mEventType = EventChangeViewState;
QueueEvent (changeviewstate_event);
}
// \todo [high] add Resource Manager!
Engine::Sprite mGUIShipSprite;
2010-04-05 23:38:59 +02:00
Engine::Sprite mAsteroidSprite;
Engine::Sprite mShipSprite;
Engine::Sprite mShipThrustSprite;
Engine::Sprite mShipPartsSprite;
float screen_left;
float screen_right;
float screen_top;
float screen_bottom;
2010-04-05 23:38:59 +02:00
2010-11-13 18:45:15 +01:00
int button_width;
int button_height;
2011-01-02 18:25:20 +01:00
enum EditorState {
EditorStateUnknown = 0,
EditorStateAddEntity,
EditorStateDelEntity,
2011-01-02 18:25:20 +01:00
EditorStateMoveEntity,
EditorStateRotateEntity,
2011-01-02 18:25:20 +01:00
EditorStateSave,
EditorStateEntityVelocity,
EditorStateLoad,
EditorStateTest
};
EditorState mEditorState;
unsigned int mEditorEntityId;
2011-03-15 10:21:26 +01:00
unsigned int mCreditsPageIndex;
/// \brief can be used to perform some fading, etc.
float mFadeTimerSecValue;
virtual bool OnReceiveEvent (const Engine::EventBasePtr &event);
2010-04-05 23:38:59 +02:00
};
}
#endif // _VIEW_H