Mercurial > mm7
view GUI/UI/UISaveLoad.cpp @ 2572:d87bfbd3bb3b
Step towards unification of Texture and RGBTexture (class Image)
author | a.parshin |
---|---|
date | Sat, 05 Mar 2016 01:51:54 +0200 |
parents | fed97f15d1e1 |
children | 0c67be4ec900 |
line wrap: on
line source
#define _CRTDBG_MAP_ALLOC #define _CRT_SECURE_NO_WARNINGS #include <stdlib.h> #include <crtdbg.h> #include <io.h> #include "Engine/Engine.h" #include "Engine/MapInfo.h" #include "Engine/Graphics/Render.h" #include "Engine/LOD.h" #include "Engine/SaveLoad.h" #include "Engine/texts.h" #include "IO/Keyboard.h" #include "GUI/GUIFont.h" #include "GUI/UI/UISaveLoad.h" #include "Game/MainMenu.h" void UI_DrawSaveLoad(bool save); GUIWindow_Save::GUIWindow_Save() : GUIWindow(0, 0, window->GetWidth(), window->GetHeight(), 0, nullptr) { // ------------------------------------------------ // 0045E93E SaveUI_Load(enum CURRENT_SCREEN screen) char *v3; // eax@7 LODWriteableFile pLODFile; // [sp+1Ch] [bp-248h]@1 ++pIcons_LOD->uTexturePacksCount; if (!pIcons_LOD->uNumPrevLoadedFiles) pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles; memset(&pSavegameUsedSlots, 0, sizeof(pSavegameUsedSlots)); memset(&pSavegameThumbnails, 0, sizeof(pSavegameThumbnails)); uTextureID_loadsave = pIcons_LOD->LoadTexture("loadsave", TEXTURE_16BIT_PALETTE); uTextureID_load_up = pIcons_LOD->LoadTexture("load_up", TEXTURE_16BIT_PALETTE); uTextureID_save_up = pIcons_LOD->LoadTexture("save_up", TEXTURE_16BIT_PALETTE); uTextureID_LS_loadU = pIcons_LOD->LoadTexture("LS_loadU", TEXTURE_16BIT_PALETTE); uTextureID_LS_saveU = pIcons_LOD->LoadTexture("LS_saveU", TEXTURE_16BIT_PALETTE); uTextureID_x_u = pIcons_LOD->LoadTexture("x_u", TEXTURE_16BIT_PALETTE); pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave)); //if (screen == SCREEN_SAVEGAME) { pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_saveU)); pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u)); pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up)); } /*else { pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_loadU)); pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u)); pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_load_up)); }*/ //pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, 25, 199, 0, pGlobalTXT_LocalizationStrings[505], 0, 0, 0);//Read...(Чтение...) pRenderer->Present(); pSavegameList->Initialize(1); pLODFile.AllocSubIndicesAndIO(300, 0); for (uint i = 0; i < 40; ++i) { v3 = pSavegameList->pFileList[i].pSaveFileName; if (!*pSavegameList->pFileList[i].pSaveFileName) v3 = "1.mm7"; sprintf(pTmpBuf.data(), "saves\\%s", v3); if (_access(pTmpBuf.data(), 0) || _access(pTmpBuf.data(), 6)) { pSavegameUsedSlots[i] = 0; strcpy(pSavegameHeader[i].pName, pGlobalTXT_LocalizationStrings[LOCSTR_EMPTY]); } else { pLODFile.LoadFile(pTmpBuf.data(), 1); fread(&pSavegameHeader[i], 100, 1, pLODFile.FindContainer("header.bin", 1)); if (pLODFile.FindContainer("image.pcx", 1)) { //pSavegameThumbnails[i].LoadFromFILE(pLODFile.FindContainer("image.pcx", 1), 0, 1); pLODFile.CloseWriteFile(); pSavegameUsedSlots[i] = 1; } else pSavegameUsedSlots[i] = 0; } } pLODFile.FreeSubIndexAndIO(); uTextureID_x_d = pIcons_LOD->LoadTexture("x_d", TEXTURE_16BIT_PALETTE); uTextureID_LS_ = pIcons_LOD->LoadTexture("LS_saveD", TEXTURE_16BIT_PALETTE); uTextureID_AR_UP_DN = pIcons_LOD->LoadTexture("AR_UP_DN", TEXTURE_16BIT_PALETTE); uTextureID_AR_DN_DN = pIcons_LOD->LoadTexture("AR_DN_DN", TEXTURE_16BIT_PALETTE); // ----------------------------- // GUIWindow_Save c-tor --- part CreateButton(21, 198, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 0, 0, "", 0); CreateButton(21, 218, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 1, 0, "", 0); CreateButton(21, 238, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 2, 0, "", 0); CreateButton(21, 258, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 3, 0, "", 0); CreateButton(21, 278, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 4, 0, "", 0); CreateButton(21, 298, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 5, 0, "", 0); CreateButton(21, 318, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 6, 0, "", 0); pBtnLoadSlot = CreateButton(241, 302, 105, 40, 1, 0, UIMSG_SaveLoadBtn, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_LS_), 0); pBtnCancel = CreateButton(350, 302, 105, 40, 1, 0, UIMSG_Cancel, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_x_d), 0); pBtnArrowUp = CreateButton(215, 199, 17, 17, 1, 0, UIMSG_ArrowUp, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_UP_DN), 0); pBtnDownArrow = CreateButton(215, 323, 17, 17, 1, 0, UIMSG_DownArrow, 34, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_DN_DN), 0); } void GUIWindow_Save::Update() { // ----------------------------------- // 004156F0 GUI_UpdateWindows --- part // { // SaveUI_Draw(); // } // ----- (004606FE) -------------------------------------------------------- // void SaveUI_Draw() // { UI_DrawSaveLoad(true); } GUIWindow_Load::GUIWindow_Load(bool ingame) : GUIWindow(0, 0, 0, 0, 0, nullptr) { // ----- (0045E361) -------------------------------------------------------- // void LoadUI_Load(unsigned int uDialogueType) // { current_screen_type = SCREEN_LOADGAME; LODWriteableFile pLODFile; // [sp+1Ch] [bp-248h]@1 dword_6BE138 = -1; pIcons_LOD->_inlined_sub2(); memset(pSavegameUsedSlots.data(), 0, sizeof(pSavegameUsedSlots)); memset(pSavegameThumbnails.data(), 0, 45 * sizeof(Image *)); uTextureID_loadsave = pIcons_LOD->LoadTexture("loadsave", TEXTURE_16BIT_PALETTE); uTextureID_load_up = pIcons_LOD->LoadTexture("load_up", TEXTURE_16BIT_PALETTE); uTextureID_save_up = pIcons_LOD->LoadTexture("save_up", TEXTURE_16BIT_PALETTE); uTextureID_LS_loadU = pIcons_LOD->LoadTexture("LS_loadU", TEXTURE_16BIT_PALETTE); uTextureID_LS_saveU = pIcons_LOD->LoadTexture("LS_saveU", TEXTURE_16BIT_PALETTE); uTextureID_x_u = pIcons_LOD->LoadTexture("x_u", TEXTURE_16BIT_PALETTE); if (ingame) { pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave)); if (current_screen_type == SCREEN_SAVEGAME) { pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_saveU)); pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up)); } else { pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_loadU)); pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_load_up)); } pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u)); } else pRenderer->DrawTextureNew(0, 0, main_menu_background); /*pGUIWindow_CurrentMenu = new GUIWindow_Load( saveload_dlg_xs[uDialogueType], saveload_dlg_ys[uDialogueType], saveload_dlg_zs[uDialogueType], saveload_dlg_ws[uDialogueType], 0, 0);*/ // GUIWindow::GUIWindow this->uFrameX = saveload_dlg_xs[ingame ? 1 : 0]; this->uFrameY = saveload_dlg_ys[ingame ? 1 : 0]; this->uFrameWidth = saveload_dlg_zs[ingame ? 1 : 0]; this->uFrameHeight = saveload_dlg_ws[ingame ? 1 : 0]; this->uFrameZ = uFrameX + uFrameWidth - 1; this->uFrameW = uFrameY + uFrameHeight - 1; DrawText(pFontSmallnum, 25, 199, 0, pGlobalTXT_LocalizationStrings[505], 0, 0, 0);// "Reading..." pRenderer->Present(); pSavegameList->Initialize(0); if (pSaveListPosition > (signed int)uNumSavegameFiles) { pSaveListPosition = 0; uLoadGameUI_SelectedSlot = 0; } pLODFile.AllocSubIndicesAndIO(300, 0); Assert(sizeof(SavegameHeader) == 100); for (uint i = 0; i < uNumSavegameFiles; ++i) { sprintf(pTmpBuf.data(), "saves\\%s", pSavegameList->pFileList[i].pSaveFileName); if (_access(pTmpBuf.data(), 6)) { pSavegameUsedSlots[i] = 0; strcpy(pSavegameHeader[i].pName, pGlobalTXT_LocalizationStrings[72]); // "Empty" continue; } pLODFile.LoadFile(pTmpBuf.data(), 1); if (pLODFile.FindContainer("header.bin", true)) fread(&pSavegameHeader[i], 100, 1, pLODFile.FindContainer("header.bin", true)); if (!_stricmp(pSavegameList->pFileList[i].pSaveFileName, pGlobalTXT_LocalizationStrings[613]))// "AutoSave.MM7" strcpy(pSavegameHeader[i].pName, pGlobalTXT_LocalizationStrings[16]);// "Autosave" if (!pLODFile.FindContainer("image.pcx", true)) { pSavegameUsedSlots[i] = 0; strcpy(pSavegameList->pFileList[i].pSaveFileName, ""); } else { //pSavegameThumbnails[i].LoadFromFILE(pLODFile.FindContainer("image.pcx", true), 0, true); pLODFile.CloseWriteFile(); pSavegameUsedSlots[i] = 1; } } pLODFile.FreeSubIndexAndIO(); if (current_screen_type == SCREEN_SAVEGAME) { uTextureID_x_d = pIcons_LOD->LoadTexture("x_d", TEXTURE_16BIT_PALETTE); uTextureID_LS_ = pIcons_LOD->LoadTexture("LS_saveD", TEXTURE_16BIT_PALETTE); } else { uTextureID_x_d = pIcons_LOD->LoadTexture("x_d", TEXTURE_16BIT_PALETTE); uTextureID_LS_ = pIcons_LOD->LoadTexture("LS_loadD", TEXTURE_16BIT_PALETTE); } uTextureID_AR_UP_DN = pIcons_LOD->LoadTexture("AR_UP_DN", TEXTURE_16BIT_PALETTE); uTextureID_AR_DN_DN = pIcons_LOD->LoadTexture("AR_DN_DN", TEXTURE_16BIT_PALETTE); CreateButton(21, 198, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 0, 0, "", 0); CreateButton(21, 219, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 1, 0, "", 0); CreateButton(21, 240, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 2, 0, "", 0); CreateButton(21, 261, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 3, 0, "", 0); CreateButton(21, 282, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 4, 0, "", 0); CreateButton(21, 303, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 5, 0, "", 0); CreateButton(21, 324, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 6, 0, "", 0); pBtnLoadSlot = CreateButton(241, 302, 105, 40, 1, 0, UIMSG_SaveLoadBtn, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_LS_), 0); pBtnCancel = CreateButton(350, 302, 105, 40, 1, 0, UIMSG_Cancel, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_x_d), 0); pBtnArrowUp = CreateButton(215, 199, 17, 17, 1, 0, UIMSG_ArrowUp, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_UP_DN), 0); pBtnDownArrow = CreateButton(215, 323, 17, 17, 1, 0, UIMSG_DownArrow, uNumSavegameFiles, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_DN_DN), 0); } void GUIWindow_Load::Update() { // ----------------------------------- // 004156F0 GUI_UpdateWindows --- part // { // LoadUI_Draw(); // } // ----- (004606F7) -------------------------------------------------------- // void LoadUI_Draw() // { UI_DrawSaveLoad(false); } //----- (004601B7) -------------------------------------------------------- static void UI_DrawSaveLoad(bool save) { // const char *pSlotName; // edi@36 GUIWindow save_load_window; // [sp+Ch] [bp-78h]@8 unsigned int pSaveFiles; // [sp+70h] [bp-14h]@10 unsigned __int64 full_hours; unsigned __int64 full_days; int full_weeks; int full_month; int current_year; int current_month; int current_day; int current_hour; int current_minutes; pRenderer->BeginScene(); if ( GetCurrentMenuID() != MENU_SAVELOAD && GetCurrentMenuID() != MENU_LoadingProcInMainMenu ) { pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave)); if (save) { pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_saveU)); pRenderer->DrawTextureIndexed( 18, 139, pIcons_LOD->GetTexture(uTextureID_save_up)); } else { pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_loadU)); pRenderer->DrawTextureIndexed( 18, 139, pIcons_LOD->GetTexture(uTextureID_load_up)); } pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u)); } if ( pSavegameUsedSlots[uLoadGameUI_SelectedSlot] ) { memset(&save_load_window, 0, 0x54); save_load_window.uFrameX = pGUIWindow_CurrentMenu->uFrameX + 240; save_load_window.uFrameWidth = 220; save_load_window.uFrameY = (pGUIWindow_CurrentMenu->uFrameY - pFontSmallnum->uFontHeight) + 157; save_load_window.uFrameZ = save_load_window.uFrameX + 219; save_load_window.uFrameHeight = pFontSmallnum->uFontHeight; save_load_window.uFrameW = pFontSmallnum->uFontHeight + save_load_window.uFrameY - 1; if ( pSavegameThumbnails[uLoadGameUI_SelectedSlot] ) pRenderer->DrawTextureNew((pGUIWindow_CurrentMenu->uFrameX + 276)/640.0f, (pGUIWindow_CurrentMenu->uFrameY + 171)/480.0f, pSavegameThumbnails[uLoadGameUI_SelectedSlot]); //Draw map name save_load_window.DrawTitleText(pFontSmallnum, 0, 0, 0, pMapStats->pInfos[pMapStats->GetMapInfo(pSavegameHeader[uLoadGameUI_SelectedSlot].pLocationName)].pName, 3); //Draw date full_hours = ((signed __int64)(pSavegameHeader[uLoadGameUI_SelectedSlot].uWordTime * 0.234375) / 60) / 60i64; full_days = (unsigned int)full_hours / 24; full_weeks = (unsigned int)(full_days / 7); full_month = (unsigned int)full_weeks / 4; current_year = (full_month / 12) + game_starting_year; current_month = full_month % 12; current_day = full_days % 28; current_hour = full_hours % 24; current_minutes = (((signed __int64)(pSavegameHeader[uLoadGameUI_SelectedSlot].uWordTime * 0.234375) / 60) % 60i64); save_load_window.uFrameY = pGUIWindow_CurrentMenu->uFrameY + 261; int am; if ( (signed int)current_hour >= 12 ) { current_hour -= 12; if ( !current_hour ) current_hour = 12; am = 1; } else am = 0; const char* day = aDayNames[full_days % 7]; const char* ampm = aAMPMNames[am]; const char* month = aMonthNames[current_month]; sprintfex(pTmpBuf.data(), "%s %d:%02d %s\n%d %s %d", day, current_hour, current_minutes, aAMPMNames[am], current_day + 1, month, current_year); save_load_window.DrawTitleText(pFontSmallnum, 0, 0, 0, pTmpBuf.data(), 3); } if ( pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_CONFIRMED) { pGUIWindow_CurrentMenu->receives_keyboard_input_2 = WINDOW_INPUT_NONE; strcpy((char *)&pSavegameHeader + 100 * uLoadGameUI_SelectedSlot, pKeyActionMap->pPressedKeysBuffer); pMessageQueue_50CBD0->AddGUIMessage(UIMSG_SaveGame, 0, 0); } else { if ( pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_CANCELLED) pGUIWindow_CurrentMenu->receives_keyboard_input_2 = WINDOW_INPUT_NONE; } if (GetCurrentMenuID() == MENU_LoadingProcInMainMenu) { pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[135]) + 25, 220, 0, pGlobalTXT_LocalizationStrings[135], 0, 0, 0);//Загрузка pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, pFontSmallnum->AlignText_Center(186, pSavegameHeader[uLoadGameUI_SelectedSlot].pName) + 25, 0x106, 0, pSavegameHeader[uLoadGameUI_SelectedSlot].pName, 185, 0); pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, pFontSmallnum->AlignText_Center(186, pGlobalTXT_LocalizationStrings[165]) + 25, 304, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0);//"Пожалуйста, пожождите" } else { if ( save ) pSaveFiles = 40; else pSaveFiles = uNumSavegameFiles; int slot_Y = 199; for ( uint i = pSaveListPosition; i < pSaveFiles; ++i ) { if ( slot_Y >= 346 ) break; if ( pGUIWindow_CurrentMenu->receives_keyboard_input_2 != WINDOW_INPUT_IN_PROGRESS || i != uLoadGameUI_SelectedSlot ) pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, 27, slot_Y, i == uLoadGameUI_SelectedSlot ? Color16(0xFF, 0xFF, 0x64) : 0, pSavegameHeader[i].pName, 185, 0); else 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, slot_Y, pFontSmallnum); slot_Y += 21; } } pRenderer->EndScene(); }