yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
gfx_group_editor.cc
Go to the documentation of this file.
1#include "gfx_group_editor.h"
2
3#include "absl/status/status.h"
4#include "absl/strings/str_cat.h"
5#include "app/gfx/bitmap.h"
7#include "app/gui/canvas.h"
8#include "app/gui/color.h"
9#include "app/gui/input.h"
10#include "app/rom.h"
11#include "imgui/imgui.h"
12
13namespace yaze {
14namespace app {
15namespace editor {
16
17using ImGui::BeginChild;
18using ImGui::BeginGroup;
19using ImGui::BeginTabBar;
20using ImGui::BeginTabItem;
21using ImGui::BeginTable;
22using ImGui::EndChild;
23using ImGui::EndGroup;
24using ImGui::EndTabBar;
25using ImGui::EndTabItem;
26using ImGui::EndTable;
27using ImGui::GetContentRegionAvail;
28using ImGui::GetStyle;
29using ImGui::IsItemClicked;
30using ImGui::PopID;
31using ImGui::PushID;
32using ImGui::SameLine;
33using ImGui::Separator;
34using ImGui::SetNextItemWidth;
35using ImGui::TableHeadersRow;
36using ImGui::TableNextColumn;
37using ImGui::TableNextRow;
38using ImGui::TableSetupColumn;
39using ImGui::Text;
40
41using gfx::kPaletteGroupNames;
43
44absl::Status GfxGroupEditor::Update() {
45 if (BeginTabBar("GfxGroupEditor")) {
46 if (BeginTabItem("Main")) {
47 gui::InputHexByte("Selected Blockset", &selected_blockset_,
48 (uint8_t)0x24);
49 rom()->resource_label()->SelectableLabelWithNameEdit(
50 false, "blockset", "0x" + std::to_string(selected_blockset_),
51 "Blockset " + std::to_string(selected_blockset_));
53 EndTabItem();
54 }
55
56 if (BeginTabItem("Rooms")) {
57 gui::InputHexByte("Selected Blockset", &selected_roomset_, (uint8_t)81);
58 rom()->resource_label()->SelectableLabelWithNameEdit(
59 false, "roomset", "0x" + std::to_string(selected_roomset_),
60 "Roomset " + std::to_string(selected_roomset_));
62 EndTabItem();
63 }
64
65 if (BeginTabItem("Sprites")) {
66 gui::InputHexByte("Selected Spriteset", &selected_spriteset_,
67 (uint8_t)143);
68 rom()->resource_label()->SelectableLabelWithNameEdit(
69 false, "spriteset", "0x" + std::to_string(selected_spriteset_),
70 "Spriteset " + std::to_string(selected_spriteset_));
71 Text("Values");
73 EndTabItem();
74 }
75
76 if (BeginTabItem("Palettes")) {
78 EndTabItem();
79 }
80
81 EndTabBar();
82 }
83
84 return absl::OkStatus();
85}
86
88 if (BeginTable("##BlocksetTable", sheet_only ? 1 : 2,
89 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable,
90 ImVec2(0, 0))) {
91 if (!sheet_only) {
92 TableSetupColumn("Inputs", ImGuiTableColumnFlags_WidthStretch,
93 GetContentRegionAvail().x);
94 }
95
96 TableSetupColumn("Sheets", ImGuiTableColumnFlags_WidthFixed, 256);
97 TableHeadersRow();
98 TableNextRow();
99 if (!sheet_only) {
100 TableNextColumn();
101 {
102 BeginGroup();
103 for (int i = 0; i < 8; i++) {
104 SetNextItemWidth(100.f);
105 gui::InputHexByte(("0x" + std::to_string(i)).c_str(),
106 &rom()->main_blockset_ids[selected_blockset_][i]);
107 }
108 EndGroup();
109 }
110 }
111 TableNextColumn();
112 {
113 BeginGroup();
114 for (int i = 0; i < 8; i++) {
115 int sheet_id = rom()->main_blockset_ids[selected_blockset_][i];
116 auto sheet = rom()->gfx_sheets().at(sheet_id);
117 gui::BitmapCanvasPipeline(blockset_canvas_, sheet, 256, 0x10 * 0x04,
118 0x20, true, false, 22);
119 }
120 EndGroup();
121 }
122 EndTable();
123 }
124}
125
127 Text("Values - Overwrites 4 of main blockset");
128 if (BeginTable("##Roomstable", 3,
129 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable,
130 ImVec2(0, 0))) {
131 TableSetupColumn("List", ImGuiTableColumnFlags_WidthFixed, 100);
132 TableSetupColumn("Inputs", ImGuiTableColumnFlags_WidthStretch,
133 GetContentRegionAvail().x);
134 TableSetupColumn("Sheets", ImGuiTableColumnFlags_WidthFixed, 256);
135 TableHeadersRow();
136 TableNextRow();
137
138 TableNextColumn();
139 {
140 BeginChild("##RoomsetList");
141 for (int i = 0; i < 0x51; i++) {
142 BeginGroup();
143 std::string roomset_label = absl::StrFormat("0x%02X", i);
144 rom()->resource_label()->SelectableLabelWithNameEdit(
145 false, "roomset", roomset_label, "Roomset " + roomset_label);
146 if (IsItemClicked()) {
148 }
149 EndGroup();
150 }
151 EndChild();
152 }
153
154 TableNextColumn();
155 {
156 BeginGroup();
157 for (int i = 0; i < 4; i++) {
158 SetNextItemWidth(100.f);
159 gui::InputHexByte(("0x" + std::to_string(i)).c_str(),
160 &rom()->room_blockset_ids[selected_roomset_][i]);
161 }
162 EndGroup();
163 }
164 TableNextColumn();
165 {
166 BeginGroup();
167 for (int i = 0; i < 4; i++) {
168 int sheet_id = rom()->room_blockset_ids[selected_roomset_][i];
169 auto sheet = rom()->gfx_sheets().at(sheet_id);
170 gui::BitmapCanvasPipeline(roomset_canvas_, sheet, 256, 0x10 * 0x04,
171 0x20, true, false, 23);
172 }
173 EndGroup();
174 }
175 EndTable();
176 }
177}
178
180 if (BeginTable("##SpritesTable", sheet_only ? 1 : 2,
181 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable,
182 ImVec2(0, 0))) {
183 if (!sheet_only) {
184 TableSetupColumn("Inputs", ImGuiTableColumnFlags_WidthStretch,
185 GetContentRegionAvail().x);
186 }
187 TableSetupColumn("Sheets", ImGuiTableColumnFlags_WidthFixed, 256);
188 TableHeadersRow();
189 TableNextRow();
190 if (!sheet_only) {
191 TableNextColumn();
192 {
193 BeginGroup();
194 for (int i = 0; i < 4; i++) {
195 SetNextItemWidth(100.f);
196 gui::InputHexByte(("0x" + std::to_string(i)).c_str(),
197 &rom()->spriteset_ids[selected_spriteset_][i]);
198 }
199 EndGroup();
200 }
201 }
202 TableNextColumn();
203 {
204 BeginGroup();
205 for (int i = 0; i < 4; i++) {
206 int sheet_id = rom()->spriteset_ids[selected_spriteset_][i];
207 auto sheet = rom()->gfx_sheets().at(115 + sheet_id);
208 gui::BitmapCanvasPipeline(spriteset_canvas_, sheet, 256, 0x10 * 0x04,
209 0x20, true, false, 24);
210 }
211 EndGroup();
212 }
213 EndTable();
214 }
215}
216
217namespace {
219 if (palette.empty()) {
220 return;
221 }
222 for (size_t n = 0; n < palette.size(); n++) {
223 PushID(n);
224 if ((n % 8) != 0) SameLine(0.0f, GetStyle().ItemSpacing.y);
225
226 // Small icon of the color in the palette
227 if (gui::SnesColorButton(absl::StrCat("Palette", n), palette[n],
228 ImGuiColorEditFlags_NoAlpha |
229 ImGuiColorEditFlags_NoPicker |
230 ImGuiColorEditFlags_NoTooltip)) {
231 }
232
233 PopID();
234 }
235}
236} // namespace
237
239 gui::InputHexByte("Selected Paletteset", &selected_paletteset_);
240 if (selected_paletteset_ >= 71) {
242 }
243 rom()->resource_label()->SelectableLabelWithNameEdit(
244 false, "paletteset", "0x" + std::to_string(selected_paletteset_),
245 "Paletteset " + std::to_string(selected_paletteset_));
246
247 uint8_t &dungeon_main_palette_val =
248 rom()->paletteset_ids[selected_paletteset_][0];
249 uint8_t &dungeon_spr_pal_1_val =
250 rom()->paletteset_ids[selected_paletteset_][1];
251 uint8_t &dungeon_spr_pal_2_val =
252 rom()->paletteset_ids[selected_paletteset_][2];
253 uint8_t &dungeon_spr_pal_3_val =
254 rom()->paletteset_ids[selected_paletteset_][3];
255
256 gui::InputHexByte("Dungeon Main", &dungeon_main_palette_val);
257
258 rom()->resource_label()->SelectableLabelWithNameEdit(
259 false, kPaletteGroupNames[PaletteCategory::kDungeons].data(),
260 std::to_string(dungeon_main_palette_val), "Unnamed dungeon palette");
261 auto &palette = *rom()->mutable_palette_group()->dungeon_main.mutable_palette(
262 rom()->paletteset_ids[selected_paletteset_][0]);
263 DrawPaletteFromPaletteGroup(palette);
264 Separator();
265
266 gui::InputHexByte("Dungeon Spr Pal 1", &dungeon_spr_pal_1_val);
267 auto &spr_aux_pal1 =
268 *rom()->mutable_palette_group()->sprites_aux1.mutable_palette(
269 rom()->paletteset_ids[selected_paletteset_][1]);
270 DrawPaletteFromPaletteGroup(spr_aux_pal1);
271 SameLine();
272 rom()->resource_label()->SelectableLabelWithNameEdit(
273 false, kPaletteGroupNames[PaletteCategory::kSpritesAux1].data(),
274 std::to_string(dungeon_spr_pal_1_val), "Dungeon Spr Pal 1");
275 Separator();
276
277 gui::InputHexByte("Dungeon Spr Pal 2", &dungeon_spr_pal_2_val);
278 auto &spr_aux_pal2 =
279 *rom()->mutable_palette_group()->sprites_aux2.mutable_palette(
280 rom()->paletteset_ids[selected_paletteset_][2]);
281 DrawPaletteFromPaletteGroup(spr_aux_pal2);
282 SameLine();
283 rom()->resource_label()->SelectableLabelWithNameEdit(
284 false, kPaletteGroupNames[PaletteCategory::kSpritesAux2].data(),
285 std::to_string(dungeon_spr_pal_2_val), "Dungeon Spr Pal 2");
286 Separator();
287
288 gui::InputHexByte("Dungeon Spr Pal 3", &dungeon_spr_pal_3_val);
289 auto &spr_aux_pal3 =
290 *rom()->mutable_palette_group()->sprites_aux3.mutable_palette(
291 rom()->paletteset_ids[selected_paletteset_][3]);
292 DrawPaletteFromPaletteGroup(spr_aux_pal3);
293 SameLine();
294 rom()->resource_label()->SelectableLabelWithNameEdit(
295 false, kPaletteGroupNames[PaletteCategory::kSpritesAux3].data(),
296 std::to_string(dungeon_spr_pal_3_val), "Dungeon Spr Pal 3");
297}
298
299} // namespace editor
300} // namespace app
301} // namespace yaze
void DrawSpritesetViewer(bool sheet_only=false)
void DrawBlocksetViewer(bool sheet_only=false)
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:175
void BitmapCanvasPipeline(gui::Canvas &canvas, const gfx::Bitmap &bitmap, int width, int height, int tile_size, bool is_loaded, bool scrollbar, int canvas_id)
Definition canvas.cc:832
IMGUI_API bool SnesColorButton(absl::string_view id, SnesColor &color, ImGuiColorEditFlags flags, const ImVec2 &size_arg)
Definition color.cc:25
Definition common.cc:22