From 6c8078fa6177e378d0b2a98952f3ecc30e98f8fe Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 25 Aug 2025 10:23:37 -0500 Subject: [PATCH] control-click to duplicate terrain/monster/item type --- src/scenedit/scen.actions.cpp | 28 ++++++++++++++++++++++++++-- src/scenedit/scen.undo.hpp | 12 ++++++------ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/scenedit/scen.actions.cpp b/src/scenedit/scen.actions.cpp index 532d1ed4b..c8c390ccb 100644 --- a/src/scenedit/scen.actions.cpp +++ b/src/scenedit/scen.actions.cpp @@ -1461,7 +1461,7 @@ static bool handle_terrain_action(location the_point, bool ctrl_hit) { return false; } -static bool handle_terpal_action(location cur_point, bool option_hit) { +static bool handle_terpal_action(location cur_point, bool option_hit, bool ctrl_hit) { int rows = TYPE_ROWS_DRAWING; if(overall_mode == MODE_EDIT_TYPES) rows = TYPE_ROWS_EDITING; for(int i = 0; i < 16 * rows; i++) @@ -1605,6 +1605,30 @@ static bool handle_terpal_action(location cur_point, bool option_hit) { break; } } + } else if(ctrl_hit){ + // Control-click a type: Duplicate it + if(i != size_before){ + switch(draw_mode){ + case DRAW_TERRAIN:{ + cTerrain orig = scenario.ter_types[i]; + scenario.ter_types.push_back(orig); + undo_list.add(action_ptr(new aCreateDeleteTerrain(true, orig, true))); + update_edit_menu(); + }break; + case DRAW_MONST:{ + cMonster orig = scenario.scen_monsters[i]; + scenario.scen_monsters.push_back(orig); + undo_list.add(action_ptr(new aCreateDeleteMonster(true, orig, true))); + update_edit_menu(); + }break; + case DRAW_ITEM:{ + cItem orig = scenario.scen_items[i]; + scenario.scen_items.push_back(orig); + undo_list.add(action_ptr(new aCreateDeleteItem(true, orig, true))); + update_edit_menu(); + }break; + } + } } else { bool is_new = false; // Click the plus button: create a new type and edit it immediately @@ -2015,7 +2039,7 @@ void handle_action(location the_point,sf::Event /*event*/) { cur_point = the_point; cur_point.x -= RIGHT_AREA_UL_X; cur_point.y -= RIGHT_AREA_UL_Y; - if(handle_terpal_action(cur_point, option_hit)) + if(handle_terpal_action(cur_point, option_hit, ctrl_hit)) return; cur_point2 = the_point; diff --git a/src/scenedit/scen.undo.hpp b/src/scenedit/scen.undo.hpp index 0f21d2842..a05ba7631 100644 --- a/src/scenedit/scen.undo.hpp +++ b/src/scenedit/scen.undo.hpp @@ -226,8 +226,8 @@ class aCreateDeleteTerrain : public cAction { bool undo_me() override; bool redo_me() override; public: - aCreateDeleteTerrain(bool create, cTerrain terrain) : - cAction(create ? "Create Terrain Type" : "Delete Terrain Type", !create), + aCreateDeleteTerrain(bool create, cTerrain terrain, bool duplicate = false) : + cAction(create ? ((duplicate ? "Duplicate":"Create") + std::string{" Terrain Type"}) : "Delete Terrain Type", !create), terrains({terrain}) {} aCreateDeleteTerrain(terrain_type_changes_t terrains) : cAction("Create Terrain Types", false), @@ -240,8 +240,8 @@ class aCreateDeleteMonster : public cAction { bool undo_me() override; bool redo_me() override; public: - aCreateDeleteMonster(bool create, cMonster monst) : - cAction(create ? "Create Monster Type" : "Delete Monster Type", !create), + aCreateDeleteMonster(bool create, cMonster monst, bool duplicate = false) : + cAction(create ? ((duplicate ? "Duplicate":"Create") + std::string{" Monster Type"}) : "Delete Monster Type", !create), monsters({monst}) {} aCreateDeleteMonster(monst_type_changes_t monsts) : cAction("Create Monster Types", false), @@ -254,8 +254,8 @@ class aCreateDeleteItem : public cAction { bool undo_me() override; bool redo_me() override; public: - aCreateDeleteItem(bool create, class cItem item) : - cAction(create ? "Create Item Type" : "Delete Item Type", !create), + aCreateDeleteItem(bool create, class cItem item, bool duplicate = false) : + cAction(create ? ((duplicate ? "Duplicate":"Create") + std::string{" Item Type"}) : "Delete Item Type", !create), items({item}) {} aCreateDeleteItem(item_type_changes_t items) : cAction("Create Item Types", false),