-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOptionsMenus.cpp
177 lines (156 loc) · 5.8 KB
/
OptionsMenus.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
#include "OptionsMenus.h"
#include "SDL_include.h"
using namespace widgets;
OptionsMenus::OptionsMenus(const int &x, const int &y, const int &width, const int &height, SDL_Texture *newtexture, SDL_Renderer *renderer, const bool &mini)
{
msg_on = true;
bgm_level = 5;
sfx_level = 5;
rect.x = x;
rect.y = y;
rect.w = width;
rect.h = height;
texture = newtexture;
SDL_Color color;
color.a = 255;
color.b = 0;
color.g = 0;
color.r = 0;
visible = false;
std::string xmlpath = "assets//xml//options_menu_config.xml";
std::string xmltype = "options";
rapidxml::file<>* hxmlFile;
hxmlFile = new rapidxml::file<>(xmlpath.c_str()); // Default template is char
hdoc.parse<0>(hxmlFile->data());
hpRoot = hdoc.first_node();
if (!mini){
pNode = hpRoot->last_node("config")->first_node(xmltype.c_str());
}
else{
pNode = hpRoot->first_node("config")->first_node(xmltype.c_str());
}
//option buttons
for (rapidxml::xml_node<> *dNode = pNode->first_node("slot"); dNode; dNode = dNode->next_sibling("slot")){
option_buttons.push_back(MeguButton(rect.x + atoi(dNode->first_node("pos")->first_node("x")->value()), rect.y + atoi(dNode->first_node("pos")->first_node("y")->value()), atoi(dNode->first_node("pos")->first_node("w")->value()), atoi(dNode->first_node("pos")->first_node("h")->value()), NULL, true));
}
//control buttons aka back button
for (rapidxml::xml_node<> *dNode = pNode->first_node("buttons"); dNode; dNode = dNode->next_sibling("buttons")){
controls.push_back(MeguButton(rect.x + atoi(dNode->first_node("pos")->first_node("x")->value()), rect.y + atoi(dNode->first_node("pos")->first_node("y")->value()), atoi(dNode->first_node("pos")->first_node("w")->value()), atoi(dNode->first_node("pos")->first_node("h")->value()), NULL, true));
}
bgm_marker_pos.x = atoi(pNode->first_node("bgm_marker_pos")->first_node("pos")->first_node("x")->value());
bgm_marker_pos.y = atoi(pNode->first_node("bgm_marker_pos")->first_node("pos")->first_node("y")->value());
bgm_marker_offset = atoi(pNode->first_node("bgm_marker_pos")->first_node("offset")->first_node("x")->value());
bgm_marker_cd.w = atoi(pNode->first_node("marker")->first_node("size")->first_node("w")->value());
bgm_marker_cd.h = atoi(pNode->first_node("marker")->first_node("size")->first_node("h")->value());
sfx_marker_pos.x = atoi(pNode->first_node("sfx_marker_pos")->first_node("pos")->first_node("x")->value());
sfx_marker_pos.y = atoi(pNode->first_node("sfx_marker_pos")->first_node("pos")->first_node("y")->value());
sfx_marker_offset = atoi(pNode->first_node("sfx_marker_pos")->first_node("offset")->first_node("x")->value());
sfx_marker_cd.w = atoi(pNode->first_node("marker")->first_node("size")->first_node("w")->value());
sfx_marker_cd.h = atoi(pNode->first_node("marker")->first_node("size")->first_node("h")->value());
msg_on_pos.h = sfx_marker_cd.h;
msg_on_pos.w = sfx_marker_cd.w;
marker = loadTexture(pNode->first_node("marker")->first_node("texture")->value(), renderer);
}
void OptionsMenus::RenderButtons(SDL_Renderer *renderer)
{
}
OptionsMenus::~OptionsMenus()
{
}
void OptionsMenus::setBGMLevel(const int&bgm){
if (bgm < 6 && bgm > -1){
bgm_level = bgm;
}
}
void OptionsMenus::setSFXLevel(const int&sfx){
if (sfx < 6 && sfx > -1){
sfx_level = sfx;
}
}
void OptionsMenus::setMSGOn(const bool&msg){
msg_on = msg;
}
int OptionsMenus::getBGMLevel()
{
return bgm_level;
}
int OptionsMenus::getSFXLevel(){
return sfx_level;
}
bool OptionsMenus::getMSGOn(){
return msg_on;
}
void OptionsMenus::updateMarkers(){
bgm_marker_cd.x = bgm_marker_pos.x + bgm_level*bgm_marker_offset;
bgm_marker_cd.y = bgm_marker_pos.y;
sfx_marker_cd.x = sfx_marker_pos.x + sfx_level*sfx_marker_offset;
sfx_marker_cd.y = sfx_marker_pos.y;
}
SDL_Texture* OptionsMenus::loadTexture(std::string path, SDL_Renderer *renderer)
{
//The final texture
SDL_Texture* newTexture = NULL;
//Load image at specified path
SDL_Surface* loadedSurface = IMG_Load(path.c_str());
if (loadedSurface == NULL)
{
printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError());
}
else
{
//Create texture from surface pixels
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
if (newTexture == NULL)
{
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
}
//Get rid of old loaded surface
SDL_FreeSurface(loadedSurface);
}
return newTexture;
}
void OptionsMenus::disableMenu(){
visible = false;
for (widgets::button_container::iterator it = option_buttons.begin(); it != option_buttons.end(); ++it){
it->setVisible(false);
}
for (widgets::button_container::iterator it = controls.begin(); it != controls.end(); ++it){
it->setVisible(false);
it->setEnable(false);
}
}
void OptionsMenus::callMenu(){
visible = true;
updateMarkers();
for (widgets::button_container::iterator it = option_buttons.begin(); it != option_buttons.end(); ++it){
it->setVisible(true);
}
for (widgets::button_container::iterator it = controls.begin(); it != controls.end(); ++it){
it->setVisible(true);
it->setEnable(true);
}
}
void OptionsMenus::Render(SDL_Renderer *renderer)
{
if (visible){
SDL_RenderCopy(renderer, texture, NULL, &rect);
for (widgets::button_container::iterator it = option_buttons.begin(); it != option_buttons.end(); ++it){
it->Render(renderer);
}
for (widgets::button_container::iterator it = controls.begin(); it != controls.end(); ++it){
it->Render(renderer);
}
if (msg_on){
msg_on_pos.x = option_buttons[4].getX();
msg_on_pos.y = option_buttons[4].getY();
SDL_RenderCopy(renderer, marker, 0, &msg_on_pos);
}
else{
msg_on_pos.x = option_buttons[5].getX();
msg_on_pos.y = option_buttons[5].getY();
SDL_RenderCopy(renderer, marker, 0, &msg_on_pos);
}
SDL_RenderCopy(renderer, marker, 0, &bgm_marker_cd);
SDL_RenderCopy(renderer, marker, 0, &sfx_marker_cd);
}
}