[Scummvm-cvs-logs] SF.net SVN: scummvm: [31866] scummvm/trunk/engines/kyra
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Sun May 4 17:18:47 CEST 2008
Revision: 31866
http://scummvm.svn.sourceforge.net/scummvm/?rev=31866&view=rev
Author: lordhoto
Date: 2008-05-04 08:18:46 -0700 (Sun, 04 May 2008)
Log Message:
-----------
Renamed kyra2 and kyra3 gui files.
Modified Paths:
--------------
scummvm/trunk/engines/kyra/kyra_hof.cpp
scummvm/trunk/engines/kyra/kyra_hof.h
scummvm/trunk/engines/kyra/kyra_mr.cpp
scummvm/trunk/engines/kyra/kyra_mr.h
scummvm/trunk/engines/kyra/module.mk
scummvm/trunk/engines/kyra/staticres.cpp
Added Paths:
-----------
scummvm/trunk/engines/kyra/gui_hof.cpp
scummvm/trunk/engines/kyra/gui_hof.h
scummvm/trunk/engines/kyra/gui_mr.cpp
scummvm/trunk/engines/kyra/gui_mr.h
Removed Paths:
-------------
scummvm/trunk/engines/kyra/gui_v2.cpp
scummvm/trunk/engines/kyra/gui_v2.h
scummvm/trunk/engines/kyra/gui_v3.cpp
scummvm/trunk/engines/kyra/gui_v3.h
Copied: scummvm/trunk/engines/kyra/gui_hof.cpp (from rev 31865, scummvm/trunk/engines/kyra/gui_v2.cpp)
===================================================================
--- scummvm/trunk/engines/kyra/gui_hof.cpp (rev 0)
+++ scummvm/trunk/engines/kyra/gui_hof.cpp 2008-05-04 15:18:46 UTC (rev 31866)
@@ -0,0 +1,2009 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "kyra/kyra.h"
+#include "kyra/kyra_hof.h"
+#include "kyra/screen.h"
+#include "kyra/wsamovie.h"
+#include "kyra/timer.h"
+#include "kyra/sound.h"
+#include "kyra/resource.h"
+
+#include "common/savefile.h"
+
+namespace Kyra {
+
+void KyraEngine_HoF::loadButtonShapes() {
+ const uint8 *src = _screen->getCPagePtr(3);
+ _screen->loadBitmap("_BUTTONS.CSH", 3, 3, 0);
+
+ _gui->_scrollUpButton.data0ShapePtr = _buttonShapes[0] = _screen->makeShapeCopy(src, 0);
+ _gui->_scrollUpButton.data2ShapePtr = _buttonShapes[1] = _screen->makeShapeCopy(src, 1);
+ _gui->_scrollUpButton.data1ShapePtr = _buttonShapes[2] = _screen->makeShapeCopy(src, 2);
+ _gui->_scrollDownButton.data0ShapePtr = _buttonShapes[3] = _screen->makeShapeCopy(src, 3);
+ _gui->_scrollDownButton.data2ShapePtr = _buttonShapes[4] = _screen->makeShapeCopy(src, 4);
+ _gui->_scrollDownButton.data1ShapePtr = _buttonShapes[5] = _screen->makeShapeCopy(src, 5);
+ _buttonShapes[6] = _screen->makeShapeCopy(src, 6);
+ _buttonShapes[7] = _screen->makeShapeCopy(src, 7);
+ _buttonShapes[8] = _screen->makeShapeCopy(src, 6);
+ _buttonShapes[9] = _screen->makeShapeCopy(src, 7);
+ _buttonShapes[10] = _screen->makeShapeCopy(src, 10);
+ _buttonShapes[11] = _screen->makeShapeCopy(src, 11);
+ _buttonShapes[16] = _screen->makeShapeCopy(src, 16);
+ _buttonShapes[17] = _screen->makeShapeCopy(src, 17);
+ _buttonShapes[18] = _screen->makeShapeCopy(src, 18);
+}
+
+void KyraEngine_HoF::setupLangButtonShapes() {
+ switch (_lang) {
+ case 0:
+ _inventoryButtons[0].data0ShapePtr = _buttonShapes[6];
+ _inventoryButtons[0].data1ShapePtr = _inventoryButtons[0].data2ShapePtr = _buttonShapes[7];
+ break;
+
+ case 1:
+ _inventoryButtons[0].data0ShapePtr = _buttonShapes[8];
+ _inventoryButtons[0].data1ShapePtr = _inventoryButtons[0].data2ShapePtr = _buttonShapes[9];
+ break;
+
+ case 2:
+ _inventoryButtons[0].data0ShapePtr = _buttonShapes[10];
+ _inventoryButtons[0].data1ShapePtr = _inventoryButtons[0].data2ShapePtr = _buttonShapes[11];
+ break;
+
+ default:
+ _inventoryButtons[0].data0ShapePtr = _buttonShapes[6];
+ _inventoryButtons[0].data1ShapePtr = _inventoryButtons[0].data2ShapePtr = _buttonShapes[7];
+ break;
+ }
+}
+
+GUI_HoF::GUI_HoF(KyraEngine_HoF *vm) : GUI(vm), _vm(vm), _screen(vm->screen_v2()) {
+ _backUpButtonList = _unknownButtonList = 0;
+ initStaticData();
+ _currentMenu = 0;
+ _isDeathMenu = false;
+ _isSaveMenu = false;
+ _isLoadMenu = false;
+ _scrollUpFunctor = BUTTON_FUNCTOR(GUI_HoF, this, &GUI_HoF::scrollUpButton);
+ _scrollDownFunctor = BUTTON_FUNCTOR(GUI_HoF, this, &GUI_HoF::scrollDownButton);
+ _sliderHandlerFunctor = BUTTON_FUNCTOR(GUI_HoF, this, &GUI_HoF::sliderHandler);
+}
+
+Button *GUI_HoF::addButtonToList(Button *list, Button *newButton) {
+ list = GUI::addButtonToList(list, newButton);
+ _buttonListChanged = true;
+ return list;
+}
+
+void GUI_HoF::processButton(Button *button) {
+ if (!button)
+ return;
+
+ if (button->flags & 8) {
+ if (button->flags & 0x10) {
+ // XXX
+ }
+ return;
+ }
+
+ int entry = button->flags2 & 5;
+
+ byte val1 = 0, val2 = 0, val3 = 0;
+ const uint8 *dataPtr = 0;
+ Button::Callback callback;
+ if (entry == 1) {
+ val1 = button->data1Val1;
+ dataPtr = button->data1ShapePtr;
+ callback = button->data1Callback;
+ val2 = button->data1Val2;
+ val3 = button->data1Val3;
+ } else if (entry == 4 || entry == 5) {
+ val1 = button->data2Val1;
+ dataPtr = button->data2ShapePtr;
+ callback = button->data2Callback;
+ val2 = button->data2Val2;
+ val3 = button->data2Val3;
+ } else {
+ val1 = button->data0Val1;
+ dataPtr = button->data0ShapePtr;
+ callback = button->data0Callback;
+ val2 = button->data0Val2;
+ val3 = button->data0Val3;
+ }
+
+ int x = 0, y = 0, x2 = 0, y2 = 0;
+
+ x = button->x;
+ if (x < 0)
+ x += _screen->getScreenDim(button->dimTableIndex)->w << 3;
+ x += _screen->getScreenDim(button->dimTableIndex)->sx << 3;
+ x2 = x + button->width - 1;
+
+ y = button->y;
+ if (y < 0)
+ y += _screen->getScreenDim(button->dimTableIndex)->h << 3;
+ y += _screen->getScreenDim(button->dimTableIndex)->sy << 3;
+ y2 = y + button->height - 1;
+
+ switch (val1 - 1) {
+ case 0:
+ _screen->hideMouse();
+ _screen->drawShape(_screen->_curPage, dataPtr, x, y, button->dimTableIndex, 0x10);
+ _screen->showMouse();
+ break;
+
+ case 1:
+ _screen->hideMouse();
+ _screen->printText((const char*)dataPtr, x, y, val2, val3);
+ _screen->showMouse();
+ break;
+
+ case 3:
+ if (callback)
+ (*callback)(button);
+ break;
+
+ case 4:
+ _screen->hideMouse();
+ _screen->drawBox(x, y, x2, y2, val2);
+ _screen->showMouse();
+ break;
+
+ case 5:
+ _screen->hideMouse();
+ _screen->fillRect(x, y, x2, y2, val2, -1, true);
+ _screen->showMouse();
+ break;
+
+ default:
+ break;
+ }
+
+ _screen->updateScreen();
+}
+
+int GUI_HoF::processButtonList(Button *buttonList, uint16 inputFlag) {
+ static uint16 flagsModifier = 0;
+
+ if (!buttonList)
+ return inputFlag & 0x7FFF;
+
+ if (_backUpButtonList != buttonList || _buttonListChanged) {
+ _unknownButtonList = 0;
+ //flagsModifier |= 0x2200;
+ _backUpButtonList = buttonList;
+ _buttonListChanged = false;
+
+ while (buttonList) {
+ processButton(buttonList);
+ buttonList = buttonList->nextButton;
+ }
+ }
+
+ int mouseX = _vm->_mouseX;
+ int mouseY = _vm->_mouseY;
+
+ uint16 flags = 0;
+
+ if (1/*!_screen_cursorDisable*/) {
+ uint16 inFlags = inputFlag & 0xFF;
+ uint16 temp = 0;
+
+ // HACK: inFlags == 200 is our left button (up)
+ if (inFlags == 199 || inFlags == 200)
+ temp = 0x1000;
+ if (inFlags == 198)
+ temp = 0x100;
+
+ if (inputFlag & 0x800)
+ temp <<= 2;
+
+ flags |= temp;
+
+ flagsModifier &= ~((temp & 0x4400) >> 1);
+ flagsModifier |= (temp & 0x1100) * 2;
+ flags |= flagsModifier;
+ flags |= (flagsModifier << 2) ^ 0x8800;
+ }
+
+ buttonList = _backUpButtonList;
+ if (_unknownButtonList) {
+ buttonList = _unknownButtonList;
+ if (_unknownButtonList->flags & 8)
+ _unknownButtonList = 0;
+ }
+
+ int returnValue = 0;
+ while (buttonList) {
+ if (buttonList->flags & 8) {
+ buttonList = buttonList->nextButton;
+ continue;
+ }
+ buttonList->flags2 &= ~0x18;
+ buttonList->flags2 |= (buttonList->flags2 & 3) << 3;
+
+ int x = buttonList->x;
+ if (x < 0)
+ x += _screen->getScreenDim(buttonList->dimTableIndex)->w << 3;
+ x += _screen->getScreenDim(buttonList->dimTableIndex)->sx << 3;
+
+ int y = buttonList->y;
+ if (y < 0)
+ y += _screen->getScreenDim(buttonList->dimTableIndex)->h;
+ y += _screen->getScreenDim(buttonList->dimTableIndex)->sy;
+
+ bool progress = false;
+
+ if (mouseX >= x && mouseY >= y && mouseX <= x+buttonList->width && mouseY <= y+buttonList->height)
+ progress = true;
+
+ buttonList->flags2 &= ~0x80;
+ uint16 inFlags = inputFlag & 0x7FFF;
+ if (inFlags) {
+ if (buttonList->unk6 == inFlags) {
+ progress = true;
+ flags = buttonList->flags & 0x0F00;
+ buttonList->flags2 |= 0x80;
+ inputFlag = 0;
+ _unknownButtonList = buttonList;
+ } else if (buttonList->unk8 == inFlags) {
+ flags = buttonList->flags & 0xF000;
+ if (!flags)
+ flags = buttonList->flags & 0x0F00;
+ progress = true;
+ buttonList->flags2 |= 0x80;
+ inputFlag = 0;
+ _unknownButtonList = buttonList;
+ }
+ }
+
+ bool unk1 = false;
+ if (!progress)
+ buttonList->flags2 &= ~6;
+
+ if ((flags & 0x3300) && (buttonList->flags & 4) && progress && (buttonList == _unknownButtonList || !_unknownButtonList)) {
+ buttonList->flags |= 6;
+ if (!_unknownButtonList)
+ _unknownButtonList = buttonList;
+ } else if ((flags & 0x8800) && !(buttonList->flags & 4) && progress) {
+ buttonList->flags2 |= 6;
+ } else {
+ buttonList->flags2 &= ~6;
+ }
+
+ bool progressSwitch = false;
+ if (!_unknownButtonList) {
+ progressSwitch = progress;
+ } else {
+ if (_unknownButtonList->flags & 0x40)
+ progressSwitch = (_unknownButtonList == buttonList);
+ else
+ progressSwitch = progress;
+ }
+
+ if (progressSwitch) {
+ if ((flags & 0x1100) && progress && !_unknownButtonList) {
+ inputFlag = 0;
+ _unknownButtonList = buttonList;
+ }
+
+ if ((buttonList->flags & flags) && (progress || !(buttonList->flags & 1))) {
+ uint16 combinedFlags = (buttonList->flags & flags);
+ combinedFlags = ((combinedFlags & 0xF000) >> 4) | (combinedFlags & 0x0F00);
+ combinedFlags >>= 8;
+
+ static const uint16 flagTable[] = {
+ 0x000, 0x100, 0x200, 0x100, 0x400, 0x100, 0x400, 0x100, 0x800, 0x100,
+ 0x200, 0x100, 0x400, 0x100, 0x400, 0x100
+ };
+
+ assert(combinedFlags < ARRAYSIZE(flagTable));
+
+ switch (flagTable[combinedFlags]) {
+ case 0x400:
+ if (!(buttonList->flags & 1) || ((buttonList->flags & 1) && _unknownButtonList == buttonList)) {
+ buttonList->flags2 ^= 1;
+ returnValue = buttonList->index | 0x8000;
+ unk1 = true;
+ }
+
+ if (!(buttonList->flags & 4)) {
+ buttonList->flags2 &= ~4;
+ buttonList->flags2 &= ~2;
+ }
+ break;
+
+ case 0x800:
+ if (!(buttonList->flags & 4)) {
+ buttonList->flags2 |= 4;
+ buttonList->flags2 |= 2;
+ }
+
+ if (!(buttonList->flags & 1))
+ unk1 = true;
+ break;
+
+ case 0x200:
+ if (buttonList->flags & 4) {
+ buttonList->flags2 |= 4;
+ buttonList->flags2 |= 2;
+ }
+
+ if (!(buttonList->flags & 1))
+ unk1 = true;
+ break;
+
+ case 0x100:
+ default:
+ buttonList->flags2 ^= 1;
+ returnValue = buttonList->index | 0x8000;
+ unk1 = true;
+ if (buttonList->flags & 4) {
+ buttonList->flags2 |= 4;
+ buttonList->flags2 |= 2;
+ }
+ _unknownButtonList = buttonList;
+ break;
+ }
+ }
+ }
+
+ bool unk2 = false;
+ if ((flags & 0x2200) && progress) {
+ buttonList->flags2 |= 6;
+ if (!(buttonList->flags & 4) && !(buttonList->flags2 & 1)) {
+ unk2 = true;
+ buttonList->flags2 |= 1;
+ }
+ }
+
+ if ((flags & 0x8800) == 0x8800) {
+ _unknownButtonList = 0;
+ if (!progress || (buttonList->flags & 4))
+ buttonList->flags2 &= ~6;
+ }
+
+ if (!progress && buttonList == _unknownButtonList && !(buttonList->flags & 0x40))
+ _unknownButtonList = 0;
+
+ if ((buttonList->flags2 & 0x18) != ((buttonList->flags2 & 3) << 3))
+ processButton(buttonList);
+
+ if (unk2)
+ buttonList->flags2 &= ~1;
+
+ if (unk1) {
+ buttonList->flags2 &= 0xFF;
+ buttonList->flags2 |= flags;
+
+ if (buttonList->buttonCallback) {
+ _vm->removeInputTop();
+ if ((*buttonList->buttonCallback.get())(buttonList))
+ break;
+ }
+
+ if (buttonList->flags & 0x20)
+ break;
+ }
+
+ if (_unknownButtonList == buttonList && (buttonList->flags & 0x40))
+ break;
+
+ buttonList = buttonList->nextButton;
+ }
+
+ if (!returnValue)
+ returnValue = inputFlag & 0x7FFF;
+ return returnValue;
+}
+
+const char *GUI_HoF::getMenuTitle(const Menu &menu) {
+ if (!menu.menuNameId)
+ return 0;
+
+ return _vm->getTableString(menu.menuNameId, _vm->_optionsBuffer, 1);
+}
+
+const char *GUI_HoF::getMenuItemTitle(const MenuItem &menuItem) {
+ if (!menuItem.itemId)
+ return 0;
+
+ return _vm->getTableString(menuItem.itemId, _vm->_optionsBuffer, 1);
+}
+
+const char *GUI_HoF::getMenuItemLabel(const MenuItem &menuItem) {
+ if (!menuItem.labelId)
+ return 0;
+
+ return _vm->getTableString(menuItem.labelId, _vm->_optionsBuffer, 1);
+}
+
+#pragma mark -
+
+
+int KyraEngine_HoF::buttonInventory(Button *button) {
+ if (!_screen->isMouseVisible())
+ return 0;
+
+ int inventorySlot = button->index - 6;
+
+ uint16 item = _mainCharacter.inventory[inventorySlot];
+ if (_itemInHand == -1) {
+ if (item == 0xFFFF)
+ return 0;
+ _screen->hideMouse();
+ clearInventorySlot(inventorySlot, 0);
+ snd_playSoundEffect(0x0B);
+ setMouseCursor(item);
+ int string = (_lang == 1) ? getItemCommandStringPickUp(item) : 7;
+ updateCommandLineEx(item+54, string, 0xD6);
+ _itemInHand = (int16)item;
+ _screen->showMouse();
+ _mainCharacter.inventory[inventorySlot] = 0xFFFF;
+ } else {
+ if (_mainCharacter.inventory[inventorySlot] != 0xFFFF) {
+ if (checkInventoryItemExchange(_itemInHand, inventorySlot))
+ return 0;
+
+ item = _mainCharacter.inventory[inventorySlot];
+ snd_playSoundEffect(0x0B);
+ _screen->hideMouse();
+ clearInventorySlot(inventorySlot, 0);
+ drawInventoryShape(0, _itemInHand, inventorySlot);
+ setMouseCursor(item);
+ int string = (_lang == 1) ? getItemCommandStringPickUp(item) : 7;
+ updateCommandLineEx(item+54, string, 0xD6);
+ _screen->showMouse();
+ _mainCharacter.inventory[inventorySlot] = _itemInHand;
+ setHandItem(item);
+ } else {
+ snd_playSoundEffect(0x0C);
+ _screen->hideMouse();
+ drawInventoryShape(0, _itemInHand, inventorySlot);
+ _screen->setMouseCursor(0, 0, getShapePtr(0));
+ int string = (_lang == 1) ? getItemCommandStringInv(_itemInHand) : 8;
+ updateCommandLineEx(_itemInHand+54, string, 0xD6);
+ _screen->showMouse();
+ _mainCharacter.inventory[inventorySlot] = _itemInHand;
+ _itemInHand = -1;
+ }
+ }
+
+ return 0;
+}
+
+int KyraEngine_HoF::scrollInventory(Button *button) {
+ uint16 *src = _mainCharacter.inventory;
+ uint16 *dst = &_mainCharacter.inventory[10];
+ uint16 temp[5];
+
+ memcpy(temp, src, sizeof(uint16)*5);
+ memcpy(src, src+5, sizeof(uint16)*5);
+ memcpy(src+5, dst, sizeof(uint16)*5);
+ memcpy(dst, dst+5, sizeof(uint16)*5);
+ memcpy(dst+5, temp, sizeof(uint16)*5);
+ _screen->hideMouse();
+ _screen->copyRegion(0x46, 0x90, 0x46, 0x90, 0x71, 0x2E, 0, 2);
+ _screen->showMouse();
+ redrawInventory(2);
+ scrollInventoryWheel();
+ return 0;
+}
+
+int KyraEngine_HoF::getInventoryItemSlot(uint16 item) {
+ for (int i = 0; i < 20; ++i) {
+ if (_mainCharacter.inventory[i] == item)
+ return i;
+ }
+ return -1;
+}
+
+int KyraEngine_HoF::findFreeVisibleInventorySlot() {
+ for (int i = 0; i < 10; ++i) {
+ if (_mainCharacter.inventory[i] == 0xFFFF)
+ return i;
+ }
+ return -1;
+}
+
+void KyraEngine_HoF::removeSlotFromInventory(int slot) {
+ _mainCharacter.inventory[slot] = 0xFFFF;
+ if (slot < 10) {
+ _screen->hideMouse();
+ clearInventorySlot(slot, 0);
+ _screen->showMouse();
+ }
+}
+
+bool KyraEngine_HoF::checkInventoryItemExchange(uint16 handItem, int slot) {
+ bool removeItem = false;
+ uint16 newItem = 0xFFFF;
+
+ uint16 invItem = _mainCharacter.inventory[slot];
+
+ for (const uint16 *table = _itemMagicTable; *table != 0xFFFF; table += 4) {
+ if (table[0] != handItem || table[1] != invItem)
+ continue;
+
+ if (table[3] == 0xFFFF)
+ continue;
+
+ removeItem = (table[3] == 1);
+ newItem = table[2];
+
+ snd_playSoundEffect(0x68);
+ _mainCharacter.inventory[slot] = newItem;
+ _screen->hideMouse();
+ clearInventorySlot(slot, 0);
+ drawInventoryShape(0, newItem, slot);
+
+ if (removeItem)
+ removeHandItem();
+
+ _screen->showMouse();
+
+ if (_lang != 1)
+ updateCommandLineEx(newItem+54, 0x2E, 0xD6);
+
+ return true;
+ }
+
+ return false;
+}
+
+void KyraEngine_HoF::drawInventoryShape(int page, uint16 item, int slot) {
+ _screen->drawShape(page, getShapePtr(item+64), _inventoryX[slot], _inventoryY[slot], 0, 0);
+ _screen->updateScreen();
+}
+
+void KyraEngine_HoF::clearInventorySlot(int slot, int page) {
+ _screen->drawShape(page, getShapePtr(240+slot), _inventoryX[slot], _inventoryY[slot], 0, 0);
+ _screen->updateScreen();
+}
+
+void KyraEngine_HoF::redrawInventory(int page) {
+ int pageBackUp = _screen->_curPage;
+ _screen->_curPage = page;
+
+ const uint16 *inventory = _mainCharacter.inventory;
+ _screen->hideMouse();
+ for (int i = 0; i < 10; ++i) {
+ clearInventorySlot(i, page);
+ if (inventory[i] != 0xFFFF) {
+ _screen->drawShape(page, getShapePtr(inventory[i]+64), _inventoryX[i], _inventoryY[i], 0, 0);
+ drawInventoryShape(page, inventory[i], i);
+ }
+ }
+ _screen->showMouse();
+ _screen->updateScreen();
+
+ _screen->_curPage = pageBackUp;
+}
+
+void KyraEngine_HoF::scrollInventoryWheel() {
+ WSAMovieV2 movie(this, _screen);
+ movie.open("INVWHEEL.WSA", 0, 0);
+ int frames = movie.opened() ? movie.frames() : 6;
+ memcpy(_screenBuffer, _screen->getCPagePtr(2), 64000);
+ uint8 overlay[0x100];
+ _screen->generateOverlay(_screen->getPalette(0), overlay, 0, 50);
+ _screen->hideMouse();
+ _screen->copyRegion(0x46, 0x90, 0x46, 0x79, 0x71, 0x17, 0, 2, Screen::CR_NO_P_CHECK);
+ _screen->showMouse();
+ snd_playSoundEffect(0x25);
+
+ movie.setDrawPage(0);
+ movie.setX(0);
+ movie.setY(0);
+
+ bool breakFlag = false;
+ for (int i = 0; i <= 6 && !breakFlag; ++i) {
+ if (movie.opened()) {
+ _screen->hideMouse();
+ movie.displayFrame(i % frames, 0, 0);
+ _screen->showMouse();
+ _screen->updateScreen();
+ }
+
+ uint32 endTime = _system->getMillis() + _tickLength;
+
+ int y = (i * 981) >> 8;
+ if (y >= 23 || i == 6) {
+ y = 23;
+ breakFlag = true;
+ }
+
+ _screen->applyOverlay(0x46, 0x79, 0x71, 0x17, 2, overlay);
+ _screen->copyRegion(0x46, y+0x79, 0x46, 0x90, 0x71, 0x2E, 2, 0, Screen::CR_NO_P_CHECK);
+ _screen->updateScreen();
+
+ delayUntil(endTime);
+ }
+
+ _screen->copyBlockToPage(2, 0, 0, 320, 200, _screenBuffer);
+ movie.close();
+}
+
+// spellbook specific code
+
+int KyraEngine_HoF::bookButton(Button *button) {
+ if (!queryGameFlag(1)) {
+ objectChat(getTableString(0xEB, _cCodeBuffer, 1), 0, 0x83, 0xEB);
+ return 0;
+ }
+
+ if (!_screen->isMouseVisible())
+ return 0;
+
+ if (queryGameFlag(0xE5)) {
+ snd_playSoundEffect(0x0D);
+ return 0;
+ }
+
+ if (_itemInHand == 72) {
+ if (!queryGameFlag(0xE2)) {
+ _bookMaxPage += 2;
+ removeHandItem();
+ snd_playSoundEffect(0x6C);
+ setGameFlag(0xE2);
+ }
+
+ if (!queryGameFlag(0x18A) && queryGameFlag(0x170)) {
+ _bookMaxPage += 2;
+ removeHandItem();
+ snd_playSoundEffect(0x6C);
+ setGameFlag(0x18A);
+ }
+
+ return 0;
+ }
+
+ if (_handItemSet != -1) {
+ snd_playSoundEffect(0x0D);
+ return 0;
+ }
+
+ _screen->hideMouse();
+ showMessage(0, 0xCF);
+ displayInvWsaLastFrame();
+ _bookNewPage = _bookCurPage;
+
+ if (_screenBuffer) {
+ _screen->hideMouse();
+ memcpy(_screenBuffer, _screen->getCPagePtr(0), 64000);
+ _screen->showMouse();
+ }
+
+ memcpy(_screen->getPalette(2), _screen->getPalette(0), 768);
+ _screen->fadeToBlack(7, &_updateFunctor);
+ _res->loadFileToBuf("_BOOK.COL", _screen->getPalette(0), 768);
+ loadBookBkgd();
+ showBookPage();
+ _screen->copyRegion(0, 0, 0, 0, 0x140, 0xC8, 2, 0, Screen::CR_NO_P_CHECK);
+ _screen->updateScreen();
+
+ int oldItemInHand = _itemInHand;
+ removeHandItem();
+ _screen->fadePalette(_screen->getPalette(0), 7);
+ _screen->showMouse();
+
+ bookLoop();
+
+ _screen->fadeToBlack(7);
+ _screen->hideMouse();
+ setHandItem(oldItemInHand);
+ updateMouse();
+ restorePage3();
+
+ if (_screenBuffer) {
+ _screen->hideMouse();
+ _screen->copyBlockToPage(0, 0, 0, 320, 200, _screenBuffer);
+ _screen->showMouse();
+ }
+
+ setHandItem(_itemInHand);
+ memcpy(_screen->getPalette(0), _screen->getPalette(2), 768);
+ _screen->fadePalette(_screen->getPalette(0), 7, &_updateFunctor);
+ _screen->showMouse();
+
+ if (!queryGameFlag(4) && !queryGameFlag(0xB8)) {
+ objectChat(getTableString(0xEC, _cCodeBuffer, 1), 0, 0x83, 0xEC);
+ objectChat(getTableString(0xED, _cCodeBuffer, 1), 0, 0x83, 0xED);
+ objectChat(getTableString(0xEE, _cCodeBuffer, 1), 0, 0x83, 0xEE);
+ objectChat(getTableString(0xEF, _cCodeBuffer, 1), 0, 0x83, 0xEF);
+ setGameFlag(4);
+ }
+
+ return 0;
+}
+
+void KyraEngine_HoF::loadBookBkgd() {
+ char filename[16];
+
+ if (_flags.isTalkie)
+ strcpy(filename, (_bookBkgd == 0) ? "_XBOOKD.CPS" : "_XBOOKC.CPS");
+ else
+ strcpy(filename, (_bookBkgd == 0) ? "_BOOKD.CPS" : "_BOOKC.CPS");
+
+ _bookBkgd ^= 1;
+
+ if (_flags.isTalkie) {
+ if (!_bookCurPage)
+ strcpy(filename, "_XBOOKB.CPS");
+ if (_bookCurPage == _bookMaxPage)
+ strcpy(filename, "_XBOOKA.CPS");
+
+ switch (_lang) {
+ case 0:
+ filename[1] = 'E';
+ break;
+
+ case 1:
+ filename[1] = 'F';
+ break;
+
+ case 2:
+ filename[1] = 'G';
+ break;
+
+ default:
+ warning("loadBookBkgd unsupported language");
+ filename[1] = 'E';
+ break;
+ }
+ } else {
+ if (!_bookCurPage)
+ strcpy(filename, "_BOOKB.CPS");
+ if (_bookCurPage == _bookMaxPage)
+ strcpy(filename, "_BOOKA.CPS");
+ }
+
+ _screen->loadBitmap(filename, 3, 3, 0);
+}
+
+void KyraEngine_HoF::showBookPage() {
+ char filename[16];
+
+ sprintf(filename, "PAGE%.01X.", _bookCurPage);
+ strcat(filename, _languageExtension[_lang]);
+ uint8 *leftPage = _res->fileData(filename, 0);
+ int leftPageY = _bookPageYOffset[_bookCurPage];
+
+ sprintf(filename, "PAGE%.01X.", _bookCurPage+1);
+ strcat(filename, _languageExtension[_lang]);
+ uint8 *rightPage = (_bookCurPage != _bookMaxPage) ? _res->fileData(filename, 0) : 0;
+ int rightPageY = _bookPageYOffset[_bookCurPage+1];
+
+ _screen->hideMouse();
+ if (leftPage) {
+ bookDecodeText(leftPage);
+ bookPrintText(2, leftPage, 20, leftPageY+20, 0x31);
+ delete [] leftPage;
+ }
+
+ if (rightPage) {
+ bookDecodeText(rightPage);
+ bookPrintText(2, rightPage, 176, rightPageY+20, 0x31);
+ delete [] rightPage;
+ }
+ _screen->showMouse();
+}
+
+void KyraEngine_HoF::bookLoop() {
+ Button bookButtons[5];
+
+ GUI_V2_BUTTON(bookButtons[0], 0x24, 0, 0, 1, 1, 1, 0x4487, 0, 0x82, 0xBE, 0x0A, 0x0A, 0xC7, 0xCF, 0xC7, 0xCF, 0xC7, 0xCF, 0);
+ bookButtons[0].buttonCallback = BUTTON_FUNCTOR(KyraEngine_HoF, this, &KyraEngine_HoF::bookPrevPage);
+ GUI_V2_BUTTON(bookButtons[1], 0x25, 0, 0, 1, 1, 1, 0x4487, 0, 0xB1, 0xBE, 0x0A, 0x0A, 0xC7, 0xCF, 0xC7, 0xCF, 0xC7, 0xCF, 0);
+ bookButtons[1].buttonCallback = BUTTON_FUNCTOR(KyraEngine_HoF, this, &KyraEngine_HoF::bookNextPage);
+ GUI_V2_BUTTON(bookButtons[2], 0x26, 0, 0, 1, 1, 1, 0x4487, 0, 0x8F, 0xBE, 0x21, 0x0A, 0xC7, 0xCF, 0xC7, 0xCF, 0xC7, 0xCF, 0);
+ bookButtons[2].buttonCallback = BUTTON_FUNCTOR(KyraEngine_HoF, this, &KyraEngine_HoF::bookClose);
+ GUI_V2_BUTTON(bookButtons[3], 0x27, 0, 0, 1, 1, 1, 0x4487, 0, 0x08, 0x08, 0x90, 0xB4, 0xC7, 0xCF, 0xC7, 0xCF, 0xC7, 0xCF, 0);
+ bookButtons[3].buttonCallback = BUTTON_FUNCTOR(KyraEngine_HoF, this, &KyraEngine_HoF::bookPrevPage);
+ GUI_V2_BUTTON(bookButtons[4], 0x28, 0, 0, 1, 1, 1, 0x4487, 0, 0xAA, 0x08, 0x8E, 0xB4, 0xC7, 0xCF, 0xC7, 0xCF, 0xC7, 0xCF, 0);
+ bookButtons[4].buttonCallback = BUTTON_FUNCTOR(KyraEngine_HoF, this, &KyraEngine_HoF::bookNextPage);
+
+ Button *buttonList = 0;
+
+ for (uint i = 0; i < ARRAYSIZE(bookButtons); ++i)
+ buttonList = _gui->addButtonToList(buttonList, &bookButtons[i]);
+
+ showBookPage();
+ _bookShown = true;
+ while (_bookShown && !_quitFlag) {
+ checkInput(buttonList);
+ removeInputTop();
+
+ if (_bookCurPage != _bookNewPage) {
+ _bookCurPage = _bookNewPage;
+ _screen->clearPage(2);
+ loadBookBkgd();
+ showBookPage();
+ snd_playSoundEffect(0x64);
+ _screen->hideMouse();
+ _screen->copyRegion(0, 0, 0, 0, 0x140, 0xC8, 2, 0, Screen::CR_NO_P_CHECK);
+ _screen->updateScreen();
+ _screen->showMouse();
+ }
+ }
+ _screen->clearPage(2);
+}
+
+void KyraEngine_HoF::bookDecodeText(uint8 *str) {
+ uint8 *dst = str, *op = str;
+ while (*op != 0x1A) {
+ while (*op != 0x1A && *op != 0x0D)
+ *dst++ = *op++;
+
+ if (*op == 0x1A)
+ break;
+
+ op += 2;
+ *dst++ = 0x0D;
+ }
+ *dst = 0;
+}
+
+void KyraEngine_HoF::bookPrintText(int dstPage, const uint8 *str, int x, int y, uint8 color) {
+ int curPageBackUp = _screen->_curPage;
+ _screen->_curPage = dstPage;
+
+ _screen->setTextColor(_bookTextColorMap, 0, 3);
+ Screen::FontId oldFont = _screen->setFont(Screen::FID_BOOKFONT_FNT);
+ _screen->_charWidth = -2;
+
+ _screen->hideMouse();
+ _screen->printText((const char*)str, x, y, color, (_flags.lang == Common::JA_JPN) ? 0xf6 : 0);
+ _screen->showMouse();
+
+ _screen->_charWidth = 0;
+ _screen->setFont(oldFont);
+ _screen->_curPage = curPageBackUp;
+}
+
+int KyraEngine_HoF::bookPrevPage(Button *button) {
+ _bookNewPage = MAX<int>(_bookCurPage-2, 0);
+ return 0;
+}
+
+int KyraEngine_HoF::bookNextPage(Button *button) {
+ _bookNewPage = MIN<int>(_bookCurPage+2, _bookMaxPage);
+ return 0;
+}
+
+int KyraEngine_HoF::bookClose(Button *button) {
+ _bookShown = false;
+ return 0;
+}
+
+// cauldron specific code
+
+int KyraEngine_HoF::cauldronClearButton(Button *button) {
+ if (!queryGameFlag(2)) {
+ updateCharFacing();
+ objectChat(getTableString(0xF0, _cCodeBuffer, 1), 0, 0x83, 0xF0);
+ return 0;
+ }
+
+ if (queryGameFlag(0xE4)) {
+ snd_playSoundEffect(0x0D);
+ return 0;
+ }
+
+ _screen->hideMouse();
+ displayInvWsaLastFrame();
+ snd_playSoundEffect(0x25);
+ loadInvWsa("PULL.WSA", 1, 6, 0, -1, -1, 1);
+ loadInvWsa("CAULD00.WSA", 1, 7, 0, 0xD4, 0x0F, 1);
+ showMessage(0, 0xCF);
+ setCauldronState(0, 0);
+ clearCauldronTable();
+ snd_playSoundEffect(0x57);
+ loadInvWsa("CAULDFIL.WSA", 1, 7, 0, -1, -1, 1);
+ _screen->showMouse();
+ return 0;
+}
+
+int KyraEngine_HoF::cauldronButton(Button *button) {
+ if (!queryGameFlag(2)) {
+ objectChat(getTableString(0xF0, _cCodeBuffer, 1), 0, 0x83, 0xF0);
+ return 0;
+ }
+
+ if (!_screen->isMouseVisible() || _handItemSet < -1)
+ return 0;
+
+ if (queryGameFlag(0xE4)) {
+ snd_playSoundEffect(0x0D);
+ return 0;
+ }
+
+ updateCharFacing();
+
+ for (int i = 0; _cauldronProtectedItems[i] != -1; ++i) {
+ if (_itemInHand == _cauldronProtectedItems[i]) {
+ objectChat(getTableString(0xF1, _cCodeBuffer, 1), 0, 0x83, 0xF1);
+ return 0;
+ }
+ }
+
+ if (_itemInHand == -1) {
+ listItemsInCauldron();
+ return 0;
+ }
+
+ for (int i = 0; _cauldronBowlTable[i] != -1; i += 2) {
+ if (_itemInHand == _cauldronBowlTable[i]) {
+ addFrontCauldronTable(_itemInHand);
+ setHandItem(_cauldronBowlTable[i+1]);
+ if (!updateCauldron()) {
+ _cauldronState = 0;
+ cauldronRndPaletteFade();
+ }
+ return 0;
+ }
+ }
+
+ if (_itemInHand == 18) {
+ const int16 *magicTable = (_mainCharacter.sceneId == 77) ? _cauldronMagicTableScene77 : _cauldronMagicTable;
+ while (magicTable[0] != -1) {
+ if (_cauldronState == magicTable[0]) {
+ setHandItem(magicTable[1]);
+ snd_playSoundEffect(0x6C);
+ ++_cauldronUseCount;
+ if (_cauldronStateTable[_cauldronState] <= _cauldronUseCount && _cauldronUseCount) {
+ showMessage(0, 0xCF);
+ setCauldronState(0, true);
+ clearCauldronTable();
+ }
+ return 0;
+ }
+ magicTable += 2;
+ }
+ } else if (_itemInHand >= 0) {
+ int item = _itemInHand;
+ cauldronItemAnim(item);
+ addFrontCauldronTable(item);
+ if (!updateCauldron()) {
+ _cauldronState = 0;
+ cauldronRndPaletteFade();
+ }
+ }
+
+ return 0;
+}
+
+#pragma mark -
+
+void GUI_HoF::getInput() {
+ if (!_displayMenu)
+ return;
+
+ _vm->checkInput(_menuButtonList);
+ _vm->removeInputTop();
+ if (_vm->quit()) {
+ _displayMenu = false;
+ _isLoadMenu = false;
+ _isSaveMenu = false;
+ _isOptionsMenu = false;
+ _isDeleteMenu = false;
+ }
+}
+
+int GUI_HoF::optionsButton(Button *button) {
+ _restartGame = false;
+ _reloadTemporarySave = false;
+
+ _screen->hideMouse();
+ updateButton(&_vm->_inventoryButtons[0]);
+ _screen->showMouse();
+
+ if (!_screen->isMouseVisible() && button)
+ return 0;
+
+ _vm->showMessage(0, 0xCF);
+
+ if (_vm->_handItemSet < -1) {
+ _vm->_handItemSet = -1;
+ _screen->hideMouse();
+ _screen->setMouseCursor(1, 1, _vm->getShapePtr(0));
+ _screen->showMouse();
+ return 0;
+ }
+
+ int oldHandItem = _vm->_itemInHand;
+ _screen->setMouseCursor(0, 0, _vm->getShapePtr(0));
+ _vm->displayInvWsaLastFrame();
+ //XXX
+ _displayMenu = true;
+
+ for (uint i = 0; i < ARRAYSIZE(_menuButtons); ++i) {
+ _menuButtons[i].data0Val1 = _menuButtons[i].data1Val1 = _menuButtons[i].data2Val1 = 4;
+ _menuButtons[i].data0Callback = _redrawShadedButtonFunctor;
+ _menuButtons[i].data1Callback = _menuButtons[i].data2Callback = _redrawButtonFunctor;
+ }
+
+ initMenuLayout(_mainMenu);
+ initMenuLayout(_gameOptions);
+ initMenuLayout(_audioOptions);
+ initMenuLayout(_choiceMenu);
+ _loadMenu.numberOfItems = 6;
+ initMenuLayout(_loadMenu);
+ initMenuLayout(_saveMenu);
+ initMenuLayout(_savenameMenu);
+ initMenuLayout(_deathMenu);
+
+ _currentMenu = &_mainMenu;
+
+ if (_vm->_menuDirectlyToLoad) {
+ backUpPage1(_vm->_screenBuffer);
+ setupPalette();
+
+ _loadedSave = false;
+
+ loadMenu(0);
+
+ if (_loadedSave) {
+ if (_restartGame)
+ _vm->_itemInHand = -1;
+ } else {
+ restorePage1(_vm->_screenBuffer);
+ restorePalette();
+ }
+
+ resetState(-1);
+ _vm->_menuDirectlyToLoad = false;
+ return 0;
+ }
+
+ if (!button) {
+ _currentMenu = &_deathMenu;
+ _isDeathMenu = true;
+ } else {
+ _isDeathMenu = false;
+ }
+
+ backUpPage1(_vm->_screenBuffer);
+ setupPalette();
+ initMenu(*_currentMenu);
+ _madeSave = false;
+ _loadedSave = false;
+ _vm->_itemInHand = -1;
+ updateAllMenuButtons();
+
+ if (_isDeathMenu) {
+ while (!_screen->isMouseVisible())
+ _screen->showMouse();
+ }
+
+ while (_displayMenu) {
+ processHighlights(*_currentMenu, _vm->_mouseX, _vm->_mouseY);
+ getInput();
+ }
+
+ if (_vm->_runFlag && !_loadedSave && !_madeSave) {
+ restorePalette();
+ restorePage1(_vm->_screenBuffer);
+ }
+
+ if (_vm->_runFlag)
+ updateMenuButton(&_vm->_inventoryButtons[0]);
+
+ resetState(oldHandItem);
+
+ if (!_loadedSave && _reloadTemporarySave) {
+ _vm->_unkSceneScreenFlag1 = true;
+ _vm->loadGame(_vm->getSavegameFilename(999));
+ _vm->_saveFileMan->removeSavefile(_vm->getSavegameFilename(999));
+ _vm->_unkSceneScreenFlag1 = false;
+ }
+
+ return 0;
+}
+
+#pragma mark -
+
+void GUI_HoF::renewHighlight(Menu &menu) {
+ if (!_displayMenu)
+ return;
+
+ MenuItem &item = menu.item[menu.highlightedItem];
+ int x = item.x + menu.x; int y = item.y + menu.y;
+ int x2 = x + item.width - 1; int y2 = y + item.height - 1;
+ redrawText(menu);
+ _screen->fillRect(x+2, y+2, x2-2, y2-2, item.bkgdColor);
+ redrawHighlight(menu);
+ _screen->updateScreen();
+}
+
+void GUI_HoF::setupPalette() {
+ memcpy(_screen->getPalette(1), _screen->getPalette(0), 768);
+
+ uint8 *palette = _screen->getPalette(0);
+ for (int i = 0; i < 768; ++i)
+ palette[i] >>= 1;
+
+ static const uint8 guiPal[] = { 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFc, 0xFD, 0xFE };
+
+ for (uint i = 0; i < ARRAYSIZE(guiPal); ++i)
+ memcpy(_screen->getPalette(0)+guiPal[i]*3, _screen->getPalette(1)+guiPal[i]*3, 3);
+
+ if (_isDeathMenu)
+ _screen->fadePalette(_screen->getPalette(0), 0x64);
+ else
+ _screen->setScreenPalette(_screen->getPalette(0));
+}
+
+void GUI_HoF::restorePalette() {
+ memcpy(_screen->getPalette(0), _screen->getPalette(1), 768);
+ _screen->setScreenPalette(_screen->getPalette(0));
+}
+
+void GUI_HoF::backUpPage1(uint8 *buffer) {
+ _screen->copyRegionToBuffer(1, 0, 0, 320, 200, buffer);
+}
+
+void GUI_HoF::restorePage1(const uint8 *buffer) {
+ _screen->copyBlockToPage(1, 0, 0, 320, 200, buffer);
+}
+
+void GUI_HoF::resetState(int item) {
+ _vm->_timer->resetNextRun();
+ _vm->setNextIdleAnimTimer();
+ _isDeathMenu = false;
+ if (!_loadedSave) {
+ _vm->setHandItem(item);
+ } else {
+ _vm->setHandItem(_vm->_itemInHand);
+ _vm->setTimer1DelaySecs(7);
+ _vm->_shownMessage = " ";
+ _vm->_fadeMessagePalette = false;
+ }
+ _buttonListChanged = true;
+}
+
+void GUI_HoF::setupSavegameNames(Menu &menu, int num) {
+ for (int i = 0; i < num; ++i) {
+ strcpy(_vm->getTableString(menu.item[i].itemId, _vm->_optionsBuffer, 0), "");
+ menu.item[i].saveSlot = -1;
+ menu.item[i].enabled = false;
+ }
+
+ int startSlot = 0;
+ if (_isSaveMenu && _savegameOffset == 0)
+ startSlot = 1;
+
+ KyraEngine::SaveHeader header;
+ Common::InSaveFile *in;
+ for (int i = startSlot; i < num && uint(_savegameOffset + i) < _saveSlots.size(); ++i) {
+ if ((in = _vm->openSaveForReading(_vm->getSavegameFilename(_saveSlots[i + _savegameOffset]), header)) != 0) {
+ strncpy(_vm->getTableString(menu.item[i].itemId, _vm->_optionsBuffer, 0), header.description.c_str(), 80);
+ menu.item[i].saveSlot = _saveSlots[i + _savegameOffset];
+ menu.item[i].enabled = true;
+ delete in;
+ }
+ }
+
+ if (_savegameOffset == 0) {
+ if (_isSaveMenu) {
+ char *dst = _vm->getTableString(menu.item[0].itemId, _vm->_optionsBuffer, 0);
+ const char *src = _vm->getTableString(_vm->gameFlags().isTalkie ? 10 : 18, _vm->_optionsBuffer, 0);
+ strcpy(dst, src);
+ menu.item[0].saveSlot = -2;
+ menu.item[0].enabled = true;
+ } else {
+ char *dst = _vm->getTableString(menu.item[0].itemId, _vm->_optionsBuffer, 0);
+ const char *src = _vm->getTableString(_vm->gameFlags().isTalkie ? 34 : 42, _vm->_optionsBuffer, 0);
+ strcpy(dst, src);
+ }
+ }
+}
+
+int GUI_HoF::scrollUpButton(Button *button) {
+ updateMenuButton(button);
+
+ if (_savegameOffset == (_isDeleteMenu ? 1 : 0))
+ return 0;
+
+ --_savegameOffset;
+ if (_isLoadMenu) {
+ setupSavegameNames(_loadMenu, 5);
+ // original calls something different here...
+ initMenu(_loadMenu);
+ } else if (_isSaveMenu || _isDeleteMenu) {
+ setupSavegameNames(_saveMenu, 5);
+ // original calls something different here...
+ initMenu(_saveMenu);
+ }
+
+ return 0;
+}
+
+int GUI_HoF::scrollDownButton(Button *button) {
+ updateMenuButton(button);
+ ++_savegameOffset;
+
+ if (uint(_savegameOffset + 5) >= _saveSlots.size())
+ _savegameOffset = MAX<int>(_saveSlots.size() - 5, _isDeleteMenu ? 1 : 0);
+
+ if (_isLoadMenu) {
+ setupSavegameNames(_loadMenu, 5);
+ // original calls something different here...
+ initMenu(_loadMenu);
+ } else if (_isSaveMenu || _isDeleteMenu) {
+ setupSavegameNames(_saveMenu, 5);
+ // original calls something different here...
+ initMenu(_saveMenu);
+ }
+
+ return 0;
+}
+
+#pragma mark -
+
+int GUI_HoF::quitGame(Button *caller) {
+ updateMenuButton(caller);
+ if (choiceDialog(_vm->gameFlags().isTalkie ? 0xF : 0x17, 1)) {
+ _displayMenu = false;
+ _vm->_runFlag = false;
+ _vm->_sound->beginFadeOut();
+ _screen->fadeToBlack();
+ _screen->clearCurPage();
+ }
+
+ if (_vm->_runFlag) {
+ initMenu(*_currentMenu);
+ updateAllMenuButtons();
+ }
+
+ return 0;
+}
+
+int GUI_HoF::resumeGame(Button *caller) {
+ updateMenuButton(caller);
+ _displayMenu = false;
+ return 0;
+}
+
+int GUI_HoF::gameOptions(Button *caller) {
+ updateMenuButton(caller);
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ initMenu(_gameOptions);
+ _isOptionsMenu = true;
+
+ const int menuX = _gameOptions.x;
+ const int menuY = _gameOptions.y;
+
+ for (int i = 0; i < 4; ++i) {
+ int x = menuX + _sliderBarsPosition[i*2+0];
+ int y = menuY + _sliderBarsPosition[i*2+1];
+ _screen->drawShape(0, _vm->_buttonShapes[16], x, y, 0, 0);
+ drawSliderBar(i, _vm->_buttonShapes[17]);
+ _sliderButtons[0][i].buttonCallback = _sliderHandlerFunctor;
+ _sliderButtons[0][i].x = x;
+ _sliderButtons[0][i].y = y;
+ _menuButtonList = addButtonToList(_menuButtonList, &_sliderButtons[0][i]);
+ _sliderButtons[2][i].buttonCallback = _sliderHandlerFunctor;
+ _sliderButtons[2][i].x = x + 10;
+ _sliderButtons[2][i].y = y;
+ _menuButtonList = addButtonToList(_menuButtonList, &_sliderButtons[2][i]);
+ _sliderButtons[1][i].buttonCallback = _sliderHandlerFunctor;
+ _sliderButtons[1][i].x = x + 120;
+ _sliderButtons[1][i].y = y;
+ _menuButtonList = addButtonToList(_menuButtonList, &_sliderButtons[1][i]);
+ }
+
+ while (_isOptionsMenu) {
+ processHighlights(_gameOptions, _vm->_mouseX, _vm->_mouseY);
+ getInput();
+ }
+
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+
+ _vm->writeSettings();
+
+ initMenu(*_currentMenu);
+ updateAllMenuButtons();
+
+ return 0;
+}
+
+int GUI_HoF::gameOptionsTalkie(Button *caller) {
+ updateMenuButton(caller);
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ bool textEnabled = _vm->textEnabled();
+ int lang = _vm->_lang;
+
+ setupOptionsButtons();
+ initMenu(_gameOptions);
+ _isOptionsMenu = true;
+
+ while (_isOptionsMenu) {
+ processHighlights(_gameOptions, _vm->_mouseX, _vm->_mouseY);
+ getInput();
+ }
+
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+
+ if (textEnabled && !_vm->textEnabled() && !_vm->speechEnabled()) {
+ _vm->_configVoice = 1;
+ choiceDialog(0x1E, 0);
+ }
+
+ if (_vm->_lang != lang) {
+ _reloadTemporarySave = true;
+ _vm->saveGame(_vm->getSavegameFilename(999), "Temporary Kyrandia 2 Savegame");
+ _vm->loadCCodeBuffer("C_CODE.XXX");
+ if (_vm->_flags.isTalkie)
+ _vm->loadOptionsBuffer("OPTIONS.XXX");
+ else
+ _vm->_optionsBuffer = _vm->_cCodeBuffer;
+ _vm->loadChapterBuffer(_vm->_newChapterFile);
+ _vm->loadNPCScript();
+ _vm->setupLangButtonShapes();
+ }
+
+ _vm->writeSettings();
+
+ initMenu(*_currentMenu);
+ updateAllMenuButtons();
+ return 0;
+}
+
+int GUI_HoF::quitOptionsMenu(Button *caller) {
+ updateMenuButton(caller);
+ _isOptionsMenu = false;
+ return 0;
+}
+
+int GUI_HoF::toggleWalkspeed(Button *caller) {
+ updateMenuButton(caller);
+ if (_vm->_configWalkspeed == 5)
+ _vm->_configWalkspeed = 3;
+ else
+ _vm->_configWalkspeed = 5;
+ _vm->_timer->setDelay(0, _vm->_configWalkspeed);
+ setupOptionsButtons();
+ renewHighlight(_gameOptions);
+ return 0;
+}
+
+int GUI_HoF::changeLanguage(Button *caller) {
+ updateMenuButton(caller);
+ ++_vm->_lang;
+ _vm->_lang %= 3;
+ setupOptionsButtons();
+ renewHighlight(_gameOptions);
+ return 0;
+}
+
+int GUI_HoF::toggleText(Button *caller) {
+ updateMenuButton(caller);
+
+ if (_vm->textEnabled()) {
+ if (_vm->speechEnabled())
+ _vm->_configVoice = 1;
+ else
+ _vm->_configVoice = 3;
+ } else {
+ if (_vm->speechEnabled())
+ _vm->_configVoice = 2;
+ else
+ _vm->_configVoice = 0;
+ }
+
+ setupOptionsButtons();
+ renewHighlight(_gameOptions);
+ return 0;
+}
+
+void GUI_HoF::setupOptionsButtons() {
+ if (_vm->_configWalkspeed == 3)
+ _gameOptions.item[0].itemId = 28;
+ else
+ _gameOptions.item[0].itemId = 27;
+
+ if (_vm->textEnabled())
+ _gameOptions.item[2].itemId = 18;
+ else
+ _gameOptions.item[2].itemId = 17;
+
+ switch (_vm->_lang) {
+ case 0:
+ _gameOptions.item[1].itemId = 31;
+ break;
+
+ case 1:
+ _gameOptions.item[1].itemId = 32;
+ break;
+
+ case 2:
+ _gameOptions.item[1].itemId = 33;
+ break;
+
+ default:
+ break;
+ }
+}
+
+int GUI_HoF::audioOptions(Button *caller) {
+ updateMenuButton(caller);
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ initMenu(_audioOptions);
+ const int menuX = _audioOptions.x;
+ const int menuY = _audioOptions.y;
+ const int maxButton = 3; // 2 if voc is disabled
+
+ for (int i = 0; i < maxButton; ++i) {
+ int x = menuX + _sliderBarsPosition[i*2+0];
+ int y = menuY + _sliderBarsPosition[i*2+1];
+ _screen->drawShape(0, _vm->_buttonShapes[16], x, y, 0, 0);
+ drawSliderBar(i, _vm->_buttonShapes[17]);
+ _sliderButtons[0][i].buttonCallback = _sliderHandlerFunctor;
+ _sliderButtons[0][i].x = x;
+ _sliderButtons[0][i].y = y;
+ _menuButtonList = addButtonToList(_menuButtonList, &_sliderButtons[0][i]);
+ _sliderButtons[2][i].buttonCallback = _sliderHandlerFunctor;
+ _sliderButtons[2][i].x = x + 10;
+ _sliderButtons[2][i].y = y;
+ _menuButtonList = addButtonToList(_menuButtonList, &_sliderButtons[2][i]);
+ _sliderButtons[1][i].buttonCallback = _sliderHandlerFunctor;
+ _sliderButtons[1][i].x = x + 120;
+ _sliderButtons[1][i].y = y;
+ _menuButtonList = addButtonToList(_menuButtonList, &_sliderButtons[1][i]);
+ }
+
+ _isOptionsMenu = true;
+ updateAllMenuButtons();
+ bool speechEnabled = _vm->speechEnabled();
+ while (_isOptionsMenu) {
+ processHighlights(_audioOptions, _vm->_mouseX, _vm->_mouseY);
+ getInput();
+ }
+
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ if (speechEnabled && !_vm->textEnabled() && (!_vm->speechEnabled() || _vm->getVolume(KyraEngine::kVolumeSpeech) == 2)) {
+ _vm->_configVoice = 0;
+ _vm->setVolume(KyraEngine::kVolumeSpeech, 75);
+ choiceDialog(0x1D, 0);
+ }
+
+ _vm->writeSettings();
+
+ initMenu(*_currentMenu);
+ updateAllMenuButtons();
+ return 0;
+}
+
+int GUI_HoF::sliderHandler(Button *caller) {
+ int button = 0;
+ if (caller->index >= 24 && caller->index <= 27)
+ button = caller->index - 24;
+ else if (caller->index >= 28 && caller->index <= 31)
+ button = caller->index - 28;
+ else
+ button = caller->index - 32;
+
+ assert(button >= 0 && button <= 3);
+
+ int oldVolume = 0;
+
+ if (_vm->gameFlags().isTalkie) {
+ oldVolume = _vm->getVolume(KyraEngine::kVolumeEntry(button));
+ } else {
+ if (button < 2)
+ oldVolume = _vm->getVolume(KyraEngine::kVolumeEntry(button));
+ else if (button == 2)
+ oldVolume = (_vm->_configWalkspeed == 3) ? 97 : 2;
+ else if (button == 3)
+ oldVolume = _vm->_configTextspeed;
+ }
+
+ int newVolume = oldVolume;
+
+ if (caller->index >= 24 && caller->index <= 27)
+ newVolume -= 10;
+ else if (caller->index >= 28 && caller->index <= 31)
+ newVolume += 10;
+ else
+ newVolume = _vm->_mouseX - caller->x - 7;
+
+ newVolume = MAX(2, newVolume);
+ newVolume = MIN(97, newVolume);
+
+ if (newVolume == oldVolume)
+ return 0;
+
+ int lastMusicCommand = -1;
+ bool playSoundEffect = false;
+
+ drawSliderBar(button, _vm->_buttonShapes[18]);
+
+ if (_vm->gameFlags().isTalkie) {
+ if (button == 2) {
+ if (_vm->textEnabled())
+ _vm->_configVoice = 2;
+ else
+ _vm->_configVoice = 1;
+ }
+
+ _vm->setVolume(KyraEngine::kVolumeEntry(button), newVolume);
+
+ switch (button) {
+ case 0:
+ lastMusicCommand = _vm->_lastMusicCommand;
+ break;
+
+ case 1:
+ playSoundEffect = true;
+ break;
+
+ case 2:
+ _vm->playVoice(90, 28);
+ break;
+
+ default:
+ return 0;
+ }
+ } else {
+ if (button < 2) {
+ _vm->setVolume(KyraEngine::kVolumeEntry(button), newVolume);
+ if (button == 0)
+ lastMusicCommand = _vm->_lastMusicCommand;
+ else
+ playSoundEffect = true;
+ } else if (button == 2) {
+ _vm->_configWalkspeed = (newVolume > 48) ? 3 : 5;
+ _vm->setWalkspeed(_vm->_configWalkspeed);
+ } else if (button == 3) {
+ _vm->_configTextspeed = newVolume;
+ }
+ }
+
+ drawSliderBar(button, _vm->_buttonShapes[17]);
+ if (playSoundEffect)
+ _vm->snd_playSoundEffect(0x18);
+ else if (lastMusicCommand >= 0)
+ _vm->snd_playWanderScoreViaMap(lastMusicCommand, 1);
+
+ _screen->updateScreen();
+ return 0;
+}
+
+void GUI_HoF::drawSliderBar(int slider, const uint8 *shape) {
+ const int menuX = _audioOptions.x;
+ const int menuY = _audioOptions.y;
+ int x = menuX + _sliderBarsPosition[slider*2+0] + 10;
+ int y = menuY + _sliderBarsPosition[slider*2+1];
+
+ int position = 0;
+ if (_vm->gameFlags().isTalkie) {
+ position = _vm->getVolume(KyraEngine::kVolumeEntry(slider));
+ } else {
+ if (slider < 2)
+ position = _vm->getVolume(KyraEngine::kVolumeEntry(slider));
+ else if (slider == 2)
+ position = (_vm->_configWalkspeed == 3) ? 97 : 2;
+ else if (slider == 3)
+ position = _vm->_configTextspeed;
+ }
+
+ position = MAX(2, position);
+ position = MIN(97, position);
+ _screen->drawShape(0, shape, x+position, y, 0, 0);
+}
+
+int GUI_HoF::loadMenu(Button *caller) {
+ updateSaveList();
+
+ if (!_vm->_menuDirectlyToLoad) {
+ updateMenuButton(caller);
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ }
+
+ _savegameOffset = 0;
+ setupSavegameNames(_loadMenu, 5);
+ initMenu(_loadMenu);
+ _isLoadMenu = true;
+ _noLoadProcess = false;
+ _vm->_gameToLoad = -1;
+ updateAllMenuButtons();
+
+ _screen->updateScreen();
+ while (_isLoadMenu) {
+ processHighlights(_loadMenu, _vm->_mouseX, _vm->_mouseY);
+ getInput();
+ }
+
+ if (_noLoadProcess) {
+ if (!_vm->_menuDirectlyToLoad) {
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ initMenu(*_currentMenu);
+ updateAllMenuButtons();
+ }
+ } else if (_vm->_gameToLoad >= 0) {
+ restorePage1(_vm->_screenBuffer);
+ restorePalette();
+ _vm->loadGame(_vm->getSavegameFilename(_vm->_gameToLoad));
+ if (_vm->_gameToLoad == 0) {
+ _restartGame = true;
+ for (int i = 0; i < 23; ++i)
+ _vm->resetCauldronStateTable(i);
+ _vm->runStartScript(1, 1);
+ }
+ _displayMenu = false;
+ _loadedSave = true;
+ }
+
+ return 0;
+}
+
+int GUI_HoF::clickLoadSlot(Button *caller) {
+ updateMenuButton(caller);
+
+ assert((caller->index-0x10) >= 0 && (caller->index-0x10 <= 6));
+ MenuItem &item = _loadMenu.item[caller->index-0x10];
+
+ if (item.saveSlot >= 0) {
+ _vm->_gameToLoad = item.saveSlot;
+ _isLoadMenu = false;
+ }
+
+ return 0;
+}
+
+int GUI_HoF::cancelLoadMenu(Button *caller) {
+ updateMenuButton(caller);
+ _isLoadMenu = false;
+ _noLoadProcess = true;
+ return 0;
+}
+
+int GUI_HoF::saveMenu(Button *caller) {
+ updateSaveList();
+
+ updateMenuButton(caller);
+
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+
+ _isSaveMenu = true;
+ _noSaveProcess = false;
+ _saveSlot = -1;
+ _savegameOffset = 0;
+ setupSavegameNames(_saveMenu, 5);
+ initMenu(_saveMenu);
+
+ updateAllMenuButtons();
+
+ while (_isSaveMenu) {
+ processHighlights(_saveMenu, _vm->_mouseX, _vm->_mouseY);
+ getInput();
+ }
+
+ if (_noSaveProcess) {
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ initMenu(*_currentMenu);
+ updateAllMenuButtons();
+ return 0;
+ } else if(_saveSlot <= -1) {
+ return 0;
+ }
+
+ restorePage1(_vm->_screenBuffer);
+ restorePalette();
+ _vm->saveGame(_vm->getSavegameFilename(_saveSlot), _saveDescription);
+ _displayMenu = false;
+ _madeSave = true;
+
+ return 0;
+}
+
+int GUI_HoF::clickSaveSlot(Button *caller) {
+ updateMenuButton(caller);
+
+ assert((caller->index-0x10) >= 0 && (caller->index-0x10 <= 6));
+ MenuItem &item = _saveMenu.item[caller->index-0x10];
+
+ if (item.saveSlot >= 0) {
+ if (_isDeleteMenu) {
+ _slotToDelete = item.saveSlot;
+ _isDeleteMenu = false;
+ return 0;
+ } else {
+ _saveSlot = item.saveSlot;
+ strcpy(_saveDescription, _vm->getTableString(item.itemId, _vm->_optionsBuffer, 0));
+ }
+ } else if (item.saveSlot == -2) {
+ _saveSlot = getNextSavegameSlot();
+ memset(_saveDescription, 0, sizeof(_saveDescription));
+ }
+
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+
+ initMenu(_savenameMenu);
+ _screen->fillRect(0x26, 0x5B, 0x11F, 0x66, 0xFA);
+ const char *desc = nameInputProcess(_saveDescription, 0x27, 0x5C, 0xFD, 0xFA, 0xFE, 0x50);
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ if (desc) {
+ _isSaveMenu = false;
+ _isDeleteMenu = false;
+ } else {
+ initMenu(_saveMenu);
+ }
+
+ return 0;
+}
+
+int GUI_HoF::cancelSaveMenu(Button *caller) {
+ updateMenuButton(caller);
+ _isSaveMenu = false;
+ _isDeleteMenu = false;
+ _noSaveProcess = true;
+ return 0;
+}
+
+int GUI_HoF::deleteMenu(Button *caller) {
+ updateSaveList();
+
+ updateMenuButton(caller);
+ if (_saveSlots.size() < 2) {
+ _vm->snd_playSoundEffect(0x0D);
+ return 0;
+ }
+
+ do {
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ _savegameOffset = 1;
+ _saveMenu.menuNameId = _vm->gameFlags().isTalkie ? 35 : 1;
+ setupSavegameNames(_saveMenu, 5);
+ initMenu(_saveMenu);
+ _isDeleteMenu = true;
+ _slotToDelete = -1;
+ updateAllMenuButtons();
+
+ while (_isDeleteMenu) {
+ processHighlights(_saveMenu, _vm->_mouseX, _vm->_mouseY);
+ getInput();
+ }
+
+ if (_slotToDelete < 1) {
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ initMenu(*_currentMenu);
+ updateAllMenuButtons();
+ _saveMenu.menuNameId = _vm->gameFlags().isTalkie ? 9 : 17;
+ return 0;
+ }
+ } while (choiceDialog(_vm->gameFlags().isTalkie ? 0x24 : 2, 1) == 0);
+
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ initMenu(*_currentMenu);
+ updateAllMenuButtons();
+ _vm->_saveFileMan->removeSavefile(_vm->getSavegameFilename(_slotToDelete));
+ Common::Array<int>::iterator i = Common::find(_saveSlots.begin(), _saveSlots.end(), _slotToDelete);
+ while (i != _saveSlots.end()) {
+ ++i;
+ if (i == _saveSlots.end())
+ break;
+ // We are only renaming all savefiles until we get some slots missing
+ // Also not rename quicksave slot filenames
+ if (*(i-1) != *i || *i >= 990)
+ break;
+ Common::String oldName = _vm->getSavegameFilename(*i);
+ Common::String newName = _vm->getSavegameFilename(*i-1);
+ _vm->_saveFileMan->renameSavefile(oldName.c_str(), newName.c_str());
+ }
+ _saveMenu.menuNameId = _vm->gameFlags().isTalkie ? 9 : 17;
+ return 0;
+}
+
+const char *GUI_HoF::nameInputProcess(char *buffer, int x, int y, uint8 c1, uint8 c2, uint8 c3, int bufferSize) {
+ bool running = true;
+ int curPos = strlen(buffer);
+
+ int x2 = x, y2 = y;
+ _text->printText(buffer, x, y, c1, c2, c2);
+
+ for (int i = 0; i < curPos; ++i)
+ x2 += getCharWidth(buffer[i]);
+
+ drawTextfieldBlock(x2, y2, c3);
+
+ _keyPressed.reset();
+ _cancelNameInput = _finishNameInput = false;
+ while (running && !_vm->quit()) {
+ processHighlights(_savenameMenu, _vm->_mouseX, _vm->_mouseY);
+ checkTextfieldInput();
+ if (_keyPressed.keycode == Common::KEYCODE_RETURN || _keyPressed.keycode == Common::KEYCODE_KP_ENTER || _finishNameInput) {
+ if (checkSavegameDescription(buffer, curPos)) {
+ buffer[curPos] = 0;
+ running = false;
+ } else {
+ _finishNameInput = false;
+ }
+ } else if (_keyPressed.keycode == Common::KEYCODE_ESCAPE || _cancelNameInput) {
+ running = false;
+ return 0;
+ } else if ((_keyPressed.keycode == Common::KEYCODE_BACKSPACE || _keyPressed.keycode == Common::KEYCODE_DELETE) && curPos > 0) {
+ drawTextfieldBlock(x2, y2, c2);
+ --curPos;
+ x2 -= getCharWidth(buffer[curPos]);
+ drawTextfieldBlock(x2, y2, c3);
+ _screen->updateScreen();
+ } else if (_keyPressed.ascii > 31 && _keyPressed.ascii < 127 && curPos < bufferSize) {
+ if (x2 + getCharWidth(_keyPressed.ascii) + 7 < 0x11F) {
+ buffer[curPos] = _keyPressed.ascii;
+ const char text[2] = { buffer[curPos], 0 };
+ _text->printText(text, x2, y2, c1, c2, c2);
+ x2 += getCharWidth(_keyPressed.ascii);
+ drawTextfieldBlock(x2, y2, c3);
+ ++curPos;
+ _screen->updateScreen();
+ }
+ }
+
+ _keyPressed.reset();
+ }
+
+ return buffer;
+}
+
+int GUI_HoF::finishSavename(Button *caller) {
+ updateMenuButton(caller);
+ _finishNameInput = true;
+ return 0;
+}
+
+int GUI_HoF::cancelSavename(Button *caller) {
+ updateMenuButton(caller);
+ _cancelNameInput = true;
+ return 0;
+}
+
+bool GUI_HoF::checkSavegameDescription(const char *buffer, int size) {
+ if (!buffer || !size)
+ return false;
+ if (buffer[0] == 0)
+ return false;
+ for (int i = 0; i < size; ++i) {
+ if (buffer[i] != 0x20)
+ return true;
+ else if (buffer[i] == 0x00)
+ return false;
+ }
+ return false;
+}
+
+int GUI_HoF::getCharWidth(uint8 c) {
+ Screen::FontId old = _screen->setFont(Screen::FID_8_FNT);
+ _screen->_charWidth = -2;
+ int width = _screen->getCharWidth(c);
+ _screen->_charWidth = 0;
+ _screen->setFont(old);
+ return width;
+}
+
+void GUI_HoF::checkTextfieldInput() {
+ Common::Event event;
+
+ bool running = true;
+ int keys = 0;
+ while (_vm->_eventMan->pollEvent(event) && running) {
+ switch (event.type) {
+ case Common::EVENT_QUIT:
+ _vm->_quitFlag = true;
+ break;
+
+ case Common::EVENT_KEYDOWN:
+ if (event.kbd.keycode == 'q' && event.kbd.flags == Common::KBD_CTRL)
+ _vm->_quitFlag = true;
+ else
+ _keyPressed = event.kbd;
+ running = false;
+ break;
+
+ case Common::EVENT_LBUTTONDOWN:
+ case Common::EVENT_LBUTTONUP: {
+ Common::Point pos = _vm->getMousePos();
+ _vm->_mouseX = pos.x;
+ _vm->_mouseY = pos.y;
+ keys = event.type == Common::EVENT_LBUTTONDOWN ? 199 : (200 | 0x800);
+ running = false;
+ } break;
+
+ case Common::EVENT_MOUSEMOVE: {
+ Common::Point pos = _vm->getMousePos();
+ _vm->_mouseX = pos.x;
+ _vm->_mouseY = pos.y;
+ _screen->updateScreen();
+ } break;
+
+ default:
+ break;
+ }
+ }
+
+ processButtonList(_menuButtonList, keys | 0x8000);
+}
+
+void GUI_HoF::drawTextfieldBlock(int x, int y, uint8 c) {
+ _screen->fillRect(x+1, y+1, x+7, y+8, c);
+}
+
+bool GUI_HoF::choiceDialog(int name, bool type) {
+ _choiceMenu.highlightedItem = 0;
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ if (type)
+ _choiceMenu.numberOfItems = 2;
+ else
+ _choiceMenu.numberOfItems = 1;
+ _choiceMenu.menuNameId = name;
+
+ initMenu(_choiceMenu);
+ _isChoiceMenu = true;
+ _choice = false;
+
+ while (_isChoiceMenu) {
+ processHighlights(_choiceMenu, _vm->_mouseX, _vm->_mouseY);
+ getInput();
+ }
+
+ restorePage1(_vm->_screenBuffer);
+ backUpPage1(_vm->_screenBuffer);
+ return _choice;
+}
+
+int GUI_HoF::choiceYes(Button *caller) {
+ updateMenuButton(caller);
+ _choice = true;
+ _isChoiceMenu = false;
+ return 0;
+}
+
+int GUI_HoF::choiceNo(Button *caller) {
+ updateMenuButton(caller);
+ _choice = false;
+ _isChoiceMenu = false;
+ return 0;
+}
+
+} // end of namespace Kyra
+
Copied: scummvm/trunk/engines/kyra/gui_hof.h (from rev 31865, scummvm/trunk/engines/kyra/gui_v2.h)
===================================================================
--- scummvm/trunk/engines/kyra/gui_hof.h (rev 0)
+++ scummvm/trunk/engines/kyra/gui_hof.h 2008-05-04 15:18:46 UTC (rev 31866)
@@ -0,0 +1,242 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef KYRA_GUI_V2_H
+#define KYRA_GUI_V2_H
+
+#include "kyra/gui.h"
+
+#define GUI_V2_BUTTON(button, a, b, c, d, e, f, h, i, j, k, l, m, n, o, p, q, r, s, t) \
+ button.nextButton = 0; \
+ button.index = a; \
+ button.unk6 = b; \
+ button.unk8 = c; \
+ button.data0Val1 = d; \
+ button.data1Val1 = e; \
+ button.data2Val1 = f; \
+ button.flags = h; \
+ button.data0ShapePtr = button.data1ShapePtr = button.data2ShapePtr = 0; \
+ button.dimTableIndex = i; \
+ button.x = j; \
+ button.y = k; \
+ button.width = l; \
+ button.height = m; \
+ button.data0Val2 = n; \
+ button.data0Val3 = o; \
+ button.data1Val2 = p; \
+ button.data1Val3 = q; \
+ button.data2Val2 = r; \
+ button.data2Val3 = s; \
+ button.flags2 = t;
+
+#define GUI_V2_MENU(menu, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) \
+ menu.x = a; \
+ menu.y = b; \
+ menu.width = c; \
+ menu.height = d; \
+ menu.bkgdColor = e; \
+ menu.color1 = f; \
+ menu.color2 = g; \
+ menu.menuNameId = h; \
+ menu.textColor = i; \
+ menu.titleX = j; \
+ menu.titleY = k; \
+ menu.highlightedItem = l; \
+ menu.numberOfItems = m; \
+ menu.scrollUpButtonX = n; \
+ menu.scrollUpButtonY = o; \
+ menu.scrollDownButtonX = p; \
+ menu.scrollDownButtonY = q
+
+#define GUI_V2_MENU_ITEM(item, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) \
+ item.enabled = a; \
+ item.itemId = b; \
+ item.x = c; \
+ item.y = d; \
+ item.width = e; \
+ item.height = f; \
+ item.textColor = g; \
+ item.highlightColor = h; \
+ item.titleX = i; \
+ item.bkgdColor = j; \
+ item.color1 = k; \
+ item.color2 = l; \
+ item.saveSlot = m; \
+ item.labelId = n; \
+ item.labelX = o; \
+ item.labelY = p; \
+ item.unk1F = q
+
+namespace Kyra {
+
+class KyraEngine_HoF;
+class Screen_v2;
+
+class GUI_HoF : public GUI {
+friend class KyraEngine_HoF;
+public:
+ GUI_HoF(KyraEngine_HoF *engine);
+
+ Button *addButtonToList(Button *list, Button *newButton);
+
+ void processButton(Button *button);
+ int processButtonList(Button *button, uint16 inputFlag);
+
+ int optionsButton(Button *button);
+private:
+ void getInput();
+
+ Button _menuButtons[7];
+ Button _scrollUpButton;
+ Button _scrollDownButton;
+ Menu _mainMenu, _gameOptions, _audioOptions, _choiceMenu, _loadMenu, _saveMenu, _savenameMenu, _deathMenu;
+ void initStaticData();
+
+ const char *getMenuTitle(const Menu &menu);
+ const char *getMenuItemTitle(const MenuItem &menuItem);
+ const char *getMenuItemLabel(const MenuItem &menuItem);
+
+ Button *getButtonListData() { return _menuButtons; }
+
+ Button *getScrollUpButton() { return &_scrollUpButton; }
+ Button *getScrollDownButton() { return &_scrollDownButton; }
+
+ int scrollUpButton(Button *button);
+ int scrollDownButton(Button *button);
+ Button::Callback _scrollUpFunctor;
+ Button::Callback _scrollDownFunctor;
+ Button::Callback getScrollUpButtonHandler() const { return _scrollUpFunctor; }
+ Button::Callback getScrollDownButtonHandler() const { return _scrollDownFunctor; }
+
+ Button _sliderButtons[3][4];
+
+ uint8 defaultColor1() const { return 0xCF; }
+ uint8 defaultColor2() const { return 0xF8; }
+
+ void renewHighlight(Menu &menu);
+
+ void setupPalette();
+ void restorePalette();
+
+ void backUpPage1(uint8 *buffer);
+ void restorePage1(const uint8 *buffer);
+
+ void resetState(int item);
+
+ KyraEngine_HoF *_vm;
+ Screen_v2 *_screen;
+
+ bool _buttonListChanged;
+ Button *_backUpButtonList;
+ Button *_unknownButtonList;
+
+ Menu *_currentMenu;
+ bool _isLoadMenu;
+ bool _isDeathMenu;
+ bool _isSaveMenu;
+ bool _isDeleteMenu;
+ bool _isChoiceMenu;
+ bool _isOptionsMenu;
+ bool _madeSave;
+ bool _loadedSave;
+ bool _restartGame;
+ bool _reloadTemporarySave;
+
+ int _savegameOffset;
+
+ void setupSavegameNames(Menu &menu, int num);
+
+ // main menu
+ int quitGame(Button *caller);
+ int resumeGame(Button *caller);
+
+ // options menu
+ int gameOptions(Button *caller);
+ int gameOptionsTalkie(Button *caller);
+ int quitOptionsMenu(Button *caller);
+
+ int toggleWalkspeed(Button *caller);
+ int changeLanguage(Button *caller);
+ int toggleText(Button *caller);
+
+ void setupOptionsButtons();
+
+ // audio menu
+ int audioOptions(Button *caller);
+
+ Button::Callback _sliderHandlerFunctor;
+ int sliderHandler(Button *caller);
+
+ void drawSliderBar(int slider, const uint8 *shape);
+
+ static const int _sliderBarsPosition[];
+
+ // load menu
+ bool _noLoadProcess;
+ int loadMenu(Button *caller);
+ int clickLoadSlot(Button *caller);
+ int cancelLoadMenu(Button *caller);
+
+ // save menu
+ bool _noSaveProcess;
+ int _saveSlot;
+ char _saveDescription[0x50];
+
+ int saveMenu(Button *caller);
+ int clickSaveSlot(Button *caller);
+ int cancelSaveMenu(Button *caller);
+
+ // delete menu
+ int _slotToDelete;
+ int deleteMenu(Button *caller);
+
+ // savename menu
+ bool _finishNameInput, _cancelNameInput;
+ Common::KeyState _keyPressed;
+
+ const char *nameInputProcess(char *buffer, int x, int y, uint8 c1, uint8 c2, uint8 c3, int bufferSize);
+ int finishSavename(Button *caller);
+ int cancelSavename(Button *caller);
+
+ bool checkSavegameDescription(const char *buffer, int size);
+ int getCharWidth(uint8 c);
+ void checkTextfieldInput();
+ void drawTextfieldBlock(int x, int y, uint8 c);
+
+ // choice menu
+ bool _choice;
+
+ bool choiceDialog(int name, bool type);
+ int choiceYes(Button *caller);
+ int choiceNo(Button *caller);
+
+ static const uint16 _menuStringsTalkie[];
+ static const uint16 _menuStringsOther[];
+};
+
+} // end of namespace Kyra
+
+#endif
+
Copied: scummvm/trunk/engines/kyra/gui_mr.cpp (from rev 31865, scummvm/trunk/engines/kyra/gui_v3.cpp)
===================================================================
--- scummvm/trunk/engines/kyra/gui_mr.cpp (rev 0)
+++ scummvm/trunk/engines/kyra/gui_mr.cpp 2008-05-04 15:18:46 UTC (rev 31866)
@@ -0,0 +1,964 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "kyra/gui_mr.h"
+#include "kyra/kyra_mr.h"
+#include "kyra/text_mr.h"
+#include "kyra/wsamovie.h"
+#include "kyra/resource.h"
+
+namespace Kyra {
+
+void KyraEngine_MR::showMessage(const char *string, uint8 c0, uint8 c1) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::showMessage('%s', %d, %d)", string, c0, c1);
+ _shownMessage = string;
+ _screen->hideMouse();
+
+ restoreCommandLine();
+ _restoreCommandLine = false;
+
+ if (string) {
+ int x = _text->getCenterStringX(string, 0, 320);
+ int pageBackUp = _screen->_curPage;
+ _screen->_curPage = 0;
+ _text->printText(string, x, _commandLineY, c0, c1, 0);
+ _screen->_curPage = pageBackUp;
+ _screen->updateScreen();
+ setCommandLineRestoreTimer(7);
+ }
+
+ _screen->showMouse();
+}
+
+void KyraEngine_MR::showMessageFromCCode(int string, uint8 c0, int) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::showMessageFromCCode(%d, %d, -)", string, c0);
+ showMessage((const char*)getTableEntry(_cCodeFile, string), c0, 0xF0);
+}
+
+void KyraEngine_MR::updateItemCommand(int item, int str, uint8 c0) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::updateItemCommand(%d, %d, %d)", item, str, c0);
+ char buffer[100];
+ char *src = (char*)getTableEntry(_itemFile, item);
+
+ while (*src != ' ')
+ ++src;
+ ++src;
+
+ *src = toupper(*src);
+
+ strcpy(buffer, src);
+ strcat(buffer, " ");
+ strcat(buffer, (const char*)getTableEntry(_cCodeFile, str));
+
+ showMessage(buffer, c0, 0xF0);
+}
+
+void KyraEngine_MR::updateCommandLine() {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::updateCommandLine()");
+ if (_restoreCommandLine) {
+ restoreCommandLine();
+ _restoreCommandLine = false;
+ }
+}
+
+void KyraEngine_MR::restoreCommandLine() {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::restoreCommandLine()");
+ int y = _inventoryState ? 144 : 188;
+ _screen->copyBlockToPage(0, 0, y, 320, 12, _interfaceCommandLine);
+}
+
+void KyraEngine_MR::updateCLState() {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::updateCLState()");
+ if (_inventoryState)
+ _commandLineY = 145;
+ else
+ _commandLineY = 189;
+}
+
+void KyraEngine_MR::showInventory() {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::showInventory()");
+ if (!_screen->isMouseVisible())
+ return;
+ if (queryGameFlag(3))
+ return;
+
+ _screen->copyBlockToPage(3, 0, 0, 320, 56, _interface);
+ drawMalcolmsMoodText();
+
+ _inventoryState = true;
+ updateCLState();
+
+ redrawInventory(30);
+ drawMalcolmsMoodPointer(-1, 30);
+ drawScore(30, 215, 191);
+
+ if (queryGameFlag(0x97))
+ drawJestersStaff(1, 30);
+
+ _screen->hideMouse();
+
+ if (_itemInHand < 0) {
+ _handItemSet = -1;
+ _screen->setMouseCursor(0, 0, getShapePtr(0));
+ }
+
+ _screen->copyRegion(0, 188, 0, 0, 320, 12, 0, 2, Screen::CR_NO_P_CHECK);
+
+ if (_inventoryScrollSpeed == -1) {
+ uint32 endTime = _system->getMillis() + _tickLength * 15;
+ int times = 0;
+ while (_system->getMillis() < endTime) {
+ _screen->copyRegion(0, 188, 0, 0, 320, 12, 0, 2, Screen::CR_NO_P_CHECK);
+ _screen->copyRegion(0, 188, 0, 0, 320, 12, 0, 2, Screen::CR_NO_P_CHECK);
+ ++times;
+ }
+
+ times = MAX(times, 1);
+
+ int speed = 60 / times;
+ if (speed <= 1)
+ _inventoryScrollSpeed = 1;
+ else if (speed >= 8)
+ _inventoryScrollSpeed = 8;
+ else
+ _inventoryScrollSpeed = speed;
+ }
+
+ int height = 12;
+ int y = 188;
+ int times = 0;
+ uint32 waitTill = _system->getMillis() + _tickLength;
+
+ while (y > 144) {
+ _screen->copyRegion(0, 0, 0, y, 320, height, 2, 0, Screen::CR_NO_P_CHECK);
+ _screen->updateScreen();
+
+ ++times;
+ if (_inventoryScrollSpeed == 1 && times == 3) {
+ while (waitTill > _system->getMillis())
+ _system->delayMillis(10);
+ times = 0;
+ waitTill = _system->getMillis() + _tickLength;
+ }
+
+ height += _inventoryScrollSpeed;
+ y -= _inventoryScrollSpeed;
+ }
+
+ _screen->copyRegion(0, 0, 0, 144, 320, 56, 2, 0, Screen::CR_NO_P_CHECK);
+ _screen->updateScreen();
+
+ initMainButtonList(false);
+
+ restorePage3();
+ _screen->showMouse();
+}
+
+void KyraEngine_MR::hideInventory() {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::hideInventory()");
+ if (queryGameFlag(3))
+ return;
+
+ _inventoryState = false;
+ updateCLState();
+ initMainButtonList(true);
+
+ _screen->copyBlockToPage(3, 0, 0, 320, 56, _interface);
+ _screen->hideMouse();
+
+ restorePage3();
+ flagAnimObjsForRefresh();
+ drawAnimObjects();
+ _screen->copyRegion(0, 144, 0, 0, 320, 56, 0, 2, Screen::CR_NO_P_CHECK);
+
+ if (_inventoryScrollSpeed == -1) {
+ uint32 endTime = _system->getMillis() + _tickLength * 15;
+ int times = 0;
+ while (_system->getMillis() < endTime) {
+ _screen->copyRegion(0, 144, 0, 0, 320, 12, 0, 2, Screen::CR_NO_P_CHECK);
+ _screen->copyRegion(0, 144, 0, 0, 320, 12, 0, 2, Screen::CR_NO_P_CHECK);
+ ++times;
+ }
+
+ times = MAX(times, 1);
+
+ int speed = 60 / times;
+ if (speed <= 1)
+ _inventoryScrollSpeed = 1;
+ else if (speed >= 8)
+ _inventoryScrollSpeed = 8;
+ else
+ _inventoryScrollSpeed = speed;
+ }
+
+ int y = 144;
+ int y2 = 144 + _inventoryScrollSpeed;
+ uint32 waitTill = _system->getMillis() + _tickLength;
+ int times = 0;
+
+ while (y2 < 188) {
+ _screen->copyRegion(0, 0, 0, y2, 320, 56, 2, 0, Screen::CR_NO_P_CHECK);
+ _screen->copyRegion(0, y, 0, y, 320, _inventoryScrollSpeed, 2, 0, Screen::CR_NO_P_CHECK);
+ _screen->updateScreen();
+
+ ++times;
+ if (_inventoryScrollSpeed == 1 && times == 3) {
+ while (waitTill > _system->getMillis())
+ _system->delayMillis(10);
+ times = 0;
+ waitTill = _system->getMillis() + _tickLength;
+ }
+
+ y += _inventoryScrollSpeed;
+ y2 += _inventoryScrollSpeed;
+ }
+
+ _screen->copyRegion(0, 0, 0, 188, 320, 56, 2, 0, Screen::CR_NO_P_CHECK);
+ _screen->copyRegion(0, y, 0, y, 320, 188-y, 2, 0, Screen::CR_NO_P_CHECK);
+ _screen->showMouse();
+}
+
+void KyraEngine_MR::drawMalcolmsMoodText() {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::drawMalcolmsMoodText()");
+ static const int stringId[] = { 0x32, 0x37, 0x3C };
+
+ if (queryGameFlag(0x219))
+ return;
+
+ const char *string = (const char*)getTableEntry(_cCodeFile, stringId[_malcolmsMood]);
+
+ Screen::FontId oldFont = _screen->setFont(Screen::FID_8_FNT);
+ _screen->_charWidth = -2;
+
+ int width = _screen->getTextWidth(string);
+
+ _screen->_charWidth = 0;
+ _screen->setFont(oldFont);
+
+ int pageBackUp = _screen->_curPage;
+ const int x = 280 - (width / 2);
+ int y = 0;
+ if (_inventoryState) {
+ y = 189;
+ _screen->_curPage = 0;
+ } else {
+ y = 45;
+ _screen->_curPage = 2;
+ }
+
+ _screen->hideMouse();
+ _screen->drawShape(_screen->_curPage, getShapePtr(432), 244, 189, 0, 0);
+ _text->printText(string, x, y+1, 0xFF, 0xF0, 0x00);
+ _screen->showMouse();
+ _screen->_curPage = pageBackUp;
+}
+
+void KyraEngine_MR::drawMalcolmsMoodPointer(int frame, int page) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::drawMalcolmsMoodPointer(%d, %d)", frame, page);
+ static const uint8 stateTable[] = {
+ 1, 6, 11
+ };
+
+ if (frame == -1)
+ frame = stateTable[_malcolmsMood];
+ if (queryGameFlag(0x219))
+ frame = 13;
+
+ if (page == 0) {
+ _invWsa->setX(0);
+ _invWsa->setY(0);
+ _invWsa->setDrawPage(0);
+ _invWsa->displayFrame(frame, 0);
+ _screen->updateScreen();
+ } else if (page == 30) {
+ _invWsa->setX(0);
+ _invWsa->setY(-144);
+ _invWsa->setDrawPage(2);
+ _invWsa->displayFrame(frame, 0);
+ }
+
+ _invWsaFrame = frame;
+}
+
+void KyraEngine_MR::drawJestersStaff(int type, int page) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::drawJestersStaff(%d, %d)", type, page);
+ int y = 155;
+ if (page == 30) {
+ page = 2;
+ y -= 144;
+ }
+
+ int shape = (type != 0) ? 454 : 453;
+ _screen->drawShape(page, getShapePtr(shape), 217, y, 0, 0);
+}
+
+void KyraEngine_MR::drawScore(int page, int x, int y) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::drawScore(%d, %d, %d)", page, x, y);
+ if (page == 30) {
+ page = 2;
+ y -= 144;
+ }
+
+ int shape1 = _score / 100;
+ int shape2 = (_score - shape1*100) / 10;
+ int shape3 = _score % 10;
+
+ _screen->drawShape(page, getShapePtr(shape1+433), x, y, 0, 0);
+ x += 8;
+ _screen->drawShape(page, getShapePtr(shape2+433), x, y, 0, 0);
+ x += 8;
+ _screen->drawShape(page, getShapePtr(shape3+433), x, y, 0, 0);
+}
+
+void KyraEngine_MR::drawScoreCounting(int oldScore, int newScore, int drawOld, const int x) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::drawScoreCounting(%d, %d, %d, %d)", oldScore, newScore, drawOld, x);
+ int y = 189;
+ if (_inventoryState)
+ y -= 44;
+
+ int old100 = oldScore / 100;
+ int old010 = (oldScore - old100*100) / 10;
+ int old001 = oldScore % 10;
+
+ int new100 = newScore / 100;
+ int new010 = (newScore - new100*100) / 10;
+ int new001 = newScore % 10;
+
+ if (drawOld) {
+ _screen->drawShape(0, getShapePtr(old100+433), x + 0, y, 0, 0);
+ _screen->drawShape(0, getShapePtr(old010+433), x + 8, y, 0, 0);
+ _screen->drawShape(0, getShapePtr(old001+433), x + 16, y, 0, 0);
+ }
+
+ if (old100 != new100)
+ _screen->drawShape(0, getShapePtr(old100+443), x + 0, y, 0, 0);
+
+ if (old010 != new010)
+ _screen->drawShape(0, getShapePtr(old010+443), x + 8, y, 0, 0);
+
+ _screen->drawShape(0, getShapePtr(old001+443), x + 16, y, 0, 0);
+
+ _screen->updateScreen();
+
+ _screen->drawShape(0, getShapePtr(new100+433), x + 0, y, 0, 0);
+ _screen->drawShape(0, getShapePtr(new010+433), x + 8, y, 0, 0);
+ _screen->drawShape(0, getShapePtr(new001+433), x + 16, y, 0, 0);
+}
+
+int KyraEngine_MR::getScoreX(const char *str) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::getScoreX('%s')", str);
+ Screen::FontId oldFont = _screen->setFont(Screen::FID_8_FNT);
+ _screen->_charWidth = -2;
+
+ int width = _screen->getTextWidth(str);
+ int x = 160 + (width / 2) - 32;
+
+ _screen->setFont(oldFont);
+ _screen->_charWidth = 0;
+ return x;
+}
+
+void KyraEngine_MR::redrawInventory(int page) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::redrawInventory(%d)", page);
+ int yOffset = 0;
+
+ if (page == 30) {
+ page = 2;
+ yOffset = -144;
+ }
+
+ int pageBackUp = _screen->_curPage;
+ _screen->_curPage = page;
+ _screen->hideMouse();
+
+ for (int i = 0; i < 10; ++i) {
+ clearInventorySlot(i, page);
+ if (_mainCharacter.inventory[i] != 0xFFFF) {
+ _screen->drawShape(page, getShapePtr(_mainCharacter.inventory[i]+248), _inventoryX[i], _inventoryY[i] + yOffset, 0, 0);
+ drawInventorySlot(page, _mainCharacter.inventory[i], i);
+ }
+ }
+
+ _screen->showMouse();
+ _screen->_curPage = pageBackUp;
+
+ if (page == 0 || page == 1)
+ _screen->updateScreen();
+}
+
+void KyraEngine_MR::clearInventorySlot(int slot, int page) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::clearInventorySlot(%d, %d)", slot, page);
+ int yOffset = 0;
+ if (page == 30) {
+ page = 2;
+ yOffset = -144;
+ }
+
+ _screen->drawShape(page, getShapePtr(slot+422), _inventoryX[slot], _inventoryY[slot] + yOffset, 0, 0);
+}
+
+void KyraEngine_MR::drawInventorySlot(int page, int item, int slot) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::drawInventorySlot(%d, %d, %d)", page, item, slot);
+ int yOffset = 0;
+ if (page == 30) {
+ page = 2;
+ yOffset = -144;
+ }
+
+ _screen->drawShape(page, getShapePtr(item+248), _inventoryX[slot], _inventoryY[slot] + yOffset, 0, 0);
+}
+
+int KyraEngine_MR::buttonInventory(Button *button) {
+ debugC(9, kDebugLevelMain, "KyraEngine_MR::buttonInventory(%p)", (const void*)button);
+ setNextIdleAnimTimer();
+ if (!_enableInventory || !_inventoryState || !_screen->isMouseVisible())
+ return 0;
+
+ const int slot = button->index - 5;
+ const int16 slotItem = (int16)_mainCharacter.inventory[slot];
+ if (_itemInHand == -1) {
+ if (slotItem == -1)
+ return 0;
+
+ _screen->hideMouse();
+ clearInventorySlot(slot, 0);
+ snd_playSoundEffect(0x0B, 0xC8);
+ setMouseCursor(slotItem);
+ updateItemCommand(slotItem, (_lang == 1) ? getItemCommandStringPickUp(slotItem) : 0, 0xFF);
+ _itemInHand = slotItem;
+ _mainCharacter.inventory[slot] = 0xFFFF;
+ _screen->showMouse();
+ } else if (_itemInHand == 27) {
+ if (_chatText)
+ return 0;
+ return buttonJesterStaff(&_mainButtonData[3]);
+ } else {
+ if (slotItem >= 0) {
+ if (itemInventoryMagic(_itemInHand, slot))
+ return 0;
+
+ snd_playSoundEffect(0x0B, 0xC8);
+
+ _screen->hideMouse();
+ clearInventorySlot(slot, 0);
+ drawInventorySlot(0, _itemInHand, slot);
+ setMouseCursor(slotItem);
+ updateItemCommand(slotItem, (_lang == 1) ? getItemCommandStringPickUp(slotItem) : 0, 0xFF);
+ _mainCharacter.inventory[slot] = _itemInHand;
+ _itemInHand = slotItem;
+ _screen->showMouse();
+ } else {
+ snd_playSoundEffect(0x0C, 0xC8);
+ _screen->hideMouse();
+ drawInventorySlot(0, _itemInHand, slot);
+ _screen->setMouseCursor(0, 0, getShapePtr(0));
+ updateItemCommand(_itemInHand, (_lang == 1) ? getItemCommandStringInv(_itemInHand) : 2, 0xFF);
+ _screen->showMouse();
+ _mainCharacter.inventory[slot] = _itemInHand;
+ _itemInHand = -1;
+ }
+ }
+
+ return 0;
+}
+
+int KyraEngine_MR::buttonMoodChange(Button *button) {
+ if (queryGameFlag(0x219)) {
+ snd_playSoundEffect(0x0D, 0xC8);
+ return 0;
+ }
+
+ static const uint8 frameTable[] = { 1, 6, 11 };
+
+ if (_mouseX >= 245 && _mouseX <= 267 && _mouseY >= 159 && _mouseY <= 198)
+ _malcolmsMood = 0;
+ else if (_mouseX >= 268 && _mouseX <= 289 && _mouseY >= 159 && _mouseY <= 198)
+ _malcolmsMood = 1;
+ else if (_mouseX >= 290 && _mouseX <= 312 && _mouseY >= 159 && _mouseY <= 198)
+ _malcolmsMood = 2;
+
+ int direction = (_invWsaFrame > frameTable[_malcolmsMood]) ? -1 : 1;
+
+ if (_invWsaFrame != frameTable[_malcolmsMood]) {
+ _screen->hideMouse();
+ setGameFlag(3);
+
+ snd_playSoundEffect(0x2E, 0xC8);
+
+ while (_invWsaFrame != frameTable[_malcolmsMood]) {
+ uint32 endTime = _system->getMillis() + 2 * _tickLength;
+ _invWsaFrame += direction;
+
+ drawMalcolmsMoodPointer(_invWsaFrame, 0);
+ _screen->updateScreen();
+
+ while (endTime > _system->getMillis()) {
+ update();
+ _system->delayMillis(10);
+ }
+ }
+
+ resetGameFlag(3);
+ _screen->showMouse();
+
+ drawMalcolmsMoodText();
+ updateDlgIndex();
+
+ EMCData data;
+ EMCState state;
+ memset(&data, 0, sizeof(data));
+ memset(&state, 0, sizeof(state));
+
+ _res->exists("_ACTOR.EMC", true);
+ _emc->load("_ACTOR.EMC", &data, &_opcodes);
+ _emc->init(&state, &data);
+ _emc->start(&state, 1);
+
+ int vocHigh = _vocHigh;
+ _vocHigh = 200;
+ _useActorBuffer = true;
+
+ while (_emc->isValid(&state))
+ _emc->run(&state);
+
+ _useActorBuffer = false;
+ _vocHigh = vocHigh;
+ _emc->unload(&data);
+ }
+
+ return 0;
+}
+
+int KyraEngine_MR::buttonShowScore(Button *button) {
+ strcpy(_stringBuffer, (const char*)getTableEntry(_cCodeFile, 18));
+
+ char *buffer = _stringBuffer;
+
+ while (*buffer != '%')
+ ++buffer;
+
+ buffer[0] = (_score / 100) + '0';
+ buffer[1] = ((_score % 100) / 10) + '0';
+ buffer[2] = (_score % 10) + '0';
+
+ while (*buffer != '%')
+ ++buffer;
+
+ buffer[0] = (_scoreMax / 100) + '0';
+ buffer[1] = ((_scoreMax % 100) / 10) + '0';
+ buffer[2] = (_scoreMax % 10) + '0';
+
+ showMessage(_stringBuffer, 0xFF, 0xF0);
+ return 0;
+}
+
+int KyraEngine_MR::buttonJesterStaff(Button *button) {
+ makeCharFacingMouse();
+ if (_itemInHand == 27) {
+ _screen->hideMouse();
+ removeHandItem();
+ snd_playSoundEffect(0x0C, 0xC8);
+ drawJestersStaff(1, 0);
+ updateItemCommand(27, 2, 0xFF);
+ setGameFlag(0x97);
+ _screen->showMouse();
+ } else if (_itemInHand == -1) {
+ if (queryGameFlag(0x97)) {
+ _screen->hideMouse();
+ snd_playSoundEffect(0x0B, 0xC8);
+ setHandItem(27);
+ drawJestersStaff(0, 0);
+ updateItemCommand(27, 0, 0xFF);
+ resetGameFlag(0x97);
+ _screen->showMouse();
+ } else {
+ if (queryGameFlag(0x2F))
+ objectChat((const char*)getTableEntry(_cCodeFile, 20), 0, 204, 20);
+ else
+ objectChat((const char*)getTableEntry(_cCodeFile, 25), 0, 204, 25);
+ }
+ } else {
+ objectChat((const char*)getTableEntry(_cCodeFile, 30), 0, 204, 30);
+ }
+ return 0;
+}
+
+#pragma mark -
+
+GUI_MR::GUI_MR(KyraEngine_MR *vm) : GUI(vm), _vm(vm), _screen(vm->_screen) {
+ _backUpButtonList = _unknownButtonList = 0;
+ _buttonListChanged = false;
+}
+
+Button *GUI_MR::addButtonToList(Button *list, Button *newButton) {
+ list = GUI::addButtonToList(list, newButton);
+ _buttonListChanged = true;
+ return list;
+}
+
+void GUI_MR::processButton(Button *button) {
+ if (!button)
+ return;
+
+ if (button->flags & 8) {
+ if (button->flags & 0x10) {
+ // XXX
+ }
+ return;
+ }
+
+ int entry = button->flags2 & 5;
+
+ byte val1 = 0, val2 = 0, val3 = 0;
+ const uint8 *dataPtr = 0;
+ Button::Callback callback;
+ if (entry == 1) {
+ val1 = button->data1Val1;
+ dataPtr = button->data1ShapePtr;
+ callback = button->data1Callback;
+ val2 = button->data1Val2;
+ val3 = button->data1Val3;
+ } else if (entry == 4 || entry == 5) {
+ val1 = button->data2Val1;
+ dataPtr = button->data2ShapePtr;
+ callback = button->data2Callback;
+ val2 = button->data2Val2;
+ val3 = button->data2Val3;
+ } else {
+ val1 = button->data0Val1;
+ dataPtr = button->data0ShapePtr;
+ callback = button->data0Callback;
+ val2 = button->data0Val2;
+ val3 = button->data0Val3;
+ }
+
+ int x = 0, y = 0, x2 = 0, y2 = 0;
+
+ x = button->x;
+ if (x < 0)
+ x += _screen->getScreenDim(button->dimTableIndex)->w << 3;
+ x += _screen->getScreenDim(button->dimTableIndex)->sx << 3;
+ x2 = x + button->width - 1;
+
+ y = button->y;
+ if (y < 0)
+ y += _screen->getScreenDim(button->dimTableIndex)->h << 3;
+ y += _screen->getScreenDim(button->dimTableIndex)->sy << 3;
+ y2 = y + button->height - 1;
+
+ switch (val1 - 1) {
+ case 0:
+ _screen->hideMouse();
+ _screen->drawShape(_screen->_curPage, dataPtr, x, y, button->dimTableIndex, 0x10);
+ _screen->showMouse();
+ break;
+
+ case 1:
+ _screen->hideMouse();
+ _screen->printText((const char*)dataPtr, x, y, val2, val3);
+ _screen->showMouse();
+ break;
+
+ case 3:
+ if (callback)
+ (*callback)(button);
+ break;
+
+ case 4:
+ _screen->hideMouse();
+ _screen->drawBox(x, y, x2, y2, val2);
+ _screen->showMouse();
+ break;
+
+ case 5:
+ _screen->hideMouse();
+ _screen->fillRect(x, y, x2, y2, val2, -1, true);
+ _screen->showMouse();
+ break;
+
+ default:
+ break;
+ }
+
+ _screen->updateScreen();
+}
+
+int GUI_MR::processButtonList(Button *buttonList, uint16 inputFlag) {
+ static uint16 flagsModifier = 0;
+
+ if (!buttonList)
+ return inputFlag & 0x7FFF;
+
+ if (_backUpButtonList != buttonList || _buttonListChanged) {
+ _unknownButtonList = 0;
+ //flagsModifier |= 0x2200;
+ _backUpButtonList = buttonList;
+ _buttonListChanged = false;
+
+ while (buttonList) {
+ processButton(buttonList);
+ buttonList = buttonList->nextButton;
+ }
+ }
+
+ int mouseX = _vm->_mouseX;
+ int mouseY = _vm->_mouseY;
+
+ uint16 flags = 0;
+
+ if (1/*!_screen_cursorDisable*/) {
+ uint16 inFlags = inputFlag & 0xFF;
+ uint16 temp = 0;
+
+ // HACK: inFlags == 200 is our left button (up)
+ if (inFlags == 199 || inFlags == 200)
+ temp = 0x1000;
+ if (inFlags == 198)
+ temp = 0x100;
+
+ if (inputFlag & 0x800)
+ temp <<= 2;
+
+ flags |= temp;
+
+ flagsModifier &= ~((temp & 0x4400) >> 1);
+ flagsModifier |= (temp & 0x1100) * 2;
+ flags |= flagsModifier;
+ flags |= (flagsModifier << 2) ^ 0x8800;
+ }
+
+ buttonList = _backUpButtonList;
+ if (_unknownButtonList) {
+ buttonList = _unknownButtonList;
+ if (_unknownButtonList->flags & 8)
+ _unknownButtonList = 0;
+ }
+
+ int returnValue = 0;
+ while (buttonList) {
+ if (buttonList->flags & 8) {
+ buttonList = buttonList->nextButton;
+ continue;
+ }
+ buttonList->flags2 &= ~0x18;
+ buttonList->flags2 |= (buttonList->flags2 & 3) << 3;
+
+ int x = buttonList->x;
+ if (x < 0)
+ x += _screen->getScreenDim(buttonList->dimTableIndex)->w << 3;
+ x += _screen->getScreenDim(buttonList->dimTableIndex)->sx << 3;
+
+ int y = buttonList->y;
+ if (y < 0)
+ y += _screen->getScreenDim(buttonList->dimTableIndex)->h;
+ y += _screen->getScreenDim(buttonList->dimTableIndex)->sy;
+
+ bool progress = false;
+
+ if (mouseX >= x && mouseY >= y && mouseX <= x+buttonList->width && mouseY <= y+buttonList->height)
+ progress = true;
+
+ buttonList->flags2 &= ~0x80;
+ uint16 inFlags = inputFlag & 0x7FFF;
+ if (inFlags) {
+ if (buttonList->unk6 == inFlags) {
+ progress = true;
+ flags = buttonList->flags & 0x0F00;
+ buttonList->flags2 |= 0x80;
+ inputFlag = 0;
+ _unknownButtonList = buttonList;
+ } else if (buttonList->unk8 == inFlags) {
+ flags = buttonList->flags & 0xF000;
+ if (!flags)
+ flags = buttonList->flags & 0x0F00;
+ progress = true;
+ buttonList->flags2 |= 0x80;
+ inputFlag = 0;
+ _unknownButtonList = buttonList;
+ }
+ }
+
+ bool unk1 = false;
+ if (!progress)
+ buttonList->flags2 &= ~6;
+
+ if ((flags & 0x3300) && (buttonList->flags & 4) && progress && (buttonList == _unknownButtonList || !_unknownButtonList)) {
+ buttonList->flags |= 6;
+ if (!_unknownButtonList)
+ _unknownButtonList = buttonList;
+ } else if ((flags & 0x8800) && !(buttonList->flags & 4) && progress) {
+ buttonList->flags2 |= 6;
+ } else {
+ buttonList->flags2 &= ~6;
+ }
+
+ bool progressSwitch = false;
+ if (!_unknownButtonList) {
+ progressSwitch = progress;
+ } else {
+ if (_unknownButtonList->flags & 0x40)
+ progressSwitch = (_unknownButtonList == buttonList);
+ else
+ progressSwitch = progress;
+ }
+
+ if (progressSwitch) {
+ if ((flags & 0x1100) && progress && !_unknownButtonList) {
+ inputFlag = 0;
+ _unknownButtonList = buttonList;
+ }
+
+ if ((buttonList->flags & flags) && (progress || !(buttonList->flags & 1))) {
+ uint16 combinedFlags = (buttonList->flags & flags);
+ combinedFlags = ((combinedFlags & 0xF000) >> 4) | (combinedFlags & 0x0F00);
+ combinedFlags >>= 8;
+
+ static const uint16 flagTable[] = {
+ 0x000, 0x100, 0x200, 0x100, 0x400, 0x100, 0x400, 0x100, 0x800, 0x100,
+ 0x200, 0x100, 0x400, 0x100, 0x400, 0x100
+ };
+
+ assert(combinedFlags < ARRAYSIZE(flagTable));
+
+ switch (flagTable[combinedFlags]) {
+ case 0x400:
+ if (!(buttonList->flags & 1) || ((buttonList->flags & 1) && _unknownButtonList == buttonList)) {
+ buttonList->flags2 ^= 1;
+ returnValue = buttonList->index | 0x8000;
+ unk1 = true;
+ }
+
+ if (!(buttonList->flags & 4)) {
+ buttonList->flags2 &= ~4;
+ buttonList->flags2 &= ~2;
+ }
+ break;
+
+ case 0x800:
+ if (!(buttonList->flags & 4)) {
+ buttonList->flags2 |= 4;
+ buttonList->flags2 |= 2;
+ }
+
+ if (!(buttonList->flags & 1))
+ unk1 = true;
+ break;
+
+ case 0x200:
+ if (buttonList->flags & 4) {
+ buttonList->flags2 |= 4;
+ buttonList->flags2 |= 2;
+ }
+
+ if (!(buttonList->flags & 1))
+ unk1 = true;
+ break;
+
+ case 0x100:
+ default:
+ buttonList->flags2 ^= 1;
+ returnValue = buttonList->index | 0x8000;
+ unk1 = true;
+ if (buttonList->flags & 4) {
+ buttonList->flags2 |= 4;
+ buttonList->flags2 |= 2;
+ }
+ _unknownButtonList = buttonList;
+ break;
+ }
+ }
+ }
+
+ bool unk2 = false;
+ if ((flags & 0x2200) && progress) {
+ buttonList->flags2 |= 6;
+ if (!(buttonList->flags & 4) && !(buttonList->flags2 & 1)) {
+ unk2 = true;
+ buttonList->flags2 |= 1;
+ }
+ }
+
+ if ((flags & 0x8800) == 0x8800) {
+ _unknownButtonList = 0;
+ if (!progress || (buttonList->flags & 4))
+ buttonList->flags2 &= ~6;
+ }
+
+ if (!progress && buttonList == _unknownButtonList && !(buttonList->flags & 0x40))
+ _unknownButtonList = 0;
+
+ if ((buttonList->flags2 & 0x18) != ((buttonList->flags2 & 3) << 3))
+ processButton(buttonList);
+
+ if (unk2)
+ buttonList->flags2 &= ~1;
+
+ if (unk1) {
+ buttonList->flags2 &= 0xFF;
+ buttonList->flags2 |= flags;
+
+ if (buttonList->buttonCallback) {
+ _vm->removeInputTop();
+ if ((*buttonList->buttonCallback.get())(buttonList))
+ break;
+ }
+
+ if (buttonList->flags & 0x20)
+ break;
+ }
+
+ if (_unknownButtonList == buttonList && (buttonList->flags & 0x40))
+ break;
+
+ buttonList = buttonList->nextButton;
+ }
+
+ if (!returnValue)
+ returnValue = inputFlag & 0x7FFF;
+ return returnValue;
+}
+
+void GUI_MR::flagButtonEnable(Button *button) {
+ if (!button)
+ return;
+
+ if (button->flags & 8) {
+ button->flags &= ~8;
+ processButton(button);
+ }
+}
+
+void GUI_MR::flagButtonDisable(Button *button) {
+ if (!button)
+ return;
+
+ if (!(button->flags & 8)) {
+ button->flags |= 8;
+ processButton(button);
+ }
+}
+
+} // end of namespace Kyra
+
Copied: scummvm/trunk/engines/kyra/gui_mr.h (from rev 31865, scummvm/trunk/engines/kyra/gui_v3.h)
===================================================================
--- scummvm/trunk/engines/kyra/gui_mr.h (rev 0)
+++ scummvm/trunk/engines/kyra/gui_mr.h 2008-05-04 15:18:46 UTC (rev 31866)
@@ -0,0 +1,98 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef KYRA_GUI_V3_H
+#define KYRA_GUI_V3_H
+
+#include "kyra/gui.h"
+
+namespace Kyra {
+
+#define GUI_V3_BUTTON(button, a, b, c, d, e, f, h, i, j, k, l, m, n, o, p, q, r, s, t) \
+ button.nextButton = 0; \
+ button.index = a; \
+ button.unk6 = b; \
+ button.unk8 = c; \
+ button.data0Val1 = d; \
+ button.data1Val1 = e; \
+ button.data2Val1 = f; \
+ button.flags = h; \
+ button.data0ShapePtr = button.data1ShapePtr = button.data2ShapePtr = 0; \
+ button.dimTableIndex = i; \
+ button.x = j; \
+ button.y = k; \
+ button.width = l; \
+ button.height = m; \
+ button.data0Val2 = n; \
+ button.data0Val3 = o; \
+ button.data1Val2 = p; \
+ button.data1Val3 = q; \
+ button.data2Val2 = r; \
+ button.data2Val3 = s; \
+ button.flags2 = t;
+
+class KyraEngine_MR;
+class Screen_MR;
+
+class GUI_MR : public GUI {
+friend class KyraEngine_MR;
+public:
+ GUI_MR(KyraEngine_MR *engine);
+
+ Button *addButtonToList(Button *list, Button *newButton);
+
+ void processButton(Button *button);
+ int processButtonList(Button *button, uint16 inputFlag);
+
+ void flagButtonEnable(Button *button);
+ void flagButtonDisable(Button *button);
+private:
+ const char *getMenuTitle(const Menu &menu) { return 0; }
+ const char *getMenuItemTitle(const MenuItem &menuItem) { return 0; }
+ const char *getMenuItemLabel(const MenuItem &menuItem) { return 0; }
+
+ Button *getButtonListData() { return 0; }
+
+ Button *getScrollUpButton() { return 0; }
+ Button *getScrollDownButton() { return 0; }
+
+ Button::Callback getScrollUpButtonHandler() const { return Button::Callback(); }
+ Button::Callback getScrollDownButtonHandler() const { return Button::Callback(); }
+
+ uint8 defaultColor1() const { return 0xCF; }
+ uint8 defaultColor2() const { return 0xF8; }
+
+ KyraEngine_MR *_vm;
+ Screen_MR *_screen;
+
+ bool _buttonListChanged;
+ Button *_backUpButtonList;
+ Button *_unknownButtonList;
+};
+
+} // end of namespace Kyra
+
+#endif
+
Deleted: scummvm/trunk/engines/kyra/gui_v2.cpp
===================================================================
--- scummvm/trunk/engines/kyra/gui_v2.cpp 2008-05-04 15:09:23 UTC (rev 31865)
+++ scummvm/trunk/engines/kyra/gui_v2.cpp 2008-05-04 15:18:46 UTC (rev 31866)
@@ -1,2009 +0,0 @@
-/* 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.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include "kyra/kyra.h"
-#include "kyra/kyra_hof.h"
-#include "kyra/screen.h"
-#include "kyra/wsamovie.h"
-#include "kyra/timer.h"
-#include "kyra/sound.h"
-#include "kyra/resource.h"
-
-#include "common/savefile.h"
-
-namespace Kyra {
-
-void KyraEngine_HoF::loadButtonShapes() {
- const uint8 *src = _screen->getCPagePtr(3);
- _screen->loadBitmap("_BUTTONS.CSH", 3, 3, 0);
-
- _gui->_scrollUpButton.data0ShapePtr = _buttonShapes[0] = _screen->makeShapeCopy(src, 0);
- _gui->_scrollUpButton.data2ShapePtr = _buttonShapes[1] = _screen->makeShapeCopy(src, 1);
- _gui->_scrollUpButton.data1ShapePtr = _buttonShapes[2] = _screen->makeShapeCopy(src, 2);
- _gui->_scrollDownButton.data0ShapePtr = _buttonShapes[3] = _screen->makeShapeCopy(src, 3);
- _gui->_scrollDownButton.data2ShapePtr = _buttonShapes[4] = _screen->makeShapeCopy(src, 4);
- _gui->_scrollDownButton.data1ShapePtr = _buttonShapes[5] = _screen->makeShapeCopy(src, 5);
- _buttonShapes[6] = _screen->makeShapeCopy(src, 6);
- _buttonShapes[7] = _screen->makeShapeCopy(src, 7);
- _buttonShapes[8] = _screen->makeShapeCopy(src, 6);
- _buttonShapes[9] = _screen->makeShapeCopy(src, 7);
- _buttonShapes[10] = _screen->makeShapeCopy(src, 10);
- _buttonShapes[11] = _screen->makeShapeCopy(src, 11);
- _buttonShapes[16] = _screen->makeShapeCopy(src, 16);
- _buttonShapes[17] = _screen->makeShapeCopy(src, 17);
- _buttonShapes[18] = _screen->makeShapeCopy(src, 18);
-}
-
-void KyraEngine_HoF::setupLangButtonShapes() {
- switch (_lang) {
- case 0:
- _inventoryButtons[0].data0ShapePtr = _buttonShapes[6];
- _inventoryButtons[0].data1ShapePtr = _inventoryButtons[0].data2ShapePtr = _buttonShapes[7];
- break;
-
- case 1:
- _inventoryButtons[0].data0ShapePtr = _buttonShapes[8];
- _inventoryButtons[0].data1ShapePtr = _inventoryButtons[0].data2ShapePtr = _buttonShapes[9];
- break;
-
- case 2:
- _inventoryButtons[0].data0ShapePtr = _buttonShapes[10];
- _inventoryButtons[0].data1ShapePtr = _inventoryButtons[0].data2ShapePtr = _buttonShapes[11];
- break;
-
- default:
- _inventoryButtons[0].data0ShapePtr = _buttonShapes[6];
- _inventoryButtons[0].data1ShapePtr = _inventoryButtons[0].data2ShapePtr = _buttonShapes[7];
- break;
- }
-}
-
-GUI_v2::GUI_v2(KyraEngine_HoF *vm) : GUI(vm), _vm(vm), _screen(vm->screen_v2()) {
- _backUpButtonList = _unknownButtonList = 0;
- initStaticData();
- _currentMenu = 0;
- _isDeathMenu = false;
- _isSaveMenu = false;
- _isLoadMenu = false;
- _scrollUpFunctor = BUTTON_FUNCTOR(GUI_v2, this, &GUI_v2::scrollUpButton);
- _scrollDownFunctor = BUTTON_FUNCTOR(GUI_v2, this, &GUI_v2::scrollDownButton);
- _sliderHandlerFunctor = BUTTON_FUNCTOR(GUI_v2, this, &GUI_v2::sliderHandler);
-}
-
-Button *GUI_v2::addButtonToList(Button *list, Button *newButton) {
- list = GUI::addButtonToList(list, newButton);
- _buttonListChanged = true;
- return list;
-}
-
-void GUI_v2::processButton(Button *button) {
- if (!button)
- return;
-
- if (button->flags & 8) {
- if (button->flags & 0x10) {
- // XXX
- }
- return;
- }
-
- int entry = button->flags2 & 5;
-
- byte val1 = 0, val2 = 0, val3 = 0;
- const uint8 *dataPtr = 0;
- Button::Callback callback;
- if (entry == 1) {
- val1 = button->data1Val1;
- dataPtr = button->data1ShapePtr;
- callback = button->data1Callback;
- val2 = button->data1Val2;
- val3 = button->data1Val3;
- } else if (entry == 4 || entry == 5) {
- val1 = button->data2Val1;
- dataPtr = button->data2ShapePtr;
- callback = button->data2Callback;
- val2 = button->data2Val2;
- val3 = button->data2Val3;
- } else {
- val1 = button->data0Val1;
- dataPtr = button->data0ShapePtr;
- callback = button->data0Callback;
- val2 = button->data0Val2;
- val3 = button->data0Val3;
- }
-
- int x = 0, y = 0, x2 = 0, y2 = 0;
-
- x = button->x;
- if (x < 0)
- x += _screen->getScreenDim(button->dimTableIndex)->w << 3;
- x += _screen->getScreenDim(button->dimTableIndex)->sx << 3;
- x2 = x + button->width - 1;
-
- y = button->y;
- if (y < 0)
- y += _screen->getScreenDim(button->dimTableIndex)->h << 3;
- y += _screen->getScreenDim(button->dimTableIndex)->sy << 3;
- y2 = y + button->height - 1;
-
- switch (val1 - 1) {
- case 0:
- _screen->hideMouse();
- _screen->drawShape(_screen->_curPage, dataPtr, x, y, button->dimTableIndex, 0x10);
- _screen->showMouse();
- break;
-
- case 1:
- _screen->hideMouse();
- _screen->printText((const char*)dataPtr, x, y, val2, val3);
- _screen->showMouse();
- break;
-
- case 3:
- if (callback)
- (*callback)(button);
- break;
-
- case 4:
- _screen->hideMouse();
- _screen->drawBox(x, y, x2, y2, val2);
- _screen->showMouse();
- break;
-
- case 5:
- _screen->hideMouse();
- _screen->fillRect(x, y, x2, y2, val2, -1, true);
- _screen->showMouse();
- break;
-
- default:
- break;
- }
-
- _screen->updateScreen();
-}
-
-int GUI_v2::processButtonList(Button *buttonList, uint16 inputFlag) {
- static uint16 flagsModifier = 0;
-
- if (!buttonList)
- return inputFlag & 0x7FFF;
-
- if (_backUpButtonList != buttonList || _buttonListChanged) {
- _unknownButtonList = 0;
- //flagsModifier |= 0x2200;
- _backUpButtonList = buttonList;
- _buttonListChanged = false;
-
- while (buttonList) {
- processButton(buttonList);
- buttonList = buttonList->nextButton;
- }
- }
-
- int mouseX = _vm->_mouseX;
- int mouseY = _vm->_mouseY;
-
- uint16 flags = 0;
-
- if (1/*!_screen_cursorDisable*/) {
- uint16 inFlags = inputFlag & 0xFF;
- uint16 temp = 0;
-
- // HACK: inFlags == 200 is our left button (up)
- if (inFlags == 199 || inFlags == 200)
- temp = 0x1000;
- if (inFlags == 198)
- temp = 0x100;
-
- if (inputFlag & 0x800)
- temp <<= 2;
-
- flags |= temp;
-
- flagsModifier &= ~((temp & 0x4400) >> 1);
- flagsModifier |= (temp & 0x1100) * 2;
- flags |= flagsModifier;
- flags |= (flagsModifier << 2) ^ 0x8800;
- }
-
- buttonList = _backUpButtonList;
- if (_unknownButtonList) {
- buttonList = _unknownButtonList;
- if (_unknownButtonList->flags & 8)
- _unknownButtonList = 0;
- }
-
- int returnValue = 0;
- while (buttonList) {
- if (buttonList->flags & 8) {
- buttonList = buttonList->nextButton;
- continue;
- }
- buttonList->flags2 &= ~0x18;
- buttonList->flags2 |= (buttonList->flags2 & 3) << 3;
-
- int x = buttonList->x;
- if (x < 0)
- x += _screen->getScreenDim(buttonList->dimTableIndex)->w << 3;
- x += _screen->getScreenDim(buttonList->dimTableIndex)->sx << 3;
-
- int y = buttonList->y;
- if (y < 0)
- y += _screen->getScreenDim(buttonList->dimTableIndex)->h;
- y += _screen->getScreenDim(buttonList->dimTableIndex)->sy;
-
- bool progress = false;
-
- if (mouseX >= x && mouseY >= y && mouseX <= x+buttonList->width && mouseY <= y+buttonList->height)
- progress = true;
-
- buttonList->flags2 &= ~0x80;
- uint16 inFlags = inputFlag & 0x7FFF;
- if (inFlags) {
- if (buttonList->unk6 == inFlags) {
- progress = true;
- flags = buttonList->flags & 0x0F00;
- buttonList->flags2 |= 0x80;
- inputFlag = 0;
- _unknownButtonList = buttonList;
- } else if (buttonList->unk8 == inFlags) {
- flags = buttonList->flags & 0xF000;
- if (!flags)
- flags = buttonList->flags & 0x0F00;
- progress = true;
- buttonList->flags2 |= 0x80;
- inputFlag = 0;
- _unknownButtonList = buttonList;
- }
- }
-
- bool unk1 = false;
- if (!progress)
- buttonList->flags2 &= ~6;
-
- if ((flags & 0x3300) && (buttonList->flags & 4) && progress && (buttonList == _unknownButtonList || !_unknownButtonList)) {
- buttonList->flags |= 6;
- if (!_unknownButtonList)
- _unknownButtonList = buttonList;
- } else if ((flags & 0x8800) && !(buttonList->flags & 4) && progress) {
- buttonList->flags2 |= 6;
- } else {
- buttonList->flags2 &= ~6;
- }
-
- bool progressSwitch = false;
- if (!_unknownButtonList) {
- progressSwitch = progress;
- } else {
- if (_unknownButtonList->flags & 0x40)
- progressSwitch = (_unknownButtonList == buttonList);
- else
- progressSwitch = progress;
- }
-
- if (progressSwitch) {
- if ((flags & 0x1100) && progress && !_unknownButtonList) {
- inputFlag = 0;
- _unknownButtonList = buttonList;
- }
-
- if ((buttonList->flags & flags) && (progress || !(buttonList->flags & 1))) {
- uint16 combinedFlags = (buttonList->flags & flags);
- combinedFlags = ((combinedFlags & 0xF000) >> 4) | (combinedFlags & 0x0F00);
- combinedFlags >>= 8;
-
- static const uint16 flagTable[] = {
- 0x000, 0x100, 0x200, 0x100, 0x400, 0x100, 0x400, 0x100, 0x800, 0x100,
- 0x200, 0x100, 0x400, 0x100, 0x400, 0x100
- };
-
- assert(combinedFlags < ARRAYSIZE(flagTable));
-
- switch (flagTable[combinedFlags]) {
- case 0x400:
- if (!(buttonList->flags & 1) || ((buttonList->flags & 1) && _unknownButtonList == buttonList)) {
- buttonList->flags2 ^= 1;
- returnValue = buttonList->index | 0x8000;
- unk1 = true;
- }
-
- if (!(buttonList->flags & 4)) {
- buttonList->flags2 &= ~4;
- buttonList->flags2 &= ~2;
- }
- break;
-
- case 0x800:
- if (!(buttonList->flags & 4)) {
- buttonList->flags2 |= 4;
- buttonList->flags2 |= 2;
- }
-
- if (!(buttonList->flags & 1))
- unk1 = true;
- break;
-
- case 0x200:
- if (buttonList->flags & 4) {
- buttonList->flags2 |= 4;
- buttonList->flags2 |= 2;
- }
-
- if (!(buttonList->flags & 1))
- unk1 = true;
- break;
-
- case 0x100:
- default:
- buttonList->flags2 ^= 1;
- returnValue = buttonList->index | 0x8000;
- unk1 = true;
- if (buttonList->flags & 4) {
- buttonList->flags2 |= 4;
- buttonList->flags2 |= 2;
- }
- _unknownButtonList = buttonList;
- break;
- }
- }
- }
-
- bool unk2 = false;
- if ((flags & 0x2200) && progress) {
- buttonList->flags2 |= 6;
- if (!(buttonList->flags & 4) && !(buttonList->flags2 & 1)) {
- unk2 = true;
- buttonList->flags2 |= 1;
- }
- }
-
- if ((flags & 0x8800) == 0x8800) {
- _unknownButtonList = 0;
- if (!progress || (buttonList->flags & 4))
- buttonList->flags2 &= ~6;
- }
-
- if (!progress && buttonList == _unknownButtonList && !(buttonList->flags & 0x40))
- _unknownButtonList = 0;
-
- if ((buttonList->flags2 & 0x18) != ((buttonList->flags2 & 3) << 3))
- processButton(buttonList);
-
- if (unk2)
- buttonList->flags2 &= ~1;
-
- if (unk1) {
- buttonList->flags2 &= 0xFF;
- buttonList->flags2 |= flags;
-
- if (buttonList->buttonCallback) {
- _vm->removeInputTop();
- if ((*buttonList->buttonCallback.get())(buttonList))
- break;
- }
-
- if (buttonList->flags & 0x20)
- break;
- }
-
- if (_unknownButtonList == buttonList && (buttonList->flags & 0x40))
- break;
-
- buttonList = buttonList->nextButton;
- }
-
- if (!returnValue)
- returnValue = inputFlag & 0x7FFF;
- return returnValue;
-}
-
-const char *GUI_v2::getMenuTitle(const Menu &menu) {
- if (!menu.menuNameId)
- return 0;
-
- return _vm->getTableString(menu.menuNameId, _vm->_optionsBuffer, 1);
-}
-
-const char *GUI_v2::getMenuItemTitle(const MenuItem &menuItem) {
- if (!menuItem.itemId)
- return 0;
-
- return _vm->getTableString(menuItem.itemId, _vm->_optionsBuffer, 1);
-}
-
-const char *GUI_v2::getMenuItemLabel(const MenuItem &menuItem) {
- if (!menuItem.labelId)
- return 0;
-
- return _vm->getTableString(menuItem.labelId, _vm->_optionsBuffer, 1);
-}
-
-#pragma mark -
-
-
-int KyraEngine_HoF::buttonInventory(Button *button) {
- if (!_screen->isMouseVisible())
- return 0;
-
- int inventorySlot = button->index - 6;
-
- uint16 item = _mainCharacter.inventory[inventorySlot];
- if (_itemInHand == -1) {
- if (item == 0xFFFF)
- return 0;
- _screen->hideMouse();
- clearInventorySlot(inventorySlot, 0);
- snd_playSoundEffect(0x0B);
- setMouseCursor(item);
- int string = (_lang == 1) ? getItemCommandStringPickUp(item) : 7;
- updateCommandLineEx(item+54, string, 0xD6);
- _itemInHand = (int16)item;
- _screen->showMouse();
- _mainCharacter.inventory[inventorySlot] = 0xFFFF;
- } else {
- if (_mainCharacter.inventory[inventorySlot] != 0xFFFF) {
- if (checkInventoryItemExchange(_itemInHand, inventorySlot))
- return 0;
-
- item = _mainCharacter.inventory[inventorySlot];
- snd_playSoundEffect(0x0B);
- _screen->hideMouse();
- clearInventorySlot(inventorySlot, 0);
- drawInventoryShape(0, _itemInHand, inventorySlot);
- setMouseCursor(item);
- int string = (_lang == 1) ? getItemCommandStringPickUp(item) : 7;
- updateCommandLineEx(item+54, string, 0xD6);
- _screen->showMouse();
- _mainCharacter.inventory[inventorySlot] = _itemInHand;
- setHandItem(item);
- } else {
- snd_playSoundEffect(0x0C);
- _screen->hideMouse();
- drawInventoryShape(0, _itemInHand, inventorySlot);
- _screen->setMouseCursor(0, 0, getShapePtr(0));
- int string = (_lang == 1) ? getItemCommandStringInv(_itemInHand) : 8;
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list