16a29f5a91ff14d80e4aa7d1f383d6487806f478
[divverent/nexuiz.git] / data / qcsrc / menu / nexuiz / dialog_singleplayer.c
1 #ifdef INTERFACE
2 CLASS(NexuizSingleplayerDialog) EXTENDS(NexuizDialog)
3         METHOD(NexuizSingleplayerDialog, fill, void(entity))
4         ATTRIB(NexuizSingleplayerDialog, title, string, "Singleplayer")
5         ATTRIB(NexuizSingleplayerDialog, color, vector, SKINCOLOR_DIALOG_SINGLEPLAYER)
6         ATTRIB(NexuizSingleplayerDialog, intendedWidth, float, 0.80)
7         ATTRIB(NexuizSingleplayerDialog, rows, float, 24)
8         ATTRIB(NexuizSingleplayerDialog, columns, float, 5)
9         ATTRIB(NexuizSingleplayerDialog, campaignBox, entity, NULL)
10 ENDCLASS(NexuizSingleplayerDialog)
11 #endif
12
13 #ifdef IMPLEMENTATION
14
15 void InstantAction_LoadMap(entity btn, entity dummy)
16 {
17         float glob, i, n, fh;
18         string s;
19         glob = search_begin("maps/*.instantaction", TRUE, TRUE);
20         if(glob < 0)
21                 return;
22         i = ceil(random() * search_getsize(glob)) - 1;
23         fh = fopen(search_getfilename(glob, i), FILE_READ);
24         search_end(glob);
25         if(fh < 0)
26                 return;
27         while((s = fgets(fh)))
28         {
29                 if(substring(s, 0, 4) == "set ")
30                         s = substring(s, 4, strlen(s) - 4);
31                 n = tokenize_console(s);
32                 if(argv(0) == "bot_number")
33                         cvar_set("bot_number", argv(1));
34                 else if(argv(0) == "skill")
35                         cvar_set("skill", argv(1));
36                 else if(argv(0) == "timelimit")
37                         cvar_set("timelimit_override", argv(1));
38                 else if(argv(0) == "fraglimit")
39                         cvar_set("fraglimit_override", argv(1));
40                 else if(argv(0) == "changelevel")
41                 {
42                         fclose(fh);
43                         localcmd("\nmenu_loadmap_prepare\n");
44                         MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);
45                         MapInfo_LoadMap(argv(1));
46                         cvar_set("lastlevel", "1");
47                         return;
48                 }
49         }
50         fclose(fh);
51 }
52
53 void fillNexuizSingleplayerDialog(entity me)
54 {
55         entity e, btnPrev, btnNext, lblTitle;
56
57         me.TR(me);
58                 me.TDempty(me, (me.columns - 3) / 2);
59                 me.TD(me, 2, 3, e = makeNexuizBigButton("Instant action! (random map with bots)", '0 0 0'));
60                         e.onClick = InstantAction_LoadMap;
61                         e.onClickEntity = NULL;
62         me.TR(me);
63         me.TR(me);
64         me.TR(me);
65                 me.TD(me, 1, 1, btnPrev = makeNexuizButton("<<", '0 0 0'));
66                 me.TD(me, 1, me.columns - 2, lblTitle = makeNexuizTextLabel(0.5, "???"));
67                 me.TD(me, 1, 1, btnNext = makeNexuizButton(">>", '0 0 0'));
68         me.TR(me);
69                 me.TD(me, me.rows - 6, me.columns, me.campaignBox = makeNexuizCampaignList());
70                         btnPrev.onClick = MultiCampaign_Prev;
71                         btnPrev.onClickEntity = me.campaignBox;
72                         btnNext.onClick = MultiCampaign_Next;
73                         btnNext.onClickEntity = me.campaignBox;
74                         me.campaignBox.buttonNext = btnNext;
75                         me.campaignBox.buttonPrev = btnPrev;
76                         me.campaignBox.labelTitle = lblTitle;
77                         me.campaignBox.campaignGo(me.campaignBox, 0);
78
79         me.gotoRC(me, me.rows - 1, 0);
80                 me.TD(me, 1, 2, e = makeNexuizModButton("Singleplayer"));
81                 me.TD(me, 1, me.columns - 2 , e = makeNexuizButton("Start Singleplayer!", '0 0 0'));
82                         e.onClick = CampaignList_LoadMap;
83                         e.onClickEntity = me.campaignBox;
84 }
85 #endif