aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlukaslw2014-07-03 20:53:19 +0200
committerlukaslw2014-07-03 20:53:19 +0200
commit4792795ac76c7103d07e9412c15fb0528c5a46a1 (patch)
tree275762fba645c2bdf625aa22c49b3d917860b3a2
parent54d3dc903ea57cbf90eceaf1bfbaa304e9b35bbe (diff)
downloadscummvm-rg350-4792795ac76c7103d07e9412c15fb0528c5a46a1.tar.gz
scummvm-rg350-4792795ac76c7103d07e9412c15fb0528c5a46a1.tar.bz2
scummvm-rg350-4792795ac76c7103d07e9412c15fb0528c5a46a1.zip
PRINCE: createDialogBox(), runDialog(), dialogLMB(), talkHero(), O_INITDIALOG(), O_SHOWDIALOGBOX() update
-rw-r--r--engines/prince/prince.cpp98
-rw-r--r--engines/prince/prince.h20
-rw-r--r--engines/prince/script.cpp85
-rw-r--r--engines/prince/script.h1
4 files changed, 102 insertions, 102 deletions
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp
index b91155344b..101af7b35c 100644
--- a/engines/prince/prince.cpp
+++ b/engines/prince/prince.cpp
@@ -87,7 +87,8 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc)
_optionsMob(-1), _currentPointerNumber(1), _selectedMob(-1), _selectedItem(0), _selectedMode(0),
_optionsWidth(210), _optionsHeight(170), _invOptionsWidth(210), _invOptionsHeight(130), _optionsStep(20),
_invOptionsStep(20), _optionsNumber(7), _invOptionsNumber(5), _optionsColor1(236), _optionsColor2(252),
- _dialogWidth(600), _dialogHeight(0), _dialogLineSpace(10), _dialogColor1(220), _dialogColor2(223), _dialogFlag(false) {
+ _dialogWidth(600), _dialogHeight(0), _dialogLineSpace(10), _dialogColor1(220), _dialogColor2(223),
+ _dialogFlag(false), _dialogLines(0), _dialogText(nullptr) {
// Debug/console setup
DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel");
@@ -2229,22 +2230,36 @@ void PrinceEngine::displayInventory() {
}
}
-void PrinceEngine::createDialogBox(Common::Array<DialogLine> &dialogData) {
- int amountOfDialogLines = 0;
- int amountOfDialogOptions = dialogData.size();
+void PrinceEngine::createDialogBox(int dialogBoxNr) {
+ _dialogLines = 0;
+ int amountOfDialogOptions = 0;
+ int dialogDataValue = (int)READ_UINT32(_dialogData);
- for (int i = 0; i < amountOfDialogOptions; i++) {
- amountOfDialogLines += calcText(dialogData[i]._line.c_str());
+ byte c;
+ int sentenceNumber;
+ _dialogText = _dialogBoxAddr[dialogBoxNr];
+ byte *dialogText = _dialogText;
+
+ while ((sentenceNumber = *dialogText) != 0xFF) {
+ dialogText++;
+ if (!(dialogDataValue & (1 << sentenceNumber))) {
+ _dialogLines += calcText((const char *)dialogText);
+ amountOfDialogOptions++;
+ }
+ do {
+ c = *dialogText;
+ dialogText++;
+ } while (c);
}
- _dialogHeight = _font->getFontHeight() * amountOfDialogLines + _dialogLineSpace * (amountOfDialogOptions + 1);
+ _dialogHeight = _font->getFontHeight() * _dialogLines + _dialogLineSpace * (amountOfDialogOptions + 1);
_dialogImage = new Graphics::Surface();
_dialogImage->create(_dialogWidth, _dialogHeight, Graphics::PixelFormat::createFormatCLUT8());
Common::Rect dBoxRect(0, 0, _dialogWidth, _dialogHeight);
_dialogImage->fillRect(dBoxRect, _graph->kShadowColor);
}
-void PrinceEngine::runDialog(Common::Array<DialogLine> &dialogData) {
+void PrinceEngine::runDialog() {
_dialogFlag = true;
@@ -2265,27 +2280,38 @@ void PrinceEngine::runDialog(Common::Array<DialogLine> &dialogData) {
Common::Point mousePos = _system->getEventManager()->getMousePos();
+ byte c;
+ int sentenceNumber;
+ byte *dialogText = _dialogText;
+ byte *dialogCurrentText = nullptr;
int dialogSelected = -1;
- int dialogSelectedText = -1;
+ int dialogDataValue = (int)READ_UINT32(_dialogData);
- for (uint i = 0; i < dialogData.size(); i++) {
+ while ((sentenceNumber = *dialogText) != 0xFF) {
+ dialogText++;
int actualColor = _dialogColor1;
- Common::Array<Common::String> lines;
- _font->wordWrapText(dialogData[i]._line, _graph->_frontScreen->w, lines);
+ if (!(dialogDataValue & (1 << sentenceNumber))) {
+ Common::Array<Common::String> lines;
+ _font->wordWrapText((const char *)dialogText, _graph->_frontScreen->w, lines);
- Common::Rect dialogOption(dialogTextX, dialogTextY - dialogSkipUp / 2, dialogX + _dialogWidth - dialogSkipLeft, dialogTextY + lines.size() * _font->getFontHeight() + dialogSkipUp / 2 - 1);
- if (dialogOption.contains(mousePos)) {
- actualColor = _dialogColor2;
- dialogSelected = dialogData[i]._nr;
- dialogSelectedText = i;
- }
+ Common::Rect dialogOption(dialogTextX, dialogTextY - dialogSkipUp / 2, dialogX + _dialogWidth - dialogSkipLeft, dialogTextY + lines.size() * _font->getFontHeight() + dialogSkipUp / 2 - 1);
+ if (dialogOption.contains(mousePos)) {
+ actualColor = _dialogColor2;
+ dialogSelected = sentenceNumber;
+ dialogCurrentText = dialogText;
+ }
- for (uint j = 0; j < lines.size(); j++) {
- _font->drawString(_graph->_frontScreen, lines[j], dialogTextX, dialogTextY, _graph->_frontScreen->w, actualColor);
- dialogTextY += _font->getFontHeight();
+ for (uint j = 0; j < lines.size(); j++) {
+ _font->drawString(_graph->_frontScreen, lines[j], dialogTextX, dialogTextY, _graph->_frontScreen->w, actualColor);
+ dialogTextY += _font->getFontHeight();
+ }
+ dialogTextY += _dialogLineSpace;
}
- dialogTextY += _dialogLineSpace;
+ do {
+ c = *dialogText;
+ dialogText++;
+ } while (c);
}
Common::Event event;
@@ -2301,7 +2327,7 @@ void PrinceEngine::runDialog(Common::Array<DialogLine> &dialogData) {
break;
case Common::EVENT_LBUTTONDOWN:
if (dialogSelected != -1) {
- dialogLeftMouseButton(dialogSelected, dialogData[dialogSelectedText]._line.c_str());
+ dialogLeftMouseButton(dialogCurrentText, dialogSelected);
_dialogFlag = false;
}
break;
@@ -2336,15 +2362,29 @@ void PrinceEngine::runDialog(Common::Array<DialogLine> &dialogData) {
// cursor?
}
-void PrinceEngine::dialogLeftMouseButton(int dialogSelected, const char *s) {
- //TODO @@showa_dialoga:
- talkHero(0, s);
+void PrinceEngine::dialogLeftMouseButton(byte *string, int dialogSelected) {
+ _interpreter->setString(string);
+ talkHero(0);
+
+ int dialogDataValue = (int)READ_UINT32(_dialogData);
+ int newValue = (dialogDataValue & (1 << dialogSelected)); // FIXME
+ WRITE_UINT32(_dialogData, newValue); // FIXME
+
+ _flags->setFlagValue(Flags::BOXSEL, dialogSelected + 1);
+ setVoice(0, 28, dialogSelected + 1);
+
+ int dialogOpt = dialogSelected << 4;
+ _flags->setFlagValue(Flags::VOICE_H_LINE, _dialogOptLines[dialogOpt]);
+ _flags->setFlagValue(Flags::VOICE_A_LINE, _dialogOptLines[dialogOpt + 1]);
+ _flags->setFlagValue(Flags::VOICE_B_LINE, _dialogOptLines[dialogOpt + 2]);
+
+ _interpreter->setString(_dialogOptAddr[dialogSelected]);
}
-void PrinceEngine::talkHero(int slot, const char *s) {
+void PrinceEngine::talkHero(int slot) {
// heroSlot = textSlot
Text &text = _textSlots[slot];
- int lines = calcText(s);
+ int lines = calcText((const char *)_interpreter->getString());
int time = lines * 30;
if (slot == 0) {
@@ -2361,7 +2401,7 @@ void PrinceEngine::talkHero(int slot, const char *s) {
text._y = _secondHero->_middleY - _secondHero->_scaledFrameYSize;
}
text._time = time; // changed by SETSPECVOICE?
- text._str = s;
+ text._str = (const char *)_interpreter->getString();
_interpreter->increaseString();
}
diff --git a/engines/prince/prince.h b/engines/prince/prince.h
index 3110d6d9a5..d59a888815 100644
--- a/engines/prince/prince.h
+++ b/engines/prince/prince.h
@@ -234,11 +234,6 @@ struct DrawNode {
void (*drawFunction)(Graphics::Surface *, DrawNode *);
};
-struct DialogLine {
- int _nr;
- Common::String _line;
-};
-
struct DebugChannel {
enum Type {
@@ -309,7 +304,6 @@ public:
Common::Array<AnimListItem> _animList;
Common::Array<BackgroundAnim> _backAnimList;
Common::Array<Anim> _normAnimList;
- Common::Array<Common::Array<DialogLine>> _dialogBoxList;
Common::Array<Mob> _mobList;
void freeNormAnim(int slot);
@@ -396,12 +390,18 @@ public:
void rightMouseButton();
void inventoryLeftMouseButton();
void inventoryRightMouseButton();
- void dialogLeftMouseButton(int dialogSelected, const char *s);
+ void dialogLeftMouseButton(byte *string, int dialogSelected);
uint32 _dialogDatSize;
byte *_dialogDat;
byte *_dialogData; // on, off flags for lines of dialog text
+ byte *_dialogBoxAddr[32]; // adresses of dialog windows
+ byte *_dialogOptAddr[32]; // adresses of dialog options
+ int _dialogOptLines[4 * 32]; // numbers of initial dialog lines
+
+ byte *_dialogText;
+ int _dialogLines;
bool _dialogFlag;
int _dialogWidth;
int _dialogHeight;
@@ -410,9 +410,9 @@ public:
int _dialogColor2; // color for selected option
Graphics::Surface *_dialogImage;
- void createDialogBox(Common::Array<DialogLine> &dialogData);
- void runDialog(Common::Array<DialogLine> &dialogData);
- void talkHero(int slot, const char *s);
+ void createDialogBox(int dialogBoxNr);
+ void runDialog();
+ void talkHero(int slot);
void doTalkAnim(int animNumber, int slot, AnimType animType);
int testAnimNr;
diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp
index ec31cda739..3fe03e8c1d 100644
--- a/engines/prince/script.cpp
+++ b/engines/prince/script.cpp
@@ -526,6 +526,10 @@ byte *Interpreter::getString() {
return _string;
}
+void Interpreter::setString(byte *newString) {
+ _string = newString;
+}
+
void Interpreter::increaseString() {
while (*_string) {
_string++;
@@ -1125,7 +1129,7 @@ void Interpreter::O_CHECKINV() {
void Interpreter::O_TALKHERO() {
uint16 hero = readScriptFlagValue();
debugInterpreter("O_TALKHERO hero %d", hero);
- _vm->talkHero(hero, (const char *)_string);
+ _vm->talkHero(hero);
}
void Interpreter::O_WAITTEXT() {
@@ -1371,22 +1375,13 @@ void Interpreter::O_INITDIALOG() {
stringCurrOff += 2;
_string = string + adressOfFirstSequence;
- for (uint i = 0; i < _vm->_dialogBoxList.size(); i++) {
- _vm->_dialogBoxList[i].clear();
- }
- _vm->_dialogBoxList.clear();
-
- byte *dialogBoxAddr[32]; // adresses of dialog windows
- byte *dialogOptAddr[32]; // adresses of dialog options
- int dialogOptLines[4 * 32]; // numbers of initial dialog lines
-
for (int i = 0; i < 32; i++) {
- dialogBoxAddr[i] = 0;
- dialogOptAddr[i] = 0;
+ _vm->_dialogBoxAddr[i] = 0;
+ _vm->_dialogOptAddr[i] = 0;
}
for (int i = 0; i < 4 * 32; i++) {
- dialogOptLines[i] = 0;
+ _vm->_dialogOptLines[i] = 0;
}
int16 off;
@@ -1398,7 +1393,7 @@ void Interpreter::O_INITDIALOG() {
if (off) {
line = string + off;
}
- dialogBoxAddr[dialogBox] = line;
+ _vm->_dialogBoxAddr[dialogBox] = line;
dialogBox++;
}
stringCurrOff += 2;
@@ -1409,49 +1404,16 @@ void Interpreter::O_INITDIALOG() {
if (off) {
line = string + off;
}
- dialogOptAddr[dialogOpt] = line;
+ _vm->_dialogOptAddr[dialogOpt] = line;
dialogOpt++;
}
- dialogBox = 0;
- byte c;
- int sentenceNumber;
- DialogLine tempDialogLine;
- Common::Array<DialogLine> tempDialogBox;
-
- while (dialogBoxAddr[dialogBox]) {
- tempDialogBox.clear();
- byte *boxAddr = dialogBoxAddr[dialogBox];
- int dialogDataValue = (int)READ_UINT32(_vm->_dialogData);
- while ((sentenceNumber = *boxAddr) != 0xFF) {
- boxAddr++;
- if (!(dialogDataValue & (1 << sentenceNumber))) {
- tempDialogLine._line.clear();
- tempDialogLine._nr = sentenceNumber;
- while ((c = *boxAddr)) {
- tempDialogLine._line += c;
- boxAddr++;
- }
- boxAddr++;
- tempDialogBox.push_back(tempDialogLine);
- } else {
- do {
- c = *boxAddr;
- boxAddr++;
- } while (c);
- }
- }
- _vm->_dialogBoxList.push_back(tempDialogBox);
- dialogBox++;
- }
-
- // TODO - dialogOptAddr, dialogOptLines
_flags->setFlagValue(Flags::VOICE_A_LINE, 0);
_flags->setFlagValue(Flags::VOICE_B_LINE, 0); // bx in original?
int freeHSlot = 0;
for (int i = 31; i >= 0; i--) {
- if (dialogOptAddr[i] != 0) {
+ if (_vm->_dialogOptAddr[i] != 0) {
i++;
freeHSlot = i;
_flags->setFlagValue(Flags::VOICE_H_LINE, i);
@@ -1462,11 +1424,11 @@ void Interpreter::O_INITDIALOG() {
freeHSlot += checkSeq(_string);
for (int i = 0; i < 32; i++) {
- dialogOptLines[i * 4] = freeHSlot;
- dialogOptLines[i * 4 + 1] = freeHSlot;
- dialogOptLines[i * 4 + 2] = freeHSlot;
- if (dialogOptAddr[i]) {
- freeHSlot += checkSeq(dialogOptAddr[i]);
+ _vm->_dialogOptLines[i * 4] = freeHSlot;
+ _vm->_dialogOptLines[i * 4 + 1] = freeHSlot;
+ _vm->_dialogOptLines[i * 4 + 2] = freeHSlot;
+ if (_vm->_dialogOptAddr[i]) {
+ freeHSlot += checkSeq(_vm->_dialogOptAddr[i]);
}
}
}
@@ -1485,15 +1447,12 @@ void Interpreter::O_DISABLEDIALOGOPT() {
void Interpreter::O_SHOWDIALOGBOX() {
uint16 box = readScriptFlagValue();
debugInterpreter("O_SHOWDIALOGBOX box %d", box);
- if (box < _vm->_dialogBoxList.size()) {
- _vm->createDialogBox(_vm->_dialogBoxList[box]);
- int dialogLines = _vm->_dialogBoxList[box].size();
- _flags->setFlagValue(Flags::DIALINES, dialogLines);
- if (dialogLines != 0) {
- _vm->changeCursor(1);
- _vm->runDialog(_vm->_dialogBoxList[box]);
- _vm->changeCursor(0);
- }
+ _vm->createDialogBox(box);
+ _flags->setFlagValue(Flags::DIALINES, _vm->_dialogLines);
+ if (_vm->_dialogLines != 0) {
+ _vm->changeCursor(1);
+ _vm->runDialog();
+ _vm->changeCursor(0);
}
}
diff --git a/engines/prince/script.h b/engines/prince/script.h
index a822b44ccb..5f9cdc3ab3 100644
--- a/engines/prince/script.h
+++ b/engines/prince/script.h
@@ -186,6 +186,7 @@ public:
void setCurrentString(uint32 value);
byte *getString();
+ void setString(byte *newString);
void increaseString();