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