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