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