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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
/*
client/graphicssettingsmenu.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#include "client/graphicssettingsmenu.h"
#include "core/cvar.h"
#include "ui/button.h"
#include "ui/checkbox.h"
#include "ui/iconbutton.h"
#include "ui/label.h"
#include "ui/ui.h"
#include "math/functions.h"
#include <iostream>
namespace client {
GraphicsSettingsMenu::GraphicsSettingsMenu(ui::Widget *parent, const char *label) : ui::Window(parent)
{
set_label(label);
set_border(true);
set_background(true);
set_font(ui::root()->font_small());
// window title
_titlelabel = new ui::Label(this);
_titlelabel->set_label("title");
_titlelabel->set_background(false);
_titlelabel->set_border(false);
_titlelabel->set_font(ui::root()->font_large());
_titlelabel->set_alignment(ui::AlignCenter);
_titlelabel->set_text("GRAPHICS SETTINGS");
// close button
_closebutton = new ui::IconButton(_titlelabel, "bitmaps/icons/window_close");
// content frame
_frame = new ui::Widget(this);
_frame->set_label("frame");
_frame->set_background(true);
_frame->set_border(true);
_frame->set_focus();
// options
_optionslabel = new ui::Label(_frame);
_optionslabel->set_label("options");
_optionslabel->set_background(false);
_optionslabel->set_border(false);
_optionslabel->set_text("Options");
_optionfullscreencheckbox = new ui::Checkbox(_frame);
_optionfullscreencheckbox->set_label("r_fullscreen");
_optionfullscreencheckbox->set_text("Fullscreen");
_optionfullscreencheckbox->set_border(true);
_optiongridcheckbox = new ui::Checkbox(_frame);
_optiongridcheckbox->set_label("r_grid");
_optiongridcheckbox->set_text("Draw space grid");
_optiongridcheckbox->set_border(true);
_optionskycheckbox = new ui::Checkbox(_frame);
_optionskycheckbox->set_label("r_sky");
_optionskycheckbox->set_text("Draw sky");
_optionskycheckbox->set_border(true);
_optionparticlescheckbox = new ui::Checkbox(_frame);
_optionparticlescheckbox->set_label("r_particles");
_optionparticlescheckbox->set_text("Draw particles");
_optionparticlescheckbox->set_border(true);
_optionindicatorscheckbox = new ui::Checkbox(_frame);
_optionindicatorscheckbox->set_label("r_indicators");
_optionindicatorscheckbox->set_text("Draw direction indicators");
_optionindicatorscheckbox->set_border(true);
_debuglabel = new ui::Label(_frame);
_debuglabel->set_label("debug");
_debuglabel->set_background(false);
_debuglabel->set_border(false);
_debuglabel->set_text("Debug");
_debugstatscheckbox = new ui::Checkbox(_frame);
_debugstatscheckbox->set_label("draw_stats");
_debugstatscheckbox->set_text("Draw FPS and statistics");
_debugstatscheckbox->set_border(true);
_debugwireframecheckbox = new ui::Checkbox(_frame);
_debugwireframecheckbox->set_label("r_wireframe");
_debugwireframecheckbox->set_text("Draw wireframe");
_debugwireframecheckbox->set_border(true);
_debugkeypresscheckbox = new ui::Checkbox(_frame);
_debugkeypresscheckbox->set_label("draw_keypressq");
_debugkeypresscheckbox->set_text("Draw keypress events");
_debugkeypresscheckbox->set_border(true);
_debugphysicscheckbox = new ui::Checkbox(_frame);
_debugphysicscheckbox->set_label("draw_physics");
_debugphysicscheckbox->set_text("Draw physics entities (singleplayer only)");
_debugphysicscheckbox->set_border(true);
// apply button
_applybutton = new ui::Button(_frame, "Apply");
_applybutton->set_label("apply");
// reset button
_resetbutton = new ui::Button(_frame, "Reset");
_resetbutton->set_label("reset");
}
GraphicsSettingsMenu::~GraphicsSettingsMenu()
{
}
void GraphicsSettingsMenu::show()
{
refresh();
ui::Window::show();
}
void GraphicsSettingsMenu::refresh()
{
math::Color color;
// fullscreen
if (core::Cvar *cv_fullscreen = core::Cvar::find("r_fullscreen"))
{
_optionfullscreencheckbox->set_value(cv_fullscreen->value() > 0.0f);
_optionfullscreencheckbox->set_enabled(true);
}
else
{
_optionfullscreencheckbox->set_value(false);
_optionfullscreencheckbox->set_enabled(false);
}
// space grid
if (core::Cvar *cv_grid = core::Cvar::find("r_grid"))
{
_optiongridcheckbox->set_value(cv_grid->value() > 0.0f);
_optiongridcheckbox->set_enabled(true);
}
else
{
_optiongridcheckbox->set_value(false);
_optiongridcheckbox->set_enabled(false);
}
// sky
if (core::Cvar *cv_sky = core::Cvar::find("r_sky"))
{
_optionskycheckbox->set_value(cv_sky->value() > 0.0f);
_optionskycheckbox->set_enabled(true);
}
else
{
_optionskycheckbox->set_value(false);
_optionskycheckbox->set_enabled(false);
}
// particles
if (core::Cvar *cv_particles = core::Cvar::find("r_particles"))
{
_optionparticlescheckbox->set_value(cv_particles->value() > 0.0f);
_optionparticlescheckbox->set_enabled(true);
}
else
{
_optionparticlescheckbox->set_value(false);
_optionparticlescheckbox->set_enabled(false);
}
// indicators
if (core::Cvar *cv_indicators = core::Cvar::find("r_indicators"))
{
_optionindicatorscheckbox->set_value(cv_indicators->value() > 0.0f);
_optionindicatorscheckbox->set_enabled(true);
}
else
{
_optionindicatorscheckbox->set_value(false);
_optionindicatorscheckbox->set_enabled(false);
}
// stats
if (core::Cvar *cv_stats = core::Cvar::find("draw_stats"))
{
_debugstatscheckbox->set_value(cv_stats->value() > 0.0f);
_debugstatscheckbox->set_enabled(true);
}
else
{
_debugstatscheckbox->set_value(false);
_debugstatscheckbox->set_enabled(false);
}
// wireframe
if (core::Cvar *cv_wireframe = core::Cvar::find("r_wireframe"))
{
_debugwireframecheckbox->set_value(cv_wireframe->value() > 0.0f);
_debugwireframecheckbox->set_enabled(true);
}
else
{
_debugwireframecheckbox->set_value(false);
_debugwireframecheckbox->set_enabled(false);
}
// keypress
if (core::Cvar *cv_keypress = core::Cvar::find("draw_keypress"))
{
_debugkeypresscheckbox->set_value(cv_keypress->value() > 0.0f);
_debugkeypresscheckbox->set_enabled(true);
}
else
{
_debugkeypresscheckbox->set_value(false);
_debugkeypresscheckbox->set_enabled(false);
}
// physics
if (core::Cvar *cv_physics = core::Cvar::find("r_physics"))
{
_debugphysicscheckbox->set_value(cv_physics->value() > 0.0f);
_debugphysicscheckbox->set_enabled(true);
}
else
{
_debugphysicscheckbox->set_value(false);
_debugphysicscheckbox->set_enabled(false);
}
}
void GraphicsSettingsMenu::apply()
{
// fullscreen
if (core::Cvar *cv_fullscreen = core::Cvar::find("r_fullscreen"))
{
cv_fullscreen->assign(_optionfullscreencheckbox->value() ? 1.0f : 0.0f);
}
// space grid
if (core::Cvar *cv_grid = core::Cvar::find("r_grid"))
{
cv_grid->assign(_optiongridcheckbox->value() ? 1.0f : 0.0f);
}
// sky
if (core::Cvar *cv_sky = core::Cvar::find("r_sky"))
{
cv_sky->assign(_optionskycheckbox->value() ? 1.0f : 0.0f);
}
// particles
if (core::Cvar *cv_particles = core::Cvar::find("r_particles"))
{
cv_particles->assign(_optionparticlescheckbox->value() ? 1.0f : 0.0f);
}
// indicators
if (core::Cvar *cv_indicators = core::Cvar::find("r_indicators"))
{
cv_indicators->assign(_optionindicatorscheckbox->value() ? 1.0f : 0.0f);
}
// stats
if (core::Cvar *cv_stats = core::Cvar::find("draw_stats"))
{
cv_stats->assign(_debugstatscheckbox->value() ? 1.0f : 0.0f);
}
// wireframe
if (core::Cvar *cv_wireframe = core::Cvar::find("r_wireframe"))
{
cv_wireframe->assign(_debugwireframecheckbox->value() ? 1.0f : 0.0f);
}
// keypress
if (core::Cvar *cv_keypress = core::Cvar::find("draw_keypress"))
{
cv_keypress->assign(_debugkeypresscheckbox->value() ? 1.0f : 0.0f);
}
// physics
if (core::Cvar *cv_physics = core::Cvar::find("r_physics"))
{
cv_physics->assign(_debugphysicscheckbox->value() ? 1.0f : 0.0f);
}
}
void GraphicsSettingsMenu::resize()
{
const float padding = ui::UI::padding;
const float margin = ui::UI::margin;
// resize title label
_titlelabel->set_size(width() - padding * 2.0f, _titlelabel->font()->height());
_titlelabel->set_location(padding, padding);
// resize close button
_closebutton->set_size(_titlelabel->font()->height(), _titlelabel->font()->height());
_closebutton->set_location(_titlelabel->width() - _closebutton->width(), 0);
// resize content frame
_frame->set_location(_titlelabel->left(), _titlelabel->bottom() + padding);
_frame->set_size(_titlelabel->width(), height() - _titlelabel->bottom() - padding * 2.0f);
//---- inside _frame ----
const float h = _frame->font()->height() + margin;
const float w = _frame->width() - ui::UI::elementsize.width() - 3.0f * padding;
// OPTIONS
_optionslabel->set_location(padding, padding);
_optionslabel->set_size(ui::UI::elementsize.width(),h);
// fullscreen
_optionfullscreencheckbox->set_location(_optionslabel->right() + padding, _optionslabel->top());
_optionfullscreencheckbox->set_size(w, h);
// grid
_optiongridcheckbox->set_location(_optionslabel->right() + padding, _optionfullscreencheckbox->bottom() + margin);
_optiongridcheckbox->set_size(w, h);
// sky
_optionskycheckbox->set_location(_optionslabel->right() + padding, _optiongridcheckbox->bottom() + margin);
_optionskycheckbox->set_size(w, h);
// particles
_optionparticlescheckbox->set_location(_optionslabel->right() + padding, _optionskycheckbox->bottom() + margin);
_optionparticlescheckbox->set_size(w, h);
// indicators
_optionindicatorscheckbox->set_location(_optionslabel->right() + padding, _optionparticlescheckbox->bottom() + margin);
_optionindicatorscheckbox->set_size(w, h);
// DEBUG OPTIONS
_debuglabel->set_location(padding, _optionindicatorscheckbox->bottom() + padding);
_debuglabel->set_size(ui::UI::elementsize.width(), h);
// stats
_debugstatscheckbox->set_location(_debuglabel->right() + padding, _debuglabel->top());
_debugstatscheckbox->set_size(w, h);
// wireframe
_debugwireframecheckbox->set_location(_debuglabel->right() + padding, _debugstatscheckbox->bottom() + margin);
_debugwireframecheckbox->set_size(w,h);
// keypress
_debugkeypresscheckbox->set_location(_debuglabel->right() + padding, _debugwireframecheckbox->bottom() + margin);
_debugkeypresscheckbox->set_size(w,h);
// physics
_debugphysicscheckbox->set_location(_debuglabel->right() + padding, _debugkeypresscheckbox->bottom() + margin);
_debugphysicscheckbox->set_size(w,h);
// resize apply button
_applybutton->set_size(ui::UI::elementsize);
_applybutton->set_location(
(_frame->width() - 2.0f * ui::UI::elementsize.width() - padding) * 0.5f,
_frame->height() - _applybutton->height() - padding
);
// resize reset button
_resetbutton->set_size(ui::UI::elementsize);
_resetbutton->set_location(_applybutton->right() + padding, _applybutton->top());
}
bool GraphicsSettingsMenu::on_emit(ui::Widget *sender, const ui::Widget::Event event, void *data)
{
if (sender == _closebutton)
{
if (event == ui::Widget::EventButtonClicked)
{
parent()->hide();
return true;
}
}
else if (sender == _applybutton)
{
if (event == ui::Widget::EventButtonClicked)
{
apply();
return true;
}
}
else if (sender == _resetbutton)
{
if (event == ui::Widget::EventButtonClicked)
{
refresh();
return true;
}
}
return Window::on_emit(sender, event, data);
}
} // namespace client
|