Skip to content

Commit 6d9d1b8

Browse files
committed
Editing the buttons for development cards to be textual, and I changed
the confirmation dialogue to be text based as well. Will now also display the current Player's number of development cards.
1 parent ba25cf5 commit 6d9d1b8

File tree

6 files changed

+173
-100
lines changed

6 files changed

+173
-100
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: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
4141

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

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)));
44+
view.addElement(makeViewButtonText(std::bind(&GameController::handleRoadCardButtonEvent, this, _1), {{0.85, 0.0}, {0.97, 0.05}}, font, fontSize, "Road Building "));
45+
view.addElement(makeViewButtonText(std::bind(&GameController::handleKnightCardButtonEvent, this, _1), {{0.85, 0.05}, {0.97, 0.10}}, font, fontSize, "Knight "));
46+
view.addElement(makeViewButtonText(std::bind(&GameController::handleYearOfPlentyCardButtonEvent, this, _1), {{0.85, 0.10}, {0.97, 0.15}}, font, fontSize, "Year of Plenty "));
47+
view.addElement(makeViewButtonText(std::bind(&GameController::handleMonopolyCardButtonEvent, this, _1), {{0.85, 0.15}, {0.97, 0.20}}, font, fontSize, "Monopoly "));
48+
view.addElement(makeViewButtonText(std::bind(&GameController::handleVictoryPointCardButtonEvent, this, _1), {{0.85, 0.20}, {0.97, 0.25}}, font, fontSize, "Victory Point "));
49+
4950

5051

5152
stateStack.push_back(BASESTATE);
@@ -178,7 +179,8 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
178179
using namespace std::placeholders;
179180
view.addElement(28, makeConfirmationDialogue(
180181
std::bind(&GameController::handleConfirmRoadCard, this, _1),
181-
std::bind(&GameController::handleCancelDialogueEvent, this, _1), {{.2, .3}, {.8, .6}}));
182+
std::bind(&GameController::handleCancelDialogueEvent, this, _1), {{.2, .3}, {.8, .6}},
183+
"Use road building card on these points?"));
182184
pushState(MODALSTATE);
183185
}
184186
break;
@@ -209,6 +211,10 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
209211
return true;
210212
}
211213

214+
/**
215+
* Handles the event when the cancel button in the top right corner of the screen is pressed. This will
216+
* reset the control state back to the base state.
217+
*/
212218
bool GameController::handleCancelButtonEvent(ScreenCoordinate){
213219
while(getState() != BASESTATE){
214220
popState();
@@ -235,7 +241,7 @@ bool GameController::handleRoadButtonEvent(ScreenCoordinate coord) {
235241
/**
236242
* 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.
237243
* @param coord The place the user clicked on screen.
238-
* @return Whether thi sevent was handled by this element. Always true.
244+
* @return Whether this event was handled by this element. Always true.
239245
*/
240246
bool GameController::handleSettlementButtonEvent(ScreenCoordinate coord) {
241247
if(getState() != BASESTATE){
@@ -245,6 +251,12 @@ bool GameController::handleSettlementButtonEvent(ScreenCoordinate coord) {
245251
return true;
246252
}
247253

254+
255+
/**
256+
* 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.
257+
* @param coord The place the user clicked on the screen
258+
* @return whether this event was handles by this element. Always true.
259+
*/
248260
bool GameController::handleRoadCardButtonEvent(ScreenCoordinate coord){
249261
if(getState() != BASESTATE){
250262
return true;
@@ -254,42 +266,73 @@ bool GameController::handleRoadCardButtonEvent(ScreenCoordinate coord){
254266
return true;
255267
}
256268

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

281+
/**
282+
* 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.
283+
* @param coord The place the user clicked on the screen
284+
* @return true
285+
*/
263286
bool GameController::handleCancelDialogueEvent(ScreenCoordinate coord){
264287
view.removeElement(28);
265288
return handleCancelButtonEvent(coord);
266289
}
267290

268-
269-
bool GameController::handleKnightCardButtonEvent(ScreenCoordinate){
291+
/**
292+
* Handles a click on the Knight Card button.
293+
* @param coord The place the user clicked
294+
* @return true
295+
*/
296+
bool GameController::handleKnightCardButtonEvent(ScreenCoordinate coord){
270297
if(getState() != BASESTATE){
271298
return true;
272299
}
273300
pushState(KNIGHT_DEVCARD);
274301
return true;
275302
}
276303

277-
bool GameController::handleYearOfPlentyCardButtonEvent(ScreenCoordinate){
304+
/**
305+
* Handles a click on the Year of Plenty Card button
306+
* @param coord The place the user clicked
307+
* @return true
308+
*/
309+
bool GameController::handleYearOfPlentyCardButtonEvent(ScreenCoordinate coord){
278310
if(getState() != BASESTATE){
279311
return true;
280312
}
281313
pushState(YEAROFPLENTY_DEVCARD);
282314
return true;
283315
}
284-
bool GameController::handleMonopolyCardButtonEvent(ScreenCoordinate){
316+
317+
/**
318+
* Handles a click on the Monopoly Card Button
319+
* @param coord The place the user clicked
320+
* @return true;
321+
*/
322+
bool GameController::handleMonopolyCardButtonEvent(ScreenCoordinate coord){
285323
if(getState() != BASESTATE){
286324
return true;
287325
}
288326
pushState(MONOPOLY_DEVCARD);
289327
return true;
290328
}
291329

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

0 commit comments

Comments
 (0)