aboutsummaryrefslogtreecommitdiff
path: root/engines/tsage/blue_force/blueforce_ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/tsage/blue_force/blueforce_ui.cpp')
-rw-r--r--engines/tsage/blue_force/blueforce_ui.cpp273
1 files changed, 212 insertions, 61 deletions
diff --git a/engines/tsage/blue_force/blueforce_ui.cpp b/engines/tsage/blue_force/blueforce_ui.cpp
index e27c744486..fb4008d2c1 100644
--- a/engines/tsage/blue_force/blueforce_ui.cpp
+++ b/engines/tsage/blue_force/blueforce_ui.cpp
@@ -21,6 +21,7 @@
*/
#include "tsage/blue_force/blueforce_ui.h"
+#include "tsage/blue_force/blueforce_dialogs.h"
#include "tsage/blue_force/blueforce_logic.h"
#include "tsage/tsage.h"
#include "tsage/core.h"
@@ -29,8 +30,15 @@ namespace TsAGE {
namespace BlueForce {
+void StripProxy::process(Event &event) {
+ if (_action)
+ _action->process(event);
+}
+
+/*--------------------------------------------------------------------------*/
+
void UIElement::synchronize(Serializer &s) {
- AltSceneObject::synchronize(s);
+ BackgroundSceneObject::synchronize(s);
s.syncAsSint16LE(_field88);
s.syncAsSint16LE(_enabled);
s.syncAsSint16LE(_frameNum);
@@ -55,7 +63,7 @@ void UIElement::setEnabled(bool flag) {
void UIQuestion::process(Event &event) {
if (event.eventType == EVENT_BUTTON_DOWN) {
- int currentCursor = GLOBALS._events.getCursor();
+ CursorType currentCursor = GLOBALS._events.getCursor();
GLOBALS._events.hideCursor();
showDescription(currentCursor);
@@ -63,12 +71,13 @@ void UIQuestion::process(Event &event) {
}
}
-void UIQuestion::showDescription(int lineNum) {
- if (lineNum == 8) {
- // Unknown object description
+void UIQuestion::showDescription(CursorType cursor) {
+ if (cursor == INV_FOREST_RAP) {
+ // Forest rap item has a graphical display
+ showItem(5, 1, 1);
} else {
// Display object description
- SceneItem::display2(9001, lineNum);
+ SceneItem::display2(9001, (int)cursor);
}
}
@@ -79,17 +88,44 @@ void UIQuestion::setEnabled(bool flag) {
}
}
+void UIQuestion::showItem(int resNum, int rlbNum, int frameNum) {
+ GfxDialog::setPalette();
+
+ // Get the item to display
+ GfxSurface objImage = surfaceFromRes(resNum, rlbNum, frameNum);
+ Rect imgRect;
+ imgRect.resize(objImage, 0, 0, 100);
+ imgRect.center(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
+
+ // Save the area behind where the image will be displayed
+ GfxSurface *savedArea = Surface_getArea(BF_GLOBALS.gfxManager().getSurface(), imgRect);
+
+ // Draw the image
+ BF_GLOBALS.gfxManager().copyFrom(objImage, imgRect);
+
+ // Wait for a press
+ BF_GLOBALS._events.waitForPress();
+
+ // Restore the old area
+ BF_GLOBALS.gfxManager().copyFrom(*savedArea, imgRect);
+ delete savedArea;
+}
+
/*--------------------------------------------------------------------------*/
void UIScore::postInit(SceneObjectList *OwnerList) {
int xp = 266;
- _digit3.setup(1, 6, 1, 266, 180, 255);
+ _digit3.setup(1, 6, 1, xp, 180, 255);
+ _digit3.reposition();
xp += 7;
- _digit2.setup(1, 6, 1, 266, 180, 255);
+ _digit2.setup(1, 6, 1, xp, 180, 255);
+ _digit2.reposition();
xp += 7;
- _digit1.setup(1, 6, 1, 266, 180, 255);
+ _digit1.setup(1, 6, 1, xp, 180, 255);
+ _digit1.reposition();
xp += 7;
- _digit0.setup(1, 6, 1, 266, 180, 255);
+ _digit0.setup(1, 6, 1, xp, 180, 255);
+ _digit0.reposition();
}
void UIScore::draw() {
@@ -101,37 +137,46 @@ void UIScore::draw() {
void UIScore::updateScore() {
int score = BF_GLOBALS._uiElements._scoreValue;
-
- _digit3.setFrame(score / 1000); score %= 1000;
- _digit2.setFrame(score / 100); score %= 100;
- _digit1.setFrame(score / 10); score %= 10;
- _digit0.setFrame(score);
+
+ _digit3.setFrame(score / 1000 + 1); score %= 1000;
+ _digit2.setFrame(score / 100 + 1); score %= 100;
+ _digit1.setFrame(score / 10 + 1); score %= 10;
+ _digit0.setFrame(score + 1);
}
/*--------------------------------------------------------------------------*/
UIInventorySlot::UIInventorySlot(): UIElement() {
_objIndex = 0;
+ _object = NULL;
}
void UIInventorySlot::synchronize(Serializer &s) {
UIElement::synchronize(s);
s.syncAsSint16LE(_objIndex);
+ SYNC_POINTER(_object);
}
void UIInventorySlot::process(Event &event) {
if (event.eventType == EVENT_BUTTON_DOWN) {
event.handled = true;
- if (_objIndex == 66) {
- // Handle showing gun and ammo
- warning("TODO: show gun");
- } else if (_objIndex != 0) {
- GLOBALS._events.setCursor((CursorType)_objIndex);
+ if (_objIndex == INV_AMMO_BELT) {
+ // Handle showing ammo belt
+ showAmmoBelt();
+
+ } else if (_objIndex != INV_NONE) {
+ _object->setCursor();
}
}
}
+void UIInventorySlot::showAmmoBelt() {
+ AmmoBeltDialog *dlg = new AmmoBeltDialog();
+ dlg->execute();
+ delete dlg;
+}
+
/*--------------------------------------------------------------------------*/
UIInventoryScroll::UIInventoryScroll() {
@@ -144,9 +189,30 @@ void UIInventoryScroll::synchronize(Serializer &s) {
}
void UIInventoryScroll::process(Event &event) {
- if (event.eventType == EVENT_BUTTON_DOWN) {
- warning("TODO: UIInventoryScroll::process");
+ switch (event.eventType) {
+ case EVENT_BUTTON_DOWN:
+ // Draw the button as selected
+ toggle(true);
+
event.handled = true;
+ break;
+ case EVENT_BUTTON_UP:
+ // Restore unselected version
+ toggle(false);
+
+ // Scroll the inventory as necessary
+ BF_GLOBALS._uiElements.scrollInventory(_isLeft);
+ event.handled = true;
+ break;
+ default:
+ break;
+ }
+}
+
+void UIInventoryScroll::toggle(bool pressed) {
+ if (_enabled) {
+ setFrame(pressed ? (_frameNum + 1) : _frameNum);
+ BF_GLOBALS._uiElements.draw();
}
}
@@ -155,7 +221,7 @@ void UIInventoryScroll::process(Event &event) {
UICollection::UICollection(): EventHandler() {
_clearScreen = false;
_visible = false;
- _field4E = 0;
+ _cursorChanged = false;
}
void UICollection::setup(const Common::Point &pt) {
@@ -169,10 +235,16 @@ void UICollection::hide() {
_visible = false;
}
+void UICollection::show() {
+ _visible = true;
+ draw();
+}
+
void UICollection::erase() {
if (_clearScreen) {
Rect tempRect(0, BF_INTERFACE_Y, SCREEN_WIDTH, SCREEN_HEIGHT);
- GLOBALS._screenSurface.fillRect(tempRect, 0);
+ BF_GLOBALS._screenSurface.fillRect(tempRect, 0);
+ BF_GLOBALS._sceneManager._scene->_backSurface.fillRect(tempRect, 0);
_clearScreen = false;
}
}
@@ -183,30 +255,89 @@ void UICollection::resetClear() {
void UICollection::draw() {
if (_visible) {
- // Draw the elements
+ // Draw the elements onto the background
for (uint idx = 0; idx < _objList.size(); ++idx)
_objList[idx]->draw();
- // Update the screen
- g_system->updateScreen();
+ // Draw the resulting UI onto the screen
+ BF_GLOBALS._screenSurface.copyFrom(BF_GLOBALS._sceneManager._scene->_backSurface,
+ Rect(0, BF_INTERFACE_Y, SCREEN_WIDTH, SCREEN_HEIGHT),
+ Rect(0, BF_INTERFACE_Y, SCREEN_WIDTH, SCREEN_HEIGHT));
+
_clearScreen = 1;
}
}
/*--------------------------------------------------------------------------*/
+UIElements::UIElements(): UICollection() {
+ _cursorVisage.setVisage(1, 5);
+ g_saver->addLoadNotifier(&UIElements::loadNotifierProc);
+}
+
+void UIElements::synchronize(Serializer &s) {
+ UICollection::synchronize(s);
+
+ s.syncAsSint16LE(_slotStart);
+ s.syncAsSint16LE(_scoreValue);
+ s.syncAsByte(_active);
+
+ int count = _itemList.size();
+ s.syncAsSint16LE(count);
+ if (s.isLoading()) {
+ // Load in item list
+ _itemList.clear();
+
+ for (int idx = 0; idx < count; ++idx) {
+ int itemId;
+ s.syncAsSint16LE(itemId);
+ _itemList.push_back(itemId);
+ }
+ } else {
+ // Save item list
+ for (int idx = 0; idx < count; ++idx) {
+ int itemId = _itemList[idx];
+ s.syncAsSint16LE(itemId);
+ }
+ }
+}
+
void UIElements::process(Event &event) {
- if (_clearScreen && BF_GLOBALS._player._field8E && (BF_GLOBALS._sceneManager._sceneNumber != 50)) {
+ if (_clearScreen && BF_GLOBALS._player._enabled && (BF_GLOBALS._sceneManager._sceneNumber != 50)) {
if (_bounds.contains(event.mousePos)) {
+ // Cursor inside UI area
+ if (!_cursorChanged) {
+ if (BF_GLOBALS._events.isInventoryIcon()) {
+ // Inventory icon being displayed, so leave alone
+ } else {
+ // Change to the inventory use cursor
+ GfxSurface surface = _cursorVisage.getFrame(6);
+ BF_GLOBALS._events.setCursor(surface);
+ }
+ _cursorChanged = true;
+ }
+
+ // Pass event to any element that the cursor falls on
+ for (int idx = (int)_objList.size() - 1; idx >= 0; --idx) {
+ if (_objList[idx]->_bounds.contains(event.mousePos) && _objList[idx]->_enabled) {
+ _objList[idx]->process(event);
+ if (event.handled)
+ break;
+ }
+ }
- } else if (_field4E) {
- BF_GLOBALS._events.hideCursor();
- BF_GLOBALS._events.setCursor((CursorType)1);
- _field4E = 0;
+ if (event.eventType == EVENT_BUTTON_DOWN)
+ event.handled = true;
+
+ } else if (_cursorChanged) {
+ // Cursor outside UI area, so reset as necessary
+ BF_GLOBALS._events.setCursor(BF_GLOBALS._events.getCursor());
+ _cursorChanged = false;
SceneExt *scene = (SceneExt *)BF_GLOBALS._sceneManager._scene;
- if (scene->_eventHandler) {
- error("TODO: UIElements::process _eventHandler");
+ if (scene->_focusObject) {
+ GfxSurface surface = _cursorVisage.getFrame(7);
+ BF_GLOBALS._events.setCursor(surface);
}
}
}
@@ -216,7 +347,7 @@ void UIElements::setup(const Common::Point &pt) {
_slotStart = 0;
_itemList.clear();
_scoreValue = 0;
- _field820 = 1;
+ _active = true;
UICollection::setup(pt);
hide();
@@ -224,6 +355,7 @@ void UIElements::setup(const Common::Point &pt) {
add(&_object1);
// Set up the inventory slots
+ int xp = 0;
for (int idx = 0; idx < 4; ++idx) {
UIElement *item = NULL;
switch (idx) {
@@ -241,14 +373,16 @@ void UIElements::setup(const Common::Point &pt) {
break;
}
- item->setup(9, 1, idx, idx * 63 + 2, 4, 255);
+ xp = idx * 63 + 2;
+ item->setup(9, 1, idx, xp, 4, 255);
add(item);
}
// Setup bottom-right hand buttons
- int xp = 62;
+ xp += 62;
_question.setup(1, 4, 7, xp, 16, 255);
_question.setEnabled(false);
+ add(&_question);
xp += 21;
_scrollLeft.setup(1, 4, 1, xp, 16, 255);
@@ -271,11 +405,13 @@ void UIElements::setup(const Common::Point &pt) {
}
void UIElements::add(UIElement *obj) {
- // Add object
+ // Add object
assert(_objList.size() < 12);
_objList.push_back(obj);
- obj->setPosition(Common::Point(_bounds.left + obj->_bounds.left, _bounds.top + obj->_bounds.top));
+ obj->setPosition(Common::Point(_bounds.left + obj->_position.x, _bounds.top + obj->_position.y));
+ obj->reposition();
+
GfxSurface s = obj->getFrame();
s.draw(obj->_position);
}
@@ -285,10 +421,10 @@ void UIElements::add(UIElement *obj) {
*/
void UIElements::updateInventory() {
_score.updateScore();
- updateInvList();
+ updateInvList();
// Enable scroll buttons if the player has more than four items
- if (_itemCount > 4) {
+ if (_itemList.size() > 4) {
_scrollLeft.setEnabled(true);
_scrollRight.setEnabled(true);
} else {
@@ -297,28 +433,31 @@ void UIElements::updateInventory() {
}
// Handle cropping the slots start within inventory
- int last = (_itemList.size() - 1) / 4 + 1;
+ int lastPage = (_itemList.size() - 1) / 4 + 1;
if (_slotStart < 0)
- _slotStart = last - 1;
- else if (_slotStart > (last - 1))
+ _slotStart = lastPage - 1;
+ else if (_slotStart > (lastPage - 1))
_slotStart = 0;
// Handle refreshing slot graphics
UIInventorySlot *slotList[4] = { &_slot1, &_slot2, &_slot3, &_slot4 };
-
+
+ // Loop through the inventory objects
SynchronizedList<InvObject *>::iterator i;
int objIndex = 0;
- for (i = BLUE_INVENTORY._itemList.begin(); i != BLUE_INVENTORY._itemList.end(); ++i, ++objIndex) {
+ for (i = BF_INVENTORY._itemList.begin(); i != BF_INVENTORY._itemList.end(); ++i, ++objIndex) {
InvObject *obj = *i;
+ // Check whether the object is in any of the four inventory slots
for (int slotIndex = 0; slotIndex < 4; ++slotIndex) {
- int idx = _slotStart + slotIndex;
+ int idx = _slotStart * 4 + slotIndex;
int objectIdx = (idx < (int)_itemList.size()) ? _itemList[idx] : 0;
if (objectIdx == objIndex) {
UIInventorySlot *slot = slotList[slotIndex];
slot->_objIndex = objIndex;
+ slot->_object = obj;
slot->setVisage(obj->_visage);
slot->setStrip(obj->_strip);
slot->setFrame(obj->_frame);
@@ -326,7 +465,8 @@ void UIElements::updateInventory() {
}
}
- if (_field820)
+ // Refresh the display if necessary
+ if (_active)
draw();
}
@@ -347,19 +487,30 @@ void UIElements::updateInvList() {
}
/**
- * Updates an inventory slot with the item to be displayed
-
-void UIElements::updateInvSlot(UIInventorySlot *slot, int objIndex) {
- slot->_objIndex = objIndex;
- int itemId = (objIndex < (int)_itemList.size()) ? _itemList[objIndex] : 0;
- InvObject *obj = BF_GLOBALS._inventory->_itemList[itemId + 2];
-
- // TODO: Validate usage of fields
- slot->setVisage(obj._displayResNum);
- slot->setStrip(obj._rlbNum);
- slot->setFrame(obj._cursorNum);
-}
-*/
+ * Set the game score
+ */
+void UIElements::addScore(int amount) {
+ _scoreValue += amount;
+ BF_GLOBALS._sound2.play(0);
+ updateInventory();
+}
+
+/*
+ * Scroll the inventory slots
+ */
+void UIElements::scrollInventory(bool isLeft) {
+ if (isLeft)
+ --_slotStart;
+ else
+ ++_slotStart;
+
+ updateInventory();
+}
+
+void UIElements::loadNotifierProc(bool postFlag) {
+ if (postFlag && BF_GLOBALS._uiElements._active)
+ BF_GLOBALS._uiElements.show();
+}
} // End of namespace BlueForce