summaryrefslogtreecommitdiff
path: root/src/game/PropertyTool.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-05-14 23:10:10 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-05-14 23:10:10 (GMT)
commit45563e97e813cfd21724ad1111e5de3e04679e1a (patch)
tree28d6e7d257c8790fa4ac892cb051bd9a86f3681d /src/game/PropertyTool.cpp
parent0b4ad4f25cf168226677f648cf4cadfdb6caa59a (diff)
downloadpowder-45563e97e813cfd21724ad1111e5de3e04679e1a.zip
powder-45563e97e813cfd21724ad1111e5de3e04679e1a.tar.gz
Make flood_prop use PropertyType from StructProperty, Property tool works
Diffstat (limited to 'src/game/PropertyTool.cpp')
-rw-r--r--src/game/PropertyTool.cpp112
1 files changed, 97 insertions, 15 deletions
diff --git a/src/game/PropertyTool.cpp b/src/game/PropertyTool.cpp
index 6d6bb68..ccc7a8d 100644
--- a/src/game/PropertyTool.cpp
+++ b/src/game/PropertyTool.cpp
@@ -1,4 +1,5 @@
#include <iostream>
+#include <sstream>
#include "Style.h"
#include "simulation/Simulation.h"
#include "Tool.h"
@@ -7,6 +8,7 @@
#include "interface/Label.h"
#include "interface/Textbox.h"
#include "interface/DropDown.h"
+#include "dialogues/ErrorMessage.h"
class PropertyWindow: public ui::Window
{
@@ -17,22 +19,25 @@ public:
Simulation * sim;
int signID;
ui::Point position;
+ std::vector<StructProperty> properties;
PropertyWindow(PropertyTool * tool_, Simulation * sim_, ui::Point position_);
+ void SetProperty();
virtual void OnDraw();
virtual ~PropertyWindow() {}
-};
-
-class OkayAction: public ui::ButtonAction
-{
-public:
- PropertyWindow * prompt;
- OkayAction(PropertyWindow * prompt_) { prompt = prompt_; }
- void ActionCallback(ui::Button * sender)
+ class OkayAction: public ui::ButtonAction
{
- ui::Engine::Ref().CloseWindow();
-
- prompt->SelfDestruct();
- }
+ public:
+ PropertyWindow * prompt;
+ OkayAction(PropertyWindow * prompt_) { prompt = prompt_; }
+ void ActionCallback(ui::Button * sender)
+ {
+ ui::Engine::Ref().CloseWindow();
+ if(prompt->textField->GetText().length())
+ prompt->SetProperty();
+ prompt->SelfDestruct();
+ return;
+ }
+ };
};
PropertyWindow::PropertyWindow(PropertyTool * tool_, Simulation * sim_, ui::Point position_):
@@ -40,6 +45,8 @@ ui::Window(ui::Point(-1, -1), ui::Point(200, 87)),
sim(sim_),
position(position_)
{
+ properties = Particle::GetProperties();
+
ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Edit property");
messageLabel->SetTextColour(style::Colour::InformationTitle);
messageLabel->SetAlignment(AlignLeft, AlignTop);
@@ -53,9 +60,10 @@ position(position_)
property = new ui::DropDown(ui::Point(8, 25), ui::Point(Size.X-16, 17));
AddComponent(property);
- property->AddOption(std::pair<std::string, int>("Left", (int)sign::Left));
- property->AddOption(std::pair<std::string, int>("Centre", (int)sign::Centre));
- property->AddOption(std::pair<std::string, int>("Right", (int)sign::Right));
+ for(int i = 0; i < properties.size(); i++)
+ {
+ property->AddOption(std::pair<std::string, int>(properties[i].Name, i));
+ }
property->SetOption(0);
textField = new ui::Textbox(ui::Point(8, 46), ui::Point(Size.X-16, 16), "");
@@ -64,6 +72,80 @@ position(position_)
ui::Engine::Ref().ShowWindow(this);
}
+void PropertyWindow::SetProperty()
+{
+ if(property->GetOption().second!=-1)
+ {
+ void * propValue;
+ int tempInt;
+ unsigned int tempUInt;
+ float tempFloat;
+ std::string value = textField->GetText();
+ try {
+ switch(properties[property->GetOption().second].Type)
+ {
+ case StructProperty::Integer:
+ case StructProperty::ParticleType:
+ if(value.length() > 2 && value.substr(0, 2) == "0x")
+ {
+ //0xC0FFEE
+ stringstream buffer;
+ buffer << std::hex << value.substr(2);
+ buffer >> tempInt;
+ }
+ else if(value.length() > 1 && value[0] == '#')
+ {
+ //#C0FFEE
+ stringstream buffer;
+ buffer << std::hex << value.substr(1);
+ buffer >> tempInt;
+ }
+ else
+ {
+ istringstream(value) >> tempInt;
+ }
+ propValue = &tempInt;
+ break;
+ case StructProperty::UInteger:
+ if(value.length() > 2 && value.substr(0, 2) == "0x")
+ {
+ //0xC0FFEE
+ stringstream buffer;
+ buffer << std::hex << value.substr(2);
+ buffer >> tempUInt;
+ }
+ else if(value.length() > 1 && value[0] == '#')
+ {
+ //#C0FFEE
+ stringstream buffer;
+ buffer << std::hex << value.substr(1);
+ buffer >> tempUInt;
+ }
+ else
+ {
+ istringstream(value) >> tempUInt;
+ }
+ propValue = &tempUInt;
+ break;
+ case StructProperty::Float:
+ istringstream(value) >> tempFloat;
+ propValue = &tempFloat;
+ break;
+ default:
+ new ErrorMessage("Could not set property", "Invalid property");
+ }
+ sim->flood_prop(
+ position.X,
+ position.Y,
+ properties[property->GetOption().second].Offset,
+ propValue,
+ properties[property->GetOption().second].Type
+ );
+ } catch (const std::exception& ex) {
+ new ErrorMessage("Could not set property", "Invalid value provided");
+ }
+ }
+}
void PropertyWindow::OnDraw()
{
Graphics * g = ui::Engine::Ref().g;