-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHanabi_Skin.cpp
247 lines (214 loc) · 7.27 KB
/
Hanabi_Skin.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
/*
* File: Hanabi_Skin.cpp
* Author: r2d2
*
* Created on January 20, 2017, 11:53 PM
*/
#include <sys/stat.h>
#include <string>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include "Hanabi_Skin.h"
#include "setting_management.h"
#define HANABI_FONT_SIZE 32
static bool check_folder_exists(const char * folder_name);
/*
* Constructor for Hanabi_Skin Initializes all the bitmaps in NULL
*
* Input:
* -void
*
* Return:
* -No return in constructor
*/
Hanabi_Skin::Hanabi_Skin()
{
#warning "Update everything to NULL and update destructor"
main_menu = NULL;
connecting_background = NULL;
game_mat = NULL;
cards_backside = NULL;
for(unsigned int i = 0 ; i < 5 ; i++)
for(unsigned int j = 0 ; j < 5 ; j++)
deck[i][j] = NULL;
/*
for(unsigned int i = 0 ; i < 5 ; i++)
{
cards_blue[i] = NULL;
cards_green[i] = NULL;
cards_red[i] = NULL;
cards_white[i] = NULL;
cards_yellow[i] = NULL;
}*/
//0 Will correspond to disable 1 to enabled for tokens
token_clue[0] = NULL;
token_clue[1] = NULL;
token_lightning[0] = NULL;
token_lightning[1] = NULL;
font = NULL;
//clue_numbers[5];
//clue_colors[5];
//clue_hover = NULL;
}
/*
* Destructor for Hanabi_Skin destroys all the bitmaps which were loaded (using al_destroy_bitmap)
* if a bitmap is set to NULL it will no be destroyed as there is nothing to destroy.
*
* Input:
* -void
*
* Return:
* -No return in constructor
*/
Hanabi_Skin::~Hanabi_Skin()
{
if( this->main_menu != NULL)
al_destroy_bitmap(this->main_menu);
if( this->connecting_background != NULL)
al_destroy_bitmap(this->connecting_background);
if( this->setting_background != NULL)
al_destroy_bitmap(this->setting_background);
if( this->token_clue[0] != NULL)
al_destroy_bitmap(this->token_clue[0]);
if( this->token_clue[1] != NULL)
al_destroy_bitmap(this->token_clue[1]);
if( this->token_lightning[0] != NULL)
al_destroy_bitmap(this->token_lightning[0]);
if( this->token_lightning[1] != NULL)
al_destroy_bitmap(this->token_lightning[1]);
if( this->cards_backside != NULL)
al_destroy_bitmap(this->cards_backside);
for(unsigned int i = 0 ; i < 5 ; i++)
for(unsigned int j = 0 ; j < 5 ; j++)
if( this->deck[i][j] != NULL)
al_destroy_bitmap(this->deck[i][j]);
for(unsigned int i = 0 ; i < HANABI_NUMBER_DECK_VIEWS ; i++)
if( this->deck_view[i] != NULL)
al_destroy_bitmap(this->deck_view[i]);
if(this->font != NULL)
al_destroy_font(this->font);
/*
if( this->cards_blue[i] != NULL)
al_destroy_bitmap(this->cards_blue[i]);
if( this->cards_green[i] != NULL)
al_destroy_bitmap(this->cards_green[i]);
if( this->cards_red[i] != NULL)
al_destroy_bitmap(this->cards_red[i]);
if( this->cards_white[i] != NULL)
al_destroy_bitmap(this->cards_white[i]);
if( this->cards_yellow[i] != NULL)
al_destroy_bitmap(this->cards_yellow[i]);
}
*/
}
/*
* Taken from stackoverflow http://stackoverflow.com/questions/12510874/how-can-i-check-if-a-directory-exists
* uses #include <sys/stat.h>
*
* Input:
* -const char * folder_name: Name of folder, will check inside root directory of project. Example "Hanabi Themes"
*
* Return:
* -bool: True is folder exists, false if it does not.
*/
bool check_folder_exists(const char * folder_name)
{
struct stat sb;
return ( stat(folder_name, &sb) == 0 && S_ISDIR(sb.st_mode) );
}
/*
* Destructor for Hanabi_Skin destroys all the bitmaps which were loaded (using al_destroy_bitmap)
* if a bitmap is set to NULL it will no be destroyed as there is nothing to destroy.
*
* Input:
* -string theme_name : Name of theme folder, example "Pokemon" or "Classic"
*
* Return:
* -bool: True if ALL skins were successfully loaded, false if any skin fails to load
*/
bool Hanabi_Skin::load_theme(std::string theme_name)
{
bool success = false;
std::string current_folder;
this->theme = theme_name;
if( check_folder_exists( ("Hanabi Themes/" + theme_name).c_str()))
{
success = true;
std::string main_menu, game_mat, connecting_background, setting_background,
token_clue, token_lightning, deck;
current_folder = "Hanabi Themes/" + theme_name + "/";
main_menu = current_folder + "main_menu.png";
game_mat = current_folder + "game_mat.png";
connecting_background = current_folder + "connecting_background.png";
setting_background = current_folder + "setting_background3.jpg";
token_clue = current_folder + "Token Clue/";
token_lightning = current_folder + "Token Lightning/";
deck = current_folder + "Deck/";
if( (this->main_menu = al_load_bitmap(main_menu.c_str())) == NULL)
success = false;
else if( (this->game_mat = al_load_bitmap(game_mat.c_str())) == NULL)
success = false;
else if( (this->connecting_background = al_load_bitmap(connecting_background.c_str())) == NULL)
success = false;
else if( (this->setting_background = al_load_bitmap(setting_background.c_str())) == NULL)
success = false;
else if( (this->token_clue[0] = al_load_bitmap( (token_clue + "disable.png").c_str())) == NULL)
success = false;
else if( (this->token_clue[1] = al_load_bitmap( (token_clue + "enable.png").c_str())) == NULL)
success = false;
else if( (this->token_lightning[0] = al_load_bitmap( (token_lightning + "disable.png").c_str())) == NULL)
success = false;
else if( (this->token_lightning[1] = al_load_bitmap( (token_lightning + "enable.png").c_str())) == NULL)
success = false;
else if( (this->cards_backside = al_load_bitmap( (deck + "back.png").c_str())) == NULL)
success = false;
else if( (this->font = al_load_ttf_font((FONT_PATH "/font.ttf"), HANABI_FONT_SIZE, 0)) == NULL)
success = false;
else
{
std::string toload = deck + "white" + "0";
for(unsigned int i = 0 ; i < 5 && success ; i++)
{
toload[toload.size()-1]++; //Increases number at end of string
if( (this->deck[0][i] = al_load_bitmap((toload+".png").c_str() ) ) == NULL)
success = false;
}
toload = deck + "blue" + "0";
for(unsigned int i = 0 ; i < 5 && success ; i++)
{
toload[toload.size()-1]++; //Increases number at end of string deck/blue1 then deck/blue2 etc...
if( (this->deck[1][i] = al_load_bitmap((toload+".png").c_str() ) ) == NULL)
success = false;
}
toload = deck + "green" + "0";
for(unsigned int i = 0 ; i < 5 && success ; i++)
{
toload[toload.size()-1]++; //Increases number at end of string
if( (this->deck[2][i] = al_load_bitmap((toload+".png").c_str() ) ) == NULL)
success = false;
}
toload = deck + "yellow" + "0";
for(unsigned int i = 0 ; i < 5 && success ; i++)
{
toload[toload.size()-1]++; //Increases number at end of string
if( (this->deck[3][i] = al_load_bitmap((toload+".png").c_str() ) ) == NULL)
success = false;
}
toload = deck + "red" + "0";
for(unsigned int i = 0 ; i < 5 && success ; i++)
{
toload[toload.size()-1]++; //Increases number at end of string
if( (this->deck[4][i] = al_load_bitmap((toload+".png").c_str() ) ) == NULL)
success = false;
}
toload = deck + "deck_view" + "0";
for(unsigned int i = 0 ; i < HANABI_NUMBER_DECK_VIEWS && success ; i++)
{
if( (this->deck_view[i] = al_load_bitmap((toload+".png").c_str() ) ) == NULL)
success = false;
toload[toload.size()-1]++; //Increases number at end of string
}
}
}
return success;
}