Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ur_ui_view.hpp
Go to the documentation of this file.
1
11
12#ifndef ZOAPPURUIVIEW_H
13#define ZOAPPURUIVIEW_H
14
15#include <toymaker/engine/sim_system.hpp>
16
17#include <toymaker/builtins/ui_text.hpp>
18
20
28class UrUIView: public ToyMaker::SimObjectAspect<UrUIView> {
29public:
30 UrUIView(): ToyMaker::SimObjectAspect<UrUIView>{0} {}
31
32 inline static std::string getSimObjectAspectTypeName() { return "UrUIView"; }
33 static std::shared_ptr<BaseSimObjectAspect> create(const nlohmann::json& jsonAspectProperties);
34 std::shared_ptr<BaseSimObjectAspect> clone() const override;
35
36 void onActivated() override;
37 void variableUpdate(uint32_t timeStep) override;
38 const GameOfUrModel& getModel() const;
39
40private:
41 enum Buttons {
42 SWALLOW=PieceTypeID::SWALLOW,
43 STORMBIRD=PieceTypeID::STORMBIRD,
44 RAVEN=PieceTypeID::RAVEN,
45 ROOSTER=PieceTypeID::ROOSTER,
46 EAGLE=PieceTypeID::EAGLE,
47
48 NEXT_TURN,
49 DICE,
50 };
51
52 enum class Mode {
53 INTERACT,
54 TRANSITION,
55 };
56
57 std::weak_ptr<ToyMaker::SimObject> mGameOfUrController {};
58 std::string mControllerPath {};
59 PlayerID mControlledBy {};
60 Mode mMode { Mode::INTERACT };
61 std::vector<std::reference_wrapper<ToyMaker::UIText>> mUpdatedTextElements {};
62 uint32_t mAnimationTimeMillis { 0 };
63 uint32_t mBlinkLengthMillis { 2500 };
64 uint32_t mBlinkPeriodMillis { 400 };
65
66 static const std::map<std::string, Buttons> kButtonEnumMap;
67
68 void onControllerReady();
69
70 void updateText(const std::string& path, const std::string& text);
71 void reactivateControls();
72
73 void onButtonClicked(const std::string& button);
74 void onButtonHoveredOver(const std::string& button);
75 void onPhaseUpdated(GamePhaseData phase);
76 void onScoreUpdated(GameScoreData score);
77 void onPlayerUpdated(PlayerData player);
78 void onDiceUpdated(DiceData dice);
79 void onViewUpdateStarted();
80 void onMoveMade(MoveResultData moveData);
81 void onControlInterface(PlayerID playerID);
82 bool onCancel(const ToyMaker::ActionData& actionData, const ToyMaker::ActionDefinition& actionDefinition);
83
84 std::shared_ptr<ToyMaker::SimObject> getLaunchButton(PieceTypeID pieceTypeID, PlayerID player);
85 std::shared_ptr<ToyMaker::SceneNode> getPlayerPanel(PlayerID player);
86 std::shared_ptr<ToyMaker::SimObject> getEndTurnButton();
87
88 std::weak_ptr<ToyMaker::FixedActionBinding> handleCancel { declareFixedActionBinding(
89 "General", "Cancel", [this](const ToyMaker::ActionData& actionData, const ToyMaker::ActionDefinition& actionDefinition) {
90 return this->onCancel(actionData, actionDefinition);
91 }
92 )};
93public:
94 ToyMaker::SignalObserver<const std::string&> mObserveButtonClicked {
95 *this, "ButtonClickedObserved",
96 [this](const std::string& button) { this->onButtonClicked(button); }
97 };
98
99 ToyMaker::SignalObserver<const std::string&> mObserveButtonHoveredOver {
100 *this, "ButtonHoveredOverObserved",
101 [this](const std::string& button) { this->onButtonHoveredOver(button); }
102 };
103
104 ToyMaker::SignalObserver<GamePhaseData> mObservePhaseUpdated {
105 *this, "PhaseUpdatedObserved",
106 [this](GamePhaseData phaseData) { this->onPhaseUpdated(phaseData); }
107 };
108 ToyMaker::SignalObserver<GameScoreData> mObserveScoreUpdated {
109 *this, "ScoreUpdatedObserved",
110 [this](GameScoreData scoreData) { this->onScoreUpdated(scoreData); }
111 };
112 ToyMaker::SignalObserver<PlayerData> mObservePlayerUpdated {
113 *this, "PlayerUpdatedObserved",
114 [this](PlayerData playerData) { this->onPlayerUpdated(playerData); }
115 };
116 ToyMaker::SignalObserver<DiceData> mObserveDiceUpdated {
117 *this, "DiceUpdatedObserved",
118 [this](DiceData diceData) { this->onDiceUpdated(diceData); }
119 };
120 ToyMaker::SignalObserver<MoveResultData> mObserveMoveMade {
121 *this, "MoveMadeObserved",
122 [this](MoveResultData moveData) { this->onMoveMade(moveData); }
123 };
124
125 ToyMaker::SignalObserver<PlayerID> mObserveControlInterface {
126 *this, "ControlInterfaceObserved",
127 [this](PlayerID playerID) { this->onControlInterface(playerID); }
128 };
129
130 ToyMaker::Signal<> mSigDiceRollAttempted { *this, "DiceRollAttempted" };
131 ToyMaker::Signal<> mSigNextTurnAttempted { *this, "NextTurnAttempted" };
132 ToyMaker::Signal<PieceTypeID> mSigLaunchPieceInitiated { *this, "LaunchPieceInitiated" };
133 ToyMaker::Signal<PieceTypeID> mSigLaunchPieceHovered { *this, "LaunchPieceHovered" };
134 ToyMaker::Signal<> mSigLaunchPieceCanceled { *this, "LaunchPieceCanceled" };
135
136 ToyMaker::SignalObserver<> mObserveControllerReady {
137 *this, "ControllerReadyObserved",
138 [this]() {this->onControllerReady();}
139 };
140 ToyMaker::Signal<std::string> mSigViewSubscribed {*this, "ViewSubscribed"};
141
142 ToyMaker::SignalObserver<> mObserveViewUpdateStarted {
143 *this, "ViewUpdateStartedObserved",
144 [this](){ this->onViewUpdateStarted(); }
145 };
146 ToyMaker::Signal<std::string> mSigViewUpdateCompleted {
147 *this, "ViewUpdateCompleted"
148 };
149};
150
151#endif
The data model representing one instance of Game of Ur.
Definition model.hpp:343
PieceTypeID
Enum listing the different types of pieces present in the game.
Definition piece_type_id.hpp:22
PlayerID
The two players playing the game, as known to GameOfUrModel.
Definition model.hpp:40
The class containing the interface to the data model for the whole game (Game of Ur).
Data returned by GameOfUrModel when queried for dice related information.
Definition model.hpp:192
Data returned by GameOfUrModel when queried about the current phase of the game.
Definition model.hpp:112
Data returned by GameOfUrModel when queried for scores.
Definition model.hpp:151
Data returned by the GameOfUrModel when making a move, or querying possible moves.
Definition model.hpp:278
Data returned by GameOfUrModel when queried about a player.
Definition model.hpp:229