From a48a85ae7200391498f49f84a6b2c9679ca50cd4 Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 14 Jul 2024 14:30:46 -0400 Subject: [PATCH] update palette editor and palette set viewer --- src/app/editor/context/gfx_context.h | 1 - src/app/editor/modules/gfx_group_editor.cc | 33 ++++++++++++++--- src/app/editor/modules/gfx_group_editor.h | 3 -- src/app/editor/modules/palette_editor.cc | 16 +++++---- src/app/editor/modules/palette_editor.h | 41 ++++------------------ 5 files changed, 45 insertions(+), 49 deletions(-) diff --git a/src/app/editor/context/gfx_context.h b/src/app/editor/context/gfx_context.h index f644b233..b8372ccf 100644 --- a/src/app/editor/context/gfx_context.h +++ b/src/app/editor/context/gfx_context.h @@ -7,7 +7,6 @@ #include #include "app/editor/utils/editor.h" -#include "app/editor/modules/palette_editor.h" #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" #include "app/gfx/snes_tile.h" diff --git a/src/app/editor/modules/gfx_group_editor.cc b/src/app/editor/modules/gfx_group_editor.cc index a034282b..e849157b 100644 --- a/src/app/editor/modules/gfx_group_editor.cc +++ b/src/app/editor/modules/gfx_group_editor.cc @@ -30,6 +30,9 @@ using ImGui::TableNextColumn; using ImGui::TableNextRow; using ImGui::TableSetupColumn; +using gfx::kPaletteGroupNames; +using gfx::PaletteCategory; + absl::Status GfxGroupEditor::Update() { if (ImGui::BeginTabBar("GfxGroupEditor")) { if (ImGui::BeginTabItem("Main")) { @@ -235,11 +238,14 @@ void DrawPaletteFromPaletteGroup(gfx::SnesPalette &palette) { } // namespace void GfxGroupEditor::DrawPaletteViewer() { - auto dungeon_main_palette_val = + static uint8_t &dungeon_main_palette_val = rom()->paletteset_ids[selected_paletteset_][0]; - auto dungeon_spr_pal_1_val = rom()->paletteset_ids[selected_paletteset_][1]; - auto dungeon_spr_pal_2_val = rom()->paletteset_ids[selected_paletteset_][2]; - auto dungeon_spr_pal_3_val = rom()->paletteset_ids[selected_paletteset_][3]; + static uint8_t &dungeon_spr_pal_1_val = + rom()->paletteset_ids[selected_paletteset_][1]; + static uint8_t &dungeon_spr_pal_2_val = + rom()->paletteset_ids[selected_paletteset_][2]; + static uint8_t &dungeon_spr_pal_3_val = + rom()->paletteset_ids[selected_paletteset_][3]; gui::InputHexByte("Dungeon Main", &dungeon_main_palette_val); gui::InputHexByte("Dungeon Spr Pal 1", &dungeon_spr_pal_1_val); @@ -249,18 +255,37 @@ void GfxGroupEditor::DrawPaletteViewer() { auto &palette = *rom()->mutable_palette_group()->dungeon_main.mutable_palette( rom()->paletteset_ids[selected_paletteset_][0]); DrawPaletteFromPaletteGroup(palette); + SameLine(); + rom()->resource_label()->SelectableLabelWithNameEdit( + false, kPaletteGroupNames[PaletteCategory::kDungeons].data(), + std::to_string(dungeon_main_palette_val), "Unnamed dungeon palette"); + auto &spr_aux_pal1 = *rom()->mutable_palette_group()->sprites_aux1.mutable_palette( rom()->paletteset_ids[selected_paletteset_][1]); DrawPaletteFromPaletteGroup(spr_aux_pal1); + SameLine(); + rom()->resource_label()->SelectableLabelWithNameEdit( + false, kPaletteGroupNames[PaletteCategory::kSpritesAux1].data(), + std::to_string(dungeon_spr_pal_1_val), "Dungeon Spr Pal 1"); + auto &spr_aux_pal2 = *rom()->mutable_palette_group()->sprites_aux2.mutable_palette( rom()->paletteset_ids[selected_paletteset_][2]); DrawPaletteFromPaletteGroup(spr_aux_pal2); + SameLine(); + rom()->resource_label()->SelectableLabelWithNameEdit( + false, kPaletteGroupNames[PaletteCategory::kSpritesAux2].data(), + std::to_string(dungeon_spr_pal_2_val), "Dungeon Spr Pal 2"); + auto &spr_aux_pal3 = *rom()->mutable_palette_group()->sprites_aux3.mutable_palette( rom()->paletteset_ids[selected_paletteset_][3]); DrawPaletteFromPaletteGroup(spr_aux_pal3); + SameLine(); + rom()->resource_label()->SelectableLabelWithNameEdit( + false, kPaletteGroupNames[PaletteCategory::kSpritesAux3].data(), + std::to_string(dungeon_spr_pal_3_val), "Dungeon Spr Pal 3"); } } // namespace editor diff --git a/src/app/editor/modules/gfx_group_editor.h b/src/app/editor/modules/gfx_group_editor.h index 971eb94d..c6aef4c8 100644 --- a/src/app/editor/modules/gfx_group_editor.h +++ b/src/app/editor/modules/gfx_group_editor.h @@ -7,7 +7,6 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "app/editor/modules/palette_editor.h" #include "app/editor/utils/editor.h" #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" @@ -54,8 +53,6 @@ class GfxGroupEditor : public SharedRom { uint8_t selected_spriteset_ = 0; uint8_t selected_paletteset_ = 0; - PaletteEditor palette_editor_; - gui::Canvas blockset_canvas_; gui::Canvas roomset_canvas_; gui::Canvas spriteset_canvas_; diff --git a/src/app/editor/modules/palette_editor.cc b/src/app/editor/modules/palette_editor.cc index 47c094a8..8a4c0a89 100644 --- a/src/app/editor/modules/palette_editor.cc +++ b/src/app/editor/modules/palette_editor.cc @@ -45,6 +45,8 @@ using ImGui::Text; using ImGui::TreeNode; using ImGui::TreePop; +using namespace gfx; + constexpr ImGuiTableFlags kPaletteTableFlags = ImGuiTableFlags_Reorderable | ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingStretchSame; @@ -87,7 +89,8 @@ absl::Status PaletteEditor::Update() { if (BeginTable("paletteEditorTable", 2, kPaletteTableFlags, ImVec2(0, 0))) { TableSetupColumn("Palette Groups", ImGuiTableColumnFlags_WidthStretch, GetContentRegionAvail().x); - TableSetupColumn("Metadata", ImGuiTableColumnFlags_WidthStretch, + TableSetupColumn("Palette Sets and Metadata", + ImGuiTableColumnFlags_WidthStretch, GetContentRegionAvail().x); TableHeadersRow(); TableNextRow(); @@ -100,6 +103,8 @@ absl::Status PaletteEditor::Update() { DisplayCategoryTable(); TableNextColumn(); + gfx_group_editor_.DrawPaletteViewer(); + Separator(); static bool in_use = false; ImGui::Checkbox("Palette in use? ", &in_use); Separator(); @@ -205,11 +210,6 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category) { static bool edit_color = false; for (int j = 0; j < size; j++) { - rom()->resource_label()->SelectableLabelWithNameEdit( - false, palette_group_name.data(), /*key=*/std::to_string(j), - "Unnamed Palette"); - SameLine(); - gfx::SnesPalette* palette = palette_group.mutable_palette(j); auto pal_size = palette->size(); @@ -238,6 +238,10 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category) { PopID(); } + SameLine(); + rom()->resource_label()->SelectableLabelWithNameEdit( + false, palette_group_name.data(), /*key=*/std::to_string(j), + "Unnamed Palette"); } return absl::OkStatus(); } diff --git a/src/app/editor/modules/palette_editor.h b/src/app/editor/modules/palette_editor.h index b59f7107..e9ff7e54 100644 --- a/src/app/editor/modules/palette_editor.h +++ b/src/app/editor/modules/palette_editor.h @@ -4,6 +4,7 @@ #include #include "absl/status/status.h" +#include "app/editor/modules/gfx_group_editor.h" #include "app/editor/utils/editor.h" #include "app/gfx/snes_palette.h" #include "app/gui/canvas.h" @@ -14,37 +15,6 @@ namespace yaze { namespace app { namespace editor { -constexpr int kNumPalettes = 14; - -enum PaletteCategory { - kSword, - kShield, - kClothes, - kWorldColors, - kAreaColors, - kGlobalSprites, - kSpritesAux1, - kSpritesAux2, - kSpritesAux3, - kDungeons, - kWorldMap, - kDungeonMap, - kTriforce, - kCrystal -}; - -static constexpr absl::string_view kPaletteCategoryNames[] = { - "Sword", "Shield", "Clothes", "World Colors", - "Area Colors", "Global Sprites", "Sprites Aux1", "Sprites Aux2", - "Sprites Aux3", "Dungeons", "World Map", "Dungeon Map", - "Triforce", "Crystal"}; - -static constexpr absl::string_view kPaletteGroupNames[] = { - "swords", "shields", "armors", "ow_main", - "ow_aux", "global_sprites", "sprites_aux1", "sprites_aux2", - "sprites_aux3", "dungeon_main", "ow_mini_map", "ow_mini_map", - "3d_object", "3d_object"}; - namespace palette_internal { struct PaletteChange { std::string group_name; @@ -136,18 +106,19 @@ class PaletteEditor : public SharedRom, public Editor { } absl::Status status_; - - palette_internal::PaletteEditorHistory history_; - - ImVec4 saved_palette_[256] = {}; gfx::SnesColor current_color_; + GfxGroupEditor gfx_group_editor_; + + ImVec4 saved_palette_[256] = {}; ImGuiColorEditFlags color_popup_flags = ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha; ImGuiColorEditFlags palette_button_flags = ImGuiColorEditFlags_NoAlpha; ImGuiColorEditFlags palette_button_flags_2 = ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoTooltip; + + palette_internal::PaletteEditorHistory history_; }; } // namespace editor