diff --git a/art/gui_calculator.xcf b/art/gui_calculator.xcf new file mode 100644 index 0000000..fe6fab3 Binary files /dev/null and b/art/gui_calculator.xcf differ diff --git a/art/gui_editor.xcf b/art/gui_editor.xcf new file mode 100644 index 0000000..b7e9bd4 Binary files /dev/null and b/art/gui_editor.xcf differ diff --git a/art/item_label_universal.xcf b/art/item_label_universal.xcf new file mode 100644 index 0000000..d2f0b14 Binary files /dev/null and b/art/item_label_universal.xcf differ diff --git a/art/resources.xcf b/art/resources.xcf new file mode 100644 index 0000000..4628893 Binary files /dev/null and b/art/resources.xcf differ diff --git a/src/main/java/me/towdium/jecalculation/client/gui/JecGui.java b/src/main/java/me/towdium/jecalculation/client/gui/JecGui.java index a95cbd1..51397a3 100644 --- a/src/main/java/me/towdium/jecalculation/client/gui/JecGui.java +++ b/src/main/java/me/towdium/jecalculation/client/gui/JecGui.java @@ -85,7 +85,7 @@ public class JecGui extends GuiContainer { @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { - drawResourceContinuous(Resource.WIDGET_PANEL, guiLeft, guiTop, xSize, ySize, 5, 5, 5, 5); + drawResourceContinuous(Resource.WGT_PANEL, guiLeft, guiTop, xSize, ySize, 5, 5, 5, 5); } @Override @@ -98,46 +98,49 @@ public class JecGui extends GuiContainer { protected void keyTyped(char typedChar, int keyCode) { if (!wgtMgr.onKey(typedChar, keyCode)) { if (keyCode == Keyboard.KEY_ESCAPE) { - if (hand != Entry.EMPTY) hand = Entry.EMPTY; - else if (parent != null) Minecraft.getMinecraft().displayGuiScreen(parent); - else super.keyTyped(typedChar, keyCode); + if (hand != Entry.EMPTY) + hand = Entry.EMPTY; + else if (parent != null) + Minecraft.getMinecraft().displayGuiScreen(parent); + else + super.keyTyped(typedChar, keyCode); } } } -// /** -// * @return if the event is canceled -// * This function handles click outside the normal region, -// * especially the overlap with JEI overlay. It handles -// * mouse event before JEI. -// */ -// public boolean handleMouseEvent() { -// int xMouse = Mouse.getEventX() * this.width / this.mc.displayWidth; -// int yMouse = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; -// if (Mouse.getEventButtonState()) { -// if (Mouse.getEventButton() == 0) { -// if (hand == Entry.EMPTY) { -// // TODO -// Entry e = JecPlugin.getEntryUnderMouse(); -// if (e != Entry.EMPTY) { -// hand = e; -// return true; -// } -// } else { -// if (!mouseIn(guiLeft, guiTop, width, height, xMouse, yMouse)) { -// hand = Entry.EMPTY; -// return true; -// } -// } -// } else if (Mouse.getEventButton() == 1) { -// if (hand != Entry.EMPTY) { -// hand = Entry.EMPTY; -// return true; -// } -// } -// } -// return false; -// } + // /** + // * @return if the event is canceled + // * This function handles click outside the normal region, + // * especially the overlap with JEI overlay. It handles + // * mouse event before JEI. + // */ + // public boolean handleMouseEvent() { + // int xMouse = Mouse.getEventX() * this.width / this.mc.displayWidth; + // int yMouse = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; + // if (Mouse.getEventButtonState()) { + // if (Mouse.getEventButton() == 0) { + // if (hand == Entry.EMPTY) { + // // TODO + // Entry e = JecPlugin.getEntryUnderMouse(); + // if (e != Entry.EMPTY) { + // hand = e; + // return true; + // } + // } else { + // if (!mouseIn(guiLeft, guiTop, width, height, xMouse, yMouse)) { + // hand = Entry.EMPTY; + // return true; + // } + // } + // } else if (Mouse.getEventButton() == 1) { + // if (hand != Entry.EMPTY) { + // hand = Entry.EMPTY; + // return true; + // } + // } + // } + // return false; + // } public FontRenderer getFontRenderer() { return fontRendererObj; @@ -147,27 +150,47 @@ public class JecGui extends GuiContainer { drawTexture(r.getResourceLocation(), xPos, yPos, r.getXPos(), r.getYPos(), r.getXSize(), r.getYSize()); } - public void drawResourceContinuous( - Resource r, int xPos, int yPos, int xSize, int ySize, - int borderTop, int borderBottom, int borderLeft, int borderRight) { - drawTextureContinuous(r.getResourceLocation(), xPos, yPos, xSize, ySize, - r.getXPos(), r.getYPos(), r.getXSize(), r.getYSize(), - borderTop, borderBottom, borderLeft, borderRight); + public void drawResourceContinuous(Resource r, + int xPos, + int yPos, + int xSize, + int ySize, + int borderTop, + int borderBottom, + int borderLeft, + int borderRight) { + drawTextureContinuous(r.getResourceLocation(), xPos, yPos, xSize, ySize, r.getXPos(), r.getYPos(), r.getXSize(), + r.getYSize(), borderTop, borderBottom, borderLeft, borderRight); } - public void drawTexture(ResourceLocation l, int destXPos, int destYPos, - int sourceXPos, int sourceYPos, int sourceXSize, int sourceYSize) { + public void drawTexture(ResourceLocation l, + int destXPos, + int destYPos, + int sourceXPos, + int sourceYPos, + int sourceXSize, + int sourceYSize) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(l); this.drawTexturedModalRect(destXPos, destYPos, sourceXPos, sourceYPos, sourceXSize, sourceYSize); } - public void drawTextureContinuous( - ResourceLocation l, int destXPos, int destYPos, int destXSize, int destYSize, - int sourceXPos, int sourceYPos, int sourceXSize, int sourceYSize, - int borderTop, int borderBottom, int borderLeft, int borderRight) { + public void drawTextureContinuous(ResourceLocation l, + int destXPos, + int destYPos, + int destXSize, + int destYSize, + int sourceXPos, + int sourceYPos, + int sourceXSize, + int sourceYSize, + int borderTop, + int borderBottom, + int borderLeft, + int borderRight) { GuiUtils.drawContinuousTexturedBox(l, destXPos, destYPos, sourceXPos, sourceYPos, destXSize, destYSize, - sourceXSize, sourceYSize, borderTop, borderBottom, borderLeft, borderRight, zLevel); + sourceXSize, sourceYSize, borderTop, borderBottom, borderLeft, borderRight, + zLevel); } public void drawRectangle(int xPos, int yPos, int xSize, int ySize, int color) { @@ -182,7 +205,8 @@ public class JecGui extends GuiContainer { public void drawText(int xPos, int yPos, Font f, Function indenter, String... text) { Single y = new Single<>(0); boolean unicode = fontRendererObj.getUnicodeFlag(); - if (!f.unicode) fontRendererObj.setUnicodeFlag(false); + if (!f.unicode) + fontRendererObj.setUnicodeFlag(false); GlStateManager.pushMatrix(); GlStateManager.translate(xPos, yPos, 0); GlStateManager.scale(f.size, f.size, 1); @@ -199,9 +223,12 @@ public class JecGui extends GuiContainer { int l = fontRendererObj.getStringWidth("..."); String[] ss = !f.cut ? text : Arrays.stream(text).map(s -> { int w = fontRendererObj.getStringWidth(s); - if (w <= sizeScaled) return s; - else if (l >= w) return "..."; - else return fontRendererObj.trimStringToWidth(s, (int) sizeScaled - l) + "..."; + if (w <= sizeScaled) + return s; + else if (l >= w) + return "..."; + else + return fontRendererObj.trimStringToWidth(s, (int) sizeScaled - l) + "..."; }).toArray(String[]::new); if (f.centred) { drawText(xPos, yPos, f, (s) -> (int) ((sizeScaled - fontRendererObj.getStringWidth(s)) / 2), ss); @@ -235,6 +262,9 @@ public class JecGui extends GuiContainer { } public void drawItemStack(int xPos, int yPos, ItemStack is, boolean centred) { + if (is.getItem() == null) { + return; + } if (centred) { xPos -= 8; yPos -= 8; @@ -300,19 +330,32 @@ public class JecGui extends GuiContainer { public class WidgetManager { protected List widgets = new ArrayList<>(); + protected boolean initialized = false; public void add(Widget w) { widgets.add(w); + if (initialized && w instanceof Widget.Advanced) + ((Widget.Advanced) w).onGuiInit(JecGui.this); + } + + public void addAll(Widget... w) { + for (Widget aw : w) + add(aw); } public void remove(Widget w) { - widgets.remove(w); - if (w instanceof Widget.Advanced) ((Widget.Advanced) w).onRemoved(JecGui.this); + if (widgets.remove(w) && w instanceof Widget.Advanced) ((Widget.Advanced) w).onRemoved(JecGui.this); + } + + public void removeAll(Widget... w) { + for (Widget aw : w) + remove(aw); } public void onInit() { widgets.stream().filter(w -> w instanceof Widget.Advanced) .forEach(w -> ((Widget.Advanced) w).onGuiInit(JecGui.this)); + initialized = true; } public void onDraw(int mouseX, int mouseY) { @@ -321,8 +364,12 @@ public class JecGui extends GuiContainer { @SuppressWarnings("UnusedReturnValue") public boolean onClick(int xMouse, int yMouse, int button) { - return widgets.stream().filter(w -> w instanceof Widget.Advanced) - .anyMatch(w -> ((Widget.Advanced) w).onClicked(JecGui.this, xMouse, yMouse, button)); + for (Widget w : widgets) { + if (w instanceof Widget.Advanced && + ((Widget.Advanced) w).onClicked(JecGui.this, xMouse, yMouse, button)) + return true; + } + return false; } @SuppressWarnings("UnusedReturnValue") @@ -333,16 +380,23 @@ public class JecGui extends GuiContainer { public Optional getEntryAt(int xMouse, int yMouse) { return widgets.stream().map(w -> { - if (w instanceof WEntryGroup) return ((WEntryGroup) w).getEntryAt(JecGui.this, xMouse, yMouse); - else if (w instanceof WEntry) return Optional.ofNullable( - ((WEntry) w).mouseIn(JecGui.this, xMouse, yMouse) ? ((WEntry) w) : null); - else return Optional.empty(); + if (w instanceof WEntryGroup) + return ((WEntryGroup) w).getEntryAt(JecGui.this, xMouse, yMouse); + else if (w instanceof WEntry) + return Optional.ofNullable(((WEntry) w).mouseIn(JecGui.this, xMouse, yMouse) ? ((WEntry) w) : null); + else + return Optional.empty(); }).filter(Optional::isPresent).findFirst().orElse(Optional.empty()); } } - public int getGuiLeft() { return guiLeft; } - public int getGuiTop() { return guiTop; } + public int getGuiLeft() { + return guiLeft; + } + + public int getGuiTop() { + return guiTop; + } public void drawHoveringText(String text, int x, int y) { super.drawHoveringText(Arrays.asList(text), x, y, fontRendererObj); diff --git a/src/main/java/me/towdium/jecalculation/client/gui/guis/GuiCalculator.java b/src/main/java/me/towdium/jecalculation/client/gui/guis/GuiCalculator.java index 16949eb..240382b 100644 --- a/src/main/java/me/towdium/jecalculation/client/gui/guis/GuiCalculator.java +++ b/src/main/java/me/towdium/jecalculation/client/gui/guis/GuiCalculator.java @@ -17,17 +17,16 @@ import javax.annotation.ParametersAreNonnullByDefault; public class GuiCalculator extends JecGui { public GuiCalculator(@Nullable GuiScreen parent) { super(parent, true); - wgtMgr.add(new WButtonIcon(7, 7, 20, 20, Resource.BUTTON_LABEL_N, Resource.BUTTON_LABEL_F, "new_label") - .setListenerLeft(() -> Minecraft.getMinecraft().displayGuiScreen(null)) - .setListenerRight(() -> Minecraft.getMinecraft().displayGuiScreen(null))); - wgtMgr.add(new WButtonIcon(130, 7, 20, 20, Resource.BUTTON_NEW_N, Resource.BUTTON_NEW_F, "new_recipe")); - wgtMgr.add(new WButtonIcon(149, 7, 20, 20, Resource.BUTTON_SEARCH_N, Resource.BUTTON_SEARCH_F, "search")); + wgtMgr.add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "label")); + wgtMgr.add(new WButtonIcon(130, 7, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "recipe") + .setListenerLeft(() -> Minecraft.getMinecraft().displayGuiScreen(new GuiEditor(this)))); + wgtMgr.add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH_N, Resource.BTN_SEARCH_F, "search")); wgtMgr.add(new WEntryGroup(7, 87, 9, 4)); wgtMgr.add(new WEntryGroup(7, 31, 8, 1)); wgtMgr.add(new WEntry(31, 7, 20, 20)); wgtMgr.add(new WLine(52)); - wgtMgr.add(new WTextField(62, 7, 63)); - wgtMgr.add(new WIcon(151, 31, 18, 18, Resource.ICON_RECENT_N, Resource.ICON_RECENT_F)); + wgtMgr.add(new WTextField(61, 7, 64)); + wgtMgr.add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT_N, Resource.ICN_RECENT_F, "history")); wgtMgr.add(new WPager(7, 56, 162, 5)); } } diff --git a/src/main/java/me/towdium/jecalculation/client/gui/guis/GuiEditor.java b/src/main/java/me/towdium/jecalculation/client/gui/guis/GuiEditor.java new file mode 100644 index 0000000..47ad889 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/client/gui/guis/GuiEditor.java @@ -0,0 +1,48 @@ +package me.towdium.jecalculation.client.gui.guis; + +import me.towdium.jecalculation.client.gui.JecGui; +import me.towdium.jecalculation.client.resource.Resource; +import me.towdium.jecalculation.client.widget.widgets.*; +import net.minecraft.client.gui.GuiScreen; + +import javax.annotation.Nullable; + +/** + * Author: towdium + * Date: 17-9-8. + */ +public class GuiEditor extends JecGui { + WButtonIcon buttonSave = new WButtonIcon(26, 33, 20, 20, Resource.BTN_SAVE_N, Resource.BTN_SAVE_F, "save"); + WButtonIcon buttonCopy = new WButtonIcon(83, 33, 20, 20, Resource.BTN_COPY_N, Resource.BTN_COPY_F, "copy"); + WButtonIcon buttonDel = new WButtonIcon(64, 33, 20, 20, Resource.BTN_DEL_N, Resource.BTN_DEL_F, "clear"); + WButtonIcon buttonLabel = new WButtonIcon(45, 33, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "label"); + WButtonIcon buttonYes = new WButtonIcon(7, 33, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F, "confirm"); + WButtonIcon buttonNo = new WButtonIcon(26, 33, 20, 20, Resource.BTN_NO_N, Resource.BTN_NO_F, "abort"); + WEntryGroup groupInput = new WEntryGroup(28, 111, 7, 2, 20, 20); + WEntryGroup groupCatalyst = new WEntryGroup(28, 87, 7, 1, 20, 20); + WEntryGroup groupOutput = new WEntryGroup(28, 63, 7, 1, 20, 20); + WTextField textField = new WTextField(49, 33, 119); + WButtonIcon buttonNew = new WButtonIcon(7, 33, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "new") + .setListenerLeft(() -> setModeNewGroup(true)); + + public GuiEditor(@Nullable GuiScreen parent) { + super(parent); + wgtMgr.add(new WPager(7, 7, 162, 2)); + wgtMgr.add(new WIcon(7, 63, 21, 20, Resource.ICN_OUTPUT_N, Resource.ICN_OUTPUT_F, "output")); + wgtMgr.add(new WIcon(7, 87, 21, 20, Resource.ICN_CATALYST_N, Resource.ICN_CATALYST_F, "catalyst")); + wgtMgr.add(new WIcon(7, 111, 21, 40, Resource.ICN_INPUT_N, Resource.ICN_INPUT_F, "input")); + wgtMgr.add(new WLine(57)); + wgtMgr.addAll(groupInput, groupCatalyst, groupOutput); + setModeNewGroup(false); + } + + public void setModeNewGroup(boolean b) { + if (b) { + wgtMgr.removeAll(buttonNew, buttonLabel, buttonDel, buttonCopy, buttonSave); + wgtMgr.addAll(buttonYes, buttonNo, textField); + } else { + wgtMgr.addAll(buttonNew, buttonLabel, buttonDel, buttonSave); // TODO buttonCopy + wgtMgr.removeAll(buttonYes, buttonNo, textField); + } + } +} diff --git a/src/main/java/me/towdium/jecalculation/client/resource/Resource.java b/src/main/java/me/towdium/jecalculation/client/resource/Resource.java index f397b05..c59c198 100644 --- a/src/main/java/me/towdium/jecalculation/client/resource/Resource.java +++ b/src/main/java/me/towdium/jecalculation/client/resource/Resource.java @@ -10,23 +10,40 @@ import net.minecraft.util.ResourceLocation; public class Resource { public static final ResourceLocation location = new ResourceLocation( JustEnoughCalculation.Reference.MODID, "textures/gui/resources.png"); - public static final Resource BUTTON_LABEL_N = new Resource(0, 14, 14, 14); - public static final Resource BUTTON_LABEL_F = new Resource(0, 0, 14, 14); - public static final Resource BUTTON_NEW_N = new Resource(14, 14, 14, 14); - public static final Resource BUTTON_NEW_F = new Resource(14, 0, 14, 14); - public static final Resource BUTTON_SEARCH_N = new Resource(28, 14, 14, 14); - public static final Resource BUTTON_SEARCH_F = new Resource(28, 0, 14, 14); - public static final Resource WIDGET_BUTTON_N = new Resource(216, 0, 20, 20); - public static final Resource WIDGET_BUTTON_F = new Resource(236, 0, 20, 20); - public static final Resource WIDGET_SLOT = new Resource(196, 0, 20, 20); - public static final Resource WIDGET_LINE = new Resource(0, 28, 163, 4); - public static final Resource WIDGET_PANEL = new Resource(176, 0, 20, 20); - public static final Resource WIDGET_ARR_L_F = new Resource(156, 0, 9, 9); - public static final Resource WIDGET_ARR_L_N = new Resource(156, 10, 9, 9); - public static final Resource WIDGET_ARR_R_F = new Resource(166, 0, 9, 9); - public static final Resource WIDGET_ARR_R_N = new Resource(166, 10, 9, 9); - public static final Resource ICON_RECENT_N = new Resource(0, 46, 14, 14); - public static final Resource ICON_RECENT_F = new Resource(0, 32, 14, 14); + public static final Resource BTN_LABEL_N = new Resource(0, 14, 14, 14); + public static final Resource BTN_LABEL_F = new Resource(0, 0, 14, 14); + public static final Resource BTN_NEW_N = new Resource(14, 14, 14, 14); + public static final Resource BTN_NEW_F = new Resource(14, 0, 14, 14); + public static final Resource BTN_SEARCH_N = new Resource(28, 14, 14, 14); + public static final Resource BTN_SEARCH_F = new Resource(28, 0, 14, 14); + public static final Resource BTN_SAVE_N = new Resource(42, 14, 14, 14); + public static final Resource BTN_SAVE_F = new Resource(42, 0, 14, 14); + public static final Resource BTN_COPY_N = new Resource(56, 14, 14, 14); + public static final Resource BTN_COPY_F = new Resource(56, 0, 14, 14); + public static final Resource BTN_DEL_N = new Resource(70, 14, 14, 14); + 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_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 WGT_BUTTON_N = new Resource(60, 232, 20, 20); + public static final Resource WGT_BUTTON_F = new Resource(80, 232, 20, 20); + public static final Resource WGT_BUTTON_D = new Resource(100, 232, 20, 20); + public static final Resource WGT_SLOT = new Resource(40, 232, 20, 20); + public static final Resource WGT_LINE = new Resource(0, 252, 163, 4); + public static final Resource WGT_PANEL = new Resource(20, 232, 20, 20); + public static final Resource WGT_ARR_L_F = new Resource(0, 232, 9, 9); + public static final Resource WGT_ARR_L_N = new Resource(0, 242, 9, 9); + public static final Resource WGT_ARR_R_F = new Resource(10, 232, 9, 9); + public static final Resource WGT_ARR_R_N = new Resource(10, 242, 9, 9); + public static final Resource ICN_RECENT_N = new Resource(0, 42, 14, 14); + public static final Resource ICN_RECENT_F = new Resource(0, 28, 14, 14); + public static final Resource ICN_INPUT_N = new Resource(14, 42, 14, 14); + public static final Resource ICN_INPUT_F = new Resource(14, 28, 14, 14); + public static final Resource ICN_OUTPUT_N = new Resource(28, 42, 14, 14); + public static final Resource ICN_OUTPUT_F = new Resource(28, 28, 14, 14); + public static final Resource ICN_CATALYST_N = new Resource(42, 42, 14, 14); + public static final Resource ICN_CATALYST_F = new Resource(42, 28, 14, 14); protected int xPos, yPos, xSize, ySize; protected ResourceLocation rl; diff --git a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WButton.java b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WButton.java index 7c426ae..a348525 100644 --- a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WButton.java +++ b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WButton.java @@ -16,7 +16,7 @@ import javax.annotation.ParametersAreNonnullByDefault; */ @ParametersAreNonnullByDefault public class WButton extends Widget.Advanced { - public int xPos, yPos, xSize, ySize; + protected int xPos, yPos, xSize, ySize; public Runnable lsnrLeft, lsnrRight; public String text, tooltip; protected GuiButtonExt button; @@ -45,6 +45,15 @@ public class WButton extends Widget.Advanced { return this; } + public boolean isEnabled() { + return button.enabled; + } + + public WButton setEnabled(boolean e) { + button.enabled = e; + return this; + } + protected static boolean mouseIn(GuiButtonExt button, int x, int y) { return button.enabled && button.visible && JecGui.mouseIn(button.xPosition, button.yPosition, button.width, button.height, x, y); @@ -65,7 +74,7 @@ public class WButton extends Widget.Advanced { @Override public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) { - if (mouseIn(this.button, xMouse, yMouse)) { + if (mouseIn(this.button, xMouse, yMouse) && isEnabled()) { if (button == 0 && lsnrLeft != null) { lsnrLeft.run(); ClientUtils.playClickSound(1.0F); diff --git a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WButtonIcon.java b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WButtonIcon.java index fae28f5..34612ba 100644 --- a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WButtonIcon.java +++ b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WButtonIcon.java @@ -21,7 +21,13 @@ public class WButtonIcon extends WButton { this(xPos, yPos, xSize, ySize, normal, focused, null); } - public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused, @Nullable String tooltip) { + public WButtonIcon(int xPos, + int yPos, + int xSize, + int ySize, + Resource normal, + Resource focused, + @Nullable String tooltip) { super(xPos, yPos, xSize, ySize, "", tooltip); this.xPos = xPos; this.yPos = yPos; @@ -38,9 +44,10 @@ public class WButtonIcon extends WButton { public void drawButton(Minecraft mc, int mouseX, int mouseY) { final int x = this.xPosition; final int y = this.yPosition; - this.field_146123_n = mouseX > x + 1 && mouseY > y + 1 && mouseX <= x + width - 1 && mouseY <= y + height - 1; - boolean hovered = this.field_146123_n; - gui.drawResourceContinuous(hovered ? Resource.WIDGET_BUTTON_F : Resource.WIDGET_BUTTON_N, x, y, width, height, 3, 3, 3, 3); + boolean hovered = mouseX > x + 1 && mouseY > y + 1 && mouseX <= x + width - 1 && mouseY <= y + height - 1; + this.field_146123_n = hovered; + gui.drawResourceContinuous(hovered ? Resource.WGT_BUTTON_F : Resource.WGT_BUTTON_N, x, y, width, height, + 3, 3, 3, 3); Resource r = hovered ? focused : normal; gui.drawResource(r, x + (width - r.getXSize()) / 2, y + (height - r.getYSize()) / 2); } @@ -60,4 +67,14 @@ public class WButtonIcon extends WButton { public WButtonIcon setListenerRight(Runnable r) { return ((WButtonIcon) super.setListenerRight(r)); } + + @Override + public boolean isEnabled() { + return true; + } + + public WButtonIcon setEnabled(boolean e) { + if (!e) throw new RuntimeException("Unsupported"); + else return this; + } } diff --git a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WEntry.java b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WEntry.java index f27724c..89c01ba 100644 --- a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WEntry.java +++ b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WEntry.java @@ -34,7 +34,7 @@ public class WEntry extends Widget.Advanced { @Override public void onDraw(JecGui gui, int xMouse, int yMouse) { - gui.drawResourceContinuous(Resource.WIDGET_SLOT, xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(), xSize, ySize, + gui.drawResourceContinuous(Resource.WGT_SLOT, xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(), xSize, ySize, 3, 3, 3, 3); gui.drawItemStack(gl(gui) + xPos + xSize / 2, gt(gui) + yPos + ySize / 2, entry.getRepresentation(), true); if (mouseIn(gui, xMouse, yMouse)) diff --git a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WIcon.java b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WIcon.java index 48f6d29..f13b3c2 100644 --- a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WIcon.java +++ b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WIcon.java @@ -37,9 +37,9 @@ public class WIcon extends Widget { @Override public void onDraw(JecGui gui, int xMouse, int yMouse) { - boolean hovered = JecGui.mouseIn(xPos + gl(gui), yPos + gt(gui), xSize, ySize, xMouse, yMouse); - gui.drawRectangle(xPos + gl(gui), yPos + gt(gui), xSize, ySize, - hovered ? JecGui.COLOR_BLUE : JecGui.COLOR_GREY); + boolean hovered = JecGui.mouseIn(xPos + gl(gui) + (xSize - normal.getXSize()) / 2, + yPos + gt(gui) + (ySize - normal.getYSize()) / 2, normal.getXSize(), normal.getYSize(), xMouse, yMouse); + gui.drawRectangle(xPos + gl(gui), yPos + gt(gui), xSize, ySize, JecGui.COLOR_GREY); Resource r = hovered ? focused : normal; gui.drawResource(r, (xSize - r.getXSize()) / 2 + xPos + gl(gui), (ySize - r.getYSize()) / 2 + yPos + gt(gui)); if (tooltip != null) { diff --git a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WLine.java b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WLine.java index 28cdae8..c8a35ab 100644 --- a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WLine.java +++ b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WLine.java @@ -20,6 +20,6 @@ public class WLine extends Widget { @Override public void onDraw(JecGui gui, int xMouse, int yMouse) { - gui.drawResource(Resource.WIDGET_LINE, 6 + gui.getGuiLeft(), y + gui.getGuiTop() - 1); + gui.drawResource(Resource.WGT_LINE, 6 + gui.getGuiLeft(), y + gui.getGuiTop() - 1); } } diff --git a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WPager.java b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WPager.java index ac083de..fa3f225 100644 --- a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WPager.java +++ b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WPager.java @@ -36,9 +36,9 @@ public class WPager extends Widget.Advanced { this.xSize = xSize; this.yPos = yPos; this.keys = keys; - left = new WButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WIDGET_ARR_L_N, Resource.WIDGET_ARR_L_F) + left = new WButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WGT_ARR_L_N, Resource.WGT_ARR_L_F) .setListenerLeft(() -> index.prev()); - right = new WButtonIcon(xPos + xSize - SIZE, yPos, SIZE, SIZE, Resource.WIDGET_ARR_R_N, Resource.WIDGET_ARR_R_F) + right = new WButtonIcon(xPos + xSize - SIZE, yPos, SIZE, SIZE, Resource.WGT_ARR_R_N, Resource.WGT_ARR_R_F) .setListenerLeft(() -> index.next()); wRect = new WRectangle(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.COLOR_GREY); wText = new WText(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.Font.DEFAULT_SHADOW, diff --git a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WTextField.java b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WTextField.java index d46edcd..a6dae22 100644 --- a/src/main/java/me/towdium/jecalculation/client/widget/widgets/WTextField.java +++ b/src/main/java/me/towdium/jecalculation/client/widget/widgets/WTextField.java @@ -23,12 +23,14 @@ public class WTextField extends Widget.Advanced { @Override public void onGuiInit(JecGui gui) { - textField = new GuiTextField(gui.getFontRenderer(), xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(), xSize, 20); + textField = new GuiTextField(gui.getFontRenderer(), xPos + gui.getGuiLeft() + 1, yPos + gui.getGuiTop() + 1, + xSize - 2, 18); } @Override public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) { - boolean flag = xMouse >= textField.xPosition && xMouse < textField.xPosition + textField.width && yMouse >= textField.yPosition && yMouse < textField.yPosition + textField.height; + boolean flag = xMouse >= textField.xPosition && xMouse < textField.xPosition + textField.width && + yMouse >= textField.yPosition && yMouse < textField.yPosition + textField.height; textField.mouseClicked(xMouse, yMouse, button); return textField.isFocused() && flag && button == 0; } diff --git a/src/main/java/me/towdium/jecalculation/core/entry/Entry.java b/src/main/java/me/towdium/jecalculation/core/entry/Entry.java index 722db9e..7cdfb83 100644 --- a/src/main/java/me/towdium/jecalculation/core/entry/Entry.java +++ b/src/main/java/me/towdium/jecalculation/core/entry/Entry.java @@ -18,9 +18,11 @@ import java.util.function.Function; * Date: 8/11/17. */ public interface Entry { + ItemStack EMPTY_ITEM_STACK = new ItemStack((Item)null); + EntryMergerRegistry MERGER = EntryMergerRegistry.INSTANCE; EntryRegistry REGISTRY = EntryRegistry.INSTANCE; - Entry EMPTY = new EntryItemStack(new ItemStack(new Item()), 0); + Entry EMPTY = new EntryItemStack(Entry.EMPTY_ITEM_STACK, 0); int getAmount(); diff --git a/src/main/resources/assets/jecalculation/textures/gui/resources.png b/src/main/resources/assets/jecalculation/textures/gui/resources.png index 0803ebb..2791f95 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