Skip to content

Commit

Permalink
#25, #24: Move the gameDialog class to the Controller namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
larspensjo committed Jan 29, 2013
1 parent d70c8e6 commit 1ea890d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
6 changes: 4 additions & 2 deletions Source/gamedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
#include "worsttime.h"
#include "ChunkProcess.h"

using namespace Controller;

using std::string;

const float defaultRenderViewAngle = 60.0f;
Expand All @@ -80,7 +82,7 @@ static std::vector<unsigned>::iterator sTextureIterator;
static bool sShowAlternateBitmap = false;

static float mouseSens = -5.0f;
gameDialog gGameDialog; // For now, there will only be one
gameDialog Controller::gGameDialog; // For now, there will only be one

// If there are any strings in these parameters, show them once in a popup dialog.
string sgPopup, sgPopupTitle = "Ephenation";
Expand Down Expand Up @@ -309,7 +311,7 @@ int xStartTurn = 0, yStartTurn = 0;
float angleHorStartTurn = 0.0f, angleVertStartTurn;

static void handleMouseActiveMotion(int x, int y) {
gGameDialog.handleMouseActiveMotion(x, y);
Controller::gGameDialog.handleMouseActiveMotion(x, y);
}

void gameDialog::handleMouseActiveMotion(int x, int y) {
Expand Down
5 changes: 5 additions & 0 deletions Source/gamedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace Rocket {
}
};

namespace Controller {

/// This corresponds to the controller class in a Model/View/Controller.
/// - keyboard input
/// - mouse input
Expand Down Expand Up @@ -142,6 +144,9 @@ class gameDialog {
};

extern gameDialog gGameDialog;

}

extern float renderViewAngle;

/// A string that automatically will be shown in a pop up window.
Expand Down
6 changes: 3 additions & 3 deletions Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ int main(int argc, char** argv) {
gUniformBuffer.Init();
gDrawFont.Init("textures/georgia12"); // Must be done before gGameDialog.
GameTexture::Init();
gGameDialog.init();
Controller::gGameDialog.init();
ChunkShader *shader = ChunkShader::Make();
gChunkShaderPicking.Init();
Tree::InitStatic();
Expand Down Expand Up @@ -444,8 +444,8 @@ int main(int argc, char** argv) {
ListenForServerMessages();
}

gGameDialog.Update();
gGameDialog.render(sHideGUI);
Controller::gGameDialog.Update();
Controller::gGameDialog.render(sHideGUI);

glfwSwapBuffers();

Expand Down
6 changes: 3 additions & 3 deletions Source/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static void ServerMessage(const char *msg) {
// This is a special string to be used for sound effects.
gSoundControl.RequestTrigSound(msg+1);
if (strncmp(msg+1, "BOOM", 4) == 0)
gGameDialog.RequestEffect(gameDialog::EFFECT_ZOOM2);
Controller::gGameDialog.RequestEffect(Controller::gameDialog::EFFECT_ZOOM2);
if (strlen(msg) < 6)
return; // That was all for now
msg += 6; // Skip the sound string.
Expand Down Expand Up @@ -312,7 +312,7 @@ void Parse(const unsigned char *b, int n) {
else
gSoundControl.RequestSound(SoundControl::SBuildBlock);
if (type == BT_Text) {
gGameDialog.CreateActivatorMessage(dx, dy, dz, cc);
Controller::gGameDialog.CreateActivatorMessage(dx, dy, dz, cc);
}
}
cp->SetDirty(true);
Expand Down Expand Up @@ -398,7 +398,7 @@ void Parse(const unsigned char *b, int n) {
case CMD_RESP_AGGRO_FROM_MONSTER:
for (int i=1; i<n; i += 4) {
unsigned long id = ParseUint32(b+i);
gGameDialog.AggroFrom(gMonsters.Find(id));
Controller::gGameDialog.AggroFrom(gMonsters.Find(id));
}
break;
case CMD_UPD_INV:
Expand Down
4 changes: 2 additions & 2 deletions Source/ui/activator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

void ActivatorDialog::UseDocument(Rocket::Core::ElementDocument *doc, std::function<void()> callback) {
this->Push(doc, callback); // Allways push the previous document first
gGameDialog.GetActivator(fDx, fDy, fDz, fCC);
Controller::gGameDialog.GetActivator(fDx, fDy, fDz, fCC);
fFormResultValues.clear(); // Restart with an empty list
this->Treewalk([this](Rocket::Core::Element *e){ this->UpdateInput(e);} ); // Fill default parameters in the document
this->Treewalk([this](Rocket::Core::Element *e) {this->DetectDefaultButton(e); }); // This can be done by the local callback
Expand Down Expand Up @@ -201,7 +201,7 @@ void ActivatorDialog::FormEvent(Rocket::Core::Event& event, const string &action
// std::cout << s << std::endl;

if (!this->Pop())
gGameDialog.ClearInputRedirect(); // Normal case
Controller::gGameDialog.ClearInputRedirect(); // Normal case
}

bool ActivatorDialog::ClickEvent(Rocket::Core::Event& event, const string &action) {
Expand Down
4 changes: 2 additions & 2 deletions Source/ui/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool BaseDialog::ClickEvent(Rocket::Core::Event& event, const string &action) {
Splitter split(action, " ");
if (action == "Close") {
if (!this->Pop())
gGameDialog.ClearInputRedirect();
Controller::gGameDialog.ClearInputRedirect();
return true;
} else if (split[0] == "Popup" && split.size() == 2) {
gDialogFactory.Make(fStack.back().fDocument->GetContext(), split[1]);
Expand All @@ -97,7 +97,7 @@ bool BaseDialog::ClickEvent(Rocket::Core::Event& event, const string &action) {
// Pop all saved documents, if any.
while(this->Pop())
continue;
gGameDialog.ClearInputRedirect();
Controller::gGameDialog.ClearInputRedirect();
gMode.Set(GameMode::ESC);
return true;
} else if (action == "") {
Expand Down
2 changes: 1 addition & 1 deletion Source/ui/login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ void LoginDialog::FormEvent(Rocket::Core::Event& event, const string &action) {
// printf("Login %s, %s, %s\n", fFormResultValues["Login.licensekey"].c_str(), fFormResultValues["Login.email"].c_str(), fFormResultValues["Login.password"].c_str());

if (!this->Pop())
gGameDialog.ClearInputRedirect(); // Normal case
Controller::gGameDialog.ClearInputRedirect(); // Normal case
}
}
2 changes: 1 addition & 1 deletion Source/ui/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ void OptionsDialog::FormEvent(Rocket::Core::Event& event, const string &action)
}

if (!this->Pop())
gGameDialog.ClearInputRedirect(); // Normal case
Controller::gGameDialog.ClearInputRedirect(); // Normal case
}
}

0 comments on commit 1ea890d

Please sign in to comment.