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
25
26absl::Status SpriteEditor::Load() {
27 return absl::OkStatus();
28}
29
30absl::Status SpriteEditor::Update() {
31 if (rom()->is_loaded() && !sheets_loaded_) {
32 // Load the values for current_sheets_ array
33 sheets_loaded_ = true;
34 }
35
36 if (ImGui::BeginTabBar("##SpriteEditorTabs")) {
37 if (ImGui::BeginTabItem("Vanilla")) {
39 ImGui::EndTabItem();
40 }
41 if (ImGui::BeginTabItem("Custom")) {
43 ImGui::EndTabItem();
44 }
45 ImGui::EndTabBar();
46 }
47
48 return status_.ok() ? absl::OkStatus() : status_;
49}
50
52 if (ImGui::BeginTable("##SpriteCanvasTable", 3, ImGuiTableFlags_Resizable,
53 ImVec2(0, 0))) {
54 TableSetupColumn("Sprites List", ImGuiTableColumnFlags_WidthFixed, 256);
55 TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
56 ImGui::GetContentRegionAvail().x);
57 TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256);
58 TableHeadersRow();
59 TableNextRow();
60
61 TableNextColumn();
63
64 TableNextColumn();
65 static int next_tab_id = 0;
66
67 if (ImGui::BeginTabBar("SpriteTabBar", kSpriteTabBarFlags)) {
68 if (ImGui::TabItemButton(ICON_MD_ADD, kSpriteTabBarFlags)) {
69 if (std::find(active_sprites_.begin(), active_sprites_.end(),
71 // Room is already open
72 next_tab_id++;
73 }
74 active_sprites_.push_back(next_tab_id++); // Add new tab
75 }
76
77 // Submit our regular tabs
78 for (int n = 0; n < active_sprites_.Size;) {
79 bool open = true;
80
81 if (active_sprites_[n] > sizeof(zelda3::kSpriteDefaultNames) / 4) {
82 active_sprites_.erase(active_sprites_.Data + n);
83 continue;
84 }
85
86 if (ImGui::BeginTabItem(
87 zelda3::kSpriteDefaultNames[active_sprites_[n]].data(), &open,
88 ImGuiTabItemFlags_None)) {
90 ImGui::EndTabItem();
91 }
92
93 if (!open)
94 active_sprites_.erase(active_sprites_.Data + n);
95 else
96 n++;
97 }
98
99 ImGui::EndTabBar();
100 }
101
102 TableNextColumn();
103 if (sheets_loaded_) {
105 }
106 ImGui::EndTable();
107 }
108}
109
111 static bool flip_x = false;
112 static bool flip_y = false;
113 if (ImGui::BeginChild(gui::GetID("##SpriteCanvas"),
114 ImGui::GetContentRegionAvail(), true)) {
115 sprite_canvas_.DrawBackground();
116 sprite_canvas_.DrawContextMenu();
117 sprite_canvas_.DrawGrid();
118 sprite_canvas_.DrawOverlay();
119
120 // Draw a table with OAM configuration
121 // X, Y, Tile, Palette, Priority, Flip X, Flip Y
122 if (ImGui::BeginTable("##OAMTable", 7, ImGuiTableFlags_Resizable,
123 ImVec2(0, 0))) {
124 TableSetupColumn("X", ImGuiTableColumnFlags_WidthStretch);
125 TableSetupColumn("Y", ImGuiTableColumnFlags_WidthStretch);
126 TableSetupColumn("Tile", ImGuiTableColumnFlags_WidthStretch);
127 TableSetupColumn("Palette", ImGuiTableColumnFlags_WidthStretch);
128 TableSetupColumn("Priority", ImGuiTableColumnFlags_WidthStretch);
129 TableSetupColumn("Flip X", ImGuiTableColumnFlags_WidthStretch);
130 TableSetupColumn("Flip Y", ImGuiTableColumnFlags_WidthStretch);
131 TableHeadersRow();
132 TableNextRow();
133
134 TableNextColumn();
136
137 TableNextColumn();
139
140 TableNextColumn();
142
143 TableNextColumn();
144 gui::InputHexByte("", &oam_config_.palette);
145
146 TableNextColumn();
147 gui::InputHexByte("", &oam_config_.priority);
148
149 TableNextColumn();
150 if (ImGui::Checkbox("##XFlip", &flip_x)) {
151 oam_config_.flip_x = flip_x;
152 }
153
154 TableNextColumn();
155 if (ImGui::Checkbox("##YFlip", &flip_y)) {
156 oam_config_.flip_y = flip_y;
157 }
158
159 ImGui::EndTable();
160 }
161
163
165
166 ImGui::EndChild();
167 }
168}
169
171 if (ImGui::BeginChild(gui::GetID("sheet_label"),
172 ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
173 ImGuiWindowFlags_NoDecoration)) {
174 for (int i = 0; i < 8; i++) {
175 std::string sheet_label = absl::StrFormat("Sheet %d", i);
176 gui::InputHexByte(sheet_label.c_str(), &current_sheets_[i]);
177 if (i % 2 == 0) ImGui::SameLine();
178 }
179
180 graphics_sheet_canvas_.DrawBackground();
181 graphics_sheet_canvas_.DrawContextMenu();
182 graphics_sheet_canvas_.DrawTileSelector(32);
183 for (int i = 0; i < 8; i++) {
184 graphics_sheet_canvas_.DrawBitmap(
185 GraphicsSheetManager::GetInstance().gfx_sheets().at(
186 current_sheets_[i]),
187 1, (i * 0x40) + 1, 2);
188 }
189 graphics_sheet_canvas_.DrawGrid();
190 graphics_sheet_canvas_.DrawOverlay();
191 ImGui::EndChild();
192 }
193}
194
196 if (ImGui::BeginChild(gui::GetID("##SpritesList"),
197 ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
198 ImGuiWindowFlags_NoDecoration)) {
199 int i = 0;
200 for (const auto each_sprite_name : zelda3::kSpriteDefaultNames) {
201 rom()->resource_label()->SelectableLabelWithNameEdit(
202 current_sprite_id_ == i, "Sprite Names", util::HexByte(i),
203 zelda3::kSpriteDefaultNames[i].data());
204 if (ImGui::IsItemClicked()) {
206 if (!active_sprites_.contains(i)) {
207 active_sprites_.push_back(i);
208 }
209 }
210 i++;
211 }
212 ImGui::EndChild();
213 }
214}
215
217 if (ImGui::Button("Add Frame")) {
218 // Add a new frame
219 }
220 if (ImGui::Button("Remove Frame")) {
221 // Remove the current frame
222 }
223}
224
226 if (BeginTable("##CustomSpritesTable", 3,
227 ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders |
228 ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable,
229 ImVec2(0, 0))) {
230 TableSetupColumn("Metadata", ImGuiTableColumnFlags_WidthFixed, 256);
231 TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthFixed, 256);
232 TableSetupColumn("TIlesheets", ImGuiTableColumnFlags_WidthFixed, 256);
233
234 TableHeadersRow();
235 TableNextRow();
236 TableNextColumn();
237
238 Separator();
240
241 TableNextColumn();
243
244 TableNextColumn();
246
247 EndTable();
248 }
249}
250
252 // ZSprite Maker format open file dialog
253 if (ImGui::Button("Open ZSprite")) {
254 // Open ZSprite file
255 std::string file_path = core::FileDialogWrapper::ShowOpenFileDialog();
256 if (!file_path.empty()) {
258 status_ = zsprite.Load(file_path);
259 if (status_.ok()) {
260 custom_sprites_.push_back(zsprite);
261 }
262 }
263 }
264
265 for (const auto custom_sprite : custom_sprites_) {
266 Selectable("%s", custom_sprite.sprName.c_str());
267 if (ImGui::IsItemClicked()) {
268 current_sprite_id_ = 256 + stoi(custom_sprite.property_sprid.Text);
269 if (!active_sprites_.contains(current_sprite_id_)) {
271 }
272 }
273 Separator();
274 }
275
276 for (const auto custom_sprite : custom_sprites_) {
277 // Draw the custom sprite metadata
278 Text("Sprite ID: %s", custom_sprite.property_sprid.Text.c_str());
279 Text("Sprite Name: %s", custom_sprite.property_sprname.Text.c_str());
280 Text("Sprite Palette: %s", custom_sprite.property_palette.Text.c_str());
281 Separator();
282 }
283}
284
285} // namespace editor
286} // namespace yaze
static GraphicsSheetManager & GetInstance()
Definition rom.h:270
auto rom()
Definition rom.h:382
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
void DrawSpritesList()
Draws the sprites list.
std::vector< zsprite::ZSprite > custom_sprites_
absl::Status Load() override
#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:272
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