comparison GUI/UI/Books/AutonotesBook.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
comparison
equal deleted inserted replaced
2547:fed97f15d1e1 2548:87e5590d034b
1 #include "Engine/Engine.h"
2 #include "Engine/LOD.h"
3 #include "Engine/Party.h"
4 #include "Engine/Timer.h"
5 #include "Engine/Autonotes.h"
6 #include "Engine/Awards.h"
7 #include "Engine/texts.h"
8 #include "Engine/Graphics/IRender.h"
9 #include "Engine/Graphics/Viewport.h"
10
11 #include "GUI/GUIFont.h"
12 #include "GUI/UI/Books/AutonotesBook.h"
13
14 #include "Media/Audio/AudioPlayer.h"
15
16 GUIWindow_AutonotesBook::GUIWindow_AutonotesBook() :
17 GUIWindow_Book()
18 {
19 this->ptr_1C = (void *)WINDOW_AutonotesBook; // inherited from GUIWindow::GUIWindow
20 BasicBookInitialization();
21
22 // --------------------------------
23 // 004304E7 Game_EventLoop --- part
24 pEventTimer->Pause();
25 pAudioPlayer->StopChannels(-1, -1);
26 pBooksButtonOverlay = new GUIWindow_BooksButtonOverlay(527, 353, 0, 0, (int)pBtn_Autonotes, 0);
27 bFlashAutonotesBook = 0;
28
29 // ----------------------------------------------
30 // 00411BFC GUIWindow::InitializeBookView -- part
31 pTexture_AutonotesBook = pIcons_LOD->LoadTexturePtr("sbautnot", TEXTURE_16BIT_PALETTE);
32 pSpellBookPagesTextr_10 = pIcons_LOD->LoadTexturePtr("divbar", TEXTURE_16BIT_PALETTE);
33 pTex_book_button1_on = pIcons_LOD->LoadTexturePtr("tab-an-6b", TEXTURE_16BIT_PALETTE);
34 pTex_book_button2_on = pIcons_LOD->LoadTexturePtr("tab-an-7b", TEXTURE_16BIT_PALETTE);
35 pTex_book_button1_off = pIcons_LOD->LoadTexturePtr("tab-an-6a", TEXTURE_16BIT_PALETTE);
36 pTex_book_button2_off = pIcons_LOD->LoadTexturePtr("tab-an-7a", TEXTURE_16BIT_PALETTE);
37 pTex_book_button3_on = pIcons_LOD->LoadTexturePtr("tab-an-1b", TEXTURE_16BIT_PALETTE);
38 pTex_book_button3_off = pIcons_LOD->LoadTexturePtr("tab-an-1a", TEXTURE_16BIT_PALETTE);
39 pTex_book_button4_on = pIcons_LOD->LoadTexturePtr("tab-an-2b", TEXTURE_16BIT_PALETTE);
40 pTex_book_button4_off = pIcons_LOD->LoadTexturePtr("tab-an-2a", TEXTURE_16BIT_PALETTE);
41 pTex_book_button5_on = pIcons_LOD->LoadTexturePtr("tab-an-3b", TEXTURE_16BIT_PALETTE);
42 pTex_book_button5_off = pIcons_LOD->LoadTexturePtr("tab-an-3a", TEXTURE_16BIT_PALETTE);
43 pTex_book_button6_on = pIcons_LOD->LoadTexturePtr("tab-an-5b", TEXTURE_16BIT_PALETTE);
44 pTex_book_button6_off = pIcons_LOD->LoadTexturePtr("tab-an-5a", TEXTURE_16BIT_PALETTE);
45 pTex_book_button7_on = pIcons_LOD->LoadTexturePtr("tab-an-4b", TEXTURE_16BIT_PALETTE);
46 pTex_book_button7_off = pIcons_LOD->LoadTexturePtr("tab-an-4a", TEXTURE_16BIT_PALETTE);
47 pTex_book_button8_on = pIcons_LOD->LoadTexturePtr("tab-an-8b", TEXTURE_16BIT_PALETTE);
48 pTex_book_button8_off = pIcons_LOD->LoadTexturePtr("tab-an-8a", TEXTURE_16BIT_PALETTE);
49
50 pBtn_Book_1 = CreateButton(
51 pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 1, 50, 34, 1, 0,
52 UIMSG_ClickBooksBtn, 11, 0, pGlobalTXT_LocalizationStrings[193], pTex_book_button1_on, 0
53 );
54 pBtn_Book_2 = CreateButton(
55 pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 38, 50, 34, 1, 0,
56 UIMSG_ClickBooksBtn, 10, 0, pGlobalTXT_LocalizationStrings[192], pTex_book_button2_on, 0
57 );
58 pBtn_Book_3 = CreateButton(
59 pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 113, 50, 34, 1, 0,
60 UIMSG_ClickBooksBtn, 2, 0, pGlobalTXT_LocalizationStrings[85], pTex_book_button3_on, 0
61 ); // "Potion Notes"
62 pBtn_Book_4 = CreateButton(
63 pViewport->uViewportTL_X + 399, pViewport->uViewportTL_Y + 150, 50, 34, 1, 0,
64 UIMSG_ClickBooksBtn, 3, 0, pGlobalTXT_LocalizationStrings[137], pTex_book_button4_on, 0
65 ); // "Fountain Notes"
66 pBtn_Book_5 = CreateButton(
67 pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 188, 50, 34, 1, 0,
68 UIMSG_ClickBooksBtn, 4, 0, pGlobalTXT_LocalizationStrings[8], pTex_book_button5_on, 0
69 ); // "Obelisk Notes"
70 pBtn_Book_6 = CreateButton(
71 pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 226, 50, 34, 1, 0,
72 UIMSG_ClickBooksBtn, 5, 0, pGlobalTXT_LocalizationStrings[141], pTex_book_button6_on, 0
73 ); // "Seer Notes"
74 pBtn_Autonotes_Misc = CreateButton(
75 pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 264, 50, 34, 1, 0,
76 UIMSG_ClickBooksBtn, 6, 0, pGlobalTXT_LocalizationStrings[123], pTex_book_button7_on, 0
77 ); // "Miscellaneous Notes"
78 pBtn_Autonotes_Instructors = CreateButton(
79 pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 302, 50, 34, 1, 0,
80 UIMSG_ClickBooksBtn, 7, 0, pGlobalTXT_LocalizationStrings[662], pTex_book_button8_on, 0
81 ); // "Instructors"
82
83 int num_achieved_awards = 0;
84 for (uint i = books_primary_item_per_page; i < 196; ++i)
85 {
86 if (_506568_autonote_type == pAutonoteTxt[i].eType)//dword_72371C[2 * v10] )
87 {
88 if (i)
89 {
90 if (_449B57_test_bit(pParty->_autonote_bits, i) && pAutonoteTxt[i].pText)
91 {
92 achieved_awards[num_achieved_awards] = (AwardType)i;
93 ++num_achieved_awards;
94 }
95 }
96 }
97 }
98 full_num_items_in_book = num_achieved_awards;
99 num_achieved_awards = 0;
100 }
101
102
103
104 void GUIWindow_AutonotesBook::Update()
105 {
106 // -----------------------------------
107 // 004156F0 GUI_UpdateWindows --- part
108 // {
109 // BookUI_Draw((WindowType)(int)ptr_1C);
110 // }
111
112 // ----- (00413CC6) --------------------------------------------------------
113 // void BookUI_Draw(WindowType book) --- part
114 // {
115 pRenderer->DrawTextureIndexed(471, 445, pIcons_LOD->GetTexture(uExitCancelTextureId));
116 // BookUI_Autonotes_Draw();
117
118 // ----- (0041338E) --------------------------------------------------------
119 // void BookUI_Autonotes_Draw()
120 // {
121 int pTextHeight; // eax@65
122 bool change_flag; // [sp+10h] [bp-58h]@1
123 GUIWindow autonotes_window; // [sp+14h] [bp-54h]@46
124
125 change_flag = false;
126 pRenderer->DrawTextureIndexed(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pTexture_AutonotesBook);
127 if (BtnUp_flag || !books_primary_item_per_page)
128 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 407, pViewport->uViewportTL_Y + 2, pTex_book_button1_off);
129 else
130 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 1, pTex_book_button1_on);
131
132 if (BtnDown_flag || books_primary_item_per_page + num_achieved_awards >= full_num_items_in_book)
133 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 407, pViewport->uViewportTL_Y + 38, pTex_book_button2_off);
134 else
135 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 38, pTex_book_button2_on);
136
137 if (Book_PageBtn3_flag)//Potions_page_flag
138 {
139 if (_506568_autonote_type == AUTONOTE_POTION_RECEPIE)//press again(повторное нажатие)
140 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 113, pTex_book_button3_on);
141 else//press(нажатие)
142 {
143 change_flag = true;
144 pAudioPlayer->PlaySound(SOUND_StartMainChoice02, 0, 0, -1, 0, 0, 0, 0);
145 _506568_autonote_type = AUTONOTE_POTION_RECEPIE;
146 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 113, pTex_book_button3_on);
147 }
148 }
149 else
150 {
151 if (_506568_autonote_type == AUTONOTE_POTION_RECEPIE)// default(по умолчанию при запуске окна)
152 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 398, pViewport->uViewportTL_Y + 113, pTex_book_button3_on);
153 else//Potions_page not active(вкладка снадобья не активна)
154 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 113, pTex_book_button3_off);
155 }
156
157 if (Book_PageBtn4_flag)//Fontains_page_flag
158 {
159 if (_506568_autonote_type == AUTONOTE_STAT_HINT)
160 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 399, pViewport->uViewportTL_Y + 150, pTex_book_button4_on);
161 else
162 {
163 change_flag = true;
164 pAudioPlayer->PlaySound(SOUND_StartMainChoice02, 0, 0, -1, 0, 0, 0, 0);
165 _506568_autonote_type = AUTONOTE_STAT_HINT;
166 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 399, pViewport->uViewportTL_Y + 150, pTex_book_button4_on);
167 }
168 }
169 else
170 {
171 if (_506568_autonote_type == AUTONOTE_STAT_HINT)
172 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 399, pViewport->uViewportTL_Y + 150, pTex_book_button4_on);
173 else
174 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 150, pTex_book_button4_off);
175 }
176
177 if (Book_PageBtn5_flag)//Autonotes_Obelisks_page_flag
178 {
179 if (_506568_autonote_type == AUTONOTE_OBELISK)
180 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 188, pTex_book_button5_on);
181 else
182 {
183 change_flag = true;
184 pAudioPlayer->PlaySound(SOUND_StartMainChoice02, 0, 0, -1, 0, 0, 0, 0);
185 _506568_autonote_type = AUTONOTE_OBELISK;
186 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 188, pTex_book_button5_on);
187 }
188 }
189 else
190 {
191 if (_506568_autonote_type == AUTONOTE_OBELISK)
192 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 188, pTex_book_button5_on);
193 else
194 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 188, pTex_book_button5_off);
195 }
196
197 if (Book_PageBtn6_flag)//Autonotes_Seer_page_flag
198 {
199 if (_506568_autonote_type == AUTONOTE_SEER)
200 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 226, pTex_book_button6_on);
201 else
202 {
203 change_flag = true;
204 pAudioPlayer->PlaySound(SOUND_StartMainChoice02, 0, 0, -1, 0, 0, 0, 0);
205 _506568_autonote_type = AUTONOTE_SEER;
206 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 226, pTex_book_button6_on);
207 }
208 }
209 else
210 {
211 if (_506568_autonote_type == AUTONOTE_SEER)
212 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 226, pTex_book_button6_on);
213 else
214 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 226, pTex_book_button6_off);
215 }
216
217 if (Autonotes_Misc_page_flag)
218 {
219 if (_506568_autonote_type == AUTONOTE_MISC)
220 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 264, pTex_book_button7_on);
221 else
222 {
223 change_flag = true;
224 pAudioPlayer->PlaySound(SOUND_StartMainChoice02, 0, 0, -1, 0, 0, 0, 0);
225 _506568_autonote_type = AUTONOTE_MISC;
226 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 264, pTex_book_button7_on);
227 }
228 }
229 else
230 {
231 if (_506568_autonote_type == AUTONOTE_MISC)
232 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 264, pTex_book_button7_on);
233 else
234 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 263, pTex_book_button7_off);
235 }
236
237 if (Autonotes_Instructors_page_flag)
238 {
239 if (_506568_autonote_type == AUTONOTE_TEACHER)
240 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 302, pTex_book_button8_on);
241 else
242 {
243 change_flag = true;
244 pAudioPlayer->PlaySound(SOUND_StartMainChoice02, 0, 0, -1, 0, 0, 0, 0);
245 _506568_autonote_type = AUTONOTE_TEACHER;
246 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 302, pTex_book_button8_on);
247 }
248 }
249 else
250 {
251 if (_506568_autonote_type == AUTONOTE_TEACHER)
252 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 397, pViewport->uViewportTL_Y + 302, pTex_book_button8_on);
253 else
254 pRenderer->DrawTextureIndexedAlpha(pViewport->uViewportTL_X + 408, pViewport->uViewportTL_Y + 302, pTex_book_button8_off);
255 }
256
257 //for title
258 autonotes_window.uFrameWidth = game_viewport_width;
259 autonotes_window.uFrameHeight = game_viewport_height;
260 autonotes_window.uFrameX = game_viewport_x;
261 autonotes_window.uFrameY = game_viewport_y;
262 autonotes_window.uFrameZ = game_viewport_z;
263 autonotes_window.uFrameW = game_viewport_w;
264 autonotes_window.DrawTitleText(pBook2Font, 0, 22, ui_book_autonotes_title_color, pGlobalTXT_LocalizationStrings[154], 3); // "Auto notes"
265
266 //for other text
267 autonotes_window.uFrameX = 48;
268 autonotes_window.uFrameY = 70;
269 autonotes_window.uFrameWidth = 360;
270 autonotes_window.uFrameHeight = 264;
271 autonotes_window.uFrameZ = 407;
272 autonotes_window.uFrameW = 333;
273 if (change_flag)//change bookmark(смена закладки)
274 {
275 full_num_items_in_book = 0;
276 books_primary_item_per_page = 0;
277 books_page_number = 0;
278 num_achieved_awards = 0;
279 for (uint i = 1; i <= 195; ++i)
280 {
281 if (pAutonoteTxt[i].eType == _506568_autonote_type)
282 {
283 if ((unsigned __int16)_449B57_test_bit(pParty->_autonote_bits, i) && (char *)pAutonoteTxt[i].pText)
284 achieved_awards[num_achieved_awards++] = (AwardType)i;
285 }
286 }
287 full_num_items_in_book = num_achieved_awards;
288 }
289 else//not change bookmark(не меняется закладка)
290 {
291 if (BtnDown_flag)// press Down bookmark(нажатие закладки пролистать дальше)
292 {
293 if (num_achieved_awards + books_primary_item_per_page < full_num_items_in_book)
294 {
295 books_num_items_per_page[books_page_number++] = num_achieved_awards;
296 books_primary_item_per_page = num_achieved_awards + books_primary_item_per_page;
297 pAudioPlayer->PlaySound(SOUND_openbook, 0, 0, -1, 0, 0, 0, 0);
298 }
299 }
300 if (BtnUp_flag && books_page_number)// press Up bookmark(нажатие закладки пролистать назад)
301 {
302 --books_page_number;
303 books_primary_item_per_page -= (unsigned __int8)books_num_items_per_page[books_page_number];
304 pAudioPlayer->PlaySound(SOUND_openbook, 0, 0, -1, 0, 0, 0, 0);
305 }
306 if (!num_achieved_awards || !books_primary_item_per_page)//количество записей 0 или номер первой страницы 0
307 {
308 books_primary_item_per_page = 0;
309 books_page_number = 0;
310 }
311 }
312 BtnUp_flag = 0;
313 BtnDown_flag = 0;
314 Book_PageBtn3_flag = 0;//Potions_page_flag
315 Book_PageBtn4_flag = 0;//Fontains_page_flag
316 Book_PageBtn5_flag = 0;//Autonotes_Obelisks_page_flag
317 Book_PageBtn6_flag = 0;//Autonotes_Seer_page_flag
318 Autonotes_Misc_page_flag = 0;
319 Autonotes_Instructors_page_flag = 0;
320 num_achieved_awards = 0;
321 for (uint i = books_primary_item_per_page; i < full_num_items_in_book; ++i)
322 {
323 ++num_achieved_awards;
324 autonotes_window.DrawText(pAutonoteFont, 1, 0, ui_book_autonotes_text_color, pAutonoteTxt[achieved_awards[i]].pText, 0, 0, 0);
325 pTextHeight = pAutonoteFont->CalcTextHeight(pAutonoteTxt[achieved_awards[i]].pText, &autonotes_window, 1, 0);
326 if ((signed int)(autonotes_window.uFrameY + pTextHeight) > (signed int)autonotes_window.uFrameHeight)
327 break;
328 pRenderer->DrawTextureIndexedAlpha(100, (autonotes_window.uFrameY + pTextHeight) + 12, pSpellBookPagesTextr_10);
329 autonotes_window.uFrameY = (autonotes_window.uFrameY + pTextHeight) + 24;
330 }
331 }