yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
sheet_browser_panel.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_SHEET_BROWSER_PANEL_H
2#define YAZE_APP_EDITOR_GRAPHICS_SHEET_BROWSER_PANEL_H
3
4#include <functional>
5#include <optional>
6#include <set>
7#include <string>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
16#include "app/gfx/core/bitmap.h"
18#include "app/gui/core/icons.h"
20
21namespace yaze {
22class Rom;
23namespace zelda3 {
24struct GameData;
25} // namespace zelda3
26namespace project {
27struct YazeProject;
28} // namespace project
29
30namespace editor {
31
32class UndoManager;
33
41 public:
42 explicit SheetBrowserPanel(GraphicsEditorState* state) : state_(state) {}
43
44 // ==========================================================================
45 // WindowContent Identity
46 // ==========================================================================
47
48 std::string GetId() const override { return "graphics.sheet_browser_v2"; }
49 std::string GetDisplayName() const override { return "Sheet Browser"; }
50 std::string GetIcon() const override { return ICON_MD_VIEW_LIST; }
51 std::string GetEditorCategory() const override { return "Graphics"; }
52 int GetPriority() const override { return 10; }
53
54 // ==========================================================================
55 // WindowContent Lifecycle
56 // ==========================================================================
57
61 void Initialize();
62
66 void Draw(bool* p_open) override;
67
72 absl::Status Update();
73
78 void SetDataSources(
79 Rom* rom, zelda3::GameData* game_data,
80 std::function<const project::YazeProject*()> project_getter);
81
86 void RefreshInventory();
87
88 const std::optional<zelda3::GfxSheetInventory>& inventory() const {
89 return inventory_;
90 }
91
93 std::function<absl::Status(uint16_t sheet, const std::string& label)>;
95 std::function<absl::StatusOr<int>(const std::string& csv_text)>;
96
101 label_setter_ = std::move(setter);
102 label_importer_ = std::move(importer);
103 }
104
108 void SetUndoManager(UndoManager* undo_manager) {
109 undo_manager_ = undo_manager;
110 }
111
113 std::function<absl::StatusOr<std::vector<GraphicsSavePlanEntry>>()>;
119 save_planner_ = std::move(planner);
120 }
121
122 private:
126 void DrawSearchBar();
127
131 void DrawSheetGrid();
132
138 void DrawSheetThumbnail(int sheet_id, gfx::Bitmap& bitmap);
139
143 void DrawBatchOperations();
144
150
153
154 // Search/filter state
155 char search_buffer_[16] = {0};
156 int filter_min_ = 0;
157 int filter_max_ = 222;
159
160 // Grid layout
161 float thumbnail_scale_ = 2.0f;
162 int columns_ = 2;
163
164 // Inventory (free blocks, reserved, used by), built from the ROM buffer.
165 Rom* rom_ = nullptr;
167 std::function<const project::YazeProject*()> project_getter_;
168 std::optional<zelda3::GfxSheetInventory> inventory_;
169 std::string inventory_error_;
170 const Rom* inventory_rom_ = nullptr;
171 bool show_free_blocks_ = true;
172
173 // Project sheet labels.
174 std::string SheetLabel(uint16_t sheet) const;
175 void DrawSheetLabelEditor(uint16_t sheet_id);
179 std::string label_buffer_;
180 std::string label_status_;
181
182 // PNG export and import (sheet_png_transfer). Imports are previewed, then
183 // applied to the Arena as one undo step per sheet; saving the ROM writes
184 // them through GraphicsEditor::Save.
185 void DrawPngTransfer(uint16_t sheet_id);
186 absl::StatusOr<zelda3::SheetPalette> PngPalette(int sheet_id = -1);
187 void SetPngStatus(std::string message, bool is_error);
190 0; // 0 gray, 1 explicit left, 2 sprite, 3 loaded slot
191 int png_room_ = 0;
194 int png_first_block_ = 0; // 16x16 block a sheet import starts at
195 std::string png_path_; // typed PNG path; empty picks in a dialog
196 std::vector<SheetPngImportPreview> png_pending_;
197 std::string png_status_;
199
200 // Pending graphics save: the preflight for the dirty sheets, computed on
201 // request because it runs the writer on a copy of the ROM.
202 void DrawPendingSave();
203 std::string SheetUsageSummary(uint16_t sheet_id) const;
205 std::vector<GraphicsSavePlanEntry> save_plan_;
206 std::string save_plan_error_;
207 std::set<uint16_t> save_plan_sheets_; // the dirty set the plan describes
208};
209
210} // namespace editor
211} // namespace yaze
212
213#endif // YAZE_APP_EDITOR_GRAPHICS_SHEET_BROWSER_PANEL_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:49
Shared state between GraphicsEditor panel components.
WindowContent for browsing and selecting graphics sheets.
void DrawBatchOperations()
Draw batch operation buttons.
int GetPriority() const override
Get display priority for menu ordering.
absl::StatusOr< zelda3::SheetPalette > PngPalette(int sheet_id=-1)
std::function< const project::YazeProject *()> project_getter_
std::string GetIcon() const override
Material Design icon for this panel.
void Draw(bool *p_open) override
Draw the sheet browser UI.
const std::optional< zelda3::GfxSheetInventory > & inventory() const
void DrawPngTransfer(uint16_t sheet_id)
void SetLabelCallbacks(LabelSetter setter, LabelImporter importer)
Project-label writers. Unset callbacks disable label editing.
std::string GetId() const override
Unique identifier for this panel.
std::string GetEditorCategory() const override
Editor category this panel belongs to.
std::optional< zelda3::GfxSheetInventory > inventory_
std::string SheetUsageSummary(uint16_t sheet_id) const
void SetUndoManager(UndoManager *undo_manager)
Where PNG imports push their undo steps. Unset means no undo.
std::function< absl::StatusOr< int >(const std::string &csv_text)> LabelImporter
void SetDataSources(Rom *rom, zelda3::GameData *game_data, std::function< const project::YazeProject *()> project_getter)
Where free-block and "used by" data come from. The project getter may return null (no project open).
void RefreshInventory()
Rebuild the sheet inventory from the ROM buffer. Runs lazily on the first draw and when the ROM chang...
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
void DrawSheetLabelEditor(uint16_t sheet_id)
std::function< absl::StatusOr< std::vector< GraphicsSavePlanEntry > >()> SavePlanner
SheetBrowserPanel(GraphicsEditorState *state)
void DrawSelectedSheetInfo()
Storage, reserved state, free 16x16 blocks and "used by" for the current sheet.
void SetPngStatus(std::string message, bool is_error)
void DrawSearchBar()
Draw the search/filter bar.
void Initialize()
Initialize the panel.
void DrawSheetThumbnail(int sheet_id, gfx::Bitmap &bitmap)
Draw a single sheet thumbnail.
std::vector< GraphicsSavePlanEntry > save_plan_
void SetSavePlanner(SavePlanner planner)
Source of the "Pending graphics save" preflight list (GraphicsEditor::PlanGraphicsSave)....
std::vector< SheetPngImportPreview > png_pending_
std::function< absl::Status(uint16_t sheet, const std::string &label)> LabelSetter
std::string SheetLabel(uint16_t sheet) const
void DrawSheetGrid()
Draw the sheet grid view.
absl::Status Update()
Legacy Update method for backward compatibility.
Manages undo/redo stacks for a single editor.
Base interface for all logical window content components.
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:70
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:64
Which graphics sheets exist, which tables use them, and which 16x16 blocks are free.
#define ICON_MD_VIEW_LIST
Definition icons.h:2092
PNG export and import for the Graphics editor.
Modern project structure with comprehensive settings consolidation.
Definition project.h:287