-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadScreen.h
207 lines (149 loc) · 5.54 KB
/
LoadScreen.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#ifndef StormForge_LoadScreen
#define StormForge_LoadScreen
#include "D3DXFont.h"
#include "Direct3D.h"
#include <stdio.h>
#include "Texturemgr.h"
#include "timer.h"
#ifndef HALF_PI
#define HALF_PI 1.5708f
#endif
class LoadScreen
{
public:
static int iTexture;
static int iFont;
static int iTitle;
static int iBar;
// Store how many bytes we're loading, and how many are loaded already
static int iTotalLoadSize;
static int iCurrentLoaded;
// Load the font for use.. Call this any time we reset the font manager
static void LoadFont(void) { iFont = DXFonts::Create("Arial", 20, true); }
static void SetSize(int iSize) { iTotalLoadSize = iSize; }
// Add the size of the file
static void AddSize(char *strFile)
{
// See how big the file was
FILE *pFile = fopen(strFile, "rb");
if (!pFile) return;
fseek(pFile, 0, SEEK_END);
long iSize = ftell(pFile);
fclose(pFile);
// Add that size to the currently loaded size
if (iTotalLoadSize == 1) iTotalLoadSize = 0; /* Compensate for the 1 to evade DBZ */
iTotalLoadSize += iSize;
}
// load textures
static void LoadTextures(void)
{
iBar = TextureMgr::LoadTexture("textures\\hudbar_charge.png");
iTexture = TextureMgr::LoadTexture("textures\\sl_loadscreen.jpg");
iTitle = TextureMgr::LoadTexture("textures\\GoNTitle_green.png");
}
// set it back to 0 size
static void Reset(void) { iCurrentLoaded = 0; iTotalLoadSize = 1; }
// Call this after every file successfully loads
static void UpdateLoaded(char *strFile)
{
// See how big the file was
FILE *pFile = fopen(strFile, "rb");
if (!pFile) return;
fseek(pFile, 0, SEEK_END);
long iSize = ftell(pFile);
fclose(pFile);
// Add that size to the currently loaded size
iCurrentLoaded += iSize;
}
// Draw the progress
static void Draw(char *strFile, float fAlpha = 255.0f)
{
// Check if we need to initialize
if (iTexture == INVALID) LoadTextures();
if (iFont == INVALID) LoadFont();
Direct3D::Clear();
Direct3D::Begin();
// Draw the screen across the whole screen no matter what
float fScaleX = Direct3D::GetScreenWidth() / TextureMgr::GetBmpWidth(iTexture);
float fScaleY = Direct3D::GetScreenHeight() / TextureMgr::GetBmpHeight(iTexture);
float fScaleTX = float(Direct3D::GetScreenWidth()) / 1024.0f;
float fScaleTY = float(Direct3D::GetScreenHeight()) / 800.0f;
TextureMgr::Draw(iTexture, 0.0f, 0.0f, NULL, fScaleX, fScaleY, 0, int(fAlpha));
TextureMgr::Draw(iTitle, 100.0f, 25.0f, NULL, fScaleTX, fScaleTY, 0, int(fAlpha));
// Write out the currently loading file.
DXFonts::Begin(iFont);
{
char strBuffer[500];
if (strFile)
sprintf(strBuffer, "Loading file: %s", strFile);
else
sprintf(strBuffer, "Initializing Guardians of Neverwood...");
DXFonts::WriteShadow(strBuffer, 250, Direct3D::GetScreenHeight() - 75, 3, 1,1,1, (fAlpha/255.0f));
}
DXFonts::End();
// Do progress bar.
float fPct = float(iCurrentLoaded) / float(iTotalLoadSize);
float fY = Direct3D::GetScreenHeight() * 0.8f;
float fX = Direct3D::GetScreenWidth() * 0.8f;
#define LoadBarScale 2.5f
float fYPos = fY - (TextureMgr::GetBmpHeight(iBar) * LoadBarScale * fPct);
TextureMgr::Draw(iBar, fX, fY - (LoadBarScale * TextureMgr::GetBmpHeight(iBar)), NULL, 3.0f, LoadBarScale, 0, int(fAlpha * 0.25f));
TextureMgr::Draw(iBar, fX, fYPos, NULL, 3.0f, LoadBarScale * fPct, 0, int(fAlpha));
Direct3D::End();
Direct3D::Present();
// Update size
if (strFile)
UpdateLoaded(strFile);
}
// Draw the progress
static void DrawText(char *strText, int iAddSize = -1, float fAlpha = 255.0f)
{
if (iAddSize == -1) iAddSize = int(0.1f * iTotalLoadSize);
// Check if we need to initialize
if (iTexture == INVALID) LoadTextures();
if (iFont == INVALID) LoadFont();
Direct3D::Clear();
Direct3D::Begin();
// Draw the screen across the whole screen no matter what
float fScaleX = Direct3D::GetScreenWidth() / TextureMgr::GetBmpWidth(iTexture);
float fScaleY = Direct3D::GetScreenHeight() / TextureMgr::GetBmpHeight(iTexture);
float fScaleTX = float(Direct3D::GetScreenWidth()) / 1024.0f;
float fScaleTY = float(Direct3D::GetScreenHeight()) / 800.0f;
TextureMgr::Draw(iTexture, 0.0f, 0.0f, NULL, fScaleX, fScaleY, 0, int(fAlpha));
TextureMgr::Draw(iTitle, 100.0f, 25.0f, NULL, fScaleTX, fScaleTY, 0, int(fAlpha));
// Write out the currently loading file.
DXFonts::Begin(iFont);
{
DXFonts::WriteShadow(strText, 250, Direct3D::GetScreenHeight() - 75, 3, 1,1,1, (fAlpha/255.0f));
}
DXFonts::End();
// Do progress bar.
float fPct = float(iCurrentLoaded) / float(iTotalLoadSize);
float fY = Direct3D::GetScreenHeight() * 0.8f;
float fX = Direct3D::GetScreenWidth() * 0.8f;
#define LoadBarScale 2.5f
float fYPos = fY - (TextureMgr::GetBmpHeight(iBar) * LoadBarScale * fPct);
TextureMgr::Draw(iBar, fX, fY - (LoadBarScale * TextureMgr::GetBmpHeight(iBar)), NULL, 3.0f, LoadBarScale, 0, int(fAlpha * 0.25f));
TextureMgr::Draw(iBar, fX, fYPos, NULL, 3.0f, LoadBarScale * fPct, 0, int(fAlpha));
Direct3D::End();
Direct3D::Present();
iCurrentLoaded += iAddSize;
}
static void FadeOut(void)
{
float fFadeStart = Timer::AppTime();
float fCurrentTime = fFadeStart;
// Fill bar
LoadScreen::iCurrentLoaded = LoadScreen::iTotalLoadSize;
while (fCurrentTime <= fFadeStart + 1.0f)
{
Draw(NULL, (255.0f * (fFadeStart + 1.0f - fCurrentTime)));
fCurrentTime = Timer::AppTime();
}
// Destroy textures at the end.
// Dont destroy bar or title since we use them elsewhere
TextureMgr::UnloadTexture(iTexture);
iTexture = INVALID;
}
};
#endif