yaze 0.2.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 int num_x_tiles = 16;
9 const int img_width = 512; // (imgwidth/2)
10 int draw_id = srcx + (srcy * 32);
11 for (int yl = 0; yl < sizey * 8; yl++) {
12 for (int xl = 0; xl < 4; xl++) {
13 int mx = xl;
14 int my = yl;
15
16 // Formula information to get tile index position in the array.
17 int tx = ((draw_id / num_x_tiles) * img_width) + ((draw_id & 0xF) << 2);
18 uint8_t pixel = font_gfx16_data_2_[tx + (yl * 64) + xl];
19
20 // nx,ny = object position, xx,yy = tile position, xl,yl = pixel
21 // position
22 int index = x + (y * 172) + (mx * 2) + (my * 172);
23 if ((pixel & 0x0F) != 0) {
24 current_preview_data_[index + 1] = (uint8_t)((pixel & 0x0F) + (0 * 4));
25 }
26
27 if (((pixel >> 4) & 0x0F) != 0) {
28 current_preview_data_[index + 0] =
29 (uint8_t)(((pixel >> 4) & 0x0F) + (0 * 4));
30 }
31 }
32 }
33}
34
35void MessagePreview::DrawStringToPreview(const std::string& str) {
36 for (const auto& c : str) {
38 }
39}
40
42 std::vector<uint8_t> text;
43 text.push_back(FindMatchingCharacter(c));
45}
46
47void MessagePreview::DrawCharacterToPreview(const std::vector<uint8_t>& text) {
48 for (const uint8_t& value : text) {
49 if (skip_next) {
50 skip_next = false;
51 continue;
52 }
53
54 if (value < 100) {
55 int srcy = value >> 4;
56 int srcx = value & 0xF;
57
58 if (text_position >= 170) {
59 text_position = 0;
60 text_line++;
61 }
62
63 DrawTileToPreview(text_position, text_line * 16, srcx, srcy, 0, 1, 2);
64 text_position += width_array[value];
65 } else if (value == kLine1) {
66 text_position = 0;
67 text_line = 0;
68 } else if (value == kScrollVertical) {
69 text_position = 0;
70 text_line += 1;
71 } else if (value == kLine2) {
72 text_position = 0;
73 text_line = 1;
74 } else if (value == kLine3) {
75 text_position = 0;
76 text_line = 2;
77 } else if (value == 0x6B || value == 0x6D || value == 0x6E ||
78 value == 0x77 || value == 0x78 || value == 0x79 ||
79 value == 0x7A) {
80 skip_next = true;
81
82 continue;
83 } else if (value == 0x6C) // BCD numbers.
84 {
86 skip_next = true;
87
88 continue;
89 } else if (value == 0x6A) {
90 // Includes parentheses to be longer, since player names can be up to 6
91 // characters.
92 const std::string name = "(NAME)";
94 } else if (value >= DICTOFF && value < (DICTOFF + 97)) {
95 int pos = value - DICTOFF;
96 if (pos < 0 || pos >= all_dictionaries_.size()) {
97 // Invalid dictionary entry.
98 std::cerr << "Invalid dictionary entry: " << pos << std::endl;
99 continue;
100 }
101 auto dictionary_entry = FindRealDictionaryEntry(value, all_dictionaries_);
102 DrawCharacterToPreview(dictionary_entry.Data);
103 }
104 }
105}
106
108 // From Parsing.
109 text_line = 0;
110 std::fill(current_preview_data_.begin(), current_preview_data_.end(), 0);
111 text_position = 0;
113 shown_lines = 0;
114}
115
116} // namespace editor
117} // namespace yaze
Editors are the view controllers for the application.
uint8_t FindMatchingCharacter(char value)
constexpr uint8_t kScrollVertical
constexpr uint8_t kLine1
DictionaryEntry FindRealDictionaryEntry(uint8_t value, std::vector< DictionaryEntry > dictionary)
constexpr uint8_t kLine2
constexpr uint8_t DICTOFF
constexpr uint8_t kLine3
Main namespace for the application.
Definition controller.cc:18
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_
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)