[Scummvm-cvs-logs] SF.net SVN: scummvm:[55846] scummvm/trunk/engines/lastexpress

Littleboy at users.sourceforge.net Littleboy at users.sourceforge.net
Wed Feb 9 01:23:36 CET 2011


Revision: 55846
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55846&view=rev
Author:   Littleboy
Date:     2011-02-09 00:23:35 +0000 (Wed, 09 Feb 2011)

Log Message:
-----------
LASTEXPRESS: Refactor inventory handling

 - Rewrite menu icon part of Inventory::handleMouseEvent()
 - Add proper support for icon brightness
 - Add drawItem method in place of macro

Modified Paths:
--------------
    scummvm/trunk/engines/lastexpress/data/cursor.cpp
    scummvm/trunk/engines/lastexpress/data/cursor.h
    scummvm/trunk/engines/lastexpress/game/fight.cpp
    scummvm/trunk/engines/lastexpress/game/inventory.cpp
    scummvm/trunk/engines/lastexpress/game/inventory.h
    scummvm/trunk/engines/lastexpress/lastexpress.cpp

Modified: scummvm/trunk/engines/lastexpress/data/cursor.cpp
===================================================================
--- scummvm/trunk/engines/lastexpress/data/cursor.cpp	2011-02-09 00:14:24 UTC (rev 55845)
+++ scummvm/trunk/engines/lastexpress/data/cursor.cpp	2011-02-09 00:23:35 UTC (rev 55846)
@@ -33,6 +33,8 @@
 
 namespace LastExpress {
 
+uint16 brigthnessData[4] = { 0, 0x7BDE, 0x739C, 0x6318 };
+
 Cursor::Cursor() : _current(kCursorMAX) {
 	memset(&_cursors, 0, sizeof(_cursors));
 }
@@ -105,17 +107,17 @@
 }
 
 
-Icon::Icon(CursorStyle style) : _style(style), _x(0), _y(0), _brightness(100) {}
+Icon::Icon(CursorStyle style) : _style(style), _x(0), _y(0), _brightnessIndex(-1) {}
 
 void Icon::setPosition(int16 x, int16 y) {
 	_x = x;
 	_y = y;
 }
 
-void Icon::setBrightness(uint brightness) {
-	assert(brightness <= 100);
+void Icon::setBrightness(int16 brightnessIndex) {
+	assert(brightnessIndex < ARRAYSIZE(brigthnessData));
 
-	_brightness = (uint8)brightness;
+	_brightnessIndex = brightnessIndex;
 }
 
 Common::Rect Icon::draw(Graphics::Surface *surface) {
@@ -127,11 +129,12 @@
 	for (int j = 0; j < 32; j++) {
 		uint16 *s = (uint16 *)surface->getBasePtr(_x, _y + j);
 		for (int i = 0; i < 32; i++) {
-			if (_brightness == 100)
+
+			// Adjust brightness
+			if (_brightnessIndex == -1)
 				*s = *image;
 			else
-				// HACK change color to show highlight
-				*s = (*image & 0x739C) >> 1;
+				*s = (*image & brigthnessData[_brightnessIndex]) >> _brightnessIndex;
 
 			// Update the image and surface pointers
 			image++;

Modified: scummvm/trunk/engines/lastexpress/data/cursor.h
===================================================================
--- scummvm/trunk/engines/lastexpress/data/cursor.h	2011-02-09 00:14:24 UTC (rev 55845)
+++ scummvm/trunk/engines/lastexpress/data/cursor.h	2011-02-09 00:23:35 UTC (rev 55846)
@@ -54,13 +54,13 @@
 	Icon(CursorStyle style);
 
 	void setPosition(int16 x, int16 y);
-	void setBrightness(uint brightness);
+	void setBrightness(int16 brightnessIndex);
 	Common::Rect draw(Graphics::Surface *surface);
 
 private:
 	CursorStyle _style;
 	int16 _x, _y;
-	uint8 _brightness;
+	int16 _brightnessIndex;
 };
 
 class Cursor {

Modified: scummvm/trunk/engines/lastexpress/game/fight.cpp
===================================================================
--- scummvm/trunk/engines/lastexpress/game/fight.cpp	2011-02-09 00:14:24 UTC (rev 55845)
+++ scummvm/trunk/engines/lastexpress/game/fight.cpp	2011-02-09 00:23:35 UTC (rev 55846)
@@ -108,7 +108,7 @@
 		if (_handleTimer) {
 			// Timer expired => show with full brightness
 			if (!getGlobalTimer())
-				getInventory()->drawEgg();
+				getInventory()->drawBlinkingEgg();
 
 			_handleTimer = false;
 		}
@@ -136,7 +136,7 @@
 		if (!_handleTimer) {
 			// Timer expired => show with full brightness
 			if (!getGlobalTimer())
-				getInventory()->drawEgg();
+				getInventory()->drawBlinkingEgg();
 
 			_handleTimer = true;
 		}

Modified: scummvm/trunk/engines/lastexpress/game/inventory.cpp
===================================================================
--- scummvm/trunk/engines/lastexpress/game/inventory.cpp	2011-02-09 00:14:24 UTC (rev 55845)
+++ scummvm/trunk/engines/lastexpress/game/inventory.cpp	2011-02-09 00:23:35 UTC (rev 55846)
@@ -41,13 +41,11 @@
 #include "lastexpress/resource.h"
 
 
-#define drawItem(x, y, index, brightness) { Icon icon((CursorStyle)(index)); icon.setPosition(x, y); icon.setBrightness(brightness); _engine->getGraphicsManager()->draw(&icon, GraphicsManager::kBackgroundInventory); }
-
 namespace LastExpress {
 
 Inventory::Inventory(LastExpressEngine *engine) : _engine(engine), _selectedItem(kItemNone), _highlightedItem(kItemNone), _opened(false), _visible(false),
-	_showingHourGlass(false), _blinkingEgg(false), _blinkingTime(0), _blinkingInterval(_defaultBlinkingInterval), _blinkingBrightness(100),
-	_flagUseMagnifier(false), _flag1(false), _flag2(false), _flagEggHightlighted(false), _itemScene(NULL) {
+	_showingHourGlass(false), _blinkingEgg(false), _blinkingTime(0), _blinkingInterval(_defaultBlinkingInterval), _blinkingBrightness(1),
+	_useMagnifier(false), _flag1(false), _flag2(false), _eggHightlighted(false), _itemScene(NULL) {
 
 	_inventoryRect = Common::Rect(0, 0, 32, 32);
 	_menuRect = Common::Rect(608, 448, 640, 480);
@@ -134,48 +132,70 @@
 
 // TODO if we draw inventory objects on screen, we need to load a new scene.
 // Signal that the inventory has taken over the screen and stop processing mouse events after we have been called
-bool Inventory::handleMouseEvent(const Common::Event &ev) {
+void Inventory::handleMouseEvent(const Common::Event &ev) {
+	_useMagnifier = false;
 
-	// Do not show inventory when on the menu screen
-	if (getMenu()->isShown() || !_visible)
-		return false;
+	// Egg (menu)
+	if (!_menuRect.contains(ev.mouse)) {
+		// Remove highlight if needed
+		if (_eggHightlighted) {
+			if (!getGlobalTimer()) {
+				drawItem((CursorStyle)(getMenu()->getGameId() + 39), 608, 448, 1);
+				askForRedraw();
+			}
+			_eggHightlighted = false;
+		}
+	} else {
+		// Highlight menu
+		if (!_eggHightlighted) {
+			if (!getGlobalTimer()) {
+				drawItem((CursorStyle)(getMenu()->getGameId() + 39), 608, 448);
+				askForRedraw();
+			}
 
-	// Flag to know whether to restore the current cursor or not
-	bool insideInventory = false;
+			_eggHightlighted = true;
+		}
 
-	// Egg (menu)
-	if (_menuRect.contains(ev.mouse)) {
-		insideInventory = true;
-		_engine->getCursor()->setStyle(kCursorNormal);
-
 		// If clicked, show the menu
-		if (ev.type == Common::EVENT_LBUTTONUP) {
-			getSound()->playSound(kEntityPlayer, "LIB039");
-			getMenu()->show(false, kSavegameTypeIndex, 0);
+		if (ev.type == Common::EVENT_LBUTTONDOWN) {
+			_eggHightlighted = false;
+			_flag1 = false;
+			_flag2 = false;
 
-			// TODO can we return directly or do we need to make sure the state will be "valid" when we come back from the menu
-			return true;
-		} else {
-			// Highlight if needed
-			if (_highlightedItem != getMenu()->getGameId() + 39) {
-				_highlightedItem = (InventoryItem)(getMenu()->getGameId() + 39);
-				drawItem(608, 448, _highlightedItem, 100)
+			getSound()->playSoundWithSubtitles("LIB039.SND", SoundManager::kFlagMenuClock, kEntityPlayer);
 
-				askForRedraw();
+			getMenu()->show(true, kSavegameTypeIndex, 0);
+		} else if (ev.type == Common::EVENT_RBUTTONDOWN) {
+			if (getGlobalTimer()) {
+				if (getSound()->isBuffered("TIMER"))
+					getSound()->removeFromQueue("TIMER");
+
+				setGlobalTimer(900);
 			}
 		}
-	} else {
-		// remove highlight if needed
-		if (_highlightedItem == getMenu()->getGameId() + 39) {
-			drawItem(608, 448, _highlightedItem, 50)
-			_highlightedItem = kItemNone;
-			askForRedraw();
-		}
 	}
 
+	//
+	//// If clicked, show the menu
+	//if (ev.type == Common::EVENT_LBUTTONUP) {
+	//	getSound()->playSound(kEntityPlayer, "LIB039");
+	//	getMenu()->show(false, kSavegameTypeIndex, 0);
+
+	//	// TODO can we return directly or do we need to make sure the state will be "valid" when we come back from the menu
+	//	return true;
+	//} else {
+	//	// Highlight if needed
+	//	if (_highlightedItem != getMenu()->getGameId() + 39) {
+	//		_highlightedItem = (InventoryItem);
+	//		drawItem(get(_highlightedItem)->cursor, 608, 448);
+
+	//		askForRedraw();
+	//	}
+	//}
+
 	// Portrait (inventory)
 	if (_inventoryRect.contains(ev.mouse)) {
-		insideInventory = true;
+		//insideInventory = true;
 		_engine->getCursor()->setStyle(kCursorNormal);
 
 		// If clicked, show pressed state and display inventory
@@ -185,7 +205,7 @@
 			// Highlight if needed
 			if (_highlightedItem != (InventoryItem)getProgress().portrait && !_opened) {
 				_highlightedItem = (InventoryItem)getProgress().portrait;
-				drawItem(0, 0, getProgress().portrait, 100)
+				drawItem((CursorStyle)getProgress().portrait, 0, 0);
 
 				askForRedraw();
 			}
@@ -193,7 +213,7 @@
 	} else {
 		// remove highlight if needed
 		if (_highlightedItem == (InventoryItem)getProgress().portrait && !_opened) {
-			drawItem(0, 0, getProgress().portrait, 50)
+			drawItem((CursorStyle)getProgress().portrait, 0, 0);
 			_highlightedItem = kItemNone;
 			askForRedraw();
 		}
@@ -203,7 +223,7 @@
 	if (_opened) {
 
 		// Always show normal cursor when the inventory is opened
-		insideInventory = true;
+		//insideInventory = true;
 		_engine->getCursor()->setStyle(kCursorNormal);
 
 		bool selected = false;
@@ -221,14 +241,14 @@
 					if (_entries[i].isSelectable) {
 						selected = true;
 						_selectedItem = (InventoryItem)i;
-						drawItem(44, 0, get(_selectedItem)->cursor, 100)
+						drawItem(get(_selectedItem)->cursor, 44, 0);
 					}
 
 					examine((InventoryItem)i);
 					break;
 				} else {
 					if (_highlightedItem != i) {
-						drawItem(0, y, _entries[i].cursor, 100)
+						drawItem(_entries[i].cursor, 0, y);
 						_highlightedItem = (InventoryItem)i;
 						askForRedraw();
 					}
@@ -236,7 +256,7 @@
 			} else {
 				// Remove highlight if necessary
 				if (_highlightedItem == i) {
-					drawItem(0, y, _entries[i].cursor, 50)
+					drawItem(_entries[i].cursor, 0, y);
 					_highlightedItem = kItemNone;
 					askForRedraw();
 				}
@@ -258,13 +278,13 @@
 
 	// Selected item
 	if (_selectedItem != kItemNone && _selectedRect.contains(ev.mouse)) {
-		insideInventory = true;
+		//insideInventory = true;
 
 		// Show magnifier icon
 		_engine->getCursor()->setStyle(kCursorMagnifier);
 
 		if (ev.type == Common::EVENT_LBUTTONUP) {
-			examine((InventoryItem)_selectedItem);
+			examine(_selectedItem);
 		}
 	}
 
@@ -275,8 +295,6 @@
 	// Restore cursor
 	//if (!insideInventory)
 	//	_engine->getCursor()->setStyle(getLogic()->getCursorStyle());
-
-	return insideInventory;
 }
 
 //////////////////////////////////////////////////////////////////////////
@@ -287,18 +305,18 @@
 	askForRedraw();
 
 	// Show portrait (first draw, cannot be highlighted)
-	drawItem(0, 0, getProgress().portrait, 50)
+	drawItem((CursorStyle)getProgress().portrait, 0, 0);
 
 	// Show selected item
 	if (_selectedItem != kItemNone)
-		drawItem(44, 0, _selectedItem, 100)
+		drawItem(get(_selectedItem)->cursor, 44, 0);
 
 	drawEgg();
 }
 
-void Inventory::setPortrait(InventoryItem item) const {
+void Inventory::setPortrait(InventoryItem item) {
 	getProgress().portrait = item;
-	drawItem(0, 0, getProgress().portrait, 50);
+	drawItem((CursorStyle)getProgress().portrait, 0, 0);
 }
 
 void Inventory::blinkEgg(bool enabled) {
@@ -309,22 +327,23 @@
 
 	// Show egg at full brightness for first step if blinking
 	if (_blinkingEgg)
-		drawItem(608, 448, getMenu()->getGameId() + 39, _blinkingBrightness)
+		drawItem((CursorStyle)(getMenu()->getGameId() + 39), 608, 448, _blinkingBrightness);
 	else {
 		// Reset values
-		_blinkingBrightness = 100;
+		_blinkingBrightness = 1;
 		_blinkingInterval = _defaultBlinkingInterval;
-		drawItem(608, 448, getMenu()->getGameId() + 39, 50) // normal egg state
+		drawItem((CursorStyle)(getMenu()->getGameId() + 39), 608, 448); // normal egg state
 	}
 
 	askForRedraw();
 }
 
-void Inventory::showHourGlass() const{
-	if (!getFlags()->flag_5) {
-		drawItem(608, 448, kCursorHourGlass, 100);
-	}
+void Inventory::showHourGlass(){
+	if (!getMenu()->isShown())
+		drawItem(kCursorHourGlass, 608, 448);
 
+	getFlags()->shouldRedraw = false;
+
 	askForRedraw();
 
 	getFlags()->shouldDrawEggOrHourGlass = true;
@@ -349,8 +368,8 @@
 
 	// Auto-select item if necessary
 	if (get(item)->cursor && !get(item)->manualSelect) {
-		_selectedItem = (InventoryItem)get(item)->cursor;
-		drawItem(44, 0, _selectedItem, 100)
+		_selectedItem = item;
+		drawItem(get(_selectedItem)->cursor, 44, 0);
 		askForRedraw();
 	}
 }
@@ -362,7 +381,7 @@
 	get(item)->isPresent = false;
 	get(item)->location = newLocation;
 
-	if (get(item)->cursor == (CursorStyle)_selectedItem) {
+	if (get(item)->cursor == get(_selectedItem)->cursor) {
 		_selectedItem = kItemNone;
 		_engine->getGraphicsManager()->clear(GraphicsManager::kBackgroundInventory, Common::Rect(44, 0, 44 + 32, 32));
 		askForRedraw();
@@ -379,7 +398,7 @@
 void Inventory::selectItem(InventoryItem item) {
 	_selectedItem = item;
 
-	drawItem(44, 0, get(_selectedItem)->cursor, 100)
+	drawItem(get(_selectedItem)->cursor, 44, 0);
 	askForRedraw();
 }
 
@@ -509,11 +528,9 @@
 	}
 }
 
-// FIXME: see different callers and adjust
-// - draw with different brightness if mousing over
-void Inventory::drawEgg() const {
-	if (!getFlags()->flag_5)
-		drawItem(608, 448, getMenu()->getGameId() + 39, 50)
+void Inventory::drawEgg() {
+	if (!getMenu()->isShown())
+		drawItem((CursorStyle)(getMenu()->getGameId() + 39), 608, 448);
 
 	getFlags()->shouldDrawEggOrHourGlass = false;
 }
@@ -552,19 +569,29 @@
 	askForRedraw();
 }
 
+void Inventory::drawItem(CursorStyle id, uint16 x, uint16 y, uint16 brightnessIndex) {
+	Icon icon(id);
+	icon.setPosition(x, y);
+
+	if (brightnessIndex != -1)
+		icon.setBrightness(brightnessIndex);
+
+	_engine->getGraphicsManager()->draw(&icon, GraphicsManager::kBackgroundInventory);
+}
+
 // Close inventory: clear items and reset icon
 void Inventory::open() {
 	_opened = true;
 
 	// Show selected state
-	drawItem(0, 0, getProgress().portrait + 1, 100)
+	drawItem((CursorStyle)(getProgress().portrait + 1), 0, 0);
 
-	int16 y = 44;
+	uint16 y = 44;
 
 	// Iterate over items
 	for (uint i = 1; i < 32; i++) {
 		if (_entries[i].isPresent) {
-			drawItem(0, y, _entries[i].cursor, 50)
+			drawItem(_entries[i].cursor, 0, y);
 			y += 40;
 		}
 	}
@@ -577,7 +604,7 @@
 	_opened = false;
 
 	// Fallback to unselected state
-	drawItem(0, 0, getProgress().portrait, 100)
+	drawItem((CursorStyle)getProgress().portrait, 0, 0);
 
 	// Erase rectangle for all inventory items
 	int count = 0;

Modified: scummvm/trunk/engines/lastexpress/game/inventory.h
===================================================================
--- scummvm/trunk/engines/lastexpress/game/inventory.h	2011-02-09 00:14:24 UTC (rev 55845)
+++ scummvm/trunk/engines/lastexpress/game/inventory.h	2011-02-09 00:23:35 UTC (rev 55846)
@@ -110,19 +110,19 @@
 	// UI Control
 	void show();
 	void blinkEgg(bool enabled);
-	void showHourGlass() const;
-	void setPortrait(InventoryItem item) const;
-	void drawEgg() const;
+	void showHourGlass();
+	void setPortrait(InventoryItem item);
+	void drawEgg();
 	void drawBlinkingEgg();
 
 	// Handle inventory UI events.
-	bool handleMouseEvent(const Common::Event &ev);
+	void handleMouseEvent(const Common::Event &ev);
 
 	// State
-	bool isMagnifierInUse() { return _flagUseMagnifier; }
+	bool isMagnifierInUse() { return _useMagnifier; }
 	bool isFlag1() { return _flag1; }
 	bool isFlag2() { return _flag2; }
-	bool isEggHighlighted() { return _flagEggHightlighted; }
+	bool isEggHighlighted() { return _eggHightlighted; }
 
 	// Serializable
 	void saveLoadWithSerializer(Common::Serializer &s);
@@ -150,13 +150,13 @@
 	bool _blinkingEgg;
 	uint32 _blinkingTime;
 	uint32 _blinkingInterval;
-	uint32 _blinkingBrightness;
+	uint16 _blinkingBrightness;
 
 	// Flags
-	bool _flagUseMagnifier;
+	bool _useMagnifier;
 	bool _flag1;
 	bool _flag2;
-	bool _flagEggHightlighted;
+	bool _eggHightlighted;
 
 	Scene *_itemScene;
 
@@ -173,6 +173,8 @@
 	Common::Rect getItemRect(int16 index) const;
 
 	bool isItemSceneParameter(InventoryItem item) const;
+
+	void drawItem(CursorStyle id, uint16 x, uint16 y, uint16 brighnessIndex = -1);
 };
 
 } // End of namespace LastExpress

Modified: scummvm/trunk/engines/lastexpress/lastexpress.cpp
===================================================================
--- scummvm/trunk/engines/lastexpress/lastexpress.cpp	2011-02-09 00:14:24 UTC (rev 55845)
+++ scummvm/trunk/engines/lastexpress/lastexpress.cpp	2011-02-09 00:23:35 UTC (rev 55846)
@@ -211,6 +211,7 @@
 			// Closing the GMM
 
 		case Common::EVENT_LBUTTONUP:
+		case Common::EVENT_LBUTTONDOWN:
 			getGameLogic()->getGameState()->getGameFlags()->mouseLeftClick = true;
 
 			// Adjust frameInterval flag
@@ -223,6 +224,7 @@
 			break;
 
 		case Common::EVENT_RBUTTONUP:
+		case Common::EVENT_RBUTTONDOWN:
 			getGameLogic()->getGameState()->getGameFlags()->mouseRightClick = true;
 			if (_eventMouse && _eventMouse->isValid())
 				(*_eventMouse)(ev);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list