Skip to content

Commit 5c0c027

Browse files
committed
Merge pull request #35 from Databean/DevCardUI_textButtons
Dev card ui text buttons
2 parents ba25cf5 + 3178108 commit 5c0c027

File tree

6 files changed

+174
-103
lines changed

6 files changed

+174
-103
lines changed

include/GameView.h

Lines changed: 27 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class GameView {
5252
std::vector<ScreenCoordinate> pointsOfInterest;
5353

5454
void highlightPoint(ScreenCoordinate & coord);
55+
void drawCardCount(std::string font, int fontSize);
5556

5657
GameView(const GameView& o) = delete;
5758
GameView& operator=(const GameView& o) = delete;
@@ -144,91 +145,7 @@ class ViewButtonColor : public ViewButton {
144145
virtual void render();
145146
};
146147

147-
template<class Fn>
148-
class ConfirmationDialogue : public ViewElement {
149-
private:
150-
Fn confirm_action;
151-
Fn cancel_action;
152148

153-
bool clickedConfirm(ScreenCoordinate coord);
154-
bool clickedCancel(ScreenCoordinate coord);
155-
ScreenCoordinate topLeft;
156-
ScreenCoordinate bottomRight;
157-
ScreenCoordinate confirmTopLeft;
158-
ScreenCoordinate confirmBottomRight;
159-
ScreenCoordinate cancelTopLeft;
160-
ScreenCoordinate cancelBottomRight;
161-
162-
163-
protected:
164-
virtual bool clicked_confirm(ScreenCoordinate coord){
165-
return confirmTopLeft.first < coord.first &&
166-
confirmTopLeft.second < coord.second &&
167-
coord.first < confirmBottomRight.first &&
168-
coord.second < confirmBottomRight.second;
169-
}
170-
virtual bool clicked_cancel(ScreenCoordinate coord){
171-
return cancelTopLeft.first < coord.first &&
172-
cancelTopLeft.second < coord.second &&
173-
coord.first < cancelBottomRight.first &&
174-
coord.second < cancelBottomRight.second;
175-
}
176-
177-
virtual bool clicked(ScreenCoordinate coord){
178-
if(clicked_confirm(coord)){
179-
confirm_action(coord);
180-
} else if(clicked_cancel(coord)){
181-
cancel_action(coord);
182-
}
183-
return false;
184-
}
185-
186-
public:
187-
ConfirmationDialogue(Fn confirm_action, Fn cancel_action, std::pair<ScreenCoordinate, ScreenCoordinate> rect): ViewElement(rect), confirm_action(confirm_action), cancel_action(cancel_action){
188-
topLeft = ViewElement::getRect().first;
189-
bottomRight = ViewElement::getRect().second;
190-
191-
float width = bottomRight.first - topLeft.first;
192-
float height = bottomRight.second - topLeft.second;
193-
confirmTopLeft = ScreenCoordinate(topLeft.first +(width*.1), topLeft.second+(height*.1));
194-
confirmBottomRight = ScreenCoordinate(bottomRight.first - (width * .6), bottomRight.second - (height * .6));
195-
cancelTopLeft = ScreenCoordinate(topLeft.first + (width*.6), topLeft.second + (height *.1));
196-
cancelBottomRight = ScreenCoordinate(bottomRight.first - (width * .1), bottomRight.second - (height * .6));
197-
198-
}
199-
virtual void render(){
200-
glBindTexture(GL_TEXTURE_2D, 0);
201-
202-
glColor3f(1., 1., 1.);
203-
glBegin(GL_QUADS);
204-
glVertex2f(topLeft.first, topLeft.second);
205-
glVertex2f(bottomRight.first, topLeft.second);
206-
glVertex2f(bottomRight.first, bottomRight.second);
207-
glVertex2f(topLeft.first, bottomRight.second);
208-
glEnd();
209-
210-
glColor3f(0., 1., 0.);
211-
glBegin(GL_QUADS);
212-
glVertex2f(confirmTopLeft.first, confirmTopLeft.second);
213-
glVertex2f(confirmBottomRight.first, confirmTopLeft.second);
214-
glVertex2f(confirmBottomRight.first, confirmBottomRight.second);
215-
glVertex2f(confirmTopLeft.first, confirmBottomRight.second);
216-
glEnd();
217-
218-
glColor3f(1.,0.,0.);
219-
glBegin(GL_QUADS);
220-
glVertex2f(cancelTopLeft.first, cancelTopLeft.second);
221-
glVertex2f(cancelBottomRight.first, cancelTopLeft.second);
222-
glVertex2f(cancelBottomRight.first, cancelBottomRight.second);
223-
glVertex2f(cancelTopLeft.first, cancelBottomRight.second);
224-
glEnd();
225-
}
226-
};
227-
228-
template<class Fn>
229-
std::unique_ptr<ViewElement> makeConfirmationDialogue(Fn confirm_fn, Fn cancel_fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect) {
230-
return std::unique_ptr<ViewElement>(new ConfirmationDialogue<Fn>(confirm_fn, cancel_fn, rect));
231-
}
232149

233150

234151

@@ -298,4 +215,30 @@ class TradingView : public ViewElement {
298215
void render();
299216
};
300217

218+
219+
class ConfirmationDialogue : public ViewElement {
220+
private:
221+
ScreenCoordinate topLeft;
222+
ScreenCoordinate bottomRight;
223+
224+
std::string message;
225+
226+
std::unique_ptr<ViewElement> confirmButton;
227+
std::unique_ptr<ViewElement> cancelButton;
228+
229+
protected:
230+
virtual bool clicked(ScreenCoordinate coord);
231+
232+
public:
233+
ConfirmationDialogue(std::function<bool(ScreenCoordinate)> confirm_action, std::function<bool(ScreenCoordinate)> cancel_action, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::string message);
234+
void render();
235+
};
236+
237+
template<class Fn>
238+
std::unique_ptr<ViewElement> makeConfirmationDialogue(Fn confirm_fn, Fn cancel_fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::string message) {
239+
return std::unique_ptr<ViewElement>(new ConfirmationDialogue(confirm_fn, cancel_fn, rect, message));
240+
}
241+
242+
243+
301244
#endif

include/Util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
typedef std::pair<int, int> Coordinate;
88
typedef std::pair<float, float> ScreenCoordinate;
99

10+
1011
/**
1112
* Converts any instance that has istream& operator>>(istream&, T&) defined from a string to its type.
1213
* @param s The string to read the value from

src/GameBoard.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,12 +907,10 @@ const std::vector<std::unique_ptr<Player>>& GameBoard::getPlayers() const {
907907
}
908908

909909
/**
910-
* WARNING THIS FUNCTION GIVES THE PLAYERS CHEATS SO I COULD DEBUG
911910
* @return reference to the current Player
912911
*/
913912
Player& GameBoard::getCurrentPlayer() const
914913
{
915-
(*players[currentTurn]).giveDevCardBoon();
916914
return *players[currentTurn];
917915
}
918916

src/GameController.cpp

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
GameController::GameController(GameBoard& model, GameView& view) : model(model), view(view) {
1818
using namespace std::placeholders;
1919

20+
view.addElement(makeViewButton(std::bind(&GameController::handleBoardEvent, this, _1), {{0, 0}, {1, 1}}));
2021

2122
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)));
2223
view.addElement(makeViewButtonColor(std::bind(&GameController::handleRoadButtonEvent, this, _1), {{0, 0}, {0.1, 0.1}}, std::make_tuple(1.f, 0.f, 0.f)));
2324
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)));
2425

25-
view.addElement(makeViewButton(std::bind(&GameController::handleBoardEvent, this, _1), {{0, 0}, {1, 1}}));
26-
2726
auto font = "resources/TypeWritersSubstitute-Black.ttf";
2827
auto fontSize = 50;
2928

@@ -41,11 +40,12 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
4140

4241
view.addElement(makeViewButtonColor(std::bind(&GameController::handleCancelButtonEvent, this, _1), {{.95, .95}, {1.0, 1.0}}, std::make_tuple(1.f, 0.0f, 0.f)));
4342

44-
view.addElement(makeViewButtonColor(std::bind(&GameController::handleRoadCardButtonEvent, this, _1), {{.2, 0}, {.3, .05}}, std::make_tuple(1.f, 0.0f, 0.f)));
45-
view.addElement(makeViewButtonColor(std::bind(&GameController::handleKnightCardButtonEvent, this, _1), {{0.3, 0}, {.4, .05}}, std::make_tuple(0.f, 0.0f, 0.f)));
46-
view.addElement(makeViewButtonColor(std::bind(&GameController::handleYearOfPlentyCardButtonEvent, this, _1), {{0.4, 0}, {.5, .05}}, std::make_tuple(1.f, 1.0f, 0.f)));
47-
view.addElement(makeViewButtonColor(std::bind(&GameController::handleMonopolyCardButtonEvent, this, _1), {{0.5, 0}, {.6, .05}}, std::make_tuple(1.f, 0.0f, 1.f)));
48-
view.addElement(makeViewButtonColor(std::bind(&GameController::handleVictoryPointCardButtonEvent, this, _1), {{0.6, 0}, {.7, .05}}, std::make_tuple(0.f, 1.0f, 1.f)));
43+
view.addElement(makeViewButtonText(std::bind(&GameController::handleRoadCardButtonEvent, this, _1), {{0.85, 0.0}, {0.97, 0.05}}, font, fontSize, "Road Building "));
44+
view.addElement(makeViewButtonText(std::bind(&GameController::handleKnightCardButtonEvent, this, _1), {{0.85, 0.05}, {0.97, 0.10}}, font, fontSize, "Knight "));
45+
view.addElement(makeViewButtonText(std::bind(&GameController::handleYearOfPlentyCardButtonEvent, this, _1), {{0.85, 0.10}, {0.97, 0.15}}, font, fontSize, "Year of Plenty "));
46+
view.addElement(makeViewButtonText(std::bind(&GameController::handleMonopolyCardButtonEvent, this, _1), {{0.85, 0.15}, {0.97, 0.20}}, font, fontSize, "Monopoly "));
47+
view.addElement(makeViewButtonText(std::bind(&GameController::handleVictoryPointCardButtonEvent, this, _1), {{0.85, 0.20}, {0.97, 0.25}}, font, fontSize, "Victory Point "));
48+
4949

5050

5151
stateStack.push_back(BASESTATE);
@@ -157,7 +157,6 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
157157

158158
switch (getState()){
159159
case BUILDROAD:
160-
std::cout << "BUILDROAD\n";
161160
if(!hasClickHistory()) {
162161
storeClick(coord);
163162
} else {
@@ -178,7 +177,8 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
178177
using namespace std::placeholders;
179178
view.addElement(28, makeConfirmationDialogue(
180179
std::bind(&GameController::handleConfirmRoadCard, this, _1),
181-
std::bind(&GameController::handleCancelDialogueEvent, this, _1), {{.2, .3}, {.8, .6}}));
180+
std::bind(&GameController::handleCancelDialogueEvent, this, _1), {{.2, .3}, {.8, .6}},
181+
"Use road building card on these points?"));
182182
pushState(MODALSTATE);
183183
}
184184
break;
@@ -209,6 +209,10 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
209209
return true;
210210
}
211211

212+
/**
213+
* Handles the event when the cancel button in the top right corner of the screen is pressed. This will
214+
* reset the control state back to the base state.
215+
*/
212216
bool GameController::handleCancelButtonEvent(ScreenCoordinate){
213217
while(getState() != BASESTATE){
214218
popState();
@@ -235,7 +239,7 @@ bool GameController::handleRoadButtonEvent(ScreenCoordinate coord) {
235239
/**
236240
* Handles a click on the "create settlement" button. Changes the internal state to indicate the user is going to be making roads on the board.
237241
* @param coord The place the user clicked on screen.
238-
* @return Whether thi sevent was handled by this element. Always true.
242+
* @return Whether this event was handled by this element. Always true.
239243
*/
240244
bool GameController::handleSettlementButtonEvent(ScreenCoordinate coord) {
241245
if(getState() != BASESTATE){
@@ -245,6 +249,12 @@ bool GameController::handleSettlementButtonEvent(ScreenCoordinate coord) {
245249
return true;
246250
}
247251

252+
253+
/**
254+
* Handles a click on the road Building Card button. This changes the control state to indicate the user is going to be building roads on the board.
255+
* @param coord The place the user clicked on the screen
256+
* @return whether this event was handles by this element. Always true.
257+
*/
248258
bool GameController::handleRoadCardButtonEvent(ScreenCoordinate coord){
249259
if(getState() != BASESTATE){
250260
return true;
@@ -254,42 +264,73 @@ bool GameController::handleRoadCardButtonEvent(ScreenCoordinate coord){
254264
return true;
255265
}
256266

267+
/**
268+
* Handles a click on the confirm button in the confirmation dialogues for the Road Building Card. This will attempt to place the roads the
269+
* user chose and clear the control state.
270+
* @param coord The place the user clicked on the screen
271+
* @return true
272+
*/
257273
bool GameController::handleConfirmRoadCard(ScreenCoordinate coord){
258274
model.getCurrentPlayer().playRoadBuilding(getPastClick(3), getPastClick(2), getPastClick(1), getPastClick(0));
259275
view.removeElement(28);
260276
return handleCancelButtonEvent(coord);
261277
}
262278

279+
/**
280+
* Handles a click on the cancel button in the confrimation dialogue for the Road Building Card. This will clear the control state back to default.
281+
* @param coord The place the user clicked on the screen
282+
* @return true
283+
*/
263284
bool GameController::handleCancelDialogueEvent(ScreenCoordinate coord){
264285
view.removeElement(28);
265286
return handleCancelButtonEvent(coord);
266287
}
267288

268-
269-
bool GameController::handleKnightCardButtonEvent(ScreenCoordinate){
289+
/**
290+
* Handles a click on the Knight Card button.
291+
* @param coord The place the user clicked
292+
* @return true
293+
*/
294+
bool GameController::handleKnightCardButtonEvent(ScreenCoordinate coord){
270295
if(getState() != BASESTATE){
271296
return true;
272297
}
273298
pushState(KNIGHT_DEVCARD);
274299
return true;
275300
}
276301

277-
bool GameController::handleYearOfPlentyCardButtonEvent(ScreenCoordinate){
302+
/**
303+
* Handles a click on the Year of Plenty Card button
304+
* @param coord The place the user clicked
305+
* @return true
306+
*/
307+
bool GameController::handleYearOfPlentyCardButtonEvent(ScreenCoordinate coord){
278308
if(getState() != BASESTATE){
279309
return true;
280310
}
281311
pushState(YEAROFPLENTY_DEVCARD);
282312
return true;
283313
}
284-
bool GameController::handleMonopolyCardButtonEvent(ScreenCoordinate){
314+
315+
/**
316+
* Handles a click on the Monopoly Card Button
317+
* @param coord The place the user clicked
318+
* @return true;
319+
*/
320+
bool GameController::handleMonopolyCardButtonEvent(ScreenCoordinate coord){
285321
if(getState() != BASESTATE){
286322
return true;
287323
}
288324
pushState(MONOPOLY_DEVCARD);
289325
return true;
290326
}
291327

292-
bool GameController::handleVictoryPointCardButtonEvent(ScreenCoordinate){
328+
/**
329+
* Handles a click on the VictoryPoint card button. Will push the victory point card state to the control stack
330+
* @param coord The place the user clicked
331+
* @return true
332+
*/
333+
bool GameController::handleVictoryPointCardButtonEvent(ScreenCoordinate coord){
293334
if(getState() != BASESTATE){
294335
return true;
295336
}

0 commit comments

Comments
 (0)