[Scummvm-git-logs] scummvm master -> 57ab02bf467042d7e23981746b8f0568a67a9577
bluegr
noreply at scummvm.org
Mon Mar 28 21:22:34 UTC 2022
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:
57ab02bf46 CHEWY: More work on text handling
Commit: 57ab02bf467042d7e23981746b8f0568a67a9577
https://github.com/scummvm/scummvm/commit/57ab02bf467042d7e23981746b8f0568a67a9577
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-03-29T00:21:53+03:00
Commit Message:
CHEWY: More work on text handling
Changed paths:
engines/chewy/atds.cpp
engines/chewy/atds.h
engines/chewy/debugger.cpp
engines/chewy/dialogs/cinema.cpp
engines/chewy/dialogs/inventory.cpp
engines/chewy/globals.h
engines/chewy/main.cpp
engines/chewy/menus.cpp
engines/chewy/rooms/room00.cpp
engines/chewy/t_event.cpp
engines/chewy/text.cpp
engines/chewy/text.h
diff --git a/engines/chewy/atds.cpp b/engines/chewy/atds.cpp
index e83b49e8514..28ff29649f5 100644
--- a/engines/chewy/atds.cpp
+++ b/engines/chewy/atds.cpp
@@ -496,8 +496,10 @@ DisplayMode Atdsys::start_ats(int16 txtNr, int16 txtMode, int16 color, int16 mod
if (_atsv._display != DISPLAY_NONE)
stop_ats();
+ //const uint8 roomNum = _G(room)->_roomInfo->_roomNr;
int16 txt_anz;
_atsv._ptr = ats_get_txt(txtNr, txtMode, &txt_anz, mode);
+ //_atsv._ptr = (char *)getTextEntry(roomNum, txtNr, txtMode).c_str();
if (_atsv._ptr) {
_atsv._display = _atdsv._display;
@@ -1304,13 +1306,6 @@ void Atdsys::show_item(int16 diaNr, int16 blockNr, int16 itemNr) {
}
int16 Atdsys::calc_inv_no_use(int16 curInv, int16 testNr, int16 mode) {
- if (curInv != -1) {
- if (_invBlockNr != curInv) {
- _invBlockNr = curInv + 1;
- load_atds(_invBlockNr + _atdsPoolOff[mode], INV_USE_DATA);
- }
- }
-
assert(mode <= 255 && testNr <= 65535);
const uint32 key = (mode & 0xff) << 16 | testNr;
@@ -1333,12 +1328,12 @@ uint32 Atdsys::getAtdsStreamSize() const {
return _dialogResource->getStreamSize();
}
-Common::StringArray Atdsys::getTextArray(uint dialogNum, uint entryNum) {
- return _text->getTextArray(dialogNum, entryNum);
+Common::StringArray Atdsys::getTextArray(uint dialogNum, uint entryNum, int type) {
+ return _text->getTextArray(dialogNum, entryNum, type);
}
-Common::String Atdsys::getTextEntry(uint dialogNum, uint entryNum) {
- return _text->getTextEntry(dialogNum, entryNum);
+Common::String Atdsys::getTextEntry(uint dialogNum, uint entryNum, int type) {
+ return _text->getTextEntry(dialogNum, entryNum, type);
}
} // namespace Chewy
diff --git a/engines/chewy/atds.h b/engines/chewy/atds.h
index f1261934dde..d29a9f04b81 100644
--- a/engines/chewy/atds.h
+++ b/engines/chewy/atds.h
@@ -312,8 +312,8 @@ public:
void loadAtdsStream(Common::SeekableReadStream *stream);
uint32 getAtdsStreamSize() const;
- Common::StringArray getTextArray(uint dialogNum, uint entryNum);
- Common::String getTextEntry(uint dialogNum, uint entryNum);
+ Common::StringArray getTextArray(uint dialogNum, uint entryNum, int type);
+ Common::String getTextEntry(uint dialogNum, uint entryNum, int type);
private:
int16 get_delay(int16 txt_len);
diff --git a/engines/chewy/debugger.cpp b/engines/chewy/debugger.cpp
index a304e6c2bd6..b3f218bd47b 100644
--- a/engines/chewy/debugger.cpp
+++ b/engines/chewy/debugger.cpp
@@ -101,14 +101,15 @@ bool Debugger::Cmd_WalkAreas(int argc, const char **argv) {
}
bool Debugger::Cmd_Text(int argc, const char **argv) {
- if (argc < 3) {
- debugPrintf("Usage: text <chunk> <entry>\n");
+ if (argc < 4) {
+ debugPrintf("Usage: text <chunk> <entry> <type>\n");
return true;
}
int chunk = atoi(argv[1]);
int entry = atoi(argv[2]);
- Common::StringArray text = _G(atds)->getTextArray(chunk, entry);
+ int type = atoi(argv[3]);
+ Common::StringArray text = _G(atds)->getTextArray(chunk, entry, type);
for (uint i = 0; i < text.size(); i++) {
debugPrintf("%d: %s\n", i, text[i].c_str());
}
diff --git a/engines/chewy/dialogs/cinema.cpp b/engines/chewy/dialogs/cinema.cpp
index fd8eff62d5d..b0ad6dff1be 100644
--- a/engines/chewy/dialogs/cinema.cpp
+++ b/engines/chewy/dialogs/cinema.cpp
@@ -73,7 +73,7 @@ void Cinema::execute() {
// Render cut-scene list
for (int i = 0; i < CINEMA_LINES; ++i) {
- cutsceneName = _G(atds)->getTextEntry(98 + 500, i + topIndex + 1);
+ cutsceneName = _G(atds)->getTextEntry(98, 546 + i + topIndex, ATS_DATA);
int yp = i * 10 + 68;
if (i == selected)
@@ -82,7 +82,7 @@ void Cinema::execute() {
}
} else {
// No cut-scene seen yet
- cutsceneName = _G(atds)->getTextEntry(98 + 500, 0);
+ cutsceneName = _G(atds)->getTextEntry(98, 545, ATS_DATA);
_G(out)->printxy(40, 68, 14, 300, _G(scr_width), cutsceneName.c_str());
}
diff --git a/engines/chewy/dialogs/inventory.cpp b/engines/chewy/dialogs/inventory.cpp
index 4421936468e..529f4ec8608 100644
--- a/engines/chewy/dialogs/inventory.cpp
+++ b/engines/chewy/dialogs/inventory.cpp
@@ -397,8 +397,8 @@ int16 Inventory::look(int16 invent_nr, int16 mode, int16 ats_nr) {
bool mouseFl = true;
if (mode == INV_ATS_MODE) {
- itemName = _G(atds)->getTextEntry(invent_nr + 700, TXT_MARK_NAME);
- itemDesc = _G(atds)->getTextArray(invent_nr + 700, TXT_MARK_LOOK);
+ itemName = _G(atds)->getTextEntry(invent_nr, TXT_MARK_NAME, INV_ATS_DATA);
+ itemDesc = _G(atds)->getTextArray(invent_nr, TXT_MARK_LOOK, INV_ATS_DATA);
lineCount = itemDesc.size();
xoff = itemName.size();
xoff *= _G(font8)->getDataWidth();
@@ -409,13 +409,12 @@ int16 Inventory::look(int16 invent_nr, int16 mode, int16 ats_nr) {
visibleCount = 3;
yoff = 0;
- //Common::StringArray tmp;
if (ats_nr >= 15000) {
txt_adr = _G(atds)->ats_get_txt(ats_nr - 15000, TXT_MARK_USE, &lineCount, INV_USE_DEF);
- //tmp = _G(atds)->getTextArray(ats_nr - 15000 + 840, TXT_MARK_USE);
+ //itemDesc = _G(atds)->getTextArray(ats_nr - 15000, TXT_MARK_USE, INV_USE_DEF);
} else {
txt_adr = _G(atds)->ats_get_txt(ats_nr, TXT_MARK_USE, &lineCount, INV_USE_DATA);
- //tmp = _G(atds)->getTextArray(ats_nr + 840, TXT_MARK_USE);
+ //itemDesc = _G(atds)->getTextArray(ats_nr, TXT_MARK_USE, INV_USE_DATA);
}
if (!txt_adr) {
endLoop = true;
diff --git a/engines/chewy/globals.h b/engines/chewy/globals.h
index 513ff9ca722..56c51714919 100644
--- a/engines/chewy/globals.h
+++ b/engines/chewy/globals.h
@@ -381,6 +381,7 @@ void remove_inventory(int16 nr);
void getDisplayCoord(int16 *x, int16 *y, int16 nr);
void calcTxtXy(int16 *x, int16 *y, char *txtAdr, int16 txtNr);
+void calcTxtXy(int16 *x, int16 *y, Common::StringArray &desc);
void adsMenu();
void stop_ads_dialog();
diff --git a/engines/chewy/main.cpp b/engines/chewy/main.cpp
index 3ad8b105faa..91ed2f8066b 100644
--- a/engines/chewy/main.cpp
+++ b/engines/chewy/main.cpp
@@ -670,8 +670,8 @@ void setupScreen(SetupScreenMode mode) {
}
void mous_obj_action(int16 nr, int16 mode, int16 txt_mode, int16 txt_nr) {
- int16 anz = 0;
- char *str_adr = nullptr;
+ const uint8 roomNum = _G(room)->_roomInfo->_roomNr;
+ Common::StringArray desc;
if (mode == DO_SETUP) {
@@ -680,19 +680,19 @@ void mous_obj_action(int16 nr, int16 mode, int16 txt_mode, int16 txt_nr) {
switch (txt_mode) {
case INVENTORY_NORMAL:
case INVENTORY_STATIC:
- str_adr = _G(atds)->ats_get_txt(txt_nr, TXT_MARK_NAME, &anz, ATS_DATA);
+ desc = _G(atds)->getTextArray(roomNum, txt_nr, ATS_DATA);
break;
default:
break;
}
- if (str_adr) {
+ if (desc.size() > 0) {
_G(fontMgr)->setFont(_G(font8));
int16 x = g_events->_mousePos.x;
int16 y = g_events->_mousePos.y;
- calcTxtXy(&x, &y, str_adr, anz);
- for (int16 i = 0; i < anz; i++)
- printShadowed(x, y + i * 10, 255, 300, 0, _G(scr_width), _G(txt)->strPos(str_adr, i));
+ calcTxtXy(&x, &y, desc);
+ for (int16 i = 0; i < desc.size(); i++)
+ printShadowed(x, y + i * 10, 255, 300, 0, _G(scr_width), desc[i].c_str());
}
}
}
@@ -1420,16 +1420,15 @@ int16 calcMouseText(int16 x, int16 y, int16 mode) {
}
if (dispFl && !actionFl) {
- int16 anz;
- char *str_ = _G(atds)->ats_get_txt(txtNr, TXT_MARK_NAME, &anz, ATS_DATA);
- if (str_ != 0) {
- //const uint8 roomNr = _G(room)->_roomInfo->_roomNr;
- //Common::StringArray s = _G(atds)->getTextArray(roomNr + 500, txtNr);
+ const uint8 roomNum = _G(room)->_roomInfo->_roomNr;
+ Common::StringArray desc = _G(atds)->getTextArray(roomNum, txtNr, ATS_DATA);
+
+ if (desc.size() > 0) {
ret = txtNr;
_G(fontMgr)->setFont(_G(font8));
- calcTxtXy(&x, &y, str_, anz);
- for (int16 i = 0; i < anz; i++)
- printShadowed(x, y + i * 10, 255, 300, 0, _G(scr_width), _G(txt)->strPos((char *)str_, i));
+ calcTxtXy(&x, &y, desc);
+ for (int16 i = 0; i < desc.size(); i++)
+ printShadowed(x, y + i * 10, 255, 300, 0, _G(scr_width), desc[i].c_str());
}
}
} else {
diff --git a/engines/chewy/menus.cpp b/engines/chewy/menus.cpp
index 216fcaa1460..a4423aeff73 100644
--- a/engines/chewy/menus.cpp
+++ b/engines/chewy/menus.cpp
@@ -91,9 +91,9 @@ void plotMainMenu() {
}
}
-void calcTxtXy(int16 *x, int16 *y, char *txtAdr, int16 txtNr) {
+void calcTxtXy(int16 *x, int16 *y, char *txtAdr, int16 txtCount) {
int16 len = 0;
- for (int16 i = 0; i < txtNr; i++) {
+ for (int16 i = 0; i < txtCount; i++) {
int16 tmpLen = strlen(_G(txt)->strPos(txtAdr, i));
if (tmpLen > len)
len = tmpLen;
@@ -105,7 +105,25 @@ void calcTxtXy(int16 *x, int16 *y, char *txtAdr, int16 txtNr) {
*x = SCREEN_WIDTH - len;
else if (*x < 0)
*x = 0;
- *y = *y - (10 * txtNr);
+ *y = *y - (10 * txtCount);
+ if (*y < 0)
+ *y = 0;
+}
+
+void calcTxtXy(int16 *x, int16 *y, Common::StringArray &textList) {
+ int16 len = 0;
+ for (int16 i = 0; i < textList.size(); i++) {
+ if (textList[i].size() > len)
+ len = textList[i].size();
+ }
+ len = len * _G(fontMgr)->getFont()->getDataWidth();
+ int16 pixLen = len / 2;
+ *x = *x - pixLen + 12;
+ if (*x > (SCREEN_WIDTH - len))
+ *x = SCREEN_WIDTH - len;
+ else if (*x < 0)
+ *x = 0;
+ *y = *y - (10 * textList.size());
if (*y < 0)
*y = 0;
}
diff --git a/engines/chewy/rooms/room00.cpp b/engines/chewy/rooms/room00.cpp
index 9c4f3b6ed29..e439e755cf7 100644
--- a/engines/chewy/rooms/room00.cpp
+++ b/engines/chewy/rooms/room00.cpp
@@ -300,15 +300,15 @@ void Room0::eyeWait() {
void Room0::calcEyeClick(int16 aniNr) {
if (mouse_on_prog_ani() == aniNr) {
if (_G(minfo)._button != 1 && g_events->_kbInfo._keyCode != Common::KEYCODE_RETURN) {
- int16 anz;
- char *str_ = _G(atds)->ats_get_txt(172, TXT_MARK_NAME, &anz, ATS_DATA);
- if (str_ != 0) {
+ const uint8 roomNum = _G(room)->_roomInfo->_roomNr;
+ Common::StringArray desc = _G(atds)->getTextArray(roomNum, 172, ATS_DATA);
+ if (desc.size() > 0) {
_G(fontMgr)->setFont(_G(font8));
int16 x = g_events->_mousePos.x;
int16 y = g_events->_mousePos.y;
- calcTxtXy(&x, &y, str_, anz);
- for (int16 i = 0; i < anz; i++)
- printShadowed(x, y + i * 10, 255, 300, 0, _G(scr_width), _G(txt)->strPos((char *)str_, i));
+ calcTxtXy(&x, &y, desc);
+ for (int16 i = 0; i < desc.size(); i++)
+ printShadowed(x, y + i * 10, 255, 300, 0, _G(scr_width), desc[i].c_str());
}
} else if (_G(minfo)._button == 1 || g_events->_kbInfo._keyCode == Common::KEYCODE_RETURN) {
if (isCurInventory(SLIME_INV)) {
@@ -538,15 +538,15 @@ void Room0::feederExtend() {
void Room0::calcPillowClick(int16 aniNr) {
if (mouse_on_prog_ani() == aniNr) {
if (_G(minfo)._button != 1 && g_events->_kbInfo._keyCode != Common::KEYCODE_RETURN) {
- int16 anz;
- char *str_ = _G(atds)->ats_get_txt(173, TXT_MARK_NAME, &anz, ATS_DATA);
- if (str_ != nullptr) {
+ const uint8 roomNum = _G(room)->_roomInfo->_roomNr;
+ Common::StringArray desc = _G(atds)->getTextArray(roomNum, 173, ATS_DATA);
+ if (desc.size() > 0) {
_G(fontMgr)->setFont(_G(font8));
int16 x = g_events->_mousePos.x;
int16 y = g_events->_mousePos.y;
- calcTxtXy(&x, &y, str_, anz);
- for (int16 i = 0; i < anz; i++)
- printShadowed(x, y + i * 10, 255, 300, 0, _G(scr_width), _G(txt)->strPos((char *)str_, i));
+ calcTxtXy(&x, &y, desc);
+ for (int16 i = 0; i < desc.size(); i++)
+ printShadowed(x, y + i * 10, 255, 300, 0, _G(scr_width), desc[i].c_str());
}
} else if (_G(minfo)._button == 1 || g_events->_kbInfo._keyCode == Common::KEYCODE_RETURN) {
if (isCurInventory(PILLOW_INV) && _G(gameState).R0SlimeUsed) {
diff --git a/engines/chewy/t_event.cpp b/engines/chewy/t_event.cpp
index 97e5ba009f2..3ff3d61bd9a 100644
--- a/engines/chewy/t_event.cpp
+++ b/engines/chewy/t_event.cpp
@@ -2299,15 +2299,11 @@ static void calc_inv_get_text(int16 cur_inv, int16 test_nr) {
const char *s = _G(atds)->ats_get_txt(31, TXT_MARK_USE, &txt_anz, INV_USE_DEF);
_G(calc_inv_text_str1) = Common::String::format("%s ", s);
-
- _G(atds)->load_atds(cur_inv, INV_ATS_DATA);
-
- _G(calc_inv_text_str1) += _G(atds)->getTextEntry(cur_inv + 700, TXT_MARK_NAME);
+ _G(calc_inv_text_str1) += _G(atds)->getTextEntry(cur_inv, TXT_MARK_NAME, INV_ATS_DATA);
s = _G(atds)->ats_get_txt(32, TXT_MARK_USE, &txt_anz, INV_USE_DEF);
_G(calc_inv_text_str2) = Common::String::format("%s ", s);
-
- _G(calc_inv_text_str2) += _G(atds)->getTextEntry(test_nr + 700, TXT_MARK_NAME);
+ _G(calc_inv_text_str2) += _G(atds)->getTextEntry(test_nr, TXT_MARK_NAME, INV_ATS_DATA);
}
bool calc_inv_no_use(int16 test_nr, int16 mode) {
diff --git a/engines/chewy/text.cpp b/engines/chewy/text.cpp
index 7b80ee51230..980be182942 100644
--- a/engines/chewy/text.cpp
+++ b/engines/chewy/text.cpp
@@ -22,6 +22,8 @@
#include "common/system.h"
#include "chewy/resource.h"
#include "chewy/text.h"
+#include "chewy/atds.h"
+#include "chewy/defines.h"
namespace Chewy {
@@ -79,27 +81,54 @@ TextEntryList *Text::getDialog(uint chunk, uint entry) {
return l;
}
-TextEntry *Text::getText(uint chunk, uint entry) {
+TextEntry *Text::getText(uint chunk, uint entry, int type) {
+ switch (type) {
+ case AAD_DATA:
+ chunk += AAD_TAP_OFF;
+ break;
+ case ATS_DATA:
+ chunk += ATS_TAP_OFF;
+ break;
+ case ADS_DATA:
+ chunk += ADS_TAP_OFF;
+ break;
+ case INV_USE_DATA:
+ chunk += USE_TAP_OFF;
+ break;
+ case INV_ATS_DATA:
+ chunk += INV_TAP_OFF;
+ break;
+ }
+
if (chunk < kADSTextMax)
- error("getText(): Invalid entry number requested, %d (min %d)", chunk, kADSTextMax);
+ error("getText(): Invalid chunk number requested, %d (min %d)", chunk, kADSTextMax);
TextEntry *d = new TextEntry();
- bool isText = (chunk >= kADSTextMax && chunk < kADSTextMax + kATSTextMax);
- bool isAutoDialog = (chunk >= kADSTextMax + kATSTextMax && chunk < kADSTextMax + kATSTextMax + kAADTextMax);
+ const bool isText = (chunk >= kADSTextMax && chunk < kADSTextMax + kATSTextMax);
+ const bool isAutoDialog = (chunk >= kADSTextMax + kATSTextMax && chunk < kADSTextMax + kATSTextMax + kAADTextMax);
+ const bool isInvDesc = (chunk >= kADSTextMax + kATSTextMax + kAADTextMax && chunk < kADSTextMax + kATSTextMax + kAADTextMax + kINVTextMax);
byte *data = getChunkData(chunk);
byte *ptr = data;
+ uint entryId = 0;
if (isAutoDialog)
ptr += 3;
- for (uint i = 0; i <= entry; i++) {
- ptr += 13;
+ while (true) {
+ ptr += 3;
+ uint16 headerBytes = READ_LE_UINT16(ptr);
+ ptr += 2;
+ if (headerBytes != 0xFEF0)
+ break;
+ uint16 txtNum = !isInvDesc ? READ_LE_UINT16(ptr) : entryId++;
+ ptr += 2;
+ ptr += 6;
d->_speechId = READ_LE_UINT16(ptr) - VOICE_OFFSET;
ptr += 2;
do {
- if (i == entry)
+ if (txtNum == entry)
d->_text += *ptr++;
else
ptr++;
@@ -123,7 +152,7 @@ TextEntry *Text::getText(uint chunk, uint entry) {
if (isAutoDialog)
ptr += 3;
- if (i == entry) {
+ if (txtNum == entry) {
// Found
delete[] data;
return d;
@@ -137,8 +166,8 @@ TextEntry *Text::getText(uint chunk, uint entry) {
return nullptr;
}
-Common::StringArray Text::getTextArray(uint chunk, uint entry) {
- TextEntry *textData = getText(chunk, entry);
+Common::StringArray Text::getTextArray(uint chunk, uint entry, int type) {
+ TextEntry *textData = getText(chunk, entry, type);
Common::StringArray res;
Common::String txt = textData ? textData->_text : "";
char *text = new char[txt.size() + 1];
@@ -156,9 +185,9 @@ Common::StringArray Text::getTextArray(uint chunk, uint entry) {
return res;
}
-Common::String Text::getTextEntry(uint chunk, uint entry) {
- Common::StringArray res = getTextArray(chunk, entry);
- return res[0];
+Common::String Text::getTextEntry(uint chunk, uint entry, int type) {
+ Common::StringArray res = getTextArray(chunk, entry, type);
+ return res.size() > 0 ? res[0] : "";
}
void Text::crypt(char *txt, uint32 size) {
diff --git a/engines/chewy/text.h b/engines/chewy/text.h
index 78e6d3cb9ad..41d4913a352 100644
--- a/engines/chewy/text.h
+++ b/engines/chewy/text.h
@@ -82,9 +82,9 @@ public:
* - inventory text (INV) - 700 - 799
* - use text (USE) - 800 - 899
*/
- TextEntry *getText(uint chunk, uint entry);
- Common::StringArray getTextArray(uint chunk, uint entry);
- Common::String getTextEntry(uint chunk, uint entry);
+ TextEntry *getText(uint chunk, uint entry, int type);
+ Common::StringArray getTextArray(uint chunk, uint entry, int type);
+ Common::String getTextEntry(uint chunk, uint entry, int type);
void crypt(char *txt, uint32 size);
const char *strPos(const char *txtAdr, int16 pos);
More information about the Scummvm-git-logs
mailing list