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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
#include "Config.h"
#include "GameView.h"
#include "interface/Window.h"
#include "interface/Button.h"
GameView::GameView():
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
pointQueue(queue<ui::Point*>()),
isMouseDown(false),
ren(NULL)
{
//Set up UI
class PauseAction : public ui::ButtonAction
{
GameView * v;
public:
PauseAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->SetPaused(sender->GetToggleState());
}
};
pauseButton = new ui::Button(ui::Point(Size.X-18, Size.Y-18), ui::Point(16, 16), "\x90"); //Pause
pauseButton->SetTogglable(true);
pauseButton->SetActionCallback(new PauseAction(this));
AddComponent(pauseButton);
class SearchAction : public ui::ButtonAction
{
GameView * v;
public:
SearchAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->OpenSearch();
}
};
searchButton = new ui::Button(ui::Point(1, Size.Y-18), ui::Point(16, 16), "\x81"); //Open
searchButton->SetTogglable(false);
searchButton->SetActionCallback(new SearchAction(this));
AddComponent(searchButton);
class ReloadAction : public ui::ButtonAction
{
GameView * v;
public:
ReloadAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->OpenSearch(); // TODO call proper function
}
};
reloadButton = new ui::Button(ui::Point(16, Size.Y-18), ui::Point(16, 16), "\x91"); // TODO Position?
reloadButton->SetTogglable(false);
reloadButton->SetActionCallback(new ReloadAction(this));
AddComponent(reloadButton);
class SaveSimulationAction : public ui::ButtonAction
{
GameView * v;
public:
SaveSimulationAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->OpenSearch(); // TODO call proper function
}
};
saveSimulationButton = new ui::Button(ui::Point(32, Size.Y-18), ui::Point(152, 16), "\x82"); // TODO All arguments
saveSimulationButton->SetTogglable(false);
saveSimulationButton->SetActionCallback(new SaveSimulationAction(this));
AddComponent(saveSimulationButton);
class UpVoteAction : public ui::ButtonAction
{
GameView * v;
public:
UpVoteAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->OpenSearch(); // TODO call proper function
}
};
upVoteButton = new ui::Button(ui::Point(184, Size.Y-18), ui::Point(16, 16), "\xCB"); // TODO All arguments
upVoteButton->SetTogglable(false);
upVoteButton->SetActionCallback(new UpVoteAction(this));
AddComponent(upVoteButton);
class DownVoteAction : public ui::ButtonAction
{
GameView * v;
public:
DownVoteAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->OpenSearch(); // TODO call proper function
}
};
downVoteButton = new ui::Button(ui::Point(200, Size.Y-18), ui::Point(16, 16), "\xCA"); // TODO All arguments
downVoteButton->SetTogglable(false);
downVoteButton->SetActionCallback(new DownVoteAction(this));
AddComponent(downVoteButton);
class TagSimulationAction : public ui::ButtonAction
{
GameView * v;
public:
TagSimulationAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->OpenSearch(); // TODO call proper function
}
};
tagSimulationButton = new ui::Button(ui::Point(216, Size.Y-18), ui::Point(152, 16), "\x83"); // TODO All arguments
tagSimulationButton->SetTogglable(false);
tagSimulationButton->SetActionCallback(new TagSimulationAction(this));
AddComponent(tagSimulationButton);
//simul option
//erase all
// login
class DisplayModeAction : public ui::ButtonAction
{
GameView * v;
public:
DisplayModeAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->SetPaused(sender->GetToggleState()); // TODO call proper function
}
};
displayModeButton = new ui::Button(ui::Point(Size.X-34, Size.Y-18), ui::Point(16, 16), "\xDA"); // TODO All arguments
displayModeButton->SetTogglable(true);
displayModeButton->SetActionCallback(new DisplayModeAction(this));
AddComponent(displayModeButton);
}
void GameView::NotifyRendererChanged(GameModel * sender)
{
ren = sender->GetRenderer();
}
void GameView::NotifySimulationChanged(GameModel * sender)
{
}
void GameView::NotifyPausedChanged(GameModel * sender)
{
pauseButton->SetToggleState(sender->GetPaused());
}
void GameView::OnMouseMove(int x, int y, int dx, int dy)
{
if(isMouseDown)
{
pointQueue.push(new ui::Point(x-dx, y-dy));
pointQueue.push(new ui::Point(x, y));
}
}
void GameView::OnMouseDown(int x, int y, unsigned button)
{
isMouseDown = true;
pointQueue.push(new ui::Point(x, y));
}
void GameView::OnMouseUp(int x, int y, unsigned button)
{
if(isMouseDown)
{
isMouseDown = false;
pointQueue.push(new ui::Point(x, y));
}
}
void GameView::OnTick(float dt)
{
if(!pointQueue.empty())
{
c->DrawPoints(pointQueue);
}
c->Tick();
}
void GameView::OnDraw()
{
if(ren)
{
ren->render_parts();
}
}
|