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