[SOLVED] Interactive window with hotspots after clicking on object: GUI?

Started by Fatrat, Mon 24/06/2024 05:49:07

Previous topic - Next topic

Fatrat

Hi! I've created this image window that I'd like the player to be able to interact with.

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

Khris

GUIs are global objects so you can access them from inside a room script no problem.

Just put
Code: ags
  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
[img width=640]https://i.ibb.co/x7PzjGp/IMG-6064.jpg[/img]


Fatrat

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).

Fatrat

After doing some additional research just now, I think I need to find a way to turn GUI labels/buttons into hotspots or objects?

RootBound

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):

Code: ags
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.
They/them. Here are some of my games:

eri0o

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.

RootBound

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.
They/them. Here are some of my games:

Fatrat

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?

Khris

Having button images change upon hovering is a) not what OP is looking for here afaik b) built-in

You need something like this:

Code: ags
  // 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;

Fatrat

Thanks so much Khris! I ended up doing something similar to what you suggested and it worked! This is what I did:

Code: ags
function repeatedly_execute_always()
{
  GUIVariable = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  if (GUIVariable == lblScissors){
    lblAction.Text = "fabric scissors";
  }
}

RootBound

They/them. Here are some of my games:

SMF spam blocked by CleanTalk