-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgame_event.hpp
166 lines (123 loc) · 4.09 KB
/
game_event.hpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef GAME_ENGINE_GAME_EVENT_HPP
#define GAME_ENGINE_GAME_EVENT_HPP
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <functional>
namespace spiced
{
class Object;
class Game;
struct Object_Action;
struct Game_Action;
struct Answer
{
Answer(std::string t_speaker, std::string t_answer)
: speaker(std::move(t_speaker)),
answer(std::move(t_answer))
{
}
std::string speaker;
std::string answer;
};
struct Question
{
Question(std::string t_question,
std::vector<Answer> t_answers,
std::function<bool(const float, const float, Game &, Object &)> t_is_available,
std::function<void(const float, const float, Game &, Object &)> t_action)
: question(std::move(t_question)),
answers(std::move(t_answers)),
is_available(std::move(t_is_available)),
action(std::move(t_action))
{
}
std::string question;
std::vector<Answer> answers;
std::function<bool(const float, const float, Game &, Object &)> is_available;
std::function<void(const float, const float, Game &, Object &)> action;
};
struct Conversation
{
Conversation(std::vector<Question> t_questions)
: questions(std::move(t_questions))
{
}
std::vector<Question> questions;
};
class Game_Event : public sf::Drawable, public sf::Transformable
{
public:
virtual ~Game_Event() = default;
virtual bool is_done() const = 0;
virtual void update(const float t_game_time, const float t_simulation_time, Game &t_game) = 0;
};
class Queued_Action : public Game_Event
{
public:
Queued_Action(std::function<void(const float, const float, Game &)> t_action);
virtual void update(const float, const float, Game &);
virtual bool is_done() const;
virtual void draw(sf::RenderTarget& /*target*/, sf::RenderStates /*states*/) const
{ /*nothing to do*/
}
private:
bool m_done = false;
std::function<void(const float, const float, Game &)> m_action;
};
class Message_Box : public Game_Event
{
public:
Message_Box(sf::String t_string, sf::Font t_font, int t_font_size,
sf::Color t_font_color, sf::Color t_fill_color, sf::Color t_outline_color, float t_outlineThickness);
virtual ~Message_Box() = default;
virtual void update(const float t_game_time, const float /*t_simulation_time*/, Game &t_game);
virtual bool is_done() const;
protected:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
private:
sf::String m_string;
sf::Font m_font;
sf::Color m_font_color;
sf::Color m_fill_color;
sf::Color m_outline_color;
float m_outline_thickness;
sf::Text m_text;
float m_start_time = 0;
bool m_is_done = false;
};
class Selection_Menu : public Game_Event
{
public:
Selection_Menu(sf::Font t_font, int t_font_size,
sf::Color t_font_color, sf::Color t_selected_font_color, sf::Color t_fill_color, sf::Color t_outline_color, float t_outlineThickness,
std::vector<Game_Action> t_actions,
const size_t t_selection);
virtual ~Selection_Menu() = default;
virtual void update(const float t_game_time, const float t_simulation_time, Game &t_game) override;
virtual bool is_done() const override;
protected:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
private:
sf::Font m_font;
sf::Color m_font_color;
sf::Color m_selected_color;
sf::Color m_selected_cur_color;
sf::Color m_fill_color;
sf::Color m_outline_color;
float m_outline_thickness;
std::vector<sf::Text> m_texts;
std::vector<Game_Action> m_actions;
size_t m_current_item = 0;
int m_last_direction = 0;
float m_start_time = 0;
bool m_is_done = false;
};
class Object_Interaction_Menu : public Selection_Menu
{
public:
Object_Interaction_Menu(Object &t_obj, sf::Font t_font, int t_font_size,
sf::Color t_font_color, sf::Color t_selected_font_color, sf::Color t_fill_color, sf::Color t_outline_color, float t_outlineThickness,
const std::vector<Object_Action> &t_actions);
};
}
#endif