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