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"
13#include "app/gfx/core/bitmap.h"
16#include "rom/rom.h"
18
19namespace yaze {
20namespace editor {
21
22constexpr ImGuiTabItemFlags kSpriteTabFlags =
23 ImGuiTabItemFlags_Trailing | ImGuiTabItemFlags_NoTooltip;
24
25constexpr ImGuiTabBarFlags kSpriteTabBarFlags =
26 ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable |
27 ImGuiTabBarFlags_FittingPolicyResizeDown |
28 ImGuiTabBarFlags_TabListPopupButton;
29
30constexpr ImGuiTableFlags kSpriteTableFlags =
31 ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable |
32 ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersOuter |
33 ImGuiTableFlags_BordersV;
34
43class SpriteEditor : public Editor {
44 public:
45 explicit SpriteEditor(Rom* rom = nullptr) : rom_(rom) {
47 }
48
49 void Initialize() override;
50 absl::Status Load() override;
51 absl::Status Update() override;
52 absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
53 absl::Status Redo() override { return absl::UnimplementedError("Redo"); }
54 absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
55 absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
56 absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
57 absl::Status Find() override { return absl::UnimplementedError("Find"); }
58 absl::Status Save() override;
59
60 void set_rom(Rom* rom) { rom_ = rom; }
61 Rom* rom() const { return rom_; }
62
63 private:
64 // ============================================================
65 // Editor-Level Methods
66 // ============================================================
68
69 // ============================================================
70 // Vanilla Sprite Editor Methods
71 // ============================================================
73 void DrawSpritesList();
74 void DrawSpriteCanvas();
75 void DrawCurrentSheets();
76 void DrawToolset();
77
78 // ============================================================
79 // Custom ZSM Sprite Editor Methods
80 // ============================================================
81 void DrawCustomSprites();
84
85 // File operations
86 void CreateNewZSprite();
87 void LoadZsmFile(const std::string& path);
88 void SaveZsmFile(const std::string& path);
89 void SaveZsmFileAs();
91 const std::string& GetCurrentZsmPath() const;
92 void SetCurrentZsmPath(const std::string& path);
93
94 // Properties panel
97 void DrawStatProperties();
98
99 // Animation panel
100 void DrawAnimationPanel();
102 void DrawFrameEditor();
103 void UpdateAnimationPlayback(float delta_time);
104
105 // User routines panel
107
108 // Canvas rendering
109 void RenderZSpriteFrame(int frame_index);
110 void DrawZSpriteOnCanvas();
111
112 // Graphics pipeline
114 void LoadSpritePalettes();
116 void LoadSheetsForSprite(const std::array<uint8_t, 4>& sheets);
117
118 // ============================================================
119 // Vanilla Sprite State
120 // ============================================================
121 ImVector<int> active_sprites_;
123 uint8_t current_sheets_[8] = {0x00, 0x0A, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00};
124 bool sheets_loaded_ = false;
125
126 // OAM Configuration for vanilla sprites
127 struct OAMConfig {
128 uint16_t x = 0;
129 uint16_t y = 0;
130 uint8_t tile = 0;
131 uint8_t palette = 0;
132 uint8_t priority = 0;
133 bool flip_x = false;
134 bool flip_y = false;
135 };
140
141 // ============================================================
142 // Custom ZSM Sprite State
143 // ============================================================
144 std::vector<zsprite::ZSprite> custom_sprites_;
145 std::vector<std::string> custom_sprite_paths_;
147 bool zsm_dirty_ = false;
148
149 // Animation playback state
150 bool animation_playing_ = false;
153 float frame_timer_ = 0.0f;
154 float last_frame_time_ = 0.0f;
155
156 // UI state
159 bool show_tile_grid_ = true;
160
161 // Sprite preview bitmap (rendered from OAM tiles)
164
165 // ============================================================
166 // Graphics Pipeline State
167 // ============================================================
169 std::vector<uint8_t> sprite_gfx_buffer_; // 8BPP combined sheets buffer
170 gfx::PaletteGroup sprite_palettes_; // Loaded sprite palettes
171 bool gfx_buffer_loaded_ = false;
172
173 // ============================================================
174 // Canvas
175 // ============================================================
176 gui::Canvas sprite_canvas_{"SpriteCanvas", ImVec2(0x200, 0x200),
178
179 gui::Canvas graphics_sheet_canvas_{"GraphicsSheetCanvas",
180 ImVec2(0x80 * 2 + 2, 0x40 * 8 + 2),
182
183 // ============================================================
184 // Common State
185 // ============================================================
186 absl::Status status_;
188};
189
190} // namespace editor
191} // namespace yaze
192
193#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:236
EditorType type_
Definition editor.h:305
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
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
void SaveZsmFile(const std::string &path)
absl::Status Load() override
std::vector< std::string > custom_sprite_paths_
SpriteEditor(Rom *rom=nullptr)
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
Represents a group of palettes.
Complete OAM layout for a vanilla sprite.