]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_create.qc
Merge branch 'master' into DefaultUser/trigger_cleanup
[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         switch(MapInfo_CurrentGametype())
56         {
57                 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;
58                 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;
59                 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;
60                 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;
61                 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;
62                 case MAPINFO_TYPE_LMS:             GameType_ConfigureSliders(me, _("Lives:"),           3,   50,  1, "g_lms_lives_override",      string_null,                    string_null); break;
63                 case MAPINFO_TYPE_RACE:            GameType_ConfigureSliders(me, _("Laps:"),            1,   25,  1, "g_race_laps_limit",         string_null,                    string_null); break;
64                 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;
65                 case MAPINFO_TYPE_ASSAULT:         GameType_ConfigureSliders(me, _("Point limit:"),    50,  500, 10, string_null,                 string_null,                    string_null); break;
66                 case MAPINFO_TYPE_ONSLAUGHT:       GameType_ConfigureSliders(me, _("Point limit:"),    50,  500, 10, string_null,                 string_null,                    string_null); break;
67                 case MAPINFO_TYPE_CTS:             GameType_ConfigureSliders(me, _("Point limit:"),    50,  500, 10, string_null,                 string_null,                    string_null); break;
68                 case MAPINFO_TYPE_INVASION:        GameType_ConfigureSliders(me, _("Point limit:"),    50,  500, 10, string_null,                 string_null,                    string_null); break;
69                 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;
70                 default:                           GameType_ConfigureSliders(me, _("Frag limit:"),      5,  100,  5, "fraglimit_override",        string_null,                    _("The amount of frags needed before the match will end")); break;
71         }
72 }
73
74 entity makeXonoticServerCreateTab()
75 {
76         entity me;
77         me = NEW(XonoticServerCreateTab);
78         me.configureDialog(me);
79         return me;
80 }
81
82 void XonoticServerCreateTab_fill(entity me)
83 {
84         entity e, e0;
85
86         // the left half begins here
87
88         me.gotoRC(me, 0.5, 0);
89                 me.TD(me, 1, 3, makeXonoticHeaderLabel(_("Gametype")));
90         me.TR(me);
91                 me.TD(me, 10.5, 3, e = makeXonoticGametypeList());
92
93         me.gotoRC(me, 12.5, 0);
94                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Time limit:")));
95                 me.TD(me, 1, 2, e = makeXonoticTextSlider_T("timelimit_override",
96                         _("Timelimit in minutes that when hit, will end the match")));
97                         #define ADDVALUE_MINUTES(i) e.addValue(e, strzone(sprintf(_("%d minutes"), i)), #i)
98                         e.addValue(e, ZCTX(_("TIMLIM^Default")), "-1");
99                         e.addValue(e, _("1 minute"), "1");
100                         ADDVALUE_MINUTES(2);
101                         ADDVALUE_MINUTES(3);
102                         ADDVALUE_MINUTES(4);
103                         ADDVALUE_MINUTES(5);
104                         ADDVALUE_MINUTES(6);
105                         ADDVALUE_MINUTES(7);
106                         ADDVALUE_MINUTES(8);
107                         ADDVALUE_MINUTES(9);
108                         ADDVALUE_MINUTES(10);
109                         ADDVALUE_MINUTES(15);
110                         ADDVALUE_MINUTES(20);
111                         ADDVALUE_MINUTES(25);
112                         ADDVALUE_MINUTES(30);
113                         ADDVALUE_MINUTES(40);
114                         ADDVALUE_MINUTES(50);
115                         ADDVALUE_MINUTES(60);
116                         e.addValue(e, ZCTX(_("TIMLIM^Infinite")), "0");
117                         e.configureXonoticTextSliderValues(e);
118                         #undef ADDVALUE_MINUTES
119         me.TR(me);
120                 me.TD(me, 1, 1, me.labelFraglimit = makeXonoticTextLabel(0, _("Frag limit:")));
121                 me.TD(me, 1, 2, e = me.sliderFraglimit = makeXonoticTextSlider("fraglimit_override"));
122
123         me.gotoRC(me, 15, 0);
124                 me.TD(me, 1, 1, me.labelTeams = makeXonoticTextLabel(0, _("Teams:")));
125                 me.TD(me, 1, 2, e = me.sliderTeams = makeXonoticTextSlider(string_null));
126                         e.addValue(e, _("Default"), "0");
127                         e.addValue(e, _("2 teams"), "2");
128                         e.addValue(e, _("3 teams"), "3");
129                         e.addValue(e, _("4 teams"), "4");
130                         e.configureXonoticTextSliderValues(e);
131         me.TR(me);
132                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Player slots:")));
133                 me.TD(me, 1, 2, e = makeXonoticSlider_T(1, 32, 1, "menu_maxplayers",
134                         _("The maximum amount of players or bots that can be connected to your server at once")));
135         me.TR(me);
136                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Number of bots:")));
137                 me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 9, 1, "bot_number",
138                         _("Amount of bots on your server")));
139         me.TR(me);
140                 me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Bot skill:")));
141                         setDependent(e, "bot_number", 0, -1);
142                 me.TD(me, 1, 2, e = makeXonoticTextSlider_T("skill",
143                         _("Specify how experienced the bots will be")));
144                         e.addValue(e, _("Botlike"), "0");
145                         e.addValue(e, _("Beginner"), "1");
146                         e.addValue(e, _("You will win"), "2");
147                         e.addValue(e, _("You can win"), "3");
148                         e.addValue(e, _("You might win"), "4");
149                         e.addValue(e, _("Advanced"), "5");
150                         e.addValue(e, _("Expert"), "6");
151                         e.addValue(e, _("Pro"), "7");
152                         e.addValue(e, _("Assassin"), "8");
153                         e.addValue(e, _("Unhuman"), "9");
154                         e.addValue(e, _("Godlike"), "10");
155                         e.configureXonoticTextSliderValues(e);
156                         setDependent(e, "bot_number", 0, -1);
157
158         me.gotoRC(me, me.rows - 3.8, 0);
159                 me.TD(me, 1, 3, e0 = makeXonoticTextLabel(0.5, string_null));
160                         e0.textEntity = main.mutatorsDialog;
161                         e0.allowCut = 1;
162                         //e0.allowWrap = 1;
163
164         // mapListBox is in the right column but the ref is needed for mutators dialog here
165         me.mapListBox = makeXonoticMapList();
166         // here we use the following line instead of me.TR(me) for better visual spacing;
167         // this decision was made in this poll: http://forums.xonotic.org/showthread.php?tid=5445
168         me.gotoRC(me, me.rows - 2.5, 0);
169                 me.TDempty(me, 0.5);
170                 me.TD(me, 1, 2, e = makeXonoticButton_T(_("Mutators..."), '0 0 0',
171                         _("Mutators and weapon arenas")));
172                         e.onClick = DialogOpenButton_Click;
173                         e.onClickEntity = main.mutatorsDialog;
174                         main.mutatorsDialog.refilterEntity = me.mapListBox;
175
176         // The right half begins here
177
178         me.gotoRC(me, 0.5, 3.2); me.setFirstColumn(me, me.currentColumn);
179                 // the maplistbox
180                 me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Maplist")));
181                         makeCallback(e, me.mapListBox, me.mapListBox.refilterCallback);
182         me.TR(me);
183                 // we use 5.8 here to visually match the bottom line of the component on the left (Bot Skill)
184                 me.TD(me, me.rows - 6.8, 3, me.mapListBox);
185
186         me.gotoRC(me, me.rows - 4.5, me.firstColumn);
187                 // string filter label and box
188                 me.TD(me, 1, 0.35, e = makeXonoticTextLabel(1, _("Filter:")));
189                 me.mapListBox.stringFilterBox = makeXonoticInputBox_T(0, string_null,
190                         _("Click here or Ctrl-F to provide a keyword to narrow down the map list. Ctrl-Delete to clear; Enter when done."));
191                 me.TD(me, 1, me.columns - me.firstColumn - 0.35, e = me.mapListBox.stringFilterBox);
192                         e.onChange = MapList_StringFilterBox_Change;
193                         e.keyDown = MapList_StringFilterBox_keyDown;
194                         e.onChangeEntity = me.mapListBox;
195
196         me.gotoRC(me, me.rows - 3.5, me.firstColumn);
197                 // the selection buttons
198                 me.TDempty(me, 0.2);
199                 me.TD(me, 1, 1.3, e = makeXonoticButton_T(_("Add shown"), '0 0 0',
200                         _("Add the maps shown in the list to your selection")));
201                         e.onClick = MapList_Add_Shown;
202                         e.onClickEntity = me.mapListBox;
203                 me.TD(me, 1, 1.3, e = makeXonoticButton_T(_("Remove shown"), '0 0 0',
204                         _("Remove the maps shown in the list from your selection")));
205                         e.onClick = MapList_Remove_Shown;
206                         e.onClickEntity = me.mapListBox;
207         me.gotoRC(me, me.rows - 2.5, me.firstColumn);
208                 me.TDempty(me, 0.2);
209                 me.TD(me, 1, 1.3, e = makeXonoticButton_T(_("Add all"), '0 0 0',
210                         _("Add every available map to your selection")));
211                         e.onClick = MapList_Add_All;
212                         e.onClickEntity = me.mapListBox;
213                 me.TD(me, 1, 1.3, e = makeXonoticButton_T(_("Remove all"), '0 0 0',
214                         _("Remove all the maps from your selection")));
215                         e.onClick = MapList_Remove_All;
216                         e.onClickEntity = me.mapListBox;
217
218         // The big button at the bottom
219
220         me.gotoRC(me, me.rows - 1, 0);
221                 me.TD(me, 1, me.columns, e = makeXonoticButton(_("Start Multiplayer!"), '0 0 0'));
222                         e.onClick = MapList_LoadMap;
223                         e.onClickEntity = me.mapListBox;
224                         me.mapListBox.startButton = e;
225
226         GameType_ConfigureSliders_for_CurrentGametype(me);
227 }
228
229 void XonoticServerCreateTab_gameTypeChangeNotify(entity me)
230 {
231         GameType_ConfigureSliders_for_CurrentGametype(me);
232
233         me.mapListBox.refilter(me.mapListBox);
234 }
235
236 void XonoticServerCreateTab_gameTypeSelectNotify(entity me)
237 {
238         me.setFocus(me, me.mapListBox);
239 }