I need help with Gspot

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Quôzul
Prole
Posts: 15
Joined: Mon Apr 16, 2018 5:03 pm
Location: France
Contact:

I need help with Gspot

Post by Quôzul »

Hello,
I'm using the Gspot library to create UI for my game and I want to create a inventory with a menu appearing beside the name of the item when I hover it.
See my attached "helpme.love" (it's in love 11)

-- Edit
The problem is that only one sub-menu is appearing (the last one created).

(Sorry if my english is bad btw)
Attachments
helpme.love
(11.15 KiB) Downloaded 89 times
Last edited by Quôzul on Tue Apr 17, 2018 7:55 am, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: I need help with Gspot

Post by pgimeno »

Hello, welcome to the forums.

I'm not sure I understand. My understanding is that you want to have a series of items as names in a list, and when you hover over one, a menu appears and you can select from it, or it disappears if you move the mouse. Is that right?
User avatar
Quôzul
Prole
Posts: 15
Joined: Mon Apr 16, 2018 5:03 pm
Location: France
Contact:

Re: I need help with Gspot

Post by Quôzul »

pgimeno wrote: Tue Apr 17, 2018 12:01 amHello, welcome to the forums.
Thanks you :nyu:
pgimeno wrote: Tue Apr 17, 2018 12:01 amI'm not sure I understand. My understanding is that you want to have a series of items as names in a list, and when you hover over one, a menu appears and you can select from it, or it disappears if you move the mouse. Is that right?
That's the idea, and from the menu that appears I can remove the items from the inventory and see the attributes of it.

But the problem is that only one menu is appearing (the last one) :|
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: I need help with Gspot

Post by pgimeno »

One more clarification. When you say menu, do you mean the tooltip text? that is, the little window with a text?

If you mean just that, you can use the tip property instead, like this:

Code: Select all

        display.item.tip = "This is a" .. (e:match("^[aeio]") and "n " or " ") .
. e .. "; you can place the\nstats you want here"
If you actually mean a menu with options like wield, drop, etc. then that needs more work.

Note that there's a bug when showing multiline tooltips like the above, that I'm going to fix right now :)
User avatar
Quôzul
Prole
Posts: 15
Joined: Mon Apr 16, 2018 5:03 pm
Location: France
Contact:

Re: I need help with Gspot

Post by Quôzul »

pgimeno wrote: Tue Apr 17, 2018 12:30 pmOne more clarification. When you say menu, do you mean the tooltip text? that is, the little window with a text?
I meant the little window that popup next to the item.
pgimeno wrote: Tue Apr 17, 2018 12:30 pmIf you mean just that, you can use the tip property instead, like this:

Code: Select all

        display.item.tip = "This is a" .. (e:match("^[aeio]") and "n " or " ") .
. e .. "; you can place the\nstats you want here"
Thank you I didn't thought of that!
pgimeno wrote: Tue Apr 17, 2018 12:30 pmIf you actually mean a menu with options like wield, drop, etc. then that needs more work.

Note that there's a bug when showing multiline tooltips like the above, that I'm going to fix right now :)
For dropping the item, I've add a small button next to the item but how can I update the list?
Attachments
game.love
(10.86 KiB) Downloaded 63 times
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: I need help with Gspot

Post by pgimeno »

Quôzul wrote: Tue Apr 17, 2018 1:12 pm For dropping the item, I've add a small button next to the item but how can I update the list?
First, you need to remove the element and the extra button with gui:rem(element). Then you will need to reposition the other elements.

You need to rethink your code a bit, though:

- You're creating a new window and new buttons every time display.update is created, and not removing any. If you want to recreate buttons, you need to delete all first; a quick way is to remove display.inventory.bag if it is not nil, right at the beginning. You can use something like print(#gui.elements) to track how many GUI elements you have active.

Even better, you can have the bag created at the start (not every time you call display.update), and make a function to add an item to the player's inventory, that also adds the controls to the GUI, and another function to remove from it, that also removes the controls from the GUI. Then, to add one item to the player's inventory, you call that function and it will automatically add the button for you. And to remove an item, you call the other function, which will also remove the controls.

- You're trying to remove from the inventory by number, but your items are names. The remove won't succeed. I'd suggest you switch your inventory to numeric, because then the order is preserved (pairs() does not iterate in any particular order, and in fact the order can change when it rehashes). You can then also use the numeric index for repositioning the GUI buttons.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: I need help with Gspot

Post by pgimeno »

I've merged the multiline fix now.
User avatar
Quôzul
Prole
Posts: 15
Joined: Mon Apr 16, 2018 5:03 pm
Location: France
Contact:

Re: I need help with Gspot

Post by Quôzul »

pgimeno wrote: Thu Apr 19, 2018 9:20 am I've merged the multiline fix now.
I'll try this out, thank you for theses tips :D

Sorry to have taken a long time to answer, I had a problem with my computer.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 56 guests