Skip to content

Commit fb34024

Browse files
committed
Moved some of the magic numbers into graphics.conf
1 parent 14fafa9 commit fb34024

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

resources/graphics.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ font.size=50
66
screen.width=1280
77
screen.height=720
88

9+
# Buttons
10+
screen.roadButton.text=Road |
11+
screen.roadButton.area=((0, 0),(0.1,0.1))
12+
13+
screen.cityButton.text=City |
14+
screen.cityButton.area=((0.1,0),(0.2,0.1))
15+
16+
screen.settlementButton.text=Settlement
17+
screen.settlementButton.area=((0.20, 0.0),(0.33, 0.1))
18+
19+
screen.wonderButton.text=|Wonder
20+
screen.wonderButton.area=((0.55, 0.0),(0.65, 0.1))
21+
22+
screen.endTurnButton.text=End Turn
23+
screen.endTurnButton.area=((0, 0.3),(0.1, 0.4))
24+
25+
screen.players.topY=0.82
26+
screen.players.width=0.15
27+
screen.players.height=0.05
28+
screen.players.right=1.0
29+
30+
screen.bankButton.text=Bank
31+
screen.bankButton.area=((0,0.8),(0.1,0.9))
32+
933
# Trading view screen coordinates
1034
screen.tradingView.bottomLeft=(0.1,0.1)
1135
screen.tradingView.topRight=(0.9,0.9)

src/GameController.cpp

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,45 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
2121
auto font = getGraphicsConfig()["font.path"];
2222
auto fontSize = getGraphicsConfig()["font.size"];
2323

24-
view.addElement(makeViewButtonText(std::bind(&GameController::handleRoadButtonEvent, this, _1), {{0, 0}, {0.1, 0.10}}, font, fontSize, "Road |"));
25-
view.addElement(makeViewButtonText(std::bind(&GameController::handleCityButtonEvent, this, _1), {{0.10, 0.0}, {0.20, 0.1}}, font, fontSize, "City |"));
26-
view.addElement(makeViewButtonText(std::bind(&GameController::handleSettlementButtonEvent, this, _1), {{0.20, 0.0}, {0.33, 0.1}}, font, fontSize, "Settlement"));
27-
view.addElement(makeViewButtonText(std::bind(&GameController::handleWonderButtonEvent, this, _1), {{0.55, 0.0}, {0.65, 0.1}}, font, fontSize, "|Wonder"));
28-
view.addElement(makeViewButtonText(std::bind(&GameController::nextTurn, this, _1), {{0, 0.3}, {0.1, 0.4}}, font, fontSize, "End Turn"));
24+
view.addElement(makeViewButtonText(
25+
std::bind(&GameController::handleRoadButtonEvent, this, _1),
26+
getGraphicsConfig()["screen.roadButton.area"],
27+
font, fontSize, getGraphicsConfig()["screen.roadButton.text"]));
2928

30-
auto playerTopY = 0.82;
29+
view.addElement(makeViewButtonText(
30+
std::bind(&GameController::handleCityButtonEvent, this, _1),
31+
getGraphicsConfig()["screen.cityButton.area"],
32+
font, fontSize, getGraphicsConfig()["screen.cityButton.text"]));
33+
34+
view.addElement(makeViewButtonText(
35+
std::bind(&GameController::handleSettlementButtonEvent, this, _1),
36+
getGraphicsConfig()["screen.settlementButton.area"],
37+
font, fontSize, getGraphicsConfig()["screen.settlementButton.text"]));
38+
39+
view.addElement(makeViewButtonText(
40+
std::bind(&GameController::handleWonderButtonEvent, this, _1),
41+
getGraphicsConfig()["screen.wonderButton.area"],
42+
font, fontSize, getGraphicsConfig()["screen.wonderButton.text"]));
43+
44+
view.addElement(makeViewButtonText(
45+
std::bind(&GameController::nextTurn, this, _1),
46+
getGraphicsConfig()["screen.endTurnButton.area"],
47+
font, fontSize, "End Turn"));
48+
49+
float playerY = getGraphicsConfig()["screen.players.topY"];
3150
for(auto i = 0; i < model.getNoOfPlayers(); i++) {
32-
auto width = 0.15;
51+
float right = getGraphicsConfig()["screen.players.right"];
52+
float width = getGraphicsConfig()["screen.players.width"];
53+
float height = getGraphicsConfig()["screen.players.height"];
3354
Player& player = model.getPlayer(i);
34-
view.addElement(makeViewButtonText(std::bind(&GameController::handlePlayerClick, this, _1, std::ref(player)), {{1.0 - width, playerTopY - 0.05}, {1.0, playerTopY}}, font, fontSize, player.getName()));
35-
playerTopY -= 0.05;
55+
view.addElement(makeViewButtonText(std::bind(&GameController::handlePlayerClick, this, _1, std::ref(player)), {{right - width, playerY - height}, {right, playerY}}, font, fontSize, player.getName()));
56+
playerY -= height;
3657
}
37-
view.addElement(makeViewButtonText(std::bind(&GameController::handleBankClick, this, _1), {{0, 0.8}, {0.1, 0.9}}, font, fontSize, "Bank"));
58+
59+
view.addElement(makeViewButtonText(
60+
std::bind(&GameController::handleBankClick, this, _1),
61+
getGraphicsConfig()["screen.bankButton.area"],
62+
font, fontSize, getGraphicsConfig()["screen.bankButton.text"]));
3863

3964
view.addElement(makeViewButtonText(std::bind(&GameController::handleCancelButtonEvent, this, _1), {{.92, .96}, {1.0, 1.0}}, font, fontSize, "Cancel"));
4065

0 commit comments

Comments
 (0)