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