SOLVED: Custom display gui positioned relative to inventory item looked at..

Started by Slasher, Sun 19/01/2014 12:37:34

Previous topic - Next topic

Slasher

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?


Snarky

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.

Slasher

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

Khris

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

Slasher

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

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


Code: ags

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





Slasher

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

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






Khris

If you look at line 4 of the above snippet:
Code: ags
return (mouse.y - invWindowY) % invWin.ItemHeight + invWindowY;

you can adjust the general y and raster height by adding numbers:
Code: ags
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.

SMF spam blocked by CleanTalk