From bb85844e7336baaa09fe7edcf16007c7ebe259d9 Mon Sep 17 00:00:00 2001
From: lukaslw
Date: Fri, 6 Jun 2014 03:21:47 +0200
Subject: PRINCE: Inventory update - first suitcase drawing

---
 engines/prince/graphics.cpp |   4 +-
 engines/prince/graphics.h   |   2 +-
 engines/prince/mhwanh.h     |   2 +-
 engines/prince/prince.cpp   | 136 +++++++++++++++++++++++++-------------------
 engines/prince/prince.h     |   5 ++
 5 files changed, 88 insertions(+), 61 deletions(-)

diff --git a/engines/prince/graphics.cpp b/engines/prince/graphics.cpp
index 210b9d9ef9..49cc88c8ae 100644
--- a/engines/prince/graphics.cpp
+++ b/engines/prince/graphics.cpp
@@ -73,11 +73,11 @@ void GraphicsMan::draw(uint16 posX, uint16 posY, const Graphics::Surface *s) {
 	change();
 }
 
-void GraphicsMan::drawTransparentIntro(int32 posX, int32 posY, const Graphics::Surface *s) {
+void GraphicsMan::drawTransparentSurface(int32 posX, int32 posY, const Graphics::Surface *s, int transColor) {
 	for (int y = 0; y < s->h; y++) {
 		for (int x = 0; x < s->w; x++) {
 			byte pixel = *((byte*)s->getBasePtr(x, y));
-			if (pixel != 255) {
+			if (pixel != transColor) {
 				if (x + posX < _frontScreen->w && x + posX >= 0) {
 					if (y + posY < _frontScreen->h && y + posY >= 0) {
 						*((byte*)_frontScreen->getBasePtr(x + posX, y + posY)) = pixel;
diff --git a/engines/prince/graphics.h b/engines/prince/graphics.h
index 2756bf4777..cd3d8b4f35 100644
--- a/engines/prince/graphics.h
+++ b/engines/prince/graphics.h
@@ -45,7 +45,7 @@ public:
 	void makeShadowTable(int brightness, byte *shadowTable);
 
 	void draw(uint16 x, uint16 y, const Graphics::Surface *s);
-	void drawTransparentIntro(int32 posX, int32 poxY, const Graphics::Surface *s);
+	void drawTransparentSurface(int32 posX, int32 poxY, const Graphics::Surface *s, int transColor);
 
 	static void drawTransparent(Graphics::Surface *frontScreen, DrawNode *drawNode);
 	static void drawAsShadow(Graphics::Surface *frontScreen, DrawNode *drawNode);
diff --git a/engines/prince/mhwanh.h b/engines/prince/mhwanh.h
index 5364c5d20a..02256569ce 100644
--- a/engines/prince/mhwanh.h
+++ b/engines/prince/mhwanh.h
@@ -38,7 +38,7 @@ public:
 	// ImageDecoder API
 	void destroy();
 	virtual bool loadStream(Common::SeekableReadStream &stream);
-	virtual const Graphics::Surface *getSurface() const { return _surface; }
+	virtual Graphics::Surface *getSurface() const { return _surface; }
 	virtual const byte *getPalette() const { return _palette; }
 	uint16 getPaletteCount() const { return _paletteColorCount; }
 
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp
index ad825fb140..a535e4f234 100644
--- a/engines/prince/prince.cpp
+++ b/engines/prince/prince.cpp
@@ -79,7 +79,8 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc)
 	_locationNr(0), _debugger(nullptr), _midiPlayer(nullptr), _room(nullptr), testAnimNr(0), testAnimFrame(0),
 	_frameNr(0), _cursor1(nullptr), _cursor2(nullptr), _font(nullptr),
 	_suitcaseBmp(nullptr), _roomBmp(nullptr), _cursorNr(0), _picWindowX(0), _picWindowY(0), _randomSource("prince"),
-	_invLineX(134), _invLineY(176), _invLine(5), _invLines(3), _invLineW(70), _invLineH(76), _invLineSkipX(2), _invLineSkipY(3) {
+	_invLineX(134), _invLineY(176), _invLine(5), _invLines(3), _invLineW(70), _invLineH(76), _invLineSkipX(2), _invLineSkipY(3),
+	_showInventoryFlag(false), _inventoryBackgroundRemember(false) {
 
 	// Debug/console setup
 	DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel");
@@ -408,7 +409,7 @@ bool PrinceEngine::playNextFrame() {
 
 	const Graphics::Surface *s = _flicPlayer.decodeNextFrame();
 	if (s) {
-		_graph->drawTransparentIntro(0, 0, s);
+		_graph->drawTransparentSurface(0, 0, s, 255);
 		_graph->change();
 	} else if (_flicLooped) {
 		_flicPlayer.rewind();
@@ -654,6 +655,7 @@ void PrinceEngine::keyHandler(Common::Event event) {
 		break;
 	case Common::KEYCODE_i:
 		_mainHero->_middleY -= 5;
+		inventoryFlagChange();
 		break;
 	case Common::KEYCODE_k:
 		_mainHero->_middleY += 5;
@@ -1183,69 +1185,76 @@ void PrinceEngine::freeDrawNodes() {
 }
 
 void PrinceEngine::drawScreen() {
-	const Graphics::Surface *roomSurface = _roomBmp->getSurface();	
-	Graphics::Surface visiblePart;
-	if (roomSurface) {
-		visiblePart = roomSurface->getSubArea(Common::Rect(_picWindowX, 0, roomSurface->w, roomSurface->h));
-		_graph->draw(0, 0, &visiblePart);
-	}
-
-	Graphics::Surface *mainHeroSurface = NULL;
-	if (_mainHero->_visible) {
-		mainHeroSurface = _mainHero->getSurface();
-		if (mainHeroSurface) {
-			_mainHero->showHeroShadow(mainHeroSurface);
+	if (!_showInventoryFlag || _inventoryBackgroundRemember) {
+		const Graphics::Surface *roomSurface = _roomBmp->getSurface();
+		Graphics::Surface visiblePart;
+		if (roomSurface) {
+			visiblePart = roomSurface->getSubArea(Common::Rect(_picWindowX, 0, roomSurface->w, roomSurface->h));
+			_graph->draw(0, 0, &visiblePart);
+		}
 
-			DrawNode newDrawNode;
-			newDrawNode.posX = _mainHero->_drawX;
-			newDrawNode.posY = _mainHero->_drawY;
-			newDrawNode.posZ = _mainHero->_drawZ;
-			newDrawNode.width = 0;
-			newDrawNode.height = 0;
-			newDrawNode.originalRoomSurface = nullptr;
-			newDrawNode.data = nullptr;
-			newDrawNode.drawFunction = &_graph->drawTransparent;
-
-			if (_mainHero->_zoomFactor != 0) {
-				Graphics::Surface *zoomedHeroSurface = _mainHero->zoomSprite(mainHeroSurface);
-				newDrawNode.s = zoomedHeroSurface;
-				newDrawNode.freeSurfaceSMemory = true;
-			} else {
-				newDrawNode.s = mainHeroSurface;
-				newDrawNode.freeSurfaceSMemory = false;
+		Graphics::Surface *mainHeroSurface = NULL;
+		if (_mainHero->_visible) {
+			mainHeroSurface = _mainHero->getSurface();
+			if (mainHeroSurface) {
+				_mainHero->showHeroShadow(mainHeroSurface);
+
+				DrawNode newDrawNode;
+				newDrawNode.posX = _mainHero->_drawX;
+				newDrawNode.posY = _mainHero->_drawY;
+				newDrawNode.posZ = _mainHero->_drawZ;
+				newDrawNode.width = 0;
+				newDrawNode.height = 0;
+				newDrawNode.originalRoomSurface = nullptr;
+				newDrawNode.data = nullptr;
+				newDrawNode.drawFunction = &_graph->drawTransparent;
+
+				if (_mainHero->_zoomFactor != 0) {
+					Graphics::Surface *zoomedHeroSurface = _mainHero->zoomSprite(mainHeroSurface);
+					newDrawNode.s = zoomedHeroSurface;
+					newDrawNode.freeSurfaceSMemory = true;
+				} else {
+					newDrawNode.s = mainHeroSurface;
+					newDrawNode.freeSurfaceSMemory = false;
+				}
+				_drawNodeList.push_back(newDrawNode);
 			}
-			_drawNodeList.push_back(newDrawNode);
 		}
-	}
 
-	showBackAnims();
+		showBackAnims();
 
-	showObjects();
+		showObjects();
 
-	if (roomSurface) {
-		insertMasks(&visiblePart);
-	}
-
-	showParallax();
+		if (roomSurface) {
+			insertMasks(&visiblePart);
+		}
 
-	displayInventory(); // temp
+		showParallax();
 
-	runDrawNodes();
+		runDrawNodes();
 
-	freeDrawNodes();
+		freeDrawNodes();
 
-	if (_mainHero->_visible) {
-		mainHeroSurface->free();
-		delete mainHeroSurface;
-	}
+		if (_mainHero->_visible) {
+			mainHeroSurface->free();
+			delete mainHeroSurface;
+		}
 
-	clsMasks();
+		clsMasks();
 
-	playNextFrame();
+		playNextFrame();
 
-	hotspot();
+		if (!_inventoryBackgroundRemember) {
+			hotspot();
+			showTexts();
+		} else {
+			rememberScreenInv();
+			_inventoryBackgroundRemember = false;
+		}
 
-	showTexts();
+	} else {
+		displayInventory();
+	}
 
 	getDebugger()->onFrame();
 
@@ -1253,7 +1262,16 @@ void PrinceEngine::drawScreen() {
 }
 
 void PrinceEngine::rememberScreenInv() {
+	_backgroundForInventory = _graph->_frontScreen;
+}
 
+void PrinceEngine::inventoryFlagChange() {
+	if (!_showInventoryFlag) {
+		_showInventoryFlag = true;
+		_inventoryBackgroundRemember = true;
+	} else {
+		_showInventoryFlag = false;
+	}
 }
 
 void PrinceEngine::prepareInventoryToView() {
@@ -1269,12 +1287,10 @@ void PrinceEngine::prepareInventoryToView() {
 	_maxInvW = (374 - 2 * _invLine) / _invLine;
 	_invLineW = _maxInvW - 2;
 
-	rememberScreenInv();
-
 	int currInvX = _invLineX;
 	int currInvY = _invLineY;
 
-	int item = 0;
+	uint item = 0;
 	for (int i = 0 ; i < _invLines; i++) {
 		for (int j = 0; j < _invLine; j++) {
 			Mob tempMobItem;
@@ -1311,14 +1327,14 @@ void PrinceEngine::drawInvItems() {
 				//MST_Shadow
 				// TODO!
 				//shad0:
-				if (_mainHero->_inventory[item] != 0) {
+				//if (_mainHero->_inventory[item] != 0) {
 					int itemNr = _mainHero->_inventory[item];
 					if (itemNr != 68) {
-						showSprite(_allInvList[itemNr].getSurface(), currInvX, currInvY, 10000, false); // temp
+						_graph->drawTransparentSurface(currInvX, currInvY, _allInvList[itemNr].getSurface(), 0);
 					} else {
 						// candle item:
 					}
-				}
+				//}
 			}
 			currInvX += _invLineW + _invLineSkipX;
 			item++;
@@ -1336,7 +1352,13 @@ void PrinceEngine::displayInventory() {
 	_mainHero->_inventory.push_back(3);
 	_mainHero->_inventory.push_back(4);
 	_mainHero->_inventory.push_back(5);
+
 	prepareInventoryToView();
+
+	_graph->drawTransparentSurface(0, 0, _backgroundForInventory, 0);
+	Graphics::Surface *suitcase = _suitcaseBmp->getSurface();
+	_graph->drawTransparentSurface(0, 0, suitcase, 0);
+
 	drawInvItems();
 }
 
diff --git a/engines/prince/prince.h b/engines/prince/prince.h
index 0f76ffc1e4..6919587271 100644
--- a/engines/prince/prince.h
+++ b/engines/prince/prince.h
@@ -275,6 +275,8 @@ public:
 	uint32 _invTxtSize;
 	byte *_invTxt;
 
+	bool _showInventoryFlag;
+	bool _inventoryBackgroundRemember;
 	int _invLineX;
 	int _invLineY;
 	int _invLine;  // number of items in one line
@@ -285,12 +287,15 @@ public:
 	int _invLineSkipX;
 	int _invLineSkipY;
 
+	void inventoryFlagChange();
 	bool loadAllInv();
 	void rememberScreenInv();
 	void prepareInventoryToView();
 	void drawInvItems();
 	void displayInventory();
 
+	Graphics::Surface *_backgroundForInventory;
+
 	int testAnimNr;
 	int testAnimFrame;
 
-- 
cgit v1.2.3