Skip to content

Commit ac27db1

Browse files
committed
Storing font information in the config
1 parent 6e762c7 commit ac27db1

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

resources/graphics.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Font settings
2+
font.path=resources/ComicNeue-Bold.ttf
3+
font.size=50
4+

src/GameController.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <functional>
55
#include <memory>
66

7+
#include "Config.h"
78
#include "GameBoard.h"
89
#include "GameView.h"
910
#include "Renderer.h"
@@ -22,11 +23,10 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
2223
view.addElement(makeViewButtonColor(std::bind(&GameController::nextTurn, this, _1), {{0, 0.2}, {0.1, 0.3}}, std::make_tuple(0.f, 0.f, 1.f)));
2324
view.addElement(makeViewButtonColor(std::bind(&GameController::handleRoadButtonEvent, this, _1), {{0, 0}, {0.1, 0.1}}, std::make_tuple(1.f, 0.f, 0.f)));
2425
view.addElement(makeViewButtonColor(std::bind(&GameController::handleSettlementButtonEvent, this, _1), {{0, 0.1}, {0.1, 0.2}}, std::make_tuple(0.f, 1.0f, 0.f)));
25-
26-
auto font = "resources/ComicNeue-Bold.ttf";
27-
auto fontSize = 50;
2826

29-
27+
auto font = getGraphicsConfig()["font.path"];
28+
auto fontSize = getGraphicsConfig()["font.size"];
29+
3030
auto playerTopY = 0.9;
3131
for(auto i = 0; i < model.getNoOfPlayers(); i++) {
3232
auto width = 0.15;

src/GameView.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stdexcept>
66
#include <cmath>
77

8+
#include "Config.h"
89
#include "GameBoard.h"
910
#include "GameController.h"
1011
#include "Renderer.h"
@@ -135,9 +136,9 @@ void GameView::render() {
135136
highlightPoint(it);
136137
}
137138

138-
auto font = "resources/ComicNeue-Bold.ttf";
139-
auto fontSize = 50;
140-
139+
auto font = getGraphicsConfig()["font.path"];
140+
auto fontSize = getGraphicsConfig()["font.size"];
141+
141142
glColor3d(1, 1, 1);
142143
renderText(font, fontSize, {.2, .9}, {.8, 1}, "Settlers of Catan");
143144

@@ -660,8 +661,8 @@ void DrawingGameVisitor::visit(DevelopmentCard& card) {
660661
*/
661662
TradingView::TradingView(Player& initiating, Player& receiving, std::function<bool(std::array<int, 5>, ScreenCoordinate)> trade, std::function<bool(ScreenCoordinate)> cancel, std::array<int, 5> initialOffer) :
662663
ViewElement({{0.1, 0.1},{0.9, 0.9}}), initiating(initiating), receiving(receiving),
663-
trade(std::bind(trade, std::ref(offer), std::placeholders::_1), {{0.7, 0.1}, {0.9, 0.2}}, "resources/ComicNeue-Bold.ttf", 50, "Trade"),
664-
cancel(cancel, {{0.1, 0.1}, {0.3, 0.2}}, "resources/ComicNeue-Bold.ttf", 50, "Cancel"),
664+
trade(std::bind(trade, std::ref(offer), std::placeholders::_1), {{0.7, 0.1}, {0.9, 0.2}}, getGraphicsConfig()["font.path"], getGraphicsConfig()["font.size"], "Trade"),
665+
cancel(cancel, {{0.1, 0.1}, {0.3, 0.2}}, getGraphicsConfig()["font.path"], getGraphicsConfig()["font.size"], "Cancel"),
665666
offer(initialOffer) {
666667

667668
}
@@ -706,8 +707,8 @@ void TradingView::render() {
706707
glVertex2f(topLeft.first, bottomRight.second);
707708
glEnd();
708709

709-
auto font = "resources/ComicNeue-Bold.ttf";
710-
auto fontSize = 50;
710+
auto font = getGraphicsConfig()["font.path"];
711+
auto fontSize = getGraphicsConfig()["font.size"];
711712

712713
std::string resources[] = {"Wood", "Brick", "Ore", "Wheat", "Wool"};
713714
for(int i = 0; i < 5; i++) {
@@ -760,9 +761,10 @@ void ConfirmationDialogue::render(){
760761
glVertex2f(bottomRight.first, bottomRight.second);
761762
glVertex2f(topLeft.first, bottomRight.second);
762763
glEnd();
763-
764-
auto font = "resources/ComicNeue-Bold.ttf";
765-
auto fontSize = 50;
764+
765+
auto font = getGraphicsConfig()["font.path"];
766+
auto fontSize = getGraphicsConfig()["font.size"];
767+
766768
float width = bottomRight.first - topLeft.first;
767769
float height = bottomRight.second - topLeft.second;
768770

tests/testRenderer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include "UnitTest++.h"
44
#include "Renderer.h"
55

6-
using std::cout;
7-
using std::endl;
86
using std::make_pair;
97

108
TEST(coordToScreen) {

0 commit comments

Comments
 (0)