yaze 0.2.0
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
9namespace yaze {
10namespace app {
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)) {
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();
139
140 TableNextColumn();
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
177 for (int i = 0; i < 8; i++) {
179 rom()->gfx_sheets().at(current_sheets_[i]), 1, (i * 0x40) + 1, 2);
180 }
183 ImGui::EndChild();
184 }
185}
186
188 if (ImGui::BeginChild(gui::GetID("##SpritesList"),
189 ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
190 ImGuiWindowFlags_NoDecoration)) {
191 int i = 0;
192 for (const auto each_sprite_name : zelda3::kSpriteDefaultNames) {
193 rom()->resource_label()->SelectableLabelWithNameEdit(
194 current_sprite_id_ == i, "Sprite Names", core::UppercaseHexByte(i),
195 zelda3::kSpriteDefaultNames[i].data());
196 if (ImGui::IsItemClicked()) {
198 if (!active_sprites_.contains(i)) {
199 active_sprites_.push_back(i);
200 }
201 }
202 i++;
203 }
204 ImGui::EndChild();
205 }
206}
207
209 if (ImGui::Button("Add Frame")) {
210 // Add a new frame
211 }
212 if (ImGui::Button("Remove Frame")) {
213 // Remove the current frame
214 }
215}
216
218 if (BeginTable("##CustomSpritesTable", 3,
219 ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders |
220 ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable,
221 ImVec2(0, 0))) {
222 TableSetupColumn("Metadata", ImGuiTableColumnFlags_WidthFixed, 256);
223 TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthFixed, 256);
224 TableSetupColumn("TIlesheets", ImGuiTableColumnFlags_WidthFixed, 256);
225
226 TableHeadersRow();
227 TableNextRow();
228 TableNextColumn();
229
230 Separator();
232
233 TableNextColumn();
235
236 TableNextColumn();
238
239 EndTable();
240 }
241}
242
244 // ZSprite Maker format open file dialog
245 if (ImGui::Button("Open ZSprite")) {
246 // Open ZSprite file
247 std::string file_path = core::FileDialogWrapper::ShowOpenFileDialog();
248 if (!file_path.empty()) {
249 zsprite::ZSprite zsprite;
250 status_ = zsprite.Load(file_path);
251 if (status_.ok()) {
252 custom_sprites_.push_back(zsprite);
253 }
254 }
255 }
256
257 for (const auto custom_sprite : custom_sprites_) {
258 Selectable("%s", custom_sprite.sprName.c_str());
259 if (ImGui::IsItemClicked()) {
260 current_sprite_id_ = 256 + stoi(custom_sprite.property_sprid.Text);
261 if (!active_sprites_.contains(current_sprite_id_)) {
263 }
264 }
265 Separator();
266 }
267
268 for (const auto custom_sprite : custom_sprites_) {
269 // Draw the custom sprite metadata
270 Text("Sprite ID: %s", custom_sprite.property_sprid.Text.c_str());
271 Text("Sprite Name: %s", custom_sprite.property_sprname.Text.c_str());
272 Text("Sprite Palette: %s", custom_sprite.property_palette.Text.c_str());
273 Separator();
274 }
275}
276
277} // namespace editor
278} // namespace app
279} // namespace yaze
static std::string ShowOpenFileDialog()
void DrawSpritesList()
Draws the sprites list.
void DrawAnimationFrames()
Draws the animation frames manager.
void DrawSpriteCanvas()
Draws the sprite canvas.
std::vector< zsprite::ZSprite > custom_sprites_
void DrawCurrentSheets()
Draws the current sheets.
absl::Status Update() override
Updates the sprite editor.
bool DrawTileSelector(int size)
Definition canvas.cc:343
void DrawBackground(ImVec2 canvas_size=ImVec2(0, 0), bool drag=false)
Definition canvas.cc:69
void DrawGrid(float grid_step=64.0f, int tile_id_offset=8)
Definition canvas.cc:689
void DrawBitmap(const Bitmap &bitmap, int border_offset=0, bool ready=true)
Definition canvas.cc:464
void DrawContextMenu(gfx::Bitmap *bitmap=nullptr)
Definition canvas.cc:104
#define ICON_MD_ADD
Definition icons.h:84
std::string UppercaseHexByte(uint8_t byte, bool leading)
Definition labeling.cc:21
constexpr ImGuiTabBarFlags kSpriteTabBarFlags
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:176
ImGuiID GetID(const std::string &id)
Definition input.cc:251
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
Definition input.cc:162
Definition common.cc:21
absl::Status Load(const std::string &filename)
Definition zsprite.h:77