-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCampaignMenu.cpp
More file actions
90 lines (74 loc) · 2.12 KB
/
CampaignMenu.cpp
File metadata and controls
90 lines (74 loc) · 2.12 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
#include "CampaignMenu.h"
#include "Constants.h"
#include <memory>
#include <fstream>
CampaignMenu::CampaignMenu() :
mFont(FontManager::GetFont()),
mTitle(TITLE, mFont, 100),
mSubTitle(SUBTITLE, mFont, 80),
mTitleShadow(),
mSubTitleShadow(),
mSize({ 300, 60 }),
mPositionNew({ HALF_WIDTH - 150.f, HALF_HEIGHT + (HALF_HEIGHT / 2) - 135.f }),
mPositionContinue({ HALF_WIDTH - 150.f, HALF_HEIGHT + (HALF_HEIGHT / 2) + 35.f }),
mButtonNew(std::make_unique<Button2>(mSize, mPositionNew, "New Game", mFont)),
mButtonContinue(std::make_unique<Button2>(mSize, mPositionContinue, "Continue", mFont)),
mIsChoiceDone(false),
mChoice("")
{
// title
mTitle.setFillColor(titleColor);
float titleMiddleWidth = mTitle.getLocalBounds().width / 2;
float titleHeight = mTitle.getLocalBounds().height;
mTitle.setPosition(HALF_WIDTH - titleMiddleWidth, HEIGHT / 5 - titleHeight);
mTitleShadow = mTitle;
mTitleShadow.setFillColor(shadowTitleColor);
mTitleShadow.move(4, 4);
// subtitle
mSubTitle.setFillColor(titleColor);
float textMiddleWidth = mSubTitle.getLocalBounds().width / 2;
float textHeight = mSubTitle.getLocalBounds().height;
mSubTitle.setPosition(HALF_WIDTH - textMiddleWidth, HALF_HEIGHT - textHeight - 50);
mSubTitleShadow = mSubTitle;
mSubTitleShadow.setFillColor(shadowTitleColor);
mSubTitleShadow.move(4, 4);
}
void CampaignMenu::eventHandler(sf::RenderWindow& window, const sf::Event& event)
{
mButtonNew->update(window);
mButtonContinue->update(window);
if (mButtonNew->isClicked())
{
mChoice = "new";
mIsChoiceDone = true;
}
if (mButtonContinue->isClicked())
{
mChoice = "continue";
mIsChoiceDone = true;
}
if (event.type == sf::Event::Closed)
{
mChoice = "exit";
mIsChoiceDone = true;
}
}
void CampaignMenu::draw(sf::RenderWindow& window)
{
window.clear(backgroundColor);
window.draw(mTitleShadow);
window.draw(mTitle);
window.draw(mSubTitleShadow);
window.draw(mSubTitle);
mButtonNew->draw(window);
if (isCampTable())
mButtonContinue->draw(window);
}
bool CampaignMenu::isCampTable()
{
std::ifstream file(ResourcePath::CAMP_RES());
if (!file.is_open())
return false;
else
return true;
}