yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sprite_editor.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SPRITE_EDITOR_H
2#define YAZE_APP_EDITOR_SPRITE_EDITOR_H
3
4#include <cstdint>
5#include <string>
6#include <vector>
7
8#include "absl/status/status.h"
9#include "app/editor/editor.h"
14#include "app/gfx/core/bitmap.h"
17#include "rom/rom.h"
19
20namespace yaze {
21namespace editor {
22
23constexpr ImGuiTabItemFlags kSpriteTabFlags =
24 ImGuiTabItemFlags_Trailing | ImGuiTabItemFlags_NoTooltip;
25
26constexpr ImGuiTabBarFlags kSpriteTabBarFlags =
27 ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable |
28 ImGuiTabBarFlags_FittingPolicyResizeDown |
29 ImGuiTabBarFlags_TabListPopupButton;
30
31constexpr ImGuiTableFlags kSpriteTableFlags =
32 ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable |
33 ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersOuter |
34 ImGuiTableFlags_BordersV;
35
44class SpriteEditor : public Editor {
45 public:
46 explicit SpriteEditor(Rom* rom = nullptr) : rom_(rom) {
48 }
49
50 void Initialize() override;
51 absl::Status Load() override;
52 absl::Status Update() override;
53 absl::Status Undo() override { return undo_manager_.Undo(); }
54 absl::Status Redo() override { return undo_manager_.Redo(); }
55 absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
56 absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
57 absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
58 absl::Status Find() override { return absl::UnimplementedError("Find"); }
59 absl::Status Save() override;
60
61 void set_rom(Rom* rom) { rom_ = rom; }
62 Rom* rom() const { return rom_; }
63
64 private:
65 // ============================================================
66 // Editor-Level Methods
67 // ============================================================
69
70 // ============================================================
71 // Vanilla Sprite Editor Methods
72 // ============================================================
74 void DrawSpritesList();
75 void DrawSpriteCanvas();
76 void DrawCurrentSheets();
77 void DrawToolset();
78
79 // ============================================================
80 // Custom ZSM Sprite Editor Methods
81 // ============================================================
82 void DrawCustomSprites();
85
86 // File operations
87 void CreateNewZSprite();
88 void LoadZsmFile(const std::string& path);
89 void SaveZsmFile(const std::string& path);
90 void SaveZsmFileAs();
92 const std::string& GetCurrentZsmPath() const;
93 void SetCurrentZsmPath(const std::string& path);
94
95 // Properties panel
98 void DrawStatProperties();
99
100 // Animation panel
101 void DrawAnimationPanel();
103 void DrawFrameEditor();
104 void UpdateAnimationPlayback(float delta_time);
105
106 // User routines panel
108
109 // Canvas rendering
110 void RenderZSpriteFrame(int frame_index);
111 void DrawZSpriteOnCanvas();
112
113 // Graphics pipeline
115 void LoadSpritePalettes();
117 void LoadSheetsForSprite(const std::array<uint8_t, 4>& sheets);
118
119 // ============================================================
120 // Undo/Redo Helpers
121 // ============================================================
123 void RestoreFromSnapshot(const SpriteSnapshot& snapshot);
126 void MarkSpriteMutated();
127
128 // ============================================================
129 // Vanilla Sprite State
130 // ============================================================
131 ImVector<int> active_sprites_;
133 uint8_t current_sheets_[8] = {0x00, 0x0A, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00};
134 bool sheets_loaded_ = false;
135
136 // OAM Configuration for vanilla sprites
137 struct OAMConfig {
138 uint16_t x = 0;
139 uint16_t y = 0;
140 uint8_t tile = 0;
141 uint8_t palette = 0;
142 uint8_t priority = 0;
143 bool flip_x = false;
144 bool flip_y = false;
145 };
150
151 // ============================================================
152 // Custom ZSM Sprite State
153 // ============================================================
154 std::vector<zsprite::ZSprite> custom_sprites_;
155 std::vector<std::string> custom_sprite_paths_;
157 bool zsm_dirty_ = false;
158
159 // Animation playback state
160 bool animation_playing_ = false;
163 float frame_timer_ = 0.0f;
164 float last_frame_time_ = 0.0f;
165
166 // UI state
169 bool show_tile_grid_ = true;
170
171 // Sprite preview bitmap (rendered from OAM tiles)
174
175 // ============================================================
176 // Graphics Pipeline State
177 // ============================================================
179 std::vector<uint8_t> sprite_gfx_buffer_; // 8BPP combined sheets buffer
180 gfx::PaletteGroup sprite_palettes_; // Loaded sprite palettes
181 bool gfx_buffer_loaded_ = false;
182
183 // ============================================================
184 // Canvas
185 // ============================================================
186 gui::Canvas sprite_canvas_{"SpriteCanvas", ImVec2(0x200, 0x200),
188
189 gui::Canvas graphics_sheet_canvas_{"GraphicsSheetCanvas",
190 ImVec2(0x80 * 2 + 2, 0x40 * 8 + 2),
192
193 // ============================================================
194 // Undo State
195 // ============================================================
199
200 // ============================================================
201 // Common State
202 // ============================================================
203 absl::Status status_;
205};
206
207} // namespace editor
208} // namespace yaze
209
210#endif // YAZE_APP_EDITOR_SPRITE_EDITOR_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
Interface for editor classes.
Definition editor.h:240
UndoManager undo_manager_
Definition editor.h:317
EditorType type_
Definition editor.h:315
Draws sprite OAM tiles to bitmaps for preview rendering.
Allows the user to edit sprites.
ImVector< int > active_sprites_
absl::Status Find() override
void UpdateAnimationPlayback(float delta_time)
void RenderZSpriteFrame(int frame_index)
void LoadSheetsForSprite(const std::array< uint8_t, 4 > &sheets)
absl::Status Paste() override
absl::Status Update() override
gfx::PaletteGroup sprite_palettes_
void LoadZsmFile(const std::string &path)
absl::Status Redo() override
absl::Status Cut() override
absl::Status Undo() override
void RenderVanillaSprite(const zelda3::SpriteOamLayout &layout)
const std::string & GetCurrentZsmPath() const
void RestoreFromSnapshot(const SpriteSnapshot &snapshot)
std::vector< zsprite::ZSprite > custom_sprites_
std::vector< uint8_t > sprite_gfx_buffer_
void SetCurrentZsmPath(const std::string &path)
absl::Status Copy() override
absl::Status Save() override
SpriteSnapshot undo_before_snapshot_
void SaveZsmFile(const std::string &path)
SpriteSnapshot CaptureCurrentSpriteSnapshot() const
absl::Status Load() override
std::vector< std::string > custom_sprite_paths_
SpriteEditor(Rom *rom=nullptr)
absl::Status Redo()
Redo the top action. Returns error if stack is empty.
absl::Status Undo()
Undo the top action. Returns error if stack is empty.
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:150
constexpr ImGuiTableFlags kSpriteTableFlags
constexpr ImGuiTabItemFlags kSpriteTabFlags
constexpr ImGuiTabBarFlags kSpriteTabBarFlags
Snapshot of a custom ZSprite's editable state for undo/redo.
Represents a group of palettes.
Complete OAM layout for a vanilla sprite.