Implement object selection rectangle functionality in DungeonEditor

- Added methods for object selection rectangle handling, including CheckForObjectSelection, DrawObjectSelectRect, and SelectObjectsInRect.
- Enhanced DungeonEditor to support right-click drag selection for multiple objects, improving user interaction and object management.
- Updated the UI in DungeonObjectSelector to optimize object previews and improve layout for better visibility.
- Refactored various sections of DungeonEditor for code clarity and consistency, including adjustments to object rendering and selection processes.
This commit is contained in:
scawful
2025-09-25 19:30:12 -04:00
parent fd538b8f31
commit 8389989ab3
3 changed files with 384 additions and 206 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -130,6 +130,11 @@ class DungeonEditor : public Editor {
bool IsObjectInSelectBox(const zelda3::RoomObject& object) const;
void PlaceObjectAtPosition(int room_x, int room_y);
// Object selection rectangle (like OverworldEditor)
void CheckForObjectSelection();
void DrawObjectSelectRect();
void SelectObjectsInRect();
// Room graphics management
absl::Status LoadAndRenderRoomGraphics(int room_id);
absl::Status ReloadAllRoomGraphics();
@@ -196,6 +201,12 @@ class DungeonEditor : public Editor {
std::vector<int> selected_objects_;
int current_layer_ = 0; // 0 = BG1, 1 = BG2, 2 = Both
// Object selection rectangle (like OverworldEditor)
bool object_select_active_ = false;
ImVec2 object_select_start_;
ImVec2 object_select_end_;
std::vector<size_t> selected_object_indices_;
// New editor system integration
std::unique_ptr<zelda3::DungeonEditorSystem> dungeon_editor_system_;
std::shared_ptr<zelda3::DungeonObjectEditor> object_editor_;

View File

@@ -119,9 +119,9 @@ void DungeonObjectSelector::DrawObjectBrowser() {
ImGui::Separator();
// Object list with previews
const int preview_size = 32; // 32x32 pixel preview
const int items_per_row = 4; // 4 items per row
// Object list with previews - optimized for 300px column width
const int preview_size = 48; // Larger 48x48 pixel preview for better visibility
const int items_per_row = 5; // 5 items per row to fit in 300px column
if (rom_ && rom_->is_loaded()) {
auto palette = rom_->palette_group().dungeon_main[current_palette_group_id_];
@@ -145,9 +145,11 @@ void DungeonObjectSelector::DrawObjectBrowser() {
test_object.set_rom(rom_);
test_object.EnsureTilesLoaded();
// Calculate position in grid
float item_width = (ImGui::GetContentRegionAvail().x - (items_per_row - 1) * ImGui::GetStyle().ItemSpacing.x) / items_per_row;
float item_height = preview_size + 40; // Preview + text
// Calculate position in grid - better sizing for 300px column
float available_width = ImGui::GetContentRegionAvail().x;
float spacing = ImGui::GetStyle().ItemSpacing.x;
float item_width = (available_width - (items_per_row - 1) * spacing) / items_per_row;
float item_height = preview_size + 30; // Preview + text (reduced padding)
ImGui::PushID(obj_id);
@@ -196,9 +198,11 @@ void DungeonObjectSelector::DrawObjectBrowser() {
"?");
}
// Draw object ID and name
ImGui::SetCursorScreenPos(ImVec2(cursor_pos.x + 2, cursor_pos.y - 25));
ImGui::Text("0x%03X", obj_id);
// Draw object ID and name with better positioning
ImGui::SetCursorScreenPos(ImVec2(cursor_pos.x + 2, cursor_pos.y - 22));
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 255, 255, 255));
ImGui::Text("0x%02X", obj_id);
ImGui::PopStyleColor();
// Try to get object name
std::string object_name = "Unknown";
@@ -227,8 +231,15 @@ void DungeonObjectSelector::DrawObjectBrowser() {
}
}
ImGui::SetCursorScreenPos(ImVec2(cursor_pos.x + 2, cursor_pos.y - 10));
// Draw object name with better sizing
ImGui::SetCursorScreenPos(ImVec2(cursor_pos.x + 2, cursor_pos.y - 8));
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(200, 200, 200, 255));
// Truncate long names to fit
if (object_name.length() > 8) {
object_name = object_name.substr(0, 8) + "...";
}
ImGui::Text("%s", object_name.c_str());
ImGui::PopStyleColor();
ImGui::PopID();
@@ -298,9 +309,9 @@ void DungeonObjectSelector::DrawRoomGraphics() {
}
int current_block = 0;
const int max_blocks_per_row = 4; // Limit blocks per row to fit canvas
const int block_width = 0x100; // 256 pixels per block
const int block_height = 0x40; // 64 pixels per block
const int max_blocks_per_row = 2; // 2 blocks per row for 300px column
const int block_width = 128; // Reduced size to fit column
const int block_height = 32; // Reduced height
for (int block : blocks) {
if (current_block >= 16) break; // Only show first 16 blocks