intermediate commit: restructuring view states
This commit is contained in:
+76
-24
@@ -72,6 +72,8 @@ int View::OnInit (int argc, char* argv[]) {
|
||||
Engine::RegisterListener (this, EventAccelerateStop);
|
||||
Engine::RegisterListener (this, EventShipExplode);
|
||||
|
||||
PushViewState (ViewStateMainMenu);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -355,34 +357,42 @@ void View::DrawUi () {
|
||||
SetFontJustification (Engine::FontJustificationLeft);
|
||||
GetController()->EnableTextinput(true);
|
||||
|
||||
switch (game_state) {
|
||||
case GameStateMainMenu:
|
||||
ViewState current_view_state = GetViewState();
|
||||
|
||||
SelectFont ("console.ttf size=12");
|
||||
Engine::GUI::Label (99999, GetStringViewState(current_view_state), 8, 16);
|
||||
|
||||
switch (current_view_state) {
|
||||
case ViewStateMainMenu:
|
||||
DrawUiMainMenu();
|
||||
break;
|
||||
case GameStateRunning:
|
||||
case ViewStateGameRunning:
|
||||
DrawUiGameRunning();
|
||||
break;
|
||||
case GameStatePaused:
|
||||
case ViewStatePaused:
|
||||
DrawUiGamePaused();
|
||||
break;
|
||||
case GameStatePlayerDied:
|
||||
case ViewStatePlayerDied:
|
||||
DrawUiPlayerDied();
|
||||
break;
|
||||
case GameStateLevelComplete:
|
||||
case ViewStateLevelComplete:
|
||||
DrawUiLevelComplete();
|
||||
break;
|
||||
case GameStateShowHighscore:
|
||||
case ViewStateShowHighscore:
|
||||
DrawUiHighscore();
|
||||
break;
|
||||
case GameStateEnterPlayername:
|
||||
case ViewStateOptions:
|
||||
DrawUiOptions();
|
||||
break;
|
||||
case ViewStateEnterPlayername:
|
||||
DrawUiEnterPlayername();
|
||||
break;
|
||||
case GameStateGameOver:
|
||||
case ViewStateGameOver:
|
||||
DrawUiGameOver();
|
||||
break;
|
||||
default:
|
||||
Engine::LogWarning ("Trying to draw unknown GameState: %s (%d)",
|
||||
GetStringGameState (game_state), game_state);
|
||||
Engine::LogWarning ("Trying to draw unknown ViewState: %s (%d)",
|
||||
GetStringViewState (game_state), game_state);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -412,14 +422,18 @@ void View::DrawUiMainMenu() {
|
||||
|
||||
SelectFont("console.ttf size=23");
|
||||
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)) {
|
||||
GetModel()->SetGameState(GameStateShowHighscore);
|
||||
if (Engine::GUI::Button (2, "Options", screen_right * 0.5 - 100, 250, button_width, button_height)) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -443,8 +457,9 @@ void View::DrawUiGameRunning() {
|
||||
// revert the font justification
|
||||
SetFontJustification (Engine::FontJustificationLeft);
|
||||
|
||||
if (Engine::GUI::CheckKeyPress(SDLK_ESCAPE))
|
||||
GetModel()->SetGameState(GameStatePaused);
|
||||
if (Engine::GUI::CheckKeyPress(SDLK_ESCAPE)) {
|
||||
PushViewState(ViewStatePaused);
|
||||
}
|
||||
}
|
||||
|
||||
void View::DrawUiGameOver() {
|
||||
@@ -472,7 +487,8 @@ void View::DrawUiGameOver() {
|
||||
if (Engine::GUI::Button (2, "Continue...",
|
||||
(screen_right - button_width) * 0.5,
|
||||
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");
|
||||
|
||||
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");
|
||||
|
||||
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)) {
|
||||
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)) {
|
||||
@@ -508,7 +528,7 @@ void View::DrawUiPlayerDied() {
|
||||
SelectFont ("console.ttf size=23");
|
||||
|
||||
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)) {
|
||||
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)) {
|
||||
PopViewState();
|
||||
PushViewState(ViewStateGameRunning);
|
||||
GetModel()->OnNewGame();
|
||||
GetModel()->SetGameState(GameStateRunning);
|
||||
}
|
||||
|
||||
if (Engine::GUI::Button (5, "Back", 20, 500, 180, 40)) {
|
||||
GetModel()->SetGameState(GameStateMainMenu);
|
||||
PopViewState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user