Better Instant Action system
[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_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);\r
35                         MapInfo_LoadMap(argv(1));\r
36                         cvar_set("lastlevel", "1");\r
37                         return;\r
38                 }\r
39                 else if(argv(0) != "" && argv(0) != "//" && argv(0) != "#")\r
40                         cvar_set(argv(0), argv(1)); //TODO: sanity check, this can currently set any cvar!\r
41         }\r
42         fclose(fh);\r
43 }\r
44 \r
45 void fillVoretSingleplayerDialog(entity me)\r
46 {\r
47         entity e, btnPrev, btnNext, lblTitle;\r
48 \r
49         me.TR(me);\r
50                 me.TDempty(me, (me.columns - 3) / 2);\r
51                 me.TD(me, 2, 3, e = makeVoretBigButton("Instant action! (random map with bots)", '0 0 0'));\r
52                         e.onClick = InstantAction_LoadMap;\r
53                         e.onClickEntity = NULL;\r
54         me.TR(me);\r
55         me.TR(me);\r
56         me.TR(me);\r
57                 me.TD(me, 1, 1, btnPrev = makeVoretButton("<<", '0 0 0'));\r
58                 me.TD(me, 1, me.columns - 2, lblTitle = makeVoretTextLabel(0.5, "???"));\r
59                 me.TD(me, 1, 1, btnNext = makeVoretButton(">>", '0 0 0'));\r
60         me.TR(me);\r
61                 me.TD(me, me.rows - 5, me.columns, me.campaignBox = makeVoretCampaignList());\r
62                         btnPrev.onClick = MultiCampaign_Prev;\r
63                         btnPrev.onClickEntity = me.campaignBox;\r
64                         btnNext.onClick = MultiCampaign_Next;\r
65                         btnNext.onClickEntity = me.campaignBox;\r
66                         me.campaignBox.buttonNext = btnNext;\r
67                         me.campaignBox.buttonPrev = btnPrev;\r
68                         me.campaignBox.labelTitle = lblTitle;\r
69                         me.campaignBox.campaignGo(me.campaignBox, 0);\r
70 \r
71         me.gotoRC(me, me.rows - 1, 0);\r
72                 //me.TD(me, 1, 2, e = makeVoretModButton("Singleplayer"));\r
73                 me.TD(me, 1, me.columns, e = makeVoretButton("Start Singleplayer!", '0 0 0'));\r
74                         e.onClick = CampaignList_LoadMap;\r
75                         e.onClickEntity = me.campaignBox;\r
76 }\r
77 #endif\r