1 /************************************************************************************
2
3 AstroMenace
4 Hardcore 3D space scroll-shooter with spaceship upgrade possibilities.
5 Copyright (c) 2006-2019 Mikhail Kurinnoi, Viewizard
6
7
8 AstroMenace is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 AstroMenace is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with AstroMenace. If not, see <https://www.gnu.org/licenses/>.
20
21
22 Website: https://viewizard.com/
23 Project: https://github.com/viewizard/astromenace
24 E-mail: viewizard@viewizard.com
25
26 *************************************************************************************/
27
28 // TODO translate comments
29
30 #include "../core/core.h"
31 #include "../assets/audio.h"
32 #include "../assets/texture.h"
33 #include "../ui/cursor.h"
34 #include "../game.h" // FIXME "game.h" should be replaced by individual headers
35
36 // NOTE switch to nested namespace definition (namespace A::B::C { ... }) (since C++17)
37 namespace viewizard {
38 namespace astromenace {
39
40 extern bool DragWeapon;
41
42
43
44 // для управление через клавиатуру
45 int CurrentActiveMenuElement = 0;
46 int CurrentKeyboardSelectMenuElement = 0;
47
48
49
50
51 // для кнопок, чтобы проигрывать наведение
52 // последние координаты кнопки на которую наводились
53 int NeedPlayOnButtonSoundX = 0;
54 int NeedPlayOnButtonSoundY = 0;
55
56
57
58 //------------------------------------------------------------------------------------
59 // прорисовка кнопки 384
60 //------------------------------------------------------------------------------------
DrawButton384(int X,int Y,const std::u32string & Text,float Transp,float & ButTransp,float & Update)61 bool DrawButton384(int X, int Y, const std::u32string &Text, float Transp, float &ButTransp, float &Update)
62 {
63 sRECT SrcRect, DstRect;
64 bool ON = false;
65 float IntTransp = Transp;
66
67
68 // работаем с клавиатурой
69 if ((Transp >= 0.99f) &&
70 !isDialogBoxDrawing() &&
71 GetShowGameCursor())
72 CurrentActiveMenuElement++;
73
74 bool InFocusByKeyboard = false;
75 if ((CurrentKeyboardSelectMenuElement > 0) &&
76 (CurrentKeyboardSelectMenuElement == CurrentActiveMenuElement))
77 InFocusByKeyboard = true;
78
79
80
81 DstRect(X+2,Y+1,X+384,Y+63);
82 if ((vw_MouseOverRect(DstRect) || InFocusByKeyboard) &&
83 !isDialogBoxDrawing() &&
84 GetShowGameCursor()) {
85 // если тухнем или появляемся - не жать
86 ON = true;
87 if (Transp == 1.0f)
88 SetCursorStatus(eCursorStatus::ActionAllowed);
89
90 if (ButTransp == 1.0f) {
91 PlayMenuSFX(eMenuSFX::OverBigButton, 1.0f);
92 Update = vw_GetTimeThread(0);
93 ButTransp = 0.99f;
94 }
95
96 ButTransp -= 3.0f*(vw_GetTimeThread(0) - Update);
97 if (ButTransp < 0.60f)
98 ButTransp = 0.60f;
99 Update = vw_GetTimeThread(0);
100
101 IntTransp = ButTransp * Transp;
102 } else {
103 if (ButTransp < 1.0f) {
104 ButTransp += 3.0f*(vw_GetTimeThread(0) - Update);
105 if (ButTransp > 1.0f)
106 ButTransp =1.0f;
107 Update = vw_GetTimeThread(0);
108 }
109
110 IntTransp = ButTransp * Transp;
111 }
112
113
114
115 // размер задней тени
116 SrcRect(2,2,512-2,96-2 );
117 // рисуем тень
118 DstRect(X-64+2,Y-17+2,X-64+512-2,Y-17+96-2);
119 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button384_back.tga"), true, IntTransp);
120
121 SrcRect(0,0,384,64 );
122 // рисуем кнопку
123 DstRect(X,Y,X+384,Y+64);
124 if (!ON)
125 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button384_out.tga"), true, Transp);
126 else
127 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button384_in.tga"), true, Transp);
128
129
130
131 // получаем длину текста
132 int Size = vw_TextWidthUTF32(Text);
133
134 // если текст сильно большой - сжимаем буквы, чтобы не вылазило за пределы кнопки
135 float WScale = 0;
136 if (Size > 310) {
137 Size = 310;
138 WScale = -310;
139 }
140
141 // находим смещение текста
142 int SizeI = X + (SrcRect.right-SrcRect.left-Size)/2;
143
144 // рисуем текст
145 if (!ON)
146 vw_DrawTextUTF32(SizeI, Y+21, WScale, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, (0.7f*Transp)/2.0f, Text);
147 else
148 vw_DrawTextUTF32(SizeI, Y+21, WScale, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, Transp, Text);
149
150
151
152 if ((GetCursorStatus() == eCursorStatus::ActionAllowed) &&
153 (vw_GetMouseLeftClick(true) ||
154 (InFocusByKeyboard && (vw_GetKeyStatus(SDLK_KP_ENTER) || vw_GetKeyStatus(SDLK_RETURN))))) {
155 PlayMenuSFX(eMenuSFX::Click, 1.0f);
156 if (InFocusByKeyboard) {
157 vw_SetKeyStatus(SDLK_KP_ENTER, false);
158 vw_SetKeyStatus(SDLK_RETURN, false);
159 }
160 return true;
161 }
162
163 return false;
164 }
165
166
167
168
169
170
171
172
173
174
175 //------------------------------------------------------------------------------------
176 // прорисовка кнопки - 256
177 //------------------------------------------------------------------------------------
DrawButton256(int X,int Y,const std::u32string & Text,float Transp,float & ButTransp,float & Update,bool Off)178 bool DrawButton256(int X, int Y, const std::u32string &Text, float Transp, float &ButTransp, float &Update, bool Off)
179 {
180 sRECT SrcRect, DstRect;
181
182
183 if (Off || DragWeapon) {
184
185 SrcRect(2,2,512-2,96-2 );
186 DstRect(X-125+2,Y-16+2,X-125+512-2,Y-16+96-2);
187 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button256_back.tga"), true, Transp);
188
189 SrcRect(0,0,256,64 );
190 DstRect(X,Y,X+256,Y+64);
191 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button256_off.tga"), true, Transp);
192
193
194 int Size = vw_TextWidthUTF32(Text);
195 int SizeI = DstRect.left + (SrcRect.right-SrcRect.left-Size)/2;
196 vw_DrawTextUTF32(SizeI, Y+21, 0, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, (0.7f*Transp)/2.0f, Text);
197
198 DstRect(X+2,Y+1,X+256,Y+63);
199 if (vw_MouseOverRect(DstRect) && !isDialogBoxDrawing()) {
200 if (Transp==1.0f && !DragWeapon) {
201 SetCursorStatus(eCursorStatus::ActionProhibited);
202 if (vw_GetMouseLeftClick(true))
203 PlayMenuSFX(eMenuSFX::CanNotClick, 1.0f);
204 }
205 }
206
207 return false;
208 }
209
210
211
212 bool ON = false;
213 float IntTransp = Transp;
214
215
216 // работаем с клавиатурой
217 if ((Transp >= 0.99f) &&
218 !isDialogBoxDrawing() &&
219 GetShowGameCursor())
220 CurrentActiveMenuElement++;
221
222 bool InFocusByKeyboard = false;
223 if ((CurrentKeyboardSelectMenuElement > 0) &&
224 (CurrentKeyboardSelectMenuElement == CurrentActiveMenuElement))
225 InFocusByKeyboard = true;
226
227
228
229 DstRect(X+2,Y+1,X+256,Y+63);
230 if ((vw_MouseOverRect(DstRect) || InFocusByKeyboard) &&
231 !isDialogBoxDrawing() &&
232 GetShowGameCursor()) {
233 // если тухнем или появляемся - не жать
234 ON = true;
235 if (Transp == 1.0f)
236 SetCursorStatus(eCursorStatus::ActionAllowed);
237
238 if (ButTransp == 1.0f) {
239 PlayMenuSFX(eMenuSFX::OverBigButton, 1.0f);
240 Update = vw_GetTimeThread(0);
241 ButTransp = 0.98f;
242 }
243
244 ButTransp -= 3.0f*(vw_GetTimeThread(0) - Update);
245 if (ButTransp < 0.60f)
246 ButTransp = 0.60f;
247 Update = vw_GetTimeThread(0);
248
249 IntTransp = ButTransp * Transp;
250 } else {
251 if (ButTransp < 1.0f) {
252 ButTransp += 3.0f*(vw_GetTimeThread(0) - Update);
253 if (ButTransp > 1.0f)
254 ButTransp =1.0f;
255 Update = vw_GetTimeThread(0);
256 }
257
258 IntTransp = ButTransp * Transp;
259 }
260
261
262
263
264
265
266
267 // размер задней тени
268 SrcRect(2,2,512-2,96-2 );
269 // рисуем тень
270 DstRect(X-125+2,Y-16+2,X-125+512-2,Y-16+96-2);
271 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button256_back.tga"), true, IntTransp);
272
273 SrcRect(0,0,256,64 );
274 // рисуем кнопку
275 DstRect(X,Y,X+256,Y+64);
276 if (!ON)
277 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button256_out.tga"), true, Transp);
278 else
279 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button256_in.tga"), true, Transp);
280
281
282 // получаем длину текста
283 int Size = vw_TextWidthUTF32(Text);
284
285 // если текст сильно большой - сжимаем буквы, чтобы не вылазило за пределы кнопки
286 float WScale = 0;
287 if (Size > 190) {
288 Size = 190;
289 WScale = -190;
290 }
291
292 // находим смещение текста
293 int SizeI = DstRect.left + (SrcRect.right-SrcRect.left-Size)/2;
294 // рисуем текст
295 if (!ON)
296 vw_DrawTextUTF32(SizeI, Y+21, WScale, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, (0.7f*Transp)/2.0f, Text);
297 else
298 vw_DrawTextUTF32(SizeI, Y+21, WScale, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, Transp, Text);
299
300 if ((GetCursorStatus() == eCursorStatus::ActionAllowed) &&
301 (vw_GetMouseLeftClick(true) ||
302 (InFocusByKeyboard && (vw_GetKeyStatus(SDLK_KP_ENTER) || vw_GetKeyStatus(SDLK_RETURN))))) {
303 PlayMenuSFX(eMenuSFX::Click, 1.0f);
304 if (InFocusByKeyboard) {
305 vw_SetKeyStatus(SDLK_KP_ENTER, false);
306 vw_SetKeyStatus(SDLK_RETURN, false);
307 }
308 return true;
309 }
310
311 return false;
312 }
313
314
315
316
317
318 //------------------------------------------------------------------------------------
319 // прорисовка кнопки - 200
320 //------------------------------------------------------------------------------------
DrawButton200_2(int X,int Y,const std::u32string & Text,float Transp,bool Off)321 bool DrawButton200_2(int X, int Y, const std::u32string &Text, float Transp, bool Off)
322 {
323 sRECT SrcRect, DstRect, MouseRect;
324 SrcRect(2,2,230-2,64-2);
325 DstRect(X-14+2,Y-14+2,X+230-14-2,Y+64-14-2);
326 MouseRect(X,Y,X+204,Y+35);
327
328 // получаем длину текста
329 int Size = vw_TextWidthUTF32(Text);
330
331 // если текст сильно большой - сжимаем буквы, чтобы не вылазило за пределы кнопки
332 float WScale = 0;
333 if (Size > 176) {
334 Size = 176;
335 WScale = -176;
336 }
337 int SizeI = DstRect.left + (SrcRect.right-SrcRect.left-Size)/2;
338
339
340 if (Off || DragWeapon) {
341 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button_dialog200_off.tga"), true, Transp);
342
343 vw_DrawTextUTF32(SizeI, Y+6, WScale, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, (0.7f*Transp)/2.0f, Text);
344
345 DstRect(X,Y,X+204,Y+35);
346 if (vw_MouseOverRect(DstRect) && !isDialogBoxDrawing()) {
347 if (Transp==1.0f && !DragWeapon) {
348 SetCursorStatus(eCursorStatus::ActionProhibited);
349 if (vw_GetMouseLeftClick(true))
350 PlayMenuSFX(eMenuSFX::CanNotClick, 1.0f);
351 }
352 }
353
354 return false;
355 }
356
357
358 bool ON = false;
359
360
361 // работаем с клавиатурой
362 if ((Transp >= 0.99f) &&
363 !isDialogBoxDrawing() &&
364 GetShowGameCursor())
365 CurrentActiveMenuElement++;
366
367 bool InFocusByKeyboard = false;
368 if ((CurrentKeyboardSelectMenuElement > 0) &&
369 (CurrentKeyboardSelectMenuElement == CurrentActiveMenuElement))
370 InFocusByKeyboard = true;
371
372
373 if ((vw_MouseOverRect(MouseRect) || InFocusByKeyboard) &&
374 !isDialogBoxDrawing() &&
375 GetShowGameCursor()) {
376 // если тухнем или появляемся - не жать
377 ON = true;
378 if (Transp == 1.0f)
379 SetCursorStatus(eCursorStatus::ActionAllowed);
380
381 if (NeedPlayOnButtonSoundX != X || NeedPlayOnButtonSoundY != Y) {
382 PlayMenuSFX(eMenuSFX::OverSmallButton, 1.0f);
383 NeedPlayOnButtonSoundX = X;
384 NeedPlayOnButtonSoundY = Y;
385 }
386 } else {
387 if (NeedPlayOnButtonSoundX == X && NeedPlayOnButtonSoundY == Y) {
388 NeedPlayOnButtonSoundX = 0;
389 NeedPlayOnButtonSoundY = 0;
390 }
391 }
392
393
394 if (!ON)
395 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button_dialog200_out.tga"), true, Transp);
396 else
397 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button_dialog200_in.tga"), true, Transp);
398
399 // рисуем текст
400 if (!ON)
401 vw_DrawTextUTF32(SizeI, Y+6, WScale, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, (0.7f*Transp)/2.0f, Text);
402 else
403 vw_DrawTextUTF32(SizeI, Y+6, WScale, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, Transp, Text);
404
405 if ((GetCursorStatus() == eCursorStatus::ActionAllowed) &&
406 (vw_GetMouseLeftClick(true) ||
407 (InFocusByKeyboard && (vw_GetKeyStatus(SDLK_KP_ENTER) || vw_GetKeyStatus(SDLK_RETURN))))) {
408 PlayMenuSFX(eMenuSFX::Click, 1.0f);
409 if (InFocusByKeyboard) {
410 vw_SetKeyStatus(SDLK_KP_ENTER, false);
411 vw_SetKeyStatus(SDLK_RETURN, false);
412 }
413 return true;
414 }
415
416 return false;
417 }
418
419
420 //------------------------------------------------------------------------------------
421 // прорисовка кнопки - 128
422 //------------------------------------------------------------------------------------
DrawButton128_2(int X,int Y,const std::u32string & Text,float Transp,bool Off,bool SoundClick)423 bool DrawButton128_2(int X, int Y, const std::u32string &Text, float Transp, bool Off, bool SoundClick)
424 {
425 sRECT SrcRect, DstRect, MouseRect;
426 SrcRect(2,2,158-2,64-2);
427 DstRect(X-14+2,Y-14+2,X+158-14-2,Y+64-14-2);
428 MouseRect(X,Y,X+132,Y+35);
429
430 // получаем длину текста
431 int Size = vw_TextWidthUTF32(Text);
432
433 // если текст сильно большой - сжимаем буквы, чтобы не вылазило за пределы кнопки
434 float WScale = 0;
435 if (Size > 108) {
436 Size = 108;
437 WScale = -108;
438 }
439
440 // находим смещение текста
441 int SizeI = DstRect.left + (SrcRect.right-SrcRect.left-Size)/2;
442
443
444 if (Off || DragWeapon) {
445 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button_dialog128_off.tga"), true, Transp);
446
447 vw_DrawTextUTF32(SizeI, Y+6, WScale, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, (0.7f*Transp)/2.0f, Text);
448
449 DstRect(X,Y,X+132,Y+35);
450 if (vw_MouseOverRect(DstRect) && !isDialogBoxDrawing()) {
451 if (Transp==1.0f && !DragWeapon) {
452 SetCursorStatus(eCursorStatus::ActionProhibited);
453 if (vw_GetMouseLeftClick(true))
454 PlayMenuSFX(eMenuSFX::CanNotClick, 1.0f);
455 }
456 }
457
458 return false;
459 }
460
461
462
463 bool ON = false;
464
465
466 // работаем с клавиатурой
467 if ((Transp >= 0.99f) &&
468 !isDialogBoxDrawing() &&
469 GetShowGameCursor())
470 CurrentActiveMenuElement++;
471
472 bool InFocusByKeyboard = false;
473 if ((CurrentKeyboardSelectMenuElement > 0) &&
474 (CurrentKeyboardSelectMenuElement == CurrentActiveMenuElement))
475 InFocusByKeyboard = true;
476
477
478 if ((vw_MouseOverRect(MouseRect) || InFocusByKeyboard) &&
479 !isDialogBoxDrawing() &&
480 GetShowGameCursor()) {
481 // если тухнем или появляемся - не жать
482 ON = true;
483 if (Transp == 1.0f)
484 SetCursorStatus(eCursorStatus::ActionAllowed);
485
486 if (NeedPlayOnButtonSoundX != X || NeedPlayOnButtonSoundY != Y) {
487 PlayMenuSFX(eMenuSFX::OverSmallButton, 1.0f);
488 NeedPlayOnButtonSoundX = X;
489 NeedPlayOnButtonSoundY = Y;
490 }
491 } else {
492 if (NeedPlayOnButtonSoundX == X && NeedPlayOnButtonSoundY == Y) {
493 NeedPlayOnButtonSoundX = 0;
494 NeedPlayOnButtonSoundY = 0;
495 }
496 }
497
498
499 if (!ON)
500 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button_dialog128_out.tga"), true, Transp);
501 else
502 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/button_dialog128_in.tga"), true, Transp);
503
504 // рисуем текст
505 if (!ON)
506 vw_DrawTextUTF32(SizeI, Y+6, WScale, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, (0.7f*Transp)/2.0f, Text);
507 else
508 vw_DrawTextUTF32(SizeI, Y+6, WScale, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, Transp, Text);
509
510 if ((GetCursorStatus() == eCursorStatus::ActionAllowed) &&
511 (vw_GetMouseLeftClick(true) ||
512 (InFocusByKeyboard && (vw_GetKeyStatus(SDLK_KP_ENTER) || vw_GetKeyStatus(SDLK_RETURN))))) {
513 if (SoundClick)
514 PlayMenuSFX(eMenuSFX::Click, 1.0f);
515 if (InFocusByKeyboard) {
516 vw_SetKeyStatus(SDLK_KP_ENTER, false);
517 vw_SetKeyStatus(SDLK_RETURN, false);
518 }
519 return true;
520 }
521
522 return false;
523 }
524
525
526
527
528
529
530
531
532
533
534 //------------------------------------------------------------------------------------
535 // прорисовка чекбокса
536 //------------------------------------------------------------------------------------
DrawCheckBox(int X,int Y,bool & CheckBoxStatus,const std::u32string & Text,float Transp)537 void DrawCheckBox(int X, int Y, bool &CheckBoxStatus, const std::u32string &Text, float Transp)
538 {
539 sRECT SrcRect, DstRect;
540
541 // получаем длину текста
542 int Size = vw_TextWidthUTF32(Text);
543
544 bool ON = false;
545
546
547 // работаем с клавиатурой
548 if ((Transp >= 0.99f) &&
549 !isDialogBoxDrawing() &&
550 GetShowGameCursor())
551 CurrentActiveMenuElement++;
552
553 bool InFocusByKeyboard = false;
554 if ((CurrentKeyboardSelectMenuElement > 0) &&
555 (CurrentKeyboardSelectMenuElement == CurrentActiveMenuElement))
556 InFocusByKeyboard = true;
557
558
559 // 20 - расстояние между текстом
560 DstRect(X+4,Y+4,X+40+20+Size,Y+40-4);
561 if ((vw_MouseOverRect(DstRect) || InFocusByKeyboard) &&
562 !isDialogBoxDrawing() &&
563 GetShowGameCursor()) {
564 // если тухнем или появляемся - не жать
565 ON = true;
566 if (Transp == 1.0f)
567 SetCursorStatus(eCursorStatus::ActionAllowed);
568 }
569
570
571
572 // рисуем
573 SrcRect(0,0,40,38);
574 DstRect(X,Y,X+40,Y+38);
575 if (!ON || DragWeapon)
576 vw_DrawTextUTF32(X+40+20, Y+8, 0, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::white}, Transp, Text);
577 else
578 vw_DrawTextUTF32(X+40+20, Y+8, 0, 0, 1.0f, sRGBCOLOR{eRGBCOLOR::orange}, Transp, Text);
579
580 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/checkbox_main.tga"), true, Transp);
581 if (CheckBoxStatus)
582 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/checkbox_in.tga"), true, Transp);
583
584
585 if ((GetCursorStatus() == eCursorStatus::ActionAllowed) && !DragWeapon &&
586 (vw_GetMouseLeftClick(true) ||
587 (InFocusByKeyboard && (vw_GetKeyStatus(SDLK_KP_ENTER) || vw_GetKeyStatus(SDLK_RETURN))))) {
588 CheckBoxStatus = !CheckBoxStatus;
589 PlayMenuSFX(eMenuSFX::Click, 1.0f);
590 if (InFocusByKeyboard) {
591 vw_SetKeyStatus(SDLK_KP_ENTER, false);
592 vw_SetKeyStatus(SDLK_RETURN, false);
593 }
594 }
595 }
596
597
598
599
600
601 //------------------------------------------------------------------------------------
602 // прорисовка кнопки вверх для списков
603 //------------------------------------------------------------------------------------
DrawListUpButton(int X,int Y,float Transp,bool Off)604 bool DrawListUpButton(int X, int Y, float Transp, bool Off)
605 {
606 sRECT SrcRect, DstRect, MouseRect;
607 SrcRect(0,0,32,32);
608 DstRect(X,Y,X+32,Y+32);
609 MouseRect(X,Y,X+32,Y+32);
610
611
612 if (Off || DragWeapon) {
613 DstRect(X+2,Y+2,X+32-2,Y+32-2);
614 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/arrow_list_up.tga"), true, 0.3f*Transp);
615
616 if (vw_MouseOverRect(MouseRect) && !isDialogBoxDrawing()) {
617 if (Transp==1.0f && !DragWeapon) {
618 SetCursorStatus(eCursorStatus::ActionProhibited);
619 if (vw_GetMouseLeftClick(true))
620 PlayMenuSFX(eMenuSFX::CanNotClick, 1.0f);
621 }
622 }
623
624 return false;
625 }
626
627
628
629 bool ON = false;
630
631
632 // работаем с клавиатурой
633 if ((Transp >= 0.99f) &&
634 !isDialogBoxDrawing() &&
635 GetShowGameCursor())
636 CurrentActiveMenuElement++;
637
638 bool InFocusByKeyboard = false;
639 if ((CurrentKeyboardSelectMenuElement > 0) &&
640 (CurrentKeyboardSelectMenuElement == CurrentActiveMenuElement))
641 InFocusByKeyboard = true;
642
643
644 if ((vw_MouseOverRect(MouseRect) || InFocusByKeyboard) &&
645 !isDialogBoxDrawing() &&
646 GetShowGameCursor()) {
647 // если тухнем или появляемся - не жать
648 ON = true;
649 if (Transp == 1.0f)
650 SetCursorStatus(eCursorStatus::ActionAllowed);
651
652 if (NeedPlayOnButtonSoundX != X || NeedPlayOnButtonSoundY != Y) {
653 PlayMenuSFX(eMenuSFX::OverSmallButton, 1.0f);
654 NeedPlayOnButtonSoundX = X;
655 NeedPlayOnButtonSoundY = Y;
656 }
657 } else {
658 if (NeedPlayOnButtonSoundX == X && NeedPlayOnButtonSoundY == Y) {
659 NeedPlayOnButtonSoundX = 0;
660 NeedPlayOnButtonSoundY = 0;
661 }
662 }
663
664
665 if (!ON) {
666 DstRect(X+2,Y+2,X+32-2,Y+32-2);
667 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/arrow_list_up.tga"), true, 0.3f*Transp);
668 } else
669 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/arrow_list_up.tga"), true, Transp);
670
671
672 if ((GetCursorStatus() == eCursorStatus::ActionAllowed) &&
673 (vw_GetMouseLeftClick(true) ||
674 (InFocusByKeyboard && (vw_GetKeyStatus(SDLK_KP_ENTER) || vw_GetKeyStatus(SDLK_RETURN))))) {
675 PlayMenuSFX(eMenuSFX::Click, 1.0f);
676 if (InFocusByKeyboard) {
677 vw_SetKeyStatus(SDLK_KP_ENTER, false);
678 vw_SetKeyStatus(SDLK_RETURN, false);
679 }
680 return true;
681 }
682
683 return false;
684 }
685
686
687
688 //------------------------------------------------------------------------------------
689 // прорисовка кнопки вниз для списков
690 //------------------------------------------------------------------------------------
DrawListDownButton(int X,int Y,float Transp,bool Off)691 bool DrawListDownButton(int X, int Y, float Transp, bool Off)
692 {
693 sRECT SrcRect, DstRect, MouseRect;
694 SrcRect(0,0,32,32);
695 DstRect(X,Y,X+32,Y+32);
696 MouseRect(X,Y,X+32,Y+32);
697
698
699 if (Off || DragWeapon) {
700 DstRect(X+2,Y+2,X+32-2,Y+32-2);
701 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/arrow_list_down.tga"), true, 0.3f*Transp);
702
703 if (vw_MouseOverRect(MouseRect) && !isDialogBoxDrawing()) {
704 if (Transp==1.0f && !DragWeapon) {
705 SetCursorStatus(eCursorStatus::ActionProhibited);
706 if (vw_GetMouseLeftClick(true))
707 PlayMenuSFX(eMenuSFX::CanNotClick, 1.0f);
708 }
709 }
710
711 return false;
712 }
713
714
715
716 bool ON = false;
717
718
719 // работаем с клавиатурой
720 if ((Transp >= 0.99f) &&
721 !isDialogBoxDrawing() &&
722 GetShowGameCursor())
723 CurrentActiveMenuElement++;
724
725 bool InFocusByKeyboard = false;
726 if ((CurrentKeyboardSelectMenuElement > 0) &&
727 (CurrentKeyboardSelectMenuElement == CurrentActiveMenuElement))
728 InFocusByKeyboard = true;
729
730
731 if ((vw_MouseOverRect(MouseRect) || InFocusByKeyboard) &&
732 !isDialogBoxDrawing() &&
733 GetShowGameCursor()) {
734 // если тухнем или появляемся - не жать
735 ON = true;
736 if (Transp == 1.0f)
737 SetCursorStatus(eCursorStatus::ActionAllowed);
738
739 if (NeedPlayOnButtonSoundX != X || NeedPlayOnButtonSoundY != Y) {
740 PlayMenuSFX(eMenuSFX::OverSmallButton, 1.0f);
741 NeedPlayOnButtonSoundX = X;
742 NeedPlayOnButtonSoundY = Y;
743 }
744 } else {
745 if (NeedPlayOnButtonSoundX == X && NeedPlayOnButtonSoundY == Y) {
746 NeedPlayOnButtonSoundX = 0;
747 NeedPlayOnButtonSoundY = 0;
748 }
749 }
750
751
752 if (!ON) {
753 DstRect(X+2,Y+2,X+32-2,Y+32-2);
754 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/arrow_list_down.tga"), true, 0.3f*Transp);
755 } else
756 vw_Draw2D(DstRect, SrcRect, GetPreloadedTextureAsset("menu/arrow_list_down.tga"), true, Transp);
757
758
759 if ((GetCursorStatus() == eCursorStatus::ActionAllowed) &&
760 (vw_GetMouseLeftClick(true) ||
761 (InFocusByKeyboard && (vw_GetKeyStatus(SDLK_KP_ENTER) || vw_GetKeyStatus(SDLK_RETURN))))) {
762 PlayMenuSFX(eMenuSFX::Click, 1.0f);
763 if (InFocusByKeyboard) {
764 vw_SetKeyStatus(SDLK_KP_ENTER, false);
765 vw_SetKeyStatus(SDLK_RETURN, false);
766 }
767 return true;
768 }
769
770 return false;
771 }
772
773 } // astromenace namespace
774 } // viewizard namespace
775