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