add basic scrolling

This commit is contained in:
Raoul Van den Berge
2015-12-20 10:40:20 +01:00
parent 6b1a3283ff
commit 414d40499b
6 changed files with 51 additions and 27 deletions

View File

@@ -3,7 +3,6 @@ package storagecraft.gui;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import storagecraft.container.ContainerController; import storagecraft.container.ContainerController;
import storagecraft.tile.TileController; import storagecraft.tile.TileController;
@@ -23,8 +22,6 @@ public class GuiController extends GuiContainer {
@Override @Override
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) { protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
GL11.glColor3f(1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(CONTROLLER_RESOURCE); mc.getTextureManager().bindTexture(CONTROLLER_RESOURCE);
int x = (this.width - xSize) / 2; int x = (this.width - xSize) / 2;

View File

@@ -2,33 +2,30 @@ package storagecraft.gui;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import storagecraft.container.ContainerDrive; import storagecraft.container.ContainerDrive;
import storagecraft.tile.TileDrive; import storagecraft.tile.TileDrive;
public class GuiDrive extends GuiMachine { public class GuiDrive extends GuiMachine {
public static final ResourceLocation DRIVE_RESOURCE = new ResourceLocation("storagecraft:textures/gui/drive.png"); public static final ResourceLocation DRIVE_RESOURCE = new ResourceLocation("storagecraft:textures/gui/drive.png");
public GuiDrive(ContainerDrive container, TileDrive drive) { public GuiDrive(ContainerDrive container, TileDrive drive) {
super(container, drive); super(container, drive);
this.xSize = 176; this.xSize = 176;
this.ySize = 190; this.ySize = 190;
} }
@Override @Override
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) { protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
GL11.glColor3f(1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(DRIVE_RESOURCE); mc.getTextureManager().bindTexture(DRIVE_RESOURCE);
drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize); drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize);
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY); super.drawGuiContainerForegroundLayer(mouseX, mouseY);
fontRendererObj.drawString(StatCollector.translateToLocal("gui.storagecraft:drive"), 7, 7, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal("gui.storagecraft:drive"), 7, 7, 4210752);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 96, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 96, 4210752);
} }

View File

@@ -3,7 +3,6 @@ package storagecraft.gui;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import storagecraft.StorageCraft; import storagecraft.StorageCraft;
import storagecraft.container.ContainerExporter; import storagecraft.container.ContainerExporter;
import storagecraft.network.MessageExporterUpdate; import storagecraft.network.MessageExporterUpdate;
@@ -63,8 +62,6 @@ public class GuiExporter extends GuiMachine {
@Override @Override
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) { protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
GL11.glColor3f(1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(EXPORTER_RESOURCE); mc.getTextureManager().bindTexture(EXPORTER_RESOURCE);
drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize); drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize);

View File

@@ -5,7 +5,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11; import org.lwjgl.input.Mouse;
import storagecraft.StorageCraft; import storagecraft.StorageCraft;
import storagecraft.container.ContainerGrid; import storagecraft.container.ContainerGrid;
import storagecraft.network.MessageStoragePull; import storagecraft.network.MessageStoragePull;
@@ -19,6 +19,8 @@ public class GuiGrid extends GuiMachine {
private ContainerGrid container; private ContainerGrid container;
private TileGrid grid; private TileGrid grid;
private int offset;
private int hoveringSlot; private int hoveringSlot;
public GuiGrid(ContainerGrid container, TileGrid grid) { public GuiGrid(ContainerGrid container, TileGrid grid) {
@@ -32,9 +34,42 @@ public class GuiGrid extends GuiMachine {
} }
@Override @Override
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) { public void updateScreen() {
GL11.glColor3f(1.0F, 1.0F, 1.0F); super.updateScreen();
int wheel = Mouse.getDWheel();
wheel = Math.max(Math.min(-wheel, 1), -1);
if (canScroll(wheel)) {
offset += wheel;
}
if (offset > getMaxOffset()) {
offset = getMaxOffset();
}
}
public int getMaxOffset() {
if (!grid.isConnected()) {
return 0;
}
int max = ((int) Math.ceil((float) grid.getController().getItems().size() / (float) 9)) - 4;
return max < 0 ? 0 : max;
}
public boolean canScroll(int delta) {
if (offset + delta < 0) {
return false;
}
return offset + delta <= getMaxOffset();
}
@Override
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
mc.getTextureManager().bindTexture(GRID_RESOURCE); mc.getTextureManager().bindTexture(GRID_RESOURCE);
drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize); drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize);
@@ -55,22 +90,26 @@ public class GuiGrid extends GuiMachine {
hoveringSlot = -1; hoveringSlot = -1;
int slot = offset * 9;
for (int i = 0; i < 9 * 4; ++i) { for (int i = 0; i < 9 * 4; ++i) {
if (grid.isConnected() && i < grid.getController().getItems().size()) { if (grid.isConnected() && slot < grid.getController().getItems().size()) {
ItemStack stack = grid.getController().getItems().get(i).toItemStack(); ItemStack stack = grid.getController().getItems().get(slot).toItemStack();
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), stack, x, y); itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), stack, x, y);
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), stack, x, y); itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), stack, x, y);
} }
if ((mx >= x && mx <= x + 16 && my >= y && my <= y + 16) || !grid.isConnected()) { if ((mx >= x && mx <= x + 16 && my >= y && my <= y + 16) || !grid.isConnected()) {
hoveringSlot = i; hoveringSlot = slot;
int color = grid.isConnected() ? -2130706433 : 0xFF5B5B5B; int color = grid.isConnected() ? -2130706433 : 0xFF5B5B5B;
drawGradientRect(x, y, x + 16, y + 16, color, color); drawGradientRect(x, y, x + 16, y + 16, color, color);
} }
slot++;
x += 18; x += 18;
if ((i + 1) % 9 == 0) { if ((i + 1) % 9 == 0) {

View File

@@ -3,7 +3,6 @@ package storagecraft.gui;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import storagecraft.StorageCraft; import storagecraft.StorageCraft;
import storagecraft.container.ContainerImporter; import storagecraft.container.ContainerImporter;
import storagecraft.network.MessageImporterUpdate; import storagecraft.network.MessageImporterUpdate;
@@ -66,8 +65,6 @@ public class GuiImporter extends GuiMachine {
@Override @Override
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) { protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
GL11.glColor3f(1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(IMPORTER_RESOURCE); mc.getTextureManager().bindTexture(IMPORTER_RESOURCE);
drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize); drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize);

View File

@@ -2,7 +2,6 @@ package storagecraft.gui;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import storagecraft.container.ContainerStorageProxy; import storagecraft.container.ContainerStorageProxy;
import storagecraft.tile.TileStorageProxy; import storagecraft.tile.TileStorageProxy;
@@ -15,8 +14,6 @@ public class GuiStorageProxy extends GuiMachine {
@Override @Override
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) { protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
GL11.glColor3f(1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(STORAGE_PROXY_RESOURCE); mc.getTextureManager().bindTexture(STORAGE_PROXY_RESOURCE);
drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize); drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize);