diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-03 11:52:07 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-03 11:52:07 (GMT) |
| commit | 347c382e9964ef7954246399ab9d96df43dcbff0 (patch) | |
| tree | f720da533d4b129290e29d7e4c935ace41b68c57 /src | |
| parent | a3ebfb0ffde9c4ec9db5ace2e15968065c744cde (diff) | |
| download | powder-347c382e9964ef7954246399ab9d96df43dcbff0.zip powder-347c382e9964ef7954246399ab9d96df43dcbff0.tar.gz | |
Allow PROP to set types from element name, fixes issue #48
Diffstat (limited to 'src')
| -rw-r--r-- | src/game/PropertyTool.cpp | 45 | ||||
| -rw-r--r-- | src/simulation/Simulation.cpp | 18 | ||||
| -rw-r--r-- | src/simulation/Simulation.h | 2 |
3 files changed, 58 insertions, 7 deletions
diff --git a/src/game/PropertyTool.cpp b/src/game/PropertyTool.cpp index bddce44..4a04996 100644 --- a/src/game/PropertyTool.cpp +++ b/src/game/PropertyTool.cpp @@ -49,11 +49,13 @@ position(position_) ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Edit property"); messageLabel->SetTextColour(style::Colour::InformationTitle); - messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop; + messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop; AddComponent(messageLabel); ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 17), "OK"); - okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; okayButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom; + okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; okayButton->Appearance.BorderInactive = ui::Colour(200, 200, 200); okayButton->SetActionCallback(new OkayAction(this)); AddComponent(okayButton); @@ -66,15 +68,16 @@ position(position_) } property->SetOption(0); - textField = new ui::Textbox(ui::Point(8, 46), ui::Point(Size.X-16, 16), ""); - textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; textField->Appearance.VerticalAlign = ui::Appearance::AlignBottom; + textField = new ui::Textbox(ui::Point(8, 46), ui::Point(Size.X-16, 16), "", "[value]"); + textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + textField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; AddComponent(textField); ui::Engine::Ref().ShowWindow(this); } void PropertyWindow::SetProperty() { - if(property->GetOption().second!=-1) + if(property->GetOption().second!=-1 && textField->GetText().length() > 0) { void * propValue; int tempInt; @@ -102,8 +105,29 @@ void PropertyWindow::SetProperty() } else { - istringstream(value) >> tempInt; + if(properties[property->GetOption().second].Type == StructProperty::ParticleType) + { + int type = sim->GetParticleType(value); + if(type != -1) + { +#ifdef DEBUG + std::cout << "Got type from particle name" << std::endl; +#endif + tempInt = type; + } + else + { + stringstream(value) >> tempInt; + } + } + else + { + stringstream(value) >> tempInt; + } } +#ifdef DEBUG + std::cout << "Got int value " << tempInt << std::endl; +#endif propValue = &tempInt; break; case StructProperty::UInteger: @@ -123,12 +147,18 @@ void PropertyWindow::SetProperty() } else { - istringstream(value) >> tempUInt; + stringstream(value) >> tempUInt; } +#ifdef DEBUG + std::cout << "Got uint value " << tempUInt << std::endl; +#endif propValue = &tempUInt; break; case StructProperty::Float: istringstream(value) >> tempFloat; +#ifdef DEBUG + std::cout << "Got float value " << tempFloat << std::endl; +#endif propValue = &tempFloat; break; default: @@ -146,6 +176,7 @@ void PropertyWindow::SetProperty() } } } + void PropertyWindow::OnDraw() { Graphics * g = ui::Engine::Ref().g; diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index f1bea94..3f2796a 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -4294,6 +4294,24 @@ movedone: } } +int Simulation::GetParticleType(std::string type) +{ + int i = -1; + char * txt = (char*)type.c_str(); + + // alternative names for some elements + if (strcasecmp(txt,"C4")==0) i = PT_PLEX; + else if (strcasecmp(txt,"C5")==0) i = PT_C5; + else if (strcasecmp(txt,"NONE")==0) i = PT_NONE; + for (i=1; i<PT_NUM; i++) { + if (strcasecmp(txt, elements[i].Name)==0 && strlen(elements[i].Name) && elements[i].Enabled) + { + return i; + } + } + return -1; +} + void Simulation::update_particles()//doesn't update the particles themselves, but some other things { int i, j, x, y, t, nx, ny, r, cr,cg,cb, l = -1; diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index ff59a92..31a0a07 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -183,6 +183,8 @@ public: void GetGravityField(int x, int y, float particleGrav, float newtonGrav, float & pGravX, float & pGravY); + int GetParticleType(std::string type); + void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate); inline void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]); inline void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]); |
