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