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/sim_system.hpp"
16#include "toymaker/signals.hpp"
17#include "toymaker/text_render.hpp"
18
20
28class UrUIView: public ToyMaker::SimObjectAspect<UrUIView> {
29public:
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<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 onPhaseUpdated(GamePhaseData phase);
75 void onScoreUpdated(GameScoreData score);
76 void onPlayerUpdated(PlayerData player);
77 void onDiceUpdated(DiceData dice);
78 void onViewUpdateStarted();
79 void onMoveMade(MoveResultData moveData);
80 void onControlInterface(PlayerID playerID);
81 bool onCancel(const ToyMaker::ActionData& actionData, const ToyMaker::ActionDefinition& actionDefinition);
82
83 std::shared_ptr<ToyMaker::SimObject> getLaunchButton(PieceTypeID pieceTypeID, PlayerID player);
84 std::shared_ptr<ToyMaker::SceneNode> getPlayerPanel(PlayerID player);
85 std::shared_ptr<ToyMaker::SimObject> getEndTurnButton();
86
87 std::weak_ptr<ToyMaker::FixedActionBinding> handleCancel { declareFixedActionBinding(
88 "General", "Cancel", [this](const ToyMaker::ActionData& actionData, const ToyMaker::ActionDefinition& actionDefinition) {
89 return this->onCancel(actionData, actionDefinition);
90 }
91 )};
92public:
94 *this, "ButtonClickedObserved",
95 [this](const std::string& button) { this->onButtonClicked(button); }
96 };
97
98 ToyMaker::SignalObserver<GamePhaseData> mObservePhaseUpdated {
99 *this, "PhaseUpdatedObserved",
100 [this](GamePhaseData phaseData) { this->onPhaseUpdated(phaseData); }
101 };
102 ToyMaker::SignalObserver<GameScoreData> mObserveScoreUpdated {
103 *this, "ScoreUpdatedObserved",
104 [this](GameScoreData scoreData) { this->onScoreUpdated(scoreData); }
105 };
106 ToyMaker::SignalObserver<PlayerData> mObservePlayerUpdated {
107 *this, "PlayerUpdatedObserved",
108 [this](PlayerData playerData) { this->onPlayerUpdated(playerData); }
109 };
110 ToyMaker::SignalObserver<DiceData> mObserveDiceUpdated {
111 *this, "DiceUpdatedObserved",
112 [this](DiceData diceData) { this->onDiceUpdated(diceData); }
113 };
115 *this, "MoveMadeObserved",
116 [this](MoveResultData moveData) { this->onMoveMade(moveData); }
117 };
118
119 ToyMaker::SignalObserver<PlayerID> mObserveControlInterface {
120 *this, "ControlInterfaceObserved",
121 [this](PlayerID playerID) { this->onControlInterface(playerID); }
122 };
123
124 ToyMaker::Signal<> mSigDiceRollAttempted { *this, "DiceRollAttempted" };
125 ToyMaker::Signal<> mSigNextTurnAttempted { *this, "NextTurnAttempted" };
126 ToyMaker::Signal<PieceTypeID> mSigLaunchPieceInitiated { *this, "LaunchPieceInitiated" };
127 ToyMaker::Signal<> mSigLaunchPieceCanceled { *this, "LaunchPieceCanceled" };
128
129 ToyMaker::SignalObserver<> mObserveControllerReady {
130 *this, "ControllerReadyObserved",
131 [this]() {this->onControllerReady();}
132 };
133 ToyMaker::Signal<std::string> mSigViewSubscribed {*this, "ViewSubscribed"};
134
135 ToyMaker::SignalObserver<> mObserveViewUpdateStarted {
136 *this, "ViewUpdateStartedObserved",
137 [this](){ this->onViewUpdateStarted(); }
138 };
139 ToyMaker::Signal<std::string> mSigViewUpdateCompleted {
140 *this, "ViewUpdateCompleted"
141 };
142};
143
144#endif
The class containing the interface to the data model for the whole game (Game of Ur).
The data model representing one instance of Game of Ur.
Definition model.hpp:337
std::weak_ptr< FixedActionBinding > declareFixedActionBinding(const std::string &context, const std::string &action, std::function< bool(const ActionData &, const ActionDefinition &)>)
Binds some method (or any function) present on this object to an action generated by the InputManager...
Definition sim_system.cpp:219
A SignalObserver object, which can subscribe to Signals matching its data signature and receive signa...
Definition signals.hpp:412
A Signal object, designed to emit signals matching some data signature to be received by all the Sign...
Definition signals.hpp:323
An object containing closely related methods and data, and exposing object lifecycle and application ...
Definition sim_system.hpp:956
void variableUpdate(uint32_t timeStep) override
Overriding this allows an aspect to respond to variable updates.
Definition ur_ui_view.cpp:262
void onActivated() override
Callback for when the aspect is activated (after it is attached to an active SimObject,...
Definition ur_ui_view.cpp:36
std::shared_ptr< BaseSimObjectAspect > clone() const override
A method which must be overridden to specify how a new aspect should be constructed as a copy of this...
Definition ur_ui_view.cpp:24
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
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
The definition of a single action, including whether it represents state or change,...
Definition input_data.hpp:511
A union that may contain any one of SimpleActionData, OneAxisActionData, TwoAxisActionData,...
Definition input_data.hpp:721