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