]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_create.qc
Header police
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_create.qc
1 #include "dialog_multiplayer_create.qh"
2 #ifndef DIALOG_MULTIPLAYER_CREATE_H
3 #define DIALOG_MULTIPLAYER_CREATE_H
4 #include "tab.qc"
5 CLASS(XonoticServerCreateTab, XonoticTab)
6         METHOD(XonoticServerCreateTab, fill, void(entity));
7         METHOD(XonoticServerCreateTab, gameTypeChangeNotify, void(entity));
8         METHOD(XonoticServerCreateTab, gameTypeSelectNotify, void(entity));
9         ATTRIB(XonoticServerCreateTab, intendedWidth, float, 0.9)
10         ATTRIB(XonoticServerCreateTab, rows, float, 23)
11         ATTRIB(XonoticServerCreateTab, columns, float, 6.2) // added extra .2 for center space
12
13         ATTRIB(XonoticServerCreateTab, mapListBox, entity, NULL)
14         ATTRIB(XonoticServerCreateTab, sliderFraglimit, entity, NULL)
15         ATTRIB(XonoticServerCreateTab, sliderTeams, entity, NULL)
16         ATTRIB(XonoticServerCreateTab, sliderTimelimit, entity, NULL)
17         ATTRIB(XonoticServerCreateTab, labelFraglimit, entity, NULL)
18         ATTRIB(XonoticServerCreateTab, labelTeams, entity, NULL)
19 ENDCLASS(XonoticServerCreateTab)
20 entity makeXonoticServerCreateTab();
21 #endif
22
23 #ifdef IMPLEMENTATION
24
25 void GameType_ConfigureSliders(entity me, string pLabel, float pMin, float pMax, float pStep, string pCvar, string tCvar, string pTooltip)
26 {
27         int i;
28         entity e = me.sliderFraglimit;
29         entity l = me.labelFraglimit;
30         e.configureXonoticTextSlider(e, pCvar, pTooltip);
31         e.disabled = l.disabled = !pCvar;
32         l.setText(l, pLabel);
33
34         // clear old values
35         for(i = 0; i < e.nValues; ++i);
36         {
37                 if(e.(valueStrings[i]))
38                 {
39                         strunzone(e.(valueStrings[i]));
40                         e.(valueStrings[i]) = string_null;
41                 }
42                 if(e.(valueIdentifiers[i]))
43                 {
44                         strunzone(e.(valueIdentifiers[i]));
45                         e.(valueIdentifiers[i]) = string_null;
46                 }
47         }
48         e.clearValues(e);
49
50         if(pCvar != "")
51         {
52                 // set new values
53                 e.addValue(e, strzone(_("Default")), strzone("-1"));
54                 for(i = pMin; i <= pMax; i += pStep) { e.addValue(e, strzone(ftos(i)), strzone(ftos(i))); }
55                 e.addValue(e, strzone(_("Unlimited")), strzone("0"));
56         }
57         e.configureXonoticTextSliderValues(e);
58
59
60         entity t = me.sliderTeams;
61         entity tl = me.labelTeams;
62         t.configureXonoticTextSlider(t, tCvar, string_null);
63         tl.disabled = t.disabled = !tCvar;
64         t.nValues = (tCvar == "") ? 0 : 4; // instead of clearing / readding the very same values
65         t.configureXonoticTextSliderValues(t);
66 }
67
68 entity makeXonoticServerCreateTab()
69 {
70         entity me;
71         me = NEW(XonoticServerCreateTab);
72         me.configureDialog(me);
73         return me;
74 }
75
76 void XonoticServerCreateTab_fill(entity me)
77 {
78         entity e, e0;
79
80         // the left half begins here
81
82         me.gotoRC(me, 0.5, 0);
83                 me.TD(me, 1, 3, makeXonoticHeaderLabel(_("Gametype")));
84         me.TR(me);
85                 me.TD(me, 10.5, 3, e = makeXonoticGametypeList());
86
87         me.gotoRC(me, 12.5, 0);
88                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Time limit:")));
89                 me.TD(me, 1, 2, e = makeXonoticTextSlider_T("timelimit_override",
90                         _("Timelimit in minutes that when hit, will end the match")));
91                         #define ADDVALUE_MINUTES(i) e.addValue(e, strzone(sprintf(_("%d minutes"), i)), #i)
92                         e.addValue(e, ZCTX(_("TIMLIM^Default")), "-1");
93                         e.addValue(e, _("1 minute"), "1");
94                         ADDVALUE_MINUTES(2);
95                         ADDVALUE_MINUTES(3);
96                         ADDVALUE_MINUTES(4);
97                         ADDVALUE_MINUTES(5);
98                         ADDVALUE_MINUTES(6);
99                         ADDVALUE_MINUTES(7);
100                         ADDVALUE_MINUTES(8);
101                         ADDVALUE_MINUTES(9);
102                         ADDVALUE_MINUTES(10);
103                         ADDVALUE_MINUTES(15);
104                         ADDVALUE_MINUTES(20);
105                         ADDVALUE_MINUTES(25);
106                         ADDVALUE_MINUTES(30);
107                         ADDVALUE_MINUTES(40);
108                         ADDVALUE_MINUTES(50);
109                         ADDVALUE_MINUTES(60);
110                         e.addValue(e, ZCTX(_("TIMLIM^Infinite")), "0");
111                         e.configureXonoticTextSliderValues(e);
112                         #undef ADDVALUE_MINUTES
113         me.TR(me);
114                 me.TD(me, 1, 1, me.labelFraglimit = makeXonoticTextLabel(0, _("Frag limit:")));
115                 me.TD(me, 1, 2, e = me.sliderFraglimit = makeXonoticTextSlider("fraglimit_override"));
116
117         me.gotoRC(me, 15, 0);
118                 me.TD(me, 1, 1, me.labelTeams = makeXonoticTextLabel(0, _("Teams:")));
119                 me.TD(me, 1, 2, e = me.sliderTeams = makeXonoticTextSlider(string_null));
120                         e.addValue(e, _("Default"), "0");
121                         e.addValue(e, _("2 teams"), "2");
122                         e.addValue(e, _("3 teams"), "3");
123                         e.addValue(e, _("4 teams"), "4");
124                         e.configureXonoticTextSliderValues(e);
125         me.TR(me);
126                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Player slots:")));
127                 me.TD(me, 1, 2, e = makeXonoticSlider_T(1, 32, 1, "menu_maxplayers",
128                         _("The maximum amount of players or bots that can be connected to your server at once")));
129         me.TR(me);
130                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Number of bots:")));
131                 me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 9, 1, "bot_number",
132                         _("Amount of bots on your server")));
133         me.TR(me);
134                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Bot skill:")));
135                         setDependent(e, "bot_number", 0, -1);
136                 me.TD(me, 1, 2, e = makeXonoticTextSlider_T("skill",
137                         _("Specify how experienced the bots will be")));
138                         e.addValue(e, _("Botlike"), "0");
139                         e.addValue(e, _("Beginner"), "1");
140                         e.addValue(e, _("You will win"), "2");
141                         e.addValue(e, _("You can win"), "3");
142                         e.addValue(e, _("You might win"), "4");
143                         e.addValue(e, _("Advanced"), "5");
144                         e.addValue(e, _("Expert"), "6");
145                         e.addValue(e, _("Pro"), "7");
146                         e.addValue(e, _("Assassin"), "8");
147                         e.addValue(e, _("Unhuman"), "9");
148                         e.addValue(e, _("Godlike"), "10");
149                         e.configureXonoticTextSliderValues(e);
150                         setDependent(e, "bot_number", 0, -1);
151
152         me.gotoRC(me, me.rows - 3.8, 0);
153                 me.TD(me, 1, 3, e0 = makeXonoticTextLabel(0.5, string_null));
154                         e0.textEntity = main.mutatorsDialog;
155                         e0.allowCut = 1;
156                         //e0.allowWrap = 1;
157
158         // mapListBox is in the right column but the ref is needed for mutators dialog here
159         me.mapListBox = makeXonoticMapList();
160         // here we use the following line instead of me.TR(me) for better visual spacing;
161         // this decision was made in this poll: http://forums.xonotic.org/showthread.php?tid=5445
162         me.gotoRC(me, me.rows - 2.5, 0);
163                 me.TDempty(me, 0.5);
164                 me.TD(me, 1, 2, e = makeXonoticButton_T(_("Mutators..."), '0 0 0',
165                         _("Mutators and weapon arenas")));
166                         e.onClick = DialogOpenButton_Click;
167                         e.onClickEntity = main.mutatorsDialog;
168                         main.mutatorsDialog.refilterEntity = me.mapListBox;
169
170         // The right half begins here
171
172         me.gotoRC(me, 0.5, 3.2); me.setFirstColumn(me, me.currentColumn);
173                 // the maplistbox
174                 me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Maplist")));
175                         makeCallback(e, me.mapListBox, me.mapListBox.refilterCallback);
176         me.TR(me);
177                 // we use 5.8 here to visually match the bottom line of the component on the left (Bot Skill)
178                 me.TD(me, me.rows - 6.8, 3, me.mapListBox);
179
180         me.gotoRC(me, me.rows - 4.5, me.firstColumn);
181                 // string filter label and box
182                 me.TD(me, 1, 0.35, e = makeXonoticTextLabel(1, _("Filter:")));
183                 me.mapListBox.stringFilterBox = makeXonoticInputBox_T(0, string_null,
184                         _("Click here or Ctrl-F to provide a keyword to narrow down the map list. Ctrl-Delete to clear; Enter when done."));
185                 me.TD(me, 1, me.columns - me.firstColumn - 0.35, e = me.mapListBox.stringFilterBox);
186                         e.onChange = MapList_StringFilterBox_Change;
187                         e.keyDown = MapList_StringFilterBox_keyDown;
188                         e.onChangeEntity = me.mapListBox;
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