diff options
Diffstat (limited to 'engines/tsage/blue_force/blueforce_dialogs.cpp')
-rw-r--r-- | engines/tsage/blue_force/blueforce_dialogs.cpp | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/engines/tsage/blue_force/blueforce_dialogs.cpp b/engines/tsage/blue_force/blueforce_dialogs.cpp index ec99df8c3b..be72b78622 100644 --- a/engines/tsage/blue_force/blueforce_dialogs.cpp +++ b/engines/tsage/blue_force/blueforce_dialogs.cpp @@ -196,6 +196,175 @@ void RightClickDialog::execute() { _gfxManager.deactivate(); } +/*--------------------------------------------------------------------------*/ + +AmmoBeltDialog::AmmoBeltDialog() : GfxDialog() { + _cursorNum = BF_GLOBALS._events.getCursor(); + _inDialog = -1; + _closeFlag = false; + + // Get the dialog image + _surface = surfaceFromRes(9, 5, 2); + + // Set the dialog position + _dialogRect.resize(_surface, 0, 0, 100); + _dialogRect.center(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2); + + _bounds = _dialogRect; + _gfxManager._bounds = _bounds; + _savedArea = NULL; + + // Set up area rects + _gunRect.set(0, 0, 82, 48); + _clip1Rect.set(90, 6, _bounds.width(), 39); + _clip2Rect.set(90, 40, _bounds.width(), _bounds.height()); + _loadedRect.set(50, 40, 60, 50); +} + +AmmoBeltDialog::~AmmoBeltDialog() { + BF_GLOBALS._events.setCursor(_cursorNum); +} + +void AmmoBeltDialog::execute() { + // Draw the dialog + draw(); + + // Dialog event handler loop + _gfxManager.activate(); + + while (!_vm->shouldQuit() && !_closeFlag) { + Event evt; + while (_globals->_events.getEvent(evt, EVENT_MOUSE_MOVE | EVENT_BUTTON_DOWN)) { + evt.mousePos.x -= _bounds.left; + evt.mousePos.y -= _bounds.top; + + process(evt); + } + + g_system->delayMillis(10); + g_system->updateScreen(); + } + + _gfxManager.deactivate(); +} + +bool AmmoBeltDialog::process(Event &event) { + switch (event.eventType) { + case EVENT_MOUSE_MOVE: { + // Handle updating cursor depending on whether cursor is in dialog or not + int inDialog = Rect(0, 0, _bounds.width(), _bounds.height()).contains(event.mousePos); + if (inDialog != _inDialog) { + // Update cursor + BF_GLOBALS._events.setCursor(inDialog ? CURSOR_USE : CURSOR_EXIT); + _inDialog = inDialog; + } + return true; + } + + case EVENT_BUTTON_DOWN: + if (!_inDialog) + // Clicked outside dialog, so flag to close it + _closeFlag = true; + else { + int v = (BF_GLOBALS.getFlag(fGunLoaded) ? 1 : 0) * (BF_GLOBALS.getFlag(fLoadedSpare) ? 2 : 1); + + // Handle first clip + if ((v != 1) && _clip1Rect.contains(event.mousePos)) { + if (BF_GLOBALS.getFlag(fGunLoaded)) { + event.mousePos.x = event.mousePos.y = 0; + } + + BF_GLOBALS.setFlag(fGunLoaded); + BF_GLOBALS.clearFlag(fLoadedSpare); + } + + // Handle second clip + if ((v != 2) && _clip2Rect.contains(event.mousePos)) { + if (BF_GLOBALS.getFlag(fGunLoaded)) { + event.mousePos.x = event.mousePos.y = 0; + } + + BF_GLOBALS.setFlag(fGunLoaded); + BF_GLOBALS.setFlag(fLoadedSpare); + } + + if (_gunRect.contains(event.mousePos) && BF_GLOBALS.getFlag(fGunLoaded)) { + BF_GLOBALS.clearFlag(fGunLoaded); + v = (BF_GLOBALS.getFlag(fGunLoaded) ? 1 : 0) * (BF_GLOBALS.getFlag(fLoadedSpare) ? 2 : 1); + + if (v != 2) + BF_GLOBALS.clearFlag(fLoadedSpare); + } + + draw(); + } + + return true; + + case EVENT_KEYPRESS: + if ((event.kbd.keycode == Common::KEYCODE_ESCAPE) || (event.kbd.keycode == Common::KEYCODE_RETURN)) { + // Escape pressed, so flag to close dialog + _closeFlag = true; + return true; + } + break; + + default: + break; + } + + return false; +} + +void AmmoBeltDialog::draw() { + Rect bounds = _bounds; + + if (!_savedArea) { + // Save the covered background area + _savedArea = Surface_getArea(_globals->_gfxManagerInstance.getSurface(), _bounds); + } else { + bounds.moveTo(0, 0); + } + + // Draw the dialog image + _globals->gfxManager().copyFrom(_surface, bounds.left, bounds.top); + + // Setup clip flags + bool clip1 = true, clip2 = true; + bool gunLoaded = BF_GLOBALS.getFlag(fGunLoaded); + if (gunLoaded) { + // A clip is currently loaded. Hide the appropriate clip + if (BF_GLOBALS.getFlag(fLoadedSpare)) + clip2 = false; + else + clip1 = false; + } + + // Draw the first clip if necessary + if (clip1) { + GfxSurface clipSurface = surfaceFromRes(9, 6, BF_GLOBALS._clip1Frame); + _clip1Rect.resize(clipSurface, _clip1Rect.left, _clip1Rect.top, 100); + _globals->gfxManager().copyFrom(clipSurface, bounds.left + _clip1Rect.left, + bounds.top + _clip1Rect.top); + } + + // Draw the second clip if necessary + if (clip2) { + GfxSurface clipSurface = surfaceFromRes(9, 6, BF_GLOBALS._clip2Frame); + _clip2Rect.resize(clipSurface, _clip2Rect.left, _clip2Rect.top, 100); + _globals->gfxManager().copyFrom(clipSurface, bounds.left + _clip2Rect.left, + bounds.top + _clip2Rect.top); + } + + // If a clip is loaded, draw the 'loaded' portion of the gun + if (gunLoaded) { + GfxSurface loadedSurface = surfaceFromRes(9, 7, 1); + _loadedRect.resize(loadedSurface, _loadedRect.left, _loadedRect.top, 100); + _globals->gfxManager().copyFrom(loadedSurface, bounds.left + _loadedRect.left, + bounds.top + _loadedRect.top); + } +} + } // End of namespace BlueForce } // End of namespace TsAGE |