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 = GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(sheet_id);
115 gui::BitmapCanvasPipeline(blockset_canvas_, sheet, 256, 0x10 * 0x04,
116 0x20, true, false, 22);
117 }
118 EndGroup();
119 }
120 EndTable();
121 }
122}
123
125 Text("Values - Overwrites 4 of main blockset");
126 if (BeginTable("##Roomstable", 3,
127 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable,
128 ImVec2(0, 0))) {
129 TableSetupColumn("List", ImGuiTableColumnFlags_WidthFixed, 100);
130 TableSetupColumn("Inputs", ImGuiTableColumnFlags_WidthStretch,
131 GetContentRegionAvail().x);
132 TableSetupColumn("Sheets", ImGuiTableColumnFlags_WidthFixed, 256);
133 TableHeadersRow();
134 TableNextRow();
135
136 TableNextColumn();
137 {
138 BeginChild("##RoomsetList");
139 for (int i = 0; i < 0x51; i++) {
140 BeginGroup();
141 std::string roomset_label = absl::StrFormat("0x%02X", i);
142 rom()->resource_label()->SelectableLabelWithNameEdit(
143 false, "roomset", roomset_label, "Roomset " + roomset_label);
144 if (IsItemClicked()) {
146 }
147 EndGroup();
148 }
149 EndChild();
150 }
151
152 TableNextColumn();
153 {
154 BeginGroup();
155 for (int i = 0; i < 4; i++) {
156 SetNextItemWidth(100.f);
157 gui::InputHexByte(("0x" + std::to_string(i)).c_str(),
158 &rom()->room_blockset_ids[selected_roomset_][i]);
159 }
160 EndGroup();
161 }
162 TableNextColumn();
163 {
164 BeginGroup();
165 for (int i = 0; i < 4; i++) {
166 int sheet_id = rom()->room_blockset_ids[selected_roomset_][i];
167 auto &sheet = GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(sheet_id);
168 gui::BitmapCanvasPipeline(roomset_canvas_, sheet, 256, 0x10 * 0x04,
169 0x20, true, false, 23);
170 }
171 EndGroup();
172 }
173 EndTable();
174 }
175}
176
178 if (BeginTable("##SpritesTable", sheet_only ? 1 : 2,
179 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable,
180 ImVec2(0, 0))) {
181 if (!sheet_only) {
182 TableSetupColumn("Inputs", ImGuiTableColumnFlags_WidthStretch,
183 GetContentRegionAvail().x);
184 }
185 TableSetupColumn("Sheets", ImGuiTableColumnFlags_WidthFixed, 256);
186 TableHeadersRow();
187 TableNextRow();
188 if (!sheet_only) {
189 TableNextColumn();
190 {
191 BeginGroup();
192 for (int i = 0; i < 4; i++) {
193 SetNextItemWidth(100.f);
194 gui::InputHexByte(("0x" + std::to_string(i)).c_str(),
195 &rom()->spriteset_ids[selected_spriteset_][i]);
196 }
197 EndGroup();
198 }
199 }
200 TableNextColumn();
201 {
202 BeginGroup();
203 for (int i = 0; i < 4; i++) {
204 int sheet_id = rom()->spriteset_ids[selected_spriteset_][i];
205 auto &sheet = GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(115 + sheet_id);
206 gui::BitmapCanvasPipeline(spriteset_canvas_, sheet, 256, 0x10 * 0x04,
207 0x20, true, false, 24);
208 }
209 EndGroup();
210 }
211 EndTable();
212 }
213}
214
215namespace {
217 if (palette.empty()) {
218 return;
219 }
220 for (size_t n = 0; n < palette.size(); n++) {
221 PushID(n);
222 if ((n % 8) != 0) SameLine(0.0f, GetStyle().ItemSpacing.y);
223
224 // Small icon of the color in the palette
225 if (gui::SnesColorButton(absl::StrCat("Palette", n), palette[n],
226 ImGuiColorEditFlags_NoAlpha |
227 ImGuiColorEditFlags_NoPicker |
228 ImGuiColorEditFlags_NoTooltip)) {
229 }
230
231 PopID();
232 }
233}
234} // namespace
235
237 gui::InputHexByte("Selected Paletteset", &selected_paletteset_);
238 if (selected_paletteset_ >= 71) {
240 }
241 rom()->resource_label()->SelectableLabelWithNameEdit(
242 false, "paletteset", "0x" + std::to_string(selected_paletteset_),
243 "Paletteset " + std::to_string(selected_paletteset_));
244
245 uint8_t &dungeon_main_palette_val =
246 rom()->paletteset_ids[selected_paletteset_][0];
247 uint8_t &dungeon_spr_pal_1_val =
248 rom()->paletteset_ids[selected_paletteset_][1];
249 uint8_t &dungeon_spr_pal_2_val =
250 rom()->paletteset_ids[selected_paletteset_][2];
251 uint8_t &dungeon_spr_pal_3_val =
252 rom()->paletteset_ids[selected_paletteset_][3];
253
254 gui::InputHexByte("Dungeon Main", &dungeon_main_palette_val);
255
256 rom()->resource_label()->SelectableLabelWithNameEdit(
257 false, kPaletteGroupNames[PaletteCategory::kDungeons].data(),
258 std::to_string(dungeon_main_palette_val), "Unnamed dungeon palette");
259 auto &palette = *rom()->mutable_palette_group()->dungeon_main.mutable_palette(
260 rom()->paletteset_ids[selected_paletteset_][0]);
261 DrawPaletteFromPaletteGroup(palette);
262 Separator();
263
264 gui::InputHexByte("Dungeon Spr Pal 1", &dungeon_spr_pal_1_val);
265 auto &spr_aux_pal1 =
266 *rom()->mutable_palette_group()->sprites_aux1.mutable_palette(
267 rom()->paletteset_ids[selected_paletteset_][1]);
268 DrawPaletteFromPaletteGroup(spr_aux_pal1);
269 SameLine();
270 rom()->resource_label()->SelectableLabelWithNameEdit(
271 false, kPaletteGroupNames[PaletteCategory::kSpritesAux1].data(),
272 std::to_string(dungeon_spr_pal_1_val), "Dungeon Spr Pal 1");
273 Separator();
274
275 gui::InputHexByte("Dungeon Spr Pal 2", &dungeon_spr_pal_2_val);
276 auto &spr_aux_pal2 =
277 *rom()->mutable_palette_group()->sprites_aux2.mutable_palette(
278 rom()->paletteset_ids[selected_paletteset_][2]);
279 DrawPaletteFromPaletteGroup(spr_aux_pal2);
280 SameLine();
281 rom()->resource_label()->SelectableLabelWithNameEdit(
282 false, kPaletteGroupNames[PaletteCategory::kSpritesAux2].data(),
283 std::to_string(dungeon_spr_pal_2_val), "Dungeon Spr Pal 2");
284 Separator();
285
286 gui::InputHexByte("Dungeon Spr Pal 3", &dungeon_spr_pal_3_val);
287 auto &spr_aux_pal3 =
288 *rom()->mutable_palette_group()->sprites_aux3.mutable_palette(
289 rom()->paletteset_ids[selected_paletteset_][3]);
290 DrawPaletteFromPaletteGroup(spr_aux_pal3);
291 SameLine();
292 rom()->resource_label()->SelectableLabelWithNameEdit(
293 false, kPaletteGroupNames[PaletteCategory::kSpritesAux3].data(),
294 std::to_string(dungeon_spr_pal_3_val), "Dungeon Spr Pal 3");
295}
296
297} // namespace editor
298} // namespace yaze
static GraphicsSheetManager & GetInstance()
Definition rom.h:271
auto rom()
Definition rom.h:383
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