mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-16 22:08:28 +01:00
Fix Lua elements getting deselected when their properties change
This was because element tools associated with Lua elements were reallocated every time their properties changed. They are now properly updated instead. This is still a mess and I don't like it at all.
This commit is contained in:
parent
82ec6b2775
commit
c03c2f3fd0
@ -1695,32 +1695,44 @@ void GameModel::AllocCustomGolTool(const CustomGOLData &gd)
|
||||
AllocTool(std::make_unique<ElementTool>(PMAP(gd.rule, PT_LIFE), gd.nameString, "Custom GOL type: " + SerialiseGOLRule(gd.rule), gd.colour1, "DEFAULT_PT_LIFECUST_" + gd.nameString.ToAscii(), nullptr));
|
||||
}
|
||||
|
||||
void GameModel::UpdateElementTool(int element)
|
||||
{
|
||||
auto &sd = SimulationData::Ref();
|
||||
auto &elements = sd.elements;
|
||||
auto &elem = elements[element];
|
||||
auto *tool = GetToolFromIdentifier(elem.Identifier);
|
||||
tool->Name = elem.Name;
|
||||
tool->Description = elem.Description;
|
||||
tool->Colour = elem.Colour;
|
||||
tool->textureGen = elem.IconGenerator;
|
||||
}
|
||||
|
||||
void GameModel::AllocElementTool(int element)
|
||||
{
|
||||
auto &sd = SimulationData::Ref();
|
||||
auto &elements = sd.elements;
|
||||
auto &elem = elements[element];
|
||||
FreeTool(GetToolFromIdentifier(elem.Identifier));
|
||||
switch (element)
|
||||
{
|
||||
case PT_LIGH:
|
||||
AllocTool(std::make_unique<Element_LIGH_Tool>(element, elem.Name, elem.Description, elem.Colour, elem.Identifier, elem.IconGenerator));
|
||||
AllocTool(std::make_unique<Element_LIGH_Tool>(element, elem.Identifier));
|
||||
break;
|
||||
|
||||
case PT_TESC:
|
||||
AllocTool(std::make_unique<Element_TESC_Tool>(element, elem.Name, elem.Description, elem.Colour, elem.Identifier, elem.IconGenerator));
|
||||
AllocTool(std::make_unique<Element_TESC_Tool>(element, elem.Identifier));
|
||||
break;
|
||||
|
||||
case PT_STKM:
|
||||
case PT_FIGH:
|
||||
case PT_STKM2:
|
||||
AllocTool(std::make_unique<PlopTool>(element, elem.Name, elem.Description, elem.Colour, elem.Identifier, elem.IconGenerator));
|
||||
AllocTool(std::make_unique<PlopTool>(element, elem.Identifier));
|
||||
break;
|
||||
|
||||
default:
|
||||
AllocTool(std::make_unique<ElementTool>(element, elem.Name, elem.Description, elem.Colour, elem.Identifier, elem.IconGenerator));
|
||||
AllocTool(std::make_unique<ElementTool>(element, elem.Identifier));
|
||||
break;
|
||||
}
|
||||
UpdateElementTool(element);
|
||||
}
|
||||
|
||||
void GameModel::InitTools()
|
||||
|
@ -202,6 +202,7 @@ public:
|
||||
std::vector<Tool *> GetActiveMenuToolList();
|
||||
void AllocTool(std::unique_ptr<Tool> tool);
|
||||
void AllocElementTool(int element);
|
||||
void UpdateElementTool(int element);
|
||||
void AllocCustomGolTool(const CustomGOLData &gd);
|
||||
void FreeTool(Tool *tool);
|
||||
|
||||
|
@ -9,6 +9,9 @@ public:
|
||||
Tool(id, name, description, colour, identifier, textureGen)
|
||||
{}
|
||||
|
||||
ElementTool(int id, ByteString identifier) : Tool(id, identifier)
|
||||
{}
|
||||
|
||||
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) override;
|
||||
void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override;
|
||||
@ -18,9 +21,7 @@ public:
|
||||
class Element_LIGH_Tool: public ElementTool
|
||||
{
|
||||
public:
|
||||
Element_LIGH_Tool(int id, String name, String description,
|
||||
RGB<uint8_t> colour, ByteString identifier, std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = NULL):
|
||||
ElementTool(id, name, description, colour, identifier, textureGen)
|
||||
Element_LIGH_Tool(int id, ByteString identifier) : ElementTool(id, identifier)
|
||||
{}
|
||||
|
||||
void Click(Simulation * sim, Brush const &brush, ui::Point position) override { }
|
||||
@ -32,9 +33,7 @@ public:
|
||||
class Element_TESC_Tool: public ElementTool
|
||||
{
|
||||
public:
|
||||
Element_TESC_Tool(int id, String name, String description,
|
||||
RGB<uint8_t> colour, ByteString identifier, std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = NULL):
|
||||
ElementTool(id, name, description, colour, identifier, textureGen)
|
||||
Element_TESC_Tool(int id, ByteString identifier) : ElementTool(id, identifier)
|
||||
{}
|
||||
|
||||
void DrawRect(Simulation * sim, Brush const &brush, ui::Point position1, ui::Point position2) override;
|
||||
@ -44,9 +43,7 @@ public:
|
||||
class PlopTool: public ElementTool
|
||||
{
|
||||
public:
|
||||
PlopTool(int id, String name, String description,
|
||||
RGB<uint8_t> colour, ByteString identifier, std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = NULL):
|
||||
ElementTool(id, name, description, colour, identifier, textureGen)
|
||||
PlopTool(int id, ByteString identifier) : ElementTool(id, identifier)
|
||||
{}
|
||||
|
||||
void Draw(Simulation * sim, Brush const &brush, ui::Point position) override { }
|
||||
|
@ -14,10 +14,9 @@ struct Particle;
|
||||
|
||||
class Tool
|
||||
{
|
||||
private:
|
||||
public:
|
||||
std::unique_ptr<VideoBuffer> (*textureGen)(int, Vec2<int>) = nullptr;
|
||||
|
||||
public:
|
||||
int ToolID = 0;
|
||||
String Name = "NULL";
|
||||
String Description = "NULL Tool, does NOTHING";
|
||||
@ -43,6 +42,9 @@ public:
|
||||
Blocky(blocky)
|
||||
{}
|
||||
|
||||
Tool(int id, ByteString identifier) : ToolID(id), Identifier(identifier)
|
||||
{}
|
||||
|
||||
virtual ~Tool()
|
||||
{}
|
||||
|
||||
|
@ -525,7 +525,7 @@ static int element(lua_State *L)
|
||||
|
||||
sd.graphicscache[id].isready = 0;
|
||||
}
|
||||
lsi->gameModel->AllocElementTool(id);
|
||||
lsi->gameModel->UpdateElementTool(id);
|
||||
lsi->gameModel->BuildMenus();
|
||||
lsi->InitCustomCanMove();
|
||||
|
||||
@ -593,7 +593,7 @@ static int property(lua_State *L)
|
||||
manageElementIdentifier(L, id, false);
|
||||
LuaSetProperty(L, *prop, propertyAddress, 3);
|
||||
manageElementIdentifier(L, id, true);
|
||||
lsi->gameModel->AllocElementTool(id);
|
||||
lsi->gameModel->UpdateElementTool(id);
|
||||
lsi->gameModel->BuildMenus();
|
||||
lsi->InitCustomCanMove();
|
||||
sd.graphicscache[id].isready = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user