2010-04-05 23:38:59 +02:00
|
|
|
#ifndef _VIEW_H
|
|
|
|
#define _VIEW_H
|
|
|
|
|
|
|
|
#include "ViewBase.h"
|
2010-04-14 22:01:45 +02:00
|
|
|
#include "OverlayBase.h"
|
2010-04-05 23:38:59 +02:00
|
|
|
#include "mathlib.h"
|
|
|
|
#include "Sprite.h"
|
|
|
|
#include "EntityBase.h"
|
2010-04-14 22:01:45 +02:00
|
|
|
#include "SimpleConsoleOverlay.h"
|
2010-11-22 20:00:44 +01:00
|
|
|
#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
|
2010-11-28 00:20:58 +01:00
|
|
|
*
|
|
|
|
* 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 {
|
2010-04-14 22:01:45 +02:00
|
|
|
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());
|
|
|
|
|
|
|
|
Engine::LogDebug("Popped ViewState: %s current %s remaining: %u", popped_name.c_str(), current_name.c_str(), mViewStateStack.size());
|
|
|
|
|
|
|
|
// 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 */
|
2010-04-14 22:01:45 +02:00
|
|
|
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:
|
2010-09-16 00:04:39 +02:00
|
|
|
void DrawUi();
|
|
|
|
|
2010-11-13 18:45:15 +01:00
|
|
|
void DrawPageTitle(const std::string &title);
|
|
|
|
|
2010-09-16 00:04:39 +02:00
|
|
|
void DrawUiMainMenu();
|
|
|
|
void DrawUiGameRunning();
|
|
|
|
void DrawUiGameOver();
|
|
|
|
void DrawUiLevelComplete();
|
|
|
|
void DrawUiGamePaused();
|
|
|
|
void DrawUiPlayerDied();
|
2010-11-13 18:45:15 +01:00
|
|
|
void DrawHighscoreEntry(float x, float y, float entry_width, const std::string &name, unsigned int points);
|
2010-09-16 00:04:39 +02:00
|
|
|
void DrawUiHighscore();
|
2010-11-22 20:00:44 +01:00
|
|
|
void DrawUiOptions();
|
2010-09-16 00:04:39 +02:00
|
|
|
void DrawUiEnterPlayername();
|
|
|
|
|
2011-01-02 18:25:20 +01:00
|
|
|
void DrawUiEditor();
|
|
|
|
|
2010-09-16 00:04:39 +02:00
|
|
|
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;
|
|
|
|
|
2010-11-28 00:20:58 +01:00
|
|
|
/** \brief The ViewState stack that is used for non-linear menus */
|
2010-11-22 20:00:44 +01:00
|
|
|
std::stack<ViewState> mViewStateStack;
|
|
|
|
|
2010-11-28 00:20:58 +01:00
|
|
|
/** \brief Removes all elements of the ViewState stack */
|
|
|
|
void ResetViewState() {
|
|
|
|
Engine::LogDebug ("Resetting ViewState stack");
|
|
|
|
while (mViewStateStack.size())
|
|
|
|
mViewStateStack.pop();
|
2010-11-28 01:13:45 +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-11-22 20:00:44 +01:00
|
|
|
}
|
|
|
|
|
2010-09-16 00:04:39 +02:00
|
|
|
// \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;
|
2010-09-16 00:04:39 +02:00
|
|
|
|
|
|
|
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,
|
2011-01-02 21:04:11 +01:00
|
|
|
EditorStateDelEntity,
|
2011-01-02 18:25:20 +01:00
|
|
|
EditorStateMoveEntity,
|
2011-02-12 15:43:06 +01:00
|
|
|
EditorStateRotateEntity,
|
2011-01-02 18:25:20 +01:00
|
|
|
EditorStateSave,
|
|
|
|
EditorStateEntityVelocity,
|
|
|
|
EditorStateLoad,
|
|
|
|
EditorStateTest
|
|
|
|
};
|
|
|
|
|
|
|
|
EditorState mEditorState;
|
|
|
|
unsigned int mEditorEntityId;
|
|
|
|
|
2010-11-28 00:20:58 +01:00
|
|
|
/// \brief can be used to perform some fading, etc.
|
|
|
|
float mFadeTimerSecValue;
|
|
|
|
|
2010-07-28 18:02:12 +02:00
|
|
|
virtual bool OnReceiveEvent (const Engine::EventBasePtr &event);
|
2010-04-05 23:38:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _VIEW_H
|