1 #ifndef CORE_SYSTEMS_HUD_HPP
2 #define CORE_SYSTEMS_HUD_HPP
4 #include <BLIB/Engine/System.hpp>
5 #include <BLIB/Graphics.hpp>
6 #include <BLIB/Interfaces/Menu.hpp>
7 #include <BLIB/Interfaces/Utilities.hpp>
8 #include <BLIB/Resources.hpp>
31 class HUD :
public bl::engine::System {
39 using Callback = std::function<void(
const std::string& value)>;
68 const std::string& message,
const Callback& cb = [](
const std::string&) {});
79 const std::string& message,
bool ghostWrite,
80 const Callback& cb = [](
const std::string&) {});
97 void promptUser(
const std::string& prompt,
const std::vector<std::string>& choices,
108 void getInputString(
const std::string& prompt,
unsigned int minLen,
unsigned int maxLen,
119 void getQty(
const std::string& prompt,
int minQty,
int maxQty,
const QtyCallback& cb);
146 enum Type { Message, Prompt, Keyboard, Qty };
148 Item(
const std::string& message,
bool sticky,
bool ghost,
const Callback& cb);
149 Item(
const std::string& prompt,
const std::vector<std::string>& choices,
151 Item(
const std::string& prompt,
unsigned int minLen,
unsigned int maxLen,
153 Item(
const std::string& prompt,
int minQty,
int maxQty,
const QtyCallback& cb);
155 Type getType()
const;
156 const std::string& getMessage()
const;
157 bool isSticky()
const;
158 bool ghostWrite()
const;
159 const std::vector<std::string>& getChoices()
const;
160 const Callback& getCallback()
const;
162 unsigned int minInputLength()
const;
163 unsigned int maxInputLength()
const;
164 int getMinQty()
const;
165 int getMaxQty()
const;
169 const std::variant<Callback, QtyCallback> cb;
170 const std::string message;
171 const std::variant<std::pair<bool, bool>, std::vector<std::string>,
172 std::pair<unsigned int, unsigned int>, std::pair<int, int>>
176 struct HudListener :
public bl::input::Listener {
177 HudListener(
HUD& owner);
178 virtual ~HudListener() =
default;
179 virtual bool observe(
const bl::input::Actor&,
unsigned int activatedControl,
180 bl::input::DispatchType,
bool eventTriggered)
override;
187 EntryCard(bl::engine::Engine& engine);
188 void display(
const std::string& text);
189 void update(
float dt);
193 bl::engine::Engine& engine;
194 bl::rc::Overlay* currentOverlay;
195 bl::rc::res::TextureRef txtr;
196 bl::gfx::Sprite card;
199 void ensureCreated();
201 enum State { Hidden, Dropping, Holding, Rising } state;
208 HudListener inputListener;
209 std::queue<Item> queuedOutput;
210 bl::interface::GhostWriter currentMessage;
211 hud::ScreenKeyboard screenKeyboard;
214 bl::rc::Overlay* currentOverlay;
215 bl::rc::res::TextureRef textboxTxtr;
216 bl::gfx::Sprite textbox;
217 bl::gfx::Text displayText;
218 bl::gfx::Triangle promptTriangle;
219 hud::QtyEntry qtyEntry;
221 bl::menu::Menu choiceMenu;
225 void setState(State newState);
227 void startPrinting();
228 void printDoneStateTransition();
229 void choiceMade(
unsigned int i);
230 void keyboardSubmit(
const std::string& input);
231 void qtySelected(
int qty);
234 virtual void init(bl::engine::Engine&)
override;
235 virtual void update(std::mutex&,
float dt,
float,
float,
float)
override;
bl::menu::TriggerDriver< Control::MoveUp, Control::MoveRight, Control::MoveDown, Control::MoveLeft, Control::Interact > MenuDriver
Helper typedef for Peoplemon specific menu driving.
Type
The type classification of an item. This is used to determine when an item may be used and how to use...
Core classes and functionality for both the editor and game.
The primary HUD system for the player. Manages displaying messages and asking questions....
void displayEntryCard(const std::string &name)
Displays a card to indicate entering a new town, route, or map.
void hideEntryCard()
Hides the entry card.
std::function< void(const std::string &value)> Callback
Signature for HUD callbacks. Used for both messages completing and choices made.
void displayMessage(const std::string &message, const Callback &cb=[](const std::string &) {})
Displays a message in the HUD textbox. Messages are queued in order that they arrive.
void getQty(const std::string &prompt, int minQty, int maxQty, const QtyCallback &cb)
Gets a number from the player.
void promptUser(const std::string &prompt, const std::vector< std::string > &choices, const Callback &cb)
Asks the player a question through the HUD.
std::function< void(int qty)> QtyCallback
Called when a qty is entered.
virtual ~HUD()=default
Destroys the system.
void displayStickyMessage(const std::string &message, bool ghostWrite, const Callback &cb=[](const std::string &) {})
Displays a message in the HUD textbox. Sticky messages stay displayed until programmatically dismisse...
void getInputString(const std::string &prompt, unsigned int minLen, unsigned int maxLen, const Callback &cb)
Prompts the player to input a string using the screen keyboard.
HUD(Systems &owner)
Construct a new HUD system.
bool dismissStickyMessage(bool ignoreGhostWrite=true)
Dismisses the currently active sticky message.
Owns all primary systems and a reference to the engine.