Permalink
Browse files

Initial implementation of a rendering frontend for actors' dialog lines.

The default dialog frontend maps text objects to actors who are speaking,
and renders their lines. When an actor is finished speaking they are removed
from the map.

This is a rough draft. The dialog is rendered under the character's feet as
it's not clever enough yet to determine a position above actors' heads. Also
all dialog is rendered in the same font and color at the moment.
  • Loading branch information...
1 parent 98a64d0 commit d5930f712e22dd8a03daf712824bc62fe0180419 @feelydj feelydj committed Dec 17, 2011
Showing with 60 additions and 10 deletions.
  1. +1 −1 demo/init.lua
  2. +16 −0 lib/dialog_frontend.cc
  3. +12 −2 lib/dialog_frontend.h
  4. +18 −4 lib/dialog_frontend_default.cc
  5. +1 −1 lib/dialog_frontend_default.h
  6. +12 −2 lib/scene.cc
View
@@ -21,7 +21,6 @@ function initChapter(n)
local scarecrow = Actor("Scarecrow")
scarecrow:addAnimation("default", Image("/media/$res/scarecrow.png"))
scarecrow:setPosition(VP(6000, 2700))
- scarecrow:say("hello world!", 3000)
s:addActor(scarecrow)
local pumpkin = Actor("Pumpkin")
@@ -32,6 +31,7 @@ function initChapter(n)
main_character.mc:setPosition(VP(250, 2700))
s:addActor(mc)
+ mc:say("Wooo, dark", 4000)
local Audio = Audio()
bgmusic = Audio:prepareSound("sounds/20moment.mp3",2)
View
@@ -1,8 +1,24 @@
// vim: set noexpandtab:
#include "dialog_frontend.h"
+#include "vector2d.h"
namespace grail {
+ void DialogFrontend::say(DialogLine::Ptr line, Actor::Ptr speaker) {
+
+ // if the speaker does not already have a text object associated
+ // with them create it now
+ if (!lines[speaker]) {
+
+ // temporary solution to create text object
+ boost::shared_ptr<Font> font(new Font("fonts/tommy_holloway.ttf", 40, 1));
+ boost::shared_ptr<Text> text(new Text(font));
+
+ text->setText(line->getText());
+
+ lines[speaker] = text;
+ }
+ }
}
View
@@ -4,7 +4,11 @@
#define DIALOG_FRONTEND_H
#include <boost/shared_ptr.hpp>
+#include <map>
+
#include "dialog_line.h"
+#include "actor.h"
+#include "text.h"
namespace grail {
@@ -17,8 +21,14 @@ namespace grail {
public:
typedef boost::shared_ptr<DialogFrontend> Ptr;
- // renders the dialog line
- virtual void render(DialogLine::Ptr) = 0;
+ virtual void say(DialogLine::Ptr, Actor::Ptr);
+
+ virtual void renderAt(SDL_Surface* target, uint32_t ticks, VirtualPosition p) = 0;
+
+ protected:
+ // map of actors to the text objects used to render
+ // their dialog
+ std::map<Actor::Ptr, Text::Ptr> lines;
};
} // namespace grail
@@ -4,10 +4,24 @@
namespace grail {
- // for now just prints out the dialog to output
- void DialogFrontendDefault::render(DialogLine::Ptr dialogLine) {
- printf("%s\n", dialogLine->getText().c_str());
- }
+ void DialogFrontendDefault::renderAt(SDL_Surface* target, uint32_t ticks, VirtualPosition p) {
+
+ // remove unused text objects
+ for (std::map<Actor::Ptr, Text::Ptr>::iterator iter = lines.begin();
+ iter != lines.end(); iter++) {
+ if (!(*iter).first->isSpeaking()) {
+ lines.erase(iter);
+ }
+ }
+ // render the text objects
+ for (std::map<Actor::Ptr, Text::Ptr>::iterator iter = lines.begin();
+ iter != lines.end(); iter++) {
+
+ VirtualPosition actorPosition = (*iter).first->getPosition();
+ (*iter).second->eachFrame(ticks); // temporarily here
+ (*iter).second->renderAt(target, ticks, actorPosition);
+ }
+ }
} // namespace grail
@@ -13,7 +13,7 @@ namespace grail {
class DialogFrontendDefault : public DialogFrontend {
public:
- virtual void render(DialogLine::Ptr);
+ virtual void renderAt(SDL_Surface* target, uint32_t ticks, VirtualPosition p);
};
} // namespace grail
View
@@ -91,11 +91,13 @@ void Scene::renderAt(SDL_Surface* target, uint32_t ticks, VirtualPosition p) con
list<Actor::Ptr>::const_iterator iter;
for(iter = actors.begin(); iter != actors.end(); ++iter) {
(*iter)->renderAt(target, ticks, p);
- // if the character is speaking render their current line through the current dialog frontend
+
if ((*iter)->isSpeaking()) {
- Game::getInstance().getDialogFrontend()->render((*iter)->getDialogLine());
+ Game::getInstance().getDialogFrontend()->say((*iter)->getDialogLine(), (*iter));
}
}
+
+ Game::getInstance().getDialogFrontend()->renderAt(target, ticks, p);
for(piter = foregrounds.begin(); piter != foregrounds.end(); ++piter) {
(*piter)->animation->renderAt(target, ticks,
@@ -116,6 +118,14 @@ void Scene::renderAt(SDL_Surface* target, uint32_t ticks, VirtualPosition p) con
}
*/
}
+
+ // check which actors are speaking and render their dialog lines
+ // using the current dialog frontend
+ for(iter = actors.begin(); iter != actors.end(); ++iter) {
+ if ((*iter)->isSpeaking()) {
+ Game::getInstance().getDialogFrontend()->say((*iter)->getDialogLine(), (*iter));
+ }
+ }
} // renderAt

0 comments on commit d5930f7

Please sign in to comment.