summary refs log tree commit diff stats
path: root/src/message_system.h
blob: 18dd299883176cce9b3e50730d3245749d480de1 (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
71
72
73
74
75
76
#ifndef MESSAGE_SYSTEM_H_DE10D011
#define MESSAGE_SYSTEM_H_DE10D011

#include <list>
#include <string_view>
#include <string>
#include "system.h"
#include "timer.h"

class Game;

enum class SpeakerType {
  None,
  Man,
  Woman,
  Boy,
  Girl,
  Nonhuman
};

class MessageSystem : public System {
public:

  static constexpr SystemKey Key = SystemKey::Message;

  MessageSystem(Game& game) : game_(game) {}

  void tick(double dt) override;

  // Commands

  void displayCutsceneBars();

  void hideCutsceneBars();

  void displayMessage(
    std::string_view msg,
    std::string speakerName = "",
    SpeakerType speakerType = SpeakerType::None);

  void advanceText();

  // Info

  double getCutsceneBarsProgress() const;

  struct MessageLine {
    std::string text;
    int charsRevealed = 0;
  };

  const std::list<MessageLine>& getLines() const { return linesToShow_; }

  const std::string& getSpeaker() const { return speakerName_; }

private:

  enum class BarsState {
    Closed,
    Opening,
    Open,
    Closing
  };

  Game& game_;
  BarsState barsState_ = BarsState::Closed;
  double accum_ = 0.0;
  double length_ = 1000.0/8;
  SpeakerType speaker_ = SpeakerType::None;
  std::string speakerName_;
  std::list<std::string> lines_;
  std::list<MessageLine> linesToShow_;
  Timer textAdvTimer_ { 10 };
};

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