2014-01-12 19:27:11 +07:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2014-06-14 15:18:24 +07:00
|
|
|
#include "zvision/core/menu.h"
|
2014-01-12 19:27:11 +07:00
|
|
|
|
2014-06-14 15:18:24 +07:00
|
|
|
#include "zvision/graphics/render_manager.h"
|
2014-01-12 19:27:11 +07:00
|
|
|
|
|
|
|
namespace ZVision {
|
|
|
|
|
|
|
|
enum {
|
2014-02-24 20:37:58 +07:00
|
|
|
SLOT_START_SLOT = 151,
|
|
|
|
SLOT_SPELL_1 = 191,
|
|
|
|
SLOT_USER_CHOSE_THIS_SPELL = 205,
|
|
|
|
SLOT_REVERSED_SPELLBOOK = 206
|
2014-01-12 19:27:11 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2014-02-24 20:37:58 +07:00
|
|
|
menu_MAIN_SAVE = 0,
|
|
|
|
menu_MAIN_REST = 1,
|
|
|
|
menu_MAIN_PREF = 2,
|
|
|
|
menu_MAIN_EXIT = 3
|
2014-01-12 19:27:11 +07:00
|
|
|
};
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
MenuHandler::MenuHandler(ZVision *engine) {
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine = engine;
|
2014-11-20 14:48:24 +06:00
|
|
|
menuBarFlag = 0xFFFF;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
MenuZGI::MenuZGI(ZVision *engine) :
|
|
|
|
MenuHandler(engine) {
|
|
|
|
menuMouseFocus = -1;
|
2014-01-12 19:27:11 +07:00
|
|
|
inmenu = false;
|
|
|
|
scrolled[0] = false;
|
|
|
|
scrolled[1] = false;
|
|
|
|
scrolled[2] = false;
|
|
|
|
scrollPos[0] = 0.0;
|
|
|
|
scrollPos[1] = 0.0;
|
|
|
|
scrollPos[2] = 0.0;
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = -1;
|
2014-12-19 15:40:45 +06:00
|
|
|
redraw = false;
|
|
|
|
clean = false;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
|
|
|
char buf[24];
|
|
|
|
for (int i = 1; i < 4; i++) {
|
|
|
|
sprintf(buf, "gmzau%2.2x1.tga", i);
|
|
|
|
_engine->getRenderManager()->readImageToSurface(buf, menuback[i - 1][0], false);
|
|
|
|
sprintf(buf, "gmzau%2.2x1.tga", i + 0x10);
|
|
|
|
_engine->getRenderManager()->readImageToSurface(buf, menuback[i - 1][1], false);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
sprintf(buf, "gmzmu%2.2x1.tga", i);
|
|
|
|
_engine->getRenderManager()->readImageToSurface(buf, menubar[i][0], false);
|
|
|
|
sprintf(buf, "gmznu%2.2x1.tga", i);
|
|
|
|
_engine->getRenderManager()->readImageToSurface(buf, menubar[i][1], false);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
items[i][0] = NULL;
|
|
|
|
items[i][1] = NULL;
|
2014-11-20 14:48:24 +06:00
|
|
|
itemId[i] = 0;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
magic[i][0] = NULL;
|
|
|
|
magic[i][1] = NULL;
|
2014-11-20 14:48:24 +06:00
|
|
|
magicId[i] = 0;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
MenuZGI::~MenuZGI() {
|
2014-01-12 19:27:11 +07:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
menuback[i][0].free();
|
|
|
|
menuback[i][1].free();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
menubar[i][0].free();
|
|
|
|
menubar[i][1].free();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 50; i++) {
|
|
|
|
if (items[i][0]) {
|
|
|
|
items[i][0]->free();
|
|
|
|
delete items[i][0];
|
|
|
|
}
|
|
|
|
if (items[i][1]) {
|
|
|
|
items[i][1]->free();
|
|
|
|
delete items[i][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
if (magic[i][0]) {
|
|
|
|
magic[i][0]->free();
|
|
|
|
delete magic[i][0];
|
|
|
|
}
|
|
|
|
if (magic[i][1]) {
|
|
|
|
magic[i][1]->free();
|
|
|
|
delete magic[i][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
void MenuZGI::onMouseUp(const Common::Point &Pos) {
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Pos.y < 40) {
|
2014-11-20 14:48:24 +06:00
|
|
|
switch (menuMouseFocus) {
|
2014-01-12 19:27:11 +07:00
|
|
|
case menu_ITEM:
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Items) {
|
|
|
|
int itemCount = _engine->getScriptManager()->getStateValue(StateKey_Inv_TotalSlots);
|
|
|
|
if (itemCount == 0)
|
|
|
|
itemCount = 20;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
for (int i = 0; i < itemCount; i++) {
|
|
|
|
int itemspace = (600 - 28) / itemCount;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
|
|
|
if (Common::Rect(scrollPos[menu_ITEM] + itemspace * i, 0,
|
|
|
|
scrollPos[menu_ITEM] + itemspace * i + 28, 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
int32 mouseItem = _engine->getScriptManager()->getStateValue(StateKey_InventoryItem);
|
|
|
|
if (mouseItem >= 0 && mouseItem < 0xE0) {
|
|
|
|
_engine->getScriptManager()->inventoryDrop(mouseItem);
|
|
|
|
_engine->getScriptManager()->inventoryAdd(_engine->getScriptManager()->getStateValue(SLOT_START_SLOT + i));
|
|
|
|
_engine->getScriptManager()->setStateValue(SLOT_START_SLOT + i, mouseItem);
|
2014-01-12 19:27:11 +07:00
|
|
|
|
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case menu_MAGIC:
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Magic) {
|
2014-01-12 19:27:11 +07:00
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
|
|
|
|
uint itemnum = _engine->getScriptManager()->getStateValue(SLOT_SPELL_1 + i);
|
|
|
|
if (itemnum != 0) {
|
|
|
|
if (_engine->getScriptManager()->getStateValue(SLOT_REVERSED_SPELLBOOK) == 1)
|
|
|
|
itemnum = 0xEE + i;
|
|
|
|
else
|
|
|
|
itemnum = 0xE0 + i;
|
|
|
|
}
|
|
|
|
if (itemnum)
|
|
|
|
if (_engine->getScriptManager()->getStateValue(StateKey_InventoryItem) == 0 || _engine->getScriptManager()->getStateValue(StateKey_InventoryItem) >= 0xE0)
|
|
|
|
if (Common::Rect(668 + 47 * i - scrollPos[menu_MAGIC], 0,
|
|
|
|
668 + 47 * i - scrollPos[menu_MAGIC] + 28, 32).contains(Pos))
|
|
|
|
_engine->getScriptManager()->setStateValue(SLOT_USER_CHOSE_THIS_SPELL, itemnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case menu_MAIN:
|
|
|
|
|
|
|
|
// Exit
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Exit)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(320 + 135,
|
|
|
|
scrollPos[menu_MAIN],
|
|
|
|
320 + 135 + 135,
|
|
|
|
scrollPos[menu_MAIN] + 32).contains(Pos)) {
|
2014-11-12 14:48:32 +06:00
|
|
|
_engine->ifQuit();
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Settings
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Settings)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(320 ,
|
|
|
|
scrollPos[menu_MAIN],
|
|
|
|
320 + 135,
|
|
|
|
scrollPos[menu_MAIN] + 32).contains(Pos)) {
|
|
|
|
_engine->getScriptManager()->changeLocation('g', 'j', 'p', 'e', 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Restore)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(320 - 135,
|
|
|
|
scrollPos[menu_MAIN],
|
|
|
|
320,
|
|
|
|
scrollPos[menu_MAIN] + 32).contains(Pos)) {
|
|
|
|
_engine->getScriptManager()->changeLocation('g', 'j', 'r', 'e', 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Save)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(320 - 135 * 2,
|
|
|
|
scrollPos[menu_MAIN],
|
|
|
|
320 - 135,
|
|
|
|
scrollPos[menu_MAIN] + 32).contains(Pos)) {
|
|
|
|
_engine->getScriptManager()->changeLocation('g', 'j', 's', 'e', 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
void MenuZGI::onMouseMove(const Common::Point &Pos) {
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Pos.y < 40) {
|
|
|
|
|
|
|
|
if (!inmenu)
|
|
|
|
redraw = true;
|
|
|
|
inmenu = true;
|
2014-11-20 14:48:24 +06:00
|
|
|
switch (menuMouseFocus) {
|
2014-01-12 19:27:11 +07:00
|
|
|
case menu_ITEM:
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Items) {
|
|
|
|
int itemCount = _engine->getScriptManager()->getStateValue(StateKey_Inv_TotalSlots);
|
|
|
|
if (itemCount == 0)
|
|
|
|
itemCount = 20;
|
|
|
|
else if (itemCount > 50)
|
|
|
|
itemCount = 50;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
int lastItem = mouseOnItem;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = -1;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
for (int i = 0; i < itemCount; i++) {
|
|
|
|
int itemspace = (600 - 28) / itemCount;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
|
|
|
if (Common::Rect(scrollPos[menu_ITEM] + itemspace * i, 0,
|
|
|
|
scrollPos[menu_ITEM] + itemspace * i + 28, 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = i;
|
2014-01-12 19:27:11 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (lastItem != mouseOnItem)
|
|
|
|
if (_engine->getScriptManager()->getStateValue(SLOT_START_SLOT + mouseOnItem) ||
|
|
|
|
_engine->getScriptManager()->getStateValue(SLOT_START_SLOT + lastItem))
|
2014-01-12 19:27:11 +07:00
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case menu_MAGIC:
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Magic) {
|
|
|
|
int lastItem = mouseOnItem;
|
|
|
|
mouseOnItem = -1;
|
2014-01-12 19:27:11 +07:00
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
if (Common::Rect(668 + 47 * i - scrollPos[menu_MAGIC], 0,
|
|
|
|
668 + 47 * i - scrollPos[menu_MAGIC] + 28, 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = i;
|
2014-01-12 19:27:11 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (lastItem != mouseOnItem)
|
|
|
|
if (_engine->getScriptManager()->getStateValue(SLOT_SPELL_1 + mouseOnItem) ||
|
|
|
|
_engine->getScriptManager()->getStateValue(SLOT_SPELL_1 + lastItem))
|
2014-01-12 19:27:11 +07:00
|
|
|
redraw = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-02-24 20:37:58 +07:00
|
|
|
case menu_MAIN: {
|
2014-11-20 14:48:24 +06:00
|
|
|
int lastItem = mouseOnItem;
|
|
|
|
mouseOnItem = -1;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
|
|
|
// Exit
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Exit)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(320 + 135,
|
|
|
|
scrollPos[menu_MAIN],
|
|
|
|
320 + 135 + 135,
|
|
|
|
scrollPos[menu_MAIN] + 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = menu_MAIN_EXIT;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Settings
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Settings)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(320 ,
|
|
|
|
scrollPos[menu_MAIN],
|
|
|
|
320 + 135,
|
|
|
|
scrollPos[menu_MAIN] + 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = menu_MAIN_PREF;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Restore)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(320 - 135,
|
|
|
|
scrollPos[menu_MAIN],
|
|
|
|
320,
|
|
|
|
scrollPos[menu_MAIN] + 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = menu_MAIN_REST;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Save)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(320 - 135 * 2,
|
|
|
|
scrollPos[menu_MAIN],
|
|
|
|
320 - 135,
|
|
|
|
scrollPos[menu_MAIN] + 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = menu_MAIN_SAVE;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (lastItem != mouseOnItem)
|
2014-01-12 19:27:11 +07:00
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-11-20 14:48:24 +06:00
|
|
|
int cur_menu = menuMouseFocus;
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(64, 0, 64 + 512, 8).contains(Pos)) { // Main
|
2014-11-20 14:48:24 +06:00
|
|
|
menuMouseFocus = menu_MAIN;
|
2014-01-12 19:27:11 +07:00
|
|
|
scrolled[menu_MAIN] = false;
|
|
|
|
scrollPos[menu_MAIN] = menuback[menu_MAIN][1].h - menuback[menu_MAIN][0].h;
|
|
|
|
_engine->getScriptManager()->setStateValue(StateKey_MenuState, 2);
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Magic)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(640 - 28, 0, 640, 32).contains(Pos)) { // Magic
|
2014-11-20 14:48:24 +06:00
|
|
|
menuMouseFocus = menu_MAGIC;
|
2014-01-12 19:27:11 +07:00
|
|
|
scrolled[menu_MAGIC] = false;
|
|
|
|
scrollPos[menu_MAGIC] = 28;
|
|
|
|
_engine->getScriptManager()->setStateValue(StateKey_MenuState, 3);
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Items)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(0, 0, 28, 32).contains(Pos)) { // Items
|
2014-11-20 14:48:24 +06:00
|
|
|
menuMouseFocus = menu_ITEM;
|
2014-01-12 19:27:11 +07:00
|
|
|
scrolled[menu_ITEM] = false;
|
|
|
|
scrollPos[menu_ITEM] = 28 - 600;
|
|
|
|
_engine->getScriptManager()->setStateValue(StateKey_MenuState, 1);
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (cur_menu != menuMouseFocus)
|
2014-01-12 19:27:11 +07:00
|
|
|
clean = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (inmenu)
|
|
|
|
clean = true;
|
|
|
|
inmenu = false;
|
|
|
|
if (_engine->getScriptManager()->getStateValue(StateKey_MenuState) != 0)
|
|
|
|
_engine->getScriptManager()->setStateValue(StateKey_MenuState, 0);
|
2014-11-20 14:48:24 +06:00
|
|
|
menuMouseFocus = -1;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
void MenuZGI::process(uint32 deltatime) {
|
2014-01-12 19:27:11 +07:00
|
|
|
if (clean) {
|
|
|
|
_engine->getRenderManager()->clearMenuSurface();
|
|
|
|
clean = false;
|
|
|
|
}
|
2014-11-20 14:48:24 +06:00
|
|
|
switch (menuMouseFocus) {
|
2014-01-12 19:27:11 +07:00
|
|
|
case menu_ITEM:
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Items)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (!scrolled[menu_ITEM]) {
|
|
|
|
redraw = true;
|
|
|
|
float scrl = 600.0 * (deltatime / 1000.0);
|
|
|
|
|
|
|
|
if (scrl == 0)
|
|
|
|
scrl = 1.0;
|
|
|
|
|
|
|
|
scrollPos [menu_ITEM] += scrl;
|
|
|
|
|
|
|
|
if (scrollPos[menu_ITEM] >= 0) {
|
|
|
|
scrolled[menu_ITEM] = true;
|
|
|
|
scrollPos [menu_ITEM] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (redraw) {
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_ITEM][0], scrollPos[menu_ITEM], 0);
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
int itemCount = _engine->getScriptManager()->getStateValue(StateKey_Inv_TotalSlots);
|
|
|
|
if (itemCount == 0)
|
|
|
|
itemCount = 20;
|
|
|
|
else if (itemCount > 50)
|
|
|
|
itemCount = 50;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
for (int i = 0; i < itemCount; i++) {
|
|
|
|
int itemspace = (600 - 28) / itemCount;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
|
|
|
bool inrect = false;
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (mouseOnItem == i)
|
2014-01-12 19:27:11 +07:00
|
|
|
inrect = true;
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
uint curItemId = _engine->getScriptManager()->getStateValue(SLOT_START_SLOT + i);
|
2014-01-12 19:27:11 +07:00
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (curItemId != 0) {
|
|
|
|
if (itemId[i] != curItemId) {
|
2014-01-12 19:27:11 +07:00
|
|
|
char buf[16];
|
2014-11-20 14:48:24 +06:00
|
|
|
sprintf(buf, "gmzwu%2.2x1.tga", curItemId);
|
2014-01-12 19:27:11 +07:00
|
|
|
items[i][0] = _engine->getRenderManager()->loadImage(buf, false);
|
2014-11-20 14:48:24 +06:00
|
|
|
sprintf(buf, "gmzxu%2.2x1.tga", curItemId);
|
2014-01-12 19:27:11 +07:00
|
|
|
items[i][1] = _engine->getRenderManager()->loadImage(buf, false);
|
2014-11-20 14:48:24 +06:00
|
|
|
itemId[i] = curItemId;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (inrect)
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(*items[i][1], scrollPos[menu_ITEM] + itemspace * i, 0, 0);
|
|
|
|
else
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(*items[i][0], scrollPos[menu_ITEM] + itemspace * i, 0, 0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (items[i][0]) {
|
|
|
|
items[i][0]->free();
|
|
|
|
delete items[i][0];
|
|
|
|
items[i][0] = NULL;
|
|
|
|
}
|
|
|
|
if (items[i][1]) {
|
|
|
|
items[i][1]->free();
|
|
|
|
delete items[i][1];
|
|
|
|
items[i][1] = NULL;
|
|
|
|
}
|
2014-11-20 14:48:24 +06:00
|
|
|
itemId[i] = 0;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
redraw = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case menu_MAGIC:
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Magic)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (!scrolled[menu_MAGIC]) {
|
|
|
|
redraw = true;
|
|
|
|
float scrl = 600.0 * (deltatime / 1000.0);
|
|
|
|
|
|
|
|
if (scrl == 0)
|
|
|
|
scrl = 1.0;
|
|
|
|
|
|
|
|
scrollPos [menu_MAGIC] += scrl;
|
|
|
|
|
|
|
|
if (scrollPos[menu_MAGIC] >= 600) {
|
|
|
|
scrolled[menu_MAGIC] = true;
|
|
|
|
scrollPos [menu_MAGIC] = 600;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (redraw) {
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_MAGIC][0], 640 - scrollPos[menu_MAGIC], 0);
|
|
|
|
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
bool inrect = false;
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (mouseOnItem == i)
|
2014-01-12 19:27:11 +07:00
|
|
|
inrect = true;
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
uint curItemId = _engine->getScriptManager()->getStateValue(SLOT_SPELL_1 + i);
|
|
|
|
if (curItemId) {
|
2014-01-12 19:27:11 +07:00
|
|
|
if (_engine->getScriptManager()->getStateValue(SLOT_REVERSED_SPELLBOOK) == 1)
|
2014-11-20 14:48:24 +06:00
|
|
|
curItemId = 0xEE + i;
|
2014-01-12 19:27:11 +07:00
|
|
|
else
|
2014-11-20 14:48:24 +06:00
|
|
|
curItemId = 0xE0 + i;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (curItemId != 0) {
|
|
|
|
if (itemId[i] != curItemId) {
|
2014-01-12 19:27:11 +07:00
|
|
|
char buf[16];
|
2014-11-20 14:48:24 +06:00
|
|
|
sprintf(buf, "gmzwu%2.2x1.tga", curItemId);
|
2014-01-12 19:27:11 +07:00
|
|
|
magic[i][0] = _engine->getRenderManager()->loadImage(buf, false);
|
2014-11-20 14:48:24 +06:00
|
|
|
sprintf(buf, "gmzxu%2.2x1.tga", curItemId);
|
2014-01-12 19:27:11 +07:00
|
|
|
magic[i][1] = _engine->getRenderManager()->loadImage(buf, false);
|
2014-11-20 14:48:24 +06:00
|
|
|
magicId[i] = curItemId;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (inrect)
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(*magic[i][1], 668 + 47 * i - scrollPos[menu_MAGIC], 0, 0);
|
|
|
|
else
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(*magic[i][0], 668 + 47 * i - scrollPos[menu_MAGIC], 0, 0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (magic[i][0]) {
|
|
|
|
magic[i][0]->free();
|
|
|
|
delete magic[i][0];
|
|
|
|
magic[i][0] = NULL;
|
|
|
|
}
|
|
|
|
if (magic[i][1]) {
|
|
|
|
magic[i][1]->free();
|
|
|
|
delete magic[i][1];
|
|
|
|
magic[i][1] = NULL;
|
|
|
|
}
|
2014-11-20 14:48:24 +06:00
|
|
|
magicId[i] = 0;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
redraw = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case menu_MAIN:
|
|
|
|
if (!scrolled[menu_MAIN]) {
|
|
|
|
redraw = true;
|
|
|
|
float scrl = 32.0 * 2.0 * (deltatime / 1000.0);
|
|
|
|
|
|
|
|
if (scrl == 0)
|
|
|
|
scrl = 1.0;
|
|
|
|
|
|
|
|
scrollPos [menu_MAIN] += scrl;
|
|
|
|
|
|
|
|
if (scrollPos[menu_MAIN] >= 0) {
|
|
|
|
scrolled[menu_MAIN] = true;
|
|
|
|
scrollPos [menu_MAIN] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (redraw) {
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_MAIN][0], 30, scrollPos[menu_MAIN]);
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Exit) {
|
|
|
|
if (mouseOnItem == menu_MAIN_EXIT)
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_EXIT][1], 320 + 135, scrollPos[menu_MAIN]);
|
|
|
|
else
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_EXIT][0], 320 + 135, scrollPos[menu_MAIN]);
|
|
|
|
}
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Settings) {
|
|
|
|
if (mouseOnItem == menu_MAIN_PREF)
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_PREF][1], 320, scrollPos[menu_MAIN]);
|
|
|
|
else
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_PREF][0], 320, scrollPos[menu_MAIN]);
|
|
|
|
}
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Restore) {
|
|
|
|
if (mouseOnItem == menu_MAIN_REST)
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_REST][1], 320 - 135, scrollPos[menu_MAIN]);
|
|
|
|
else
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_REST][0], 320 - 135, scrollPos[menu_MAIN]);
|
|
|
|
}
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Save) {
|
|
|
|
if (mouseOnItem == menu_MAIN_SAVE)
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_SAVE][1], 320 - 135 * 2, scrollPos[menu_MAIN]);
|
|
|
|
else
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_SAVE][0], 320 - 135 * 2, scrollPos[menu_MAIN]);
|
|
|
|
}
|
|
|
|
redraw = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (redraw) {
|
|
|
|
if (inmenu) {
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_MAIN][1], 30, 0);
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Items)
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_ITEM][1], 0, 0);
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Magic)
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_MAGIC][1], 640 - 28, 0);
|
|
|
|
}
|
|
|
|
redraw = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
MenuNemesis::MenuNemesis(ZVision *engine) :
|
|
|
|
MenuHandler(engine) {
|
2014-01-12 19:27:11 +07:00
|
|
|
inmenu = false;
|
|
|
|
scrolled = false;
|
|
|
|
scrollPos = 0.0;
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = -1;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
|
|
|
char buf[24];
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < 6; j++) {
|
|
|
|
sprintf(buf, "butfrm%d%d.tga", i + 1, j);
|
|
|
|
_engine->getRenderManager()->readImageToSurface(buf, but[i][j], false);
|
|
|
|
}
|
|
|
|
|
|
|
|
_engine->getRenderManager()->readImageToSurface("bar.tga", menubar, false);
|
|
|
|
|
|
|
|
frm = 0;
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
MenuNemesis::~MenuNemesis() {
|
2014-01-12 19:27:11 +07:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < 6; j++)
|
|
|
|
but[i][j].free();
|
|
|
|
|
|
|
|
menubar.free();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int16 buts[4][2] = { {120 , 64}, {144, 184}, {128, 328}, {120, 456} };
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
void MenuNemesis::onMouseUp(const Common::Point &Pos) {
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Pos.y < 40) {
|
|
|
|
// Exit
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Exit)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(buts[3][1],
|
|
|
|
scrollPos,
|
|
|
|
buts[3][0] + buts[3][1],
|
|
|
|
scrollPos + 32).contains(Pos)) {
|
2014-11-12 14:48:32 +06:00
|
|
|
_engine->ifQuit();
|
2014-01-12 19:27:11 +07:00
|
|
|
frm = 5;
|
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Settings
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Settings)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(buts[2][1],
|
|
|
|
scrollPos,
|
|
|
|
buts[2][0] + buts[2][1],
|
|
|
|
scrollPos + 32).contains(Pos)) {
|
|
|
|
_engine->getScriptManager()->changeLocation('g', 'j', 'p', 'e', 0);
|
|
|
|
frm = 5;
|
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Restore)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(buts[1][1],
|
|
|
|
scrollPos,
|
|
|
|
buts[1][0] + buts[1][1],
|
|
|
|
scrollPos + 32).contains(Pos)) {
|
|
|
|
_engine->getScriptManager()->changeLocation('g', 'j', 'r', 'e', 0);
|
|
|
|
frm = 5;
|
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Save)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(buts[0][1],
|
|
|
|
scrollPos,
|
|
|
|
buts[0][0] + buts[0][1],
|
|
|
|
scrollPos + 32).contains(Pos)) {
|
|
|
|
_engine->getScriptManager()->changeLocation('g', 'j', 's', 'e', 0);
|
|
|
|
frm = 5;
|
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
void MenuNemesis::onMouseMove(const Common::Point &Pos) {
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Pos.y < 40) {
|
|
|
|
|
|
|
|
inmenu = true;
|
|
|
|
|
|
|
|
if (_engine->getScriptManager()->getStateValue(StateKey_MenuState) != 2)
|
|
|
|
_engine->getScriptManager()->setStateValue(StateKey_MenuState, 2);
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
int lastItem = mouseOnItem;
|
|
|
|
mouseOnItem = -1;
|
2014-01-12 19:27:11 +07:00
|
|
|
|
|
|
|
// Exit
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Exit)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(buts[3][1],
|
|
|
|
scrollPos,
|
|
|
|
buts[3][0] + buts[3][1],
|
|
|
|
scrollPos + 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = menu_MAIN_EXIT;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Settings
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Settings)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(buts[2][1],
|
|
|
|
scrollPos,
|
|
|
|
buts[2][0] + buts[2][1],
|
|
|
|
scrollPos + 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = menu_MAIN_PREF;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Restore)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(buts[1][1],
|
|
|
|
scrollPos,
|
|
|
|
buts[1][0] + buts[1][1],
|
|
|
|
scrollPos + 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = menu_MAIN_REST;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Save)
|
2014-01-12 19:27:11 +07:00
|
|
|
if (Common::Rect(buts[0][1],
|
|
|
|
scrollPos,
|
|
|
|
buts[0][0] + buts[0][1],
|
|
|
|
scrollPos + 32).contains(Pos)) {
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = menu_MAIN_SAVE;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (lastItem != mouseOnItem) {
|
2014-01-12 19:27:11 +07:00
|
|
|
redraw = true;
|
|
|
|
frm = 0;
|
|
|
|
delay = 200;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inmenu = false;
|
|
|
|
if (_engine->getScriptManager()->getStateValue(StateKey_MenuState) != 0)
|
|
|
|
_engine->getScriptManager()->setStateValue(StateKey_MenuState, 0);
|
2014-11-20 14:48:24 +06:00
|
|
|
mouseOnItem = -1;
|
2014-01-12 19:27:11 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
void MenuNemesis::process(uint32 deltatime) {
|
2014-01-12 19:27:11 +07:00
|
|
|
if (inmenu) {
|
2014-02-24 20:37:58 +07:00
|
|
|
if (!scrolled) {
|
2014-01-12 19:27:11 +07:00
|
|
|
float scrl = 32.0 * 2.0 * (deltatime / 1000.0);
|
|
|
|
|
|
|
|
if (scrl == 0)
|
|
|
|
scrl = 1.0;
|
|
|
|
|
|
|
|
scrollPos += scrl;
|
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
|
2014-02-24 20:37:58 +07:00
|
|
|
if (scrollPos >= 0) {
|
2014-01-12 19:27:11 +07:00
|
|
|
scrolled = true;
|
|
|
|
scrollPos = 0;
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (mouseOnItem != -1) {
|
2014-01-12 19:27:11 +07:00
|
|
|
delay -= deltatime;
|
|
|
|
if (delay <= 0 && frm < 4) {
|
|
|
|
delay = 200;
|
|
|
|
frm++;
|
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (redraw) {
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menubar, 64, scrollPos);
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Exit)
|
|
|
|
if (mouseOnItem == menu_MAIN_EXIT)
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(but[3][frm], buts[3][1], scrollPos);
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Settings)
|
|
|
|
if (mouseOnItem == menu_MAIN_PREF)
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(but[2][frm], buts[2][1], scrollPos);
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Restore)
|
|
|
|
if (mouseOnItem == menu_MAIN_REST)
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(but[1][frm], buts[1][1], scrollPos);
|
|
|
|
|
2014-11-20 14:48:24 +06:00
|
|
|
if (menuBarFlag & menuBar_Save)
|
|
|
|
if (mouseOnItem == menu_MAIN_SAVE)
|
2014-01-12 19:27:11 +07:00
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(but[0][frm], buts[0][1], scrollPos);
|
|
|
|
|
|
|
|
redraw = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scrolled = false;
|
2014-02-24 20:37:58 +07:00
|
|
|
if (scrollPos > -32) {
|
2014-01-12 19:27:11 +07:00
|
|
|
float scrl = 32.0 * 2.0 * (deltatime / 1000.0);
|
|
|
|
|
|
|
|
if (scrl == 0)
|
|
|
|
scrl = 1.0;
|
|
|
|
|
|
|
|
Common::Rect cl(64, 32 + scrollPos - scrl, 64 + 512, 32 + scrollPos + 1);
|
|
|
|
_engine->getRenderManager()->clearMenuSurface(cl);
|
|
|
|
|
|
|
|
scrollPos -= scrl;
|
|
|
|
redraw = true;
|
2014-02-24 20:37:58 +07:00
|
|
|
} else
|
2014-01-12 19:27:11 +07:00
|
|
|
scrollPos = -32;
|
|
|
|
|
|
|
|
if (redraw) {
|
|
|
|
_engine->getRenderManager()->blitSurfaceToMenu(menubar, 64, scrollPos);
|
|
|
|
redraw = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace ZVision
|