Mercurial > mm7
annotate Engine/MMT.cpp @ 2544:c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
author | a.parshin |
---|---|
date | Mon, 11 May 2015 09:51:04 +0200 |
parents | a902abdfc7f2 |
children | f9bdfe26d03d |
rev | line source |
---|---|
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 |
2544
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
20 #include "Game/MainMenu.h" |
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
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 | |
2541 | 219 current_screen_type = SCREEN_GAME; |
2499 | 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 | |
2544
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
235 pWindow_MMT_MainMenu = new GUIWindow(0, 0, window->GetWidth(), window->GetHeight(), 0, 0); |
2499 | 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 | |
2544
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
254 main_menu_background.Release(); |
2499 | 255 |
256 sprintf(pContainerName, "data\\New_Icons/%s", "MMTTITLE.pcx"); | |
2544
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
257 if (main_menu_background.LoadPCXFile(pContainerName, 0) == 1) |
2499 | 258 Error("File not found: %s", pContainerName); |
259 | |
2541 | 260 SetCurrentMenuID(MENU_MMT_MAIN_MENU); |
2499 | 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) | |
2541 | 271 Engine_DeinitializeAndTerminate(0); |
2499 | 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(); | |
2544
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
283 pRenderer->DrawTextureRGB(0, 0, &main_menu_background); |
2499 | 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 | |
2544
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
340 main_menu_background.Release(); |
2499 | 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: | |
2544
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
389 extern GUIButton *pMainMenu_BtnExit; |
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
390 new OnButtonClick2(495, 337, 0, 0, (int)pMainMenu_BtnExit, 0); |
2499 | 391 SetCurrentMenuID(MENU_EXIT_GAME); |
392 | |
393 default: | |
394 break; | |
395 } | |
396 } | |
397 while ( pMessageQueue_50CBD0->uNumMessages ); | |
398 } | |
399 } | |
400 void DrawMMTCopyrightWindow() | |
401 { | |
402 GUIWindow Dst; // [sp+8h] [bp-54h]@1 | |
403 | |
404 memset(&Dst, 0, 0x54u); | |
405 Dst.uFrameWidth = 624; | |
406 Dst.uFrameHeight = 256; | |
407 Dst.uFrameX = 8; | |
408 Dst.uFrameY = 30; | |
409 Dst.uFrameHeight = pFontSmallnum->CalcTextHeight("Text Verification: Here we can write an explanation of the project", &Dst, 24, 0) | |
410 + 2 * LOBYTE(pFontSmallnum->uFontHeight) | |
411 + 24; | |
412 Dst.uFrameY = 470 - Dst.uFrameHeight; | |
413 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1; | |
414 Dst.uFrameW = 469; | |
415 //Dst.Hint = "abcagfdsgsg ljsrengvlkjesnfkjwnef"; | |
416 Dst.DrawMessageBox(0); | |
417 | |
418 Dst.uFrameWidth -= 24; | |
419 Dst.uFrameX += 12; | |
420 Dst.uFrameY += 12; | |
421 Dst.uFrameHeight -= 12; | |
422 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1; | |
423 Dst.uFrameW = Dst.uFrameY + Dst.uFrameHeight - 1; | |
424 Dst.DrawTitleText(pFontSmallnum, 0, 0xCu, ui_mainmenu_copyright_color, "Text Verification: Here we can write an explanation of the project", 3); | |
425 } |