Mercurial > mm7
diff GUI/UI/Spellbook.cpp @ 2574:dd36326a9994
More texture refactoring
GetLeather -> DrawTextureCustomHeight
author | a.parshin |
---|---|
date | Mon, 07 Mar 2016 03:48:40 +0200 |
parents | 0c67be4ec900 |
children |
line wrap: on
line diff
--- a/GUI/UI/Spellbook.cpp Sat Mar 05 16:25:53 2016 +0200 +++ b/GUI/UI/Spellbook.cpp Mon Mar 07 03:48:40 2016 +0200 @@ -1,4 +1,5 @@ #include "Engine/Engine.h" +#include "Engine/AssetsManager.h" #include "Engine/Party.h" #include "Engine/LOD.h" #include "Engine/Timer.h" @@ -40,6 +41,18 @@ }; +Image *ui_spellbook_btn_quckspell = nullptr; +Image *ui_spellbook_btn_quckspell_click = nullptr; +Image *ui_spellbook_btn_close = nullptr; +Image *ui_spellbook_btn_close_click = nullptr; + + +std::array<Image *, 12> SBPageCSpellsTextureList; +std::array<Image *, 12> SBPageSSpellsTextureList; + +std::array<Image *, 9> ui_spellbook_school_backgrounds; +std::array<std::array<Image *, 2>, 9> ui_spellbook_school_tabs; + GUIWindow_Spellbook::GUIWindow_Spellbook() : @@ -64,7 +77,7 @@ { // ------------------------------------ // 004304E7 void Game_EventLoop -- part - + OnCloseSpellBookPage(); pPlayers[uActiveCharacter]->lastOpenedSpellbookPage = page; OpenSpellbook(); @@ -95,10 +108,11 @@ continue; v4 = pPlayer->lastOpenedSpellbookPage; //v4 = (12 * pPlayer->lastOpenedSpellbookPage + pSpellbookSpellIndices[pPlayer->lastOpenedSpellbookPage][i + 1]); - CreateButton(pViewport->uViewportTL_X + pIconPos[v4][pSpellbookSpellIndices[v4][i + 1]].Xpos, + CreateButton( + pViewport->uViewportTL_X + pIconPos[v4][pSpellbookSpellIndices[v4][i + 1]].Xpos, pViewport->uViewportTL_Y + pIconPos[v4][pSpellbookSpellIndices[v4][i + 1]].Ypos, //dword_4E20D0 - SBPageSSpellsTextureList[i + 1]->uTextureWidth, - SBPageSSpellsTextureList[i + 1]->uTextureHeight, + SBPageSSpellsTextureList[i + 1]->GetWidth(), + SBPageSSpellsTextureList[i + 1]->GetHeight(), 1, 79, UIMSG_SelectSpell, i, 0, "", 0); ++a2; //++v3; @@ -119,10 +133,10 @@ if (pPlayer->pActiveSkills[PLAYER_SKILL_LIGHT]) CreateButton(400, 271, 50, 36, 1, 0, UIMSG_OpenSpellbookPage, 7, 0, aSpellSchoolNames[7], 0); if (pPlayer->pActiveSkills[PLAYER_SKILL_DARK]) CreateButton(400, 307, 50, 36, 1, 0, UIMSG_OpenSpellbookPage, 8, 0, aSpellSchoolNames[8], 0); - CreateButton(476, 450, pSBClickQuickSpellBtnTextr->uTextureWidth, pSBClickQuickSpellBtnTextr->uTextureHeight, 1, 78, UIMSG_ClickInstallRemoveQuickSpellBtn, 0, 0, "", 0); - pBtn_InstallRemoveSpell = CreateButton(476, 450, 48, 32, 1, 78, UIMSG_ClickInstallRemoveQuickSpellBtn, 0, 0, "", pSBClickQuickSpellBtnTextr, 0); - CreateButton(561, 450, pSpellBookClickCloseBtnTextr->uTextureWidth, pSpellBookClickCloseBtnTextr->uTextureHeight, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], 0); - pBtn_CloseBook = CreateButton(561, 450, 48, 32, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pSpellBookClickCloseBtnTextr, 0); + CreateButton(476, 450, ui_spellbook_btn_quckspell->GetWidth(), ui_spellbook_btn_quckspell->GetHeight(), 1, 78, UIMSG_ClickInstallRemoveQuickSpellBtn, 0, 0, "", 0); + pBtn_InstallRemoveSpell = CreateButton(476, 450, 48, 32, 1, 78, UIMSG_ClickInstallRemoveQuickSpellBtn, 0, 0, "", ui_spellbook_btn_quckspell_click, 0); + CreateButton(561, 450, ui_spellbook_btn_close->GetWidth(), ui_spellbook_btn_close->GetHeight(), 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], 0); + pBtn_CloseBook = CreateButton(561, 450, 48, 32, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], ui_spellbook_btn_close_click, 0); } void GUIWindow_Spellbook::Update() @@ -137,12 +151,12 @@ // 00412B58 void DrawSpellBookContent(Player *player) auto player = pPlayers[uActiveCharacter]; - Texture *PendingTexture; // edi@1 - Texture *pTexture; // edx@5 + //Texture_MM7 *PendingTexture; // edi@1 + Image *pTexture; // edx@5 int v10; // eax@13 unsigned int pX_coord; // esi@18 unsigned int pY_coord; // edi@18 - Texture *pPageTexture; // eax@21 + //Texture_MM7 *pPageTexture; // eax@21 // signed int v22; // [sp-4h] [bp-24h]@22 POINT a2; // [sp+18h] [bp-8h]@13 @@ -154,7 +168,7 @@ BookUI_Spellbook_DrawCurrentSchoolBackground(); - PendingTexture = pIcons_LOD->GetTexture(pIcons_LOD->FindTextureByName("Pending")); + //PendingTexture = pIcons_LOD->GetTexture(pIcons_LOD->FindTextureByName("Pending")); pRenderer->ClearZBuffer(0, 479); if ((11 * player->lastOpenedSpellbookPage) || ((11 * player->lastOpenedSpellbookPage) + 11))//??? maybe structure need fix { @@ -162,22 +176,22 @@ { if (player->_achieved_awards_bits[(11 * player->lastOpenedSpellbookPage) + i + 63]) { - if (SBPageSSpellsTextureList[i] != PendingTexture) + if (SBPageSSpellsTextureList[i]) { if (quick_spell_at_page == i) pTexture = SBPageCSpellsTextureList[i]; else pTexture = SBPageSSpellsTextureList[i]; - if (pTexture->paletted_pixels) + if (pTexture) { pX_coord = pViewport->uViewportTL_X + pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][i]].Xpos; pY_coord = pViewport->uViewportTL_Y + pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][i]].Ypos; - if (pTexture->pBits & 0x200) - pRenderer->DrawTextureIndexedAlpha(pX_coord, pY_coord, pTexture); - else - pRenderer->DrawTextureTransparentColorKey(pX_coord, pY_coord, pTexture); - pRenderer->DrawMaskToZBuffer(pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][i]].Xpos, - pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][i]].Ypos, pTexture, i); + + pRenderer->DrawTextureAlphaNew(pX_coord/640.0f, pY_coord/480.0f, pTexture); + pRenderer->ZDrawTextureAlpha( + pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][i]].Xpos/640.0f, + pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][i]].Ypos/480.0f, + pTexture, i); } } } @@ -188,35 +202,34 @@ v10 = pRenderer->pActiveZBuffer[a2.x + pSRZBufferLineOffsets[a2.y]] & 0xFFFF; if (v10) { - if (SBPageCSpellsTextureList[v10]->paletted_pixels) + if (SBPageCSpellsTextureList[v10]) { pX_coord = pViewport->uViewportTL_X + pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][v10]].Xpos; pY_coord = pViewport->uViewportTL_Y + pIconPos[player->lastOpenedSpellbookPage][pSpellbookSpellIndices[player->lastOpenedSpellbookPage][v10]].Ypos; - if (SBPageCSpellsTextureList[v10]->pBits & 0x200) - pRenderer->DrawTextureIndexedAlpha(pX_coord, pY_coord, SBPageCSpellsTextureList[v10]); - else - pRenderer->DrawTextureTransparentColorKey(pX_coord, pY_coord, SBPageCSpellsTextureList[v10]); + + pRenderer->DrawTextureAlphaNew(pX_coord/640.0f, pY_coord/480.0f, SBPageCSpellsTextureList[v10]); } } - //pX_coord = (unsigned int)&player->pActiveSkills[PLAYER_SKILL_FIRE]; - //pY_coord = (unsigned int)&player->pActiveSkills[PLAYER_SKILL_FIRE]; + for (uint i = 0; i < 9; i++) { if (player->pActiveSkills[PLAYER_SKILL_FIRE + i]) { + auto pPageTexture = ui_spellbook_school_tabs[i][0]; if (player->lastOpenedSpellbookPage == i) { - pPageTexture = pTextures_tabs[i][1]; + pPageTexture = ui_spellbook_school_tabs[i][1]; pX_coord = texture_tab_coord1[i][0]; pY_coord = texture_tab_coord1[i][1]; } else { - pPageTexture = pTextures_tabs[i][0]; + pPageTexture = ui_spellbook_school_tabs[i][0]; pX_coord = texture_tab_coord0[i][0]; pY_coord = texture_tab_coord0[i][1]; } - pRenderer->DrawTextureIndexedAlpha(pX_coord, pY_coord, pPageTexture); + + pRenderer->DrawTextureAlphaNew(pX_coord/640.0f, pY_coord/480.0f, pPageTexture); } } } @@ -249,10 +262,10 @@ if (pPlayers[uActiveCharacter]->spellbook.pChapters[spell_school].bIsSpellAvailable[i - 1]) { sprintf(pContainer, "SB%sS%02d", spellbook_texture_filename_suffices[spell_school], pSpellbookSpellIndices[spell_school][i]); - SBPageSSpellsTextureList[i] = pIcons_LOD->LoadTexturePtr(pContainer, TEXTURE_16BIT_PALETTE); + SBPageSSpellsTextureList[i] = assets->GetImage_16BitAlpha(pContainer); sprintf(pContainer, "SB%sC%02d", spellbook_texture_filename_suffices[spell_school], pSpellbookSpellIndices[spell_school][i]); - SBPageCSpellsTextureList[i] = pIcons_LOD->LoadTexturePtr(pContainer, TEXTURE_16BIT_PALETTE); + SBPageCSpellsTextureList[i] = assets->GetImage_16BitAlpha(pContainer); } } } @@ -263,9 +276,10 @@ int pTexID = 0; if ( uActiveCharacter ) pTexID = pParty->pPlayers[uActiveCharacter - 1].lastOpenedSpellbookPage; - pRenderer->DrawTextureTransparentColorKey(8, 8, pSpellBookPagesTextr[pTexID]); - pRenderer->DrawTextureTransparentColorKey(476, 450, pSBQuickSpellBtnTextr); - pRenderer->DrawTextureTransparentColorKey(561, 450, pSpellBookCloseBtnTextr); + pRenderer->DrawTextureAlphaNew(8/640.0f, 8/480.0f, ui_spellbook_school_backgrounds[pTexID]); + + pRenderer->DrawTextureAlphaNew(476/640.0f, 450/480.0f, ui_spellbook_btn_quckspell); + pRenderer->DrawTextureAlphaNew(561/640.0f, 450/480.0f, ui_spellbook_btn_close); } @@ -280,11 +294,11 @@ if (!pIcons_LOD->uNumPrevLoadedFiles) pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles; pAudioPlayer->PlaySound(SOUND_openbook, 0, 0, -1, 0, 0, 0, 0); - pSpellBookPagesTextr_9 = pIcons_LOD->LoadTexturePtr("book", TEXTURE_16BIT_PALETTE); - pTexture_pagemask = pIcons_LOD->LoadTexturePtr("pagemask", TEXTURE_16BIT_PALETTE); - pSpellBookCloseBtnTextr = pIcons_LOD->LoadTexturePtr("ib-m5-u", TEXTURE_16BIT_PALETTE); - pSpellBookClickCloseBtnTextr = pIcons_LOD->LoadTexturePtr("ib-m5-d", TEXTURE_16BIT_PALETTE); - pSBQuickSpellBtnTextr = pIcons_LOD->LoadTexturePtr("ib-m6-u", TEXTURE_16BIT_PALETTE); + + ui_spellbook_btn_close = assets->GetImage_16BitAlpha(L"ib-m5-u"); + ui_spellbook_btn_close_click = assets->GetImage_16BitAlpha(L"ib-m5-d"); + ui_spellbook_btn_quckspell = assets->GetImage_16BitAlpha(L"ib-m6-u"); + ui_spellbook_btn_quckspell_click = assets->GetImage_16BitAlpha(L"ib-m6-d"); static const char *texNames[9] = // 004E24EC { @@ -292,14 +306,15 @@ "SBSB00", "SBMB00", "SBBB00", "SBLB00", "SBDB00" }; - pSBClickQuickSpellBtnTextr = pIcons_LOD->LoadTexturePtr("ib-m6-d", TEXTURE_16BIT_PALETTE); for (uint i = 0; i < 9; ++i) { - pSpellBookPagesTextr[i] = pIcons_LOD->LoadTexturePtr(texNames[i], TEXTURE_16BIT_PALETTE); + ui_spellbook_school_backgrounds[i] = assets->GetImage_16BitColorKey(texNames[i], 0x7FF); + sprintf(pTmpBuf.data(), "tab%da", i + 1); - pTextures_tabs[i][0] = pIcons_LOD->LoadTexturePtr(pTmpBuf.data(), TEXTURE_16BIT_PALETTE); + ui_spellbook_school_tabs[i][0] = assets->GetImage_16BitAlpha(pTmpBuf.data()); + sprintf(pTmpBuf.data(), "tab%db", i + 1); - pTextures_tabs[i][1] = pIcons_LOD->LoadTexturePtr(pTmpBuf.data(), TEXTURE_16BIT_PALETTE); + ui_spellbook_school_tabs[i][1] = assets->GetImage_16BitAlpha(pTmpBuf.data()); } } @@ -307,15 +322,88 @@ //----- (00411473) -------------------------------------------------------- void OnCloseSpellBook() { - pTexture_pagemask->Release(); - pSpellBookCloseBtnTextr->Release(); - pSBQuickSpellBtnTextr->Release(); + if (ui_spellbook_btn_close) + { + ui_spellbook_btn_close->Release(); + ui_spellbook_btn_close = nullptr; + } + if (ui_spellbook_btn_close_click) + { + ui_spellbook_btn_close_click->Release(); + ui_spellbook_btn_close_click = nullptr; + } + + + + if (ui_spellbook_btn_quckspell) + { + ui_spellbook_btn_quckspell->Release(); + ui_spellbook_btn_quckspell = nullptr; + } + if (ui_spellbook_btn_quckspell_click) + { + ui_spellbook_btn_quckspell_click->Release(); + ui_spellbook_btn_quckspell_click = nullptr; + } + + for (uint i = 0; i < 9; ++i) { - pSpellBookPagesTextr[i]->Release(); - pTextures_tabs[i][0]->Release(); - pTextures_tabs[i][1]->Release(); + if (ui_spellbook_school_backgrounds[i]) + { + ui_spellbook_school_backgrounds[i]->Release(); + ui_spellbook_school_backgrounds[i] = nullptr; + } + + if (ui_spellbook_school_tabs[i][0]) + { + ui_spellbook_school_tabs[i][0]->Release(); + ui_spellbook_school_tabs[i][0] = nullptr; + } + if (ui_spellbook_school_tabs[i][1]) + { + ui_spellbook_school_tabs[i][1]->Release(); + ui_spellbook_school_tabs[i][1] = nullptr; + } } + pAudioPlayer->PlaySound(SOUND_openbook, 0, 0, -1, 0, 0, 0, 0); - pIcons_LOD->RemoveTexturesPackFromTextureList(); } + + + +//----- (0041140B) -------------------------------------------------------- +void OnCloseSpellBookPage() +{ + GUIButton *pNextButton; // esi@4 + for ( uint i = 1; i <= 11; i++ ) + { + if (SBPageCSpellsTextureList[i]) + { + SBPageCSpellsTextureList[i]->Release(); + SBPageCSpellsTextureList[i] = nullptr; + } + if (SBPageSSpellsTextureList[i]) + { + SBPageSSpellsTextureList[i]->Release(); + SBPageSSpellsTextureList[i] = nullptr; + } + } + + + pIcons_LOD->SyncLoadedFilesCount(); + if ( pGUIWindow_CurrentMenu->pControlsHead ) + { + do + { + pNextButton = pGUIWindow_CurrentMenu->pControlsHead->pNext; + free(pGUIWindow_CurrentMenu->pControlsHead); + pGUIWindow_CurrentMenu->pControlsHead = pNextButton; + } + while ( pNextButton ); + } + pGUIWindow_CurrentMenu->pControlsHead = 0; + pGUIWindow_CurrentMenu->pControlsTail = 0; + pGUIWindow_CurrentMenu->uNumControls = 0; +} +