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