improve container gui
This commit is contained in:
parent
448d54c441
commit
c8d4b8a48e
21 changed files with 226 additions and 296 deletions
|
@ -47,15 +47,6 @@ public abstract class Gui {
|
|||
}
|
||||
|
||||
public void onGuiClosed() {
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
}
|
||||
|
||||
public void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
}
|
||||
|
||||
public void mouseDragged(int mouseX, int mouseY) {
|
||||
}
|
||||
|
||||
public void drawPost() {
|
||||
|
@ -71,10 +62,6 @@ public abstract class Gui {
|
|||
}
|
||||
|
||||
public void renameItem() {
|
||||
}
|
||||
|
||||
public void drawBackground() {
|
||||
|
||||
}
|
||||
|
||||
public Element clicked(int x, int y) {
|
||||
|
@ -235,7 +222,6 @@ public abstract class Gui {
|
|||
|
||||
public void render() {
|
||||
this.drawMainBackground();
|
||||
this.drawBackground();
|
||||
if(this.gm.fbX != 0 && this.gm.fbY != 0)
|
||||
this.draw();
|
||||
GlState.bindTexture(0);
|
||||
|
|
|
@ -31,6 +31,7 @@ import common.entity.npc.Attribute;
|
|||
import common.init.ItemRegistry;
|
||||
import common.inventory.Container;
|
||||
import common.inventory.Slot;
|
||||
import common.inventory.SlotCommon;
|
||||
import common.item.CheatTab;
|
||||
import common.item.ItemStack;
|
||||
import common.packet.CPacketAction;
|
||||
|
@ -62,11 +63,10 @@ public abstract class GuiContainer extends Gui
|
|||
private static CheatTab selectedTab = CheatTab.ALL;
|
||||
|
||||
protected RenderItem itemRender;
|
||||
protected final int xSize;
|
||||
protected final int ySize;
|
||||
public Container inventorySlots;
|
||||
private Slot theSlot;
|
||||
protected final List<Overlay> drawnOverlays = Lists.<Overlay>newArrayList();
|
||||
private final InventoryButton[] invButtons;
|
||||
private boolean ignoreMouseUp;
|
||||
private long lastClickTime;
|
||||
private Slot lastClickSlot;
|
||||
|
@ -74,9 +74,6 @@ public abstract class GuiContainer extends Gui
|
|||
private boolean doubleClick;
|
||||
private ItemStack shiftClickedSlot;
|
||||
|
||||
protected int container_x;
|
||||
protected int container_y;
|
||||
|
||||
private int hover_x;
|
||||
private int hover_y;
|
||||
private String tooltip;
|
||||
|
@ -195,110 +192,178 @@ public abstract class GuiContainer extends Gui
|
|||
}
|
||||
|
||||
public Label label(String text, int x, int y) {
|
||||
return this.add(new FontLabel(x + this.container_x, y + this.container_y, 300, Font.LARGE, text, true));
|
||||
return this.add(new FontLabel(x, y, 300, Font.LARGE, text, true));
|
||||
}
|
||||
|
||||
public DisplayLabel display(String text, int x, int y, int w, int lines) {
|
||||
return this.add(new DisplayLabel(x + this.container_x, y + this.container_y, w, lines, Font.LARGE, text));
|
||||
return this.add(new DisplayLabel(x, y, w, lines, Font.LARGE, text));
|
||||
}
|
||||
|
||||
public Bar bar(int x, int y, int w, int h) {
|
||||
return this.add(new Bar(x + this.container_x, y + this.container_y, w, h, Font.LARGE));
|
||||
}
|
||||
|
||||
public void rect(int x, int y, int width, int height, int color) {
|
||||
Drawing.drawRect(this.container_x + x, this.container_y + y, width, height, 0xff000000 | color);
|
||||
}
|
||||
|
||||
public void grad(int x, int y, int width, int height, int top, int bottom, int topleft, int btmright) {
|
||||
Drawing.drawGradient(this.container_x + x, this.container_y + y, width, height, 0xff000000 | top, 0xff000000 | bottom, 0xff000000 | topleft, 0xff000000 | btmright);
|
||||
}
|
||||
|
||||
public InventoryButton slot(int x, int y, int w, int h, Slot slot) {
|
||||
return this.add(new InventoryButton(this.container_x + x, this.container_y + y, w, h, slot));
|
||||
return this.add(new Bar(x, y, w, h, Font.LARGE));
|
||||
}
|
||||
|
||||
public InventoryButton slot(int x, int y, int w, int h) {
|
||||
return this.slot(x, y, w, h, null);
|
||||
return this.add(new InventoryButton(x, y, w, h, null, 1, 1));
|
||||
}
|
||||
|
||||
public ActButton button(int x, int y, int w, int h, ButtonCallback callback, String text) {
|
||||
return this.add(new ActButton(this.container_x + x, this.container_y + y, w, h, callback, text));
|
||||
return this.add(new ActButton(x, y, w, h, callback, text));
|
||||
}
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
super.mouse(btn, x, y, ctrl, shift);
|
||||
this.mouseClicked(x - this.container_x, y - this.container_y, btn.ordinal()); //TODO: enum
|
||||
this.mouseClicked(x, y, btn.ordinal()); //TODO: enum
|
||||
}
|
||||
|
||||
public void mouserel(Button btn, int x, int y) {
|
||||
super.mouserel(btn, x, y);
|
||||
this.mouseReleased(x - this.container_x, y - this.container_y, btn.ordinal()); //TODO: enum
|
||||
}
|
||||
|
||||
public void drag(int x, int y) {
|
||||
super.drag(x, y);
|
||||
if(Button.MOUSE_LEFT.isDown() || Button.MOUSE_RIGHT.isDown() || Button.MOUSE_MIDDLE.isDown())
|
||||
this.mouseDragged(x - this.container_x, y - this.container_y);
|
||||
this.mouseReleased(x, y, btn.ordinal()); //TODO: enum
|
||||
}
|
||||
|
||||
public GuiContainer(Container container)
|
||||
{
|
||||
this.inventorySlots = container;
|
||||
this.ignoreMouseUp = true;
|
||||
this.xSize = (container.getInventoryOffsetX() - 2) * 2 + 36 * Container.INVENTORY_WIDTH;
|
||||
this.ySize = container.getInventoryOffsetY() + 52 + 36 * ((Equipment.INVENTORY_SLOTS + Container.INVENTORY_WIDTH - 1) / Container.INVENTORY_WIDTH);
|
||||
this.invButtons = new InventoryButton[container.inventorySlots.size()];
|
||||
}
|
||||
|
||||
public int getControlAreaWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
this.itemRender = this.gm.getRenderItem();
|
||||
this.tooltip = null;
|
||||
this.cheatStack = null;
|
||||
this.container_x = (width - this.xSize) / 2;
|
||||
this.container_y = (height - this.ySize) / 2;
|
||||
this.initGui();
|
||||
this.gm.player.openContainer = this.inventorySlots;
|
||||
|
||||
boolean invLeft = false;
|
||||
boolean invRight = false;
|
||||
int leftSlots = 0;
|
||||
int rightSlots = 0;
|
||||
for(int z = 0; z < this.inventorySlots.getPlayerInventoryOffset() - Equipment.ARMOR_SLOTS; z++) {
|
||||
Slot slot = this.inventorySlots.inventorySlots.get(z);
|
||||
if(slot.slotRight)
|
||||
++rightSlots;
|
||||
else
|
||||
++leftSlots;
|
||||
if(slot instanceof SlotCommon) {
|
||||
if(slot.slotRight)
|
||||
invRight = true;
|
||||
else
|
||||
invLeft = true;
|
||||
}
|
||||
}
|
||||
boolean center = leftSlots == 0 || rightSlots == 0;
|
||||
|
||||
int area = this.getControlAreaWidth();
|
||||
int side = this.gm.itemCheat ? 450 : 0;
|
||||
int gap = 2;
|
||||
int border = 2;
|
||||
int frame = 16;
|
||||
int header = 20;
|
||||
|
||||
int invWidth = (this.gm.fbX - frame - border - border - side - frame) / 32;
|
||||
int invHeight = ((Equipment.INVENTORY_SLOTS + invWidth - 1) / invWidth);
|
||||
int playerWidth = border + invWidth * 32 + border;
|
||||
int playerHeight = header + border + 32 + border + gap + border + invHeight * 32 + border;
|
||||
int playerX = frame;
|
||||
int playerY = this.gm.fbY - frame - playerHeight;
|
||||
int playerX2 = playerX + playerWidth;
|
||||
int playerY2 = playerY + playerHeight;
|
||||
|
||||
int slotsWidth = center ? (this.gm.fbX - frame - border - (invLeft ? border : 0) - area - side - frame) / (invLeft ? 32 : border + 32 + border + gap) : (this.gm.fbX - frame - border - (invLeft ? border : 0) - area - border - (invRight ? border : 0) - side - frame) / ((invLeft ? 32 : border + 32 + border + gap) + (invRight ? 32 : border + 32 + border + gap));
|
||||
|
||||
int leftSlotsHeight = ((leftSlots + slotsWidth - 1) / slotsWidth);
|
||||
int leftWidth = border + slotsWidth * (invLeft ? 32 : border + 32 + border) + (invLeft ? 0 : (slotsWidth - 1) * gap) + (invLeft ? border : 0);
|
||||
int leftHeight = header + border + leftSlotsHeight * (invLeft ? 32 : border + 32 + border) + (invLeft ? 0 : (leftSlotsHeight - 1) * gap) + (invLeft ? border : 0);
|
||||
int leftX = frame;
|
||||
int leftY = frame;
|
||||
int leftX2 = leftX + leftWidth;
|
||||
int leftY2 = leftY + leftHeight;
|
||||
|
||||
int rightSlotsHeight = ((rightSlots + slotsWidth - 1) / slotsWidth);
|
||||
int rightWidth = border + slotsWidth * (invRight ? 32 : border + 32 + border) + (invRight ? 0 : (slotsWidth - 1) * gap) + (invRight ? border : 0);
|
||||
int rightHeight = header + border + rightSlotsHeight * (invRight ? 32 : border + 32 + border) + (invRight ? 0 : (rightSlotsHeight - 1) * gap) + (invRight ? border : 0);
|
||||
int rightX = this.gm.fbX - frame - side - rightWidth;
|
||||
int rightY = frame;
|
||||
int rightX2 = rightX + rightWidth;
|
||||
int rightY2 = rightY + rightHeight;
|
||||
|
||||
int leftIndex = 0;
|
||||
int rightIndex = 0;
|
||||
|
||||
for(int z = 0; z < this.invButtons.length; z++) {
|
||||
Slot slot = this.inventorySlots.inventorySlots.get(z);
|
||||
int x;
|
||||
int y;
|
||||
int w = 1;
|
||||
int h = 1;
|
||||
if(slot.slotNumber >= this.inventorySlots.getPlayerInventoryOffset()) {
|
||||
int n = slot.slotNumber - this.inventorySlots.getPlayerInventoryOffset();
|
||||
x = playerX + border + (n % invWidth) * 32;
|
||||
y = playerY + header + border + 32 + border + gap + border + (n / invWidth) * 32;
|
||||
w = invWidth;
|
||||
h = invHeight;
|
||||
}
|
||||
else if(slot.slotNumber >= this.inventorySlots.getPlayerInventoryOffset() - Equipment.ARMOR_SLOTS) {
|
||||
int n = slot.slotNumber - (this.inventorySlots.getPlayerInventoryOffset() - Equipment.ARMOR_SLOTS);
|
||||
x = playerX + border + n * (32 + border + gap + border);
|
||||
y = playerY + header + border;
|
||||
}
|
||||
else if(slot.slotRight) {
|
||||
int n = rightIndex++;
|
||||
x = rightX + border + ((rightSlots < slotsWidth ? n + slotsWidth - rightSlots : n) % slotsWidth) * (32 + (invRight ? 0 : border + gap + border));
|
||||
y = rightY + header + border + (n / slotsWidth) * (32 + (invRight ? 0 : border + gap + border));
|
||||
if(invRight) {
|
||||
w = slotsWidth;
|
||||
h = rightSlotsHeight;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int n = leftIndex++;
|
||||
x = leftX + border + (n % slotsWidth) * (32 + (invLeft ? 0 : border + gap + border));
|
||||
y = leftY + header + border + (n / slotsWidth) * (32 + (invLeft ? 0 : border + gap + border));
|
||||
if(invLeft) {
|
||||
w = slotsWidth;
|
||||
h = leftSlotsHeight;
|
||||
}
|
||||
}
|
||||
this.invButtons[z] = this.add(new InventoryButton(x, y, 32, 32, slot, w, h));
|
||||
}
|
||||
|
||||
if(this.gm.itemCheat) {
|
||||
int x2 = Math.max(playerX2, rightX2);
|
||||
this.cheatX = x2 + 4;
|
||||
this.cheatY = 32;
|
||||
this.cheatWidth = Math.max((this.gm.fbX - x2 - 32) / 36, 1);
|
||||
this.cheatHeight = Math.max((this.gm.fbY - 40 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) - 92) / 36, 1);
|
||||
}
|
||||
this.addButtons();
|
||||
this.addElements();
|
||||
this.label("Inventar", this.inventorySlots.getInventoryOffsetX(), this.inventorySlots.getInventoryOffsetY() - 4);
|
||||
this.inventoryLabel = this.label("", this.inventorySlots.getInventoryOffsetX() + 36 * Container.INVENTORY_WIDTH - 180, this.inventorySlots.getInventoryOffsetY() - 4);
|
||||
this.label("Inventar", playerX, playerY + 18);
|
||||
this.inventoryLabel = this.label("", playerX2 - 180, playerY + 18);
|
||||
}
|
||||
|
||||
public void hover(String text, int x, int y) {
|
||||
this.tooltip = text;
|
||||
this.hover_x = x + this.container_x + 16;
|
||||
this.hover_y = y + this.container_y + 16;
|
||||
this.hover_x = x + 16;
|
||||
this.hover_y = y + 16;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Inventar";
|
||||
}
|
||||
|
||||
public void initGui()
|
||||
{
|
||||
this.gm.player.openContainer = this.inventorySlots;
|
||||
if(this.gm.itemCheat) {
|
||||
this.cheatX = this.container_x + this.xSize + 4;
|
||||
this.cheatY = 32;
|
||||
this.cheatWidth = Math.max((this.gm.fbX - this.container_x - this.xSize - 32) / 36, 1);
|
||||
this.cheatHeight = Math.max((this.gm.fbY - 40 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) - 92) / 36, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void addButtons() {
|
||||
if(this.inventorySlots != null) {
|
||||
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) {
|
||||
Slot slot = this.inventorySlots.inventorySlots.get(i1);
|
||||
if(slot.canDraw())
|
||||
this.slot(slot.xDisplayPosition - 2, slot.yDisplayPosition - 2, 36, 36, slot);
|
||||
}
|
||||
}
|
||||
if(this.gm.itemCheat) {
|
||||
this.cheatLabel = this.add(new FontLabel(this.cheatX, this.cheatY, this.cheatWidth * 36, Font.SMALL, "", true));
|
||||
// this.cheatDesc = this.add(new DisplayLabel(this.cheatX, this.cheatY + this.cheatHeight * 18 + 20 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) + 4 + 18, this.cheatWidth * 18, 4, Font.SMALL, "Vorsicht: Schummeln\nwird mit Keule bestraft!!\n(Halte Strg beim Klick\nfür vollen Stapel)"));
|
||||
this.cheatSearch = this.add(new Field(this.cheatX, this.cheatY + this.cheatHeight * 36 + 40 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) + 8, this.cheatWidth * 36 + 20, 0, 128, null, ""));
|
||||
this.cheatLast = "";
|
||||
for(CheatTab tab : CheatTab.values()) {
|
||||
this.add(new InventoryButton(this.cheatX + 36 * (tab.getIndex() % this.cheatWidth), this.cheatY + this.cheatHeight * 36 + 8 + 40 * (tab.getIndex() / this.cheatWidth), 36, 36, null));
|
||||
this.add(new InventoryButton(this.cheatX + 36 * (tab.getIndex() % this.cheatWidth), this.cheatY + this.cheatHeight * 36 + 8 + 40 * (tab.getIndex() / this.cheatWidth), 36, 36, null, 1, 1));
|
||||
}
|
||||
this.setCurrentTab(selectedTab);
|
||||
}
|
||||
|
@ -307,14 +372,14 @@ public abstract class GuiContainer extends Gui
|
|||
public abstract void addElements();
|
||||
|
||||
protected void drawSlots(int mouseX, int mouseY) {
|
||||
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1)
|
||||
for (int i1 = 0; i1 < this.invButtons.length; ++i1)
|
||||
{
|
||||
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
|
||||
InventoryButton slot = this.invButtons[i1];
|
||||
this.drawSlot(slot);
|
||||
|
||||
if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canHover())
|
||||
if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.getSlot().canHover())
|
||||
{
|
||||
this.theSlot = slot;
|
||||
this.theSlot = slot.getSlot();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -462,11 +527,13 @@ public abstract class GuiContainer extends Gui
|
|||
|
||||
private void drawItemStack(ItemStack stack, int x, int y, String altText)
|
||||
{
|
||||
GL15.glPushMatrix();
|
||||
GL15.glTranslatef(0.0F, 0.0F, 32.0F);
|
||||
this.itemRender.zLevel = 200.0F;
|
||||
this.itemRender.renderItemAndEffectIntoGUI(stack, this.container_x + x, this.container_y + y);
|
||||
this.itemRender.renderItemAndEffectIntoGUI(stack, x, y);
|
||||
this.drawnOverlays.add(new Overlay(stack, x, y, altText));
|
||||
this.itemRender.zLevel = 0.0F;
|
||||
GL15.glPopMatrix();
|
||||
}
|
||||
|
||||
protected void renderToolTip(ItemStack stack, int x, int y) {
|
||||
|
@ -501,19 +568,15 @@ public abstract class GuiContainer extends Gui
|
|||
}
|
||||
|
||||
public void drawPost() {
|
||||
GL15.glPushMatrix();
|
||||
// GL15.glTranslatef((float)((this.gm.fbX - this.xSize * SCALE) / 2), (float)((this.gm.fbY - this.ySize * SCALE) / 2), 0.0f);
|
||||
// GL15.glScalef(2.0f, 2.0f, 2.0f);
|
||||
this.drawScreen(this.gm.mouseX - this.container_x, this.gm.mouseY - this.container_y);
|
||||
GL15.glPopMatrix();
|
||||
this.drawScreen(this.gm.mouseX, this.gm.mouseY);
|
||||
ItemRenderer.disableStandardItemLighting();
|
||||
}
|
||||
|
||||
private void drawSlot(Slot slotIn)
|
||||
private void drawSlot(InventoryButton btn)
|
||||
{
|
||||
int i = slotIn.xDisplayPosition;
|
||||
int j = slotIn.yDisplayPosition;
|
||||
ItemStack itemstack = slotIn.getStack();
|
||||
int i = btn.getX();
|
||||
int j = btn.getY();
|
||||
ItemStack itemstack = btn.getSlot().getStack();
|
||||
boolean flag = false;
|
||||
ItemStack itemstack1 = this.gm.player.getMouseItem();
|
||||
String s = null;
|
||||
|
@ -521,7 +584,7 @@ public abstract class GuiContainer extends Gui
|
|||
this.itemRender.zLevel = 100.0F;
|
||||
|
||||
GlState.enableDepth();
|
||||
this.itemRender.renderItemAndEffectIntoGUI(itemstack, this.container_x + i, this.container_y + j);
|
||||
this.itemRender.renderItemAndEffectIntoGUI(itemstack, i, j);
|
||||
this.drawnOverlays.add(new Overlay(itemstack, i, j, s));
|
||||
|
||||
this.itemRender.zLevel = 0.0F;
|
||||
|
@ -529,20 +592,20 @@ public abstract class GuiContainer extends Gui
|
|||
|
||||
private Slot getSlotAtPosition(int x, int y)
|
||||
{
|
||||
for (int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i)
|
||||
for (int i = 0; i < this.invButtons.length; ++i)
|
||||
{
|
||||
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i);
|
||||
InventoryButton btn = this.invButtons[i];
|
||||
|
||||
if (this.isMouseOverSlot(slot, x, y))
|
||||
if (this.isMouseOverSlot(btn, x, y))
|
||||
{
|
||||
return slot;
|
||||
return btn.getSlot();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton)
|
||||
private void mouseClicked(int mouseX, int mouseY, int mouseButton)
|
||||
{
|
||||
if(this.gm == null)
|
||||
return;
|
||||
|
@ -580,24 +643,11 @@ public abstract class GuiContainer extends Gui
|
|||
|
||||
if (mouseButton == 0 || mouseButton == 1)
|
||||
{
|
||||
boolean flag1 = mouseX < 0 || mouseY < 0 || mouseX >= this.xSize || mouseY >= this.ySize;
|
||||
int l = -1;
|
||||
|
||||
if (slot != null)
|
||||
{
|
||||
l = slot.slotNumber;
|
||||
}
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
l = -999;
|
||||
}
|
||||
|
||||
if (l != -1)
|
||||
{
|
||||
if (this.gm.player.getMouseItem() == null)
|
||||
{
|
||||
boolean flag2 = l != -999 && this.gm.shift();
|
||||
boolean flag2 = this.gm.shift();
|
||||
int i1 = 0;
|
||||
|
||||
if (flag2)
|
||||
|
@ -605,12 +655,8 @@ public abstract class GuiContainer extends Gui
|
|||
this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
|
||||
i1 = 1;
|
||||
}
|
||||
else if (l == -999)
|
||||
{
|
||||
i1 = 4;
|
||||
}
|
||||
|
||||
this.handleMouseClick(slot, l, mouseButton, i1);
|
||||
this.handleMouseClick(slot, slot.slotNumber, mouseButton, i1);
|
||||
|
||||
this.ignoreMouseUp = true;
|
||||
}
|
||||
|
@ -626,27 +672,11 @@ public abstract class GuiContainer extends Gui
|
|||
this.lastClickButton = mouseButton;
|
||||
}
|
||||
|
||||
public void mouseDragged(int mouseX, int mouseY)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseReleased(int mouseX, int mouseY, int state)
|
||||
private void mouseReleased(int mouseX, int mouseY, int state)
|
||||
{
|
||||
if(this.gm == null || this.cheatStack != null)
|
||||
return;
|
||||
Slot slot = this.getSlotAtPosition(mouseX, mouseY);
|
||||
boolean flag = mouseX < 0 || mouseY < 0 || mouseX >= this.xSize || mouseY >= this.ySize;
|
||||
int k = -1;
|
||||
|
||||
if (slot != null)
|
||||
{
|
||||
k = slot.slotNumber;
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
k = -999;
|
||||
}
|
||||
|
||||
if (this.doubleClick && slot != null && state == 0 && this.inventorySlots.canMergeSlot((ItemStack)null, slot))
|
||||
{
|
||||
|
@ -665,7 +695,7 @@ public abstract class GuiContainer extends Gui
|
|||
}
|
||||
else
|
||||
{
|
||||
this.handleMouseClick(slot, k, state, 6);
|
||||
this.handleMouseClick(slot, slot.slotNumber, state, 6);
|
||||
}
|
||||
|
||||
this.doubleClick = false;
|
||||
|
@ -681,14 +711,14 @@ public abstract class GuiContainer extends Gui
|
|||
|
||||
if (this.gm.player.getMouseItem() != null)
|
||||
{
|
||||
boolean flag1 = k != -999 && this.gm.shift();
|
||||
boolean flag1 = this.gm.shift();
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
|
||||
}
|
||||
|
||||
this.handleMouseClick(slot, k, state, flag1 ? 1 : 0);
|
||||
this.handleMouseClick(slot, slot != null ? slot.slotNumber : -1, state, flag1 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -698,9 +728,9 @@ public abstract class GuiContainer extends Gui
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY)
|
||||
private boolean isMouseOverSlot(InventoryButton btn, int mouseX, int mouseY)
|
||||
{
|
||||
return this.isPointInRegion(slotIn.xDisplayPosition, slotIn.yDisplayPosition, 32, 32, mouseX, mouseY);
|
||||
return this.isPointInRegion(btn.getX() + 2, btn.getY() + 2, 32, 32, mouseX, mouseY);
|
||||
}
|
||||
|
||||
protected boolean isPointInRegion(int left, int top, int right, int bottom, int pointX, int pointY)
|
||||
|
@ -766,7 +796,7 @@ public abstract class GuiContainer extends Gui
|
|||
|
||||
public void renderItemOverlayIntoGUI(ItemStack stack, int xPosition, int yPosition, String text)
|
||||
{
|
||||
renderItemOverlay(stack, this.container_x + xPosition, this.container_y + yPosition, text, 0, 0);
|
||||
renderItemOverlay(stack, xPosition, yPosition, text, 0, 0);
|
||||
}
|
||||
|
||||
public static void renderItemOverlay(ItemStack stack, int xPosition, int yPosition, String text, int bar2, int bar2max)
|
||||
|
@ -811,8 +841,9 @@ public abstract class GuiContainer extends Gui
|
|||
Drawing.drawRect(x, y, width, height, 0xff000000 | (red << 16) | (green << 8) | blue);
|
||||
}
|
||||
|
||||
public void drawBackground() {
|
||||
Drawing.drawGradientBorder(this.container_x, this.container_y, this.xSize, this.ySize, Util.mulColor(this.gm.style.fill_top, 0.8f), Util.mulColor(this.gm.style.fill_btm, 0.8f), 0xff000000, Util.mulColor(this.gm.style.brdr_top, 0.8f), Util.mulColor(this.gm.style.brdr_btm, 0.8f));
|
||||
public void drawMainBackground() {
|
||||
super.drawMainBackground();
|
||||
Drawing.drawGradientBorder(0, 0, this.gm.fbX, this.gm.fbY, Util.mulColor(this.gm.style.fill_top, 0.8f), Util.mulColor(this.gm.style.fill_btm, 0.8f), 0xff000000, Util.mulColor(this.gm.style.brdr_top, 0.8f), Util.mulColor(this.gm.style.brdr_btm, 0.8f));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -17,4 +17,8 @@ public class GuiCrafting extends GuiContainer {
|
|||
public void addElements() {
|
||||
this.label(this.type.getDisplay(), 16, 32);
|
||||
}
|
||||
|
||||
public int getControlAreaWidth() {
|
||||
return 300;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,10 @@ public class GuiDevice extends GuiContainer {
|
|||
this.tileInv = tile;
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
public int getControlAreaWidth() {
|
||||
return 350;
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
|
|
@ -29,6 +29,10 @@ public class GuiEnchant extends GuiContainer implements ButtonCallback {
|
|||
super(new ContainerEnchantment(inv, world));
|
||||
this.enchantment = (ContainerEnchantment)this.inventorySlots;
|
||||
}
|
||||
|
||||
public int getControlAreaWidth() {
|
||||
return 250;
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
|
|
@ -12,6 +12,10 @@ public class GuiEntity extends GuiContainer {
|
|||
super(new ContainerEntityInventory(player, entityInv, entity));
|
||||
this.title = entity.getName();
|
||||
}
|
||||
|
||||
public int getControlAreaWidth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
public void addElements() {
|
||||
this.label(this.title, 16, 32);
|
||||
|
|
|
@ -27,6 +27,10 @@ public class GuiMerchant extends GuiContainer implements ButtonCallback {
|
|||
super(new ContainerMerchant(inv, null, world));
|
||||
this.title = entity.getName();
|
||||
}
|
||||
|
||||
public int getControlAreaWidth() {
|
||||
return 380;
|
||||
}
|
||||
|
||||
public void addButtons() {
|
||||
super.addButtons();
|
||||
|
|
|
@ -16,6 +16,10 @@ public class GuiRepair extends GuiContainer {
|
|||
this.playerInv = inv;
|
||||
this.anvil = (ContainerRepair)this.inventorySlots;
|
||||
}
|
||||
|
||||
public int getControlAreaWidth() {
|
||||
return 250;
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
|
|
@ -130,7 +130,7 @@ public abstract class GuiList<T extends ListEntry> extends Gui
|
|||
int mouseYIn = this.gm.mouseY;
|
||||
this.mouseX = mouseXIn;
|
||||
this.mouseY = mouseYIn;
|
||||
this.drawBackground();
|
||||
// this.drawBackground();
|
||||
this.bindAmountScrolled();
|
||||
|
||||
Drawing.drawScaled(this.gm, Gui.BACKGROUND, 0, this.top, this.gm.fbX, this.bottom - this.top, 0xff7f7f7f);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package client.gui.element;
|
||||
|
||||
import client.Client;
|
||||
import client.gui.Gui;
|
||||
import client.gui.container.GuiContainer;
|
||||
import client.renderer.Drawing;
|
||||
import common.inventory.Slot;
|
||||
|
@ -11,23 +10,34 @@ public class InventoryButton extends Element {
|
|||
private final Slot slot;
|
||||
private final String texture;
|
||||
private final boolean background;
|
||||
private final boolean hoverable;
|
||||
private final int bgX;
|
||||
private final int bgY;
|
||||
private final int bgW;
|
||||
private final int bgH;
|
||||
|
||||
public InventoryButton(int x, int y, int w, int h, Slot slot) {
|
||||
public InventoryButton(int x, int y, int w, int h, Slot slot, int slotsX, int slotsY) {
|
||||
super(x, y, w, h, null);
|
||||
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.background = slot == null || (slot.getTexture() != null && slot.canDraw());
|
||||
this.hoverable = slot == null || slot.canDraw();
|
||||
this.slot = slot;
|
||||
this.bgW = slot == null ? w : slot.getBackgroundWidth() * 36;
|
||||
this.bgH = slot == null ? h : slot.getBackgroundHeight() * 36;
|
||||
this.bgX = slot == null ? 0 : -2;
|
||||
this.bgY = slot == null ? 0 : -2;
|
||||
this.bgW = slot == null ? w : 2 + slotsX * 32 + 2;
|
||||
this.bgH = slot == null ? h : 2 + slotsY * 32 + 2;
|
||||
}
|
||||
|
||||
public Slot getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
if(this.background)
|
||||
drawButton(this.gm, this.pos_x, this.pos_y, this.bgW, this.bgH);
|
||||
if(this.texture != null && !this.slot.getHasStack())
|
||||
Drawing.drawTexturedRect(this.gm, this.texture, 32, 32, this.pos_x + 2, this.pos_y + 2, 0, 0, this.size_x - 4, this.size_y - 4);
|
||||
if(this.background) {
|
||||
drawButton(this.gm, this.pos_x + this.bgX, this.pos_y + this.bgY, this.bgW, this.bgH);
|
||||
if(this.texture != null && !this.slot.getHasStack())
|
||||
Drawing.drawTexturedRect(this.gm, this.texture, 32, 32, this.pos_x, this.pos_y, 0, 0, this.size_x, this.size_y);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawForeground(int x1, int y1, int x2, int y2) {
|
||||
|
@ -38,14 +48,13 @@ public class InventoryButton extends Element {
|
|||
}
|
||||
|
||||
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() {
|
||||
Drawing.drawRect(this.pos_x + 2, this.pos_y + 2, 32, 32, Gui.HOVER_COLOR);
|
||||
if(this.hoverable) {
|
||||
if(this.slot == null)
|
||||
return true;
|
||||
ItemStack hover = ((GuiContainer)this.gui).getHoverItem(this.slot);
|
||||
return hover == null ? this.slot.getHasStack() : this.slot.isItemValid(hover);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canClick() {
|
||||
|
|
|
@ -1124,23 +1124,8 @@ public class ClientPlayer implements IClientPlayer
|
|||
}
|
||||
else
|
||||
{
|
||||
// boolean flag = false;
|
||||
//
|
||||
// if (this.gameController.openGui instanceof GuiCheat)
|
||||
// {
|
||||
//// GuiCheat guicontainercreative = (GuiCheat)this.gameController.openGui;
|
||||
// flag = true; // guicontainercreative.getSelectedTabIndex() != CheatTab.tabInventory.getIndex();
|
||||
// }
|
||||
|
||||
if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= Equipment.ARMOR_SLOTS && packetIn.getSlot() < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)
|
||||
if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= 0 && packetIn.getSlot() < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)
|
||||
{
|
||||
ItemStack itemstack = entityplayer.inventoryContainer.getSlot(packetIn.getSlot()).getStack();
|
||||
|
||||
// if (packetIn.getStack() != null && (itemstack == null || itemstack.stackSize < packetIn.getStack().stackSize))
|
||||
// {
|
||||
// packetIn.getStack().animationsToGo = 5;
|
||||
// }
|
||||
|
||||
entityplayer.inventoryContainer.putStackInSlot(packetIn.getSlot(), packetIn.getStack());
|
||||
}
|
||||
else if (packetIn.getWindowId() == entityplayer.openContainer.windowId) // && (packetIn.getWindowId() != 0 || !flag))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue