summary refs log tree commit diff stats
path: root/src/menu.h
blob: 67c75c02568b77b27f145ec24c903afcb2ca55c0 (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
64
65
66
67
68
69
70
#ifndef MENU_H_3F6E62B3
#define MENU_H_3F6E62B3

#include <functional>
#include <memory>
#include <string>
#include <vector>

class Game;

enum class MenuType {
  Command
};

struct MenuItem {
  MenuType type = MenuType::Command;
  std::string text;
  std::function<void(Game&)> activationFunction;
  bool playSfx = false;
};

class MenuBuilder {
public:

  MenuBuilder& Command(std::string text) {
    result_.type = MenuType::Command;
    result_.text = std::move(text);
    result_.playSfx = true;
    return *this;
  }

  MenuBuilder& ActivationFunction(std::function<void(Game&)> val) {
    result_.activationFunction = std::move(val);
    return *this;
  }

  MenuBuilder& SkipSoundEffect() {
    result_.playSfx = false;
    return *this;
  }

  MenuItem Build() const {
    return result_;
  }

private:

  MenuItem result_;
};

class Menu {
public:

  explicit Menu(const std::vector<MenuBuilder>& builders);

  const std::vector<MenuItem>& getItems() const { return items_; }

  int getCursorPosition() const { return cursor_; }

  void moveCursorUp();

  void moveCursorDown();

private:

  std::vector<MenuItem> items_;
  int cursor_ = 0;
};

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