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();
90
91 // Properties panel
94 void DrawStatProperties();
95
96 // Animation panel
97 void DrawAnimationPanel();
99 void DrawFrameEditor();
100 void UpdateAnimationPlayback(float delta_time);
101
102 // User routines panel
104
105 // Canvas rendering
106 void RenderZSpriteFrame(int frame_index);
107 void DrawZSpriteOnCanvas();
108
109 // Graphics pipeline
111 void LoadSpritePalettes();
113 void LoadSheetsForSprite(const std::array<uint8_t, 4>& sheets);
114
115 // ============================================================
116 // Vanilla Sprite State
117 // ============================================================
118 ImVector<int> active_sprites_;
120 uint8_t current_sheets_[8] = {0x00, 0x0A, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00};
121 bool sheets_loaded_ = false;
122
123 // OAM Configuration for vanilla sprites
124 struct OAMConfig {
125 uint16_t x = 0;
126 uint16_t y = 0;
127 uint8_t tile = 0;
128 uint8_t palette = 0;
129 uint8_t priority = 0;
130 bool flip_x = false;
131 bool flip_y = false;
132 };
137
138 // ============================================================
139 // Custom ZSM Sprite State
140 // ============================================================
141 std::vector<zsprite::ZSprite> custom_sprites_;
143 std::string current_zsm_path_;
144 bool zsm_dirty_ = false;
145
146 // Animation playback state
147 bool animation_playing_ = false;
150 float frame_timer_ = 0.0f;
151 float last_frame_time_ = 0.0f;
152
153 // UI state
156 bool show_tile_grid_ = true;
157
158 // Sprite preview bitmap (rendered from OAM tiles)
161
162 // ============================================================
163 // Graphics Pipeline State
164 // ============================================================
166 std::vector<uint8_t> sprite_gfx_buffer_; // 8BPP combined sheets buffer
167 gfx::PaletteGroup sprite_palettes_; // Loaded sprite palettes
168 bool gfx_buffer_loaded_ = false;
169
170 // ============================================================
171 // Canvas
172 // ============================================================
173 gui::Canvas sprite_canvas_{"SpriteCanvas", ImVec2(0x200, 0x200),
175
176 gui::Canvas graphics_sheet_canvas_{"GraphicsSheetCanvas",
177 ImVec2(0x80 * 2 + 2, 0x40 * 8 + 2),
179
180 // ============================================================
181 // Common State
182 // ============================================================
183 absl::Status status_;
185};
186
187} // namespace editor
188} // namespace yaze
189
190#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:24
Interface for editor classes.
Definition editor.h:179
EditorType type_
Definition editor.h:236
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)
std::vector< zsprite::ZSprite > custom_sprites_
std::vector< uint8_t > sprite_gfx_buffer_
absl::Status Copy() override
absl::Status Save() override
void SaveZsmFile(const std::string &path)
absl::Status Load() override
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.