summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-05 13:32:04 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-05 13:32:04 -0500
commitf7875a6d2f129af47a203a5a31c2785b6e2fcf58 (patch)
tree815d7fb1c28b5667dcd31d50aa65b18a802a89bc /src
parent871943d6a90bdb92b3cc495d4d927199611f8c6b (diff)
downloadtanetane-f7875a6d2f129af47a203a5a31c2785b6e2fcf58.tar.gz
tanetane-f7875a6d2f129af47a203a5a31c2785b6e2fcf58.tar.bz2
tanetane-f7875a6d2f129af47a203a5a31c2785b6e2fcf58.zip
Added speaker header
Diffstat (limited to 'src')
-rw-r--r--src/input_system.cpp2
-rw-r--r--src/message_system.cpp5
-rw-r--r--src/message_system.h8
-rw-r--r--src/renderer.cpp30
-rw-r--r--src/renderer.h15
5 files changed, 49 insertions, 11 deletions
diff --git a/src/input_system.cpp b/src/input_system.cpp index a0acc5e..e8b2bb9 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp
@@ -33,7 +33,7 @@ void InputSystem::tick(double dt) {
33 game_.getSystem<MessageSystem>().displayCutsceneBars(); 33 game_.getSystem<MessageSystem>().displayCutsceneBars();
34 }*/ 34 }*/
35 //game_.getSystem<MessageSystem>().displayMessage("Some people always try to avoid fighting when there are enemies around. You know the type, right? They use the dash ability to zoom right by. I guess you could say they're followers of \"peace at any price\".", SpeakerType::Woman); 35 //game_.getSystem<MessageSystem>().displayMessage("Some people always try to avoid fighting when there are enemies around. You know the type, right? They use the dash ability to zoom right by. I guess you could say they're followers of \"peace at any price\".", SpeakerType::Woman);
36 game_.getSystem<MessageSystem>().displayMessage("Go to sleep.\nIn the absolute darkness.\nDon't do aaaanything.\nDon't see anyone.\nJust sleep.\nIt'll be oh, so much fun......!\nOhohohoho!", SpeakerType::Woman); 36 game_.getSystem<MessageSystem>().displayMessage("Lucas. You're awful at hide-and-seek, you know that? Try harder.", "Kumatora", SpeakerType::Woman);
37 } else if (e.key.keysym.sym == SDLK_b) { 37 } else if (e.key.keysym.sym == SDLK_b) {
38 // TODO: Remove this, it's just for testing. 38 // TODO: Remove this, it's just for testing.
39 game_.getSystem<MessageSystem>().advanceText(); 39 game_.getSystem<MessageSystem>().advanceText();
diff --git a/src/message_system.cpp b/src/message_system.cpp index 5abb4b3..08ef799 100644 --- a/src/message_system.cpp +++ b/src/message_system.cpp
@@ -76,12 +76,13 @@ void MessageSystem::hideCutsceneBars() {
76 barsState_ = BarsState::Closing; 76 barsState_ = BarsState::Closing;
77} 77}
78 78
79void MessageSystem::displayMessage(std::string_view msg, SpeakerType speaker) { 79void MessageSystem::displayMessage(std::string_view msg, std::string speakerName, SpeakerType speakerType) {
80 if (!(barsState_ == BarsState::Opening || barsState_ == BarsState::Open)) { 80 if (!(barsState_ == BarsState::Opening || barsState_ == BarsState::Open)) {
81 displayCutsceneBars(); 81 displayCutsceneBars();
82 } 82 }
83 83
84 speaker_ = speaker; 84 speaker_ = speakerType;
85 speakerName_ = speakerName;
85 86
86 auto lineChunks = splitStr<std::list<std::string>>(std::string(msg), "\n"); 87 auto lineChunks = splitStr<std::list<std::string>>(std::string(msg), "\n");
87 for (const std::string& text : lineChunks) { 88 for (const std::string& text : lineChunks) {
diff --git a/src/message_system.h b/src/message_system.h index 153805a..18dd299 100644 --- a/src/message_system.h +++ b/src/message_system.h
@@ -33,7 +33,10 @@ public:
33 33
34 void hideCutsceneBars(); 34 void hideCutsceneBars();
35 35
36 void displayMessage(std::string_view msg, SpeakerType speaker); 36 void displayMessage(
37 std::string_view msg,
38 std::string speakerName = "",
39 SpeakerType speakerType = SpeakerType::None);
37 40
38 void advanceText(); 41 void advanceText();
39 42
@@ -48,6 +51,8 @@ public:
48 51
49 const std::list<MessageLine>& getLines() const { return linesToShow_; } 52 const std::list<MessageLine>& getLines() const { return linesToShow_; }
50 53
54 const std::string& getSpeaker() const { return speakerName_; }
55
51private: 56private:
52 57
53 enum class BarsState { 58 enum class BarsState {
@@ -62,6 +67,7 @@ private:
62 double accum_ = 0.0; 67 double accum_ = 0.0;
63 double length_ = 1000.0/8; 68 double length_ = 1000.0/8;
64 SpeakerType speaker_ = SpeakerType::None; 69 SpeakerType speaker_ = SpeakerType::None;
70 std::string speakerName_;
65 std::list<std::string> lines_; 71 std::list<std::string> lines_;
66 std::list<MessageLine> linesToShow_; 72 std::list<MessageLine> linesToShow_;
67 Timer textAdvTimer_ { 10 }; 73 Timer textAdvTimer_ { 10 };
diff --git a/src/renderer.cpp b/src/renderer.cpp index b22c316..ae18851 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -157,10 +157,35 @@ void Renderer::render(Game& game) {
157 157
158 if (game.getSystem<MessageSystem>().getCutsceneBarsProgress() == 1.0 && 158 if (game.getSystem<MessageSystem>().getCutsceneBarsProgress() == 1.0 &&
159 !game.getSystem<MessageSystem>().getLines().empty()) { 159 !game.getSystem<MessageSystem>().getLines().empty()) {
160 if (!game.getSystem<MessageSystem>().getSpeaker().empty()) {
161 if (speakerHeaderTex_ == -1) {
162 speakerHeaderTex_ = loadImageFromFile("../res/speaker_header.png");
163 }
164
165 {
166 SDL_Rect destRect { 0, 111, 57, 13 };
167 SDL_RenderCopy(ren_.get(), textures_.at(speakerHeaderTex_).get(), nullptr, &destRect);
168 }
169
170 if (speakerHeaderLine_.line != game.getSystem<MessageSystem>().getSpeaker()) {
171 renderMessageLine(speakerHeaderLine_, game.getSystem<MessageSystem>().getSpeaker(), game);
172 }
173
174 {
175 SDL_Rect destRect {
176 4,
177 112,
178 MESSAGE_TEXT_WIDTH,
179 game.getFont().getCharacterHeight() };
180
181 SDL_RenderCopy(ren_.get(), speakerHeaderLine_.renderedTex.get(), nullptr, &destRect);
182 }
183 }
184
160 int lineIndex = 0; 185 int lineIndex = 0;
161 for (const MessageSystem::MessageLine& line : game.getSystem<MessageSystem>().getLines()) { 186 for (const MessageSystem::MessageLine& line : game.getSystem<MessageSystem>().getLines()) {
162 if (messageLines_[lineIndex].line != line.text) { 187 if (messageLines_[lineIndex].line != line.text) {
163 renderMessageLine(lineIndex, line.text, game); 188 renderMessageLine(messageLines_[lineIndex], line.text, game);
164 } 189 }
165 190
166 // 18x, 127y1, 143y2 191 // 18x, 127y1, 143y2
@@ -204,8 +229,7 @@ int Renderer::loadImageFromFile(std::string_view filename) {
204 return texId; 229 return texId;
205} 230}
206 231
207void Renderer::renderMessageLine(int lineIndex, const std::string& text, Game& game) { 232void Renderer::renderMessageLine(MessageCache& line, const std::string& text, Game& game) {
208 MessageCache& line = messageLines_[lineIndex];
209 line.line = text; 233 line.line = text;
210 234
211 line.renderedTex.reset( 235 line.renderedTex.reset(
diff --git a/src/renderer.h b/src/renderer.h index fd6f707..4195d11 100644 --- a/src/renderer.h +++ b/src/renderer.h
@@ -123,26 +123,33 @@ public:
123 123
124private: 124private:
125 125
126 texture_ptr renderMapLayer(const Map& map, int layer); 126 // Important wrappers
127
128 void renderMessageLine(int lineIndex, const std::string& text, Game& game);
129
130 sdl_wrapper sdl_; 127 sdl_wrapper sdl_;
131 img_wrapper img_; 128 img_wrapper img_;
132 window_ptr win_; 129 window_ptr win_;
133 renderer_ptr ren_; 130 renderer_ptr ren_;
134 131
132 // Textures loaded from files
135 std::vector<texture_ptr> textures_; 133 std::vector<texture_ptr> textures_;
134
135 // Map rendering
136 texture_ptr renderMapLayer(const Map& map, int layer);
137
136 texture_ptr renLay0_; 138 texture_ptr renLay0_;
137 texture_ptr renLay1_; 139 texture_ptr renLay1_;
138 140
141 // Text rendering
139 struct MessageCache { 142 struct MessageCache {
140 texture_ptr renderedTex; 143 texture_ptr renderedTex;
141 std::vector<int> charIndexToWidth; 144 std::vector<int> charIndexToWidth;
142 std::string line; 145 std::string line;
143 }; 146 };
144 147
148 void renderMessageLine(MessageCache& line, const std::string& text, Game& game);
149
145 MessageCache messageLines_[2]; 150 MessageCache messageLines_[2];
151 int speakerHeaderTex_ = -1;
152 MessageCache speakerHeaderLine_;
146}; 153};
147 154
148#endif /* end of include guard: RENDERER_H_6A58EC30 */ 155#endif /* end of include guard: RENDERER_H_6A58EC30 */