yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
message_preview.cc
Go to the documentation of this file.
2
3namespace yaze {
4namespace editor {
5
6void MessagePreview::DrawTileToPreview(int x, int y, int srcx, int srcy,
7 int pal, int sizex, int sizey) {
8 const auto& font_data =
10 if (font_data.empty()) {
11 return;
12 }
13 const size_t font_size = font_data.size();
14 const size_t preview_size = current_preview_data_.size();
15 const int sheet_width = 128;
16 if (sheet_width <= 0) {
17 return;
18 }
19 const int sheet_height = static_cast<int>(font_size / sheet_width);
20 if (sheet_height <= 0) {
21 return;
22 }
23
24 const int tile_size = 8;
25 const int palette_offset = pal * 4;
26 const int base_tile_y = srcy * sizey;
27
28 for (int tile_y = 0; tile_y < sizey; ++tile_y) {
29 for (int tile_x = 0; tile_x < sizex; ++tile_x) {
30 const int tile_px = (srcx + tile_x) * tile_size;
31 const int tile_py = (base_tile_y + tile_y) * tile_size;
32
33 for (int py = 0; py < tile_size; ++py) {
34 const int src_y = tile_py + py;
35 if (src_y < 0 || src_y >= sheet_height) {
36 continue;
37 }
38
39 for (int px = 0; px < tile_size; ++px) {
40 const int src_x = tile_px + px;
41 if (src_x < 0 || src_x >= sheet_width) {
42 continue;
43 }
44
45 const size_t src_index =
46 static_cast<size_t>(src_x + (src_y * sheet_width));
47 if (src_index >= font_size) {
48 continue;
49 }
50
51 const uint8_t pixel = font_data[src_index];
52 if ((pixel & 0x0F) == 0) {
53 continue;
54 }
55
56 const int dst_x = x + tile_x * tile_size + px;
57 const int dst_y = y + tile_y * tile_size + py;
58 const int dst_index = dst_x + (dst_y * kCurrentMessageWidth);
59 if (dst_index < 0 ||
60 static_cast<size_t>(dst_index) >= preview_size) {
61 continue;
62 }
63
64 current_preview_data_[dst_index] =
65 static_cast<uint8_t>(pixel + palette_offset);
66 }
67 }
68 }
69 }
70}
71
72void MessagePreview::DrawStringToPreview(const std::string& str) {
73 for (const auto& c : str) {
75 }
76}
77
79 std::vector<uint8_t> text;
80 text.push_back(FindMatchingCharacter(c));
82}
83
84void MessagePreview::DrawCharacterToPreview(const std::vector<uint8_t>& text) {
85 for (const uint8_t& value : text) {
86 if (skip_next) {
87 skip_next = false;
88 continue;
89 }
90
91 if (value < 100) {
92 int srcy = value >> 4;
93 int srcx = value & 0xF;
94
95 if (text_position >= 170) {
96 text_position = 0;
97 text_line++;
98 }
99
100 DrawTileToPreview(text_position, text_line * 16, srcx, srcy, 0, 1, 2);
101 text_position += width_array[value];
102 } else if (value == kLine1) {
103 text_position = 0;
104 text_line = 0;
105 } else if (value == kScrollVertical) {
106 text_position = 0;
107 text_line += 1;
109 } else if (value == kLine2) {
110 text_position = 0;
111 text_line = 1;
112 } else if (value == kLine3) {
113 text_position = 0;
114 text_line = 2;
115 } else if (value == 0x6B || value == 0x6D || value == 0x6E ||
116 value == 0x77 || value == 0x78 || value == 0x79 ||
117 value == 0x7A) {
118 skip_next = true;
119
120 continue;
121 } else if (value == 0x6C) // BCD numbers.
122 {
124 skip_next = true;
125
126 continue;
127 } else if (value == 0x6A) {
128 // Includes parentheses to be longer, since player names can be up to 6
129 // characters.
130 const std::string name = "(NAME)";
132 } else if (value >= DICTOFF && value < (DICTOFF + 97)) {
133 int pos = value - DICTOFF;
134 if (pos < 0 || pos >= all_dictionaries_.size()) {
135 // Invalid dictionary entry.
136 std::cerr << "Invalid dictionary entry: " << pos << std::endl;
137 continue;
138 }
139 auto dictionary_entry = FindRealDictionaryEntry(value, all_dictionaries_);
140 DrawCharacterToPreview(dictionary_entry.Data);
141 }
142 }
143}
144
146 // From Parsing.
147 text_line = 0;
148 std::fill(current_preview_data_.begin(), current_preview_data_.end(), 0);
149 text_position = 0;
150 scroll_marker_lines.clear();
152 shown_lines = 0;
153}
154
155} // namespace editor
156} // namespace yaze
uint8_t FindMatchingCharacter(char value)
DictionaryEntry FindRealDictionaryEntry(uint8_t value, const std::vector< DictionaryEntry > &dictionary)
constexpr uint8_t kScrollVertical
constexpr uint8_t kLine1
constexpr int kCurrentMessageWidth
constexpr uint8_t kLine2
constexpr uint8_t DICTOFF
constexpr uint8_t kLine3
std::vector< uint8_t > Data
std::vector< uint8_t > current_preview_data_
void DrawMessagePreview(const MessageData &message)
std::array< uint8_t, kWidthArraySize > width_array
std::vector< uint8_t > font_gfx16_data_2_
std::vector< uint8_t > font_gfx16_data_
std::vector< int > scroll_marker_lines
void DrawStringToPreview(const std::string &str)
std::vector< DictionaryEntry > all_dictionaries_
void DrawTileToPreview(int x, int y, int srcx, int srcy, int pal, int sizex=1, int sizey=1)