[Scummvm-cvs-logs] SF.net SVN: scummvm:[46152] scummvm/trunk/engines/m4

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Thu Nov 26 12:48:44 CET 2009


Revision: 46152
          http://scummvm.svn.sourceforge.net/scummvm/?rev=46152&view=rev
Author:   dreammaster
Date:     2009-11-26 11:48:43 +0000 (Thu, 26 Nov 2009)

Log Message:
-----------
Added the basics of a action list display

Modified Paths:
--------------
    scummvm/trunk/engines/m4/events.h
    scummvm/trunk/engines/m4/m4.cpp
    scummvm/trunk/engines/m4/m4.h
    scummvm/trunk/engines/m4/mads_menus.cpp
    scummvm/trunk/engines/m4/scene.cpp
    scummvm/trunk/engines/m4/scene.h

Modified: scummvm/trunk/engines/m4/events.h
===================================================================
--- scummvm/trunk/engines/m4/events.h	2009-11-26 10:59:46 UTC (rev 46151)
+++ scummvm/trunk/engines/m4/events.h	2009-11-26 11:48:43 UTC (rev 46152)
@@ -56,6 +56,7 @@
 
 enum M4CommonCursors {
 	CURSOR_ARROW = 0,
+	CURSOR_WAIT = 1,
 	CURSOR_HOURGLASS = 5,
 	CURSOR_LOOK = 6,
 	CURSOR_TAKE = 8,

Modified: scummvm/trunk/engines/m4/m4.cpp
===================================================================
--- scummvm/trunk/engines/m4/m4.cpp	2009-11-26 10:59:46 UTC (rev 46151)
+++ scummvm/trunk/engines/m4/m4.cpp	2009-11-26 11:48:43 UTC (rev 46152)
@@ -182,6 +182,7 @@
 	}
 	_rails = new Rails();	// needs to be initialized before _scene
 	_scene = new Scene(this);
+	_actionsView = new ActionsView(this);
 	_dialogs = new Dialogs();
 	_viewManager = new ViewManager(this);
 	_inventory = new Inventory(this);
@@ -306,6 +307,7 @@
 		}
 
 		_viewManager->addView(_scene);
+		_viewManager->addView(_actionsView);
 
 		_font->setFont(FONT_MAIN_MADS);
 		_font->setColors(2, 1, 3);

Modified: scummvm/trunk/engines/m4/m4.h
===================================================================
--- scummvm/trunk/engines/m4/m4.h	2009-11-26 10:59:46 UTC (rev 46151)
+++ scummvm/trunk/engines/m4/m4.h	2009-11-26 11:48:43 UTC (rev 46152)
@@ -173,6 +173,7 @@
 	Font *_font;
 	Actor *_actor;
 	Scene *_scene;
+	ActionsView *_actionsView;
 	Dialogs *_dialogs;
 	M4Surface *_screen;
 	Inventory *_inventory;

Modified: scummvm/trunk/engines/m4/mads_menus.cpp
===================================================================
--- scummvm/trunk/engines/m4/mads_menus.cpp	2009-11-26 10:59:46 UTC (rev 46151)
+++ scummvm/trunk/engines/m4/mads_menus.cpp	2009-11-26 11:48:43 UTC (rev 46152)
@@ -308,6 +308,7 @@
 		// removes this menu screen from being displayed
 		vm->_mouse->cursorOn();
 		vm->_viewManager->addView(vm->_scene);
+		vm->_viewManager->addView(vm->_actionsView);
 		vm->_scene->loadScene(101);
 
 		// **DEBUG** - set the default object

Modified: scummvm/trunk/engines/m4/scene.cpp
===================================================================
--- scummvm/trunk/engines/m4/scene.cpp	2009-11-26 10:59:46 UTC (rev 46151)
+++ scummvm/trunk/engines/m4/scene.cpp	2009-11-26 11:48:43 UTC (rev 46152)
@@ -717,4 +717,171 @@
 	_selectedObject = objectNumber;
 }
 
+/*
+ * TODO: decide if this should be kept centralised like it is in the original, or separated for the different
+ * visual elements
+void Scene::getInterfaceObjectRect(int xv, int yv, Common::Rect &bounds) {
+	// TODO: Implement these later as proper fields of the interface when I understand them better
+	const int interfaceObjY = 0;
+	const int interfaceObjX = 0;
+
+	int16 height = 8, width = 0;
+	bounds.top = 0; bounds.left = 0;
+
+	// Handle X position and width
+	switch (xv) {
+	case 1:
+		bounds.left = ((yv / 5) << 3) + 3;
+		width = ((yv / 5) << 6) + 2;
+		break;
+
+	case 2:
+		if ((yv < interfaceObjX) || (yv > (interfaceObjX + 5))) return;
+		bounds.left = ((yv - interfaceObjX) << 3) + 3;
+		width = yv * 69 + 90;
+		break;
+
+	case 6:
+		bounds.left = (yv << 3) + 3;
+		width = yv * 318 + 2;
+		break;
+
+	case 7:
+		bounds.left = 0;
+		width = (yv == 4) ? 75 : 73;
+		break;
+
+	default:
+		bounds.left = (yv << 3) + 3;
+		width = yv * 80 + 240;
+		break;
+	}
+
+	// Handle Y position and height
+	if (xv ==  7) {
+		switch (yv) {
+		case 1:
+			bounds.top = 4;
+			height = 7;
+			break;
+		case 2:
+			bounds.top = 35;
+			height = 7;
+			break;
+		case 3:
+			bounds.top = 12;
+			height = 22;
+			break;
+		case 4:
+			bounds.top = interfaceObjY + 14;
+			height = 1;
+			break;
+		default:
+			break;
+		}
+	}
+
+	// Set the right and bottom bounds based on the specified size
+	bounds.right = bounds.left + width;
+	bounds.bottom = bounds.top + height;
+}
+*/
+
+/**
+ *--------------------------------------------------------------------------
+ * Base class for interface elements
+ *
+ *--------------------------------------------------------------------------
+ */
+
+InterfaceElement::InterfaceElement(M4Engine *vm, const Common::Rect &viewBounds, bool transparent):
+					View(vm, viewBounds, transparent) {
+}
+
+void InterfaceElement::setFontMode(FontMode newMode) {
+	switch (newMode) {
+	case MODE_0:
+		_vm->_font->setColors(4, 4, 0xff);
+		break;
+	case MODE_1:
+		//_vm->_font->setColors(5, 5, 0xff);
+		_vm->_font->setColors(0xff, 0xff, 0xff);
+		break;
+	case MODE_2:
+		_vm->_font->setColors(6, 6, 0xff);
+		break;
+	}
+}
+
+/**
+ *--------------------------------------------------------------------------
+ * ActionsView handles the display of the actions/verb list
+ *
+ *--------------------------------------------------------------------------
+ */
+
+ActionsView::ActionsView(M4Engine *vm): InterfaceElement(vm, Common::Rect(0, MADS_SURFACE_HEIGHT, 70, 
+														 vm->_screen->height())) {
+	_screenType = VIEWID_INTERFACE;
+	_highlightedAction = 0;
+}
+
+void ActionsView::getActionRect(int actionId, Common::Rect &bounds) {
+	int idx = actionId - kVerbLook;
+
+	bounds.left = (idx / 5) * 32 + 2;
+	bounds.top = (idx % 5) * 8 + MADS_SURFACE_HEIGHT + 3;
+	bounds.right = ((idx / 5) + 1) * 32 + 3;
+	bounds.bottom = ((idx % 5) + 1) * 8 + MADS_SURFACE_HEIGHT + 4;
+}
+
+void ActionsView::onRefresh(RectList *rects, M4Surface *destSurface) {
+	_vm->_font->setFont(FONT_INTERFACE_MADS);
+
+	int actionId = kVerbLook;
+	for (int x = 0; x < 2; ++x) {
+		for (int y = 0; y < 5; ++y, ++actionId) {
+			// Get the bounds for the next item
+			Common::Rect r;
+			getActionRect(actionId, r);
+
+			// Determine the font colour depending on whether an item is selected
+			setFontMode((_highlightedAction == actionId) ? MODE_1 : MODE_0);
+
+			// Get the verb action and capitalise it
+			const char *verbStr = _vm->_globals->getVocab(actionId);
+			char buffer[20];
+			strcpy(buffer, verbStr);
+			if ((buffer[0] >= 'a') && (buffer[0] <= 'z')) buffer[0] -= 'a' - 'A';
+
+			// Display the verb
+			_vm->_font->writeString(destSurface, buffer, r.left, r.top, r.width(), 0);
+		}
+	}
+}
+
+bool ActionsView::onEvent(M4EventType eventType, int param1, int x, int y, bool &captureEvents) {
+	if (eventType == MEVENT_MOVE) {
+		// If the cursor isn't in "wait mode", reset it back to the normal cursor
+		if (_vm->_mouse->getCursorNum() != CURSOR_WAIT)
+			_vm->_mouse->setCursorNum(CURSOR_ARROW);
+
+		// Check if any of the actions are currently highlighted
+		_highlightedAction = 0;
+		for (int i = kVerbLook; i <= kVerbThrow; ++i) {
+			Common::Rect r;
+			getActionRect(i, r);
+
+			if (r.contains(x, y)) {
+				_highlightedAction = i;
+				break;
+			}
+		}
+
+		return true;
+	}
+
+	return false;
+}
+
 } // End of namespace M4

Modified: scummvm/trunk/engines/m4/scene.h
===================================================================
--- scummvm/trunk/engines/m4/scene.h	2009-11-26 10:59:46 UTC (rev 46151)
+++ scummvm/trunk/engines/m4/scene.h	2009-11-26 11:48:43 UTC (rev 46152)
@@ -127,6 +127,29 @@
 	void nextCommonCursor();
 };
 
+enum FontMode {MODE_0, MODE_1, MODE_2};
+
+class InterfaceElement: public View {
+protected:
+	void setFontMode(FontMode newMode);
+public:
+	InterfaceElement(M4Engine *vm, const Common::Rect &viewBounds, bool transparent = true);
+	~InterfaceElement() {};
+};
+
+class ActionsView: public InterfaceElement {
+private:
+	int _highlightedAction;
+
+	void getActionRect(int actionId, Common::Rect &bounds);
+public:
+	ActionsView(M4Engine *vm);
+	~ActionsView() {};
+
+	void onRefresh(RectList *rects, M4Surface *destSurface);
+	bool onEvent(M4EventType eventType, int param1, int x, int y, bool &captureEvents);
+};
+
 } // End of namespace M4
 
 #endif


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