Mercurial > mm7
annotate Engine/MMT.cpp @ 2575:a76d408c5132 tip
DrawTranslucent -> DrawTextureGrayShade
Removed old texture drawing stuff
author | a.parshin |
---|---|
date | Wed, 09 Mar 2016 01:39:52 +0200 |
parents | dd36326a9994 |
children |
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 | |
2574 | 59 Texture_MM7 *LoadPNG(const char *name) |
2499 | 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; | |
2574 | 70 Texture_MM7 *tex; |
2499 | 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 | |
2574 | 117 tex = new Texture_MM7; |
2499 | 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); | |
2572
d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents:
2564
diff
changeset
|
124 tex->paletted_pixels = (unsigned __int8 *) malloc(sizeof(unsigned __int8) * width * height); |
2499 | 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]); | |
2572
d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents:
2564
diff
changeset
|
140 tex->paletted_pixels[i] = ptr[3]; |
2499 | 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 { | |
2572
d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents:
2564
diff
changeset
|
153 /*GUIButton *pButton; // eax@27 |
2499 | 154 unsigned int pControlParam; // ecx@35 |
155 unsigned int pX; | |
156 unsigned int pY; // [sp-18h] [bp-54h]@39 | |
2574 | 157 Texture_MM7 *pTexture; // [sp-14h] [bp-50h]@39 |
2499 | 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 | |
2574 | 180 //Texture_MM7* MMT_MM6 = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE); |
2499 | 181 |
182 sprintf(pContainerName, "data\\New_Icons/%s", "mm6_button_oval.png"); | |
2574 | 183 Texture_MM7* MMT_MM6 = LoadPNG(pContainerName); |
2499 | 184 |
2574 | 185 Texture_MM7* MMT_MM7 = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE); |
186 Texture_MM7* MMT_MM8 = pIcons_LOD->LoadTexturePtr("title_cred", TEXTURE_16BIT_PALETTE); | |
187 Texture_MM7* MMT_Continue = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE); | |
188 Texture_MM7* MMT_Exit = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE); | |
2499 | 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 } | |
2573
0c67be4ec900
DrawTextureIndexed renamed to DrawTextureTransparentColorKey
a.parshin
parents:
2572
diff
changeset
|
267 pRenderer->DrawTextureTransparentColorKey(pX, pY, pTexture); |
2499 | 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 | |
282 if ( pGUIWindow2 ) | |
283 { | |
284 pGUIWindow2->Release(); | |
285 pGUIWindow2 = 0; | |
286 } | |
287 pWindow_MMT_MainMenu->Release(); | |
2572
d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
a.parshin
parents:
2564
diff
changeset
|
288 pIcons_LOD->RemoveTexturesPackFromTextureList();*/ |
2499 | 289 } |
290 | |
291 void MMT_MenuMessageProc() | |
292 { | |
293 int pParam; | |
294 int pParam2; | |
295 UIMessageType pUIMessageType; | |
296 | |
297 if ( pMessageQueue_50CBD0->uNumMessages ) | |
298 { | |
299 do | |
300 { | |
301 pMessageQueue_50CBD0->PopMessage(&pUIMessageType, &pParam, &pParam2); | |
302 | |
303 switch (pUIMessageType) | |
304 { | |
305 case UIMSG_MMT_MainMenu_MM6: | |
306 //video | |
307 //SetCurrentMenuID(MENU_MAIN_MM6); | |
2506 | 308 alSourcef (mSourceID, AL_GAIN, 0.5f); |
309 pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);//temporarily | |
2499 | 310 break; |
311 case UIMSG_MMT_MainMenu_MM7: //new button for ÌÌ7 | |
312 //GUIWindow::Create(495, 172, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnNew, 0); | |
313 alSourceStop(mSourceID); | |
314 pMediaPlayer->ShowMM7IntroVideo_and_LoadingScreen(); | |
315 SetCurrentMenuID(MENU_MAIN); | |
316 break; | |
317 case UIMSG_MMT_MainMenu_MM8: | |
318 //video | |
319 //SetCurrentMenuID(MENU_MAIN_MM8); | |
2506 | 320 alSourcei (mSourceID, AL_LOOPING, 1); |
321 pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);//temporarily | |
2499 | 322 break; |
323 case UIMSG_MMT_MainMenu_Continue: | |
324 //video | |
325 //SetCurrentMenuID(MENU_MAIN_Continue); | |
2506 | 326 alSourcef (mSourceID, AL_GAIN, 1.0f); |
327 pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);//temporarily | |
2499 | 328 break; |
329 case UIMSG_ExitToWindows: | |
2544
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
330 extern GUIButton *pMainMenu_BtnExit; |
c674d547cc7c
GUIWindow switch logic refactored into behaviour classes
a.parshin
parents:
2541
diff
changeset
|
331 new OnButtonClick2(495, 337, 0, 0, (int)pMainMenu_BtnExit, 0); |
2499 | 332 SetCurrentMenuID(MENU_EXIT_GAME); |
333 | |
334 default: | |
335 break; | |
336 } | |
337 } | |
338 while ( pMessageQueue_50CBD0->uNumMessages ); | |
339 } | |
340 } | |
341 void DrawMMTCopyrightWindow() | |
342 { | |
343 GUIWindow Dst; // [sp+8h] [bp-54h]@1 | |
344 | |
345 memset(&Dst, 0, 0x54u); | |
346 Dst.uFrameWidth = 624; | |
347 Dst.uFrameHeight = 256; | |
348 Dst.uFrameX = 8; | |
349 Dst.uFrameY = 30; | |
350 Dst.uFrameHeight = pFontSmallnum->CalcTextHeight("Text Verification: Here we can write an explanation of the project", &Dst, 24, 0) | |
351 + 2 * LOBYTE(pFontSmallnum->uFontHeight) | |
352 + 24; | |
353 Dst.uFrameY = 470 - Dst.uFrameHeight; | |
354 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1; | |
355 Dst.uFrameW = 469; | |
356 //Dst.Hint = "abcagfdsgsg ljsrengvlkjesnfkjwnef"; | |
357 Dst.DrawMessageBox(0); | |
358 | |
359 Dst.uFrameWidth -= 24; | |
360 Dst.uFrameX += 12; | |
361 Dst.uFrameY += 12; | |
362 Dst.uFrameHeight -= 12; | |
363 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1; | |
364 Dst.uFrameW = Dst.uFrameY + Dst.uFrameHeight - 1; | |
365 Dst.DrawTitleText(pFontSmallnum, 0, 0xCu, ui_mainmenu_copyright_color, "Text Verification: Here we can write an explanation of the project", 3); | |
366 } |