diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 8979d2b90..9cbf16a69 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1121,14 +1121,7 @@ void GameController::SetActiveTool(int toolSelection, Tool * tool) gameModel->GetRendererSettings().gravityZonesEnabled = true; } } - if (tool->Identifier == "DEFAULT_UI_PROPERTY") - { - static_cast(tool)->OpenWindow(gameModel->GetSimulation(), std::nullopt); - } - if(tool->Identifier == "DEFAULT_UI_ADDLIFE") - { - static_cast(tool)->OpenWindow(gameModel->GetSimulation(), toolSelection); - } + tool->Select(toolSelection); } void GameController::SetActiveTool(int toolSelection, ByteString identifier) diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index c0c8cb547..eccd3f40d 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -1775,7 +1775,7 @@ void GameModel::InitTools() AllocTool(std::make_unique(view, DECO_SMUDGE , "SMDG", "Smudge tool, blends surrounding deco together.", 0x000000_rgb, "DEFAULT_DECOR_SMDG")); AllocTool(std::make_unique(view, DECO_CLEAR , "CLR" , "Erase any set decoration." , 0x000000_rgb, "DEFAULT_DECOR_CLR" )); AllocTool(std::make_unique(view, DECO_DRAW , "SET" , "Draw decoration (No blending)." , 0x000000_rgb, "DEFAULT_DECOR_SET" )); - AllocTool(std::make_unique()); + AllocTool(std::make_unique(*this)); AllocTool(std::make_unique(*this)); AllocTool(std::make_unique(*this)); AllocTool(std::make_unique(*this)); diff --git a/src/gui/game/tool/GOLTool.cpp b/src/gui/game/tool/GOLTool.cpp index 467a5dc81..272fa0b6e 100644 --- a/src/gui/game/tool/GOLTool.cpp +++ b/src/gui/game/tool/GOLTool.cpp @@ -200,3 +200,8 @@ void GOLTool::OpenWindow(Simulation *sim, int toolSelection, int rule, RGBflood_prop(position.X, position.Y, configuration->changeProperty); } + +void PropertyTool::Select(int toolSelection) +{ + OpenWindow(gameModel.GetSimulation(), std::nullopt); +} diff --git a/src/gui/game/tool/PropertyTool.h b/src/gui/game/tool/PropertyTool.h index 6b2fa1f51..dafdc837a 100644 --- a/src/gui/game/tool/PropertyTool.h +++ b/src/gui/game/tool/PropertyTool.h @@ -18,15 +18,16 @@ private: void SetProperty(Simulation *sim, ui::Point position); void SetConfiguration(std::optional newConfiguration); + GameModel &gameModel; std::optional configuration; friend class PropertyWindow; public: - PropertyTool(): + PropertyTool(GameModel &newGameModel): Tool(0, "PROP", "Property Drawing Tool. Use to alter the properties of elements in the field.", 0xFEA900_rgb, "DEFAULT_UI_PROPERTY", NULL - ) + ), gameModel(newGameModel) {} void OpenWindow(Simulation *sim, std::optional takePropertyFrom); @@ -40,4 +41,6 @@ public: { return configuration; } + + void Select(int toolSelection) final override; }; diff --git a/src/gui/game/tool/Tool.h b/src/gui/game/tool/Tool.h index adb09f131..0238cdb4a 100644 --- a/src/gui/game/tool/Tool.h +++ b/src/gui/game/tool/Tool.h @@ -61,6 +61,8 @@ public: virtual void Drag(Simulation *sim, const Brush &brush, ui::Point position1, ui::Point position2) { } + + virtual void Select(int toolSelection) + { + } }; - - diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index 2519a5c5a..cfcae63d7 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -67,6 +67,7 @@ struct CustomTool LuaSmartRef drawLine; LuaSmartRef drawRect; LuaSmartRef drawFill; + LuaSmartRef select; }; class LuaScriptInterface : public CommandInterface diff --git a/src/lua/LuaTools.cpp b/src/lua/LuaTools.cpp index 0480c58b8..68400bf3f 100644 --- a/src/lua/LuaTools.cpp +++ b/src/lua/LuaTools.cpp @@ -250,6 +250,24 @@ static void luaDrawFillWrapper(SimTool *tool, Simulation *sim, const Brush &brus } } +static void luaSelectWrapper(SimTool *tool, int toolSelection) +{ + auto *lsi = GetLSI(); + auto L = lsi->L; + auto index = *lsi->gameModel->GetToolIndex(tool); + auto &customTools = lsi->customTools; + if (customTools[index].select) + { + lua_rawgeti(L, LUA_REGISTRYINDEX, customTools[index].select); + lua_pushinteger(L, toolSelection); + if (tpt_lua_pcall(L, 1, 0, 0, eventTraitNone)) + { + lsi->Log(CommandInterface::LogError, "In select func: " + LuaGetError()); + lua_pop(L, 1); + } + } +} + template struct DependentFalse : std::false_type { @@ -301,7 +319,8 @@ static int property(lua_State *L) handleCallback(&CustomTool::draw , &SimTool::PerformDraw , luaDrawWrapper , "Draw" ) || handleCallback(&CustomTool::drawLine, &SimTool::PerformDrawLine, luaDrawLineWrapper, "DrawLine") || handleCallback(&CustomTool::drawRect, &SimTool::PerformDrawRect, luaDrawRectWrapper, "DrawRect") || - handleCallback(&CustomTool::drawFill, &SimTool::PerformDrawFill, luaDrawFillWrapper, "DrawFill")) + handleCallback(&CustomTool::drawFill, &SimTool::PerformDrawFill, luaDrawFillWrapper, "DrawFill") || + handleCallback(&CustomTool::select , &SimTool::PerformSelect , luaSelectWrapper , "Select" )) { return 0; } diff --git a/src/simulation/SimTool.cpp b/src/simulation/SimTool.cpp index a6467d671..3137d2b0a 100644 --- a/src/simulation/SimTool.cpp +++ b/src/simulation/SimTool.cpp @@ -104,6 +104,7 @@ SimTool::SimTool() PerformDrawLine = defaultPerformDrawLine; PerformDrawRect = defaultPerformDrawRect; PerformDrawFill = nullptr; + PerformSelect = nullptr; } void SimTool::Click(Simulation * sim, const Brush &brush, ui::Point position) @@ -153,3 +154,11 @@ void SimTool::DrawFill(Simulation * sim, const Brush &brush, ui::Point position) PerformDrawFill(this, sim, brush, position); } } + +void SimTool::Select(int toolSelection) +{ + if (PerformSelect) + { + PerformSelect(this, toolSelection); + } +} diff --git a/src/simulation/SimTool.h b/src/simulation/SimTool.h index 664fb8d3e..7b69dfe23 100644 --- a/src/simulation/SimTool.h +++ b/src/simulation/SimTool.h @@ -15,6 +15,7 @@ public: void (*PerformDrawLine)(SimTool *tool, Simulation *sim, const Brush &brush, ui::Point position1, ui::Point position2, bool dragging); void (*PerformDrawRect)(SimTool *tool, Simulation *sim, const Brush &brush, ui::Point position1, ui::Point position2); void (*PerformDrawFill)(SimTool *tool, Simulation *sim, const Brush &brush, ui::Point position); + void (*PerformSelect )(SimTool *tool, int toolSelection); #define TOOL_NUMBERS_DECLARE @@ -30,4 +31,5 @@ public: void DrawLine(Simulation *sim, const Brush &brush, ui::Point position1, ui::Point position2, bool dragging) override; void DrawRect(Simulation *sim, const Brush &brush, ui::Point position1, ui::Point position2) override; void DrawFill(Simulation * sim, Brush const &brush, ui::Point position) override; + void Select(int toolSelection) override; };