-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEda_Menu_Game.cpp
637 lines (542 loc) · 26.8 KB
/
Eda_Menu_Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/*
* File: Eda_Menu_Game.cpp
* Author: r2d2
*
* Created on January 22, 2017, 3:53 AM
*/
#include "Eda_Menu_Game.h"
#include "Eda_Button.h"
#include "Hanabi_Board.h"
#include "setting_management.h"
#include "Eda_Menu_Settings.h"
#include "Eda_Menu_Network.h"
#include <string>
#include <iostream>
#include <allegro5/allegro_color.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
Eda_Menu_Game::Eda_Menu_Game(std::string theme)
{
//give clue could be a Button and not a pointer and construct during call but I rather everything be the same in this menu
give_clue = new Eda_Button(0.5, 0.75, 0.281, 0.08, CLUE_BUT_DIR "give_clue.png", CLUE_BUT_DIR "give_clue_hover.png", NULL, EDA_BUTTON_GIVE_CLUE_PRESSED);
discard_card = new Eda_Button(0.85, 0.9, 0.045 * 3.75, 0.08, CLUE_BUT_DIR "discard_card.png", CLUE_BUT_DIR "discard_card_hover.png", NULL, EDA_BUTTON_DISCARD_CARD_PRESSED);
play_card = new Eda_Button(0.15, 0.9, 0.045 * 3.75, 0.08, CLUE_BUT_DIR "play_card.png", CLUE_BUT_DIR "play_card_hover.png", NULL, EDA_BUTTON_PLAY_CARD_PRESSED);
graveyard_toggle = new Eda_Button(0.85, 0.78, 0.07, 0.07 * 16.0/9.0, CLUE_BUT_DIR "graveyard.png", CLUE_BUT_DIR "graveyard_hover.png", NULL, NO_EVENT);
textbox_status = new Eda_Textbox_Status(0.86,0.5, 0.25, 0.30,
COMMON_FILE_PATH"/text_box_status.png",NULL,NULL,NO_EVENT, 20);
this->add_message(">Connection est.");
hidden_graveyard = true;
give_clue->hide();
discard_card->hide();
play_card->hide();
color_buttons[0] = new Eda_Button(0.410, 0.575, 0.045, 0.08, CLUE_BUT_DIR "Button White.png", CLUE_BUT_DIR "hover.png", CLUE_BUT_DIR "selection.png", EDA_BUTTON_WHITE_PRESSED);
color_buttons[1] = new Eda_Button(0.455, 0.575, 0.045, 0.08, CLUE_BUT_DIR "Button Blue.png", CLUE_BUT_DIR "hover.png", CLUE_BUT_DIR "selection.png", EDA_BUTTON_BLUE_PRESSED);
color_buttons[2] = new Eda_Button(0.500, 0.575, 0.045, 0.08, CLUE_BUT_DIR "Button Green.png", CLUE_BUT_DIR "hover.png", CLUE_BUT_DIR "selection.png", EDA_BUTTON_GREEN_PRESSED);
color_buttons[3] = new Eda_Button(0.545, 0.575, 0.045, 0.08, CLUE_BUT_DIR "Button Yellow.png", CLUE_BUT_DIR "hover.png", CLUE_BUT_DIR "selection.png", EDA_BUTTON_YELLOW_PRESSED);
color_buttons[4] = new Eda_Button(0.590, 0.575, 0.045, 0.08, CLUE_BUT_DIR "Button Red.png", CLUE_BUT_DIR "hover.png", CLUE_BUT_DIR "selection.png", EDA_BUTTON_RED_PRESSED);
number_buttons[0] = new Eda_Button(0.410, 0.655, 0.045, 0.08, CLUE_BUT_DIR "Number1.png", CLUE_BUT_DIR "hover.png", CLUE_BUT_DIR "selection.png", EDA_BUTTON_ONE_PRESSED);
number_buttons[1] = new Eda_Button(0.455, 0.655, 0.045, 0.08, CLUE_BUT_DIR "Number2.png", CLUE_BUT_DIR "hover.png", CLUE_BUT_DIR "selection.png", EDA_BUTTON_TWO_PRESSED);
number_buttons[2] = new Eda_Button(0.500, 0.655, 0.045, 0.08, CLUE_BUT_DIR "Number3.png", CLUE_BUT_DIR "hover.png", CLUE_BUT_DIR "selection.png", EDA_BUTTON_THREE_PRESSED);
number_buttons[3] = new Eda_Button(0.545, 0.655, 0.045, 0.08, CLUE_BUT_DIR "Number4.png", CLUE_BUT_DIR "hover.png", CLUE_BUT_DIR "selection.png", EDA_BUTTON_FOUR_PRESSED);
number_buttons[4] = new Eda_Button(0.590, 0.655, 0.045, 0.08, CLUE_BUT_DIR "Number5.png", CLUE_BUT_DIR "hover.png", CLUE_BUT_DIR "selection.png", EDA_BUTTON_FIVE_PRESSED);
my_cards_buttons[0] = new Eda_Button(0.325, 0.9, 0.063, 0.168, ("Hanabi Themes/" + theme + "/Deck/back.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_hover.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_selected.png").c_str(), EDA_BUTTON_GIVE_CARD_ONE);
my_cards_buttons[1] = new Eda_Button(0.395, 0.9, 0.063, 0.168, ("Hanabi Themes/" + theme + "/Deck/back.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_hover.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_selected.png").c_str(), EDA_BUTTON_GIVE_CARD_TWO);
my_cards_buttons[2] = new Eda_Button(0.465, 0.9, 0.063, 0.168, ("Hanabi Themes/" + theme + "/Deck/back.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_hover.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_selected.png").c_str(), EDA_BUTTON_GIVE_CARD_THREE);
my_cards_buttons[3] = new Eda_Button(0.535, 0.9, 0.063, 0.168, ("Hanabi Themes/" + theme + "/Deck/back.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_hover.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_selected.png").c_str(), EDA_BUTTON_GIVE_CARD_FOUR);
my_cards_buttons[4] = new Eda_Button(0.605, 0.9, 0.063, 0.168, ("Hanabi Themes/" + theme + "/Deck/back.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_hover.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_selected.png").c_str(), EDA_BUTTON_GIVE_CARD_FIVE);
my_cards_buttons[5] = new Eda_Button(0.675, 0.9, 0.063, 0.168, ("Hanabi Themes/" + theme + "/Deck/back.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_hover.png").c_str(), ("Hanabi Themes/" + theme + "/Deck/Card_selected.png").c_str(), EDA_BUTTON_GIVE_CARD_SIX);
}
Eda_Menu_Game::Eda_Menu_Game(const Eda_Menu_Game& orig) {
}
Eda_Menu_Game::~Eda_Menu_Game()
{
for(int i = 0 ; i < 5 ; i++)
{
delete color_buttons[i];
delete number_buttons[i];
}
delete give_clue;
delete discard_card;
delete play_card;
delete textbox_status;
}
void Eda_Menu_Game::add_message(std::string message)
{
textbox_status->add_message(message);
}
void Eda_Menu_Game::draw(ALLEGRO_DISPLAY *display, Hanabi_Skin *theme, Hanabi_Board *game_board, bool mem_help)
{
static int first_call = 0;
#warning "Fix esta villa"
if(!first_call)
{
textbox_status->load_mono_font(display,MONO_FONT_PATH);
first_call++;
}
al_draw_scaled_bitmap(theme->game_mat,
0.0, 0.0, al_get_bitmap_width(theme->game_mat), al_get_bitmap_height(theme->game_mat),
0.0, 0.0, al_get_display_width(display), al_get_display_height(display), //x , y cord to draw and width and height to draw
0); //flags
for(int i = 0 ; i < 5 ; i++)
{
color_buttons[i]->draw(display);
number_buttons[i]->draw(display);
}
Hanabi_Card empty_card;
for(int i = 0; i <6 ; i++)
{
if( game_board->my_cards[i].playing_card == empty_card)
my_cards_buttons[i]->hide();
else
my_cards_buttons[i]->show();
}
for(int i = 0 ; i < 6 ; i++)
my_cards_buttons[i]->draw(display);
give_clue->draw(display);
discard_card->draw(display);
play_card->draw(display);
graveyard_toggle->draw(display);
draw_clue_tokens(display, theme, game_board,
0.1, 0.1,
0.045, 0.08 );
draw_lightning_tokens(display, theme, game_board,
0.2, 0.1,
0.045, 0.08 );
draw_cards(display,theme, //DRAW OTHER PLAYERS CARDS
0.5, 0.1,
0.063, 0.168, 0.005,
6 , game_board->otherplayers_hand);
draw_cards(display,theme, //DRAW CENTRAL_CARDS
0.5, 0.4,
0.063, 0.168, 0.02,
5 , game_board->central_cards);
//0.0495, 0.132);
//0.045, 0.12);
draw_deck(display, theme, game_board,
0.2, 0.6,
0.065, 0.190);
if(!hidden_graveyard)
draw_graveyard(display,theme,
0.78,0.2,
0.063, 0.168,game_board);
#warning "Cambiar el uso de other_player_name al de game_data hay que cambiar la funcion draw para que reciba game_data"
draw_player_box_name(display, game_board->other_player_name.c_str(), 0.5, 0.25, 0.2, 0.025 );
//draw_player_box_name(display, "gonza_puto", 0.5, 1-0.25, 0.2, 0.025);
for (int i=0; i<HANABI_HAND_SIZE; i++)
if (game_board->my_cards[i].color_hint == true && game_board->my_cards[i].color_time_hint >= 0)
{
draw_clue(display, game_board, game_board->my_cards[i].playing_card.get_suit());//draw the color hint
if (mem_help==0)
{
game_board->my_cards[i].color_time_hint--;
if(game_board->my_cards[i].color_time_hint == 0)
game_board->my_cards[i].color_hint == false;
//std::cout<<"mem help "<<mem_help<<std::endl;
}
}
for (int i=0; i<HANABI_HAND_SIZE; i++)
if(game_board->my_cards[i].num_hint == true && game_board->my_cards[i].number_time_hint>=0)
{
draw_clue(display, game_board, game_board->my_cards[i].playing_card.get_value());//draw the number hint
if (mem_help==0)
game_board->my_cards[i].number_time_hint--;
if(game_board->my_cards[i].number_time_hint == 0)
game_board->my_cards[i].num_hint == false;
}
//:draw_clue(ALLEGRO_DISPLAY *display, Hanabi_Skin *theme,
// float x_center , float y_center ,float x_size_percent , float y_size_percent, float space_between,
// int number_cards, const in_game_hanabi_Card_t * cards, unsigned char value_or_suit)
textbox_status->draw(display);
al_flip_display();
}
void Eda_Menu_Game::update_buttons(ALLEGRO_DISPLAY * display, float x_mouse, float y_mouse)
{
for(int i = 0 ; i < 5 ; i++)
{
color_buttons[i]->update_hovering(display, x_mouse, y_mouse);
number_buttons[i]->update_hovering(display, x_mouse, y_mouse);
}
for(int i = 0 ; i < 6 ; i++)
my_cards_buttons[i]->update_hovering(display, x_mouse, y_mouse);
give_clue->update_hovering(display, x_mouse, y_mouse);
discard_card->update_hovering(display, x_mouse, y_mouse);
play_card->update_hovering(display, x_mouse, y_mouse);
graveyard_toggle->update_hovering(display, x_mouse, y_mouse);
}
bool Eda_Menu_Game::check_for_click(ALLEGRO_DISPLAY * display, float x_mouse, float y_mouse, std::queue<hanabi_game_event_t> &button_event_queue)
{
bool click_color = false;
bool click_number = false;
bool click_card = false;
bool click_button = false;
unsigned int i, k;
if( give_clue->check_mouse_over_toggle(display, x_mouse, y_mouse) )
{
click_button = true;
button_event_queue.push( give_clue->get_click_event() );
}
else if( play_card->check_mouse_over_toggle(display, x_mouse, y_mouse) )
{
click_button = true;
button_event_queue.push( play_card->get_click_event() );
}
else if( discard_card->check_mouse_over_toggle(display, x_mouse, y_mouse) )
{
click_button = true;
button_event_queue.push( discard_card->get_click_event() );
}
else if( graveyard_toggle->check_mouse_over(display, x_mouse, y_mouse))
{
hidden_graveyard = !hidden_graveyard;
if(!hidden_graveyard)
textbox_status->hide();
else
textbox_status->show();
}
for(i = 0 ; i < 5 && !click_button && !click_color && !click_number; i++)
{
if( color_buttons[i]->check_mouse_over_toggle(display, x_mouse, y_mouse) )
{
button_event_queue.push( color_buttons[i]->get_click_event() );
click_color = true;
}
else if( number_buttons[i]->check_mouse_over_toggle(display, x_mouse, y_mouse))
{
button_event_queue.push( number_buttons[i]->get_click_event() );
click_number = true;
}
}
for(k = 0 ; k < 6 && !click_button && !click_card && !click_color && !click_number ; k++)
{
if(my_cards_buttons[k]->check_mouse_over_toggle(display, x_mouse, y_mouse) )
{
button_event_queue.push( my_cards_buttons[k]->get_click_event() );
click_card = true;
}
}
--k;
--i; // i will point to the click button in array
//If click occurs on a button will deselect rest of buttons
if(click_color || click_number)
{
for(int j = 0 ; j < 5 ; j++)
{
if( !click_color || i != j) //If click color will deselect all except clicked
color_buttons[j]->deselect();
if( !click_number || i != j) //If click number will deselect all except clicked
number_buttons[j]->deselect();
}
if(color_buttons[i]->is_selected() || number_buttons[i]->is_selected() )
give_clue->show();
else
give_clue->hide();
}
else if(click_card)
{
for(int j = 0 ; j < 6 ; j++)
if( k != j) //If click color will deselect all except clicked
my_cards_buttons[j]->deselect();
if(my_cards_buttons[k]->is_selected())
{
play_card->show();
discard_card->show();
}
else
{
play_card->hide();
discard_card->hide();
}
}
return click_color || click_number;
}
void Eda_Menu_Game::draw_lightning_tokens(ALLEGRO_DISPLAY *display, Hanabi_Skin *theme, Hanabi_Board * game_board,
float x_center , float y_center ,float x_size_percent , float y_size_percent)
{
unsigned int used_tokens = HANABI_LIGHT_TOKENS - game_board->number_lives_left();
for(unsigned int i = 1 ; i <= HANABI_LIGHT_TOKENS ; i++)
{
if( i <= used_tokens)
al_draw_scaled_bitmap(theme->token_lightning[0], //token_lightning[0] corresponds to disabled
0.0, 0.0, al_get_bitmap_width(theme->token_lightning[0]), al_get_bitmap_height(theme->token_lightning[0]),
(x_center-0.5 * x_size_percent) * al_get_display_width(display), //x_cord to draw
(y_center-0.5 * y_size_percent + y_size_percent * (i-1)) * al_get_display_height(display), //y_cord to draw
x_size_percent * al_get_display_width(display), y_size_percent * al_get_display_height(display), //width and height to draw
0); //flags
else
al_draw_scaled_bitmap(theme->token_lightning[1], //token_lightning[1] corresponds to enabled
0.0, 0.0, al_get_bitmap_width(theme->token_lightning[1]), al_get_bitmap_height(theme->token_lightning[1]),
(x_center-0.5 * x_size_percent) * al_get_display_width(display), //x_cord to draw
(y_center-0.5 * y_size_percent + y_size_percent * (i-1)) * al_get_display_height(display), //y_cord to draw
x_size_percent * al_get_display_width(display), y_size_percent * al_get_display_height(display), //width and height to draw
0); //flags
}
}
void Eda_Menu_Game::draw_clue_tokens(ALLEGRO_DISPLAY *display, Hanabi_Skin *theme, Hanabi_Board * game_board,
float x_center , float y_center ,float x_size_percent , float y_size_percent)
{
unsigned int used_tokens = HANABI_CLUE_TOKENS - game_board->number_clues_left();
for(unsigned int i = 1 ; i <= HANABI_CLUE_TOKENS ; i++)
{
if( i <= used_tokens)
al_draw_scaled_bitmap(theme->token_clue[0], //token_lightning[0] corresponds to disabled
0.0, 0.0, al_get_bitmap_width(theme->token_clue[0]), al_get_bitmap_height(theme->token_clue[0]),
(x_center-0.5 * x_size_percent) * al_get_display_width(display), //x_cord to draw
(y_center-0.5 * y_size_percent + y_size_percent * (i-1)) * al_get_display_height(display), //y_cord to draw
x_size_percent * al_get_display_width(display), y_size_percent * al_get_display_height(display), //width and height to draw
0); //flags
else
al_draw_scaled_bitmap(theme->token_clue[1], //token_lightning[1] corresponds to enabled
0.0, 0.0, al_get_bitmap_width(theme->token_lightning[1]), al_get_bitmap_height(theme->token_clue[1]),
(x_center-0.5 * x_size_percent) * al_get_display_width(display), //x_cord to draw
(y_center-0.5 * y_size_percent + y_size_percent * (i-1)) * al_get_display_height(display), //y_cord to draw
x_size_percent * al_get_display_width(display), y_size_percent * al_get_display_height(display), //width and height to draw
0); //flags
}
}
void Eda_Menu_Game::draw_cards(ALLEGRO_DISPLAY *display, Hanabi_Skin *theme,
float x_center , float y_center ,float x_size_percent , float y_size_percent, float space_between,
int number_cards, const Hanabi_Card * cards_to_draw)
{
Hanabi_Card empty_card;
for(int i = 0 ; i < number_cards ; i++) //Checks all the cards
{
Hanabi_Card temp_copy = cards_to_draw[i];
if( empty_card == cards_to_draw[i] ) //Checks if it is an empty card, if is true draws the card backside
al_draw_scaled_bitmap(theme->cards_backside,
0.0, 0.0, al_get_bitmap_width(theme->cards_backside), al_get_bitmap_height(theme->cards_backside),
(x_center + (space_between+x_size_percent) * (i-number_cards/2.0)) * al_get_display_width(display), //x_cord to draw
(y_center - 0.5 * y_size_percent) * al_get_display_height(display), //y_cord to draw
x_size_percent * al_get_display_width(display), y_size_percent * al_get_display_height(display), //width and height to draw
0); //flags
else
{
int suit_num = temp_copy.get_suit_number();
al_draw_scaled_bitmap(theme->deck[suit_num][temp_copy.get_value()-1],
0.0, 0.0, al_get_bitmap_width(theme->deck[suit_num][temp_copy.get_value()-1]), al_get_bitmap_height(theme->deck[suit_num][temp_copy.get_value()-1]),
(x_center + (space_between+x_size_percent) * (i-number_cards/2.0)) * al_get_display_width(display), //x_cord to draw
(y_center - 0.5 * y_size_percent) * al_get_display_height(display), //y_cord to draw
x_size_percent * al_get_display_width(display), y_size_percent * al_get_display_height(display), //width and height to draw
0); //flags
}
#warning "FIX DRAWING IS SLIGHTLY OFF WHEN IMPAIR NUMBER DUE TO SPACING I THINK"
}
}
void Eda_Menu_Game::draw_deck(ALLEGRO_DISPLAY *display, Hanabi_Skin *theme, Hanabi_Board * game_board, float x_center , float y_center ,float x_size_percent , float y_size_percent)
{
//font with number of cards remaining
ALLEGRO_BITMAP * deck_to_draw = NULL;
if(game_board->hanabi_game_deck.size() >= HANABI_NUMBER_DECK_VIEWS)
{
deck_to_draw = theme->deck_view[HANABI_NUMBER_DECK_VIEWS-1];
al_draw_scaled_bitmap(deck_to_draw,
0.0, 0.0, al_get_bitmap_width(deck_to_draw), al_get_bitmap_height(deck_to_draw),
(x_center-0.5 * x_size_percent) * al_get_display_width(display), //x_cord to draw
(y_center-0.5 * y_size_percent) * al_get_display_height(display), //y_cord to draw
x_size_percent * al_get_display_width(display), y_size_percent * al_get_display_height(display), //width and height to draw
0); //flags
}
else if (game_board->hanabi_game_deck.size())
{
deck_to_draw = theme->deck_view[game_board->hanabi_game_deck.size()-1];
al_draw_scaled_bitmap(deck_to_draw,
0.0, 0.0, al_get_bitmap_width(deck_to_draw), al_get_bitmap_height(deck_to_draw),
(x_center-0.5 * x_size_percent) * al_get_display_width(display), //x_cord to draw
(y_center-0.5 * y_size_percent) * al_get_display_height(display), //y_cord to draw
x_size_percent * al_get_display_width(display), y_size_percent * al_get_display_height(display), //width and height to draw
0);
}
if(game_board->hanabi_game_deck.size())
al_draw_textf(theme->font, al_color_name("ghostwhite"),
x_center * al_get_display_width(display), (y_size_percent/2.0 + y_center) * al_get_display_height(display),ALLEGRO_ALIGN_CENTRE,
"%d", game_board->hanabi_game_deck.size());
}
#define XSPACE_GRAVE_CARD 0.018
#define YSPACE_GRAVE_CARD 0.10
#define BORDER_WIDTH 0.015
void Eda_Menu_Game::draw_graveyard(ALLEGRO_DISPLAY *display, Hanabi_Skin *theme,float x_center , float y_center ,float x_size_percent , float y_size_percent, Hanabi_Board * board)
{
al_draw_filled_rounded_rectangle( (x_center - 0.5 * x_size_percent - BORDER_WIDTH) * al_get_display_width(display) ,
(y_center - 0.5 * y_size_percent - BORDER_WIDTH * 16.0/9.0 ) * al_get_display_height(display),
(x_center + 0.5 * x_size_percent + BORDER_WIDTH + XSPACE_GRAVE_CARD * 9) * al_get_display_width(display), //9 and 4 one less than cards and suits
(y_center + 0.5 * y_size_percent + BORDER_WIDTH * 16.0/9.0 + YSPACE_GRAVE_CARD * 4) * al_get_display_height(display),
15, 15, al_map_rgba(0,0,0,125)
);
al_draw_rounded_rectangle( (x_center - 0.5 * x_size_percent - BORDER_WIDTH) * al_get_display_width(display) ,
(y_center - 0.5 * y_size_percent - BORDER_WIDTH * 16.0/9.0 ) * al_get_display_height(display),
(x_center + 0.5 * x_size_percent + BORDER_WIDTH + XSPACE_GRAVE_CARD * 9) * al_get_display_width(display), //9 and 4 one less than cards and suits
(y_center + 0.5 * y_size_percent + BORDER_WIDTH * 16.0/9.0 + YSPACE_GRAVE_CARD * 4) * al_get_display_height(display),
15, 15, al_map_rgb(0,0,0), 2.0
);
Hanabi_Card card;
for(int i = 0; i < 5 ; i++)
for( int j = 0; j < board->grave_yard[i].size(); j++ )
{
board->grave_yard[i].get_ncard(j,card);
ALLEGRO_BITMAP * card_to_draw = theme->deck[card.get_suit_number()][card.get_value()-1];
al_draw_scaled_bitmap(card_to_draw,
0.0, 0.0, al_get_bitmap_width(card_to_draw), al_get_bitmap_height(card_to_draw),
(x_center-0.5 * x_size_percent+ j * XSPACE_GRAVE_CARD) * al_get_display_width(display), //x_cord to draw
(y_center-0.5 * y_size_percent+ i * YSPACE_GRAVE_CARD) * al_get_display_height(display), //y_cord to draw
x_size_percent * al_get_display_width(display), y_size_percent * al_get_display_height(display), //width and height to draw
0); //flags
}
}
#warning "puede que sea char, Hanabi_You_Have_Packet, tambien puede ser asi el get card"
unsigned int Eda_Menu_Game::get_selected_clue(void)
{
bool button_selected = false;
unsigned int selected = 0;// 0 stands for no selected
for(int i = 0 ; !button_selected && i < 5 ; i++)
{
if( this->number_buttons[i]->is_selected() )
{
selected = i + '1';
button_selected = true;
}
else if( this->color_buttons[i]->is_selected())
{
switch(i)
{
case 0:
selected = 'W';
break;
case 1:
selected = 'B';
break;
case 2:
selected = 'G';
break;
case 3:
selected = 'Y';
break;
case 4:
selected = 'R';
break;
default:
selected = 0;
break;
}
button_selected = true;
}
}
return selected;
}
#warning "agregar comentario"
unsigned int Eda_Menu_Game::get_selected_card(void)
{
bool card_selected = false;
unsigned int selected = NO_CARD_SELECTED;
for(int i = 0 ; !card_selected && i < 6 ; i++)
{
if( this->my_cards_buttons[i]->is_selected() )
{
selected = i;
card_selected = true;
}
}
return selected;
}
void Eda_Menu_Game::draw_player_box_name (ALLEGRO_DISPLAY *display,const char* player_name,float x_center , float y_center ,float x_size_percent , float y_size_percent)
{
ALLEGRO_FONT * font;
font = al_load_ttf_font(MONO_FONT_PATH,calculate_font_size(display, x_size_percent, y_size_percent, MONO_FONT_PATH, NAME_SIZE),0);
al_draw_filled_rounded_rectangle( (x_center - 0.5 * x_size_percent - BORDER_WIDTH) * al_get_display_width(display) ,
(y_center - 0.5 * y_size_percent - BORDER_WIDTH * 16.0/9.0 ) * al_get_display_height(display),
(x_center + 0.5 * x_size_percent + BORDER_WIDTH ) * al_get_display_width(display),
(y_center + 0.5 * y_size_percent + BORDER_WIDTH * 16.0/9.0 ) * al_get_display_height(display),
10.0,10.0,
al_map_rgba(0,0,0,125));
al_draw_text(font, al_color_name("white"),x_center * al_get_display_width(display),
y_center * al_get_display_height(display) - al_get_font_line_height(font)*0.5,
ALLEGRO_ALIGN_CENTRE, player_name );
al_destroy_font(font);
}
/*
* This function draws a clue. Checks if it is a suit or a value. If it is a value, draws the value in the given clue in all the
* cards. If the clue is a suit, all the cards borders change thier color.
*
* Input:
* -ALLEGRO_DISPLAY *display: The display.
* -Hanabi_Skin *theme
* -float x_center , float y_center ,float x_size_percent , float y_size_percent, float space_between: floats to draw the elements in the correct place.
-int number_cards: number of cards to be drawn.
* -const Hanabi_Card * cards_to_draw: array of Hanabi Cards
*
* Return:
* -void.
*/
void Eda_Menu_Game::draw_clue(ALLEGRO_DISPLAY *display,
Hanabi_Board * game_board, unsigned char value_or_suit)
{
float font_width = my_cards_buttons[1]->x_size_percent-0.1;
float font_height = my_cards_buttons[1]->y_size_percent -0.1;
ALLEGRO_FONT * font;
font = al_load_ttf_font(MONO_FONT_PATH,calculate_font_size(display,font_width , font_height, MONO_FONT_PATH, 1),0);
bool value = (value_or_suit <= 5) ? true : false; //Check if is value or suit
bool clue_is_in_hand=false;
if(value) //The clue is a value
{
for (int i=0; i< HANABI_CARDS_PER_HAND ; i++) //Checks all the hand.
{
if (game_board->my_cards[i].playing_card.get_value() == value_or_suit)
{
std::string number2draw(1,value_or_suit+'0');
//al_draw_text(font, al_color_name("white"),
// ((x_center + (space_between+x_size_percent) * (i-number_cards/2.0)) * al_get_display_width(display))+ (x_size_percent * (al_get_display_width(display))/2),
// ((y_center - 0.5 * y_size_percent) * al_get_display_height(display)) + ((y_size_percent * al_get_display_height(display))/2),
// 0, number2draw.c_str());
al_draw_text(font, al_color_name("white"),
((my_cards_buttons[i]->x_center-0.5 * my_cards_buttons[i]->x_size_percent) - font_width/2) * al_get_display_width(display),
((my_cards_buttons[i]->y_center-0.5 * my_cards_buttons[i]->y_size_percent)+font_height/2) * al_get_display_height(display),
0, number2draw.c_str());
clue_is_in_hand=true;
}
}
}
else
{
for (int i=0; i< HANABI_CARDS_PER_HAND; i++) //Checks all the hand
{
if (game_board->my_cards[i].playing_card.get_suit() == value_or_suit)
{
switch (value_or_suit)
{
case 'Y':
al_draw_filled_circle(((my_cards_buttons[i]->x_center-0.5 * my_cards_buttons[i]->x_size_percent) - font_width/2 - .004) * al_get_display_width(display),
((my_cards_buttons[i]->y_center-0.5 * my_cards_buttons[i]->y_size_percent)+ font_height - .04) * al_get_display_height(display),
0.015 * al_get_display_height(display), al_map_rgba_f(0.8,0.8,0,0.5));
break;
case 'R':
al_draw_filled_circle(((my_cards_buttons[i]->x_center-0.5 * my_cards_buttons[i]->x_size_percent) - font_width/2 - .004) * al_get_display_width(display),
((my_cards_buttons[i]->y_center-0.5 * my_cards_buttons[i]->y_size_percent)+ font_height - .04) * al_get_display_height(display),
0.015 * al_get_display_height(display), al_map_rgba_f(0.7,0,0,0.5));
break;
case 'B':
al_draw_filled_circle(((my_cards_buttons[i]->x_center-0.5 * my_cards_buttons[i]->x_size_percent) - font_width/2 - .004) * al_get_display_width(display),
((my_cards_buttons[i]->y_center-0.5 * my_cards_buttons[i]->y_size_percent)+ font_height - .04) * al_get_display_height(display),
0.015 * al_get_display_height(display), al_map_rgba_f(0,0,0.7,0.5));
break;
case 'G':
al_draw_filled_circle(((my_cards_buttons[i]->x_center-0.5 * my_cards_buttons[i]->x_size_percent) - font_width/2 - .004) * al_get_display_width(display),
((my_cards_buttons[i]->y_center-0.5 * my_cards_buttons[i]->y_size_percent)+ font_height - .04) * al_get_display_height(display),
0.015 * al_get_display_height(display), al_map_rgba_f(0,0.75,0,0.5));
break;
case 'W':
al_draw_filled_circle(((my_cards_buttons[i]->x_center-0.5 * my_cards_buttons[i]->x_size_percent) - font_width/2 - .004) * al_get_display_width(display),
((my_cards_buttons[i]->y_center-0.5 * my_cards_buttons[i]->y_size_percent)+ font_height - .04) * al_get_display_height(display),
0.015 * al_get_display_height(display), al_map_rgba_f(0.9,0.9,0.9,0.5));
break;
}
clue_is_in_hand=true;
}
}
}
//if (clue_is_in_hand==false)
/* al_draw_filled_rounded_rectangle((my_cards_buttons[3]->x_center-0.5) * al_get_display_width(display),
(my_cards_buttons[3]->y_center-0.5) * al_get_display_width(display),
(my_cards_buttons[3]->x_center-0.5 + 10) * al_get_display_width(display),
(my_cards_buttons[3]->y_center-0.5 + 10) * al_get_display_width(display),
0,0,al_color_name("black"));*/
al_destroy_font(font);
}