2003-12-16 02:10:15 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2004-01-06 12:45:34 +00:00
|
|
|
* Copyright (C) 2003-2004 The ScummVM project
|
2003-12-16 02:10:15 +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
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2004-10-21 12:43:49 +00:00
|
|
|
#include "sword1/mouse.h"
|
|
|
|
#include "sword1/menu.h"
|
|
|
|
#include "sword1/screen.h"
|
|
|
|
#include "sword1/logic.h"
|
|
|
|
#include "sword1/resman.h"
|
|
|
|
#include "sword1/objectman.h"
|
|
|
|
#include "sword1/sworddefs.h"
|
2003-12-16 02:10:15 +00:00
|
|
|
#include "system.h"
|
2004-10-21 12:43:49 +00:00
|
|
|
#include "sword1/swordres.h"
|
|
|
|
#include "sword1/menu.h"
|
2003-12-16 02:10:15 +00:00
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
namespace Sword1 {
|
|
|
|
|
|
|
|
Mouse::Mouse(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan) {
|
2003-12-16 02:10:15 +00:00
|
|
|
_resMan = pResMan;
|
|
|
|
_objMan = pObjMan;
|
|
|
|
_system = system;
|
2003-12-30 21:32:50 +00:00
|
|
|
_currentPtr = NULL;
|
2003-12-16 02:10:15 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::initialize(void) {
|
2003-12-20 09:12:54 +00:00
|
|
|
_numObjs = 0;
|
2004-01-11 15:47:41 +00:00
|
|
|
Logic::_scriptVars[MOUSE_STATUS] = 0; // mouse off and unlocked
|
2003-12-20 09:12:54 +00:00
|
|
|
_getOff = 0;
|
|
|
|
_inTopMenu = false;
|
2004-02-13 11:04:15 +00:00
|
|
|
_lastState = 0;
|
2003-12-20 17:55:09 +00:00
|
|
|
_mouseOverride = false;
|
2003-12-30 21:32:50 +00:00
|
|
|
_currentPtrId = _currentLuggageId = 0;
|
2003-12-20 09:12:54 +00:00
|
|
|
|
2003-12-30 21:32:50 +00:00
|
|
|
for (uint8 cnt = 0; cnt < 17; cnt++) // force res manager to keep mouse
|
|
|
|
_resMan->resOpen(MSE_POINTER + cnt); // cursors in memory all the time
|
|
|
|
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->showMouse(false);
|
2003-12-30 21:32:50 +00:00
|
|
|
createPointer(0, 0);
|
2003-12-20 09:12:54 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::controlPanel(bool on) { // true on entering cpanel, false when leaving
|
2003-12-30 21:32:50 +00:00
|
|
|
static uint32 savedPtrId = 0;
|
2003-12-20 09:12:54 +00:00
|
|
|
if (on) {
|
|
|
|
savedPtrId = _currentPtrId;
|
2003-12-20 17:55:09 +00:00
|
|
|
_mouseOverride = true;
|
2003-12-30 21:32:50 +00:00
|
|
|
setLuggage(0, 0);
|
2003-12-20 09:12:54 +00:00
|
|
|
setPointer(MSE_POINTER, 0);
|
|
|
|
} else {
|
|
|
|
_currentPtrId = savedPtrId;
|
2003-12-20 17:55:09 +00:00
|
|
|
_mouseOverride = false;
|
2003-12-30 21:32:50 +00:00
|
|
|
setLuggage(_currentLuggageId, 0);
|
|
|
|
setPointer(_currentPtrId, 0);
|
2003-12-20 09:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::useLogicAndMenu(Logic *pLogic, Menu *pMenu) {
|
2003-12-16 02:10:15 +00:00
|
|
|
_logic = pLogic;
|
2003-12-17 05:16:37 +00:00
|
|
|
_menu = pMenu;
|
2003-12-16 02:10:15 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::addToList(int id, Object *compact) {
|
2003-12-16 02:10:15 +00:00
|
|
|
_objList[_numObjs].id = id;
|
|
|
|
_objList[_numObjs].compact = compact;
|
|
|
|
_numObjs++;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::engine(uint16 x, uint16 y, uint16 eventFlags) {
|
2003-12-16 02:10:15 +00:00
|
|
|
_state = 0; // all mouse events are flushed after one cycle.
|
|
|
|
if (_lastState) { // delay all events by one cycle to notice L_button + R_button clicks correctly.
|
|
|
|
_state = _lastState | eventFlags;
|
|
|
|
_lastState = 0;
|
|
|
|
} else if (eventFlags)
|
|
|
|
_lastState = eventFlags;
|
2003-12-17 01:47:47 +00:00
|
|
|
|
|
|
|
// if we received both, mouse down and mouse up event in this cycle, resort them so that
|
|
|
|
// we'll receive the up event in the next one.
|
|
|
|
if ((_state & MOUSE_DOWN_MASK) && (_state & MOUSE_UP_MASK)) {
|
|
|
|
_lastState = _state & MOUSE_UP_MASK;
|
|
|
|
_state &= MOUSE_DOWN_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
_mouseX = x;
|
|
|
|
_mouseY = y;
|
2004-01-11 15:47:41 +00:00
|
|
|
if (!(Logic::_scriptVars[MOUSE_STATUS] & 1)) { // no human?
|
2003-12-16 02:10:15 +00:00
|
|
|
_numObjs = 0;
|
|
|
|
return; // no human, so we don't want the mouse engine
|
|
|
|
}
|
2003-12-17 07:33:00 +00:00
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
if (!Logic::_scriptVars[TOP_MENU_DISABLED]) {
|
2003-12-17 07:33:00 +00:00
|
|
|
if (y < 40) { // okay, we are in the top menu.
|
2003-12-31 15:52:48 +00:00
|
|
|
if (!_inTopMenu) { // are we just entering it?
|
2004-01-11 15:47:41 +00:00
|
|
|
if (!Logic::_scriptVars[OBJECT_HELD])
|
2004-01-07 19:03:30 +00:00
|
|
|
_menu->fnStartMenu();
|
2003-12-31 15:52:48 +00:00
|
|
|
setPointer(MSE_POINTER, 0);
|
|
|
|
}
|
2003-12-17 07:33:00 +00:00
|
|
|
_menu->checkTopMenu();
|
|
|
|
_inTopMenu = true;
|
|
|
|
} else if (_inTopMenu) { // we're not in the menu. did we just leave it?
|
2004-01-11 15:47:41 +00:00
|
|
|
if (!Logic::_scriptVars[OBJECT_HELD])
|
2004-01-07 19:03:30 +00:00
|
|
|
_menu->fnEndMenu();
|
2003-12-17 07:33:00 +00:00
|
|
|
_inTopMenu = false;
|
|
|
|
}
|
|
|
|
} else if (_inTopMenu) {
|
2003-12-17 05:16:37 +00:00
|
|
|
_menu->fnEndMenu();
|
|
|
|
_inTopMenu = false;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
Logic::_scriptVars[MOUSE_X] = Logic::_scriptVars[SCROLL_OFFSET_X] + x + 128;
|
|
|
|
Logic::_scriptVars[MOUSE_Y] = Logic::_scriptVars[SCROLL_OFFSET_Y] + y + 128 - 40;
|
2003-12-16 02:10:15 +00:00
|
|
|
|
|
|
|
//-
|
|
|
|
int32 touchedId = 0;
|
2003-12-16 09:43:08 +00:00
|
|
|
uint16 clicked = 0;
|
2003-12-16 02:10:15 +00:00
|
|
|
if (y > 40) {
|
|
|
|
for (uint16 priority = 0; (priority < 10) && (!touchedId); priority++) {
|
2003-12-28 23:24:03 +00:00
|
|
|
for (uint16 cnt = 0; (cnt < _numObjs) && (!touchedId); cnt++) {
|
2003-12-16 02:10:15 +00:00
|
|
|
if ((_objList[cnt].compact->o_priority == priority) &&
|
2004-01-11 15:47:41 +00:00
|
|
|
(Logic::_scriptVars[MOUSE_X] >= (uint32)_objList[cnt].compact->o_mouse_x1) &&
|
|
|
|
(Logic::_scriptVars[MOUSE_X] <= (uint32)_objList[cnt].compact->o_mouse_x2) &&
|
|
|
|
(Logic::_scriptVars[MOUSE_Y] >= (uint32)_objList[cnt].compact->o_mouse_y1) &&
|
|
|
|
(Logic::_scriptVars[MOUSE_Y] <= (uint32)_objList[cnt].compact->o_mouse_y2)) {
|
2003-12-16 02:10:15 +00:00
|
|
|
touchedId = _objList[cnt].id;
|
|
|
|
clicked = cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-01-11 15:47:41 +00:00
|
|
|
if (touchedId != (int)Logic::_scriptVars[SPECIAL_ITEM]) { //the mouse collision situation has changed in one way or another
|
|
|
|
Logic::_scriptVars[SPECIAL_ITEM] = touchedId;
|
2003-12-16 02:10:15 +00:00
|
|
|
if (_getOff) { // there was something else selected before, run its get-off script
|
|
|
|
_logic->runMouseScript(NULL, _getOff);
|
|
|
|
_getOff = 0;
|
|
|
|
}
|
|
|
|
if (touchedId) { // there's something new selected, now.
|
2004-01-07 19:03:30 +00:00
|
|
|
if (_objList[clicked].compact->o_mouse_on) //run its get on
|
2003-12-16 02:10:15 +00:00
|
|
|
_logic->runMouseScript(_objList[clicked].compact, _objList[clicked].compact->o_mouse_on);
|
|
|
|
|
|
|
|
_getOff = _objList[clicked].compact->o_mouse_off; //setup get-off for later
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
2004-01-11 15:47:41 +00:00
|
|
|
Logic::_scriptVars[SPECIAL_ITEM] = 0;
|
2003-12-17 01:47:47 +00:00
|
|
|
if (_state & MOUSE_DOWN_MASK) {
|
2004-01-01 18:00:34 +00:00
|
|
|
if (_inTopMenu) {
|
2004-01-11 15:47:41 +00:00
|
|
|
if (Logic::_scriptVars[SECOND_ITEM])
|
|
|
|
_logic->runMouseScript(NULL, _menu->_objectDefs[Logic::_scriptVars[SECOND_ITEM]].useScript);
|
|
|
|
if (Logic::_scriptVars[MENU_LOOKING])
|
2004-01-01 18:00:34 +00:00
|
|
|
_logic->cfnPresetScript(NULL, -1, PLAYER, SCR_menu_look, 0, 0, 0, 0);
|
|
|
|
}
|
2003-12-21 16:50:02 +00:00
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
Logic::_scriptVars[MOUSE_BUTTON] = _state & MOUSE_DOWN_MASK;
|
|
|
|
if (Logic::_scriptVars[SPECIAL_ITEM]) {
|
|
|
|
Object *compact = _objMan->fetchObject(Logic::_scriptVars[SPECIAL_ITEM]);
|
2003-12-16 02:10:15 +00:00
|
|
|
_logic->runMouseScript(compact, compact->o_mouse_click);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_numObjs = 0;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
uint16 Mouse::testEvent(void) {
|
2003-12-16 02:10:15 +00:00
|
|
|
return _state;
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::createPointer(uint32 ptrId, uint32 luggageId) {
|
2003-12-30 21:32:50 +00:00
|
|
|
if (_currentPtr) {
|
|
|
|
free(_currentPtr);
|
|
|
|
_currentPtr = NULL;
|
|
|
|
}
|
|
|
|
if (ptrId) {
|
|
|
|
MousePtr *lugg = NULL;
|
|
|
|
MousePtr *ptr = (MousePtr*)_resMan->openFetchRes(ptrId);
|
|
|
|
uint16 resSizeX = FROM_LE_16(ptr->sizeX);
|
|
|
|
uint16 resSizeY = FROM_LE_16(ptr->sizeY);
|
|
|
|
uint16 noFrames = FROM_LE_16(ptr->numFrames);
|
|
|
|
if (luggageId) {
|
|
|
|
lugg = (MousePtr*)_resMan->openFetchRes(luggageId);
|
|
|
|
resSizeX = MAX(resSizeX, (uint16)((resSizeX / 2) + FROM_LE_16(lugg->sizeX)));
|
|
|
|
resSizeY = MAX(resSizeY, (uint16)((resSizeY / 2) + FROM_LE_16(lugg->sizeY)));
|
|
|
|
}
|
|
|
|
_currentPtr = (MousePtr*)malloc(sizeof(MousePtr) + resSizeX * resSizeY * noFrames);
|
|
|
|
_currentPtr->hotSpotX = FROM_LE_16(ptr->hotSpotX);
|
|
|
|
_currentPtr->hotSpotY = FROM_LE_16(ptr->hotSpotY);
|
|
|
|
_currentPtr->numFrames = noFrames;
|
|
|
|
_currentPtr->sizeX = resSizeX;
|
|
|
|
_currentPtr->sizeY = resSizeY;
|
|
|
|
uint8 *ptrData = (uint8*)_currentPtr + sizeof(MousePtr);
|
|
|
|
memset(ptrData, 255, resSizeX * resSizeY * noFrames);
|
|
|
|
if (luggageId) {
|
2003-12-31 15:41:17 +00:00
|
|
|
uint8 *dstData = ptrData + resSizeX - FROM_LE_16(lugg->sizeX);
|
2003-12-30 21:32:50 +00:00
|
|
|
for (uint32 frameCnt = 0; frameCnt < noFrames; frameCnt++) {
|
|
|
|
uint8 *luggSrc = (uint8*)lugg + sizeof(MousePtr);
|
|
|
|
dstData += (resSizeY - FROM_LE_16(lugg->sizeY)) * resSizeX;
|
|
|
|
for (uint32 cnty = 0; cnty < FROM_LE_16(lugg->sizeY); cnty++) {
|
|
|
|
for (uint32 cntx = 0; cntx < FROM_LE_16(lugg->sizeX); cntx++)
|
|
|
|
if (luggSrc[cntx])
|
|
|
|
dstData[cntx] = luggSrc[cntx];
|
|
|
|
dstData += resSizeX;
|
|
|
|
luggSrc += FROM_LE_16(lugg->sizeX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_resMan->resClose(luggageId);
|
|
|
|
}
|
2003-12-31 15:41:17 +00:00
|
|
|
uint8 *dstData = ptrData;
|
|
|
|
uint8 *srcData = (uint8*)ptr + sizeof(MousePtr);
|
|
|
|
for (uint32 frameCnt = 0; frameCnt < noFrames; frameCnt++) {
|
|
|
|
for (uint32 cnty = 0; cnty < FROM_LE_16(ptr->sizeY); cnty++) {
|
|
|
|
for (uint32 cntx = 0; cntx < FROM_LE_16(ptr->sizeX); cntx++)
|
|
|
|
if (srcData[cntx])
|
|
|
|
dstData[cntx] = srcData[cntx];
|
|
|
|
srcData += FROM_LE_16(ptr->sizeX);
|
|
|
|
dstData += resSizeX;
|
|
|
|
}
|
|
|
|
dstData += (resSizeY - FROM_LE_16(ptr->sizeY)) * resSizeX;
|
|
|
|
}
|
2003-12-30 21:32:50 +00:00
|
|
|
_resMan->resClose(ptrId);
|
|
|
|
}
|
2003-12-16 02:10:15 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::setPointer(uint32 resId, uint32 rate) {
|
2003-12-30 21:32:50 +00:00
|
|
|
_currentPtrId = resId;
|
2003-12-16 02:10:15 +00:00
|
|
|
_frame = 0;
|
2003-12-17 01:47:47 +00:00
|
|
|
|
2003-12-30 21:32:50 +00:00
|
|
|
createPointer(resId, _currentLuggageId);
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
if ((resId == 0) || (!(Logic::_scriptVars[MOUSE_STATUS] & 1) && (!_mouseOverride))) {
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->setMouseCursor(NULL, 0, 0, 0, 0);
|
|
|
|
_system->showMouse(false);
|
2003-12-16 02:10:15 +00:00
|
|
|
} else {
|
2003-12-19 14:07:12 +00:00
|
|
|
animate();
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->showMouse(true);
|
2003-12-16 02:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::setLuggage(uint32 resId, uint32 rate) {
|
2003-12-30 21:32:50 +00:00
|
|
|
_currentLuggageId = resId;
|
|
|
|
_frame = 0;
|
|
|
|
createPointer(_currentPtrId, resId);
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::animate(void) {
|
|
|
|
if ((Logic::_scriptVars[MOUSE_STATUS] == 1) || (_mouseOverride && _currentPtr)) {
|
2003-12-30 21:32:50 +00:00
|
|
|
_frame = (_frame + 1) % _currentPtr->numFrames;
|
|
|
|
uint8 *ptrData = (uint8*)_currentPtr + sizeof(MousePtr);
|
|
|
|
ptrData += _frame * _currentPtr->sizeX * _currentPtr->sizeY;
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->setMouseCursor(ptrData, _currentPtr->sizeX, _currentPtr->sizeY, _currentPtr->hotSpotX, _currentPtr->hotSpotY);
|
2003-12-16 02:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::fnNoHuman(void) {
|
|
|
|
if (Logic::_scriptVars[MOUSE_STATUS] & 2) // locked, can't do anything
|
2003-12-16 02:10:15 +00:00
|
|
|
return ;
|
2004-01-11 15:47:41 +00:00
|
|
|
Logic::_scriptVars[MOUSE_STATUS] = 0; // off & unlocked
|
2003-12-16 02:10:15 +00:00
|
|
|
setLuggage(0, 0);
|
|
|
|
setPointer(0, 0);
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::fnAddHuman(void) {
|
|
|
|
if (Logic::_scriptVars[MOUSE_STATUS] & 2) // locked, can't do anything
|
2003-12-16 02:10:15 +00:00
|
|
|
return ;
|
2004-01-11 15:47:41 +00:00
|
|
|
Logic::_scriptVars[MOUSE_STATUS] = 1;
|
|
|
|
Logic::_scriptVars[SPECIAL_ITEM] = 0;
|
2003-12-16 02:10:15 +00:00
|
|
|
_getOff = SCR_std_off;
|
|
|
|
setPointer(MSE_POINTER, 0);
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::fnBlankMouse(void) {
|
2003-12-16 02:10:15 +00:00
|
|
|
setPointer(0, 0);
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::fnNormalMouse(void) {
|
2003-12-16 02:10:15 +00:00
|
|
|
setPointer(MSE_POINTER, 0);
|
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::fnLockMouse(void) {
|
|
|
|
Logic::_scriptVars[MOUSE_STATUS] |= 2;
|
2003-12-16 02:10:15 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::fnUnlockMouse(void) {
|
|
|
|
Logic::_scriptVars[MOUSE_STATUS] &= 1;
|
2003-12-16 02:10:15 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 15:47:41 +00:00
|
|
|
void Mouse::giveCoords(uint16 *x, uint16 *y) {
|
2003-12-16 02:10:15 +00:00
|
|
|
*x = _mouseX;
|
|
|
|
*y = _mouseY;
|
|
|
|
}
|
2004-01-11 15:47:41 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword1
|