[Scummvm-cvs-logs] scummvm master -> 5afdf3277ebe6ea334b928d20e54d9acac69c377

dreammaster dreammaster at scummvm.org
Sun Jan 17 23:57:45 CET 2016


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
5afdf3277e MADS: Beginnings of loading Phantom-style dialogs


Commit: 5afdf3277ebe6ea334b928d20e54d9acac69c377
    https://github.com/scummvm/scummvm/commit/5afdf3277ebe6ea334b928d20e54d9acac69c377
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2016-01-17T17:57:10-05:00

Commit Message:
MADS: Beginnings of loading Phantom-style dialogs

Changed paths:
    engines/mads/conversations.cpp
    engines/mads/conversations.h
    engines/mads/dialogs.cpp
    engines/mads/dialogs.h



diff --git a/engines/mads/conversations.cpp b/engines/mads/conversations.cpp
index 169e844..84e0f83 100644
--- a/engines/mads/conversations.cpp
+++ b/engines/mads/conversations.cpp
@@ -47,6 +47,7 @@ GameConversations::GameConversations(MADSEngine *vm) : _vm(vm) {
 	_currentNode = 0;
 	_dialogNodeOffset = _dialogNodeSize = 0;
 	_dialog = nullptr;
+	_dialogAltFlag = false;
 
 	// Mark all conversation slots as empty
 	for (int idx = 0; idx < MAX_CONVERSATIONS; ++idx)
@@ -417,23 +418,27 @@ ConversationMode GameConversations::generateMenu() {
 }
 
 void GameConversations::generateText(int textLineIndex, Common::Array<int> &messages) {
+	_dialogAltFlag = true;
+
 	error("TODO: GameConversations::generateText");
 }
 
 void GameConversations::generateMessage(Common::Array<int> &messageList, Common::Array<int> &voiceList) {
+	_dialogAltFlag = false;
 	if (messageList.size() == 0)
 		return;
 
 	if (_dialog)
 		delete _dialog;
 
+	// Get the speaker portrait
+	SpriteAsset &sprites = *_vm->_game->_scene._sprites[_speakerSeries[_personSpeaking]];
+	MSprite *portrait = sprites.getFrame(_speakerFrame[_personSpeaking]);
+
 	// Create the new text dialog
 	_dialog = new TextDialog(_vm, FONT_INTERFACE,
-		Common::Point(_popupX[_personSpeaking], _popupY[_personSpeaking]), _popupMaxLen[_personSpeaking]);
-
-	// Add the sprite for the speaker
-	SpriteAsset &sprites = *_vm->_game->_scene._sprites[_speakerSeries[_personSpeaking]];
-	_dialog->addIcon(sprites.getFrame(_speakerFrame[_personSpeaking]));
+		Common::Point(_popupX[_personSpeaking], _popupY[_personSpeaking]), 
+		portrait, _popupMaxLen[_personSpeaking]);
 
 	// Add in the lines
 	for (uint msgNum = 0; msgNum < messageList.size(); ++msgNum) {
diff --git a/engines/mads/conversations.h b/engines/mads/conversations.h
index 7abdfbd..a56cef5 100644
--- a/engines/mads/conversations.h
+++ b/engines/mads/conversations.h
@@ -337,6 +337,7 @@ private:
 	int _dialogNodeOffset, _dialogNodeSize;
 	int _personSpeaking;
 	TextDialog *_dialog;
+	bool _dialogAltFlag;
 	
 	/**
 	 * Returns the record for the specified conversation, if it's loaded
diff --git a/engines/mads/dialogs.cpp b/engines/mads/dialogs.cpp
index 8003660..14aa41e 100644
--- a/engines/mads/dialogs.cpp
+++ b/engines/mads/dialogs.cpp
@@ -29,6 +29,12 @@
 
 namespace MADS {
 
+enum PopupEdge {
+	EDGE_UPPER_LEFT = 0, EDGE_UPPER_RIGHT = 1, EDGE_LOWER_LEFT = 2,
+	EDGE_LOWER_RIGHT = 3, EDGE_LEFT = 4, EDGE_RIGHT = 5, EDGE_TOP = 6,
+	EDGE_BOTTOM = 7, EDGE_UPPER_CENTER = 8
+};
+
 Dialog::Dialog(MADSEngine *vm)
 	: _vm(vm), _savedSurface(nullptr), _position(Common::Point(-1, -1)),
 	  _width(0), _height(0) {
@@ -140,15 +146,34 @@ void Dialog::drawContent(const Common::Rect &r, int seed, byte color1, byte colo
 TextDialog::TextDialog(MADSEngine *vm, const Common::String &fontName,
 		const Common::Point &pos, int maxChars)
 	: Dialog(vm) {
-	_vm = vm;
 	_font = _vm->_font->getFont(fontName);
 	_position = pos;
+	_icon = nullptr;
+	_edgeSeries = nullptr;
+	_piecesPerCenter = 0;
+	_vm->_font->setColors(TEXTDIALOG_BLACK, TEXTDIALOG_BLACK, TEXTDIALOG_BLACK, TEXTDIALOG_BLACK);
+	_piecesPerCenter = 0;
+
+	init(maxChars);
+}
 
+TextDialog::TextDialog(MADSEngine *vm, const Common::String &fontName,
+		const Common::Point &pos, MSurface *icon, int maxTextChars): Dialog(vm) {
+	_font = _vm->_font->getFont(fontName);
+	_position = pos;
+	_icon = icon;
+	_edgeSeries = new SpriteAsset(_vm, "box.ss", PALFLAG_RESERVED);
 	_vm->_font->setColors(TEXTDIALOG_BLACK, TEXTDIALOG_BLACK, TEXTDIALOG_BLACK, TEXTDIALOG_BLACK);
+	_piecesPerCenter = _edgeSeries->getFrame(EDGE_UPPER_CENTER)->w / _edgeSeries->getFrame(EDGE_BOTTOM)->w;
 
-	_innerWidth = (_font->maxWidth() + 1) * maxChars;
+	int maxLen = estimatePieces(maxTextChars);
+	init(maxLen);
+}
+
+void TextDialog::init(int maxTextChars) {
+	_innerWidth = (_font->maxWidth() + 1) * maxTextChars;
 	_width = _innerWidth + 10;
-	_lineSize = maxChars * 2;
+	_lineSize = maxTextChars * 2;
 	_lineWidth = 0;
 	_currentX = 0;
 	_numLines = 0;
@@ -157,7 +182,16 @@ TextDialog::TextDialog(MADSEngine *vm, const Common::String &fontName,
 	_askXp = 0;
 }
 
+int TextDialog::estimatePieces(int maxLen) {
+	int fontLen = (_font->maxWidth() + 1) * maxLen;
+	int pieces = ((fontLen - 1) / _edgeSeries->getFrame(EDGE_TOP)->w) + 1;
+	int estimate = (maxLen - _piecesPerCenter) / 2;
+
+	return estimate;
+}
+
 TextDialog::~TextDialog() {
+	delete _edgeSeries;
 }
 
 void TextDialog::addLine(const Common::String &line, bool underline) {
@@ -275,10 +309,6 @@ void TextDialog::setLineXp(int xp) {
 	_lineXp[_numLines] = xp;
 }
 
-void TextDialog::addIcon(MSprite *frame) {
-	warning("TODO: addIcon");
-}
-
 void TextDialog::draw() {
 	if (!_lineWidth)
 		--_numLines;
diff --git a/engines/mads/dialogs.h b/engines/mads/dialogs.h
index 61ba480..14e0932 100644
--- a/engines/mads/dialogs.h
+++ b/engines/mads/dialogs.h
@@ -110,6 +110,11 @@ private:
 	 * Clean up after finishing displaying the dialog
 	 */
 	void restorePalette();
+
+	/**
+	 * Used by the constructors to initialize the dialog fields
+	 */
+	void init(int maxTextChars);
 protected:
 	Font *_font;
 	int _innerWidth;
@@ -121,6 +126,9 @@ protected:
 	int _askLineNum;
 	Common::String _lines[TEXT_DIALOG_MAX_LINES];
 	int _lineXp[TEXT_DIALOG_MAX_LINES];
+	SpriteAsset *_edgeSeries;
+	MSurface *_icon;
+	int _piecesPerCenter;
 
 	/**
 	 * Calculate the bounds for the dialog
@@ -138,6 +146,17 @@ public:
 		int maxChars);
 
 	/**
+	 * Constructor
+	 * @param vm			Engine reference
+	 * @param fontName		Font to use for display
+	 * @param pos			Position for window top-left
+	 * @param icon			Speaker portrait to show in dialog
+	 * @param maxTextChars	Horizontal width of text portion of window in characters
+	 */
+	TextDialog(MADSEngine *vm, const Common::String &fontName, const Common::Point &pos,
+		MSurface *icon, int maxTextChars);
+
+	/**
 	 * Destructor
 	 */
 	virtual ~TextDialog();
@@ -190,9 +209,9 @@ public:
 	void setLineXp(int xp);
 
 	/**
-	 * Adds an icon to the dialog
+	 * Estimates the maximum dialog length for text dialogs with icons
 	 */
-	void addIcon(MSprite *frame);
+	int estimatePieces(int maxLen);
 
 	/**
 	 * Show the dialog, and wait until a key or mouse press.






More information about the Scummvm-git-logs mailing list