yaze 0.2.0
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 <string>
5#include <vector>
6
7#include "absl/status/status.h"
8#include "absl/strings/str_format.h"
11#include "app/gfx/bitmap.h"
12#include "app/gui/canvas.h"
13#include "app/rom.h"
14
15namespace yaze {
16namespace app {
17namespace editor {
18
19constexpr int kGfxFont = 0x70000; // 2bpp format
20constexpr int kTextData2 = 0x75F40;
21constexpr int kTextData2End = 0x773FF;
22constexpr int kCharactersWidth = 0x74ADF;
23constexpr int kNumMessages = 396;
24constexpr int kCurrentMessageWidth = 172;
25constexpr int kCurrentMessageHeight = 4096;
26
27constexpr uint8_t kWidthArraySize = 100;
28constexpr uint8_t kBlockTerminator = 0x80;
29constexpr uint8_t kMessageBankChangeId = 0x80;
30constexpr uint8_t kScrollVertical = 0x73;
31constexpr uint8_t kLine1 = 0x74;
32constexpr uint8_t kLine2 = 0x75;
33constexpr uint8_t kLine3 = 0x76;
34
35static TextElement DictionaryElement =
36 TextElement(0x80, DICTIONARYTOKEN, true, "Dictionary");
37
38class MessageEditor : public Editor, public SharedRom {
39 public:
41
42 absl::Status Initialize();
43 absl::Status Update() override;
44 void DrawMessageList();
45 void DrawCurrentMessage();
46 void DrawTextCommands();
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();
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
84
85 std::string search_text_ = "";
86
87 std::vector<uint8_t> font_gfx16_data_;
88 std::vector<uint8_t> current_font_gfx16_data_;
89 std::vector<std::string> parsed_messages_;
90
91 std::vector<MessageData> list_of_texts_;
92
93 std::vector<DictionaryEntry> all_dictionaries_;
94
96
100
101 gui::Canvas font_gfx_canvas_{"##FontGfxCanvas", ImVec2(128, 128)};
103 ImVec2(172, 4096)};
104
105 struct TextBox {
106 std::string text;
107 std::string buffer;
108 int cursor_pos = 0;
112 bool has_selection = false;
113 bool has_focus = false;
114 bool changed = false;
115 bool can_undo = false;
116
117 void Undo() {
118 text = buffer;
120 has_selection = false;
121 }
122 void clearUndo() { can_undo = false; }
123 void Copy() { ImGui::SetClipboardText(text.c_str()); }
124 void Cut() {
125 Copy();
128 has_selection = false;
129 changed = true;
130 }
131 void Paste() {
133 text.insert(selection_start, ImGui::GetClipboardText());
134 std::string str = ImGui::GetClipboardText();
135 cursor_pos = selection_start + str.size();
136 has_selection = false;
137 changed = true;
138 }
139 void clear() {
140 text.clear();
141 buffer.clear();
142 cursor_pos = 0;
143 selection_start = 0;
144 selection_end = 0;
146 has_selection = false;
147 has_focus = false;
148 changed = false;
149 can_undo = false;
150 }
151 void SelectAll() {
152 selection_start = 0;
153 selection_end = text.size();
154 selection_length = text.size();
155 has_selection = true;
156 }
157 void Focus() { has_focus = true; }
158 };
159
161};
162
163} // namespace editor
164} // namespace app
165} // namespace yaze
166
167#endif // YAZE_APP_EDITOR_MESSAGE_EDITOR_H
A class to hold a shared pointer to a Rom object.
Definition rom.h:585
Interface for editor classes.
Definition editor.h:39
DictionaryEntry GetDictionaryFromID(uint8_t value)
void DrawTileToPreview(int x, int y, int srcx, int srcy, int pal, int sizex=1, int sizey=1)
absl::Status Paste() override
std::string DisplayTextOverflowError(int pos, bool bank)
std::vector< std::string > parsed_messages_
absl::Status Find() override
std::vector< uint8_t > current_font_gfx16_data_
absl::Status Redo() override
absl::Status Update() override
std::vector< MessageData > list_of_texts_
std::vector< uint8_t > font_gfx16_data_
std::vector< DictionaryEntry > all_dictionaries_
void DrawStringToPreview(std::string str)
uint8_t width_array[kWidthArraySize]
Represents a bitmap image.
Definition bitmap.h:70
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Represents a canvas for drawing and manipulating graphics.
Definition canvas.h:36
constexpr uint8_t kLine3
const std::string DICTIONARYTOKEN
constexpr int kNumMessages
constexpr int kCurrentMessageHeight
constexpr int kGfxFont
constexpr int kTextData2
constexpr uint8_t kWidthArraySize
constexpr uint8_t kLine1
constexpr uint8_t kMessageBankChangeId
constexpr int kCurrentMessageWidth
constexpr uint8_t kLine2
constexpr int kTextData2End
constexpr uint8_t kBlockTerminator
constexpr int kCharactersWidth
constexpr uint8_t kScrollVertical
Definition common.cc:21