diff options
| -rw-r--r-- | engines/sherlock/events.cpp | 4 | ||||
| -rw-r--r-- | engines/sherlock/events.h | 5 | ||||
| -rw-r--r-- | engines/sherlock/tattoo/tattoo_journal.cpp | 309 | ||||
| -rw-r--r-- | engines/sherlock/tattoo/tattoo_journal.h | 24 | ||||
| -rw-r--r-- | engines/sherlock/tattoo/tattoo_user_interface.cpp | 18 | 
5 files changed, 357 insertions, 3 deletions
diff --git a/engines/sherlock/events.cpp b/engines/sherlock/events.cpp index 354e2a1640..fdfd77ef74 100644 --- a/engines/sherlock/events.cpp +++ b/engines/sherlock/events.cpp @@ -173,6 +173,10 @@ void Events::pollEventsAndWait() {  	g_system->delayMillis(10);  } +void Events::warpMouse(const Common::Point &pt) { +	g_system->warpMouse(pt.x, pt.y); +} +  bool Events::checkForNextFrameCounter() {  	// Check for next game frame  	uint32 milli = g_system->getMillis(); diff --git a/engines/sherlock/events.h b/engines/sherlock/events.h index c9ca041c13..b0dda37607 100644 --- a/engines/sherlock/events.h +++ b/engines/sherlock/events.h @@ -120,6 +120,11 @@ public:  	void pollEventsAndWait();  	/** +	 * Move the mouse cursor +	 */ +	void warpMouse(const Common::Point &pt); + +	/**  	 * Get the current mouse position  	 */  	Common::Point mousePos() const; diff --git a/engines/sherlock/tattoo/tattoo_journal.cpp b/engines/sherlock/tattoo/tattoo_journal.cpp index c5779ced59..22d2d27ac7 100644 --- a/engines/sherlock/tattoo/tattoo_journal.cpp +++ b/engines/sherlock/tattoo/tattoo_journal.cpp @@ -37,11 +37,17 @@ static const char *const JOURNAL_SEARCH_COMMANDS[3] = { "Abort Search", "Search  TattooJournal::TattooJournal(SherlockEngine *vm) : Journal(vm) {  	_journalImages = nullptr; +	_selector = _oldSelector = 0; +	_wait = false; +	_exitJournal = false; +	_scrollingTimer = 0; +	_savedIndex = _savedSub = _savedPage = 0;  	loadLocations();  }  void TattooJournal::show() { +	Events &events = *_vm->_events;  	Resources &res = *_vm->_res;  	Screen &screen = *_vm->_screen;  	TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui; @@ -66,13 +72,293 @@ void TattooJournal::show() {  	} else {  		drawJournal(0, 0);  	} +	drawControls(0); +	screen.slamRect(Common::Rect(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT)); -	// TODO +	_exitJournal = false; +	_scrollingTimer = 0; + +	do { +		events.pollEventsAndWait(); +		Common::Point mousePos = events.mousePos(); +		_wait = true; + +		handleKeyboardEvents(); +		highlightJournalControls(true); +		 +		handleButtons(); + +		if (_wait) +			events.wait(2); +		 +	} while (!_vm->shouldQuit() && !_exitJournal); + +	// Clear events +	events.clearEvents();  	// Free the images  	delete _journalImages;  } +void TattooJournal::handleKeyboardEvents() { +	Events &events = *_vm->_events; +	Screen &screen = *_vm->_screen; +	Common::Point mousePos = events.mousePos(); + +	if (!events.kbHit()) +		return; + +	Common::KeyState keyState = events.getKey(); + +	if (keyState.keycode == Common::KEYCODE_TAB && (keyState.flags & Common::KBD_SHIFT)) { +		// Shift tab +		Common::Rect r(JOURNAL_BAR_WIDTH, BUTTON_SIZE + screen.fontHeight() + 13); +		r.moveTo((SHERLOCK_SCREEN_WIDTH - r.width()) / 2, SHERLOCK_SCREEN_HEIGHT - r.height()); + +		// See if mouse is over any of the journal controls +		_selector = -1; +		if (Common::Rect(r.left + 3, r.top + 3, r.right - 3, r.top + screen.fontHeight() + 4).contains(mousePos)) +			_selector = (mousePos.x - r.left) / (r.width() / 3); + +		// If the mouse is not over an option, move the mouse to that it points to the first option +		if (_selector == -1) { +			events.warpMouse(Common::Point(r.left + r.width() / 3 - 10, r.top + screen.fontHeight() + 2)); +		} else { +			if (_selector == 0) +				_selector = 2; +			else +				--_selector; + +			events.warpMouse(Common::Point(r.left + (r.width() / 3) * (_selector + 1) - 10, mousePos.y)); +		} + +	} else if (keyState.keycode == Common::KEYCODE_PAGEUP || keyState.keycode == Common::KEYCODE_KP9) { +		// See if they have Shift held down to go forward 10 pages +		if (keyState.flags & Common::KBD_SHIFT) { +			if (_page > 1) { +				// Scroll Up 10 pages if possible +				if (_page < 11) +					drawJournal(1, (_page - 1) * LINES_PER_PAGE); +				else +					drawJournal(1, 10 * LINES_PER_PAGE); + +				drawScrollBar(); +				screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); +				_wait = false; +			} +		} else { +			if (_page > 1) { +				// Scroll Up 1 page +				drawJournal(1, LINES_PER_PAGE); +				drawScrollBar(); +				show(); +				screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); +				_wait = false; +			} +		} + +	} else if (keyState.keycode == Common::KEYCODE_PAGEDOWN || keyState.keycode == Common::KEYCODE_KP3) { +		if (keyState.flags & Common::KBD_SHIFT) { +			if (_down) { +				// Scroll down 10 Pages +				if (_page + 10 > _maxPage) +					drawJournal(2, (_maxPage - _page) * LINES_PER_PAGE); +				else +					drawJournal(2, 10 * LINES_PER_PAGE); +				drawScrollBar(); +				screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); + +				_wait = false; +			} +		} else { +			if (_down) { +				// Scroll down 1 page +				drawJournal(2, LINES_PER_PAGE); +				drawScrollBar(); +				show(); +				screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); + +				_wait = false; +			} +		} + +	} else if (keyState.keycode == Common::KEYCODE_HOME || keyState.keycode == Common::KEYCODE_KP7) { +		// Scroll to start of journal +		if (_page > 1) { +			// Go to the beginning of the journal +			_index = _sub = _up = _down = 0; +			_page = 1; + +			drawFrame(); +			drawJournal(0, 0); + +			drawScrollBar(); +			screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); + +			_wait = false; +		} + +	} else if (keyState.keycode == Common::KEYCODE_END || keyState.keycode == Common::KEYCODE_KP1) { +		// Scroll to end of journal +		if (_down) { +			// Go to the end of the journal +			drawJournal(2, 100000); +			drawScrollBar(); +			screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); + +			_wait = false; +		} +	} else if (keyState.keycode == Common::KEYCODE_RETURN || keyState.keycode == Common::KEYCODE_KP_ENTER) { +		events._pressed = false; +		events._released = true; +		events._oldButtons = 0; +	} else if (keyState.keycode == Common::KEYCODE_ESCAPE) { +		_exitJournal = true; +	} else if (keyState.keycode == Common::KEYCODE_TAB) { +		Common::Rect r(JOURNAL_BAR_WIDTH, BUTTON_SIZE + screen.fontHeight() + 13); +		r.moveTo((SHERLOCK_SCREEN_WIDTH - r.width()) / 2, SHERLOCK_SCENE_HEIGHT - r.height()); + +		// See if the mouse is over any of the journal controls +		_selector = -1; +		if (Common::Rect(r.left + 3, r.top + 3, r.right - 3, r.top + screen.fontHeight() + 4).contains(mousePos)) +			_selector = (mousePos.x - r.left) / (r.width() / 3); + +		// If the mouse is not over any of the options, move the mouse so that it points to the first option +		if (_selector == -1) { +			events.warpMouse(Common::Point(r.left + r.width() / 3 - 10, r.top + screen.fontHeight() + 2)); +		} else { +			if (_selector == 2) +				_selector = 0; +			else +				++_selector; + +			events.warpMouse(Common::Point(r.left + (r.width() / 3) * (_selector + 1) - 10, mousePos.y)); +		} +	} +} + +void TattooJournal::handleButtons() { +	Events &events = *_vm->_events; +	Screen &screen = *_vm->_screen; +	uint32 frameCounter = events.getFrameCounter(); + +	if (_selector != -1 && events._pressed) { +		if (frameCounter >= _scrollingTimer) { +			// Set next scrolling time +			_scrollingTimer = frameCounter + 6; + +			// Handle different scrolling actions +			switch (_selector) { +			case 3: +				// Scroll left (1 page back) +				if (_page > 1) { +					// Scroll Up +					drawJournal(1, LINES_PER_PAGE); +					drawScrollBar(); +					screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); +					_wait = false; +				} +				break; + +			case 4: +				// Page left (10 pages back) +				if (_page > 1) { +					// Scroll Up 10 Pages if possible +					if (_page < 11) +						drawJournal(1, (_page - 1) * LINES_PER_PAGE); +					else +						drawJournal(1, 10 * LINES_PER_PAGE); +					drawScrollBar(); +					show(); +					screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); +					_wait = false; +				} +				break; + +			case 5: +				// Page right (10 pages ahead) +				if (_down) { +					// Scroll Down 10 Pages +					if (_page + 10 > _maxPage) +						drawJournal(2, (_maxPage - _page) * LINES_PER_PAGE); +					else +						drawJournal(2, 10 * LINES_PER_PAGE); +					drawScrollBar(); +					screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); +					_wait = false; +				} +				break; + +			case 6: +				// Scroll right (1 Page Ahead) +				if (_down) { +					// Scroll Down +					drawJournal(2, LINES_PER_PAGE); +					drawScrollBar(); +					screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); +					_wait = false; +				} +				break; + +			default: +				break; +			} +		} +	} + +	if (events._released || events._rightReleased) { +		_scrollingTimer = 0; + +		switch (_selector) { +		case 0: +			_exitJournal = true; +			break; + +		case 1: { +			// Search Journal +			disableControls(); + +			bool notFound = false; +			int dir; + +			do { +				if ((dir = getFindName(notFound)) != 0) { +					_savedIndex = _index; +					_savedSub = _sub; +					_savedPage = _page; +					 +					if (drawJournal(dir + 2, 1000 * LINES_PER_PAGE) == 0) +					{ +						_index = _savedIndex; +						_sub = _savedSub; +						_page = _savedPage; +						 +						drawFrame(); +						drawJournal(0, 0); +						notFound = true; +					} else { +						break; +					} + +					highlightJournalControls(false); +					screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT); +				} else { +					break; +				} +			} while (!_vm->shouldQuit()); +			break; +		} + +		case 2: +			// Print Journal - not implemented in ScummVM +			break; + +		default: +			break; +		} +	} +} +  void TattooJournal::loadLocations() {  	Resources &res = *_vm->_res; @@ -410,6 +696,27 @@ void TattooJournal::drawScrollBar() {  		r.top + screen.fontHeight() + 10 + BUTTON_SIZE), true);  } +void TattooJournal::disableControls() { +	Screen &screen = *_vm->_screen; +	Common::Rect r(JOURNAL_BAR_WIDTH, BUTTON_SIZE + screen.fontHeight() + 13); +	r.moveTo((SHERLOCK_SCREEN_HEIGHT - r.width()) / 2, SHERLOCK_SCREEN_HEIGHT - r.height()); + +	// Print the Journal commands +	int xp = r.left + r.width() / 6; +	for (int idx = 0; idx < 3; ++idx) { +		screen.gPrint(Common::Point(xp - screen.stringWidth(JOURNAL_COMMANDS[idx]) / 2, r.top + 5), +			INFO_BOTTOM, "%s", JOURNAL_COMMANDS[idx]); + +		xp += r.width() / 3; +	} + +	screen.slamRect(r); +} + +bool TattooJournal::getFindName(bool printError) { +	return false; +} +  } // End of namespace Tattoo  } // End of namespace Sherlock diff --git a/engines/sherlock/tattoo/tattoo_journal.h b/engines/sherlock/tattoo/tattoo_journal.h index f9ed7afa2b..a482d2c16f 100644 --- a/engines/sherlock/tattoo/tattoo_journal.h +++ b/engines/sherlock/tattoo/tattoo_journal.h @@ -34,6 +34,10 @@ class TattooJournal : public Journal {  private:  	ImageFile *_journalImages;  	int _selector, _oldSelector; +	bool _wait; +	bool _exitJournal; +	uint32 _scrollingTimer; +	int _savedIndex, _savedSub, _savedPage;  	/**  	 * Load the list of journal locations @@ -57,6 +61,26 @@ private:  	void highlightSearchControls(bool slamIt);  	void drawScrollBar(); + +	/** +	 * Check for and handle any pending keyboard events +	 */ +	void handleKeyboardEvents(); + +	/** +	 * Handle mouse presses on interface buttons +	 */ +	void handleButtons(); + +	/** +	 * Disable the journal controls +	 */ +	void disableControls(); + +	/** +	 * Get in a name to search through the journal for +	 */ +	bool getFindName(bool printError);  public:  	TattooJournal(SherlockEngine *vm);  	virtual ~TattooJournal() {} diff --git a/engines/sherlock/tattoo/tattoo_user_interface.cpp b/engines/sherlock/tattoo/tattoo_user_interface.cpp index 696e38f5c6..f1b75f45d4 100644 --- a/engines/sherlock/tattoo/tattoo_user_interface.cpp +++ b/engines/sherlock/tattoo/tattoo_user_interface.cpp @@ -198,9 +198,23 @@ void TattooUserInterface::printObjectDesc(const Common::String &str, bool firstT  void TattooUserInterface::doJournal() {  	TattooJournal &journal = *(TattooJournal *)_vm->_journal; -	 +	TattooScene &scene = *(TattooScene *)_vm->_scene; +	Screen &screen = *_vm->_screen; +  	_menuMode = JOURNAL_MODE; -	journal.show();	 +	journal.show(); + +	_menuMode = STD_MODE; +	_windowOpen = false; +	_key = -1; + +	setupBGArea(screen._cMap); +	screen.clear(); +	screen.setPalette(screen._cMap); + +	screen._backBuffer1.blitFrom(screen._backBuffer2); +	scene.updateBackground(); +	screen.slamArea(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT);  }  void TattooUserInterface::reset() {  | 
