This commit is contained in:
Raoul Van den Berge
2015-12-22 12:39:03 +01:00
parent da89f6778e
commit 3b143310e3
76 changed files with 1730 additions and 847 deletions

View File

@@ -19,7 +19,8 @@ import storagecraft.storage.StorageItem;
import storagecraft.tile.TileController;
import storagecraft.tile.TileGrid;
public class GuiGrid extends GuiBase {
public class GuiGrid extends GuiBase
{
public static final int SORTING_DIRECTION_ASCENDING = 0;
public static final int SORTING_DIRECTION_DESCENDING = 1;
@@ -39,7 +40,8 @@ public class GuiGrid extends GuiBase {
private int offset;
public GuiGrid(ContainerGrid container, TileGrid grid) {
public GuiGrid(ContainerGrid container, TileGrid grid)
{
super(container, 176, 190);
this.container = container;
@@ -47,7 +49,8 @@ public class GuiGrid extends GuiBase {
}
@Override
public void init(int x, int y) {
public void init(int x, int y)
{
addSideButton(new SideButtonRedstoneMode(grid));
addSideButton(new SideButtonGridSortingDirection());
@@ -62,22 +65,27 @@ public class GuiGrid extends GuiBase {
}
@Override
public void update(int x, int y) {
public void update(int x, int y)
{
int wheel = Mouse.getDWheel();
wheel = Math.max(Math.min(-wheel, 1), -1);
if (canScroll(wheel)) {
if (canScroll(wheel))
{
offset += wheel;
}
if (offset > getMaxOffset()) {
if (offset > getMaxOffset())
{
offset = getMaxOffset();
}
}
private int getMaxOffset() {
if (!grid.isConnected()) {
private int getMaxOffset()
{
if (!grid.isConnected())
{
return 0;
}
@@ -86,24 +94,29 @@ public class GuiGrid extends GuiBase {
return max < 0 ? 0 : max;
}
private boolean canScroll(int delta) {
if (offset + delta < 0) {
private boolean canScroll(int delta)
{
if (offset + delta < 0)
{
return false;
}
return offset + delta <= getMaxOffset();
}
private boolean isHoveringOverValidSlot() {
private boolean isHoveringOverValidSlot()
{
return grid.isConnected() && isHoveringOverSlot() && hoveringSlotId < getItems().size();
}
private boolean isHoveringOverSlot() {
private boolean isHoveringOverSlot()
{
return hoveringSlotId >= 0;
}
@Override
public void drawBackground(int x, int y, int mouseX, int mouseY) {
public void drawBackground(int x, int y, int mouseX, int mouseY)
{
bindTexture("gui/grid.png");
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
@@ -112,7 +125,8 @@ public class GuiGrid extends GuiBase {
}
@Override
public void drawForeground(int mouseX, int mouseY) {
public void drawForeground(int mouseX, int mouseY)
{
drawString(7, 7, t("gui.storagecraft:grid"));
drawString(7, 96, t("container.inventory"));
@@ -125,15 +139,19 @@ public class GuiGrid extends GuiBase {
int slot = offset * 9;
for (int i = 0; i < 9 * 4; ++i) {
if (slot < items.size()) {
for (int i = 0; i < 9 * 4; ++i)
{
if (slot < items.size())
{
drawItem(x, y, items.get(slot).toItemStack(), true);
}
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected())
{
hoveringSlotId = slot;
if (slot < items.size()) {
if (slot < items.size())
{
// We need to use the ID, because if we filter, the client-side index will change
// while the serverside's index will still be the same.
hoveringId = items.get(slot).getId();
@@ -150,44 +168,55 @@ public class GuiGrid extends GuiBase {
x += 18;
if ((i + 1) % 9 == 0) {
if ((i + 1) % 9 == 0)
{
x = 8;
y += 18;
}
}
if (isHoveringOverValidSlot()) {
if (isHoveringOverValidSlot())
{
drawTooltip(mouseX, mouseY, items.get(hoveringSlotId).toItemStack());
}
}
public List<StorageItem> getItems() {
public List<StorageItem> getItems()
{
List<StorageItem> items = new ArrayList<StorageItem>();
if (!grid.isConnected()) {
if (!grid.isConnected())
{
return items;
}
items.addAll(grid.getController().getItems());
if (!searchField.getText().trim().isEmpty()) {
if (!searchField.getText().trim().isEmpty())
{
Iterator<StorageItem> t = items.iterator();
while (t.hasNext()) {
while (t.hasNext())
{
StorageItem item = t.next();
if (!item.toItemStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase())) {
if (!item.toItemStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase()))
{
t.remove();
}
}
}
switch (SORTING_TYPE) {
switch (SORTING_TYPE)
{
case SORTING_TYPE_COUNT:
items.sort(new Comparator<StorageItem>() {
items.sort(new Comparator<StorageItem>()
{
@Override
public int compare(StorageItem o1, StorageItem o2) {
switch (SORTING_DIRECTION) {
public int compare(StorageItem o1, StorageItem o2)
{
switch (SORTING_DIRECTION)
{
case SORTING_DIRECTION_ASCENDING:
return Integer.valueOf(o2.getQuantity()).compareTo(o1.getQuantity());
case SORTING_DIRECTION_DESCENDING:
@@ -200,10 +229,13 @@ public class GuiGrid extends GuiBase {
break;
case SORTING_TYPE_NAME:
items.sort(new Comparator<StorageItem>() {
items.sort(new Comparator<StorageItem>()
{
@Override
public int compare(StorageItem o1, StorageItem o2) {
switch (SORTING_DIRECTION) {
public int compare(StorageItem o1, StorageItem o2)
{
switch (SORTING_DIRECTION)
{
case SORTING_DIRECTION_ASCENDING:
return o2.toItemStack().getDisplayName().compareTo(o1.toItemStack().getDisplayName());
case SORTING_DIRECTION_DESCENDING:
@@ -221,22 +253,32 @@ public class GuiGrid extends GuiBase {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int clickedButton) {
public void mouseClicked(int mouseX, int mouseY, int clickedButton)
{
super.mouseClicked(mouseX, mouseY, clickedButton);
if (grid.isConnected()) {
if (grid.isConnected())
{
TileController controller = grid.getController();
if (isHoveringOverSlot() && container.getPlayer().inventory.getItemStack() != null) {
if (isHoveringOverSlot() && container.getPlayer().inventory.getItemStack() != null)
{
StorageCraft.NETWORK.sendToServer(new MessageStoragePush(controller.xCoord, controller.yCoord, controller.zCoord, -1, clickedButton == 1));
} else if (isHoveringOverValidSlot() && container.getPlayer().inventory.getItemStack() == null) {
}
else if (isHoveringOverValidSlot() && container.getPlayer().inventory.getItemStack() == null)
{
StorageCraft.NETWORK.sendToServer(new MessageStoragePull(controller.xCoord, controller.yCoord, controller.zCoord, hoveringId, clickedButton == 1, Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)));
} else {
for (int i = 0; i < container.inventorySlots.size(); ++i) {
}
else
{
for (int i = 0; i < container.inventorySlots.size(); ++i)
{
Slot slot = (Slot) container.inventorySlots.get(i);
if (inBounds(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX - guiLeft, mouseY - guiTop)) {
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
if (inBounds(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX - guiLeft, mouseY - guiTop))
{
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
{
StorageCraft.NETWORK.sendToServer(new MessageStoragePush(controller.xCoord, controller.yCoord, controller.zCoord, slot.slotNumber, clickedButton == 1));
}
}
@@ -246,9 +288,13 @@ public class GuiGrid extends GuiBase {
}
@Override
protected void keyTyped(char character, int keyCode) {
if (!checkHotbarKeys(keyCode) && searchField.textboxKeyTyped(character, keyCode)) {
} else {
protected void keyTyped(char character, int keyCode)
{
if (!checkHotbarKeys(keyCode) && searchField.textboxKeyTyped(character, keyCode))
{
}
else
{
super.keyTyped(character, keyCode);
}
}