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

@t0neg0d Ok, I will tomorrow. I’m beyond tired right now.

@t0neg0d How do I make sure the mouse slot stays on top of everything else? The documentation says:

setZOrder(float zOrder)
Sets the Elements zOrder (I would suggest NOT using this method)

:stuck_out_tongue:

@t0neg0d said: Can you point specifically at where this is set so I can fix this?

I thought there was a way of setting the minDimensions already. Also, I thought these were only taken into account when resizing, so if you set a height of 0 via code… it should be a height of 0.

Anyways… just drop me a line number where you think the problem is happening and I’ll run a test here to see if I can repro the issue to get it resolved.

It seems Screen’s addElement calls resize on the Element it adds. And whether or not I can set minDimensions is not really the issue. If there is some reason why minDimensions needs to be some positive number, then so be it, but in that case I should not be able to set it to anything lower with setMinDimensions either. And minDimensions should be set to the lowest possible value in the constructor, probably [0, 0].

@tuffe said: It seems Screen's addElement calls resize on the Element it adds. And whether or not I can set minDimensions is not really the issue. If there is some reason why minDimensions needs to be some positive number, then so be it, but in that case I should not be able to set it to anything lower with setMinDimensions either. And minDimensions should be set to the lowest possible value in the constructor, probably [0, 0].

I think I know what the issue is. It has nothing to do with minDimensions, it is the nine-patch borders which are not scaled when you resize… it’s an unfortunate side effect of the scaling process using this type of mesh.

Is there a reason you are not hiding the element as apposed to setting the height to 0?

EDIT: To see this in action, create a window and set the minDimensions to negative numbers then resize it past the 0,0 mark and you’ll see what I’m talking about.

@t0neg0d I have hidden it with setUseAsContainerOnly (or whatever it’s called) but the problem is that when adding a child, the new childs position depends on the height of the parent. The only thing that works is setting the parent’s size the same as the size of the child, or the child’s position will not be where I want it. I can do that, so in that sense it’s not a big problem, but I just wanted to set the size of the invisible thing to 0 and be done with it. Also, it was unexpected, and probably not what people want to have happen.

Also, don’t forget this http://hub.jmonkeyengine.org/forum/topic/how-do-i-make-an-inventory-with-lots-of-slots/page/5/#post-268892 :wink:

@tuffe said: @t0neg0d I have hidden it with setUseAsContainerOnly (or whatever it's called) but the problem is that when adding a child, the new childs position depends on the height of the parent. The only thing that works is setting the parent's size the same as the size of the child, or the child's position will not be where I want it. I can do that, so in that sense it's not a big problem, but I just wanted to set the size of the invisible thing to 0 and be done with it. Also, it was unexpected, and probably not what people want to have happen.

Also, don’t forget this http://hub.jmonkeyengine.org/forum/topic/how-do-i-make-an-inventory-with-lots-of-slots/page/5/#post-268892 :wink:

You can set the size to 0, you just need to account for the flipped y axis… meaning that you would have to set y of the child element to negative the height of the child control to place it properly. Not really anything I can do about this as trying to keep track of y flipping it internal to the library is WAY more than I am willing to try and manage.

Tried it early on and it became nightmarish.

@tuffe said: Also, don't forget this http://hub.jmonkeyengine.org/forum/topic/how-do-i-make-an-inventory-with-lots-of-slots/page/5/#post-268892 ;)

I already answered this.

@t0neg0d said: I think I know what the issue is. It has nothing to do with minDimensions, it is the nine-patch borders which are *not* scaled when you resize... it's an unfortunate side effect of the scaling process using this type of mesh.

Is there a reason you are not hiding the element as apposed to setting the height to 0?

EDIT: To see this in action, create a window and set the minDimensions to negative numbers then resize it past the 0,0 mark and you’ll see what I’m talking about.

EDIT: More specifically, 0,0 is not an option, unless your resize borders are set to 0,0, which by default never happens.

@tuffe said: @t0neg0d How do I make sure the mouse slot stays on top of everything else? The documentation says:

setZOrder(float zOrder)
Sets the Elements zOrder (I would suggest NOT using this method)

:stuck_out_tongue:

Missed this post…

Try:

[java]
slot.setIsModal(true);
slot.setIsGlobalModal(true);
slot.move(0,0,20);
[/java]

This should do it.

@t0neg0d said: Missed this post...

Try:

[java]
slot.setIsModal(true);
slot.setIsGlobalModal(true);
slot.move(0,0,20);
[/java]

This should do it.

It works on the content, but not on the slot (container). If I do that on the container, the child (content) can still show up behind other things. Shouldn’t the child always be on top of its container?

@tuffe said: It works on the content, but not on the slot (container). If I do that on the container, the child (content) can still show up behind other things. Shouldn't the child always be on top of its container?

Actually, move uses addLocal to the local translation of the Node, all child nodes should have their global translation recalc’d due to there parent being modified.

Are you only calling move once? if not, this could potentially be the problem.

@t0neg0d Yes, only once.

@tuffe said: @t0neg0d Yes, only once.

Can I see how you are setting up the container and item? The way I was doing it was using a button and then adding an icon to show the item (which is basically an Element as a child to an Element and never had this happen. Maybe I can figure it out from seeing how you implemented it.

@t0neg0d

I think you will understand the below code, even if it’s not Java.

java
[0 0] sizev “fireball.png”)
(.setIsGlobalModal true)
(.setIsModal true)
(.move 0 0 20))

(doto (create-element screen “mouse slot” [0 0] [size size] nil)
.setAsContainerOnly
(.setIgnoreMouse true)
(.setIsGlobalModal true)
(.setIsModal true)
(.move 0 0 20))[/java]

So, I just call the methods after I have new’ed them. And then I add the child to the slot afterwards.

@tuffe said: @t0neg0d

I think you will understand the below code, even if it’s not Java.

java
[0 0] sizev “fireball.png”)
(.setIsGlobalModal true)
(.setIsModal true)
(.move 0 0 20))

(doto (create-element screen “mouse slot” [0 0] [size size] nil)
.setAsContainerOnly
(.setIgnoreMouse true)
(.setIsGlobalModal true)
(.setIsModal true)
(.move 0 0 20))[/java]

So, I just call the methods after I have new’ed them. And then I add the child to the slot afterwards.

Ah… think I see the problem. You should only need to worry about the modal & move calls on the parent container. When you add the item as a child of this, the position is relative to it’s parent.

@t0neg0d Yes should. But that didn’t work. This works. Probably only calling on the child would work too. But not only on parent.

@tuffe said: @t0neg0d Yes should. But that didn't work. This works. Probably only calling on the child would work too. But not only on parent.

You’ll definitely want the move call to be something like 20.1f or something for the item, otherwise it renders it based on whichever ends up in the GeometryList first.

@t0neg0d Ok. But in this case the parent is invisible. :stuck_out_tongue:

“Ah… think I see the problem. You should only need to worry about the modal & move calls on the parent container. When you add the item as a child of this, the position is relative to it’s parent.”

What was the problem that you saw?

@tuffe said: @t0neg0d Ok. But in this case the parent is invisible. :P

“Ah… think I see the problem. You should only need to worry about the modal & move calls on the parent container. When you add the item as a child of this, the position is relative to it’s parent.”

What was the problem that you saw?

Oh… I’m missing some info then. I thought you said that the item was showing up behind the container… which container is this? Um… and what type of control are you using for the items? DragElement might be resetting the z-order just based on the internal code.

@t0neg0d I said “everything else”. :stuck_out_tongue:

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.

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

This is my setup: Everythig 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.

Ok… I’ll give a shot setting this up today and see if I can repro the issue. What element are you using for the items?