Skip to content

Commit c9cfbb2

Browse files
committed
Moved TradingView magic numbers into graphics.conf
1 parent ac27db1 commit c9cfbb2

File tree

6 files changed

+43
-29
lines changed

6 files changed

+43
-29
lines changed

include/Config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class ConfigValue {
1919
ConfigValue& operator=(const ConfigValue&) = default;
2020
ConfigValue& operator=(ConfigValue&&) = default;
2121

22-
operator int() const;
2322
operator float() const;
2423
operator std::string() const;
2524
operator Coordinate() const;

resources/graphics.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,20 @@
22
font.path=resources/ComicNeue-Bold.ttf
33
font.size=50
44

5+
# Trading view screen coordinates
6+
screen.tradingView.bottomLeft=(0.1,0.1)
7+
screen.tradingView.topRight=(0.9,0.9)
8+
9+
screen.tradingView.tradeButton.bottomLeft=(0.7,0.1)
10+
screen.tradingView.tradeButton.topRight=(0.9,0.2)
11+
12+
screen.tradingView.cancelButton.bottomLeft=(0.1,0.1)
13+
screen.tradingView.cancelButton.topRight=(0.3,0.2)
14+
15+
screen.tradingView.resources.height=0.13
16+
screen.tradingView.resources.leftX=0.3
17+
screen.tradingView.resources.rightX=0.6
18+
screen.tradingView.resources.bottomY=0.2
19+
20+
screen.tradingView.players.bottomLeft=(0.1,0.8)
21+
screen.tradingView.players.topRight=(0.9,0.9)

src/Config.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ ConfigValue::ConfigValue(const string& value) : value(value) {
1515

1616
}
1717

18-
ConfigValue::operator int() const {
19-
return fromString<int>(value);
20-
}
21-
2218
ConfigValue::operator float() const {
2319
return fromString<float>(value);
2420
}

src/GameController.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
3535
playerTopY -= 0.05;
3636
}
3737

38-
39-
40-
4138
view.addElement(makeViewButtonColor(std::bind(&GameController::handleCancelButtonEvent, this, _1), {{.95, .95}, {1.0, 1.0}}, std::make_tuple(1.f, 0.0f, 0.f)));
42-
39+
4340
view.addElement(makeViewButtonText(std::bind(&GameController::handleRoadCardButtonEvent, this, _1), {{0.85, 0.0}, {0.97, 0.05}}, font, fontSize, "Road Building "));
4441
view.addElement(makeViewButtonText(std::bind(&GameController::handleKnightCardButtonEvent, this, _1), {{0.85, 0.05}, {0.97, 0.10}}, font, fontSize, "Knight "));
4542
view.addElement(makeViewButtonText(std::bind(&GameController::handleYearOfPlentyCardButtonEvent, this, _1), {{0.85, 0.10}, {0.97, 0.15}}, font, fontSize, "Year of Plenty "));

src/GameView.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,19 @@ void DrawingGameVisitor::visit(DevelopmentCard& card) {
660660
* @param initialOffer The initial offer to display.
661661
*/
662662
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) :
663-
ViewElement({{0.1, 0.1},{0.9, 0.9}}), initiating(initiating), receiving(receiving),
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"),
663+
ViewElement({getGraphicsConfig()["screen.tradingView.bottomLeft"], getGraphicsConfig()["screen.tradingView.topRight"]}),
664+
initiating(initiating),
665+
receiving(receiving),
666+
trade(
667+
std::bind(trade, std::ref(offer), std::placeholders::_1),
668+
{getGraphicsConfig()["screen.tradingView.tradeButton.bottomLeft"], getGraphicsConfig()["screen.tradingView.tradeButton.topRight"]},
669+
getGraphicsConfig()["font.path"], getGraphicsConfig()["font.size"], "Trade"
670+
),
671+
cancel(cancel,
672+
{getGraphicsConfig()["screen.tradingView.cancelButton.bottomLeft"], getGraphicsConfig()["screen.tradingView.cancelButton.topRight"]},
673+
getGraphicsConfig()["font.path"], getGraphicsConfig()["font.size"], "Cancel"
674+
),
666675
offer(initialOffer) {
667-
668676
}
669677

670678
/**
@@ -685,7 +693,7 @@ bool TradingView::clicked(ScreenCoordinate coord) {
685693
return true;
686694
}
687695
int modifier = coord.first <= 0.5 ? -1 : 1;
688-
int resource = (coord.second - 0.2) / 0.13;
696+
int resource = (coord.second - getGraphicsConfig()["screen.tradingView.resources.bottomY"]) / getGraphicsConfig()["screen.tradingView.resources.height"];
689697
if(resource >= 0 && resource <= 5) {
690698
offer[resource] += modifier;
691699
}
@@ -712,10 +720,15 @@ void TradingView::render() {
712720

713721
std::string resources[] = {"Wood", "Brick", "Ore", "Wheat", "Wool"};
714722
for(int i = 0; i < 5; i++) {
715-
auto height = 0.13;
716-
renderText(font, fontSize, {0.3, 0.2 + (i * height)}, {0.6, 0.2 + height + (i * height)}, toString(offer[i]) + " " + resources[i]);
723+
auto leftX = getGraphicsConfig()["screen.tradingView.resources.leftX"];
724+
auto rightX = getGraphicsConfig()["screen.tradingView.resources.rightX"];
725+
auto height = getGraphicsConfig()["screen.tradingView.resources.height"];
726+
auto bottomY = getGraphicsConfig()["screen.tradingView.resources.bottomY"];
727+
renderText(font, fontSize, {leftX, bottomY + (i * height)}, {rightX, bottomY + height + (i * height)}, toString(offer[i]) + " " + resources[i]);
717728
}
718-
renderText(font, fontSize, {0.1, 0.8}, {0.9, 0.9}, initiating.getName() + " -> " + receiving.getName());
729+
auto playersBottomLeft = getGraphicsConfig()["screen.tradingView.players.bottomLeft"];
730+
auto playersTopRight = getGraphicsConfig()["screen.tradingView.players.topRight"];
731+
renderText(font, fontSize, playersBottomLeft, playersTopRight, initiating.getName() + " -> " + receiving.getName());
719732

720733
cancel.render();
721734
trade.render();
@@ -734,10 +747,10 @@ ConfirmationDialogue::ConfirmationDialogue(std::function<bool(ScreenCoordinate)>
734747
ScreenCoordinate confirmBottomRight = ScreenCoordinate(bottomRight.first - (width * .6), bottomRight.second - (height * .6));
735748
ScreenCoordinate cancelTopLeft = ScreenCoordinate(topLeft.first + (width*.6), topLeft.second + (height *.1));
736749
ScreenCoordinate cancelBottomRight = ScreenCoordinate(bottomRight.first - (width * .1), bottomRight.second - (height * .6));
737-
738-
auto font = "resources/ComicNeue-Bold.ttf";
739-
auto fontSize = 50;
740-
750+
751+
auto font = getGraphicsConfig()["font.path"];
752+
auto fontSize = getGraphicsConfig()["font.size"];
753+
741754
confirmButton = std::unique_ptr<ViewElement>(new ViewButtonText(confirm_action, {confirmTopLeft, confirmBottomRight}, font, fontSize, "Yes"));
742755
cancelButton = std::unique_ptr<ViewElement>(new ViewButtonText(cancel_action, {cancelTopLeft, cancelBottomRight}, font, fontSize, "No"));
743756
}

tests/testConfig.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ TEST(readTwoStrings) {
1919
CHECK((string)config["var_b"] == "val_b");
2020
}
2121

22-
TEST(readIntAndString) {
23-
stringstream file("string=hello\nint=5\n");
24-
Config config(file);
25-
26-
CHECK((string)config["string"] == "hello");
27-
CHECK((int)config["int"] == 5);
28-
}
29-
3022
TEST(readFloat) {
3123
stringstream file("float=5.0\n");
3224
Config config(file);

0 commit comments

Comments
 (0)