Looking with the right mouse button

From SCI Wiki
Jump to: navigation, search

To accomplish this we will use the priority colors - you can use the control colors as well.

Step 1: Trace & fill all the objects in your room with a priority color. For immediately adjacent objects, use a different color.

Step 2: Determine the bounding rectangle around each object. This will allow you to re-use a priority color more than once per room. Note that you can have overlapping bounding rectangles for objects - just make sure that the objects have different priority colors. To aid with determining the coordinates of the rectangles, temporarily include the following code in your handleEvent method to give you the cursor hotspot location on a right-click:

        (if(== (send pEvent:type) evMOUSEBUTTON and == (send pEvent:modifiers) 515)
            FormatPrint("x:%d, y:%d" (send pEvent:x) (send pEvent:y) )	 

Step 3: Modify your 'look' logic

                   (    == (send pEvent:type) evMOUSEBUTTON  // mouse click
        	    and == (send pEvent:modifiers) 515   // specifically a right mouse click
        	    and == $0002 OnControl(ocPRIORITY (send pEvent:x) (send pEvent:y))  // on NAVY priority color
                    // check that the mouse is in the bounding rectangle for this object
        	    and > (send pEvent:x) 93
        	    and < (send pEvent:x) 132
        	    and > (send pEvent:y) 78
        	    and < (send pEvent:y) 110
           Print("The box is closed")

Or for much cleaner implementation, create a class and then create instances of the class for each right-clickable area:

(class MouseLookObj
      priorityColor $0000
      xMin 0
      xMax 0
      yMin 0
      yMax 0
   (method (rightClicked pEvent)
(procedure (MouseLook pEvent) of MouseLookObj
       (if (== (send pEvent:type) evMOUSEBUTTON
    	    and == (send pEvent:modifiers) 515
    	    and == priorityColor OnControl(ocPRIORITY (send pEvent:x) (send pEvent:y))
    		and > (send pEvent:x) xMin
    		and < (send pEvent:x) xMax
    		and > (send pEvent:y) yMin
    		and < (send pEvent:y) yMax)

In your room script:

(instance public BoxLook of MouseLookObj
        priorityColor $0002 
        xMin  93 
        xMax 132 
        yMin  78
        yMax 110
(if(Said('look/box') or BoxLook:rightClicked(pEvent))
    Print("The box is closed")