Peoplemon  0.1.0
Peoplemon 3 game source documentation
StoreMenu.hpp
Go to the documentation of this file.
1 #ifndef GAME_STATES_STOREMENU_HPP
2 #define GAME_STATES_STOREMENU_HPP
3 
4 #include <BLIB/Graphics.hpp>
5 #include <BLIB/Interfaces/Menu.hpp>
6 #include <Core/Events/Store.hpp>
10 #include <Game/States/State.hpp>
11 #include <unordered_map>
12 #include <vector>
13 
14 namespace game
15 {
16 namespace state
17 {
23 class StoreMenu
24 : public State
25 , public bl::input::Listener {
26 public:
34  static bl::engine::State::Ptr create(core::system::Systems& systems,
35  const core::event::StoreOpened& data);
36 
40  virtual ~StoreMenu() = default;
41 
46  virtual const char* name() const override;
47 
53  virtual void activate(bl::engine::Engine& engine) override;
54 
60  virtual void deactivate(bl::engine::Engine& engine) override;
61 
68  virtual void update(bl::engine::Engine& engine, float dt, float) override;
69 
70 private:
71  struct Item {
72  const core::item::Id item;
73  const int price;
74 
75  Item(core::item::Id item, int price);
76  };
77  enum struct MenuState {
78  ImpulseBuyMessage,
79  GetAction,
80  BuyMenu,
81  BuyQty,
82  BuyDing,
83  SellMenu,
84  SellQty,
85  SellDing,
86  TooPoorDing
87  };
88 
89  MenuState menuState;
90  std::vector<Item> items;
91  std::unordered_map<core::item::Id, int> sellPrices;
92  bl::audio::AudioSystem::Handle dingSound;
93  core::input::MenuDriver inputDriver;
94  unsigned int buyingItemIndex;
95  menu::StoreItemRow* sellingItem;
96  float dingTime;
97  unsigned int curCat;
98 
99  bl::rc::res::TextureRef bgndTxtr;
100  bl::gfx::Sprite background;
101 
102  bl::menu::Menu* renderMenu;
103  bl::menu::Menu actionMenu;
104  bl::menu::Menu buyMenu;
105  bl::menu::Menu sellMenus[3];
107  bl::gfx::Text actionText;
108  bl::gfx::Text boxText;
109  bl::gfx::Text moneyText;
110  bl::gfx::Text catText;
111  bl::gfx::Triangle leftArrow;
112  bl::gfx::Triangle rightArrow;
113 
114  StoreMenu(core::system::Systems& systems, const core::event::StoreOpened& data);
115 
116  void enterState(MenuState state);
117  void setBoxText(const std::string& text);
118  void setMoneyText();
119  int getSellPrice(core::item::Id item) const;
120 
121  void closeMenu();
122  void selectBuyItem(unsigned int i);
123  void selectSellItem(menu::StoreItemRow* row);
124  void catRight();
125  void catLeft();
126  void catSync();
127 
128  void close();
129 
130  virtual bool observe(const bl::input::Actor&, unsigned int activatedControl,
131  bl::input::DispatchType, bool eventTriggered) override;
132 
133  bl::menu::Item::Ptr makeItemRow(core::item::Id item, int price, unsigned int i);
134  bl::menu::Item::Ptr makeSellItemRow(core::item::Id item, int qty);
135  bl::menu::Item::Ptr makeCloseItem();
136 };
137 
138 } // namespace state
139 } // namespace game
140 
141 #endif
bl::menu::TriggerDriver< Control::MoveUp, Control::MoveRight, Control::MoveDown, Control::MoveLeft, Control::Interact > MenuDriver
Helper typedef for Peoplemon specific menu driving.
Definition: MenuDriver.hpp:18
Id
Represents an item in its simplist form.
Definition: Id.hpp:24
Parent namespace for all functionality unique to the game.
Event that is fired by the Core module to signal to the game to open a store.
Definition: Store.hpp:17
Helper class to render a number selector.
Definition: QtyEntry.hpp:18
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47
Menu item for an item in the store. Does both sellable and for-sale items.
Parent to all game states. Provides some commonly required data like core game systems.
Definition: State.hpp:29
core::system::Systems & systems
Definition: State.hpp:66
State that renders and implements a store menu to buy and sell items.
Definition: StoreMenu.hpp:25
virtual ~StoreMenu()=default
Destroy the Store State object.
virtual void activate(bl::engine::Engine &engine) override
Subscribes to event buses.
Definition: StoreMenu.cpp:124
virtual void deactivate(bl::engine::Engine &engine) override
Unsubscribes from event buses.
Definition: StoreMenu.cpp:208
virtual void update(bl::engine::Engine &engine, float dt, float) override
Updates the store menu.
Definition: StoreMenu.cpp:214
virtual const char * name() const override
Returns "StoreMenu".
Definition: StoreMenu.cpp:122
static bl::engine::State::Ptr create(core::system::Systems &systems, const core::event::StoreOpened &data)
Create a new StoreMenu.
Definition: StoreMenu.cpp:27