- Home /
Problems with Custom Tool Tip Generation
I am currently having problems generating custom windows to appear when hovering over an item in my inventory. I am using a self modified version of Brackeys Inventory System.
All works fine, if i hover over the objects the window appears on my cursor as expected. But when i take away my cursor from any icon it still persists.

The Code for this as follows:
//Drawing the Inventory window
function OnGUI()
{
GUI.skin = invSkin;
if(itemBeingDragged != null) //If we are dragging an Item, draw the button on top:
{
GUI.depth = 3;
GUI.Button(Rect(draggedItemPosition.x,draggedItemPosition.y,draggedItemSize.x,draggedItemSize.y),itemBeingDragged.itemIcon);
GUI.depth = 0;
}
//If the inventory is opened up we create the Inventory window:
if(DisplayWindow)
{
mouse = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
WepHand.CanUseInventory = false;
CameraScript.LockCamera();
CameraUnlocked = false;
windowRect = GUI.Window (windowID, windowRect, SetUpDisplayWindow, WindowName);
}
else
{
if(!CameraUnlocked)
{
CameraScript.UnlockCamera();
CameraUnlocked = true;
}
WepHand.CanUseInventory = true;
}
GUI.skin = ToolTipSkin;
if(HoverItem != null)
{
ToolTipRectangle = GUI.Window(99, ToolTipRectangle, ToolTipSetup, "");
}
}
function SetUpDisplayWindow(windowID:int)
{
GUI.skin = invSkin; //Use the invSkin
var MaxSpace : int = InventoryObj.GetComponent(InvStorage).MaxContent;
var SpaceTaken : int = InventoryObj.GetComponent(InvStorage).Contents.Length;
GUI.Label(Rect(12, 5,100,100), (MaxSpace - SpaceTaken) + " / " + MaxSpace );
if (canBeDragged == true)
{
GUI.DragWindow (Rect (0,0, 10000, 30)); //the window to be able to be dragged
}
var currentX = 0 + Offset.x; //Where to put the first items.
var currentY = 18 + Offset.y; //Im setting the start y position to 18 to give room for the title bar on the window.
for(var i:Transform in UpdatedList) //Start a loop for whats in our list.
{
//Get the items script
var item=i.GetComponent(Item);
//Create a button for this instance
ButtonRect = new Rect(currentX,currentY,itemIconSize.x,itemIconSize.y);
// if the player clicks this button, add the item to their inventory
if (GUI.Button(ButtonRect, item.itemIcon))
{
if(PlayerInv.Contents.Length < PlayerInv.MaxContent)
{
item.TransferToPlayer(i);
}
}
//if hovering over the item, trigger an window to open with info on the object
if(ButtonRect.Contains(new Vector2(mouse.x - windowRect.x, mouse.y - windowRect.y)))
{
HoverItem = item;
}
//If its stackable, display the ammount in the stack
if(item.stackable) //If the item can be stacked:
{
GUI.Label(Rect(currentX, currentY, itemIconSize.x, itemIconSize.y), "" + item.stack, "Stacks"); //Showing the number (if stacked).
}
//Space the items out in the display.
currentX += itemIconSize.x;
if(currentX + itemIconSize.x + Offset.x > windowSize.x) //Make new row
{
currentX=Offset.x; //Move it back to its startpoint wich is 0 + offsetX.
currentY+=itemIconSize.y; //Move it down a row.
if(currentY + itemIconSize.y + Offset.y > windowSize.y) //If there are no more room for rows we exit the loop.
{
return;
}
}
}
}
function ToolTipSetup(windowID : int)
{
ToolTipRectangle.position = mouse;
}
Annoying, i thought if i added in an else statement to the ButtonBox.Contains it would fix it, but it only makes things worse. It only shows a tooltip for the final item, but atleast it dissapears.

//if hovering over the item, trigger an window to open with info on the object
if(ButtonRect.Contains(new Vector2(mouse.x - windowRect.x, mouse.y - windowRect.y)))
{
HoverItem = item;
}
else
{
HoverItem = null;
}
It appears to me its due to the type of loop that is used in the procedural generation of the inventory icons...
Any ideas on the best way to achieve what i am trying to do?
Answer by Jamoy1993 · Aug 16, 2014 at 12:31 PM
I fixed it by changing the for loop from an x in y to an incremental loop. Then i made another loop to loop through rects stored in an array and a few lines of code to deter whether or not the player is over an rect.
Your answer
Follow this Question
Related Questions
Create objects in a selected area 2 Answers
By Code generated Mesh (problems with visibility) 4 Answers
Procedural terrain generation ? 0 Answers
How would i make this code not lag the game 1 Answer
Difference between if statement, while and for loop? 4 Answers