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