aboutsummaryrefslogtreecommitdiff
path: root/engines/mutationofjb/tasks
diff options
context:
space:
mode:
authorĽubomír Remák2018-07-08 17:06:41 +0200
committerEugene Sandulenko2018-08-25 23:12:01 +0200
commit20d6d71ec97c1f7bc4b95ed6c98375b47dff6646 (patch)
tree527a0c509903ac64e9ea878aedd6421932bdd11c /engines/mutationofjb/tasks
parentf102667fc20d91149b685aac1bb5b05cabbc6e2b (diff)
downloadscummvm-rg350-20d6d71ec97c1f7bc4b95ed6c98375b47dff6646.tar.gz
scummvm-rg350-20d6d71ec97c1f7bc4b95ed6c98375b47dff6646.tar.bz2
scummvm-rg350-20d6d71ec97c1f7bc4b95ed6c98375b47dff6646.zip
MUTATIONOFJB: Basic conversation support.
Diffstat (limited to 'engines/mutationofjb/tasks')
-rw-r--r--engines/mutationofjb/tasks/conversationtask.cpp83
-rw-r--r--engines/mutationofjb/tasks/conversationtask.h45
-rw-r--r--engines/mutationofjb/tasks/task.h56
-rw-r--r--engines/mutationofjb/tasks/taskmanager.cpp47
-rw-r--r--engines/mutationofjb/tasks/taskmanager.h51
5 files changed, 282 insertions, 0 deletions
diff --git a/engines/mutationofjb/tasks/conversationtask.cpp b/engines/mutationofjb/tasks/conversationtask.cpp
new file mode 100644
index 0000000000..75d850465b
--- /dev/null
+++ b/engines/mutationofjb/tasks/conversationtask.cpp
@@ -0,0 +1,83 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "mutationofjb/tasks/conversationtask.h"
+#include "mutationofjb/tasks/taskmanager.h"
+#include "mutationofjb/assets.h"
+#include "mutationofjb/game.h"
+#include "mutationofjb/gamedata.h"
+#include "mutationofjb/gui.h"
+#include "mutationofjb/util.h"
+#include "mutationofjb/widgets/conversationwidget.h"
+
+namespace MutationOfJB {
+
+void ConversationTask::start() {
+ Game &game = getTaskManager()->getGame();
+ ConversationWidget &widget = game.getGui().getConversationWidget();
+
+ widget.setCallback(this);
+ widget.setVisible(true);
+
+ updateWidget();
+}
+
+void ConversationTask::update() {
+}
+
+void ConversationTask::onResponseClicked(ConversationWidget *, int response) {
+
+ uint8 nextLineIndex = _convInfo._lines[_currentLine]._items[response]._nextLineIndex;
+ if (nextLineIndex == 0) {
+ setState(FINISHED);
+ Game &game = getTaskManager()->getGame();
+ ConversationWidget &widget = game.getGui().getConversationWidget();
+ widget.setVisible(false);
+ game.getGui().markDirty(); // TODO: Handle automatically when changing visibility.
+ return;
+ }
+
+ _currentLine = nextLineIndex - 1;
+ updateWidget();
+}
+
+void ConversationTask::updateWidget() {
+ Game &game = getTaskManager()->getGame();
+ ConversationWidget &widget = game.getGui().getConversationWidget();
+
+ const ConversationLineList& toSayList = game.getAssets().getToSayList();
+
+ const ConversationInfo::Line &convLine = _convInfo._lines[_currentLine];
+
+ for (ConversationInfo::Items::size_type i = 0; i < convLine._items.size(); ++i) {
+ Common::String widgetText;
+ const uint8 question = convLine._items[i]._question;
+ if (question != 0) {
+ const ConversationLineList::Line *line = toSayList.getLine(convLine._items[i]._question);
+ widgetText = toUpperCP895(line->_speeches[0]._text);
+ }
+
+ widget.setLine(i, widgetText);
+ }
+}
+
+}
diff --git a/engines/mutationofjb/tasks/conversationtask.h b/engines/mutationofjb/tasks/conversationtask.h
new file mode 100644
index 0000000000..5cc0e5f49f
--- /dev/null
+++ b/engines/mutationofjb/tasks/conversationtask.h
@@ -0,0 +1,45 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "mutationofjb/tasks/task.h"
+#include "mutationofjb/gamedata.h"
+#include "mutationofjb/widgets/conversationwidget.h"
+
+namespace MutationOfJB {
+
+class ConversationTask : public Task, public ConversationWidgetCallback {
+public:
+ ConversationTask(const ConversationInfo& convInfo) : _convInfo(convInfo), _currentLine(0) {}
+ virtual ~ConversationTask() {}
+
+ virtual void start() override;
+ virtual void update() override;
+
+ virtual void onResponseClicked(ConversationWidget *, int response) override;
+private:
+ void updateWidget();
+
+ const ConversationInfo &_convInfo;
+ uint _currentLine;
+};
+
+}
diff --git a/engines/mutationofjb/tasks/task.h b/engines/mutationofjb/tasks/task.h
new file mode 100644
index 0000000000..7b43868269
--- /dev/null
+++ b/engines/mutationofjb/tasks/task.h
@@ -0,0 +1,56 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/scummsys.h"
+
+namespace MutationOfJB {
+
+class TaskManager;
+
+class Task {
+public:
+ enum State {
+ IDLE,
+ RUNNING,
+ FINISHED
+ };
+
+ Task() : _taskManager(nullptr) {}
+ virtual ~Task() {}
+
+ virtual void start() = 0;
+ virtual void update() = 0;
+
+ void setTaskManager(TaskManager *taskMan) { _taskManager = taskMan; }
+ TaskManager *getTaskManager() { return _taskManager; }
+
+ State getState() const { return _state; }
+
+protected:
+ void setState(State state) { _state = state; }
+
+private:
+ TaskManager *_taskManager;
+ State _state;
+};
+
+}
diff --git a/engines/mutationofjb/tasks/taskmanager.cpp b/engines/mutationofjb/tasks/taskmanager.cpp
new file mode 100644
index 0000000000..981654981f
--- /dev/null
+++ b/engines/mutationofjb/tasks/taskmanager.cpp
@@ -0,0 +1,47 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "mutationofjb/tasks/taskmanager.h"
+#include "mutationofjb/tasks/task.h"
+
+namespace MutationOfJB {
+
+void TaskManager::addTask(Task *task) {
+ _tasks.push_back(task);
+ task->setTaskManager(this);
+ task->start();
+}
+
+void TaskManager::removeTask(Task *task) {
+ Tasks::iterator it = Common::find(_tasks.begin(), _tasks.end(), task);
+ if (it != _tasks.end()) {
+ _tasks.erase(it);
+ }
+}
+
+void TaskManager::update() {
+ for (Tasks::const_iterator it = _tasks.begin(); it != _tasks.end(); ++it) {
+ (*it)->update();
+ }
+}
+
+}
diff --git a/engines/mutationofjb/tasks/taskmanager.h b/engines/mutationofjb/tasks/taskmanager.h
new file mode 100644
index 0000000000..1f6be36ced
--- /dev/null
+++ b/engines/mutationofjb/tasks/taskmanager.h
@@ -0,0 +1,51 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef MUTATIONOFJB_TASKMANAGER_H
+#define MUTATIONOFJB_TASKMANAGER_H
+
+#include "common/array.h"
+
+namespace MutationOfJB {
+
+class Game;
+class Task;
+
+class TaskManager {
+public:
+ TaskManager(Game &game) : _game(game) {}
+
+ void addTask(Task *task);
+ void removeTask(Task *task);
+ void update();
+
+ Game &getGame() { return _game; }
+
+private:
+ typedef Common::Array<Task *> Tasks;
+ Tasks _tasks;
+ Game &_game;
+};
+
+}
+
+#endif