script: marked all unsafe pointer operations with `cast([unsafe])`
[k8vavoom.git] / progs / strife / cgame / IntermissionScreen.vc
blobce7f804e01ce2d5de28bed2c9979914becd77d36
1 //**************************************************************************
2 //**
3 //**    ##   ##    ##    ##   ##   ####     ####   ###     ###
4 //**    ##   ##  ##  ##  ##   ##  ##  ##   ##  ##  ####   ####
5 //**     ## ##  ##    ##  ## ##  ##    ## ##    ## ## ## ## ##
6 //**     ## ##  ########  ## ##  ##    ## ##    ## ##  ###  ##
7 //**      ###   ##    ##   ###    ##  ##   ##  ##  ##       ##
8 //**       #    ##    ##    #      ####     ####   ##       ##
9 //**
10 //**  Copyright (C) 1999-2006 Jānis Legzdiņš
11 //**  Copyright (C) 2018-2023 Ketmar Dark
12 //**
13 //**  This program is free software: you can redistribute it and/or modify
14 //**  it under the terms of the GNU General Public License as published by
15 //**  the Free Software Foundation, version 3 of the License ONLY.
16 //**
17 //**  This program is distributed in the hope that it will be useful,
18 //**  but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 //**  GNU General Public License for more details.
21 //**
22 //**  You should have received a copy of the GNU General Public License
23 //**  along with this program.  If not, see <http://www.gnu.org/licenses/>.
24 //**
25 //**************************************************************************
26 class IntermissionScreen : Widget;
28 enum
30   IMS_Stats,
31   IMS_Text,
32   IMS_Done
35 ClientGameBase ClGame;
37 float TextSpeed;
38 float TextWait;
40 // specifies current state
41 int interstate;
42 float intertime;
44 float HubCount;
45 string HubText;
46 name TextFlat;
47 int TextPic;
49 //==========================================================================
51 //  Start
53 //==========================================================================
55 void Start()
57   StopAllSounds(keepLastSwitch:true);
58   if (!ClGame.deathmatch && !ClGame.cl.Level.bNoIntermission)
59   {
60     print("Intermission stats are not yet implemented");
61   }
62   if (!ClGame.deathmatch)
63   {
64     IM_InitHubText();
65   }
66   else
67   {
68     CmdBuf_AddText("TeleportNewMap\n");
69   }
72 //==========================================================================
74 //  Tick
76 //==========================================================================
78 override void Tick(float DeltaTime)
80   intertime += DeltaTime;
81   if (ClGame.bSkipIntermission || intertime > HubCount)
82   {
83     CmdBuf_AddText("TeleportNewMap\n");
84     interstate = IMS_Done;
85     ClGame.bSkipIntermission = false;
86   }
89 //==========================================================================
91 //  OnDraw
93 //==========================================================================
95 override void OnDraw()
97   if (interstate == IMS_Done)
98   {
99     return;
100   }
102   switch (interstate)
103   {
104   case IMS_Text:
105     IM_DrawHubText();
106   }
109 //========================================================================
111 //  IM_InitHubText
113 //  Initialises the stats for single player mode
115 //========================================================================
117 void IM_InitHubText()
119   IntermissionText *itext =
120     ClGame.intermissionPhase == ClientGame::IM_Phase.Leave ? cast([unsafe])(&ClGame.im.LeaveText) :
121     ClGame.intermissionPhase == ClientGame::IM_Phase.Enter ? cast([unsafe])(&ClGame.im.EnterText) :
122     nullptr;
124   if (!itext.Text)
125   {
126     CmdBuf_AddText("TeleportNewMap\n");
127     interstate = IMS_Done;
128     return;
129   }
131   if (itext.bTextIsLump)
132   {
133     HubText = LoadTextLump(name(itext.Text));
134   }
135   else
136   {
137     HubText = itext.Text;
138   }
139   HubCount = float(strlenutf8(HubText)) * TextSpeed + TextWait;
141   TextFlat = '';
142   TextPic = 0;
143   if (itext.TextPic)
144   {
145     TextPic = R_RegisterPic(itext.TextPic);
146   }
147   else if (itext.TextFlat)
148   {
149     TextFlat = itext.TextFlat;
150   }
152   if (itext.TextMusic)
153   {
154     CmdBuf_AddText(va("music looprandom \"%q\"\n", itext.TextMusic));
155   }
156   else
157   {
158     CmdBuf_AddText("music looprandom d_intro\n");
159   }
160   interstate = IMS_Text;
163 //===========================================================================
165 //  IM_DrawHubText
167 //===========================================================================
169 void IM_DrawHubText()
171   if (TextPic)
172   {
173     DrawFullScreenPic(TextPic);
174   }
175   else if (TextFlat)
176   {
177     FillRectWithFlatRepeat(0, 0, 640, 480, TextFlat);
178   }
179   else
180   {
181     R_FillRect(0, 0, 640, 480, 0);
182   }
183   int count = int((intertime - 0.3) / TextSpeed);
184   count = clamp(count, 0, strlenutf8(HubText));
185   SetFont('smallfont');
186   SetTextAlign(hleft, vtop);
187   DrawText(170, 145, substrutf8(HubText, 0, count));
190 //==========================================================================
192 //  OnVisibilityChanged
194 //==========================================================================
196 override void OnVisibilityChanged(bool bNewVisibility)
198   bTickEnabled = bNewVisibility;
199   if (bNewVisibility) SetFullScaledSize(Width, Height);
202 defaultproperties
204   bTickEnabled = true;
205   Focusable = true;
206   Width = 320;
207   Height = 200;