diff --git a/src/main/java/me/towdium/jecalculation/data/label/ILabel.java b/src/main/java/me/towdium/jecalculation/data/label/ILabel.java index 7140303..ed5556d 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/ILabel.java +++ b/src/main/java/me/towdium/jecalculation/data/label/ILabel.java @@ -42,12 +42,8 @@ public interface ILabel { ILabel increaseAmount(); - ILabel increaseAmountLarge(); - ILabel decreaseAmount(); - ILabel decreaseAmountLarge(); - ILabel invertAmount(); int getAmount(); @@ -73,7 +69,7 @@ public interface ILabel { String getDisplayName(); - List getToolTip(List existing, boolean detailed); + void getToolTip(List existing, boolean detailed); ILabel copy(); @@ -244,21 +240,11 @@ public interface ILabel { return this; } - @Override - public ILabel increaseAmountLarge() { - return this; - } - @Override public ILabel decreaseAmount() { return this; } - @Override - public ILabel decreaseAmountLarge() { - return this; - } - @Override public ILabel invertAmount() { return this; @@ -285,8 +271,7 @@ public interface ILabel { } @Override - public List getToolTip(List existing, boolean detailed) { - return new ArrayList<>(); + public void getToolTip(List existing, boolean detailed) { } @Override @@ -348,12 +333,6 @@ public interface ILabel { return this; } - @Override - public ILabel increaseAmountLarge() { - setAmount(getAmount() + 10 * getMultiplier()); - return this; - } - @Override public ILabel decreaseAmount() { if (getAmount() <= getMultiplier()) return ILabel.EMPTY; @@ -363,15 +342,6 @@ public interface ILabel { } } - @Override - public ILabel decreaseAmountLarge() { - if (getAmount() <= 10 * getMultiplier()) return ILabel.EMPTY; - else { - setAmount(getAmount() - 10 * getMultiplier()); - return this; - } - } - @Override public ILabel invertAmount() { setAmount(-getAmount()); @@ -380,10 +350,9 @@ public interface ILabel { @Override @SideOnly(Side.CLIENT) - public List getToolTip(List existing, boolean detailed) { + public void getToolTip(List existing, boolean detailed) { if (detailed) existing.add(FORMAT_GREY + Utilities.I18n.format("label.common.tooltip.amount", getAmountString())); - return existing; } @Override diff --git a/src/main/java/me/towdium/jecalculation/data/label/labels/LFluidStack.java b/src/main/java/me/towdium/jecalculation/data/label/labels/LFluidStack.java index a9d5ca7..051dfc5 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/labels/LFluidStack.java +++ b/src/main/java/me/towdium/jecalculation/data/label/labels/LFluidStack.java @@ -102,11 +102,10 @@ public class LFluidStack extends ILabel.Impl { @Override @SideOnly(Side.CLIENT) - public List getToolTip(List existing, boolean detailed) { + public void getToolTip(List existing, boolean detailed) { if (detailed) existing.add(FORMAT_GREY + Utilities.I18n.format("label.common.tooltip.amount", Integer.toString(getAmount())) + "mB"); existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(fluid)); - return existing; } diff --git a/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java b/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java index 9ed6ccd..b700b36 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java +++ b/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java @@ -83,10 +83,9 @@ public class LItemStack extends ILabel.Impl { @Override @SideOnly(Side.CLIENT) - public List getToolTip(List existing, boolean detailed) { + public void getToolTip(List existing, boolean detailed) { super.getToolTip(existing, detailed); existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(item)); - return existing; } @Override diff --git a/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java b/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java index 85b4055..9bd78da 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java +++ b/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java @@ -163,10 +163,9 @@ public class LOreDict extends ILabel.Impl { @Override @SideOnly(Side.CLIENT) - public List getToolTip(List existing, boolean detailed) { + public void getToolTip(List existing, boolean detailed) { super.getToolTip(existing, detailed); existing.add(FORMAT_BLUE + FORMAT_ITALIC + JustEnoughCalculation.Reference.MODNAME); - return existing; } @Override diff --git a/src/main/java/me/towdium/jecalculation/data/label/labels/LPlaceholder.java b/src/main/java/me/towdium/jecalculation/data/label/labels/LPlaceholder.java index fba735d..49e0646 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/labels/LPlaceholder.java +++ b/src/main/java/me/towdium/jecalculation/data/label/labels/LPlaceholder.java @@ -100,9 +100,8 @@ public class LPlaceholder extends ILabel.Impl { @Override @SideOnly(Side.CLIENT) - public List getToolTip(List existing, boolean detailed) { + public void getToolTip(List existing, boolean detailed) { super.getToolTip(existing, detailed); existing.add(FORMAT_BLUE + FORMAT_ITALIC + JustEnoughCalculation.Reference.MODNAME); - return existing; } } diff --git a/src/main/java/me/towdium/jecalculation/gui/IWPicker.java b/src/main/java/me/towdium/jecalculation/gui/IWPicker.java index edf1952..66f1aeb 100644 --- a/src/main/java/me/towdium/jecalculation/gui/IWPicker.java +++ b/src/main/java/me/towdium/jecalculation/gui/IWPicker.java @@ -22,7 +22,7 @@ public interface IWPicker extends IWidget { protected Consumer callback; @Override - public IWPicker setCallback(Consumer callback) { + public Impl setCallback(Consumer callback) { this.callback = callback; return this; } diff --git a/src/main/java/me/towdium/jecalculation/gui/IWidget.java b/src/main/java/me/towdium/jecalculation/gui/IWidget.java index e3ac380..79518b3 100644 --- a/src/main/java/me/towdium/jecalculation/gui/IWidget.java +++ b/src/main/java/me/towdium/jecalculation/gui/IWidget.java @@ -1,8 +1,14 @@ package me.towdium.jecalculation.gui; +import java.util.List; + public interface IWidget { void onDraw(JecaGui gui, int xMouse, int yMouse); + default boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List tooltip) { + return false; + } + default boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) { return false; } diff --git a/src/main/java/me/towdium/jecalculation/gui/JecaGui.java b/src/main/java/me/towdium/jecalculation/gui/JecaGui.java index eff7676..b17260b 100644 --- a/src/main/java/me/towdium/jecalculation/gui/JecaGui.java +++ b/src/main/java/me/towdium/jecalculation/gui/JecaGui.java @@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.JustEnoughCalculation; import me.towdium.jecalculation.data.label.ILabel; +import me.towdium.jecalculation.gui.drawables.WContainer; import me.towdium.jecalculation.nei.NEIPlugin; import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager; import me.towdium.jecalculation.utils.IllegalPositionException; @@ -46,15 +47,14 @@ public class JecaGui extends GuiContainer { public static final int COLOR_TEXT_WHITE = 0xFFFFFF; public static final boolean ALWAYS_TOOLTIP = false; public ILabel hand = ILabel.EMPTY; - public IWidget root; + public WContainer root; protected JecaGui parent; - protected List>> tooltipBuffer = new ArrayList<>(); - public JecaGui(@Nullable JecaGui parent, IWidget root) { + public JecaGui(@Nullable JecaGui parent, WContainer root) { this(parent, false, root); } - public JecaGui(@Nullable JecaGui parent, boolean acceptsTransfer, IWidget root) { + public JecaGui(@Nullable JecaGui parent, boolean acceptsTransfer, WContainer root) { super(acceptsTransfer ? new ContainerTransfer() : new ContainerNonTransfer()); this.parent = parent; this.root = root; @@ -66,11 +66,11 @@ public class JecaGui extends GuiContainer { return xMouse > xPos && yMouse > yPos && xMouse <= xPos + xSize && yMouse <= yPos + ySize; } - public static void displayGui(IWidget root) { + public static void displayGui(WContainer root) { displayGui(true, false, root); } - public static void displayGui(boolean updateParent, boolean acceptsTransfer, IWidget root) { + public static void displayGui(boolean updateParent, boolean acceptsTransfer, WContainer root) { // isCallingFromMinecraftThread if (Minecraft.getMinecraft().func_152345_ab()) displayGuiUnsafe(updateParent, acceptsTransfer, root); @@ -88,7 +88,7 @@ public class JecaGui extends GuiContainer { return ret; } - private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, IWidget root) { + private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, WContainer root) { Minecraft mc = Minecraft.getMinecraft(); JecaGui parent; if (mc.currentScreen == null) @@ -137,7 +137,9 @@ public class JecaGui extends GuiContainer { GlStateManager.translate(0, 0, 80); hand.drawLabel(this, mouseX, mouseY, true); GlStateManager.popMatrix(); - drawBufferedTooltip(); + List tooltip = new ArrayList<>(); + root.onTooltip(this, mouseX - guiLeft, mouseY - guiTop, tooltip); + drawHoveringText(tooltip, mouseX, mouseY); GlStateManager.enableLighting(); GlStateManager.enableDepth(); } @@ -363,23 +365,6 @@ public class JecaGui extends GuiContainer { drawText(xPos, yPos + yOffset, xSize, f, text); } - public void drawTooltip(int xPos, int yPos, String... text) { - drawTooltip(xPos, yPos, Arrays.asList(text)); - } - - public void drawTooltip(int xPos, int yPos, List text) { - tooltipBuffer.add(new Triple<>(xPos + guiLeft, yPos + guiTop, text)); - } - - protected void drawBufferedTooltip() { - tooltipBuffer.forEach(i -> { - drawHoveringText(i.three, i.one, i.two); - GlStateManager.disableLighting(); - GlStateManager.disableDepth(); - }); - tooltipBuffer.clear(); - } - public void drawItemStack(int xPos, int yPos, ItemStack is, boolean centred) { if (is.getItem() == null) { return; diff --git a/src/main/java/me/towdium/jecalculation/gui/Resource.java b/src/main/java/me/towdium/jecalculation/gui/Resource.java index 69be70d..8ec7a34 100644 --- a/src/main/java/me/towdium/jecalculation/gui/Resource.java +++ b/src/main/java/me/towdium/jecalculation/gui/Resource.java @@ -31,12 +31,25 @@ public class Resource { public static final Resource BTN_DEL_F = new Resource(70, 0, 14, 14); public static final Resource BTN_YES_N = new Resource(84, 14, 14, 14); public static final Resource BTN_YES_F = new Resource(84, 0, 14, 14); + public static final Resource BTN_YES_D = new Resource(228, 14, 14, 14); public static final Resource BTN_NO_N = new Resource(98, 14, 14, 14); public static final Resource BTN_NO_F = new Resource(98, 0, 14, 14); public static final Resource BTN_NO_D = new Resource(228, 0, 14, 14); public static final Resource BTN_DISAMB_N = new Resource(112, 14, 14, 14); public static final Resource BTN_DISAMB_F = new Resource(112, 0, 14, 14); public static final Resource BTN_DISAMB_D = new Resource(242, 0, 14, 14); + public static final Resource BTN_IN_N = new Resource(126, 14, 14, 14); + public static final Resource BTN_IN_F = new Resource(126, 0, 14, 14); + public static final Resource BTN_IN_D = new Resource(200, 0, 14, 14); + public static final Resource BTN_OUT_N = new Resource(140, 14, 14, 14); + public static final Resource BTN_OUT_F = new Resource(140, 0, 14, 14); + public static final Resource BTN_OUT_D = new Resource(214, 0, 14, 14); + public static final Resource BTN_CAT_N = new Resource(154, 14, 14, 14); + public static final Resource BTN_CAT_F = new Resource(154, 0, 14, 14); + public static final Resource BTN_CAT_D = new Resource(200, 14, 14, 14); + public static final Resource BTN_LIST_N = new Resource(168, 14, 14, 14); + public static final Resource BTN_LIST_F = new Resource(168, 0, 14, 14); + public static final Resource BTN_LIST_D = new Resource(214, 14, 14, 14); public static final Resource WGT_BUTTON_N = new Resource(40, 232, 20, 20); public static final Resource WGT_BUTTON_F = new Resource(60, 232, 20, 20); public static final Resource WGT_BUTTON_D = new Resource(80, 232, 20, 20); diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WContainer.java b/src/main/java/me/towdium/jecalculation/gui/drawables/WContainer.java index a6f72bf..f8431bb 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WContainer.java +++ b/src/main/java/me/towdium/jecalculation/gui/drawables/WContainer.java @@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.IWidget; +import me.towdium.jecalculation.utils.Utilities; import javax.annotation.ParametersAreNonnullByDefault; import java.util.ArrayList; @@ -16,7 +17,6 @@ import java.util.List; @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) public class WContainer implements IWidget { - boolean modified = false; protected List widgets = new ArrayList<>(); public void add(IWidget w) { @@ -63,4 +63,11 @@ public class WContainer implements IWidget { for (IWidget w : widgets) if (w.onScroll(gui, xMouse, yMouse, diff)) return true; return false; } + + @Override + public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List tooltip) { + Utilities.ReversedIterator i = new Utilities.ReversedIterator<>(widgets); + while (i.hasNext()) if (i.next().onTooltip(gui, xMouse, yMouse, tooltip)) return true; + return false; + } } diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WLabel.java b/src/main/java/me/towdium/jecalculation/gui/drawables/WLabel.java index bc98eb8..66bcbbe 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WLabel.java +++ b/src/main/java/me/towdium/jecalculation/gui/drawables/WLabel.java @@ -2,16 +2,16 @@ package me.towdium.jecalculation.gui.drawables; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; -import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.utils.IllegalPositionException; import me.towdium.jecalculation.utils.Utilities; +import org.lwjgl.input.Keyboard; import javax.annotation.ParametersAreNonnullByDefault; -import java.util.ArrayList; -import java.util.Arrays; +import java.util.List; import java.util.stream.IntStream; /** @@ -49,8 +49,8 @@ public class WLabel implements IWidget { public void setLabel(ILabel label) { this.label = label; -// if (mode == enumMode.EDITOR || mode == enumMode.SELECTOR) -// notifyLsnr(); + // if (mode == enumMode.EDITOR || mode == enumMode.SELECTOR) + // notifyLsnr(); } @Override @@ -58,16 +58,11 @@ public class WLabel implements IWidget { gui.drawResourceContinuous(Resource.WGT_SLOT, xPos, yPos, xSize, ySize, 3, 3, 3, 3); label.drawLabel(gui, xPos + xSize / 2, yPos + ySize / 2, true); if (mode == enumMode.RESULT || mode == enumMode.EDITOR) - gui.drawText(xPos + xSize / 2.0f + 7.5f, yPos + ySize / 2 + 7 - - (int) (font.size * gui.getFontRenderer().FONT_HEIGHT), font, label.getAmountString()); + gui.drawText(xPos + xSize / 2.0f + 7.5f, + yPos + ySize / 2 + 7 - (int) (font.size * gui.getFontRenderer().FONT_HEIGHT), font, + label.getAmountString()); if (mouseIn(xMouse, yMouse)) { gui.drawRectangle(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF); - if (label != ILabel.EMPTY) { - ArrayList buf = new ArrayList<>(); - buf.add(label.getDisplayName()); - gui.drawTooltip(xMouse, yMouse, - label.getToolTip(buf, mode == enumMode.EDITOR || mode == enumMode.RESULT)); - } } if (mode == enumMode.EDITOR || mode == enumMode.SELECTOR) { timer.setState(gui.hand != ILabel.EMPTY); @@ -76,16 +71,26 @@ public class WLabel implements IWidget { } } + @Override + public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List tooltip) { + if (mouseIn(xMouse, yMouse)) { + if (label != ILabel.EMPTY) { + tooltip.add(label.getDisplayName()); + label.getToolTip(tooltip, mode == enumMode.EDITOR || mode == enumMode.RESULT); + } + } + return false; + } + @Override public boolean onScroll(JecaGui gui, int xMouse, int yMouse, int diff) { if (mouseIn(xMouse, yMouse) && mode == enumMode.EDITOR && label != ILabel.EMPTY) { - IntStream.range(0, Math.abs(diff)).forEach(i -> { - if (JecaGui.isShiftDown()) label = diff > 0 ? label.increaseAmountLarge() : label.decreaseAmountLarge(); - else label = diff > 0 ? label.increaseAmount() : label.decreaseAmount(); - }); + IntStream.range(0, Math.abs(diff)) + .forEach(i -> label = diff > 0 ? label.increaseAmount() : label.decreaseAmount()); notifyLsnr(); return true; - } else return false; + } else + return false; } @@ -101,18 +106,18 @@ public class WLabel implements IWidget { return true; } else if (label != label.EMPTY) { if (button == 0) { - if (JecaGui.isShiftDown()) - label = label.increaseAmountLarge(); - else + if (JecaGui.isShiftDown()) gui.root.add(new WAmount()); + else { label = label.increaseAmount(); - notifyLsnr(); + notifyLsnr(); + } return true; } else if (button == 1) { - if (JecaGui.isShiftDown()) - label = label.decreaseAmountLarge(); - else + if (JecaGui.isShiftDown()) gui.root.add(new WAmount()); + else { label = label.decreaseAmount(); - notifyLsnr(); + notifyLsnr(); + } return true; } } else @@ -149,7 +154,8 @@ public class WLabel implements IWidget { } void notifyLsnr() { - if (lsnrUpdate != null) lsnrUpdate.run(); + if (lsnrUpdate != null) + lsnrUpdate.run(); } @@ -171,4 +177,49 @@ public class WLabel implements IWidget { */ SELECTOR } + + class WAmount extends WContainer { + public WAmount() { + WLabel w = WLabel.this; + int xAlign = w.xPos + w.xSize; + WLabel wl = new WLabel(w.xPos, w.yPos, w.xSize, w.ySize, enumMode.SELECTOR); + wl.setLabel(w.getLabel()); + WTextField wtf = new WTextField(xAlign + 10, w.yPos + w.ySize / 2 - WTextField.HEIGHT / 2, 50); + WButton wby = new WButtonIcon(xAlign + 60, w.yPos, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F, + Resource.BTN_YES_D).setListenerLeft(() -> { + w.setLabel(wl.getLabel().setAmount( + wtf.getText().isEmpty() ? 0 : Integer.parseInt(wtf.getText()))); + JecaGui.getCurrent().root.remove(this); + }); + WButton wbn = new WButtonIcon(xAlign + 79, w.yPos, 20, 20, Resource.BTN_NO_N, Resource.BTN_NO_F) + .setListenerLeft(() -> { + w.setLabel(ILabel.EMPTY); + JecaGui.getCurrent().root.remove(this); + }); + wtf.setText(Integer.toString(w.getLabel().getAmount())); + wtf.setLsnrText(i -> { + try { + Integer.parseInt(wtf.getText()); + wtf.setColor(JecaGui.COLOR_TEXT_WHITE); + wby.setDisabled(false); + } catch (NumberFormatException e) { + boolean acceptable = wtf.getText().isEmpty(); + wtf.setColor(acceptable ? JecaGui.COLOR_TEXT_WHITE : JecaGui.COLOR_TEXT_RED); + wby.setDisabled(!acceptable); + } + }); + add(new WPanel(w.xPos - 5, w.yPos - 5, w.xSize + 110, w.ySize + 10)); + add(new WText(xAlign + 3, w.yPos + 5, JecaGui.Font.DEFAULT_NO_SHADOW, "x")); + addAll(wl, wtf, wby, wbn); + } + + @Override + public boolean onKey(JecaGui gui, char ch, int code) { + if (super.onKey(gui, ch, code)) return true; + if (code == Keyboard.KEY_ESCAPE) { + gui.root.remove(this); + return true; + } else return false; + } + } } diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WPage.java b/src/main/java/me/towdium/jecalculation/gui/drawables/WPage.java index 965067f..18b63a6 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WPage.java +++ b/src/main/java/me/towdium/jecalculation/gui/drawables/WPage.java @@ -2,13 +2,15 @@ package me.towdium.jecalculation.gui.drawables; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import me.towdium.jecalculation.data.label.ILabel; +import me.towdium.jecalculation.data.label.ILabel.RegistryEditor.Record; import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; -import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.utils.Utilities; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; /** * Author: towdium @@ -17,15 +19,13 @@ import javax.annotation.ParametersAreNonnullByDefault; @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) public class WPage implements IWidget { - - protected int index; protected ILabel.RegistryEditor.Record record; protected Utilities.Timer timer = new Utilities.Timer(); protected boolean focused; protected Runnable listener; - public WPage(int index, ILabel.RegistryEditor.Record record, boolean focused) { + public WPage(int index, Record record, boolean focused) { this.index = index; this.record = record; this.focused = focused; @@ -33,22 +33,29 @@ public class WPage implements IWidget { @Override public void onDraw(JecaGui gui, int xMouse, int yMouse) { - Resource resource = focused ? (index == 0 ? Resource.WGT_PAGER_F0 : Resource.WGT_PAGER_FN) - : Resource.WGT_PAGER_N; + Resource resource = focused ? + (index == 0 ? Resource.WGT_PAGER_F0 : Resource.WGT_PAGER_FN) : + Resource.WGT_PAGER_N; gui.drawResourceContinuous(resource, index * 24, -21, 24, 25, 4, 4, 4, 4); record.representation.drawLabel(gui, index * 24 + 4, -17, false); timer.setState(JecaGui.mouseIn(index * 24, -21, 24, 21, xMouse, yMouse)); - if (timer.getTime() > 1000) - gui.drawTooltip(xMouse, yMouse, Utilities.I18n.format("gui." + record.localizeKey)); } @Override public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) { boolean ret = JecaGui.mouseIn(index * 24, -21, 24, 21, xMouse, yMouse) && listener != null && !focused; - if (ret) listener.run(); + if (ret) + listener.run(); return ret; } + @Override + public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List tooltip) { + if (timer.getTime() > 1000 && !focused) + tooltip.add(Utilities.I18n.format("gui." + record.localizeKey)); + return false; + } + public WPage setListener(Runnable r) { listener = r; return this; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WPanel.java b/src/main/java/me/towdium/jecalculation/gui/drawables/WPanel.java index 81d5e31..c9fa992 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WPanel.java +++ b/src/main/java/me/towdium/jecalculation/gui/drawables/WPanel.java @@ -7,6 +7,7 @@ import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; /** * Author: towdium @@ -16,8 +17,33 @@ import javax.annotation.ParametersAreNonnullByDefault; @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) public class WPanel implements IWidget { + int xPos, yPos, xSize, ySize; + + public WPanel(int xPos, int yPos, int xSize, int ySize) { + this.xPos = xPos; + this.yPos = yPos; + this.xSize = xSize; + this.ySize = ySize; + } + + public WPanel() { + this(0, 0, 176, 166); + } + + @Override public void onDraw(JecaGui gui, int xMouse, int yMouse) { - gui.drawResourceContinuous(Resource.WGT_PANEL, 0, 0, gui.getXSize(), gui.getYSize(), 5, 5, 5, 5); + gui.drawResourceContinuous(Resource.WGT_PANEL, xPos, yPos, xSize, ySize, 5, 5, 5, 5); + } + + @Override + public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List tooltip) { + return mouseIn(xMouse, yMouse); + } + + public boolean mouseIn(int x, int y) { + int xx = x - xPos; + int yy = y - yPos; + return xx >= 0 && xx < xSize && yy >= 0 && yy < ySize; } } diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WTextField.java b/src/main/java/me/towdium/jecalculation/gui/drawables/WTextField.java index 6d59da5..4c6e87e 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WTextField.java +++ b/src/main/java/me/towdium/jecalculation/gui/drawables/WTextField.java @@ -20,6 +20,7 @@ public class WTextField implements IWidget { public Consumer lsnrText; protected int xPos, yPos, xSize; GuiTextField textField; + public static final int HEIGHT = 20; public WTextField(int xPos, int yPos, int xSize) { this.xPos = xPos; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WTooltip.java b/src/main/java/me/towdium/jecalculation/gui/drawables/WTooltip.java index 40fec9e..fc58875 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WTooltip.java +++ b/src/main/java/me/towdium/jecalculation/gui/drawables/WTooltip.java @@ -28,15 +28,18 @@ public abstract class WTooltip implements IWidget { @Override public void onDraw(JecaGui gui, int xMouse, int yMouse) { - if (name != null) { - timer.setState(mouseIn(xMouse, yMouse)); - if (timer.getTime() > 500) { - String str = getSuffix().stream().map(s -> Utilities.I18n.search(String.join(".", "gui", name, s))) - .filter(p -> p.two).findFirst().map(p -> p.one) - .orElse(JecaGui.ALWAYS_TOOLTIP ? String.join(".", "gui", name, getSuffix().get(0)) : null); - if (str != null) gui.drawTooltip(xMouse, yMouse, str); - } + if (name != null) timer.setState(mouseIn(xMouse, yMouse)); + } + + @Override + public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List tooltip) { + if (timer.getTime() > 500) { + String str = getSuffix().stream().map(s -> Utilities.I18n.search(String.join(".", "gui", name, s))) + .filter(p -> p.two).findFirst().map(p -> p.one) + .orElse(JecaGui.ALWAYS_TOOLTIP ? String.join(".", "gui", name, getSuffix().get(0)) : null); + if (str != null) tooltip.add(str); } + return false; } protected List getSuffix() { diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java index 38e3d14..122a48f 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java @@ -20,8 +20,21 @@ import java.util.List; public class GuiCalculator extends WContainer { WLabelGroup wRecent = new WLabelGroup(7, 31, 8, 1, WLabel.enumMode.PICKER); WLabel wLabel = new WLabel(31, 7, 20, 20, WLabel.enumMode.SELECTOR); + WButton btnSteps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST_N, Resource.BTN_LIST_F, + Resource.BTN_LIST_D, "calculator.step").setListenerLeft(() -> setMode(enumMode.STEPS)); + WButton btnCatalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT_N, Resource.BTN_CAT_F, + Resource.BTN_CAT_D, "calculator.catalyst").setListenerLeft(() -> setMode(enumMode.CATALYST)); + WButton btnOutput = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT_N, Resource.BTN_OUT_F, + Resource.BTN_OUT_D, "calculator.output").setListenerLeft(() -> setMode(enumMode.OUTPUT)); + WButton btnInput = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN_N, Resource.BTN_IN_F, + Resource.BTN_IN_D, "calculator.input").setListenerLeft(() -> setMode(enumMode.INPUT)); public GuiCalculator() { + wLabel.setLsnrUpdate(() -> { + Controller.setRecent(wLabel.label); + refreshRecent(); + }); + wRecent.setLsnrUpdate(l -> JecaGui.getCurrent().hand = wRecent.getLabelAt(l)); add(new WPanel()); add(new WTextField(61, 7, 64)); add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "calculator.label") @@ -33,25 +46,27 @@ public class GuiCalculator extends WContainer { .setListenerLeft(() -> JecaGui.displayGui(true, true, new GuiRecipe()))); add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH_N, Resource.BTN_SEARCH_F, "calculator.search") .setListenerLeft(() -> JecaGui.displayGui(new GuiSearch()))); - add(new WLabelGroup(7, 87, 9, 4, WLabel.enumMode.RESULT)); - add(wRecent); - add(wLabel); - add(new WLine(52)); + add(new WLine(55)); add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT_N, Resource.ICN_RECENT_F, "calculator.history")); - add(new WSwitcher(7, 56, 162, 5)); - refresh(); - List recent = Controller.getRecent(); - if (recent.size() > 0) wLabel.setLabel(Controller.getRecent().get(0)); - wLabel.setLsnrUpdate(() -> { - Controller.setRecent(wLabel.label); - refresh(); - }); - wRecent.setLsnrUpdate(l -> JecaGui.getCurrent().hand = wRecent.getLabelAt(l)); + add(new WLabelScroll(7, 87, 8, 4, WLabel.enumMode.RESULT, true)); + addAll(wRecent, wLabel, btnInput, btnOutput, btnCatalyst, btnSteps); + refreshRecent(); + setMode(enumMode.INPUT); } - void refresh() { + void setMode(enumMode mode) { + btnInput.setDisabled(mode == enumMode.INPUT); + btnOutput.setDisabled(mode == enumMode.OUTPUT); + btnCatalyst.setDisabled(mode == enumMode.CATALYST); + btnSteps.setDisabled(mode == enumMode.STEPS); + } + + void refreshRecent() { List recent = Controller.getRecent(); - if (recent.size() > 1) - wRecent.setLabel(recent.subList(1, recent.size()), 0); + if (recent.size() > 1) wRecent.setLabel(recent.subList(1, recent.size()), 0); + } + + enum enumMode { + INPUT, OUTPUT, CATALYST, STEPS } } diff --git a/src/main/resources/assets/jecalculation/textures/gui/resources.png b/src/main/resources/assets/jecalculation/textures/gui/resources.png index c8551fd..8dc55ec 100644 Binary files a/src/main/resources/assets/jecalculation/textures/gui/resources.png and b/src/main/resources/assets/jecalculation/textures/gui/resources.png differ