Sample "into" the PROP tool when it is active

That is, if the PROP tool is active and is configured correctly, instead of sampling a type and activating the corresponding ElementTool, sample whichever property has been configured in the PROP tool and put the result back into the PROP tool.
This commit is contained in:
Tamás Bálint Misius 2023-09-29 21:27:28 +02:00
parent d1a4c6ad85
commit 146fb4b549
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
3 changed files with 59 additions and 6 deletions

View File

@ -222,6 +222,8 @@ void PropertyWindow::CheckProperty()
return; return;
} }
newConfiguration.prop = properties[property->GetOption().second]; newConfiguration.prop = properties[property->GetOption().second];
newConfiguration.propertyIndex = property->GetOption().second;
newConfiguration.propertyValueStr = value;
newConfiguration.changeType = properties[property->GetOption().second].Name == "type"; newConfiguration.changeType = properties[property->GetOption().second].Name == "type";
} }
catch (const std::exception& ex) catch (const std::exception& ex)
@ -231,17 +233,23 @@ void PropertyWindow::CheckProperty()
configuration = newConfiguration; configuration = newConfiguration;
} }
void PropertyWindow::SetProperty() void PropertyTool::SetConfiguration(std::optional<Configuration> newConfiguration)
{ {
tool->configuration = configuration; configuration = newConfiguration;
if (configuration)
{ {
auto &prefs = GlobalPrefs::Ref(); auto &prefs = GlobalPrefs::Ref();
Prefs::DeferWrite dw(prefs); Prefs::DeferWrite dw(prefs);
prefs.Set("Prop.Type", property->GetOption().second); prefs.Set("Prop.Type", configuration->propertyIndex);
prefs.Set("Prop.Value", textField->GetText()); prefs.Set("Prop.Value", configuration->propertyValueStr);
} }
} }
void PropertyWindow::SetProperty()
{
tool->SetConfiguration(configuration);
}
void PropertyWindow::OnTryExit(ExitMethod method) void PropertyWindow::OnTryExit(ExitMethod method)
{ {
CloseActiveWindow(); CloseActiveWindow();
@ -302,6 +310,39 @@ void PropertyTool::SetProperty(Simulation *sim, ui::Point position)
} }
} }
void PropertyTool::UpdateConfigurationFromParticle(const Particle &part)
{
auto configuration = GetConfiguration();
switch (configuration->prop.Type)
{
case StructProperty::Float:
{
auto value = *((float*)(((char*)&part)+configuration->prop.Offset));;
configuration->propValue = value;
configuration->propertyValueStr = String::Build(value);
}
break;
case StructProperty::ParticleType:
case StructProperty::Integer:
{
auto value = *((int*)(((char*)&part)+configuration->prop.Offset));;
configuration->propValue = value;
configuration->propertyValueStr = String::Build(value);
}
break;
case StructProperty::UInteger:
{
auto value = *((unsigned int*)(((char*)&part)+configuration->prop.Offset));;
configuration->propValue = value;
configuration->propertyValueStr = String::Build(value);
}
break;
default:
break;
}
SetConfiguration(configuration);
}
void PropertyTool::Draw(Simulation *sim, Brush const &cBrush, ui::Point position) void PropertyTool::Draw(Simulation *sim, Brush const &cBrush, ui::Point position)
{ {
for (ui::Point off : cBrush) for (ui::Point off : cBrush)

View File

@ -40,7 +40,13 @@ void SampleTool::Draw(Simulation * sim, Brush const &brush, ui::Point position)
} }
if (part) if (part)
{ {
if (part->type == PT_LIFE) auto *propTool = static_cast<PropertyTool *>(gameModel.GetToolFromIdentifier("DEFAULT_UI_PROPERTY"));
if (gameModel.GetActiveTool(0) == propTool && propTool->GetConfiguration())
{
propTool->UpdateConfigurationFromParticle(*part);
gameModel.SetActiveTool(0, propTool); // trigger change so Renderer::findingElement is updated
}
else if (part->type == PT_LIFE)
{ {
bool found = false; bool found = false;
for (auto *elementTool : gameModel.GetMenuList()[SC_LIFE]->GetToolList()) for (auto *elementTool : gameModel.GetMenuList()[SC_LIFE]->GetToolList())

View File

@ -10,6 +10,7 @@
class Simulation; class Simulation;
class Brush; class Brush;
class VideoBuffer; class VideoBuffer;
class Particle;
class Tool class Tool
{ {
@ -104,6 +105,8 @@ public:
StructProperty prop; StructProperty prop;
PropertyValue propValue; PropertyValue propValue;
bool changeType; bool changeType;
int propertyIndex;
String propertyValueStr;
}; };
private: private:
@ -124,13 +127,16 @@ public:
{} {}
void OpenWindow(Simulation *sim); void OpenWindow(Simulation *sim);
virtual void SetProperty(Simulation *sim, ui::Point position); void SetProperty(Simulation *sim, ui::Point position);
void UpdateConfigurationFromParticle(const Particle &part);
void Click(Simulation * sim, Brush const &brush, ui::Point position) override { } void Click(Simulation * sim, Brush const &brush, ui::Point position) override { }
void Draw(Simulation *sim, Brush const &brush, ui::Point position) override; void Draw(Simulation *sim, Brush const &brush, ui::Point position) override;
void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override; void DrawLine(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2, bool dragging = false) override;
void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override; void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override;
void DrawFill(Simulation * sim, Brush const &brush, ui::Point position) override; void DrawFill(Simulation * sim, Brush const &brush, ui::Point position) override;
void SetConfiguration(std::optional<Configuration> newConfiguration);
std::optional<Configuration> GetConfiguration() const std::optional<Configuration> GetConfiguration() const
{ {
return configuration; return configuration;