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"
9#include "app/editor/editor.h"
10#include "app/gfx/bitmap.h"
11#include "app/gui/canvas.h"
12#include "app/rom.h"
13
14namespace yaze {
15namespace app {
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;
27
28constexpr uint8_t kWidthArraySize = 100;
29constexpr uint8_t kBlockTerminator = 0x80;
30constexpr uint8_t kMessageBankChangeId = 0x80;
31constexpr uint8_t kScrollVertical = 0x73;
32constexpr uint8_t kLine1 = 0x74;
33constexpr uint8_t kLine2 = 0x75;
34constexpr uint8_t kLine3 = 0x76;
35
36static TextElement DictionaryElement =
37 TextElement(0x80, DICTIONARYTOKEN, true, "Dictionary");
38
39class MessageEditor : public Editor, public SharedRom {
40 public:
42
43 absl::Status Initialize();
44 absl::Status Update() override;
45 void DrawMessageList();
46 void DrawCurrentMessage();
47 void DrawTextCommands();
48 void DrawDictionary();
49
50 void ReadAllTextDataV2();
51 [[deprecated]] void ReadAllTextData();
52
53 absl::Status Cut() override;
54 absl::Status Copy() override;
55 absl::Status Paste() override;
56 absl::Status Undo() override;
57 absl::Status Redo() override {
58 return absl::UnimplementedError("Redo not implemented");
59 }
60 absl::Status Find() override {
61 return absl::UnimplementedError("Find not implemented");
62 }
63 absl::Status Save();
64 void Delete();
65 void SelectAll();
66
68 void DrawTileToPreview(int x, int y, int srcx, int srcy, int pal,
69 int sizex = 1, int sizey = 1);
70 void DrawCharacterToPreview(char c);
71 void DrawCharacterToPreview(const std::vector<uint8_t>& text);
72
73 void DrawStringToPreview(std::string str);
74 void DrawMessagePreview();
75 std::string DisplayTextOverflowError(int pos, bool bank);
76
77 private:
78 bool skip_next = false;
79 bool data_loaded_ = false;
80
81 int text_line_ = 0;
83 int shown_lines_ = 0;
84
86
87 std::string search_text_ = "";
88
89 std::vector<uint8_t> font_gfx16_data_;
90 std::vector<uint8_t> current_font_gfx16_data_;
91 std::vector<std::string> parsed_messages_;
92
93 std::vector<MessageData> list_of_texts_;
94
95 std::vector<DictionaryEntry> all_dictionaries_;
96
98
102
103 gui::Canvas font_gfx_canvas_{"##FontGfxCanvas", ImVec2(128, 128)};
105 ImVec2(172, 4096)};
106
107 struct TextBox {
108 std::string text;
109 std::string buffer;
110 int cursor_pos = 0;
114 bool has_selection = false;
115 bool has_focus = false;
116 bool changed = false;
117 bool can_undo = false;
118
119 void Undo() {
120 text = buffer;
122 has_selection = false;
123 }
124 void clearUndo() { can_undo = false; }
125 void Copy() { ImGui::SetClipboardText(text.c_str()); }
126 void Cut() {
127 Copy();
130 has_selection = false;
131 changed = true;
132 }
133 void Paste() {
135 text.insert(selection_start, ImGui::GetClipboardText());
136 std::string str = ImGui::GetClipboardText();
137 cursor_pos = selection_start + str.size();
138 has_selection = false;
139 changed = true;
140 }
141 void clear() {
142 text.clear();
143 buffer.clear();
144 cursor_pos = 0;
145 selection_start = 0;
146 selection_end = 0;
148 has_selection = false;
149 has_focus = false;
150 changed = false;
151 can_undo = false;
152 }
153 void SelectAll() {
154 selection_start = 0;
155 selection_end = text.size();
156 selection_length = text.size();
157 has_selection = true;
158 }
159 void Focus() { has_focus = true; }
160 };
161
163};
164
165} // namespace editor
166} // namespace app
167} // namespace yaze
168
169#endif // YAZE_APP_EDITOR_MESSAGE_EDITOR_H
A class to hold a shared pointer to a Rom object.
Definition rom.h:576
Interface for editor classes.
Definition editor.h:54
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: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
constexpr uint8_t kLine3
const std::string DICTIONARYTOKEN
constexpr int kNumMessages
constexpr int kCurrentMessageHeight
constexpr int kGfxFont
constexpr int kFontGfxMessageDepth
constexpr int kTextData2
constexpr int kFontGfxMessageSize
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:22