]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_singleplayer.c
Merge remote branch 'origin/fruitiex/cl_vyes'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_singleplayer.c
1 #ifdef INTERFACE
2 CLASS(XonoticSingleplayerDialog) EXTENDS(XonoticDialog)
3         METHOD(XonoticSingleplayerDialog, fill, void(entity))
4         ATTRIB(XonoticSingleplayerDialog, title, string, "Singleplayer")
5         ATTRIB(XonoticSingleplayerDialog, color, vector, SKINCOLOR_DIALOG_SINGLEPLAYER)
6         ATTRIB(XonoticSingleplayerDialog, intendedWidth, float, 0.80)
7         ATTRIB(XonoticSingleplayerDialog, rows, float, 24)
8         ATTRIB(XonoticSingleplayerDialog, columns, float, 5)
9         ATTRIB(XonoticSingleplayerDialog, campaignBox, entity, NULL)
10 ENDCLASS(XonoticSingleplayerDialog)
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 XonoticSingleplayerDialog_fill(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 = makeXonoticBigButton("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 = makeXonoticButton("<<", '0 0 0'));
66                 me.TD(me, 1, me.columns - 2, lblTitle = makeXonoticTextLabel(0.5, "???"));
67                 me.TD(me, 1, 1, btnNext = makeXonoticButton(">>", '0 0 0'));
68         me.TR(me);
69                 me.TD(me, me.rows - 5, me.columns, me.campaignBox = makeXonoticCampaignList());
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, me.columns, e = makeXonoticButton("Start Singleplayer!", '0 0 0'));
81                         e.onClick = CampaignList_LoadMap;
82                         e.onClickEntity = me.campaignBox;
83 }
84 #endif