Actually, set the gametype in the .instantaction file
[voretournament/voretournament.git] / data / qcsrc / menu / voret / dialog_singleplayer.c
1 #ifdef INTERFACE\r
2 CLASS(VoretSingleplayerDialog) EXTENDS(VoretDialog)\r
3         METHOD(VoretSingleplayerDialog, fill, void(entity))\r
4         ATTRIB(VoretSingleplayerDialog, title, string, "Singleplayer")\r
5         ATTRIB(VoretSingleplayerDialog, color, vector, SKINCOLOR_DIALOG_SINGLEPLAYER)\r
6         ATTRIB(VoretSingleplayerDialog, intendedWidth, float, 0.80)\r
7         ATTRIB(VoretSingleplayerDialog, rows, float, 24)\r
8         ATTRIB(VoretSingleplayerDialog, columns, float, 5)\r
9         ATTRIB(VoretSingleplayerDialog, campaignBox, entity, NULL)\r
10 ENDCLASS(VoretSingleplayerDialog)\r
11 #endif\r
12 \r
13 #ifdef IMPLEMENTATION\r
14 \r
15 void InstantAction_LoadMap(entity btn, entity dummy)\r
16 {\r
17         float glob, i, n, fh;\r
18         string s;\r
19         glob = search_begin("maps/*.instantaction", TRUE, TRUE);\r
20         if(glob < 0)\r
21                 return;\r
22         i = ceil(random() * search_getsize(glob)) - 1;\r
23         fh = fopen(search_getfilename(glob, i), FILE_READ);\r
24         search_end(glob);\r
25         if(fh < 0)\r
26                 return;\r
27         while((s = fgets(fh)))\r
28         {\r
29                 n = tokenize_console(s);\r
30                 if(argv(0) == "changelevel")\r
31                 {\r
32                         fclose(fh);\r
33                         localcmd("\nmenu_loadmap_prepare\n");\r
34                         MapInfo_LoadMap(argv(1));\r
35                         cvar_set("lastlevel", "1");\r
36                         return;\r
37                 }\r
38                 else if(argv(0) == "gametype")\r
39                         MapInfo_SwitchGameType(MapInfo_Type_FromString(argv(1)));\r
40                 else if(argv(0) != "" && argv(0) != "//" && argv(0) != "#")\r
41                         cvar_set(argv(0), argv(1)); //TODO: sanity check, this can currently set any cvar!\r
42         }\r
43         fclose(fh);\r
44 }\r
45 \r
46 void fillVoretSingleplayerDialog(entity me)\r
47 {\r
48         entity e, btnPrev, btnNext, lblTitle;\r
49 \r
50         me.TR(me);\r
51                 me.TDempty(me, (me.columns - 3) / 2);\r
52                 me.TD(me, 2, 3, e = makeVoretBigButton("Instant action! (random map with bots)", '0 0 0'));\r
53                         e.onClick = InstantAction_LoadMap;\r
54                         e.onClickEntity = NULL;\r
55         me.TR(me);\r
56         me.TR(me);\r
57         me.TR(me);\r
58                 me.TD(me, 1, 1, btnPrev = makeVoretButton("<<", '0 0 0'));\r
59                 me.TD(me, 1, me.columns - 2, lblTitle = makeVoretTextLabel(0.5, "???"));\r
60                 me.TD(me, 1, 1, btnNext = makeVoretButton(">>", '0 0 0'));\r
61         me.TR(me);\r
62                 me.TD(me, me.rows - 5, me.columns, me.campaignBox = makeVoretCampaignList());\r
63                         btnPrev.onClick = MultiCampaign_Prev;\r
64                         btnPrev.onClickEntity = me.campaignBox;\r
65                         btnNext.onClick = MultiCampaign_Next;\r
66                         btnNext.onClickEntity = me.campaignBox;\r
67                         me.campaignBox.buttonNext = btnNext;\r
68                         me.campaignBox.buttonPrev = btnPrev;\r
69                         me.campaignBox.labelTitle = lblTitle;\r
70                         me.campaignBox.campaignGo(me.campaignBox, 0);\r
71 \r
72         me.gotoRC(me, me.rows - 1, 0);\r
73                 //me.TD(me, 1, 2, e = makeVoretModButton("Singleplayer"));\r
74                 me.TD(me, 1, me.columns, e = makeVoretButton("Start Singleplayer!", '0 0 0'));\r
75                         e.onClick = CampaignList_LoadMap;\r
76                         e.onClickEntity = me.campaignBox;\r
77 }\r
78 #endif\r