How do I make an inventory with lots of "slots"?

@t0neg0d “Everything is a basic Element.” :slight_smile:

1 Like
@tuffe said: @t0neg0d "Everything is a basic Element." :)

Awesome… should be able to setup a test case in just a bit here. I’ll let you know what I find.

Hi @t0neg0d how goes it?

Quick question: Is there something like a reposition/resize listener? I want to do something each time an element is resized or repositioned. How would you do that?

Just override:

[java]
Element.controlResizeHook();
[/java]

For the control you want to do this with. If you need to centralize this, you can always setup a global method that takes Element or Node as a param and just call this method from the resize hook passing a reference to the control:

[java]
public void myGlobalResizeHandler(Element el) {
// You code here
}
[/java]

Then in the resize hook when creating whatever control you are creating:

[java]
Element el = new Element(screen, Vector2f.ZERO) {
@Override
public void controlResizeHook() {
((Main)screen.getApplication()).myGlobalResizeHandler(this);
}
};
[/java]

@t0neg0d does that work for repositions too? I took a quick look in the code, and it does not seem that way.

@tuffe said: @t0neg0d does that work for repositions too? I took a quick look in the code, and it does not seem that way.

There should be a separate hook for move. Something along the lines of:

[java]
Element.controlMoveHook();
[/java]

@t0neg0d Ah, nice!

Did you find out what was up with that .move(0, 0, 20) on the container element? :stuck_out_tongue:

Another question:

Say I want to show a tooltip if the user hovers over some other Element. (Like, I want to show a description of the item if the user hovers over an item in the inventory.) How would you do that? I mean, how would you detect that a tooltip should be displayed, and of what? The actual displaying of the tooltip is not a problem.

I thought about just using getEventElement, getTargetElement or getContactElement to get at the item and go from there. Btw, what is the difference between those 3? Which one would I use for just getting the thing under the cursor, with as little side effects as possible?

You should be able to show the tooltip just by setting the tool tip text for the control:

[java]
Element.setToolTipText(“Formatted display string”); // i.e. \n for new line etc
[/java]

@sgold came up with a patch for this that I am going to get in today… Though, today has been really rough so far (sicker than sick last night).

EDIT: Oooops… remember to enable tool tips through the screen. And I have not figured out the move issue yet. Just due to how sick I’ve been over the past few weeks. Won’t be much longer before this isn’t an issue anymore. Sorry for the delay =)

@t0neg0d

A few questions about the appearance of the tool tip:

  1. The bgColor attribute in the XML does not seem to do anything.
  2. The textPadding attribute does not seem to do anything.
  3. Why is there a margin (in the screen shot below) above, below, and to the right, but not to the left?

Get well!

@t0neg0d Just wanted to make sure you saw my previous message. There’s no rush though. :stuck_out_tongue:

@tuffe said: @t0neg0d Just wanted to make sure you saw my previous message. There's no rush though. :p

Thanks for this… I saw it before I got sick and then promptly forgot I saw it!

Let me take a look and I’ll let you know.

@tuffe said: @t0neg0d

A few questions about the appearance of the tool tip:

  1. The bgColor attribute in the XML does not seem to do anything.
  2. The textPadding attribute does not seem to do anything.
  3. Why is there a margin (in the screen shot below) above, below, and to the right, but not to the left?

Get well!

Ah… ToolTips just got an overhaul code-wise thanks to @sgold and there are about to get a visual facelift (and become customizable) thanks to @rockfire

Instead of trying to work around it’s current limitations, let me implement rockfire’s approach, which will allow you to design your own ToolTip window instead of trying to work with the extremely limited one I used as a default.

@t0neg0d Nice, sounds good!

@t0neg0d Hi! I haven’t been following the developments with the GUI recently. Are the tooltip changes you were talking about ready?

Btw I saw that you fixed the problem that I had before with private boolean initializedLoader; in Screen being static. But if it is not static, it is not needed at all, right? It will be false every time from the beginning, and it is only used in the constructor. So get rid of the code that uses it. This was maybe a little off-topic in this thread, but I just wanted to mention it, and here seemed to be as good a place as any. :stuck_out_tongue:

@tuffe said: @t0neg0d Hi! I haven't been following the developments with the GUI recently. Are the tooltip changes you were talking about ready?

Btw I saw that you fixed the problem that I had before with private boolean initializedLoader; in Screen being static. But if it is not static, it is not needed at all, right? It will be false every time from the beginning, and it is only used in the constructor. So get rid of the code that uses it. This was maybe a little off-topic in this thread, but I just wanted to mention it, and here seemed to be as good a place as any. :stuck_out_tongue:

Ugh… I just woke up (rough night)… I have no clue atm! =) But once the brain is working, I’ll try and answer the second part.

Btw, the test app that includes a bunch of examples including both drag/drop & point/click inventory system can be downloaded here:

tonegodemitter - Browse Files at SourceForge.net?

Just remember to update the reference to the plugin in project properties.

@t0neg0d said: Ah... ToolTips just got an overhaul code-wise thanks to @sgold and there are about to get a visual facelift (and become customizable) thanks to @rockfire

Instead of trying to work around it’s current limitations, let me implement rockfire’s approach, which will allow you to design your own ToolTip window instead of trying to work with the extremely limited one I used as a default.

This is what I’m talking about btw. :wink:

@tuffe said: This is what I'm talking about btw. ;)

This update hasn’t happened yet.

  • Still trying to clean up the Layouts a bit.
  • There are some important changes happening with styles that help expand each controls customization without effecting the current styles in place.
  • Implementing texture tiling for atlas enabled ui’s

Then I should be able to get this on in place.

@t0neg0d Ok!

1 Like
@tuffe said: @t0neg0d I said "everything else". :p

This is my setup: Everything is a basic Element. I have “inventories”, each one being a container element that is invisible (setAsContainerOnly) and several Elements inside it, that are not invisible, and those are the inventory slots. Each of those can have another Element as a child, and that is the item in the slot. Each inventory is just added to the Screen.

And then there is the mouse slot, that is a single (setAsContainerOnly) slot that is added to the screen. That can have a child too, when something is being moved. But that child always shows up behind the other stuff, i.e. the inventories, if I don’t do anything else.

The thing is that if I call .move(0, 0, 20) on the mouse slot, the mouse image (which is a child of the slot) still shows up behind the other stuff (inventories). I have to call move on the child for it to work, and that seems a bit odd.

Remember this? I don’t know if you followed up on this. But anyway, now that I updated tonegodgui to the latest version, even calling move on the child element, the one that can actually be seen, does not work. It shows up behind other stuff. ;/ How should I make sure it does not show up behind other things? Just to be clear, I did not change my code, I only checked out the latest version of tonegodgui and now my mouse slot, the one that I use to drag things with the mouse, shows up behind my inventory. This is my code:

[java](.addChild mouse-slot
(doto (create-element screen (str "mouse item "
(ccfns/get-new-id))
[0 0] sizev “fireball.png”)
(.setIsGlobalModal true)
(.setIsModal true)
(.setIgnoreMouse true)
(.move 0 0 20)))[/java]

So basically, I just create an Element, and set .setIsGlobalModal, .setIsModal and .setIgnoreMouse all to true, and move it to (0, 0, 20) with .move.