view UISaveLoad.cpp @ 734:2f4e33c1ed24

stru154
author Nomad
date Fri, 22 Mar 2013 16:16:40 +0200
parents d6236f6a9882
children dfd683c4f538
line wrap: on
line source

#include <assert.h>

#include "MM7.h"

#include "MapInfo.h"
#include "Game.h"
#include "GUIWindow.h"
#include "GUIFont.h"
#include "GUIButton.h"
#include "GUIProgressBar.h"
#include "Party.h"
#include "AudioPlayer.h"
#include "Outdoor.h"
#include "IndoorCamera.h"
#include "Overlays.h"
#include "Monsters.h"
#include "Arcomage.h"
#include "LOD.h"
#include "Actor.h"
#include "Allocator.h"
#include "Events.h"
#include "Viewport.h"
#include "FrameTableInc.h"
#include "Math.h"
#include "SpriteObject.h"
#include "ObjectList.h"
#include "Chest.h"
#include "PaletteManager.h"
#include "DecorationList.h"
#include "SaveLoad.h"
#include "stru123.h"
#include "Time.h"
#include "IconFrameTable.h"
#include "Awards.h"
#include "Autonotes.h"
#include "stru160.h"
#include "stru279.h"
#include "TurnEngine.h"
#include "stru277.h"
#include "Weather.h"
#include "stru272.h"
#include "stru298.h"
#include "StorylineTextTable.h"
#include "Events2D.h"
#include "texts.h"
#include "stru351.h"

#include "mm7_data.h"


//----- (004601B7) --------------------------------------------------------
void GameUI_MainMenu_DoDrawLoad(int a1)
{
  unsigned __int16 v1; // bx@1
  unsigned int v2; // edi@4
  unsigned int v3; // eax@4
  unsigned int v4; // eax@8
  int v5; // edi@8
  unsigned int v6; // eax@8
  unsigned int pMapID; // eax@10
  signed __int64 v8; // qax@10
  unsigned int v9; // ebx@10
  unsigned __int64 v10; // qax@10
  __int64 v11; // qax@10
  char v12; // di@10
  unsigned __int64 v13; // qtt@10
  unsigned int v14; // ecx@10
  __int64 pOurHour; // qax@10
  int v16; // edi@10
  signed int pHour; // ebx@22
  //const char *v18; // ST14_4@32
  int v19; // eax@32
  const char *v20; // ST18_4@32
  int v21; // eax@32
  //const char *v22; // ST14_4@32
  int v23; // eax@32
  const char *pSlotName; // edi@36
  int v25; // eax@43
  GUIWindow pWindow; // [sp+Ch] [bp-78h]@8
  /*unsigned int Dst; // [sp+Ch] [bp-78h]@8
  unsigned int v27; // [sp+10h] [bp-74h]@8
  int v28; // [sp+14h] [bp-70h]@8
  int v29; // [sp+18h] [bp-6Ch]@8
  unsigned int v30; // [sp+1Ch] [bp-68h]@8
  unsigned int v31; // [sp+20h] [bp-64h]@8*/
  int pMinutes; // [sp+60h] [bp-24h]@10
  int pMonthNum; // [sp+68h] [bp-1Ch]@10
  unsigned int pSaveFiles; // [sp+70h] [bp-14h]@10
  __int64 pAMPM2; // [sp+74h] [bp-10h]@10
  int pYear; // [sp+7Ch] [bp-8h]@10
  int a4; // [sp+80h] [bp-4h]@1
  int pFilesID;

  v1 = 255;
  a4 = a1;
  GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFF, 0xFF, 0xFF);
  GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFF, 0xFF, 0x9B);
  pRenderer->BeginScene();
  if ( GetCurrentMenuID() != MENU_SAVELOAD && GetCurrentMenuID() != MENU_LOADINGPROC )
  {
    pRenderer->DrawTextureIndexed(8, 8, uTextureID_loadsave != -1 ? &pIcons_LOD->pTextures[uTextureID_loadsave] : 0);
    if ( a4 )
    {
      v2 = uTextureID_save_up;
      v3 = uTextureID_LS_saveU;
    }
    else
    {
      v2 = uTextureID_load_up;
      v3 = uTextureID_LS_loadU;
    }
    pRenderer->DrawTextureIndexed(241, 302, (Texture *)(v3 != -1 ? &pIcons_LOD->pTextures[v3] : 0));
    pRenderer->DrawTextureIndexed(18, 139, (Texture *)(v2 != -1 ? &pIcons_LOD->pTextures[v2] : 0));
    pRenderer->DrawTextureIndexed(351, 302, (Texture *)(uTextureID_x_u != -1 ? &pIcons_LOD->pTextures[uTextureID_x_u] : 0));
    v1 = 255;
  }
  if ( pSavegameUsedSlots[uLoadGameUI_SelectedSlot] )
  {
    memset(&pWindow, 0, 0x54);
    pWindow.uFrameX = pGUIWindow_CurrentMenu->uFrameX + 240;
    v4 = pGUIWindow_CurrentMenu->uFrameY - pFontSmallnum->uFontHeight;
    pWindow.uFrameWidth = 220;
    v4 += 157;
    pWindow.uFrameY = v4;
    v5 = pFontSmallnum->uFontHeight;
    pWindow.uFrameZ = pWindow.uFrameX + 219;
    pWindow.uFrameHeight = v5;
    pWindow.uFrameW = v5 + v4 - 1;
    v6 = uLoadGameUI_SelectedSlot;
    if (pSavegameThumbnails[uLoadGameUI_SelectedSlot].pPixels)
    {
      pRenderer->DrawTextureRGB(pGUIWindow_CurrentMenu->uFrameX + 276, pGUIWindow_CurrentMenu->uFrameY + 171, pSavegameThumbnails + uLoadGameUI_SelectedSlot);
      v6 = uLoadGameUI_SelectedSlot;
    }
    pMapID = pMapStats->GetMapInfo(pSavegameHeader[v6].pLocationName);
    pWindow.DrawTitleText(pFontSmallnum, 0, 0, 0, pMapStats->pInfos[pMapID].pName, 3);
    v8 = (signed __int64)(pSavegameHeader[uLoadGameUI_SelectedSlot].uWordTime * 0.234375) / 60;
    pMinutes = (int)((signed __int64)(pSavegameHeader[uLoadGameUI_SelectedSlot].uWordTime * 0.234375) / 60) >> 32;
    v9 = v8;
    v8 /= 60i64;
    pAMPM2 = v8;
    v10 = (unsigned int)v8 / 24;
    pSaveFiles = v10;
    v11 = (unsigned int)(v10 / 7);
    v12 = v11;
    LODWORD(v13) = (unsigned int)v11 >> 2;
    HIDWORD(v13) = HIDWORD(v11);
    pMonthNum = v13 % 12;
    pYear = v13 / 12;
    pMinutes = (int)__PAIR__(pMinutes, v9) % 60;
    pOurHour = pAMPM2 % 24;
    v14 = (unsigned __int64)(pAMPM2 % 24) >> 32;
    LODWORD(pAMPM2) = pAMPM2 % 24;
    HIDWORD(pOurHour) = pSaveFiles % 28;
    pYear += game_starting_year;
    v16 = v12 & 3;
    pWindow.uFrameY = pGUIWindow_CurrentMenu->uFrameY + 261;
    HIDWORD(pAMPM2) = v14 == 0 && ((signed int)v14 > 0 || (unsigned int)pOurHour >= 12)
                && (signed int)v14 <= 0 && (v14 != 0 || (unsigned int)pOurHour < 24);
    if ( v14  != 0 || (signed int)v14 <= 0 && (unsigned int)pOurHour <= 12 )
    {
      if ( !(v14 | (unsigned int)pOurHour) )
      {
        pSaveFiles = 0;
        pHour = 12;
        goto LABEL_23;
      }
    }
    else
    {
      v14 = (__PAIR__(v14, (unsigned int)pOurHour) - 12) >> 32;
      LODWORD(pOurHour) = pOurHour - 12;
    }
    pHour = pOurHour;
    pSaveFiles = v14;
LABEL_23:
    auto day = aDayNames[HIDWORD(pOurHour) % 7];
    auto ampm = aAMPMNames[HIDWORD(pAMPM2)];
    auto month = aMonthNames[pMonthNum];
    //sprintf(pTmpBuf, "%s %d:%02d%s\n%d %s %d", _d, v17, (int)32, _a, 3, _m, pFilesID);
    sprintf(pTmpBuf, "%s %d:%02d%s\n%d %s %d", day, pHour, pMinutes, ampm, 7 * v16 + HIDWORD(pOurHour) % 7 + 1, month, pYear);
    pWindow.DrawTitleText(pFontSmallnum, 0, 0, 0, pTmpBuf, 3u);
    v1 = 255;
  }
  if ( pGUIWindow_CurrentMenu->field_40 == 2 )
  {
    pGUIWindow_CurrentMenu->field_40 = 0;
    strcpy((char *)&pSavegameHeader + 100 * uLoadGameUI_SelectedSlot, (const char *)pKeyActionMap->pPressedKeysBuffer);
    /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
    {
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)83;
      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
      *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
      ++pMessageQueue_50CBD0->uNumMessages;
    }*/
    pMessageQueue_50CBD0->AddMessage(UIMSG_SaveGame, 0, 0);
  }
  else
  {
    if ( pGUIWindow_CurrentMenu->field_40 == 3 )
      pGUIWindow_CurrentMenu->field_40 = 0;
  }
  if (GetCurrentMenuID() == MENU_LOADINGPROC)
  {
    //v18 = pGlobalTXT_LocalizationStrings[135];
    v19 = pFontSmallnum->AlignText_Center(0xBA, pGlobalTXT_LocalizationStrings[135]);//"Загрузка"
    pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, v19 + 25, 220, 0, pGlobalTXT_LocalizationStrings[135], 0, 0, 0);
    v20 = (const char *)(pSavegameHeader + uLoadGameUI_SelectedSlot);
    v21 = pFontSmallnum->AlignText_Center(0xBA, (const char *)pSavegameHeader + 100 * uLoadGameUI_SelectedSlot);
    pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, v21 + 25, 0x106, 0, v20, 185, 0);
    //v22 = pGlobalTXT_LocalizationStrings[165];
    v23 = pFontSmallnum->AlignText_Center(0xBA, pGlobalTXT_LocalizationStrings[165]);//"Пожалуйста, пожождите"
    pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, v23 + 25, 304, 0, pGlobalTXT_LocalizationStrings[165], 0, 0, 0);
  }
  else
  {
    if ( a4 )
      pSaveFiles = 40;
    else
      pSaveFiles = uNumSavegameFiles;
    a4 = 199;
    pFilesID = pSaveListPosition;
    pSlotName = (const char *)(&pSavegameHeader[pSaveListPosition]);//draw name for save slot
    do
    {
      if ( pFilesID >= (signed int)pSaveFiles )
        break;
      short clr;
      HIDWORD(pAMPM2) = clr = (pFilesID == uLoadGameUI_SelectedSlot ? GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(v1, v1, 0x64) : 0);
      if ( pGUIWindow_CurrentMenu->field_40 != 1 || pFilesID != uLoadGameUI_SelectedSlot )
      {
        pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, 0x1B, a4, clr, pSlotName, 185, 0);
      }
      else
      {
        v25 = pGUIWindow_CurrentMenu->DrawTextInRect(pFontSmallnum, 0x1B, a4, clr, (const char *)pKeyActionMap->pPressedKeysBuffer, 175, 1);
        pGUIWindow_CurrentMenu->DrawFlashingInputCursor(v25 + 27, a4, pFontSmallnum);
      }
      a4 += 21;
      ++pFilesID;
      pSlotName += 100;
    }
    while ( a4 < 346 );
  }
  pRenderer->EndScene();
}
// 6A0C9C: using guessed type int dword_6A0C9C;

//----- (004606F7) --------------------------------------------------------
void __cdecl GameUI_MainMenu_DrawLoad()
{
  GameUI_MainMenu_DoDrawLoad(0);
}

//----- (004606FE) --------------------------------------------------------
void __cdecl sub_4606FE()
{
  GameUI_MainMenu_DoDrawLoad(1);
}


void __cdecl FreeSavegameThumbnails()
    {
    for (int i = 0; i < 40; ++i)
        //pAllocator->FreeChunk(pSavegameThumbnails[i].pPixels);
        pSavegameThumbnails[i].Release();
    }