From bdb74a27c0f864c6d317a64fe66d36a5c0ad1fc8 Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 11 May 2024 14:47:04 -0400 Subject: [PATCH] refactor palette editor --- src/app/editor/modules/palette_editor.cc | 90 +++++++++++++++++++++--- src/app/editor/modules/palette_editor.h | 1 + 2 files changed, 81 insertions(+), 10 deletions(-) diff --git a/src/app/editor/modules/palette_editor.cc b/src/app/editor/modules/palette_editor.cc index c478c65c..4b2cad7f 100644 --- a/src/app/editor/modules/palette_editor.cc +++ b/src/app/editor/modules/palette_editor.cc @@ -35,12 +35,7 @@ absl::Status PaletteEditor::Update() { ImGui::TableHeadersRow(); ImGui::TableNextRow(); ImGui::TableNextColumn(); - for (int category = 0; category < kNumPalettes; ++category) { - if (ImGui::TreeNode(kPaletteCategoryNames[category].data())) { - status_ = DrawPaletteGroup(category); - ImGui::TreePop(); - } - } + DisplayCategoryTable(); ImGui::TableNextColumn(); if (gui::SnesColorEdit4("Color Picker", current_color_, ImGuiColorEditFlags_NoAlpha)) { @@ -53,6 +48,81 @@ absl::Status PaletteEditor::Update() { return absl::OkStatus(); } +void PaletteEditor::DisplayCategoryTable() { + // Check if the table is created successfully with 3 columns + if (ImGui::BeginTable("Category Table", 3)) { // 3 columns + + // Headers (optional, remove if you don't want headers) + ImGui::TableSetupColumn("Weapons and Gear"); + ImGui::TableSetupColumn("World and Enemies"); + ImGui::TableSetupColumn("Maps and Items"); + ImGui::TableHeadersRow(); + + // Start the first row + ImGui::TableNextRow(); + + // Column 1 - Weapons and Gear + ImGui::TableSetColumnIndex(0); + + if (ImGui::TreeNode("Sword")) { + status_ = DrawPaletteGroup(0); + ImGui::TreePop(); + } + if (ImGui::TreeNode("Shield")) { + status_ = DrawPaletteGroup(1); + ImGui::TreePop(); + } + if (ImGui::TreeNode("Clothes")) { + status_ = DrawPaletteGroup(2); + ImGui::TreePop(); + } + + // Column 2 - World and Enemies + ImGui::TableSetColumnIndex(1); + if (ImGui::TreeNode("World Colors")) { + status_ = DrawPaletteGroup(3); + ImGui::TreePop(); + } + if (ImGui::TreeNode("Area Colors")) { + status_ = DrawPaletteGroup(4); + ImGui::TreePop(); + } + if (ImGui::TreeNode("Enemies")) { + status_ = DrawPaletteGroup(5); + ImGui::TreePop(); + } + + // Column 3 - Maps and Items + ImGui::TableSetColumnIndex(2); + if (ImGui::TreeNode("Dungeons")) { + status_ = DrawPaletteGroup(6); + ImGui::TreePop(); + } + if (ImGui::TreeNode("World Map")) { + status_ = DrawPaletteGroup(7); + ImGui::TreePop(); + } + if (ImGui::TreeNode("Dungeon Map")) { + status_ = DrawPaletteGroup(8); + ImGui::TreePop(); + } + + // Additional items in the last column, if any + { + if (ImGui::TreeNode("Triforce")) { + status_ = DrawPaletteGroup(9); + ImGui::TreePop(); + } + if (ImGui::TreeNode("Crystal")) { + status_ = DrawPaletteGroup(10); + ImGui::TreePop(); + } + } + // End the table + ImGui::EndTable(); + } +} + absl::Status PaletteEditor::EditColorInPalette(gfx::SnesPalette& palette, int index) { if (index >= palette.size()) { @@ -92,10 +162,10 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category) { static bool edit_color = false; for (int j = 0; j < size; j++) { - // ImGui::Text("%d", j); - rom()->resource_label()->SelectableLabelWithNameEdit( - false, "Palette Group Name", std::to_string(j), - std::string(kPaletteGroupNames[category])); + ImGui::Text("%d", j); + // rom()->resource_label()->SelectableLabelWithNameEdit( + // false, "Palette Group Name", std::to_string(j), + // std::string(kPaletteGroupNames[category])); auto palette = palette_group.mutable_palette(j); auto pal_size = palette->size(); diff --git a/src/app/editor/modules/palette_editor.h b/src/app/editor/modules/palette_editor.h index cbc5aec3..04de62d6 100644 --- a/src/app/editor/modules/palette_editor.h +++ b/src/app/editor/modules/palette_editor.h @@ -84,6 +84,7 @@ class PaletteEditorHistory { class PaletteEditor : public SharedRom { public: absl::Status Update(); + void DisplayCategoryTable(); absl::Status DrawPaletteGroups(); absl::Status EditColorInPalette(gfx::SnesPalette& palette, int index);