From f56a2f60008adb1328f841aa67cc27beb0a3d271 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 18 Jul 2013 15:40:32 -0400 Subject: [PATCH] add back replace mode and specific delete. Activated with insert key / delete key, use ctrl+alt click to select what to use for the checks --- src/cat/LuaScriptInterface.cpp | 3 +++ src/cat/LuaScriptInterface.h | 2 +- src/gui/game/GameController.cpp | 12 ++++++++++++ src/gui/game/GameController.h | 2 ++ src/gui/game/GameModel.cpp | 12 +++++++++--- src/gui/game/GameModel.h | 4 ++-- src/gui/game/GameView.cpp | 22 +++++++++++++++++++++- src/gui/game/GameView.h | 1 + src/gui/game/ToolButton.cpp | 7 +++++-- src/gui/game/ToolButton.h | 3 ++- 10 files changed, 58 insertions(+), 10 deletions(-) diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 265745677..b1169f421 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -84,6 +84,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m): luacon_selectedl(""), luacon_selectedr(""), luacon_selectedalt(""), + luacon_selectedreplace(""), luacon_mousedown(false) { luacon_model = m; @@ -2821,6 +2822,8 @@ bool LuaScriptInterface::OnActiveToolChanged(int toolSelection, Tool * tool) luacon_selectedr = tool->GetIdentifier(); else if (toolSelection == 2) luacon_selectedalt = tool->GetIdentifier(); + else if (toolSelection == 3) + luacon_selectedreplace = tool->GetIdentifier(); return true; } diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h index 298385f54..eda6832a0 100644 --- a/src/cat/LuaScriptInterface.h +++ b/src/cat/LuaScriptInterface.h @@ -46,7 +46,7 @@ class TPTScriptInterface; class LuaScriptInterface: public CommandInterface { int luacon_mousex, luacon_mousey, luacon_mousebutton, luacon_brushx, luacon_brushy; - std::string luacon_selectedl, luacon_selectedr, luacon_selectedalt; + std::string luacon_selectedl, luacon_selectedr, luacon_selectedalt, luacon_selectedreplace; bool luacon_mousedown; bool currentCommand; TPTScriptInterface * legacy; diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 6b3e4f2bb..7312cbe7d 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1001,6 +1001,8 @@ void GameController::SetActiveTool(int toolSelection, Tool * tool) toolSelection = 0; gameModel->SetActiveTool(toolSelection, tool); gameModel->GetRenderer()->gravityZonesEnabled = false; + if (toolSelection == 3) + gameModel->GetSimulation()->replaceModeSelected = tool->GetToolID(); gameModel->SetLastTool(tool); for(int i = 0; i < 3; i++) { @@ -1011,6 +1013,16 @@ void GameController::SetActiveTool(int toolSelection, Tool * tool) } } +int GameController::GetReplaceModeFlags() +{ + return gameModel->GetSimulation()->replaceModeFlags; +} + +void GameController::SetReplaceModeFlags(int flags) +{ + gameModel->GetSimulation()->replaceModeFlags = flags; +} + void GameController::OpenSearch() { if(!search) diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index 2e1014c3e..844fbe777 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -102,6 +102,8 @@ public: std::vector GetMenuList(); Tool * GetActiveTool(int selection); void SetActiveTool(int toolSelection, Tool * tool); + int GetReplaceModeFlags(); + void SetReplaceModeFlags(int flags); void ActiveToolChanged(int toolSelection, Tool *tool); void SetActiveColourPreset(int preset); void SetColour(ui::Colour colour); diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index 22c5e3cfd..c58bab022 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -39,8 +39,8 @@ GameModel::GameModel(): activeTools = regularToolset; - std::fill(decoToolset, decoToolset+3, (Tool*)NULL); - std::fill(regularToolset, regularToolset+3, (Tool*)NULL); + std::fill(decoToolset, decoToolset+4, (Tool*)NULL); + std::fill(regularToolset, regularToolset+4, (Tool*)NULL); //Default render prefs std::vector tempArray; @@ -235,13 +235,15 @@ void GameModel::BuildMenus() if(activeMenu != -1) lastMenu = activeMenu; - std::string activeToolIdentifiers[3]; + std::string activeToolIdentifiers[4]; if(regularToolset[0]) activeToolIdentifiers[0] = regularToolset[0]->GetIdentifier(); if(regularToolset[1]) activeToolIdentifiers[1] = regularToolset[1]->GetIdentifier(); if(regularToolset[2]) activeToolIdentifiers[2] = regularToolset[2]->GetIdentifier(); + if(regularToolset[3]) + activeToolIdentifiers[3] = regularToolset[3]->GetIdentifier(); //Empty current menus for(std::vector::iterator iter = menuList.begin(), end = menuList.end(); iter != end; ++iter) @@ -338,11 +340,13 @@ void GameModel::BuildMenus() decoToolset[0] = GetToolFromIdentifier("DEFAULT_DECOR_SET"); decoToolset[1] = GetToolFromIdentifier("DEFAULT_DECOR_CLR"); decoToolset[2] = GetToolFromIdentifier("DEFAULT_UI_SAMPLE"); + decoToolset[3] = GetToolFromIdentifier("DEFAULT_PT_NONE"); //Set default tools regularToolset[0] = GetToolFromIdentifier("DEFAULT_PT_DUST"); regularToolset[1] = GetToolFromIdentifier("DEFAULT_PT_NONE"); regularToolset[2] = GetToolFromIdentifier("DEFAULT_UI_SAMPLE"); + regularToolset[3] = GetToolFromIdentifier("DEFAULT_PT_NONE"); if(activeToolIdentifiers[0].length()) @@ -351,6 +355,8 @@ void GameModel::BuildMenus() regularToolset[1] = GetToolFromIdentifier(activeToolIdentifiers[1]); if(activeToolIdentifiers[2].length()) regularToolset[2] = GetToolFromIdentifier(activeToolIdentifiers[2]); + if(activeToolIdentifiers[3].length()) + regularToolset[3] = GetToolFromIdentifier(activeToolIdentifiers[3]); lastTool = activeTools[0]; diff --git a/src/gui/game/GameModel.h b/src/gui/game/GameModel.h index 92df87f51..c47bdcebb 100644 --- a/src/gui/game/GameModel.h +++ b/src/gui/game/GameModel.h @@ -62,8 +62,8 @@ private: Renderer * ren; Tool * lastTool; Tool ** activeTools; - Tool * decoToolset[3]; - Tool * regularToolset[3]; + Tool * decoToolset[4]; + Tool * regularToolset[4]; User currentUser; float toolStrength; std::deque history; diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 5bbcb3a9c..3f47c9823 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -518,7 +518,9 @@ public: void ActionCallback(ui::Button * sender_) { ToolButton *sender = (ToolButton*)sender_; - if(sender->GetSelectionState() >= 0 && sender->GetSelectionState() <= 2) + if (v->CtrlBehaviour() && v->AltBehaviour() && !v->ShiftBehaviour()) + sender->SetSelectionState(3); + if(sender->GetSelectionState() >= 0 && sender->GetSelectionState() <= 3) v->c->SetActiveTool(sender->GetSelectionState(), tool); } }; @@ -631,6 +633,10 @@ void GameView::NotifyActiveToolsChanged(GameModel * sender) { toolButtons[i]->SetSelectionState(2); //Tertiary } + else if(sender->GetActiveTool(3) == tool) + { + toolButtons[i]->SetSelectionState(3); //Replace Mode + } else { toolButtons[i]->SetSelectionState(-1); @@ -640,6 +646,7 @@ void GameView::NotifyActiveToolsChanged(GameModel * sender) c->ActiveToolChanged(0, sender->GetActiveTool(0)); c->ActiveToolChanged(1, sender->GetActiveTool(1)); c->ActiveToolChanged(2, sender->GetActiveTool(2)); + c->ActiveToolChanged(3, sender->GetActiveTool(3)); } void GameView::NotifyLastToolChanged(GameModel * sender) @@ -713,6 +720,10 @@ void GameView::NotifyToolListChanged(GameModel * sender) { tempButton->SetSelectionState(2); //Tertiary } + else if(sender->GetActiveTool(3) == toolList[i]) + { + tempButton->SetSelectionState(3); //Replace mode + } tempButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; tempButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -1461,6 +1472,11 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool break; } + if (key == SDLK_INSERT) + c->SetReplaceModeFlags(c->GetReplaceModeFlags()^REPLACE_MODE); + else if (key == SDLK_DELETE) + c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE); + if (shift && showDebug && key == '1') c->LoadRenderPreset(10); else if(key >= '0' && key <= '9') @@ -2162,6 +2178,10 @@ void GameView::OnDraw() if (showDebug) fpsInfo << " Parts: " << sample.NumParts; + if (c->GetReplaceModeFlags()&REPLACE_MODE) + fpsInfo << " [REPLACE MODE]"; + if (c->GetReplaceModeFlags()&SPECIFIC_DELETE) + fpsInfo << " [SPECIFIC DELETE]"; if (ren->GetGridSize()) fpsInfo << " [GRID: " << ren->GetGridSize() << "]"; diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index f37c34bb0..ab3b714b6 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -138,6 +138,7 @@ public: bool GetDebugHUD(); bool CtrlBehaviour(){ return ctrlBehaviour; } bool ShiftBehaviour(){ return shiftBehaviour; } + bool AltBehaviour(){ return altBehaviour; } void ExitPrompt(); SelectMode GetSelectMode() { return selectMode; } void BeginStampSelection(); diff --git a/src/gui/game/ToolButton.cpp b/src/gui/game/ToolButton.cpp index 8539ac734..3b3170b75 100644 --- a/src/gui/game/ToolButton.cpp +++ b/src/gui/game/ToolButton.cpp @@ -33,7 +33,7 @@ void ToolButton::Draw(const ui::Point& screenPos) Graphics * g = ui::Engine::Ref().g; int totalColour = Appearance.BackgroundInactive.Blue + (3*Appearance.BackgroundInactive.Green) + (2*Appearance.BackgroundInactive.Red); - if(Appearance.GetTexture()) + if (Appearance.GetTexture()) { g->draw_image(Appearance.GetTexture(), screenPos.X+2, screenPos.Y+2, 255); } @@ -42,7 +42,7 @@ void ToolButton::Draw(const ui::Point& screenPos) g->fillrect(screenPos.X+2, screenPos.Y+2, Size.X-4, Size.Y-4, Appearance.BackgroundInactive.Red, Appearance.BackgroundInactive.Green, Appearance.BackgroundInactive.Blue, Appearance.BackgroundInactive.Alpha); } - if(isMouseInside && currentSelection == -1) + if (isMouseInside && currentSelection == -1) { g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderActive.Red, Appearance.BorderActive.Green, Appearance.BorderActive.Blue, Appearance.BorderActive.Alpha); } @@ -75,6 +75,9 @@ void ToolButton::SetSelectionState(int state) case 2: Appearance.BorderInactive = ui::Colour(0, 255, 0); break; + case 3: + Appearance.BorderInactive = ui::Colour(0, 255, 255); + break; default: Appearance.BorderInactive = ui::Colour(0, 0, 0); break; diff --git a/src/gui/game/ToolButton.h b/src/gui/game/ToolButton.h index 86c89701a..a14595d6b 100644 --- a/src/gui/game/ToolButton.h +++ b/src/gui/game/ToolButton.h @@ -3,7 +3,8 @@ #include "gui/interface/Button.h" -class ToolButton: public ui::Button { +class ToolButton: public ui::Button +{ int currentSelection; public: ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolTip = "");