refactor(canvas): unify context menu item handling with CanvasMenuItem
- Replaced the legacy ContextMenuItem structure with a new CanvasMenuItem across various files, enhancing consistency in context menu management. - Introduced CanvasMenuBuilder for fluent menu construction, allowing for easier addition of items and submenus. - Updated Canvas and related components to utilize the new menu system, improving organization and maintainability of context menus. Benefits: - Streamlines context menu item management, making it more intuitive and flexible. - Enhances code readability and reduces duplication, facilitating future enhancements.
This commit is contained in:
@@ -218,158 +218,158 @@ void DungeonCanvasViewer::DrawDungeonCanvas(int room_id) {
|
||||
auto& layer_settings = GetRoomLayerSettings(room_id);
|
||||
|
||||
// Add object placement option
|
||||
canvas_.AddContextMenuItem({
|
||||
ICON_MD_ADD " Place Object",
|
||||
[]() {
|
||||
// TODO: Show object palette/selector
|
||||
},
|
||||
"Ctrl+P"
|
||||
});
|
||||
canvas_.AddContextMenuItem(
|
||||
gui::CanvasMenuItem(ICON_MD_ADD " Place Object", ICON_MD_ADD,
|
||||
[]() {
|
||||
// TODO: Show object palette/selector
|
||||
},
|
||||
"Ctrl+P")
|
||||
);
|
||||
|
||||
// Add object deletion for selected objects
|
||||
canvas_.AddContextMenuItem({
|
||||
ICON_MD_DELETE " Delete Selected",
|
||||
[this]() {
|
||||
object_interaction_.HandleDeleteSelected();
|
||||
},
|
||||
"Del"
|
||||
});
|
||||
canvas_.AddContextMenuItem(
|
||||
gui::CanvasMenuItem(ICON_MD_DELETE " Delete Selected", ICON_MD_DELETE,
|
||||
[this]() {
|
||||
object_interaction_.HandleDeleteSelected();
|
||||
},
|
||||
"Del")
|
||||
);
|
||||
|
||||
// Add room property quick toggles
|
||||
canvas_.AddContextMenuItem({
|
||||
ICON_MD_LAYERS " Toggle BG1",
|
||||
[this, room_id]() {
|
||||
auto& settings = GetRoomLayerSettings(room_id);
|
||||
settings.bg1_visible = !settings.bg1_visible;
|
||||
},
|
||||
"1"
|
||||
});
|
||||
canvas_.AddContextMenuItem(
|
||||
gui::CanvasMenuItem(ICON_MD_LAYERS " Toggle BG1", ICON_MD_LAYERS,
|
||||
[this, room_id]() {
|
||||
auto& settings = GetRoomLayerSettings(room_id);
|
||||
settings.bg1_visible = !settings.bg1_visible;
|
||||
},
|
||||
"1")
|
||||
);
|
||||
|
||||
canvas_.AddContextMenuItem({
|
||||
ICON_MD_LAYERS " Toggle BG2",
|
||||
[this, room_id]() {
|
||||
auto& settings = GetRoomLayerSettings(room_id);
|
||||
settings.bg2_visible = !settings.bg2_visible;
|
||||
},
|
||||
"2"
|
||||
});
|
||||
canvas_.AddContextMenuItem(
|
||||
gui::CanvasMenuItem(ICON_MD_LAYERS " Toggle BG2", ICON_MD_LAYERS,
|
||||
[this, room_id]() {
|
||||
auto& settings = GetRoomLayerSettings(room_id);
|
||||
settings.bg2_visible = !settings.bg2_visible;
|
||||
},
|
||||
"2")
|
||||
);
|
||||
|
||||
// Add re-render option
|
||||
canvas_.AddContextMenuItem({
|
||||
ICON_MD_REFRESH " Re-render Room",
|
||||
[&room]() {
|
||||
room.RenderRoomGraphics();
|
||||
},
|
||||
"Ctrl+R"
|
||||
});
|
||||
canvas_.AddContextMenuItem(
|
||||
gui::CanvasMenuItem(ICON_MD_REFRESH " Re-render Room", ICON_MD_REFRESH,
|
||||
[&room]() {
|
||||
room.RenderRoomGraphics();
|
||||
},
|
||||
"Ctrl+R")
|
||||
);
|
||||
|
||||
// === DEBUG MENU ===
|
||||
gui::Canvas::ContextMenuItem debug_menu;
|
||||
gui::CanvasMenuItem debug_menu;
|
||||
debug_menu.label = ICON_MD_BUG_REPORT " Debug";
|
||||
|
||||
// Show room info
|
||||
debug_menu.subitems.push_back({
|
||||
ICON_MD_INFO " Show Room Info",
|
||||
[this, room_id]() {
|
||||
show_room_debug_info_ = !show_room_debug_info_;
|
||||
}
|
||||
});
|
||||
debug_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem(ICON_MD_INFO " Show Room Info", ICON_MD_INFO,
|
||||
[this]() {
|
||||
show_room_debug_info_ = !show_room_debug_info_;
|
||||
})
|
||||
);
|
||||
|
||||
// Show texture info
|
||||
debug_menu.subitems.push_back({
|
||||
ICON_MD_IMAGE " Show Texture Debug",
|
||||
[this]() {
|
||||
show_texture_debug_ = !show_texture_debug_;
|
||||
}
|
||||
});
|
||||
debug_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem(ICON_MD_IMAGE " Show Texture Debug", ICON_MD_IMAGE,
|
||||
[this]() {
|
||||
show_texture_debug_ = !show_texture_debug_;
|
||||
})
|
||||
);
|
||||
|
||||
// Show object bounds with sub-menu for categories
|
||||
gui::Canvas::ContextMenuItem object_bounds_menu;
|
||||
gui::CanvasMenuItem object_bounds_menu;
|
||||
object_bounds_menu.label = ICON_MD_CROP_SQUARE " Show Object Bounds";
|
||||
object_bounds_menu.callback = [this]() {
|
||||
show_object_bounds_ = !show_object_bounds_;
|
||||
};
|
||||
|
||||
// Sub-menu for filtering by type
|
||||
object_bounds_menu.subitems.push_back({
|
||||
"Type 1 (0x00-0xFF)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_type1_objects = !object_outline_toggles_.show_type1_objects;
|
||||
}
|
||||
});
|
||||
object_bounds_menu.subitems.push_back({
|
||||
"Type 2 (0x100-0x1FF)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_type2_objects = !object_outline_toggles_.show_type2_objects;
|
||||
}
|
||||
});
|
||||
object_bounds_menu.subitems.push_back({
|
||||
"Type 3 (0xF00-0xFFF)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_type3_objects = !object_outline_toggles_.show_type3_objects;
|
||||
}
|
||||
});
|
||||
object_bounds_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem("Type 1 (0x00-0xFF)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_type1_objects = !object_outline_toggles_.show_type1_objects;
|
||||
})
|
||||
);
|
||||
object_bounds_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem("Type 2 (0x100-0x1FF)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_type2_objects = !object_outline_toggles_.show_type2_objects;
|
||||
})
|
||||
);
|
||||
object_bounds_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem("Type 3 (0xF00-0xFFF)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_type3_objects = !object_outline_toggles_.show_type3_objects;
|
||||
})
|
||||
);
|
||||
|
||||
// Separator
|
||||
gui::Canvas::ContextMenuItem sep;
|
||||
gui::CanvasMenuItem sep;
|
||||
sep.label = "---";
|
||||
sep.enabled_condition = []() { return false; };
|
||||
object_bounds_menu.subitems.push_back(sep);
|
||||
|
||||
// Sub-menu for filtering by layer
|
||||
object_bounds_menu.subitems.push_back({
|
||||
"Layer 0 (BG1)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_layer0_objects = !object_outline_toggles_.show_layer0_objects;
|
||||
}
|
||||
});
|
||||
object_bounds_menu.subitems.push_back({
|
||||
"Layer 1 (BG2)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_layer1_objects = !object_outline_toggles_.show_layer1_objects;
|
||||
}
|
||||
});
|
||||
object_bounds_menu.subitems.push_back({
|
||||
"Layer 2 (BG3)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_layer2_objects = !object_outline_toggles_.show_layer2_objects;
|
||||
}
|
||||
});
|
||||
object_bounds_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem("Layer 0 (BG1)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_layer0_objects = !object_outline_toggles_.show_layer0_objects;
|
||||
})
|
||||
);
|
||||
object_bounds_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem("Layer 1 (BG2)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_layer1_objects = !object_outline_toggles_.show_layer1_objects;
|
||||
})
|
||||
);
|
||||
object_bounds_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem("Layer 2 (BG3)",
|
||||
[this]() {
|
||||
object_outline_toggles_.show_layer2_objects = !object_outline_toggles_.show_layer2_objects;
|
||||
})
|
||||
);
|
||||
|
||||
debug_menu.subitems.push_back(object_bounds_menu);
|
||||
|
||||
// Show layer info
|
||||
debug_menu.subitems.push_back({
|
||||
ICON_MD_LAYERS " Show Layer Info",
|
||||
[this]() {
|
||||
show_layer_info_ = !show_layer_info_;
|
||||
}
|
||||
});
|
||||
debug_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem(ICON_MD_LAYERS " Show Layer Info", ICON_MD_LAYERS,
|
||||
[this]() {
|
||||
show_layer_info_ = !show_layer_info_;
|
||||
})
|
||||
);
|
||||
|
||||
// Force reload room
|
||||
debug_menu.subitems.push_back({
|
||||
ICON_MD_REFRESH " Force Reload",
|
||||
[&room, room_id]() {
|
||||
room.LoadObjects();
|
||||
room.LoadRoomGraphics(room.blockset);
|
||||
room.RenderRoomGraphics();
|
||||
}
|
||||
});
|
||||
debug_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem(ICON_MD_REFRESH " Force Reload", ICON_MD_REFRESH,
|
||||
[&room]() {
|
||||
room.LoadObjects();
|
||||
room.LoadRoomGraphics(room.blockset);
|
||||
room.RenderRoomGraphics();
|
||||
})
|
||||
);
|
||||
|
||||
// Log room state
|
||||
debug_menu.subitems.push_back({
|
||||
ICON_MD_PRINT " Log Room State",
|
||||
[&room, room_id]() {
|
||||
LOG_DEBUG("DungeonDebug", "=== Room %03X Debug ===", room_id);
|
||||
LOG_DEBUG("DungeonDebug", "Blockset: %d, Palette: %d, Layout: %d",
|
||||
room.blockset, room.palette, room.layout);
|
||||
LOG_DEBUG("DungeonDebug", "Objects: %zu, Sprites: %zu",
|
||||
room.GetTileObjects().size(), room.GetSprites().size());
|
||||
LOG_DEBUG("DungeonDebug", "BG1: %dx%d, BG2: %dx%d",
|
||||
room.bg1_buffer().bitmap().width(), room.bg1_buffer().bitmap().height(),
|
||||
room.bg2_buffer().bitmap().width(), room.bg2_buffer().bitmap().height());
|
||||
}
|
||||
});
|
||||
debug_menu.subitems.push_back(
|
||||
gui::CanvasMenuItem(ICON_MD_PRINT " Log Room State", ICON_MD_PRINT,
|
||||
[&room, room_id]() {
|
||||
LOG_DEBUG("DungeonDebug", "=== Room %03X Debug ===", room_id);
|
||||
LOG_DEBUG("DungeonDebug", "Blockset: %d, Palette: %d, Layout: %d",
|
||||
room.blockset, room.palette, room.layout);
|
||||
LOG_DEBUG("DungeonDebug", "Objects: %zu, Sprites: %zu",
|
||||
room.GetTileObjects().size(), room.GetSprites().size());
|
||||
LOG_DEBUG("DungeonDebug", "BG1: %dx%d, BG2: %dx%d",
|
||||
room.bg1_buffer().bitmap().width(), room.bg1_buffer().bitmap().height(),
|
||||
room.bg2_buffer().bitmap().width(), room.bg2_buffer().bitmap().height());
|
||||
})
|
||||
);
|
||||
|
||||
canvas_.AddContextMenuItem(debug_menu);
|
||||
}
|
||||
|
||||
@@ -418,11 +418,11 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
|
||||
// Add entity insertion submenu (only in MOUSE mode)
|
||||
if (current_mode == 0 && entity_insert_callback_) { // 0 = EditingMode::MOUSE
|
||||
gui::Canvas::ContextMenuItem entity_menu;
|
||||
gui::CanvasMenuItem entity_menu;
|
||||
entity_menu.label = ICON_MD_ADD_LOCATION " Insert Entity";
|
||||
|
||||
// Entrance submenu item
|
||||
gui::Canvas::ContextMenuItem entrance_item;
|
||||
gui::CanvasMenuItem entrance_item;
|
||||
entrance_item.label = ICON_MD_DOOR_FRONT " Entrance";
|
||||
entrance_item.callback = [this]() {
|
||||
if (entity_insert_callback_) {
|
||||
@@ -432,7 +432,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
entity_menu.subitems.push_back(entrance_item);
|
||||
|
||||
// Hole submenu item
|
||||
gui::Canvas::ContextMenuItem hole_item;
|
||||
gui::CanvasMenuItem hole_item;
|
||||
hole_item.label = ICON_MD_CYCLONE " Hole";
|
||||
hole_item.callback = [this]() {
|
||||
if (entity_insert_callback_) {
|
||||
@@ -442,7 +442,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
entity_menu.subitems.push_back(hole_item);
|
||||
|
||||
// Exit submenu item
|
||||
gui::Canvas::ContextMenuItem exit_item;
|
||||
gui::CanvasMenuItem exit_item;
|
||||
exit_item.label = ICON_MD_DOOR_BACK " Exit";
|
||||
exit_item.callback = [this]() {
|
||||
if (entity_insert_callback_) {
|
||||
@@ -452,7 +452,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
entity_menu.subitems.push_back(exit_item);
|
||||
|
||||
// Item submenu item
|
||||
gui::Canvas::ContextMenuItem item_item;
|
||||
gui::CanvasMenuItem item_item;
|
||||
item_item.label = ICON_MD_GRASS " Item";
|
||||
item_item.callback = [this]() {
|
||||
if (entity_insert_callback_) {
|
||||
@@ -462,7 +462,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
entity_menu.subitems.push_back(item_item);
|
||||
|
||||
// Sprite submenu item
|
||||
gui::Canvas::ContextMenuItem sprite_item;
|
||||
gui::CanvasMenuItem sprite_item;
|
||||
sprite_item.label = ICON_MD_PEST_CONTROL_RODENT " Sprite";
|
||||
sprite_item.callback = [this]() {
|
||||
if (entity_insert_callback_) {
|
||||
@@ -475,7 +475,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
}
|
||||
|
||||
// Add overworld-specific context menu items
|
||||
gui::Canvas::ContextMenuItem lock_item;
|
||||
gui::CanvasMenuItem lock_item;
|
||||
lock_item.label = current_map_lock ? "Unlock Map" : "Lock to This Map";
|
||||
lock_item.callback = [¤t_map_lock]() {
|
||||
current_map_lock = !current_map_lock;
|
||||
@@ -483,7 +483,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
canvas.AddContextMenuItem(lock_item);
|
||||
|
||||
// Area Configuration
|
||||
gui::Canvas::ContextMenuItem properties_item;
|
||||
gui::CanvasMenuItem properties_item;
|
||||
properties_item.label = ICON_MD_TUNE " Area Configuration";
|
||||
properties_item.callback = [&show_map_properties_panel]() {
|
||||
show_map_properties_panel = true;
|
||||
@@ -495,7 +495,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||
if (asm_version >= 3 && asm_version != 0xFF) {
|
||||
// Custom Background Color
|
||||
gui::Canvas::ContextMenuItem bg_color_item;
|
||||
gui::CanvasMenuItem bg_color_item;
|
||||
bg_color_item.label = ICON_MD_FORMAT_COLOR_FILL " Custom Background Color";
|
||||
bg_color_item.callback = [&show_custom_bg_color_editor]() {
|
||||
show_custom_bg_color_editor = true;
|
||||
@@ -503,7 +503,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
canvas.AddContextMenuItem(bg_color_item);
|
||||
|
||||
// Visual Effects Editor
|
||||
gui::Canvas::ContextMenuItem overlay_item;
|
||||
gui::CanvasMenuItem overlay_item;
|
||||
overlay_item.label = ICON_MD_LAYERS " Visual Effects";
|
||||
overlay_item.callback = [&show_overlay_editor]() {
|
||||
show_overlay_editor = true;
|
||||
@@ -512,7 +512,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
}
|
||||
|
||||
// Canvas controls
|
||||
gui::Canvas::ContextMenuItem reset_view_item;
|
||||
gui::CanvasMenuItem reset_view_item;
|
||||
reset_view_item.label = ICON_MD_RESTORE " Reset View";
|
||||
reset_view_item.callback = [&canvas]() {
|
||||
canvas.set_global_scale(1.0f);
|
||||
@@ -520,7 +520,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
};
|
||||
canvas.AddContextMenuItem(reset_view_item);
|
||||
|
||||
gui::Canvas::ContextMenuItem zoom_in_item;
|
||||
gui::CanvasMenuItem zoom_in_item;
|
||||
zoom_in_item.label = ICON_MD_ZOOM_IN " Zoom In";
|
||||
zoom_in_item.callback = [&canvas]() {
|
||||
float scale = std::min(2.0f, canvas.global_scale() + 0.25f);
|
||||
@@ -528,7 +528,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
||||
};
|
||||
canvas.AddContextMenuItem(zoom_in_item);
|
||||
|
||||
gui::Canvas::ContextMenuItem zoom_out_item;
|
||||
gui::CanvasMenuItem zoom_out_item;
|
||||
zoom_out_item.label = ICON_MD_ZOOM_OUT " Zoom Out";
|
||||
zoom_out_item.callback = [&canvas]() {
|
||||
float scale = std::max(0.25f, canvas.global_scale() - 0.25f);
|
||||
|
||||
Reference in New Issue
Block a user