-
Notifications
You must be signed in to change notification settings - Fork 1
/
startmenu.cpp
94 lines (83 loc) · 2.3 KB
/
startmenu.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
#include "startmenu.h"
#include <iostream>
StartMenu::StartMenu()
{
resourceMgr = ResourceMgr::getInstance();
input = Input::getInstance();
window = Window::getInstance();
isOpen = true;
nameMenu = new PlayerNameMenu();
resourceMgr->loadImage( "./data/images/startmenu.png", "startMenu" );
resourceMgr->loadFont( "./data/fonts/arial.ttf", "profileFont", 12 );
buttons.push_back( ClickableButton( "NEW GAME", Point( 450, 450 ), 19, 4 ) );
buttons.push_back( ClickableButton( "LOAD GAME", Point( 447, 400 ), 19, 4 ) );
buttons.push_back( ClickableButton( "OPTIONS", Point( 465, 350 ), 19, 4 ) );
buttons.push_back( ClickableButton( "QUIT", Point( 490, 300 ), 19, 4 ) );
}
void StartMenu::checkInput()
{
if( nameMenu->isStart() )
{
if( isOpen == true )
isOpen = false;
}
else
{
for( int i = 0; i <= buttons.size() - 1; ++i )
buttons[i].enableHover( true );
}
if( !nameMenu->inMenu() && isOpen == true )
{
if( buttons[0].isClicked() )
{
nameMenu->open();
for( int i = 0; i <= buttons.size() - 1; ++i )
buttons[i].enableHover( false );
}
if( buttons[1].isClicked() )
{
if( isOpen == true )
isOpen = false;
}
if( buttons[2].isClicked() )
{
if( isOpen == true )
isOpen = false;
}
if( buttons[3].isClicked() )
exit( 0 );
}
else
nameMenu->checkInput();
}
void StartMenu::draw()
{
resourceMgr->drawImage( "startMenu",
window->leftCoord(),
window->rightCoord(),
window->bottomCoord(),
window->topCoord() );
for( int i = 0; i <= buttons.size() - 1; ++i )
{
if( !nameMenu->inMenu() )
buttons[i].draw();
}
if( nameMenu->inMenu() )
nameMenu->draw();
glColor3f( 1, 1, 1 );
resourceMgr->drawTextOverlay( "profileFont", "profile: ", .8, .017 );
}
bool StartMenu::inMenu()
{
return isOpen;
}
void StartMenu::open()
{
if( isOpen == false )
isOpen = true;
}
StartMenu::~StartMenu()
{
input->release();
window->release();
}