2011-06-10 05:45:18 +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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on original Soltys source code
|
|
|
|
* Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
|
|
|
|
*/
|
|
|
|
|
2011-09-04 12:28:12 +00:00
|
|
|
#include "gui/saveload.h"
|
|
|
|
#include "gui/about.h"
|
|
|
|
#include "gui/message.h"
|
|
|
|
#include "common/config-manager.h"
|
2011-07-02 08:38:25 +00:00
|
|
|
#include "common/events.h"
|
2012-02-22 15:30:39 +00:00
|
|
|
#include "engines/advancedDetector.h"
|
2011-07-02 06:19:36 +00:00
|
|
|
#include "cge/events.h"
|
|
|
|
#include "cge/events.h"
|
|
|
|
#include "cge/text.h"
|
|
|
|
#include "cge/cge_main.h"
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-10 20:57:09 +00:00
|
|
|
namespace CGE {
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-02 06:19:36 +00:00
|
|
|
/*----------------- KEYBOARD interface -----------------*/
|
|
|
|
|
2011-09-04 12:28:12 +00:00
|
|
|
Keyboard::Keyboard(CGEEngine *vm) : _client(NULL), _vm(vm) {
|
2011-11-30 18:52:19 +00:00
|
|
|
_keyAlt = false;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 23:02:14 +00:00
|
|
|
Keyboard::~Keyboard() {
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 23:02:14 +00:00
|
|
|
Sprite *Keyboard::setClient(Sprite *spr) {
|
2011-09-05 22:16:07 +00:00
|
|
|
SWAP(_client, spr);
|
2011-06-13 09:57:24 +00:00
|
|
|
return spr;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 18:52:19 +00:00
|
|
|
bool Keyboard::getKey(Common::Event &event) {
|
2011-07-31 07:38:08 +00:00
|
|
|
Common::KeyCode keycode = event.kbd.keycode;
|
2011-11-30 18:52:19 +00:00
|
|
|
|
2012-06-24 22:44:59 +00:00
|
|
|
if (((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) && event.type == Common::EVENT_KEYDOWN)
|
2011-11-30 18:52:19 +00:00
|
|
|
_keyAlt = true;
|
|
|
|
else
|
|
|
|
_keyAlt = false;
|
|
|
|
|
|
|
|
switch (keycode) {
|
|
|
|
case Common::KEYCODE_F1:
|
2011-11-13 11:33:36 +00:00
|
|
|
if (event.type == Common::EVENT_KEYUP)
|
|
|
|
return false;
|
|
|
|
// Display ScummVM version and translation strings
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
_vm->_commandHandler->addCommand(kCmdInf, 1, kShowScummVMVersion + i, NULL);
|
|
|
|
return false;
|
2011-11-30 18:52:19 +00:00
|
|
|
case Common::KEYCODE_F5:
|
2011-09-04 12:28:12 +00:00
|
|
|
if (_vm->canSaveGameStateCurrently()) {
|
2012-06-10 02:14:17 +00:00
|
|
|
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save", true);
|
2012-06-10 02:49:42 +00:00
|
|
|
int16 savegameId = dialog->runModalWithCurrentTarget();
|
2011-09-04 12:28:12 +00:00
|
|
|
Common::String savegameDescription = dialog->getResultString();
|
|
|
|
delete dialog;
|
2011-11-08 09:37:14 +00:00
|
|
|
|
|
|
|
if (savegameId != -1)
|
|
|
|
_vm->saveGameState(savegameId, savegameDescription);
|
2011-11-30 18:52:19 +00:00
|
|
|
}
|
2011-09-04 12:28:12 +00:00
|
|
|
return false;
|
2011-11-30 18:52:19 +00:00
|
|
|
case Common::KEYCODE_F7:
|
2011-09-04 12:28:12 +00:00
|
|
|
if (_vm->canLoadGameStateCurrently()) {
|
2012-06-10 02:14:17 +00:00
|
|
|
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore", false);
|
2012-06-10 02:49:42 +00:00
|
|
|
int16 savegameId = dialog->runModalWithCurrentTarget();
|
2011-09-04 12:28:12 +00:00
|
|
|
delete dialog;
|
2011-11-08 09:37:14 +00:00
|
|
|
|
|
|
|
if (savegameId != -1)
|
|
|
|
_vm->loadGameState(savegameId);
|
2011-09-04 12:28:12 +00:00
|
|
|
}
|
|
|
|
return false;
|
2011-11-30 18:52:19 +00:00
|
|
|
case Common::KEYCODE_d:
|
|
|
|
if (event.kbd.flags & Common::KBD_CTRL) {
|
2011-11-27 08:57:34 +00:00
|
|
|
// Start the debugger
|
2011-11-30 18:52:19 +00:00
|
|
|
_vm->getDebugger()->attach();
|
|
|
|
_vm->getDebugger()->onFrame();
|
|
|
|
return false;
|
2011-07-02 08:38:25 +00:00
|
|
|
}
|
2011-11-30 18:52:19 +00:00
|
|
|
break;
|
|
|
|
case Common::KEYCODE_x:
|
|
|
|
if (event.kbd.flags & Common::KBD_ALT) {
|
|
|
|
_vm->quit();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_0:
|
|
|
|
case Common::KEYCODE_1:
|
|
|
|
case Common::KEYCODE_2:
|
|
|
|
case Common::KEYCODE_3:
|
|
|
|
case Common::KEYCODE_4:
|
|
|
|
if (event.kbd.flags & Common::KBD_ALT) {
|
2012-07-03 21:55:48 +00:00
|
|
|
_vm->_commandHandler->addCommand(kCmdLevel, -1, keycode - Common::KEYCODE_0, NULL);
|
2011-11-30 18:52:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-03 20:43:04 +00:00
|
|
|
// Fallthrough intended
|
|
|
|
case Common::KEYCODE_5:
|
|
|
|
case Common::KEYCODE_6:
|
|
|
|
case Common::KEYCODE_7:
|
|
|
|
case Common::KEYCODE_8:
|
2012-07-03 21:55:48 +00:00
|
|
|
if (event.type == Common::EVENT_KEYDOWN && !(event.kbd.flags & Common::KBD_ALT) && keycode != Common::KEYCODE_0) {
|
|
|
|
_vm->selectPocket(keycode - Common::KEYCODE_1);
|
2012-07-03 20:43:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2011-11-30 18:52:19 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-07-02 08:38:25 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 18:52:19 +00:00
|
|
|
return true;
|
2011-07-02 08:38:25 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 22:41:47 +00:00
|
|
|
void Keyboard::newKeyboard(Common::Event &event) {
|
2011-11-30 18:52:19 +00:00
|
|
|
if (!getKey(event))
|
2011-07-02 08:38:25 +00:00
|
|
|
return;
|
|
|
|
|
2011-11-30 18:52:19 +00:00
|
|
|
if ((event.type == Common::EVENT_KEYDOWN) && (_client)) {
|
|
|
|
CGEEvent &evt = _vm->_eventManager->getNextEvent();
|
2012-07-04 21:18:29 +00:00
|
|
|
evt._x = 0;
|
|
|
|
evt._y = 0;
|
|
|
|
evt._keyCode = event.kbd.keycode; // Keycode
|
|
|
|
evt._mask = kEventKeyb; // Event mask
|
|
|
|
evt._spritePtr = _client; // Sprite pointer
|
2011-07-02 08:38:25 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-10 20:57:09 +00:00
|
|
|
|
2011-07-02 06:19:36 +00:00
|
|
|
/*----------------- MOUSE interface -----------------*/
|
|
|
|
|
2011-07-10 00:00:57 +00:00
|
|
|
Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) {
|
2011-07-08 06:21:35 +00:00
|
|
|
_hold = NULL;
|
2011-07-28 13:35:12 +00:00
|
|
|
_hx = 0;
|
2011-07-08 06:21:35 +00:00
|
|
|
_hy = 0;
|
|
|
|
_exist = true;
|
|
|
|
_buttons = 0;
|
|
|
|
_busy = NULL;
|
2011-07-02 11:45:29 +00:00
|
|
|
_active = false;
|
2011-08-19 10:36:43 +00:00
|
|
|
_flags._kill = false;
|
2011-07-28 13:35:12 +00:00
|
|
|
|
2011-07-12 11:16:23 +00:00
|
|
|
const Seq ms[] = {
|
|
|
|
{ 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 1, 0, 0, 1 }
|
|
|
|
};
|
|
|
|
Seq *seq = (Seq *)malloc(2 * sizeof(Seq));
|
|
|
|
Common::copy(ms, ms + 2, seq);
|
|
|
|
setSeq(seq);
|
2011-07-02 06:19:36 +00:00
|
|
|
|
2011-07-30 22:52:35 +00:00
|
|
|
BitmapPtr *MC = new BitmapPtr[3];
|
2011-09-16 21:54:08 +00:00
|
|
|
MC[0] = new Bitmap(_vm, "MOUSE");
|
|
|
|
MC[1] = new Bitmap(_vm, "DUMMY");
|
2011-07-10 00:00:57 +00:00
|
|
|
MC[2] = NULL;
|
|
|
|
setShapeList(MC);
|
|
|
|
|
2011-07-30 22:52:35 +00:00
|
|
|
gotoxy(kScrWidth / 2, kScrHeight / 2);
|
2011-07-02 06:19:36 +00:00
|
|
|
_z = 127;
|
|
|
|
step(1);
|
|
|
|
}
|
|
|
|
|
2011-07-08 06:21:35 +00:00
|
|
|
Mouse::~Mouse() {
|
|
|
|
off();
|
2011-07-02 06:19:36 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 06:21:35 +00:00
|
|
|
void Mouse::on() {
|
|
|
|
if (_seqPtr && _exist) {
|
2011-07-02 11:45:29 +00:00
|
|
|
_active = true;
|
|
|
|
step(0);
|
2011-07-08 06:21:35 +00:00
|
|
|
if (_busy)
|
|
|
|
_busy->step(0);
|
2012-12-16 08:34:54 +00:00
|
|
|
}
|
2011-07-02 06:19:36 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 06:21:35 +00:00
|
|
|
void Mouse::off() {
|
2011-07-02 11:45:29 +00:00
|
|
|
if (_seqPtr == 0) {
|
2011-07-08 06:21:35 +00:00
|
|
|
if (_exist) {
|
2011-07-02 11:45:29 +00:00
|
|
|
_active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
step(1);
|
2011-07-08 06:21:35 +00:00
|
|
|
if (_busy)
|
|
|
|
_busy->step(1);
|
2011-07-02 06:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 06:21:35 +00:00
|
|
|
void Mouse::newMouse(Common::Event &event) {
|
2011-07-02 11:45:29 +00:00
|
|
|
if (!_active)
|
|
|
|
return;
|
|
|
|
|
2011-09-17 08:54:50 +00:00
|
|
|
CGEEvent &evt = _vm->_eventManager->getNextEvent();
|
2011-07-02 11:34:40 +00:00
|
|
|
evt._x = event.mouse.x;
|
|
|
|
evt._y = event.mouse.y;
|
2012-07-04 21:18:29 +00:00
|
|
|
evt._keyCode = Common::KEYCODE_INVALID;
|
2011-09-16 04:45:28 +00:00
|
|
|
evt._spritePtr = _vm->spriteAt(evt._x, evt._y);
|
2011-07-02 11:34:40 +00:00
|
|
|
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
2011-08-02 19:47:56 +00:00
|
|
|
evt._mask = kMouseRoll;
|
2011-07-02 11:34:40 +00:00
|
|
|
break;
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2011-08-02 19:47:56 +00:00
|
|
|
evt._mask = kMouseLeftDown;
|
2011-07-08 06:21:35 +00:00
|
|
|
_buttons |= 1;
|
2011-07-02 11:34:40 +00:00
|
|
|
break;
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
2011-08-02 19:47:56 +00:00
|
|
|
evt._mask = kMouseLeftUp;
|
2011-07-08 06:21:35 +00:00
|
|
|
_buttons &= ~1;
|
2011-07-02 11:34:40 +00:00
|
|
|
break;
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
2011-08-02 19:47:56 +00:00
|
|
|
evt._mask = kMouseRightDown;
|
2011-07-08 06:21:35 +00:00
|
|
|
_buttons |= 2;
|
2011-07-02 11:34:40 +00:00
|
|
|
break;
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
2011-08-02 19:47:56 +00:00
|
|
|
evt._mask = kMouseRightUp;
|
2011-07-08 06:21:35 +00:00
|
|
|
_buttons &= ~2;
|
2011-07-02 11:34:40 +00:00
|
|
|
break;
|
2011-07-03 04:55:49 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-07-02 11:34:40 +00:00
|
|
|
}
|
2011-07-02 06:19:36 +00:00
|
|
|
}
|
|
|
|
|
2011-07-02 10:04:30 +00:00
|
|
|
/*----------------- EventManager interface -----------------*/
|
|
|
|
|
2011-09-16 18:31:11 +00:00
|
|
|
EventManager::EventManager(CGEEngine *vm) : _vm(vm){
|
2011-08-01 07:53:15 +00:00
|
|
|
_eventQueueHead = 0;
|
|
|
|
_eventQueueTail = 0;
|
2011-08-19 16:32:46 +00:00
|
|
|
memset(&_eventQueue, 0, kEventMax * sizeof(CGEEvent));
|
2011-08-06 09:23:01 +00:00
|
|
|
memset(&_event, 0, sizeof(Common::Event));
|
2011-07-02 10:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventManager::poll() {
|
|
|
|
while (g_system->getEventManager()->pollEvent(_event)) {
|
|
|
|
switch (_event.type) {
|
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
case Common::EVENT_KEYUP:
|
2011-07-02 11:34:40 +00:00
|
|
|
// Handle keyboard events
|
2011-09-17 08:08:24 +00:00
|
|
|
_vm->_keyboard->newKeyboard(_event);
|
2011-07-02 10:04:30 +00:00
|
|
|
handleEvents();
|
|
|
|
break;
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
2011-07-02 11:34:40 +00:00
|
|
|
// Handle mouse events
|
2011-09-17 08:08:24 +00:00
|
|
|
_vm->_mouse->newMouse(_event);
|
2011-07-02 10:04:30 +00:00
|
|
|
handleEvents();
|
|
|
|
break;
|
2011-07-03 04:55:49 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-07-02 10:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-02 06:19:36 +00:00
|
|
|
|
2011-07-05 21:13:12 +00:00
|
|
|
void EventManager::handleEvents() {
|
2011-08-01 07:53:15 +00:00
|
|
|
while (_eventQueueTail != _eventQueueHead) {
|
|
|
|
CGEEvent e = _eventQueue[_eventQueueTail];
|
|
|
|
if (e._mask) {
|
2011-09-17 08:08:24 +00:00
|
|
|
if (_vm->_mouse->_hold && e._spritePtr != _vm->_mouse->_hold)
|
2012-07-04 21:18:29 +00:00
|
|
|
_vm->_mouse->_hold->touch(e._mask | kEventAttn, e._x - _vm->_mouse->_hold->_x, e._y - _vm->_mouse->_hold->_y, e._keyCode);
|
2011-07-02 06:19:36 +00:00
|
|
|
|
|
|
|
// update mouse cursor position
|
2011-08-02 19:47:56 +00:00
|
|
|
if (e._mask & kMouseRoll)
|
2011-09-17 08:08:24 +00:00
|
|
|
_vm->_mouse->gotoxy(e._x, e._y);
|
2011-07-02 06:19:36 +00:00
|
|
|
|
|
|
|
// activate current touched SPRITE
|
2011-08-01 07:53:15 +00:00
|
|
|
if (e._spritePtr) {
|
2011-08-02 19:47:56 +00:00
|
|
|
if (e._mask & kEventKeyb)
|
2012-07-04 21:18:29 +00:00
|
|
|
e._spritePtr->touch(e._mask, e._x, e._y, e._keyCode);
|
2011-07-02 06:19:36 +00:00
|
|
|
else
|
2012-07-04 21:18:29 +00:00
|
|
|
e._spritePtr->touch(e._mask, e._x - e._spritePtr->_x, e._y - e._spritePtr->_y, e._keyCode);
|
2011-09-17 08:08:24 +00:00
|
|
|
} else if (_vm->_sys)
|
2012-07-04 21:18:29 +00:00
|
|
|
_vm->_sys->touch(e._mask, e._x, e._y, e._keyCode);
|
2011-07-02 06:19:36 +00:00
|
|
|
|
2011-08-02 19:47:56 +00:00
|
|
|
if (e._mask & kMouseLeftDown) {
|
2011-09-17 08:08:24 +00:00
|
|
|
_vm->_mouse->_hold = e._spritePtr;
|
|
|
|
if (_vm->_mouse->_hold) {
|
|
|
|
_vm->_mouse->_hold->_flags._hold = true;
|
2011-07-15 09:38:58 +00:00
|
|
|
|
2011-09-17 08:08:24 +00:00
|
|
|
if (_vm->_mouse->_hold->_flags._drag) {
|
|
|
|
_vm->_mouse->_hx = e._x - _vm->_mouse->_hold->_x;
|
|
|
|
_vm->_mouse->_hy = e._y - _vm->_mouse->_hold->_y;
|
2011-07-15 09:38:58 +00:00
|
|
|
}
|
2011-07-02 06:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-02 19:47:56 +00:00
|
|
|
if (e._mask & kMouseLeftUp) {
|
2011-09-17 08:08:24 +00:00
|
|
|
if (_vm->_mouse->_hold) {
|
|
|
|
_vm->_mouse->_hold->_flags._hold = false;
|
|
|
|
_vm->_mouse->_hold = NULL;
|
2011-07-02 06:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
///Touched = e.Ptr;
|
|
|
|
|
|
|
|
// discard Text if button released
|
2011-08-02 19:47:56 +00:00
|
|
|
if (e._mask & (kMouseLeftUp | kMouseRightUp))
|
2011-09-16 18:31:11 +00:00
|
|
|
_vm->killText();
|
2011-07-02 06:19:36 +00:00
|
|
|
}
|
2011-08-02 19:47:56 +00:00
|
|
|
_eventQueueTail = (_eventQueueTail + 1) % kEventMax;
|
2011-07-02 06:19:36 +00:00
|
|
|
}
|
2011-09-17 08:08:24 +00:00
|
|
|
if (_vm->_mouse->_hold) {
|
|
|
|
if (_vm->_mouse->_hold->_flags._drag)
|
|
|
|
_vm->_mouse->_hold->gotoxy(_vm->_mouse->_x - _vm->_mouse->_hx, _vm->_mouse->_y - _vm->_mouse->_hy);
|
2011-07-15 09:38:58 +00:00
|
|
|
}
|
2011-07-02 08:38:25 +00:00
|
|
|
}
|
2011-07-02 06:19:36 +00:00
|
|
|
|
2011-08-01 07:53:15 +00:00
|
|
|
void EventManager::clearEvent(Sprite *spr) {
|
2011-07-02 11:34:40 +00:00
|
|
|
if (spr) {
|
2011-08-19 14:04:10 +00:00
|
|
|
for (uint16 e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % kEventMax)
|
2011-08-01 07:53:15 +00:00
|
|
|
if (_eventQueue[e]._spritePtr == spr)
|
|
|
|
_eventQueue[e]._mask = 0;
|
2011-07-02 11:34:40 +00:00
|
|
|
} else
|
2011-08-01 07:53:15 +00:00
|
|
|
_eventQueueTail = _eventQueueHead;
|
2011-07-02 11:34:40 +00:00
|
|
|
}
|
|
|
|
|
2011-08-01 07:53:15 +00:00
|
|
|
CGEEvent &EventManager::getNextEvent() {
|
|
|
|
CGEEvent &evt = _eventQueue[_eventQueueHead];
|
2011-08-02 19:47:56 +00:00
|
|
|
_eventQueueHead = (_eventQueueHead + 1) % kEventMax;
|
2011-08-01 07:53:15 +00:00
|
|
|
|
|
|
|
return evt;
|
|
|
|
}
|
2011-08-19 14:04:10 +00:00
|
|
|
|
2011-06-10 20:57:09 +00:00
|
|
|
} // End of namespace CGE
|