aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorNicola Mettifogo2007-07-01 16:12:21 +0000
committerNicola Mettifogo2007-07-01 16:12:21 +0000
commit94fab1c1513b26520cef88d5f9baf4ee2f4e094f (patch)
tree72621b35a40fccc66fef56c95f3282dce50324ed /engines
parent5acf6b76c4792174401cfcdefbaecf778734eedc (diff)
downloadscummvm-rg350-94fab1c1513b26520cef88d5f9baf4ee2f4e094f.tar.gz
scummvm-rg350-94fab1c1513b26520cef88d5f9baf4ee2f4e094f.tar.bz2
scummvm-rg350-94fab1c1513b26520cef88d5f9baf4ee2f4e094f.zip
Wrapped dialogue functions into a new DialogueManager, and some basic refactoring.
svn-id: r27827
Diffstat (limited to 'engines')
-rw-r--r--engines/parallaction/dialogue.cpp234
-rw-r--r--engines/parallaction/parallaction.h13
2 files changed, 129 insertions, 118 deletions
diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp
index b3de3e5da3..b431064692 100644
--- a/engines/parallaction/dialogue.cpp
+++ b/engines/parallaction/dialogue.cpp
@@ -46,10 +46,6 @@ namespace Parallaction {
#define ANSWER_CHARACTER_X 10
#define ANSWER_CHARACTER_Y 80
-
-void enterDialogue();
-void exitDialogue();
-
int16 selectAnswer(Question *q, StaticCnv*);
int16 getHoverAnswer(int16 x, int16 y, Question *q);
@@ -191,7 +187,49 @@ char *Parallaction::parseDialogueString(Script &script) {
return vCC;
}
-uint16 Parallaction::askDialoguePassword(Dialogue *q, StaticCnv *face) {
+class DialogueManager {
+
+ Parallaction *_vm;
+ SpeakData *_data;
+ Dialogue *_dialogue;
+
+ bool _askPassword;
+
+ bool isNpc;
+ Cnv *_questioner;
+ Cnv *_answerer;
+
+ Question *_q;
+
+public:
+ DialogueManager(Parallaction *vm, SpeakData *data) : _vm(vm), _data(data) {
+ _dialogue = _data->_dialogue;
+ isNpc = scumm_stricmp(_data->_name, "yourself") && _data->_name[0] != '\0';
+ _questioner = isNpc ? _vm->_disk->loadTalk(_data->_name) : _vm->_char._talk;
+ _answerer = _vm->_char._talk;
+ }
+
+ ~DialogueManager() {
+ if (isNpc) {
+ delete _questioner;
+ }
+ }
+
+ void run();
+
+protected:
+ void displayQuestion();
+ bool displayAnswers();
+ bool displayAnswer(uint16 i);
+
+ uint16 getAnswer();
+ int16 selectAnswer(StaticCnv *cnv);
+ uint16 askPassword(StaticCnv *face);
+ int16 getHoverAnswer(int16 x, int16 y);
+
+};
+
+uint16 DialogueManager::askPassword(StaticCnv *face) {
debugC(1, kDebugDialogue, "checkDialoguePassword()");
char password[100];
@@ -199,15 +237,15 @@ uint16 Parallaction::askDialoguePassword(Dialogue *q, StaticCnv *face) {
while (true) {
strcpy(password, ".......");
- _gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
+ _vm->_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
Common::Rect r(_answerBalloonW[0], _answerBalloonH[0]);
r.moveTo(_answerBalloonX[0], _answerBalloonY[0]);
- _gfx->drawBalloon(r, 1);
- _gfx->displayWrappedString(q->_answers[0]->_text, _answerBalloonX[0], _answerBalloonY[0], MAX_BALLOON_WIDTH, 3);
- _gfx->flatBlitCnv(face, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
- _gfx->displayBalloonString(_answerBalloonX[0] + 5, _answerBalloonY[0] + _answerBalloonH[0] - 15, "> ", 0);
+ _vm->_gfx->drawBalloon(r, 1);
+ _vm->_gfx->displayWrappedString(_q->_answers[0]->_text, _answerBalloonX[0], _answerBalloonY[0], MAX_BALLOON_WIDTH, 3);
+ _vm->_gfx->flatBlitCnv(face, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
+ _vm->_gfx->displayBalloonString(_answerBalloonX[0] + 5, _answerBalloonY[0] + _answerBalloonH[0] - 15, "> ", 0);
Common::Event e;
while (e.kbd.ascii != Common::KEYCODE_RETURN && passwordLen < MAX_PASSWORD_LENGTH) {
@@ -223,15 +261,15 @@ uint16 Parallaction::askDialoguePassword(Dialogue *q, StaticCnv *face) {
passwordLen++;
password[passwordLen] = '\0';
- _gfx->displayBalloonString(_answerBalloonX[0] + 5, _answerBalloonY[0] + _answerBalloonH[0] - 15, password, 0);
- _gfx->updateScreen();
+ _vm->_gfx->displayBalloonString(_answerBalloonX[0] + 5, _answerBalloonY[0] + _answerBalloonH[0] - 15, password, 0);
+ _vm->_gfx->updateScreen();
g_system->delayMillis(20);
}
- if ((!scumm_stricmp(_characterName, _doughName) && !scumm_strnicmp(password, "1732461", 7)) ||
- (!scumm_stricmp(_characterName, _donnaName) && !scumm_strnicmp(password, "1622", 4)) ||
- (!scumm_stricmp(_characterName, _dinoName) && !scumm_strnicmp(password, "179", 3))) {
+ if ((!scumm_stricmp(_vm->_characterName, _doughName) && !scumm_strnicmp(password, "1732461", 7)) ||
+ (!scumm_stricmp(_vm->_characterName, _donnaName) && !scumm_strnicmp(password, "1622", 4)) ||
+ (!scumm_stricmp(_vm->_characterName, _dinoName) && !scumm_strnicmp(password, "179", 3))) {
break;
@@ -243,165 +281,149 @@ uint16 Parallaction::askDialoguePassword(Dialogue *q, StaticCnv *face) {
}
-bool _askPassword;
-bool Parallaction::displayAnswer(Dialogue *q, uint16 i) {
- uint32 v28 = _localFlags[_currentLocationIndex];
- if (q->_answers[i]->_yesFlags & kFlagsGlobal)
+bool DialogueManager::displayAnswer(uint16 i) {
+
+ uint32 v28 = _localFlags[_vm->_currentLocationIndex];
+ if (_q->_answers[i]->_yesFlags & kFlagsGlobal)
v28 = _commandFlags | kFlagsGlobal;
// display suitable answers
- if (((q->_answers[i]->_yesFlags & v28) == q->_answers[i]->_yesFlags) && ((q->_answers[i]->_noFlags & ~v28) == q->_answers[i]->_noFlags)) {
+ if (((_q->_answers[i]->_yesFlags & v28) == _q->_answers[i]->_yesFlags) && ((_q->_answers[i]->_noFlags & ~v28) == _q->_answers[i]->_noFlags)) {
- _gfx->getStringExtent(q->_answers[i]->_text, MAX_BALLOON_WIDTH, &_answerBalloonW[i], &_answerBalloonH[i]);
+ _vm->_gfx->getStringExtent(_q->_answers[i]->_text, MAX_BALLOON_WIDTH, &_answerBalloonW[i], &_answerBalloonH[i]);
Common::Rect r(_answerBalloonW[i], _answerBalloonH[i]);
r.moveTo(_answerBalloonX[i], _answerBalloonY[i]);
- _gfx->drawBalloon(r, 1);
+ _vm->_gfx->drawBalloon(r, 1);
_answerBalloonY[i+1] = 10 + _answerBalloonY[i] + _answerBalloonH[i];
- _askPassword = _gfx->displayWrappedString(q->_answers[i]->_text, _answerBalloonX[i], _answerBalloonY[i], MAX_BALLOON_WIDTH, 3);
+ _askPassword = _vm->_gfx->displayWrappedString(_q->_answers[i]->_text, _answerBalloonX[i], _answerBalloonY[i], MAX_BALLOON_WIDTH, 3);
return true;
}
+ _answerBalloonY[i+1] = _answerBalloonY[i];
+ _answerBalloonY[i] = SKIPPED_ANSWER;
+
return false;
}
-bool Parallaction::displayAnswers(Dialogue *q) {
+bool DialogueManager::displayAnswers() {
bool displayed = false;
uint16 i = 0;
- while (i < NUM_ANSWERS && q->_answers[i]) {
- if (displayAnswer(q, i)) {
+ while (i < NUM_ANSWERS && _q->_answers[i]) {
+ if (displayAnswer(i))
displayed = true;
- } else {
- _answerBalloonY[i+1] = _answerBalloonY[i];
- _answerBalloonY[i] = SKIPPED_ANSWER;
- }
+
i++;
}
- _gfx->updateScreen();
+ _vm->_gfx->updateScreen();
return displayed;
}
-void Parallaction::displayQuestion(Dialogue *q, Cnv *cnv) {
+void DialogueManager::displayQuestion() {
int16 w = 0, h = 0;
- if (!scumm_stricmp(q->_text, "NULL")) return;
+ if (!scumm_stricmp(_q->_text, "NULL")) return;
StaticCnv face;
- face._width = cnv->_width;
- face._height = cnv->_height;
- face._data0 = cnv->getFramePtr(q->_mood & 0xF);
- face._data1 = NULL; // cnv->field_8[v60->_mood & 0xF];
+ face._width = _questioner->_width;
+ face._height = _questioner->_height;
+ face._data0 = _questioner->getFramePtr(_q->_mood & 0xF);
+ face._data1 = NULL; // _questioner->field_8[v60->_mood & 0xF];
- _gfx->flatBlitCnv(&face, QUESTION_CHARACTER_X, QUESTION_CHARACTER_Y, Gfx::kBitFront);
- _gfx->getStringExtent(q->_text, MAX_BALLOON_WIDTH, &w, &h);
+ _vm->_gfx->flatBlitCnv(&face, QUESTION_CHARACTER_X, QUESTION_CHARACTER_Y, Gfx::kBitFront);
+ _vm->_gfx->getStringExtent(_q->_text, MAX_BALLOON_WIDTH, &w, &h);
Common::Rect r(w, h);
r.moveTo(QUESTION_BALLOON_X, QUESTION_BALLOON_Y);
- _gfx->drawBalloon(r, q->_mood & 0x10);
- _gfx->displayWrappedString(q->_text, QUESTION_BALLOON_X, QUESTION_BALLOON_Y, MAX_BALLOON_WIDTH, 0);
- _gfx->updateScreen();
+ _vm->_gfx->drawBalloon(r, _q->_mood & 0x10);
+ _vm->_gfx->displayWrappedString(_q->_text, QUESTION_BALLOON_X, QUESTION_BALLOON_Y, MAX_BALLOON_WIDTH, 0);
+ _vm->_gfx->updateScreen();
waitUntilLeftClick();
- _gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
+ _vm->_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
return;
}
-uint16 Parallaction::getDialogueAnswer(Dialogue *q, Cnv *cnv) {
+uint16 DialogueManager::getAnswer() {
uint16 answer = 0;
StaticCnv face;
- face._width = cnv->_width;
- face._height = cnv->_height;
- face._data0 = cnv->getFramePtr(0);
+ face._width = _answerer->_width;
+ face._height = _answerer->_height;
+ face._data0 = _answerer->getFramePtr(0);
face._data1 = NULL; // cnv->field_8[0];
- _gfx->flatBlitCnv(&face, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
+ _vm->_gfx->flatBlitCnv(&face, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
if (_askPassword == false) {
- answer = selectAnswer(q, &face);
+ answer = selectAnswer(&face);
} else {
- answer = askDialoguePassword(q, &face);
+ answer = askPassword(&face);
}
- _gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront); // erase answer screen
+ _vm->_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront); // erase answer screen
debugC(1, kDebugDialogue, "runDialogue: user selected answer #%i", answer);
return answer;
}
-void Parallaction::runDialogue(SpeakData *data) {
- debugC(1, kDebugDialogue, "runDialogue: starting dialogue '%s'", data->_name);
-
- enterDialogue();
-
- _gfx->setFont(kFontDialogue);
-
- bool isNpc = scumm_stricmp(data->_name, "yourself") && data->_name[0] != '\0';
- Cnv *face = isNpc ? _disk->loadTalk(data->_name) : _char._talk;
+void DialogueManager::run() {
_askPassword = false;
CommandList *cmdlist = NULL;
- uint16 answer;
- Dialogue *q = data->_dialogue;
- while (q) {
+ _q = _dialogue;
+ int16 answer;
+
+ while (_q) {
answer = 0;
- displayQuestion(q, face);
- if (q->_answers[0] == NULL) break;
+ displayQuestion();
+ if (_q->_answers[0] == NULL) break;
_answerBalloonY[0] = 10;
- if (scumm_stricmp(q->_answers[0]->_text, "NULL")) {
- if (!displayAnswers(q)) break;
- answer = getDialogueAnswer(q, _char._talk);
- cmdlist = &q->_answers[answer]->_commands;
+ if (scumm_stricmp(_q->_answers[0]->_text, "NULL")) {
+ if (!displayAnswers()) break;
+ answer = getAnswer();
+ cmdlist = &_q->_answers[answer]->_commands;
}
- q = q->_answers[answer]->_following._question;
+ _q = _q->_answers[answer]->_following._question;
}
- debugC(1, kDebugDialogue, "runDialogue: out of dialogue loop");
-
- _gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
+ _vm->_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
- if (isNpc) {
- delete face;
- }
-
- exitDialogue();
if (cmdlist)
- runCommands(*cmdlist);
-
- return;
+ _vm->runCommands(*cmdlist);
}
-int16 Parallaction::selectAnswer(Question *q, StaticCnv *cnv) {
+int16 DialogueManager::selectAnswer(StaticCnv *cnv) {
int16 numAvailableAnswers = 0;
int16 _si = 0;
int16 _di = 0;
int16 i = 0;
- for (; q->_answers[i]; i++) {
+ for (; _q->_answers[i]; i++) {
if (_answerBalloonY[i] == SKIPPED_ANSWER) continue;
_di = i;
@@ -410,11 +432,11 @@ int16 Parallaction::selectAnswer(Question *q, StaticCnv *cnv) {
_answerBalloonY[i] = 2000;
if (numAvailableAnswers == 1) {
- _gfx->displayWrappedString(q->_answers[_di]->_text, _answerBalloonX[_di], _answerBalloonY[_di], MAX_BALLOON_WIDTH, 0);
- cnv->_data0 = _char._talk->getFramePtr(q->_answers[_di]->_mood & 0xF);
-// cnv->_data1 = _char._talk->field_8[q->_answers[_di]->_mood & 0xF];
- _gfx->flatBlitCnv(cnv, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
- _gfx->updateScreen();
+ _vm->_gfx->displayWrappedString(_q->_answers[_di]->_text, _answerBalloonX[_di], _answerBalloonY[_di], MAX_BALLOON_WIDTH, 0);
+ cnv->_data0 = _answerer->getFramePtr(_q->_answers[_di]->_mood & 0xF);
+// cnv->_data1 = _answerer->field_8[q->_answers[_di]->_mood & 0xF];
+ _vm->_gfx->flatBlitCnv(cnv, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
+ _vm->_gfx->updateScreen();
waitUntilLeftClick();
return _di;
}
@@ -424,20 +446,20 @@ int16 Parallaction::selectAnswer(Question *q, StaticCnv *cnv) {
_mouseButtons = kMouseNone;
while (_mouseButtons != kMouseLeftUp) {
- updateInput();
- _si = getHoverAnswer(_mousePos.x, _mousePos.y, q);
+ _vm->updateInput();
+ _si = getHoverAnswer(_vm->_mousePos.x, _vm->_mousePos.y);
if (_si != v2) {
if (v2 != -1)
- _gfx->displayWrappedString(q->_answers[v2]->_text, _answerBalloonX[v2], _answerBalloonY[v2], MAX_BALLOON_WIDTH, 3);
+ _vm->_gfx->displayWrappedString(_q->_answers[v2]->_text, _answerBalloonX[v2], _answerBalloonY[v2], MAX_BALLOON_WIDTH, 3);
- _gfx->displayWrappedString(q->_answers[_si]->_text, _answerBalloonX[_si], _answerBalloonY[_si], MAX_BALLOON_WIDTH, 0);
- cnv->_data0 = _char._talk->getFramePtr(q->_answers[_si]->_mood & 0xF);
-// cnv->_data1 = _char._talk->field_8[q->_answers[_si]->_mood & 0xF];
- _gfx->flatBlitCnv(cnv, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
+ _vm->_gfx->displayWrappedString(_q->_answers[_si]->_text, _answerBalloonX[_si], _answerBalloonY[_si], MAX_BALLOON_WIDTH, 0);
+ cnv->_data0 = _answerer->getFramePtr(_q->_answers[_si]->_mood & 0xF);
+// cnv->_data1 = _answerer->field_8[q->_answers[_si]->_mood & 0xF];
+ _vm->_gfx->flatBlitCnv(cnv, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y, Gfx::kBitFront);
}
- _gfx->updateScreen();
+ _vm->_gfx->updateScreen();
g_system->delayMillis(30);
v2 = _si;
}
@@ -449,13 +471,13 @@ int16 Parallaction::selectAnswer(Question *q, StaticCnv *cnv) {
//
// finds out which answer is currently selected
//
-int16 getHoverAnswer(int16 x, int16 y, Question *q) {
+int16 DialogueManager::getHoverAnswer(int16 x, int16 y) {
int16 top = 1000;
int16 bottom = 1000;
for (int16 _si = 0; _si < NUM_ANSWERS; _si++) {
- if (q->_answers[_si] == NULL) break;
+ if (_q->_answers[_si] == NULL) break;
if (_answerBalloonY[_si] != SKIPPED_ANSWER) {
top = _answerBalloonY[_si];
@@ -476,21 +498,19 @@ int16 getHoverAnswer(int16 x, int16 y, Question *q) {
}
-void Parallaction::enterDialogue() {
+void Parallaction::runDialogue(SpeakData *data) {
+ debugC(1, kDebugDialogue, "runDialogue: starting dialogue '%s'", data->_name);
+
+ _gfx->setFont(kFontDialogue);
showCursor(false);
-
- return;
-}
-// rebuilds inventory
-//
-void Parallaction::exitDialogue() {
+ DialogueManager man(this, data);
+ man.run();
refreshInventory(_characterName);
-
showCursor(true);
-
+
return;
}
diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h
index 38db16ce99..5f7ada5d68 100644
--- a/engines/parallaction/parallaction.h
+++ b/engines/parallaction/parallaction.h
@@ -62,7 +62,7 @@ enum {
enum {
GF_DEMO = 1 << 0,
GF_LANG_EN = 1 << 1,
- GF_LANG_FR = 1 << 2,
+ GF_LANG_FR = 1 << 2,
GF_LANG_DE = 1 << 3,
GF_LANG_IT = 1 << 4,
GF_LANG_MULT = 1 << 5
@@ -398,7 +398,7 @@ protected: // data
bool _skipMenu;
bool _mouseHidden;
-
+
// input-only
InputData _input;
bool _actionAfterWalk; // actived when the character needs to move before taking an action
@@ -461,15 +461,6 @@ protected: // members
void freeCharacter();
- uint16 askDialoguePassword(Dialogue *q, StaticCnv *face);
- bool displayAnswer(Dialogue *q, uint16 i);
- bool displayAnswers(Dialogue *q);
- void displayQuestion(Dialogue *q, Cnv *cnv);
- uint16 getDialogueAnswer(Dialogue *q, Cnv *cnv);
- int16 selectAnswer(Question *q, StaticCnv *cnv);
- void enterDialogue();
- void exitDialogue();
-
int addInventoryItem(uint16 item);
void dropItem(uint16 item);
int16 pickupItem(Zone *z);