yaze 0.2.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 <string>
6#include <vector>
7
8#include "absl/status/status.h"
9#include "app/editor/editor.h"
11#include "app/gfx/bitmap.h"
12#include "app/gui/canvas.h"
13#include "app/rom.h"
14
15namespace yaze {
16namespace editor {
17
18constexpr int kGfxFont = 0x70000; // 2bpp format
19constexpr int kTextData2 = 0x75F40;
20constexpr int kTextData2End = 0x773FF;
21constexpr int kCharactersWidth = 0x74ADF;
22constexpr int kNumMessages = 396;
23constexpr int kCurrentMessageWidth = 172;
24constexpr int kCurrentMessageHeight = 4096;
25constexpr int kFontGfxMessageSize = 128;
26constexpr int kFontGfxMessageDepth = 8;
27constexpr int kFontGfx16Size = 172 * 4096;
28
29constexpr uint8_t kWidthArraySize = 100;
30constexpr uint8_t kBlockTerminator = 0x80;
31constexpr uint8_t kMessageBankChangeId = 0x80;
32
33static TextElement DictionaryElement =
34 TextElement(0x80, DICTIONARYTOKEN, true, "Dictionary");
35
36class MessageEditor : public Editor, public SharedRom {
37 public:
39
40 void Initialize() override;
41 absl::Status Load() override;
42 absl::Status Update() override;
43 void DrawMessageList();
44 void DrawCurrentMessage();
45 void DrawTextCommands();
46 void DrawDictionary();
47
48 void ReadAllTextDataV2();
49 [[deprecated]] void ReadAllTextData();
50
51 absl::Status Cut() override;
52 absl::Status Copy() override;
53 absl::Status Paste() override;
54 absl::Status Undo() override;
55 absl::Status Redo() override {
56 return absl::UnimplementedError("Redo not implemented");
57 }
58 absl::Status Find() override {
59 return absl::UnimplementedError("Find not implemented");
60 }
61 absl::Status Save() override;
62 void Delete();
63 void SelectAll();
64
66 void DrawTileToPreview(int x, int y, int srcx, int srcy, int pal,
67 int sizex = 1, int sizey = 1);
68 void DrawCharacterToPreview(char c);
69 void DrawCharacterToPreview(const std::vector<uint8_t>& text);
70
71 void DrawStringToPreview(std::string str);
72 void DrawMessagePreview();
73 std::string DisplayTextOverflowError(int pos, bool bank);
74
75 private:
76 bool skip_next = false;
77 bool data_loaded_ = false;
78
79 int text_line_ = 0;
81 int shown_lines_ = 0;
82
83 std::string search_text_ = "";
84
85 std::array<uint8_t, kWidthArraySize> width_array = {0};
86 std::vector<uint8_t> font_gfx16_data_;
87 std::vector<uint8_t> current_font_gfx16_data_;
88 std::vector<std::string> parsed_messages_;
89 std::vector<MessageData> list_of_texts_;
90 std::vector<DictionaryEntry> all_dictionaries_;
91
93
97
98 gui::Canvas font_gfx_canvas_{"##FontGfxCanvas", ImVec2(128, 128)};
100 ImVec2(172, 4096)};
101
102 struct TextBox {
103 std::string text;
104 std::string buffer;
105 int cursor_pos = 0;
109 bool has_selection = false;
110 bool has_focus = false;
111 bool changed = false;
112 bool can_undo = false;
113
114 void Undo() {
115 text = buffer;
117 has_selection = false;
118 }
119 void clearUndo() { can_undo = false; }
120 void Copy() { ImGui::SetClipboardText(text.c_str()); }
121 void Cut() {
122 Copy();
125 has_selection = false;
126 changed = true;
127 }
128 void Paste() {
130 text.insert(selection_start, ImGui::GetClipboardText());
131 std::string str = ImGui::GetClipboardText();
132 cursor_pos = selection_start + str.size();
133 has_selection = false;
134 changed = true;
135 }
136 void clear() {
137 text.clear();
138 buffer.clear();
139 cursor_pos = 0;
140 selection_start = 0;
141 selection_end = 0;
143 has_selection = false;
144 has_focus = false;
145 changed = false;
146 can_undo = false;
147 }
148 void SelectAll() {
149 selection_start = 0;
150 selection_end = text.size();
151 selection_length = text.size();
152 has_selection = true;
153 }
154 void Focus() { has_focus = true; }
155 };
156
158};
159
160} // namespace editor
161} // namespace yaze
162
163#endif // YAZE_APP_EDITOR_MESSAGE_EDITOR_H
SharedRom()=default
EditorType type_
Definition editor.h:88
std::vector< std::string > parsed_messages_
absl::Status Copy() override
absl::Status Find() override
absl::Status Update() override
std::array< uint8_t, kWidthArraySize > width_array
absl::Status Paste() override
std::string DisplayTextOverflowError(int pos, bool bank)
void DrawStringToPreview(std::string str)
absl::Status Undo() override
absl::Status Load() override
void DrawTileToPreview(int x, int y, int srcx, int srcy, int pal, int sizex=1, int sizey=1)
absl::Status Cut() override
std::vector< MessageData > list_of_texts_
std::vector< uint8_t > font_gfx16_data_
std::vector< uint8_t > current_font_gfx16_data_
gfx::SnesPalette font_preview_colors_
absl::Status Redo() override
DictionaryEntry GetDictionaryFromID(uint8_t value)
std::vector< DictionaryEntry > all_dictionaries_
absl::Status Save() override
Represents a bitmap image.
Definition bitmap.h:67
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Represents a canvas for drawing and manipulating graphics.
Definition canvas.h:34
Editors are the view controllers for the application.
constexpr int kCharactersWidth
const std::string DICTIONARYTOKEN
constexpr int kFontGfx16Size
constexpr int kCurrentMessageWidth
constexpr int kTextData2
constexpr int kCurrentMessageHeight
constexpr uint8_t kBlockTerminator
constexpr int kGfxFont
constexpr int kFontGfxMessageSize
constexpr int kFontGfxMessageDepth
constexpr int kTextData2End
constexpr uint8_t kWidthArraySize
constexpr uint8_t kMessageBankChangeId
constexpr int kNumMessages
Main namespace for the application.
Definition controller.cc:18