view UI/Books/UISpellBook.cpp @ 1348:3ed6dcf82912

Player::IsPlayerHealableByTemple final version
author Grumpy7
date Sat, 13 Jul 2013 00:25:19 +0200
parents 16036e3e2642
children eb02a65e5c82 8557d021a31b
line wrap: on
line source

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <assert.h>

#include "..\..\MM7.h"
#include "..\..\Render.h"
#include "..\..\Mouse.h"
#include "..\UIBooks.h"
#include "..\..\GUIWindow.h"
#include "..\..\GUIFont.h"
#include "..\..\Party.h"
#include "..\..\AudioPlayer.h"
#include "..\..\LOD.h"
#include "..\..\Allocator.h"
#include "..\..\Viewport.h"
#include "..\..\texts.h"
//
#include "..\..\mm7_data.h"


std::array<char *, 9> spellbook_texture_filename_suffices = {{"f", "a", "w", "e", "s", "m", "b", "l", "d"}}; // weak

//----- (00411300) --------------------------------------------------------
void LoadSpellbook(unsigned int spell_school)
    {
    //unsigned int v1; // esi@1
    Player *pPlayer; // ecx@1
    char v3; // al@1
    //int v4; // edi@5
    //Texture *result; // eax@6
    //unsigned char *v6; // edi@7
    //unsigned int v7; // eax@7
    //unsigned __int8 v8; // sf@8
    //unsigned __int8 v9; // of@8
    char pContainer[20]; // [sp+Ch] [bp-1Ch]@7
    //Texture *v11; // [sp+20h] [bp-8h]@5
    //int v12; // [sp+24h] [bp-4h]@5

    byte_506550 = 0;
    //v1 = uID;
    pPlayer = pPlayers[uActiveCharacter];
    v3 = pPlayer->uQuickSpell;
    if ( v3 && (unsigned __int8)v3 / 11 == spell_school )
        quick_spell_at_page = (unsigned __int8)v3 - 11 * spell_school;
    else
        quick_spell_at_page = 0;

    for (uint i = 1; i < 12; ++i)
        {
        if (pPlayer->spellbook.pChapters[spell_school].bIsSpellAvailable[i - 1])
            {
            sprintf(pContainer, "SB%sS%02d", spellbook_texture_filename_suffices[spell_school], pSpellbookSpellIndices[spell_school][i]);
            dword_506408[i] = pIcons_LOD->LoadTexturePtr(pContainer, TEXTURE_16BIT_PALETTE);

            sprintf(pContainer, "SB%sC%02d", spellbook_texture_filename_suffices[spell_school], pSpellbookSpellIndices[spell_school][i]);
            dword_5063D8[i] = pIcons_LOD->LoadTexturePtr(pContainer, TEXTURE_16BIT_PALETTE);
            }
        }
    }



//----- (00411597) --------------------------------------------------------
void OnCloseSpellBook()
    {
    pAllocator->FreeChunk(pSpellFont);
    pSpellFont = nullptr;
    pAllocator->FreeChunk(pBookFont);
    pBookFont = nullptr;
    pAllocator->FreeChunk(pBook2Font);
    pBook2Font = nullptr;
    pAllocator->FreeChunk(pAutonoteFont);
    pAutonoteFont = nullptr;
    pTexture_mapbordr->Release();
    pAudioPlayer->PlaySound(SOUND_CloseBook, 0, 0, -1, 0, 0, 0, 0);
    pIcons_LOD->_4114F2();
    dword_506364 = 0;
    }



//----- (00412AF9) --------------------------------------------------------
static void BookUI_Spellbook_DrawCurrentSchoolBackground()
{
  int v0; // ecx@1

  v0 = 0;
  if ( uActiveCharacter )
	  v0 = pParty->pPlayers[uActiveCharacter - 1].lastOpenedSpellbookPage;//*((char *)&pParty->pPartyBuffs[5].uExpireTime + 6972 * uActiveCharacter + 2);
  pRenderer->DrawTextureIndexed(8, 8, pSpellBookPagesTextr[v0]);
  pRenderer->DrawTextureIndexed(0x1DCu, 0x1C2u, pTexture_50643C);
  pRenderer->DrawTextureIndexed(0x231u, 0x1C2u, pTexture_506448);
}





//----- (00412B58) --------------------------------------------------------
void DrawSpellBookContent(Player *player)
{
  //Player *v0; // ebx@1
  int v1; // ebp@1
  //unsigned int v2; // eax@1
  Texture *v3; // edi@1
  int v4; // esi@1
  Texture *v5; // eax@3
  Texture *v6; // edx@5
  int v7; // eax@8
  int v8; // eax@11
  POINT *v9; // esi@13
  int v10; // eax@13
  Texture *v11; // edx@14
  int v12; // eax@15
  signed int v13; // ecx@18
  unsigned int v14; // esi@18
  unsigned int v15; // edi@18
  Texture *pPageTexture; // eax@21
  unsigned int v17; // [sp-Ch] [bp-2Ch]@8
  unsigned int v18; // [sp-Ch] [bp-2Ch]@15
  unsigned int v19; // [sp-8h] [bp-28h]@8
  unsigned int v20; // [sp-8h] [bp-28h]@15
  Texture *v21; // [sp-4h] [bp-24h]@15
  signed int v22; // [sp-4h] [bp-24h]@22
  Texture *v23; // [sp+10h] [bp-10h]@5
  POINT a2; // [sp+18h] [bp-8h]@13
  POINT v24;
  int v25;

  static unsigned int texture_tab_coord1[9][2]=
      {{406, 9}, {406, 46}, {406, 84}, {406,121}, {407,158}, {405, 196}, {405, 234}, {405, 272}, {405,309} };

  static unsigned int texture_tab_coord0[9][2]=
      {{415, 10}, {415, 46}, {415, 83}, {415,121}, {415,158}, {416, 196}, {416, 234}, {416, 271}, {416,307} };

  BookUI_Spellbook_DrawCurrentSchoolBackground();

  //v0 = pPlayers[uActiveCharacter];
  v1 = 11 * player->lastOpenedSpellbookPage;
  //v2 = pIcons_LOD->FindTextureByName("Pending");
  v3 = pIcons_LOD->GetTexture(pIcons_LOD->FindTextureByName("Pending"));
  pRenderer->ClearZBuffer(0, 479);
  v4 = 1;
  if ( __OFSUB__(v1, v1 + 11) ^ 1 )
  {
    do
    {
      if ( *(&player->_guilds_member_bits[v1 + 63] + v4) )
      {
        v5 = (Texture *)dword_506408[v4];
        if ( v5 != v3 )
        {
          if ( quick_spell_at_page == v4 )
          {
            v6 = dword_5063D8[v4];
            v23 = dword_5063D8[v4];
          }
          else
          {
            v23 = dword_506408[v4];
            v6 = v5;
          }
          if ( v6->pLevelOfDetail0_prolly_alpha_mask )
          {
			v7 = player->lastOpenedSpellbookPage;
           // v7 =  (12 * v0->lastOpenedSpellbookPage + pSpellbookSpellIndices[v0->lastOpenedSpellbookPage][v4]);
            v19 = pViewport->uViewportTL_Y +  pIconPos[v7][pSpellbookSpellIndices[v7][v4]].Ypos;
            v17 = pViewport->uViewportTL_X +  pIconPos[v7][pSpellbookSpellIndices[v7][v4]].Xpos;
            if ( BYTE1(v6->pBits) & 2 )
              pRenderer->DrawTextureTransparent(v17, v19, v6);
            else
              pRenderer->DrawTextureIndexed(v17, v19, v6);
            pRenderer->DrawMaskToZBuffer(pIconPos[v7][pSpellbookSpellIndices[v7][v4]].Xpos,
				               pIconPos[v7][pSpellbookSpellIndices[v7][v4]].Ypos, v23, v4);
          }
        }
      }
      ++v4;
    }
    while ( v4 - 1 < 11 );
  }

  v9 = pMouse->GetCursorPos(&a2);
  v10 = pRenderer->pActiveZBuffer[v9->x + pSRZBufferLineOffsets[pMouse->GetCursorPos(&v24)->y]] & 0xFFFF;
  if ( v10 )
  {
    v11 = dword_5063D8[v10];
    if ( v11->pLevelOfDetail0_prolly_alpha_mask )
    {
      v21 = dword_5063D8[v10];
	  v12 = player->lastOpenedSpellbookPage;
    //  v12 = (12 * v0->lastOpenedSpellbookPage + pSpellbookSpellIndices[v0->lastOpenedSpellbookPage][v10]);
      v20 = pViewport->uViewportTL_Y +  pIconPos[v12][pSpellbookSpellIndices[v12][v10]].Ypos;
      v18 = pViewport->uViewportTL_X +  pIconPos[v12][pSpellbookSpellIndices[v12][v10]].Xpos;
      if ( BYTE1(v11->pBits) & 2 )
        pRenderer->DrawTextureTransparent(v18, v20, v21);
      else
        pRenderer->DrawTextureIndexed(v18, v20, v21);
    }
  }
  v13 = 0;
  a2.x = (LONG)&player->pActiveSkills[12];
  v14 = (unsigned int)&player->pActiveSkills[12];
  v15 = (unsigned int)&player->pActiveSkills[12];
  v25 = 0;
  do
  {
    if ( *(short *)a2.x )
    {
      if ( player->lastOpenedSpellbookPage == v13 )
      {
        pPageTexture = pTextures_tabs[v13][1];
       v14=texture_tab_coord1[v13][0];
       v15=texture_tab_coord1[v13][1];
      }
      else
      {
        pPageTexture = pTextures_tabs[v13][0];
        v14=texture_tab_coord0[v13][0];
        v15=texture_tab_coord0[v13][1];
      }
      pRenderer->DrawTextureTransparent(v14, v15, pPageTexture);
      v13 = v25;
    }
    a2.x += 2;
    ++v13;
    v25 = v13;
  }
  while ( v13 < 9 );
}