yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
message_editor.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_MESSAGE_EDITOR_H
2#define YAZE_APP_EDITOR_MESSAGE_EDITOR_H
3
4#include <array>
5#include <cstdint>
6#include <optional>
7#include <string>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
12#include "app/editor/editor.h"
17#include "app/gfx/core/bitmap.h"
20#include "app/gui/core/style.h"
21#include "rom/rom.h"
22
23namespace yaze {
24namespace editor {
25
26class MessageEditorTestPeer;
27class MessageEditorSaveTestPeer;
28
29constexpr int kGfxFont = 0x70000; // 2bpp format
30constexpr int kCharactersWidth = 0x74ADF;
31constexpr int kNumMessages = 396;
32constexpr int kFontGfxMessageSize = 128;
33constexpr int kFontGfxMessageDepth =
34 8; // Fixed: Must be 8 for indexed palette mode
35constexpr int kFontGfx16Size = 172 * 4096;
36
37constexpr uint8_t kBlockTerminator = 0x80;
38constexpr uint8_t kMessageBankChangeId = 0x80;
39
40class MessageEditor : public Editor {
41 public:
42 explicit MessageEditor(Rom* rom = nullptr) : rom_(rom) {
44 }
45
46 explicit MessageEditor(Rom* rom, const EditorDependencies& deps)
48 dependencies_ = deps;
49 }
50
51 void Initialize() override;
52 absl::Status Load() override;
53 absl::Status Update() override;
55
56 void DrawMessageList();
57 void DrawCurrentMessage();
58 void DrawFontAtlas();
59 void DrawTextCommands();
62 void DrawDictionary();
63 void DrawMessagePreview();
64 void UpdateCurrentMessageFromText(const std::string& text);
65
66 // Jump/navigation helper used by panels (e.g. Story Event Graph).
67 // Accepts vanilla IDs (0..N) and expanded IDs (expanded_base_id..).
68 bool OpenMessageById(int display_id);
69
70 absl::Status Save() override;
71 absl::Status BeginSaveTransaction() override;
72 void RollbackSaveTransaction() override;
73 void CommitSaveTransaction() override;
74 absl::Status SaveExpandedMessages();
75 absl::Status LoadExpandedMessagesFromRom();
77
78 absl::Status Cut() override;
79 absl::Status Copy() override;
80 absl::Status Paste() override;
81 absl::Status Undo() override;
82 absl::Status Redo() override;
83 absl::Status Find() override;
84 void Delete();
85 void SelectAll();
86
87 void set_rom(Rom* rom) { rom_ = rom; }
88 Rom* rom() const { return rom_; }
89
90 private:
93
99
102 uint32_t start;
103 std::vector<uint8_t> bytes;
104
105 uint32_t end() const { return start + static_cast<uint32_t>(bytes.size()); }
106 };
107
108 struct SavePlan {
109 std::vector<PlannedWrite> writes;
111 bool saves_font_widths = false;
114 };
115
116 struct DirtyState {
117 bool font_widths = false;
118 bool vanilla_messages = false;
119 bool expanded_messages = false;
120 };
121
122 absl::StatusOr<SavePlan> BuildSavePlan(bool include_font_widths,
123 bool include_vanilla_messages,
124 bool include_expanded_messages) const;
125 absl::Status ValidateSavePlan(const SavePlan& plan) const;
126 absl::Status ApplySavePlan(const SavePlan& plan);
127 absl::Status SaveDirtyDomains(bool include_font_widths,
128 bool include_vanilla_messages,
129 bool include_expanded_messages);
130 void MarkDomainDirty(SaveDomain domain);
131 void RecordSavedDomains(const SavePlan& plan);
132 void ClearSavedDomains(const DirtyState& saved);
134
135 bool case_sensitive_ = false;
136 bool match_whole_word_ = false;
137 std::string search_text_ = "";
138 std::string replace_text_ = "";
139 std::string replace_status_ = "";
141
142 // Replace helpers
144 int ReplaceAllMatches();
145
146 std::array<uint8_t, 0x4000> raw_font_gfx_data_;
147 std::vector<std::string> parsed_messages_;
148 std::vector<MessageData> list_of_texts_;
149 std::vector<MessageData> expanded_messages_;
150
153
157
158 gui::Canvas font_gfx_canvas_{"##FontGfxCanvas", ImVec2(256, 256)};
160 ImVec2(172 * 2, 4096)};
173
174 // Undo/Redo - delegates to UndoManager (inherited from Editor)
175 std::optional<MessageSnapshot> pending_undo_before_;
176 void PushUndoSnapshot();
177 void FinalizePendingUndo();
178 void ApplySnapshot(const MessageSnapshot& snapshot);
179
180 // Panel visibility states
181 bool show_message_list_ = false;
183 bool show_font_atlas_ = false;
184 bool show_dictionary_ = false;
185
186 void ResolveFontPalette();
188 void LoadFontGraphics();
189 void RefreshFontAtlasBitmap(const std::vector<uint8_t>& font_data);
190 void ApplyFontPalette();
192 void ImportMessageBundleFromFile(const std::string& path);
194
198 std::vector<std::string> current_parse_errors_;
199 std::vector<std::string> current_parse_warnings_;
200};
201
202} // namespace editor
203} // namespace yaze
204
205#endif // YAZE_APP_EDITOR_MESSAGE_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:245
zelda3::GameData * game_data() const
Definition editor.h:320
EditorDependencies dependencies_
Definition editor.h:333
EditorType type_
Definition editor.h:332
std::vector< std::string > parsed_messages_
absl::Status Copy() override
void CommitSaveTransaction() override
std::vector< MessageData > expanded_messages_
absl::Status Find() override
void RollbackSaveTransaction() override
absl::Status Update() override
void ClearSavedDomains(const DirtyState &saved)
absl::Status LoadExpandedMessagesFromRom()
void RecordSavedDomains(const SavePlan &plan)
void UpdateCurrentMessageFromText(const std::string &text)
absl::Status Paste() override
void ApplySnapshot(const MessageSnapshot &snapshot)
absl::StatusOr< SavePlan > BuildSavePlan(bool include_font_widths, bool include_vanilla_messages, bool include_expanded_messages) const
std::vector< int > transaction_expanded_address_snapshot_
void MarkDomainDirty(SaveDomain domain)
void RefreshFontAtlasBitmap(const std::vector< uint8_t > &font_data)
std::vector< std::string > current_parse_errors_
absl::Status Undo() override
absl::Status Load() override
friend class MessageEditorSaveTestPeer
std::vector< std::string > current_parse_warnings_
std::array< uint8_t, 0x4000 > raw_font_gfx_data_
gfx::SnesPalette BuildFallbackFontPalette() const
MessageEditor(Rom *rom=nullptr)
absl::Status SaveDirtyDomains(bool include_font_widths, bool include_vanilla_messages, bool include_expanded_messages)
absl::Status Cut() override
MessageEditor(Rom *rom, const EditorDependencies &deps)
std::optional< MessageSnapshot > pending_undo_before_
absl::Status BeginSaveTransaction() override
std::vector< MessageData > list_of_texts_
bool OpenMessageById(int display_id)
gfx::SnesPalette font_preview_colors_
absl::Status Redo() override
void ImportMessageBundleFromFile(const std::string &path)
absl::Status ValidateSavePlan(const SavePlan &plan) const
absl::Status ApplySavePlan(const SavePlan &plan)
absl::Status Save() override
void SetGameData(zelda3::GameData *game_data) override
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:64
constexpr int kCharactersWidth
constexpr int kFontGfx16Size
constexpr uint8_t kBlockTerminator
constexpr int kGfxFont
constexpr int kFontGfxMessageSize
constexpr int kFontGfxMessageDepth
constexpr uint8_t kMessageBankChangeId
constexpr int kNumMessages
Unified dependency container for all editor types.
Definition editor.h:169
std::vector< PlannedWrite > writes