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