HYPNO: allow to replay conversations and refactor code some code in spider

This commit is contained in:
neuromancer 2022-04-15 12:07:07 +02:00
parent 3e6b514cf3
commit fa9feb0df3
5 changed files with 51 additions and 11 deletions

View File

@ -231,7 +231,9 @@ void HypnoEngine::runChangeLevel(ChangeLevel *a) {
}
void HypnoEngine::runTalk(Talk *a) {
_conversation.push_back(a);
// Recreate the items to allow modifications
Talk *n = new Talk(a);
_conversation.push_back(n);
_refreshConversation = true;
}

View File

@ -300,6 +300,11 @@ public:
escape = false;
active = true;
}
Talk(Talk *t) {
*this = *t;
}
TalkCommands commands;
bool active;
bool escape;

View File

@ -323,6 +323,7 @@ public:
Actions _conversation;
bool _refreshConversation;
virtual void showConversation();
virtual void endConversation();
virtual void rightClickedConversation(const Common::Point &mousePos);
virtual void leftClickedConversation(const Common::Point &mousePos);
virtual bool hoverConversation(const Common::Point &mousePos);
@ -442,6 +443,7 @@ public:
void drawString(const Filename &name, const Common::String &str, int x, int y, int w, uint32 c) override;
void showConversation() override;
void endConversation() override;
void rightClickedConversation(const Common::Point &mousePos) override;
void leftClickedConversation(const Common::Point &mousePos) override;
bool hoverConversation(const Common::Point &mousePos) override;

View File

@ -119,9 +119,10 @@ void HypnoEngine::clickedHotspot(Common::Point mousePos) {
}
}
if (selected.type == MakeMenu) {
if (isDemo())
if (isDemo()) {
_nextLevel = "sixdemo/mis/demo.mis";
else // TODO: remove when proper escape to main menu is implemented
resetSceneState();
} else // TODO: remove when proper escape to main menu is implemented
openMainMenuDialog();
return;
}
@ -254,7 +255,6 @@ void HypnoEngine::runTransition(Transition *trans) {
void HypnoEngine::runScene(Scene *scene) {
_refreshConversation = false;
_timerStarted = false;
_conversation.clear();
Common::Event event;
Common::Point mousePos;
Common::List<uint32> videosToRemove;
@ -530,11 +530,13 @@ void HypnoEngine::runScene(Scene *scene) {
_nextParallelVideoToPlay.clear();
_nextSequentialVideoToPlay.clear();
_escapeSequentialVideoToPlay.clear();
_conversation.clear();
removeTimers();
}
void HypnoEngine::showConversation() { error("Function \"%s\" not implemented", __FUNCTION__); }
void HypnoEngine::endConversation() { error("Function \"%s\" not implemented", __FUNCTION__); }
void HypnoEngine::rightClickedConversation(const Common::Point &mousePos) { error("Function \"%s\" not implemented", __FUNCTION__); }
void HypnoEngine::leftClickedConversation(const Common::Point &mousePos) { error("Function \"%s\" not implemented", __FUNCTION__); }
bool HypnoEngine::hoverConversation(const Common::Point &mousePos) { error("Function \"%s\" not implemented", __FUNCTION__); }

View File

@ -24,6 +24,15 @@
namespace Hypno {
void SpiderEngine::endConversation() {
debugC(1, kHypnoDebugScene, "Ending and clearing conversation");
for (Actions::iterator itt = _conversation.begin(); itt != _conversation.end(); ++itt) {
Talk *a = (Talk *)*itt;
delete a;
}
_conversation.clear();
}
void SpiderEngine::showConversation() {
debugC(1, kHypnoDebugScene, "Showing conversation");
defaultCursor();
@ -31,11 +40,21 @@ void SpiderEngine::showConversation() {
uint32 y = 0;
Graphics::Surface *speaker = decodeFrame("dialog/speaker3.smk", 0);
bool activeFound = false;
bool skipRepeated = false;
// First iteration on the talk commands
Videos videos;
for (Actions::iterator itt = _conversation.begin(); itt != _conversation.end(); ++itt) {
Talk *a = (Talk *)*itt;
for (TalkCommands::const_iterator it = a->commands.begin(); it != a->commands.end(); ++it) {
if (it->command == "P") {
if (_intros[it->path]) {
skipRepeated = true;
}
}
}
if (a->boxPos != Common::Point(0, 0)) {
if (!(x == 0 && x == y))
error("Multiple BOX positions found");
@ -47,6 +66,7 @@ void SpiderEngine::showConversation() {
videos.push_back(MVideo(a->intro, a->introPos, false, false, false));
_intros[a->intro] = true;
}
}
if (videos.size() > 0) {
@ -60,7 +80,7 @@ void SpiderEngine::showConversation() {
// Second iteration on the talk commands
for (Actions::const_iterator itt = _conversation.begin(); itt != _conversation.end(); ++itt) {
Talk *a = (Talk *)*itt;
if (a->active) {
if (a->active && !skipRepeated) {
uint32 frame;
Common::String path;
for (TalkCommands::const_iterator it = a->commands.begin(); it != a->commands.end(); ++it) {
@ -78,7 +98,7 @@ void SpiderEngine::showConversation() {
drawImage(*surf, x + speaker->w, y, false);
a->rect = Common::Rect(x + speaker->w, y, x + surf->w, y + surf->h);
y = y + surf->h;
surf->free();
delete surf;
}
@ -88,8 +108,18 @@ void SpiderEngine::showConversation() {
debugC(1, kHypnoDebugScene, "No active item was found in the current conversation");
// Final iteration on the talk commands
bool shouldEscape = false;
for (Actions::const_iterator it = _conversation.begin(); it != _conversation.end(); ++it) {
Talk *a = (Talk *)*it;
for (Actions::const_iterator itt = _conversation.begin(); itt != _conversation.end(); ++itt) {
Talk *a = (Talk *)*itt;
// Avoid this conversation next time
for (TalkCommands::const_iterator it = a->commands.begin(); it != a->commands.end(); ++it) {
if (it->command == "P") {
if (!it->path.empty()) {
_intros[it->path] = true;
}
}
}
if (!a->second.empty()) {
debugC(1, kHypnoDebugScene, "Adding %s to play after the conversation ends", a->second.c_str());
videos.push_back(MVideo(a->second, a->secondPos, false, false, false));
@ -104,8 +134,7 @@ void SpiderEngine::showConversation() {
videos.clear();
}
debugC(1, kHypnoDebugScene, "Clearing conversation");
_conversation.clear();
endConversation();
_music.clear();
if (shouldEscape) {
@ -123,7 +152,7 @@ void SpiderEngine::showConversation() {
}
drawScreen();
}
}
speaker->free();
delete speaker;
}