Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'features/broker' into develop
- Loading branch information
Showing
21 changed files
with
512 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// vim: set noexpandtab: | ||
|
||
#include "dialog_frontend.h" | ||
|
||
namespace grail { | ||
|
||
// void DialogFrontend::say(DialogLine::Ptr line) { | ||
// } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// vim: set noexpandtab: | ||
|
||
#ifndef DIALOG_FRONTEND_H | ||
#define DIALOG_FRONTEND_H | ||
|
||
#include <boost/shared_ptr.hpp> | ||
#include <map> | ||
|
||
#include "dialog_line.h" | ||
#include "actor.h" | ||
#include "text.h" | ||
|
||
namespace grail { | ||
|
||
// Virtual base class for in-game dialog renderers. | ||
// Intended to be pluggable so a developer may customise how dialog | ||
// is outputted to the screen. | ||
// For example via subtitles or text floating above an actor's head. | ||
class DialogFrontend { | ||
|
||
public: | ||
typedef boost::shared_ptr<DialogFrontend> Ptr; | ||
|
||
virtual void say(DialogLine::Ptr) = 0; | ||
|
||
virtual void eachFrame(uint32_t ticks) = 0; | ||
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 | ||
|
||
#endif // DIALOG_FRONTEND_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// vim: set noexpandtab: | ||
|
||
#include "dialog_frontend_subtitle.h" | ||
|
||
namespace grail { | ||
|
||
DialogFrontendSubtitle::DialogFrontendSubtitle() { | ||
|
||
// sdefault subs position | ||
int defaultX = 2000; | ||
int defaultY = 2800; | ||
subtitlePosition = VirtualPosition(defaultX, defaultY); | ||
|
||
|
||
//center the subs by default | ||
centered = true; | ||
|
||
// show speaker's name by default | ||
showSpeakersName = true; | ||
|
||
// default font to be used | ||
setFont("fonts/crkdwno1.ttf"); | ||
} | ||
|
||
void DialogFrontendSubtitle::say(DialogLine::Ptr line) { | ||
|
||
// set the default font here if not set | ||
// ** for some reason doing this in the constructor causes a segfault | ||
// and I can't figure out why -- feedelli ** | ||
if (!defaultFont) { | ||
defaultFont = boost::shared_ptr<Font>(new Font(defaultFontPath, 30, 1)); | ||
} | ||
|
||
std::string subtitleText = line->getText(); | ||
|
||
// prepend the speakers name and a colon if showSpeakersName is set | ||
if (showSpeakersName) { | ||
subtitleText = line->getSpeaker()->getName() + ": " + subtitleText; | ||
line->setText(subtitleText); | ||
} | ||
|
||
// queue a new subtitle with the line to be said and using the default font for now | ||
// ** to be implemented: allow characters to have their own fonts | ||
boost::shared_ptr<Subtitle> s(new Subtitle(line, defaultFont)); | ||
subtitles.push_back(s); | ||
} | ||
|
||
void DialogFrontendSubtitle::eachFrame(uint32_t ticks) { | ||
|
||
// remove completed subs | ||
for (std::vector<boost::shared_ptr<Subtitle> >::iterator iter = subtitles.begin(); | ||
iter != subtitles.end(); ) { | ||
if ((*iter)->isComplete()) { | ||
iter = subtitles.erase(iter); | ||
} else { | ||
++iter; | ||
} | ||
} | ||
|
||
// update the subtitles | ||
for (std::vector<boost::shared_ptr<Subtitle> >::iterator iter = subtitles.begin(); | ||
iter != subtitles.end(); iter++) { | ||
(*iter)->eachFrame(ticks); | ||
} | ||
} | ||
|
||
void DialogFrontendSubtitle::renderAt(SDL_Surface* target, uint32_t ticks, VirtualPosition p) { | ||
|
||
// count active subs | ||
int activeSubtitles = 0; | ||
|
||
// render the subtitles centered | ||
// render backwards so earlier subtitles stack upwards | ||
for (std::vector<boost::shared_ptr<Subtitle> >::reverse_iterator riter = subtitles.rbegin(); | ||
riter != subtitles.rend(); ++riter) { | ||
|
||
if ((*riter)->isStarted()) { | ||
|
||
activeSubtitles++; | ||
|
||
VirtualPosition renderPosition = subtitlePosition; | ||
|
||
// center the text around the rener position if set to centered | ||
if (centered) { | ||
renderPosition = renderPosition - ((*riter)->getSize()/2); | ||
} | ||
|
||
if (activeSubtitles > 1) { | ||
renderPosition.setY(renderPosition.getY() - (200 * (activeSubtitles - 1))); | ||
} | ||
|
||
(*riter)->renderAt(target, ticks, (renderPosition)); | ||
} | ||
} | ||
} | ||
|
||
void DialogFrontendSubtitle::setFont(std::string path) { | ||
defaultFontPath = path; | ||
} | ||
|
||
void DialogFrontendSubtitle::setCentered(bool c) { | ||
centered = c; | ||
} | ||
} // namespace grail | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// vim: set noexpandtab: | ||
|
||
#ifndef DIALOG_FRONTEND_SUBTITLE_H | ||
#define DIALOG_FRONTEND_SUBTITLE_H | ||
|
||
#include "dialog_frontend.h" | ||
#include "subtitle.h" | ||
#include "font.h" | ||
#include "boost/shared_ptr.hpp" | ||
|
||
namespace grail { | ||
|
||
// Displays actors' lines in subtitles on the screen | ||
class DialogFrontendSubtitle : public DialogFrontend { | ||
|
||
protected: | ||
std::string defaultFontPath; | ||
Font::Ptr defaultFont; | ||
VirtualPosition subtitlePosition; | ||
bool centered; //is the text centered around subtitleposition | ||
bool showSpeakersName; | ||
|
||
std::vector<boost::shared_ptr<Subtitle> > subtitles; | ||
|
||
public: | ||
DialogFrontendSubtitle(); | ||
void say(DialogLine::Ptr); | ||
|
||
void eachFrame(uint32_t ticks); | ||
virtual void renderAt(SDL_Surface* target, uint32_t ticks, VirtualPosition p); | ||
|
||
void setFont(std::string); | ||
void setCentered(bool); //set whether text should be centered or not | ||
}; | ||
|
||
} // namespace grail | ||
|
||
#endif // DIALOG_FRONTEND_SUBTITLE_H | ||
|
Oops, something went wrong.