2007-05-30 21:56:52 +00: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.
|
2003-12-20 09:18:43 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-12-20 09:18:43 +00:00
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-12-20 09:18:43 +00:00
|
|
|
*
|
2006-02-11 10:01:01 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-12-20 09:18:43 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-01-10 22:18:39 +00:00
|
|
|
#include "common/file.h"
|
2004-03-28 12:59:51 +00:00
|
|
|
#include "common/util.h"
|
2005-01-10 22:18:39 +00:00
|
|
|
#include "common/savefile.h"
|
2007-03-17 00:53:21 +00:00
|
|
|
#include "common/events.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/system.h"
|
2008-11-10 11:24:55 +00:00
|
|
|
#include "common/config-manager.h"
|
2004-03-28 12:59:51 +00:00
|
|
|
|
|
|
|
#include "gui/message.h"
|
|
|
|
|
|
|
|
#include "sword1/control.h"
|
|
|
|
#include "sword1/logic.h"
|
|
|
|
#include "sword1/mouse.h"
|
|
|
|
#include "sword1/music.h"
|
|
|
|
#include "sword1/objectman.h"
|
|
|
|
#include "sword1/resman.h"
|
|
|
|
#include "sword1/sound.h"
|
|
|
|
#include "sword1/sword1.h"
|
|
|
|
#include "sword1/sworddefs.h"
|
|
|
|
#include "sword1/swordres.h"
|
2004-01-11 15:47:41 +00:00
|
|
|
|
|
|
|
namespace Sword1 {
|
2003-12-20 09:18:43 +00:00
|
|
|
|
|
|
|
enum LangStrings {
|
|
|
|
STR_PAUSED = 0,
|
|
|
|
STR_INSERT_CD_A,
|
|
|
|
STR_INSERT_CD_B,
|
|
|
|
STR_INCORRECT_CD,
|
|
|
|
STR_SAVE,
|
|
|
|
STR_RESTORE,
|
|
|
|
STR_RESTART,
|
|
|
|
STR_START,
|
|
|
|
STR_QUIT,
|
|
|
|
STR_SPEED,
|
|
|
|
STR_VOLUME,
|
|
|
|
STR_TEXT,
|
|
|
|
STR_DONE,
|
|
|
|
STR_OK,
|
|
|
|
STR_CANCEL,
|
|
|
|
STR_MUSIC,
|
|
|
|
STR_SPEECH,
|
|
|
|
STR_FX,
|
|
|
|
STR_THE_END,
|
|
|
|
STR_DRIVE_FULL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ButtonIds {
|
|
|
|
BUTTON_DONE = 1,
|
|
|
|
BUTTON_MAIN_PANEL,
|
|
|
|
BUTTON_SAVE_PANEL,
|
|
|
|
BUTTON_RESTORE_PANEL,
|
|
|
|
BUTTON_RESTART,
|
|
|
|
BUTTON_QUIT,
|
|
|
|
BUTTON_SPEED,
|
2003-12-23 16:58:06 +00:00
|
|
|
BUTTON_VOLUME_PANEL,
|
2003-12-20 09:18:43 +00:00
|
|
|
BUTTON_TEXT,
|
2004-01-04 06:31:29 +00:00
|
|
|
BUTTON_CONFIRM,
|
2003-12-20 09:18:43 +00:00
|
|
|
//-
|
|
|
|
BUTTON_SCROLL_UP_FAST,
|
|
|
|
BUTTON_SCROLL_UP_SLOW,
|
|
|
|
BUTTON_SCROLL_DOWN_SLOW,
|
|
|
|
BUTTON_SCROLL_DOWN_FAST,
|
|
|
|
BUTTON_SAVE_SELECT1,
|
|
|
|
BUTTON_SAVE_SELECT2,
|
|
|
|
BUTTON_SAVE_SELECT3,
|
|
|
|
BUTTON_SAVE_SELECT4,
|
|
|
|
BUTTON_SAVE_SELECT5,
|
|
|
|
BUTTON_SAVE_SELECT6,
|
|
|
|
BUTTON_SAVE_SELECT7,
|
|
|
|
BUTTON_SAVE_SELECT8,
|
|
|
|
BUTTON_SAVE_RESTORE_OKAY,
|
2004-01-04 06:31:29 +00:00
|
|
|
BUTTON_SAVE_CANCEL,
|
|
|
|
//-
|
|
|
|
CONFIRM_OKAY,
|
|
|
|
CONFIRM_CANCEL
|
2003-12-20 09:18:43 +00:00
|
|
|
};
|
|
|
|
|
2003-12-23 16:58:06 +00:00
|
|
|
enum TextModes {
|
|
|
|
TEXT_LEFT_ALIGN = 0,
|
|
|
|
TEXT_CENTER,
|
2003-12-29 15:38:16 +00:00
|
|
|
TEXT_RIGHT_ALIGN,
|
|
|
|
TEXT_RED_FONT = 128
|
2003-12-23 16:58:06 +00:00
|
|
|
};
|
|
|
|
|
2005-08-24 16:10:09 +00:00
|
|
|
ControlButton::ControlButton(uint16 x, uint16 y, uint32 resId, uint8 id, uint8 flag, ResMan *pResMan, uint8 *screenBuf, OSystem *system) {
|
2003-12-20 09:18:43 +00:00
|
|
|
_x = x;
|
|
|
|
_y = y;
|
|
|
|
_id = id;
|
2005-08-24 16:10:09 +00:00
|
|
|
_flag = flag;
|
2003-12-20 09:18:43 +00:00
|
|
|
_resId = resId;
|
|
|
|
_resMan = pResMan;
|
|
|
|
_frameIdx = 0;
|
|
|
|
_resMan->resOpen(_resId);
|
|
|
|
FrameHeader *tmp = _resMan->fetchFrame(_resMan->fetchRes(_resId), 0);
|
2006-11-12 19:05:51 +00:00
|
|
|
_width = _resMan->getUint16(tmp->width);
|
|
|
|
_height = _resMan->getUint16(tmp->height);
|
2003-12-23 16:58:06 +00:00
|
|
|
if ((x == 0) && (y == 0)) { // center the frame (used for panels);
|
|
|
|
_x = (640 - _width) / 2;
|
|
|
|
_y = (480 - _height) / 2;
|
|
|
|
}
|
|
|
|
_dstBuf = screenBuf + _y * SCREEN_WIDTH + _x;
|
2003-12-20 09:18:43 +00:00
|
|
|
_system = system;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlButton::~ControlButton(void) {
|
|
|
|
_resMan->resClose(_resId);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ControlButton::isSaveslot(void) {
|
|
|
|
return ((_resId >= SR_SLAB1) && (_resId <= SR_SLAB4));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlButton::draw(void) {
|
|
|
|
FrameHeader *fHead = _resMan->fetchFrame(_resMan->fetchRes(_resId), _frameIdx);
|
|
|
|
uint8 *src = (uint8*)fHead + sizeof(FrameHeader);
|
|
|
|
uint8 *dst = _dstBuf;
|
2006-11-12 19:05:51 +00:00
|
|
|
for (uint16 cnt = 0; cnt < _resMan->readUint16(&fHead->height); cnt++) {
|
|
|
|
for (uint16 cntx = 0; cntx < _resMan->readUint16(&fHead->width); cntx++)
|
2003-12-20 09:18:43 +00:00
|
|
|
if (src[cntx])
|
|
|
|
dst[cntx] = src[cntx];
|
|
|
|
dst += SCREEN_WIDTH;
|
2006-11-12 19:05:51 +00:00
|
|
|
src += _resMan->readUint16(&fHead->width);
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(_dstBuf, SCREEN_WIDTH, _x, _y, _width, _height);
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ControlButton::wasClicked(uint16 mouseX, uint16 mouseY) {
|
|
|
|
if ((_x <= mouseX) && (_y <= mouseY) && (_x + _width >= mouseX) && (_y + _height >= mouseY))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlButton::setSelected(uint8 selected) {
|
|
|
|
_frameIdx = selected;
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
Control::Control(Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic) {
|
2004-06-25 22:39:21 +00:00
|
|
|
_saveFileMan = saveFileMan;
|
2003-12-20 09:18:43 +00:00
|
|
|
_resMan = pResMan;
|
|
|
|
_objMan = pObjMan;
|
|
|
|
_system = system;
|
|
|
|
_mouse = pMouse;
|
2003-12-28 23:24:03 +00:00
|
|
|
_music = pMusic;
|
2004-01-07 17:47:46 +00:00
|
|
|
_sound = pSound;
|
2004-10-21 08:47:13 +00:00
|
|
|
_lStrings = _languageStrings + SwordEngine::_systemVars.language * 20;
|
2006-09-09 09:50:00 +00:00
|
|
|
_selectedButton = 255;
|
2003-12-30 22:57:52 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::askForCd(void) {
|
2003-12-30 22:57:52 +00:00
|
|
|
_screenBuf = (uint8*)malloc(640 * 480);
|
2004-01-07 18:08:24 +00:00
|
|
|
uint32 fontId = SR_FONT;
|
|
|
|
if (SwordEngine::_systemVars.language == BS1_CZECH)
|
|
|
|
fontId = CZECH_SR_FONT;
|
|
|
|
_font = (uint8*)_resMan->openFetchRes(fontId);
|
2003-12-30 22:57:52 +00:00
|
|
|
uint8 *pal = (uint8*)_resMan->openFetchRes(SR_PALETTE);
|
|
|
|
uint8 *palOut = (uint8*)malloc(256 * 4);
|
|
|
|
for (uint16 cnt = 1; cnt < 256; cnt++) {
|
|
|
|
palOut[cnt * 4 + 0] = pal[cnt * 3 + 0] << 2;
|
|
|
|
palOut[cnt * 4 + 1] = pal[cnt * 3 + 1] << 2;
|
|
|
|
palOut[cnt * 4 + 2] = pal[cnt * 3 + 2] << 2;
|
|
|
|
}
|
|
|
|
palOut[0] = palOut[1] = palOut[2] = palOut[3] = 0;
|
|
|
|
_resMan->resClose(SR_PALETTE);
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->setPalette(palOut, 0, 256);
|
2003-12-30 22:57:52 +00:00
|
|
|
free(palOut);
|
|
|
|
|
2003-12-31 17:38:27 +00:00
|
|
|
char fName[10];
|
|
|
|
uint8 textA[50];
|
2003-12-30 22:57:52 +00:00
|
|
|
sprintf(fName, "cd%d.id", SwordEngine::_systemVars.currentCD);
|
2003-12-31 17:38:27 +00:00
|
|
|
sprintf((char*)textA, "%s%d", _lStrings[STR_INSERT_CD_A], SwordEngine::_systemVars.currentCD);
|
2003-12-30 22:57:52 +00:00
|
|
|
bool notAccepted = true;
|
|
|
|
bool refreshText = true;
|
|
|
|
do {
|
|
|
|
if (refreshText) {
|
|
|
|
memset(_screenBuf, 0, 640 * 480);
|
|
|
|
renderText(textA, 320, 220, TEXT_CENTER);
|
|
|
|
renderText(_lStrings[STR_INSERT_CD_B], 320, 240, TEXT_CENTER);
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(_screenBuf, 640, 0, 0, 640, 480);
|
2003-12-30 22:57:52 +00:00
|
|
|
}
|
|
|
|
delay(300);
|
2007-06-22 21:34:03 +00:00
|
|
|
if (_keyPressed.keycode) {
|
2006-06-20 18:08:03 +00:00
|
|
|
if (!Common::File::exists(fName)) {
|
2003-12-30 22:57:52 +00:00
|
|
|
memset(_screenBuf, 0, 640 * 480);
|
|
|
|
renderText(_lStrings[STR_INCORRECT_CD], 320, 230, TEXT_CENTER);
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(_screenBuf, 640, 0, 0, 640, 480);
|
2003-12-30 22:57:52 +00:00
|
|
|
delay(2000);
|
|
|
|
refreshText = true;
|
|
|
|
} else {
|
|
|
|
notAccepted = false;
|
|
|
|
}
|
|
|
|
}
|
2008-09-30 12:27:38 +00:00
|
|
|
} while (notAccepted && (!g_engine->shouldQuit()));
|
2003-12-30 22:57:52 +00:00
|
|
|
|
2004-01-07 18:08:24 +00:00
|
|
|
_resMan->resClose(fontId);
|
2003-12-30 22:57:52 +00:00
|
|
|
free(_screenBuf);
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
|
2008-01-01 16:42:05 +00:00
|
|
|
static int volToBalance(int volL, int volR) {
|
|
|
|
if (volL + volR == 0) {
|
|
|
|
return 50;
|
|
|
|
} else {
|
|
|
|
return (100 * volL / (volL + volR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
uint8 Control::runPanel(void) {
|
2004-01-07 17:47:46 +00:00
|
|
|
_mouseDown = false;
|
2003-12-20 09:18:43 +00:00
|
|
|
_restoreBuf = NULL;
|
2007-06-22 22:19:17 +00:00
|
|
|
_keyPressed.reset();
|
2007-06-22 21:34:03 +00:00
|
|
|
_numButtons = 0;
|
2003-12-20 09:18:43 +00:00
|
|
|
_screenBuf = (uint8*)malloc(640 * 480);
|
2005-11-12 09:14:07 +00:00
|
|
|
memset(_screenBuf, 0, 640 * 480);
|
|
|
|
_system->copyRectToScreen(_screenBuf, 640, 0, 0, 640, 480);
|
2005-11-12 15:25:22 +00:00
|
|
|
_sound->quitScreen();
|
2005-11-12 09:14:07 +00:00
|
|
|
|
2004-01-07 18:08:24 +00:00
|
|
|
uint32 fontId = SR_FONT, redFontId = SR_REDFONT;
|
|
|
|
if (SwordEngine::_systemVars.language == BS1_CZECH) {
|
|
|
|
fontId = CZECH_SR_FONT;
|
|
|
|
redFontId = CZECH_SR_REDFONT;
|
|
|
|
}
|
|
|
|
_font = (uint8*)_resMan->openFetchRes(fontId);
|
|
|
|
_redFont = (uint8*)_resMan->openFetchRes(redFontId);
|
|
|
|
|
2003-12-20 09:18:43 +00:00
|
|
|
uint8 *pal = (uint8*)_resMan->openFetchRes(SR_PALETTE);
|
|
|
|
uint8 *palOut = (uint8*)malloc(256 * 4);
|
|
|
|
for (uint16 cnt = 1; cnt < 256; cnt++) {
|
|
|
|
palOut[cnt * 4 + 0] = pal[cnt * 3 + 0] << 2;
|
|
|
|
palOut[cnt * 4 + 1] = pal[cnt * 3 + 1] << 2;
|
|
|
|
palOut[cnt * 4 + 2] = pal[cnt * 3 + 2] << 2;
|
|
|
|
}
|
|
|
|
palOut[0] = palOut[1] = palOut[2] = palOut[3] = 0;
|
|
|
|
_resMan->resClose(SR_PALETTE);
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->setPalette(palOut, 0, 256);
|
2003-12-20 09:18:43 +00:00
|
|
|
free(palOut);
|
|
|
|
uint8 mode = 0, newMode = BUTTON_MAIN_PANEL;
|
|
|
|
bool fullRefresh = false;
|
|
|
|
_mouse->controlPanel(true);
|
|
|
|
uint8 retVal = CONTROL_NOTHING_DONE;
|
2003-12-28 23:24:03 +00:00
|
|
|
_music->startMusic(61, 1);
|
2003-12-20 09:18:43 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
if (newMode) {
|
|
|
|
mode = newMode;
|
|
|
|
fullRefresh = true;
|
|
|
|
destroyButtons();
|
|
|
|
memset(_screenBuf, 0, 640 * 480);
|
2004-05-12 06:21:44 +00:00
|
|
|
if (mode != BUTTON_SAVE_PANEL)
|
|
|
|
_cursorVisible = false;
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
switch (mode) {
|
2005-04-07 08:50:48 +00:00
|
|
|
case BUTTON_MAIN_PANEL:
|
|
|
|
if (fullRefresh)
|
|
|
|
setupMainPanel();
|
|
|
|
break;
|
|
|
|
case BUTTON_SAVE_PANEL:
|
|
|
|
if (fullRefresh) {
|
|
|
|
setupSaveRestorePanel(true);
|
|
|
|
}
|
|
|
|
if (_selectedSavegame < 255) {
|
2005-10-15 15:46:12 +00:00
|
|
|
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
|
2005-04-07 08:50:48 +00:00
|
|
|
bool visible = _cursorVisible;
|
2005-10-17 07:15:18 +00:00
|
|
|
_cursorTick++;
|
|
|
|
if (_cursorTick == 7)
|
2005-04-07 08:50:48 +00:00
|
|
|
_cursorVisible = true;
|
2005-10-17 07:15:18 +00:00
|
|
|
else if (_cursorTick == 14) {
|
2005-04-07 08:50:48 +00:00
|
|
|
_cursorVisible = false;
|
2005-10-17 07:15:18 +00:00
|
|
|
_cursorTick = 0;
|
|
|
|
}
|
2007-06-22 21:34:03 +00:00
|
|
|
if (_keyPressed.keycode)
|
2005-04-07 08:50:48 +00:00
|
|
|
handleSaveKey(_keyPressed);
|
|
|
|
else if (_cursorVisible != visible)
|
|
|
|
showSavegameNames();
|
2005-10-15 15:46:12 +00:00
|
|
|
} else {
|
|
|
|
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
|
2005-04-07 08:50:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BUTTON_RESTORE_PANEL:
|
|
|
|
if (fullRefresh)
|
|
|
|
setupSaveRestorePanel(false);
|
|
|
|
break;
|
|
|
|
case BUTTON_VOLUME_PANEL:
|
|
|
|
if (fullRefresh)
|
|
|
|
setupVolumePanel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
if (fullRefresh) {
|
|
|
|
fullRefresh = false;
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(_screenBuf, SCREEN_WIDTH, 0, 0, SCREEN_WIDTH, 480);
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
2005-10-26 06:16:14 +00:00
|
|
|
delay(1000 / 12);
|
2003-12-20 09:18:43 +00:00
|
|
|
newMode = getClicks(mode, &retVal);
|
2008-09-30 12:27:38 +00:00
|
|
|
} while ((newMode != BUTTON_DONE) && (retVal == 0) && (!g_engine->shouldQuit()));
|
2008-01-01 16:42:05 +00:00
|
|
|
|
|
|
|
if (SwordEngine::_systemVars.controlPanelMode == CP_NORMAL) {
|
|
|
|
uint8 volL, volR;
|
|
|
|
_music->giveVolume(&volL, &volR);
|
|
|
|
ConfMan.setInt("music_volume", (int)((volR + volL) / 2));
|
|
|
|
ConfMan.setInt("music_balance", volToBalance(volL, volR));
|
|
|
|
|
|
|
|
_sound->giveSpeechVol(&volL, &volR);
|
|
|
|
ConfMan.setInt("speech_volume", (int)((volR + volL) / 2));
|
|
|
|
ConfMan.setInt("speech_balance", volToBalance(volL, volR));
|
|
|
|
|
|
|
|
_sound->giveSfxVol(&volL, &volR);
|
|
|
|
ConfMan.setInt("sfx_volume", (int)((volR + volL) / 2));
|
|
|
|
ConfMan.setInt("sfx_balance", volToBalance(volL, volR));
|
|
|
|
|
|
|
|
ConfMan.setBool("subtitles", SwordEngine::_systemVars.showText == 1);
|
|
|
|
ConfMan.flushToDisk();
|
|
|
|
}
|
|
|
|
|
2003-12-20 19:19:42 +00:00
|
|
|
destroyButtons();
|
2004-01-07 18:08:24 +00:00
|
|
|
_resMan->resClose(fontId);
|
|
|
|
_resMan->resClose(redFontId);
|
2003-12-20 09:18:43 +00:00
|
|
|
memset(_screenBuf, 0, 640 * 480);
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(_screenBuf, 640, 0, 0, 640, 480);
|
2003-12-20 09:18:43 +00:00
|
|
|
free(_screenBuf);
|
|
|
|
_mouse->controlPanel(false);
|
2004-01-11 15:47:41 +00:00
|
|
|
_music->startMusic(Logic::_scriptVars[CURRENT_MUSIC], 1);
|
2003-12-20 09:18:43 +00:00
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
uint8 Control::getClicks(uint8 mode, uint8 *retVal) {
|
2004-01-07 17:47:46 +00:00
|
|
|
uint8 checkButtons = _numButtons;
|
|
|
|
if (mode == BUTTON_VOLUME_PANEL) {
|
|
|
|
handleVolumeClicks();
|
|
|
|
checkButtons = 1;
|
|
|
|
}
|
|
|
|
|
2005-08-24 16:10:09 +00:00
|
|
|
uint8 flag = 0;
|
2007-06-22 21:34:03 +00:00
|
|
|
if (_keyPressed.keycode == Common::KEYCODE_ESCAPE)
|
2005-08-24 16:10:09 +00:00
|
|
|
flag = kButtonCancel;
|
2007-06-22 21:34:03 +00:00
|
|
|
else if (_keyPressed.keycode == Common::KEYCODE_RETURN || _keyPressed.keycode == Common::KEYCODE_KP_ENTER)
|
2005-08-24 16:10:09 +00:00
|
|
|
flag = kButtonOk;
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
for (uint8 cnt = 0; cnt < checkButtons; cnt++)
|
|
|
|
if (_buttons[cnt]->_flag == flag)
|
|
|
|
return handleButtonClick(_buttons[cnt]->_id, mode, retVal);
|
|
|
|
}
|
|
|
|
|
2003-12-20 09:18:43 +00:00
|
|
|
if (!_mouseState)
|
|
|
|
return 0;
|
|
|
|
if (_mouseState & BS1L_BUTTON_DOWN)
|
2004-01-07 17:47:46 +00:00
|
|
|
for (uint8 cnt = 0; cnt < checkButtons; cnt++)
|
2007-11-28 15:00:41 +00:00
|
|
|
if (_buttons[cnt]->wasClicked(_mouseCoord.x, _mouseCoord.y)) {
|
2003-12-20 09:18:43 +00:00
|
|
|
_selectedButton = cnt;
|
|
|
|
_buttons[cnt]->setSelected(1);
|
2004-01-01 17:18:00 +00:00
|
|
|
if (_buttons[cnt]->isSaveslot())
|
|
|
|
showSavegameNames();
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
if (_mouseState & BS1L_BUTTON_UP) {
|
2004-01-07 17:47:46 +00:00
|
|
|
for (uint8 cnt = 0; cnt < checkButtons; cnt++)
|
2007-11-28 15:00:41 +00:00
|
|
|
if (_buttons[cnt]->wasClicked(_mouseCoord.x, _mouseCoord.y))
|
2003-12-20 09:18:43 +00:00
|
|
|
if (_selectedButton == cnt) {
|
|
|
|
// saveslots stay selected after clicking
|
|
|
|
if (!_buttons[cnt]->isSaveslot())
|
|
|
|
_buttons[cnt]->setSelected(0);
|
|
|
|
_selectedButton = 255;
|
|
|
|
return handleButtonClick(_buttons[cnt]->_id, mode, retVal);
|
|
|
|
}
|
2004-01-07 17:47:46 +00:00
|
|
|
if (_selectedButton < checkButtons) {
|
2003-12-20 09:18:43 +00:00
|
|
|
_buttons[_selectedButton]->setSelected(0);
|
2004-01-01 17:18:00 +00:00
|
|
|
if (_buttons[_selectedButton]->isSaveslot())
|
|
|
|
showSavegameNames();
|
|
|
|
}
|
2003-12-20 09:18:43 +00:00
|
|
|
_selectedButton = 255;
|
|
|
|
}
|
2004-05-12 06:21:44 +00:00
|
|
|
if (_mouseState & BS1_WHEEL_UP) {
|
|
|
|
for (uint8 cnt = 0; cnt < checkButtons; cnt++)
|
|
|
|
if (_buttons[cnt]->_id == BUTTON_SCROLL_UP_SLOW)
|
|
|
|
return handleButtonClick(_buttons[cnt]->_id, mode, retVal);
|
|
|
|
}
|
|
|
|
if (_mouseState & BS1_WHEEL_DOWN) {
|
|
|
|
for (uint8 cnt = 0; cnt < checkButtons; cnt++)
|
|
|
|
if (_buttons[cnt]->_id == BUTTON_SCROLL_DOWN_SLOW)
|
|
|
|
return handleButtonClick(_buttons[cnt]->_id, mode, retVal);
|
|
|
|
}
|
2003-12-20 09:18:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
uint8 Control::handleButtonClick(uint8 id, uint8 mode, uint8 *retVal) {
|
2005-04-07 08:50:48 +00:00
|
|
|
switch (mode) {
|
|
|
|
case BUTTON_MAIN_PANEL:
|
|
|
|
if (id == BUTTON_RESTART) {
|
|
|
|
if (SwordEngine::_systemVars.controlPanelMode) // if player is dead or has just started, don't ask for confirmation
|
|
|
|
*retVal |= CONTROL_RESTART_GAME;
|
|
|
|
else if (getConfirm(_lStrings[STR_RESTART]))
|
|
|
|
*retVal |= CONTROL_RESTART_GAME;
|
|
|
|
else
|
2004-11-09 04:06:10 +00:00
|
|
|
return mode;
|
2005-04-07 08:50:48 +00:00
|
|
|
} else if ((id == BUTTON_RESTORE_PANEL) || (id == BUTTON_SAVE_PANEL) ||
|
|
|
|
(id == BUTTON_DONE) || (id == BUTTON_VOLUME_PANEL))
|
|
|
|
return id;
|
|
|
|
else if (id == BUTTON_TEXT) {
|
|
|
|
SwordEngine::_systemVars.showText ^= 1;
|
|
|
|
_buttons[5]->setSelected(SwordEngine::_systemVars.showText);
|
|
|
|
} else if (id == BUTTON_QUIT) {
|
|
|
|
if (getConfirm(_lStrings[STR_QUIT]))
|
2008-07-13 21:54:23 +00:00
|
|
|
g_engine->quitGame();
|
2005-04-07 08:50:48 +00:00
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BUTTON_SAVE_PANEL:
|
|
|
|
case BUTTON_RESTORE_PANEL:
|
|
|
|
if ((id >= BUTTON_SCROLL_UP_FAST) && (id <= BUTTON_SCROLL_DOWN_FAST))
|
|
|
|
saveNameScroll(id, mode == BUTTON_SAVE_PANEL);
|
|
|
|
else if ((id >= BUTTON_SAVE_SELECT1) && (id <= BUTTON_SAVE_SELECT8))
|
|
|
|
saveNameSelect(id, mode == BUTTON_SAVE_PANEL);
|
|
|
|
else if (id == BUTTON_SAVE_RESTORE_OKAY) {
|
|
|
|
if (mode == BUTTON_SAVE_PANEL) {
|
2004-03-02 19:47:17 +00:00
|
|
|
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
|
2005-04-07 08:50:48 +00:00
|
|
|
if (saveToFile()) // don't go back to main panel if save fails.
|
2005-09-09 07:32:29 +00:00
|
|
|
return BUTTON_DONE;
|
2005-04-07 08:50:48 +00:00
|
|
|
} else {
|
|
|
|
if (restoreFromFile()) { // don't go back to main panel if restore fails.
|
|
|
|
*retVal |= CONTROL_GAME_RESTORED;
|
|
|
|
return BUTTON_MAIN_PANEL;
|
|
|
|
}
|
2004-03-02 19:47:17 +00:00
|
|
|
}
|
2005-04-07 08:50:48 +00:00
|
|
|
} else if (id == BUTTON_SAVE_CANCEL) {
|
|
|
|
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
|
|
|
|
return BUTTON_MAIN_PANEL; // mode down to main panel
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BUTTON_VOLUME_PANEL:
|
|
|
|
return id;
|
2008-01-28 00:14:17 +00:00
|
|
|
}
|
2003-12-20 09:18:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::deselectSaveslots(void) {
|
2003-12-20 09:18:43 +00:00
|
|
|
for (uint8 cnt = 0; cnt < 8; cnt++)
|
|
|
|
_buttons[cnt]->setSelected(0);
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::setupMainPanel(void) {
|
2003-12-20 09:18:43 +00:00
|
|
|
uint32 panelId;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-11-09 04:06:10 +00:00
|
|
|
if (SwordEngine::_systemVars.controlPanelMode == CP_DEATHSCREEN)
|
2003-12-20 09:18:43 +00:00
|
|
|
panelId = SR_DEATHPANEL;
|
2004-10-21 08:47:13 +00:00
|
|
|
else {
|
|
|
|
if (SwordEngine::_systemVars.language <= BS1_SPANISH)
|
|
|
|
panelId = SR_PANEL_ENGLISH + SwordEngine::_systemVars.language;
|
|
|
|
else
|
|
|
|
panelId = SR_PANEL_ENGLISH;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-24 16:10:09 +00:00
|
|
|
ControlButton *panel = new ControlButton(0, 0, panelId, 0, 0, _resMan, _screenBuf, _system);
|
2003-12-20 09:18:43 +00:00
|
|
|
panel->draw();
|
|
|
|
delete panel;
|
|
|
|
|
2004-11-09 04:06:10 +00:00
|
|
|
if (SwordEngine::_systemVars.controlPanelMode != CP_NORMAL)
|
2005-07-30 21:11:48 +00:00
|
|
|
createButtons(_deathButtons, 3);
|
2003-12-23 16:58:06 +00:00
|
|
|
else {
|
2004-01-04 05:21:22 +00:00
|
|
|
createButtons(_panelButtons, 7);
|
|
|
|
_buttons[5]->setSelected(SwordEngine::_systemVars.showText);
|
2003-12-23 16:58:06 +00:00
|
|
|
}
|
2003-12-20 09:18:43 +00:00
|
|
|
|
2004-11-09 04:06:10 +00:00
|
|
|
if (SwordEngine::_systemVars.controlPanelMode == CP_THEEND) // end of game
|
2003-12-28 23:24:03 +00:00
|
|
|
renderText(_lStrings[STR_THE_END], 480, 188 + 40, TEXT_RIGHT_ALIGN);
|
2003-12-20 09:18:43 +00:00
|
|
|
|
2004-11-09 04:06:10 +00:00
|
|
|
if (SwordEngine::_systemVars.controlPanelMode == CP_NORMAL) { // normal panel
|
2003-12-23 16:58:06 +00:00
|
|
|
renderText(_lStrings[STR_SAVE], 180, 188 + 40, TEXT_LEFT_ALIGN);
|
|
|
|
renderText(_lStrings[STR_DONE], 460, 332 + 40, TEXT_RIGHT_ALIGN);
|
|
|
|
renderText(_lStrings[STR_RESTORE], 180, 224 + 40, TEXT_LEFT_ALIGN);
|
|
|
|
renderText(_lStrings[STR_RESTART], 180, 260 + 40, TEXT_LEFT_ALIGN);
|
|
|
|
renderText(_lStrings[STR_QUIT], 180, 296 + 40, TEXT_LEFT_ALIGN);
|
|
|
|
|
2004-01-04 05:21:22 +00:00
|
|
|
renderText(_lStrings[STR_VOLUME], 460, 188 + 40, TEXT_RIGHT_ALIGN);
|
|
|
|
renderText(_lStrings[STR_TEXT], 460, 224 + 40, TEXT_RIGHT_ALIGN);
|
2003-12-20 09:18:43 +00:00
|
|
|
} else {
|
2003-12-23 16:58:06 +00:00
|
|
|
renderText(_lStrings[STR_RESTORE], 285, 224 + 40, TEXT_LEFT_ALIGN);
|
2004-11-09 04:06:10 +00:00
|
|
|
if (SwordEngine::_systemVars.controlPanelMode == CP_NEWGAME) // just started game
|
2003-12-28 23:24:03 +00:00
|
|
|
renderText(_lStrings[STR_START], 285, 260 + 40, TEXT_LEFT_ALIGN);
|
2003-12-20 09:18:43 +00:00
|
|
|
else
|
2003-12-23 16:58:06 +00:00
|
|
|
renderText(_lStrings[STR_RESTART], 285, 260 + 40, TEXT_LEFT_ALIGN);
|
|
|
|
renderText(_lStrings[STR_QUIT], 285, 296 + 40, TEXT_LEFT_ALIGN);
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::setupSaveRestorePanel(bool saving) {
|
2003-12-20 09:18:43 +00:00
|
|
|
FrameHeader *savePanel = _resMan->fetchFrame(_resMan->openFetchRes(SR_WINDOW), 0);
|
2006-11-12 19:05:51 +00:00
|
|
|
uint16 panelX = (640 - _resMan->getUint16(savePanel->width)) / 2;
|
|
|
|
uint16 panelY = (480 - _resMan->getUint16(savePanel->height)) / 2;
|
2005-08-24 16:10:09 +00:00
|
|
|
ControlButton *panel = new ControlButton(panelX, panelY, SR_WINDOW, 0, 0, _resMan, _screenBuf, _system);
|
2003-12-20 09:18:43 +00:00
|
|
|
panel->draw();
|
|
|
|
delete panel;
|
|
|
|
_resMan->resClose(SR_WINDOW);
|
|
|
|
createButtons(_saveButtons, 14);
|
2003-12-23 16:58:06 +00:00
|
|
|
renderText(_lStrings[STR_CANCEL], _saveButtons[13].x - 10, _saveButtons[13].y, TEXT_RIGHT_ALIGN);
|
2003-12-20 09:18:43 +00:00
|
|
|
if (saving) {
|
2003-12-23 16:58:06 +00:00
|
|
|
renderText(_lStrings[STR_SAVE], _saveButtons[12].x + 30, _saveButtons[13].y, TEXT_LEFT_ALIGN);
|
2003-12-20 09:18:43 +00:00
|
|
|
} else {
|
2003-12-23 16:58:06 +00:00
|
|
|
renderText(_lStrings[STR_RESTORE], _saveButtons[12].x + 30, _saveButtons[13].y, TEXT_LEFT_ALIGN);
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
2003-12-28 19:03:35 +00:00
|
|
|
readSavegameDescriptions();
|
2003-12-20 09:18:43 +00:00
|
|
|
_selectedSavegame = 255;
|
|
|
|
showSavegameNames();
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::setupVolumePanel(void) {
|
2005-08-24 16:10:09 +00:00
|
|
|
ControlButton *panel = new ControlButton(0, 0, SR_VOLUME, 0, 0, _resMan, _screenBuf, _system);
|
2003-12-23 16:58:06 +00:00
|
|
|
panel->draw();
|
|
|
|
delete panel;
|
|
|
|
|
|
|
|
renderText(_lStrings[STR_MUSIC], 149, 39 + 40, TEXT_LEFT_ALIGN);
|
|
|
|
renderText(_lStrings[STR_SPEECH], 320, 39 + 40, TEXT_CENTER);
|
|
|
|
renderText(_lStrings[STR_FX], 438, 39 + 40, TEXT_LEFT_ALIGN);
|
|
|
|
|
2004-01-07 17:47:46 +00:00
|
|
|
createButtons(_volumeButtons, 4);
|
2003-12-23 16:58:06 +00:00
|
|
|
renderText(_lStrings[STR_DONE], _volumeButtons[0].x - 10, _volumeButtons[0].y, TEXT_RIGHT_ALIGN);
|
2004-01-07 17:47:46 +00:00
|
|
|
|
|
|
|
uint8 volL, volR;
|
|
|
|
_music->giveVolume(&volL, &volR);
|
|
|
|
renderVolumeBar(1, volL, volR);
|
|
|
|
_sound->giveSpeechVol(&volL, &volR);
|
|
|
|
renderVolumeBar(2, volL, volR);
|
|
|
|
_sound->giveSfxVol(&volL, &volR);
|
|
|
|
renderVolumeBar(3, volL, volR);
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::handleVolumeClicks(void) {
|
2004-01-07 17:47:46 +00:00
|
|
|
if (_mouseDown) {
|
|
|
|
uint8 clickedId = 0;
|
|
|
|
for (uint8 cnt = 1; cnt < 4; cnt++)
|
2007-11-28 15:00:41 +00:00
|
|
|
if (_buttons[cnt]->wasClicked(_mouseCoord.x, _mouseCoord.y))
|
2004-01-07 17:47:46 +00:00
|
|
|
clickedId = cnt;
|
|
|
|
if (clickedId) { // these are circle shaped, so check again if it was clicked.
|
|
|
|
uint8 clickDest = 0;
|
2007-11-28 15:00:41 +00:00
|
|
|
int16 mouseDiffX = _mouseCoord.x - (_volumeButtons[clickedId].x + 48);
|
|
|
|
int16 mouseDiffY = _mouseCoord.y - (_volumeButtons[clickedId].y + 48);
|
2004-02-01 21:10:26 +00:00
|
|
|
int16 mouseOffs = (int16)sqrt((double)(mouseDiffX * mouseDiffX + mouseDiffY * mouseDiffY));
|
2004-01-07 17:47:46 +00:00
|
|
|
// check if the player really hit the button (but not the center).
|
|
|
|
if ((mouseOffs <= 42) && (mouseOffs >= 8)) {
|
|
|
|
if (mouseDiffX > 8) { // right part
|
|
|
|
if (mouseDiffY < -8) // upper right
|
|
|
|
clickDest = 2;
|
|
|
|
else if (ABS(mouseDiffY) <= 8) // right
|
|
|
|
clickDest = 3;
|
|
|
|
else // lower right
|
|
|
|
clickDest = 4;
|
|
|
|
} else if (mouseDiffX < -8) { // left part
|
|
|
|
if (mouseDiffY < -8) // upper left
|
|
|
|
clickDest = 8;
|
|
|
|
else if (ABS(mouseDiffY) <= 8) // left
|
|
|
|
clickDest = 7;
|
|
|
|
else // lower left
|
|
|
|
clickDest = 6;
|
|
|
|
} else { // middle
|
|
|
|
if (mouseDiffY < -8)
|
|
|
|
clickDest = 1; // upper
|
|
|
|
else if (mouseDiffY > 8)
|
|
|
|
clickDest = 5; // lower
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_buttons[clickedId]->setSelected(clickDest);
|
|
|
|
changeVolume(clickedId, clickDest);
|
|
|
|
}
|
|
|
|
} else if (_mouseState & BS1L_BUTTON_UP) {
|
|
|
|
_buttons[1]->setSelected(0);
|
|
|
|
_buttons[2]->setSelected(0);
|
|
|
|
_buttons[3]->setSelected(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::changeVolume(uint8 id, uint8 action) {
|
2004-01-07 17:47:46 +00:00
|
|
|
// ids: 1 = music, 2 = speech, 3 = sfx
|
|
|
|
uint8 volL = 0, volR = 0;
|
|
|
|
if (id == 1)
|
2005-07-30 21:11:48 +00:00
|
|
|
_music->giveVolume(&volL, &volR);
|
2004-01-07 17:47:46 +00:00
|
|
|
else if (id == 2)
|
|
|
|
_sound->giveSpeechVol(&volL, &volR);
|
|
|
|
else if (id == 3)
|
|
|
|
_sound->giveSfxVol(&volL, &volR);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-01-07 17:47:46 +00:00
|
|
|
int8 direction = 0;
|
|
|
|
if ((action >= 4) && (action <= 6)) // lower part of the button => decrease volume
|
|
|
|
direction = -1;
|
|
|
|
else if ((action == 8) || (action == 1) || (action == 2)) // upper part => increase volume
|
|
|
|
direction = 1;
|
|
|
|
else if ((action == 3) || (action == 7)) // middle part => pan volume
|
|
|
|
direction = 1;
|
|
|
|
int8 factorL = 8, factorR = 8;
|
|
|
|
if ((action >= 6) && (action <= 8)) { // left part => left pan
|
|
|
|
factorL = 8;
|
|
|
|
factorR = (action == 7) ? -8 : 0;
|
|
|
|
} else if ((action >= 2) && (action <= 4)) { // right part
|
|
|
|
factorR = 8;
|
|
|
|
factorL = (action == 3) ? -8 : 0;
|
|
|
|
}
|
|
|
|
int16 resVolL = volL + direction * factorL;
|
|
|
|
int16 resVolR = volR + direction * factorR;
|
|
|
|
|
|
|
|
volL = (uint8)MAX((int16)0, MIN(resVolL, (int16)255));
|
2005-07-30 21:11:48 +00:00
|
|
|
volR = (uint8)MAX((int16)0, MIN(resVolR, (int16)255));
|
2004-01-07 17:47:46 +00:00
|
|
|
|
|
|
|
if (id == 1)
|
|
|
|
_music->setVolume(volL, volR);
|
|
|
|
else if (id == 2)
|
|
|
|
_sound->setSpeechVol(volL, volR);
|
|
|
|
else if (id == 3)
|
|
|
|
_sound->setSfxVol(volL, volR);
|
|
|
|
|
|
|
|
renderVolumeBar(id, volL, volR);
|
2003-12-23 16:58:06 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
bool Control::getConfirm(const uint8 *title) {
|
2005-08-24 16:10:09 +00:00
|
|
|
ControlButton *panel = new ControlButton(0, 0, SR_CONFIRM, 0, 0, _resMan, _screenBuf, _system);
|
2004-01-04 06:31:29 +00:00
|
|
|
panel->draw();
|
|
|
|
delete panel;
|
|
|
|
renderText(title, 320, 160, TEXT_CENTER);
|
|
|
|
ControlButton *buttons[2];
|
2005-08-24 16:10:09 +00:00
|
|
|
buttons[0] = new ControlButton(260, 192 + 40, SR_BUTTON, 0, 0, _resMan, _screenBuf, _system);
|
2004-01-04 06:31:29 +00:00
|
|
|
renderText(_lStrings[STR_OK], 640 - 260, 192 + 40, TEXT_RIGHT_ALIGN);
|
2005-08-24 16:10:09 +00:00
|
|
|
buttons[1] = new ControlButton(260, 256 + 40, SR_BUTTON, 0, 0, _resMan, _screenBuf, _system);
|
2004-01-04 06:31:29 +00:00
|
|
|
renderText(_lStrings[STR_CANCEL], 640 - 260, 256 + 40, TEXT_RIGHT_ALIGN);
|
|
|
|
uint8 retVal = 0;
|
|
|
|
uint8 clickVal = 0;
|
|
|
|
do {
|
|
|
|
buttons[0]->draw();
|
|
|
|
buttons[1]->draw();
|
|
|
|
delay(1000 / 12);
|
2007-06-22 21:34:03 +00:00
|
|
|
if (_keyPressed.keycode == Common::KEYCODE_ESCAPE)
|
2005-08-24 16:10:09 +00:00
|
|
|
retVal = 2;
|
2007-06-22 21:34:03 +00:00
|
|
|
else if (_keyPressed.keycode == Common::KEYCODE_RETURN || _keyPressed.keycode == Common::KEYCODE_KP_ENTER)
|
2005-08-24 16:10:09 +00:00
|
|
|
retVal = 1;
|
2004-01-04 06:31:29 +00:00
|
|
|
if (_mouseState & BS1L_BUTTON_DOWN) {
|
2007-11-28 15:00:41 +00:00
|
|
|
if (buttons[0]->wasClicked(_mouseCoord.x, _mouseCoord.y))
|
2004-01-04 06:31:29 +00:00
|
|
|
clickVal = 1;
|
2007-11-28 15:00:41 +00:00
|
|
|
else if (buttons[1]->wasClicked(_mouseCoord.x, _mouseCoord.y))
|
2004-01-04 06:31:29 +00:00
|
|
|
clickVal = 2;
|
|
|
|
else
|
|
|
|
clickVal = 0;
|
|
|
|
if (clickVal)
|
|
|
|
buttons[clickVal - 1]->setSelected(1);
|
|
|
|
}
|
|
|
|
if ((_mouseState & BS1L_BUTTON_UP) && (clickVal)) {
|
2007-11-28 15:00:41 +00:00
|
|
|
if (buttons[clickVal - 1]->wasClicked(_mouseCoord.x, _mouseCoord.y))
|
2004-01-04 06:31:29 +00:00
|
|
|
retVal = clickVal;
|
|
|
|
else
|
|
|
|
buttons[clickVal - 1]->setSelected(0);
|
|
|
|
clickVal = 0;
|
|
|
|
}
|
|
|
|
} while (!retVal);
|
|
|
|
delete buttons[0];
|
|
|
|
delete buttons[1];
|
|
|
|
return retVal == 1;
|
|
|
|
}
|
|
|
|
|
2007-06-22 21:34:03 +00:00
|
|
|
bool Control::keyAccepted(uint16 ascii) {
|
2007-07-01 12:47:07 +00:00
|
|
|
static const char allowedSpecials[] = ",.:-()?! \"\'";
|
2007-06-22 21:34:03 +00:00
|
|
|
if (((ascii >= 'A') && (ascii <= 'Z')) ||
|
|
|
|
((ascii >= 'a') && (ascii <= 'z')) ||
|
|
|
|
((ascii >= '0') && (ascii <= '9')) ||
|
|
|
|
strchr(allowedSpecials, ascii))
|
2003-12-20 09:18:43 +00:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-22 21:34:03 +00:00
|
|
|
void Control::handleSaveKey(Common::KeyState kbd) {
|
2003-12-20 09:18:43 +00:00
|
|
|
if (_selectedSavegame < 255) {
|
2003-12-31 17:38:27 +00:00
|
|
|
uint8 len = strlen((char*)_saveNames[_selectedSavegame]);
|
2007-06-22 21:34:03 +00:00
|
|
|
if ((kbd.keycode == Common::KEYCODE_BACKSPACE) && len) // backspace
|
2003-12-20 09:18:43 +00:00
|
|
|
_saveNames[_selectedSavegame][len - 1] = '\0';
|
2007-06-22 21:34:03 +00:00
|
|
|
else if (keyAccepted(kbd.ascii) && (len < 31)) {
|
|
|
|
_saveNames[_selectedSavegame][len] = kbd.ascii;
|
2003-12-20 09:18:43 +00:00
|
|
|
_saveNames[_selectedSavegame][len + 1] = '\0';
|
|
|
|
}
|
|
|
|
showSavegameNames();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
bool Control::saveToFile(void) {
|
2003-12-31 17:38:27 +00:00
|
|
|
if ((_selectedSavegame == 255) || !strlen((char*)_saveNames[_selectedSavegame]))
|
2003-12-20 09:18:43 +00:00
|
|
|
return false; // no saveslot selected or no name entered
|
2008-10-20 04:39:10 +00:00
|
|
|
saveGameToFile(_selectedSavegame);
|
2003-12-20 09:18:43 +00:00
|
|
|
writeSavegameDescriptions();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
bool Control::restoreFromFile(void) {
|
2003-12-20 09:18:43 +00:00
|
|
|
if (_selectedSavegame < 255) {
|
2003-12-23 16:58:06 +00:00
|
|
|
return restoreGameFromFile(_selectedSavegame);
|
2003-12-20 09:18:43 +00:00
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::readSavegameDescriptions(void) {
|
2005-05-10 23:17:38 +00:00
|
|
|
Common::InSaveFile *inf;
|
2005-04-10 15:13:40 +00:00
|
|
|
inf = _saveFileMan->openForLoading("SAVEGAME.INF");
|
2003-12-20 09:18:43 +00:00
|
|
|
_saveScrollPos = _saveFiles = 0;
|
|
|
|
_selectedSavegame = 255;
|
2007-06-16 19:27:05 +00:00
|
|
|
for (uint8 cnt = 0; cnt < 64; cnt++) {
|
|
|
|
memset(_saveNames[cnt], 0, sizeof(_saveNames[cnt]));
|
|
|
|
}
|
2005-04-10 15:13:40 +00:00
|
|
|
if (inf) {
|
2003-12-20 09:18:43 +00:00
|
|
|
uint8 curFileNum = 0;
|
|
|
|
uint8 ch;
|
|
|
|
do {
|
|
|
|
uint8 pos = 0;
|
|
|
|
do {
|
|
|
|
ch = inf->readByte();
|
2007-06-16 19:27:05 +00:00
|
|
|
if (pos < sizeof(_saveNames[curFileNum]) - 1) {
|
|
|
|
if ((ch == 10) || (ch == 255) || (inf->eos()))
|
|
|
|
_saveNames[curFileNum][pos++] = '\0';
|
|
|
|
else if (ch >= 32)
|
|
|
|
_saveNames[curFileNum][pos++] = ch;
|
|
|
|
}
|
|
|
|
} while ((ch != 10) && (ch != 255) && (!inf->eos()));
|
2008-10-20 04:39:10 +00:00
|
|
|
curFileNum++;
|
2007-06-16 19:27:05 +00:00
|
|
|
} while ((ch != 255) && (!inf->eos()));
|
2003-12-28 19:03:35 +00:00
|
|
|
_saveFiles = curFileNum;
|
2008-08-15 20:49:56 +00:00
|
|
|
_numSaves = _saveFiles;
|
2007-06-16 19:27:05 +00:00
|
|
|
}
|
2003-12-20 09:18:43 +00:00
|
|
|
delete inf;
|
|
|
|
}
|
|
|
|
|
2004-03-28 12:59:51 +00:00
|
|
|
int Control::displayMessage(const char *altButton, const char *message, ...) {
|
2004-11-09 10:26:33 +00:00
|
|
|
char buf[STRINGBUFLEN];
|
2004-03-28 12:59:51 +00:00
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, message);
|
2005-04-09 01:52:44 +00:00
|
|
|
vsnprintf(buf, STRINGBUFLEN, message, va);
|
2004-03-28 12:59:51 +00:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
GUI::MessageDialog dialog(buf, "OK", altButton);
|
2004-07-18 17:47:19 +00:00
|
|
|
int result = dialog.runModal();
|
|
|
|
_mouse->setPointer(MSE_POINTER, 0);
|
|
|
|
return result;
|
2004-03-28 12:59:51 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::writeSavegameDescriptions(void) {
|
2005-05-10 23:17:38 +00:00
|
|
|
Common::OutSaveFile *outf;
|
2005-04-10 15:13:40 +00:00
|
|
|
outf = _saveFileMan->openForSaving("SAVEGAME.INF");
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-03-28 12:59:51 +00:00
|
|
|
if (!outf) {
|
|
|
|
// Display an error message, and do nothing
|
2007-12-28 07:37:04 +00:00
|
|
|
displayMessage(0, "Can't create SAVEGAME.INF. (%s)", _saveFileMan->popErrorDesc().c_str());
|
2004-03-28 12:59:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-20 09:18:43 +00:00
|
|
|
// if the player accidently clicked the last slot and then deselected it again,
|
|
|
|
// we'd still have _saveFiles == 64, so get rid of the empty end.
|
2003-12-31 17:38:27 +00:00
|
|
|
while (strlen((char*)_saveNames[_saveFiles - 1]) == 0)
|
2003-12-20 09:18:43 +00:00
|
|
|
_saveFiles--;
|
|
|
|
for (uint8 cnt = 0; cnt < _saveFiles; cnt++) {
|
2005-11-08 07:28:31 +00:00
|
|
|
int len = strlen((char*)_saveNames[cnt]);
|
|
|
|
if (len > 0)
|
|
|
|
outf->write(_saveNames[cnt], len);
|
2003-12-20 09:18:43 +00:00
|
|
|
if (cnt < _saveFiles - 1)
|
|
|
|
outf->writeByte(10);
|
|
|
|
else
|
|
|
|
outf->writeByte(255);
|
|
|
|
}
|
2007-02-17 18:55:51 +00:00
|
|
|
outf->finalize();
|
2005-10-26 06:30:28 +00:00
|
|
|
if (outf->ioFailed())
|
2007-12-28 07:37:04 +00:00
|
|
|
displayMessage(0, "Can't write to SAVEGAME.INF. Device full? (%s)", _saveFileMan->popErrorDesc().c_str());
|
2003-12-20 09:18:43 +00:00
|
|
|
delete outf;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
bool Control::savegamesExist(void) {
|
2003-12-30 22:57:52 +00:00
|
|
|
bool retVal = false;
|
2005-05-10 23:17:38 +00:00
|
|
|
Common::InSaveFile *inf;
|
2005-04-10 15:13:40 +00:00
|
|
|
inf = _saveFileMan->openForLoading("SAVEGAME.INF");
|
|
|
|
if (inf)
|
2003-12-30 22:57:52 +00:00
|
|
|
retVal = true;
|
|
|
|
delete inf;
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::showSavegameNames(void) {
|
2003-12-20 09:18:43 +00:00
|
|
|
for (uint8 cnt = 0; cnt < 8; cnt++) {
|
|
|
|
_buttons[cnt]->draw();
|
2003-12-29 15:38:16 +00:00
|
|
|
uint8 textMode = TEXT_LEFT_ALIGN;
|
|
|
|
uint16 ycoord = _saveButtons[cnt].y + 2;
|
2004-05-12 06:21:44 +00:00
|
|
|
uint8 str[40];
|
|
|
|
sprintf((char*)str, "%d. %s", cnt + _saveScrollPos + 1, _saveNames[cnt + _saveScrollPos]);
|
2003-12-29 15:38:16 +00:00
|
|
|
if (cnt + _saveScrollPos == _selectedSavegame) {
|
|
|
|
textMode |= TEXT_RED_FONT;
|
|
|
|
ycoord += 2;
|
2004-05-12 06:21:44 +00:00
|
|
|
if (_cursorVisible)
|
|
|
|
strcat((char*)str, "_");
|
2003-12-29 15:38:16 +00:00
|
|
|
}
|
2004-05-12 06:21:44 +00:00
|
|
|
renderText(str, _saveButtons[cnt].x + 6, ycoord, textMode);
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::saveNameSelect(uint8 id, bool saving) {
|
2003-12-20 09:18:43 +00:00
|
|
|
deselectSaveslots();
|
|
|
|
_buttons[id - BUTTON_SAVE_SELECT1]->setSelected(1);
|
|
|
|
uint8 num = (id - BUTTON_SAVE_SELECT1) + _saveScrollPos;
|
|
|
|
if (saving && (_selectedSavegame != 255)) // the player may have entered something, clear it again
|
2003-12-31 17:38:27 +00:00
|
|
|
strcpy((char*)_saveNames[_selectedSavegame], (char*)_oldName);
|
2003-12-20 09:18:43 +00:00
|
|
|
if (num < _saveFiles) {
|
2003-12-28 19:03:35 +00:00
|
|
|
_selectedSavegame = num;
|
2003-12-31 17:38:27 +00:00
|
|
|
strcpy((char*)_oldName, (char*)_saveNames[num]); // save for later
|
2003-12-20 09:18:43 +00:00
|
|
|
} else {
|
|
|
|
if (!saving)
|
|
|
|
_buttons[id - BUTTON_SAVE_SELECT1]->setSelected(0); // no save in slot, deselect it
|
|
|
|
else {
|
|
|
|
if (_saveFiles <= num)
|
|
|
|
_saveFiles = num + 1;
|
|
|
|
_selectedSavegame = num;
|
|
|
|
_oldName[0] = '\0';
|
|
|
|
}
|
|
|
|
}
|
2004-05-12 06:21:44 +00:00
|
|
|
if (_selectedSavegame < 255)
|
|
|
|
_cursorTick = 0;
|
2003-12-20 09:18:43 +00:00
|
|
|
showSavegameNames();
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::saveNameScroll(uint8 scroll, bool saving) {
|
2003-12-20 09:18:43 +00:00
|
|
|
uint16 maxScroll;
|
|
|
|
if (saving)
|
|
|
|
maxScroll = 64;
|
|
|
|
else
|
|
|
|
maxScroll = _saveFiles; // for loading, we can only scroll as far as there are savegames
|
|
|
|
if (scroll == BUTTON_SCROLL_UP_FAST) {
|
|
|
|
if (_saveScrollPos >= 8)
|
|
|
|
_saveScrollPos -= 8;
|
|
|
|
else
|
|
|
|
_saveScrollPos = 0;
|
|
|
|
} else if (scroll == BUTTON_SCROLL_UP_SLOW) {
|
|
|
|
if (_saveScrollPos >= 1)
|
|
|
|
_saveScrollPos--;
|
|
|
|
} else if (scroll == BUTTON_SCROLL_DOWN_SLOW) {
|
2005-10-16 15:06:51 +00:00
|
|
|
if (_saveScrollPos + 8 < maxScroll)
|
2003-12-20 09:18:43 +00:00
|
|
|
_saveScrollPos++;
|
|
|
|
} else if (scroll == BUTTON_SCROLL_DOWN_FAST) {
|
2005-10-16 15:06:51 +00:00
|
|
|
if (_saveScrollPos + 16 < maxScroll)
|
2003-12-20 09:18:43 +00:00
|
|
|
_saveScrollPos += 8;
|
2005-10-16 15:06:51 +00:00
|
|
|
else {
|
|
|
|
if (maxScroll >= 8)
|
|
|
|
_saveScrollPos = maxScroll - 8;
|
|
|
|
else
|
|
|
|
_saveScrollPos = 0;
|
|
|
|
}
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
_selectedSavegame = 255; // deselect savegame
|
|
|
|
deselectSaveslots();
|
|
|
|
showSavegameNames();
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::createButtons(const ButtonInfo *buttons, uint8 num) {
|
2003-12-20 09:18:43 +00:00
|
|
|
for (uint8 cnt = 0; cnt < num; cnt++) {
|
2005-08-24 16:10:09 +00:00
|
|
|
_buttons[cnt] = new ControlButton(buttons[cnt].x, buttons[cnt].y, buttons[cnt].resId, buttons[cnt].id, buttons[cnt].flag, _resMan, _screenBuf, _system);
|
2003-12-20 09:18:43 +00:00
|
|
|
_buttons[cnt]->draw();
|
|
|
|
}
|
|
|
|
_numButtons = num;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::destroyButtons(void) {
|
2003-12-20 09:18:43 +00:00
|
|
|
for (uint8 cnt = 0; cnt < _numButtons; cnt++)
|
|
|
|
delete _buttons[cnt];
|
|
|
|
_numButtons = 0;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
uint16 Control::getTextWidth(const uint8 *str) {
|
2003-12-20 09:18:43 +00:00
|
|
|
uint16 width = 0;
|
|
|
|
while (*str) {
|
2006-11-12 19:05:51 +00:00
|
|
|
width += _resMan->getUint16(_resMan->fetchFrame(_font, *str - 32)->width) - 3;
|
2003-12-20 09:18:43 +00:00
|
|
|
str++;
|
|
|
|
}
|
2003-12-28 19:03:35 +00:00
|
|
|
return width;
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::renderText(const uint8 *str, uint16 x, uint16 y, uint8 mode) {
|
2003-12-29 15:38:16 +00:00
|
|
|
uint8 *font = _font;
|
2004-05-12 06:21:44 +00:00
|
|
|
if (mode & TEXT_RED_FONT) {
|
|
|
|
mode &= ~TEXT_RED_FONT;
|
2003-12-29 15:38:16 +00:00
|
|
|
font = _redFont;
|
2004-05-12 06:21:44 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-23 16:58:06 +00:00
|
|
|
if (mode == TEXT_RIGHT_ALIGN) // negative x coordinate means right-aligned.
|
|
|
|
x -= getTextWidth(str);
|
|
|
|
else if (mode == TEXT_CENTER)
|
|
|
|
x -= getTextWidth(str) / 2;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-20 09:18:43 +00:00
|
|
|
uint16 destX = x;
|
|
|
|
while (*str) {
|
|
|
|
uint8 *dst = _screenBuf + y * SCREEN_WIDTH + destX;
|
|
|
|
|
2003-12-31 17:38:27 +00:00
|
|
|
FrameHeader *chSpr = _resMan->fetchFrame(font, *str - 32);
|
2003-12-20 09:18:43 +00:00
|
|
|
uint8 *sprData = (uint8*)chSpr + sizeof(FrameHeader);
|
2006-11-12 19:05:51 +00:00
|
|
|
for (uint16 cnty = 0; cnty < _resMan->getUint16(chSpr->height); cnty++) {
|
|
|
|
for (uint16 cntx = 0; cntx < _resMan->getUint16(chSpr->width); cntx++) {
|
2003-12-20 09:18:43 +00:00
|
|
|
if (sprData[cntx])
|
|
|
|
dst[cntx] = sprData[cntx];
|
|
|
|
}
|
2006-11-12 19:05:51 +00:00
|
|
|
sprData += _resMan->getUint16(chSpr->width);
|
2003-12-20 09:18:43 +00:00
|
|
|
dst += SCREEN_WIDTH;
|
|
|
|
}
|
2006-11-12 19:05:51 +00:00
|
|
|
destX += _resMan->getUint16(chSpr->width) - 3;
|
2003-12-20 09:18:43 +00:00
|
|
|
str++;
|
|
|
|
}
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(_screenBuf + y * SCREEN_WIDTH + x, SCREEN_WIDTH, x, y, (destX - x) + 3, 28);
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::renderVolumeBar(uint8 id, uint8 volL, uint8 volR) {
|
2004-01-07 17:47:46 +00:00
|
|
|
uint16 destX = _volumeButtons[id].x + 20;
|
|
|
|
uint16 destY = _volumeButtons[id].y + 116;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-01-07 17:47:46 +00:00
|
|
|
for (uint8 chCnt = 0; chCnt < 2; chCnt++) {
|
|
|
|
uint8 vol = (chCnt == 0) ? volL : volR;
|
|
|
|
FrameHeader *frHead = _resMan->fetchFrame(_resMan->openFetchRes(SR_VLIGHT), (vol + 15) >> 4);
|
|
|
|
uint8 *destMem = _screenBuf + destY * SCREEN_WIDTH + destX;
|
|
|
|
uint8 *srcMem = (uint8*)frHead + sizeof(FrameHeader);
|
2006-11-12 19:05:51 +00:00
|
|
|
for (uint16 cnty = 0; cnty < _resMan->getUint16(frHead->height); cnty++) {
|
|
|
|
memcpy(destMem, srcMem, _resMan->getUint16(frHead->width));
|
|
|
|
srcMem += _resMan->getUint16(frHead->width);
|
2004-01-07 17:47:46 +00:00
|
|
|
destMem += SCREEN_WIDTH;
|
|
|
|
}
|
2006-11-12 19:05:51 +00:00
|
|
|
_system->copyRectToScreen(_screenBuf + destY * SCREEN_WIDTH + destX, SCREEN_WIDTH, destX, destY, _resMan->getUint16(frHead->width), _resMan->getUint16(frHead->height));
|
2004-01-07 17:47:46 +00:00
|
|
|
_resMan->resClose(SR_VLIGHT);
|
|
|
|
destX += 32;
|
|
|
|
}
|
2003-12-23 16:58:06 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::saveGameToFile(uint8 slot) {
|
2003-12-20 09:18:43 +00:00
|
|
|
char fName[15];
|
2003-12-23 00:59:18 +00:00
|
|
|
uint16 cnt;
|
2003-12-20 09:18:43 +00:00
|
|
|
sprintf(fName, "SAVEGAME.%03d", slot);
|
|
|
|
uint16 liveBuf[TOTAL_SECTIONS];
|
2005-05-10 23:17:38 +00:00
|
|
|
Common::OutSaveFile *outf;
|
2005-04-10 15:13:40 +00:00
|
|
|
outf = _saveFileMan->openForSaving(fName);
|
|
|
|
if (!outf) {
|
2005-10-26 06:30:28 +00:00
|
|
|
// Display an error message and do nothing
|
2007-12-28 07:37:04 +00:00
|
|
|
displayMessage(0, "Unable to create file '%s'. (%s)", fName, _saveFileMan->popErrorDesc().c_str());
|
2004-03-28 12:59:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-12-20 09:18:43 +00:00
|
|
|
|
|
|
|
_objMan->saveLiveList(liveBuf);
|
2003-12-23 00:59:18 +00:00
|
|
|
for (cnt = 0; cnt < TOTAL_SECTIONS; cnt++)
|
2003-12-20 09:18:43 +00:00
|
|
|
outf->writeUint16LE(liveBuf[cnt]);
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
Object *cpt = _objMan->fetchObject(PLAYER);
|
|
|
|
Logic::_scriptVars[CHANGE_DIR] = cpt->o_dir;
|
|
|
|
Logic::_scriptVars[CHANGE_X] = cpt->o_xcoord;
|
|
|
|
Logic::_scriptVars[CHANGE_Y] = cpt->o_ycoord;
|
|
|
|
Logic::_scriptVars[CHANGE_STANCE] = STAND;
|
|
|
|
Logic::_scriptVars[CHANGE_PLACE] = cpt->o_place;
|
2003-12-20 09:18:43 +00:00
|
|
|
|
2003-12-23 00:59:18 +00:00
|
|
|
for (cnt = 0; cnt < NUM_SCRIPT_VARS; cnt++)
|
2004-01-11 15:47:41 +00:00
|
|
|
outf->writeUint32LE(Logic::_scriptVars[cnt]);
|
2003-12-20 09:18:43 +00:00
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
uint32 playerSize = (sizeof(Object) - 12000) / 4;
|
2003-12-20 09:18:43 +00:00
|
|
|
uint32 *playerRaw = (uint32*)cpt;
|
2003-12-23 00:59:18 +00:00
|
|
|
for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++)
|
|
|
|
outf->writeUint32LE(playerRaw[cnt2]);
|
2007-02-17 18:55:51 +00:00
|
|
|
outf->finalize();
|
2005-10-26 06:30:28 +00:00
|
|
|
if (outf->ioFailed())
|
2007-12-28 07:37:04 +00:00
|
|
|
displayMessage(0, "Couldn't write to file '%s'. Device full? (%s)", fName, _saveFileMan->popErrorDesc().c_str());
|
2003-12-20 09:18:43 +00:00
|
|
|
delete outf;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
bool Control::restoreGameFromFile(uint8 slot) {
|
2003-12-20 09:18:43 +00:00
|
|
|
char fName[15];
|
2003-12-23 00:59:18 +00:00
|
|
|
uint16 cnt;
|
2003-12-20 09:18:43 +00:00
|
|
|
sprintf(fName, "SAVEGAME.%03d", slot);
|
2005-05-10 23:17:38 +00:00
|
|
|
Common::InSaveFile *inf;
|
2005-04-10 15:13:40 +00:00
|
|
|
inf = _saveFileMan->openForLoading(fName);
|
|
|
|
if (!inf) {
|
2004-03-28 12:59:51 +00:00
|
|
|
// Display an error message, and do nothing
|
2007-12-28 07:37:04 +00:00
|
|
|
displayMessage(0, "Can't open file '%s'. (%s)", fName, _saveFileMan->popErrorDesc().c_str());
|
2003-12-23 16:58:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
2003-12-20 09:18:43 +00:00
|
|
|
|
|
|
|
_restoreBuf = (uint8*)malloc(
|
2005-07-30 21:11:48 +00:00
|
|
|
TOTAL_SECTIONS * 2 +
|
2003-12-20 09:18:43 +00:00
|
|
|
NUM_SCRIPT_VARS * 4 +
|
2004-01-11 15:47:41 +00:00
|
|
|
(sizeof(Object) - 12000));
|
2003-12-20 09:18:43 +00:00
|
|
|
|
|
|
|
uint16 *liveBuf = (uint16*)_restoreBuf;
|
|
|
|
uint32 *scriptBuf = (uint32*)(_restoreBuf + 2 * TOTAL_SECTIONS);
|
|
|
|
uint32 *playerBuf = (uint32*)(_restoreBuf + 2 * TOTAL_SECTIONS + 4 * NUM_SCRIPT_VARS);
|
|
|
|
|
2003-12-23 00:59:18 +00:00
|
|
|
for (cnt = 0; cnt < TOTAL_SECTIONS; cnt++)
|
2003-12-20 09:18:43 +00:00
|
|
|
liveBuf[cnt] = inf->readUint16LE();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-23 00:59:18 +00:00
|
|
|
for (cnt = 0; cnt < NUM_SCRIPT_VARS; cnt++)
|
2003-12-20 09:18:43 +00:00
|
|
|
scriptBuf[cnt] = inf->readUint32LE();
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
uint32 playerSize = (sizeof(Object) - 12000) / 4;
|
2003-12-23 00:59:18 +00:00
|
|
|
for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++)
|
|
|
|
playerBuf[cnt2] = inf->readUint32LE();
|
2003-12-20 09:18:43 +00:00
|
|
|
|
2005-10-26 06:30:28 +00:00
|
|
|
if (inf->ioFailed()) {
|
2007-12-28 07:37:04 +00:00
|
|
|
displayMessage(0, "Can't read from file '%s'. (%s)", fName, _saveFileMan->popErrorDesc().c_str());
|
2005-10-26 06:30:28 +00:00
|
|
|
delete inf;
|
|
|
|
free(_restoreBuf);
|
|
|
|
_restoreBuf = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
2003-12-20 09:18:43 +00:00
|
|
|
delete inf;
|
2003-12-23 16:58:06 +00:00
|
|
|
return true;
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::doRestore(void) {
|
2003-12-20 09:18:43 +00:00
|
|
|
uint8 *bufPos = _restoreBuf;
|
|
|
|
_objMan->loadLiveList((uint16*)bufPos);
|
|
|
|
bufPos += TOTAL_SECTIONS * 2;
|
|
|
|
for (uint16 cnt = 0; cnt < NUM_SCRIPT_VARS; cnt++) {
|
2004-01-11 15:47:41 +00:00
|
|
|
Logic::_scriptVars[cnt] = *(uint32*)bufPos;
|
2003-12-20 09:18:43 +00:00
|
|
|
bufPos += 4;
|
|
|
|
}
|
2004-01-11 15:47:41 +00:00
|
|
|
uint32 playerSize = (sizeof(Object) - 12000) / 4;
|
2003-12-20 09:18:43 +00:00
|
|
|
uint32 *playerRaw = (uint32*)_objMan->fetchObject(PLAYER);
|
2004-01-11 15:47:41 +00:00
|
|
|
Object *cpt = _objMan->fetchObject(PLAYER);
|
2003-12-23 00:59:18 +00:00
|
|
|
for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++) {
|
2003-12-20 09:18:43 +00:00
|
|
|
*playerRaw = *(uint32*)bufPos;
|
|
|
|
playerRaw++;
|
|
|
|
bufPos += 4;
|
|
|
|
}
|
2003-12-28 19:03:35 +00:00
|
|
|
free(_restoreBuf);
|
2004-01-11 15:47:41 +00:00
|
|
|
Logic::_scriptVars[CHANGE_DIR] = cpt->o_dir;
|
|
|
|
Logic::_scriptVars[CHANGE_X] = cpt->o_xcoord;
|
|
|
|
Logic::_scriptVars[CHANGE_Y] = cpt->o_ycoord;
|
|
|
|
Logic::_scriptVars[CHANGE_STANCE] = STAND;
|
|
|
|
Logic::_scriptVars[CHANGE_PLACE] = cpt->o_place;
|
2003-12-20 20:20:53 +00:00
|
|
|
SwordEngine::_systemVars.justRestoredGame = 1;
|
2004-11-15 08:23:09 +00:00
|
|
|
if (SwordEngine::_systemVars.isDemo)
|
|
|
|
Logic::_scriptVars[PLAYINGDEMO] = 1;
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Control::delay(uint32 msecs) {
|
2007-03-17 19:02:05 +00:00
|
|
|
Common::Event event;
|
2003-12-20 09:18:43 +00:00
|
|
|
|
2005-08-25 15:33:38 +00:00
|
|
|
uint32 now = _system->getMillis();
|
|
|
|
uint32 endTime = now + msecs;
|
2007-06-22 22:19:17 +00:00
|
|
|
_keyPressed.reset();
|
2003-12-20 09:18:43 +00:00
|
|
|
_mouseState = 0;
|
|
|
|
|
|
|
|
do {
|
2007-03-17 00:53:21 +00:00
|
|
|
Common::EventManager *eventMan = _system->getEventManager();
|
|
|
|
while (eventMan->pollEvent(event)) {
|
2004-12-05 17:42:20 +00:00
|
|
|
switch (event.type) {
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_KEYDOWN:
|
2007-06-22 21:34:03 +00:00
|
|
|
_keyPressed = event.kbd;
|
2005-10-26 06:16:14 +00:00
|
|
|
// we skip the rest of the delay and return immediately
|
|
|
|
// to handle keyboard input
|
|
|
|
return;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_MOUSEMOVE:
|
2007-11-28 15:00:41 +00:00
|
|
|
_mouseCoord = event.mouse;
|
2003-12-20 09:18:43 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2004-01-07 17:47:46 +00:00
|
|
|
_mouseDown = true;
|
2003-12-20 09:18:43 +00:00
|
|
|
_mouseState |= BS1L_BUTTON_DOWN;
|
2007-11-28 15:00:41 +00:00
|
|
|
_mouseCoord = event.mouse;
|
2003-12-20 09:18:43 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_LBUTTONUP:
|
2004-01-07 17:47:46 +00:00
|
|
|
_mouseDown = false;
|
2003-12-20 09:18:43 +00:00
|
|
|
_mouseState |= BS1L_BUTTON_UP;
|
2007-11-28 15:00:41 +00:00
|
|
|
_mouseCoord = event.mouse;
|
2003-12-20 09:18:43 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_WHEELUP:
|
2004-05-12 06:21:44 +00:00
|
|
|
_mouseDown = false;
|
|
|
|
_mouseState |= BS1_WHEEL_UP;
|
2007-11-28 15:00:41 +00:00
|
|
|
_mouseCoord = event.mouse;
|
2004-05-12 06:21:44 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_WHEELDOWN:
|
2004-05-12 06:21:44 +00:00
|
|
|
_mouseDown = false;
|
|
|
|
_mouseState |= BS1_WHEEL_DOWN;
|
|
|
|
break;
|
2003-12-20 09:18:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-11-05 19:26:26 +00:00
|
|
|
|
2006-04-18 00:20:07 +00:00
|
|
|
_system->updateScreen();
|
2004-09-28 20:19:37 +00:00
|
|
|
_system->delayMillis(10);
|
|
|
|
} while (_system->getMillis() < endTime);
|
2003-12-20 09:18:43 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
const ButtonInfo Control::_deathButtons[3] = {
|
2005-08-24 16:10:09 +00:00
|
|
|
{250, 224 + 40, SR_BUTTON, BUTTON_RESTORE_PANEL, 0 },
|
|
|
|
{250, 260 + 40, SR_BUTTON, BUTTON_RESTART, kButtonOk },
|
|
|
|
{250, 296 + 40, SR_BUTTON, BUTTON_QUIT, kButtonCancel }
|
2003-12-20 09:18:43 +00:00
|
|
|
};
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
const ButtonInfo Control::_panelButtons[7] = {
|
2005-08-24 16:10:09 +00:00
|
|
|
{145, 188 + 40, SR_BUTTON, BUTTON_SAVE_PANEL, 0 },
|
|
|
|
{145, 224 + 40, SR_BUTTON, BUTTON_RESTORE_PANEL, 0 },
|
|
|
|
{145, 260 + 40, SR_BUTTON, BUTTON_RESTART, 0 },
|
|
|
|
{145, 296 + 40, SR_BUTTON, BUTTON_QUIT, kButtonCancel },
|
|
|
|
{475, 188 + 40, SR_BUTTON, BUTTON_VOLUME_PANEL, 0 },
|
|
|
|
{475, 224 + 40, SR_TEXT_BUTTON, BUTTON_TEXT, 0 },
|
|
|
|
{475, 332 + 40, SR_BUTTON, BUTTON_DONE, kButtonOk }
|
2003-12-20 09:18:43 +00:00
|
|
|
};
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
const ButtonInfo Control::_saveButtons[16] = {
|
2005-08-24 16:10:09 +00:00
|
|
|
{114, 32 + 40, SR_SLAB1, BUTTON_SAVE_SELECT1, 0 },
|
|
|
|
{114, 68 + 40, SR_SLAB2, BUTTON_SAVE_SELECT2, 0 },
|
|
|
|
{114, 104 + 40, SR_SLAB3, BUTTON_SAVE_SELECT3, 0 },
|
|
|
|
{114, 140 + 40, SR_SLAB4, BUTTON_SAVE_SELECT4, 0 },
|
|
|
|
{114, 176 + 40, SR_SLAB1, BUTTON_SAVE_SELECT5, 0 },
|
|
|
|
{114, 212 + 40, SR_SLAB2, BUTTON_SAVE_SELECT6, 0 },
|
|
|
|
{114, 248 + 40, SR_SLAB3, BUTTON_SAVE_SELECT7, 0 },
|
|
|
|
{114, 284 + 40, SR_SLAB4, BUTTON_SAVE_SELECT8, 0 },
|
|
|
|
|
|
|
|
{516, 25 + 40, SR_BUTUF, BUTTON_SCROLL_UP_FAST, 0 },
|
|
|
|
{516, 45 + 40, SR_BUTUS, BUTTON_SCROLL_UP_SLOW, 0 },
|
|
|
|
{516, 289 + 40, SR_BUTDS, BUTTON_SCROLL_DOWN_SLOW, 0 },
|
|
|
|
{516, 310 + 40, SR_BUTDF, BUTTON_SCROLL_DOWN_FAST, 0 },
|
|
|
|
|
|
|
|
{125, 338 + 40, SR_BUTTON, BUTTON_SAVE_RESTORE_OKAY, kButtonOk},
|
|
|
|
{462, 338 + 40, SR_BUTTON, BUTTON_SAVE_CANCEL, kButtonCancel }
|
2003-12-20 09:18:43 +00:00
|
|
|
};
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
const ButtonInfo Control::_volumeButtons[4] = {
|
2005-08-24 16:10:09 +00:00
|
|
|
{ 478, 338 + 40, SR_BUTTON, BUTTON_MAIN_PANEL, kButtonOk },
|
|
|
|
{ 138, 135, SR_VKNOB, 0, 0 },
|
|
|
|
{ 273, 135, SR_VKNOB, 0, 0 },
|
|
|
|
{ 404, 135, SR_VKNOB, 0, 0 },
|
2003-12-23 16:58:06 +00:00
|
|
|
};
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
const uint8 Control::_languageStrings[8 * 20][43] = {
|
2003-12-20 09:18:43 +00:00
|
|
|
// BS1_ENGLISH:
|
|
|
|
"PAUSED",
|
|
|
|
"PLEASE INSERT CD-",
|
|
|
|
"THEN PRESS A KEY",
|
|
|
|
"INCORRECT CD",
|
|
|
|
"Save",
|
|
|
|
"Restore",
|
|
|
|
"Restart",
|
|
|
|
"Start",
|
|
|
|
"Quit",
|
|
|
|
"Speed",
|
|
|
|
"Volume",
|
|
|
|
"Text",
|
|
|
|
"Done",
|
|
|
|
"OK",
|
|
|
|
"Cancel",
|
|
|
|
"Music",
|
|
|
|
"Speech",
|
|
|
|
"Fx",
|
|
|
|
"The End",
|
|
|
|
"DRIVE FULL!",
|
|
|
|
// BS1_FRENCH:
|
|
|
|
"PAUSE",
|
2003-12-31 16:56:16 +00:00
|
|
|
"INS\xC9REZ LE CD-",
|
2003-12-20 09:18:43 +00:00
|
|
|
"ET APPUYES SUR UNE TOUCHE",
|
|
|
|
"CD INCORRECT",
|
|
|
|
"Sauvegarder",
|
|
|
|
"Recharger",
|
|
|
|
"Recommencer",
|
|
|
|
"Commencer",
|
2003-12-31 16:56:16 +00:00
|
|
|
"Quitter",
|
2003-12-20 09:18:43 +00:00
|
|
|
"Vitesse",
|
|
|
|
"Volume",
|
|
|
|
"Texte",
|
|
|
|
"Termin\xE9",
|
|
|
|
"OK",
|
|
|
|
"Annuler",
|
|
|
|
"Musique",
|
|
|
|
"Voix",
|
|
|
|
"Fx",
|
|
|
|
"Fin",
|
|
|
|
"DISQUE PLEIN!",
|
|
|
|
//BS1_GERMAN:
|
|
|
|
"PAUSE",
|
|
|
|
"BITTE LEGEN SIE CD-",
|
|
|
|
"EIN UND DR\xDC CKEN SIE EINE BELIEBIGE TASTE",
|
|
|
|
"FALSCHE CD",
|
|
|
|
"Speichern",
|
|
|
|
"Laden",
|
|
|
|
"Neues Spiel",
|
|
|
|
"Start",
|
|
|
|
"Beenden",
|
|
|
|
"Geschwindigkeit",
|
|
|
|
"Lautst\xE4rke",
|
|
|
|
"Text",
|
|
|
|
"Fertig",
|
|
|
|
"OK",
|
|
|
|
"Abbrechen",
|
|
|
|
"Musik",
|
|
|
|
"Sprache",
|
|
|
|
"Fx",
|
|
|
|
"Ende",
|
|
|
|
"DRIVE FULL!",
|
|
|
|
//BS1_ITALIAN:
|
|
|
|
"PAUSA",
|
|
|
|
"INSERITE IL CD-",
|
|
|
|
"E PREMETE UN TASTO",
|
|
|
|
"CD ERRATO",
|
|
|
|
"Salva",
|
|
|
|
"Ripristina",
|
|
|
|
"Ricomincia",
|
|
|
|
"Inizio",
|
2003-12-31 16:56:16 +00:00
|
|
|
"Esci",
|
2003-12-20 09:18:43 +00:00
|
|
|
"Velocit\xE0",
|
|
|
|
"Volume",
|
|
|
|
"Testo",
|
|
|
|
"Fatto",
|
|
|
|
"OK",
|
2008-06-01 18:37:35 +00:00
|
|
|
"Annulla",
|
2003-12-20 09:18:43 +00:00
|
|
|
"Musica",
|
|
|
|
"Parlato",
|
|
|
|
"Fx",
|
|
|
|
"Fine",
|
|
|
|
"DISCO PIENO!",
|
|
|
|
//BS1_SPANISH:
|
|
|
|
"PAUSA",
|
|
|
|
"POR FAVOR INTRODUCE EL CD-",
|
|
|
|
"Y PULSA UNA TECLA",
|
|
|
|
"CD INCORRECTO",
|
|
|
|
"Guardar",
|
|
|
|
"Recuperar",
|
|
|
|
"Reiniciar",
|
|
|
|
"Empezar",
|
|
|
|
"Abandonar",
|
|
|
|
"Velocidad",
|
|
|
|
"Volumen",
|
|
|
|
"Texto",
|
|
|
|
"Hecho",
|
|
|
|
"OK",
|
|
|
|
"Cancelar",
|
|
|
|
"M\xFAsica",
|
|
|
|
"Di\xE1logo",
|
|
|
|
"Fx",
|
|
|
|
"Fin",
|
|
|
|
"DISCO LLENO",
|
|
|
|
// BS1_CZECH:
|
|
|
|
"\xAC\x41S SE ZASTAVIL",
|
|
|
|
"VLO\xA6TE DO MECHANIKY CD DISK",
|
|
|
|
"PAK STISKN\xB7TE LIBOVOLNOU KL\xB5VESU",
|
|
|
|
"TO NEBUDE TO SPR\xB5VN\x90 CD",
|
|
|
|
"Ulo\xA7it pozici",
|
|
|
|
"Nahr\xA0t pozici",
|
|
|
|
"Za\x9F\xA1t znovu",
|
|
|
|
"Start",
|
|
|
|
"Ukon\x9Fit hru",
|
|
|
|
"Rychlost",
|
|
|
|
"Hlasitost",
|
|
|
|
"Titulky",
|
|
|
|
"Souhlas\xA1m",
|
|
|
|
"Ano",
|
|
|
|
"Ne",
|
|
|
|
"Hudba",
|
|
|
|
"Mluven, slovo",
|
|
|
|
"Zvuky",
|
|
|
|
"Konec",
|
|
|
|
"Disk pln\xEC",
|
|
|
|
//BS1_PORTUGESE:
|
|
|
|
"PAUSA",
|
|
|
|
"FAVOR INSERIR CD",
|
|
|
|
"E DIGITAR UMA TECLA",
|
|
|
|
"CD INCORRETO",
|
|
|
|
"Salvar",
|
|
|
|
"Restaurar",
|
|
|
|
"Reiniciar",
|
|
|
|
"Iniciar",
|
|
|
|
"Sair",
|
|
|
|
"Velocidade",
|
|
|
|
"Volume",
|
|
|
|
"Texto",
|
|
|
|
"Feito",
|
|
|
|
"OK",
|
|
|
|
"Cancelar",
|
|
|
|
"M\xFAsica",
|
|
|
|
"Voz",
|
|
|
|
"Efeitos",
|
2003-12-28 19:03:35 +00:00
|
|
|
"Fim",
|
2003-12-20 09:18:43 +00:00
|
|
|
"UNIDADE CHEIA!",
|
|
|
|
};
|
2004-01-11 15:47:41 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword1
|