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