view GUIProgressBar.cpp @ 2:2ca04ccb612a

NoCD, main menu, various
author Nomad
date Wed, 10 Oct 2012 14:21:15 +0200
parents 8b8875f5b359
children be2066176d89
line wrap: on
line source

#include "GUIProgressBar.h"
#include "LOD.h"
#include "Mouse.h"
#include "Party.h"
#include "Render.h"
#include "IconFrameTable.h"

#include "mm7_data.h"




struct GUIProgressBar *pGameLoadingUI_ProgressBar;




//----- (00443484) --------------------------------------------------------
bool GUIProgressBar::_443484(int a2)
{
  GUIProgressBar *v2; // esi@1
  signed int v4; // eax@7
  int v5; // ecx@8
  int v6; // edi@8
  int v7; // edx@14
  const char *v8; // [sp-8h] [bp-84h]@20
  unsigned int v9; // [sp-4h] [bp-80h]@20
  char Str1[64]; // [sp+4h] [bp-78h]@16

  v2 = this;
  if (pAsyncMouse)
    pAsyncMouse->Suspend();
  if ( v2->pLoadingBg.pPixels )
    return 0;
  if ( a2 )
    v2->uType = a2;
  v4 = 1;
  if ( v2->uType == 1 )
  {
    v5 = 0;
    v6 = (int)&v2->field_10;
    do
    {
      if ( *(char *)(v6 + v4) == 1 )
        ++v5;
      ++v4;
    }
    while ( v4 <= 5 );
    if ( v5 == 5 )
      memset(&v2->field_10, 0, 8u);
    v7 = rand() % 5 + 1;
    if ( *(&v2->field_10 + v7) == 1 )
    {
      do
        v7 = rand() % 5 + 1;
      while ( *(char *)(v6 + v7) == 1 );
    }
    sprintfex(Str1, "loading%d.pcx", v7);
    v2->pLoadingBg.Load(Str1, 2);
    v2->uProgressCurrent = 0;
    v2->uX = 122;
    v2->uY = 151;
    v2->uWidth = 449;
    v2->uHeight = 56;
    v2->uProgressMax = 26;
    pIcons_LOD->_410522(&v2->pLoadingProgress, "loadprog", 2u);
    Draw();
    return 1;
  }
  if ( !pParty->uAlignment )
  {
    v9 = 2;
    v8 = "bardata-b";
    goto LABEL_23;
  }
  if ( pParty->uAlignment == 1 )
  {
    v9 = 2;
    v8 = "bardata";
    goto LABEL_23;
  }
  if ( pParty->uAlignment == 2 )
  {
    v9 = 2;
    v8 = "bardata-c";
LABEL_23:
    pIcons_LOD->_410522(&v2->pBardata, v8, v9);
  }
  v2->uProgressCurrent = 0;
  v2->uProgressMax = 26;
  Draw();
  return 1;
}

//----- (004435BB) --------------------------------------------------------
void GUIProgressBar::Reset(unsigned __int8 uMaxProgress)
{
  this->field_9 = 0;
  this->uProgressCurrent = 0;
  this->uProgressMax = uMaxProgress;
}

//----- (004435CD) --------------------------------------------------------
void GUIProgressBar::Progress()
{
  unsigned __int8 v1; // al@1

  ++this->uProgressCurrent;
  v1 = this->uProgressMax;
  if ( this->uProgressCurrent > v1 )
    this->uProgressCurrent = v1;
  Draw();
}

//----- (004435E2) --------------------------------------------------------
void GUIProgressBar::Release()
{
  GUIProgressBar *v1; // esi@1
  char v2; // al@5
  int v3; // edi@7

  v1 = this;
  if (pAsyncMouse)
    pAsyncMouse->Resume();
  if ( v1->uType == 1 )
  {
    if ( !v1->pLoadingBg.pPixels )
      return;
    v2 = v1->uProgressMax;
    if ( v1->uProgressCurrent != v2 )
    {
      v1->uProgressCurrent = v2 - 1;
      Progress();
    }
    free(v1->pLoadingBg.pPixels);
    v3 = (int)&v1->pLoadingProgress.pLevelOfDetail0;
    free(v1->pLoadingProgress.pLevelOfDetail0);
    free(v1->pLoadingProgress.pPalette16);
    v1->pLoadingProgress.pPalette16 = 0;
    v1->pLoadingBg.pPixels = 0;
  }
  else
  {
    if ( !v1->pBardata.pLevelOfDetail0 )
      return;
    free(v1->pBardata.pLevelOfDetail0);
    v3 = (int)&v1->pBardata.pPalette16;
    free(v1->pBardata.pPalette16);
    v1->pBardata.pLevelOfDetail0 = 0;
  }
  *(int *)v3 = 0;
}

//----- (00443670) --------------------------------------------------------
void GUIProgressBar::Draw()
{
  GUIProgressBar *v1; // edi@1
  Render *v2; // ecx@2
  IconFrame *v3; // eax@10
  float v4; // ST2C_4@10

  v1 = this;
  pRenderer->BeginScene();
  if ( v1->uType != 1 )
  {
    if ( v1->pBardata.pLevelOfDetail0 )
    {
      if ( pRenderer->pRenderD3D )
      {
        if ( !pRenderer->bWindowMode )
          pRenderer->_49FD3A((int)v1);
      }
      pRenderer->DrawTextureIndexed(0x50u, 0x7Au, &v1->pBardata);
      v3 = pIconsFrameTable->GetFrame(uIconID_TurnHour, 0);
      pRenderer->DrawTextureTransparent(0x64u, 0x92u, &pIcons_LOD->pTextures[v3->uTextureID]);
      v4 = (double)(113 * v1->uProgressCurrent) / (double)v1->uProgressMax;
      pRenderer->FillRect2(
        0,
        174,
        164,
        COERCE_UNSIGNED_INT64(v4 + 6.7553994e15),
        16,
        LOWORD(pRenderer->uTargetRMask));
      goto LABEL_11;
    }
    v2 = pRenderer;
LABEL_6:
    pRenderer->EndScene();
    return;
  }
  v2 = pRenderer;
  if ( !v1->pLoadingBg.pPixels )
    goto LABEL_6;
  pRenderer->DrawTextureRGB(0, 0, &v1->pLoadingBg);
  pRenderer->Clip_v2(0, 0, 0x27Fu, 0x1DFu);
  pRenderer->Clip(
    0xACu,
    0x1CBu,
    15 * (signed int)(signed __int64)((double)(300 * v1->uProgressCurrent) / (double)v1->uProgressMax) / 15 + 172,
    0x1D7u);
  pRenderer->DrawTextureTransparent(0xACu, 0x1CBu, &v1->pLoadingProgress);
  pRenderer->ResetClip();
LABEL_11:
  pRenderer->EndScene();
  pRenderer->Present();
}