intermediate commit: restructuring view states
parent
652367b824
commit
3cbbedde7e
|
@ -19,16 +19,24 @@ BEGIN_ENUM(GameEntityType)
|
||||||
}
|
}
|
||||||
END_ENUM(GameEntityType)
|
END_ENUM(GameEntityType)
|
||||||
|
|
||||||
|
BEGIN_ENUM(ViewState)
|
||||||
|
{
|
||||||
|
DECL_ENUM_ELEMENT(ViewStateMainMenu),
|
||||||
|
DECL_ENUM_ELEMENT(ViewStateGameRunning),
|
||||||
|
DECL_ENUM_ELEMENT(ViewStatePaused),
|
||||||
|
DECL_ENUM_ELEMENT(ViewStatePlayerDied),
|
||||||
|
DECL_ENUM_ELEMENT(ViewStateLevelComplete),
|
||||||
|
DECL_ENUM_ELEMENT(ViewStateShowHighscore),
|
||||||
|
DECL_ENUM_ELEMENT(ViewStateEnterPlayername),
|
||||||
|
DECL_ENUM_ELEMENT(ViewStateOptions),
|
||||||
|
DECL_ENUM_ELEMENT(ViewStateGameOver)
|
||||||
|
}
|
||||||
|
END_ENUM(ViewState)
|
||||||
|
|
||||||
BEGIN_ENUM(GameState)
|
BEGIN_ENUM(GameState)
|
||||||
{
|
{
|
||||||
DECL_ENUM_ELEMENT(GameStateMainMenu),
|
|
||||||
DECL_ENUM_ELEMENT(GameStateRunning),
|
DECL_ENUM_ELEMENT(GameStateRunning),
|
||||||
DECL_ENUM_ELEMENT(GameStatePaused),
|
DECL_ENUM_ELEMENT(GameStatePaused),
|
||||||
DECL_ENUM_ELEMENT(GameStatePlayerDied),
|
|
||||||
DECL_ENUM_ELEMENT(GameStateLevelComplete),
|
|
||||||
DECL_ENUM_ELEMENT(GameStateShowHighscore),
|
|
||||||
DECL_ENUM_ELEMENT(GameStateEnterPlayername),
|
|
||||||
DECL_ENUM_ELEMENT(GameStateGameOver)
|
|
||||||
}
|
}
|
||||||
END_ENUM(GameState)
|
END_ENUM(GameState)
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@ int Model::OnInit (int argc, char* argv[]) {
|
||||||
|
|
||||||
ModelInstance = this;
|
ModelInstance = this;
|
||||||
|
|
||||||
mGameState = GameStateMainMenu;
|
mGameState = GameStatePaused;
|
||||||
mLastGameState = GameStateMainMenu;
|
mLastGameState = GameStatePaused;
|
||||||
|
|
||||||
/// \TODO use <optional> or similar for initialization of mCurrentLevelIndex
|
/// \TODO use <optional> or similar for initialization of mCurrentLevelIndex
|
||||||
mCurrentLevelIndex = 99999;
|
mCurrentLevelIndex = 99999;
|
||||||
|
@ -62,6 +62,7 @@ int Model::OnInit (int argc, char* argv[]) {
|
||||||
// initialize event handlers and register them
|
// initialize event handlers and register them
|
||||||
Engine::RegisterListener (this, EventLevelComplete);
|
Engine::RegisterListener (this, EventLevelComplete);
|
||||||
Engine::RegisterListener (this, EventGameOver);
|
Engine::RegisterListener (this, EventGameOver);
|
||||||
|
Engine::RegisterListener (this, EventShipExplode);
|
||||||
|
|
||||||
mPlayerName = "Player";
|
mPlayerName = "Player";
|
||||||
|
|
||||||
|
@ -84,6 +85,9 @@ bool Model::OnReceiveEvent (const Engine::EventBasePtr &event) {
|
||||||
case EventLevelComplete:
|
case EventLevelComplete:
|
||||||
return OnLevelComplete();
|
return OnLevelComplete();
|
||||||
break;
|
break;
|
||||||
|
case EventShipExplode:
|
||||||
|
OnShipExplode();
|
||||||
|
break;
|
||||||
case EventGameOver:
|
case EventGameOver:
|
||||||
return OnGameOver();
|
return OnGameOver();
|
||||||
break;
|
break;
|
||||||
|
@ -110,36 +114,6 @@ void Model::Process () {
|
||||||
// some action.
|
// some action.
|
||||||
Engine::LogDebug ("Switching from %s->%s", GetStringGameState(mLastGameState), GetStringGameState(mGameState));
|
Engine::LogDebug ("Switching from %s->%s", GetStringGameState(mLastGameState), GetStringGameState(mGameState));
|
||||||
|
|
||||||
if ( (mLastGameState == GameStateMainMenu && mGameState == GameStateRunning)
|
|
||||||
|| (mLastGameState == GameStateEnterPlayername && mGameState == GameStateRunning)){
|
|
||||||
OnNewGame();
|
|
||||||
}
|
|
||||||
else if (mLastGameState == GameStateRunning && mGameState == GameStatePlayerDied) {
|
|
||||||
mPlayerLives --;
|
|
||||||
|
|
||||||
ClearEntities();
|
|
||||||
|
|
||||||
if (mPlayerLives == 0) {
|
|
||||||
Engine::EventBasePtr gameover_event (new Engine::EventBase());
|
|
||||||
gameover_event->mEventType = EventGameOver;
|
|
||||||
QueueEvent (gameover_event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (mLastGameState == GameStateLevelComplete && mGameState == GameStateRunning) {
|
|
||||||
mCurrentLevelIndex++;
|
|
||||||
if (mCurrentLevelIndex == mLevelList.size()) {
|
|
||||||
Engine::EventBasePtr gameover_event (new Engine::EventBase());
|
|
||||||
gameover_event->mEventType = EventGameOver;
|
|
||||||
QueueEvent (gameover_event);
|
|
||||||
} else {
|
|
||||||
DoLoadLevel(mLevelList[mCurrentLevelIndex].c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (mLastGameState == GameStatePlayerDied && mGameState == GameStateRunning)
|
|
||||||
DoLoadLevel(mLevelList[mCurrentLevelIndex].c_str());
|
|
||||||
else if (mLastGameState == GameStateRunning && mGameState == GameStateGameOver)
|
|
||||||
ClearEntities();
|
|
||||||
|
|
||||||
// ... and we have to set the last game state to the current gamestate
|
// ... and we have to set the last game state to the current gamestate
|
||||||
// otherwise we end up in an infinite loop of performing the switching
|
// otherwise we end up in an infinite loop of performing the switching
|
||||||
// action.
|
// action.
|
||||||
|
@ -391,24 +365,31 @@ void Model::SetGameState (const unsigned int &state) {
|
||||||
bool Model::OnLevelComplete() {
|
bool Model::OnLevelComplete() {
|
||||||
Engine::LogMessage ("Level complete!");
|
Engine::LogMessage ("Level complete!");
|
||||||
|
|
||||||
|
mCurrentLevelIndex++;
|
||||||
|
|
||||||
if (mCurrentLevelIndex + 1 == mLevelList.size()) {
|
if (mCurrentLevelIndex + 1 == mLevelList.size()) {
|
||||||
Engine::EventBasePtr gameover_event (new Engine::EventBase());
|
Engine::EventBasePtr gameover_event (new Engine::EventBase());
|
||||||
gameover_event->mEventType = EventGameOver;
|
gameover_event->mEventType = EventGameOver;
|
||||||
QueueEvent (gameover_event);
|
QueueEvent (gameover_event);
|
||||||
} else {
|
} else {
|
||||||
SetGameState (GameStateLevelComplete);
|
DoLoadLevel(mLevelList[mCurrentLevelIndex].c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetGameState(GameStatePaused);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Model::OnGameOver() {
|
bool Model::OnGameOver() {
|
||||||
|
ClearEntities();
|
||||||
|
|
||||||
Engine::LogMessage ("Points = %d lowest = %d", mPoints, mHighscoreList.back().points );
|
Engine::LogMessage ("Points = %d lowest = %d", mPoints, mHighscoreList.back().points );
|
||||||
|
|
||||||
if (mPoints > mHighscoreList.back().points) {
|
if (mPoints > mHighscoreList.back().points) {
|
||||||
Engine::LogMessage ("New Highscore!");
|
Engine::LogMessage ("New Highscore!");
|
||||||
AddHighscoreEntry (mPlayerName, mPoints);
|
AddHighscoreEntry (mPlayerName, mPoints);
|
||||||
}
|
}
|
||||||
SetGameState(GameStateGameOver);
|
SetGameState(GameStatePaused);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -421,6 +402,22 @@ void Model::OnNewGame() {
|
||||||
DoLoadLevel (mLevelList[mCurrentLevelIndex].c_str());
|
DoLoadLevel (mLevelList[mCurrentLevelIndex].c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Model::OnShipExplode () {
|
||||||
|
mPlayerLives --;
|
||||||
|
|
||||||
|
ClearEntities();
|
||||||
|
|
||||||
|
if (mPlayerLives == 0) {
|
||||||
|
Engine::EventBasePtr gameover_event (new Engine::EventBase());
|
||||||
|
gameover_event->mEventType = EventGameOver;
|
||||||
|
QueueEvent (gameover_event);
|
||||||
|
} else {
|
||||||
|
DoLoadLevel(mLevelList[mCurrentLevelIndex].c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
SetGameState(GameStatePaused);
|
||||||
|
}
|
||||||
|
|
||||||
void Model::OnCreateEntity (const int type, const unsigned int id) {
|
void Model::OnCreateEntity (const int type, const unsigned int id) {
|
||||||
GameEntityType entity_type = (GameEntityType) type;
|
GameEntityType entity_type = (GameEntityType) type;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ class Model : public Engine::ModelBase {
|
||||||
bool OnGameOver();
|
bool OnGameOver();
|
||||||
/** \brief Resets values from a previous game */
|
/** \brief Resets values from a previous game */
|
||||||
void OnNewGame ();
|
void OnNewGame ();
|
||||||
|
void OnShipExplode ();
|
||||||
|
|
||||||
virtual void SetGameState (const unsigned int &state);
|
virtual void SetGameState (const unsigned int &state);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ void ShipEntity::Update (float delta_sec) {
|
||||||
|
|
||||||
if (mFadeTimer <= 0.) {
|
if (mFadeTimer <= 0.) {
|
||||||
Model *model = (Model*) Engine::EngineGetModel();
|
Model *model = (Model*) Engine::EngineGetModel();
|
||||||
model->SetGameState (GameStatePlayerDied);
|
model->SetGameState (GameStatePaused);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,8 @@ int View::OnInit (int argc, char* argv[]) {
|
||||||
Engine::RegisterListener (this, EventAccelerateStop);
|
Engine::RegisterListener (this, EventAccelerateStop);
|
||||||
Engine::RegisterListener (this, EventShipExplode);
|
Engine::RegisterListener (this, EventShipExplode);
|
||||||
|
|
||||||
|
PushViewState (ViewStateMainMenu);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,34 +357,42 @@ void View::DrawUi () {
|
||||||
SetFontJustification (Engine::FontJustificationLeft);
|
SetFontJustification (Engine::FontJustificationLeft);
|
||||||
GetController()->EnableTextinput(true);
|
GetController()->EnableTextinput(true);
|
||||||
|
|
||||||
switch (game_state) {
|
ViewState current_view_state = GetViewState();
|
||||||
case GameStateMainMenu:
|
|
||||||
|
SelectFont ("console.ttf size=12");
|
||||||
|
Engine::GUI::Label (99999, GetStringViewState(current_view_state), 8, 16);
|
||||||
|
|
||||||
|
switch (current_view_state) {
|
||||||
|
case ViewStateMainMenu:
|
||||||
DrawUiMainMenu();
|
DrawUiMainMenu();
|
||||||
break;
|
break;
|
||||||
case GameStateRunning:
|
case ViewStateGameRunning:
|
||||||
DrawUiGameRunning();
|
DrawUiGameRunning();
|
||||||
break;
|
break;
|
||||||
case GameStatePaused:
|
case ViewStatePaused:
|
||||||
DrawUiGamePaused();
|
DrawUiGamePaused();
|
||||||
break;
|
break;
|
||||||
case GameStatePlayerDied:
|
case ViewStatePlayerDied:
|
||||||
DrawUiPlayerDied();
|
DrawUiPlayerDied();
|
||||||
break;
|
break;
|
||||||
case GameStateLevelComplete:
|
case ViewStateLevelComplete:
|
||||||
DrawUiLevelComplete();
|
DrawUiLevelComplete();
|
||||||
break;
|
break;
|
||||||
case GameStateShowHighscore:
|
case ViewStateShowHighscore:
|
||||||
DrawUiHighscore();
|
DrawUiHighscore();
|
||||||
break;
|
break;
|
||||||
case GameStateEnterPlayername:
|
case ViewStateOptions:
|
||||||
|
DrawUiOptions();
|
||||||
|
break;
|
||||||
|
case ViewStateEnterPlayername:
|
||||||
DrawUiEnterPlayername();
|
DrawUiEnterPlayername();
|
||||||
break;
|
break;
|
||||||
case GameStateGameOver:
|
case ViewStateGameOver:
|
||||||
DrawUiGameOver();
|
DrawUiGameOver();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Engine::LogWarning ("Trying to draw unknown GameState: %s (%d)",
|
Engine::LogWarning ("Trying to draw unknown ViewState: %s (%d)",
|
||||||
GetStringGameState (game_state), game_state);
|
GetStringViewState (game_state), game_state);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,14 +422,18 @@ void View::DrawUiMainMenu() {
|
||||||
|
|
||||||
SelectFont("console.ttf size=23");
|
SelectFont("console.ttf size=23");
|
||||||
if (Engine::GUI::Button (1, "New Game", screen_right * 0.5 - 100, 200, button_width, button_height)) {
|
if (Engine::GUI::Button (1, "New Game", screen_right * 0.5 - 100, 200, button_width, button_height)) {
|
||||||
GetModel()->SetGameState(GameStateEnterPlayername);
|
PushViewState(ViewStateEnterPlayername);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (2, "Highscores", screen_right * 0.5 - 100, 250, button_width, button_height)) {
|
if (Engine::GUI::Button (2, "Options", screen_right * 0.5 - 100, 250, button_width, button_height)) {
|
||||||
GetModel()->SetGameState(GameStateShowHighscore);
|
PushViewState (ViewStateOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (3, "Quit", screen_right * 0.5 - 100, 330, button_width, button_height)) {
|
if (Engine::GUI::Button (3, "Highscores", screen_right * 0.5 - 100, 300, button_width, button_height)) {
|
||||||
|
PushViewState(ViewStateShowHighscore);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Engine::GUI::Button (4, "Quit", screen_right * 0.5 - 100, 380, button_width, button_height)) {
|
||||||
Engine::RunCommand("quit");
|
Engine::RunCommand("quit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,8 +457,9 @@ void View::DrawUiGameRunning() {
|
||||||
// revert the font justification
|
// revert the font justification
|
||||||
SetFontJustification (Engine::FontJustificationLeft);
|
SetFontJustification (Engine::FontJustificationLeft);
|
||||||
|
|
||||||
if (Engine::GUI::CheckKeyPress(SDLK_ESCAPE))
|
if (Engine::GUI::CheckKeyPress(SDLK_ESCAPE)) {
|
||||||
GetModel()->SetGameState(GameStatePaused);
|
PushViewState(ViewStatePaused);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::DrawUiGameOver() {
|
void View::DrawUiGameOver() {
|
||||||
|
@ -472,7 +487,8 @@ void View::DrawUiGameOver() {
|
||||||
if (Engine::GUI::Button (2, "Continue...",
|
if (Engine::GUI::Button (2, "Continue...",
|
||||||
(screen_right - button_width) * 0.5,
|
(screen_right - button_width) * 0.5,
|
||||||
screen_bottom * 0.5 + 80, button_width, button_height)) {
|
screen_bottom * 0.5 + 80, button_width, button_height)) {
|
||||||
GetModel()->SetGameState(GameStateShowHighscore);
|
PopViewState();
|
||||||
|
PushViewState(ViewStateShowHighscore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +498,7 @@ void View::DrawUiLevelComplete() {
|
||||||
SelectFont ("console.ttf size=23");
|
SelectFont ("console.ttf size=23");
|
||||||
|
|
||||||
if(Engine::GUI::Button (1, "Next level ...", (screen_right - button_width) * 0.5, screen_bottom * 0.5 + 60, button_width, button_height)) {
|
if(Engine::GUI::Button (1, "Next level ...", (screen_right - button_width) * 0.5, screen_bottom * 0.5 + 60, button_width, button_height)) {
|
||||||
GetModel()->SetGameState(GameStateRunning);
|
PopViewState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,11 +507,15 @@ void View::DrawUiGamePaused() {
|
||||||
SelectFont ("console.ttf size=23");
|
SelectFont ("console.ttf size=23");
|
||||||
|
|
||||||
if (Engine::GUI::Button (1, "Resume Game", screen_right * 0.5 - 100, 200, button_width, button_height)) {
|
if (Engine::GUI::Button (1, "Resume Game", screen_right * 0.5 - 100, 200, button_width, button_height)) {
|
||||||
GetModel()->SetGameState(GameStateRunning);
|
PopViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (2, "Abort Game", screen_right * 0.5 - 100, 250, button_width, button_height)) {
|
if (Engine::GUI::Button (2, "Abort Game", screen_right * 0.5 - 100, 250, button_width, button_height)) {
|
||||||
GetModel()->SetGameState(GameStateMainMenu);
|
while (mViewStateStack.size())
|
||||||
|
PopViewState();
|
||||||
|
|
||||||
|
PushViewState(ViewStateGameRunning);
|
||||||
|
GetModel()->SetGameState(GameStateRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (3, "Quit", screen_right * 0.5 - 100, 330, button_width, button_height)) {
|
if (Engine::GUI::Button (3, "Quit", screen_right * 0.5 - 100, 330, button_width, button_height)) {
|
||||||
|
@ -508,7 +528,7 @@ void View::DrawUiPlayerDied() {
|
||||||
SelectFont ("console.ttf size=23");
|
SelectFont ("console.ttf size=23");
|
||||||
|
|
||||||
if (Engine::GUI::Button (1, "Continue", screen_right * 0.5 - 100, 200, button_width, button_height)) {
|
if (Engine::GUI::Button (1, "Continue", screen_right * 0.5 - 100, 200, button_width, button_height)) {
|
||||||
GetModel()->SetGameState(GameStateRunning);
|
PopViewState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,7 +608,36 @@ void View::DrawUiHighscore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (1, "Back to Menu", screen_right * 0.5 - 250 * 0.5, y + 16, button_width, button_height)) {
|
if (Engine::GUI::Button (1, "Back to Menu", screen_right * 0.5 - 250 * 0.5, y + 16, button_width, button_height)) {
|
||||||
GetModel()->SetGameState(GameStateMainMenu);
|
PopViewState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void View::DrawUiOptions() {
|
||||||
|
DrawPageTitle ("Options");
|
||||||
|
SelectFont ("console.ttf size=23");
|
||||||
|
|
||||||
|
// Enter your name
|
||||||
|
std::string player_name = GetModel()->GetPlayerName();
|
||||||
|
|
||||||
|
Engine::GUI::Label (1, "Effects Volume: ", screen_right * 0.5 - 150, 240);
|
||||||
|
|
||||||
|
float effects_volume = Engine::GetEffectsVolume();
|
||||||
|
if (Engine::GUI::VerticalSlider (2, screen_right * 0.5 - 100, 250, 250, 16, 0., 1., effects_volume)) {
|
||||||
|
Engine::LogDebug ("Setting effects volume to: %f", effects_volume);
|
||||||
|
Engine::SetEffectsVolume(effects_volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
Engine::GUI::Label (3, "Music Volume: ", screen_right * 0.5 - 150, 300);
|
||||||
|
|
||||||
|
float music_volume = Engine::GetMusicVolume();
|
||||||
|
if (Engine::GUI::VerticalSlider (4, screen_right * 0.5 - 100, 310, 250, 16, 0., 1., music_volume)) {
|
||||||
|
Engine::LogDebug ("Setting music volume to: %f", music_volume);
|
||||||
|
Engine::SetMusicVolume(music_volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (Engine::GUI::Button (5, "Back", screen_right * 0.5 - 100, 380, button_width, button_height)) {
|
||||||
|
PopViewState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,11 +656,14 @@ void View::DrawUiEnterPlayername() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (3, "Start Game", screen_right - 180 - 20, 500, 180, 40)) {
|
if (Engine::GUI::Button (3, "Start Game", screen_right - 180 - 20, 500, 180, 40)) {
|
||||||
|
PopViewState();
|
||||||
|
PushViewState(ViewStateGameRunning);
|
||||||
|
GetModel()->OnNewGame();
|
||||||
GetModel()->SetGameState(GameStateRunning);
|
GetModel()->SetGameState(GameStateRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (5, "Back", 20, 500, 180, 40)) {
|
if (Engine::GUI::Button (5, "Back", 20, 500, 180, 40)) {
|
||||||
GetModel()->SetGameState(GameStateMainMenu);
|
PopViewState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "Sprite.h"
|
#include "Sprite.h"
|
||||||
#include "EntityBase.h"
|
#include "EntityBase.h"
|
||||||
#include "SimpleConsoleOverlay.h"
|
#include "SimpleConsoleOverlay.h"
|
||||||
|
#include "AsteroidsEnums.h"
|
||||||
|
|
||||||
namespace asteroids {
|
namespace asteroids {
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ class View : public Engine::ViewBase {
|
||||||
void DrawUiPlayerDied();
|
void DrawUiPlayerDied();
|
||||||
void DrawHighscoreEntry(float x, float y, float entry_width, const std::string &name, unsigned int points);
|
void DrawHighscoreEntry(float x, float y, float entry_width, const std::string &name, unsigned int points);
|
||||||
void DrawUiHighscore();
|
void DrawUiHighscore();
|
||||||
|
void DrawUiOptions();
|
||||||
void DrawUiEnterPlayername();
|
void DrawUiEnterPlayername();
|
||||||
|
|
||||||
virtual void Draw ();
|
virtual void Draw ();
|
||||||
|
@ -64,6 +66,20 @@ class View : public Engine::ViewBase {
|
||||||
|
|
||||||
std::vector<unsigned int> mShipPartsEntityIds;
|
std::vector<unsigned int> mShipPartsEntityIds;
|
||||||
|
|
||||||
|
std::stack<ViewState> mViewStateStack;
|
||||||
|
|
||||||
|
void PushViewState (const ViewState state) {
|
||||||
|
Engine::LogDebug ("Pushing ViewState %s", GetStringViewState(state));
|
||||||
|
mViewStateStack.push(state);
|
||||||
|
}
|
||||||
|
ViewState GetViewState () {
|
||||||
|
return mViewStateStack.top();
|
||||||
|
}
|
||||||
|
void PopViewState () {
|
||||||
|
mViewStateStack.pop();
|
||||||
|
Engine::LogDebug ("Popped ViewState top is now:%s", GetStringViewState(mViewStateStack.top()));
|
||||||
|
}
|
||||||
|
|
||||||
// \todo [high] add Resource Manager!
|
// \todo [high] add Resource Manager!
|
||||||
Engine::Sprite mGUIShipSprite;
|
Engine::Sprite mGUIShipSprite;
|
||||||
Engine::Sprite mAsteroidSprite;
|
Engine::Sprite mAsteroidSprite;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <stack>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
|
||||||
#include "Module.h"
|
#include "Module.h"
|
||||||
|
|
|
@ -31,13 +31,9 @@ bool regionhit (int x, int y, int w, int h) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawBlock (int x, int y, int w, int h) {
|
void DrawBlock (int x, int y, int w, int h) {
|
||||||
const int d = 16;
|
|
||||||
const float shading_dark = 0.5;
|
const float shading_dark = 0.5;
|
||||||
const float shading_light = 1.3;
|
const float shading_light = 1.3;
|
||||||
|
|
||||||
assert (h > d);
|
|
||||||
assert (w > d);
|
|
||||||
|
|
||||||
float color[4];
|
float color[4];
|
||||||
glGetFloatv (GL_CURRENT_COLOR, color);
|
glGetFloatv (GL_CURRENT_COLOR, color);
|
||||||
|
|
||||||
|
@ -413,6 +409,103 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float VerticalSlider (int id, int x, int y, int w, int h, float min_value, float max_value, float &value) {
|
||||||
|
const int knob_width = 16;
|
||||||
|
const int knob_height = h * 2;
|
||||||
|
|
||||||
|
int slider_pos = (w * value) / max_value - knob_width / 2;
|
||||||
|
|
||||||
|
// Check for hotness
|
||||||
|
if (regionhit (x, y + h * 0.5 - knob_height * 0.5, w, knob_height)) {
|
||||||
|
controller->uistate.hotitem = id;
|
||||||
|
if (controller->uistate.activeitem == 0
|
||||||
|
&& controller->GetButtonState(MouseButtonLeft)) {
|
||||||
|
controller->uistate.activeitem = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If nothing is selected
|
||||||
|
if (controller->uistate.hotitem != 0) {
|
||||||
|
controller->uistate.kbditem = controller->uistate.hotitem;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (controller->uistate.kbditem == 0) {
|
||||||
|
controller->uistate.hotitem = id;
|
||||||
|
controller->uistate.kbditem = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have keyboard focus, we highlight the widget
|
||||||
|
if ( controller->uistate.kbditem == id) {
|
||||||
|
if (controller->uistate.activeitem == id) {
|
||||||
|
glColor3f (0.6, 0.6, 0.6);
|
||||||
|
DrawBlock (x, y, w, h);
|
||||||
|
glColor3f (0.8, 0.8, 0.8);
|
||||||
|
DrawBlock (x + slider_pos, y + h * 0.5 - knob_height * 0.5, knob_width, knob_height);
|
||||||
|
} else {
|
||||||
|
glColor3f (0.6, 0.6, 0.6);
|
||||||
|
DrawBlock (x, y, w, h);
|
||||||
|
glColor3f (0.7, 0.7, 0.7);
|
||||||
|
DrawBlock (x + slider_pos, y + h * 0.5 - knob_height * 0.5, knob_width, knob_height);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
glColor3f (0.4, 0.4, 0.4);
|
||||||
|
DrawBlock (x, y, w, h);
|
||||||
|
glColor3f (0.5, 0.5, 0.5);
|
||||||
|
DrawBlock (x + slider_pos, y + h * 0.5 - knob_height * 0.5, knob_width, knob_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (controller->uistate.kbditem == id) {
|
||||||
|
switch (controller->uistate.last_keysym) {
|
||||||
|
case SDLK_DOWN:
|
||||||
|
controller->uistate.kbditem = 0;
|
||||||
|
controller->uistate.hotitem = 0;
|
||||||
|
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||||
|
break;
|
||||||
|
case SDLK_UP:
|
||||||
|
controller->uistate.kbditem = controller->uistate.lastwidget;
|
||||||
|
controller->uistate.hotitem = controller->uistate.lastwidget;
|
||||||
|
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||||
|
break;
|
||||||
|
case SDLK_LEFT:
|
||||||
|
value -= (max_value - min_value) * 0.1;
|
||||||
|
if ( value < min_value)
|
||||||
|
value = min_value;
|
||||||
|
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
case SDLK_RIGHT:
|
||||||
|
value += (max_value - min_value) * 0.1;
|
||||||
|
if ( value > max_value)
|
||||||
|
value = max_value;
|
||||||
|
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
controller->uistate.lastwidget = id;
|
||||||
|
|
||||||
|
if (controller->uistate.activeitem == id) {
|
||||||
|
int mouse_pos[2];
|
||||||
|
controller->GetMouseScreenPosition(mouse_pos);
|
||||||
|
int rel_mouse_pos = mouse_pos[0] - x;
|
||||||
|
if (rel_mouse_pos < 0)
|
||||||
|
rel_mouse_pos = 0;
|
||||||
|
if (rel_mouse_pos > w)
|
||||||
|
rel_mouse_pos = w;
|
||||||
|
|
||||||
|
float mouse_value = rel_mouse_pos * max_value / static_cast<float>(w);
|
||||||
|
|
||||||
|
if (mouse_value != value) {
|
||||||
|
value = mouse_value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CheckKeyPress (int keycode) {
|
bool CheckKeyPress (int keycode) {
|
||||||
if (controller->uistate.last_keysym == keycode)
|
if (controller->uistate.last_keysym == keycode)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -34,6 +34,8 @@ bool Button (int id, const char* caption, int x, int y, int w, int h);
|
||||||
|
|
||||||
bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxlength);
|
bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxlength);
|
||||||
|
|
||||||
|
float VerticalSlider (int id, int x, int y, int w, int h, float min_value, float max_value, float &value);
|
||||||
|
|
||||||
/** \brief Checks whether a given key was pressed
|
/** \brief Checks whether a given key was pressed
|
||||||
*
|
*
|
||||||
* This function can be used to check whether a single key (e.g. ESC) was
|
* This function can be used to check whether a single key (e.g. ESC) was
|
||||||
|
|
|
@ -233,5 +233,36 @@ void HaltSoundLoop (const std::string &sound_name) {
|
||||||
SoundInstance->HaltSoundLoop(sound_name);
|
SoundInstance->HaltSoundLoop(sound_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetMusicVolume (const float &music_volume) {
|
||||||
|
if (!SoundInstance) {
|
||||||
|
LogError("Could set music volume: sound system not initialized!");
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundInstance->SetMusicVolume(music_volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetMusicVolume () {
|
||||||
|
if (!SoundInstance) {
|
||||||
|
LogError("Could get music volume: sound system not initialized!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return SoundInstance->GetMusicVolume();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetEffectsVolume (const float &effects_volume) {
|
||||||
|
if (!SoundInstance) {
|
||||||
|
LogError("Could set effects volume: sound system not initialized!");
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundInstance->SetEffectsVolume(effects_volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetEffectsVolume () {
|
||||||
|
if (!SoundInstance) {
|
||||||
|
LogError("Could get effects volume: sound system not initialized!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return SoundInstance->GetEffectsVolume();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,21 @@ void PlaySoundLoop (const std::string &sound_name, int count);
|
||||||
void HaltSoundLoop (const std::string &sound_name);
|
void HaltSoundLoop (const std::string &sound_name);
|
||||||
void PlayMusic (const std::string &music_name);
|
void PlayMusic (const std::string &music_name);
|
||||||
|
|
||||||
|
/** \brief Sets the volume of the music channel to the given value
|
||||||
|
*
|
||||||
|
* \param music_value is a value from 0. (no music) to 1. (maximum volume)
|
||||||
|
*/
|
||||||
|
void SetMusicVolume (const float &music_volume);
|
||||||
|
/** \brief Returns the value of the music (0. - 1.) */
|
||||||
|
float GetMusicVolume ();
|
||||||
|
/** \brief Sets the volume of the music channel to the given value
|
||||||
|
*
|
||||||
|
* \param music_value is a value from 0. (no music) to 1. (maximum volume)
|
||||||
|
*/
|
||||||
|
void SetEffectsVolume (const float &effects_volume);
|
||||||
|
/** \brief Returns the value of the effects (0. - 1.) */
|
||||||
|
float GetEffectsVolume ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _SOUNDGLOBAL_H */
|
#endif /* _SOUNDGLOBAL_H */
|
||||||
|
|
Loading…
Reference in New Issue