-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngineGUI.cpp
280 lines (221 loc) · 9.58 KB
/
EngineGUI.cpp
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "StdH.h"
#include <Engine/Templates/Stock_CTextureData.h>
// global engine gui handling object
CEngineGUI _EngineGUI;
// We cannot use dllmain if using MFC.
// See MSDN article "Regular DLLs Dynamically Linked to MFC" if initialization is needed.
/*BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}*/
void CEngineGUI::SelectMode(CDisplayMode &dm, GfxAPIType &gat)
{
// stupid way to change resources, but it must be done
HANDLE hOldResource = AfxGetResourceHandle();
// call select mode dialog
CDlgSelectMode dlgSelectMode(dm, gat);
// activate CTGfx resources
AfxSetResourceHandle(GetGuiHandle());
INDEX iDialogResult = dlgSelectMode.DoModal();
// restore resources
AfxSetResourceHandle((HINSTANCE)hOldResource);
// if mode dialog ended successfully
if (iDialogResult == IDOK) {
SetFullScreenModeToRegistry("Display modes", dm, gat);
}
}
CTFileName CEngineGUI::CreateTexture(CTFileName fnTexFileToRecreate, CDynamicArray<CTFileName> *pafnCreatedTextures)
{
CTFileName fnResult;
// stupid way to change resources, but it must be done
HANDLE hOldResource = AfxGetResourceHandle();
// activate CTGfx resources
AfxSetResourceHandle(GetGuiHandle());
// if create texture is called with a wish to recreate texture
if (fnTexFileToRecreate != "") {
fnResult = CTString("");
CTextureData *ptdTextureToRecreate;
CTFileName fnToRecreateNoExt = fnTexFileToRecreate.NoExt();
try {
// obtain texture to recreate
ptdTextureToRecreate = _pTextureStock->Obtain_t(fnTexFileToRecreate);
ptdTextureToRecreate->Reload();
// if texture is of effect type, call create effect texture dialog
if (ptdTextureToRecreate->td_ptegEffect != NULL) {
// call create effect texture dialog with .tex name
CDlgCreateEffectTexture dlgCreateEffectTexture(fnTexFileToRecreate);
const INDEX iResult = dlgCreateEffectTexture.DoModal();
if (iResult == IDOK) {
fnResult = fnTexFileToRecreate;
}
// else this texture was created from script or from single picture
} else {
if (FileExists(fnToRecreateNoExt + ".tga")) {
// call create normal texture dialog with tga picture name
CDlgCreateNormalTexture dlgCreateNormalTexture(fnToRecreateNoExt + ".tga");
if (dlgCreateNormalTexture.m_bSourcePictureValid) {
const INDEX iResult = dlgCreateNormalTexture.DoModal();
if (iResult == IDOK) {
fnResult = dlgCreateNormalTexture.m_fnCreatedFileName;
}
}
// else if script exists
} else if (FileExists(fnToRecreateNoExt + ".scr")) {
CDynamicArray<CTFileName> afnScript;
CTFileName *pfnScript = afnScript.New();
*pfnScript = fnToRecreateNoExt + ".scr";
// call create animated texture dialog with script name
CDlgCreateAnimatedTexture dlgCreateAnimatedTexture(afnScript);
const INDEX iResult = dlgCreateAnimatedTexture.DoModal();
if (iResult == IDOK) {
fnResult = dlgCreateAnimatedTexture.m_fnCreatedFileName;
}
} else {
// not found!
WarningMessage("Cannot find source for recreating texture: \"%s\"", (CTString &)fnTexFileToRecreate);
}
}
// reload the texture
ptdTextureToRecreate->Reload();
// release obtained texture
_pTextureStock->Release(ptdTextureToRecreate);
} catch (char *err_str) {
// not loaded!
WarningMessage(err_str);
}
// create, not recreate
} else {
// call choose texture type dialog
CDlgChooseTextureType dlgChooseTextureType;
int iDlgResult = dlgChooseTextureType.DoModal();
// if user choosed a texture type
if (iDlgResult != -1 && iDlgResult >= 0 && iDlgResult <= 2) {
// if result is 2 we want to create effect texture
if (iDlgResult == 2) {
// no file requester, just call dialog
CDlgCreateEffectTexture dlgCreateEffectTexture;
if (dlgCreateEffectTexture.DoModal() == IDOK) {
fnResult = dlgCreateEffectTexture.m_fnCreatedTextureName;
if (pafnCreatedTextures != NULL) {
CTFileName *pfnCreatedTexture = pafnCreatedTextures->New();
*pfnCreatedTexture = fnResult;
}
}
// both normal and animated textures need to call open file requester
} else {
// different filters for different requests
char *pFilters = "All files (*.*)\0*.*\0\0";
// if dialog result is 0 we want to create normal texture
if (iDlgResult == 0) {
pFilters = "Pictures (*.pcx;*.tga)\0*.pcx;*.tga\0"
"PCX files (*.pcx)\0*.pcx\0"
"TGA files (*.tga)\0*.tga\0\0";
// if dialog result is 1 we want to create animated texture
} else if (iDlgResult == 1) {
pFilters = "Picture or script files (*.pcx;*.tga;*.scr)\0*.pcx;*.tga;*.scr\0"
"PCX files (*.pcx)\0*.pcx\0"
"TGA files (*.tga)\0*.tga\0"
"Script files (*.scr)\0;*.scr\0\0";
}
// call file requester for opening textures
CDynamicArray<CTFileName> afnCreateTexture;
FileRequester("Create texture", pFilters, KEY_NAME_CREATE_TEXTURE_DIR, "Textures\\", "", &afnCreateTexture);
if (afnCreateTexture.Count() == 0) {
// restore resources
AfxSetResourceHandle((HINSTANCE)hOldResource);
return CTString("");
}
// if requested texture type is 0 we want to create normal texture
if (iDlgResult == 0) {
// create textures
FOREACHINDYNAMICARRAY(afnCreateTexture, CTFileName, itPicture) {
CTFileName fnSource = itPicture.Current();
if (fnSource.FileExt() == ".pcx" || fnSource.FileExt() == ".tga") {
// call create normal texture dialog
CDlgCreateNormalTexture dlgCreateNormalTexture(fnSource);
if (dlgCreateNormalTexture.m_bSourcePictureValid) {
if (dlgCreateNormalTexture.DoModal() == IDOK) {
fnResult = dlgCreateNormalTexture.m_fnCreatedFileName;
if (pafnCreatedTextures != NULL) {
CTFileName *pfnCreatedTexture = pafnCreatedTextures->New();
*pfnCreatedTexture = fnResult;
}
}
}
}
}
// if requested texture type is 1 we want to create animated texture
} else if (iDlgResult == 1) {
// call create animated texture dialog
CDlgCreateAnimatedTexture dlgCreateAnimatedTexture(afnCreateTexture);
INDEX iDlgResult = dlgCreateAnimatedTexture.DoModal();
if (iDlgResult == IDOK) {
fnResult = dlgCreateAnimatedTexture.m_fnCreatedFileName;
if (pafnCreatedTextures != NULL) {
CTFileName *pfnCreatedTexture = pafnCreatedTextures->New();
*pfnCreatedTexture = fnResult;
}
}
}
}
}
}
// restore resources
AfxSetResourceHandle((HINSTANCE)hOldResource);
return fnResult;
}
// Functions used by application for getting and setting registry keys concerning modes
// [Cecil] NOTE: This method is called after initializing the engine in Serious Editor
void CEngineGUI::GetFullScreenModeFromRegistry(CTString strSectionName, CDisplayMode &dm, GfxAPIType &gat)
{
// prepare full screen mode as default
dm.dm_pixSizeI = 640;
dm.dm_pixSizeJ = 480;
dm.dm_ddDepth = DD_DEFAULT;
// read FS parameters from registry
CString strResult = AfxGetApp()->GetProfileString(CString(strSectionName), _T("Full screen mode"), _T("640 x 480 x 0"));
#ifdef UNICODE
swscanf(strResult, _T("%d x %d x %d"), &dm.dm_pixSizeI, &dm.dm_pixSizeJ, &dm.dm_ddDepth);
#else
sscanf(strResult, _T("%d x %d x %d"), &dm.dm_pixSizeI, &dm.dm_pixSizeJ, &dm.dm_ddDepth);
#endif
if (dm.dm_ddDepth < DD_DEFAULT || dm.dm_ddDepth > DD_32BIT) {
dm.dm_ddDepth = DD_DEFAULT;
}
strResult = AfxGetApp()->GetProfileString(CString(strSectionName), _T("Full screen API"), _T("OpenGL"));
#ifdef SE1_D3D
gat = (strResult == "Direct3D") ? GAT_D3D : GAT_OGL;
#else
gat = GAT_OGL;
#endif
// [Cecil] Custom initialization
ClassicsPatch_InitEditor();
}
void CEngineGUI::SetFullScreenModeToRegistry(CTString strSectionName, CDisplayMode dm, GfxAPIType gat)
{
CTString strDM(0, "%d x %d x %d", dm.dm_pixSizeI, dm.dm_pixSizeJ, dm.dm_ddDepth);
#ifdef SE1_D3D
CTString strGAT = (gat == GAT_D3D) ? "Direct3D" : "OpenGL";
#else
CTString strGAT = "OpenGL";
#endif
AfxGetApp()->WriteProfileString(CString(strSectionName), _T("Full screen mode"), CString(strDM));
AfxGetApp()->WriteProfileString(CString(strSectionName), _T("Full screen API"), CString(strGAT));
}