summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-03 14:29:18 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-03 14:29:18 (GMT)
commit36b2aa01918344d91df30c4a6722ac39eaca0642 (patch)
tree4833adffc9aa2db54f00e9c162b65eb9117a600f /src
parent80dfc96c7c30f9bc22cc802b876c79f4205d0cbd (diff)
downloadpowder-36b2aa01918344d91df30c4a6722ac39eaca0642.zip
powder-36b2aa01918344d91df30c4a6722ac39eaca0642.tar.gz
QuickOptions!! #46
Diffstat (limited to 'src')
-rw-r--r--src/game/GameController.cpp1
-rw-r--r--src/game/GameModel.cpp47
-rw-r--r--src/game/GameModel.h7
-rw-r--r--src/game/GameView.cpp53
-rw-r--r--src/game/GameView.h4
-rw-r--r--src/game/QuickOption.h76
-rw-r--r--src/game/QuickOptions.h99
-rw-r--r--src/graphics/Renderer.cpp8
-rw-r--r--src/graphics/Renderer.h1
9 files changed, 294 insertions, 2 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 5cf7654..c992120 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -74,6 +74,7 @@ public:
OptionsCallback(GameController * cc_) { cc = cc_; }
virtual void ControllerExit()
{
+ cc->gameModel->UpdateQuickOptions();
//cc->gameModel->SetUser(cc->loginWindow->GetUser());
}
};
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 7c2ddeb..28ed550 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -10,6 +10,7 @@
#include "client/Client.h"
#include "game/DecorationTool.h"
#include "GameModelException.h"
+#include "QuickOptions.h"
GameModel::GameModel():
sim(NULL),
@@ -68,6 +69,7 @@ GameModel::GameModel():
}
BuildMenus();
+ BuildQuickOptionMenu();
//Set default decoration colour
unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255);
@@ -114,6 +116,33 @@ GameModel::~GameModel()
// delete[] activeTools;
}
+void GameModel::UpdateQuickOptions()
+{
+ for(std::vector<QuickOption*>::iterator iter = quickOptions.begin(), end = quickOptions.end(); iter != end; ++iter)
+ {
+ QuickOption * option = *iter;
+ option->Update();
+ }
+}
+
+void GameModel::BuildQuickOptionMenu()
+{
+ for(std::vector<QuickOption*>::iterator iter = quickOptions.begin(), end = quickOptions.end(); iter != end; ++iter)
+ {
+ delete *iter;
+ }
+ quickOptions.clear();
+
+ quickOptions.push_back(new SandEffectOption(this));
+ quickOptions.push_back(new DrawGravOption(this));
+ quickOptions.push_back(new DecorationsOption(this));
+ quickOptions.push_back(new NGravityOption(this));
+ quickOptions.push_back(new AHeatOption(this));
+
+ notifyQuickOptionsChanged();
+ UpdateQuickOptions();
+}
+
void GameModel::BuildMenus()
{
//Empty current menus
@@ -246,6 +275,8 @@ void GameModel::AddObserver(GameView * observer){
observer->NotifyZoomChanged(this);
observer->NotifyColourSelectorVisibilityChanged(this);
observer->NotifyColourSelectorColourChanged(this);
+ observer->NotifyQuickOptionsChanged(this);
+ UpdateQuickOptions();
}
void GameModel::SetActiveMenu(Menu * menu)
@@ -282,6 +313,11 @@ void GameModel::SetActiveTool(int selection, Tool * tool)
notifyActiveToolsChanged();
}
+vector<QuickOption*> GameModel::GetQuickOptions()
+{
+ return quickOptions;
+}
+
vector<Menu*> GameModel::GetMenuList()
{
return menuList;
@@ -320,6 +356,7 @@ void GameModel::SetSave(SaveInfo * newSave)
sim->Load(saveData);
}
notifySaveChanged();
+ UpdateQuickOptions();
}
void GameModel::SetSaveFile(SaveFile * newSave)
@@ -348,6 +385,7 @@ void GameModel::SetSaveFile(SaveFile * newSave)
delete newSave;
notifySaveChanged();
+ UpdateQuickOptions();
}
Simulation * GameModel::GetSimulation()
@@ -476,6 +514,7 @@ void GameModel::SetDecoration(bool decorationState)
{
ren->decorations_enable = decorationState?1:0;
notifyDecorationChanged();
+ UpdateQuickOptions();
}
bool GameModel::GetDecoration()
@@ -749,4 +788,12 @@ void GameModel::notifyToolTipChanged()
{
observers[i]->NotifyToolTipChanged(this);
}
+}
+
+void GameModel::notifyQuickOptionsChanged()
+{
+ for(int i = 0; i < observers.size(); i++)
+ {
+ observers[i]->NotifyQuickOptionsChanged(this);
+ }
} \ No newline at end of file
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index 2c8636a..e41ff2b 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -21,6 +21,7 @@ class GameView;
class Simulation;
class Renderer;
+class QuickOption;
class ToolSelection
{
public:
@@ -43,6 +44,7 @@ private:
vector<GameView*> observers;
vector<Tool*> toolList;
vector<Menu*> menuList;
+ vector<QuickOption*> quickOptions;
Menu * activeMenu;
int currentBrush;
vector<Brush *> brushList;
@@ -76,6 +78,7 @@ private:
void notifyLogChanged(string entry);
void notifyInfoTipChanged();
void notifyToolTipChanged();
+ void notifyQuickOptionsChanged();
public:
GameModel();
~GameModel();
@@ -92,6 +95,9 @@ public:
std::string GetInfoTip();
void BuildMenus();
+ void BuildQuickOptionMenu();
+
+ void UpdateQuickOptions();
void SetVote(int direction);
SaveInfo * GetSave();
@@ -108,6 +114,7 @@ public:
void ClearSimulation();
vector<Menu*> GetMenuList();
vector<Tool*> GetToolList();
+ vector<QuickOption*> GetQuickOptions();
void SetActiveMenu(Menu * menu);
Menu * GetActiveMenu();
void FrameStep(int frames);
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index d86f2b6..39211fc 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -12,6 +12,7 @@
#include "interface/Slider.h"
#include "search/Thumbnail.h"
#include "simulation/SaveRenderer.h"
+#include "QuickOption.h"
GameView::GameView():
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
@@ -362,6 +363,33 @@ public:
}
};
+class GameView::OptionAction: public ui::ButtonAction
+{
+ QuickOption * option;
+public:
+ OptionAction(QuickOption * _option) { option = _option; }
+ void ActionCallback(ui::Button * sender)
+ {
+ option->Perform();
+ }
+};
+
+class GameView::OptionListener: public QuickOptionListener
+{
+ ui::Button * button;
+public:
+ OptionListener(ui::Button * _button) { button = _button; }
+ virtual void OnValueChanged(QuickOption * option)
+ {
+ switch(option->GetType())
+ {
+ case QuickOption::Toggle:
+ button->SetTogglable(true);
+ button->SetToggleState(option->GetToggle());
+ }
+ }
+};
+
class GameView::ToolAction: public ui::ButtonAction
{
GameView * v;
@@ -376,6 +404,31 @@ public:
}
};
+void GameView::NotifyQuickOptionsChanged(GameModel * sender)
+{
+ for(int i = 0; i < quickOptionButtons.size(); i++)
+ {
+ RemoveComponent(quickOptionButtons[i]);
+ delete quickOptionButtons[i];
+ }
+
+ int currentY = 1;
+ vector<QuickOption*> optionList = sender->GetQuickOptions();
+ for(vector<QuickOption*>::iterator iter = optionList.begin(), end = optionList.end(); iter != end; ++iter)
+ {
+ QuickOption * option = *iter;
+ ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-16, currentY), ui::Point(15, 15), option->GetIcon(), option->GetDescription());
+ //tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2);
+ tempButton->SetTogglable(true);
+ tempButton->SetActionCallback(new OptionAction(option));
+ option->AddListener(new OptionListener(tempButton));
+ AddComponent(tempButton);
+
+ quickOptionButtons.push_back(tempButton);
+ currentY += 16;
+ }
+}
+
void GameView::NotifyMenuListChanged(GameModel * sender)
{
int currentY = YRES+MENUSIZE-48;//-(sender->GetMenuList().size()*16);
diff --git a/src/game/GameView.h b/src/game/GameView.h
index 4c0ad85..15bf0dc 100644
--- a/src/game/GameView.h
+++ b/src/game/GameView.h
@@ -54,6 +54,7 @@ private:
Renderer * ren;
Brush * activeBrush;
//UI Elements
+ vector<ui::Button*> quickOptionButtons;
vector<ui::Button*> menuButtons;
vector<ToolButton*> toolButtons;
vector<ui::Component*> notificationComponents;
@@ -139,6 +140,7 @@ public:
void NotifyLogChanged(GameModel * sender, string entry);
void NotifyToolTipChanged(GameModel * sender);
void NotifyInfoTipChanged(GameModel * sender);
+ void NotifyQuickOptionsChanged(GameModel * sender);
virtual void ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip);
@@ -163,6 +165,8 @@ public:
class MenuAction;
class ToolAction;
+ class OptionAction;
+ class OptionListener;
};
#endif // GAMEVIEW_H
diff --git a/src/game/QuickOption.h b/src/game/QuickOption.h
new file mode 100644
index 0000000..8383029
--- /dev/null
+++ b/src/game/QuickOption.h
@@ -0,0 +1,76 @@
+#pragma once
+
+#include <string>
+#include <vector>
+
+class GameModel;
+class QuickOption;
+class QuickOptionListener
+{
+protected:
+ QuickOptionListener() {}
+public:
+ virtual ~QuickOptionListener() {}
+ virtual void OnValueChanged(QuickOption * sender) {}
+};
+class QuickOption
+{
+public:
+ enum Type {
+ Toggle, Multi
+ };
+protected:
+ std::vector<QuickOptionListener*> listeners;
+ GameModel * m;
+ Type type;
+ std::string icon;
+ std::string description;
+ QuickOption(std::string icon, std::string description, GameModel * m, Type type) :
+ icon(icon),
+ description(description),
+ m(m),
+ type(type)
+ {
+
+ }
+ virtual void perform() {}
+public:
+ virtual ~QuickOption()
+ {
+ //for(std::vector<QuickOptionListener*>::iterator iter = listeners.begin(), end = listeners.end(); iter != end; ++iter)
+ // delete *iter;
+ }
+
+ std::vector<QuickOptionListener*> GetListeners()
+ {
+ return listeners;
+ }
+
+ void AddListener(QuickOptionListener * listener)
+ {
+ listeners.push_back(listener);
+ }
+
+ Type GetType() { return type; }
+
+ virtual bool GetToggle() {}
+ virtual int GetMutli() {}
+ virtual int GetMultiCount() {}
+
+ std::string GetIcon() { return icon; }
+ void SetIcon(std::string icon) { this->icon = icon; }
+ std::string GetDescription() { return description; }
+ void SetDescription(std::string description) { this->description = description; }
+ void Perform()
+ {
+ perform();
+ for(std::vector<QuickOptionListener*>::iterator iter = listeners.begin(), end = listeners.end(); iter != end; ++iter)
+ (*iter)->OnValueChanged(this);
+ }
+ void Update()
+ {
+ for(std::vector<QuickOptionListener*>::iterator iter = listeners.begin(), end = listeners.end(); iter != end; ++iter)
+ (*iter)->OnValueChanged(this);
+ }
+};
+
diff --git a/src/game/QuickOptions.h b/src/game/QuickOptions.h
new file mode 100644
index 0000000..f194c1c
--- /dev/null
+++ b/src/game/QuickOptions.h
@@ -0,0 +1,99 @@
+#include "QuickOption.h"
+#include "GameModel.h"
+
+class SandEffectOption: public QuickOption
+{
+public:
+ SandEffectOption(GameModel * m):
+ QuickOption("P", "Sand effect", m, Toggle)
+ {
+
+ }
+ virtual bool GetToggle()
+ {
+ return m->GetSimulation()->pretty_powder;
+ }
+ virtual void perform()
+ {
+ m->GetSimulation()->pretty_powder = !m->GetSimulation()->pretty_powder;
+ }
+};
+
+class DrawGravOption: public QuickOption
+{
+public:
+ DrawGravOption(GameModel * m):
+ QuickOption("G", "Draw gravity field", m, Toggle)
+ {
+
+ }
+ virtual bool GetToggle()
+ {
+ return m->GetRenderer()->gravifyFieldEnabled;
+ }
+ virtual void perform()
+ {
+ m->GetRenderer()->gravifyFieldEnabled = !m->GetRenderer()->gravifyFieldEnabled;
+ }
+};
+
+class DecorationsOption: public QuickOption
+{
+public:
+ DecorationsOption(GameModel * m):
+ QuickOption("D", "Draw decorations", m, Toggle)
+ {
+
+ }
+ virtual bool GetToggle()
+ {
+ return m->GetRenderer()->decorations_enable;
+ }
+ virtual void perform()
+ {
+ m->GetRenderer()->decorations_enable = !m->GetRenderer()->decorations_enable;
+ }
+};
+
+class NGravityOption: public QuickOption
+{
+public:
+ NGravityOption(GameModel * m):
+ QuickOption("N", "Newtonian Gravity", m, Toggle)
+ {
+
+ }
+ virtual bool GetToggle()
+ {
+ return m->GetSimulation()->grav->ngrav_enable;
+ }
+ virtual void perform()
+ {
+ if(m->GetSimulation()->grav->ngrav_enable)
+ {
+ m->GetSimulation()->grav->stop_grav_async();
+ }
+ else
+ {
+ m->GetSimulation()->grav->start_grav_async();
+ }
+ }
+};
+
+class AHeatOption: public QuickOption
+{
+public:
+ AHeatOption(GameModel * m):
+ QuickOption("A", "Ambient heat", m, Toggle)
+ {
+
+ }
+ virtual bool GetToggle()
+ {
+ return m->GetSimulation()->aheat_enable;
+ }
+ virtual void perform()
+ {
+ m->GetSimulation()->aheat_enable = !m->GetSimulation()->aheat_enable;
+ }
+}; \ No newline at end of file
diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp
index 73d9b63..f18dbbb 100644
--- a/src/graphics/Renderer.cpp
+++ b/src/graphics/Renderer.cpp
@@ -39,9 +39,9 @@ void Renderer::RenderBegin()
{
draw_air();
+ draw_grav();
render_parts();
render_fire();
- draw_grav();
DrawWalls();
DrawSigns();
#ifndef OGLR
@@ -1899,6 +1899,9 @@ void Renderer::draw_grav()
int x, y, i, ca;
float nx, ny, dist;
+ if(!gravifyFieldEnabled)
+ return;
+
for (y=0; y<YRES/CELL; y++)
{
for (x=0; x<XRES/CELL; x++)
@@ -2096,7 +2099,8 @@ Renderer::Renderer(Graphics * g, Simulation * sim):
zoomScopeSize(32),
ZFACTOR(8),
zoomEnabled(false),
- decorations_enable(1)
+ decorations_enable(1),
+ gravifyFieldEnabled(false)
{
this->g = g;
this->sim = sim;
diff --git a/src/graphics/Renderer.h b/src/graphics/Renderer.h
index c292b80..721d39e 100644
--- a/src/graphics/Renderer.h
+++ b/src/graphics/Renderer.h
@@ -42,6 +42,7 @@ public:
char * plasma_data;
int emp_decor;
//
+ bool gravifyFieldEnabled;
int decorations_enable;
Simulation * sim;
Graphics * g;