2499
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
2509
|
4 #include <io.h>
|
2499
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6
|
|
7 #include "MMT.h"
|
2502
|
8 #include "GUI/GUIWindow.h"
|
2499
|
9
|
|
10 #include "mm7_data.h"
|
2502
|
11 #include "Media/Audio/AudioPlayer.h"
|
|
12 #include "IO/Mouse.h"
|
2499
|
13 #include "LOD.h"
|
|
14 #include "Engine/Graphics/Render.h"
|
2502
|
15 #include "GUI/GUIFont.h"
|
2499
|
16 #include "lib/libpng/png.h"
|
|
17 #include "Engine/ErrorHandling.h"
|
2502
|
18 #include "Media/Video/Bink_Smacker.h"
|
2499
|
19 #include "Game.h"
|
|
20 #include "Log.h"
|
|
21
|
2509
|
22 bool FileExists(const char *fname)
|
|
23 {
|
|
24 return access(fname, 0) != -1;
|
|
25 }
|
2499
|
26
|
|
27 void ShowLogoVideo()
|
|
28 {
|
|
29 RGBTexture tex; // [sp+Ch] [bp-30h]@1
|
|
30 unsigned int uTrackStartMS; // [sp+34h] [bp-8h]@8
|
|
31 unsigned int uTrackEndMS; // [sp+38h] [bp-4h]@8
|
|
32
|
|
33 pMediaPlayer->bStopBeforeSchedule = false;
|
|
34
|
|
35 // pMediaPlayer->pResetflag = 0;
|
|
36 bGameoverLoop = 1;
|
|
37 if (!bNoVideo)
|
|
38 {
|
|
39 pRenderer->PresentBlackScreen();
|
|
40 pMediaPlayer->PlayFullscreenMovie(MOVIE_3DOLogo, true);
|
|
41 if ( !pMediaPlayer->bStopBeforeSchedule )
|
|
42 {
|
|
43 pMediaPlayer->PlayFullscreenMovie(MOVIE_NWCLogo, true);
|
|
44 if ( !pMediaPlayer->bStopBeforeSchedule )
|
|
45 {
|
|
46
|
|
47 if (for_refactoring)
|
|
48 {
|
|
49 MessageBoxA(nullptr, "Ritor1: MOVIE_JVC crash", "", 0);
|
|
50 __debugbreak();
|
|
51 }
|
|
52
|
|
53 //pMediaPlayer->PlayFullscreenMovie(MOVIE_JVC, true);
|
|
54 //if ( !pMediaPlayer->bStopBeforeSchedule )
|
|
55 if (!use_MMT)
|
|
56 pMediaPlayer->PlayFullscreenMovie(MOVIE_Intro, true);
|
|
57 }
|
|
58 }
|
|
59 }
|
|
60
|
|
61 if (use_MMT)
|
2518
|
62 tex.LoadPCXFile("data/New_Icons/MMTTITLE.pcx", 0);
|
2499
|
63 else
|
|
64 tex.Load("mm6title.pcx", 2);
|
|
65
|
|
66 pRenderer->BeginScene();
|
2518
|
67 pRenderer->DrawTextureNew(0, 0, &tex);
|
2519
|
68 //Sleep(5000);
|
2518
|
69
|
|
70 tex.Release();
|
|
71
|
2499
|
72 MainMenuUI_LoadFontsAndSomeStuff();
|
|
73
|
|
74 if (use_MMT)
|
2518
|
75 DrawMMTCopyrightWindow();
|
2499
|
76 else
|
|
77 DrawMM7CopyrightWindow();
|
|
78
|
|
79 pRenderer->EndScene();
|
|
80 pRenderer->Present();
|
|
81
|
|
82 #ifndef _DEBUG
|
|
83 Sleep(1500); // let the copyright window stay for a while
|
|
84 #endif
|
|
85 if (!use_MMT)
|
|
86 {
|
|
87 if (!bNoSound && pAudioPlayer->hAILRedbook )
|
|
88 {
|
2508
|
89 if ( use_music_folder )
|
|
90 {
|
2509
|
91 if (!FileExists("Music\\14.mp3"))
|
|
92 {
|
|
93 Log::Warning(L"File 14.mp3 in Music\\ folder not found");
|
2511
|
94 //Error("File 14.mp3 in Music\\ folder not found");
|
2509
|
95 return;
|
|
96 }
|
2508
|
97 PlayAudio(L"Music\\14.mp3");
|
|
98 alSourcef (mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
|
|
99 }
|
|
100 else
|
|
101 {
|
|
102 pAudioPlayer->SetMusicVolume((signed __int64)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0));
|
|
103 AIL_redbook_stop(pAudioPlayer->hAILRedbook);
|
|
104 AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 14, &uTrackStartMS, &uTrackEndMS);
|
|
105 AIL_redbook_play(pAudioPlayer->hAILRedbook, uTrackStartMS + 1, uTrackEndMS);
|
|
106 }
|
2499
|
107 }
|
|
108 }
|
|
109 bGameoverLoop = 0;
|
|
110 }
|
|
111
|
|
112 void abort_(const char * s, ...)
|
|
113 {
|
|
114 va_list args;
|
|
115 va_start(args, s);
|
|
116 vfprintf(stderr, s, args);
|
|
117 fprintf(stderr, "\n");
|
|
118 va_end(args);
|
|
119 abort();
|
|
120 }
|
|
121
|
|
122 Texture *LoadPNG(const char *name)
|
|
123 {
|
|
124 int x, y;
|
|
125 int width, height;
|
|
126 png_byte color_type;
|
|
127 png_byte bit_depth;
|
|
128 png_structp png_ptr;
|
|
129 png_infop info_ptr;
|
|
130 int number_of_passes;
|
|
131 png_bytep * row_pointers;
|
|
132 uint i = 0;
|
|
133 Texture *tex;
|
|
134
|
|
135 char header[8]; // 8 is the maximum size that can be checked
|
|
136
|
|
137 /* open file and test for it being a png */
|
|
138 FILE *fp = fopen(name, "rb");
|
|
139 if (!fp)
|
|
140 abort_("[read_png_file] File %s could not be opened for reading", name);
|
|
141 fread(header, 1, 8, fp);
|
|
142 if (png_sig_cmp((png_bytep)header, 0, 8))
|
|
143 abort_("[read_png_file] File %s is not recognized as a PNG file", name);
|
|
144 /* initialize stuff */
|
|
145 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
146
|
|
147 if (!png_ptr)
|
|
148 abort_("[read_png_file] png_create_read_struct failed");
|
|
149 info_ptr = png_create_info_struct(png_ptr);
|
|
150 if (!info_ptr)
|
|
151 abort_("[read_png_file] png_create_info_struct failed");
|
|
152
|
|
153 if (setjmp(png_jmpbuf(png_ptr)))
|
|
154 abort_("[read_png_file] Error during init_io");
|
|
155
|
|
156 png_init_io(png_ptr, fp);
|
|
157 png_set_sig_bytes(png_ptr, 8);
|
|
158
|
|
159 png_read_info(png_ptr, info_ptr);
|
|
160
|
|
161 width = png_get_image_width(png_ptr, info_ptr);
|
|
162 height = png_get_image_height(png_ptr, info_ptr);
|
|
163 color_type = png_get_color_type(png_ptr, info_ptr);
|
|
164 bit_depth = png_get_bit_depth(png_ptr, info_ptr);
|
|
165
|
|
166 number_of_passes = png_set_interlace_handling(png_ptr);
|
|
167 png_read_update_info(png_ptr, info_ptr);
|
|
168
|
|
169 /* read file */
|
|
170 if (setjmp(png_jmpbuf(png_ptr)))
|
|
171 abort_("[read_png_file] Error during read_image");
|
|
172 row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
|
|
173 for (y=0; y<height; y++)
|
|
174 row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr));
|
|
175
|
|
176 png_read_image(png_ptr, row_pointers);
|
|
177
|
|
178 fclose(fp);
|
|
179
|
|
180 tex = new Texture;
|
|
181 tex->uTextureHeight = height;
|
|
182 tex->uTextureWidth = width;
|
|
183 tex->uSizeOfMaxLevelOfDetail = png_get_rowbytes(png_ptr, info_ptr);
|
|
184 tex->uTextureSize = png_get_rowbytes(png_ptr, info_ptr);
|
|
185 tex->uDecompressedSize = png_get_rowbytes(png_ptr, info_ptr);
|
|
186 tex->pPalette16 = (unsigned __int16 *) malloc(sizeof(unsigned __int16) * width * height);
|
|
187 tex->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *) malloc(sizeof(unsigned __int8) * width * height);
|
|
188
|
|
189 for (y=0; y<height; y++)
|
|
190 {
|
|
191 png_byte* row = row_pointers[y];
|
|
192 for (x=0; x<width; x++)
|
|
193 {
|
|
194 png_byte* ptr = &(row[x*4]);
|
|
195 //Log::Warning(L"Pixel at position [ %d - %d ] has RGBA values: %d - %d - %d - %d\n",
|
|
196 // x, y, ptr[0], ptr[1], ptr[2], ptr[3]);
|
|
197 png_byte tmp = ptr[2];
|
|
198 ptr[2] = ptr[0];
|
|
199 ptr[0] = ptr[3];
|
|
200 //ptr[3] = 255 - ptr[3]; // alpha mask gradient
|
|
201 ptr[3] = 255 - tmp;
|
|
202 tex->pPalette16[i] = Color16(ptr[0], ptr[1], ptr[2]);
|
|
203 tex->pLevelOfDetail0_prolly_alpha_mask[i] = ptr[3];
|
|
204 i++;
|
|
205 }
|
|
206 }
|
|
207 //Ritor1: temporarily stopped, needed change RGBTexture structure
|
|
208 /*for (int i = 0; i < width * height; ++i)
|
|
209 tex->pPalette16[i] = 0x7FF;
|
|
210 memset(tex->pLevelOfDetail0_prolly_alpha_mask, 1, sizeof(unsigned __int8) * width * height);*/
|
|
211 return tex;
|
|
212 }
|
|
213
|
|
214 void MMT_MainMenu_Loop()
|
|
215 {
|
|
216 GUIButton *pButton; // eax@27
|
|
217 unsigned int pControlParam; // ecx@35
|
|
218 unsigned int pX;
|
|
219 unsigned int pY; // [sp-18h] [bp-54h]@39
|
|
220 Texture *pTexture; // [sp-14h] [bp-50h]@39
|
|
221 char pContainerName[64];
|
|
222 MSG msg;
|
|
223
|
|
224 pCurrentScreen = SCREEN_GAME;
|
|
225
|
|
226 pGUIWindow2 = 0;
|
|
227 pAudioPlayer->StopChannels(-1, -1);
|
|
228
|
2506
|
229 if (!bNoSound )
|
|
230 PlayAudio(L"Sounds\\New_Sounds/Stronghold_Theme.mp3");
|
2499
|
231 //if (!bNoVideo )
|
|
232 //pVideoPlayer->PlayMovie(L"Anims\\New_Video/3DOLOGO.smk");
|
|
233
|
|
234 pMouse->RemoveHoldingItem();
|
|
235
|
|
236 pIcons_LOD->_inlined_sub2();
|
|
237
|
|
238 //Create new window
|
|
239 //WINDOW_MainMenu included in GUIWindow.h
|
|
240 pWindow_MMT_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
|
|
241
|
|
242 //load buttons
|
|
243 //Texture* MMT_MM6 = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE);
|
|
244
|
|
245 sprintf(pContainerName, "data\\New_Icons/%s", "mm6_button_oval.png");
|
|
246 Texture* MMT_MM6 = LoadPNG(pContainerName);
|
|
247
|
|
248 Texture* MMT_MM7 = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE);
|
|
249 Texture* MMT_MM8 = pIcons_LOD->LoadTexturePtr("title_cred", TEXTURE_16BIT_PALETTE);
|
|
250 Texture* MMT_Continue = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE);
|
|
251 Texture* MMT_Exit = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE);
|
|
252
|
|
253 pMMT_MainMenu_BtnMM6 = pWindow_MMT_MainMenu->CreateButton(0, 0, MMT_MM6->uTextureWidth, MMT_MM6->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM6, 0, 0, "", MMT_MM6, 0);
|
|
254 pMMT_MainMenu_BtnMM7 = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - (window->GetWidth() / 4), window->GetHeight() / 4, MMT_MM7->uTextureWidth, MMT_MM7->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM7, 1, 0, "", MMT_MM7, 0);
|
|
255 pMMT_MainMenu_BtnMM8 = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - (window->GetWidth() / 4), window->GetHeight() - ((window->GetHeight() / 4) + 50), MMT_MM8->uTextureWidth, MMT_MM8->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM8, 2, 0, "", MMT_MM8, 0);
|
|
256 pMMT_MainMenu_BtnContinue = pWindow_MMT_MainMenu->CreateButton((window->GetWidth() / 4) - 100, window->GetHeight() - ((window->GetHeight() / 4) + 50), MMT_Continue->uTextureWidth, MMT_Continue->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_Continue, 3, 0, "", MMT_Continue, 0);
|
|
257 pMMT_MainMenu_BtnExit = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - 130, window->GetHeight() - 35, MMT_Exit->uTextureWidth, MMT_Exit->uTextureHeight, 1, 0, UIMSG_ExitToWindows, 4, 0, "", MMT_Exit, 0);
|
|
258
|
|
259 pTexture_PCX.Release();
|
|
260
|
|
261 sprintf(pContainerName, "data\\New_Icons/%s", "MMTTITLE.pcx");
|
|
262 if (pTexture_PCX.LoadPCXFile(pContainerName, 0) == 1)
|
|
263 Error("File not found: %s", pContainerName);
|
|
264
|
|
265 SetCurrentMenuID(MENU_MMT_MAIN_MENU);//included in enum MENU_STATE in GUIWindows.h
|
|
266 SetForegroundWindow(window->GetApiHandle());
|
|
267 SendMessageW(window->GetApiHandle(), WM_ACTIVATEAPP, 1, 0);
|
|
268 while (GetCurrentMenuID() == MENU_MMT_MAIN_MENU )
|
|
269 {
|
|
270 POINT cursor;
|
|
271 pMouse->GetCursorPos(&cursor);
|
|
272
|
|
273 while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
|
|
274 {
|
|
275 if (msg.message == WM_QUIT)
|
|
276 Game_DeinitializeAndTerminate(0);
|
|
277 TranslateMessage(&msg);
|
|
278 DispatchMessageW(&msg);
|
|
279 }
|
|
280
|
|
281 if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)
|
|
282 {
|
|
283 WaitMessage();
|
|
284 continue;
|
|
285 }
|
|
286
|
|
287 pRenderer->BeginScene();
|
|
288 pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
|
|
289
|
|
290 MMT_MenuMessageProc();//for ÌÌÒ menu
|
|
291 GUI_UpdateWindows();
|
|
292
|
|
293 if ( !pModalWindow )// ???
|
|
294 {
|
|
295 pButton = pWindow_MMT_MainMenu->pControlsHead;
|
|
296 for ( pButton = pWindow_MMT_MainMenu->pControlsHead; pButton; pButton = pButton->pNext )
|
|
297 {
|
|
298 if ( cursor.x >= (signed int)pButton->uX && cursor.x <= (signed int)pButton->uZ
|
|
299 && cursor.y >= (signed int)pButton->uY && cursor.y <= (signed int)pButton->uW )
|
|
300 {
|
|
301 pControlParam = pButton->msg_param;
|
|
302 switch (pControlParam) // backlight for buttons
|
|
303 {
|
|
304 case 0:
|
|
305 pTexture = MMT_MM6;
|
|
306 pX = 0;
|
|
307 pY = 0;
|
|
308 break;
|
|
309 case 1:
|
|
310 pTexture = MMT_MM7;
|
|
311 pX = window->GetWidth() - (window->GetWidth() / 4);
|
|
312 pY = window->GetHeight() / 4;
|
|
313 break;
|
|
314 case 2:
|
|
315 pTexture = MMT_MM8;
|
|
316 pX = window->GetWidth() - (window->GetWidth() / 4);
|
|
317 pY = window->GetHeight() - ((window->GetHeight() / 4) + 50);
|
|
318 break;
|
|
319 case 3:
|
|
320 pTexture = MMT_Continue;
|
|
321 pX = (window->GetWidth() / 4) - 100;
|
|
322 pY = window->GetHeight() - ((window->GetHeight() / 4) + 50);
|
|
323 break;
|
|
324 case 4:
|
|
325 pTexture = MMT_Exit;
|
|
326 pX = window->GetWidth() - 130;
|
|
327 pY = window->GetHeight() - 35;
|
|
328 break;
|
|
329 }
|
|
330 pRenderer->DrawTextureIndexed(pX, pY, pTexture);
|
|
331 }
|
|
332 }
|
|
333 }
|
|
334 //}
|
|
335 pRenderer->EndScene();
|
|
336 pRenderer->Present();
|
|
337 }
|
|
338 MMT_MenuMessageProc();
|
|
339 pRenderer->BeginScene();
|
|
340 GUI_UpdateWindows();
|
|
341 pRenderer->EndScene();
|
|
342 pRenderer->Present();
|
|
343
|
|
344 //remove resource
|
|
345 pTexture_PCX.Release();
|
|
346 if ( pGUIWindow2 )
|
|
347 {
|
|
348 pGUIWindow2->Release();
|
|
349 pGUIWindow2 = 0;
|
|
350 }
|
|
351 pWindow_MMT_MainMenu->Release();
|
|
352 pIcons_LOD->RemoveTexturesPackFromTextureList();
|
|
353 }
|
|
354
|
|
355 void MMT_MenuMessageProc()
|
|
356 {
|
|
357 int pParam;
|
|
358 int pParam2;
|
|
359 UIMessageType pUIMessageType;
|
|
360
|
|
361 if ( pMessageQueue_50CBD0->uNumMessages )
|
|
362 {
|
|
363 do
|
|
364 {
|
|
365 pMessageQueue_50CBD0->PopMessage(&pUIMessageType, &pParam, &pParam2);
|
|
366
|
|
367 switch (pUIMessageType)
|
|
368 {
|
|
369 case UIMSG_MMT_MainMenu_MM6:
|
|
370 //video
|
|
371 //SetCurrentMenuID(MENU_MAIN_MM6);
|
2506
|
372 alSourcef (mSourceID, AL_GAIN, 0.5f);
|
|
373 pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);//temporarily
|
2499
|
374 break;
|
|
375 case UIMSG_MMT_MainMenu_MM7: //new button for ÌÌ7
|
|
376 //GUIWindow::Create(495, 172, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnNew, 0);
|
|
377 alSourceStop(mSourceID);
|
|
378 pMediaPlayer->ShowMM7IntroVideo_and_LoadingScreen();
|
|
379 SetCurrentMenuID(MENU_MAIN);
|
|
380 break;
|
|
381 case UIMSG_MMT_MainMenu_MM8:
|
|
382 //video
|
|
383 //SetCurrentMenuID(MENU_MAIN_MM8);
|
2506
|
384 alSourcei (mSourceID, AL_LOOPING, 1);
|
|
385 pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);//temporarily
|
2499
|
386 break;
|
|
387 case UIMSG_MMT_MainMenu_Continue:
|
|
388 //video
|
|
389 //SetCurrentMenuID(MENU_MAIN_Continue);
|
2506
|
390 alSourcef (mSourceID, AL_GAIN, 1.0f);
|
|
391 pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);//temporarily
|
2499
|
392 break;
|
|
393 case UIMSG_ExitToWindows:
|
|
394 GUIWindow::Create(495, 337, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnExit, 0);
|
|
395 SetCurrentMenuID(MENU_EXIT_GAME);
|
|
396
|
|
397 default:
|
|
398 break;
|
|
399 }
|
|
400 }
|
|
401 while ( pMessageQueue_50CBD0->uNumMessages );
|
|
402 }
|
|
403 }
|
|
404 void DrawMMTCopyrightWindow()
|
|
405 {
|
|
406 GUIWindow Dst; // [sp+8h] [bp-54h]@1
|
|
407
|
|
408 memset(&Dst, 0, 0x54u);
|
|
409 Dst.uFrameWidth = 624;
|
|
410 Dst.uFrameHeight = 256;
|
|
411 Dst.uFrameX = 8;
|
|
412 Dst.uFrameY = 30;
|
|
413 Dst.uFrameHeight = pFontSmallnum->CalcTextHeight("Text Verification: Here we can write an explanation of the project", &Dst, 24, 0)
|
|
414 + 2 * LOBYTE(pFontSmallnum->uFontHeight)
|
|
415 + 24;
|
|
416 Dst.uFrameY = 470 - Dst.uFrameHeight;
|
|
417 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1;
|
|
418 Dst.uFrameW = 469;
|
|
419 //Dst.Hint = "abcagfdsgsg ljsrengvlkjesnfkjwnef";
|
|
420 Dst.DrawMessageBox(0);
|
|
421
|
|
422 Dst.uFrameWidth -= 24;
|
|
423 Dst.uFrameX += 12;
|
|
424 Dst.uFrameY += 12;
|
|
425 Dst.uFrameHeight -= 12;
|
|
426 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1;
|
|
427 Dst.uFrameW = Dst.uFrameY + Dst.uFrameHeight - 1;
|
|
428 Dst.DrawTitleText(pFontSmallnum, 0, 0xCu, ui_mainmenu_copyright_color, "Text Verification: Here we can write an explanation of the project", 3);
|
|
429 } |