comparison GUI/UI/UISaveLoad.cpp @ 2501:0ff6a9e9bf7f

GUI folger
author Ritor1
date Fri, 19 Sep 2014 04:21:12 +0600
parents
children a77c34acdbc9
comparison
equal deleted inserted replaced
2500:952025b157aa 2501:0ff6a9e9bf7f
1 #define _CRTDBG_MAP_ALLOC
2 #include <stdlib.h>
3 #include <crtdbg.h>
4
5 #define _CRT_SECURE_NO_WARNINGS
6 #include <io.h>
7
8 #include "..\../Engine/MM7.h"
9 #include "..\../Engine/ErrorHandling.h"
10
11 #include "..\../Keyboard.h"
12
13 #include "..\../Engine/MapInfo.h"
14 #include "..\../GUIWindow.h"
15 #include "..\../GUIFont.h"
16 #include "..\../Engine/Graphics/Render.h"
17 #include "..\../Engine/LOD.h"
18 #include "..\../Engine/SaveLoad.h"
19 #include "..\../Engine/texts.h"
20
21 #include "..\../Engine/mm7_data.h"
22
23 #include "..\../Engine/Game.h"
24
25
26 //----- (004601B7) --------------------------------------------------------
27 static void UI_DrawSaveLoad(bool save)
28 {
29 // const char *pSlotName; // edi@36
30 GUIWindow save_load_window; // [sp+Ch] [bp-78h]@8
31 unsigned int pSaveFiles; // [sp+70h] [bp-14h]@10
32 unsigned __int64 full_hours;
33 unsigned __int64 full_days;
34 int full_weeks;
35 int full_month;
36 int current_year;
37 int current_month;
38 int current_day;
39 int current_hour;
40 int current_minutes;
41
42 pRenderer->BeginScene();
43 if ( GetCurrentMenuID() != MENU_SAVELOAD && GetCurrentMenuID() != MENU_LoadingProcInMainMenu )
44 {
45 pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave));
46 if (save)
47 {
48 pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_saveU));
49 pRenderer->DrawTextureIndexed( 18, 139, pIcons_LOD->GetTexture(uTextureID_save_up));
50 }
51 else
52 {
53 pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_loadU));
54 pRenderer->DrawTextureIndexed( 18, 139, pIcons_LOD->GetTexture(uTextureID_load_up));
55 }
56 pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u));
57 }
58 if ( pSavegameUsedSlots[uLoadGameUI_SelectedSlot] )
59 {
60 memset(&save_load_window, 0, 0x54);
61 save_load_window.uFrameX = pGUIWindow_CurrentMenu->uFrameX + 240;
62 save_load_window.uFrameWidth = 220;
63 save_load_window.uFrameY = (pGUIWindow_CurrentMenu->uFrameY - pFontSmallnum->uFontHeight) + 157;
64 save_load_window.uFrameZ = save_load_window.uFrameX + 219;
65 save_load_window.uFrameHeight = pFontSmallnum->uFontHeight;
66 save_load_window.uFrameW = pFontSmallnum->uFontHeight + save_load_window.uFrameY - 1;
67 if ( pSavegameThumbnails[uLoadGameUI_SelectedSlot].pPixels )
68 pRenderer->DrawTextureRGB(pGUIWindow_CurrentMenu->uFrameX + 276, pGUIWindow_CurrentMenu->uFrameY + 171, &pSavegameThumbnails[uLoadGameUI_SelectedSlot]);
69 //Draw map name
70 save_load_window.DrawTitleText(pFontSmallnum, 0, 0, 0, pMapStats->pInfos[pMapStats->GetMapInfo(pSavegameHeader[uLoadGameUI_SelectedSlot].pLocationName)].pName, 3);
71 //Draw date
72 full_hours = ((signed __int64)(pSavegameHeader[uLoadGameUI_SelectedSlot].uWordTime * 0.234375) / 60) / 60i64;
73 full_days = (unsigned int)full_hours / 24;
74 full_weeks = (unsigned int)(full_days / 7);
75 full_month = (unsigned int)full_weeks / 4;
76 current_year = (full_month / 12) + game_starting_year;
77 current_month = full_month % 12;
78 current_day = full_days % 28;
79 current_hour = full_hours % 24;
80 current_minutes = (((signed __int64)(pSavegameHeader[uLoadGameUI_SelectedSlot].uWordTime * 0.234375) / 60) % 60i64);
81
82 save_load_window.uFrameY = pGUIWindow_CurrentMenu->uFrameY + 261;
83 int am;
84 if ( (signed int)current_hour >= 12 )
85 {
86 current_hour -= 12;
87 if ( !current_hour )
88 current_hour = 12;
89 am = 1;
90 }
91 else
92 am = 0;
93 const char* day = aDayNames[full_days % 7];
94 const char* ampm = aAMPMNames[am];
95 const char* month = aMonthNames[current_month];
96
97 sprintfex(pTmpBuf.data(), "%s %d:%02d %s\n%d %s %d", day, current_hour, current_minutes, aAMPMNames[am], current_day + 1, month, current_year);
98 save_load_window.DrawTitleText(pFontSmallnum, 0, 0, 0, pTmpBuf.data(), 3);
99 }
100 if ( pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_CONFIRMED)
101 {
102 pGUIWindow_CurrentMenu->receives_keyboard_input_2 = WINDOW_INPUT_NONE;
103 strcpy((char *)&pSavegameHeader + 100 * uLoadGameUI_SelectedSlot, pKeyActionMap->pPressedKeysBuffer);
104 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_SaveGame, 0, 0);
105 }
106 else
107 {
108 if ( pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_CANCELLED)
109 pGUIWindow_CurrentMenu->receives_keyboard_input_2 = WINDOW_INPUT_NONE;
110 }
111 if (GetCurrentMenuID() == MENU_LoadingProcInMainMenu)
112 {
113 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[135]) + 25,
114 220, 0, pGlobalTXT_LocalizationStrings[135], 0, 0, 0);//Загрузка
115 pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, pFontSmallnum->AlignText_Center(186,
116 pSavegameHeader[uLoadGameUI_SelectedSlot].pName) + 25, 0x106, 0, pSavegameHeader[uLoadGameUI_SelectedSlot].pName, 185, 0);
117 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[165]) + 25,
118 304, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0);//"Пожалуйста, пожождите"
119 }
120 else
121 {
122 if ( save )
123 pSaveFiles = 40;
124 else
125 pSaveFiles = uNumSavegameFiles;
126
127 int slot_Y = 199;
128 for ( uint i = pSaveListPosition; i < pSaveFiles; ++i )
129 {
130 if ( slot_Y >= 346 )
131 break;
132 if ( pGUIWindow_CurrentMenu->receives_keyboard_input_2 != WINDOW_INPUT_IN_PROGRESS || i != uLoadGameUI_SelectedSlot )
133 pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, 27, slot_Y, i == uLoadGameUI_SelectedSlot ? Color16(0xFF, 0xFF, 0x64) : 0, pSavegameHeader[i].pName, 185, 0);
134 else
135 pGUIWindow_CurrentMenu->DrawFlashingInputCursor(pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, 27, slot_Y, i == uLoadGameUI_SelectedSlot ? Color16(0xFF, 0xFF, 0x64) : 0, (const char *)pKeyActionMap->pPressedKeysBuffer, 175, 1) + 27,
136 slot_Y, pFontSmallnum);
137 slot_Y += 21;
138 }
139 }
140 pRenderer->EndScene();
141 }
142 // 6A0C9C: using guessed type int dword_6A0C9C;
143
144 //----- (004606F7) --------------------------------------------------------
145 void LoadUI_Draw()
146 {
147 UI_DrawSaveLoad(false);
148 }
149
150 //----- (004606FE) --------------------------------------------------------
151 void SaveUI_Draw()
152 {
153 UI_DrawSaveLoad(true);
154 }
155
156 //----- (0045E361) --------------------------------------------------------
157 void LoadUI_Load(unsigned int uDialogueType)
158 {
159 LODWriteableFile pLODFile; // [sp+1Ch] [bp-248h]@1
160
161 dword_6BE138 = -1;
162 pIcons_LOD->_inlined_sub2();
163
164 memset(pSavegameUsedSlots.data(), 0, sizeof(pSavegameUsedSlots));
165 memset(pSavegameThumbnails.data(), 0, 45 * sizeof(RGBTexture));
166 uTextureID_loadsave = pIcons_LOD->LoadTexture("loadsave", TEXTURE_16BIT_PALETTE);
167 uTextureID_load_up = pIcons_LOD->LoadTexture("load_up", TEXTURE_16BIT_PALETTE);
168 uTextureID_save_up = pIcons_LOD->LoadTexture("save_up", TEXTURE_16BIT_PALETTE);
169 uTextureID_LS_loadU = pIcons_LOD->LoadTexture("LS_loadU", TEXTURE_16BIT_PALETTE);
170 uTextureID_LS_saveU = pIcons_LOD->LoadTexture("LS_saveU", TEXTURE_16BIT_PALETTE);
171 uTextureID_x_u = pIcons_LOD->LoadTexture("x_u", TEXTURE_16BIT_PALETTE);
172 if ( uDialogueType )
173 {
174 pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave));
175 if ( pCurrentScreen == SCREEN_SAVEGAME )
176 {
177 pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_saveU));
178 pRenderer->DrawTextureIndexed( 18, 141, pIcons_LOD->GetTexture(uTextureID_save_up));
179 }
180 else
181 {
182 pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_loadU));
183 pRenderer->DrawTextureIndexed( 18, 141, pIcons_LOD->GetTexture(uTextureID_load_up));
184 }
185 pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u));
186 }
187 else
188 pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
189 pGUIWindow_CurrentMenu = GUIWindow::Create(saveload_dlg_xs[uDialogueType], saveload_dlg_ys[uDialogueType], saveload_dlg_zs[uDialogueType],
190 saveload_dlg_ws[uDialogueType], WINDOW_MainMenu_Load, 0, 0);
191 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, 25, 199, 0, pGlobalTXT_LocalizationStrings[505], 0, 0, 0);// "Reading..."
192 pRenderer->Present();
193 pSavegameList->Initialize(0);
194 if ( pSaveListPosition > (signed int)uNumSavegameFiles )
195 {
196 pSaveListPosition = 0;
197 uLoadGameUI_SelectedSlot = 0;
198 }
199 pLODFile.AllocSubIndicesAndIO(300, 0);
200 Assert(sizeof(SavegameHeader) == 100);
201 for (uint i = 0; i < uNumSavegameFiles; ++i)
202 {
203 sprintf(pTmpBuf.data(), "saves\\%s", pSavegameList->pFileList[i].pSaveFileName);
204 if (_access(pTmpBuf.data(), 6))
205 {
206 pSavegameUsedSlots[i] = 0;
207 strcpy(pSavegameHeader[i].pName, pGlobalTXT_LocalizationStrings[72]); // "Empty"
208 continue;
209 }
210 pLODFile.LoadFile(pTmpBuf.data(), 1);
211 if ( pLODFile.FindContainer("header.bin", true) )
212 fread(&pSavegameHeader[i], 100, 1, pLODFile.FindContainer("header.bin", true));
213 if ( !_stricmp(pSavegameList->pFileList[i].pSaveFileName, pGlobalTXT_LocalizationStrings[613]) )// "AutoSave.MM7"
214 strcpy(pSavegameHeader[i].pName, pGlobalTXT_LocalizationStrings[16]);// "Autosave"
215 if ( !pLODFile.FindContainer("image.pcx", true) )
216 {
217 pSavegameUsedSlots[i] = 0;
218 strcpy(pSavegameList->pFileList[i].pSaveFileName, "");
219 }
220 else
221 {
222 pSavegameThumbnails[i].LoadFromFILE(pLODFile.FindContainer("image.pcx", true), 0, true);
223 pLODFile.CloseWriteFile();
224 pSavegameUsedSlots[i] = 1;
225 }
226 }
227
228 pLODFile.FreeSubIndexAndIO();
229 if ( pCurrentScreen == SCREEN_SAVEGAME )
230 {
231 uTextureID_x_d = pIcons_LOD->LoadTexture("x_d", TEXTURE_16BIT_PALETTE);
232 uTextureID_LS_ = pIcons_LOD->LoadTexture("LS_saveD",TEXTURE_16BIT_PALETTE);
233 }
234 else
235 {
236 uTextureID_x_d = pIcons_LOD->LoadTexture("x_d", TEXTURE_16BIT_PALETTE);
237 uTextureID_LS_ = pIcons_LOD->LoadTexture("LS_loadD",TEXTURE_16BIT_PALETTE);
238 }
239 uTextureID_AR_UP_DN = pIcons_LOD->LoadTexture("AR_UP_DN", TEXTURE_16BIT_PALETTE);
240 uTextureID_AR_DN_DN = pIcons_LOD->LoadTexture("AR_DN_DN", TEXTURE_16BIT_PALETTE);
241 pGUIWindow_CurrentMenu->CreateButton(21, 198, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 0, 0, "", 0);
242 pGUIWindow_CurrentMenu->CreateButton(21, 219, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 1, 0, "", 0);
243 pGUIWindow_CurrentMenu->CreateButton(21, 240, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 2, 0, "", 0);
244 pGUIWindow_CurrentMenu->CreateButton(21, 261, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 3, 0, "", 0);
245 pGUIWindow_CurrentMenu->CreateButton(21, 282, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 4, 0, "", 0);
246 pGUIWindow_CurrentMenu->CreateButton(21, 303, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 5, 0, "", 0);
247 pGUIWindow_CurrentMenu->CreateButton(21, 324, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 6, 0, "", 0);
248 pBtnLoadSlot = pGUIWindow_CurrentMenu->CreateButton(241, 302, 105, 40, 1, 0, UIMSG_SaveLoadBtn, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_LS_), 0);
249 pBtnCancel = pGUIWindow_CurrentMenu->CreateButton(350, 302, 105, 40, 1, 0, UIMSG_Cancel, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_x_d), 0);
250 pBtnArrowUp = pGUIWindow_CurrentMenu->CreateButton(215, 199, 17, 17, 1, 0, UIMSG_ArrowUp, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_UP_DN), 0);
251 pBtnDownArrow = pGUIWindow_CurrentMenu->CreateButton(215, 323, 17, 17, 1, 0, UIMSG_DownArrow, uNumSavegameFiles, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_DN_DN), 0);
252 }
253
254 //----- (0045E93E) --------------------------------------------------------
255 void SaveUI_Load()
256 {
257 char *v3; // eax@7
258 LODWriteableFile pLODFile; // [sp+1Ch] [bp-248h]@1
259
260 ++pIcons_LOD->uTexturePacksCount;
261 if ( !pIcons_LOD->uNumPrevLoadedFiles )
262 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
263 memset(&pSavegameUsedSlots, 0, sizeof(pSavegameUsedSlots));
264 memset(&pSavegameThumbnails, 0, sizeof(pSavegameThumbnails));
265 uTextureID_loadsave = pIcons_LOD->LoadTexture("loadsave", TEXTURE_16BIT_PALETTE);
266 uTextureID_load_up = pIcons_LOD->LoadTexture("load_up", TEXTURE_16BIT_PALETTE);
267 uTextureID_save_up = pIcons_LOD->LoadTexture("save_up", TEXTURE_16BIT_PALETTE);
268 uTextureID_LS_loadU = pIcons_LOD->LoadTexture("LS_loadU", TEXTURE_16BIT_PALETTE);
269 uTextureID_LS_saveU = pIcons_LOD->LoadTexture("LS_saveU", TEXTURE_16BIT_PALETTE);
270 uTextureID_x_u = pIcons_LOD->LoadTexture("x_u", TEXTURE_16BIT_PALETTE);
271 pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave));
272 if ( pCurrentScreen == SCREEN_SAVEGAME )
273 {
274 pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_saveU));
275 pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u));
276 pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up));
277 }
278 else
279 {
280 pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_loadU));
281 pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u));
282 pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_load_up));
283 }
284 pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, 25, 199, 0, pGlobalTXT_LocalizationStrings[505], 0, 0, 0);//Read...(Чтение...)
285 pRenderer->Present();
286 pSavegameList->Initialize(1);
287 pLODFile.AllocSubIndicesAndIO(300, 0);
288 for (uint i = 0; i < 40; ++i)
289 {
290 v3 = pSavegameList->pFileList[i].pSaveFileName;
291 if ( !*pSavegameList->pFileList[i].pSaveFileName )
292 v3 = "1.mm7";
293 sprintf(pTmpBuf.data(), "saves\\%s", v3);
294 if ( _access(pTmpBuf.data(), 0) || _access(pTmpBuf.data(), 6) )
295 {
296 pSavegameUsedSlots[i] = 0;
297 strcpy(pSavegameHeader[i].pName, pGlobalTXT_LocalizationStrings[LOCSTR_EMPTY]);
298 }
299 else
300 {
301 pLODFile.LoadFile(pTmpBuf.data(), 1);
302 fread(&pSavegameHeader[i], 100, 1, pLODFile.FindContainer("header.bin", 1));
303 if ( pLODFile.FindContainer("image.pcx", 1) )
304 {
305 pSavegameThumbnails[i].LoadFromFILE(pLODFile.FindContainer("image.pcx", 1), 0, 1);
306 pLODFile.CloseWriteFile();
307 pSavegameUsedSlots[i] = 1;
308 }
309 else
310 pSavegameUsedSlots[i] = 0;
311 }
312 }
313 pLODFile.FreeSubIndexAndIO();
314 uTextureID_x_d = pIcons_LOD->LoadTexture("x_d", TEXTURE_16BIT_PALETTE);
315 uTextureID_LS_ = pIcons_LOD->LoadTexture("LS_saveD", TEXTURE_16BIT_PALETTE);
316 uTextureID_AR_UP_DN = pIcons_LOD->LoadTexture("AR_UP_DN", TEXTURE_16BIT_PALETTE);
317 uTextureID_AR_DN_DN = pIcons_LOD->LoadTexture("AR_DN_DN", TEXTURE_16BIT_PALETTE);
318 pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_SaveLoadButtons, 0, 0);
319 pGUIWindow_CurrentMenu->CreateButton(21, 198, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 0, 0, "", 0);
320 pGUIWindow_CurrentMenu->CreateButton(21, 218, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 1, 0, "", 0);
321 pGUIWindow_CurrentMenu->CreateButton(21, 238, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 2, 0, "", 0);
322 pGUIWindow_CurrentMenu->CreateButton(21, 258, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 3, 0, "", 0);
323 pGUIWindow_CurrentMenu->CreateButton(21, 278, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 4, 0, "", 0);
324 pGUIWindow_CurrentMenu->CreateButton(21, 298, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 5, 0, "", 0);
325 pGUIWindow_CurrentMenu->CreateButton(21, 318, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 6, 0, "", 0);
326 pBtnLoadSlot = pGUIWindow_CurrentMenu->CreateButton(241, 302, 105, 40, 1, 0, UIMSG_SaveLoadBtn, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_LS_), 0);
327 pBtnCancel = pGUIWindow_CurrentMenu->CreateButton(350, 302, 105, 40, 1, 0, UIMSG_Cancel, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_x_d), 0);
328 pBtnArrowUp = pGUIWindow_CurrentMenu->CreateButton(215, 199, 17, 17, 1, 0, UIMSG_ArrowUp, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_UP_DN), 0);
329 pBtnDownArrow = pGUIWindow_CurrentMenu->CreateButton(215, 323, 17, 17, 1, 0, UIMSG_DownArrow, 34, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_DN_DN), 0);
330 }