Civilization
GameWindow.hpp
1 // Generated by dia2code
2 #ifndef CLIENT__GAMEWINDOW__H
3 #define CLIENT__GAMEWINDOW__H
4 
5 #include <memory>
6 #include <vector>
7 #include <string>
8 #include <unordered_map>
9 #include <SFML/Graphics.hpp>
10 #include <array>
11 #include <mutex>
12 #include <json/json.h>
13 
14 namespace client {
15  class ClientGameEngine;
16  class TextureDisplayer;
17  class GraphicCard;
18 };
19 namespace shared {
20  class Map;
21 };
22 namespace client {
23  class Button;
24  class Chat;
25  class PopUpWindow;
26 }
27 
28 #include "TextureDisplayer.hpp"
29 #include "GraphicCard.hpp"
30 #include "shared/Map.hpp"
31 #include "Button.hpp"
32 #include "Chat.hpp"
33 #include "PopUpWindow.hpp"
34 
35 namespace client {
36 
38  class GameWindow {
39  // Associations
40  // Attributes
41  public:
42  ClientGameEngine* gameEnginePtr = nullptr;
43  std::unique_ptr<TextureDisplayer> backgroundTexture;
44  std::vector<TextureDisplayer> mapTextureToDisplay;
45  std::unique_ptr<TextureDisplayer> boxTexture;
46  std::unordered_map<std::string, std::unique_ptr<TextureDisplayer>> elementTextureToDisplay;
47  std::vector<TextureDisplayer> hudTextureToDisplay;
48  std::vector<GraphicCard> priorityCards;
49  std::vector<GraphicCard> actionCardsToDisplay;
50  std::shared_ptr<shared::Map> mapShared = nullptr;
51  sf::Cursor clientCursor;
52  sf::Font titleFont;
53  std::array<int, 2> firstHexagonPosition;
54  std::vector<Button> whoIsPlayingButtons;
55  sf::Font bodyFont;
56  std::unique_ptr<Chat> chatBox;
57  bool isChatOpen = false;
58  std::unique_ptr<PopUpWindow> validateBoxesWindow;
59  std::array<int, 25> techWheelRotation;
60  std::shared_ptr<Button> textForTheUser;
61  std::mutex updatePlayerMutex;
62  std::unique_ptr<Button> endOfRoundButton;
63  std::unique_ptr<PopUpWindow> winnerWindow;
64  // Operations
65  public:
66  GameWindow ();
67  void* menuWindow ();
68  void startGame ();
69  void displayWindow ();
70  void loadMapTexture ();
71  void loadElementTexture ();
72  void loadHudTexture ();
73  void updateElementTexture ();
74  const Json::Value openJsonFile (std::string path);
75  void setUpText (GraphicCard& card, std::string title, std::string body, sf::Font& titleFont, sf::Font& bodyFont, const Json::Value& dataNumber, float titleTextProportion, float bodyTextProportion);
76  bool clickAction (sf::Event& event, sf::Vector2i clickPosition, std::shared_ptr<bool> moveMode);
77  long getCurrentTime (bool timeSecond = true);
78  sf::Vector2i getBoxesElementsPosition (float boxXProportion, float boxYProportion, GraphicCard& priorityCard);
79  bool handleGameEvent (sf::Event& event, sf::Vector2i& clickStartingPoint, std::shared_ptr<bool> moveMode, std::shared_ptr<bool> clickMode);
80  bool handleKeyboardEvent (sf::Event::KeyEvent keyEvent);
81  void moveMap (sf::Vector2i & clickStartingPoint, sf::Vector2i position, bool reset = false);
82  void changeMouseCursor (sf::Event& event, std::shared_ptr<bool> moveMode);
83  bool priorityCardClickAction (sf::Vector2i clickPosition);
84  void moveToRightPriorityCards (int difficulty);
85  void rotateTechWheel (int newLevel);
86  void sendMessage ();
87  bool onHexagonClick (sf::Vector2i clickPosition);
88  void addPlayer (std::string username);
89  void modifyTextForUser (std::string text);
90  int getPlayerNumber (std::string username);
91  void selectElementToDisplay (int x, int y);
92  void setWinnerWindow (std::string winner, std::string causes);
93  // Setters and Getters
94  };
95 
96 };
97 
98 #endif
class ClientGameEngine -
Definition: ClientGameEngine.hpp:34
class GameWindow -
Definition: GameWindow.hpp:38
const Json::Value openJsonFile(std::string path)
Open JSON File.
Definition: GameWindow.cpp:366
void modifyTextForUser(std::string text)
Function to modify the text that is specified at a player.
Definition: GameWindow.cpp:1014
void moveToRightPriorityCards(int difficulty)
Move to right priority cards when a player play one.
Definition: GameWindow.cpp:392
void updateElementTexture()
Update all the textures of the map.
Definition: GameWindow.cpp:725
void moveMap(sf::Vector2i &clickStartingPoint, sf::Vector2i position, bool reset=false)
Move the map on the screen.
Definition: GameWindow.cpp:329
bool clickAction(sf::Event &event, sf::Vector2i clickPosition, std::shared_ptr< bool > moveMode)
Function that deteck where the user click and what to send to the engine.
Definition: GameWindow.cpp:506
bool handleKeyboardEvent(sf::Event::KeyEvent keyEvent)
Test keyboard events and do actions corresponding to the event.
Definition: GameWindow.cpp:257
void setUpText(GraphicCard &card, std::string title, std::string body, sf::Font &titleFont, sf::Font &bodyFont, const Json::Value &dataNumber, float titleTextProportion, float bodyTextProportion)
Display text on the cards.
Definition: GameWindow.cpp:565
bool handleGameEvent(sf::Event &event, sf::Vector2i &clickStartingPoint, std::shared_ptr< bool > moveMode, std::shared_ptr< bool > clickMode)
Test events and do actions corresponding to the event.
Definition: GameWindow.cpp:201
long getCurrentTime(bool timeSecond=true)
Function that deteck where the user click and what to send to the engine.
Definition: GameWindow.cpp:1052
GameWindow()
Constructor.
Definition: GameWindow.cpp:58
void startGame()
Loop that look for events to happend and call displayWindow()
Definition: GameWindow.cpp:152
void changeMouseCursor(sf::Event &event, std::shared_ptr< bool > moveMode)
Change the cursor type to a hand or an arrow.
Definition: GameWindow.cpp:300
bool priorityCardClickAction(sf::Vector2i clickPosition)
Detect when we click on a priority card or on the play button on priorityCard and make the action ass...
Definition: GameWindow.cpp:421
void loadMapTexture()
Load all the textures of the map.
Definition: GameWindow.cpp:662
void displayWindow()
Display all the different variable in the screen.
Definition: GameWindow.cpp:74
sf::Vector2i getBoxesElementsPosition(float boxXProportion, float boxYProportion, GraphicCard &priorityCard)
Get position of number of boxes and boxes on priority cards.
Definition: GameWindow.cpp:838
void loadHudTexture()
Load all the HUD textures.
Definition: GameWindow.cpp:857
void setWinnerWindow(std::string winner, std::string causes)
Function to set the winnee window at the end of the party.
Definition: GameWindow.cpp:1069
void loadElementTexture()
Load all the textures of the elements.
Definition: GameWindow.cpp:690
void sendMessage()
This function send a message to the server.
Definition: GameWindow.cpp:281
class GraphicCard -
Definition: GraphicCard.hpp:22