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
|
2425
|
185 //if (!bNoSound )
|
|
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 из папки
|
2427
|
218 if (pTexture_PCX.LoadPCXFile(pContainerName, 0) == 1)
|
|
219 Error("File not found: %s", pContainerName);
|
|
220
|
2375
|
221 SetCurrentMenuID(MENU_MMT_MAIN_MENU);//Добавлено в enum MENU_STATE в GUIWindows.h
|
2290
|
222 SetForegroundWindow(window->GetApiHandle());
|
|
223 SendMessageW(window->GetApiHandle(), WM_ACTIVATEAPP, 1, 0);
|
|
224 while (GetCurrentMenuID() == MENU_MMT_MAIN_MENU )
|
|
225 {
|
|
226 POINT cursor;
|
|
227 pMouse->GetCursorPos(&cursor);
|
|
228
|
|
229 for (MSG msg; PeekMessageW(&msg, 0, 0, 0, PM_REMOVE);)
|
|
230 {
|
|
231 if (msg.message == WM_QUIT)
|
|
232 Game_DeinitializeAndTerminate(0);
|
|
233 TranslateMessage(&msg);
|
|
234 DispatchMessageW(&msg);
|
|
235 }
|
|
236
|
|
237 if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)
|
|
238 {
|
|
239 WaitMessage();
|
|
240 continue;
|
|
241 }
|
|
242
|
|
243 pRenderer->BeginScene();
|
|
244 pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
|
|
245
|
2375
|
246 MMT_MenuMessageProc();//отдельный для ММТ меню обработчик сообщений
|
2290
|
247 GUI_UpdateWindows();
|
|
248
|
|
249 if ( !pModalWindow )// ???
|
|
250 {
|
|
251 pButton = pWindow_MMT_MainMenu->pControlsHead;
|
|
252 for ( pButton = pWindow_MMT_MainMenu->pControlsHead; pButton; pButton = pButton->pNext )
|
|
253 {
|
|
254 if ( cursor.x >= (signed int)pButton->uX && cursor.x <= (signed int)pButton->uZ
|
|
255 && cursor.y >= (signed int)pButton->uY && cursor.y <= (signed int)pButton->uW )
|
|
256 {
|
|
257 pControlParam = pButton->msg_param;
|
|
258 switch (pControlParam) // подсветка кнопок
|
|
259 {
|
|
260 case 0:
|
|
261 pTexture = MMT_MM6;
|
2308
|
262 pX = 0;
|
|
263 pY = 0;
|
2290
|
264 break;
|
|
265 case 1:
|
|
266 pTexture = MMT_MM7;
|
|
267 pX = window->GetWidth() - (window->GetWidth() / 4);
|
|
268 pY = window->GetHeight() / 4;
|
|
269 break;
|
|
270 case 2:
|
|
271 pTexture = MMT_MM8;
|
|
272 pX = window->GetWidth() - (window->GetWidth() / 4);
|
|
273 pY = window->GetHeight() - ((window->GetHeight() / 4) + 50);
|
|
274 break;
|
|
275 case 3:
|
|
276 pTexture = MMT_Continue;
|
|
277 pX = (window->GetWidth() / 4) - 100;
|
|
278 pY = window->GetHeight() - ((window->GetHeight() / 4) + 50);
|
|
279 break;
|
|
280 case 4:
|
|
281 pTexture = MMT_Exit;
|
|
282 pX = window->GetWidth() - 130;
|
|
283 pY = window->GetHeight() - 35;
|
|
284 break;
|
|
285 }
|
|
286 pRenderer->DrawTextureIndexed(pX, pY, pTexture); //подсветка кнопок
|
|
287 }
|
|
288 }
|
|
289 }
|
|
290 //}
|
|
291 pRenderer->EndScene();
|
|
292 pRenderer->Present();
|
|
293 }
|
|
294 MMT_MenuMessageProc();
|
|
295 pRenderer->BeginScene();
|
|
296 GUI_UpdateWindows();
|
|
297 pRenderer->EndScene();
|
|
298 pRenderer->Present();
|
2375
|
299
|
|
300 //освобождаем ресурсы
|
2290
|
301 pTexture_PCX.Release();
|
|
302 if ( pGUIWindow2 )
|
|
303 {
|
|
304 pGUIWindow2->Release();
|
|
305 pGUIWindow2 = 0;
|
|
306 }
|
|
307 pWindow_MMT_MainMenu->Release();
|
|
308 pIcons_LOD->RemoveTexturesPackFromTextureList();
|
|
309 }
|
|
310
|
|
311 void MMT_MenuMessageProc()
|
|
312 {
|
|
313 int pParam;
|
|
314 int pParam2;
|
|
315 UIMessageType pUIMessageType;
|
|
316
|
|
317 if ( pMessageQueue_50CBD0->uNumMessages )
|
|
318 {
|
|
319 do
|
|
320 {
|
|
321
|
|
322 pMessageQueue_50CBD0->PopMessage(&pUIMessageType, &pParam, &pParam2);
|
|
323
|
|
324 switch (pUIMessageType)
|
|
325 {
|
|
326 case UIMSG_MMT_MainMenu_MM7: //кнопка игры ММ7
|
|
327 //GUIWindow::Create(495, 172, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnNew, 0);
|
2359
|
328 alSourceStop(mSourceID);
|
2290
|
329 ShowMM7IntroVideo_and_LoadingScreen();
|
|
330 SetCurrentMenuID(MENU_MAIN);
|
|
331 break;
|
|
332
|
|
333 default:
|
|
334 break;
|
|
335 }
|
|
336 }
|
|
337 while ( pMessageQueue_50CBD0->uNumMessages );
|
|
338 }
|
|
339 }
|
|
340 void DrawMMTCopyrightWindow()
|
|
341 {
|
|
342 GUIWindow Dst; // [sp+8h] [bp-54h]@1
|
|
343
|
|
344 memset(&Dst, 0, 0x54u);
|
|
345 Dst.uFrameWidth = 624;
|
|
346 Dst.uFrameHeight = 256;
|
|
347 Dst.uFrameX = 8;
|
|
348 Dst.uFrameY = 30;
|
|
349 Dst.uFrameHeight = pFontSmallnum->CalcTextHeight("Text Verification: Here we can write an explanation of the project", &Dst, 24, 0)
|
|
350 + 2 * LOBYTE(pFontSmallnum->uFontHeight)
|
|
351 + 24;
|
|
352 Dst.uFrameY = 470 - Dst.uFrameHeight;
|
|
353 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1;
|
|
354 Dst.uFrameW = 469;
|
|
355 //Dst.Hint = "abcagfdsgsg ljsrengvlkjesnfkjwnef";
|
|
356 Dst.DrawMessageBox(0);
|
|
357
|
|
358 Dst.uFrameWidth -= 24;
|
|
359 Dst.uFrameX += 12;
|
|
360 Dst.uFrameY += 12;
|
|
361 Dst.uFrameHeight -= 12;
|
|
362 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1;
|
|
363 Dst.uFrameW = Dst.uFrameY + Dst.uFrameHeight - 1;
|
|
364 Dst.DrawTitleText(pFontSmallnum, 0, 0xCu, ui_mainmenu_copyright_color, "Text Verification: Here we can write an explanation of the project", 3);
|
|
365 } |