State.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef FREESHOP_STATE_HPP
  2. #define FREESHOP_STATE_HPP
  3. #include <functional>
  4. #include "StateIdentifiers.hpp"
  5. #include <cpp3ds/System/Time.hpp>
  6. #include <cpp3ds/Window/Event.hpp>
  7. #include <memory>
  8. #include <vector>
  9. #include <cpp3ds/Graphics/Color.hpp>
  10. #include <cpp3ds/System/String.hpp>
  11. namespace cpp3ds
  12. {
  13. class Window;
  14. class TcpSocket;
  15. }
  16. namespace FreeShop {
  17. class StateStack;
  18. class Player;
  19. typedef std::function<bool(void*)> StateCallback;
  20. class State
  21. {
  22. public:
  23. typedef std::unique_ptr<State> Ptr;
  24. struct Context
  25. {
  26. Context(cpp3ds::String& text, std::vector<char*>& data);
  27. cpp3ds::String& text;
  28. std::vector<char*>& data;
  29. };
  30. State(StateStack& stack, Context& context, StateCallback callback);
  31. virtual ~State();
  32. virtual void renderTopScreen(cpp3ds::Window& window) = 0;
  33. virtual void renderBottomScreen(cpp3ds::Window& window) = 0;
  34. virtual bool update(float delta) = 0;
  35. virtual bool processEvent(const cpp3ds::Event& event) = 0;
  36. void requestStackPush(States::ID stateID, bool renderAlone = false, StateCallback callback = nullptr);
  37. void requestStackPop();
  38. void requestStackClear();
  39. void requestStackClearUnder();
  40. bool runCallback(void *data);
  41. Context getContext() const;
  42. private:
  43. StateStack* m_stack;
  44. Context m_context;
  45. StateCallback m_callback;
  46. };
  47. } // namespace FreeShop
  48. #endif // FREESHOP_STATE_HPP