-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathplayer_message.cpp
89 lines (71 loc) · 2.37 KB
/
player_message.cpp
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
#include "stdafx.h"
#include "player_message.h"
#include "view.h"
#include "scripted_ui_data.h"
#include "scripted_ui.h"
#include "gui_elem.h"
PlayerMessage::PlayerMessage(const TString& t, MessagePriority p)
: text(TSentence("MAKE_SENTENCE", std::move(t))), priority(p),
freshness(1) {}
PlayerMessage::PlayerMessage(const TSentence& s, MessagePriority p) : PlayerMessage(TString(std::move(s)), p) {
}
PlayerMessage::PlayerMessage(const TStringId& s, MessagePriority p) : PlayerMessage(TString(std::move(s)), p) {
}
void PlayerMessage::presentMessages(View* view, const vector<PlayerMessage>& messages) {
auto list = ScriptedUIDataElems::List {};
for (int i : All(messages))
list.push_back(ScriptedUIDataElems::Record {{
{EnumInfo<MessagePriority>::getString(messages[i].priority), TString(messages[i].getTranslatedText(view))}
}});
if (messages.empty())
list.push_back(ScriptedUIDataElems::Record {{
{"NORMAL", TString(TStringId("NO_MESSAGES_YET"))}
}});
ScriptedUIState state;
state.scrollPos[0].set(10000000, milliseconds{0});
view->scriptedUI("message_history", list, state);
}
string PlayerMessage::getTranslatedText(View* view) const {
return view->translate(text);
}
string PlayerMessage::getTranslatedText(GuiFactory* view) const {
return view->translate(text);
}
const TString& PlayerMessage::getText() const {
return text;
}
double PlayerMessage::getFreshness() const {
return freshness;
}
void PlayerMessage::setFreshness(double val) {
freshness = val;
}
MessagePriority PlayerMessage::getPriority() const {
return priority;
}
PlayerMessage& PlayerMessage::setPosition(Position pos) {
position = pos;
return *this;
}
optional<Position> PlayerMessage::getPosition() const {
return position;
}
PlayerMessage& PlayerMessage::setCreature(UniqueEntity<Creature>::Id id) {
creature = id;
return *this;
}
optional<UniqueEntity<Creature>::Id> PlayerMessage::getCreature() const {
return creature;
}
bool PlayerMessage::isClickable() const {
return position || creature;
}
int PlayerMessage::getHash() const {
return combineHash(text, priority, freshness);
}
template <class Archive>
void PlayerMessage::serialize(Archive& ar, const unsigned int version) {
ar(SUBCLASS(UniqueEntity), text, priority, freshness, announcementTitle, position, creature);
}
SERIALIZABLE(PlayerMessage);
SERIALIZATION_CONSTRUCTOR_IMPL(PlayerMessage);