1
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
7
#include <base/system.h>
8
#include <base/math.hpp>
9
#include <base/vmath.hpp>
14
#include <engine/e_client_interface.h>
17
#include <engine/client/ec_font.h>
20
#include <game/version.hpp>
21
#include <game/generated/g_protocol.hpp>
23
#include <game/generated/gc_data.hpp>
24
#include <game/client/gameclient.hpp>
25
#include <mastersrv/mastersrv.h>
27
vec4 MENUS::gui_color;
28
vec4 MENUS::color_tabbar_inactive_outgame;
29
vec4 MENUS::color_tabbar_active_outgame;
30
vec4 MENUS::color_tabbar_inactive;
31
vec4 MENUS::color_tabbar_active;
32
vec4 MENUS::color_tabbar_inactive_ingame;
33
vec4 MENUS::color_tabbar_active_ingame;
36
float MENUS::button_height = 25.0f;
37
float MENUS::listheader_height = 17.0f;
38
float MENUS::fontmod_height = 0.8f;
40
INPUT_EVENT MENUS::inputevents[MAX_INPUTEVENTS];
41
int MENUS::num_inputevents;
43
inline float hue_to_rgb(float v1, float v2, float h)
47
if((6 * h) < 1) return v1 + ( v2 - v1 ) * 6 * h;
48
if((2 * h) < 1) return v2;
49
if((3 * h) < 2) return v1 + ( v2 - v1 ) * ((2.0f/3.0f) - h) * 6;
53
inline vec3 hsl_to_rgb(vec3 in)
67
v2 = in.l * (1 + in.s);
69
v2 = (in.l+in.s) - (in.s*in.l);
73
out.r = hue_to_rgb(v1, v2, in.h + (1.0f/3.0f));
74
out.g = hue_to_rgb(v1, v2, in.h);
75
out.b = hue_to_rgb(v1, v2, in.h - (1.0f/3.0f));
85
active_page = PAGE_INTERNET;
86
game_page = PAGE_GAME;
89
need_sendinfo = false;
92
escape_pressed = false;
93
enter_pressed = false;
99
last_input = time_get();
102
vec4 MENUS::button_color_mul(const void *id)
104
if(ui_active_item() == id)
105
return vec4(1,1,1,0.5f);
106
else if(ui_hot_item() == id)
107
return vec4(1,1,1,1.5f);
108
return vec4(1,1,1,1);
111
void MENUS::ui_draw_browse_icon(int what, const RECT *r)
113
gfx_texture_set(data->images[IMAGE_BROWSEICONS].id);
116
gfx_quads_drawTL(r->x,r->y,r->w,r->h);
121
void MENUS::ui_draw_menu_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
123
ui_draw_rect(r, vec4(1,1,1,0.5f)*button_color_mul(id), CORNER_ALL, 5.0f);
124
ui_do_label(r, text, r->h*fontmod_height, 0);
127
void MENUS::ui_draw_keyselect_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
129
ui_draw_rect(r, vec4(1,1,1,0.5f)*button_color_mul(id), CORNER_ALL, 5.0f);
130
ui_do_label(r, text, r->h*fontmod_height, 0);
133
void MENUS::ui_draw_menu_tab_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
135
int corners = CORNER_T;
136
vec4 colormod(1,1,1,1);
138
corners = *(int *)extra;
141
ui_draw_rect(r, color_tabbar_active, corners, 10.0f);
143
ui_draw_rect(r, color_tabbar_inactive, corners, 10.0f);
144
ui_do_label(r, text, r->h*fontmod_height, 0);
148
void MENUS::ui_draw_settings_tab_button(const void *id, const char *text, int checked, const RECT *r, const void *extra)
151
ui_draw_rect(r, color_tabbar_active, CORNER_R, 10.0f);
153
ui_draw_rect(r, color_tabbar_inactive, CORNER_R, 10.0f);
154
ui_do_label(r, text, r->h*fontmod_height, 0);
157
void MENUS::ui_draw_grid_header(const void *id, const char *text, int checked, const RECT *r, const void *extra)
160
ui_draw_rect(r, vec4(1,1,1,0.5f), CORNER_T, 5.0f);
162
ui_vsplit_l(r, 5.0f, 0, &t);
163
ui_do_label(&t, text, r->h*fontmod_height, -1);
166
void MENUS::ui_draw_list_row(const void *id, const char *text, int checked, const RECT *r, const void *extra)
171
ui_margin(&sr, 1.5f, &sr);
172
ui_draw_rect(&sr, vec4(1,1,1,0.5f), CORNER_ALL, 4.0f);
174
ui_do_label(r, text, r->h*fontmod_height, -1);
177
void MENUS::ui_draw_checkbox_common(const void *id, const char *text, const char *boxtext, const RECT *r)
184
ui_vsplit_l(&t, 5.0f, 0, &t);
186
ui_margin(&c, 2.0f, &c);
187
ui_draw_rect(&c, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 3.0f);
189
ui_do_label(&c, boxtext, r->h*fontmod_height*0.75f, 0);
190
ui_do_label(&t, text, r->h*fontmod_height*0.8f, -1);
193
void MENUS::ui_draw_checkbox(const void *id, const char *text, int checked, const RECT *r, const void *extra)
195
ui_draw_checkbox_common(id, text, checked?"X":"", r);
199
void MENUS::ui_draw_checkbox_number(const void *id, const char *text, int checked, const RECT *r, const void *extra)
202
str_format(buf, sizeof(buf), "%d", checked);
203
ui_draw_checkbox_common(id, text, buf, r);
206
int MENUS::ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, float font_size, bool hidden)
208
int inside = ui_mouse_inside(rect);
210
static int at_index = 0;
212
if(ui_last_active_item() == id)
214
int len = strlen(str);
216
if (inside && ui_mouse_button(0))
218
int mx_rel = (int)(ui_mouse_x() - rect->x);
220
for (int i = 1; i <= len; i++)
222
if (gfx_text_width(0, font_size, str, i) + 10 > mx_rel)
233
for(int i = 0; i < num_inputevents; i++)
236
INPUT_EVENT e = inputevents[i];
243
if (!(c >= 0 && c < 32) && c != 127)
245
if (len < str_size - 1 && at_index < str_size - 1)
247
memmove(str + at_index + 1, str + at_index, len - at_index + 1);
254
if(e.flags&INPFLAG_PRESS)
256
if (k == KEY_BACKSPACE && at_index > 0)
258
memmove(str + at_index - 1, str + at_index, len - at_index + 1);
262
else if (k == KEY_DELETE && at_index < len)
264
memmove(str + at_index, str + at_index + 1, len - at_index);
267
else if (k == KEY_RETURN)
268
ui_clear_last_active_item();
269
else if (k == KEY_LEFT && at_index > 0)
271
else if (k == KEY_RIGHT && at_index < len)
273
else if (k == KEY_HOME)
275
else if (k == KEY_END)
281
bool just_got_active = false;
283
if(ui_active_item() == id)
285
if(!ui_mouse_button(0))
286
ui_set_active_item(0);
288
else if(ui_hot_item() == id)
290
if(ui_mouse_button(0))
292
if (ui_last_active_item() != id)
293
just_got_active = true;
294
ui_set_active_item(id);
301
RECT textbox = *rect;
302
ui_draw_rect(&textbox, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f);
303
ui_vmargin(&textbox, 5.0f, &textbox);
305
const char *display_str = str;
310
unsigned s = strlen(str);
311
if(s >= sizeof(stars))
313
memset(stars, '*', s);
318
ui_do_label(&textbox, display_str, font_size, -1);
320
if (ui_last_active_item() == id && !just_got_active)
322
float w = gfx_text_width(0, font_size, display_str, at_index);
323
textbox.x += w*ui_scale();
324
ui_do_label(&textbox, "_", font_size, -1);
330
float MENUS::ui_do_scrollbar_v(const void *id, const RECT *rect, float current)
333
static float offset_y;
334
ui_hsplit_t(rect, 33, &handle, 0);
336
handle.y += (rect->h-handle.h)*current;
340
int inside = ui_mouse_inside(&handle);
342
if(ui_active_item() == id)
344
if(!ui_mouse_button(0))
345
ui_set_active_item(0);
348
float max = rect->h-handle.h;
349
float cur = ui_mouse_y()-offset_y;
351
if(ret < 0.0f) ret = 0.0f;
352
if(ret > 1.0f) ret = 1.0f;
354
else if(ui_hot_item() == id)
356
if(ui_mouse_button(0))
358
ui_set_active_item(id);
359
offset_y = ui_mouse_y()-handle.y;
368
ui_vmargin(rect, 5.0f, &rail);
369
ui_draw_rect(&rail, vec4(1,1,1,0.25f), 0, 0.0f);
371
RECT slider = handle;
372
slider.w = rail.x-slider.x;
373
ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_L, 2.5f);
374
slider.x = rail.x+rail.w;
375
ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_R, 2.5f);
378
ui_margin(&slider, 5.0f, &slider);
379
ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f);
386
float MENUS::ui_do_scrollbar_h(const void *id, const RECT *rect, float current)
389
static float offset_x;
390
ui_vsplit_l(rect, 33, &handle, 0);
392
handle.x += (rect->w-handle.w)*current;
396
int inside = ui_mouse_inside(&handle);
398
if(ui_active_item() == id)
400
if(!ui_mouse_button(0))
401
ui_set_active_item(0);
404
float max = rect->w-handle.w;
405
float cur = ui_mouse_x()-offset_x;
407
if(ret < 0.0f) ret = 0.0f;
408
if(ret > 1.0f) ret = 1.0f;
410
else if(ui_hot_item() == id)
412
if(ui_mouse_button(0))
414
ui_set_active_item(id);
415
offset_x = ui_mouse_x()-handle.x;
424
ui_hmargin(rect, 5.0f, &rail);
425
ui_draw_rect(&rail, vec4(1,1,1,0.25f), 0, 0.0f);
427
RECT slider = handle;
428
slider.h = rail.y-slider.y;
429
ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_T, 2.5f);
430
slider.y = rail.y+rail.h;
431
ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_B, 2.5f);
434
ui_margin(&slider, 5.0f, &slider);
435
ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f);
440
int MENUS::ui_do_key_reader(void *id, const RECT *rect, int key)
443
static void *grabbed_id = 0;
444
static bool mouse_released = true;
445
int inside = ui_mouse_inside(rect);
448
if(!ui_mouse_button(0) && grabbed_id == id)
449
mouse_released = true;
451
if(ui_active_item() == id)
455
new_key = binder.key.key;
456
binder.got_key = false;
457
ui_set_active_item(0);
458
mouse_released = false;
462
else if(ui_hot_item() == id)
464
if(ui_mouse_button(0) && mouse_released)
466
binder.take_key = true;
467
binder.got_key = false;
468
ui_set_active_item(id);
476
if (ui_active_item() == id)
477
ui_draw_keyselect_button(id, "???", 0, rect, 0);
481
ui_draw_keyselect_button(id, "", 0, rect, 0);
483
ui_draw_keyselect_button(id, inp_key_name(key), 0, rect, 0);
489
int MENUS::render_menubar(RECT r)
494
int active_page = config.ui_page;
497
if(client_state() != CLIENTSTATE_OFFLINE)
498
active_page = game_page;
500
if(client_state() == CLIENTSTATE_OFFLINE)
503
if(0) // this is not done yet
505
ui_vsplit_l(&box, 90.0f, &button, &box);
506
static int news_button=0;
507
if (ui_do_button(&news_button, "News", active_page==PAGE_NEWS, &button, ui_draw_menu_tab_button, 0))
508
new_page = PAGE_NEWS;
509
ui_vsplit_l(&box, 30.0f, 0, &box);
512
ui_vsplit_l(&box, 100.0f, &button, &box);
513
static int internet_button=0;
514
int corners = CORNER_TL;
515
if (ui_do_button(&internet_button, "Internet", active_page==PAGE_INTERNET, &button, ui_draw_menu_tab_button, &corners))
517
client_serverbrowse_refresh(BROWSETYPE_INTERNET);
518
new_page = PAGE_INTERNET;
521
//ui_vsplit_l(&box, 4.0f, 0, &box);
522
ui_vsplit_l(&box, 80.0f, &button, &box);
523
static int lan_button=0;
525
if (ui_do_button(&lan_button, "LAN", active_page==PAGE_LAN, &button, ui_draw_menu_tab_button, &corners))
527
client_serverbrowse_refresh(BROWSETYPE_LAN);
531
//ui_vsplit_l(&box, 4.0f, 0, &box);
532
ui_vsplit_l(&box, 110.0f, &button, &box);
533
static int favorites_button=0;
535
if (ui_do_button(&favorites_button, "Favorites", active_page==PAGE_FAVORITES, &button, ui_draw_menu_tab_button, &corners))
537
client_serverbrowse_refresh(BROWSETYPE_FAVORITES);
538
new_page = PAGE_FAVORITES;
541
ui_vsplit_l(&box, 4.0f*5, 0, &box);
542
ui_vsplit_l(&box, 100.0f, &button, &box);
543
static int demos_button=0;
544
if (ui_do_button(&demos_button, "Demos", active_page==PAGE_DEMOS, &button, ui_draw_menu_tab_button, 0))
547
new_page = PAGE_DEMOS;
553
ui_vsplit_l(&box, 90.0f, &button, &box);
554
static int game_button=0;
555
if (ui_do_button(&game_button, "Game", active_page==PAGE_GAME, &button, ui_draw_menu_tab_button, 0))
556
new_page = PAGE_GAME;
558
ui_vsplit_l(&box, 4.0f, 0, &box);
559
ui_vsplit_l(&box, 140.0f, &button, &box);
560
static int server_info_button=0;
561
if (ui_do_button(&server_info_button, "Server Info", active_page==PAGE_SERVER_INFO, &button, ui_draw_menu_tab_button, 0))
562
new_page = PAGE_SERVER_INFO;
564
ui_vsplit_l(&box, 4.0f, 0, &box);
565
ui_vsplit_l(&box, 140.0f, &button, &box);
566
static int callvote_button=0;
567
if (ui_do_button(&callvote_button, "Call Vote", active_page==PAGE_CALLVOTE, &button, ui_draw_menu_tab_button, 0))
568
new_page = PAGE_CALLVOTE;
570
ui_vsplit_l(&box, 30.0f, 0, &box);
574
ui_vsplit_r(&box, 110.0f, &box, &button);
575
static int system_button=0;
576
if (ui_do_button(&system_button, "System", config.ui_page==PAGE_SYSTEM, &button, ui_draw_menu_tab_button, 0))
577
config.ui_page = PAGE_SYSTEM;
579
ui_vsplit_r(&box, 30.0f, &box, 0);
582
ui_vsplit_r(&box, 90.0f, &box, &button);
583
static int quit_button=0;
584
if (ui_do_button(&quit_button, "Quit", 0, &button, ui_draw_menu_tab_button, 0))
587
ui_vsplit_r(&box, 10.0f, &box, &button);
588
ui_vsplit_r(&box, 120.0f, &box, &button);
589
static int settings_button=0;
590
if (ui_do_button(&settings_button, "Settings", active_page==PAGE_SETTINGS, &button, ui_draw_menu_tab_button, 0))
591
new_page = PAGE_SETTINGS;
595
if(client_state() == CLIENTSTATE_OFFLINE)
596
config.ui_page = new_page;
598
game_page = new_page;
604
void MENUS::render_loading(float percent)
606
// need up date this here to get correct
607
vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f));
608
gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f);
610
RECT screen = *ui_screen();
611
gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
619
float x = screen.w/2-w/2;
620
float y = screen.h/2-h/2;
626
gfx_setcolor(0,0,0,0.50f);
627
draw_round_rect(x, y, w, h, 40.0f);
631
const char *caption = "Loading";
633
tw = gfx_text_width(0, 48.0f, caption, -1);
639
ui_do_label(&r, caption, 48.0f, 0, -1);
643
gfx_setcolor(1,1,1,0.75f);
644
draw_round_rect(x+40, y+h-75, (w-80)*percent, 25, 5.0f);
650
void MENUS::render_news(RECT main_view)
652
ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
657
if(config.cl_show_welcome)
658
popup = POPUP_FIRST_LAUNCH;
659
config.cl_show_welcome = 0;
664
RECT screen = *ui_screen();
665
gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
667
static bool first = true;
670
if(config.ui_page == PAGE_INTERNET)
671
client_serverbrowse_refresh(0);
672
else if(config.ui_page == PAGE_LAN)
673
client_serverbrowse_refresh(1);
677
if(client_state() == CLIENTSTATE_ONLINE)
679
color_tabbar_inactive = color_tabbar_inactive_ingame;
680
color_tabbar_active = color_tabbar_active_ingame;
685
color_tabbar_inactive = color_tabbar_inactive_outgame;
686
color_tabbar_active = color_tabbar_active_outgame;
692
// some margin around the screen
693
ui_margin(&screen, 10.0f, &screen);
695
if(popup == POPUP_NONE)
698
ui_hsplit_t(&screen, 24.0f, &tab_bar, &main_view);
699
ui_vmargin(&tab_bar, 20.0f, &tab_bar);
700
render_menubar(tab_bar);
702
// news is not implemented yet
703
if(config.ui_page <= PAGE_NEWS || config.ui_page > PAGE_SETTINGS || (client_state() == CLIENTSTATE_OFFLINE && config.ui_page >= PAGE_GAME && config.ui_page <= PAGE_CALLVOTE))
705
client_serverbrowse_refresh(BROWSETYPE_INTERNET);
706
config.ui_page = PAGE_INTERNET;
709
// render current page
710
if(client_state() != CLIENTSTATE_OFFLINE)
712
if(game_page == PAGE_GAME)
713
render_game(main_view);
714
else if(game_page == PAGE_SERVER_INFO)
715
render_serverinfo(main_view);
716
else if(game_page == PAGE_CALLVOTE)
717
render_servercontrol(main_view);
718
else if(game_page == PAGE_SETTINGS)
719
render_settings(main_view);
721
else if(config.ui_page == PAGE_NEWS)
722
render_news(main_view);
723
else if(config.ui_page == PAGE_INTERNET)
724
render_serverbrowser(main_view);
725
else if(config.ui_page == PAGE_LAN)
726
render_serverbrowser(main_view);
727
else if(config.ui_page == PAGE_DEMOS)
728
render_demolist(main_view);
729
else if(config.ui_page == PAGE_FAVORITES)
730
render_serverbrowser(main_view);
731
else if(config.ui_page == PAGE_SETTINGS)
732
render_settings(main_view);
736
// make sure that other windows doesn't do anything funnay!
737
//ui_set_hot_item(0);
738
//ui_set_active_item(0);
740
const char *title = "";
741
const char *extra_text = "";
742
const char *button_text = "";
745
if(popup == POPUP_CONNECTING)
747
title = "Connecting to";
748
extra_text = config.ui_server_address; // TODO: query the client about the address
749
button_text = "Abort";
750
if(client_mapdownload_totalsize() > 0)
752
title = "Downloading map";
753
str_format(buf, sizeof(buf), "%d/%d KiB", client_mapdownload_amount()/1024, client_mapdownload_totalsize()/1024);
757
else if(popup == POPUP_DISCONNECTED)
759
title = "Disconnected";
760
extra_text = client_error_string();
764
else if(popup == POPUP_PURE)
766
title = "Disconnected";
767
extra_text = "The server is running a non-standard tuning on a pure game mode.";
771
else if(popup == POPUP_PASSWORD)
773
title = "Password Error";
774
extra_text = client_error_string();
775
button_text = "Try Again";
777
else if(popup == POPUP_QUIT)
780
extra_text = "Are you sure that you want to quit?";
782
else if(popup == POPUP_FIRST_LAUNCH)
784
title = "Welcome to Teeworlds";
786
"As this is the first time you launch the game, please enter your nick name below. "
787
"It's recommended that you check the settings to adjust them to your liking "
788
"before joining a server.";
795
ui_vmargin(&box, 150.0f, &box);
796
ui_hmargin(&box, 150.0f, &box);
799
ui_draw_rect(&box, vec4(0,0,0,0.5f), CORNER_ALL, 15.0f);
801
ui_hsplit_t(&box, 20.f, &part, &box);
802
ui_hsplit_t(&box, 24.f, &part, &box);
803
ui_do_label(&part, title, 24.f, 0);
804
ui_hsplit_t(&box, 20.f, &part, &box);
805
ui_hsplit_t(&box, 24.f, &part, &box);
806
ui_vmargin(&part, 20.f, &part);
808
if(extra_align == -1)
809
ui_do_label(&part, extra_text, 20.f, -1, (int)part.w);
811
ui_do_label(&part, extra_text, 20.f, 0, -1);
813
if(popup == POPUP_QUIT)
816
ui_hsplit_b(&box, 20.f, &box, &part);
817
ui_hsplit_b(&box, 24.f, &box, &part);
818
ui_vmargin(&part, 80.0f, &part);
820
ui_vsplit_mid(&part, &no, &yes);
822
ui_vmargin(&yes, 20.0f, &yes);
823
ui_vmargin(&no, 20.0f, &no);
825
static int button_abort = 0;
826
if(ui_do_button(&button_abort, "No", 0, &no, ui_draw_menu_button, 0) || escape_pressed)
829
static int button_tryagain = 0;
830
if(ui_do_button(&button_tryagain, "Yes", 0, &yes, ui_draw_menu_button, 0) || enter_pressed)
833
else if(popup == POPUP_PASSWORD)
835
RECT label, textbox, tryagain, abort;
837
ui_hsplit_b(&box, 20.f, &box, &part);
838
ui_hsplit_b(&box, 24.f, &box, &part);
839
ui_vmargin(&part, 80.0f, &part);
841
ui_vsplit_mid(&part, &abort, &tryagain);
843
ui_vmargin(&tryagain, 20.0f, &tryagain);
844
ui_vmargin(&abort, 20.0f, &abort);
846
static int button_abort = 0;
847
if(ui_do_button(&button_abort, "Abort", 0, &abort, ui_draw_menu_button, 0) || escape_pressed)
850
static int button_tryagain = 0;
851
if(ui_do_button(&button_tryagain, "Try again", 0, &tryagain, ui_draw_menu_button, 0) || enter_pressed)
853
client_connect(config.ui_server_address);
856
ui_hsplit_b(&box, 60.f, &box, &part);
857
ui_hsplit_b(&box, 24.f, &box, &part);
859
ui_vsplit_l(&part, 60.0f, 0, &label);
860
ui_vsplit_l(&label, 100.0f, 0, &textbox);
861
ui_vsplit_l(&textbox, 20.0f, 0, &textbox);
862
ui_vsplit_r(&textbox, 60.0f, &textbox, 0);
863
ui_do_label(&label, "Password:", 20, -1);
864
ui_do_edit_box(&config.password, &textbox, config.password, sizeof(config.password), 14.0f, true);
866
else if(popup == POPUP_FIRST_LAUNCH)
870
ui_hsplit_b(&box, 20.f, &box, &part);
871
ui_hsplit_b(&box, 24.f, &box, &part);
872
ui_vmargin(&part, 80.0f, &part);
874
static int enter_button = 0;
875
if(ui_do_button(&enter_button, "Enter", 0, &part, ui_draw_menu_button, 0) || enter_pressed)
878
ui_hsplit_b(&box, 40.f, &box, &part);
879
ui_hsplit_b(&box, 24.f, &box, &part);
881
ui_vsplit_l(&part, 60.0f, 0, &label);
882
ui_vsplit_l(&label, 100.0f, 0, &textbox);
883
ui_vsplit_l(&textbox, 20.0f, 0, &textbox);
884
ui_vsplit_r(&textbox, 60.0f, &textbox, 0);
885
ui_do_label(&label, "Nickname:", 20, -1);
886
ui_do_edit_box(&config.player_name, &textbox, config.player_name, sizeof(config.player_name), 14.0f);
890
ui_hsplit_b(&box, 20.f, &box, &part);
891
ui_hsplit_b(&box, 24.f, &box, &part);
892
ui_vmargin(&part, 120.0f, &part);
894
static int button = 0;
895
if(ui_do_button(&button, button_text, 0, &part, ui_draw_menu_button, 0) || escape_pressed || enter_pressed)
897
if(popup == POPUP_CONNECTING)
908
void MENUS::set_active(bool active)
910
menu_active = active;
911
if(!menu_active && need_sendinfo)
913
gameclient.send_info(false);
914
need_sendinfo = false;
918
void MENUS::on_reset()
922
bool MENUS::on_mousemove(float x, float y)
924
last_input = time_get();
931
if(mouse_pos.x < 0) mouse_pos.x = 0;
932
if(mouse_pos.y < 0) mouse_pos.y = 0;
933
if(mouse_pos.x > gfx_screenwidth()) mouse_pos.x = gfx_screenwidth();
934
if(mouse_pos.y > gfx_screenheight()) mouse_pos.y = gfx_screenheight();
939
bool MENUS::on_input(INPUT_EVENT e)
941
last_input = time_get();
943
// special handle esc and enter for popup purposes
944
if(e.flags&INPFLAG_PRESS)
946
if(e.key == KEY_ESCAPE)
948
escape_pressed = true;
949
set_active(!is_active());
956
// special for popups
957
if(e.flags&INPFLAG_PRESS && e.key == KEY_RETURN)
958
enter_pressed = true;
960
if(num_inputevents < MAX_INPUTEVENTS)
961
inputevents[num_inputevents++] = e;
967
void MENUS::on_statechange(int new_state, int old_state)
969
if(new_state == CLIENTSTATE_OFFLINE)
972
if(client_error_string() && client_error_string()[0] != 0)
974
if(strstr(client_error_string(), "password"))
976
popup = POPUP_PASSWORD;
977
ui_set_hot_item(&config.password);
978
ui_set_active_item(&config.password);
981
popup = POPUP_DISCONNECTED;
983
else if(new_state == CLIENTSTATE_LOADING)
985
popup = POPUP_CONNECTING;
986
client_serverinfo_request();
988
else if(new_state == CLIENTSTATE_CONNECTING)
989
popup = POPUP_CONNECTING;
990
else if (new_state == CLIENTSTATE_ONLINE || new_state == CLIENTSTATE_DEMOPLAYBACK)
997
void MENUS::on_render()
999
if(client_state() != CLIENTSTATE_ONLINE && client_state() != CLIENTSTATE_DEMOPLAYBACK)
1002
if(client_state() == CLIENTSTATE_DEMOPLAYBACK)
1004
RECT screen = *ui_screen();
1005
gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
1006
render_demoplayer(screen);
1009
if(client_state() == CLIENTSTATE_ONLINE && gameclient.servermode == gameclient.SERVERMODE_PUREMOD)
1011
client_disconnect();
1018
escape_pressed = false;
1019
enter_pressed = false;
1020
num_inputevents = 0;
1025
vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f));
1026
gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f);
1028
color_tabbar_inactive_outgame = vec4(0,0,0,0.25f);
1029
color_tabbar_active_outgame = vec4(0,0,0,0.5f);
1031
float color_ingame_scale_i = 0.5f;
1032
float color_ingame_scale_a = 0.2f;
1033
color_tabbar_inactive_ingame = vec4(
1034
gui_color.r*color_ingame_scale_i,
1035
gui_color.g*color_ingame_scale_i,
1036
gui_color.b*color_ingame_scale_i,
1039
color_tabbar_active_ingame = vec4(
1040
gui_color.r*color_ingame_scale_a,
1041
gui_color.g*color_ingame_scale_a,
1042
gui_color.b*color_ingame_scale_a,
1046
RECT *screen = ui_screen();
1047
float mx = (mouse_pos.x/(float)gfx_screenwidth())*screen->w;
1048
float my = (mouse_pos.y/(float)gfx_screenheight())*screen->h;
1051
if(inp_key_pressed(KEY_MOUSE_1)) buttons |= 1;
1052
if(inp_key_pressed(KEY_MOUSE_2)) buttons |= 2;
1053
if(inp_key_pressed(KEY_MOUSE_3)) buttons |= 4;
1055
ui_update(mx,my,mx*3.0f,my*3.0f,buttons);
1058
if(client_state() != CLIENTSTATE_DEMOPLAYBACK)
1062
gfx_texture_set(data->images[IMAGE_CURSOR].id);
1064
gfx_setcolor(1,1,1,1);
1065
gfx_quads_drawTL(mx,my,24,24);
1068
// render debug information
1071
RECT screen = *ui_screen();
1072
gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
1075
str_format(buf, sizeof(buf), "%p %p %p", ui_hot_item(), ui_active_item(), ui_last_active_item());
1077
gfx_text_set_cursor(&cursor, 10, 10, 10, TEXTFLAG_RENDER);
1078
gfx_text_ex(&cursor, buf, -1);
1081
escape_pressed = false;
1082
enter_pressed = false;
1083
num_inputevents = 0;
1086
static int texture_blob = -1;
1088
void MENUS::render_background()
1091
//render_sunrays(0,0);
1092
if(texture_blob == -1)
1093
texture_blob = gfx_load_texture("blob.png", IMG_AUTO, 0);
1096
float sw = 300*gfx_screenaspect();
1098
gfx_mapscreen(0, 0, sw, sh);
1100
RECT s = *ui_screen();
1102
// render background color
1103
gfx_texture_set(-1);
1105
//vec4 bottom(gui_color.r*0.3f, gui_color.g*0.3f, gui_color.b*0.3f, 1.0f);
1106
//vec4 bottom(0, 0, 0, 1.0f);
1107
vec4 bottom(gui_color.r, gui_color.g, gui_color.b, 1.0f);
1108
vec4 top(gui_color.r, gui_color.g, gui_color.b, 1.0f);
1109
gfx_setcolorvertex(0, top.r, top.g, top.b, top.a);
1110
gfx_setcolorvertex(1, top.r, top.g, top.b, top.a);
1111
gfx_setcolorvertex(2, bottom.r, bottom.g, bottom.b, bottom.a);
1112
gfx_setcolorvertex(3, bottom.r, bottom.g, bottom.b, bottom.a);
1113
gfx_quads_drawTL(0, 0, sw, sh);
1117
gfx_texture_set(-1);
1120
float offset_time = fmod(client_localtime()*0.15f, 2.0f);
1121
for(int y = -2; y < (int)(sw/size); y++)
1122
for(int x = -2; x < (int)(sh/size); x++)
1124
gfx_setcolor(0,0,0,0.045f);
1125
gfx_quads_drawTL((x-offset_time)*size*2+(y&1)*size, (y+offset_time)*size, size, size);
1129
// render border fade
1130
gfx_texture_set(texture_blob);
1132
gfx_setcolor(0,0,0,0.5f);
1133
gfx_quads_drawTL(-100, -100, sw+200, sh+200);
1137
{RECT screen = *ui_screen();
1138
gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);}