Author Topic: Cursor Hot Spot  (Read 2962 times)

0 Members and 1 Guest are viewing this topic.

Offline Doan Sephim

Cursor Hot Spot
« on: March 19, 2007, 11:06:44 AM »
I want to have a cursor with a hotspot of (8,8) instead of (0,0). This is cannot be accomplished in the cursor editor, but Troflip suggested it can be done with some internal coding. What I have done is created a variable for my cursor called gTargetCursor and set it equal to the number for a custom-drawn cursor.

for instance gNormalCursor = 999 and gLoadingCursor = 997.

However, I have tried with no success in locating where the "hotspot" would be defined. I do realize the word "hotspot" most likely won't be used, but has anyone programmed this kind of thing or know where to go?


Artificial Intelligence Competition

Offline Eigen

Re: Cursor Hot Spot
« Reply #1 on: March 20, 2007, 07:35:53 AM »
It should go something like this

pseudocode:
Code: [Select]
var cursor_x
var cursor_y
var hotspot_x = 8
var hotspot_y = 8

= cursor_x (+ (event: x) hotspot_x)
= cursor_y (+ (event: y) hotspot_y)

if (cursor_x and cursor_y are in certain area)
    do stuff
)

event: x and event: y would be the real mouse coordinates you receive from the mouse event.


Basically you take the real mouse cursor position and add your hotspot values and then work with the new variables.


-Eigen
Artificial Intelligence Competition

Offline Doan Sephim

Re: Cursor Hot Spot
« Reply #2 on: March 20, 2007, 02:55:41 PM »
Thanks Eigen, that should help me to do somework, but I am mainly looking for the Script where the mouse properties are defined. I don't know which script it is in. ???

Offline troflip

Re: Cursor Hot Spot
« Reply #3 on: March 20, 2007, 07:14:39 PM »
Use SCI Companions handy "find in all files" function to search for a piece of text in all scripts.

There must be some code in the template game that converts a mouse click into a MoveTo motion for the ego.  So maybe try searching for one of the mouse events:
http://www.bripro.com/scistudio/help/scc/kernel_getevent.html
e.g. evMOUSEBUTTON

The conversion of the x and y coordinates will need to happen somewhere between the GetEvent call (which gets the raw event from the game engine) and where it is actually used.

On problem might be the menubar... I could be wrong, but I think the menubar clicks are handled all in the game engine (E.g. sciv.exe)... so you don't get to change the x and y coordinates.  So there may be no way to have a center hotspot for clicking on menus (unless of course you draw your own menu bar, but that would be a ton of work!)
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline I. Lostalim

Re: Cursor Hot Spot
« Reply #4 on: March 20, 2007, 08:32:35 PM »
Quote
There must be some code in the template game that converts a mouse click into a MoveTo motion for the ego.
pre-SCI companion, I found it the hard way... ie simply reading through all the likely scripts.

It's found in USER and looks something like this:
Code: [Select]
(method (handleEvent pEvent)
(var direction)
(if( not (super:handleEvent(pEvent)) )
    (switch( (send pEvent:type) )
(case evMOUSEBUTTON
// Make sure it's the left button
(if(not (& (send pEvent:modifiers) emRIGHT_BUTTON)
    and (User:controls) ) 
(self:
setMotion(
MoveTo
(send pEvent:x)
(send pEvent:y)
)
)
(User:prevDir(CENTER))
(send pEvent:claimed(TRUE))
)
)
  (case evJOYSTICK
  = direction (send pEvent:message)
  (if( (== direction (User:prevDir)) and (IsObject(mover)))
    = direction CENTER
    )
    (User:prevDir(direction))
    (self:setDirection(direction))
    (send pEvent:claimed(TRUE))
  )
  )
  )
  return(send pEvent:claimed)
)/[code]

 - I've never tried editing it yet - at least not successfully, but then I've not had my head in SCI code for a very long time, I'm a little rusty.
[/code]

Offline Doan Sephim

Re: Cursor Hot Spot
« Reply #5 on: March 21, 2007, 12:24:05 PM »
Interesting find...I wonder why I didn't see that? So that method is part of the Ego Class. Do you think I would want to create a Class with a similar method? I say that beacuse I do not want to control the Ego with the cursor hotspot (8,8) but do something more like QfG II with targeted actions not involving the Ego directly...so would I want to create a different class? (which I have never done before)

Offline Eigen

Re: Cursor Hot Spot
« Reply #6 on: March 21, 2007, 02:11:57 PM »
Add these global variables to main.sc:
Code: [Select]
mouse_x
mouse_y
hotspot_x = 8
hotspot_y = 8

And in User.sc add these two lines to handleEvent method under mousebutton event
Code: [Select]
= mouse_x (+(send pEvent:x) hotspot_x)
= mouse_y (+(send pEvent:x) hotspot_y)

so it would be:
Code: [Select]
(method (handleEvent pEvent)
...
(case evMOUSEBUTTON
// Make sure it's the left button
(if(not (& (send pEvent:modifiers) emRIGHT_BUTTON)
    and (User:controls) ) 
(self:
setMotion(
MoveTo
(send pEvent:x)
(send pEvent:y)
)
)
                = mouse_x (+(send pEvent:x) hotspot_x)
              = mouse_y (+(send pEvent:x) hotspot_y)
(User:prevDir(CENTER))
(send pEvent:claimed(TRUE))
)
)
  ...
  )
  )
  return(send pEvent:claimed)
)

And now you can use variables mouse_x and mouse_y if you want to get mouse position.
Although the position is currently updated only when the mouse button is clicked, not moved.



-Eigen
Artificial Intelligence Competition

Offline troflip

Re: Cursor Hot Spot
« Reply #7 on: March 21, 2007, 02:31:01 PM »
Yeah, but that code is for controlling the ego with the cursor, which he just said he wasn't interested in...

I'm not sure exactly what "targetted actions" you're talking about Doan... but basically, whereever you were going to write code that checked the x/y of a mouse event, you would just need to adjust by the appropriate value (e.g. 8).

If you're talking about the user clicking on buttons, then go change that code (probably in Controls.sc?).
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Eigen

Re: Cursor Hot Spot
« Reply #8 on: March 21, 2007, 04:17:57 PM »
No, this script, among other things, sets the position for ego to walk to when mouse is clicked. It's not specifically done for "moving the ego". So it's perfect for calculating "hotspotted cursor" position as well.

Artificial Intelligence Competition

Offline Doan Sephim

Re: Cursor Hot Spot
« Reply #9 on: March 21, 2007, 04:38:24 PM »
Looks good! I don't have time at the moment to test it all out, but I have an idea of how to make it work...I'll get back to ya!  :)

EDIT: I must be missing something...I am beginning to think that such a function as this might be more work than is really beneficial anyways.
« Last Edit: March 23, 2007, 01:40:31 PM by Doan Sephim »
Artificial Intelligence Competition


SMF 2.0.14 | SMF © 2017, Simple Machines
Simple Audio Video Embedder

Page created in 0.095 seconds with 24 queries.