-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainMenuState.cpp
146 lines (140 loc) · 5.44 KB
/
MainMenuState.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
#include <sstream>
#include "MainMenuState.hpp"
#include "DEFINITIONS.hpp"
#include "playOptionState.hpp"
#include "options.hpp"
#include "rgba.hpp"
#include <fstream>
#include <iostream>
namespace GameEngine{
MainMenuState::MainMenuState(GameDataRef data) : _data(data){ }
void MainMenuState::Init(){
this->boolIsdefaultTheme();
/*
For loading data
*/
this->_data->themeDefault = new rgba();
this->_data->themeNew = new rgba(true);
this->_data->assets.LoadTexture("Resume Button",resume_button);
this->_data->assets.LoadTexture("Pause Button", PAUSE_BUTTON);
this->_data->assets.LoadTexture("Grid Sprite", GRID_SPRITE_FILEPATH);
this->_data->assets.LoadTexture("X Piece", X_PIECE_FILEPATH);
this->_data->assets.LoadTexture("O Piece", O_PIECE_FILEPATH);
this->_data->assets.LoadTexture("X Winning Piece", X_WINNING_PIECE_FILEPATH);
this->_data->assets.LoadTexture("O Winning Piece", O_WINNING_PIECE_FILEPATH);
this->_data->assets.LoadTexture("Retry Button", "Resources/res/Retry Button.png");
this->_data->assets.LoadTexture("Home Button", "Resources/res/Home Button.png");
this->_data->assets.LoadTexture("Play Button", PLAY_BUTTON);
this->_data->assets.LoadTexture("Play Button Outer", MAIN_MENU_PLAY_BUTTON_OUTER);
this->_data->assets.LoadTexture("X Win", X_WINNING_PIECE_FILEPATH);
this->_data->assets.LoadTexture("O Win",O_WINNING_PIECE_FILEPATH);
this->_data->assets.LoadFont("Felt",FELT_FRONT);
this->_data->assets.LoadFont("arial","Resources/fonts/ARIAL.TTF");
/*
for play button
*/
this->_play.setFont(this->_data->assets.GetFont("Felt"));
this->_play.setPosition((SCREEN_WIDTH / 2) - (this->_play.getGlobalBounds().width / 2) - 30, (SCREEN_HEIGHT / 2) - (this->_play.getGlobalBounds().height / 2) - 20);
this->_play.setString("PLAY");
this->_playButton.setTexture(this->_data->assets.GetTexture("Play Button"));
this->_playButton.setPosition((SCREEN_WIDTH / 2) - (this->_playButton.getGlobalBounds().width / 2), (SCREEN_HEIGHT / 2) - (this->_playButton.getGlobalBounds().height / 2));
/*
For bottom bar lines
*/
this->_playButtonOuter.setPosition(0,0);
this->_playButtonOuter.setTexture(this->_data->assets.GetTexture("Play Button Outer"));
/*
For title card
*/
/*
For options button
*/
this->_option.setTexture(this->_data->assets.GetTexture("Play Button"));
this->_option.setPosition(this->_playButton.getPosition().x , this->_playButton.getPosition().y + 100);
this->_options.setFont(this->_data->assets.GetFont("Felt"));
this->_options.setPosition(this->_option.getPosition().x + 60 , this->_option.getPosition().y + 5);
this->_options.setString("THEMES");
/*
For exit button
*/
this->_exit_btn.setTexture(this->_data->assets.GetTexture("Play Button"));
this->_exit_btn.setPosition(this->_playButton.getPosition().x , this->_playButton.getPosition().y + 200);
this->_exit.setFont(this->_data->assets.GetFont("Felt"));
this->_exit.setPosition(this->_exit_btn.getPosition().x + 85 , this->_exit_btn.getPosition().y + 5);
this->_exit.setString("EXIT");
}
void MainMenuState::HandleInput()
{
sf::Event event;
while (this->_data->window.pollEvent(event))
{
if (sf::Event::Closed == event.type)
{
this->_data->window.close();
}
if(this->_playButton.getGlobalBounds().contains(static_cast<sf::Vector2f>(sf::Mouse::getPosition(this->_data->window)))){
this->_playButton.setScale(1.25,1.25);
}
else{
this->_playButton.setScale(1,1);
}
if (this->_data->input.IsSpriteClicked(this->_playButton, sf::Mouse::Left, this->_data->window))
{
this->_data->machine.AddState(StateRef(new PlayOptionState(_data)),true);
}
if(this->_option.getGlobalBounds().contains(static_cast<sf::Vector2f>(sf::Mouse::getPosition(this->_data->window)))){
this->_option.setScale(1.25,1.25);
}
else{
this->_option.setScale(1,1);
}
if (this->_data->input.IsSpriteClicked(this->_option, sf::Mouse::Left, this->_data->window))
{
this->_data->machine.AddState(StateRef(new Options(_data)),false);
}
if(this->_exit_btn.getGlobalBounds().contains(static_cast<sf::Vector2f>(sf::Mouse::getPosition(this->_data->window)))){
this->_exit_btn.setScale(1.25,1.25);
}
else{
this->_exit_btn.setScale(1,1);
}
if (this->_data->input.IsSpriteClicked(this->_exit_btn, sf::Mouse::Left, this->_data->window))
{
this->_data->window.close();
}
}
}
void MainMenuState::boolIsdefaultTheme(){
std::fstream fileForRead("data.ini");
int tempString = 1;
if(fileForRead.is_open()){
fileForRead >> tempString ;
}
fileForRead.close();
if(tempString == 0 ){
this->_data->isdefaultTheme = false;
}
else{
this->_data->isdefaultTheme = true;
}
}
void MainMenuState::Update(float dt)
{
}
void MainMenuState::Draw(float dt)
{
if(this->_data->isdefaultTheme){
this->_data->window.clear(sf::Color(this->_data->themeDefault->getMainMenuR(),this->_data->themeDefault->getMainMenuG(),this->_data->themeDefault->getMainMenuB()));
}else{
this->_data->window.clear(sf::Color(this->_data->themeNew->getMainMenuR(),this->_data->themeNew->getMainMenuG(),this->_data->themeNew->getMainMenuB()));
}
this->_data->window.draw(this->_playButton);
this->_data->window.draw(this->_playButtonOuter);
this->_data->window.draw(this->_play);
this->_data->window.draw(this->_option);
this->_data->window.draw(this->_options);
this->_data->window.draw(this->_exit_btn);
this->_data->window.draw(this->_exit);
this->_data->window.display();
}
}