yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
paletteset_editor_view.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
38void PalettesetEditorView::Draw(bool* p_open) {
39 Update().IgnoreError();
40}
41
43 if (!rom() || !rom()->is_loaded() || !game_data()) {
44 Text(tr("No ROM loaded. Please open a Zelda 3 ROM."));
45 return absl::OkStatus();
46 }
47
48 // Header with controls
49 Text(ICON_MD_PALETTE " Paletteset Editor");
50 SameLine();
51 ImGui::Checkbox(tr("Show All Colors"), &show_all_colors_);
52 if (ImGui::IsItemHovered()) {
53 ImGui::SetTooltip(tr("Show full 16-color palettes instead of 8"));
54 }
55 Separator();
56
57 // Two-column layout: list on left, editor on right
58 if (BeginTable("##PalettesetLayout", 2,
59 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable)) {
60 TableSetupColumn("Palettesets", ImGuiTableColumnFlags_WidthFixed, 200);
61 TableSetupColumn("Editor", ImGuiTableColumnFlags_WidthStretch);
62 TableHeadersRow();
63 TableNextRow();
64
65 TableNextColumn();
67
68 TableNextColumn();
70
71 EndTable();
72 }
73
74 return absl::OkStatus();
75}
76
78 if (BeginChild("##PalettesetListChild", ImVec2(0, 400))) {
79 for (uint8_t idx = 0; idx < 72; idx++) {
80 PushID(idx);
81
82 std::string label = absl::StrFormat("0x%02X", idx);
83 bool is_selected = (selected_paletteset_ == idx);
84
85 // Show custom name if available
86 std::string display_name = label;
87 // if (rom()->resource_label()->HasLabel("paletteset", label)) {
88 // display_name =
89 // rom()->resource_label()->GetLabel("paletteset", label) + " (" +
90 // label + ")";
91 // }
92
93 if (Selectable(display_name.c_str(), is_selected)) {
95 }
96
97 PopID();
98 }
99 }
100 EndChild();
101}
102
104 if (selected_paletteset_ >= 72) {
106 }
107
108 // Paletteset name editing
109 std::string paletteset_label =
110 absl::StrFormat("Paletteset 0x%02X", selected_paletteset_);
111 Text("%s", paletteset_label.c_str());
112
114 false, "paletteset", "0x" + std::to_string(selected_paletteset_),
115 paletteset_label);
116
117 Separator();
118
119 // Get the paletteset data
120 auto& paletteset_ids = game_data()->paletteset_ids[selected_paletteset_];
121
122 // Dungeon Main Palette
123 BeginGroup();
124 Text(ICON_MD_LANDSCAPE " Dungeon Main Palette");
125 SetNextItemWidth(80.f);
126 gui::InputHexByte("##DungeonMainIdx", &paletteset_ids[0]);
127 SameLine();
128 Text(tr("Index: %d"), paletteset_ids[0]);
129
130 auto* dungeon_palette =
132 paletteset_ids[0]);
133 if (dungeon_palette) {
134 DrawPalettePreview(*dungeon_palette, "dungeon_main");
135 }
136 EndGroup();
137
138 Separator();
139
140 // Sprite Auxiliary Palettes
141 const char* sprite_labels[] = {"Sprite Aux 1", "Sprite Aux 2",
142 "Sprite Aux 3"};
143 const char* sprite_icons[] = {ICON_MD_PERSON, ICON_MD_PETS,
145 gfx::PaletteGroup* sprite_groups[] = {
149
150 for (int slot = 0; slot < 3; slot++) {
151 PushID(slot);
152 BeginGroup();
153
154 Text("%s %s", sprite_icons[slot], sprite_labels[slot]);
155 SetNextItemWidth(80.f);
156 gui::InputHexByte("##SpriteAuxIdx", &paletteset_ids[slot + 1]);
157 SameLine();
158 Text(tr("Index: %d"), paletteset_ids[slot + 1]);
159
160 auto* sprite_palette =
161 sprite_groups[slot]->mutable_palette(paletteset_ids[slot + 1]);
162 if (sprite_palette) {
163 DrawPalettePreview(*sprite_palette, sprite_labels[slot]);
164 }
165
166 EndGroup();
167 if (slot < 2) {
168 Separator();
169 }
170
171 PopID();
172 }
173}
174
176 const char* label) {
177 PushID(label);
178 DrawPaletteGrid(palette, false);
179 PopID();
180}
181
183 bool editable) {
184 if (palette.empty()) {
185 Text(tr("(Empty palette)"));
186 return;
187 }
188
189 size_t colors_to_show = show_all_colors_ ? palette.size() : 8;
190 colors_to_show = std::min(colors_to_show, palette.size());
191
192 for (size_t color_idx = 0; color_idx < colors_to_show; color_idx++) {
193 PushID(static_cast<int>(color_idx));
194
195 if ((color_idx % 8) != 0) {
196 SameLine(0.0f, GetStyle().ItemSpacing.y);
197 }
198
199 ImGuiColorEditFlags flags =
200 ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoTooltip;
201 if (!editable) {
202 flags |= ImGuiColorEditFlags_NoPicker;
203 }
204
205 if (gui::SnesColorButton(absl::StrCat("Color", color_idx),
206 palette[color_idx], flags)) {
207 // Color was clicked - could open color picker if editable
208 }
209
210 if (ImGui::IsItemHovered()) {
211 auto& color = palette[color_idx];
212 ImGui::SetTooltip(tr("Color %zu\nRGB: %d, %d, %d\nSNES: $%04X"),
213 color_idx, color.rom_color().red,
214 color.rom_color().green, color.rom_color().blue,
215 color.snes());
216 }
217
218 PopID();
219 }
220
221 if (!show_all_colors_ && palette.size() > 8) {
222 SameLine();
223 Text(tr("(+%zu more)"), palette.size() - 8);
224 }
225}
226
227} // namespace editor
228} // namespace yaze
project::ResourceLabelManager * resource_label()
Definition rom.h:162
void DrawPaletteGrid(gfx::SnesPalette &palette, bool editable=false)
void Draw(bool *p_open) override
Draw the panel content.
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