some progress concerning IMGUI widgets (added simple text input)
This commit is contained in:
@@ -10,6 +10,7 @@ BEGIN_ENUM(Event)
|
||||
DECL_ENUM_ELEMENT(EventAccelerateStart),
|
||||
DECL_ENUM_ELEMENT(EventAccelerateStop),
|
||||
DECL_ENUM_ELEMENT(EventLevelComplete),
|
||||
DECL_ENUM_ELEMENT(EventChangeGameState),
|
||||
DECL_ENUM_ELEMENT(EventGameOver),
|
||||
DECL_ENUM_ELEMENT(EventShipExplode)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "Controller.h"
|
||||
#include "AsteroidsEvents.h"
|
||||
|
||||
namespace asteroids {
|
||||
|
||||
@@ -16,7 +17,16 @@ int Controller::OnInit (int argc, char *argv[]) {
|
||||
mBindings[SDLK_F8] = "toggleconsole";
|
||||
mBindings[SDLK_F9] = "set playerspeed 5.0";
|
||||
|
||||
Engine::RegisterListener (this, EventChangeGameState);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Controller::OnReceiveEvent (const Engine::EventBasePtr &event) {
|
||||
if (event->mEventType == EventChangeGameState) {
|
||||
IMGUIClear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ class Controller : public Engine::ControllerBase {
|
||||
virtual int OnInit (int argc, char* argv[]);
|
||||
/** \brief Registers the commands of the cnotroller */
|
||||
virtual void OnRegisterCommands ();
|
||||
virtual bool OnReceiveEvent (const Engine::EventBasePtr &event);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -359,6 +359,15 @@ int Model::DoSaveLevel (const char* filename) {
|
||||
level_file.close();
|
||||
return 0;
|
||||
}
|
||||
void Model::SetGameState (const unsigned int &state) {
|
||||
mLastGameState = mGameState;
|
||||
|
||||
Engine::EventBasePtr changegamestate_event (new Engine::EventBase());
|
||||
changegamestate_event->mEventType = EventChangeGameState;
|
||||
QueueEvent (changegamestate_event);
|
||||
|
||||
mGameState = state;
|
||||
}
|
||||
|
||||
bool Model::OnLevelComplete() {
|
||||
Engine::LogMessage ("Level complete!");
|
||||
|
||||
+6
-1
@@ -17,10 +17,15 @@ class Model : public Engine::ModelBase {
|
||||
/** \brief Resets values from a previous game */
|
||||
void OnNewGame ();
|
||||
|
||||
virtual void SetGameState (const unsigned int &state);
|
||||
|
||||
int GetPlayerLives () { return mPlayerLives; };
|
||||
unsigned int GetPoints () { return mPoints; };
|
||||
std::string GetPlayerName() { return mPlayerName; };
|
||||
void SetPlayerName(const std::string &name) { mPlayerName = name; };
|
||||
void SetPlayerName(const std::string &name) {
|
||||
Engine::LogDebug("new player name: %s", name.c_str());
|
||||
mPlayerName = name;
|
||||
};
|
||||
|
||||
float GetWorldWidth ();
|
||||
float GetWorldHeight ();
|
||||
|
||||
+30
-66
@@ -33,19 +33,9 @@ void MainMenuOverlay::Init () {
|
||||
}
|
||||
|
||||
bool MainMenuOverlay::OnKeyDown (const SDL_keysym &keysym) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
Engine::RunCommand ("quit");
|
||||
return true;
|
||||
case SDLK_RETURN:
|
||||
GetModel()->SetGameState(GameStateEnterPlayername);
|
||||
return true;
|
||||
case SDLK_h:
|
||||
GetModel()->SetGameState(GameStateShowHighscore);
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
if (keysym.sym == SDLK_ESCAPE)
|
||||
Engine::RunCommand("quit");
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainMenuOverlay::Draw () {
|
||||
@@ -70,16 +60,16 @@ void MainMenuOverlay::Draw () {
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
// Engine::DrawGLString ( right * 0.5 - 100, 100, "A s t e r o i d s");
|
||||
|
||||
Engine::GUI::Label (4, "A s t e r o i d s", right * 0.5 - 100, 180);
|
||||
|
||||
if (Engine::GUI::Button (1, "Start Game", right * 0.5 - 100, 200, 250, 40)) {
|
||||
if (Engine::GUI::Button (1, "New Game", right * 0.5 - 100, 200, 250, 40)) {
|
||||
GetModel()->SetGameState(GameStateEnterPlayername);
|
||||
GetController()->uistate.hotitem = 0;
|
||||
}
|
||||
|
||||
if (Engine::GUI::Button (2, "Highscores", right * 0.5 - 100, 250, 250, 40)) {
|
||||
GetModel()->SetGameState(GameStateShowHighscore);
|
||||
GetController()->uistate.hotitem = 0;
|
||||
}
|
||||
|
||||
if (Engine::GUI::Button (3, "Quit", right * 0.5 - 100, 330, 250, 40)) {
|
||||
@@ -88,13 +78,6 @@ void MainMenuOverlay::Draw () {
|
||||
|
||||
GetView()->SelectFont("console.ttf");
|
||||
|
||||
/*
|
||||
// then we do the drawings
|
||||
Engine::DrawGLString ( right * 0.5 - 100, bottom * 0.5 - 8 - 32, "Main Menu");
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8 - 16, "[Return] - Start Game");
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8, "[h] - Show Highscore");
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 + 8, "[Escape] - Quit");
|
||||
*/
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
@@ -553,39 +536,13 @@ void EnterPlayernameOverlay::Init () {
|
||||
}
|
||||
|
||||
bool EnterPlayernameOverlay::OnKeyDown (const SDL_keysym &keysym) {
|
||||
GetController()->EnableTextinput(true);
|
||||
|
||||
switch (keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
GetModel()->SetGameState(GameStateMainMenu);
|
||||
return true;
|
||||
case SDLK_BACKSPACE:
|
||||
if (mPlayerNameInput.size() > 0)
|
||||
mPlayerNameInput = mPlayerNameInput.substr (0, mPlayerNameInput.size() - 1 );
|
||||
return true;
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
// If we just entered a new entry we simply show the highscore table,
|
||||
// otherwise we switch back to the main menu
|
||||
GetModel()->SetPlayerName(mPlayerNameInput);
|
||||
GetController()->EnableTextinput(false);
|
||||
GetModel()->SetGameState(GameStateRunning);
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
if (keysym.sym == SDLK_ESCAPE) {
|
||||
GetModel()->SetGameState(GameStateMainMenu);
|
||||
GetController()->uistate.hotitem = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (keysym.unicode) {
|
||||
if ((keysym.unicode & 0xFF80) == 0) {
|
||||
mPlayerNameInput += keysym.unicode & 0x7F;
|
||||
return true;
|
||||
} else {
|
||||
Engine::LogWarning ("Input key not supported!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void EnterPlayernameOverlay::Draw () {
|
||||
@@ -611,21 +568,28 @@ void EnterPlayernameOverlay::Draw () {
|
||||
glLoadIdentity ();
|
||||
|
||||
GetView()->SelectFont("console.ttf");
|
||||
float x = right * 0.5 - 100;
|
||||
float y = bottom * 0.5 - 8 - 128;
|
||||
|
||||
// then we do the drawings
|
||||
Engine::DrawGLString ( x, y, "A s t e r o i d s");
|
||||
y += 30;
|
||||
Engine::DrawGLString ( x, y, "Enter your name: ");
|
||||
Engine::GUI::Label (4, "A s t e r o i d s", right * 0.5 - 100, 180);
|
||||
|
||||
std::string name_output (mPlayerNameInput);
|
||||
if (SDL_GetTicks() >> 9 & 1)
|
||||
name_output += "_";
|
||||
Engine::GUI::Label (1, "Enter your name: ", right * 0.5 - 100, 250);
|
||||
|
||||
// Make sure we have UNICODE processing enabled!
|
||||
GetController()->EnableTextinput(true);
|
||||
|
||||
std::string player_name = GetModel()->GetPlayerName();
|
||||
if (Engine::GUI::LineEdit (2, right * 0.5 + 20, 238, player_name, 16)) {
|
||||
GetModel()->SetPlayerName(player_name);
|
||||
}
|
||||
|
||||
if (Engine::GUI::Button (3, "Start Game", right - 150 - 20, 500, 150, 40)) {
|
||||
GetModel()->SetGameState(GameStateRunning);
|
||||
}
|
||||
|
||||
if (Engine::GUI::Button (5, "Back", 20, 500, 150, 40)) {
|
||||
GetModel()->SetGameState(GameStateMainMenu);
|
||||
GetController()->uistate.hotitem = 0;
|
||||
}
|
||||
|
||||
Engine::DrawGLString ( x + 15*8, y, name_output.c_str());
|
||||
Engine::DrawGLString ( x + 16, y + 16, "Press [Return] to continue.");
|
||||
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
|
||||
Reference in New Issue
Block a user