mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-26 15:03:01 +00:00
CraftingStation side chest now work with any IInventory with a configurable blacklist. (#35)
* CraftingStation side chest now work with any IInventory with a configurable blacklist. * Check ISidedInventory and accessible slots. Still needs some work for shift clicking. * Backport shift click behavior and some helper functions * Fix NEI overlap, and tinker's tool station integration * Fix NEI shift clicking by redoing math
This commit is contained in:
1 parent
1c305ff293
commit
1c46541223
14 files changed
+1455
-499
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package tconstruct.tools.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
public class ChestSlot extends Slot {
|
||||
/*
|
||||
* A Slot, used for adjacent Chest Inventories, that can be disabled.
|
||||
*/
|
||||
public boolean enabled = true;
|
||||
|
||||
public ChestSlot(IInventory inventory, int index, int xPosition, int yPosition) {
|
||||
super(inventory, index, xPosition, yPosition);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public boolean func_111238_b/*isEnabled*/() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import cpw.mods.fml.common.Optional;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -20,48 +22,72 @@ import tconstruct.library.tools.ToolMaterial;
|
||||
import tconstruct.library.util.HarvestLevels;
|
||||
import tconstruct.tools.logic.CraftingStationLogic;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems")
|
||||
public class CraftingStationGui extends GuiContainer implements INEIGuiHandler
|
||||
{
|
||||
public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
|
||||
/*
|
||||
* Slider/slots related. Taken & adapted from Tinkers Construct 1.12 under the MIT License
|
||||
*/
|
||||
private static final ResourceLocation gui_inventory = new ResourceLocation("tinker", "textures/gui/generic.png");
|
||||
|
||||
public static final GuiElementScalable slotElement = new GuiElementScalable(7, 7, 18, 18, 64, 64);
|
||||
public static final GuiElementScalable slotEmptyElement = new GuiElementScalable(7 + 18, 7, 18, 18, 64, 64);
|
||||
|
||||
private static final GuiElementDuex sliderNormal = new GuiElementDuex(7, 25, 10, 15, 64, 64);
|
||||
private static final GuiElementDuex sliderLow = new GuiElementDuex(17, 25, 10, 15, 64, 64);
|
||||
private static final GuiElementDuex sliderHigh = new GuiElementDuex(27, 25, 10, 15, 64, 64);
|
||||
private static final GuiElementDuex sliderTop = new GuiElementDuex(43, 7, 12, 1, 64, 64);
|
||||
private static final GuiElementDuex sliderBottom = new GuiElementDuex(43, 38, 12, 1, 64, 64);
|
||||
private static final GuiElementScalable sliderBackground = new GuiElementScalable(43, 8, 12, 30, 64, 64);
|
||||
private static final GuiElementScalable textBackground = new GuiElementScalable(7 + 18, 7, 18, 10, 64, 64);
|
||||
|
||||
private final GuiSliderWidget slider = new GuiSliderWidget(sliderNormal, sliderHigh, sliderLow, sliderTop, sliderBottom, sliderBackground);
|
||||
private final GuiBorderWidget border = new GuiBorderWidget();
|
||||
|
||||
private int firstSlotId;
|
||||
private int lastSlotId;
|
||||
private int chestSlotCount;
|
||||
|
||||
/* end slider/slots */
|
||||
|
||||
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/tinkertable.png");
|
||||
private static final ResourceLocation description = new ResourceLocation("tinker", "textures/gui/description.png");
|
||||
private static final ResourceLocation icons = new ResourceLocation("tinker", "textures/gui/icons.png");
|
||||
|
||||
public boolean active;
|
||||
|
||||
// Panel positions
|
||||
public String toolName;
|
||||
public GuiTextField text;
|
||||
public String title, body = "";
|
||||
CraftingStationLogic logic;
|
||||
|
||||
public static final int CHEST_WIDTH = 116;
|
||||
|
||||
// Panel positions
|
||||
|
||||
private int craftingLeft = 0;
|
||||
private int craftingTop = 0;
|
||||
private int craftingTextLeft = 0;
|
||||
|
||||
private int descLeft = 0;
|
||||
private int descTop = 0;
|
||||
private int descTextLeft = 0;
|
||||
|
||||
|
||||
private int chestLeft = 0;
|
||||
private int chestTop = 0;
|
||||
|
||||
public CraftingStationGui(InventoryPlayer inventory, CraftingStationLogic logic, World world, int x, int y, int z)
|
||||
{
|
||||
private int chestWidth = 0;
|
||||
private int chestHeight = 0;
|
||||
|
||||
public CraftingStationGui(InventoryPlayer inventory, CraftingStationLogic logic, World world, int x, int y, int z) {
|
||||
super(logic.getGuiContainer(inventory, world, x, y, z));
|
||||
this.logic = logic;
|
||||
// text = new GuiTextField(this.fontRendererObj, this.xSize / 2 - 5, 8,
|
||||
// 30, 12);
|
||||
// this.text.setText("");
|
||||
|
||||
title = "\u00A7n" + StatCollector.translateToLocal("gui.toolforge1");
|
||||
body = StatCollector.translateToLocal("gui.toolforge2");
|
||||
toolName = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui ()
|
||||
{
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
this.xSize = 176;
|
||||
@@ -73,20 +99,15 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler
|
||||
this.craftingLeft = this.guiLeft;
|
||||
this.craftingTop = this.guiTop;
|
||||
|
||||
if (logic.tinkerTable)
|
||||
{
|
||||
if (logic.tinkerTable) {
|
||||
this.descLeft = this.guiLeft + 176;
|
||||
this.descTop = this.craftingTop;
|
||||
}
|
||||
|
||||
if (logic.chest != null)
|
||||
{
|
||||
this.xSize += CHEST_WIDTH;
|
||||
this.guiLeft -= CHEST_WIDTH;
|
||||
this.chestLeft = this.guiLeft;
|
||||
this.chestTop = this.craftingTop;
|
||||
if (logic.doubleChest != null)
|
||||
this.ySize = 187;
|
||||
if (logic.chest != null) {
|
||||
updateChest();
|
||||
} else {
|
||||
slider.hide();
|
||||
}
|
||||
|
||||
this.craftingTextLeft = this.craftingLeft - this.guiLeft;
|
||||
@@ -94,14 +115,11 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer (int par1, int par2)
|
||||
{
|
||||
if (logic.chest != null)
|
||||
{
|
||||
if(logic.chest.get() instanceof TileEntity) {
|
||||
TileEntity te = (TileEntity)logic.chest.get();
|
||||
if(te.getWorldObj().getTileEntity(te.xCoord, te.yCoord, te.zCoord) == null && te.getWorldObj().isRemote)
|
||||
{
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
||||
if (logic.chest != null) {
|
||||
if (logic.chest.get() instanceof TileEntity) {
|
||||
TileEntity te = (TileEntity) logic.chest.get();
|
||||
if (te == null || te.getWorldObj().getTileEntity(te.xCoord, te.yCoord, te.zCoord) == null && te.getWorldObj().isRemote) {
|
||||
mc.thePlayer.closeScreen();
|
||||
return;
|
||||
}
|
||||
@@ -112,46 +130,43 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler
|
||||
this.fontRendererObj.drawString(StatCollector.translateToLocal(logic.tinkerTable ? "crafters.TinkerTable" : logic.getInvName()), craftingTextLeft + 8, 6, 0x202020);
|
||||
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), craftingTextLeft + 8, 72, 0x202020);
|
||||
|
||||
// this.fontRendererObj.drawString(toolName + "_", this.xSize / 2 - 18,
|
||||
// 8, 0xffffff);
|
||||
|
||||
if (logic.tinkerTable)
|
||||
{
|
||||
if (logic.tinkerTable) {
|
||||
if (logic.isStackInSlot(0)) // output slot = modified item
|
||||
drawToolStats(logic.getStackInSlot(0));
|
||||
else if (logic.isStackInSlot(5)) // center slot if no output item
|
||||
{
|
||||
else if (logic.isStackInSlot(5)) { // center slot if no output item
|
||||
// other slots empty?
|
||||
if(!logic.isStackInSlot(1) && !logic.isStackInSlot(2) && !logic.isStackInSlot(3) && !logic.isStackInSlot(4)
|
||||
&& !logic.isStackInSlot(6) && !logic.isStackInSlot(7) && !logic.isStackInSlot(8) && !logic.isStackInSlot(9))
|
||||
if (!logic.isStackInSlot(1) && !logic.isStackInSlot(2) && !logic.isStackInSlot(3) && !logic.isStackInSlot(4)
|
||||
&& !logic.isStackInSlot(6) && !logic.isStackInSlot(7) && !logic.isStackInSlot(8) && !logic.isStackInSlot(9))
|
||||
drawToolStats(logic.getStackInSlot(5));
|
||||
else
|
||||
drawToolInformation();
|
||||
}
|
||||
else
|
||||
} else
|
||||
drawToolInformation();
|
||||
}
|
||||
}
|
||||
|
||||
void drawToolStats (ItemStack stack)
|
||||
{
|
||||
if(stack.getItem() instanceof IModifyable)
|
||||
void drawToolStats(ItemStack stack) {
|
||||
if (stack.getItem() instanceof IModifyable)
|
||||
ToolStationGuiHelper.drawToolStats(stack, descTextLeft + 10, 0);
|
||||
|
||||
|
||||
int matID = PatternBuilder.instance.getPartID(stack);
|
||||
|
||||
if (matID != Short.MAX_VALUE && matID > 0)
|
||||
{
|
||||
if (matID != Short.MAX_VALUE && matID > 0) {
|
||||
ToolMaterial material = TConstructRegistry.getMaterial(matID);
|
||||
|
||||
if(material != null)
|
||||
if (material != null)
|
||||
drawMaterialStats(material);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawMaterialStats(ToolMaterial materialEnum)
|
||||
{
|
||||
|
||||
void drawToolInformation() {
|
||||
int offsetX = descTextLeft + 63;
|
||||
|
||||
this.drawCenteredString(fontRendererObj, title, offsetX, 8, 0xffffff);
|
||||
fontRendererObj.drawSplitString(body, offsetX - 56, 24, 115, 0xffffff);
|
||||
}
|
||||
|
||||
protected void drawMaterialStats(ToolMaterial materialEnum) {
|
||||
final int baseX = descTextLeft + 8;
|
||||
final int baseY = 8;
|
||||
|
||||
@@ -172,56 +187,58 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler
|
||||
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2f + heart, baseX, baseY + 60, 0xffffff);
|
||||
}
|
||||
|
||||
void drawToolInformation ()
|
||||
{
|
||||
int offsetX = descTextLeft + 63;
|
||||
|
||||
this.drawCenteredString(fontRendererObj, title, offsetX, 8, 0xffffff);
|
||||
fontRendererObj.drawSplitString(body, offsetX - 56, 24, 115, 0xffffff);
|
||||
}
|
||||
|
||||
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/tinkertable.png");
|
||||
private static final ResourceLocation description = new ResourceLocation("tinker", "textures/gui/description.png");
|
||||
private static final ResourceLocation icons = new ResourceLocation("tinker", "textures/gui/icons.png");
|
||||
private static final ResourceLocation chest = new ResourceLocation("tinker", "textures/gui/chestside.png");
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
|
||||
{
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
|
||||
// Draw the background
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(background);
|
||||
this.drawTexturedModalRect(this.craftingLeft, this.craftingTop, 0, 0, 176, 166);
|
||||
|
||||
if (active)
|
||||
{
|
||||
if (active) {
|
||||
this.drawTexturedModalRect(this.craftingLeft + 62, this.craftingTop, 0, 166, 112, 22);
|
||||
}
|
||||
|
||||
this.mc.getTextureManager().bindTexture(icons);
|
||||
// Draw the slots
|
||||
|
||||
// Draw the slots
|
||||
if (logic.tinkerTable && !logic.isStackInSlot(5))
|
||||
this.drawTexturedModalRect(this.craftingLeft + 47, this.craftingTop + 33, 0, 233, 18, 18);
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(icons);
|
||||
|
||||
// Draw chest side
|
||||
if (logic.chest != null)
|
||||
{
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(chest);
|
||||
|
||||
this.mc.getTextureManager().bindTexture(gui_inventory);
|
||||
if(hasChest()) {
|
||||
chestLeft += border.w;
|
||||
chestTop += border.h;
|
||||
|
||||
if (logic.doubleChest == null)
|
||||
this.drawTexturedModalRect(this.chestLeft, this.chestTop, 0, 0, 122, 114);
|
||||
else
|
||||
this.drawTexturedModalRect(this.chestLeft, this.chestTop, 125, 0, 122, 187);
|
||||
border.draw();
|
||||
|
||||
int x = chestLeft;
|
||||
int y = chestTop;
|
||||
final int midW = chestWidth - border.w * 2;
|
||||
|
||||
if (shouldDrawName()) {
|
||||
textBackground.drawScaledX(chestLeft, chestTop, midW);
|
||||
y += textBackground.h;
|
||||
}
|
||||
|
||||
drawChestSlots(x, y);
|
||||
|
||||
// slider
|
||||
if (slider.isEnabled()) {
|
||||
slider.update(mouseX, mouseY, !isMouseOverFullSlot(mouseX, mouseY) && isMouseInChest(mouseX, mouseY));
|
||||
slider.draw();
|
||||
|
||||
updateChestSlots();
|
||||
}
|
||||
|
||||
chestLeft -= border.w;
|
||||
chestTop -= border.h;
|
||||
}
|
||||
|
||||
// Draw description
|
||||
if (logic.tinkerTable)
|
||||
{
|
||||
if (logic.tinkerTable) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(description);
|
||||
this.drawTexturedModalRect(this.descLeft, this.descTop, 0, 0, 126, 172);
|
||||
@@ -230,19 +247,10 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisiblityData modifyVisiblity (GuiContainer gui, VisiblityData currentVisibility)
|
||||
{
|
||||
if (width - xSize < 107)
|
||||
{
|
||||
currentVisibility.showWidgets = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentVisibility.showWidgets = true;
|
||||
}
|
||||
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) {
|
||||
currentVisibility.showWidgets = width - xSize >= 107;
|
||||
|
||||
if (guiLeft < 58)
|
||||
{
|
||||
if (guiLeft < 58) {
|
||||
currentVisibility.showStateButtons = false;
|
||||
}
|
||||
|
||||
@@ -250,37 +258,209 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Integer> getItemSpawnSlots (GuiContainer gui, ItemStack item)
|
||||
{
|
||||
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaggedInventoryArea> getInventoryAreas (GuiContainer gui)
|
||||
{
|
||||
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleDragNDrop (GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button)
|
||||
{
|
||||
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hideItemPanelSlot (GuiContainer gui, int x, int y, int w, int h) {
|
||||
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
|
||||
final int cw = (logic.chest != null ? chestWidth : 0);
|
||||
if(logic.chest != null) {
|
||||
final Rectangle blah = new Rectangle(x, y, w, h);
|
||||
final Rectangle chestRectangle = new Rectangle(
|
||||
chestLeft, chestTop, chestWidth, chestHeight + (shouldDrawName() ? textBackground.y : 0) + (border.h * 2)
|
||||
);
|
||||
|
||||
if(chestRectangle.intersects(blah))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (y + h - 4 < guiTop || y + 4 > guiTop + ySize)
|
||||
return false;
|
||||
|
||||
if (x - w - 4 < guiLeft - (logic.chest != null ? 40 : 0) || x + 4 > guiLeft + xSize + (logic.tinkerTable ? 126 : 0))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
return x - w - 4 >= guiLeft + cw && x + 4 <= guiLeft + xSize + cw + (logic.tinkerTable ? 126 : 0);
|
||||
}
|
||||
|
||||
public boolean hasChest()
|
||||
{
|
||||
|
||||
public boolean hasChest() {
|
||||
return logic.chest != null;
|
||||
}
|
||||
|
||||
public boolean isMouseInChest(int mouseX, int mouseY) {
|
||||
final int xMod = (slider.isEnabled() ? slider.width : 0) + border.w;
|
||||
final int yMod = (shouldDrawName() ? textBackground.y : 0) + (border.h * 2);
|
||||
|
||||
return mouseX >= (this.chestLeft - xMod) && mouseX < (chestLeft + chestWidth + xMod) &&
|
||||
mouseY >= (this.chestTop - yMod) && mouseY < (chestTop + chestHeight + yMod);
|
||||
}
|
||||
|
||||
public boolean isMouseOverFullSlot(int mouseX, int mouseY) {
|
||||
for(final Object slot : inventorySlots.inventorySlots) {
|
||||
if(isMouseOverSlot((Slot)slot, mouseX, mouseY) && ((Slot)slot).getHasStack()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean shouldDrawName() {
|
||||
return this.logic.chest != null && this.logic.chest.get().getInventoryName() != null && !this.logic.chest.get().getInventoryName().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_146977_a/*drawSlot*/(Slot slot) {
|
||||
if(!slot.func_111238_b/*isEnabled*/()) return;
|
||||
|
||||
super.func_146977_a(slot);
|
||||
}
|
||||
|
||||
public boolean shouldDrawSlot(Slot slot) {
|
||||
if(!(slot instanceof ChestSlot)) return true;
|
||||
|
||||
if(slot.getSlotIndex() >= chestSlotCount) return false;
|
||||
|
||||
// all visible
|
||||
if(!slider.isEnabled()) return true;
|
||||
|
||||
return firstSlotId <= slot.getSlotIndex() && lastSlotId > slot.getSlotIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY) {
|
||||
return super.isMouseOverSlot(slotIn, mouseX, mouseY) && shouldDrawSlot(slotIn);
|
||||
}
|
||||
|
||||
private int getDisplayedRows() {
|
||||
return chestHeight / slotElement.h;
|
||||
}
|
||||
|
||||
private int calcCappedYSize(int max) {
|
||||
int h = slotElement.h * logic.invRows;
|
||||
|
||||
// not higher than the max
|
||||
while(h > max) {
|
||||
h -= slotElement.h;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
public int getChestWidth() {
|
||||
return chestWidth;
|
||||
}
|
||||
|
||||
// updatePosition
|
||||
public void updateChest() {
|
||||
chestHeight = calcCappedYSize(CraftingStationGui.slotElement.h * 10);
|
||||
chestSlotCount = logic.slotCount;
|
||||
|
||||
// slider needed?
|
||||
if(getDisplayedRows() < logic.invRows) {
|
||||
slider.enable();
|
||||
}
|
||||
else {
|
||||
slider.disable();
|
||||
}
|
||||
|
||||
chestWidth = logic.invColumns * CraftingStationGui.slotElement.w + 2 * border.w + (slider.isEnabled() ? slider.width : 0);
|
||||
|
||||
chestLeft = guiLeft - chestWidth;
|
||||
chestTop = guiTop;
|
||||
|
||||
// Leaving out the xsize increase by chestSize and adjusting where it's used, because otherwise it shifts both the bookmarks and item panel
|
||||
// way too far out.
|
||||
//xSize += guiLeft - chestLeft;
|
||||
guiLeft = chestLeft;
|
||||
|
||||
if (logic.doubleChest != null)
|
||||
this.ySize = 187;
|
||||
|
||||
border.setPosition(chestLeft, chestTop);
|
||||
border.setSize(chestWidth, chestHeight + (shouldDrawName() ? textBackground.h : 0) + 2 * border.h);
|
||||
|
||||
slider.show();
|
||||
slider.setPosition(chestLeft + logic.invColumns * slotElement.w + border.w, chestTop + (shouldDrawName() ? textBackground.h : 0) + border.h);
|
||||
slider.setSize(chestHeight);
|
||||
slider.setSliderParameters(0, logic.invRows - getDisplayedRows(), 1);
|
||||
|
||||
updateChestSlots();
|
||||
}
|
||||
|
||||
// updates slot visibility
|
||||
protected void updateChestSlots() {
|
||||
if(!hasChest()) return;
|
||||
|
||||
final IInventory secondInventory = logic.getSecondInventory();
|
||||
|
||||
int xOffset = border.w;
|
||||
int yOffset = border.h;
|
||||
|
||||
if(shouldDrawName()) {
|
||||
yOffset += textBackground.h;
|
||||
}
|
||||
|
||||
firstSlotId = slider.getValue() * logic.invColumns;
|
||||
lastSlotId = Math.min(chestSlotCount, firstSlotId + getDisplayedRows() * logic.invColumns);
|
||||
|
||||
for(Object o : inventorySlots.inventorySlots) {
|
||||
if(!(o instanceof ChestSlot)) continue;
|
||||
|
||||
final ChestSlot slot = (ChestSlot)o;
|
||||
|
||||
if(shouldDrawSlot(slot)) {
|
||||
slot.enable();
|
||||
// calc position of the slot
|
||||
final int offset = slot.getSlotIndex() + (slot.inventory == secondInventory ? 27 : 0) - firstSlotId;
|
||||
final int x = (offset % logic.invColumns) * CraftingStationGui.slotElement.w;
|
||||
final int y = (offset / logic.invColumns) * CraftingStationGui.slotElement.h;
|
||||
|
||||
slot.xDisplayPosition = x + xOffset + 1 /*- this.chestWidth*/;
|
||||
slot.yDisplayPosition = y + yOffset + 1;
|
||||
}
|
||||
else {
|
||||
slot.disable();
|
||||
slot.xDisplayPosition = 0;
|
||||
slot.yDisplayPosition = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// drawSlots
|
||||
protected void drawChestSlots(int xPos, int yPos) {
|
||||
if(!hasChest()) return;
|
||||
|
||||
int width = logic.invColumns * slotElement.w;
|
||||
int height = chestHeight - border.h * 2;
|
||||
|
||||
int fullRows = (lastSlotId - firstSlotId) / logic.invColumns;
|
||||
int slotsLeft = (lastSlotId - firstSlotId) % logic.invColumns;
|
||||
|
||||
int y; // We use it after the loop
|
||||
for(y = 0; y < fullRows * slotElement.h && y < height; y += slotElement.h) {
|
||||
slotElement.drawScaledX(xPos, yPos + y, width);
|
||||
}
|
||||
|
||||
// draw partial row and unused slots
|
||||
if(slotsLeft > 0) {
|
||||
slotElement.drawScaledX(xPos, yPos + y, slotsLeft * slotElement.w);
|
||||
// empty slots that don't exist
|
||||
slotEmptyElement.drawScaledX(xPos + slotsLeft * slotElement.w, yPos + y, width - slotsLeft * slotElement.w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Hide the deprecated stuff at the bottom
|
||||
*/
|
||||
@Deprecated
|
||||
public static final int CHEST_WIDTH = 116;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package tconstruct.tools.gui;
|
||||
|
||||
/*
|
||||
* Taken from Tinker's Construct 1.12 under the MIT License
|
||||
*
|
||||
* The MIT License (MIT) Copyright (c) 2013-2014 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6, pillbox, alexbegt)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
public class GuiBorderWidget {
|
||||
// all elements based on generic gui
|
||||
public GuiElementDuex cornerTopLeft = new GuiElementDuex(0, 0, 7, 7, 64, 64);
|
||||
public GuiElementDuex cornerTopRight = new GuiElementDuex(64 - 7, 0, 7, 7, 64, 64);
|
||||
public GuiElementDuex cornerBottomLeft = new GuiElementDuex(0, 64 - 7, 7, 7, 64, 64);
|
||||
public GuiElementDuex cornerBottomRight = new GuiElementDuex(64 - 7, 64 - 7, 7, 7, 64, 64);
|
||||
|
||||
public GuiElementScalable borderTop = new GuiElementScalable(7, 0, 64 - 7 - 7, 7, 64, 64);
|
||||
public GuiElementScalable borderBottom = new GuiElementScalable(7, 64 - 7, 64 - 7 - 7, 7, 64, 64);
|
||||
public GuiElementScalable borderLeft = new GuiElementScalable(0, 7, 7, 64 - 7 - 7, 64, 64);
|
||||
public GuiElementScalable borderRight = new GuiElementScalable(64 - 7, 7, 7, 64 - 7 - 7, 64, 64);
|
||||
|
||||
public int xPos;
|
||||
public int yPos;
|
||||
public int height;
|
||||
public int width;
|
||||
public int w = borderLeft.w;
|
||||
public int h = borderTop.h;
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
this.xPos = x;
|
||||
this.yPos = y;
|
||||
}
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/** Sets the size so that the given point is the upper left corner of the inside */
|
||||
public void setPosInner(int x, int y) {
|
||||
setPosition(x - cornerTopLeft.w, y - cornerTopLeft.h);
|
||||
}
|
||||
|
||||
/** Sets the size so that it surrounds the given area */
|
||||
public void sedSizeInner(int width, int height) {
|
||||
setSize(width + borderLeft.w + borderRight.w, height + borderTop.h + borderBottom.h);
|
||||
}
|
||||
|
||||
public int getWidthWithBorder(int width) {
|
||||
return width + borderRight.w + borderLeft.w;
|
||||
}
|
||||
|
||||
public int getHeightWithBorder(int height) {
|
||||
return height + borderTop.h + borderBottom.h;
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
int x = xPos;
|
||||
int y = yPos;
|
||||
int midW = width - borderLeft.w - borderRight.w;
|
||||
int midH = height - borderTop.h - borderBottom.h;
|
||||
|
||||
// top row
|
||||
x += cornerTopLeft.draw(x, y);
|
||||
x += borderTop.drawScaledX(x, y, midW);
|
||||
cornerTopRight.draw(x, y);
|
||||
|
||||
// center row
|
||||
x = xPos;
|
||||
y += borderTop.h;
|
||||
x += borderLeft.drawScaledY(x, y, midH);
|
||||
x += midW;
|
||||
borderRight.drawScaledY(x, y, midH);
|
||||
|
||||
// bottom row
|
||||
x = xPos;
|
||||
y += midH;
|
||||
x += cornerBottomLeft.draw(x, y);
|
||||
x += borderBottom.drawScaledX(x, y, midW);
|
||||
cornerBottomRight.draw(x, y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package tconstruct.tools.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
/*
|
||||
* Taken from Mantle 1.12-1.3.3.49 under the MIT License
|
||||
*
|
||||
* The MIT License (MIT) Copyright (c) 2013-2014 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6, pillbox, alexbegt)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiElementDuex {
|
||||
|
||||
// this is totally completely ugly but it's a simple solution that doesn't clutter everything too much >_>
|
||||
public static int defaultTexW = 256;
|
||||
public static int defaultTexH = 256;
|
||||
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int w;
|
||||
public final int h;
|
||||
|
||||
public int texW;
|
||||
public int texH;
|
||||
|
||||
public GuiElementDuex(int x, int y, int w, int h, int texW, int texH) {
|
||||
this(x, y, w, h);
|
||||
setTextureSize(texW, texH);
|
||||
|
||||
defaultTexW = texW;
|
||||
defaultTexH = texH;
|
||||
}
|
||||
|
||||
public GuiElementDuex(int x, int y, int w, int h) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
setTextureSize(defaultTexW, defaultTexH);
|
||||
}
|
||||
|
||||
public GuiElementDuex setTextureSize(int w, int h) {
|
||||
texW = w;
|
||||
texH = h;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiElementDuex shift(int xd, int yd) {
|
||||
return new GuiElementDuex(this.x + xd, this.y + yd, this.w, this.h, this.texW, this.texH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the element at the given x/y coordinates
|
||||
*
|
||||
* @param xPos X-Coordinate on the screen
|
||||
* @param yPos Y-Coordinate on the screen
|
||||
*/
|
||||
public int draw(int xPos, int yPos) {
|
||||
// drawModalRectWithCustomSizedTexture
|
||||
GuiScreen.func_146110_a(xPos, yPos, x, y, w, h, texW, texH);
|
||||
return w;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
public int w;
|
||||
public int h;
|
||||
|
||||
public Builder(int w, int h) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
public GuiElementDuex get(int x, int y, int w, int h) {
|
||||
return new GuiElementDuex(x, y, w, h, this.w, this.h);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package tconstruct.tools.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
/*
|
||||
* Taken from Mantle 1.12-1.3.3.49 under the MIT License
|
||||
*
|
||||
* The MIT License (MIT) Copyright (c) 2013-2014 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6, pillbox, alexbegt)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiElementScalable extends GuiElementDuex {
|
||||
|
||||
public GuiElementScalable(int x, int y, int w, int h, int texW, int texH) {
|
||||
super(x, y, w, h, texW, texH);
|
||||
}
|
||||
|
||||
public GuiElementScalable(int x, int y, int w, int h) {
|
||||
super(x, y, w, h);
|
||||
}
|
||||
|
||||
public int drawScaledX(int xPos, int yPos, int width) {
|
||||
for(int i = 0; i < width / w; i++) {
|
||||
draw(xPos + i * w, yPos);
|
||||
}
|
||||
// remainder that doesn't fit total width
|
||||
int remainder = width % w;
|
||||
if(remainder > 0) {
|
||||
GuiScreen.func_146110_a(xPos + width - remainder, yPos, x, y, remainder, h, texW, texH);
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
public int drawScaledY(int xPos, int yPos, int height) {
|
||||
for(int i = 0; i < height / h; i++) {
|
||||
draw(xPos, yPos + i * h);
|
||||
}
|
||||
// remainder that doesn't fit total width
|
||||
int remainder = height % h;
|
||||
if(remainder > 0) {
|
||||
// drawModalRectWithCustomSizedTexture
|
||||
GuiScreen.func_146110_a(xPos, yPos + height - remainder, x, y, w, remainder, texW, texH);
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
public int drawScaled(int xPos, int yPos, int width, int height) {
|
||||
// we draw full height row-wise
|
||||
int full = height / this.h;
|
||||
for(int i = 0; i < full; i++) {
|
||||
drawScaledX(xPos, yPos + i * this.h, width);
|
||||
}
|
||||
|
||||
yPos += full * this.h;
|
||||
|
||||
// and the remainder is drawn manually
|
||||
int yRest = height % this.h;
|
||||
// the same as drawScaledX but with the remaining height
|
||||
for(int i = 0; i < width / w; i++) {
|
||||
drawScaledY(xPos + i * w, yPos, yRest);
|
||||
}
|
||||
// remainder that doesn't fit total width
|
||||
int remainder = width % w;
|
||||
if(remainder > 0) {
|
||||
// drawModalRectWithCustomSizedTexture
|
||||
GuiScreen.func_146110_a(xPos + width - remainder, yPos, x, y, remainder, yRest, texW, texH);
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiElementScalable shift(int xd, int yd) {
|
||||
GuiElementScalable element = new GuiElementScalable(this.x + xd, this.y + yd, this.w, this.h);
|
||||
element.setTextureSize(texW, texH);
|
||||
return element;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
package tconstruct.tools.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
/*
|
||||
* Taken from Mantle 1.12-1.3.3.49 under the MIT License
|
||||
*
|
||||
* The MIT License (MIT) Copyright (c) 2013-2014 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6, pillbox, alexbegt)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
// a vertical slider!
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiSliderWidget {
|
||||
// gui info
|
||||
public final GuiElementDuex slider;
|
||||
public final GuiElementDuex sliderHighlighted;
|
||||
public final GuiElementDuex sliderDisabled;
|
||||
public final GuiElementDuex slideBarTop;
|
||||
public final GuiElementDuex slideBarBottom;
|
||||
public final GuiElementScalable slideBar;
|
||||
public int xPos;
|
||||
public int yPos;
|
||||
public int height;
|
||||
public int width;
|
||||
public int sliderOffset; // x-offset of the slider to the left edge of the slideBar
|
||||
// slider info
|
||||
protected int minValue;
|
||||
protected int maxValue;
|
||||
protected int increment;
|
||||
// positioning info
|
||||
protected int currentValue;
|
||||
protected boolean enabled;
|
||||
protected boolean hidden;
|
||||
|
||||
protected boolean isScrolling;
|
||||
protected boolean isHighlighted;
|
||||
// where the slider was clicked on the slider itself (not on the bar, on the thing that slides)
|
||||
private int clickX;
|
||||
private int clickY;
|
||||
private boolean clickedBar; // if the bar has already been clicked and not released
|
||||
|
||||
public GuiSliderWidget(GuiElementDuex slider, GuiElementDuex sliderHighlighted, GuiElementDuex sliderDisabled, GuiElementDuex slideBarTop, GuiElementDuex slideBarBottom, GuiElementScalable slideBar) {
|
||||
this.slider = slider;
|
||||
this.sliderHighlighted = sliderHighlighted;
|
||||
this.sliderDisabled = sliderDisabled;
|
||||
this.slideBar = slideBar;
|
||||
this.slideBarTop = slideBarTop;
|
||||
this.slideBarBottom = slideBarBottom;
|
||||
|
||||
height = slideBar.h;
|
||||
width = slideBar.w;
|
||||
currentValue = minValue = 0;
|
||||
maxValue = slideBar.h;
|
||||
increment = 1;
|
||||
|
||||
sliderOffset = Math.abs(slideBar.w - slider.w) / 2;
|
||||
|
||||
isScrolling = false;
|
||||
isHighlighted = false;
|
||||
|
||||
enabled = true;
|
||||
hidden = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the part will be drawn. Upper left corner.
|
||||
*/
|
||||
public void setPosition(int x, int y) {
|
||||
this.xPos = x;
|
||||
this.yPos = y;
|
||||
}
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the height of the whole slider and slidebar
|
||||
*/
|
||||
public void setSize(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* specifies the values that the slider represents
|
||||
*/
|
||||
public void setSliderParameters(int min, int max, int stepsize) {
|
||||
this.minValue = min;
|
||||
this.maxValue = max;
|
||||
this.increment = stepsize;
|
||||
|
||||
// just in case
|
||||
setSliderValue(currentValue);
|
||||
}
|
||||
|
||||
public int setSliderValue(int val) {
|
||||
if (val > maxValue) {
|
||||
val = maxValue;
|
||||
} else if (val < minValue) {
|
||||
val = minValue;
|
||||
}
|
||||
|
||||
currentValue = val;
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
if (isHidden()) {
|
||||
return 0;
|
||||
}
|
||||
return Math.min(maxValue, Math.max(minValue, currentValue));
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return this.hidden;
|
||||
}
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
this.hidden = true;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
this.hidden = false;
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
if (hidden) {
|
||||
return;
|
||||
}
|
||||
|
||||
// slidebar background
|
||||
slideBarTop.draw(xPos, yPos);
|
||||
slideBar.drawScaledY(xPos, yPos + slideBarTop.h, getUsableSlidebarHeight());
|
||||
slideBarBottom.draw(xPos, yPos + height - slideBarBottom.h);
|
||||
|
||||
int x = xPos + sliderOffset;
|
||||
int y = yPos + getSliderTop();
|
||||
|
||||
// the slider depending on state
|
||||
if (enabled) {
|
||||
if (isScrolling) {
|
||||
sliderDisabled.draw(x, y);
|
||||
} else if (isHighlighted) {
|
||||
sliderHighlighted.draw(x, y);
|
||||
} else {
|
||||
slider.draw(x, y);
|
||||
}
|
||||
} else {
|
||||
sliderDisabled.draw(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
private int getUsableSlidebarHeight() {
|
||||
return height - slideBarTop.h - slideBarBottom.h;
|
||||
}
|
||||
|
||||
private int getSliderTop() {
|
||||
float d = maxValue - minValue;
|
||||
d = (float) (currentValue - minValue) / d;
|
||||
d *= getUsableSlidebarHeight() - slider.h;
|
||||
|
||||
return (int) d + slideBarTop.h;
|
||||
}
|
||||
|
||||
public void update(int mouseX, int mouseY, boolean useMouseWheel) {
|
||||
if (!enabled || hidden) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean mouseDown = Mouse.isButtonDown(0); // left mouse button
|
||||
int wheel = Mouse.getDWheel();
|
||||
|
||||
if (useMouseWheel) {
|
||||
if (wheel > 0) {
|
||||
decrement();
|
||||
return;
|
||||
} else if (wheel < 0) {
|
||||
increment();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// relative position inside the widget
|
||||
int x = mouseX - xPos;
|
||||
int y = mouseY - yPos;
|
||||
|
||||
// reset click data
|
||||
if (!mouseDown && clickedBar) {
|
||||
clickedBar = false;
|
||||
}
|
||||
|
||||
// button not pressed and scrolling -> stop scrolling
|
||||
if (!mouseDown && isScrolling) {
|
||||
isScrolling = false;
|
||||
}
|
||||
// button pressed and scrolling -> update position of slider
|
||||
else if (isScrolling) {
|
||||
float d = maxValue - minValue;
|
||||
float val = (float) (y - clickY) / (float) (getUsableSlidebarHeight() - slider.h);
|
||||
val *= d;
|
||||
|
||||
if (val < (float) increment / 2f) {
|
||||
// < 1/2 increment
|
||||
setSliderValue(minValue);
|
||||
} else if (val > maxValue - ((float) increment / 2f)) {
|
||||
// > max-1/2 increment
|
||||
setSliderValue(maxValue);
|
||||
} else {
|
||||
// in between
|
||||
setSliderValue((int) (minValue + (float) increment * Math.round(val)));
|
||||
}
|
||||
}
|
||||
// not scrolling yet but possibly inside the slider
|
||||
else if (x >= 0 && y >= getSliderTop() &&
|
||||
x - sliderOffset <= slider.w && y <= getSliderTop() + slider.h) {
|
||||
isHighlighted = true;
|
||||
if (mouseDown) {
|
||||
isScrolling = true;
|
||||
clickX = x - sliderOffset;
|
||||
clickY = y - getSliderTop();
|
||||
}
|
||||
}
|
||||
// not on the slider but clicked on the bar
|
||||
else if (mouseDown && !clickedBar &&
|
||||
x >= 0 && y >= 0 &&
|
||||
x <= slideBar.w && y <= height) {
|
||||
if (y < getSliderTop()) {
|
||||
decrement();
|
||||
} else {
|
||||
increment();
|
||||
}
|
||||
|
||||
clickedBar = true;
|
||||
} else {
|
||||
isHighlighted = false;
|
||||
}
|
||||
}
|
||||
|
||||
public int decrement() {
|
||||
setSliderValue(currentValue - increment);
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
public int increment() {
|
||||
setSliderValue(currentValue + increment);
|
||||
return currentValue;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user