diff GUI/UI/Books/JournalBook.cpp @ 2548:87e5590d034b

All Books windows are refactored into respective classes
author a.parshin
date Tue, 12 May 2015 03:24:19 +0200
parents
children 0c67be4ec900
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GUI/UI/Books/JournalBook.cpp	Tue May 12 03:24:19 2015 +0200
@@ -0,0 +1,166 @@
+#include "Engine/Engine.h"
+#include "Engine/LOD.h"
+#include "Engine/Party.h"
+#include "Engine/Timer.h"
+#include "Engine/Awards.h"
+#include "Engine/texts.h"
+#include "Engine/Graphics/IRender.h"
+#include "Engine/Graphics/Viewport.h"
+#include "Engine/Tables/StorylineTextTable.h"
+
+#include "GUI/GUIFont.h"
+#include "GUI/UI/Books/JournalBook.h"
+
+#include "Media/Audio/AudioPlayer.h"
+
+
+
+GUIWindow_JournalBook::GUIWindow_JournalBook() :
+    GUIWindow_Book()
+{
+    this->ptr_1C = (void *)WINDOW_JournalBook; // inherited from GUIWindow::GUIWindow
+    BasicBookInitialization();
+
+// --------------------------------
+// 004304E7 Game_EventLoop --- part
+    pEventTimer->Pause();
+    pAudioPlayer->StopChannels(-1, -1);
+    pBooksButtonOverlay = new GUIWindow_BooksButtonOverlay(0x258u, 0x169u, 0, 0, (int)pBtn_History, 0);
+    bFlashHistoryBook = 0;
+
+// ----------------------------------------------
+// 00411BFC GUIWindow::InitializeBookView -- part
+    char *pString; // eax@12
+    int pTextHeight; // eax@12
+    unsigned int page_count; // esi@12
+    GUIWindow journal_window; // [sp+18h] [bp-54h]@8
+
+    pSpellBookPagesTextr_11 = pIcons_LOD->LoadTexturePtr("sbplayrnot", TEXTURE_16BIT_PALETTE);
+    pTex_book_button1_on = pIcons_LOD->LoadTexturePtr("tab-an-6b", TEXTURE_16BIT_PALETTE);
+    pTex_book_button2_on = pIcons_LOD->LoadTexturePtr("tab-an-7b", TEXTURE_16BIT_PALETTE);
+    pTex_book_button1_off = pIcons_LOD->LoadTexturePtr("tab-an-6a", TEXTURE_16BIT_PALETTE);
+    pTex_book_button2_off = pIcons_LOD->LoadTexturePtr("tab-an-7a", TEXTURE_16BIT_PALETTE);
+
+    pBtn_Book_1 = this->CreateButton(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 1,
+        pTex_book_button1_on->uTextureWidth, pTex_book_button1_on->uTextureHeight, 1, 0,
+        UIMSG_ClickBooksBtn, 11, 0, pGlobalTXT_LocalizationStrings[192], pTex_book_button1_on, 0);
+    pBtn_Book_2 = this->CreateButton(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 38, pTex_book_button2_on->uTextureHeight,
+        pTex_book_button2_on->uTextureHeight, 1, 0, UIMSG_ClickBooksBtn, 10, 0,
+        pGlobalTXT_LocalizationStrings[193], pTex_book_button2_on, 0);
+
+    num_achieved_awards = 0;
+    journal_window.uFrameX = 48;
+    journal_window.uFrameY = 70;
+    journal_window.uFrameWidth = 360;
+    journal_window.uFrameHeight = 264;
+    journal_window.uFrameZ = 407;
+    journal_window.uFrameHeight = (LOBYTE(pAutonoteFont->uFontHeight) - 3) * 264 / LOBYTE(pAutonoteFont->uFontHeight) - 3;
+    journal_window.uFrameW = journal_window.uFrameHeight + 69;
+    memset(&achieved_awards, 0, 4000);
+    memset(Journal_limitation_factor.data(), 0, 100);
+    if (books_primary_item_per_page < 29)
+    {
+        for (int i = books_primary_item_per_page; i < books_primary_item_per_page + 29; i++)
+        {
+            if (pParty->PartyTimes.HistoryEventTimes[i] > 0)
+            {
+                if (pStorylineText->StoreLine[i + 1].pText)
+                {
+                    pString = BuildDialogueString(pStorylineText->StoreLine[i + 1].pText, uActiveCharacter - 1, 0, 0, 0, &pParty->PartyTimes.HistoryEventTimes[i]);
+                    pTextHeight = pAutonoteFont->CalcTextHeight(pString, &journal_window, 1, 0);
+                    page_count = ((pTextHeight - (pAutonoteFont->uFontHeight - 3)) / (signed int)journal_window.uFrameHeight) + 1;
+                    memset32((char *)&achieved_awards[num_achieved_awards], i + 1, page_count);
+                    for (uint j = 0; j <= page_count - 1; ++j)
+                        Journal_limitation_factor[num_achieved_awards++] = j;
+                }
+            }
+        }
+    }
+    full_num_items_in_book = num_achieved_awards;
+    num_achieved_awards = 0;
+}
+
+
+
+void GUIWindow_JournalBook::Update()
+{
+// -----------------------------------
+// 004156F0 GUI_UpdateWindows --- part
+// {
+//     BookUI_Draw((WindowType)(int)ptr_1C);
+// }
+
+// ----- (00413CC6) --------------------------------------------------------
+// void BookUI_Draw(WindowType book) --- part
+// {
+    pRenderer->DrawTextureIndexed(471, 445, pIcons_LOD->GetTexture(uExitCancelTextureId));
+//     BookUI_Journal_Draw();
+
+// ----- (00412E85) --------------------------------------------------------
+// void BookUI_Journal_Draw()
+// {
+    char *pDialogueString; // eax@21
+    char* pStringOnPage; // eax@22
+    GUIWindow journal_window; // [sp+8h] [bp-54h]@10
+
+    pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pSpellBookPagesTextr_11);
+    if (BtnUp_flag || !books_primary_item_per_page)
+        pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 407, pViewport->uViewportTL_Y + 2, pTex_book_button1_off);
+    else
+        pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 1, pTex_book_button1_on);
+
+    if (BtnDown_flag || books_primary_item_per_page + num_achieved_awards >= full_num_items_in_book)
+        pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 407, pViewport->uViewportTL_Y + 38, pTex_book_button2_off);
+    else
+        pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 38, pTex_book_button2_on);
+
+    if (!Journal_limitation_factor[books_primary_item_per_page])//for title
+    {
+        journal_window.uFrameWidth = game_viewport_width;
+        journal_window.uFrameX = game_viewport_x;
+        journal_window.uFrameY = game_viewport_y;
+        journal_window.uFrameHeight = game_viewport_height;
+        journal_window.uFrameZ = game_viewport_z;
+        journal_window.uFrameW = game_viewport_w;
+        if (pStorylineText->StoreLine[achieved_awards[books_primary_item_per_page]].pPageTitle)
+            journal_window.DrawTitleText(pBook2Font, 0, 22, ui_book_journal_title_color, pStorylineText->StoreLine[achieved_awards[books_primary_item_per_page]].pPageTitle, 3);
+    }
+
+    //for other text
+    journal_window.uFrameX = 48;
+    journal_window.uFrameY = 70;
+    journal_window.uFrameWidth = 360;
+    journal_window.uFrameHeight = 264;
+    journal_window.uFrameZ = 407;
+    journal_window.uFrameW = journal_window.uFrameHeight + 69;
+    if (BtnDown_flag && books_primary_item_per_page + num_achieved_awards < full_num_items_in_book)//Press bookmark next page
+    {
+        pAudioPlayer->PlaySound(SOUND_openbook, 0, 0, -1, 0, 0, 0, 0);
+        books_primary_item_per_page += num_achieved_awards;
+        books_num_items_per_page[books_page_number++] = num_achieved_awards;
+    }
+    if (BtnUp_flag && books_page_number)//Press bookmark previous page
+    {
+        pAudioPlayer->PlaySound(SOUND_openbook, 0, 0, -1, 0, 0, 0, 0);
+        --books_page_number;
+        books_primary_item_per_page -= (unsigned __int8)books_num_items_per_page[books_page_number];
+    }
+    if (!num_achieved_awards || books_primary_item_per_page < 1)
+    {
+        books_primary_item_per_page = 0;
+        books_page_number = 0;
+    }
+    BtnDown_flag = 0;
+    BtnUp_flag = 0;
+    num_achieved_awards = 0;
+    if (achieved_awards[books_primary_item_per_page])
+    {
+        int index = ((int)achieved_awards[books_primary_item_per_page] - 1);
+        pDialogueString = BuildDialogueString(pStorylineText->StoreLine[achieved_awards[books_primary_item_per_page]].pText, uActiveCharacter - 1,
+            0, 0, 0, &pParty->PartyTimes.HistoryEventTimes[index]);
+        pStringOnPage = pAutonoteFont->GetPageTop(pDialogueString, &journal_window, 1, (unsigned __int8)Journal_limitation_factor[books_primary_item_per_page]);
+        journal_window.DrawText(pAutonoteFont, 1, 0, ui_book_journal_text_color, pStringOnPage, 0,
+            journal_window.uFrameY + journal_window.uFrameHeight, ui_book_journal_text_shadow);
+        ++num_achieved_awards;
+    }
+}
\ No newline at end of file