yaze 0.2.2
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"
6#include "app/gui/canvas.h"
7#include "app/gui/color.h"
8#include "app/gui/input.h"
9#include "app/rom.h"
10#include "imgui/imgui.h"
11
12namespace yaze {
13namespace editor {
14
15using ImGui::BeginChild;
16using ImGui::BeginGroup;
17using ImGui::BeginTabBar;
18using ImGui::BeginTabItem;
19using ImGui::BeginTable;
20using ImGui::EndChild;
21using ImGui::EndGroup;
22using ImGui::EndTabBar;
23using ImGui::EndTabItem;
24using ImGui::EndTable;
25using ImGui::GetContentRegionAvail;
26using ImGui::GetStyle;
27using ImGui::IsItemClicked;
28using ImGui::PopID;
29using ImGui::PushID;
30using ImGui::SameLine;
31using ImGui::Separator;
32using ImGui::SetNextItemWidth;
33using ImGui::TableHeadersRow;
34using ImGui::TableNextColumn;
35using ImGui::TableNextRow;
36using ImGui::TableSetupColumn;
37using ImGui::Text;
38
39using gfx::kPaletteGroupNames;
41
42absl::Status GfxGroupEditor::Update() {
43 if (BeginTabBar("GfxGroupEditor")) {
44 if (BeginTabItem("Main")) {
45 gui::InputHexByte("Selected Blockset", &selected_blockset_,
46 (uint8_t)0x24);
47 rom()->resource_label()->SelectableLabelWithNameEdit(
48 false, "blockset", "0x" + std::to_string(selected_blockset_),
49 "Blockset " + std::to_string(selected_blockset_));
51 EndTabItem();
52 }
53
54 if (BeginTabItem("Rooms")) {
55 gui::InputHexByte("Selected Blockset", &selected_roomset_, (uint8_t)81);
56 rom()->resource_label()->SelectableLabelWithNameEdit(
57 false, "roomset", "0x" + std::to_string(selected_roomset_),
58 "Roomset " + std::to_string(selected_roomset_));
60 EndTabItem();
61 }
62
63 if (BeginTabItem("Sprites")) {
64 gui::InputHexByte("Selected Spriteset", &selected_spriteset_,
65 (uint8_t)143);
66 rom()->resource_label()->SelectableLabelWithNameEdit(
67 false, "spriteset", "0x" + std::to_string(selected_spriteset_),
68 "Spriteset " + std::to_string(selected_spriteset_));
69 Text("Values");
71 EndTabItem();
72 }
73
74 if (BeginTabItem("Palettes")) {
76 EndTabItem();
77 }
78
79 EndTabBar();
80 }
81
82 return absl::OkStatus();
83}
84
86 if (BeginTable("##BlocksetTable", sheet_only ? 1 : 2,
87 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable,
88 ImVec2(0, 0))) {
89 if (!sheet_only) {
90 TableSetupColumn("Inputs", ImGuiTableColumnFlags_WidthStretch,
91 GetContentRegionAvail().x);
92 }
93
94 TableSetupColumn("Sheets", ImGuiTableColumnFlags_WidthFixed, 256);
95 TableHeadersRow();
96 TableNextRow();
97 if (!sheet_only) {
98 TableNextColumn();
99 {
100 BeginGroup();
101 for (int i = 0; i < 8; i++) {
102 SetNextItemWidth(100.f);
103 gui::InputHexByte(("0x" + std::to_string(i)).c_str(),
104 &rom()->main_blockset_ids[selected_blockset_][i]);
105 }
106 EndGroup();
107 }
108 }
109 TableNextColumn();
110 {
111 BeginGroup();
112 for (int i = 0; i < 8; i++) {
113 int sheet_id = rom()->main_blockset_ids[selected_blockset_][i];
114 auto &sheet =
116 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 =
171 sheet_id);
172 gui::BitmapCanvasPipeline(roomset_canvas_, sheet, 256, 0x10 * 0x04,
173 0x20, true, false, 23);
174 }
175 EndGroup();
176 }
177 EndTable();
178 }
179}
180
182 if (BeginTable("##SpritesTable", sheet_only ? 1 : 2,
183 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable,
184 ImVec2(0, 0))) {
185 if (!sheet_only) {
186 TableSetupColumn("Inputs", ImGuiTableColumnFlags_WidthStretch,
187 GetContentRegionAvail().x);
188 }
189 TableSetupColumn("Sheets", ImGuiTableColumnFlags_WidthFixed, 256);
190 TableHeadersRow();
191 TableNextRow();
192 if (!sheet_only) {
193 TableNextColumn();
194 {
195 BeginGroup();
196 for (int i = 0; i < 4; i++) {
197 SetNextItemWidth(100.f);
198 gui::InputHexByte(("0x" + std::to_string(i)).c_str(),
199 &rom()->spriteset_ids[selected_spriteset_][i]);
200 }
201 EndGroup();
202 }
203 }
204 TableNextColumn();
205 {
206 BeginGroup();
207 for (int i = 0; i < 4; i++) {
208 int sheet_id = rom()->spriteset_ids[selected_spriteset_][i];
209 auto &sheet =
211 115 + sheet_id);
212 gui::BitmapCanvasPipeline(spriteset_canvas_, sheet, 256, 0x10 * 0x04,
213 0x20, true, false, 24);
214 }
215 EndGroup();
216 }
217 EndTable();
218 }
219}
220
221namespace {
223 if (palette.empty()) {
224 return;
225 }
226 for (size_t n = 0; n < palette.size(); n++) {
227 PushID(n);
228 if ((n % 8) != 0) SameLine(0.0f, GetStyle().ItemSpacing.y);
229
230 // Small icon of the color in the palette
231 if (gui::SnesColorButton(absl::StrCat("Palette", n), palette[n],
232 ImGuiColorEditFlags_NoAlpha |
233 ImGuiColorEditFlags_NoPicker |
234 ImGuiColorEditFlags_NoTooltip)) {
235 }
236
237 PopID();
238 }
239}
240} // namespace
241
243 if (!rom()->is_loaded()) {
244 return;
245 }
246 gui::InputHexByte("Selected Paletteset", &selected_paletteset_);
247 if (selected_paletteset_ >= 71) {
249 }
250 rom()->resource_label()->SelectableLabelWithNameEdit(
251 false, "paletteset", "0x" + std::to_string(selected_paletteset_),
252 "Paletteset " + std::to_string(selected_paletteset_));
253
254 uint8_t &dungeon_main_palette_val =
255 rom()->paletteset_ids[selected_paletteset_][0];
256 uint8_t &dungeon_spr_pal_1_val =
257 rom()->paletteset_ids[selected_paletteset_][1];
258 uint8_t &dungeon_spr_pal_2_val =
259 rom()->paletteset_ids[selected_paletteset_][2];
260 uint8_t &dungeon_spr_pal_3_val =
261 rom()->paletteset_ids[selected_paletteset_][3];
262
263 gui::InputHexByte("Dungeon Main", &dungeon_main_palette_val);
264
265 rom()->resource_label()->SelectableLabelWithNameEdit(
266 false, kPaletteGroupNames[PaletteCategory::kDungeons].data(),
267 std::to_string(dungeon_main_palette_val), "Unnamed dungeon palette");
268 auto &palette = *rom()->mutable_palette_group()->dungeon_main.mutable_palette(
269 rom()->paletteset_ids[selected_paletteset_][0]);
270 DrawPaletteFromPaletteGroup(palette);
271 Separator();
272
273 gui::InputHexByte("Dungeon Spr Pal 1", &dungeon_spr_pal_1_val);
274 auto &spr_aux_pal1 =
275 *rom()->mutable_palette_group()->sprites_aux1.mutable_palette(
276 rom()->paletteset_ids[selected_paletteset_][1]);
277 DrawPaletteFromPaletteGroup(spr_aux_pal1);
278 SameLine();
279 rom()->resource_label()->SelectableLabelWithNameEdit(
280 false, kPaletteGroupNames[PaletteCategory::kSpritesAux1].data(),
281 std::to_string(dungeon_spr_pal_1_val), "Dungeon Spr Pal 1");
282 Separator();
283
284 gui::InputHexByte("Dungeon Spr Pal 2", &dungeon_spr_pal_2_val);
285 auto &spr_aux_pal2 =
286 *rom()->mutable_palette_group()->sprites_aux2.mutable_palette(
287 rom()->paletteset_ids[selected_paletteset_][2]);
288 DrawPaletteFromPaletteGroup(spr_aux_pal2);
289 SameLine();
290 rom()->resource_label()->SelectableLabelWithNameEdit(
291 false, kPaletteGroupNames[PaletteCategory::kSpritesAux2].data(),
292 std::to_string(dungeon_spr_pal_2_val), "Dungeon Spr Pal 2");
293 Separator();
294
295 gui::InputHexByte("Dungeon Spr Pal 3", &dungeon_spr_pal_3_val);
296 auto &spr_aux_pal3 =
297 *rom()->mutable_palette_group()->sprites_aux3.mutable_palette(
298 rom()->paletteset_ids[selected_paletteset_][3]);
299 DrawPaletteFromPaletteGroup(spr_aux_pal3);
300 SameLine();
301 rom()->resource_label()->SelectableLabelWithNameEdit(
302 false, kPaletteGroupNames[PaletteCategory::kSpritesAux3].data(),
303 std::to_string(dungeon_spr_pal_3_val), "Dungeon Spr Pal 3");
304}
305
306} // namespace editor
307} // namespace yaze
static GraphicsSheetManager & GetInstance()
Definition rom.h:270
auto rom()
Definition rom.h:382
void DrawSpritesetViewer(bool sheet_only=false)
void DrawBlocksetViewer(bool sheet_only=false)
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Editors are the view controllers for the application.
IMGUI_API bool SnesColorButton(absl::string_view id, gfx::SnesColor &color, ImGuiColorEditFlags flags, const ImVec2 &size_arg)
Definition color.cc:19
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:831
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:167
Main namespace for the application.
Definition controller.cc:18