]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_termsofservice.qc
Fixed formatting issues
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_termsofservice.qc
1 #include "dialog_termsofservice.qh"
2
3 #include "../menu.qh"
4 #include "mainwindow.qh"
5 #include "dialog_firstrun.qh"
6 #include "textbox.qh"
7 #include "textlabel.qh"
8 #include "button.qh"
9 #include "util.qh"
10
11 void Close_Clicked(entity btn, entity me)
12 {
13         LOG_INFOF("Accepted ToS version %d", _Nex_ExtResponseSystem_NewToS);
14         cvar_set("_termsofservice_accepted", ftos(_Nex_ExtResponseSystem_NewToS));
15         localcmd("saveconfig");
16         if (main.firstRunDialog.shouldShow())
17                 main.firstDraw = true;
18         Dialog_Close(btn, me);
19 }
20
21 void DontAccept_Clicked(entity btn, entity me)
22 {
23         localcmd("quit");
24 }
25
26 void XonoticToSDialog_loadXonoticToS(entity me)
27 {
28         string downloadurl = "http://maria.omaera.org/tos.txt";
29         url_single_fopen(downloadurl, FILE_READ, XonoticToS_OnGet, me);
30 }
31
32 void XonoticToS_OnGet(entity fh, entity me, int status)
33 {
34         switch (status) {
35                 case URL_READY_CLOSED:
36                 {
37                         break;
38                 }
39                 case URL_READY_ERROR:
40                 {
41                         me.text = strzone("Error reading ToS");
42                         me.textBox.setText(me.textBox, me.text);
43                         break;
44                 }
45                 case URL_READY_CANREAD:
46                 {
47                         strfree(me.text);
48                         string temp = "";
49                         for (string s; (s = url_fgets(fh)); )
50                         {
51                                 if (temp != "")
52                                         temp = strcat(temp, "\n", s);
53                                 else
54                                         temp = s;
55                         }
56                         url_fclose(fh);
57                         me.text = strzone(temp);
58                         me.textBox.setText(me.textBox, me.text);
59                         break;
60                 }
61                 default:
62                 {
63                         break;
64                 }
65         }
66 }
67
68 bool XonoticToSDialog_shouldShow()
69 {
70         return (_Nex_ExtResponseSystem_NewToS && _Nex_ExtResponseSystem_NewToS > autocvar__termsofservice_accepted);
71 }
72
73 void XonoticToSDialog_fill(entity me)
74 {
75         entity e;
76         string subtitle;
77
78         if (autocvar__termsofservice_accepted > 0)
79                 subtitle = _("Terms of Service have been updated. Please read them before continuing:");
80         else
81                 subtitle = _("Welcome to Xonotic! Please read the following Terms of Service:");
82
83         me.TR(me);
84         me.TD(me, 1, 5, e = makeXonoticTextLabel(0, subtitle));
85         e.allowWrap = 1;
86
87         me.TR(me);
88         me.TR(me);
89         me.TD(me, me.rows - 4, me.columns, me.textBox = makeXonoticTextBox());
90         me.loadXonoticToS(me);
91
92         me.TR(me);
93         me.gotoRC(me, me.rows - 1, 0);
94
95         me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Accept"), '0 0 0'));
96         e.onClick = Close_Clicked;
97         e.onClickEntity = me;
98
99         me.TD(me, 1, me.columns/2, e = makeXonoticButton(_("Don't accept (quit the game)"), '0 0 0'));
100         e.onClick = DontAccept_Clicked;
101         e.onClickEntity = me;
102 }
103