control-click to duplicate terrain/monster/item type

This commit is contained in:
2025-08-25 10:23:37 -05:00
parent 3889c04b8a
commit 6c8078fa61
2 changed files with 32 additions and 8 deletions

View File

@@ -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;

View File

@@ -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),