Prevent property tool from being used with bad values (#791)
Co-authored-by: Tamás Bálint Misius <lbphacker@gmail.com>
This commit is contained in:
parent
e3c9176277
commit
f13fe3d36b
@ -53,7 +53,7 @@ public:
|
||||
Simulation *sim;
|
||||
std::vector<StructProperty> properties;
|
||||
PropertyWindow(PropertyTool *tool_, Simulation *sim);
|
||||
void SetProperty();
|
||||
void SetProperty(bool warn);
|
||||
void OnDraw() override;
|
||||
void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
|
||||
void OnTryExit(ExitMethod method) override;
|
||||
@ -81,7 +81,7 @@ sim(sim_)
|
||||
if (textField->GetText().length())
|
||||
{
|
||||
CloseActiveWindow();
|
||||
SetProperty();
|
||||
SetProperty(true);
|
||||
SelfDestruct();
|
||||
}
|
||||
} });
|
||||
@ -103,14 +103,17 @@ sim(sim_)
|
||||
textField->SetText(Client::Ref().GetPrefString("Prop.Value", ""));
|
||||
AddComponent(textField);
|
||||
FocusComponent(textField);
|
||||
SetProperty(false);
|
||||
|
||||
MakeActiveWindow();
|
||||
}
|
||||
|
||||
void PropertyWindow::SetProperty()
|
||||
void PropertyWindow::SetProperty(bool warn)
|
||||
{
|
||||
tool->validProperty = false;
|
||||
if(property->GetOption().second!=-1 && textField->GetText().length() > 0)
|
||||
{
|
||||
tool->validProperty = true;
|
||||
String value = textField->GetText().ToUpper();
|
||||
try {
|
||||
switch(properties[property->GetOption().second].Type)
|
||||
@ -174,7 +177,9 @@ void PropertyWindow::SetProperty()
|
||||
|
||||
if (properties[property->GetOption().second].Name == "type" && (v < 0 || v >= PT_NUM || !sim->elements[v].Enabled))
|
||||
{
|
||||
new ErrorMessage("Could not set property", "Invalid particle type");
|
||||
tool->validProperty = false;
|
||||
if (warn)
|
||||
new ErrorMessage("Could not set property", "Invalid particle type");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -214,14 +219,18 @@ void PropertyWindow::SetProperty()
|
||||
}
|
||||
break;
|
||||
default:
|
||||
new ErrorMessage("Could not set property", "Invalid property");
|
||||
tool->validProperty = false;
|
||||
if (warn)
|
||||
new ErrorMessage("Could not set property", "Invalid property");
|
||||
return;
|
||||
}
|
||||
tool->propOffset = properties[property->GetOption().second].Offset;
|
||||
tool->propType = properties[property->GetOption().second].Type;
|
||||
tool->changeType = properties[property->GetOption().second].Name == "type";
|
||||
} catch (const std::exception& ex) {
|
||||
new ErrorMessage("Could not set property", "Invalid value provided");
|
||||
tool->validProperty = false;
|
||||
if (warn)
|
||||
new ErrorMessage("Could not set property", "Invalid value provided");
|
||||
return;
|
||||
}
|
||||
Client::Ref().SetPref("Prop.Type", property->GetOption().second);
|
||||
@ -258,7 +267,7 @@ void PropertyTool::OpenWindow(Simulation *sim)
|
||||
|
||||
void PropertyTool::SetProperty(Simulation *sim, ui::Point position)
|
||||
{
|
||||
if(position.X<0 || position.X>XRES || position.Y<0 || position.Y>YRES)
|
||||
if(position.X<0 || position.X>XRES || position.Y<0 || position.Y>YRES || !validProperty)
|
||||
return;
|
||||
int i = sim->pmap[position.Y][position.X];
|
||||
if(!i)
|
||||
@ -379,5 +388,6 @@ void PropertyTool::DrawRect(Simulation *sim, Brush *cBrush, ui::Point position,
|
||||
|
||||
void PropertyTool::DrawFill(Simulation *sim, Brush *cBrush, ui::Point position)
|
||||
{
|
||||
sim->flood_prop(position.X, position.Y, propOffset, propValue, propType);
|
||||
if (validProperty)
|
||||
sim->flood_prop(position.X, position.Y, propOffset, propValue, propType);
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ public:
|
||||
PropertyValue propValue;
|
||||
bool changeType;
|
||||
size_t propOffset;
|
||||
bool validProperty;
|
||||
|
||||
void OpenWindow(Simulation *sim);
|
||||
virtual ~PropertyTool() {}
|
||||
|
Reference in New Issue
Block a user