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"
10#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;
27
28constexpr uint8_t kWidthArraySize = 100;
29constexpr uint8_t kBlockTerminator = 0x80;
30constexpr uint8_t kMessageBankChangeId = 0x80;
31
32static TextElement DictionaryElement =
33 TextElement(0x80, DICTIONARYTOKEN, true, "Dictionary");
34
35class MessageEditor : public Editor, public SharedRom {
36 public:
38
39 absl::Status Initialize();
40 absl::Status Update() override;
41 void DrawMessageList();
42 void DrawCurrentMessage();
43 void DrawTextCommands();
44 void DrawDictionary();
45
46 void ReadAllTextDataV2();
47 [[deprecated]] void ReadAllTextData();
48
49 absl::Status Cut() override;
50 absl::Status Copy() override;
51 absl::Status Paste() override;
52 absl::Status Undo() override;
53 absl::Status Redo() override {
54 return absl::UnimplementedError("Redo not implemented");
55 }
56 absl::Status Find() override {
57 return absl::UnimplementedError("Find not implemented");
58 }
59 absl::Status Save();
60 void Delete();
61 void SelectAll();
62
64 void DrawTileToPreview(int x, int y, int srcx, int srcy, int pal,
65 int sizex = 1, int sizey = 1);
66 void DrawCharacterToPreview(char c);
67 void DrawCharacterToPreview(const std::vector<uint8_t>& text);
68
69 void DrawStringToPreview(std::string str);
70 void DrawMessagePreview();
71 std::string DisplayTextOverflowError(int pos, bool bank);
72
73 private:
74 bool skip_next = false;
75 bool data_loaded_ = false;
76
77 int text_line_ = 0;
79 int shown_lines_ = 0;
80
81 std::string search_text_ = "";
82
83 std::array<uint8_t, kWidthArraySize> width_array = {0};
84 std::vector<uint8_t> font_gfx16_data_;
85 std::vector<uint8_t> current_font_gfx16_data_;
86 std::vector<std::string> parsed_messages_;
87 std::vector<MessageData> list_of_texts_;
88 std::vector<DictionaryEntry> all_dictionaries_;
89
91
95
96 gui::Canvas font_gfx_canvas_{"##FontGfxCanvas", ImVec2(128, 128)};
98 ImVec2(172, 4096)};
99
100 struct TextBox {
101 std::string text;
102 std::string buffer;
103 int cursor_pos = 0;
107 bool has_selection = false;
108 bool has_focus = false;
109 bool changed = false;
110 bool can_undo = false;
111
112 void Undo() {
113 text = buffer;
115 has_selection = false;
116 }
117 void clearUndo() { can_undo = false; }
118 void Copy() { ImGui::SetClipboardText(text.c_str()); }
119 void Cut() {
120 Copy();
123 has_selection = false;
124 changed = true;
125 }
126 void Paste() {
128 text.insert(selection_start, ImGui::GetClipboardText());
129 std::string str = ImGui::GetClipboardText();
130 cursor_pos = selection_start + str.size();
131 has_selection = false;
132 changed = true;
133 }
134 void clear() {
135 text.clear();
136 buffer.clear();
137 cursor_pos = 0;
138 selection_start = 0;
139 selection_end = 0;
141 has_selection = false;
142 has_focus = false;
143 changed = false;
144 can_undo = false;
145 }
146 void SelectAll() {
147 selection_start = 0;
148 selection_end = text.size();
149 selection_length = text.size();
150 has_selection = true;
151 }
152 void Focus() { has_focus = true; }
153 };
154
156};
157
158} // namespace editor
159} // namespace yaze
160
161#endif // YAZE_APP_EDITOR_MESSAGE_EDITOR_H
SharedRom()=default
EditorType type_
Definition editor.h:68
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
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_
Represents a bitmap image.
Definition bitmap.h:66
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 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