aboutsummaryrefslogtreecommitdiff
path: root/engines/parallaction/input.cpp
diff options
context:
space:
mode:
authorChristopher Page2008-08-04 22:34:07 +0000
committerChristopher Page2008-08-04 22:34:07 +0000
commit4198ee962399305a4a158b1f43224c00e2e04a1b (patch)
treeeea375b5cb471509df2e2c5d9123d963a62403c6 /engines/parallaction/input.cpp
parenta51f45407659bba43254b466d20b6af2e8f17ffd (diff)
parent4f5479ee744ac6b419cdf7ec1e96fbf7c83d36ef (diff)
downloadscummvm-rg350-4198ee962399305a4a158b1f43224c00e2e04a1b.tar.gz
scummvm-rg350-4198ee962399305a4a158b1f43224c00e2e04a1b.tar.bz2
scummvm-rg350-4198ee962399305a4a158b1f43224c00e2e04a1b.zip
Merged revisions 33188-33189,33191-33193,33196,33198,33202-33203,33206,33210,33212,33218-33220,33222,33224-33226,33229-33243,33246,33248-33250,33252,33258-33261,33263,33266,33270,33272-33283,33285,33287-33290,33295-33298,33321,33325-33330,33332-33335,33337-33340,33342,33345,33347,33349-33350,33352-33357,33359-33367,33369-33371,33373,33375-33377,33379-33380,33383-33385,33387-33389,33392-33394,33400-33402,33404-33405,33407-33410,33412-33416,33418-33419,33425-33427,33432,33436-33438,33444,33446,33452-33453,33455-33459,33463-33464,33466-33471,33473-33474,33478,33490,33492,33495-33496,33509-33512,33518-33519,33522-33527,33529-33530,33537,33541,33544,33546,33550,33552-33554,33556,33558,33561-33562,33565,33568,33570,33574,33576,33578-33581,33584-33587,33590,33596,33604-33611,33614-33615,33617-33618,33620-33621 via svnmerge from
https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk svn-id: r33624
Diffstat (limited to 'engines/parallaction/input.cpp')
-rw-r--r--engines/parallaction/input.cpp222
1 files changed, 124 insertions, 98 deletions
diff --git a/engines/parallaction/input.cpp b/engines/parallaction/input.cpp
index d625199e2b..19747c007e 100644
--- a/engines/parallaction/input.cpp
+++ b/engines/parallaction/input.cpp
@@ -36,25 +36,23 @@ namespace Parallaction {
// loops which could possibly be merged into this one with some effort in changing
// caller code, i.e. adding condition checks.
//
-uint16 Input::readInput() {
+void Input::readInput() {
Common::Event e;
- uint16 KeyDown = 0;
_mouseButtons = kMouseNone;
- _lastKeyDownAscii = -1;
+ _hasKeyPressEvent = false;
Common::EventManager *eventMan = _vm->_system->getEventManager();
while (eventMan->pollEvent(e)) {
switch (e.type) {
case Common::EVENT_KEYDOWN:
- _lastKeyDownAscii = e.kbd.ascii;
+ _hasKeyPressEvent = true;
+ _keyPressed = e.kbd;
+
if (e.kbd.flags == Common::KBD_CTRL && e.kbd.keycode == 'd')
_vm->_debugger->attach();
- if (_vm->getFeatures() & GF_DEMO) break;
- if (e.kbd.keycode == Common::KEYCODE_l) KeyDown = kEvLoadGame;
- if (e.kbd.keycode == Common::KEYCODE_s) KeyDown = kEvSaveGame;
break;
case Common::EVENT_LBUTTONDOWN:
@@ -83,7 +81,7 @@ uint16 Input::readInput() {
case Common::EVENT_RTL:
case Common::EVENT_QUIT:
_vm->_quit = true;
- return KeyDown;
+ return;
default:
break;
@@ -95,13 +93,13 @@ uint16 Input::readInput() {
if (_vm->_debugger->isAttached())
_vm->_debugger->onFrame();
- return KeyDown;
+ return;
}
bool Input::getLastKeyDown(uint16 &ascii) {
- ascii = _lastKeyDownAscii;
- return (_lastKeyDownAscii != -1);
+ ascii = _keyPressed.ascii;
+ return (_hasKeyPressEvent);
}
// FIXME: see comment for readInput()
@@ -128,64 +126,36 @@ void Input::waitForButtonEvent(uint32 buttonEventMask, int32 timeout) {
}
-// FIXME: see comment for readInput()
-void Input::waitUntilLeftClick() {
-
- do {
- readInput();
- _vm->_gfx->updateScreen();
- _vm->_system->delayMillis(30);
- } while (_mouseButtons != kMouseLeftUp);
-
- return;
-}
-
void Input::updateGameInput() {
- int16 keyDown = readInput();
+ readInput();
- debugC(3, kDebugInput, "translateInput: input flags (%i, %i, %i, %i)",
- !_mouseHidden,
- (_engineFlags & kEngineBlockInput) == 0,
- (_engineFlags & kEngineWalking) == 0,
- (_engineFlags & kEngineChangeLocation) == 0
- );
-
- if ((_mouseHidden) ||
- (_engineFlags & kEngineBlockInput) ||
+ if (!isMouseEnabled() ||
(_engineFlags & kEngineWalking) ||
(_engineFlags & kEngineChangeLocation)) {
+ debugC(3, kDebugInput, "updateGameInput: input flags (mouse: %i, walking: %i, changeloc: %i)",
+ isMouseEnabled(),
+ (_engineFlags & kEngineWalking) == 0,
+ (_engineFlags & kEngineChangeLocation) == 0
+ );
+
return;
}
- if (keyDown == kEvQuitGame) {
- _inputData._event = kEvQuitGame;
- } else
- if (keyDown == kEvSaveGame) {
- _inputData._event = kEvSaveGame;
- } else
- if (keyDown == kEvLoadGame) {
- _inputData._event = kEvLoadGame;
- } else {
+ if (_hasKeyPressEvent && (_vm->getFeatures() & GF_DEMO) == 0) {
+ if (_keyPressed.keycode == Common::KEYCODE_l) _inputData._event = kEvLoadGame;
+ if (_keyPressed.keycode == Common::KEYCODE_s) _inputData._event = kEvSaveGame;
+ }
+
+ if (_inputData._event == kEvNone) {
_inputData._mousePos = _mousePos;
- _inputData._event = kEvNone;
- if (!translateGameInput()) {
- translateInventoryInput();
- }
+ translateGameInput();
}
}
-void Input::updateCommentInput() {
- waitUntilLeftClick();
-
- _vm->hideDialogueStuff();
- _vm->_gfx->setHalfbriteMode(false);
-
- _inputMode = kInputModeGame;
-}
InputData* Input::updateInput() {
@@ -193,15 +163,18 @@ InputData* Input::updateInput() {
switch (_inputMode) {
case kInputModeComment:
- updateCommentInput();
+ case kInputModeDialogue:
+ case kInputModeMenu:
+ readInput();
break;
case kInputModeGame:
updateGameInput();
break;
- case kInputModeDialogue:
+ case kInputModeInventory:
readInput();
+ updateInventoryInput();
break;
}
@@ -230,38 +203,45 @@ void Input::stopHovering() {
_vm->_gfx->hideFloatingLabel();
}
+void Input::takeAction(ZonePtr z) {
+ stopHovering();
+ _vm->pauseJobs();
+ _vm->runZone(z);
+ _vm->resumeJobs();
+}
+
+void Input::walkTo(const Common::Point &dest) {
+ stopHovering();
+ _vm->setArrowCursor();
+ _vm->_char.scheduleWalk(dest.x, dest.y);
+}
bool Input::translateGameInput() {
- if ((_engineFlags & kEnginePauseJobs) || (_engineFlags & kEngineInventory)) {
+ if (_engineFlags & kEnginePauseJobs) {
return false;
}
- if (_actionAfterWalk) {
+ if (_hasDelayedAction) {
// if walking is over, then take programmed action
- _inputData._event = kEvAction;
- _actionAfterWalk = false;
+ takeAction(_delayedActionZone);
+ _hasDelayedAction = false;
+ _delayedActionZone = nullZonePtr;
return true;
}
if (_mouseButtons == kMouseRightDown) {
// right button down shows inventory
-
- if (_vm->hitZone(kZoneYou, _mousePos.x, _mousePos.y) && (_activeItem._id != 0)) {
- _activeItem._index = (_activeItem._id >> 16) & 0xFFFF;
- _engineFlags |= kEngineDragging;
- }
-
- _inputData._event = kEvOpenInventory;
- _transCurrentHoverItem = -1;
+ enterInventoryMode();
return true;
}
// test if mouse is hovering on an interactive zone for the currently selected inventory item
ZonePtr z = _vm->hitZone(_activeItem._id, _mousePos.x, _mousePos.y);
+ Common::Point dest(_mousePos);
if (((_mouseButtons == kMouseLeftUp) && (_activeItem._id == 0) && ((_engineFlags & kEngineWalking) == 0)) && ((!z) || ((z->_type & 0xFFFF) != kZoneCommand))) {
- _inputData._event = kEvWalk;
+ walkTo(dest);
return true;
}
@@ -275,16 +255,17 @@ bool Input::translateGameInput() {
_inputData._zone = z;
if (z->_flags & kFlagsNoWalk) {
// character doesn't need to walk to take specified action
- _inputData._event = kEvAction;
-
+ takeAction(z);
} else {
// action delayed: if Zone defined a moveto position the character is programmed to move there,
// else it will move to the mouse position
- _inputData._event = kEvWalk;
- _actionAfterWalk = true;
+ _delayedActionZone = z;
+ _hasDelayedAction = true;
if (z->_moveTo.y != 0) {
- _inputData._mousePos = z->_moveTo;
+ dest = z->_moveTo;
}
+
+ walkTo(dest);
}
_vm->beep();
@@ -293,31 +274,40 @@ bool Input::translateGameInput() {
}
return true;
-
}
-bool Input::translateInventoryInput() {
- if ((_engineFlags & kEngineInventory) == 0) {
- return false;
+void Input::enterInventoryMode() {
+ bool hitCharacter = _vm->hitZone(kZoneYou, _mousePos.x, _mousePos.y);
+
+ if (hitCharacter) {
+ if (_activeItem._id != 0) {
+ _activeItem._index = (_activeItem._id >> 16) & 0xFFFF;
+ _engineFlags |= kEngineDragging;
+ } else {
+ _vm->setArrowCursor();
+ }
}
- // in inventory
- int16 _si = _vm->getHoverInventoryItem(_mousePos.x, _mousePos.y);
+ stopHovering();
+ _vm->pauseJobs();
+ _vm->openInventory();
- if (_mouseButtons == kMouseRightUp) {
- // right up hides inventory
+ _transCurrentHoverItem = -1;
- _inputData._event = kEvCloseInventory;
- _inputData._inventoryIndex = _vm->getHoverInventoryItem(_mousePos.x, _mousePos.y);
- _vm->highlightInventoryItem(-1); // disable
+ _inputMode = kInputModeInventory;
+}
- if ((_engineFlags & kEngineDragging) == 0) {
- return true;
- }
+void Input::exitInventoryMode() {
+ // right up hides inventory
+
+ int pos = _vm->getHoverInventoryItem(_mousePos.x, _mousePos.y);
+ _vm->highlightInventoryItem(-1); // disable
+
+ if ((_engineFlags & kEngineDragging)) {
_engineFlags &= ~kEngineDragging;
- ZonePtr z = _vm->hitZone(kZoneMerge, _activeItem._index, _vm->getInventoryItemIndex(_inputData._inventoryIndex));
+ ZonePtr z = _vm->hitZone(kZoneMerge, _activeItem._index, _vm->getInventoryItemIndex(pos));
if (z) {
_vm->dropItem(z->u.merge->_obj1);
@@ -326,25 +316,61 @@ bool Input::translateInventoryInput() {
_vm->_cmdExec->run(z->_commands);
}
- return true;
}
- if (_si == _transCurrentHoverItem) {
- _inputData._event = kEvNone;
+ _vm->closeInventory();
+ if (pos == -1) {
+ _vm->setArrowCursor();
+ } else {
+ const InventoryItem *item = _vm->getInventoryItem(pos);
+ if (item->_index != 0) {
+ _activeItem._id = item->_id;
+ _vm->setInventoryCursor(item->_index);
+ }
+ }
+ _vm->resumeJobs();
+
+ _inputMode = kInputModeGame;
+}
+
+bool Input::updateInventoryInput() {
+ if (_mouseButtons == kMouseRightUp) {
+ exitInventoryMode();
return true;
}
- _transCurrentHoverItem = _si;
- _inputData._event = kEvHoverInventory;
- _inputData._inventoryIndex = _si;
+ int16 _si = _vm->getHoverInventoryItem(_mousePos.x, _mousePos.y);
+ if (_si != _transCurrentHoverItem) {
+ _transCurrentHoverItem = _si;
+ _vm->highlightInventoryItem(_si); // enable
+ }
+
return true;
}
-void Input::showCursor(bool visible) {
- _mouseHidden = !visible;
- _vm->_system->showMouse(visible);
+void Input::setMouseState(MouseTriState state) {
+ assert(state == MOUSE_ENABLED_SHOW || state == MOUSE_ENABLED_HIDE || state == MOUSE_DISABLED);
+ _mouseState = state;
+
+ switch (_mouseState) {
+ case MOUSE_ENABLED_HIDE:
+ case MOUSE_DISABLED:
+ _vm->_system->showMouse(false);
+ break;
+
+ case MOUSE_ENABLED_SHOW:
+ _vm->_system->showMouse(true);
+ break;
+ }
+}
+
+MouseTriState Input::getMouseState() {
+ return _mouseState;
}
+bool Input::isMouseEnabled() {
+ return (_mouseState == MOUSE_ENABLED_SHOW) || (_mouseState == MOUSE_ENABLED_HIDE);
+}
} // namespace Parallaction