From dcf79fecb62add46eeb5262f8936bf423861480c Mon Sep 17 00:00:00 2001 From: Teh-Mad-Cow <5084133+Teh-Mad-Cow@users.noreply.github.com> Date: Thu, 3 Mar 2022 01:22:10 -0600 Subject: [PATCH 1/3] Stack tool can erase stacks using right mouse. Signed-off-by: Teh-Mad-Cow <5084133+Teh-Mad-Cow@users.noreply.github.com> --- src/gui/game/GameModel.cpp | 11 +++- src/gui/game/GameModel.h | 1 + src/gui/game/StackTool.cpp | 111 +++++++++++++++++++++++++++++++++++++ src/gui/game/Tool.h | 25 ++++++++- 4 files changed, 146 insertions(+), 2 deletions(-) diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index 3f7b375128..7985210151 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -415,6 +415,13 @@ void GameModel::BuildMenus() configToolset[2] = GetToolFromIdentifier("DEFAULT_UI_SAMPLE"); configToolset[3] = GetToolFromIdentifier("DEFAULT_PT_NONE"); + StackTool *stackTool = (StackTool*)GetToolFromIdentifier("DEFAULT_UI_STACK"); + stackTool->SetClearTool(GetToolFromIdentifier("DEFAULT_PT_NONE")); + stackToolToolset[0] = stackTool; + stackToolToolset[1] = &stackTool->deleteStackTool; + stackToolToolset[2] = GetToolFromIdentifier("DEFAULT_UI_SAMPLE"); + stackToolToolset[3] = GetToolFromIdentifier("DEFAULT_PT_NONE"); + regularToolset[0] = GetToolFromIdentifier(activeToolIdentifiers[0]); regularToolset[1] = GetToolFromIdentifier(activeToolIdentifiers[1]); regularToolset[2] = GetToolFromIdentifier(activeToolIdentifiers[2]); @@ -943,7 +950,9 @@ void GameModel::SetActiveTool(int selection, Tool * tool) sim->configToolSampleActive = false; if (tool->GetIdentifier() == "DEFAULT_UI_CONFIG") activeTools = configToolset; - else if (activeTools == configToolset) + else if (tool->GetIdentifier() == "DEFAULT_UI_STACK") + activeTools = stackToolToolset; + else activeTools = regularToolset; activeTools[selection] = tool; notifyActiveToolsChanged(); diff --git a/src/gui/game/GameModel.h b/src/gui/game/GameModel.h index f3f57a43c7..2a7af98f6b 100644 --- a/src/gui/game/GameModel.h +++ b/src/gui/game/GameModel.h @@ -73,6 +73,7 @@ class GameModel Tool * decoToolset[4]; Tool * regularToolset[4]; Tool * configToolset[4]; + Tool * stackToolToolset[4]; User currentUser; float toolStrength; std::deque history; diff --git a/src/gui/game/StackTool.cpp b/src/gui/game/StackTool.cpp index 522942d8d5..01e64a96e4 100644 --- a/src/gui/game/StackTool.cpp +++ b/src/gui/game/StackTool.cpp @@ -235,3 +235,114 @@ void StackTool::DrawRect(Simulation *sim, Brush *cBrush, ui::Point position, ui: } ProcessParts(sim, parts, position, position2); } + +void StackTool::DeleteStackTool::Draw(Simulation *sim, Brush *cBrush, ui::Point position) +{ + if (cBrush) + { + int radiusX = cBrush->GetRadius().X, radiusY = cBrush->GetRadius().Y, sizeX = cBrush->GetSize().X, sizeY = cBrush->GetSize().Y; + unsigned char *bitmap = cBrush->GetBitmap(); + for (int i=0; i<=sim->parts_lastActiveIndex; i++) + { + if (sim->parts[i].type) + { + int partx = (int)(sim->parts[i].x+0.5f); + int party = (int)(sim->parts[i].y+0.5f); + int partbmpx = partx - position.X + radiusX; + int partbmpy = party - position.Y + radiusY; + if (partbmpx >= 0 && partbmpx < sizeX && partbmpy >= 0 && partbmpy < sizeY && bitmap[partbmpy * sizeX + partbmpx]) + sim->kill_part(i); + } + } + } +} + +void StackTool::DeleteStackTool::DrawLine(Simulation *sim, Brush *cBrush, ui::Point position, ui::Point position2, bool dragging) +{ + int x1 = position.X, y1 = position.Y, x2 = position2.X, y2 = position2.Y; + bool reverseXY = abs(y2-y1) > abs(x2-x1); + int x, y, dx, dy, sy, rx = cBrush->GetRadius().X, ry = cBrush->GetRadius().Y; + float e = 0.0f, de; + if (reverseXY) + { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if (x1 > x2) + { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + if (dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) + { + y += sy; + if (!(rx+ry) && ((y1=y2))) + { + if (reverseXY) + Draw(sim, cBrush, ui::Point(y, x)); + else + Draw(sim, cBrush, ui::Point(x, y)); + } + e -= 1.0f; + } + } +} + +void StackTool::DeleteStackTool::DrawRect(Simulation *sim, Brush *cBrush, ui::Point position, ui::Point position2) +{ + int x1 = position.X, y1 = position.Y, x2 = position2.X, y2 = position2.Y; + int i, j; + if (x1>x2) + { + i = x2; + x2 = x1; + x1 = i; + } + if (y1>y2) + { + j = y2; + y2 = y1; + y1 = j; + } + for (int i=0; i<=sim->parts_lastActiveIndex; i++) + { + if (sim->parts[i].type) + { + int partx = (int)(sim->parts[i].x+0.5f); + int party = (int)(sim->parts[i].y+0.5f); + if (partx >= x1 && partx <= x2 && party >= y1 && party <= y2) + sim->kill_part(i); + } + } +} + +void StackTool::DeleteStackTool::DrawFill(Simulation * sim, Brush * cbrush, ui::Point position) +{ + // create a heatmap of particles. Index is: Y*XRES + X + clearTool->DrawFill(sim, cbrush, position); + // re-implement flood fill and kill stacks that it encounters. + +} \ No newline at end of file diff --git a/src/gui/game/Tool.h b/src/gui/game/Tool.h index 699b2c6aec..1da0fac2bc 100644 --- a/src/gui/game/Tool.h +++ b/src/gui/game/Tool.h @@ -84,13 +84,36 @@ class SampleTool: public Tool class StackTool: public Tool { + class DeleteStackTool : public Tool + { + StackTool * stackTool; + Tool * clearTool; + public: + DeleteStackTool(StackTool *stackTool_): + Tool(0, "", "", 0, 0, 0, "DEFAULT_UI_STACK_DELETE", NULL), + stackTool(stackTool_), + clearTool(NULL) + { + } + virtual ~DeleteStackTool() {} + void SetClearTool(Tool *clearTool_) { clearTool = clearTool_; } + virtual void Click(Simulation * sim, Brush * brush, ui::Point position){ } + virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false); + virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position); + }; + GameModel * gameModel; public: + DeleteStackTool deleteStackTool; StackTool(GameModel *model): Tool(0, "STCK", "Stack or unstack particles.", 0xff, 0xff, 0, "DEFAULT_UI_STACK", NULL), - gameModel(model) + gameModel(model), + deleteStackTool(DeleteStackTool(this)) { } + void SetClearTool(Tool *clearTool) { deleteStackTool.SetClearTool(clearTool); } virtual ~StackTool() {} void ProcessParts(Simulation * sim, std::vector &parts, ui::Point position, ui::Point position2); virtual void Click(Simulation * sim, Brush * brush, ui::Point position) { } From 68448ac8f6a75b858cfdd8fc84dd53bfbf2ea99b Mon Sep 17 00:00:00 2001 From: Teh-Mad-Cow <5084133+Teh-Mad-Cow@users.noreply.github.com> Date: Thu, 3 Mar 2022 01:22:10 -0600 Subject: [PATCH 2/3] Fixed accidental bug with decotoolset. Signed-off-by: Teh-Mad-Cow <5084133+Teh-Mad-Cow@users.noreply.github.com> --- src/gui/game/GameModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index 7985210151..2a32848bc4 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -952,7 +952,7 @@ void GameModel::SetActiveTool(int selection, Tool * tool) activeTools = configToolset; else if (tool->GetIdentifier() == "DEFAULT_UI_STACK") activeTools = stackToolToolset; - else + else if (activeTools != decoToolset) activeTools = regularToolset; activeTools[selection] = tool; notifyActiveToolsChanged(); From 72cafb7745c86b48a3f0a01f8fded561d99d1fed Mon Sep 17 00:00:00 2001 From: Teh-Mad-Cow <5084133+Teh-Mad-Cow@users.noreply.github.com> Date: Thu, 3 Mar 2022 01:22:10 -0600 Subject: [PATCH 3/3] Stack tool is now toggleable. Signed-off-by: Teh-Mad-Cow <5084133+Teh-Mad-Cow@users.noreply.github.com> --- src/gui/game/GameController.cpp | 10 +++++++++- src/gui/game/GameController.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 867e6f556d..d9bada2352 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -708,7 +708,7 @@ bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool c case SDL_SCANCODE_S: if (shift) { - SetActiveTool(0, "DEFAULT_UI_STACK"); + ToggleStackTool(); break; } gameView->BeginStampSelection(); @@ -1231,6 +1231,14 @@ void GameController::ToggleConfigTool() SetActiveTool(0, "DEFAULT_UI_CONFIG"); } +void GameController::ToggleStackTool() +{ + if (GetActiveTool(0)->GetIdentifier() == "DEFAULT_UI_STACK") + SetActiveMenu(gameModel->GetActiveMenu()); + else + SetActiveTool(0, "DEFAULT_UI_STACK"); +} + int GameController::GetStackEditDepth() { return gameModel->GetSimulation()->stackEditDepth; diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index eb82021b89..8ce0c6ef71 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -134,6 +134,7 @@ class GameController: public ClientListener int GetParticleDebugPosition(); ConfigTool * GetActiveConfigTool(); void ToggleConfigTool(); + void ToggleStackTool(); int GetStackEditDepth(); void SetStackEditDepth(int depth); void AdjustStackEditDepth(int ddepth);