Broken Sword style mouse icons

Started by oskargunn, Mon 29/09/2014 00:19:14

Previous topic - Next topic

oskargunn

Hi,

I would like to create a Broken Sword-ish mouse interaction.

What I already have is the mouse-over code ready for particular hotspot:


Code: ags

// in room script
function hPainting_MouseMove()
{
  mouse.SaveCursorUntilItLeaves();
  mouse.Mode = eModeInteract;
}


Once the user clicks on the object I make a gui visible. The gui consists of 2 buttons:

Code: ags

// in room script
function hPainting_Interact()
{
  gItemIcons.SetPosition(mouse.x-50,  mouse.y-70);  
  gItemIcons.Visible = true;
}


The only way I know of how to implement this is to let the logic lay inside the GlobalScript, in the onclick function of the button:

Code: ags

// in global script
function btnLookAt_OnClick(GUIControl *control, MouseButton button)
{
  gItemIcons.Visible = false;
  return;
}


I would like to return control back to the room with the id of the button pushed and then the particular action occurs.
Does anyone know what is the best way to do that ?

Khris

You're looking for GetLocationType(), ProcessClick(), and possibly *.RunInteraction().
Those make it possible to implement everything about this interface globally, which means you won't need the first snippet you posted at all, and in the second one you can state what actually happens when the player interacts with the hotspot, regardless of how the UI works.
Imagine you had to add those two functions like that to every single active spot in the game; that's just nuts and thankfully not necessary.

To implement an automatic cursor:
In repeatedly_execute in the GlobalScript, check GetLocationType and change the mouse.Mode accordingly. (Multiple threads about this exist already.)

As for the verb-coin, the idea is to use on_mouse_click(). In there, the position of the click is stored, then the GUI is shown. In the button's code, ProcessClick is called using the stored values. Scrolling rooms might require some additional code. (Again, asked and answered multiple times before.)

In general, make sure you exhaust the forum search before opening a thread. I know it's not always easy to find a recent thread with a nice solution, but it really helps to reduce clutter and make future searches more relevant.

oskargunn

Excellent reply Khris!
I hadn't noticed GetLocationType(). 
I could now create the whole workings in a seperate script, which makes it general with the help of ProcessClick.

Yeah, I searched the forum, but I guess not well enough :/   I'll try harder in the future.

But thanks again Khris, you put me on the right track :)

SMF spam blocked by CleanTalk