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"
17#include "app/gfx/core/bitmap.h"
19#include "app/gui/core/icons.h"
21
22namespace yaze {
23class Rom;
24namespace zelda3 {
25struct GameData;
26} // namespace zelda3
27namespace project {
28struct YazeProject;
29} // namespace project
30
31namespace editor {
32
33class UndoManager;
34
42 public:
43 explicit SheetBrowserPanel(GraphicsEditorState* state) : state_(state) {}
44
45 // ==========================================================================
46 // WindowContent Identity
47 // ==========================================================================
48
49 std::string GetId() const override { return "graphics.sheet_browser_v2"; }
50 std::string GetDisplayName() const override { return "Sheet Browser"; }
51 std::string GetIcon() const override { return ICON_MD_VIEW_LIST; }
52 std::string GetEditorCategory() const override { return "Graphics"; }
53 int GetPriority() const override { return 10; }
54
55 // ==========================================================================
56 // WindowContent Lifecycle
57 // ==========================================================================
58
62 void Initialize();
63
67 void Draw(bool* p_open) override;
68
73 absl::Status Update();
74
79 void SetDataSources(
80 Rom* rom, zelda3::GameData* game_data,
81 std::function<const project::YazeProject*()> project_getter);
82
87 void RefreshInventory();
88
89 const std::optional<zelda3::GfxSheetInventory>& inventory() const {
90 return inventory_;
91 }
92
94 std::function<absl::Status(uint16_t sheet, const std::string& label)>;
96 std::function<absl::StatusOr<int>(const std::string& csv_text)>;
97
102 label_setter_ = std::move(setter);
103 label_importer_ = std::move(importer);
104 }
105
109 void SetUndoManager(UndoManager* undo_manager) {
110 undo_manager_ = undo_manager;
111 }
112
114 std::function<absl::StatusOr<std::vector<GraphicsSavePlanEntry>>()>;
120 save_planner_ = std::move(planner);
121 }
122
123 private:
127 void DrawSearchBar();
128
132 void DrawSheetGrid();
133
139 void DrawSheetThumbnail(int sheet_id, gfx::Bitmap& bitmap);
140
144 void DrawBatchOperations();
145
151
154
155 // Search/filter state
156 char search_buffer_[16] = {0};
157 int filter_min_ = 0;
158 int filter_max_ = 222;
160
161 // Grid layout
162 float thumbnail_scale_ = 2.0f;
163 int columns_ = 2;
164
165 // Inventory (free blocks, reserved, used by), built from the ROM buffer.
166 Rom* rom_ = nullptr;
168 std::function<const project::YazeProject*()> project_getter_;
169 std::optional<zelda3::GfxSheetInventory> inventory_;
170 std::string inventory_error_;
171 const Rom* inventory_rom_ = nullptr;
172 bool show_free_blocks_ = true;
173
174 // Project sheet labels.
175 std::string SheetLabel(uint16_t sheet) const;
176 void DrawSheetLabelEditor(uint16_t sheet_id);
180 std::string label_buffer_;
181 std::string label_status_;
182
183 // PNG export and import (sheet_png_transfer). Imports are previewed, then
184 // applied to the Arena as one undo step per sheet; saving the ROM writes
185 // them through GraphicsEditor::Save.
186 void DrawPngTransfer(uint16_t sheet_id);
187 absl::StatusOr<zelda3::SheetPalette> PngPalette(int sheet_id = -1);
188 void SetPngStatus(std::string message, bool is_error);
192 0; // 0 gray, 1 explicit left, 2 sprite, 3 loaded slot
193 int png_room_ = 0;
196 int png_first_block_ = 0; // 16x16 block a sheet import starts at
197 std::string png_path_; // typed PNG path; empty picks in a dialog
198 std::vector<SheetPngImportPreview> png_pending_;
199 std::string png_status_;
201
202 // Pending graphics save: the preflight for the dirty sheets, computed on
203 // request because it runs the writer on a copy of the ROM.
204 void DrawPendingSave();
205 std::string SheetUsageSummary(uint16_t sheet_id) const;
207 std::vector<GraphicsSavePlanEntry> save_plan_;
208 std::string save_plan_error_;
209 std::set<uint16_t> save_plan_sheets_; // the dirty set the plan describes
210};
211
212} // namespace editor
213} // namespace yaze
214
215#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:52
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...
CatalogTileBrowserState catalog_browser_
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:290