yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
palette_group_card.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_PALETTE_GROUP_CARD_H
2#define YAZE_APP_EDITOR_GRAPHICS_PALETTE_GROUP_CARD_H
3
4#include <functional>
5#include <memory>
6#include <string>
7#include <unordered_map>
8#include <unordered_set>
9#include <vector>
10
11#include "absl/status/status.h"
14#include "app/rom.h"
15#include "imgui/imgui.h"
16
17namespace yaze {
18namespace editor {
19
30
35 int palette_id; // Palette ID in ROM
36 std::string name; // Display name (e.g., "Light World Main")
37 std::string description; // Usage description
38 uint32_t rom_address; // Base ROM address for this palette
39 uint32_t vram_address; // VRAM address (for sprite palettes, 0 if N/A)
40 std::string usage_notes; // Additional usage information
41};
42
47 std::string group_name; // Internal group name
48 std::string display_name; // Display name for UI
49 std::vector<PaletteMetadata> palettes; // Metadata for each palette
50 int colors_per_palette; // Number of colors per palette (usually 8 or 16)
51 int colors_per_row; // Colors per row for grid layout
52};
53
68 public:
75 PaletteGroupCard(const std::string& group_name,
76 const std::string& display_name,
77 Rom* rom);
78
79 virtual ~PaletteGroupCard() = default;
80
81 // ========== Main Rendering ==========
82
86 void Draw();
87
88 // ========== Card Control ==========
89
90 void Show() { show_ = true; }
91 void Hide() { show_ = false; }
92 bool IsVisible() const { return show_; }
93 bool* visibility_flag() { return &show_; }
94
95 // ========== Palette Operations ==========
96
100 absl::Status SaveToRom();
101
105 void DiscardChanges();
106
110 void ResetPalette(int palette_index);
111
115 void ResetColor(int palette_index, int color_index);
116
120 void SetColor(int palette_index, int color_index, const gfx::SnesColor& new_color);
121
122 // ========== History Management ==========
123
124 void Undo();
125 void Redo();
126 bool CanUndo() const;
127 bool CanRedo() const;
128 void ClearHistory();
129
130 // ========== State Queries ==========
131
132 bool HasUnsavedChanges() const;
133 bool IsPaletteModified(int palette_index) const;
134 bool IsColorModified(int palette_index, int color_index) const;
135
137 void SetSelectedPaletteIndex(int index) { selected_palette_ = index; }
138
140 void SetSelectedColorIndex(int index) { selected_color_ = index; }
141
142 // ========== Export/Import ==========
143
144 std::string ExportToJson() const;
145 absl::Status ImportFromJson(const std::string& json);
146
147 std::string ExportToClipboard() const;
148 absl::Status ImportFromClipboard();
149
150 protected:
151 // ========== Pure Virtual Methods (Implemented by Derived Classes) ==========
152
157 virtual const gfx::PaletteGroup* GetPaletteGroup() const = 0;
158
162 virtual const PaletteGroupMetadata& GetMetadata() const = 0;
163
167 virtual void DrawPaletteGrid() = 0;
168
172 virtual int GetColorsPerRow() const = 0;
173
174 // ========== Optional Overrides ==========
175
179 virtual void DrawCustomToolbarButtons() {}
180
184 virtual void DrawCustomPanels() {}
185
186 // ========== Common UI Components ==========
187
191 void DrawToolbar();
192
196 void DrawPaletteSelector();
197
201 void DrawColorPicker();
202
206 void DrawColorInfo();
207
211 void DrawMetadataInfo();
212
217
218 // ========== Helper Methods ==========
219
224
228 gfx::SnesColor GetOriginalColor(int palette_index, int color_index) const;
229
233 absl::Status WriteColorToRom(int palette_index, int color_index,
234 const gfx::SnesColor& color);
235
239 void MarkModified(int palette_index, int color_index);
240
244 void ClearModified(int palette_index);
245
246 // ========== Member Variables ==========
247
248 std::string group_name_; // Internal name (e.g., "ow_main")
249 std::string display_name_; // Display name (e.g., "Overworld Main")
250 Rom* rom_; // ROM instance
251 bool show_ = false; // Visibility flag
252
253 // Selection state
254 int selected_palette_ = 0; // Currently selected palette index
255 int selected_color_ = -1; // Currently selected color (-1 = none)
256 gfx::SnesColor editing_color_; // Color being edited in picker
257
258 // Settings
259 bool auto_save_enabled_ = false; // Auto-save to ROM on every change
260 bool show_snes_format_ = true; // Show SNES $xxxx format in info
261 bool show_hex_format_ = true; // Show #xxxxxx hex in info
262};
263
264// ============================================================================
265// Concrete Palette Card Implementations
266// ============================================================================
267
277 public:
278 explicit OverworldMainPaletteCard(Rom* rom);
279 ~OverworldMainPaletteCard() override = default;
280
281 protected:
283 const gfx::PaletteGroup* GetPaletteGroup() const override;
284 const PaletteGroupMetadata& GetMetadata() const override { return metadata_; }
285 void DrawPaletteGrid() override;
286 int GetColorsPerRow() const override { return 8; }
287
288 private:
291};
292
299 public:
300 explicit OverworldAnimatedPaletteCard(Rom* rom);
301 ~OverworldAnimatedPaletteCard() override = default;
302
303 protected:
305 const gfx::PaletteGroup* GetPaletteGroup() const override;
306 const PaletteGroupMetadata& GetMetadata() const override { return metadata_; }
307 void DrawPaletteGrid() override;
308 int GetColorsPerRow() const override { return 8; }
309
310 private:
313};
314
321 public:
322 explicit DungeonMainPaletteCard(Rom* rom);
323 ~DungeonMainPaletteCard() override = default;
324
325 protected:
327 const gfx::PaletteGroup* GetPaletteGroup() const override;
328 const PaletteGroupMetadata& GetMetadata() const override { return metadata_; }
329 void DrawPaletteGrid() override;
330 int GetColorsPerRow() const override { return 16; }
331
332 private:
335};
336
346 public:
347 explicit SpritePaletteCard(Rom* rom);
348 ~SpritePaletteCard() override = default;
349
350 protected:
352 const gfx::PaletteGroup* GetPaletteGroup() const override;
353 const PaletteGroupMetadata& GetMetadata() const override { return metadata_; }
354 void DrawPaletteGrid() override;
355 int GetColorsPerRow() const override { return 16; }
356 void DrawCustomPanels() override; // Show VRAM info
357
358 private:
361};
362
370 public:
371 explicit SpritesAux1PaletteCard(Rom* rom);
372 ~SpritesAux1PaletteCard() override = default;
373
374 protected:
376 const gfx::PaletteGroup* GetPaletteGroup() const override;
377 const PaletteGroupMetadata& GetMetadata() const override { return metadata_; }
378 void DrawPaletteGrid() override;
379 int GetColorsPerRow() const override { return 8; }
380
381 private:
384};
385
393 public:
394 explicit SpritesAux2PaletteCard(Rom* rom);
395 ~SpritesAux2PaletteCard() override = default;
396
397 protected:
399 const gfx::PaletteGroup* GetPaletteGroup() const override;
400 const PaletteGroupMetadata& GetMetadata() const override { return metadata_; }
401 void DrawPaletteGrid() override;
402 int GetColorsPerRow() const override { return 8; }
403
404 private:
407};
408
416 public:
417 explicit SpritesAux3PaletteCard(Rom* rom);
418 ~SpritesAux3PaletteCard() override = default;
419
420 protected:
422 const gfx::PaletteGroup* GetPaletteGroup() const override;
423 const PaletteGroupMetadata& GetMetadata() const override { return metadata_; }
424 void DrawPaletteGrid() override;
425 int GetColorsPerRow() const override { return 8; }
426
427 private:
430};
431
438 public:
439 explicit EquipmentPaletteCard(Rom* rom);
440 ~EquipmentPaletteCard() override = default;
441
442 protected:
444 const gfx::PaletteGroup* GetPaletteGroup() const override;
445 const PaletteGroupMetadata& GetMetadata() const override { return metadata_; }
446 void DrawPaletteGrid() override;
447 int GetColorsPerRow() const override { return 8; }
448
449 private:
452};
453
454} // namespace editor
455} // namespace yaze
456
457#endif // YAZE_APP_EDITOR_GRAPHICS_PALETTE_GROUP_CARD_H
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:74
Dungeon Main palette group card.
void DrawPaletteGrid() override
Draw the palette grid specific to this palette type.
static PaletteGroupMetadata InitializeMetadata()
~DungeonMainPaletteCard() override=default
int GetColorsPerRow() const override
Get the number of colors per row for grid layout.
const PaletteGroupMetadata & GetMetadata() const override
Get metadata for this palette group.
gfx::PaletteGroup * GetPaletteGroup() override
Get the palette group for this card.
static const PaletteGroupMetadata metadata_
Equipment/Armor palette group card.
static const PaletteGroupMetadata metadata_
void DrawPaletteGrid() override
Draw the palette grid specific to this palette type.
const PaletteGroupMetadata & GetMetadata() const override
Get metadata for this palette group.
static PaletteGroupMetadata InitializeMetadata()
gfx::PaletteGroup * GetPaletteGroup() override
Get the palette group for this card.
int GetColorsPerRow() const override
Get the number of colors per row for grid layout.
~EquipmentPaletteCard() override=default
Overworld Animated palette group card.
int GetColorsPerRow() const override
Get the number of colors per row for grid layout.
const PaletteGroupMetadata & GetMetadata() const override
Get metadata for this palette group.
void DrawPaletteGrid() override
Draw the palette grid specific to this palette type.
gfx::PaletteGroup * GetPaletteGroup() override
Get the palette group for this card.
static PaletteGroupMetadata InitializeMetadata()
static const PaletteGroupMetadata metadata_
Overworld Main palette group card.
static PaletteGroupMetadata InitializeMetadata()
int GetColorsPerRow() const override
Get the number of colors per row for grid layout.
void DrawPaletteGrid() override
Draw the palette grid specific to this palette type.
const PaletteGroupMetadata & GetMetadata() const override
Get metadata for this palette group.
gfx::PaletteGroup * GetPaletteGroup() override
Get the palette group for this card.
~OverworldMainPaletteCard() override=default
static const PaletteGroupMetadata metadata_
Base class for palette group editing cards.
void DrawPaletteSelector()
Draw palette selector dropdown.
absl::Status SaveToRom()
Save all modified palettes to ROM.
gfx::SnesPalette * GetMutablePalette(int index)
Get mutable palette by index.
virtual gfx::PaletteGroup * GetPaletteGroup()=0
Get the palette group for this card.
void MarkModified(int palette_index, int color_index)
Mark palette as modified.
bool IsColorModified(int palette_index, int color_index) const
void DrawColorPicker()
Draw color picker for selected color.
virtual ~PaletteGroupCard()=default
virtual int GetColorsPerRow() const =0
Get the number of colors per row for grid layout.
void SetColor(int palette_index, int color_index, const gfx::SnesColor &new_color)
Set a color value (records change for undo)
void DrawBatchOperationsPopup()
Draw batch operations popup.
virtual void DrawCustomToolbarButtons()
Draw additional toolbar buttons (called after standard buttons)
void DrawToolbar()
Draw standard toolbar with save/discard/undo/redo.
virtual void DrawCustomPanels()
Draw additional panels (called after main content)
void ClearModified(int palette_index)
Clear modified flags for palette.
virtual void DrawPaletteGrid()=0
Draw the palette grid specific to this palette type.
virtual const PaletteGroupMetadata & GetMetadata() const =0
Get metadata for this palette group.
void ResetPalette(int palette_index)
Reset a specific palette to original ROM values.
gfx::SnesColor GetOriginalColor(int palette_index, int color_index) const
Get original color from ROM (for reset/comparison)
absl::Status WriteColorToRom(int palette_index, int color_index, const gfx::SnesColor &color)
Write a single color to ROM.
void ResetColor(int palette_index, int color_index)
Reset a specific color to original ROM value.
void DrawMetadataInfo()
Draw palette metadata info panel.
void DrawColorInfo()
Draw color info panel with RGB/SNES/Hex values.
bool IsPaletteModified(int palette_index) const
virtual const gfx::PaletteGroup * GetPaletteGroup() const =0
void DiscardChanges()
Discard all unsaved changes.
void Draw()
Draw the card's ImGui UI.
absl::Status ImportFromJson(const std::string &json)
Global Sprite palette group card.
static const PaletteGroupMetadata metadata_
gfx::PaletteGroup * GetPaletteGroup() override
Get the palette group for this card.
static PaletteGroupMetadata InitializeMetadata()
int GetColorsPerRow() const override
Get the number of colors per row for grid layout.
void DrawCustomPanels() override
Draw additional panels (called after main content)
void DrawPaletteGrid() override
Draw the palette grid specific to this palette type.
const PaletteGroupMetadata & GetMetadata() const override
Get metadata for this palette group.
~SpritePaletteCard() override=default
Sprites Aux1 palette group card.
void DrawPaletteGrid() override
Draw the palette grid specific to this palette type.
gfx::PaletteGroup * GetPaletteGroup() override
Get the palette group for this card.
static const PaletteGroupMetadata metadata_
static PaletteGroupMetadata InitializeMetadata()
int GetColorsPerRow() const override
Get the number of colors per row for grid layout.
~SpritesAux1PaletteCard() override=default
const PaletteGroupMetadata & GetMetadata() const override
Get metadata for this palette group.
Sprites Aux2 palette group card.
~SpritesAux2PaletteCard() override=default
void DrawPaletteGrid() override
Draw the palette grid specific to this palette type.
gfx::PaletteGroup * GetPaletteGroup() override
Get the palette group for this card.
const PaletteGroupMetadata & GetMetadata() const override
Get metadata for this palette group.
int GetColorsPerRow() const override
Get the number of colors per row for grid layout.
static PaletteGroupMetadata InitializeMetadata()
static const PaletteGroupMetadata metadata_
Sprites Aux3 palette group card.
~SpritesAux3PaletteCard() override=default
int GetColorsPerRow() const override
Get the number of colors per row for grid layout.
static PaletteGroupMetadata InitializeMetadata()
const PaletteGroupMetadata & GetMetadata() const override
Get metadata for this palette group.
void DrawPaletteGrid() override
Draw the palette grid specific to this palette type.
gfx::PaletteGroup * GetPaletteGroup() override
Get the palette group for this card.
static const PaletteGroupMetadata metadata_
SNES Color container.
Definition snes_color.h:109
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Main namespace for the application.
Definition controller.cc:20
Represents a single color change for undo/redo.
Metadata for an entire palette group.
std::vector< PaletteMetadata > palettes
Metadata for a single palette in a group.
Represents a group of palettes.