change inventory system
This commit is contained in:
parent
9bd1ac3b45
commit
2d9ea3d654
15 changed files with 349 additions and 245 deletions
|
@ -188,6 +188,15 @@ public abstract class GuiContainer extends Gui
|
|||
|
||||
return list;
|
||||
}
|
||||
|
||||
public int getScale() {
|
||||
return this.container_scale;
|
||||
}
|
||||
|
||||
public ItemStack getHoverItem(Slot slot) {
|
||||
return this.gm.player != null && this.gm.player.getMouseItem() != null ? this.gm.player.getMouseItem() : (this.gm.itemCheat && this.cheatStack != null ? this.cheatStack : (Bind.CRAFT.isDown()
|
||||
&& slot.canCheatItem() && slot.getHasStack() ? this.gm.player.inventoryContainer.getSingleRecipe(slot.getStack()) : null));
|
||||
}
|
||||
|
||||
public Label label(String text, int x, int y) {
|
||||
x = x * this.container_scale + this.container_x;
|
||||
|
@ -292,7 +301,7 @@ public abstract class GuiContainer extends Gui
|
|||
if(this.inventorySlots != null) {
|
||||
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) {
|
||||
Slot slot = this.inventorySlots.inventorySlots.get(i1);
|
||||
if(slot.getTexture() == null || !slot.getTexture().isEmpty())
|
||||
if(slot.canDraw())
|
||||
this.slot(slot.xDisplayPosition - 1, slot.yDisplayPosition - 1, 18, 18, slot);
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +325,7 @@ public abstract class GuiContainer extends Gui
|
|||
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
|
||||
this.drawSlot(slot);
|
||||
|
||||
if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canBeHovered())
|
||||
if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canHover())
|
||||
{
|
||||
this.theSlot = slot;
|
||||
}
|
||||
|
|
|
@ -1,23 +1,34 @@
|
|||
package client.gui.element;
|
||||
|
||||
import client.Client;
|
||||
import client.gui.Gui;
|
||||
import client.gui.container.GuiContainer;
|
||||
import client.renderer.Drawing;
|
||||
import common.inventory.Slot;
|
||||
import common.item.ItemStack;
|
||||
|
||||
public class InventoryButton extends Element {
|
||||
private final boolean bordered;
|
||||
private final Slot slot;
|
||||
private final String texture;
|
||||
private final boolean background;
|
||||
private final int bgW;
|
||||
private final int bgH;
|
||||
|
||||
public InventoryButton(int x, int y, int w, int h, boolean bordered, Slot slot) {
|
||||
super(x, y, w, h, null);
|
||||
this.bordered = bordered;
|
||||
this.texture = slot == null || slot.getTexture() == null ? null : "textures/items/icon_" + slot.getTexture() + ".png";
|
||||
this.slot = this.texture == null ? null : slot;
|
||||
this.texture = slot == null || slot.getTexture() == null || slot.getTexture().isEmpty() ? null : "textures/items/icon_" + slot.getTexture() + ".png";
|
||||
this.background = slot == null || slot.getTexture() != null;
|
||||
this.slot = slot;
|
||||
int scale = this.bordered ? 2 : 1;
|
||||
this.bgW = slot == null ? w : slot.getBackgroundWidth() * 18 * scale;
|
||||
this.bgH = slot == null ? h : slot.getBackgroundHeight() * 18 * scale;
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
drawButton(this.gm, this.pos_x, this.pos_y, this.size_x, this.size_y, this.bordered);
|
||||
if(this.background)
|
||||
drawButton(this.gm, this.pos_x, this.pos_y, this.bgW, this.bgH, this.bordered);
|
||||
if(this.texture != null && !this.slot.getHasStack()) {
|
||||
int scale = this.bordered ? 2 : 1;
|
||||
Drawing.drawTexturedRect(this.gm, this.texture, 16 * scale, 16 * scale, this.pos_x + scale, this.pos_y + scale, 0, 0, this.size_x - scale * 2, this.size_y - scale * 2);
|
||||
|
@ -33,4 +44,20 @@ public class InventoryButton extends Element {
|
|||
else
|
||||
Drawing.drawGradient(x, y, w, h, gm.style.fill_top, gm.style.fill_btm, gm.style.brdr_top, gm.style.brdr_btm);
|
||||
}
|
||||
|
||||
public boolean canHover() {
|
||||
if(this.slot == null)
|
||||
return true;
|
||||
ItemStack hover = ((GuiContainer)this.gui).getHoverItem(this.slot);
|
||||
return hover == null ? this.slot.getHasStack() : this.slot.isItemValid(hover);
|
||||
}
|
||||
|
||||
public void drawHover() {
|
||||
int scale = this.bordered ? 2 : 1;
|
||||
Drawing.drawRect(this.pos_x + scale, this.pos_y + scale, 16 * scale, 16 * scale, Gui.HOVER_COLOR);
|
||||
}
|
||||
|
||||
public boolean canClick() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue