diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2018-12-22 13:17:31 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2018-12-22 13:17:31 +0800 |
| commit | d1e292ca25b7987bc4ddf334205238d75f7f29b7 (patch) | |
| tree | 3c2911284faccd10f97e3aa307719ec12efd4b53 /src/main/java/me/shedaniel/gui | |
| parent | 7bcd4d2e868210a842ad7e4e4fc34240de40a121 (diff) | |
| download | RoughlyEnoughItems-d1e292ca25b7987bc4ddf334205238d75f7f29b7.tar.gz RoughlyEnoughItems-d1e292ca25b7987bc4ddf334205238d75f7f29b7.tar.bz2 RoughlyEnoughItems-d1e292ca25b7987bc4ddf334205238d75f7f29b7.zip | |
from aei but like jei now
Diffstat (limited to 'src/main/java/me/shedaniel/gui')
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/AEIRenderHelper.java | 235 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/Drawable.java | 33 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/GuiItemList.java | 264 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/RecipeContainer.java | 13 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/RecipeGui.java | 218 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/widget/AEISlot.java | 181 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/widget/Button.java | 72 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/widget/Control.java | 96 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/widget/IFocusable.java | 10 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/widget/TextBox.java | 71 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/gui/widget/WidgetArrow.java | 38 |
11 files changed, 1231 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/gui/AEIRenderHelper.java b/src/main/java/me/shedaniel/gui/AEIRenderHelper.java new file mode 100755 index 000000000..3ffbc7d82 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/AEIRenderHelper.java @@ -0,0 +1,235 @@ +package me.shedaniel.gui; + +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.IFocusable; +import me.shedaniel.impl.AEIRecipeManager; +import me.shedaniel.library.KeyBindManager; +import me.shedaniel.listenerdefinitions.IMixinGuiContainer; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.item.ItemStack; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + + +/** + * Created by James on 7/28/2018. + */ +public class AEIRenderHelper { + static Point mouseLoc; + static public GuiItemList aeiGui; + static GuiContainer overlayedGui; + static List<TooltipData> tooltipsToRender = new ArrayList<>(); + + public static void setMouseLoc(int x, int y) { + mouseLoc = new Point(x, y); + } + + static public IFocusable focusedControl; + + public static Point getMouseLoc() { + return mouseLoc; + } + + public static MainWindow getResolution() { + + return Minecraft.getInstance().mainWindow; + } + + public static void drawAEI(GuiContainer overlayedGui) { + AEIRenderHelper.overlayedGui = overlayedGui; + if (aeiGui == null) { + aeiGui = new GuiItemList(overlayedGui); + } + aeiGui.draw(); + renderTooltips(); + } + + public static void resize() { + if (aeiGui != null) { + aeiGui.resize(); + } + if (overlayedGui instanceof RecipeGui) { + overlayedGui.onResize(Minecraft.getInstance(), 0, 0); + } + } + + public static ItemRenderer getItemRender() { + return Minecraft.getInstance().getItemRenderer(); + } + + public static FontRenderer getFontRenderer() { + return Minecraft.getInstance().fontRenderer; + } + + public static GuiContainer getOverlayedGui() { + if (overlayedGui instanceof GuiContainer) + return overlayedGui; + return null; + } + + public static void addToolTip(List<String> text, int x, int y) { + tooltipsToRender.add(new TooltipData(text, x, y)); + } + + + private static void renderTooltips() { + GlStateManager.pushMatrix(); + GlStateManager.enableLighting(); + for(TooltipData tooltipData : tooltipsToRender) { + getOverlayedGui().drawHoveringText(tooltipData.text, tooltipData.x, tooltipData.y); + } + GlStateManager.disableLighting(); + tooltipsToRender.clear(); + GlStateManager.popMatrix(); + + } + + public static boolean mouseClick(int x, int y, int button) { + if (aeiGui.visible) { + for(Control control : aeiGui.controls) { + if (control.isHighlighted() && control.isEnabled() && control.onClick != null) { + if (focusedControl != null) + focusedControl.setFocused(false); + if (control instanceof IFocusable) { + focusedControl = (IFocusable) control; + ((IFocusable) control).setFocused(true); + } + return control.onClick.apply(button); + } + } + if (focusedControl != null) { + focusedControl.setFocused(false); + focusedControl = null; + } + } + if (overlayedGui instanceof RecipeGui) { + List<Control> controls = ((RecipeGui) overlayedGui).controls; + Optional<Control> ctrl = controls.stream().filter(Control::isHighlighted).filter(Control::isEnabled).findFirst(); + if (ctrl.isPresent()) { + try { + return ctrl.get().onClick.apply(button); + } catch (Exception e) { + } + } + } + return false; + } + + public static boolean keyDown(int typedChar, int keyCode, int unknown) { + boolean handled = false; + if (focusedControl != null && focusedControl instanceof Control) { + Control control = (Control) focusedControl; + if (control.onKeyDown != null) { + handled = control.onKeyDown.accept(typedChar, keyCode, unknown); + } + if (control.charPressed != null) + if (typedChar == 256) { + ((IFocusable) control).setFocused(false); + focusedControl = null; + } + handled = true; + } + if (!handled) { + return KeyBindManager.processGuiKeybinds(typedChar); + } + return handled; + } + + public static boolean charInput(long num, int keyCode, int unknown) { + if (focusedControl != null && focusedControl instanceof Control) { + Control control = (Control) focusedControl; + if (control.charPressed != null) { + int numChars = Character.charCount(keyCode); + if (num == numChars) + control.charPressed.accept((char) keyCode, unknown); + else { + char[] chars = Character.toChars(keyCode); + for(int x = 0; x < chars.length; x++) { + control.charPressed.accept(chars[x], unknown); + } + } + return true; + } + } + return false; + } + + public static boolean mouseScrolled(double direction) { + if (!aeiGui.visible) + return false; + if (direction > 0 && aeiGui.buttonLeft.isEnabled()) + aeiGui.buttonLeft.onClick.apply(0); + else if (direction < 0 && aeiGui.buttonRight.isEnabled()) + aeiGui.buttonRight.onClick.apply(0); + return true; + } + + private static class TooltipData { + + private final List<String> text; + private final int x; + private final int y; + + public TooltipData(List<String> text, int x, int y) { + this.text = text; + this.x = x; + this.y = y; + } + } + + public static void updateSearch() { + aeiGui.updateView(); + } + + public static void tick() { + if (aeiGui != null && Minecraft.getInstance().currentScreen == overlayedGui) + aeiGui.tick(); + } + + public static void recipeKeybind() { + if (!(Minecraft.getInstance().currentScreen instanceof GuiContainer)) + return; + Control control = aeiGui.getLastHovered(); + if (control != null && control.isHighlighted() && control instanceof AEISlot) { + AEISlot slot = (AEISlot) control; + AEIRecipeManager.instance().displayRecipesFor(slot.getStack()); + return; + } + if (((IMixinGuiContainer) overlayedGui).getHoveredSlot() != null) { + ItemStack stack = ((IMixinGuiContainer) overlayedGui).getHoveredSlot().getStack(); + AEIRecipeManager.instance().displayRecipesFor(stack); + } + + } + + public static void useKeybind() { + if (!(Minecraft.getInstance().currentScreen instanceof GuiContainer)) + return; + Control control = aeiGui.getLastHovered(); + if (control != null && control.isHighlighted() && control instanceof AEISlot) { + AEISlot slot = (AEISlot) control; + AEIRecipeManager.instance().displayUsesFor(slot.getStack()); + return; + } + if (((IMixinGuiContainer) overlayedGui).getHoveredSlot() != null) { + ItemStack stack = ((IMixinGuiContainer) overlayedGui).getHoveredSlot().getStack(); + AEIRecipeManager.instance().displayUsesFor(stack); + } + + } + + public static void hideKeybind() { + if (Minecraft.getInstance().currentScreen == overlayedGui && aeiGui != null) { + aeiGui.visible = !aeiGui.visible; + } + } +} diff --git a/src/main/java/me/shedaniel/gui/Drawable.java b/src/main/java/me/shedaniel/gui/Drawable.java new file mode 100755 index 000000000..8fffc17af --- /dev/null +++ b/src/main/java/me/shedaniel/gui/Drawable.java @@ -0,0 +1,33 @@ +package me.shedaniel.gui; + +import me.shedaniel.api.IDrawable; +import me.shedaniel.gui.widget.Control; + +import java.awt.*; + +/** + * Created by James on 7/28/2018. + */ +public abstract class Drawable implements IDrawable { + protected Rectangle rect; + + public Drawable(int x, int y, int width, int height) { + rect = new Rectangle(x, y, width, height); + } + + public Drawable(Rectangle rect) { + this.rect = rect; + } + + public abstract void draw(); + + public boolean isHighlighted() { + Point mousePoint = AEIRenderHelper.getMouseLoc(); + if (rect.contains(mousePoint.x, mousePoint.y)) { + if (this instanceof Control) + AEIRenderHelper.aeiGui.setLastHovered((Control) this); + return true; + } + return false; + } +} diff --git a/src/main/java/me/shedaniel/gui/GuiItemList.java b/src/main/java/me/shedaniel/gui/GuiItemList.java new file mode 100755 index 000000000..80666f2cb --- /dev/null +++ b/src/main/java/me/shedaniel/gui/GuiItemList.java @@ -0,0 +1,264 @@ +package me.shedaniel.gui; + +import me.shedaniel.ClientListener; +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Button; +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.TextBox; +import me.shedaniel.listenerdefinitions.IMixinGuiContainer; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.registry.IRegistry; +import net.minecraft.util.text.TextComponentTranslation; + +import java.awt.*; +import java.util.ArrayList; + +public class GuiItemList extends Drawable { + + public static final int FOOTERSIZE = 44; + private GuiContainer overlayedGui; + private static int page = 0; + private ArrayList<AEISlot> displaySlots; + protected ArrayList<Control> controls; + private boolean needsResize = false; + Button buttonLeft; + Button buttonRight; + Button buttonCheating; + TextBox searchBox; + private ArrayList<ItemStack> view; + private Control lastHovered; + protected boolean visible = true; + private int oldGuiLeft = 0; + private boolean cheatMode = false; + + public GuiItemList(GuiContainer overlayedGui) { + super(calculateRect(overlayedGui)); + displaySlots = new ArrayList<>(); + controls = new ArrayList<>(); + this.overlayedGui = overlayedGui; + view = new ArrayList<>(); + resize(); + } + + public boolean canCheat() { + EntityPlayer player = Minecraft.getInstance().player; + if (cheatMode) { + if (!player.hasPermissionLevel(1)) { + cheatClicked(0); + return false; + } + return true; + } + return false; + } + + private static Rectangle calculateRect(GuiContainer overlayedGui) { + MainWindow res = AEIRenderHelper.getResolution(); + int startX = (((IMixinGuiContainer) overlayedGui).getGuiLeft() + ((IMixinGuiContainer) overlayedGui).getXSize()) + 10; + int width = res.getScaledWidth() - startX; + return new Rectangle(startX, 0, width, res.getScaledHeight()); + } + + protected void resize() { + MainWindow res = AEIRenderHelper.getResolution(); + + if (overlayedGui != Minecraft.getInstance().currentScreen) { + if (Minecraft.getInstance().currentScreen instanceof GuiContainer) { + overlayedGui = (GuiContainer) Minecraft.getInstance().currentScreen; + + } else { + needsResize = true; + return; + } + } + oldGuiLeft = ((IMixinGuiContainer) overlayedGui).getGuiLeft(); + rect = calculateRect(overlayedGui); + page = 0; + buttonLeft = new Button(rect.x, rect.y + 3, 16, 20, "<"); + buttonLeft.onClick = this::btnLeftClicked; + buttonRight = new Button(rect.x + rect.width - 18, rect.y + 3, 16, 20, ">"); + buttonRight.onClick = this::btnRightClicked; + controls.clear(); + controls.add(buttonLeft); + controls.add(buttonRight); + String savedText = ""; + if (searchBox != null) { + savedText = searchBox.getText(); + } + searchBox = new TextBox(rect.x, rect.height - 31, rect.width - 4, 18); + searchBox.setText(savedText); + controls.add(searchBox); + buttonCheating = new Button(5, 5, 45, 20, getCheatModeText()); + buttonCheating.onClick = this::cheatClicked; + controls.add(buttonCheating); + calculateSlots(); + updateView(); + fillSlots(); + controls.addAll(displaySlots); + } + + private void fillSlots() { + page = MathHelper.clamp(page, 0, (int) Math.floor(view.size() / displaySlots.size())); + int firstSlot = page * displaySlots.size(); + for(int i = 0; i < displaySlots.size(); i++) { + if (firstSlot + i < view.size() && firstSlot + i >= 0) { + displaySlots.get(i).setStack(view.get(firstSlot + i)); + } else { + displaySlots.get(i).setStack(ItemStack.EMPTY); + } + } + } + + private void calculateSlots() { + int x = rect.x; + int y = rect.y + 20; + MainWindow res = AEIRenderHelper.getResolution(); + displaySlots.clear(); + int xOffset = 4; + int yOffset = 4; + while (true) { + AEISlot slot = new AEISlot(x + xOffset, y + yOffset); + slot.setCheatable(true); + xOffset += 18; + displaySlots.add(slot); + if (x + xOffset + 18 > res.getScaledWidth()) { + xOffset = 4; + yOffset += 18; + } + if (y + yOffset + 9 + FOOTERSIZE > rect.height) { + break; + } + } + } + + @Override + public void draw() { + if (!visible) + return; + if (needsResize == true) + resize(); + if (oldGuiLeft != ((IMixinGuiContainer) overlayedGui).getGuiLeft()) + resize(); + GlStateManager.pushMatrix(); + updateButtons(); + controls.forEach(Control::draw); + String header = String.format("%s/%s", page + 1, ((int) Math.floor(view.size() / displaySlots.size())) + 1); + Minecraft.getInstance().fontRenderer.drawStringWithShadow(header, rect.x + (rect.width / 2) - (Minecraft.getInstance().fontRenderer.getStringWidth(header) / 2), rect.y + 10, -1); + GlStateManager.popMatrix(); + } + + private void updateButtons() { + if (page == 0) + buttonLeft.setEnabled(false); + else + buttonLeft.setEnabled(true); + if (displaySlots.size() + displaySlots.size() * page >= view.size()) + buttonRight.setEnabled(false); + else + buttonRight.setEnabled(true); + } + + + public boolean btnRightClicked(int button) { + if (button == 0) { + page++; + fillSlots(); + return true; + } + return false; + } + + public boolean btnLeftClicked(int button) { + if (button == 0) { + page--; + fillSlots(); + return true; + } + return false; + } + + public boolean cheatClicked(int button) { + if (button == 0) { + cheatMode = !cheatMode; + + buttonCheating.setString(getCheatModeText()); + return true; + } + return false; + } + + private String getCheatModeText() { + if (cheatMode) { + TextComponentTranslation cheat = new TextComponentTranslation("text.aei.cheat", new Object[]{null}); + return cheat.getFormattedText(); + } + TextComponentTranslation noCheat = new TextComponentTranslation("text.aei.nocheat", new Object[]{null}); + return noCheat.getFormattedText(); + } + + protected void updateView() { + String searchText = searchBox.getText(); + String modText = null; + if (searchText.contains("@")) { + int nextBreak = searchText.indexOf(' ', searchText.indexOf('@')); + if (nextBreak == 0 || nextBreak == -1) + nextBreak = searchText.length(); + modText = searchText.substring(searchText.indexOf('@'), nextBreak); + searchText = searchText.replace(modText, "").trim(); + modText = modText.replace("@", "").toLowerCase(); + } + + view.clear(); + if (searchText.equals("") || searchText == null) { + for(ItemStack stack : ClientListener.stackList) { + if (modText != null) { + if (getMod(stack).contains(modText)) { + view.add(stack); + } + } else { + view.add(stack); + } + } + } else { + for(ItemStack stack : ClientListener.stackList) { + if (stack.getItem().getName().getString().toLowerCase().contains(searchText)) + if (modText != null) { + if (getMod(stack).contains(modText)) { + view.add(stack); + } + } else { + view.add(stack); + } + } + } + page = 0; + fillSlots(); + } + + public void tick() { + controls.forEach(f -> f.tick()); + } + + public void setLastHovered(Control ctrl) { + lastHovered = ctrl; + } + + public Control getLastHovered() { + return lastHovered; + } + + private String getMod(ItemStack stack) { + if (stack != null && !stack.isEmpty()) { + ResourceLocation location = IRegistry.ITEM.getKey(stack.getItem()); + return location.getNamespace(); + } + return ""; + } +} diff --git a/src/main/java/me/shedaniel/gui/RecipeContainer.java b/src/main/java/me/shedaniel/gui/RecipeContainer.java new file mode 100755 index 000000000..f8605a45c --- /dev/null +++ b/src/main/java/me/shedaniel/gui/RecipeContainer.java @@ -0,0 +1,13 @@ +package me.shedaniel.gui; + + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; + +public class RecipeContainer extends Container { + + @Override + public boolean canInteractWith(EntityPlayer entityPlayer) { + return true; + } +} diff --git a/src/main/java/me/shedaniel/gui/RecipeGui.java b/src/main/java/me/shedaniel/gui/RecipeGui.java new file mode 100755 index 000000000..6cdd9542a --- /dev/null +++ b/src/main/java/me/shedaniel/gui/RecipeGui.java @@ -0,0 +1,218 @@ +package me.shedaniel.gui; + +import me.shedaniel.api.IDisplayCategory; +import me.shedaniel.api.IRecipe; +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Button; +import me.shedaniel.gui.widget.Control; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.inventory.Container; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class RecipeGui extends GuiContainer { + private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("almostenoughitems", "textures/gui/recipecontainer.png"); + private final MainWindow mainWindow; + private final Container container; + private final GuiScreen prevScreen; + private final Map<IDisplayCategory, List<IRecipe>> recipes; + private int guiWidth = 176; + private int guiHeight = 222; + ArrayList<IDisplayCategory> categories = new ArrayList<>(); + private int categoryPointer = 0; + private int recipePointer = 0; + private List<AEISlot> slots; + private int cycleCounter = 0; + private int[] itemPointer; + List<Control> controls = new LinkedList<>(); + + public RecipeGui(Container p_i1072_1_, GuiScreen prevScreen, Map<IDisplayCategory, List<IRecipe>> recipes) { + super(new RecipeContainer()); + this.container = p_i1072_1_; + this.prevScreen = prevScreen; + this.recipes = recipes; + this.mc = Minecraft.getInstance(); + this.itemRender = mc.getItemRenderer(); + this.fontRenderer = mc.fontRenderer; + this.mainWindow = Minecraft.getInstance().mainWindow; + + setupCategories(); + } + + private void setupCategories() { + categories.addAll(recipes.keySet()); + updateRecipe(); + } + + + @Override + public void render(int mouseX, int mouseY, float partialTicks) { + super.render(mouseX, mouseY, partialTicks); + int y = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); + drawCenteredString(this.fontRenderer, categories.get(categoryPointer).getDisplayName(), guiLeft + guiWidth / 2, y + 11, -1); + drawCenteredString(this.fontRenderer, String.format("%d/%d", 1 + getCurrentPage(), getTotalPages()), guiLeft + guiWidth / 2, y + 34, -1); + controls.forEach(Control::draw); + } + + private int getCurrentPage() { + return recipePointer / 2; + } + + @Override + public void tick() { + super.tick(); + slots.forEach(AEISlot::tick); + controls.forEach(Control::tick); + } + + + @Override + public void onResize(Minecraft p_onResize_1_, int p_onResize_2_, int p_onResize_3_) { + super.onResize(p_onResize_1_, p_onResize_2_, p_onResize_3_); + updateRecipe(); + } + + private void updateRecipe() { + IRecipe recipe = recipes.get(categories.get(categoryPointer)).get(recipePointer); + categories.get(categoryPointer).resetRecipes(); + categories.get(categoryPointer).addRecipe(recipe); + slots = categories.get(categoryPointer).setupDisplay(0); + if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) { + IRecipe recipe2 = recipes.get(categories.get(categoryPointer)).get(recipePointer + 1); + categories.get(categoryPointer).addRecipe(recipe2); + slots.addAll(categories.get(categoryPointer).setupDisplay(1)); + } + + guiLeft = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2)); + guiTop = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); + + for(AEISlot slot : slots) { + slot.move(guiLeft, guiTop); + } + + Button btnCategoryLeft = new Button(guiLeft + 10, guiTop + 5, 15, 20, "<"); + Button btnCategoryRight = new Button(guiLeft + guiWidth - 25, guiTop + 5, 15, 20, ">"); + btnCategoryRight.onClick = this::btnCategoryRight; + btnCategoryLeft.onClick = this::btnCategoryLeft; + + Button btnRecipeLeft = new Button(guiLeft + 10, guiTop + 28, 15, 20, "<"); + Button btnRecipeRight = new Button(guiLeft + guiWidth - 25, guiTop + 28, 15, 20, ">"); + btnRecipeLeft.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && recipePointer > 0); + btnRecipeRight.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && getCurrentPage() + 1 < getTotalPages()); + btnRecipeRight.onClick = this::btnRecipeRight; + btnRecipeLeft.onClick = this::btnRecipeLeft; + + controls.clear(); + controls.add(btnCategoryLeft); + controls.add(btnCategoryRight); + if (categories.size() <= 2) { + btnCategoryLeft.setEnabled(false); + btnCategoryRight.setEnabled(false); + } + + controls.add(btnRecipeLeft); + controls.add(btnRecipeRight); + + itemPointer = new int[9]; + for(int i = 0; i < itemPointer.length; i++) { + itemPointer[i] = 0; + } + + List<Control> newControls = new LinkedList<>(); + categories.get(categoryPointer).addWidget(newControls, 0); + if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) { + categories.get(categoryPointer).addWidget(newControls, 1); + } + newControls.forEach(f -> f.move(guiLeft, guiTop)); + controls.addAll(newControls); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float v, int i, int i1) { + drawDefaultBackground(); + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(CHEST_GUI_TEXTURE); + + int lvt_4_1_ = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2)); + int lvt_5_1_ = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); + + this.drawTexturedModalRect(lvt_4_1_, lvt_5_1_, 0, 0, this.guiWidth, this.guiHeight); + slots.forEach(AEISlot::draw); + } + + + @Override + protected void initGui() { + super.initGui(); + } + + @Override + public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) { + if (p_keyPressed_1_ == 259 && prevScreen != null && AEIRenderHelper.focusedControl == null) { + Minecraft.getInstance().displayGuiScreen(prevScreen); + return true; + } + + return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + } + + private boolean btnCategoryLeft(int button) { + recipePointer = 0; + categoryPointer--; + if (categoryPointer < 0) { + categoryPointer = categories.size() - 1; + } + updateRecipe(); + return true; + } + + private boolean btnCategoryRight(int button) { + recipePointer = 0; + categoryPointer++; + if (categoryPointer >= categories.size()) { + categoryPointer = 0; + } + updateRecipe(); + return true; + } + + private boolean btnRecipeLeft(int button) { + recipePointer -= 2; + if (recipePointer < 0) { + recipePointer = (getTotalPages() - 1) * 2; + } + updateRecipe(); + return true; + } + + private boolean btnRecipeRight(int button) { + recipePointer += 2; + if (recipePointer >= recipes.get(categories.get(categoryPointer)).size()) { + recipePointer = 0; + } + updateRecipe(); + return true; + } + + private int riseDoublesToInt(double i) { + return (int) (i + (i % 1 == 0 ? 0 : 1)); + } + + private int getTotalPages() { + return MathHelper.clamp(riseDoublesToInt(recipes.get(categories.get(categoryPointer)).size() / 2), 1, Integer.MAX_VALUE); + } +} diff --git a/src/main/java/me/shedaniel/gui/widget/AEISlot.java b/src/main/java/me/shedaniel/gui/widget/AEISlot.java new file mode 100755 index 000000000..bc3569699 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/AEISlot.java @@ -0,0 +1,181 @@ +package me.shedaniel.gui.widget; + +import com.google.common.collect.Lists; +import me.shedaniel.gui.AEIRenderHelper; +import me.shedaniel.listenerdefinitions.IMixinGuiContainer; +import me.shedaniel.network.CheatPacket; +import me.shedaniel.network.DeletePacket; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.IRegistry; + +import java.awt.*; +import java.util.LinkedList; +import java.util.List; + +/** + * Created by James on 7/28/2018. + */ +public class AEISlot extends Control { + private static final ResourceLocation RECIPE_GUI = new ResourceLocation("almostenoughitems", "textures/gui/recipecontainer.png"); + private boolean cheatable = false; + private List<ItemStack> itemList = new LinkedList<>(); + private int itemListPointer = 0; + private long displayCounter = 0; + + public boolean isDrawBackground() { + return drawBackground; + } + + private String extraTooltip; + + + @Override + public void tick() { + if (itemList.size() > 1) { + displayCounter++; + if (displayCounter % 10 == 0) + if (itemListPointer + 1 >= itemList.size()) + itemListPointer = 0; + else itemListPointer++; + } + } + + public void setStackList(List<ItemStack> newItemList) { + itemList = newItemList; + itemListPointer = 0; + displayCounter = 0; + } + + public void setExtraTooltip(String toolTip) { + extraTooltip = toolTip; + } + + public void setDrawBackground(boolean drawBackground) { + this.drawBackground = drawBackground; + } + + private boolean drawBackground = false; + private Point backgroundUV = new Point(0, 222); + + public AEISlot(int x, int y) { + super(x, y, |
