-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassMenu.cpp
More file actions
167 lines (139 loc) · 4.96 KB
/
ClassMenu.cpp
File metadata and controls
167 lines (139 loc) · 4.96 KB
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
/*
* ClassMenu.cpp
*
* Copyright 2015 Joaquín Monteagudo Gómez <kindos7@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
/*
FDX_Fighter - ClassMenu.cpp
Little spaceship game made with C++ and SFML
Menu and windows - code file
*/
/*
Version 0.1 (dd/mm/yy, 24/11/2015 -> )
*/
/*
Preprocessor
*/
/* Includes */
//Header file
#include "ClassMenu.hpp"
namespace fdx{ namespace menu
{
/*
Code
*/
/* Initializations */
//Language
//Selected language
Language::en_type Language::lang=Language::DEF_LANG;
//Language dictionary
const std::string Language::language_text[MAX_LANG][MAX_TEXT] =
{
{"Singleplayer", "Multiplayer", "Tutorial", "OPTIONS", "Personalize", "Color", "Language", "COLORS", "LANGUAGE", "Confirm", "Confirm and start the program to see the changes","VSYNC on","VSYNC off","You died!","Enemy destroyed!", "CONTROLS", "Configure", "CONFIGURE MOUSE", "CONFIGURE XBOX", "CONFIGURE WIIMOTE", "SHOOT", "ACCELERATE", "BRAKE", "STICK","You win!","You lose"},
{"Un jugador", "Multijugador", "Tutorial", "OPCIONES", "Personalizar", "Color", "Idioma", "COLORES", "IDIOMA", "Confirmar", "Confirme y inicie el programa para ver los cambios","VSYNC activado","VSYNC desactivado","¡Has muerto!","¡Enemigo destruido!", "CONTROLES", "Configurar", "CONFIGURAR RATÓN", "CONFIGURAR MANDO XBOX", "CONFIGURAR WIIMOTE", "DISPARO", "ACELERAR", "FRENAR", "STICK","¡Has ganado","¡Has perdido!"}
};
//Dictionary of colors
const sf::Color DictionaryColors::colors [] =
{sf::Color(0,0,255), sf::Color::Yellow, sf::Color::Red, sf::Color::Green, sf::Color(128,0,128), sf::Color::Magenta, sf::Color::White, sf::Color(179,179,179)};
/* Functions */
/* Methods */
/*Button*/
//Button methods
//Test if the button is pressed by the given mouse
bool Button::isPressed(int mos_x, int mos_y, bool but)
{
//Button is disable
if (!isAvailable())
return false;
//Rect over RectShape
const sf::RectangleShape& current_rect=pressed?back_rect:front_rect;
sf::FloatRect rect_bounds(current_rect.getGlobalBounds());
//Button is pressed
if(pressed)
{
//Mouse is pressed
if (but)
{
//Mouse not over button
if(!rect_bounds.contains(sf::Vector2f(mos_x,mos_y)))
pressed = false;
//Mouse over button: keep it pressed, do not change anything
}
//Mouse not pressed
else
{
pressed=false;
//Mouse was released over the button
if (rect_bounds.contains(sf::Vector2f(mos_x,mos_y)))
{
pressed_sound.play();
return true;//Button pressed
}
}
}
//Button is not pressed
else
{
//Mouse is pressed and over the button
if (but&&rect_bounds.contains(sf::Vector2f(mos_x,mos_y)))
pressed = true;
else
{
if (!played&&rect_bounds.contains(sf::Vector2f(mos_x, mos_y)))
{
over_sound.play();
played = true;
}
if (!rect_bounds.contains(sf::Vector2f(mos_x,mos_y)))
played = false;
}
}
//Button not pressed
return false;
}
/*ButtonText*/
//Draw function
void ButtonText::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
Button::draw(target,states);
target.draw(button_text, states);
}
/*Menu*/
//Returns the button's pressed ID
int Menu::button_pressed(int x, int y, bool but)
{
for(unsigned int nbutton = 0; nbutton < menu_buttons.size(); ++nbutton)
{
if (menu_buttons[nbutton]->isPressed(x, y, but))
return nbutton;
}
return -1;
}
//Draw function
void Menu::draw (sf::RenderTarget &target, sf::RenderStates states) const
{
target.draw(background, states);
target.draw(title,states);
for(const Button* x : menu_buttons)
{
target.draw(*x, states);
}
}
}}//End of namespace