yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
paletteset_editor_panel.cc
Go to the documentation of this file.
2
3#include "absl/strings/str_cat.h"
4#include "absl/strings/str_format.h"
9#include "imgui/imgui.h"
10
11namespace yaze {
12namespace editor {
13
14using ImGui::BeginChild;
15using ImGui::BeginGroup;
16using ImGui::BeginTable;
17using ImGui::EndChild;
18using ImGui::EndGroup;
19using ImGui::EndTable;
20using ImGui::GetContentRegionAvail;
21using ImGui::GetStyle;
22using ImGui::PopID;
23using ImGui::PushID;
24using ImGui::SameLine;
25using ImGui::Selectable;
26using ImGui::Separator;
27using ImGui::SetNextItemWidth;
28using ImGui::TableHeadersRow;
29using ImGui::TableNextColumn;
30using ImGui::TableNextRow;
31using ImGui::TableSetupColumn;
32using ImGui::Text;
33
34using gfx::kPaletteGroupNames;
36
38 if (!rom() || !rom()->is_loaded() || !game_data()) {
39 Text("No ROM loaded. Please open a Zelda 3 ROM.");
40 return absl::OkStatus();
41 }
42
43 // Header with controls
44 Text(ICON_MD_PALETTE " Paletteset Editor");
45 SameLine();
46 ImGui::Checkbox("Show All Colors", &show_all_colors_);
47 if (ImGui::IsItemHovered()) {
48 ImGui::SetTooltip("Show full 16-color palettes instead of 8");
49 }
50 Separator();
51
52 // Two-column layout: list on left, editor on right
53 if (BeginTable("##PalettesetLayout", 2,
54 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable)) {
55 TableSetupColumn("Palettesets", ImGuiTableColumnFlags_WidthFixed, 200);
56 TableSetupColumn("Editor", ImGuiTableColumnFlags_WidthStretch);
57 TableHeadersRow();
58 TableNextRow();
59
60 TableNextColumn();
62
63 TableNextColumn();
65
66 EndTable();
67 }
68
69 return absl::OkStatus();
70}
71
73 if (BeginChild("##PalettesetListChild", ImVec2(0, 400))) {
74 for (uint8_t idx = 0; idx < 72; idx++) {
75 PushID(idx);
76
77 std::string label = absl::StrFormat("0x%02X", idx);
78 bool is_selected = (selected_paletteset_ == idx);
79
80 // Show custom name if available
81 std::string display_name = label;
82 // if (rom()->resource_label()->HasLabel("paletteset", label)) {
83 // display_name =
84 // rom()->resource_label()->GetLabel("paletteset", label) + " (" +
85 // label + ")";
86 // }
87
88 if (Selectable(display_name.c_str(), is_selected)) {
90 }
91
92 PopID();
93 }
94 }
95 EndChild();
96}
97
99 if (selected_paletteset_ >= 72) {
101 }
102
103 // Paletteset name editing
104 std::string paletteset_label =
105 absl::StrFormat("Paletteset 0x%02X", selected_paletteset_);
106 Text("%s", paletteset_label.c_str());
107
109 false, "paletteset", "0x" + std::to_string(selected_paletteset_),
110 paletteset_label);
111
112 Separator();
113
114 // Get the paletteset data
115 auto& paletteset_ids = game_data()->paletteset_ids[selected_paletteset_];
116
117 // Dungeon Main Palette
118 BeginGroup();
119 Text(ICON_MD_LANDSCAPE " Dungeon Main Palette");
120 SetNextItemWidth(80.f);
121 gui::InputHexByte("##DungeonMainIdx", &paletteset_ids[0]);
122 SameLine();
123 Text("Index: %d", paletteset_ids[0]);
124
125 auto* dungeon_palette =
127 paletteset_ids[0]);
128 if (dungeon_palette) {
129 DrawPalettePreview(*dungeon_palette, "dungeon_main");
130 }
131 EndGroup();
132
133 Separator();
134
135 // Sprite Auxiliary Palettes
136 const char* sprite_labels[] = {"Sprite Aux 1", "Sprite Aux 2",
137 "Sprite Aux 3"};
138 const char* sprite_icons[] = {ICON_MD_PERSON, ICON_MD_PETS,
140 gfx::PaletteGroup* sprite_groups[] = {
144
145 for (int slot = 0; slot < 3; slot++) {
146 PushID(slot);
147 BeginGroup();
148
149 Text("%s %s", sprite_icons[slot], sprite_labels[slot]);
150 SetNextItemWidth(80.f);
151 gui::InputHexByte("##SpriteAuxIdx", &paletteset_ids[slot + 1]);
152 SameLine();
153 Text("Index: %d", paletteset_ids[slot + 1]);
154
155 auto* sprite_palette =
156 sprite_groups[slot]->mutable_palette(paletteset_ids[slot + 1]);
157 if (sprite_palette) {
158 DrawPalettePreview(*sprite_palette, sprite_labels[slot]);
159 }
160
161 EndGroup();
162 if (slot < 2) {
163 Separator();
164 }
165
166 PopID();
167 }
168}
169
171 const char* label) {
172 PushID(label);
173 DrawPaletteGrid(palette, false);
174 PopID();
175}
176
178 bool editable) {
179 if (palette.empty()) {
180 Text("(Empty palette)");
181 return;
182 }
183
184 size_t colors_to_show = show_all_colors_ ? palette.size() : 8;
185 colors_to_show = std::min(colors_to_show, palette.size());
186
187 for (size_t color_idx = 0; color_idx < colors_to_show; color_idx++) {
188 PushID(static_cast<int>(color_idx));
189
190 if ((color_idx % 8) != 0) {
191 SameLine(0.0f, GetStyle().ItemSpacing.y);
192 }
193
194 ImGuiColorEditFlags flags = ImGuiColorEditFlags_NoAlpha |
195 ImGuiColorEditFlags_NoTooltip;
196 if (!editable) {
197 flags |= ImGuiColorEditFlags_NoPicker;
198 }
199
200 if (gui::SnesColorButton(absl::StrCat("Color", color_idx),
201 palette[color_idx], flags)) {
202 // Color was clicked - could open color picker if editable
203 }
204
205 if (ImGui::IsItemHovered()) {
206 auto& color = palette[color_idx];
207 ImGui::SetTooltip("Color %zu\nRGB: %d, %d, %d\nSNES: $%04X",
208 color_idx, color.rom_color().red, color.rom_color().green, color.rom_color().blue,
209 color.snes());
210 }
211
212 PopID();
213 }
214
215 if (!show_all_colors_ && palette.size() > 8) {
216 SameLine();
217 Text("(+%zu more)", palette.size() - 8);
218 }
219}
220
221} // namespace editor
222} // namespace yaze
223
project::ResourceLabelManager * resource_label()
Definition rom.h:146
void DrawPaletteGrid(gfx::SnesPalette &palette, bool editable=false)
void DrawPalettePreview(gfx::SnesPalette &palette, const char *label)
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
#define ICON_MD_LANDSCAPE
Definition icons.h:1059
#define ICON_MD_PETS
Definition icons.h:1431
#define ICON_MD_PERSON
Definition icons.h:1415
#define ICON_MD_PALETTE
Definition icons.h:1370
#define ICON_MD_SMART_TOY
Definition icons.h:1781
IMGUI_API bool SnesColorButton(absl::string_view id, gfx::SnesColor &color, ImGuiColorEditFlags flags, const ImVec2 &size_arg)
Definition color.cc:37
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:370
Represents a group of palettes.
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:1294
std::array< std::array< uint8_t, 4 >, kNumPalettesets > paletteset_ids
Definition game_data.h:99
gfx::PaletteGroupMap palette_groups
Definition game_data.h:89