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