]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_welcome.qc
Fix #2689 "Welcome dialog is not closed by voting screens or by disconnecting"
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_welcome.qc
1 #include "dialog_welcome.qh"
2
3 #include "image.qh"
4 #include "textlabel.qh"
5 #include "textbox.qh"
6 #include "radiobutton.qh"
7 #include "commandbutton.qh"
8 #include "slider.qh"
9
10 void welcomeDialog_resetStrings(entity me)
11 {
12         strcpy(me.serverinfo_name, _("Welcome"));
13         strcpy(me.serverinfo_MOTD, "");
14 }
15
16 float XonoticWelcomeDialog_keyDown(entity me, float key, float ascii, float shift)
17 {
18         switch(key)
19         {
20                 case K_KP_ENTER:
21                 case K_ENTER:
22                 case K_SPACE:
23                         me.close(me);
24                         return true;
25                 default:
26                         return SUPER(XonoticWelcomeDialog).keyDown(me, key, ascii, shift);
27         }
28 }
29
30 // the same implentation in mousePress apparently works, but for some reason if you try to open
31 // the dialog again it doesn't show up and requires opening it a seconds time to show up
32 bool XonoticWelcomeDialog_mouseRelease(entity me, vector pos)
33 {
34         if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
35         {
36                 return SUPER(XonoticWelcomeDialog).mouseRelease(me, pos);
37         }
38         me.close(me);
39         return true;
40 }
41
42 void XonoticWelcomeDialog_destroy(entity me)
43 {
44         cvar_set("_menu_welcome_dialog_available", "0");
45 }
46
47 void XonoticWelcomeDialog_readInputArgs(entity me, int argsbuf)
48 {
49         int i = 0;
50         string s;
51         welcomeDialog_resetStrings(me);
52         if(argsbuf >= 0)
53         while((s = bufstr_get(argsbuf, i)) != "")
54         {
55                 if(s == "HOSTNAME")
56                         strcpy(me.serverinfo_name, bufstr_get(argsbuf, ++i));
57                 else if(s == "WELCOME")
58                         strcpy(me.serverinfo_MOTD, bufstr_get(argsbuf, ++i));
59                 else if(s == "RESET")
60                 {
61                         welcomeDialog_resetStrings(me);
62                         break;
63                 }
64                 ++i;
65         }
66         //me.serverinfo_name_ent.setText(me.serverinfo_name_ent, me.serverinfo_name);
67         me.serverinfo_MOTD_ent.setText(me.serverinfo_MOTD_ent, me.serverinfo_MOTD);
68         me.frame.setText(me.frame, me.serverinfo_name);
69 }
70
71 void XonoticWelcomeDialog_draw(entity me)
72 {
73         SUPER(XonoticWelcomeDialog).draw(me);
74
75         if (!(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)))
76                 me.close(me);
77
78         if(me.serverinfo_MOTD == "" && gamestatus & (GAME_CONNECTED | GAME_ISSERVER))
79         {
80                 // if serverinfo_MOTD is empty while connected it means we are connected to an old server
81                 // in this case show the csqc welcome message and instantly close the dialog
82                 localcmd("\n+show_info0; defer 2 -show_info0\n");
83                 me.close(me);
84         }
85 }
86
87 void XonoticWelcomeDialog_fill(entity me)
88 {
89         registercvar("_menu_welcome_dialog_available", "0", 0);
90         cvar_set("_menu_welcome_dialog_available", "1");
91
92         me.frame.allowColors = true; // allow color codes in the title
93
94         entity e;
95
96         me.TR(me);
97                 me.TD(me, me.rows - 1, me.columns, me.serverinfo_MOTD_ent = makeXonoticTextBox());
98                         me.serverinfo_MOTD_ent.align = 0.5;
99                         me.serverinfo_MOTD_ent.allowColors = true;
100                         me.serverinfo_MOTD_ent.escapedNewLines = true;
101         me.gotoRC(me, me.rows - 1, 0);
102                 me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0'));
103                         e.onClick = Dialog_Close;
104                         e.onClickEntity = me;
105                         e.preferredFocusPriority = 1;
106 }