-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
122 lines (109 loc) · 4.59 KB
/
Copy pathMenu.cpp
File metadata and controls
122 lines (109 loc) · 4.59 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Menu.cpp
* Author: gabrielascurra
*
* Created on 10 de junio de 2018, 20:06
*/
#include "Menu.h"
#include <SFML/Graphics/Text.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <SFML/Audio/Sound.hpp>
#include "ConstantesGlobales.h"
#include "Configuracion.h"
Menu::Menu() {
}
Menu::Menu(const Menu& orig){}
Menu::~Menu(){}
void Menu::ConfigurarTexto(sf::Font &fuente,sf::Text &titulo,sf::Text &opcionUno,sf::Text &opcionDos,sf::Text &opcionTres,string mensajeTitulo,string mensajeUno,string mensajeDos,string mensajeTres){
fuente.loadFromFile("font/Cave-Story.ttf");
font=fuente;
titulo.setFont(fuente);
opcionUno.setFont(fuente);
opcionDos.setFont(fuente);
opcionTres.setFont(fuente);
titulo.setString(mensajeTitulo);
opcionUno.setString(mensajeUno);
opcionDos.setString(mensajeDos);
opcionTres.setString(mensajeTres);
titulo.setFillColor(sf::Color::Yellow);
}
void Menu::ConfigurarTamanoTexto(sf::Text &titulo,sf::Text &opcionUno,sf::Text &opcionDos,sf::Text &opcionTres,int tamanoTitulo,int tamanoUno,int tamanoDos){
titulo.setCharacterSize(tamanoTitulo);
opcionUno.setCharacterSize(tamanoUno);
opcionDos.setCharacterSize(tamanoDos);
opcionTres.setCharacterSize(tamanoDos);
}
void Menu::ConfigurarPosicionTexto(sf::Text &titulo,sf::Text &opcionUno,sf::Text &opcionDos,sf::Text &opcionTres,int offset){
sf::FloatRect textRec=titulo.getGlobalBounds();
titulo.setOrigin(textRec.left + textRec.width / 2.0f, textRec.top + textRec.height / 2.0f);
opcionUno.setOrigin(textRec.left + textRec.width / 2.0f, textRec.top + textRec.height / 2.0f);
opcionDos.setOrigin(textRec.left + textRec.width / 2.0f, textRec.top + textRec.height / 2.0f);
opcionTres.setOrigin(textRec.left + textRec.width / 2.0f, textRec.top + textRec.height / 2.0f);
titulo.setPosition(anchoResolucion / 2, (altoResolucion / 2) - offset);
opcionUno.setPosition(titulo.getPosition().x , titulo.getPosition().y + 90);
opcionDos.setPosition(titulo.getPosition().x , titulo.getPosition().y + 120);
opcionTres.setPosition(titulo.getPosition().x , titulo.getPosition().y + 150);
}
void Menu::SeleccionarOpcion(sf::RenderWindow &window,sf::Sprite &fondo,int &itemSeleccionado,sf::Text &opcionUno,sf::Text &opcionDos, sf::Text &opcionTres,bool &running,sf::Sound &cambiarSeleccion){
// reloj.restart();
tiempo=reloj.getElapsedTime();
if(tiempo.asSeconds() > 0.15){
switch (itemSeleccionado) {
case 0:
opcionUno.setFillColor(sf::Color::Red);
opcionDos.setFillColor(sf::Color::White);
opcionTres.setFillColor(sf::Color::White);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
cambiarSeleccion.play();
itemSeleccionado = 1;
reloj.restart();
}
break;
case 1:
opcionUno.setFillColor(sf::Color::White);
opcionDos.setFillColor(sf::Color::Red);
opcionTres.setFillColor(sf::Color::White);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
cambiarSeleccion.play();
itemSeleccionado = 0;
reloj.restart();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
cambiarSeleccion.play();
itemSeleccionado = 2;
reloj.restart();
}
break;
case 2:
opcionUno.setFillColor(sf::Color::White);
opcionDos.setFillColor(sf::Color::White);
opcionTres.setFillColor(sf::Color::Red);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
cambiarSeleccion.play();
itemSeleccionado = 1;
reloj.restart();
}
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) {
if (itemSeleccionado == 0) {
OpcionUno(window,running);
}
if (itemSeleccionado == 1) {
reloj.restart();
OpcionDos(window,fondo);
}
if(itemSeleccionado == 2){
OpcionTres();
}
}
}
void Menu::OpcionDos(sf::RenderWindow &window,sf::Sprite &fondo){
Configuracion conf;
conf.run(window,fondo,font);
}