mirror of
https://github.com/GTNewHorizons/Baubles-Expanded.git
synced 2026-11-20 12:09:59 +00:00
Finally implement a working scrollbar.
This commit is contained in:
1 parent
ce3f82a756
commit
4f2d032dcd
5 files changed
+31
-186
No files matched your search
@@ -56,8 +56,6 @@ public class GuiPlayerExpanded extends GuiContainer implements INEIGuiHandler {
|
||||
|
||||
public boolean showActivePotionEffects;
|
||||
|
||||
private boolean widthTooNarrow;
|
||||
|
||||
/** Amount scrolled in Creative mode inventory (0 = top, 1 = bottom) */
|
||||
private float currentScroll;
|
||||
/** True if the scrollbar is being dragged */
|
||||
@@ -88,8 +86,6 @@ public class GuiPlayerExpanded extends GuiContainer implements INEIGuiHandler {
|
||||
buttonList.clear();
|
||||
super.initGui();
|
||||
|
||||
this.widthTooNarrow = this.width < 379;
|
||||
|
||||
if (!this.mc.thePlayer.getActivePotionEffects().isEmpty()) {
|
||||
this.showActivePotionEffects = true;
|
||||
}
|
||||
@@ -129,15 +125,16 @@ public class GuiPlayerExpanded extends GuiContainer implements INEIGuiHandler {
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
int upperHeight = 7 + BaubleExpandedSlots.slotsCurrentlyUsed() * 18;
|
||||
this.mc.getTextureManager().bindTexture(gui_background);
|
||||
this.drawTexturedModalRect(this.guiLeft - 26, this.guiTop + 4, 0, 0, 27, upperHeight);
|
||||
|
||||
final int slotOffset = 18;
|
||||
final int slotStartX = guiLeft - 26;
|
||||
final int slotStartY = 12;
|
||||
|
||||
if (BaubleExpandedSlots.slotsCurrentlyUsed() <= 8) {
|
||||
this.drawTexturedModalRect(this.guiLeft - 26, this.guiTop + 4, 0, 0, 27, upperHeight);
|
||||
this.drawTexturedModalRect(this.guiLeft - 26, this.guiTop + 4 + upperHeight, 0, 151, 27, 7);
|
||||
} else {
|
||||
this.drawTexturedModalRect(this.guiLeft - 26, this.guiTop + 4, 0, 0, 27, 158);
|
||||
this.drawTexturedModalRect(this.guiLeft - 42, this.guiTop + 4, 27, 0, 23, 158);
|
||||
this.mc.getTextureManager().bindTexture(creative_inventory_tabs);
|
||||
this.drawTexturedModalRect(this.guiLeft - 34, this.guiTop + 12 + (int) (127f * this.currentScroll), 232, 0, 12, 15);
|
||||
@@ -248,7 +245,7 @@ public class GuiPlayerExpanded extends GuiContainer implements INEIGuiHandler {
|
||||
super.handleMouseInput();
|
||||
int wheel = Mouse.getEventDWheel();
|
||||
if (this.needsScrollBars()) {
|
||||
int i = ((ContainerPlayerExpanded)this.inventorySlots).baubleSlotMap.size();
|
||||
int i = BaubleExpandedSlots.slotsCurrentlyUsed();
|
||||
this.currentScroll = (float)((double)this.currentScroll - wheel / (double) i);
|
||||
this.currentScroll = MathHelper.clamp_float(this.currentScroll, 0.0F, 1.0F);
|
||||
((ContainerPlayerExpanded)this.inventorySlots).scrollTo(this.currentScroll);
|
||||
|
||||
@@ -5,14 +5,9 @@ import baubles.api.expanded.BaubleExpandedSlots;
|
||||
import baubles.api.expanded.IBaubleExpanded;
|
||||
import baubles.common.BaublesConfig;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import baubles.common.network.PacketHandler;
|
||||
import baubles.common.network.client.PacketScrollBaubleClient;
|
||||
import baubles.common.network.server.PacketScrollBaubleServer;
|
||||
import codechicken.nei.api.IInfiniteItemHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -27,15 +22,12 @@ import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ContainerPlayerExpanded extends Container {
|
||||
|
||||
public SortedMap<Integer, String> baubleSlotMap = new TreeMap<>();
|
||||
SortedMap<Integer, String> shownFilteredSlots = new TreeMap<>();
|
||||
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2);
|
||||
public IInventory craftResult = new InventoryCraftResult();
|
||||
public InventoryBaubles baubles;
|
||||
@@ -87,22 +79,31 @@ public class ContainerPlayerExpanded extends Container {
|
||||
}
|
||||
|
||||
final int slotOffset = 18;
|
||||
|
||||
//Bauble Slots
|
||||
for(i = 0; i < BaubleExpandedSlots.slotLimit; i++) {
|
||||
String slotType = BaubleExpandedSlots.getSlotType(i);
|
||||
if(BaublesConfig.showUnusedSlots || !slotType.equals(BaubleExpandedSlots.unknownType)) {
|
||||
addSlotToContainer(new SlotBauble(baubles, slotType, i, -18, 12 + (slotOffset * i)));
|
||||
}
|
||||
}
|
||||
|
||||
final int slotStartY = 8;
|
||||
|
||||
//inventory slots
|
||||
for (i = 0; i < 3; ++i) {
|
||||
for (j = 0; j < 9; ++j) {
|
||||
addSlotToContainer(new Slot(playerInv, j + (i + 1) * 9, slotStartY + j * slotOffset, 84 + i * 18));
|
||||
this.addSlotToContainer(new Slot(playerInv, j + (i + 1) * 9, slotStartY + j * slotOffset, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
//hotbar slots
|
||||
for (i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new Slot(playerInv, i, slotStartY + i * slotOffset, 142));
|
||||
this.addSlotToContainer(new Slot(playerInv, i, slotStartY + i * slotOffset, 142));
|
||||
}
|
||||
|
||||
this.onCraftMatrixChanged(this.craftMatrix);
|
||||
this.scrollToIndex(0);
|
||||
this.scrollTo(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,92 +128,34 @@ public class ContainerPlayerExpanded extends Container {
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollToIndex(int indexIn) {
|
||||
String[] numberOfActiveSlots = BaubleExpandedSlots.getCurrentSlotAssignments();
|
||||
final int visibleBaubleSlots = BaublesConfig.showUnusedSlots ? BaubleExpandedSlots.slotLimit : BaubleExpandedSlots.slotsCurrentlyUsed();
|
||||
//System.out.print(Arrays.toString(numberOfActiveSlots));
|
||||
|
||||
int slots = 0;
|
||||
int yOffset = 12;
|
||||
int index = 0;
|
||||
this.inventorySlots.subList(45, this.inventorySlots.size()).clear();
|
||||
this.inventoryItemStacks.subList(45, this.inventoryItemStacks.size()).clear();
|
||||
|
||||
for (int i = 0; i < numberOfActiveSlots.length && i < BaubleExpandedSlots.slotLimit; i++) {
|
||||
if (!numberOfActiveSlots[i].equals(BaubleExpandedSlots.unknownType)) {
|
||||
baubleSlotMap.put(i, numberOfActiveSlots[i]);
|
||||
//System.out.println(baubleSlotMap);
|
||||
}
|
||||
}
|
||||
//System.out.println(baubleSlotMap);
|
||||
for (int identifier : baubleSlotMap.keySet()) {
|
||||
//System.out.println(identifier + " " + baubleSlotMap.get(identifier));
|
||||
|
||||
String shownSlot = baubleSlotMap.get(identifier);
|
||||
|
||||
//System.out.println(identifier + " " + baubleSlotMap.get(identifier));
|
||||
for (int i = 0; i + 1 < shownSlot.length() && slots < 8; i++) {
|
||||
String slotType = BaubleExpandedSlots.getSlotType(i);
|
||||
//System.out.println(slotType + i);
|
||||
if (index >= indexIn) {
|
||||
addSlotToContainer(new SlotBauble(baubles, slotType, i, -18, yOffset));
|
||||
yOffset += 18;
|
||||
slots++;
|
||||
//System.out.println(shownSlot + " " + identifier);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
if (!this.isLocalWorld) {
|
||||
PacketHandler.INSTANCE.sendTo(new PacketScrollBaubleServer(this.windowId, indexIn), (EntityPlayerMP) this.thePlayer);
|
||||
}
|
||||
lastScrollIndex = indexIn;
|
||||
}
|
||||
|
||||
public void scrollTo(float offset) {
|
||||
|
||||
if (!canScroll()) return;
|
||||
final int activeBaubleSlots = BaublesConfig.showUnusedSlots ? BaubleExpandedSlots.slotLimit : BaubleExpandedSlots.slotsCurrentlyUsed();
|
||||
|
||||
if (offset < 0) offset = 0;
|
||||
if (offset > 1) offset = 1;
|
||||
|
||||
int shownslots = 8;
|
||||
int slotOffset = (int) ((double) (offset * (float) (activeBaubleSlots - shownslots)) + 0.5F);
|
||||
|
||||
int k = Math.min (baubleSlotMap.size(), 8);
|
||||
|
||||
int j = (int)((double)(offset * (float) k) + 0.5D);
|
||||
|
||||
if (j < 0) {
|
||||
j = 0;
|
||||
if (slotOffset < 0) {
|
||||
slotOffset = 0;
|
||||
}
|
||||
|
||||
if (j == this.lastScrollIndex) {
|
||||
return;
|
||||
for (int i = 0; i < activeBaubleSlots && i < BaubleExpandedSlots.slotLimit; i++) {
|
||||
//TODO: Find a way to not use a magic number to get to the correct ID range for the Slot editing.
|
||||
Slot slot = (Slot) this.inventorySlots.get(9 + i);
|
||||
int displayIndex = i;
|
||||
if (displayIndex >= 0 && displayIndex < activeBaubleSlots) {
|
||||
slot.yDisplayPosition = (12 - (slotOffset * 18) + (displayIndex) * 18);
|
||||
if (slot.yDisplayPosition < 12 || slot.yDisplayPosition > 8 * 18) {
|
||||
//Hide the rest of the slots!
|
||||
slot.yDisplayPosition = -2000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shownFilteredSlots = baubleSlotMap.subMap(this.lastScrollIndex * (int) offset, (int)(offset * (float) k));
|
||||
System.out.println(lastScrollIndex + " " + offset + " " + k);
|
||||
System.out.println(shownFilteredSlots);
|
||||
|
||||
if (this.isLocalWorld) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketScrollBaubleClient(this.windowId, j));
|
||||
}
|
||||
//baubleSlotMap.subMap( , (int)(offset * (float) k));
|
||||
/*
|
||||
for ()
|
||||
this.baubleSlotMap.subMap();
|
||||
int k = (baubleSlotMap.get());
|
||||
int j = (int)((double)(pos * (float) k) + 0.5D);
|
||||
|
||||
if (j < 0) {
|
||||
j = 0;
|
||||
}
|
||||
|
||||
if (j == this.lastScrollIndex) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
public boolean canScroll() {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package baubles.common.network;
|
||||
|
||||
import baubles.common.Baubles;
|
||||
import baubles.common.network.client.PacketScrollBaubleClient;
|
||||
import baubles.common.network.client.PacketSyncBauble;
|
||||
import baubles.common.network.server.PacketOpenBaublesInventory;
|
||||
import baubles.common.network.server.PacketOpenNormalInventory;
|
||||
import baubles.common.network.server.PacketScrollBaubleServer;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -19,8 +17,6 @@ public class PacketHandler
|
||||
INSTANCE.registerMessage(PacketOpenBaublesInventory.class, PacketOpenBaublesInventory.class, 0, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketOpenNormalInventory.class, PacketOpenNormalInventory.class, 1, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketSyncBauble.class, PacketSyncBauble.class, 2, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketScrollBaubleClient.class, PacketScrollBaubleClient.class, 3, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketScrollBaubleServer.class, PacketScrollBaubleServer.class, 4, Side.SERVER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package baubles.common.network.client;
|
||||
|
||||
import baubles.common.container.ContainerPlayerExpanded;
|
||||
import baubles.common.network.server.PacketOpenNormalInventory;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
public class PacketScrollBaubleClient implements IMessage, IMessageHandler<PacketScrollBaubleClient, IMessage> {
|
||||
|
||||
int windowId;
|
||||
int index;
|
||||
|
||||
public PacketScrollBaubleClient() {};
|
||||
|
||||
public PacketScrollBaubleClient(int windowId, int index) {
|
||||
this.windowId = windowId;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
windowId = buf.readInt();
|
||||
index = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(windowId);
|
||||
buf.writeInt(index);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketScrollBaubleClient message, MessageContext ctx) {
|
||||
EntityPlayerMP serverPlayer = ctx.getServerHandler().playerEntity;
|
||||
Container container = serverPlayer.openContainer;
|
||||
if (container instanceof ContainerPlayerExpanded && container.windowId == message.windowId) {
|
||||
((ContainerPlayerExpanded) container).scrollToIndex(message.index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package baubles.common.network.server;
|
||||
|
||||
import baubles.common.container.ContainerPlayerExpanded;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
public class PacketScrollBaubleServer implements IMessage, IMessageHandler<PacketScrollBaubleServer, IMessage> {
|
||||
|
||||
int windowId;
|
||||
int index;
|
||||
|
||||
public PacketScrollBaubleServer(){}
|
||||
public PacketScrollBaubleServer(int windowId, int index) {
|
||||
this.windowId = windowId;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
windowId = buf.readInt();
|
||||
index = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(windowId);
|
||||
buf.writeInt(index);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketScrollBaubleServer message, MessageContext ctx) {
|
||||
EntityPlayerSP sp = Minecraft.getMinecraft().thePlayer;
|
||||
Container container = sp.openContainer;
|
||||
if (container instanceof ContainerPlayerExpanded && container.windowId == message.windowId) {
|
||||
((ContainerPlayerExpanded) container).scrollToIndex(message.index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user