forked from Dzejrou/tdt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuilderWindow.cpp
More file actions
128 lines (113 loc) · 2.99 KB
/
BuilderWindow.cpp
File metadata and controls
128 lines (113 loc) · 2.99 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
117
118
119
120
121
122
123
124
125
126
127
128
#include "BuilderWindow.hpp"
#include "EntityPlacer.hpp"
#include "GUI.hpp"
BuilderWindow::BuilderWindow()
: buildings_{}, selection_number_{3}, placer_{nullptr}
{ /* DUMMY BODY */ }
void BuilderWindow::register_building(const std::string& tname)
{
for(const auto& b : buildings_)
{
if(b == tname) // Prevents multiple entries of a building.
return;
}
buildings_.push_back(tname);
update_selection_();
}
void BuilderWindow::set_placer(EntityPlacer* p)
{
placer_ = p;
}
void BuilderWindow::init_()
{
update_selection_();
window_->getChild("BUILD_1")->subscribeEvent(
CEGUI::PushButton::EventClicked,
[&](const CEGUI::EventArgs&) -> bool {
if(get_building_(selection_number_ - 3) != "" && placer_)
{
placer_->set_current_entity_table(buildings_[selection_number_ - 3], true);
placer_->set_visible(true);
}
return true;
}
);
window_->getChild("BUILD_2")->subscribeEvent(
CEGUI::PushButton::EventClicked,
[&](const CEGUI::EventArgs&) -> bool {
if(get_building_(selection_number_ - 2) != "" && placer_)
{
placer_->set_current_entity_table(buildings_[selection_number_ - 2], true);
placer_->set_visible(true);
}
return true;
}
);
window_->getChild("BUILD_3")->subscribeEvent(
CEGUI::PushButton::EventClicked,
[&](const CEGUI::EventArgs&) -> bool {
if(get_building_(selection_number_ - 1) != "" && placer_)
{
placer_->set_current_entity_table(buildings_[selection_number_ - 1], true);
placer_->set_visible(true);
}
return true;
}
);
window_->getChild("BUILD_4")->subscribeEvent(
CEGUI::PushButton::EventClicked,
[&](const CEGUI::EventArgs&) -> bool {
if(get_building_(selection_number_) != "" && placer_)
{
placer_->set_current_entity_table(buildings_[selection_number_], true);
placer_->set_visible(true);
}
return true;
}
);
window_->getChild("LEFT")->subscribeEvent(
CEGUI::PushButton::EventClicked,
[&](const CEGUI::EventArgs&) -> bool {
this->dec_selection_();
return true;
}
);
window_->getChild("RIGHT")->subscribeEvent(
CEGUI::PushButton::EventClicked,
[&](const CEGUI::EventArgs&) -> bool {
this->inc_selection_();
return true;
}
);
}
void BuilderWindow::dec_selection_()
{
if(selection_number_ > 3)
{
--selection_number_;
update_selection_();
}
}
void BuilderWindow::inc_selection_()
{
if(buildings_.size() > 4 && selection_number_ < buildings_.size() - 1)
{
++selection_number_;
update_selection_();
}
}
const std::string& BuilderWindow::get_building_(std::size_t index)
{
static std::string NO_BUILDING{""};
if(index >= 0 && index < buildings_.size())
return buildings_[index];
else
return NO_BUILDING;
}
void BuilderWindow::update_selection_()
{
window_->getChild("BUILD_1")->setText(get_building_(selection_number_ - 3));
window_->getChild("BUILD_2")->setText(get_building_(selection_number_ - 2));
window_->getChild("BUILD_3")->setText(get_building_(selection_number_ - 1));
window_->getChild("BUILD_4")->setText(get_building_(selection_number_));
}