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