forked from scarsty/kys-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTalk.cpp
More file actions
80 lines (77 loc) · 1.86 KB
/
Talk.cpp
File metadata and controls
80 lines (77 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Talk.h"
#include "Engine.h"
#include "Font.h"
#include "PotConv.h"
#include <iostream>
#include <string>
void Talk::draw()
{
if (!content_.empty())
{
Engine::getInstance()->fillColor({ 0, 0, 0, 128 }, x_ + 225, y_ + 65, 530, 150);
if (head_id_ >= 0)
{
if (head_style_ == 0)
{
TextureManager::getInstance()->renderTexture("head", head_id_, x_ + 50, y_ + 50);
}
else
{
TextureManager::getInstance()->renderTexture("head", head_id_, x_ + 770, y_ + 50);
}
}
int end_line = current_line_ + height_;
if (end_line > content_lines_.size()) { end_line = content_lines_.size(); }
for (int i = current_line_; i < end_line; i++)
{
Font::getInstance()->draw(content_lines_[i], 24, x_ + 250, y_ + 75 + 25 * (i - current_line_), { 255, 255, 255, 255 });
}
}
}
void Talk::onPressedOK()
{
if (current_line_ + height_ >= content_lines_.size())
{
setExit(true);
}
else
{
current_line_ += height_;
}
//e.type = BP_FIRSTEVENT;
result_ = 0;
}
void Talk::onEntrance()
{
content_lines_.clear();
current_line_ = 0;
int i = 0;
while (i < content_.size())
{
int len = 0;
//计算英文个数
int eng_count = 0;
int j = i;
for (; j < content_.size();)
{
if (uint8_t(content_.at(j)) > 128)
{
j += 3;
len += 2;
}
else
{
eng_count++;
j++;
len += 1;
}
if (len >= width_)
{
break;
}
}
auto line = content_.substr(i, j - i);
content_lines_.push_back(line);
i = j;
}
}