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