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/gfx/arena.h"
6#include "app/gui/icons.h"
7#include "app/gui/input.h"
9#include "util/hex.h"
10
11namespace yaze {
12namespace editor {
13
14using ImGui::BeginTable;
15using ImGui::Button;
16using ImGui::EndTable;
17using ImGui::Selectable;
18using ImGui::Separator;
19using ImGui::TableHeadersRow;
20using ImGui::TableNextColumn;
21using ImGui::TableNextRow;
22using ImGui::TableSetupColumn;
23using ImGui::Text;
24
26
27absl::Status SpriteEditor::Load() { return absl::OkStatus(); }
28
29absl::Status SpriteEditor::Update() {
30 if (rom()->is_loaded() && !sheets_loaded_) {
31 // Load the values for current_sheets_ array
32 sheets_loaded_ = true;
33 }
34
35 if (ImGui::BeginTabBar("##SpriteEditorTabs")) {
36 if (ImGui::BeginTabItem("Vanilla")) {
38 ImGui::EndTabItem();
39 }
40 if (ImGui::BeginTabItem("Custom")) {
42 ImGui::EndTabItem();
43 }
44 ImGui::EndTabBar();
45 }
46
47 return status_.ok() ? absl::OkStatus() : status_;
48}
49
51 if (ImGui::BeginTable("##SpriteCanvasTable", 3, ImGuiTableFlags_Resizable,
52 ImVec2(0, 0))) {
53 TableSetupColumn("Sprites List", ImGuiTableColumnFlags_WidthFixed, 256);
54 TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthStretch,
55 ImGui::GetContentRegionAvail().x);
56 TableSetupColumn("Tile Selector", ImGuiTableColumnFlags_WidthFixed, 256);
57 TableHeadersRow();
58 TableNextRow();
59
60 TableNextColumn();
62
63 TableNextColumn();
64 static int next_tab_id = 0;
65
66 if (ImGui::BeginTabBar("SpriteTabBar", kSpriteTabBarFlags)) {
67 if (ImGui::TabItemButton(ICON_MD_ADD, kSpriteTabBarFlags)) {
68 if (std::find(active_sprites_.begin(), active_sprites_.end(),
70 // Room is already open
71 next_tab_id++;
72 }
73 active_sprites_.push_back(next_tab_id++); // Add new tab
74 }
75
76 // Submit our regular tabs
77 for (int n = 0; n < active_sprites_.Size;) {
78 bool open = true;
79
80 if (active_sprites_[n] > sizeof(zelda3::kSpriteDefaultNames) / 4) {
81 active_sprites_.erase(active_sprites_.Data + n);
82 continue;
83 }
84
85 if (ImGui::BeginTabItem(
86 zelda3::kSpriteDefaultNames[active_sprites_[n]].data(), &open,
87 ImGuiTabItemFlags_None)) {
89 ImGui::EndTabItem();
90 }
91
92 if (!open)
93 active_sprites_.erase(active_sprites_.Data + n);
94 else
95 n++;
96 }
97
98 ImGui::EndTabBar();
99 }
100
101 TableNextColumn();
102 if (sheets_loaded_) {
104 }
105 ImGui::EndTable();
106 }
107}
108
110 static bool flip_x = false;
111 static bool flip_y = false;
112 if (ImGui::BeginChild(gui::GetID("##SpriteCanvas"),
113 ImGui::GetContentRegionAvail(), true)) {
114 sprite_canvas_.DrawBackground();
115 sprite_canvas_.DrawContextMenu();
116 sprite_canvas_.DrawGrid();
117 sprite_canvas_.DrawOverlay();
118
119 // Draw a table with OAM configuration
120 // X, Y, Tile, Palette, Priority, Flip X, Flip Y
121 if (ImGui::BeginTable("##OAMTable", 7, ImGuiTableFlags_Resizable,
122 ImVec2(0, 0))) {
123 TableSetupColumn("X", ImGuiTableColumnFlags_WidthStretch);
124 TableSetupColumn("Y", ImGuiTableColumnFlags_WidthStretch);
125 TableSetupColumn("Tile", ImGuiTableColumnFlags_WidthStretch);
126 TableSetupColumn("Palette", ImGuiTableColumnFlags_WidthStretch);
127 TableSetupColumn("Priority", ImGuiTableColumnFlags_WidthStretch);
128 TableSetupColumn("Flip X", ImGuiTableColumnFlags_WidthStretch);
129 TableSetupColumn("Flip Y", ImGuiTableColumnFlags_WidthStretch);
130 TableHeadersRow();
131 TableNextRow();
132
133 TableNextColumn();
135
136 TableNextColumn();
138
139 TableNextColumn();
141
142 TableNextColumn();
143 gui::InputHexByte("", &oam_config_.palette);
144
145 TableNextColumn();
146 gui::InputHexByte("", &oam_config_.priority);
147
148 TableNextColumn();
149 if (ImGui::Checkbox("##XFlip", &flip_x)) {
150 oam_config_.flip_x = flip_x;
151 }
152
153 TableNextColumn();
154 if (ImGui::Checkbox("##YFlip", &flip_y)) {
155 oam_config_.flip_y = flip_y;
156 }
157
158 ImGui::EndTable();
159 }
160
162
164
165 ImGui::EndChild();
166 }
167}
168
170 if (ImGui::BeginChild(gui::GetID("sheet_label"),
171 ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
172 ImGuiWindowFlags_NoDecoration)) {
173 for (int i = 0; i < 8; i++) {
174 std::string sheet_label = absl::StrFormat("Sheet %d", i);
175 gui::InputHexByte(sheet_label.c_str(), &current_sheets_[i]);
176 if (i % 2 == 0) ImGui::SameLine();
177 }
178
179 graphics_sheet_canvas_.DrawBackground();
180 graphics_sheet_canvas_.DrawContextMenu();
181 graphics_sheet_canvas_.DrawTileSelector(32);
182 for (int i = 0; i < 8; i++) {
183 graphics_sheet_canvas_.DrawBitmap(
184 gfx::Arena::Get().gfx_sheets().at(current_sheets_[i]), 1,
185 (i * 0x40) + 1, 2);
186 }
187 graphics_sheet_canvas_.DrawGrid();
188 graphics_sheet_canvas_.DrawOverlay();
189 }
190 ImGui::EndChild();
191}
192
194 if (ImGui::BeginChild(gui::GetID("##SpritesList"),
195 ImVec2(ImGui::GetContentRegionAvail().x, 0), true,
196 ImGuiWindowFlags_NoDecoration)) {
197 int i = 0;
198 for (const auto each_sprite_name : zelda3::kSpriteDefaultNames) {
200 current_sprite_id_ == i, "Sprite Names", util::HexByte(i),
201 zelda3::kSpriteDefaultNames[i].data());
202 if (ImGui::IsItemClicked()) {
204 if (!active_sprites_.contains(i)) {
205 active_sprites_.push_back(i);
206 }
207 }
208 i++;
209 }
210 ImGui::EndChild();
211 }
212}
213
215 if (ImGui::Button("Add Frame")) {
216 // Add a new frame
217 }
218 if (ImGui::Button("Remove Frame")) {
219 // Remove the current frame
220 }
221}
222
224 if (BeginTable("##CustomSpritesTable", 3,
225 ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders |
226 ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable,
227 ImVec2(0, 0))) {
228 TableSetupColumn("Metadata", ImGuiTableColumnFlags_WidthFixed, 256);
229 TableSetupColumn("Canvas", ImGuiTableColumnFlags_WidthFixed, 256);
230 TableSetupColumn("TIlesheets", ImGuiTableColumnFlags_WidthFixed, 256);
231
232 TableHeadersRow();
233 TableNextRow();
234 TableNextColumn();
235
236 Separator();
238
239 TableNextColumn();
241
242 TableNextColumn();
244
245 EndTable();
246 }
247}
248
250 // ZSprite Maker format open file dialog
251 if (ImGui::Button("Open ZSprite")) {
252 // Open ZSprite file
253 std::string file_path = core::FileDialogWrapper::ShowOpenFileDialog();
254 if (!file_path.empty()) {
256 status_ = zsprite.Load(file_path);
257 if (status_.ok()) {
258 custom_sprites_.push_back(zsprite);
259 }
260 }
261 }
262
263 for (const auto custom_sprite : custom_sprites_) {
264 Selectable("%s", custom_sprite.sprName.c_str());
265 if (ImGui::IsItemClicked()) {
266 current_sprite_id_ = 256 + stoi(custom_sprite.property_sprid.Text);
267 if (!active_sprites_.contains(current_sprite_id_)) {
269 }
270 }
271 Separator();
272 }
273
274 for (const auto custom_sprite : custom_sprites_) {
275 // Draw the custom sprite metadata
276 Text("Sprite ID: %s", custom_sprite.property_sprid.Text.c_str());
277 Text("Sprite Name: %s", custom_sprite.property_sprname.Text.c_str());
278 Text("Sprite Palette: %s", custom_sprite.property_palette.Text.c_str());
279 Separator();
280 }
281}
282
283} // namespace editor
284} // namespace yaze
ResourceLabelManager * resource_label()
Definition rom.h:194
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
static Arena & Get()
Definition arena.cc:10
#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:162
ImGuiID GetID(const std::string &id)
Definition input.cc:306
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:176
std::string HexByte(uint8_t byte, HexStringParams params)
Definition hex.cc:30
Main namespace for the application.
Definition controller.cc:18
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:146