summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-23 10:50:48 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-23 10:50:48 (GMT)
commit8a65c395f490baea3b55f1418207c4ee172a2b3a (patch)
tree261957afa7218bd67d4a59c32594488aff269861 /src
parent8c0678fa48f9598a5ade2d4960c46bfea7e6abef (diff)
downloadpowder-8a65c395f490baea3b55f1418207c4ee172a2b3a.zip
powder-8a65c395f490baea3b55f1418207c4ee172a2b3a.tar.gz
Element menu
Diffstat (limited to 'src')
-rw-r--r--src/game/GameController.cpp12
-rw-r--r--src/game/GameController.h2
-rw-r--r--src/game/GameModel.cpp11
-rw-r--r--src/game/GameModel.h1
-rw-r--r--src/game/GameView.cpp58
-rw-r--r--src/game/GameView.h3
-rw-r--r--src/game/Tool.h8
-rw-r--r--src/interface/Button.cpp17
-rw-r--r--src/interface/Button.h2
9 files changed, 106 insertions, 8 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 5749fd4..9056ba8 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -88,7 +88,7 @@ void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
void GameController::Tick()
{
- //gameModel->GetSimulation()->update_particles();
+ gameModel->GetSimulation()->update_particles();
}
void GameController::SetPaused(bool pauseState)
@@ -96,11 +96,21 @@ void GameController::SetPaused(bool pauseState)
gameModel->SetPaused(pauseState);
}
+void GameController::SetPaused()
+{
+ gameModel->SetPaused(!gameModel->GetPaused());
+}
+
void GameController::SetActiveMenu(Menu * menu)
{
gameModel->SetActiveMenu(menu);
}
+void GameController::SetActiveTool(Tool * tool)
+{
+ gameModel->SetActiveTool(tool);
+}
+
void GameController::OpenSearch()
{
search = new SearchController();
diff --git a/src/game/GameController.h b/src/game/GameController.h
index d83c459..d7232d2 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -28,7 +28,9 @@ public:
void DrawPoints(queue<ui::Point*> & pointQueue);
void Tick();
void SetPaused(bool pauseState);
+ void SetPaused();
void SetActiveMenu(Menu * menu);
+ void SetActiveTool(Tool * tool);
void OpenSearch();
void OpenLogin();
void OpenTags();
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 090f46a..91b1c8d 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -26,7 +26,7 @@ GameModel::GameModel():
{
if(sim->ptypes[i].menusection < 12)
{
- Tool * tempTool = new ElementTool(i, sim->ptypes[i].name, 0, 0, 0);
+ Tool * tempTool = new ElementTool(i, sim->ptypes[i].name, PIXR(sim->ptypes[i].pcolors), PIXG(sim->ptypes[i].pcolors), PIXB(sim->ptypes[i].pcolors));
menuList[sim->ptypes[i].menusection]->AddTool(tempTool);
}
}
@@ -96,6 +96,7 @@ Tool * GameModel::GetActiveTool()
void GameModel::SetActiveTool(Tool * tool)
{
activeTool = tool;
+ notifyActiveToolChanged();
}
vector<Menu*> GameModel::GetMenuList()
@@ -195,3 +196,11 @@ void GameModel::notifyToolListChanged()
observers[i]->NotifyToolListChanged(this);
}
}
+
+void GameModel::notifyActiveToolChanged()
+{
+ for(int i = 0; i < observers.size(); i++)
+ {
+ observers[i]->NotifyActiveToolChanged(this);
+ }
+}
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index d65165b..14319e7 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -36,6 +36,7 @@ private:
void notifyBrushChanged();
void notifyMenuListChanged();
void notifyToolListChanged();
+ void notifyActiveToolChanged();
public:
GameModel();
~GameModel();
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index ed2094d..80965ce 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -187,6 +187,18 @@ public:
}
};
+class GameView::ToolAction: public ui::ButtonAction
+{
+ GameView * v;
+public:
+ Tool * tool;
+ ToolAction(GameView * _v, Tool * tool_) { v = _v; tool = tool_; }
+ void ActionCallback(ui::Button * sender)
+ {
+ v->c->SetActiveTool(tool);
+ }
+};
+
void GameView::NotifyMenuListChanged(GameModel * sender)
{
int currentY = YRES+MENUSIZE-36;
@@ -216,8 +228,24 @@ void GameView::NotifyMenuListChanged(GameModel * sender)
}
}
+void GameView::NotifyActiveToolChanged(GameModel * sender)
+{
+ for(int i = 0; i < toolButtons.size(); i++)
+ {
+ if(((ToolAction*)toolButtons[i]->GetActionCallback())->tool==sender->GetActiveTool())
+ {
+ toolButtons[i]->SetToggleState(true);
+ }
+ else
+ {
+ toolButtons[i]->SetToggleState(false);
+ }
+ }
+}
+
void GameView::NotifyToolListChanged(GameModel * sender)
{
+ int currentX = XRES+BARSIZE-56;
for(int i = 0; i < menuButtons.size(); i++)
{
if(((MenuAction*)menuButtons[i]->GetActionCallback())->menu==sender->GetActiveMenu())
@@ -229,6 +257,25 @@ void GameView::NotifyToolListChanged(GameModel * sender)
menuButtons[i]->SetToggleState(false);
}
}
+ for(int i = 0; i < toolButtons.size(); i++)
+ {
+ RemoveComponent(toolButtons[i]);
+ delete toolButtons[i];
+ }
+ toolButtons.clear();
+ vector<Tool*> toolList = sender->GetToolList();
+ for(int i = 0; i < toolList.size(); i++)
+ {
+ ui::Button * tempButton = new ui::Button(ui::Point(currentX, YRES), ui::Point(32, 16), toolList[i]->GetName());
+ currentX -= 36;
+ tempButton->SetTogglable(true);
+ tempButton->SetActionCallback(new ToolAction(this, toolList[i]));
+ tempButton->SetBackgroundColour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue);
+ tempButton->SetAlignment(AlignCentre, AlignBottom);
+ AddComponent(tempButton);
+ toolButtons.push_back(tempButton);
+ }
+
}
void GameView::NotifyRendererChanged(GameModel * sender)
@@ -313,6 +360,15 @@ void GameView::OnMouseWheel(int x, int y, int d)
}
}
+void GameView::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
+{
+ switch(key)
+ {
+ case ' ':
+ c->SetPaused();
+ }
+}
+
void GameView::OnTick(float dt)
{
if(!pointQueue.empty())
@@ -327,6 +383,8 @@ void GameView::OnDraw()
if(ren)
{
ren->render_parts();
+ ren->render_fire();
+ ren->render_signs();
}
if(activeBrush)
{
diff --git a/src/game/GameView.h b/src/game/GameView.h
index c27c2cc..3881795 100644
--- a/src/game/GameView.h
+++ b/src/game/GameView.h
@@ -46,15 +46,18 @@ public:
void NotifyBrushChanged(GameModel * sender);
void NotifyMenuListChanged(GameModel * sender);
void NotifyToolListChanged(GameModel * sender);
+ void NotifyActiveToolChanged(GameModel * sender);
virtual void OnMouseMove(int x, int y, int dx, int dy);
virtual void OnMouseDown(int x, int y, unsigned button);
virtual void OnMouseUp(int x, int y, unsigned button);
virtual void OnMouseWheel(int x, int y, int d);
+ virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
//virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt) {}
//virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {}
virtual void OnTick(float dt);
virtual void OnDraw();
class MenuAction;
+ class ToolAction;
};
#endif // GAMEVIEW_H
diff --git a/src/game/Tool.h b/src/game/Tool.h
index 842f4a2..4777e6d 100644
--- a/src/game/Tool.h
+++ b/src/game/Tool.h
@@ -15,10 +15,10 @@ using namespace std;
class Tool
{
protected:
- int toolID, colRed, colBlue, colGreen;
+ int toolID;
string toolName;
public:
- Tool(int id, string name, int r, int b, int g):
+ Tool(int id, string name, int r, int g, int b):
toolID(id),
toolName(name),
colRed(r),
@@ -26,16 +26,18 @@ public:
colBlue(b)
{
}
+ string GetName() { return toolName; }
virtual ~Tool() {}
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) {}
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {}
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {}
+ int colRed, colBlue, colGreen;
};
class ElementTool: public Tool
{
public:
- ElementTool(int id, string name, int r, int b, int g):
+ ElementTool(int id, string name, int r, int g, int b):
Tool(id, name, r, g, b)
{
}
diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp
index e0f5172..2694de5 100644
--- a/src/interface/Button.cpp
+++ b/src/interface/Button.cpp
@@ -26,7 +26,10 @@ Button::Button(Window* parent_state, std::string buttonText):
textPosition(ui::Point(0, 0)),
textVAlign(AlignMiddle),
textHAlign(AlignCentre),
- Enabled(true)
+ Enabled(true),
+ colr(0),
+ colg(0),
+ colb(0)
{
TextPosition();
}
@@ -42,7 +45,10 @@ Button::Button(Point position, Point size, std::string buttonText):
textPosition(ui::Point(0, 0)),
textVAlign(AlignMiddle),
textHAlign(AlignCentre),
- Enabled(true)
+ Enabled(true),
+ colr(0),
+ colg(0),
+ colb(0)
{
TextPosition();
}
@@ -58,7 +64,10 @@ Button::Button(std::string buttonText):
textPosition(ui::Point(0, 0)),
textVAlign(AlignMiddle),
textHAlign(AlignCentre),
- Enabled(true)
+ Enabled(true),
+ colr(0),
+ colg(0),
+ colb(0)
{
TextPosition();
}
@@ -135,6 +144,8 @@ void Button::Draw(const Point& screenPos)
{
if(isMouseInside)
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 20, 20, 20, 255);
+ else
+ g->fillrect(Position.X, Position.Y, Size.X, Size.Y, colr, colg, colb, 255);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 255, 255, 255, 255);
}
diff --git a/src/interface/Button.h b/src/interface/Button.h
index a137aac..bff54c9 100644
--- a/src/interface/Button.h
+++ b/src/interface/Button.h
@@ -59,7 +59,9 @@ public:
HorizontalAlignment GetHAlignment() { return textHAlign; }
VerticalAlignment GetVAlignment() { return textVAlign; }
void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
+ void SetBackgroundColour(int colr, int colg, int colb) { this->colr = colr; this->colg = colg; this->colb = colb; }
protected:
+ int colr, colg, colb;
bool isButtonDown, state, isMouseInside, isTogglable, toggle;
ButtonAction * actionCallback;
ui::Point textPosition;