]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_create.qc
Add "Quit campaign" / "Quit current game" button to Singleplayer and Multiplayer...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_create.qc
1 #include "dialog_multiplayer_create.qh"
2
3 #include "dialog_multiplayer_create_mapinfo.qh"
4 #include "dialog_multiplayer_create_mutators.qh"
5
6 #include "gametypelist.qh"
7 #include "maplist.qh"
8 #include <common/mapinfo.qh>
9
10 #include "image.qh"
11 #include "textslider.qh"
12 #include "textlabel.qh"
13 #include "slider.qh"
14 #include "mainwindow.qh"
15 #include "button.qh"
16 #include "inputbox.qh"
17
18 void GameType_ConfigureSliders(entity me, string pLabel, float pMin, float pMax, float pStep, string pCvar, string tCvar, string pTooltip)
19 {
20         int i;
21         entity e = me.sliderFraglimit;
22         entity l = me.labelFraglimit;
23         e.configureXonoticTextSlider(e, pCvar, pTooltip);
24         e.disabled = l.disabled = !pCvar;
25         l.setText(l, pLabel);
26
27         // clear old values
28         for(i = 0; i < e.nValues; ++i);
29         {
30                 strfree(e.(valueStrings[i]));
31                 strfree(e.(valueIdentifiers[i]));
32         }
33         e.clearValues(e);
34
35         if(pCvar != "")
36         {
37                 // set new values
38                 e.addValue(e, strzone(_("Default")), strzone("-1"));
39                 for(i = pMin; i <= pMax; i += pStep) { e.addValue(e, strzone(ftos(i)), strzone(ftos(i))); }
40                 e.addValue(e, strzone(_("Unlimited")), strzone("0"));
41         }
42         e.configureXonoticTextSliderValues(e);
43
44
45         entity t = me.sliderTeams;
46         entity tl = me.labelTeams;
47         t.configureXonoticTextSlider(t, tCvar, string_null);
48         tl.disabled = t.disabled = !tCvar;
49         t.nValues = (tCvar == "") ? 0 : 4; // instead of clearing / readding the very same values
50         t.configureXonoticTextSliderValues(t);
51 }
52
53 void GameType_ConfigureSliders_for_CurrentGametype(entity me)
54 {
55         Gametype gt = MapInfo_CurrentGametype();
56         gt.m_configuremenu(gt, me, GameType_ConfigureSliders);
57 }
58
59 entity makeXonoticServerCreateTab()
60 {
61         entity me;
62         me = NEW(XonoticServerCreateTab);
63         me.configureDialog(me);
64         return me;
65 }
66
67 .entity quitGameButton;
68 void XonoticServerCreateTab_draw(entity me)
69 {
70         entity e = me.quitGameButton;
71         e.disabled = !(gamestatus & (GAME_ISSERVER | GAME_CONNECTED));
72         if(cvar("g_campaign"))
73                 e.setText(e, _("Quit campaign"));
74         else
75                 e.setText(e, _("Quit current game"));
76         SUPER(XonoticServerCreateTab).draw(me);
77 }
78
79 void XonoticServerCreateTab_fill(entity me)
80 {
81         entity e, e0;
82
83         // the left half begins here
84
85         me.gotoRC(me, 0.5, 0);
86                 me.TD(me, 1, 3, makeXonoticHeaderLabel(_("Gametype")));
87         me.TR(me);
88                 me.TD(me, 10.5, 3, e = makeXonoticGametypeList());
89
90         me.gotoRC(me, 12.5, 0);
91                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Time limit:")));
92                 me.TD(me, 1, 2, e = makeXonoticTextSlider_T("timelimit_override",
93                         _("Timelimit in minutes that when hit, will end the match")));
94                         #define ADDVALUE_MINUTES(i) e.addValue(e, strzone(sprintf(_("%d minutes"), i)), #i)
95                         e.addValue(e, ZCTX(_("TIMLIM^Default")), "-1");
96                         e.addValue(e, _("1 minute"), "1");
97                         ADDVALUE_MINUTES(2);
98                         ADDVALUE_MINUTES(3);
99                         ADDVALUE_MINUTES(4);
100                         ADDVALUE_MINUTES(5);
101                         ADDVALUE_MINUTES(6);
102                         ADDVALUE_MINUTES(7);
103                         ADDVALUE_MINUTES(8);
104                         ADDVALUE_MINUTES(9);
105                         ADDVALUE_MINUTES(10);
106                         ADDVALUE_MINUTES(15);
107                         ADDVALUE_MINUTES(20);
108                         ADDVALUE_MINUTES(25);
109                         ADDVALUE_MINUTES(30);
110                         ADDVALUE_MINUTES(40);
111                         ADDVALUE_MINUTES(50);
112                         ADDVALUE_MINUTES(60);
113                         e.addValue(e, ZCTX(_("TIMLIM^Infinite")), "0");
114                         e.configureXonoticTextSliderValues(e);
115                         #undef ADDVALUE_MINUTES
116         me.TR(me);
117                 me.TD(me, 1, 1, me.labelFraglimit = makeXonoticTextLabel(0, _("Frag limit:")));
118                 me.TD(me, 1, 2, e = me.sliderFraglimit = makeXonoticTextSlider("fraglimit_override"));
119
120         me.gotoRC(me, 15, 0);
121                 me.TD(me, 1, 1, me.labelTeams = makeXonoticTextLabel(0, _("Teams:")));
122                 me.TD(me, 1, 2, e = me.sliderTeams = makeXonoticTextSlider(string_null));
123                         e.addValue(e, _("Default"), "0");
124                         e.addValue(e, _("2 teams"), "2");
125                         e.addValue(e, _("3 teams"), "3");
126                         e.addValue(e, _("4 teams"), "4");
127                         e.configureXonoticTextSliderValues(e);
128         me.TR(me);
129                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Player slots:")));
130                 me.TD(me, 1, 2, e = makeXonoticSlider_T(1, 32, 1, "menu_maxplayers",
131                         _("The maximum amount of players or bots that can be connected to your server at once")));
132         me.TR(me);
133                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Number of bots:")));
134                 me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 9, 1, "bot_number",
135                         _("Amount of bots on your server")));
136         me.TR(me);
137                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Bot skill:")));
138                         setDependent(e, "bot_number", 0, -1);
139                 me.TD(me, 1, 2, e = makeXonoticTextSlider_T("skill",
140                         _("Specify how experienced the bots will be")));
141                         e.addValue(e, _("Botlike"), "0");
142                         e.addValue(e, _("Beginner"), "1");
143                         e.addValue(e, _("You will win"), "2");
144                         e.addValue(e, _("You can win"), "3");
145                         e.addValue(e, _("You might win"), "4");
146                         e.addValue(e, _("Advanced"), "5");
147                         e.addValue(e, _("Expert"), "6");
148                         e.addValue(e, _("Pro"), "7");
149                         e.addValue(e, _("Assassin"), "8");
150                         e.addValue(e, _("Unhuman"), "9");
151                         e.addValue(e, _("Godlike"), "10");
152                         e.configureXonoticTextSliderValues(e);
153                         setDependent(e, "bot_number", 0, -1);
154
155         me.gotoRC(me, me.rows - 3.8, 0);
156                 me.TD(me, 1, 3, e0 = makeXonoticTextLabel(0.5, string_null));
157                         e0.textEntity = main.mutatorsDialog;
158                         e0.allowCut = 1;
159                         //e0.allowWrap = 1;
160
161         // mapListBox is in the right column but the ref is needed for mutators dialog here
162         me.mapListBox = makeXonoticMapList();
163         // here we use the following line instead of me.TR(me) for better visual spacing;
164         // this decision was made in this poll: http://forums.xonotic.org/showthread.php?tid=5445
165         me.gotoRC(me, me.rows - 2.5, 0);
166                 me.TDempty(me, 0.5);
167                 me.TD(me, 1, 2, e = makeXonoticButton_T(_("Mutators..."), '0 0 0',
168                         _("Mutators and weapon arenas")));
169                         e.onClick = DialogOpenButton_Click;
170                         e.onClickEntity = main.mutatorsDialog;
171                         main.mutatorsDialog.refilterEntity = me.mapListBox;
172
173         // The right half begins here
174
175         me.gotoRC(me, 0.5, 3.2); me.setFirstColumn(me, me.currentColumn);
176                 // the maplistbox
177                 me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Maplist")));
178                         makeCallback(e, me.mapListBox, me.mapListBox.refilterCallback);
179         me.TR(me);
180                 // we use 5.8 here to visually match the bottom line of the component on the left (Bot Skill)
181                 me.TD(me, me.rows - 6.8, 3, me.mapListBox);
182
183         me.gotoRC(me, me.rows - 4.5, me.firstColumn);
184                 // string filter label and box
185                 me.TD(me, 1, 0.35, e = makeXonoticTextLabel(1, _("Filter:")));
186                 me.mapListBox.stringFilterBox = makeXonoticInputBox_T(0, string_null,
187                         _("Click here or Ctrl-F to provide a keyword to narrow down the map list. Ctrl-Delete to clear; Enter when done."));
188                 me.TD(me, 1, me.columns - me.firstColumn - 0.35, e = me.mapListBox.stringFilterBox);
189                         e.onChange = MapList_StringFilterBox_Change;
190                         e.keyDown = MapList_StringFilterBox_keyDown;
191                         e.onChangeEntity = me.mapListBox;
192
193         me.gotoRC(me, me.rows - 3.5, me.firstColumn);
194                 // the selection buttons
195                 me.TDempty(me, 0.2);
196                 me.TD(me, 1, 1.3, e = makeXonoticButton_T(_("Add shown"), '0 0 0',
197                         _("Add the maps shown in the list to your selection")));
198                         e.onClick = MapList_Add_Shown;
199                         e.onClickEntity = me.mapListBox;
200                 me.TD(me, 1, 1.3, e = makeXonoticButton_T(_("Remove shown"), '0 0 0',
201                         _("Remove the maps shown in the list from your selection")));
202                         e.onClick = MapList_Remove_Shown;
203                         e.onClickEntity = me.mapListBox;
204         me.gotoRC(me, me.rows - 2.5, me.firstColumn);
205                 me.TDempty(me, 0.2);
206                 me.TD(me, 1, 1.3, e = makeXonoticButton_T(_("Add all"), '0 0 0',
207                         _("Add every available map to your selection")));
208                         e.onClick = MapList_Add_All;
209                         e.onClickEntity = me.mapListBox;
210                 me.TD(me, 1, 1.3, e = makeXonoticButton_T(_("Remove all"), '0 0 0',
211                         _("Remove all the maps from your selection")));
212                         e.onClick = MapList_Remove_All;
213                         e.onClickEntity = me.mapListBox;
214
215         // bottom row
216         me.gotoRC(me, me.rows - 1, 0);
217                 me.TDempty(me, me.columns * 1/12);
218                 me.TD(me, 1, me.columns * 5/12, me.quitGameButton = makeXonoticCommandButton(string_null, '0 0 0', QUITGAME_CMD, 0));
219                 me.TD(me, 1, me.columns * 5/12, e = makeXonoticButton(_("Start multiplayer!"), '0 0 0'));
220                         e.onClick = MapList_LoadMap;
221                         e.onClickEntity = me.mapListBox;
222                         me.mapListBox.startButton = e;
223
224         GameType_ConfigureSliders_for_CurrentGametype(me);
225 }
226
227 void XonoticServerCreateTab_gameTypeChangeNotify(entity me)
228 {
229         GameType_ConfigureSliders_for_CurrentGametype(me);
230
231         me.mapListBox.refilter(me.mapListBox);
232 }
233
234 void XonoticServerCreateTab_gameTypeSelectNotify(entity me)
235 {
236         me.setFocus(me, me.mapListBox);
237 }