summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-05-12 21:28:45 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-05-12 21:28:45 (GMT)
commit724c99102e1d2ed3a2c347eedb05d9818bac7513 (patch)
tree036b97a683491243f79e42daf65c4f00ecf36c97 /src/game
parent7128188048395f503b2f70ace2880459acdf7515 (diff)
downloadpowder-724c99102e1d2ed3a2c347eedb05d9818bac7513.zip
powder-724c99102e1d2ed3a2c347eedb05d9818bac7513.tar.gz
Stupid git
Diffstat (limited to 'src/game')
-rw-r--r--src/game/GameModel.cpp6
-rw-r--r--src/game/SignTool.cpp88
-rw-r--r--src/game/Tool.h42
3 files changed, 122 insertions, 14 deletions
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index c040566..60e3c15 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -93,6 +93,10 @@ GameModel::GameModel():
//sim->wtypes[i]
}
+ //Add special sign and prop tools
+ menuList[SC_TOOL]->AddTool(new SignTool());
+ menuList[SC_TOOL]->AddTool(new PropertyTool());
+
//Build menu for simtools
for(int i = 0; i < sim->tools.size(); i++)
{
@@ -109,8 +113,8 @@ GameModel::GameModel():
menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendSet, "SET", 0, 0, 0));
//Set default brush palette
- brushList.push_back(new Brush(ui::Point(4, 4)));
brushList.push_back(new EllipseBrush(ui::Point(4, 4)));
+ brushList.push_back(new Brush(ui::Point(4, 4)));
//Set default tools
activeTools[0] = menuList[SC_POWDERS]->GetToolList()[0];
diff --git a/src/game/SignTool.cpp b/src/game/SignTool.cpp
index ce4c181..50ddb8a 100644
--- a/src/game/SignTool.cpp
+++ b/src/game/SignTool.cpp
@@ -1,9 +1,81 @@
-//
-// SignTool.cpp
-// PowderToypp
-//
-// Created by Simon Robertshaw on 12/05/2012.
-// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
-//
-
#include <iostream>
+#include "simulation/Simulation.h"
+#include "Tool.h"
+#include "interface/Window.h"
+#include "interface/Button.h"
+#include "interface/Label.h"
+#include "interface/Textbox.h"
+
+class SignWindow: public ui::Window
+{
+public:
+ ui::Textbox * textField;
+ SignTool * tool;
+ Simulation * sim;
+ int signID;
+ ui::Point signPosition;
+ SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Point position_);
+ virtual void OnDraw();
+ virtual ~SignWindow() {}
+};
+
+class OkayAction: public ui::ButtonAction
+{
+public:
+ SignWindow * prompt;
+ OkayAction(SignWindow * prompt_) { prompt = prompt_; }
+ void ActionCallback(ui::Button * sender)
+ {
+ ui::Engine::Ref().CloseWindow();
+ prompt->SelfDestruct();
+
+ if(prompt->signID==-1 && prompt->textField->GetText().length())
+ {
+ prompt->sim->signs.push_back(sign(prompt->textField->GetText(), prompt->signPosition.X, prompt->signPosition.Y, sign::Left));
+ }
+ else
+ {
+ prompt->sim->signs[prompt->signID] = sign(sign(prompt->textField->GetText(), prompt->signPosition.X, prompt->signPosition.Y, sign::Left));
+ }
+ }
+};
+
+SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Point position_):
+ ui::Window(ui::Point(-1, -1), ui::Point(200, 75)),
+ tool(tool_),
+ signID(signID_),
+ sim(sim_),
+ signPosition(position_)
+{
+ ui::Label * messageLabel = new ui::Label(ui::Point(4, 18), ui::Point(Size.X-8, 60), "New sign");
+ messageLabel->SetAlignment(AlignLeft, AlignTop);
+ AddComponent(messageLabel);
+
+ ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "OK");
+ okayButton->SetAlignment(AlignLeft, AlignBottom);
+ okayButton->SetBorderColour(ui::Colour(200, 200, 200));
+ okayButton->SetActionCallback(new OkayAction(this));
+ AddComponent(okayButton);
+
+ textField = new ui::Textbox(ui::Point(4, 32), ui::Point(Size.X-8, 16), "");
+ textField->SetAlignment(AlignLeft, AlignBottom);
+ AddComponent(textField);
+
+ ui::Engine::Ref().ShowWindow(this);
+}
+void SignWindow::OnDraw()
+{
+ Graphics * g = ui::Engine::Ref().g;
+
+ g->clearrect(Position.X-2, Position.Y-2, Size.X+4, Size.Y+4);
+ g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 200, 200, 200, 255);
+}
+
+void SignTool::Draw(Simulation * sim, Brush * brush, ui::Point position)
+{
+ if(!opened) //Ensure the dialogue can only be shown one at a time.
+ {
+ opened = true;
+ new SignWindow(this, sim, -1, position);
+ }
+} \ No newline at end of file
diff --git a/src/game/Tool.h b/src/game/Tool.h
index 9f88188..935e598 100644
--- a/src/game/Tool.h
+++ b/src/game/Tool.h
@@ -19,11 +19,11 @@ protected:
string toolName;
public:
Tool(int id, string name, int r, int g, int b):
- toolID(id),
- toolName(name),
- colRed(r),
- colGreen(g),
- colBlue(b)
+ toolID(id),
+ toolName(name),
+ colRed(r),
+ colGreen(g),
+ colBlue(b)
{
}
string GetName() { return toolName; }
@@ -41,6 +41,38 @@ public:
int colRed, colBlue, colGreen;
};
+class SignTool: public Tool
+{
+public:
+ SignTool():
+ Tool(0, "SIGN", 0, 0, 0),
+ opened(false)
+ {
+ }
+ virtual ~SignTool() {}
+ 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) { }
+ virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { }
+ void SetClosed() { opened = false; }
+protected:
+ bool opened;
+};
+
+class PropertyTool: public Tool
+{
+public:
+ PropertyTool():
+ Tool(0, "PROP", 0, 0, 0)
+ {
+ }
+ virtual ~PropertyTool() {}
+ 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) { }
+ virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { }
+};
+
class ElementTool: public Tool
{
public: