-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatBoardBase.cpp
More file actions
122 lines (107 loc) · 3.21 KB
/
StatBoardBase.cpp
File metadata and controls
122 lines (107 loc) · 3.21 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
#include "StatBoardBase.h"
#include "Constants.h"
StatBoardBase::StatBoardBase(const std::string& fileRes) :
mGradientLeft(sf::Quads, 4),
mGradientRight(sf::Quads, 4),
mPanelOutlineLeft(),
mPanelOutlineRight(),
mFont(FontManager::GetFont()),
mTexts(),
mStatus(),
mOffsetY(300),
mFontSizeLeft(40),
mPtrTableResults(std::make_unique<TableResults>(fileRes)),
mNames(),
mResults(),
mNamesPosX((WIDTH - MARGIN_WIDTH) + 40),
mResultsPosX((WIDTH - MARGIN_WIDTH) + 250),
mRightOffsetY(29),
mFontSizeRight(16),
mPosResult(30),
mNewName(),
mNewResult(),
initTempNameResult(false)
{
createPanels("left");
createPanels("right");
createLeftSide();
}
void StatBoardBase::createPanels(const std::string& side)
{
sf::Vector2f panelPosition;
sf::Vector2f panelSize;
sf::Color topColor, bottomColor;
sf::VertexArray& gradient = (side == "left") ? mGradientLeft : mGradientRight;
sf::RectangleShape& panelOutline = (side == "left") ? mPanelOutlineLeft : mPanelOutlineRight;
if (side == "left")
{
panelPosition = { 20.f, 80.f };
panelSize = { 360.f, 880.f };
topColor = sf::Color(8, 98, 159);
bottomColor = sf::Color(0, 50, 120);
}
else if (side == "right")
{
panelPosition = { 820.f, 80.f };
panelSize = { 360.f, 880.f };
topColor = sf::Color(20, 110, 180);
bottomColor = sf::Color(0, 60, 140);
}
gradient.setPrimitiveType(sf::Quads);
gradient.resize(4);
gradient[0].position = panelPosition;
gradient[1].position = sf::Vector2f(panelPosition.x + panelSize.x, panelPosition.y);
gradient[2].position = sf::Vector2f(panelPosition.x + panelSize.x, panelPosition.y + panelSize.y);
gradient[3].position = sf::Vector2f(panelPosition.x, panelPosition.y + panelSize.y);
gradient[0].color = topColor;
gradient[1].color = topColor;
gradient[2].color = bottomColor;
gradient[3].color = bottomColor;
panelOutline.setSize(panelSize);
panelOutline.setPosition(panelPosition);
panelOutline.setFillColor(sf::Color::Transparent);
panelOutline.setOutlineColor(sf::Color::White);
panelOutline.setOutlineThickness(2.f);
}
void StatBoardBase::createLeftSide()
{
for (size_t i = 0; i < mStatus.size(); ++i)
{
sf::Text text(mStatus[i], mFont, mFontSizeLeft);
float textMiddleWidth = text.getLocalBounds().width / 2;
text.setPosition(MARGIN_WIDTH / 2 - textMiddleWidth, MARGIN_HEIGHT + i * mOffsetY);
text.setFillColor(sf::Color::Yellow);
mTexts.push_back(text);
}
}
void StatBoardBase::putText(std::vector<std::string>& messages, float pos_x, std::vector<sf::Text>& texts)
{
for (size_t i = 0; i < TABLE_SIZE; ++i)
{
sf::Text text(messages[i], mFont, mFontSizeRight);
text.setPosition(pos_x, MARGIN_HEIGHT + 10 + i * mRightOffsetY);
if (i < 3)
text.setFillColor(top3Color);
else if (i >= 3 && i < 10)
text.setFillColor(top10Color);
else
text.setFillColor(top2030Color);
if (i == mPosResult)
text.setFillColor(sf::Color::Black);
texts.push_back(text);
}
}
void StatBoardBase::drawPanelsAndTexts(sf::RenderWindow& window)
{
window.draw(mGradientLeft);
window.draw(mPanelOutlineLeft);
window.draw(mGradientRight);
window.draw(mPanelOutlineRight);
for (auto& text : mTexts)
window.draw(text);
for (size_t i = 0; i < mNames.size(); ++i)
{
window.draw(mNames[i]);
window.draw(mResults[i]);
}
}