Difference between revisions of "Adding 'Look' On Right Click"

From SCI Wiki
Jump to navigationJump to search
 
(3 intermediate revisions by the same user not shown)
Line 8: Line 8:
  
 
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:
 
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:
Code:
+
 
  
 
<div class="CodeBlockHeader">Code:</div>
 
<div class="CodeBlockHeader">Code:</div>
Line 16: Line 16:
 
)
 
)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
&nbsp;
  
 
Tip:  Even easier, in the picture editor (either Studio or Companion) use the x/y coordinate indicator to get the current location of the mouse.
 
Tip:  Even easier, in the picture editor (either Studio or Companion) use the x/y coordinate indicator to get the current location of the mouse.
 +
 +
&nbsp;
  
 
Step 3: Modify your 'look' logic
 
Step 3: Modify your 'look' logic
Line 39: Line 42:
 
)
 
)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
&nbsp;
  
 
For much cleaner implementation, create a class and then create instances of the class for each right-clickable area:
 
For much cleaner implementation, create a class and then create instances of the class for each right-clickable area:
Line 71: Line 74:
 
)
 
)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
&nbsp;
  
 
Then in your room script:
 
Then in your room script:

Latest revision as of 19:16, 30 October 2013

Originally posted on the SCI Programming Forums by Gumby.


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:


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

 

Tip: Even easier, in the picture editor (either Studio or Companion) use the x/y coordinate indicator to get the current location of the mouse.

 

Step 3: Modify your 'look' logic

Code:
        (if(Said('look/box')
        	or
                   (    == (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")
	)

 

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

Code:
(class MouseLookObj
   (properties
      priorityColor $0000
      xMin 0
      xMax 0
      yMin 0
      yMax 0
   )
   (method (rightClicked pEvent)
   	  MouseLook(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)
	      return(TRUE)
	)
        return(FALSE)
)

 

Then in your room script:

Code:
(instance public BoxLook of MouseLookObj
    (properties 
        priorityColor $0002 
        xMin  93 
        xMax 132 
        yMin  78
        yMax 110
    )
)

....

(if(Said('look/box') or BoxLook:rightClicked(pEvent))
    Print("The box is closed")
)