Display text for an objects Description, when mouse is over object

Started by bx83, Sun 11/02/2018 00:44:28

Previous topic - Next topic

bx83

Hi,

I've been wanting to write a piece of text in the game to describe an object, and bring it up on an overlay at the bottom-centre of the screen. Something like this:


I've been searching, but still can't find how to do it. Also I've been having problems with overlays... which basically means I don't know how to use them :P

Here's my code for the mouse graphic - it updates to an 'active cursor' when we're over something we want to look at/talk to/interact with/etc:
Code: ags

function UpdateMouseGraphic ()
{
  int newGraphic;
  int lt = GetLocationType(mouse.x, mouse.y);

  if (mouse.Mode==eModeUseinv) return;

  if (mouse.Mode==eModeWalkto) {
    newGraphic=3; //stand still
    if (gInventory.Visible==true) {
		} else if (GetWalkableAreaAt(mouse.x, mouse.y) !=0) {
      newGraphic=2054;  //walking
    }
  }
  
  else if (mouse.Mode==eModeLookat) {		//LOOKAT
    newGraphic=105; //eye close
    Hotspot *hs = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
    Object *ob = Object.GetAtScreenXY(mouse.x, mouse.y);
		InventoryItem *inve = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

		if (gInventory.Visible==true && inve!=null) {
			if (inve.IsInteractionAvailable(eModeLookat)) {
				newGraphic=2056;  //eye open
			}
			
		//looking at hotspot
    } else {
			if (lt == eLocationHotspot) {
				if (hs != hotspot[0]) {
					if (hs.GetProperty("hidden")==false) {
						if(hs.IsInteractionAvailable(eModeLookat)) { 
							 newGraphic=2056;	//eye open
						}
					}
				}
			}
			
			//looking at object
			else if (lt == eLocationObject && ob.IsInteractionAvailable(eModeLookat) && ob.Visible == true) {
				newGraphic=2056;  //eye open
			}
		}
	}
	
  else if (mouse.Mode==eModeInteract) {		//INTERACTION
    newGraphic = 2;  //interact off
    Hotspot *hs = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
    Object *ob = Object.GetAtScreenXY(mouse.x, mouse.y);
		
 		InventoryItem *inve = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

		//interacting with inventory item
		if (gInventory.Visible==true && inve!=null) {
			if (inve.IsInteractionAvailable(eModeLookat)) {
				newGraphic=286;
			}
		} else {

			//interacting with hotspot
			if (hs != hotspot[0]) {
				if (hs.GetProperty("hidden")==false) {
					if (hs.IsInteractionAvailable(eModeInteract)) {
						newGraphic=286;
					}
				}
			}
			
			else if (lt == eLocationObject) {
				if (ob.Visible==true) {
					if (ob.IsInteractionAvailable(eModeInteract)) {
						newGraphic=286;
					}
				}
			}
		}
	}
	
	else if (mouse.Mode==eModeTalkto) {		//TALKTO
		newGraphic = 2058;  //talk off
		Character *ch = Character.GetAtScreenXY(mouse.x, mouse.y);
		Object *ob = Object.GetAtScreenXY(mouse.x, mouse.y);
		InventoryItem *inve = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
		
		if (gInventory.Visible==true && inve!=null) {
		} else {
			if (lt == eLocationCharacter) {
				if (ch != null) {
					if (player.ID != ch.ID) {
						newGraphic = 213; //talk on
					}
				}
			}
			else if (lt == eLocationObject && ob.Visible && ob.IsInteractionAvailable(eModeTalkto)) {
				newGraphic=213;
			}
		}
  } 

  if (newGraphic != mouse.GetModeGraphic(mouse.Mode)) {
    mouse.ChangeModeGraphic(mouse.Mode, newGraphic);
  }
	
}


I'm assuming that after each MouseMode check, I put the decription in after every "newGraphic = ACTIVE_ICON" line:
Code: ags

...
if (mouse.Mode==eModeTalkto) {		//TALKTO
newGraphic = 2058;  //talk off
Character *ch = Character.GetAtScreenXY(mouse.x, mouse.y);
		
if (lt == eLocationCharacter) {
	if (ch != null) {
		if (player.ID != ch.ID) {
			newGraphic = 213; //talk on
                        Overlay "this is a "+character.Description;
		}
	}
}
...


Is this correct? Should I do something simple like this?
What is the correct Overlay code?

Grundislav

Easiest way to do this is to create a GUI. Call it something like "gHotSpotLabel" and create a blank label over it.

Then, in your game's repeatedly_execute_always, put in Label1.Text = Game.GetLocationName(mouse.x, mouse.y); (Where "Label1" is the name of your label)

Hope that helps!

Buckethead

Unless you want something fancy, you can just make your GUI label text: "@overhotspot@" and it will display hotspot, object and character names automatically.

Crimson Wizard

The two posts above answer your question on displaying a label. I will add a little info about Overlays.

In AGS, Overlays seem to be inferior to GUIs in all accounts, except one: you can create them dynamically and do not have to prepare them in the editor.
On the other hand, they are much simplier and can only have 1 string of text or 1 sprite displayed at a time.
Ofcourse, if you use a dynamic sprite, you can draw any kind of stuff using DrawingSurface.
Also, Overlays do not have configurable Z-order, they are always displayed on a strict layer on screen - above room, but below GUIs.
And, you cannot interact with them, meaning clicking on them won't trigger anything. In fact, AGS does not provide built-in function to detect if there is an overlay under mouse cursor.

Overlays are good when you need to display something simple on screen occasionally.

QuoteWhat is the correct Overlay code?

Hey, there is a manual with code examples: http://www.adventuregamestudio.co.uk/manual/ags71.htm#topic63

bx83

Buckethead: I've never heard of this before, does it work for anything always just by including the text? Are there any other @ variables in th game?

Crimson Wizard

Quote from: bx83 on Mon 12/02/2018 01:03:26
I've never heard of this before, does it work for anything always just by including the text?

BTW, @OVERHOTSPOT@ works only on GUI Labels, it is like a special function for them. But it is essentially the same as doing Game.GetLocationName, as in Grundislav's example.


Egmundo Huevoz

Quote from: bx83 on Mon 12/02/2018 01:03:26
Buckethead: I've never heard of this before, does it work for anything always just by including the text? Are there any other @ variables in th game?
Yes, it works for everything, provided it has a name (for instance, if you create an object and don't name it, nothing will show).
If you search "@overhotspot@" in the manual, it will direct you to an entry called "editing the GUIs". There, under "interface text", is a list of other commands you can put into a label.

Quote from: AGS
@GAMENAME@    The game's name, specified on the Game Settings pane
@OVERHOTSPOT@ Name of the hotspot which the cursor is over
@SCORE@       The player's current score
@SCORETEXT@   The text "Score: X of XX" with the relevant numbers filled in.
@TOTALSCORE@  The maximum possible score, specified on the Game Settings pane

Anyway, you can show lots of information in labels, but you'll need to know the basics of scripting. If you're interested, I can explain further.

bx83

Okay, well I created my GUI, however it didn't far as the background (which was transparent) blocked the mouse cursor from objects.... sometimes.
How do I z-order the thing to the not-interfering with the mouse layer?
Or do I just make it a small GUI and place it at the bottom of the screen?
Well that would seem obvious...

Crimson Wizard

Quote from: bx83 on Thu 15/02/2018 23:27:26
Okay, well I created my GUI, however it didn't far as the background (which was transparent) blocked the mouse cursor from objects.... sometimes.
How do I z-order the thing to the not-interfering with the mouse layer?
Or do I just make it a small GUI and place it at the bottom of the screen?
Well that would seem obvious...

Just set Clickable to false.

bx83

Thank you, it works :)

BTW now my problem is: How do I set a hotspot's Description at runtime? I can't look it up as a property, and Set/GetTextProperty doesn't have it (ofcourse, but I gave it a try).

Khris

The property is Hotspot.Name, but it's read-only. If you want to change it during the game, you have to use a custom property (and can no longer use @OVERHOTSPOT@).

SMF spam blocked by CleanTalk