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:
parent
d1a4c6ad85
commit
146fb4b549
@ -222,6 +222,8 @@ void PropertyWindow::CheckProperty()
|
||||
return;
|
||||
}
|
||||
newConfiguration.prop = properties[property->GetOption().second];
|
||||
newConfiguration.propertyIndex = property->GetOption().second;
|
||||
newConfiguration.propertyValueStr = value;
|
||||
newConfiguration.changeType = properties[property->GetOption().second].Name == "type";
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
@ -231,17 +233,23 @@ void PropertyWindow::CheckProperty()
|
||||
configuration = newConfiguration;
|
||||
}
|
||||
|
||||
void PropertyWindow::SetProperty()
|
||||
void PropertyTool::SetConfiguration(std::optional<Configuration> newConfiguration)
|
||||
{
|
||||
tool->configuration = configuration;
|
||||
configuration = newConfiguration;
|
||||
if (configuration)
|
||||
{
|
||||
auto &prefs = GlobalPrefs::Ref();
|
||||
Prefs::DeferWrite dw(prefs);
|
||||
prefs.Set("Prop.Type", property->GetOption().second);
|
||||
prefs.Set("Prop.Value", textField->GetText());
|
||||
prefs.Set("Prop.Type", configuration->propertyIndex);
|
||||
prefs.Set("Prop.Value", configuration->propertyValueStr);
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyWindow::SetProperty()
|
||||
{
|
||||
tool->SetConfiguration(configuration);
|
||||
}
|
||||
|
||||
void PropertyWindow::OnTryExit(ExitMethod method)
|
||||
{
|
||||
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)
|
||||
{
|
||||
for (ui::Point off : cBrush)
|
||||
|
@ -40,7 +40,13 @@ void SampleTool::Draw(Simulation * sim, Brush const &brush, ui::Point position)
|
||||
}
|
||||
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;
|
||||
for (auto *elementTool : gameModel.GetMenuList()[SC_LIFE]->GetToolList())
|
||||
|
@ -10,6 +10,7 @@
|
||||
class Simulation;
|
||||
class Brush;
|
||||
class VideoBuffer;
|
||||
class Particle;
|
||||
|
||||
class Tool
|
||||
{
|
||||
@ -104,6 +105,8 @@ public:
|
||||
StructProperty prop;
|
||||
PropertyValue propValue;
|
||||
bool changeType;
|
||||
int propertyIndex;
|
||||
String propertyValueStr;
|
||||
};
|
||||
|
||||
private:
|
||||
@ -124,13 +127,16 @@ public:
|
||||
{}
|
||||
|
||||
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 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 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 SetConfiguration(std::optional<Configuration> newConfiguration);
|
||||
|
||||
std::optional<Configuration> GetConfiguration() const
|
||||
{
|
||||
return configuration;
|
||||
|
Reference in New Issue
Block a user