[Scummvm-cvs-logs] scummvm master -> 7ea081e7a0df465b6fda8e01aa0f1e7a990e24be

dreammaster dreammaster at scummvm.org
Sun Jul 27 02:20:33 CEST 2014


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
7ea081e7a0 MADS: Add support to event manager for intercepting events


Commit: 7ea081e7a0df465b6fda8e01aa0f1e7a990e24be
    https://github.com/scummvm/scummvm/commit/7ea081e7a0df465b6fda8e01aa0f1e7a990e24be
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2014-07-26T20:19:35-04:00

Commit Message:
MADS: Add support to event manager for intercepting events

Changed paths:
    engines/mads/events.cpp
    engines/mads/events.h
    engines/mads/nebular/dialogs_nebular.h
    engines/mads/nebular/menu_nebular.cpp
    engines/mads/nebular/menu_nebular.h



diff --git a/engines/mads/events.cpp b/engines/mads/events.cpp
index 41c8255..de4dc3c 100644
--- a/engines/mads/events.cpp
+++ b/engines/mads/events.cpp
@@ -46,6 +46,7 @@ EventsManager::EventsManager(MADSEngine *vm) {
 	_mouseMoved = false;
 	_vD8 = 0;
 	_rightMousePressed = false;
+	_eventTarget = nullptr;
 }
 
 EventsManager::~EventsManager() {
@@ -138,6 +139,12 @@ void EventsManager::pollEvents() {
 
 	Common::Event event;
 	while (g_system->getEventManager()->pollEvent(event)) {
+		// If an event target is specified, pass the event to it
+		if (_eventTarget) {
+			_eventTarget->onEvent(event);
+			continue;
+		}
+
 		// Handle keypress
 		switch (event.type) {
 		case Common::EVENT_QUIT:
diff --git a/engines/mads/events.h b/engines/mads/events.h
index f491556..c906b62 100644
--- a/engines/mads/events.h
+++ b/engines/mads/events.h
@@ -39,6 +39,11 @@ enum CursorType { CURSOR_NONE = 0, CURSOR_ARROW = 1, CURSOR_WAIT = 2, CURSOR_GO_
 
 class MADSEngine;
 
+class EventTarget {
+public:
+	virtual bool onEvent(Common::Event &event) { return false; }
+};
+
 class EventsManager {
 private:
 	MADSEngine *_vm;
@@ -46,6 +51,7 @@ private:
 	uint32 _priorFrameTime;
 	Common::Point _mousePos;
 	Common::Point _currentPos;
+	EventTarget *_eventTarget;
 
 	/**
 	 * Updates the cursor image when the current cursor changes
@@ -122,6 +128,11 @@ public:
 	void pollEvents();
 
 	/**
+	 * Sets an event handler other than the events manager
+	 */
+	void setEventTarget(EventTarget *target) { _eventTarget = target; }
+
+	/**
 	 * Return the current mouse position
 	 */
 	Common::Point mousePos() const { return _mousePos; }
diff --git a/engines/mads/nebular/dialogs_nebular.h b/engines/mads/nebular/dialogs_nebular.h
index fe7e656..1468db3 100644
--- a/engines/mads/nebular/dialogs_nebular.h
+++ b/engines/mads/nebular/dialogs_nebular.h
@@ -107,7 +107,7 @@ enum DialogTextAlign { ALIGN_NONE = 0, ALIGN_CENTER = -1, ALIGN_AT_CENTER = -2,
 
 enum DialogState { DLGSTATE_UNSELECTED = 0, DLGSTATE_SELECTED = 1, DLGSTATE_FOCUSED = 2 };
 
-class FullScreenDialog {
+class FullScreenDialog: public EventTarget {
 protected:
 	/**
 	 * Engine reference
diff --git a/engines/mads/nebular/menu_nebular.cpp b/engines/mads/nebular/menu_nebular.cpp
index b9fc390..8cd6ee0 100644
--- a/engines/mads/nebular/menu_nebular.cpp
+++ b/engines/mads/nebular/menu_nebular.cpp
@@ -46,11 +46,10 @@ void MenuView::show() {
 	EventsManager &events = *_vm->_events;
 	display();
 
+	events.setEventTarget(this);
 	events.hideCursor();
 
 	while (!_breakFlag && !_vm->shouldQuit()) {
-		handleEvents();
-
 		if (_redrawFlag) {
 			scene.drawElements(_vm->_game->_fx, _vm->_game->_fx);
 			_redrawFlag = false;
@@ -60,6 +59,8 @@ void MenuView::show() {
 		_vm->_game->_fx = kTransitionNone;
 		doFrame();
 	}
+
+	events.setEventTarget(nullptr);
 }
 
 void MenuView::display() {
@@ -68,13 +69,6 @@ void MenuView::display() {
 	FullScreenDialog::display();
 }
 
-void MenuView::handleEvents() {
-	Common::Event event;
-
-	while (g_system->getEventManager()->pollEvent(event))
-		onEvent(event);
-}
-
 /*------------------------------------------------------------------------*/
 
 MainMenu::MainMenu(MADSEngine *vm): MenuView(vm) {
@@ -127,11 +121,6 @@ void MainMenu::doFrame() {
 	if (_menuItemIndex == 6)
 		return;
 
-	// Delete any previous sprite slots
-	scene._spriteSlots.deleteTimer(1);
-	if (_menuItemIndex == -1)
-		scene._spriteSlots.deleteTimer(2);
-
 	// If the user has chosen to skip the animation, show the full menu immediately
 	if (_skipFlag && _menuItemIndex >= 0) {
 		// Quickly loop through all the menu items to display each's final frame		
@@ -163,13 +152,14 @@ void MainMenu::doFrame() {
 void MainMenu::addSpriteSlot() {
 	Scene &scene = _vm->_game->_scene;
 	SpriteSlots &spriteSlots = scene._spriteSlots;
+	spriteSlots.deleteTimer(_menuItemIndex);
 
 	SpriteAsset *menuItem = _menuItems[_menuItemIndex];
 	MSprite *spr = menuItem->getFrame(_frameIndex);
 
 	SpriteSlot &slot = spriteSlots[spriteSlots.add()];
 	slot._flags = IMG_UPDATE;
-	slot._seqIndex = (_frameIndex > 0) ? 1 : 2;
+	slot._seqIndex = _menuItemIndex;
 	slot._spritesIndex = _menuItemIndexes[_menuItemIndex];
 	slot._frameNumber = _frameIndex + 1;
 	slot._position = spr->_offset;
@@ -180,6 +170,8 @@ void MainMenu::addSpriteSlot() {
 }
 
 bool MainMenu::onEvent(Common::Event &event) {
+	Scene &scene = _vm->_game->_scene;
+
 	// Handle keypresses - these can be done at any time, even when the menu items are being drawn
 	if (event.type == Common::EVENT_KEYDOWN) {
 		switch (event.kbd.keycode) {
@@ -212,6 +204,9 @@ bool MainMenu::onEvent(Common::Event &event) {
 			// Goodness knows why, but Rex has a key to restart the menuitem animations
 			// Restart the animation
 			_menuItemIndex = -1;
+			for (int i = 0; i < 6; ++i)
+				scene._spriteSlots.deleteTimer(i);
+
 			_skipFlag = false;
 			_vm->_events->hideCursor();
 			break;
diff --git a/engines/mads/nebular/menu_nebular.h b/engines/mads/nebular/menu_nebular.h
index 71a1fec..e96819b 100644
--- a/engines/mads/nebular/menu_nebular.h
+++ b/engines/mads/nebular/menu_nebular.h
@@ -37,16 +37,12 @@ namespace Nebular {
 enum MADSGameAction { START_GAME, RESUME_GAME, SHOW_INTRO, CREDITS, QUOTES, EXIT };
 
 class MenuView: public FullScreenDialog {
-private:
-	void handleEvents();
 protected:
 	bool _breakFlag;
 	bool _redrawFlag;
 
 	virtual void doFrame() = 0;
 
-	virtual bool onEvent(Common::Event &event) = 0;
-
 	virtual void display();
 public:
 	MenuView(MADSEngine *vm);






More information about the Scummvm-git-logs mailing list