-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialog.cpp
More file actions
116 lines (98 loc) · 2.34 KB
/
Dialog.cpp
File metadata and controls
116 lines (98 loc) · 2.34 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "stdafx.h"
#include "Dialog.h"
#include <qjsonarray.h>
#include "Input.h"
using namespace LarasEngine;
Dialog::Dialog(const TypId& _typId)
: GameObject (0, 0, _typId)
, indexCurrentText (0)
, maxCharCount (0)
, framesCount (0)
, drawNext (false)
, textSpeed (1)
{
font = QApplication::font();
font.setPointSize(18);
QRectF rect = GetImageRect ();
textRect = rect;
textRect.setWidth(textRect.width() * 0.9);
textRect.setHeight(textRect.height() * 0.85);
textRect.moveCenter(rect.center());
}
void Dialog::Draw (QPainter* painter)
{
if (indexCurrentText < textVec.size())
{
GameObject::Draw(painter);
std::string text = textVec.at(indexCurrentText);
int charCount = std::min(maxCharCount, text.size());
text = text.substr(0, charCount);
painter->save();
painter->setFont(font);
painter->setPen(pen);
painter->drawText(textRect, Qt::AlignCenter, text.c_str());
painter->drawText(textRect, Qt::AlignBottom | Qt::AlignRight, "[ENTER]");
painter->restore();
}
//textObj.Draw(painter);
}
void Dialog::Update ()
{
if (drawNext)
{
if (Input::Me ().TestKey (Input::Key::Key_Enter))
{
indexCurrentText++;
drawNext = false;
maxCharCount = 0;
}
}
else
{
if (framesCount % textSpeed == 0)
{
++maxCharCount;
if (textVec.at(indexCurrentText).size() <= maxCharCount)
drawNext = true;
}
}
framesCount++;
if (indexCurrentText >= textVec.size())
deleteMe = true;
}
void Dialog::ReadJson(const QJsonObject& json)
{
QJsonArray d = json["Dialogs"].toArray();
for (size_t i = 0; i < d.size(); ++i)
{
std::string tmp = d[i].toString().toLatin1();
textVec.push_back(tmp);
}
if (json.contains("xPos") && json.contains("yPos"))
{
int xPos = json["xPos"].toInt();
int yPos = json["yPos"].toInt();
SetPosition(xPos, yPos);
textRect.moveCenter(GetCenter());
}
else
{
const QPixmap& image = GetImage ();
int xPos = screenW / 2 - image.width() / 2;
int yPos = screenH - image.height() * 1.1;
SetPosition(xPos, yPos);
}
if (json.contains("fontSize"))
font.setPointSize(json["fontSize"].toInt());
if (json.contains("text_speed"))
textSpeed = json["text_speed"].toInt();
if (json.contains("fontColor"))
{
QJsonArray c = json["fontColor"].toArray();
int r = c[0].toInt();
int g = c[1].toInt();
int b = c[2].toInt();
int a = c[3].toInt();
pen = QPen (QColor (r, g, b, a));
}
}