Switch to the old (safer) instantaction system. With the only exception of allowing...
[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                 if(substring(s, 0, 4) == "set ")\r
30                         s = substring(s, 4, strlen(s) - 4);\r
31                 n = tokenize_console(s);\r
32                 if(argv(0) == "bot_number")\r
33                         cvar_set("bot_number", argv(1));\r
34                 else if(argv(0) == "skill")\r
35                         cvar_set("skill", argv(1));\r
36                 else if(argv(0) == "timelimit")\r
37                         cvar_set("timelimit_override", argv(1));\r
38                 else if(argv(0) == "fraglimit")\r
39                         cvar_set("fraglimit_override", argv(1));\r
40                 else if(argv(0) == "gametype")\r
41                         MapInfo_SwitchGameType(MapInfo_Type_FromString(argv(1)));\r
42                 else if(argv(0) == "changelevel")\r
43                 {\r
44                         fclose(fh);\r
45                         localcmd("\nmenu_loadmap_prepare\n");\r
46                         MapInfo_LoadMap(argv(1));\r
47                         cvar_set("lastlevel", "1");\r
48                         return;\r
49                 }\r
50         }\r
51         fclose(fh);\r
52 }\r
53 \r
54 void fillVoretSingleplayerDialog(entity me)\r
55 {\r
56         entity e, btnPrev, btnNext, lblTitle;\r
57 \r
58         me.TR(me);\r
59                 me.TDempty(me, (me.columns - 3) / 2);\r
60                 me.TD(me, 2, 3, e = makeVoretBigButton("Instant action! (random map with bots)", '0 0 0'));\r
61                         e.onClick = InstantAction_LoadMap;\r
62                         e.onClickEntity = NULL;\r
63         me.TR(me);\r
64         me.TR(me);\r
65         me.TR(me);\r
66                 me.TD(me, 1, 1, btnPrev = makeVoretButton("<<", '0 0 0'));\r
67                 me.TD(me, 1, me.columns - 2, lblTitle = makeVoretTextLabel(0.5, "???"));\r
68                 me.TD(me, 1, 1, btnNext = makeVoretButton(">>", '0 0 0'));\r
69         me.TR(me);\r
70                 me.TD(me, me.rows - 5, me.columns, me.campaignBox = makeVoretCampaignList());\r
71                         btnPrev.onClick = MultiCampaign_Prev;\r
72                         btnPrev.onClickEntity = me.campaignBox;\r
73                         btnNext.onClick = MultiCampaign_Next;\r
74                         btnNext.onClickEntity = me.campaignBox;\r
75                         me.campaignBox.buttonNext = btnNext;\r
76                         me.campaignBox.buttonPrev = btnPrev;\r
77                         me.campaignBox.labelTitle = lblTitle;\r
78                         me.campaignBox.campaignGo(me.campaignBox, 0);\r
79 \r
80         me.gotoRC(me, me.rows - 1, 0);\r
81                 //me.TD(me, 1, 2, e = makeVoretModButton("Singleplayer"));\r
82                 me.TD(me, 1, me.columns, e = makeVoretButton("Start Singleplayer!", '0 0 0'));\r
83                         e.onClick = CampaignList_LoadMap;\r
84                         e.onClickEntity = me.campaignBox;\r
85 }\r
86 #endif\r