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