summary refs log tree commit diff stats
path: root/src/menu_system.h
blob: 736d5551b80063f3c6e09f85215d09ccd4ee40f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef MENU_SYSTEM_H_205861EC
#define MENU_SYSTEM_H_205861EC

#include <vector>
#include "interpolation.h"
#include "menu.h"
#include "system.h"
#include "timer.h"

class Game;

class MenuSystem : public System {
public:

  static constexpr SystemKey Key = SystemKey::Menu;

  explicit MenuSystem(Game& game) : game_(game) {}

  void tick(double dt) override;

  // Commands

  void openPauseMenu();

  void closePauseMenu(bool playSfx = true);

  void pressedUp();

  void pressedDown();

  void activateOption();

  // Info

  double getPauseAnimationProgress() const { return pauseAnimation_.getProgress(); }

  bool isMenuOpen() const { return openState_ == OpenState::Open; }

  const std::vector<MenuItem>& getMenu() const { return menu_; }

  int getCursorPosition() const { return cursor_; }

  int getCursorBob() const { return cursorBob_; }

private:

  enum class OpenState {
    Closed,
    Animating,
    Open
  };

  Game& game_;
  Interpolation pauseAnimation_;
  OpenState openState_ = OpenState::Closed;
  std::vector<MenuItem> menu_;
  int cursor_ = 0;
  int cursorBob_ = 0;
  bool cursorBobDown_ = true;
  Timer cursorBobTimer_ { 125 };
};

#endif /* end of include guard: MENU_SYSTEM_H_205861EC */