yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sprite_editor.cc
Go to the documentation of this file.
1#include "sprite_editor.h"
2
5#include "app/gui/icons.h"
6#include "app/gui/input.h"
8#include "util/hex.h"
9
10namespace yaze {
11namespace editor {
12
13using ImGui::BeginTable;
14using ImGui::Button;
15using ImGui::EndTable;
16using ImGui::Selectable;
17using ImGui::Separator;
18using ImGui::TableHeadersRow;
19using ImGui::TableNextColumn;
20using ImGui::TableNextRow;
21using ImGui::TableSetupColumn;
22using ImGui::Text;
23
24absl::Status SpriteEditor::Update() {
25 if (rom()->is_loaded() && !sheets_loaded_) {
26 // Load the values for current_sheets_ array
27 sheets_loaded_ = true;
28 }
29
30 if (ImGui::BeginTabBar("##SpriteEditorTabs")) {
31 if (ImGui::BeginTabItem("Vanilla")) {
33 ImGui::EndTabItem();
34 }
35 if (ImGui::BeginTabItem("Custom")) {
37 ImGui::EndTabItem();
38 }
39 ImGui::EndTabBar();
40 }
41
42 return status_.ok() ? absl::OkStatus() : status_;
43}
44
46 if (ImGui::BeginTable("##SpriteCanvasTable", 3, ImGuiTableFlags_Resizable,
47 ImVec2(0, 0))) {
48 TableSetupColumn("Sprites List", ImGuiTableColumnFlags_WidthFixed, 256);
49 TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
50 ImGui::GetContentRegionAvail().x);
51 TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256);
52 TableHeadersRow();
53 TableNextRow();
54
55 TableNextColumn();
57
58 TableNextColumn();
59 static int next_tab_id = 0;
60
61 if (ImGui::BeginTabBar("SpriteTabBar", kSpriteTabBarFlags)) {
62 if (ImGui::TabItemButton(ICON_MD_ADD, kSpriteTabBarFlags)) {
63 if (std::find(active_sprites_.begin(), active_sprites_.end(),
65 // Room is already open
66 next_tab_id++;
67 }
68 active_sprites_.push_back(next_tab_id++); // Add new tab
69 }
70
71 // Submit our regular tabs
72 for (int n = 0; n < active_sprites_.Size;) {
73 bool open = true;
74
75 if (active_sprites_[n] > sizeof(zelda3::kSpriteDefaultNames) / 4) {
76 active_sprites_.erase(active_sprites_.Data + n);
77 continue;
78 }
79
80 if (ImGui::BeginTabItem(
81 zelda3::kSpriteDefaultNames[active_sprites_[n]].data(), &open,
82 ImGuiTabItemFlags_None)) {
84 ImGui::EndTabItem();
85 }
86
87 if (!open)
88 active_sprites_.erase(active_sprites_.Data + n);
89 else
90 n++;
91 }
92
93 ImGui::EndTabBar();
94 }
95
96 TableNextColumn();
97 if (sheets_loaded_) {
99 }
100 ImGui::EndTable();
101 }
102}
103
105 static bool flip_x = false;
106 static bool flip_y = false;
107 if (ImGui::BeginChild(gui::GetID("##SpriteCanvas"),
108 ImGui::GetContentRegionAvail(), true)) {
109 sprite_canvas_.DrawBackground();
110 sprite_canvas_.DrawContextMenu();
111 sprite_canvas_.DrawGrid();
112 sprite_canvas_.DrawOverlay();
113
114 // Draw a table with OAM configuration
115 // X, Y, Tile, Palette, Priority, Flip X, Flip Y
116 if (ImGui::BeginTable("##OAMTable", 7, ImGuiTableFlags_Resizable,
117 ImVec2(0, 0))) {
118 TableSetupColumn("X", ImGuiTableColumnFlags_WidthStretch);
119 TableSetupColumn("Y", ImGuiTableColumnFlags_WidthStretch);
120 TableSetupColumn("Tile", ImGuiTableColumnFlags_WidthStretch);
121 TableSetupColumn("Palette", ImGuiTableColumnFlags_WidthStretch);
122 TableSetupColumn("Priority", ImGuiTableColumnFlags_WidthStretch);
123 TableSetupColumn("Flip X", ImGuiTableColumnFlags_WidthStretch);
124 TableSetupColumn("Flip Y", ImGuiTableColumnFlags_WidthStretch);
125 TableHeadersRow();
126 TableNextRow();
127
128 TableNextColumn();
130
131 TableNextColumn();
133
134 TableNextColumn();
136
137 TableNextColumn();
138 gui::InputHexByte("", &oam_config_.palette);
139
140 TableNextColumn();
141 gui::InputHexByte("", &oam_config_.priority);
142
143 TableNextColumn();
144 if (ImGui::Checkbox("##XFlip", &flip_x)) {
145 oam_config_.flip_x = flip_x;
146 }
147
148 TableNextColumn();
149 if (ImGui::Checkbox("##YFlip", &flip_y)) {
150 oam_config_.flip_y = flip_y;
151 }
152
153 ImGui::EndTable();
154 }
155
157
159
160 ImGui::EndChild();
161 }
162}
163
165 if (ImGui::BeginChild(gui::GetID("sheet_label"),
166 ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
167 ImGuiWindowFlags_NoDecoration)) {
168 for (int i = 0; i < 8; i++) {
169 std::string sheet_label = absl::StrFormat("Sheet %d", i);
170 gui::InputHexByte(sheet_label.c_str(), &current_sheets_[i]);
171 if (i % 2 == 0) ImGui::SameLine();
172 }
173
174 graphics_sheet_canvas_.DrawBackground();
175 graphics_sheet_canvas_.DrawContextMenu();
176 graphics_sheet_canvas_.DrawTileSelector(32);
177 for (int i = 0; i < 8; i++) {
178 graphics_sheet_canvas_.DrawBitmap(
179 GraphicsSheetManager::GetInstance().gfx_sheets().at(
180 current_sheets_[i]),
181 1, (i * 0x40) + 1, 2);
182 }
183 graphics_sheet_canvas_.DrawGrid();
184 graphics_sheet_canvas_.DrawOverlay();
185 ImGui::EndChild();
186 }
187}
188
190 if (ImGui::BeginChild(gui::GetID("##SpritesList"),
191 ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
192 ImGuiWindowFlags_NoDecoration)) {
193 int i = 0;
194 for (const auto each_sprite_name : zelda3::kSpriteDefaultNames) {
195 rom()->resource_label()->SelectableLabelWithNameEdit(
196 current_sprite_id_ == i, "Sprite Names", util::HexByte(i),
197 zelda3::kSpriteDefaultNames[i].data());
198 if (ImGui::IsItemClicked()) {
200 if (!active_sprites_.contains(i)) {
201 active_sprites_.push_back(i);
202 }
203 }
204 i++;
205 }
206 ImGui::EndChild();
207 }
208}
209
211 if (ImGui::Button("Add Frame")) {
212 // Add a new frame
213 }
214 if (ImGui::Button("Remove Frame")) {
215 // Remove the current frame
216 }
217}
218
220 if (BeginTable("##CustomSpritesTable", 3,
221 ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders |
222 ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable,
223 ImVec2(0, 0))) {
224 TableSetupColumn("Metadata", ImGuiTableColumnFlags_WidthFixed, 256);
225 TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthFixed, 256);
226 TableSetupColumn("TIlesheets", ImGuiTableColumnFlags_WidthFixed, 256);
227
228 TableHeadersRow();
229 TableNextRow();
230 TableNextColumn();
231
232 Separator();
234
235 TableNextColumn();
237
238 TableNextColumn();
240
241 EndTable();
242 }
243}
244
246 // ZSprite Maker format open file dialog
247 if (ImGui::Button("Open ZSprite")) {
248 // Open ZSprite file
249 std::string file_path = core::FileDialogWrapper::ShowOpenFileDialog();
250 if (!file_path.empty()) {
252 status_ = zsprite.Load(file_path);
253 if (status_.ok()) {
254 custom_sprites_.push_back(zsprite);
255 }
256 }
257 }
258
259 for (const auto custom_sprite : custom_sprites_) {
260 Selectable("%s", custom_sprite.sprName.c_str());
261 if (ImGui::IsItemClicked()) {
262 current_sprite_id_ = 256 + stoi(custom_sprite.property_sprid.Text);
263 if (!active_sprites_.contains(current_sprite_id_)) {
265 }
266 }
267 Separator();
268 }
269
270 for (const auto custom_sprite : custom_sprites_) {
271 // Draw the custom sprite metadata
272 Text("Sprite ID: %s", custom_sprite.property_sprid.Text.c_str());
273 Text("Sprite Name: %s", custom_sprite.property_sprname.Text.c_str());
274 Text("Sprite Palette: %s", custom_sprite.property_palette.Text.c_str());
275 Separator();
276 }
277}
278
279} // namespace editor
280} // namespace yaze
static GraphicsSheetManager & GetInstance()
Definition rom.h:271
auto rom()
Definition rom.h:383
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath.
ImVector< int > active_sprites_
void DrawAnimationFrames()
Draws the animation frames manager.
void DrawCurrentSheets()
Draws the current sheets.
void DrawSpriteCanvas()
Draws the sprite canvas.
absl::Status Update() override
Updates the sprite editor.
void DrawSpritesList()
Draws the sprites list.
std::vector< zsprite::ZSprite > custom_sprites_
#define ICON_MD_ADD
Definition icons.h:84
Namespace for the ZSprite format from Zarby's ZSpriteMaker.
Definition zsprite.h:17
Editors are the view controllers for the application.
constexpr ImGuiTabBarFlags kSpriteTabBarFlags
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
Definition input.cc:153
ImGuiID GetID(const std::string &id)
Definition input.cc:256
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:167
std::string HexByte(uint8_t byte, HexStringParams params)
Definition hex.cc:33
Main namespace for the application.
Definition controller.cc:18