2014-02-18 23:43:06 -05: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"
|
|
|
|
#include "mads/mads.h"
|
2014-03-10 00:00:39 -04:00
|
|
|
#include "mads/game.h"
|
2014-03-13 22:25:16 -04:00
|
|
|
#include "mads/screen.h"
|
2014-03-10 00:00:39 -04:00
|
|
|
#include "mads/palette.h"
|
2014-03-18 19:56:29 -04:00
|
|
|
#include "mads/user_interface.h"
|
2014-02-18 23:43:06 -05:00
|
|
|
|
|
|
|
namespace MADS {
|
|
|
|
|
2014-03-17 21:53:22 -04:00
|
|
|
MADSEngine *DirtyArea::_vm = nullptr;
|
|
|
|
|
|
|
|
DirtyArea::DirtyArea() {
|
|
|
|
_active = false;
|
|
|
|
_textActive = false;
|
2014-04-07 23:48:43 -04:00
|
|
|
_mergedArea = nullptr;
|
2014-03-17 21:53:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DirtyArea::setArea(int width, int height, int maxWidth, int maxHeight) {
|
|
|
|
if (_bounds.left % 2) {
|
|
|
|
--_bounds.left;
|
|
|
|
++width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_bounds.left < 0)
|
|
|
|
_bounds.left = 0;
|
|
|
|
else if (_bounds.left > maxWidth)
|
|
|
|
_bounds.left = maxWidth;
|
|
|
|
int right = _bounds.left + width;
|
|
|
|
if (right < 0)
|
|
|
|
right = 0;
|
|
|
|
if (right > maxWidth)
|
|
|
|
right = maxWidth;
|
|
|
|
|
|
|
|
_bounds.right = right;
|
|
|
|
_bounds2.left = _bounds.width() / 2;
|
|
|
|
_bounds2.right = _bounds.left + (_bounds.width() + 1) / 2 - 1;
|
|
|
|
|
|
|
|
if (_bounds.top < 0)
|
|
|
|
_bounds.top = 0;
|
|
|
|
else if (_bounds.top > maxHeight)
|
|
|
|
_bounds.top = maxHeight;
|
|
|
|
int bottom = _bounds.top + height;
|
|
|
|
if (bottom < 0)
|
|
|
|
bottom = 0;
|
|
|
|
if (bottom > maxHeight)
|
|
|
|
bottom = maxHeight;
|
|
|
|
|
|
|
|
_bounds.bottom = bottom;
|
|
|
|
_bounds2.top = _bounds.height() / 2;
|
|
|
|
_bounds2.bottom = _bounds.top + (_bounds.height() + 1) / 2 - 1;
|
|
|
|
|
|
|
|
_active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DirtyArea::setSpriteSlot(const SpriteSlot *spriteSlot) {
|
|
|
|
int width, height;
|
|
|
|
Scene &scene = _vm->_game->_scene;
|
|
|
|
|
2014-04-02 21:24:22 -04:00
|
|
|
if (spriteSlot->_flags == IMG_REFRESH) {
|
2014-03-17 21:53:22 -04:00
|
|
|
// Special entry to refresh the entire screen
|
|
|
|
_bounds.left = 0;
|
|
|
|
_bounds.top = 0;
|
|
|
|
width = MADS_SCREEN_WIDTH;
|
|
|
|
height = MADS_SCENE_HEIGHT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Standard sprite slots
|
|
|
|
_bounds.left = spriteSlot->_position.x - scene._posAdjust.x;
|
|
|
|
_bounds.top = spriteSlot->_position.y - scene._posAdjust.y;
|
|
|
|
|
|
|
|
SpriteAsset &spriteSet = *scene._sprites[spriteSlot->_spritesIndex];
|
2014-03-21 22:47:31 -04:00
|
|
|
MSprite *frame = spriteSet.getFrame(ABS(spriteSlot->_frameNumber) - 1);
|
2014-03-17 21:53:22 -04:00
|
|
|
|
|
|
|
if (spriteSlot->_scale == -1) {
|
|
|
|
width = frame->w;
|
|
|
|
height = frame->h;
|
2014-03-21 22:47:31 -04:00
|
|
|
} else {
|
2014-03-17 21:53:22 -04:00
|
|
|
width = frame->w * spriteSlot->_scale / 100;
|
|
|
|
height = frame->h * spriteSlot->_scale / 100;
|
|
|
|
|
|
|
|
_bounds.left -= width / 2;
|
|
|
|
_bounds.top += -(height - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setArea(width, height, MADS_SCREEN_WIDTH, MADS_SCENE_HEIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirtyArea::setTextDisplay(const TextDisplay *textDisplay) {
|
|
|
|
_bounds.left = textDisplay->_bounds.left;
|
|
|
|
_bounds.top = textDisplay->_bounds.top;
|
|
|
|
|
|
|
|
setArea(textDisplay->_bounds.width(), textDisplay->_bounds.height(),
|
|
|
|
MADS_SCREEN_WIDTH, MADS_SCENE_HEIGHT);
|
|
|
|
}
|
|
|
|
|
2014-03-18 19:56:29 -04:00
|
|
|
void DirtyArea::setUISlot(const UISlot *slot) {
|
2014-04-02 21:24:22 -04:00
|
|
|
int type = slot->_flags;
|
|
|
|
if (type <= IMG_UPDATE_ONLY)
|
|
|
|
type += -IMG_UPDATE_ONLY;
|
2014-03-23 09:19:28 -04:00
|
|
|
if (type >= 0x40)
|
|
|
|
type &= ~0x40;
|
2014-03-18 19:56:29 -04:00
|
|
|
|
|
|
|
MSurface &intSurface = _vm->_game->_scene._userInterface;
|
|
|
|
switch (type) {
|
2014-04-02 21:24:22 -04:00
|
|
|
case IMG_REFRESH:
|
2014-03-18 19:56:29 -04:00
|
|
|
_bounds.left = 0;
|
|
|
|
_bounds.top = 0;
|
|
|
|
setArea(intSurface.w, intSurface.h, intSurface.w, intSurface.h);
|
|
|
|
break;
|
2014-04-09 09:32:14 -04:00
|
|
|
|
2014-04-02 21:24:22 -04:00
|
|
|
case IMG_OVERPRINT:
|
2014-03-18 19:56:29 -04:00
|
|
|
_bounds.left = slot->_position.x;
|
|
|
|
_bounds.top = slot->_position.y;
|
2014-04-09 09:32:14 -04:00
|
|
|
_bounds.setWidth(slot->_width);
|
|
|
|
_bounds.setHeight(slot->_height);
|
|
|
|
setArea(slot->_width, slot->_height, intSurface.w, intSurface.h);
|
2014-03-18 19:56:29 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
SpriteAsset *asset = _vm->_game->_scene._sprites[slot->_spritesIndex];
|
|
|
|
MSprite *frame = asset->getFrame(slot->_frameNumber - 1);
|
|
|
|
int w = frame->w;
|
|
|
|
int h = frame->h;
|
|
|
|
|
2014-04-02 21:24:22 -04:00
|
|
|
if (slot->_segmentId == IMG_SPINNING_OBJECT) {
|
2014-03-18 19:56:29 -04:00
|
|
|
_bounds.left = slot->_position.x;
|
|
|
|
_bounds.top = slot->_position.y;
|
|
|
|
} else {
|
|
|
|
_bounds.left = slot->_position.x + w / 2;
|
2014-03-23 09:19:28 -04:00
|
|
|
_bounds.top = slot->_position.y - h + 1;
|
2014-03-18 19:56:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setArea(w, h, intSurface.w, intSurface.h);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-17 21:53:22 -04:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
DirtyAreas::DirtyAreas(MADSEngine *vm) : _vm(vm) {
|
|
|
|
DirtyArea::_vm = vm;
|
|
|
|
|
|
|
|
for (int i = 0; i < DIRTY_AREAS_SIZE; ++i) {
|
|
|
|
DirtyArea rec;
|
|
|
|
rec._active = false;
|
|
|
|
push_back(rec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirtyAreas::merge(int startIndex, int count) {
|
|
|
|
if (startIndex >= count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int outerCtr = startIndex - 1, idx = 0; idx < count; ++outerCtr, ++idx) {
|
|
|
|
if (!(*this)[outerCtr]._active)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (int innerCtr = outerCtr + 1; innerCtr < count; ++innerCtr) {
|
|
|
|
if (!(*this)[innerCtr]._active || !intersects(outerCtr, innerCtr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((*this)[outerCtr]._textActive && (*this)[innerCtr]._textActive)
|
2014-03-23 09:19:28 -04:00
|
|
|
mergeAreas(innerCtr, outerCtr);
|
2014-03-17 21:53:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if two dirty areas intersect
|
|
|
|
*/
|
|
|
|
bool DirtyAreas::intersects(int idx1, int idx2) {
|
|
|
|
return (*this)[idx1]._bounds2.intersects((*this)[idx2]._bounds2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirtyAreas::mergeAreas(int idx1, int idx2) {
|
|
|
|
DirtyArea &da1 = (*this)[idx1];
|
|
|
|
DirtyArea &da2 = (*this)[idx2];
|
|
|
|
|
|
|
|
da1._bounds.extend(da2._bounds);
|
|
|
|
|
|
|
|
da1._bounds2.left = da1._bounds.width() / 2;
|
|
|
|
da1._bounds2.right = da1._bounds.left + (da1._bounds.width() + 1) / 2 - 1;
|
|
|
|
da1._bounds2.top = da1._bounds.height() / 2;
|
|
|
|
da1._bounds2.bottom = da1._bounds.top + (da1._bounds.height() + 1) / 2 - 1;
|
|
|
|
|
|
|
|
da2._active = false;
|
2014-04-07 23:48:43 -04:00
|
|
|
da2._mergedArea = &da1;
|
2014-03-17 21:53:22 -04:00
|
|
|
da1._textActive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirtyAreas::copy(MSurface *srcSurface, MSurface *destSurface, const Common::Point &posAdjust) {
|
|
|
|
for (uint i = 0; i < size(); ++i) {
|
|
|
|
const Common::Rect &srcBounds = (*this)[i]._bounds;
|
|
|
|
|
|
|
|
Common::Rect bounds(srcBounds.left + posAdjust.x, srcBounds.top + posAdjust.y,
|
|
|
|
srcBounds.right + posAdjust.x, srcBounds.bottom + posAdjust.y);
|
|
|
|
|
|
|
|
if ((*this)[i]._active && bounds.isValidRect()) {
|
|
|
|
srcSurface->copyTo(destSurface, bounds, Common::Point(bounds.left, bounds.top));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirtyAreas::copyToScreen(const Common::Point &posAdjust) {
|
|
|
|
for (uint i = 0; i < size(); ++i) {
|
|
|
|
const Common::Rect &srcBounds = (*this)[i]._bounds;
|
|
|
|
|
|
|
|
Common::Rect bounds(srcBounds.left + posAdjust.x, srcBounds.top + posAdjust.y,
|
|
|
|
srcBounds.right + posAdjust.x, srcBounds.bottom + posAdjust.y);
|
|
|
|
|
|
|
|
if ((*this)[i]._active && (*this)[i]._bounds.isValidRect()) {
|
|
|
|
_vm->_screen.copyRectToScreen(bounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DirtyAreas::reset() {
|
|
|
|
for (uint i = 0; i < size(); ++i)
|
|
|
|
(*this)[i]._active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2014-03-19 19:44:51 -04:00
|
|
|
ScreenObject::ScreenObject() {
|
|
|
|
_category = CAT_NONE;
|
|
|
|
_descId = 0;
|
|
|
|
_layer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
ScreenObjects::ScreenObjects(MADSEngine *vm) : _vm(vm) {
|
2014-03-22 12:02:17 -04:00
|
|
|
_objectY = -1;
|
2014-04-05 21:30:42 -04:00
|
|
|
_forceRescan = false;
|
2014-04-03 22:02:12 -04:00
|
|
|
_inputMode = kInputBuildingSentences;
|
2014-03-19 19:44:51 -04:00
|
|
|
_v7FED6 = 0;
|
|
|
|
_v8332A = 0;
|
|
|
|
_category = CAT_NONE;
|
2014-04-10 22:14:57 -04:00
|
|
|
_spotId = 0;
|
2014-03-19 19:44:51 -04:00
|
|
|
_released = false;
|
2014-03-19 23:33:18 -04:00
|
|
|
_uiCount = 0;
|
2014-03-21 09:27:22 -04:00
|
|
|
_selectedObject = -1;
|
2014-03-22 12:02:17 -04:00
|
|
|
_eventFlag = false;
|
2014-04-02 20:28:57 -04:00
|
|
|
_baseTime = 0;
|
2014-03-19 19:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenObjects::add(const Common::Rect &bounds, Layer layer, ScrCategory category, int descId) {
|
|
|
|
assert(size() < 100);
|
|
|
|
|
|
|
|
ScreenObject so;
|
|
|
|
so._bounds = bounds;
|
|
|
|
so._category = category;
|
|
|
|
so._descId = descId;
|
|
|
|
so._layer = layer;
|
2014-03-22 21:55:36 -04:00
|
|
|
so._active = true;
|
2014-03-19 19:44:51 -04:00
|
|
|
|
|
|
|
push_back(so);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenObjects::check(bool scanFlag) {
|
|
|
|
Scene &scene = _vm->_game->_scene;
|
2014-03-22 20:02:02 -04:00
|
|
|
UserInterface &userInterface = scene._userInterface;
|
2014-03-19 19:44:51 -04:00
|
|
|
|
2014-04-03 22:02:12 -04:00
|
|
|
if (!_vm->_events->_mouseButtons || _inputMode != kInputBuildingSentences)
|
2014-04-05 14:27:33 -04:00
|
|
|
_vm->_events->_rightMousePressed = false;
|
2014-03-19 19:44:51 -04:00
|
|
|
|
2014-04-10 22:14:57 -04:00
|
|
|
if ((_vm->_events->_mouseMoved || userInterface._scrollbarActive
|
2014-04-05 21:30:42 -04:00
|
|
|
|| _v8332A || _forceRescan) && scanFlag) {
|
2014-03-22 12:02:17 -04:00
|
|
|
_category = CAT_NONE;
|
2014-03-21 09:27:22 -04:00
|
|
|
_selectedObject = scanBackwards(_vm->_events->currentPos(), LAYER_GUI);
|
|
|
|
if (_selectedObject > 0) {
|
2014-03-23 22:40:37 -04:00
|
|
|
ScreenObject &scrObject = (*this)[_selectedObject];
|
|
|
|
_category = (ScrCategory)(scrObject._category & 7);
|
2014-04-10 22:14:57 -04:00
|
|
|
_spotId = scrObject._descId;
|
2014-03-19 19:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handling for easy mouse
|
|
|
|
ScrCategory category = scene._userInterface._category;
|
2014-03-26 22:22:50 -04:00
|
|
|
if (_vm->_easyMouse && _vm->_events->_mouseButtons && category != _category
|
2014-03-19 19:44:51 -04:00
|
|
|
&& scene._userInterface._category != CAT_NONE) {
|
|
|
|
_released = true;
|
2014-03-27 22:38:28 -04:00
|
|
|
if (category >= CAT_COMMAND && category <= CAT_TALK_ENTRY) {
|
2014-03-22 18:26:41 -04:00
|
|
|
elementHighlighted();
|
2014-03-19 19:44:51 -04:00
|
|
|
}
|
2014-03-22 12:02:17 -04:00
|
|
|
|
|
|
|
scene._action.checkActionAtMousePos();
|
2014-03-19 19:44:51 -04:00
|
|
|
}
|
|
|
|
|
2014-03-26 22:22:50 -04:00
|
|
|
//_released = _vm->_events->_mouseReleased;
|
2014-04-08 22:04:43 -04:00
|
|
|
if (_vm->_events->_vD2 || (_vm->_easyMouse && !_vm->_events->_mouseStatusCopy))
|
2014-03-19 19:44:51 -04:00
|
|
|
scene._userInterface._category = _category;
|
|
|
|
|
|
|
|
if (!_vm->_events->_mouseButtons || _vm->_easyMouse) {
|
2014-03-27 22:38:28 -04:00
|
|
|
if (userInterface._category >= CAT_COMMAND && userInterface._category <= CAT_TALK_ENTRY) {
|
2014-03-22 18:26:41 -04:00
|
|
|
elementHighlighted();
|
2014-03-19 19:44:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-05 21:30:42 -04:00
|
|
|
if (_vm->_events->_mouseButtons || (_vm->_easyMouse && scene._action._interAwaiting > AWAITING_COMMAND
|
2014-03-19 19:44:51 -04:00
|
|
|
&& scene._userInterface._category == CAT_INV_LIST) ||
|
|
|
|
(_vm->_easyMouse && scene._userInterface._category == CAT_HOTSPOT)) {
|
|
|
|
scene._action.checkActionAtMousePos();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_vm->_events->_mouseReleased) {
|
2014-03-19 23:33:18 -04:00
|
|
|
scene._action.leftClick();
|
2014-03-19 19:44:51 -04:00
|
|
|
scene._userInterface._category = CAT_NONE;
|
|
|
|
}
|
|
|
|
|
2014-04-10 22:14:57 -04:00
|
|
|
if (_vm->_events->_mouseButtons || _vm->_easyMouse || userInterface._scrollbarActive)
|
|
|
|
scene._userInterface.updateInventoryScroller();
|
2014-03-19 19:44:51 -04:00
|
|
|
|
|
|
|
if (_vm->_events->_mouseButtons || _vm->_easyMouse)
|
|
|
|
scene._action.set();
|
|
|
|
|
2014-04-10 22:14:57 -04:00
|
|
|
_forceRescan = false;
|
2014-03-19 19:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
scene._action.refresh();
|
|
|
|
|
2014-03-19 23:33:18 -04:00
|
|
|
uint32 currentTicks = _vm->_events->getFrameCounter();
|
2014-04-02 20:28:57 -04:00
|
|
|
if (currentTicks >= _baseTime) {
|
2014-03-19 23:33:18 -04:00
|
|
|
// Check the user interface slots to see if there's any slots that need to be expired
|
|
|
|
UISlots &uiSlots = userInterface._uiSlots;
|
|
|
|
for (uint idx = 0; idx < uiSlots.size(); ++idx) {
|
|
|
|
UISlot &slot = uiSlots[idx];
|
|
|
|
|
2014-04-02 22:27:11 -04:00
|
|
|
if (slot._flags != IMG_REFRESH && slot._flags > IMG_UPDATE_ONLY
|
2014-04-02 21:24:22 -04:00
|
|
|
&& slot._segmentId != IMG_SPINNING_OBJECT)
|
|
|
|
slot._flags = IMG_ERASE;
|
2014-03-19 23:33:18 -04:00
|
|
|
}
|
|
|
|
|
2014-04-07 22:37:22 -04:00
|
|
|
// Any background animation in the user interface
|
|
|
|
userInterface.doBackgroundAnimation();
|
2014-04-02 20:28:57 -04:00
|
|
|
|
2014-04-07 22:37:22 -04:00
|
|
|
// Handle animating the selected inventory item
|
2014-03-19 23:33:18 -04:00
|
|
|
userInterface.inventoryAnim();
|
|
|
|
|
2014-04-02 20:28:57 -04:00
|
|
|
// Set the base time
|
|
|
|
_baseTime = currentTicks + 6;
|
|
|
|
}
|
2014-03-19 19:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int ScreenObjects::scanBackwards(const Common::Point &pt, int layer) {
|
2014-03-22 21:55:36 -04:00
|
|
|
for (int i = (int)size(); i >= 1; --i) {
|
|
|
|
ScreenObject &sObj = (*this)[i];
|
|
|
|
if (sObj._active && sObj._bounds.contains(pt) && sObj._layer == layer)
|
|
|
|
return i;
|
2014-03-19 19:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry not found
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-22 18:26:41 -04:00
|
|
|
void ScreenObjects::elementHighlighted() {
|
|
|
|
Scene &scene = _vm->_game->_scene;
|
|
|
|
UserInterface &userInterface = scene._userInterface;
|
|
|
|
Common::Array<int> &invList = _vm->_game->_objects._inventoryList;
|
|
|
|
MADSAction &action = scene._action;
|
|
|
|
int varA;
|
|
|
|
int topIndex;
|
2014-03-24 22:34:09 -04:00
|
|
|
int *idxP;
|
2014-03-22 18:26:41 -04:00
|
|
|
int var4;
|
2014-03-22 20:02:02 -04:00
|
|
|
int index;
|
|
|
|
int indexEnd = -1;
|
2014-03-22 18:26:41 -04:00
|
|
|
int var8 = 0;
|
2014-04-12 12:09:29 -04:00
|
|
|
//int uiCount;
|
2014-03-22 18:26:41 -04:00
|
|
|
|
|
|
|
switch (userInterface._category) {
|
2014-03-27 22:38:28 -04:00
|
|
|
case CAT_COMMAND:
|
2014-03-22 18:26:41 -04:00
|
|
|
index = 10;
|
|
|
|
indexEnd = 9;
|
|
|
|
varA = 5;
|
|
|
|
topIndex = 0;
|
2014-04-05 14:27:33 -04:00
|
|
|
idxP = !_vm->_events->_rightMousePressed ? &userInterface._highlightedCommandIndex :
|
2014-03-24 22:34:09 -04:00
|
|
|
&userInterface._selectedActionIndex;
|
2014-03-22 18:26:41 -04:00
|
|
|
|
2014-04-05 14:27:33 -04:00
|
|
|
if (_vm->_events->_rightMousePressed && userInterface._selectedItemVocabIdx >= 0)
|
2014-03-24 22:34:09 -04:00
|
|
|
userInterface.updateSelection(CAT_INV_VOCAB, -1, &userInterface._selectedItemVocabIdx);
|
2014-03-22 18:26:41 -04:00
|
|
|
|
2014-04-05 14:27:33 -04:00
|
|
|
var4 = _released && !_vm->_events->_rightMousePressed ? 1 : 0;
|
2014-03-22 18:26:41 -04:00
|
|
|
break;
|
|
|
|
|
2014-03-22 21:55:36 -04:00
|
|
|
case CAT_INV_LIST:
|
2014-03-22 18:26:41 -04:00
|
|
|
userInterface.scrollInventory();
|
|
|
|
|
|
|
|
index = MIN((int)invList.size() - userInterface._inventoryTopIndex, 5);
|
|
|
|
indexEnd = invList.size() - 1;
|
|
|
|
varA = 0;
|
|
|
|
topIndex = userInterface._inventoryTopIndex;
|
2014-04-09 09:32:14 -04:00
|
|
|
idxP = &userInterface._highlightedInvIndex;
|
2014-03-27 22:38:28 -04:00
|
|
|
var4 = (!_released || (_vm->_events->_mouseButtons && action._interAwaiting == 1)) ? 0 : 1;
|
2014-03-22 18:26:41 -04:00
|
|
|
break;
|
|
|
|
|
2014-03-22 21:55:36 -04:00
|
|
|
case CAT_INV_VOCAB:
|
2014-03-22 18:26:41 -04:00
|
|
|
if (userInterface._selectedInvIndex >= 0) {
|
|
|
|
InventoryObject &invObject = _vm->_game->_objects.getItem(
|
|
|
|
userInterface._selectedInvIndex);
|
|
|
|
index = invObject._vocabCount;
|
|
|
|
indexEnd = index - 1;
|
|
|
|
} else {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
varA = 0;
|
|
|
|
topIndex = 0;
|
2014-04-09 09:32:14 -04:00
|
|
|
idxP = _vm->_events->_rightMousePressed ? &userInterface._selectedItemVocabIdx : &userInterface._highlightedItemVocabIndex;
|
2014-03-22 18:26:41 -04:00
|
|
|
|
2014-04-05 14:27:33 -04:00
|
|
|
if (_vm->_events->_rightMousePressed && userInterface._selectedActionIndex >= 0)
|
2014-03-27 22:38:28 -04:00
|
|
|
userInterface.updateSelection(CAT_COMMAND, -1, &userInterface._selectedActionIndex);
|
2014-03-22 18:26:41 -04:00
|
|
|
|
2014-04-05 14:27:33 -04:00
|
|
|
var4 = _released && !_vm->_events->_rightMousePressed ? 1 : 0;
|
2014-03-22 18:26:41 -04:00
|
|
|
break;
|
|
|
|
|
2014-03-22 21:55:36 -04:00
|
|
|
case CAT_INV_ANIM:
|
2014-03-22 18:26:41 -04:00
|
|
|
index = 1;
|
|
|
|
indexEnd = invList.size() - 1;
|
|
|
|
varA = 0;
|
|
|
|
topIndex = userInterface._selectedInvIndex;
|
2014-03-24 22:34:09 -04:00
|
|
|
idxP = &var8;
|
2014-03-22 18:26:41 -04:00
|
|
|
var4 = -1;
|
|
|
|
break;
|
|
|
|
|
2014-03-22 21:55:36 -04:00
|
|
|
case CAT_TALK_ENTRY:
|
2014-03-22 18:26:41 -04:00
|
|
|
index = 0;
|
|
|
|
for (int idx = 0; idx < 5; ++idx) {
|
|
|
|
if (!userInterface._talkStrings[idx].empty())
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
|
|
|
indexEnd = index - 1;
|
|
|
|
varA = 0;
|
|
|
|
topIndex = 0;
|
2014-03-27 22:38:28 -04:00
|
|
|
idxP = &userInterface._highlightedCommandIndex;
|
2014-03-22 18:26:41 -04:00
|
|
|
var4 = -1;
|
|
|
|
break;
|
2014-03-22 21:55:36 -04:00
|
|
|
|
|
|
|
default:
|
2014-04-12 12:09:29 -04:00
|
|
|
//uiCount = size() - _uiCount;
|
2014-03-22 21:55:36 -04:00
|
|
|
index = scene._hotspots.size();
|
|
|
|
indexEnd = index - 1;
|
|
|
|
varA = 0;
|
|
|
|
topIndex = 0;
|
2014-03-24 22:34:09 -04:00
|
|
|
idxP = &var8;
|
2014-03-22 21:55:36 -04:00
|
|
|
var4 = -1;
|
|
|
|
break;
|
2014-03-22 18:26:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int newIndex = -1;
|
|
|
|
int catIndex = userInterface._categoryIndexes[userInterface._category - 1];
|
2014-03-22 19:09:25 -04:00
|
|
|
int newX = 0, newY = 0;
|
|
|
|
Common::Point currentPos = _vm->_events->currentPos();
|
2014-03-22 18:26:41 -04:00
|
|
|
|
2014-03-22 20:02:02 -04:00
|
|
|
for (int idx = 0; idx < index && newIndex < 0; ++idx) {
|
2014-03-22 19:09:25 -04:00
|
|
|
int scrObjIndex = (_category == CAT_HOTSPOT) ? catIndex - idx + index - 1 :
|
|
|
|
catIndex + idx;
|
2014-03-22 21:55:36 -04:00
|
|
|
|
2014-03-22 19:09:25 -04:00
|
|
|
ScreenObject &scrObject = (*this)[scrObjIndex];
|
2014-03-22 21:55:36 -04:00
|
|
|
if (!scrObject._active)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const Common::Rect &bounds = scrObject._bounds;
|
2014-03-22 19:09:25 -04:00
|
|
|
newY = MAX((int)bounds.bottom, newY);
|
|
|
|
newX = MAX((int)bounds.left, newX);
|
|
|
|
|
2014-03-22 21:55:36 -04:00
|
|
|
if (currentPos.y >= bounds.top && currentPos.y < bounds.bottom) {
|
2014-03-22 19:09:25 -04:00
|
|
|
if (var4) {
|
2014-03-22 21:55:36 -04:00
|
|
|
if (currentPos.x >= bounds.left && currentPos.x < bounds.right) {
|
|
|
|
// Cursor is inside hotspot bounds
|
2014-03-22 19:09:25 -04:00
|
|
|
newIndex = scrObjIndex - catIndex;
|
2014-03-22 20:02:02 -04:00
|
|
|
if (_category == CAT_HOTSPOT && newIndex < (int)scene._hotspots.size())
|
2014-03-22 19:09:25 -04:00
|
|
|
newIndex = scene._hotspots.size() - newIndex - 1;
|
|
|
|
}
|
|
|
|
} else if (!varA) {
|
|
|
|
newIndex = idx;
|
|
|
|
} else if (varA <= idx) {
|
|
|
|
if (currentPos.x > bounds.left)
|
|
|
|
newIndex = idx;
|
|
|
|
} else {
|
2014-03-25 08:55:29 -04:00
|
|
|
if (currentPos.x < bounds.right)
|
2014-03-22 19:09:25 -04:00
|
|
|
newIndex = idx;
|
|
|
|
}
|
|
|
|
}
|
2014-03-22 18:26:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newIndex == -1 && index > 0 && !var4) {
|
|
|
|
if (_vm->_events->currentPos().y <= newY) {
|
|
|
|
newIndex = 0;
|
2014-03-22 19:09:25 -04:00
|
|
|
if (varA && _vm->_events->currentPos().x >= newX)
|
2014-03-22 18:26:41 -04:00
|
|
|
newIndex = varA;
|
|
|
|
} else {
|
|
|
|
newIndex = index - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newIndex >= 0)
|
|
|
|
newIndex = MIN(newIndex + topIndex, indexEnd);
|
|
|
|
|
2014-04-02 22:27:11 -04:00
|
|
|
action._pickedWord = newIndex;
|
2014-03-22 18:26:41 -04:00
|
|
|
|
|
|
|
if (_category == CAT_INV_LIST || _category == CAT_INV_ANIM) {
|
2014-03-27 22:38:28 -04:00
|
|
|
if (action._interAwaiting == 1 && newIndex >= 0 && _released &&
|
2014-03-22 18:26:41 -04:00
|
|
|
(!_vm->_events->_mouseReleased || !_vm->_easyMouse))
|
|
|
|
newIndex = -1;
|
|
|
|
}
|
|
|
|
|
2014-04-05 14:27:33 -04:00
|
|
|
if (_released && !_vm->_events->_rightMousePressed &&
|
2014-03-22 18:26:41 -04:00
|
|
|
(_vm->_events->_mouseReleased || !_vm->_easyMouse))
|
|
|
|
newIndex = -1;
|
|
|
|
|
|
|
|
if (_category != CAT_HOTSPOT && _category != CAT_INV_ANIM)
|
2014-03-24 22:34:09 -04:00
|
|
|
userInterface.updateSelection(_category, newIndex, idxP);
|
2014-03-22 18:26:41 -04:00
|
|
|
}
|
|
|
|
|
2014-03-22 21:55:36 -04:00
|
|
|
void ScreenObjects::setActive(ScrCategory category, int descId, bool active) {
|
|
|
|
for (uint idx = 1; idx < size(); ++idx) {
|
|
|
|
ScreenObject &sObj = (*this)[idx];
|
|
|
|
if (sObj._category == category && sObj._descId == descId)
|
|
|
|
sObj._active = active;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 19:44:51 -04:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
2014-03-13 22:25:16 -04:00
|
|
|
ScreenSurface::ScreenSurface() {
|
|
|
|
_dataP = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:27:39 -05:00
|
|
|
void ScreenSurface::init() {
|
|
|
|
setSize(g_system->getWidth(), g_system->getHeight());
|
|
|
|
}
|
|
|
|
|
2014-03-13 22:25:16 -04:00
|
|
|
void ScreenSurface::copyRectToScreen(const Common::Point &destPos,
|
|
|
|
const Common::Rect &bounds) {
|
|
|
|
byte *buf = getBasePtr(destPos.x, destPos.y);
|
2014-03-21 22:47:31 -04:00
|
|
|
|
|
|
|
if (bounds.width() != 0 && bounds.height() != 0)
|
|
|
|
g_system->copyRectToScreen(buf, this->pitch, bounds.left, bounds.top,
|
|
|
|
bounds.width(), bounds.height());
|
2014-03-13 22:25:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenSurface::copyRectToScreen(const Common::Rect &bounds) {
|
|
|
|
copyRectToScreen(Common::Point(bounds.left, bounds.top), bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-05 07:27:39 -05:00
|
|
|
void ScreenSurface::updateScreen() {
|
|
|
|
g_system->updateScreen();
|
|
|
|
}
|
|
|
|
|
2014-03-10 00:00:39 -04:00
|
|
|
void ScreenSurface::transition(ScreenTransition transitionType, bool surfaceFlag) {
|
|
|
|
switch (transitionType) {
|
|
|
|
case kTransitionFadeOutIn:
|
|
|
|
fadeOut();
|
|
|
|
fadeIn();
|
|
|
|
break;
|
2014-03-05 07:27:39 -05:00
|
|
|
|
2014-03-10 00:00:39 -04:00
|
|
|
case kTransitionFadeIn:
|
|
|
|
fadeIn();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kTransitionBoxInBottomLeft:
|
|
|
|
case kTransitionBoxInBottomRight:
|
|
|
|
case kTransitionBoxInTopLeft:
|
|
|
|
case kTransitionBoxInTopRight:
|
|
|
|
error("TODO: transition");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kTransitionPanLeftToRight:
|
|
|
|
case kTransitionPanRightToLeft:
|
|
|
|
error("TODO: transition");
|
|
|
|
|
|
|
|
case kTransitionCircleIn1:
|
|
|
|
case kTransitionCircleIn2:
|
|
|
|
case kTransitionCircleIn3:
|
|
|
|
case kTransitionCircleIn4:
|
|
|
|
error("TODO circle transition");
|
|
|
|
|
|
|
|
case kCenterVertTransition:
|
|
|
|
error("TODO: center vert transition");
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Quick transitions
|
|
|
|
break;
|
|
|
|
}
|
2014-03-05 07:27:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenSurface::setPointer(MSurface *s) {
|
2014-03-13 22:25:16 -04:00
|
|
|
_dataP = s->getData();
|
2014-03-05 07:27:39 -05:00
|
|
|
}
|
|
|
|
|
2014-03-10 00:00:39 -04:00
|
|
|
void ScreenSurface::fadeOut() {
|
|
|
|
warning("TODO: Proper fade out");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenSurface::fadeIn() {
|
|
|
|
warning("TODO: Proper fade in");
|
|
|
|
_vm->_palette->setFullPalette(_vm->_palette->_mainPalette);
|
2014-03-13 22:25:16 -04:00
|
|
|
_vm->_screen.copyRectToScreen(Common::Rect(0, 0, 320, 200));
|
2014-03-10 00:00:39 -04:00
|
|
|
}
|
2014-02-18 23:43:06 -05:00
|
|
|
|
|
|
|
} // End of namespace MADS
|