~ubuntu-branches/ubuntu/trusty/teeworlds/trusty-updates

« back to all changes in this revision

Viewing changes to src/game/client/gc_menu.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jack Coulter
  • Date: 2008-04-13 18:48:12 UTC
  • Revision ID: james.westby@ubuntu.com-20080413184812-efc80waq2er6p1bs
Tags: upstream-0.4.2
ImportĀ upstreamĀ versionĀ 0.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
 
2
#include <stdio.h>
 
3
#include <math.h>
 
4
#include <string.h>
 
5
#include <stdlib.h>
 
6
 
 
7
#include <game/g_math.h>
 
8
#include <game/g_vmath.h>
 
9
 
 
10
extern "C" {
 
11
        #include <engine/e_system.h>
 
12
        #include <engine/e_client_interface.h>
 
13
        #include <engine/e_config.h>
 
14
        #include <engine/client/ec_font.h>
 
15
}
 
16
 
 
17
#include "../g_version.h"
 
18
#include "../g_protocol.h"
 
19
 
 
20
#include "../generated/gc_data.h"
 
21
#include "gc_render.h"
 
22
#include "gc_anim.h"
 
23
#include "gc_skin.h"
 
24
#include "gc_ui.h"
 
25
#include "gc_client.h"
 
26
#include <mastersrv/mastersrv.h>
 
27
 
 
28
extern data_container *data;
 
29
 
 
30
extern bool menu_active;
 
31
//extern bool menu_game_active;
 
32
 
 
33
static bool need_restart = false;
 
34
 
 
35
enum
 
36
{
 
37
        POPUP_NONE=0,
 
38
        POPUP_FIRST_LAUNCH,
 
39
        POPUP_CONNECTING,
 
40
        POPUP_DISCONNECTED,
 
41
        POPUP_PASSWORD,
 
42
        POPUP_QUIT, 
 
43
};
 
44
 
 
45
static int popup = POPUP_NONE;
 
46
 
 
47
static vec4 gui_color(0.65f,0.78f,0.9f, 0.5f);
 
48
 
 
49
static vec4 color_tabbar_inactive_outgame(0,0,0,0.25f);
 
50
static vec4 color_tabbar_active_outgame(0,0,0,0.5f);
 
51
 
 
52
static float color_ingame_scale_i = 0.5f;
 
53
static float color_ingame_scale_a = 0.2f;
 
54
static vec4 color_tabbar_inactive_ingame(gui_color.r*color_ingame_scale_i, gui_color.g*color_ingame_scale_i, gui_color.b*color_ingame_scale_i,0.75f);
 
55
static vec4 color_tabbar_active_ingame(gui_color.r*color_ingame_scale_a, gui_color.g*color_ingame_scale_a, gui_color.b*color_ingame_scale_a,0.85f);
 
56
 
 
57
static vec4 color_tabbar_inactive = color_tabbar_inactive_outgame;
 
58
static vec4 color_tabbar_active = color_tabbar_active_outgame;
 
59
 
 
60
enum
 
61
{
 
62
        PAGE_NEWS=0,
 
63
        PAGE_GAME,
 
64
        PAGE_SERVER_INFO,
 
65
        PAGE_INTERNET,
 
66
        PAGE_LAN,
 
67
        PAGE_FAVORITES,
 
68
        PAGE_SETTINGS,
 
69
        PAGE_SYSTEM,
 
70
};
 
71
 
 
72
static int menu_game_page = PAGE_GAME;
 
73
 
 
74
static void ui_draw_browse_icon(int what, const RECT *r)
 
75
{
 
76
        gfx_texture_set(data->images[IMAGE_BROWSEICONS].id);
 
77
        gfx_quads_begin();
 
78
        select_sprite(SPRITE_BROWSE_PROGRESS1); // default
 
79
        if(what == -1)
 
80
        {
 
81
        }
 
82
        else if(what <= 100)
 
83
        {
 
84
                if(what < 66)
 
85
                        select_sprite(SPRITE_BROWSE_PROGRESS2);
 
86
                else
 
87
                        select_sprite(SPRITE_BROWSE_PROGRESS3);
 
88
        }
 
89
        else if(what&0x100)
 
90
        {
 
91
                select_sprite(SPRITE_BROWSE_LOCK);
 
92
        }
 
93
        gfx_quads_drawTL(r->x,r->y,r->w,r->h);
 
94
        gfx_quads_end();
 
95
}
 
96
 
 
97
static vec4 button_color_mul(const void *id)
 
98
{
 
99
        if(ui_active_item() == id)
 
100
                return vec4(1,1,1,0.5f);
 
101
        else if(ui_hot_item() == id)
 
102
                return vec4(1,1,1,1.5f);
 
103
        return vec4(1,1,1,1);
 
104
}
 
105
 
 
106
static void ui_draw_menu_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
 
107
{
 
108
        ui_draw_rect(r, vec4(1,1,1,0.5f)*button_color_mul(id), CORNER_ALL, 5.0f);
 
109
        ui_do_label(r, text, 18.0f, 0);
 
110
}
 
111
 
 
112
static void ui_draw_keyselect_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
 
113
{
 
114
        ui_draw_rect(r, vec4(1,1,1,0.5f)*button_color_mul(id), CORNER_ALL, 5.0f);
 
115
        ui_do_label(r, text, 14.0f, 0);
 
116
}
 
117
 
 
118
static void ui_draw_menu_tab_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
 
119
{
 
120
        if(checked)
 
121
                ui_draw_rect(r, color_tabbar_active, CORNER_T, 10.0f);
 
122
        else
 
123
                ui_draw_rect(r, color_tabbar_inactive, CORNER_T, 10.0f);
 
124
        ui_do_label(r, text, 22.0f, 0);
 
125
}
 
126
 
 
127
 
 
128
static void ui_draw_settings_tab_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
 
129
{
 
130
        if(checked)
 
131
                ui_draw_rect(r, color_tabbar_active, CORNER_R, 10.0f);
 
132
        else
 
133
                ui_draw_rect(r, color_tabbar_inactive, CORNER_R, 10.0f);
 
134
        ui_do_label(r, text, 20.0f, 0);
 
135
}
 
136
 
 
137
static void ui_draw_grid_header(const void *id, const char *text, int checked, const RECT *r, const void *extra)
 
138
{
 
139
        if(checked)
 
140
                ui_draw_rect(r, vec4(1,1,1,0.5f), CORNER_T, 5.0f);
 
141
        RECT t;
 
142
        ui_vsplit_l(r, 5.0f, 0, &t);
 
143
        ui_do_label(&t, text, 14.0f, -1);
 
144
}
 
145
 
 
146
static void ui_draw_list_row(const void *id, const char *text, int checked, const RECT *r, const void *extra)
 
147
{
 
148
        if(checked)
 
149
        {
 
150
                RECT sr = *r;
 
151
                ui_margin(&sr, 1.5f, &sr);
 
152
                ui_draw_rect(&sr, vec4(1,1,1,0.5f), CORNER_ALL, 4.0f);
 
153
        }
 
154
        ui_do_label(r, text, 14.0f, -1);
 
155
}
 
156
 
 
157
static void ui_draw_checkbox_common(const void *id, const char *text, const char *boxtext, const RECT *r)
 
158
{
 
159
        RECT c = *r;
 
160
        RECT t = *r;
 
161
        c.w = c.h;
 
162
        t.x += c.w;
 
163
        t.w -= c.w;
 
164
        ui_vsplit_l(&t, 5.0f, 0, &t);
 
165
        
 
166
        ui_margin(&c, 2.0f, &c);
 
167
        ui_draw_rect(&c, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 3.0f);
 
168
        c.y += 2;
 
169
        ui_do_label(&c, boxtext, 12.0f, 0);
 
170
        ui_do_label(&t, text, 14.0f, -1);       
 
171
}
 
172
 
 
173
static void ui_draw_checkbox(const void *id, const char *text, int checked, const RECT *r, const void *extra)
 
174
{
 
175
        ui_draw_checkbox_common(id, text, checked?"X":"", r);
 
176
}
 
177
 
 
178
 
 
179
static void ui_draw_checkbox_number(const void *id, const char *text, int checked, const RECT *r, const void *extra)
 
180
{
 
181
        char buf[16];
 
182
        str_format(buf, sizeof(buf), "%d", checked);
 
183
        ui_draw_checkbox_common(id, text, buf, r);
 
184
}
 
185
 
 
186
int ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, float font_size, bool hidden=false)
 
187
{
 
188
    int inside = ui_mouse_inside(rect);
 
189
        int r = 0;
 
190
        static int at_index = 0;
 
191
 
 
192
        if(ui_last_active_item() == id)
 
193
        {
 
194
                int len = strlen(str);
 
195
 
 
196
                if (inside && ui_mouse_button(0))
 
197
                {
 
198
                        int mx_rel = (int)(ui_mouse_x() - rect->x);
 
199
 
 
200
                        for (int i = 1; i <= len; i++)
 
201
                        {
 
202
                                if (gfx_text_width(0, font_size, str, i) + 10 > mx_rel)
 
203
                                {
 
204
                                        at_index = i - 1;
 
205
                                        break;
 
206
                                }
 
207
 
 
208
                                if (i == len)
 
209
                                        at_index = len;
 
210
                        }
 
211
                }
 
212
 
 
213
                for(int i = 0; i < inp_num_events(); i++)
 
214
                {
 
215
                        INPUT_EVENT e = inp_get_event(i);
 
216
                        char c = e.ch;
 
217
                        int k = e.key;
 
218
 
 
219
                        if (at_index > len)
 
220
                                at_index = len;
 
221
                        
 
222
                        if (!(c >= 0 && c < 32))
 
223
                        {
 
224
                                if (len < str_size - 1 && at_index < str_size - 1)
 
225
                                {
 
226
                                        memmove(str + at_index + 1, str + at_index, len - at_index + 1);
 
227
                                        str[at_index] = c;
 
228
                                        at_index++;
 
229
                                }
 
230
                        }
 
231
                        
 
232
                        if(e.flags&INPFLAG_PRESS)
 
233
                        {
 
234
                                if (k == KEY_BACKSPACE && at_index > 0)
 
235
                                {
 
236
                                        memmove(str + at_index - 1, str + at_index, len - at_index + 1);
 
237
                                        at_index--;
 
238
                                }
 
239
                                else if (k == KEY_DEL && at_index < len)
 
240
                                        memmove(str + at_index, str + at_index + 1, len - at_index);
 
241
                                else if (k == KEY_ENTER)
 
242
                                        ui_clear_last_active_item();
 
243
                                else if (k == KEY_LEFT && at_index > 0)
 
244
                                        at_index--;
 
245
                                else if (k == KEY_RIGHT && at_index < len)
 
246
                                        at_index++;
 
247
                                else if (k == KEY_HOME)
 
248
                                        at_index = 0;
 
249
                                else if (k == KEY_END)
 
250
                                        at_index = len;
 
251
                        }
 
252
                }
 
253
                
 
254
                r = 1;
 
255
        }
 
256
 
 
257
        bool just_got_active = false;
 
258
        
 
259
        if(ui_active_item() == id)
 
260
        {
 
261
                if(!ui_mouse_button(0))
 
262
                        ui_set_active_item(0);
 
263
        }
 
264
        else if(ui_hot_item() == id)
 
265
        {
 
266
                if(ui_mouse_button(0))
 
267
                {
 
268
                        if (ui_last_active_item() != id)
 
269
                                just_got_active = true;
 
270
                        ui_set_active_item(id);
 
271
                }
 
272
        }
 
273
        
 
274
        if(inside)
 
275
                ui_set_hot_item(id);
 
276
 
 
277
        RECT textbox = *rect;
 
278
        ui_draw_rect(&textbox, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f);
 
279
        ui_vmargin(&textbox, 5.0f, &textbox);
 
280
        
 
281
        const char *display_str = str;
 
282
        char stars[128];
 
283
        
 
284
        if(hidden)
 
285
        {
 
286
                unsigned s = strlen(str);
 
287
                if(s >= sizeof(stars))
 
288
                        s = sizeof(stars)-1;
 
289
                memset(stars, '*', s);
 
290
                stars[s] = 0;
 
291
                display_str = stars;
 
292
        }
 
293
 
 
294
        ui_do_label(&textbox, display_str, font_size, -1);
 
295
        
 
296
        if (ui_last_active_item() == id && !just_got_active)
 
297
        {
 
298
                float w = gfx_text_width(0, font_size, display_str, at_index);
 
299
                textbox.x += w*ui_scale();
 
300
                ui_do_label(&textbox, "_", font_size, -1);
 
301
        }
 
302
 
 
303
        return r;
 
304
}
 
305
 
 
306
float ui_do_scrollbar_v(const void *id, const RECT *rect, float current)
 
307
{
 
308
        RECT handle;
 
309
        static float offset_y;
 
310
        ui_hsplit_t(rect, 33, &handle, 0);
 
311
 
 
312
        handle.y += (rect->h-handle.h)*current;
 
313
 
 
314
        /* logic */
 
315
    float ret = current;
 
316
    int inside = ui_mouse_inside(&handle);
 
317
 
 
318
        if(ui_active_item() == id)
 
319
        {
 
320
                if(!ui_mouse_button(0))
 
321
                        ui_set_active_item(0);
 
322
                
 
323
                float min = rect->y;
 
324
                float max = rect->h-handle.h;
 
325
                float cur = ui_mouse_y()-offset_y;
 
326
                ret = (cur-min)/max;
 
327
                if(ret < 0.0f) ret = 0.0f;
 
328
                if(ret > 1.0f) ret = 1.0f;
 
329
        }
 
330
        else if(ui_hot_item() == id)
 
331
        {
 
332
                if(ui_mouse_button(0))
 
333
                {
 
334
                        ui_set_active_item(id);
 
335
                        offset_y = ui_mouse_y()-handle.y;
 
336
                }
 
337
        }
 
338
        
 
339
        if(inside)
 
340
                ui_set_hot_item(id);
 
341
 
 
342
        // render
 
343
        RECT rail;
 
344
        ui_vmargin(rect, 5.0f, &rail);
 
345
        ui_draw_rect(&rail, vec4(1,1,1,0.25f), 0, 0.0f);
 
346
 
 
347
        RECT slider = handle;
 
348
        slider.w = rail.x-slider.x;
 
349
        ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_L, 2.5f);
 
350
        slider.x = rail.x+rail.w;
 
351
        ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_R, 2.5f);
 
352
 
 
353
        slider = handle;
 
354
        ui_margin(&slider, 5.0f, &slider);
 
355
        ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f);
 
356
        
 
357
    return ret;
 
358
}
 
359
 
 
360
 
 
361
 
 
362
float ui_do_scrollbar_h(const void *id, const RECT *rect, float current)
 
363
{
 
364
        RECT handle;
 
365
        static float offset_x;
 
366
        ui_vsplit_l(rect, 33, &handle, 0);
 
367
 
 
368
        handle.x += (rect->w-handle.w)*current;
 
369
 
 
370
        /* logic */
 
371
    float ret = current;
 
372
    int inside = ui_mouse_inside(&handle);
 
373
 
 
374
        if(ui_active_item() == id)
 
375
        {
 
376
                if(!ui_mouse_button(0))
 
377
                        ui_set_active_item(0);
 
378
                
 
379
                float min = rect->x;
 
380
                float max = rect->w-handle.w;
 
381
                float cur = ui_mouse_x()-offset_x;
 
382
                ret = (cur-min)/max;
 
383
                if(ret < 0.0f) ret = 0.0f;
 
384
                if(ret > 1.0f) ret = 1.0f;
 
385
        }
 
386
        else if(ui_hot_item() == id)
 
387
        {
 
388
                if(ui_mouse_button(0))
 
389
                {
 
390
                        ui_set_active_item(id);
 
391
                        offset_x = ui_mouse_x()-handle.x;
 
392
                }
 
393
        }
 
394
        
 
395
        if(inside)
 
396
                ui_set_hot_item(id);
 
397
 
 
398
        // render
 
399
        RECT rail;
 
400
        ui_hmargin(rect, 5.0f, &rail);
 
401
        ui_draw_rect(&rail, vec4(1,1,1,0.25f), 0, 0.0f);
 
402
 
 
403
        RECT slider = handle;
 
404
        slider.h = rail.y-slider.y;
 
405
        ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_T, 2.5f);
 
406
        slider.y = rail.y+rail.h;
 
407
        ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_B, 2.5f);
 
408
 
 
409
        slider = handle;
 
410
        ui_margin(&slider, 5.0f, &slider);
 
411
        ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f);
 
412
        
 
413
    return ret;
 
414
}
 
415
 
 
416
int ui_do_key_reader(void *id, const RECT *rect, int key)
 
417
{
 
418
        // process
 
419
        static bool mouse_released = true;
 
420
        int inside = ui_mouse_inside(rect);
 
421
        int new_key = key;
 
422
        
 
423
        if(!ui_mouse_button(0))
 
424
                mouse_released = true;
 
425
 
 
426
        if(ui_active_item() == id)
 
427
        {
 
428
                for(int i = 0; i < inp_num_events(); i++)
 
429
                {
 
430
                        INPUT_EVENT e = inp_get_event(i);
 
431
                        if(e.flags&INPFLAG_PRESS && e.key && e.key != KEY_ESC)
 
432
                        {
 
433
                                new_key = e.key;
 
434
                                ui_set_active_item(0);
 
435
                                mouse_released = false;
 
436
                                inp_clear_events();
 
437
                                break;
 
438
                        }
 
439
                }
 
440
        }
 
441
        else if(ui_hot_item() == id)
 
442
        {
 
443
                if(ui_mouse_button(0) && mouse_released)
 
444
                        ui_set_active_item(id);
 
445
        }
 
446
        
 
447
        if(inside)
 
448
                ui_set_hot_item(id);
 
449
 
 
450
        // draw
 
451
        if (ui_active_item() == id)
 
452
                ui_draw_keyselect_button(id, "???", 0, rect, 0);
 
453
        else
 
454
        {
 
455
                if(key == 0)
 
456
                        ui_draw_keyselect_button(id, "", 0, rect, 0);
 
457
                else
 
458
                        ui_draw_keyselect_button(id, inp_key_name(key), 0, rect, 0);
 
459
        }
 
460
        return new_key;
 
461
}
 
462
 
 
463
 
 
464
static int menu2_render_menubar(RECT r)
 
465
{
 
466
        RECT box = r;
 
467
        RECT button;
 
468
        
 
469
        int active_page = config.ui_page;
 
470
        int new_page = -1;
 
471
        
 
472
        if(client_state() != CLIENTSTATE_OFFLINE)
 
473
                active_page = menu_game_page;
 
474
        
 
475
        if(client_state() == CLIENTSTATE_OFFLINE)
 
476
        {
 
477
                /* offline menus */
 
478
                if(0) // this is not done yet
 
479
                {
 
480
                        ui_vsplit_l(&box, 90.0f, &button, &box);
 
481
                        static int news_button=0;
 
482
                        if (ui_do_button(&news_button, "News", active_page==PAGE_NEWS, &button, ui_draw_menu_tab_button, 0))
 
483
                                new_page = PAGE_NEWS;
 
484
                        ui_vsplit_l(&box, 30.0f, 0, &box); 
 
485
                }
 
486
 
 
487
                ui_vsplit_l(&box, 110.0f, &button, &box);
 
488
                static int internet_button=0;
 
489
                if (ui_do_button(&internet_button, "Internet", active_page==PAGE_INTERNET, &button, ui_draw_menu_tab_button, 0))
 
490
                {
 
491
                        client_serverbrowse_refresh(0);
 
492
                        new_page = PAGE_INTERNET;
 
493
                }
 
494
 
 
495
                ui_vsplit_l(&box, 4.0f, 0, &box);
 
496
                ui_vsplit_l(&box, 90.0f, &button, &box);
 
497
                static int lan_button=0;
 
498
                if (ui_do_button(&lan_button, "LAN", active_page==PAGE_LAN, &button, ui_draw_menu_tab_button, 0))
 
499
                {
 
500
                        client_serverbrowse_refresh(1);
 
501
                        new_page = PAGE_LAN;
 
502
                }
 
503
 
 
504
                if(0) // this one is not done yet
 
505
                {
 
506
                        ui_vsplit_l(&box, 4.0f, 0, &box);
 
507
                        ui_vsplit_l(&box, 120.0f, &button, &box);
 
508
                        static int favorites_button=0;
 
509
                        if (ui_do_button(&favorites_button, "Favorites", active_page==PAGE_FAVORITES, &button, ui_draw_menu_tab_button, 0))
 
510
                                new_page  = PAGE_FAVORITES;
 
511
                }
 
512
 
 
513
 
 
514
        }
 
515
        else
 
516
        {
 
517
                /* online menus */
 
518
                ui_vsplit_l(&box, 90.0f, &button, &box);
 
519
                static int game_button=0;
 
520
                if (ui_do_button(&game_button, "Game", active_page==PAGE_GAME, &button, ui_draw_menu_tab_button, 0))
 
521
                        new_page = PAGE_GAME;
 
522
 
 
523
                ui_vsplit_l(&box, 4.0f, 0, &box);
 
524
                ui_vsplit_l(&box, 140.0f, &button, &box);
 
525
                static int server_info_button=0;
 
526
                if (ui_do_button(&server_info_button, "Server Info", active_page==PAGE_SERVER_INFO, &button, ui_draw_menu_tab_button, 0))
 
527
                        new_page = PAGE_SERVER_INFO;
 
528
                        
 
529
                ui_vsplit_l(&box, 30.0f, 0, &box);
 
530
        }
 
531
                
 
532
        /*
 
533
        ui_vsplit_r(&box, 110.0f, &box, &button);
 
534
        static int system_button=0;
 
535
        if (ui_do_button(&system_button, "System", config.ui_page==PAGE_SYSTEM, &button, ui_draw_menu_tab_button, 0))
 
536
                config.ui_page = PAGE_SYSTEM;
 
537
                
 
538
        ui_vsplit_r(&box, 30.0f, &box, 0);
 
539
        */
 
540
        
 
541
        ui_vsplit_r(&box, 110.0f, &box, &button);
 
542
        static int quit_button=0;
 
543
        if (ui_do_button(&quit_button, "Quit", 0, &button, ui_draw_menu_tab_button, 0))
 
544
                popup = POPUP_QUIT;
 
545
 
 
546
        ui_vsplit_r(&box, 10.0f, &box, &button);
 
547
        ui_vsplit_r(&box, 110.0f, &box, &button);
 
548
        static int settings_button=0;
 
549
        if (ui_do_button(&settings_button, "Settings", active_page==PAGE_SETTINGS, &button, ui_draw_menu_tab_button, 0))
 
550
                new_page = PAGE_SETTINGS;
 
551
        
 
552
        if(new_page != -1)
 
553
        {
 
554
                if(client_state() == CLIENTSTATE_OFFLINE)
 
555
                        config.ui_page = new_page;
 
556
                else
 
557
                        menu_game_page = new_page;
 
558
        }
 
559
                
 
560
        return 0;
 
561
}
 
562
 
 
563
static void menu2_render_background()
 
564
{
 
565
        RECT s = *ui_screen();
 
566
 
 
567
        gfx_texture_set(-1);
 
568
        gfx_quads_begin();
 
569
                vec4 bottom(gui_color.r*0.6f, gui_color.g*0.6f, gui_color.b*0.6f, 1.0f);
 
570
                vec4 top(gui_color.r, gui_color.g, gui_color.b, 1.0f);
 
571
                gfx_setcolorvertex(0, top.r, top.g, top.b, top.a);
 
572
                gfx_setcolorvertex(1, top.r, top.g, top.b, top.a);
 
573
                gfx_setcolorvertex(2, bottom.r, bottom.g, bottom.b, bottom.a);
 
574
                gfx_setcolorvertex(3, bottom.r, bottom.g, bottom.b, bottom.a);
 
575
                gfx_quads_drawTL(0, 0, s.w, s.h);
 
576
        gfx_quads_end();
 
577
        
 
578
        if(data->images[IMAGE_BANNER].id != 0)
 
579
        {
 
580
                gfx_texture_set(data->images[IMAGE_BANNER].id);
 
581
                gfx_quads_begin();
 
582
                gfx_setcolor(0,0,0,0.05f);
 
583
                gfx_quads_setrotation(-pi/4+0.15f);
 
584
                gfx_quads_draw(400, 300, 1000, 250);
 
585
                gfx_quads_end();
 
586
        }
 
587
}
 
588
 
 
589
void render_loading(float percent)
 
590
{
 
591
        // need up date this here to get correct
 
592
        vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f));
 
593
        gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f);
 
594
        
 
595
    RECT screen = *ui_screen();
 
596
        gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
 
597
        
 
598
        menu2_render_background();
 
599
 
 
600
        float tw;
 
601
 
 
602
        float w = 700;
 
603
        float h = 200;
 
604
        float x = screen.w/2-w/2;
 
605
        float y = screen.h/2-h/2;
 
606
 
 
607
        gfx_blend_normal();
 
608
 
 
609
        gfx_texture_set(-1);
 
610
        gfx_quads_begin();
 
611
        gfx_setcolor(0,0,0,0.50f);
 
612
        draw_round_rect(x, y, w, h, 40.0f);
 
613
        gfx_quads_end();
 
614
 
 
615
 
 
616
        const char *caption = "Loading";
 
617
 
 
618
        tw = gfx_text_width(0, 48.0f, caption, -1);
 
619
        RECT r;
 
620
        r.x = x;
 
621
        r.y = y+20;
 
622
        r.w = w;
 
623
        r.h = h;
 
624
        ui_do_label(&r, caption, 48.0f, 0, -1);
 
625
 
 
626
        gfx_texture_set(-1);
 
627
        gfx_quads_begin();
 
628
        gfx_setcolor(1,1,1,0.75f);
 
629
        draw_round_rect(x+40, y+h-75, (w-80)*percent, 25, 5.0f);
 
630
        gfx_quads_end();
 
631
 
 
632
        gfx_swap();
 
633
}
 
634
 
 
635
static void menu2_render_serverbrowser(RECT main_view)
 
636
{
 
637
        ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
 
638
        
 
639
        RECT view;
 
640
        ui_margin(&main_view, 10.0f, &view);
 
641
        
 
642
        RECT headers;
 
643
        RECT filters;
 
644
        RECT status;
 
645
        RECT toolbox;
 
646
        RECT server_details;
 
647
        RECT server_scoreboard;
 
648
 
 
649
        //ui_hsplit_t(&view, 20.0f, &status, &view);
 
650
        ui_hsplit_b(&view, 110.0f, &view, &filters);
 
651
 
 
652
        // split off a piece for details and scoreboard
 
653
        ui_vsplit_r(&view, 200.0f, &view, &server_details);
 
654
 
 
655
        // server list
 
656
        ui_hsplit_t(&view, 16.0f, &headers, &view);
 
657
        //ui_hsplit_b(&view, 110.0f, &view, &filters);
 
658
        ui_hsplit_b(&view, 5.0f, &view, 0);
 
659
        ui_hsplit_b(&view, 20.0f, &view, &status);
 
660
 
 
661
        //ui_vsplit_r(&filters, 300.0f, &filters, &toolbox);
 
662
        //ui_vsplit_r(&filters, 150.0f, &filters, 0);
 
663
 
 
664
        ui_vsplit_mid(&filters, &filters, &toolbox);
 
665
        ui_vsplit_r(&filters, 50.0f, &filters, 0);
 
666
        
 
667
        // split of the scrollbar
 
668
        ui_draw_rect(&headers, vec4(1,1,1,0.25f), CORNER_T, 5.0f);
 
669
        ui_vsplit_r(&headers, 20.0f, &headers, 0);
 
670
        
 
671
        struct column
 
672
        {
 
673
                int id;
 
674
                int sort;
 
675
                const char *caption;
 
676
                int direction;
 
677
                float width;
 
678
                int flags;
 
679
                RECT rect;
 
680
                RECT spacer;
 
681
        };
 
682
        
 
683
        enum
 
684
        {
 
685
                FIXED=1,
 
686
                SPACER=2,
 
687
                
 
688
                COL_FLAGS=0,
 
689
                COL_NAME,
 
690
                COL_GAMETYPE,
 
691
                COL_MAP,
 
692
                COL_PLAYERS,
 
693
                COL_PING,
 
694
                COL_PROGRESS,
 
695
                COL_VERSION,
 
696
        };
 
697
        
 
698
        static column cols[] = {
 
699
                {-1,                    -1,                                             " ",            -1, 10.0f, 0, {0}, {0}},
 
700
                {COL_FLAGS,             -1,                                             " ",            -1, 20.0f, 0, {0}, {0}},
 
701
                {COL_NAME,              BROWSESORT_NAME,                "Name",         0, 300.0f, 0, {0}, {0}},
 
702
                {COL_GAMETYPE,  BROWSESORT_GAMETYPE,    "Type",         1, 50.0f, 0, {0}, {0}},
 
703
                {COL_MAP,               BROWSESORT_MAP,                 "Map",          1, 100.0f, 0, {0}, {0}},
 
704
                {COL_PLAYERS,   BROWSESORT_NUMPLAYERS,  "Players",      1, 60.0f, 0, {0}, {0}},
 
705
                {-1,                    -1,                                             " ",            1, 10.0f, 0, {0}, {0}},
 
706
                {COL_PING,              BROWSESORT_PING,                "Ping",         1, 40.0f, FIXED, {0}, {0}},
 
707
        };
 
708
        
 
709
        int num_cols = sizeof(cols)/sizeof(column);
 
710
        
 
711
        // do layout
 
712
        for(int i = 0; i < num_cols; i++)
 
713
        {
 
714
                if(cols[i].direction == -1)
 
715
                {
 
716
                        ui_vsplit_l(&headers, cols[i].width, &cols[i].rect, &headers);
 
717
                        
 
718
                        if(i+1 < num_cols)
 
719
                        {
 
720
                                //cols[i].flags |= SPACER;
 
721
                                ui_vsplit_l(&headers, 2, &cols[i].spacer, &headers);
 
722
                        }
 
723
                }
 
724
        }
 
725
        
 
726
        for(int i = num_cols-1; i >= 0; i--)
 
727
        {
 
728
                if(cols[i].direction == 1)
 
729
                {
 
730
                        ui_vsplit_r(&headers, cols[i].width, &headers, &cols[i].rect);
 
731
                        ui_vsplit_r(&headers, 2, &headers, &cols[i].spacer);
 
732
                }
 
733
        }
 
734
        
 
735
        for(int i = 0; i < num_cols; i++)
 
736
        {
 
737
                if(cols[i].direction == 0)
 
738
                        cols[i].rect = headers;
 
739
        }
 
740
        
 
741
        // do headers
 
742
        for(int i = 0; i < num_cols; i++)
 
743
        {
 
744
                if(ui_do_button(cols[i].caption, cols[i].caption, config.b_sort == cols[i].sort, &cols[i].rect, ui_draw_grid_header, 0))
 
745
                {
 
746
                        if(cols[i].sort != -1)
 
747
                        {
 
748
                                if(config.b_sort == cols[i].sort)
 
749
                                        config.b_sort_order ^= 1;
 
750
                                else
 
751
                                        config.b_sort_order = 0;
 
752
                                config.b_sort = cols[i].sort;
 
753
                        }
 
754
                }
 
755
        }
 
756
        
 
757
        ui_draw_rect(&view, vec4(0,0,0,0.15f), 0, 0);
 
758
        
 
759
        RECT scroll;
 
760
        ui_vsplit_r(&view, 15, &view, &scroll);
 
761
        
 
762
        int num_servers = client_serverbrowse_sorted_num();
 
763
        
 
764
        int num = (int)(view.h/cols[0].rect.h);
 
765
        static int scrollbar = 0;
 
766
        static float scrollvalue = 0;
 
767
        //static int selected_index = -1;
 
768
        ui_hmargin(&scroll, 5.0f, &scroll);
 
769
        scrollvalue = ui_do_scrollbar_v(&scrollbar, &scroll, scrollvalue);
 
770
        
 
771
        int scrollnum = num_servers-num+10;
 
772
        if(scrollnum > 0)
 
773
        {
 
774
                if(inp_key_presses(KEY_MOUSE_WHEEL_UP))
 
775
                        scrollvalue -= 1.0f/scrollnum;
 
776
                if(inp_key_presses(KEY_MOUSE_WHEEL_DOWN))
 
777
                        scrollvalue += 1.0f/scrollnum;
 
778
                        
 
779
                if(scrollvalue < 0) scrollvalue = 0;
 
780
                if(scrollvalue > 1) scrollvalue = 1;
 
781
        }
 
782
        else
 
783
                scrollnum = 0;
 
784
 
 
785
        // set clipping
 
786
        ui_clip_enable(&view);
 
787
        
 
788
        int start = (int)(scrollnum*scrollvalue);
 
789
        if(start < 0)
 
790
                start = 0;
 
791
        
 
792
        RECT original_view = view;
 
793
        view.y -= scrollvalue*scrollnum*cols[0].rect.h;
 
794
        
 
795
        int new_selected = -1;
 
796
        int selected_index = -1;
 
797
        int num_players = 0;
 
798
 
 
799
        for (int i = 0; i < num_servers; i++)
 
800
        {
 
801
                SERVER_INFO *item = client_serverbrowse_sorted_get(i);
 
802
                num_players += item->num_players;
 
803
        }
 
804
        
 
805
        for (int i = 0; i < num_servers; i++)
 
806
        {
 
807
                int item_index = i;
 
808
                SERVER_INFO *item = client_serverbrowse_sorted_get(item_index);
 
809
                RECT row;
 
810
        RECT select_hit_box;
 
811
                        
 
812
                int selected = strcmp(item->address, config.ui_server_address) == 0; //selected_index==item_index;
 
813
                
 
814
                
 
815
                ui_hsplit_t(&view, 17.0f, &row, &view);
 
816
                select_hit_box = row;
 
817
        
 
818
                if(selected)
 
819
                {
 
820
                        selected_index = i;
 
821
                        RECT r = row;
 
822
                        ui_margin(&r, 1.5f, &r);
 
823
                        ui_draw_rect(&r, vec4(1,1,1,0.5f), CORNER_ALL, 4.0f);
 
824
                }
 
825
 
 
826
 
 
827
                // make sure that only those in view can be selected
 
828
                if(row.y+row.h > original_view.y)
 
829
                {
 
830
                        if(select_hit_box.y < original_view.y) // clip the selection
 
831
                        {
 
832
                                select_hit_box.h -= original_view.y-select_hit_box.y;
 
833
                                select_hit_box.y = original_view.y;
 
834
                        }
 
835
                        
 
836
                        if(ui_do_button(item, "", selected, &select_hit_box, 0, 0))
 
837
                        {
 
838
                                new_selected = item_index;
 
839
                        }
 
840
                }
 
841
                
 
842
                // check if we need to do more
 
843
                if(row.y > original_view.y+original_view.h)
 
844
                        break;
 
845
 
 
846
                for(int c = 0; c < num_cols; c++)
 
847
                {
 
848
                        RECT button;
 
849
                        char temp[64];
 
850
                        button.x = cols[c].rect.x;
 
851
                        button.y = row.y;
 
852
                        button.h = row.h;
 
853
                        button.w = cols[c].rect.w;
 
854
                        
 
855
                        //int s = 0;
 
856
                        int id = cols[c].id;
 
857
 
 
858
                        //s = ui_do_button(item, "L", l, &button, ui_draw_browse_icon, 0);
 
859
                        
 
860
                        if(id == COL_FLAGS)
 
861
                        {
 
862
                                if(item->flags&1)
 
863
                                        ui_draw_browse_icon(0x100, &button);
 
864
                        }
 
865
                        else if(id == COL_NAME)
 
866
                        {
 
867
                                TEXT_CURSOR cursor;
 
868
                                gfx_text_set_cursor(&cursor, button.x, button.y, 12.0f, TEXTFLAG_RENDER);
 
869
                                
 
870
                                if(config.b_filter_string[0] && (item->quicksearch_hit&BROWSEQUICK_SERVERNAME))
 
871
                                {
 
872
                                        // highlight the parts that matches
 
873
                                        const char *s = str_find_nocase(item->name, config.b_filter_string);
 
874
                                        if(s)
 
875
                                        {
 
876
                                                gfx_text_ex(&cursor, item->name, (int)(s-item->name));
 
877
                                                gfx_text_color(0.4f,0.4f,1.0f,1);
 
878
                                                gfx_text_ex(&cursor, s, strlen(config.b_filter_string));
 
879
                                                gfx_text_color(1,1,1,1);
 
880
                                                gfx_text_ex(&cursor, s+strlen(config.b_filter_string), -1);
 
881
                                        }
 
882
                                        else
 
883
                                                gfx_text_ex(&cursor, item->name, -1);
 
884
                                }
 
885
                                else
 
886
                                        gfx_text_ex(&cursor, item->name, -1);
 
887
                        }
 
888
                        else if(id == COL_MAP)
 
889
                                ui_do_label(&button, item->map, 12.0f, -1);
 
890
                        else if(id == COL_PLAYERS)
 
891
                        {
 
892
                                str_format(temp, sizeof(temp), "%i/%i", item->num_players, item->max_players);
 
893
                                if(config.b_filter_string[0] && (item->quicksearch_hit&BROWSEQUICK_PLAYERNAME))
 
894
                                        gfx_text_color(0.4f,0.4f,1.0f,1);
 
895
                                ui_do_label(&button, temp, 12.0f, 1);
 
896
                                gfx_text_color(1,1,1,1);
 
897
                        }
 
898
                        else if(id == COL_PING)
 
899
                        {
 
900
                                str_format(temp, sizeof(temp), "%i", item->latency);
 
901
                                ui_do_label(&button, temp, 12.0f, 1);
 
902
                        }
 
903
                        else if(id == COL_PROGRESS)
 
904
                        {
 
905
                                if(item->progression > 100)
 
906
                                        item->progression = 100;
 
907
                                ui_draw_browse_icon(item->progression, &button);
 
908
                        }
 
909
                        else if(id == COL_VERSION)
 
910
                        {
 
911
                                const char *version = item->version;
 
912
                                if(strcmp(version, "0.3 e2d7973c6647a13c") == 0) // TODO: remove me later on
 
913
                                        version = "0.3.0";
 
914
                                ui_do_label(&button, version, 12.0f, 1);
 
915
                        }                       
 
916
                        else if(id == COL_GAMETYPE)
 
917
                        {
 
918
                                const char *type = "???";
 
919
                                if(item->game_type == GAMETYPE_DM) type = "DM";
 
920
                                else if(item->game_type == GAMETYPE_TDM) type = "TDM";
 
921
                                else if(item->game_type == GAMETYPE_CTF) type = "CTF";
 
922
                                ui_do_label(&button, type, 12.0f, 0);
 
923
                        }
 
924
                }
 
925
        }
 
926
 
 
927
        ui_clip_disable();
 
928
        
 
929
        if(new_selected != -1)
 
930
        {
 
931
                // select the new server
 
932
                SERVER_INFO *item = client_serverbrowse_sorted_get(new_selected);
 
933
                strncpy(config.ui_server_address, item->address, sizeof(config.ui_server_address));
 
934
                if(inp_mouse_doubleclick())
 
935
                        client_connect(config.ui_server_address);
 
936
        }
 
937
        
 
938
        SERVER_INFO *selected_server = client_serverbrowse_sorted_get(selected_index);
 
939
        RECT server_header;
 
940
 
 
941
        ui_vsplit_l(&server_details, 10.0f, 0x0, &server_details);
 
942
 
 
943
        // split off a piece to use for scoreboard
 
944
        ui_hsplit_t(&server_details, 140.0f, &server_details, &server_scoreboard);
 
945
        ui_hsplit_b(&server_details, 10.0f, &server_details, 0x0);
 
946
 
 
947
        // server details
 
948
        const float font_size = 12.0f;
 
949
        ui_hsplit_t(&server_details, 20.0f, &server_header, &server_details);
 
950
        ui_draw_rect(&server_header, vec4(1,1,1,0.25f), CORNER_T, 4.0f);
 
951
        ui_draw_rect(&server_details, vec4(0,0,0,0.15f), CORNER_B, 4.0f);
 
952
        ui_vsplit_l(&server_header, 8.0f, 0x0, &server_header);
 
953
        ui_do_label(&server_header, "Server Details: ", font_size+2.0f, -1);
 
954
 
 
955
        ui_vsplit_l(&server_details, 5.0f, 0x0, &server_details);
 
956
 
 
957
        ui_margin(&server_details, 3.0f, &server_details);
 
958
 
 
959
        if (selected_server)
 
960
        {
 
961
                RECT row;
 
962
                static char *labels[] = { "Version:", "Game Type:", "Progression:", "Ping:" };
 
963
 
 
964
                RECT left_column;
 
965
                RECT right_column;
 
966
 
 
967
                ui_vsplit_l(&server_details, 5.0f, 0x0, &server_details);
 
968
                ui_vsplit_l(&server_details, 80.0f, &left_column, &right_column);
 
969
 
 
970
                for (int i = 0; i < 4; i++)
 
971
                {
 
972
                        ui_hsplit_t(&left_column, 15.0f, &row, &left_column);
 
973
                        ui_do_label(&row, labels[i], font_size, -1);
 
974
                }
 
975
 
 
976
                ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
 
977
                ui_do_label(&row, selected_server->version, font_size, -1);
 
978
 
 
979
                ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
 
980
                static char *game_types[] = { "DM", "TDM", "CTF" };
 
981
                if (selected_server->game_type >= 0 && selected_server->game_type < (int)(sizeof(game_types)/sizeof(*game_types)))
 
982
                        ui_do_label(&row, game_types[selected_server->game_type], font_size, -1);
 
983
 
 
984
                char temp[16];
 
985
 
 
986
                if(selected_server->progression < 0)
 
987
                        str_format(temp, sizeof(temp), "N/A");
 
988
                else
 
989
                        str_format(temp, sizeof(temp), "%d%%", selected_server->progression);
 
990
                ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
 
991
                ui_do_label(&row, temp, font_size, -1);
 
992
 
 
993
                str_format(temp, sizeof(temp), "%d", selected_server->latency);
 
994
                ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
 
995
                ui_do_label(&row, temp, font_size, -1);
 
996
        }
 
997
        
 
998
        // server scoreboard
 
999
        ui_hsplit_b(&server_scoreboard, 10.0f, &server_scoreboard, 0x0);
 
1000
        ui_hsplit_t(&server_scoreboard, 20.0f, &server_header, &server_scoreboard);
 
1001
        ui_draw_rect(&server_header, vec4(1,1,1,0.25f), CORNER_T, 4.0f);
 
1002
        ui_draw_rect(&server_scoreboard, vec4(0,0,0,0.15f), CORNER_B, 4.0f);
 
1003
        ui_vsplit_l(&server_header, 8.0f, 0x0, &server_header);
 
1004
        ui_do_label(&server_header, "Scoreboard: ", font_size+2.0f, -1);
 
1005
 
 
1006
        ui_vsplit_l(&server_scoreboard, 5.0f, 0x0, &server_scoreboard);
 
1007
 
 
1008
        ui_margin(&server_scoreboard, 3.0f, &server_scoreboard);
 
1009
 
 
1010
        if (selected_server)
 
1011
        {
 
1012
                for (int i = 0; i < selected_server->num_players; i++)
 
1013
                {
 
1014
                        RECT row;
 
1015
                        char temp[16];
 
1016
                        ui_hsplit_t(&server_scoreboard, 16.0f, &row, &server_scoreboard);
 
1017
 
 
1018
                        str_format(temp, sizeof(temp), "%d", selected_server->players[i].score);
 
1019
                        ui_do_label(&row, temp, font_size, -1);
 
1020
 
 
1021
                        ui_vsplit_l(&row, 25.0f, 0x0, &row);
 
1022
                
 
1023
                        TEXT_CURSOR cursor;
 
1024
                        gfx_text_set_cursor(&cursor, row.x, row.y, 12.0f, TEXTFLAG_RENDER);
 
1025
                        
 
1026
                        const char *name = selected_server->players[i].name;
 
1027
                        if(config.b_filter_string[0])
 
1028
                        {
 
1029
                                // highlight the parts that matches
 
1030
                                const char *s = str_find_nocase(name, config.b_filter_string);
 
1031
                                if(s)
 
1032
                                {
 
1033
                                        gfx_text_ex(&cursor, name, (int)(s-name));
 
1034
                                        gfx_text_color(0.4f,0.4f,1,1);
 
1035
                                        gfx_text_ex(&cursor, s, strlen(config.b_filter_string));
 
1036
                                        gfx_text_color(1,1,1,1);
 
1037
                                        gfx_text_ex(&cursor, s+strlen(config.b_filter_string), -1);
 
1038
                                }
 
1039
                                else
 
1040
                                        gfx_text_ex(&cursor, name, -1);
 
1041
                        }
 
1042
                        else
 
1043
                                gfx_text_ex(&cursor, name, -1);
 
1044
                        
 
1045
                        /*ui_do_label(&row, selected_server->player_names[i], font_size, -1);*/
 
1046
                }
 
1047
        }
 
1048
        
 
1049
        RECT button;
 
1050
        RECT types;
 
1051
        ui_hsplit_t(&filters, 20.0f, &button, &filters);
 
1052
        ui_do_label(&button, "Quick search: ", 14.0f, -1);
 
1053
        ui_vsplit_l(&button, 95.0f, 0, &button);
 
1054
        ui_do_edit_box(&config.b_filter_string, &button, config.b_filter_string, sizeof(config.b_filter_string), 14.0f);
 
1055
 
 
1056
        ui_vsplit_l(&filters, 180.0f, &filters, &types);
 
1057
 
 
1058
        // render filters
 
1059
        ui_hsplit_t(&filters, 20.0f, &button, &filters);
 
1060
        if (ui_do_button(&config.b_filter_empty, "Has people playing", config.b_filter_empty, &button, ui_draw_checkbox, 0))
 
1061
                config.b_filter_empty ^= 1;
 
1062
 
 
1063
        ui_hsplit_t(&filters, 20.0f, &button, &filters);
 
1064
        if (ui_do_button(&config.b_filter_full, "Server not full", config.b_filter_full, &button, ui_draw_checkbox, 0))
 
1065
                config.b_filter_full ^= 1;
 
1066
 
 
1067
        ui_hsplit_t(&filters, 20.0f, &button, &filters);
 
1068
        if (ui_do_button(&config.b_filter_pw, "No password", config.b_filter_pw, &button, ui_draw_checkbox, 0))
 
1069
                config.b_filter_pw ^= 1;
 
1070
 
 
1071
        ui_hsplit_t(&filters, 20.0f, &button, &filters);
 
1072
        if (ui_do_button((char *)&config.b_filter_compatversion, "Compatible Version", config.b_filter_compatversion, &button, ui_draw_checkbox, 0))
 
1073
                config.b_filter_compatversion ^= 1;
 
1074
 
 
1075
        // game types
 
1076
        ui_hsplit_t(&types, 20.0f, &button, &types);
 
1077
        if (ui_do_button(&config.b_filter_gametype, "DM", config.b_filter_gametype&(1<<GAMETYPE_DM), &button, ui_draw_checkbox, 0))
 
1078
                config.b_filter_gametype ^= (1<<GAMETYPE_DM);
 
1079
 
 
1080
        ui_hsplit_t(&types, 20.0f, &button, &types);
 
1081
        if (ui_do_button((char *)&config.b_filter_gametype + 1, "TDM", config.b_filter_gametype&(1<<GAMETYPE_TDM), &button, ui_draw_checkbox, 0))
 
1082
                config.b_filter_gametype ^= (1<<GAMETYPE_TDM);
 
1083
 
 
1084
        ui_hsplit_t(&types, 20.0f, &button, &types);
 
1085
        if (ui_do_button((char *)&config.b_filter_gametype + 2, "CTF", config.b_filter_gametype&(1<<GAMETYPE_CTF), &button, ui_draw_checkbox, 0))
 
1086
                config.b_filter_gametype ^= (1<<GAMETYPE_CTF);
 
1087
 
 
1088
        // ping
 
1089
        ui_hsplit_t(&types, 2.0f, &button, &types);
 
1090
        ui_hsplit_t(&types, 20.0f, &button, &types);
 
1091
        {
 
1092
                RECT editbox;
 
1093
                ui_vsplit_l(&button, 40.0f, &editbox, &button);
 
1094
                ui_vsplit_l(&button, 5.0f, &button, &button);
 
1095
                
 
1096
                char buf[8];
 
1097
                str_format(buf, sizeof(buf), "%d", config.b_filter_ping);
 
1098
                ui_do_edit_box(&config.b_filter_ping, &editbox, buf, sizeof(buf), 14.0f);
 
1099
                config.b_filter_ping = atoi(buf);
 
1100
                
 
1101
                ui_do_label(&button, "Maximum ping", 14.0f, -1);
 
1102
        }
 
1103
 
 
1104
 
 
1105
        // render status
 
1106
        ui_draw_rect(&status, vec4(1,1,1,0.25f), CORNER_B, 5.0f);
 
1107
        ui_vmargin(&status, 50.0f, &status);
 
1108
        char buf[128];
 
1109
        str_format(buf, sizeof(buf), "%d of %d servers, %d players", client_serverbrowse_sorted_num(), client_serverbrowse_num(), num_players);
 
1110
        ui_do_label(&status, buf, 14.0f, -1);
 
1111
 
 
1112
        // render toolbox
 
1113
        {
 
1114
                RECT buttons, button;
 
1115
                ui_hsplit_b(&toolbox, 25.0f, &toolbox, &buttons);
 
1116
 
 
1117
                ui_vsplit_r(&buttons, 100.0f, &buttons, &button);
 
1118
                ui_vmargin(&button, 2.0f, &button);
 
1119
                static int join_button = 0;
 
1120
                if(ui_do_button(&join_button, "Connect", 0, &button, ui_draw_menu_button, 0))
 
1121
                        client_connect(config.ui_server_address);
 
1122
 
 
1123
                ui_vsplit_r(&buttons, 20.0f, &buttons, &button);
 
1124
                ui_vsplit_r(&buttons, 100.0f, &buttons, &button);
 
1125
                ui_vmargin(&button, 2.0f, &button);
 
1126
                static int refresh_button = 0;
 
1127
                if(ui_do_button(&refresh_button, "Refresh", 0, &button, ui_draw_menu_button, 0))
 
1128
                {
 
1129
                        if(config.ui_page == PAGE_INTERNET)
 
1130
                                client_serverbrowse_refresh(0);
 
1131
                        else if(config.ui_page == PAGE_LAN)
 
1132
                                client_serverbrowse_refresh(1);
 
1133
                }
 
1134
 
 
1135
                //ui_vsplit_r(&buttons, 30.0f, &buttons, &button);
 
1136
                ui_vsplit_l(&buttons, 120.0f, &button, &buttons);
 
1137
                static int clear_button = 0;
 
1138
                if(ui_do_button(&clear_button, "Reset Filter", 0, &button, ui_draw_menu_button, 0))
 
1139
                {
 
1140
                        config.b_filter_full = 0;
 
1141
                        config.b_filter_empty = 0;
 
1142
                        config.b_filter_pw = 0;
 
1143
                        config.b_filter_ping = 999;
 
1144
                        config.b_filter_gametype = 0xf;
 
1145
                        config.b_filter_compatversion = 1;
 
1146
                        config.b_filter_string[0] = 0;
 
1147
                }
 
1148
 
 
1149
                
 
1150
                ui_hsplit_t(&toolbox, 20.0f, &button, &toolbox);
 
1151
                ui_do_label(&button, "Host address:", 14.0f, -1);
 
1152
                ui_vsplit_l(&button, 100.0f, 0, &button);
 
1153
                ui_do_edit_box(&config.ui_server_address, &button, config.ui_server_address, sizeof(config.ui_server_address), 14.0f);
 
1154
        }
 
1155
}
 
1156
 
 
1157
static void menu2_render_settings_player(RECT main_view)
 
1158
{
 
1159
        RECT button;
 
1160
        RECT skinselection;
 
1161
        ui_vsplit_l(&main_view, 300.0f, &main_view, &skinselection);
 
1162
 
 
1163
 
 
1164
        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1165
 
 
1166
        // render settings
 
1167
        {       
 
1168
                ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1169
                ui_do_label(&button, "Name:", 14.0, -1);
 
1170
                ui_vsplit_l(&button, 80.0f, 0, &button);
 
1171
                ui_vsplit_l(&button, 180.0f, &button, 0);
 
1172
                ui_do_edit_box(config.player_name, &button, config.player_name, sizeof(config.player_name), 14.0f);
 
1173
 
 
1174
                static int dynamic_camera_button = 0;
 
1175
                ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1176
                if(ui_do_button(&dynamic_camera_button, "Dynamic Camera", config.cl_mouse_deadzone != 0, &button, ui_draw_checkbox, 0))
 
1177
                {
 
1178
                        
 
1179
                        if(config.cl_mouse_deadzone)
 
1180
                        {
 
1181
                                config.cl_mouse_followfactor = 0;
 
1182
                                config.cl_mouse_max_distance = 400;
 
1183
                                config.cl_mouse_deadzone = 0;
 
1184
                        }
 
1185
                        else
 
1186
                        {
 
1187
                                config.cl_mouse_followfactor = 60;
 
1188
                                config.cl_mouse_max_distance = 1000;
 
1189
                                config.cl_mouse_deadzone = 300;
 
1190
                        }
 
1191
                }
 
1192
 
 
1193
                ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1194
                if (ui_do_button(&config.cl_autoswitch_weapons, "Switch weapon on pickup", config.cl_autoswitch_weapons, &button, ui_draw_checkbox, 0))
 
1195
                        config.cl_autoswitch_weapons ^= 1;
 
1196
                        
 
1197
                ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1198
                if (ui_do_button(&config.cl_nameplates, "Show name plates", config.cl_nameplates, &button, ui_draw_checkbox, 0))
 
1199
                        config.cl_nameplates ^= 1;
 
1200
 
 
1201
                //if(config.cl_nameplates)
 
1202
                {
 
1203
                        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1204
                        ui_vsplit_l(&button, 15.0f, 0, &button);
 
1205
                        if (ui_do_button(&config.cl_nameplates_always, "Always show name plates", config.cl_nameplates_always, &button, ui_draw_checkbox, 0))
 
1206
                                config.cl_nameplates_always ^= 1;
 
1207
                }
 
1208
                        
 
1209
                ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1210
                
 
1211
                ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1212
                if (ui_do_button(&config.player_color_body, "Custom colors", config.player_use_custom_color, &button, ui_draw_checkbox, 0))
 
1213
                        config.player_use_custom_color = config.player_use_custom_color?0:1;
 
1214
                
 
1215
                if(config.player_use_custom_color)
 
1216
                {
 
1217
                        int *colors[2];
 
1218
                        colors[0] = &config.player_color_body;
 
1219
                        colors[1] = &config.player_color_feet;
 
1220
                        
 
1221
                        const char *parts[] = {"Body", "Feet"};
 
1222
                        const char *labels[] = {"Hue", "Sat.", "Lht."};
 
1223
                        static int color_slider[2][3] = {{0}};
 
1224
                        //static float v[2][3] = {{0, 0.5f, 0.25f}, {0, 0.5f, 0.25f}};
 
1225
                                
 
1226
                        for(int i = 0; i < 2; i++)
 
1227
                        {
 
1228
                                RECT text;
 
1229
                                ui_hsplit_t(&main_view, 20.0f, &text, &main_view);
 
1230
                                ui_vsplit_l(&text, 15.0f, 0, &text);
 
1231
                                ui_do_label(&text, parts[i], 14.0f, -1);
 
1232
                                
 
1233
                                int prevcolor = *colors[i];
 
1234
                                int color = 0;
 
1235
                                for(int s = 0; s < 3; s++)
 
1236
                                {
 
1237
                                        RECT text;
 
1238
                                        ui_hsplit_t(&main_view, 19.0f, &button, &main_view);
 
1239
                                        ui_vsplit_l(&button, 30.0f, 0, &button);
 
1240
                                        ui_vsplit_l(&button, 30.0f, &text, &button);
 
1241
                                        ui_vsplit_r(&button, 5.0f, &button, 0);
 
1242
                                        ui_hsplit_t(&button, 4.0f, 0, &button);
 
1243
                                        
 
1244
                                        float k = ((prevcolor>>((2-s)*8))&0xff)  / 255.0f;
 
1245
                                        k = ui_do_scrollbar_h(&color_slider[i][s], &button, k);
 
1246
                                        color <<= 8;
 
1247
                                        color += clamp((int)(k*255), 0, 255);
 
1248
                                        ui_do_label(&text, labels[s], 15.0f, -1);
 
1249
                                         
 
1250
                                }
 
1251
                                
 
1252
                                *colors[i] = color;
 
1253
                                ui_hsplit_t(&main_view, 5.0f, 0, &main_view);
 
1254
                        }
 
1255
                }
 
1256
        }
 
1257
                
 
1258
        // draw header
 
1259
        RECT header, footer;
 
1260
        ui_hsplit_t(&skinselection, 20, &header, &skinselection);
 
1261
        ui_draw_rect(&header, vec4(1,1,1,0.25f), CORNER_T, 5.0f); 
 
1262
        ui_do_label(&header, "Skins", 18.0f, 0);
 
1263
 
 
1264
        // draw footers 
 
1265
        ui_hsplit_b(&skinselection, 20, &skinselection, &footer);
 
1266
        ui_draw_rect(&footer, vec4(1,1,1,0.25f), CORNER_B, 5.0f); 
 
1267
        ui_vsplit_l(&footer, 10.0f, 0, &footer);
 
1268
 
 
1269
        // modes
 
1270
        ui_draw_rect(&skinselection, vec4(0,0,0,0.15f), 0, 0);
 
1271
 
 
1272
        RECT scroll;
 
1273
        ui_vsplit_r(&skinselection, 15, &skinselection, &scroll);
 
1274
 
 
1275
        RECT list = skinselection;
 
1276
        ui_hsplit_t(&list, 50, &button, &list);
 
1277
        
 
1278
        int num = (int)(skinselection.h/button.h);
 
1279
        static float scrollvalue = 0;
 
1280
        static int scrollbar = 0;
 
1281
        ui_hmargin(&scroll, 5.0f, &scroll);
 
1282
        scrollvalue = ui_do_scrollbar_v(&scrollbar, &scroll, scrollvalue);
 
1283
 
 
1284
        int start = (int)((skin_num()-num)*scrollvalue);
 
1285
        if(start < 0)
 
1286
                start = 0;
 
1287
                
 
1288
        animstate state;
 
1289
        anim_eval(&data->animations[ANIM_BASE], 0, &state);
 
1290
        anim_eval_add(&state, &data->animations[ANIM_IDLE], 0, 1.0f);
 
1291
        //anim_eval_add(&state, &data->animations[ANIM_WALK], fmod(client_localtime(), 1.0f), 1.0f);
 
1292
                
 
1293
        for(int i = start; i < start+num && i < skin_num(); i++)
 
1294
        {
 
1295
                const skin *s = skin_get(i);
 
1296
                
 
1297
                // no special skins
 
1298
                if(s->name[0] == 'x' && s->name[1] == '_')
 
1299
                {
 
1300
                        num++;
 
1301
                        continue;
 
1302
                }
 
1303
                
 
1304
                char buf[128];
 
1305
                str_format(buf, sizeof(buf), "%s", s->name);
 
1306
                int selected = 0;
 
1307
                if(strcmp(s->name, config.player_skin) == 0)
 
1308
                        selected = 1;
 
1309
                
 
1310
                tee_render_info info;
 
1311
                info.texture = s->org_texture;
 
1312
                info.color_body = vec4(1,1,1,1);
 
1313
                info.color_feet = vec4(1,1,1,1);
 
1314
                if(config.player_use_custom_color)
 
1315
                {
 
1316
                        info.color_body = skin_get_color(config.player_color_body);
 
1317
                        info.color_feet = skin_get_color(config.player_color_feet);
 
1318
                        info.texture = s->color_texture;
 
1319
                }
 
1320
                        
 
1321
                info.size = ui_scale()*50.0f;
 
1322
                
 
1323
                RECT icon;
 
1324
                RECT text;
 
1325
                ui_vsplit_l(&button, 50.0f, &icon, &text);
 
1326
                
 
1327
                if(ui_do_button(s, "", selected, &button, ui_draw_list_row, 0))
 
1328
                        config_set_player_skin(&config, s->name);
 
1329
                
 
1330
                ui_hsplit_t(&text, 12.0f, 0, &text); // some margin from the top
 
1331
                ui_do_label(&text, buf, 18.0f, 0);
 
1332
                
 
1333
                ui_hsplit_t(&icon, 5.0f, 0, &icon); // some margin from the top
 
1334
                render_tee(&state, &info, 0, vec2(1, 0), vec2(icon.x+icon.w/2, icon.y+icon.h/2));
 
1335
                
 
1336
                if(config.debug)
 
1337
                {
 
1338
                        gfx_texture_set(-1);
 
1339
                        gfx_quads_begin();
 
1340
                        gfx_setcolor(s->blood_color.r, s->blood_color.g, s->blood_color.b, 1.0f);
 
1341
                        gfx_quads_drawTL(icon.x, icon.y, 12, 12);
 
1342
                        gfx_quads_end();
 
1343
                }
 
1344
                
 
1345
                ui_hsplit_t(&list, 50, &button, &list);
 
1346
        }
 
1347
}
 
1348
 
 
1349
typedef void (*assign_func_callback)(CONFIGURATION *config, int value);
 
1350
 
 
1351
static void menu2_render_settings_controls(RECT main_view)
 
1352
{
 
1353
        RECT right_part;
 
1354
        ui_vsplit_l(&main_view, 300.0f, &main_view, &right_part);
 
1355
 
 
1356
        {
 
1357
                RECT button, label;
 
1358
                ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1359
                ui_vsplit_l(&button, 110.0f, &label, &button);
 
1360
                ui_do_label(&label, "Mouse sens.", 14.0f, -1);
 
1361
                ui_hmargin(&button, 2.0f, &button);
 
1362
                config.inp_mousesens = (int)(ui_do_scrollbar_h(&config.inp_mousesens, &button, (config.inp_mousesens-5)/500.0f)*500.0f)+5;
 
1363
                //*key.key = ui_do_key_reader(key.key, &button, *key.key);
 
1364
                ui_hsplit_t(&main_view, 20.0f, 0, &main_view);
 
1365
        }
 
1366
        
 
1367
        typedef struct 
 
1368
        {
 
1369
                const char *name;
 
1370
                const char *command;
 
1371
                int keyid;
 
1372
        } KEYINFO;
 
1373
 
 
1374
        KEYINFO keys[] = 
 
1375
        {
 
1376
                { "Move Left:", "+left", 0},
 
1377
                { "Move Right:", "+right", 0 },
 
1378
                { "Jump:", "+jump", 0 },
 
1379
                { "Fire:", "+fire", 0 },
 
1380
                { "Hook:", "+hook", 0 },
 
1381
                { "Hammer:", "+weapon1", 0 },
 
1382
                { "Pistol:", "+weapon2", 0 },
 
1383
                { "Shotgun:", "+weapon3", 0 },
 
1384
                { "Grenade:", "+weapon4", 0 },
 
1385
                { "Rifle:", "+weapon5", 0 },
 
1386
                { "Next Weapon:", "+nextweapon", 0 },
 
1387
                { "Prev. Weapon:", "+prevweapon", 0 },
 
1388
                { "Emoticon:", "+emote", 0 },
 
1389
                { "Chat:", "chat all", 0 },
 
1390
                { "Team Chat:", "chat team", 0 },
 
1391
                { "Console:", "toggle_local_console", 0 },
 
1392
                { "Remote Console:", "toggle_remote_console", 0 },
 
1393
                { "Screenshot:", "screenshot", 0 },
 
1394
        };
 
1395
 
 
1396
        const int key_count = sizeof(keys) / sizeof(KEYINFO);
 
1397
        
 
1398
        // this is kinda slow, but whatever
 
1399
        for(int keyid = 0; keyid < KEY_LAST; keyid++)
 
1400
        {
 
1401
                const char *bind = binds_get(keyid);
 
1402
                if(!bind[0])
 
1403
                        continue;
 
1404
                        
 
1405
                for(int i = 0; i < key_count; i++)
 
1406
                        if(strcmp(bind, keys[i].command) == 0)
 
1407
                        {
 
1408
                                keys[i].keyid = keyid;
 
1409
                                break;
 
1410
                        }
 
1411
        }
 
1412
        
 
1413
        for (int i = 0; i < key_count; i++)
 
1414
    {
 
1415
                KEYINFO key = keys[i];
 
1416
        RECT button, label;
 
1417
        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1418
        ui_vsplit_l(&button, 110.0f, &label, &button);
 
1419
        
 
1420
                ui_do_label(&label, key.name, 14.0f, -1);
 
1421
                int oldid = key.keyid;
 
1422
                int newid = ui_do_key_reader((void *)keys[i].name, &button, oldid);
 
1423
                if(newid != oldid)
 
1424
                {
 
1425
                        binds_set(oldid, "");
 
1426
                        binds_set(newid, keys[i].command);
 
1427
                }
 
1428
        ui_hsplit_t(&main_view, 5.0f, 0, &main_view);
 
1429
    }   
 
1430
    
 
1431
    // defaults
 
1432
        RECT button;
 
1433
        ui_hsplit_b(&right_part, 25.0f, &right_part, &button);
 
1434
        ui_vsplit_l(&button, 50.0f, 0, &button);
 
1435
        if (ui_do_button((void*)binds_default, "Reset to defaults", 0, &button, ui_draw_menu_button, 0))
 
1436
                binds_default();
 
1437
}
 
1438
 
 
1439
static void menu2_render_settings_graphics(RECT main_view)
 
1440
{
 
1441
        RECT button;
 
1442
        char buf[128];
 
1443
        
 
1444
        static const int MAX_RESOLUTIONS = 256;
 
1445
        static VIDEO_MODE modes[MAX_RESOLUTIONS];
 
1446
        static int num_modes = -1;
 
1447
        
 
1448
        if(num_modes == -1)
 
1449
                num_modes = gfx_get_video_modes(modes, MAX_RESOLUTIONS);
 
1450
        
 
1451
        RECT modelist;
 
1452
        ui_vsplit_l(&main_view, 300.0f, &main_view, &modelist);
 
1453
        
 
1454
        // draw allmodes switch
 
1455
        RECT header, footer;
 
1456
        ui_hsplit_t(&modelist, 20, &button, &modelist);
 
1457
        if (ui_do_button(&config.gfx_display_all_modes, "Show only supported", config.gfx_display_all_modes^1, &button, ui_draw_checkbox, 0))
 
1458
        {
 
1459
                config.gfx_display_all_modes ^= 1;
 
1460
                num_modes = gfx_get_video_modes(modes, MAX_RESOLUTIONS);
 
1461
        }
 
1462
        
 
1463
        // draw header
 
1464
        ui_hsplit_t(&modelist, 20, &header, &modelist);
 
1465
        ui_draw_rect(&header, vec4(1,1,1,0.25f), CORNER_T, 5.0f); 
 
1466
        ui_do_label(&header, "Display Modes", 14.0f, 0);
 
1467
 
 
1468
        // draw footers 
 
1469
        ui_hsplit_b(&modelist, 20, &modelist, &footer);
 
1470
        str_format(buf, sizeof(buf), "Current: %dx%d %d bit", config.gfx_screen_width, config.gfx_screen_height, config.gfx_color_depth);
 
1471
        ui_draw_rect(&footer, vec4(1,1,1,0.25f), CORNER_B, 5.0f); 
 
1472
        ui_vsplit_l(&footer, 10.0f, 0, &footer);
 
1473
        ui_do_label(&footer, buf, 14.0f, -1);
 
1474
 
 
1475
        // modes
 
1476
        ui_draw_rect(&modelist, vec4(0,0,0,0.15f), 0, 0);
 
1477
 
 
1478
        RECT scroll;
 
1479
        ui_vsplit_r(&modelist, 15, &modelist, &scroll);
 
1480
 
 
1481
        RECT list = modelist;
 
1482
        ui_hsplit_t(&list, 20, &button, &list);
 
1483
        
 
1484
        int num = (int)(modelist.h/button.h);
 
1485
        static float scrollvalue = 0;
 
1486
        static int scrollbar = 0;
 
1487
        ui_hmargin(&scroll, 5.0f, &scroll);
 
1488
        scrollvalue = ui_do_scrollbar_v(&scrollbar, &scroll, scrollvalue);
 
1489
 
 
1490
        int start = (int)((num_modes-num)*scrollvalue);
 
1491
        if(start < 0)
 
1492
                start = 0;
 
1493
                
 
1494
        for(int i = start; i < start+num && i < num_modes; i++)
 
1495
        {
 
1496
                int depth = modes[i].red+modes[i].green+modes[i].blue;
 
1497
                if(depth < 16)
 
1498
                        depth = 16;
 
1499
                else if(depth > 16)
 
1500
                        depth = 24;
 
1501
                        
 
1502
                int selected = 0;
 
1503
                if(config.gfx_color_depth == depth &&
 
1504
                        config.gfx_screen_width == modes[i].width &&
 
1505
                        config.gfx_screen_height == modes[i].height)
 
1506
                {
 
1507
                        selected = 1;
 
1508
                }
 
1509
                
 
1510
                str_format(buf, sizeof(buf), "  %dx%d %d bit", modes[i].width, modes[i].height, depth);
 
1511
                if(ui_do_button(&modes[i], buf, selected, &button, ui_draw_list_row, 0))
 
1512
                {
 
1513
                        config.gfx_color_depth = depth;
 
1514
                        config.gfx_screen_width = modes[i].width;
 
1515
                        config.gfx_screen_height = modes[i].height;
 
1516
                        if(!selected)
 
1517
                                need_restart = true;
 
1518
                }
 
1519
                
 
1520
                ui_hsplit_t(&list, 20, &button, &list);
 
1521
        }
 
1522
        
 
1523
        
 
1524
        // switches
 
1525
        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1526
        if (ui_do_button(&config.gfx_fullscreen, "Fullscreen", config.gfx_fullscreen, &button, ui_draw_checkbox, 0))
 
1527
        {
 
1528
                config.gfx_fullscreen ^= 1;
 
1529
                need_restart = true;
 
1530
        }
 
1531
 
 
1532
        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1533
        if (ui_do_button(&config.gfx_vsync, "V-Sync", config.gfx_vsync, &button, ui_draw_checkbox, 0))
 
1534
                config.gfx_vsync ^= 1;
 
1535
 
 
1536
        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1537
        if (ui_do_button(&config.gfx_fsaa_samples, "FSAA samples", config.gfx_fsaa_samples, &button, ui_draw_checkbox_number, 0))
 
1538
        {
 
1539
                if(config.gfx_fsaa_samples < 2) config.gfx_fsaa_samples = 2;
 
1540
                else if(config.gfx_fsaa_samples < 4) config.gfx_fsaa_samples = 4;
 
1541
                else if(config.gfx_fsaa_samples < 6) config.gfx_fsaa_samples = 6;
 
1542
                else if(config.gfx_fsaa_samples < 8) config.gfx_fsaa_samples = 8;
 
1543
                else if(config.gfx_fsaa_samples < 16) config.gfx_fsaa_samples = 16;
 
1544
                else if(config.gfx_fsaa_samples >= 16) config.gfx_fsaa_samples = 0;
 
1545
                need_restart = true;
 
1546
        }
 
1547
                
 
1548
        ui_hsplit_t(&main_view, 40.0f, &button, &main_view);
 
1549
        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1550
        if (ui_do_button(&config.gfx_texture_quality, "Quality Textures", config.gfx_texture_quality, &button, ui_draw_checkbox, 0))
 
1551
        {
 
1552
                config.gfx_texture_quality ^= 1;
 
1553
                need_restart = true;
 
1554
        }
 
1555
 
 
1556
        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1557
        if (ui_do_button(&config.gfx_texture_compression, "Texture Compression", config.gfx_texture_compression, &button, ui_draw_checkbox, 0))
 
1558
        {
 
1559
                config.gfx_texture_compression ^= 1;
 
1560
                need_restart = true;
 
1561
        }
 
1562
 
 
1563
        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1564
        if (ui_do_button(&config.gfx_high_detail, "High Detail", config.gfx_high_detail, &button, ui_draw_checkbox, 0))
 
1565
                config.gfx_high_detail ^= 1;
 
1566
 
 
1567
        //
 
1568
        
 
1569
        RECT text;
 
1570
        ui_hsplit_t(&main_view, 20.0f, 0, &main_view);
 
1571
        ui_hsplit_t(&main_view, 20.0f, &text, &main_view);
 
1572
        //ui_vsplit_l(&text, 15.0f, 0, &text);
 
1573
        ui_do_label(&text, "UI Color", 14.0f, -1);
 
1574
        
 
1575
        const char *labels[] = {"Hue", "Sat.", "Lht.", "Alpha"};
 
1576
        int *color_slider[4] = {&config.ui_color_hue, &config.ui_color_sat, &config.ui_color_lht, &config.ui_color_alpha};
 
1577
        for(int s = 0; s < 4; s++)
 
1578
        {
 
1579
                RECT text;
 
1580
                ui_hsplit_t(&main_view, 19.0f, &button, &main_view);
 
1581
                ui_vmargin(&button, 15.0f, &button);
 
1582
                ui_vsplit_l(&button, 30.0f, &text, &button);
 
1583
                ui_vsplit_r(&button, 5.0f, &button, 0);
 
1584
                ui_hsplit_t(&button, 4.0f, 0, &button);
 
1585
                
 
1586
                float k = (*color_slider[s]) / 255.0f;
 
1587
                k = ui_do_scrollbar_h(color_slider[s], &button, k);
 
1588
                *color_slider[s] = (int)(k*255.0f);
 
1589
                ui_do_label(&text, labels[s], 15.0f, -1);
 
1590
        }               
 
1591
}
 
1592
 
 
1593
static void menu2_render_settings_sound(RECT main_view)
 
1594
{
 
1595
        RECT button;
 
1596
        ui_vsplit_l(&main_view, 300.0f, &main_view, 0);
 
1597
        
 
1598
        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1599
        if (ui_do_button(&config.snd_enable, "Use Sounds", config.snd_enable, &button, ui_draw_checkbox, 0))
 
1600
        {
 
1601
                config.snd_enable ^= 1;
 
1602
                need_restart = true;
 
1603
        }
 
1604
        
 
1605
        if(!config.snd_enable)
 
1606
                return;
 
1607
        
 
1608
        ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1609
        if (ui_do_button(&config.snd_nonactive_mute, "Mute when not active", config.snd_nonactive_mute, &button, ui_draw_checkbox, 0))
 
1610
                config.snd_nonactive_mute ^= 1;
 
1611
                
 
1612
        // sample rate box
 
1613
        {
 
1614
                char buf[64];
 
1615
                str_format(buf, sizeof(buf), "%d", config.snd_rate);
 
1616
                ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1617
                ui_do_label(&button, "Sample Rate", 14.0f, -1);
 
1618
                ui_vsplit_l(&button, 110.0f, 0, &button);
 
1619
                ui_vsplit_l(&button, 180.0f, &button, 0);
 
1620
                ui_do_edit_box(&config.snd_rate, &button, buf, sizeof(buf), 14.0f);
 
1621
                int before = config.snd_rate;
 
1622
                config.snd_rate = atoi(buf);
 
1623
                
 
1624
                if(config.snd_rate != before)
 
1625
                        need_restart = true;
 
1626
 
 
1627
                if(config.snd_rate < 1)
 
1628
                        config.snd_rate = 1;
 
1629
        }
 
1630
        
 
1631
        // volume slider
 
1632
        {
 
1633
                RECT button, label;
 
1634
                ui_hsplit_t(&main_view, 5.0f, &button, &main_view);
 
1635
                ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1636
                ui_vsplit_l(&button, 110.0f, &label, &button);
 
1637
                ui_hmargin(&button, 2.0f, &button);
 
1638
                ui_do_label(&label, "Sound Volume", 14.0f, -1);
 
1639
                config.snd_volume = (int)(ui_do_scrollbar_h(&config.snd_volume, &button, config.snd_volume/100.0f)*100.0f);
 
1640
                ui_hsplit_t(&main_view, 20.0f, 0, &main_view);
 
1641
        }
 
1642
}
 
1643
 
 
1644
 
 
1645
        /*
 
1646
static void menu2_render_settings_network(RECT main_view)
 
1647
{
 
1648
        RECT button;
 
1649
        ui_vsplit_l(&main_view, 300.0f, &main_view, 0);
 
1650
        
 
1651
        {
 
1652
                ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 
1653
                ui_do_label(&button, "Rcon Password", 14.0, -1);
 
1654
                ui_vsplit_l(&button, 110.0f, 0, &button);
 
1655
                ui_vsplit_l(&button, 180.0f, &button, 0);
 
1656
                ui_do_edit_box(&config.rcon_password, &button, config.rcon_password, sizeof(config.rcon_password), true);
 
1657
        }
 
1658
}*/
 
1659
 
 
1660
static void menu2_render_settings(RECT main_view)
 
1661
{
 
1662
        static int settings_page = 0;
 
1663
        
 
1664
        // render background
 
1665
        RECT temp, tabbar;
 
1666
        ui_vsplit_r(&main_view, 120.0f, &main_view, &tabbar);
 
1667
        ui_draw_rect(&main_view, color_tabbar_active, CORNER_B|CORNER_TL, 10.0f);
 
1668
        ui_hsplit_t(&tabbar, 50.0f, &temp, &tabbar);
 
1669
        ui_draw_rect(&temp, color_tabbar_active, CORNER_R, 10.0f);
 
1670
        
 
1671
        ui_hsplit_t(&main_view, 10.0f, 0, &main_view);
 
1672
        
 
1673
        RECT button;
 
1674
        
 
1675
        const char *tabs[] = {"Player", "Controls", "Graphics", "Sound"};
 
1676
        int num_tabs = (int)(sizeof(tabs)/sizeof(*tabs));
 
1677
 
 
1678
        for(int i = 0; i < num_tabs; i++)
 
1679
        {
 
1680
                ui_hsplit_t(&tabbar, 10, &button, &tabbar);
 
1681
                ui_hsplit_t(&tabbar, 26, &button, &tabbar);
 
1682
                if(ui_do_button(tabs[i], tabs[i], settings_page == i, &button, ui_draw_settings_tab_button, 0))
 
1683
                        settings_page = i;
 
1684
        }
 
1685
        
 
1686
        ui_margin(&main_view, 10.0f, &main_view);
 
1687
        
 
1688
        if(settings_page == 0)
 
1689
                menu2_render_settings_player(main_view);
 
1690
        else if(settings_page == 1)
 
1691
                menu2_render_settings_controls(main_view);
 
1692
        else if(settings_page == 2)
 
1693
                menu2_render_settings_graphics(main_view);
 
1694
        else if(settings_page == 3)
 
1695
                menu2_render_settings_sound(main_view);
 
1696
 
 
1697
        if(need_restart)
 
1698
        {
 
1699
                RECT restart_warning;
 
1700
                ui_hsplit_b(&main_view, 40, &main_view, &restart_warning);
 
1701
                ui_do_label(&restart_warning, "You must restart the game for all settings to take effect.", 15.0f, -1, 220);
 
1702
        }
 
1703
}
 
1704
 
 
1705
static void menu2_render_news(RECT main_view)
 
1706
{
 
1707
        ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
 
1708
}
 
1709
 
 
1710
static void menu2_render_game(RECT main_view)
 
1711
{
 
1712
        RECT button;
 
1713
        ui_hsplit_t(&main_view, 45.0f, &main_view, 0);
 
1714
        ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
 
1715
 
 
1716
        ui_hsplit_t(&main_view, 10.0f, 0, &main_view);
 
1717
        ui_hsplit_t(&main_view, 25.0f, &main_view, 0);
 
1718
        ui_vmargin(&main_view, 10.0f, &main_view);
 
1719
        
 
1720
        ui_vsplit_r(&main_view, 120.0f, &main_view, &button);
 
1721
        static int disconnect_button = 0;
 
1722
        if(ui_do_button(&disconnect_button, "Disconnect", 0, &button, ui_draw_menu_button, 0))
 
1723
                client_disconnect();
 
1724
 
 
1725
        if(netobjects.local_info && netobjects.gameobj)
 
1726
        {
 
1727
                if(netobjects.local_info->team != -1)
 
1728
                {
 
1729
                        ui_vsplit_l(&main_view, 10.0f, &button, &main_view);
 
1730
                        ui_vsplit_l(&main_view, 120.0f, &button, &main_view);
 
1731
                        static int spectate_button = 0;
 
1732
                        if(ui_do_button(&spectate_button, "Spectate", 0, &button, ui_draw_menu_button, 0))
 
1733
                        {
 
1734
                                send_switch_team(-1);
 
1735
                                menu_active = false;
 
1736
                        }
 
1737
                }
 
1738
                
 
1739
                if(netobjects.gameobj->gametype == GAMETYPE_DM)
 
1740
                {
 
1741
                        if(netobjects.local_info->team != 0)
 
1742
                        {
 
1743
                                ui_vsplit_l(&main_view, 10.0f, &button, &main_view);
 
1744
                                ui_vsplit_l(&main_view, 120.0f, &button, &main_view);
 
1745
                                static int spectate_button = 0;
 
1746
                                if(ui_do_button(&spectate_button, "Join Game", 0, &button, ui_draw_menu_button, 0))
 
1747
                                {
 
1748
                                        send_switch_team(0);
 
1749
                                        menu_active = false;
 
1750
                                }
 
1751
                        }                                               
 
1752
                }
 
1753
                else
 
1754
                {
 
1755
                        if(netobjects.local_info->team != 0)
 
1756
                        {
 
1757
                                ui_vsplit_l(&main_view, 10.0f, &button, &main_view);
 
1758
                                ui_vsplit_l(&main_view, 120.0f, &button, &main_view);
 
1759
                                static int spectate_button = 0;
 
1760
                                if(ui_do_button(&spectate_button, "Join Red", 0, &button, ui_draw_menu_button, 0))
 
1761
                                {
 
1762
                                        send_switch_team(0);
 
1763
                                        menu_active = false;
 
1764
                                }
 
1765
                        }
 
1766
 
 
1767
                        if(netobjects.local_info->team != 1)
 
1768
                        {
 
1769
                                ui_vsplit_l(&main_view, 10.0f, &button, &main_view);
 
1770
                                ui_vsplit_l(&main_view, 120.0f, &button, &main_view);
 
1771
                                static int spectate_button = 0;
 
1772
                                if(ui_do_button(&spectate_button, "Join Blue", 0, &button, ui_draw_menu_button, 0))
 
1773
                                {
 
1774
                                        send_switch_team(1);
 
1775
                                        menu_active = false;
 
1776
                                }
 
1777
                        }
 
1778
                }
 
1779
        }
 
1780
}
 
1781
 
 
1782
void menu2_render_serverinfo(RECT main_view)
 
1783
{
 
1784
        // render background
 
1785
        ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
 
1786
        
 
1787
        // render motd
 
1788
        RECT view;
 
1789
        ui_margin(&main_view, 10.0f, &view);
 
1790
        //void gfx_text(void *font, float x, float y, float size, const char *text, int max_width);
 
1791
        gfx_text(0, view.x, view.y, 16, server_motd, -1);
 
1792
}
 
1793
 
 
1794
void menu_do_disconnected()
 
1795
{
 
1796
        popup = POPUP_NONE;
 
1797
        if(client_error_string() && client_error_string()[0] != 0)
 
1798
        {
 
1799
                if(strstr(client_error_string(), "password"))
 
1800
                {
 
1801
                        popup = POPUP_PASSWORD;
 
1802
                        ui_set_hot_item(&config.password);
 
1803
                        ui_set_active_item(&config.password);
 
1804
                }
 
1805
                else
 
1806
                        popup = POPUP_DISCONNECTED;
 
1807
        }
 
1808
}
 
1809
 
 
1810
void menu_do_connecting()
 
1811
{
 
1812
        popup = POPUP_CONNECTING;
 
1813
}
 
1814
 
 
1815
void menu_do_connected()
 
1816
{
 
1817
        popup = POPUP_NONE;
 
1818
}
 
1819
 
 
1820
void menu_init()
 
1821
{
 
1822
        if(config.cl_show_welcome)
 
1823
                popup = POPUP_FIRST_LAUNCH;
 
1824
        config.cl_show_welcome = 0;
 
1825
}
 
1826
 
 
1827
int menu2_render()
 
1828
{
 
1829
        if(0)
 
1830
        {
 
1831
                gfx_mapscreen(0,0,10*4/3.0f,10);
 
1832
                gfx_clear(gui_color.r, gui_color.g, gui_color.b);
 
1833
                
 
1834
                animstate state;
 
1835
                anim_eval(&data->animations[ANIM_BASE], 0, &state);
 
1836
                anim_eval_add(&state, &data->animations[ANIM_IDLE], 0, 1.0f);
 
1837
                //anim_eval_add(&state, &data->animations[ANIM_WALK], fmod(client_localtime(), 1.0f), 1.0f);
 
1838
                        
 
1839
                for(int i = 0; i < skin_num(); i++)
 
1840
                {
 
1841
                        float x = (i/8)*3;
 
1842
                        float y = (i%8);
 
1843
                        for(int c = 0; c < 2; c++)
 
1844
                        {
 
1845
                                //int colors[2] = {54090, 10998628};
 
1846
                                //int colors[2] = {65432, 9895832}; // NEW
 
1847
                                int colors[2] = {65387, 10223467}; // NEW
 
1848
                                
 
1849
                                tee_render_info info;
 
1850
                                info.texture = skin_get(i)->color_texture;
 
1851
                                info.color_feet = info.color_body = skin_get_color(colors[c]);
 
1852
                                //info.color_feet = info.color_body = vec4(1,1,1,1);
 
1853
                                info.size = 1.0f; //ui_scale()*16.0f;
 
1854
                                //render_tee(&state, &info, 0, vec2(sinf(client_localtime()*3), cosf(client_localtime()*3)), vec2(1+x+c,1+y));
 
1855
                                render_tee(&state, &info, 0, vec2(1,0), vec2(1+x+c,1+y));
 
1856
                        }
 
1857
                }
 
1858
                        
 
1859
                return 0;
 
1860
        }
 
1861
        
 
1862
    RECT screen = *ui_screen();
 
1863
        gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
 
1864
 
 
1865
        static bool first = true;
 
1866
        if(first)
 
1867
        {
 
1868
                if(config.ui_page == PAGE_INTERNET)
 
1869
                        client_serverbrowse_refresh(0);
 
1870
                else if(config.ui_page == PAGE_LAN)
 
1871
                        client_serverbrowse_refresh(1);
 
1872
                first = false;
 
1873
        }
 
1874
        
 
1875
        if(client_state() == CLIENTSTATE_ONLINE)
 
1876
        {
 
1877
                color_tabbar_inactive = color_tabbar_inactive_ingame;
 
1878
                color_tabbar_active = color_tabbar_active_ingame;
 
1879
        }
 
1880
        else
 
1881
        {
 
1882
                menu2_render_background();
 
1883
                color_tabbar_inactive = color_tabbar_inactive_outgame;
 
1884
                color_tabbar_active = color_tabbar_active_outgame;
 
1885
        }
 
1886
        
 
1887
        RECT tab_bar;
 
1888
        RECT main_view;
 
1889
 
 
1890
        // some margin around the screen
 
1891
        ui_margin(&screen, 10.0f, &screen);
 
1892
        
 
1893
        if(popup == POPUP_NONE)
 
1894
        {
 
1895
                // do tab bar
 
1896
                ui_hsplit_t(&screen, 26.0f, &tab_bar, &main_view);
 
1897
                ui_vmargin(&tab_bar, 20.0f, &tab_bar);
 
1898
                menu2_render_menubar(tab_bar);
 
1899
                        
 
1900
                // render current page
 
1901
                if(client_state() != CLIENTSTATE_OFFLINE)
 
1902
                {
 
1903
                        if(menu_game_page == PAGE_GAME)
 
1904
                                menu2_render_game(main_view);
 
1905
                        else if(menu_game_page == PAGE_SERVER_INFO)
 
1906
                                menu2_render_serverinfo(main_view);
 
1907
                        else if(menu_game_page == PAGE_SETTINGS)
 
1908
                                menu2_render_settings(main_view);
 
1909
                }
 
1910
                else if(config.ui_page == PAGE_NEWS)
 
1911
                        menu2_render_news(main_view);
 
1912
                else if(config.ui_page == PAGE_INTERNET)
 
1913
                        menu2_render_serverbrowser(main_view);
 
1914
                else if(config.ui_page == PAGE_LAN)
 
1915
                        menu2_render_serverbrowser(main_view);
 
1916
                else if(config.ui_page == PAGE_FAVORITES)
 
1917
                        menu2_render_serverbrowser(main_view);
 
1918
                else if(config.ui_page == PAGE_SETTINGS)
 
1919
                        menu2_render_settings(main_view);
 
1920
        }
 
1921
        else
 
1922
        {
 
1923
                // make sure that other windows doesn't do anything funnay!
 
1924
                //ui_set_hot_item(0);
 
1925
                //ui_set_active_item(0);
 
1926
                char buf[128];
 
1927
                const char *title = "";
 
1928
                const char *extra_text = "";
 
1929
                const char *button_text = "";
 
1930
                int extra_align = 0;
 
1931
                
 
1932
                if(popup == POPUP_CONNECTING)
 
1933
                {
 
1934
                        title = "Connecting to";
 
1935
                        extra_text = config.ui_server_address;  // TODO: query the client about the address
 
1936
                        button_text = "Abort";
 
1937
                        if(client_mapdownload_totalsize() > 0)
 
1938
                        {
 
1939
                                title = "Downloading map";
 
1940
                                str_format(buf, sizeof(buf), "%d/%d KiB", client_mapdownload_amount()/1024, client_mapdownload_totalsize()/1024);
 
1941
                                extra_text = buf;
 
1942
                        }
 
1943
                }
 
1944
                else if(popup == POPUP_DISCONNECTED)
 
1945
                {
 
1946
                        title = "Disconnected";
 
1947
                        extra_text = client_error_string();
 
1948
                        button_text = "Ok";
 
1949
                        extra_align = -1;
 
1950
                }
 
1951
                else if(popup == POPUP_PASSWORD)
 
1952
                {
 
1953
                        title = "Password Error";
 
1954
                        extra_text = client_error_string();
 
1955
                        button_text = "Try Again";
 
1956
                }
 
1957
                else if(popup == POPUP_QUIT)
 
1958
                {
 
1959
                        title = "Quit";
 
1960
                        extra_text = "Are you sure that you want to quit?";
 
1961
                }
 
1962
                else if(popup == POPUP_FIRST_LAUNCH)
 
1963
                {
 
1964
                        title = "Welcome to Teeworlds";
 
1965
                        extra_text =
 
1966
                        "As this is the first time you launch the game, please enter your nick name below. "
 
1967
                        "It's recommended that you check the settings to adjust them to your liking "
 
1968
                        "before joining a server.";
 
1969
                        button_text = "Ok";
 
1970
                        extra_align = -1;
 
1971
                }
 
1972
                
 
1973
                RECT box, part;
 
1974
                box = screen;
 
1975
                ui_vmargin(&box, 150.0f, &box);
 
1976
                ui_hmargin(&box, 150.0f, &box);
 
1977
                
 
1978
                // render the box
 
1979
                ui_draw_rect(&box, vec4(0,0,0,0.5f), CORNER_ALL, 15.0f);
 
1980
                 
 
1981
                ui_hsplit_t(&box, 20.f, &part, &box);
 
1982
                ui_hsplit_t(&box, 24.f, &part, &box);
 
1983
                ui_do_label(&part, title, 24.f, 0);
 
1984
                ui_hsplit_t(&box, 20.f, &part, &box);
 
1985
                ui_hsplit_t(&box, 24.f, &part, &box);
 
1986
                ui_vmargin(&part, 20.f, &part);
 
1987
                
 
1988
                if(extra_align == -1)
 
1989
                        ui_do_label(&part, extra_text, 20.f, -1, (int)part.w);
 
1990
                else
 
1991
                        ui_do_label(&part, extra_text, 20.f, 0, -1);
 
1992
 
 
1993
                if(popup == POPUP_QUIT)
 
1994
                {
 
1995
                        RECT yes, no;
 
1996
                        ui_hsplit_b(&box, 20.f, &box, &part);
 
1997
                        ui_hsplit_b(&box, 24.f, &box, &part);
 
1998
                        ui_vmargin(&part, 80.0f, &part);
 
1999
                        
 
2000
                        ui_vsplit_mid(&part, &no, &yes);
 
2001
                        
 
2002
                        ui_vmargin(&yes, 20.0f, &yes);
 
2003
                        ui_vmargin(&no, 20.0f, &no);
 
2004
 
 
2005
                        static int button_abort = 0;
 
2006
                        if(ui_do_button(&button_abort, "No", 0, &no, ui_draw_menu_button, 0) || inp_key_down(KEY_ESC))
 
2007
                                popup = POPUP_NONE;
 
2008
 
 
2009
                        static int button_tryagain = 0;
 
2010
                        if(ui_do_button(&button_tryagain, "Yes", 0, &yes, ui_draw_menu_button, 0) || inp_key_down(KEY_ENTER))
 
2011
                                client_quit();
 
2012
                }
 
2013
                else if(popup == POPUP_PASSWORD)
 
2014
                {
 
2015
                        RECT label, textbox, tryagain, abort;
 
2016
                        
 
2017
                        ui_hsplit_b(&box, 20.f, &box, &part);
 
2018
                        ui_hsplit_b(&box, 24.f, &box, &part);
 
2019
                        ui_vmargin(&part, 80.0f, &part);
 
2020
                        
 
2021
                        ui_vsplit_mid(&part, &abort, &tryagain);
 
2022
                        
 
2023
                        ui_vmargin(&tryagain, 20.0f, &tryagain);
 
2024
                        ui_vmargin(&abort, 20.0f, &abort);
 
2025
                        
 
2026
                        static int button_abort = 0;
 
2027
                        if(ui_do_button(&button_abort, "Abort", 0, &abort, ui_draw_menu_button, 0) || inp_key_down(KEY_ESC))
 
2028
                                popup = POPUP_NONE;
 
2029
 
 
2030
                        static int button_tryagain = 0;
 
2031
                        if(ui_do_button(&button_tryagain, "Try again", 0, &tryagain, ui_draw_menu_button, 0) || inp_key_down(KEY_ENTER))
 
2032
                        {
 
2033
                                client_connect(config.ui_server_address);
 
2034
                        }
 
2035
                        
 
2036
                        ui_hsplit_b(&box, 60.f, &box, &part);
 
2037
                        ui_hsplit_b(&box, 24.f, &box, &part);
 
2038
                        
 
2039
                        ui_vsplit_l(&part, 60.0f, 0, &label);
 
2040
                        ui_vsplit_l(&label, 100.0f, 0, &textbox);
 
2041
                        ui_vsplit_l(&textbox, 20.0f, 0, &textbox);
 
2042
                        ui_vsplit_r(&textbox, 60.0f, &textbox, 0);
 
2043
                        ui_do_label(&label, "Password:", 20, -1);
 
2044
                        ui_do_edit_box(&config.password, &textbox, config.password, sizeof(config.password), 14.0f, true);
 
2045
                }
 
2046
                else if(popup == POPUP_FIRST_LAUNCH)
 
2047
                {
 
2048
                        RECT label, textbox;
 
2049
                        
 
2050
                        ui_hsplit_b(&box, 20.f, &box, &part);
 
2051
                        ui_hsplit_b(&box, 24.f, &box, &part);
 
2052
                        ui_vmargin(&part, 80.0f, &part);
 
2053
                        
 
2054
                        static int enter_button = 0;
 
2055
                        if(ui_do_button(&enter_button, "Enter", 0, &part, ui_draw_menu_button, 0) || inp_key_down(KEY_ENTER))
 
2056
                                popup = POPUP_NONE;
 
2057
                        
 
2058
                        ui_hsplit_b(&box, 40.f, &box, &part);
 
2059
                        ui_hsplit_b(&box, 24.f, &box, &part);
 
2060
                        
 
2061
                        ui_vsplit_l(&part, 60.0f, 0, &label);
 
2062
                        ui_vsplit_l(&label, 100.0f, 0, &textbox);
 
2063
                        ui_vsplit_l(&textbox, 20.0f, 0, &textbox);
 
2064
                        ui_vsplit_r(&textbox, 60.0f, &textbox, 0);
 
2065
                        ui_do_label(&label, "Nickname:", 20, -1);
 
2066
                        ui_do_edit_box(&config.player_name, &textbox, config.player_name, sizeof(config.player_name), 14.0f);
 
2067
                }
 
2068
                else
 
2069
                {
 
2070
                        ui_hsplit_b(&box, 20.f, &box, &part);
 
2071
                        ui_hsplit_b(&box, 24.f, &box, &part);
 
2072
                        ui_vmargin(&part, 120.0f, &part);
 
2073
 
 
2074
                        static int button = 0;
 
2075
                        if(ui_do_button(&button, button_text, 0, &part, ui_draw_menu_button, 0) || inp_key_down(KEY_ESC) || inp_key_down(KEY_ENTER))
 
2076
                        {
 
2077
                                if(popup == POPUP_CONNECTING)
 
2078
                                        client_disconnect();
 
2079
                                popup = POPUP_NONE;
 
2080
                        }
 
2081
                }
 
2082
        }
 
2083
        
 
2084
        return 0;
 
2085
}
 
2086
 
 
2087
void menu_render()
 
2088
{
 
2089
        static int mouse_x = 0;
 
2090
        static int mouse_y = 0;
 
2091
 
 
2092
        // update colors
 
2093
 
 
2094
        vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f));
 
2095
        gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f);
 
2096
 
 
2097
        color_tabbar_inactive_outgame = vec4(0,0,0,0.25f);
 
2098
        color_tabbar_active_outgame = vec4(0,0,0,0.5f);
 
2099
 
 
2100
        color_ingame_scale_i = 0.5f;
 
2101
        color_ingame_scale_a = 0.2f;
 
2102
        color_tabbar_inactive_ingame = vec4(
 
2103
                gui_color.r*color_ingame_scale_i,
 
2104
                gui_color.g*color_ingame_scale_i,
 
2105
                gui_color.b*color_ingame_scale_i,
 
2106
                gui_color.a*0.8f);
 
2107
        
 
2108
        color_tabbar_active_ingame = vec4(
 
2109
                gui_color.r*color_ingame_scale_a,
 
2110
                gui_color.g*color_ingame_scale_a,
 
2111
                gui_color.b*color_ingame_scale_a,
 
2112
                gui_color.a);
 
2113
 
 
2114
 
 
2115
    // handle mouse movement
 
2116
    float mx, my;
 
2117
    {
 
2118
        int rx, ry;
 
2119
        inp_mouse_relative(&rx, &ry);
 
2120
        mouse_x += rx;
 
2121
        mouse_y += ry;
 
2122
        if(mouse_x < 0) mouse_x = 0;
 
2123
        if(mouse_y < 0) mouse_y = 0;
 
2124
        if(mouse_x > gfx_screenwidth()) mouse_x = gfx_screenwidth();
 
2125
        if(mouse_y > gfx_screenheight()) mouse_y = gfx_screenheight();
 
2126
            
 
2127
        // update the ui
 
2128
        RECT *screen = ui_screen();
 
2129
        mx = (mouse_x/(float)gfx_screenwidth())*screen->w;
 
2130
        my = (mouse_y/(float)gfx_screenheight())*screen->h;
 
2131
            
 
2132
        int buttons = 0;
 
2133
        if(inp_key_pressed(KEY_MOUSE_1)) buttons |= 1;
 
2134
        if(inp_key_pressed(KEY_MOUSE_2)) buttons |= 2;
 
2135
        if(inp_key_pressed(KEY_MOUSE_3)) buttons |= 4;
 
2136
            
 
2137
        ui_update(mx,my,mx*3.0f,my*3.0f,buttons);
 
2138
    }
 
2139
    
 
2140
        menu2_render();
 
2141
        
 
2142
    gfx_texture_set(data->images[IMAGE_CURSOR].id);
 
2143
    gfx_quads_begin();
 
2144
    gfx_setcolor(1,1,1,1);
 
2145
    gfx_quads_drawTL(mx,my,24,24);
 
2146
    gfx_quads_end();
 
2147
 
 
2148
        if(config.debug)
 
2149
        {
 
2150
                RECT screen = *ui_screen();
 
2151
                gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
 
2152
 
 
2153
                char buf[512];
 
2154
                str_format(buf, sizeof(buf), "%p %p %p", ui_hot_item(), ui_active_item(), ui_last_active_item());
 
2155
                TEXT_CURSOR cursor;
 
2156
                gfx_text_set_cursor(&cursor, 10, 10, 10, TEXTFLAG_RENDER);
 
2157
                gfx_text_ex(&cursor, buf, -1);
 
2158
        }
 
2159
 
 
2160
}