Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Sun 19/01/2014 12:37:34

Title: SOLVED: Custom display gui positioned relative to inventory item looked at..
Post by: Slasher on Sun 19/01/2014 12:37:34
Hi,

I am trying to have a custom gui with a label display at a location relating to which inventory item is looked at.

The inventory is only 1 column and is vertically positioned at 710.

The usual code I have does not seem to like this situation: type mismatch, can't convert to int.

Example: Looking at ifinger in the inventory, the display gui will position itself adjacent to ifinger and then become visible with the correct text on the label.

Maybe there is a better way?

Would you help please?

Title: Re: Custom display gui positioned relative to inventory item looked at..
Post by: Snarky on Sun 19/01/2014 13:00:59
This is one of those cases where you should actually include the bit of code that causes the error.

Actually, every case where your code crashes or fails to compile is one of those cases.
Title: Re: Custom display gui positioned relative to inventory item looked at..
Post by: Slasher on Sun 19/01/2014 13:10:56
Snarky,

all I am trying to do is have text displayed (could use normal textgui) to display adjacent to inventory item wherever it is positioned in the inventory item whenever it is looked at.

I will continue...
Title: Re: Custom display gui positioned relative to inventory item looked at..
Post by: Khris on Sun 19/01/2014 13:54:14
So you're basically asking how to calculate the y coordinate?
A very quick way of doing that would be to use the mouse position:
Code (ags) Select
int GetItemY() {
  InvWindow *invWin = the_inv_window;  // <- put correct name here
  int invWindowY = invWin.Y + invWin.OwningGUI.Y;
  return (mouse.y - invWindowY) % invWin.ItemHeight + invWindowY;
}

function iScrewdriver_LookAt() {
  DisplayAt(50, GetItemY(), 300, "It's a screwdriver.");
}


This will basically "round down" the mouse's y coordinate to the top of the item.
Title: Re: Custom display gui positioned relative to inventory item looked at..
Post by: Slasher on Sun 19/01/2014 16:39:09
Hi Khris,

many thanks for your help.

Your code works up to a point:

The dialog does not actually line up adjacent to the inventory item as much as I would like plus the further down the inventory items you go the more it is out of line.

Item H= 52
Item W= 63

QuoteThis will basically "round down" the mouse's y coordinate to the top of the item.
Middle would be preferred. I have tried setting y +  -  to get around it.

I have:

Code (ags) Select

  int GetItemY() {
  InvWindow *invWin = InventoryWindow3; 
  int invWindowY = invWin.Y + invWin.OwningGUI.Y;
  return (mouse.y - invWindowY) % invWin.ItemHeight + invWindowY;
}


Code (ags) Select

DisplayAt(440, GetItemY(),280, "The blood oozing finger must belong to a grave robber.");




Title: SOLVED: Re: Custom display gui positioned relative to inventory item looked at..
Post by: Slasher on Tue 21/01/2014 07:48:49
Hi,

As per last post.

Is there any real harm using this code as it seems to work fine for each item?

Using normal text gui.

Tweak X according to string length of Item Display.

Example of Looking at an Inventory Item:
Code (ags) Select

DisplayAt (mouse.x-320, mouse.y, 320, "The severed finger, you deduce, came from a grave robbers' hand very recently. You could tell it was a grave robbers' finger because it had a very dirty fingernail along with an expensive gold ring. No gentleman would have such dirty finger nails.");





Title: Re: SOLVED: Custom display gui positioned relative to inventory item looked at..
Post by: Khris on Thu 23/01/2014 21:24:25
If you look at line 4 of the above snippet:
Code (ags) Select
return (mouse.y - invWindowY) % invWin.ItemHeight + invWindowY;
you can adjust the general y and raster height by adding numbers:
Code (ags) Select
return (mouse.y - invWindowY) % (invWin.ItemHeight + 4) + invWindowY - 7;

This will increase the y distance of items by 4, but move it up by 7 pixels as a whole. Try experimenting with positive and negative numbers till it looks right.
I'm wondering though why the y raster size seems to be greater than .ItemHeight? That shouldn't happen I guess.