Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Fatrat on Mon 24/06/2024 05:49:07

Title: [SOLVED] Interactive window with hotspots after clicking on object: GUI?
Post by: Fatrat on Mon 24/06/2024 05:49:07
Hi! I've created this image window that I'd like the player to be able to interact with.
(https://ibb.co/BCdTZjX)
In this specific case , I'd like:

1. this window to open up when the player clicks on the overturned basket.
2.hotspot description to show up over hotspot when cursor is hovering
3. dialogue shows over the window

I'm currently doing this as a gui, but the problem is gui only works in global script so it cannot be called when clicking room specific object. Do I do this as an overlay? But then how do I add hotspots onto the window? I've seen this done in multiple AGS games so I know it's possible, I'm just not sure how. Any help appreciated, thank you!

Link to image in case the inserted one doesn't work (https://ibb.co/BCdTZjX)
Title: Re: Interactive window with hotspots after clicking on object: GUI or Overlay?
Post by: Khris on Mon 24/06/2024 08:17:04
GUIs are global objects so you can access them from inside a room script no problem.

Just put   gBasket.Visible = true; in your interaction function.

Hotspot hovering means you need to add GUI buttons to the code that displays them. Which template / module are you using?



Side note: to upload screen shots, first check the global on_key_press function for an existing F12 line. Some templates have this built-in. Press F12 during the game (when the interface isn't blocked) and AGS saves a screenshot to the save game folder. Usually C:\Windows\Users\[Username]\Saved Games\[Name of Game]

Next, upload this image to a host that supports hotlinking. After the upload, right-click the image and select "copy image location" or similar.

Finally, paste the url into your post and surround it with tags:
Code (bb) Select
[img width=640]https://i.ibb.co/x7PzjGp/IMG-6064.jpg[/img]
(https://i.ibb.co/x7PzjGp/IMG-6064.jpg)
Title: Re: Interactive window with hotspots after clicking on object: GUI or Overlay?
Post by: Fatrat on Mon 24/06/2024 19:52:26
Thank you Khris! I guess the problem was I was using the open_gui function. I'm not using any module at the moment, I just made a GUI with the image as the background and a simple close button.

Would you have any advice on how to code the hotspot hovering buttons? Since it seems there is only Mouseover Image in the properties? I'm guessing I would have to code for hovering, right click to look, and left click to interact (which I know is already built in).
Title: Re: Interactive window with hotspots after clicking on object: GUI or Overlay?
Post by: Fatrat on Mon 24/06/2024 20:59:25
After doing some additional research just now, I think I need to find a way to turn GUI labels/buttons into hotspots or objects?
Title: Re: Interactive window with hotspots after clicking on object: GUI or Overlay?
Post by: RootBound on Mon 24/06/2024 22:10:35
You can use GUIControl.GetAtScreenXY(mouse.x, mouse.y) to check what button is under the mouse, and then code within that what images or animations you want the button to have.

For example, in the global repeatedly_execute_always function, you could try the following (untested, sorry):

if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == gButton1){
  gButton1.Graphic = (whatever graphic you want to change it to);
else{
  gButton1.Graphic = (original button graphic)
}
if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == gButton2){
  gButton2.Graphic = (whatever graphic you want to change it to);
else{
  gButton2.Graphic = (original button graphic)
}
and so on.
Title: Re: Interactive window with hotspots after clicking on object: GUI or Overlay?
Post by: eri0o on Mon 24/06/2024 22:28:08
No need to go to the script API so many times, just store the GUIControl.GetAtScreenXY(mouse.x, mouse.y) result in a variable and compare the results. Also you can't be on top of more than one button at the same time.
Title: Re: Interactive window with hotspots after clicking on object: GUI or Overlay?
Post by: RootBound on Tue 25/06/2024 00:44:59
Quote from: eri0o on Mon 24/06/2024 22:28:08No need to go to the script API so many times, just store the GUIControl.GetAtScreenXY(mouse.x, mouse.y) result in a variable and compare the results. Also you can't be on top of more than one button at the same time.

I considered that but thought it might return a null pointer if there's no button under the mouse. And I assume the button graphic needs to change back when the mouse moves off it, which is why I included the else.
Title: Re: Interactive window with hotspots after clicking on object: GUI or Overlay?
Post by: Fatrat on Tue 25/06/2024 01:31:30
Thank you! I'll try that right now. Do you think it'll be possible to do text instead of a graphic, or am I just going to have to make text png files?

Edit: So my current plan is storing the GUIcontrol result as a variable and when it is on top of a label, have the action bar label change to reflect the hotspot.
To do this, should I create a global variable? Of what type?
Title: Re: Interactive window with hotspots after clicking on object: GUI or Overlay?
Post by: Khris on Tue 25/06/2024 01:48:02
Having button images change upon hovering is a) not what OP is looking for here afaik b) built-in

You need something like this:

  // inside repeatedly_execute

  // default value is name of hotspot / object / character under cursor
  String ln = Game.GetLocationName(mouse.x, mouse.y);

  GUIControl* gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  // if mouse is over button, change text to button description
  if (gc == btnScissors) ln = "scissors";
  if (gc == btnThread) ln = "thread";
  ...

  // set label text
  lblDescription.Text = ln;
Title: Re: Interactive window with hotspots after clicking on object: GUI or Overlay?
Post by: Fatrat on Tue 25/06/2024 02:03:41
Thanks so much Khris! I ended up doing something similar to what you suggested and it worked! This is what I did:

function repeatedly_execute_always()
{
  GUIVariable = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  if (GUIVariable == lblScissors){
    lblAction.Text = "fabric scissors";
  }
}
Title: Re: [SOLVED] Interactive window with hotspots after clicking on object: GUI?
Post by: RootBound on Tue 25/06/2024 02:38:44
Seems I misunderstood the request. Apologies. :X