Skip to content

Commit

Permalink
ILLUSIONS: BBDOU: Add menu system class, adjust existing code (actual…
Browse files Browse the repository at this point in the history
… menus not done yet)
  • Loading branch information
johndoe123 committed May 18, 2018
1 parent 1e822f0 commit 03b0ca1
Show file tree
Hide file tree
Showing 14 changed files with 453 additions and 27 deletions.
2 changes: 1 addition & 1 deletion engines/illusions/actor.cpp
Expand Up @@ -935,7 +935,7 @@ void Control::getActorFrameDimensions(WidthHeight &dimensions) {
}

void Control::drawActorRect(const Common::Rect r, byte color) {
_actor->_surface->fillRect(r, color);
_vm->_screen->fillSurfaceRect(_actor->_surface, r, color);
_actor->_flags |= 0x4000;
}

Expand Down
60 changes: 60 additions & 0 deletions engines/illusions/bbdou/bbdou_menukeys.cpp
@@ -0,0 +1,60 @@
/* 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 "illusions/bbdou/illusions_bbdou.h"
#include "illusions/bbdou/bbdou_menukeys.h"
#include "illusions/bbdou/menusystem_bbdou.h"
#include "illusions/input.h"
#include "illusions/screen.h"

namespace Illusions {

// BBDOUMenuKeys

BBDOUMenuKeys::BBDOUMenuKeys(IllusionsEngine_BBDOU *vm)
: _vm(vm) {
}

BBDOUMenuKeys::~BBDOUMenuKeys() {

}

void BBDOUMenuKeys::addMenuKey(uint bitMask, uint32 threadId) {
MenuKey menuKey;
menuKey.bitMask = bitMask;
menuKey.threadId = threadId;
_menuKeys.push_back(menuKey);
}

void BBDOUMenuKeys::update() {
if (_vm->_screen->isDisplayOn() && !_vm->_menuSystem->isActive()) {
for (MenuKeys::iterator it = _menuKeys.begin(); it != _menuKeys.end(); ++it) {
const MenuKey &menuKey = *it;
if (_vm->_input->pollButton(menuKey.bitMask)) {
_vm->startScriptThread(menuKey.threadId, 0, 0, 0, 0);
break;
}
}
}
}

} // End of namespace Illusions
53 changes: 53 additions & 0 deletions engines/illusions/bbdou/bbdou_menukeys.h
@@ -0,0 +1,53 @@
/* 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 ILLUSIONS_BBDOU_BBDOU_MENUKEYS_H
#define ILLUSIONS_BBDOU_BBDOU_MENUKEYS_H

#include "illusions/specialcode.h"
#include "illusions/thread.h"
#include "common/array.h"

namespace Illusions {

class IllusionsEngine_BBDOU;

struct MenuKey {
uint bitMask;
uint32 threadId;
};

class BBDOUMenuKeys {
public:
BBDOUMenuKeys(IllusionsEngine_BBDOU *vm);
~BBDOUMenuKeys();
void addMenuKey(uint bitMask, uint32 threadId);
void update();
protected:
typedef Common::Array<MenuKey> MenuKeys;
IllusionsEngine_BBDOU *_vm;
MenuKeys _menuKeys;
};

} // End of namespace Illusions

#endif // ILLUSIONS_BBDOU_BBDOU_MENUKEYS_H
16 changes: 14 additions & 2 deletions engines/illusions/bbdou/illusions_bbdou.cpp
Expand Up @@ -21,7 +21,9 @@
*/

#include "illusions/bbdou/illusions_bbdou.h"
#include "illusions/bbdou/bbdou_menukeys.h"
#include "illusions/bbdou/bbdou_videoplayer.h"
#include "illusions/bbdou/menusystem_bbdou.h"
#include "illusions/actor.h"
#include "illusions/camera.h"
#include "illusions/cursor.h"
Expand Down Expand Up @@ -166,7 +168,9 @@ Common::Error IllusionsEngine_BBDOU::run() {
_threads = new ThreadList(this);
_updateFunctions = new UpdateFunctions();
_soundMan = new SoundMan(this);
_menuSystem = new BBDOUMenuSystem(this);
_videoPlayer = new BBDOUVideoPlayer(this);
_menuKeys = new BBDOUMenuKeys(this);

_screen->setColorKey1(0xF81F);

Expand Down Expand Up @@ -215,7 +219,9 @@ Common::Error IllusionsEngine_BBDOU::run() {
delete _stack;
delete _scriptOpcodes;

delete _menuKeys;
delete _videoPlayer;
delete _menuSystem;
delete _soundMan;
delete _updateFunctions;
delete _threads;
Expand Down Expand Up @@ -278,6 +284,7 @@ void IllusionsEngine_BBDOU::initInput() {
void IllusionsEngine_BBDOU::initUpdateFunctions() {
UPDATEFUNCTION(30, 0, updateScript);
UPDATEFUNCTION(50, 0, updateActors);
UPDATEFUNCTION(60, 0, updateMenuKeys);
UPDATEFUNCTION(60, 0, updateSequences);
UPDATEFUNCTION(70, 0, updateGraphics);
UPDATEFUNCTION(70, 0, updateVideoPlayer);
Expand All @@ -289,7 +296,12 @@ void IllusionsEngine_BBDOU::initUpdateFunctions() {

int IllusionsEngine_BBDOU::updateScript(uint flags) {
_threads->updateThreads();
return 1;
return kUFNext;
}

int IllusionsEngine_BBDOU::updateMenuKeys(uint flags) {
_menuKeys->update();
return kUFNext;
}

bool IllusionsEngine_BBDOU::causeIsDeclared(uint32 sceneId, uint32 verbId, uint32 objectId2, uint32 objectId) {
Expand Down Expand Up @@ -434,7 +446,7 @@ void IllusionsEngine_BBDOU::cursorControlRoutine(Control *control, uint32 deltaT
// Unused nullsub_1(control);
break;
case 3:
// TODO _vm->_shellMgr->handleMouse(control);
_menuSystem->update(control);
break;
}
}
Expand Down
5 changes: 5 additions & 0 deletions engines/illusions/bbdou/illusions_bbdou.h
Expand Up @@ -34,6 +34,8 @@ class Dictionary;
class ScriptMan;
class ScriptStack;
class BBDOUVideoPlayer;
class BBDOUMenuKeys;
class BBDOUMenuSystem;

struct ActiveScene {
uint32 _sceneId;
Expand Down Expand Up @@ -73,14 +75,17 @@ class IllusionsEngine_BBDOU : public IllusionsEngine {
uint32 _theThreadId;
uint32 _globalSceneId;

BBDOUMenuSystem *_menuSystem;
BBDOUVideoPlayer *_videoPlayer;
BBDOUMenuKeys *_menuKeys;

bool _walkthroughStarted;

void initInput();

void initUpdateFunctions();
int updateScript(uint flags);
int updateMenuKeys(uint flags);

bool causeIsDeclared(uint32 sceneId, uint32 verbId, uint32 objectId2, uint32 objectId);
void causeDeclare(uint32 verbId, uint32 objectId2, uint32 objectId, TriggerFunctionCallback *callback);
Expand Down
168 changes: 168 additions & 0 deletions engines/illusions/bbdou/menusystem_bbdou.cpp
@@ -0,0 +1,168 @@
/* 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 "illusions/illusions.h"
#include "illusions/actor.h"
#include "illusions/cursor.h"
#include "illusions/bbdou/illusions_bbdou.h"
#include "illusions/bbdou/menusystem_bbdou.h"

namespace Illusions {

// BBDOUMenuSystem

BBDOUMenuSystem::BBDOUMenuSystem(IllusionsEngine_BBDOU *vm)
: BaseMenuSystem(vm), _vm(vm) {
clearMenus();
}

BBDOUMenuSystem::~BBDOUMenuSystem() {
freeMenus();
}

void BBDOUMenuSystem::runMenu(MenuChoiceOffsets menuChoiceOffsets, int16 *menuChoiceOffset,
uint32 menuId, uint32 duration, uint timeOutMenuChoiceIndex, uint32 menuCallerThreadId) {

debug(0, "BBDOUMenuSystem::runMenu(%08X)", menuId);

setTimeOutDuration(duration, timeOutMenuChoiceIndex);
setMenuCallerThreadId(menuCallerThreadId);
setMenuChoiceOffsets(menuChoiceOffsets, menuChoiceOffset);

int rootMenuId = convertRootMenuId(menuId);
BaseMenu *rootMenu = getMenuById(rootMenuId);
openMenu(rootMenu);

}

void BBDOUMenuSystem::clearMenus() {
for (int i = 0; i < kBBDOULastMenuIndex; ++i)
_menus[i] = 0;
}

void BBDOUMenuSystem::freeMenus() {
for (int i = 0; i < kBBDOULastMenuIndex; ++i)
delete _menus[i];
}

BaseMenu *BBDOUMenuSystem::getMenuById(int menuId) {
if (!_menus[menuId])
_menus[menuId] = createMenuById(menuId);
return _menus[menuId];
}

BaseMenu *BBDOUMenuSystem::createMenuById(int menuId) {
switch (menuId) {
case kBBDOUMainMenu:
return createMainMenu();
case kBBDOUPauseMenu:
return createPauseMenu();
// TODO Other menus
default:
error("BBDOUMenuSystem::createMenuById() Invalid menu id %d", menuId);
}
}

BaseMenu *BBDOUMenuSystem::createMainMenu() {
return 0; // TODO
}

BaseMenu *BBDOUMenuSystem::createLoadGameMenu() {
return 0; // TODO
}

BaseMenu *BBDOUMenuSystem::createOptionsMenu() {
return 0; // TODO
}

BaseMenu *BBDOUMenuSystem::createPauseMenu() {
BaseMenu *menu = new BaseMenu(this, 0x00120003, 218, 150, 80, 20, 1);
menu->addText(" Game Paused");
menu->addText("-------------------");
menu->addMenuItem(new MenuItem("Resume", new MenuActionReturnChoice(this, 1)));
// menu->addMenuItem(new MenuItem("Load Game", new MenuActionLoadGame(this, 1)));
// TODO menu->addMenuItem(new MenuItem("Save Game", new MenuActionSaveGame(this, 11)));
// TODO menu->addMenuItem(new MenuItem("Restart Game", new MenuActionEnterQueryMenu(this, kDuckmanQueryRestartMenu, 2)));
// TODO menu->addMenuItem(new MenuItem("Options", new MenuActionEnterMenu(this, kDuckmanOptionsMenu)));
// menu->addMenuItem(new MenuItem("Quit Game", new MenuActionEnterQueryMenu(this, kDuckmanQueryQuitMenu, 23)));
return menu;
}

int BBDOUMenuSystem::convertRootMenuId(uint32 menuId) {
switch (menuId) {
case 0x1C0001:
return kBBDOUMainMenu;
case 0x1C0002:
return kBBDOUPauseMenu;
case 0x1C0006:
return kBBDOULoadGameMenu;
case 0x1C0007:
return kBBDOUSaveGameMenu;
case 0x1C0008:
return kBBDOUGameSavedMenu;
case 0x1C0009:
return kBBDOUSaveFailedMenu;
case 0x1C000A:
return kBBDOULoadFailedMenu;
/* Unused/unimplemented debug menus
case 0x1C0003: debugStartMenu
case 0x1C0004: debugPauseMenu
case 0x1C0005: unitTestsMenu
*/
default:
error("BBDOUMenuSystem() Menu ID %08X not found", menuId);
}
}

bool BBDOUMenuSystem::initMenuCursor() {
bool cursorInitialVisibleFlag = false;
Control *cursorControl = _vm->getObjectControl(0x40004);
if (cursorControl) {
if (cursorControl->_flags & 1) {
cursorInitialVisibleFlag = false;
} else {
cursorInitialVisibleFlag = true;
cursorControl->appearActor();
}
} else {
Common::Point pos = _vm->getNamedPointPosition(0x70023);
_vm->_controls->placeActor(0x50001, pos, 0x60001, 0x40004, 0);
cursorControl = _vm->getObjectControl(0x40004);
}
return cursorInitialVisibleFlag;
}

int BBDOUMenuSystem::getGameState() {
return _vm->_cursor->_status;
}

void BBDOUMenuSystem::setMenuCursorNum(int cursorNum) {
Control *mouseCursor = _vm->getObjectControl(0x40004);
_vm->_cursor->setActorIndex(5, cursorNum, 0);
mouseCursor->startSequenceActor(0x60001, 2, 0);
}

void BBDOUMenuSystem::setGameState(int gameState) {
_vm->_cursor->_status = gameState;
}

} // End of namespace Illusions

0 comments on commit 03b0ca1

Please sign in to comment.