mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-14 01:04:06 +00:00
feat: decoupling label
This commit is contained in:
1 parent
d7d4135528
commit
595c0cdcb1
42 files changed
+1095
-1054
No files matched your search
@@ -0,0 +1,23 @@
|
||||
package me.towdium.jecalculation.client.gui;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
|
||||
public interface IDrawable {
|
||||
static int gl(JecGui gui) {
|
||||
return gui.getGuiLeft();
|
||||
}
|
||||
|
||||
static int gt(JecGui gui) {
|
||||
return gui.getGuiTop();
|
||||
}
|
||||
|
||||
void onDraw(JecGui gui, int xMouse, int yMouse);
|
||||
|
||||
default boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean onKey(JecGui gui, char ch, int code) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,8 @@ package me.towdium.jecalculation.client.gui;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiUtils;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.widget.Widget;
|
||||
import me.towdium.jecalculation.client.gui.widget.widgets.WEntry;
|
||||
import me.towdium.jecalculation.client.gui.widget.widgets.WEntryGroup;
|
||||
import me.towdium.jecalculation.core.entry.Entry;
|
||||
import me.towdium.jecalculation.client.gui.drawables.DContainer;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
@@ -16,8 +12,6 @@ import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import me.towdium.jecalculation.utils.wrappers.Triple;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
@@ -36,7 +30,6 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@@ -46,48 +39,45 @@ import java.util.function.Function;
|
||||
@ParametersAreNonnullByDefault
|
||||
public class JecGui extends GuiContainer {
|
||||
public static final int COLOR_GREY = 0xFFA1A1A1;
|
||||
public static final int COLOR_BLUE = 0xFFb0b9e6;
|
||||
|
||||
public List<GuiButton> buttonList = super.buttonList;
|
||||
public WidgetManager wgtMgr = new WidgetManager();
|
||||
public Entry hand = Entry.EMPTY;
|
||||
protected GuiScreen parent;
|
||||
protected static JecGui last;
|
||||
protected JecGui parent;
|
||||
public ILabel hand = ILabel.EMPTY;
|
||||
public DContainer container = new DContainer();
|
||||
protected List<Triple<Integer, Integer, List<String>>> tooltipBuffer = new ArrayList<>();
|
||||
|
||||
public JecGui(@Nullable GuiScreen parent) {
|
||||
this(parent, false);
|
||||
public JecGui(@Nullable JecGui parent, IDrawable... drawables) {
|
||||
this(parent, false, drawables);
|
||||
}
|
||||
|
||||
public JecGui(@Nullable GuiScreen parent, boolean acceptsTransfer) {
|
||||
public JecGui(@Nullable JecGui parent, boolean acceptsTransfer, IDrawable... drawables) {
|
||||
super(acceptsTransfer ? new ContainerTransfer() : new ContainerNonTransfer());
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
wgtMgr.onInit();
|
||||
container.addAll(drawables);
|
||||
}
|
||||
|
||||
public static boolean mouseIn(int xPos, int yPos, int xSize, int ySize, int xMouse, int yMouse) {
|
||||
return xMouse > xPos && yMouse > yPos && xMouse <= xPos + xSize && yMouse <= yPos + ySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
wgtMgr.onDraw(mouseX, mouseY);
|
||||
drawExtra();
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(mouseX - 8, mouseY - 8, 0);
|
||||
hand.drawEntry(this);
|
||||
GlStateManager.popMatrix();
|
||||
drawBufferedTooltip();
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.enableDepth();
|
||||
public static void displayGui(IDrawable... components) {
|
||||
displayGui(true, false, components);
|
||||
}
|
||||
|
||||
public static void displayGui(boolean updateParent, boolean acceptsTransfer, IDrawable... components) {
|
||||
// isCallingFromMinecraftThread
|
||||
if (Minecraft.getMinecraft().func_152345_ab())
|
||||
displayGuiUnsafe(updateParent, acceptsTransfer, components);
|
||||
}
|
||||
|
||||
public static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, IDrawable... components) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
JecGui parent;
|
||||
if (mc.currentScreen == null) parent = null;
|
||||
else if (!(mc.currentScreen instanceof JecGui)) parent = last;
|
||||
else if (updateParent) parent = (JecGui) mc.currentScreen;
|
||||
else parent = ((JecGui) mc.currentScreen).parent;
|
||||
mc.displayGuiScreen(new JecGui(parent, acceptsTransfer, components));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,35 +87,25 @@ public class JecGui extends GuiContainer {
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
drawResourceContinuous(Resource.WGT_PANEL, guiLeft, guiTop, xSize, ySize, 5, 5, 5, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
boolean InGui = wgtMgr.onClick(mouseX, mouseY, mouseButton);
|
||||
if(!InGui) {
|
||||
this.handleMouseEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(guiLeft, guiTop, 0);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
container.onDraw(this, mouseX - guiLeft, mouseY - guiTop);
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(mouseX - 8, mouseY - 8, 0);
|
||||
hand.drawEntry(this);
|
||||
GlStateManager.popMatrix();
|
||||
drawBufferedTooltip();
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.enableDepth();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,22 +120,21 @@ public class JecGui extends GuiContainer {
|
||||
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 = NEIPlugin.getEntryUnderMouse();
|
||||
if (e != Entry.EMPTY) {
|
||||
if (hand == ILabel.EMPTY) {
|
||||
ILabel e = NEIPlugin.getEntryUnderMouse();
|
||||
if (e != ILabel.EMPTY) {
|
||||
hand = e;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (!mouseIn(guiLeft, guiTop, width, height, xMouse, yMouse)) {
|
||||
hand = Entry.EMPTY;
|
||||
hand = ILabel.EMPTY;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (Mouse.getEventButton() == 1) {
|
||||
if (hand != Entry.EMPTY) {
|
||||
hand = Entry.EMPTY;
|
||||
if (hand != ILabel.EMPTY) {
|
||||
hand = ILabel.EMPTY;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -199,7 +178,8 @@ public class JecGui extends GuiContainer {
|
||||
public void drawFluid(Fluid f, int xPos, int yPos, int xSize, int ySize) {
|
||||
IIcon fluidStillIcon = f.getStillIcon();
|
||||
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
|
||||
if (fluidStillIcon != null) drawTexturedModelRectFromIcon(xPos, yPos, fluidStillIcon, xSize, ySize);
|
||||
if (fluidStillIcon != null)
|
||||
drawTexturedModelRectFromIcon(xPos, yPos, fluidStillIcon, xSize, ySize);
|
||||
}
|
||||
|
||||
public void drawTextureContinuous(ResourceLocation l,
|
||||
@@ -221,7 +201,6 @@ public class JecGui extends GuiContainer {
|
||||
}
|
||||
|
||||
public void drawRectangle(int xPos, int yPos, int xSize, int ySize, int color) {
|
||||
drawRect(xPos, yPos, xPos + xSize, yPos + ySize, color);
|
||||
float f3 = (float) (color >> 24 & 255) / 255.0F;
|
||||
float f = (float) (color >> 16 & 255) / 255.0F;
|
||||
float f1 = (float) (color >> 8 & 255) / 255.0F;
|
||||
@@ -281,9 +260,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);
|
||||
switch (f.align) {
|
||||
case LEFT:
|
||||
@@ -307,7 +289,7 @@ public class JecGui extends GuiContainer {
|
||||
}
|
||||
|
||||
public void drawTooltip(int xPos, int yPos, String... text) {
|
||||
drawTooltip(xPos, yPos, Arrays.asList(text));
|
||||
drawTooltip(xPos + guiLeft, yPos + guiTop, Arrays.asList(text));
|
||||
}
|
||||
|
||||
public void drawTooltip(int xPos, int yPos, List<String> text) {
|
||||
@@ -340,11 +322,6 @@ public class JecGui extends GuiContainer {
|
||||
return LocalizationHelper.format(this.getClass(), "gui", key, os);
|
||||
}
|
||||
|
||||
// function to override
|
||||
|
||||
protected void drawExtra() {
|
||||
}
|
||||
|
||||
public static class Font {
|
||||
public static final Font DEFAULT_SHADOW = new Font(0xFFFFFF, true, true, false, 1, enumAlign.AUTO);
|
||||
public static final Font DEFAULT_NO_SHADOW = new Font(0x404040, false, true, false, 1, enumAlign.AUTO);
|
||||
@@ -378,6 +355,29 @@ public class JecGui extends GuiContainer {
|
||||
public enum enumAlign {LEFT, CENTRE, RIGHT, AUTO}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
boolean inGui = container.onClicked(this, mouseX - guiLeft, mouseY - guiTop, mouseButton);
|
||||
if(!inGui) {
|
||||
this.handleMouseEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
if (!container.onKey(this, typedChar, keyCode)) {
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
if (hand != ILabel.EMPTY)
|
||||
hand = ILabel.EMPTY;
|
||||
else if (parent != null)
|
||||
Minecraft.getMinecraft().displayGuiScreen(parent);
|
||||
else
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isShiftDown() {
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
}
|
||||
@@ -396,69 +396,6 @@ public class JecGui extends GuiContainer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class WidgetManager {
|
||||
protected List<Widget> widgets = new ArrayList<>();
|
||||
protected boolean initialized = false;
|
||||
|
||||
public void add(Widget w) {
|
||||
widgets.add(w);
|
||||
if (initialized && w instanceof IDrawable)
|
||||
((IDrawable) w).onGuiInit(JecGui.this);
|
||||
}
|
||||
|
||||
public void addAll(Widget... w) {
|
||||
for (Widget aw : w)
|
||||
add(aw);
|
||||
}
|
||||
|
||||
public void remove(Widget w) {
|
||||
if (widgets.remove(w) && w instanceof IDrawable) ((IDrawable) w).onRemoved(JecGui.this);
|
||||
}
|
||||
|
||||
public void removeAll(Widget... w) {
|
||||
for (Widget aw : w)
|
||||
remove(aw);
|
||||
}
|
||||
|
||||
public void onInit() {
|
||||
widgets.stream().filter(w -> w instanceof IDrawable)
|
||||
.forEach(w -> ((IDrawable) w).onGuiInit(JecGui.this));
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
public void onDraw(int mouseX, int mouseY) {
|
||||
widgets.forEach(widget -> widget.onDraw(JecGui.this, mouseX, mouseY));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public boolean onClick(int xMouse, int yMouse, int button) {
|
||||
for (Widget w : widgets) {
|
||||
if (w instanceof IDrawable &&
|
||||
((IDrawable) w).onClicked(JecGui.this, xMouse, yMouse, button))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public boolean onKey(char ch, int code) {
|
||||
return widgets.stream().filter(w -> w instanceof IDrawable)
|
||||
.anyMatch(w -> ((IDrawable) w).onKey(JecGui.this, ch, code));
|
||||
}
|
||||
|
||||
public Optional<WEntry> 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.<WEntry>empty();
|
||||
}).filter(Optional::isPresent).findFirst().orElse(Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
public int getGuiLeft() {
|
||||
return guiLeft;
|
||||
}
|
||||
@@ -474,4 +411,7 @@ public class JecGui extends GuiContainer {
|
||||
public void drawHoveringText(List<String> textLines, int x, int y) {
|
||||
super.drawHoveringText(textLines, x, y, fontRendererObj);
|
||||
}
|
||||
|
||||
public int getXSize() { return xSize; }
|
||||
public int getYSize() { return ySize; }
|
||||
}
|
||||
+3
-1
@@ -1,4 +1,4 @@
|
||||
package me.towdium.jecalculation.client.gui.resource;
|
||||
package me.towdium.jecalculation.client.gui;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -36,6 +36,8 @@ public class Resource {
|
||||
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 WGT_PAGER_F = new Resource(120, 232, 20, 20);
|
||||
public static final Resource WGT_PAGER_B = new Resource(120, 232, 20, 16);
|
||||
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);
|
||||
@@ -0,0 +1,92 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.utils.ClientUtils;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class DButton implements IDrawable {
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
protected Resource normal, focused;
|
||||
protected String tooltip, text;
|
||||
protected Runnable lsnrLeft, lsnrRight;
|
||||
protected Utilities.Timer timer = new Utilities.Timer();
|
||||
|
||||
public DButton(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
|
||||
this(xPos, yPos, xSize, ySize, "", normal, focused, null);
|
||||
}
|
||||
|
||||
public DButton(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused, String tooltip) {
|
||||
this(xPos, yPos, xSize, ySize, "", normal, focused, tooltip);
|
||||
}
|
||||
|
||||
public DButton(int xPos, int yPos, int xSize, int ySize, String text,
|
||||
@Nullable Resource normal, @Nullable Resource focused, @Nullable String tooltip) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.normal = normal;
|
||||
this.focused = focused;
|
||||
this.tooltip = tooltip;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public DButton setListenerLeft(Runnable r) {
|
||||
lsnrLeft = r;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DButton setListenerRight(Runnable r) {
|
||||
lsnrRight = r;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
boolean hovered = JecGui.mouseIn(xPos + 1, yPos + 1, xSize - 2, ySize - 2, xMouse, yMouse);
|
||||
gui.drawResourceContinuous(hovered ? Resource.WGT_BUTTON_F : Resource.WGT_BUTTON_N, xPos, yPos,
|
||||
xSize, ySize, 3, 3, 3, 3);
|
||||
Resource r = hovered ? focused : normal;
|
||||
if (r != null)
|
||||
gui.drawResource(r, xPos + (xSize - r.getXSize()) / 2, yPos + (ySize - r.getYSize()) / 2);
|
||||
if (tooltip != null) {
|
||||
timer.setState(hovered);
|
||||
if (timer.getTime() > 500) gui.drawTooltip(xMouse, yMouse, gui.localize("tooltip." + tooltip));
|
||||
}
|
||||
int textColor = hovered ? 16777120 : 0;
|
||||
int strWidth = gui.getFontRenderer().getStringWidth(text);
|
||||
int ellipsisWidth = gui.getFontRenderer().getStringWidth("...");
|
||||
String str = text;
|
||||
if (strWidth > xSize - 6 && strWidth > ellipsisWidth)
|
||||
str = gui.getFontRenderer().trimStringToWidth(text, xSize - 6 - ellipsisWidth).trim() + "...";
|
||||
JecGui.Font f = JecGui.Font.DEFAULT_SHADOW.copy();
|
||||
f.color = textColor;
|
||||
gui.drawText(xPos, yPos, xSize, ySize, f, str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
if (JecGui.mouseIn(xPos + 1, yPos + 1, xSize - 2, ySize - 2, xMouse, yMouse)) {
|
||||
if (button == 0 && lsnrLeft != null) {
|
||||
lsnrLeft.run();
|
||||
ClientUtils.playClickSound(1.0F);
|
||||
return true;
|
||||
} else if (button == 1 && lsnrRight != null) {
|
||||
lsnrLeft.run();
|
||||
ClientUtils.playClickSound(0.8F);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-14.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class DContainer implements IDrawable {
|
||||
protected List<IDrawable> widgets = new ArrayList<>();
|
||||
protected JecGui gui;
|
||||
|
||||
public void add(IDrawable w) {
|
||||
widgets.add(w);
|
||||
}
|
||||
|
||||
public void addAll(IDrawable... w) {
|
||||
for (IDrawable aw : w)
|
||||
add(aw);
|
||||
}
|
||||
|
||||
public void remove(IDrawable w) {
|
||||
widgets.remove(w);
|
||||
}
|
||||
|
||||
public void removeAll(IDrawable... w) {
|
||||
for (IDrawable aw : w)
|
||||
remove(aw);
|
||||
}
|
||||
|
||||
public void onDraw(JecGui gui, int mouseX, int mouseY) {
|
||||
widgets.forEach(widget -> widget.onDraw(gui, mouseX, mouseY));
|
||||
}
|
||||
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
for (IDrawable w : widgets) {
|
||||
if (w.onClicked(gui, xMouse, yMouse, button)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onKey(JecGui gui, char ch, int code) {
|
||||
for (IDrawable w : widgets) {
|
||||
if (w.onKey(gui, ch, code)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*public Optional<DLabel> getEntryAt(int xMouse, int yMouse) {
|
||||
return drawables.stream().map(w -> {
|
||||
if (w instanceof DLabelGroup) return ((DLabelGroup) w).getEntryAt(xMouse, yMouse);
|
||||
else if (w instanceof DLabel) return Optional.ofNullable(
|
||||
((DLabel) w).mouseIn(xMouse, yMouse) ? ((DLabel) w) : null);
|
||||
else return Optional.<DLabel>empty();
|
||||
}).filter(Optional::isPresent).findFirst().orElse(Optional.empty());
|
||||
}*/
|
||||
}
|
||||
+10
-10
@@ -1,8 +1,8 @@
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.Widget;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.utils.Utilities.Timer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -14,17 +14,17 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
* Date: 17-8-18.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WIcon extends Widget {
|
||||
public class DIcon implements IDrawable {
|
||||
public int xPos, yPos, xSize, ySize;
|
||||
public Resource normal, focused;
|
||||
Timer timer = new Timer();
|
||||
public String tooltip;
|
||||
|
||||
public WIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
|
||||
public DIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
|
||||
this(xPos, yPos, xSize, ySize, normal, focused, null);
|
||||
}
|
||||
|
||||
public WIcon(int xPos, int yPos, int xSize, int ySize,
|
||||
public DIcon(int xPos, int yPos, int xSize, int ySize,
|
||||
Resource normal, Resource focused, @Nullable String tooltip) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
@@ -37,11 +37,11 @@ public class WIcon extends Widget {
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
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);
|
||||
boolean hovered = JecGui.mouseIn(xPos + (xSize - normal.getXSize()) / 2,
|
||||
yPos + (ySize - normal.getYSize()) / 2, normal.getXSize(), normal.getYSize(), xMouse, yMouse);
|
||||
gui.drawRectangle(xPos, yPos, 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));
|
||||
gui.drawResource(r, (xSize - r.getXSize()) / 2 + xPos, (ySize - r.getYSize()) / 2 + yPos);
|
||||
if (tooltip != null) {
|
||||
timer.setState(hovered);
|
||||
if (timer.getTime() > 500) gui.drawTooltip(xMouse, yMouse, gui.localize("tooltip." + tooltip));
|
||||
@@ -0,0 +1,125 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class DLabel implements IDrawable {
|
||||
static JecGui.Font font;
|
||||
|
||||
static {
|
||||
font = JecGui.Font.DEFAULT_HALF.copy();
|
||||
font.align = JecGui.Font.enumAlign.RIGHT;
|
||||
}
|
||||
|
||||
public int xPos, yPos, xSize, ySize;
|
||||
public ILabel ILabel;
|
||||
public enumMode mode;
|
||||
|
||||
public DLabel(int xPos, int yPos, int xSize, int ySize, enumMode mode) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.ILabel = ILabel.EMPTY;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public ILabel getILabel() {
|
||||
return ILabel;
|
||||
}
|
||||
|
||||
public void setILabel(ILabel ILabel) {
|
||||
this.ILabel = ILabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawResourceContinuous(Resource.WGT_SLOT, xPos, yPos, xSize, ySize, 3, 3, 3, 3);
|
||||
ILabel.drawEntry(gui, xPos + xSize / 2, yPos + ySize / 2, true);
|
||||
if (mode == enumMode.RESULT || mode == enumMode.EDITOR)
|
||||
gui.drawText(xPos + xSize / 2 + 7.5f,
|
||||
yPos + ySize / 2 + 7 - (int) (font.size * gui.getFontRenderer().FONT_HEIGHT), font,
|
||||
ILabel.getAmountString());
|
||||
if (mouseIn(gui, xMouse, yMouse))
|
||||
gui.drawRectangle(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
if (mouseIn(gui, xMouse, yMouse)) {
|
||||
switch (mode) {
|
||||
case EDITOR:
|
||||
if (gui.hand != ILabel.EMPTY) {
|
||||
ILabel = gui.hand;
|
||||
gui.hand = ILabel.EMPTY;
|
||||
return true;
|
||||
} else if (ILabel != ILabel.EMPTY) {
|
||||
if (button == 0) {
|
||||
if (JecGui.isShiftDown())
|
||||
ILabel = ILabel.increaseAmountLarge();
|
||||
else
|
||||
ILabel = ILabel.increaseAmount();
|
||||
return true;
|
||||
} else if (button == 1) {
|
||||
if (JecGui.isShiftDown())
|
||||
ILabel = ILabel.decreaseAmountLarge();
|
||||
else
|
||||
ILabel = ILabel.decreaseAmount();
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
case RESULT:
|
||||
return false;
|
||||
case PICKER:
|
||||
if (ILabel != ILabel.EMPTY) {
|
||||
gui.hand = ILabel.copy();
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
case SELECTOR:
|
||||
ILabel = gui.hand;
|
||||
gui.hand = ILabel.EMPTY;
|
||||
return true;
|
||||
default:
|
||||
throw new IllegalPositionException();
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mouseIn(JecGui gui, int x, int y) {
|
||||
int xx = x - xPos;
|
||||
int yy = y - yPos;
|
||||
return xx >= 0 && xx < xSize && yy >= 0 && yy < ySize;
|
||||
}
|
||||
|
||||
public enum enumMode {
|
||||
/**
|
||||
* Slots in editor gui. Can use to edit amount. Exact amount displayed.
|
||||
*/
|
||||
EDITOR,
|
||||
/**
|
||||
* Slots to display calculate/search result. Rounded amount displayed.
|
||||
*/
|
||||
RESULT,
|
||||
/**
|
||||
* Slots that can pick items from. No amount displayed.
|
||||
*/
|
||||
PICKER,
|
||||
/**
|
||||
* Slots to select items, eg. in calculate and search gui. No amount displayed.
|
||||
*/
|
||||
SELECTOR
|
||||
}
|
||||
}
|
||||
+8
-18
@@ -1,7 +1,7 @@
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
@@ -13,21 +13,16 @@ import java.util.stream.IntStream;
|
||||
* Date: 17-8-17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WEntryGroup extends IDrawable {
|
||||
ArrayList<WEntry> widgets = new ArrayList<>();
|
||||
public class DLabelGroup implements IDrawable {
|
||||
ArrayList<DLabel> widgets = new ArrayList<>();
|
||||
|
||||
public WEntryGroup(int xPos, int yPos, int column, int row, WEntry.enumMode mode) {
|
||||
public DLabelGroup(int xPos, int yPos, int column, int row, DLabel.enumMode mode) {
|
||||
this(xPos, yPos, column, row, 18, 18, mode);
|
||||
}
|
||||
|
||||
public WEntryGroup(int xPos, int yPos, int column, int row, int xSize, int ySize, WEntry.enumMode mode) {
|
||||
public DLabelGroup(int xPos, int yPos, int column, int row, int xSize, int ySize, DLabel.enumMode mode) {
|
||||
IntStream.range(0, column).forEach(c -> IntStream.range(0, row).forEach(r ->
|
||||
widgets.add(new WEntry(xPos + c * xSize, yPos + r * ySize, xSize, ySize, mode))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiInit(JecGui gui) {
|
||||
widgets.forEach(w -> w.onGuiInit(gui));
|
||||
widgets.add(new DLabel(xPos + c * xSize, yPos + r * ySize, xSize, ySize, mode))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,17 +30,12 @@ public class WEntryGroup extends IDrawable {
|
||||
widgets.forEach(w -> w.onDraw(gui, xMouse, yMouse));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved(JecGui gui) {
|
||||
widgets.forEach(w -> w.onRemoved(gui));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
return widgets.stream().anyMatch(w -> w.onClicked(gui, xMouse, yMouse, button));
|
||||
}
|
||||
|
||||
public Optional<WEntry> getEntryAt(JecGui gui, int xMouse, int yMouse) {
|
||||
public Optional<DLabel> getEntryAt(JecGui gui, int xMouse, int yMouse) {
|
||||
return widgets.stream().filter(w -> w.mouseIn(gui, xMouse, yMouse)).findFirst();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-18.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class DLine implements IDrawable {
|
||||
public int y;
|
||||
|
||||
public DLine(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawResource(Resource.WGT_LINE, 6, y - 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-19.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class DPager extends DContainer {
|
||||
public DPager() {
|
||||
// TODO
|
||||
//add(new DPage(0, ILabel.DESERIALIZER.getRecords().stream().filter(r -> r.representation != null).findFirst().get()));
|
||||
}
|
||||
|
||||
public class DPage implements IDrawable {
|
||||
protected int index;
|
||||
protected ILabel.RegistryEditor.Record record;
|
||||
|
||||
public DPage(int index, ILabel.RegistryEditor.Record record) {
|
||||
this.index = index;
|
||||
this.record = record;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawResourceContinuous(Resource.WGT_PAGER_B, index * 24, -21, 24, 24, 4, 4, 4, 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-15.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class DPanel implements IDrawable {
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawResourceContinuous(Resource.WGT_PANEL, 0, 0, gui.getXSize(), gui.getYSize(), 5, 5, 5, 5);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.widget.Widget;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -10,10 +10,10 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
* Date: 17-8-22.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WRectangle extends Widget {
|
||||
public class DRectangle implements IDrawable {
|
||||
public int xPos, yPos, xSize, ySize, color;
|
||||
|
||||
public WRectangle(int xPos, int yPos, int xSize, int ySize, int color) {
|
||||
public DRectangle(int xPos, int yPos, int xSize, int ySize, int color) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
@@ -23,6 +23,6 @@ public class WRectangle extends Widget {
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawRectangle(xPos + gl(gui), yPos + gt(gui), xSize, ySize, color);
|
||||
gui.drawRectangle(xPos, yPos, xSize, ySize, color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.utils.Utilities.Circulator;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-19.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class DScroll implements IDrawable {
|
||||
public static final int SIZE = 13;
|
||||
|
||||
protected int xPos, xSize, yPos;
|
||||
protected DButton left, right;
|
||||
protected DRectangle wRect;
|
||||
protected DText dText;
|
||||
protected List<String> keys;
|
||||
protected Circulator index;
|
||||
|
||||
public DScroll(int xPos, int yPos, int xSize, int total) {
|
||||
this(xPos, yPos, xSize, IntStream.rangeClosed(1, total)
|
||||
.mapToObj(i -> i + "/" + total).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public DScroll(int xPos, int yPos, int xSize, List<String> keys) {
|
||||
this.xPos = xPos;
|
||||
this.xSize = xSize;
|
||||
this.yPos = yPos;
|
||||
this.keys = keys;
|
||||
left = new DButton(xPos, yPos, SIZE, SIZE, Resource.WGT_ARR_L_N, Resource.WGT_ARR_L_F)
|
||||
.setListenerLeft(() -> index.prev());
|
||||
right = new DButton(xPos + xSize - SIZE, yPos, SIZE, SIZE,
|
||||
Resource.WGT_ARR_R_N, Resource.WGT_ARR_R_F)
|
||||
.setListenerLeft(() -> index.next());
|
||||
wRect = new DRectangle(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.COLOR_GREY);
|
||||
dText = new DText(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.Font.DEFAULT_SHADOW,
|
||||
() -> keys.get(index.index()));
|
||||
index = new Circulator(keys.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
Stream.of(left, right, wRect, dText).forEach(w -> w.onDraw(gui, xMouse, yMouse));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
return Stream.of(left, right).anyMatch(w -> w.onClicked(gui, xMouse, yMouse, button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKey(JecGui gui, char ch, int code) {
|
||||
return Stream.of(left, right).anyMatch(w -> w.onKey(gui, ch, code));
|
||||
}
|
||||
}
|
||||
+12
-14
@@ -1,7 +1,7 @@
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.widget.Widget;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.function.Supplier;
|
||||
@@ -11,35 +11,35 @@ import java.util.function.Supplier;
|
||||
* Date: 17-8-21.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WText extends Widget {
|
||||
public class DText implements IDrawable {
|
||||
public static final int UNDEFINED = Integer.MAX_VALUE;
|
||||
|
||||
public int xPos, yPos, xSize, ySize;
|
||||
public JecGui.Font font;
|
||||
public Supplier<String> key;
|
||||
|
||||
public WText(int xPos, int yPos, JecGui.Font font, String key) {
|
||||
public DText(int xPos, int yPos, JecGui.Font font, String key) {
|
||||
this(xPos, yPos, UNDEFINED, UNDEFINED, font, key);
|
||||
}
|
||||
|
||||
public WText(int xPos, int yPos, JecGui.Font font, Supplier<String> key) {
|
||||
public DText(int xPos, int yPos, JecGui.Font font, Supplier<String> key) {
|
||||
this(xPos, yPos, UNDEFINED, UNDEFINED, font, key);
|
||||
}
|
||||
|
||||
public WText(int xPos, int yPos, int xSize, JecGui.Font font, String key) {
|
||||
public DText(int xPos, int yPos, int xSize, JecGui.Font font, String key) {
|
||||
this(xPos, yPos, xSize, UNDEFINED, font, key);
|
||||
}
|
||||
|
||||
public WText(int xPos, int yPos, int xSize, JecGui.Font font, Supplier<String> key) {
|
||||
public DText(int xPos, int yPos, int xSize, JecGui.Font font, Supplier<String> key) {
|
||||
this(xPos, yPos, xSize, UNDEFINED, font, key);
|
||||
}
|
||||
|
||||
|
||||
public WText(int xPos, int yPos, int xSize, int ySize, JecGui.Font font, String key) {
|
||||
public DText(int xPos, int yPos, int xSize, int ySize, JecGui.Font font, String key) {
|
||||
this(xPos, yPos, xSize, UNDEFINED, font, () -> key);
|
||||
}
|
||||
|
||||
public WText(int xPos, int yPos, int xSize, int ySize, JecGui.Font font, Supplier<String> key) {
|
||||
public DText(int xPos, int yPos, int xSize, int ySize, JecGui.Font font, Supplier<String> key) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
@@ -50,11 +50,9 @@ public class WText extends Widget {
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
int gl = gl(gui);
|
||||
int gt = gt(gui);
|
||||
String[] text = key.get().split("\n");
|
||||
if (xSize == UNDEFINED) gui.drawText(xPos + gl, yPos + gt, font, text);
|
||||
else if (ySize == UNDEFINED) gui.drawText(xPos + gl, yPos + gt, xSize, font, text);
|
||||
else gui.drawText(xPos + gl, yPos + gt, xSize, ySize, font, text);
|
||||
if (xSize == UNDEFINED) gui.drawText(xPos, yPos, font, text);
|
||||
else if (ySize == UNDEFINED) gui.drawText(xPos, yPos, xSize, font, text);
|
||||
else gui.drawText(xPos, yPos, xSize, ySize, font, text);
|
||||
}
|
||||
}
|
||||
+6
-11
@@ -1,7 +1,8 @@
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -11,20 +12,14 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
* Date: 17-8-18.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WTextField extends IDrawable {
|
||||
public class DTextField implements IDrawable {
|
||||
protected int xPos, yPos, xSize;
|
||||
GuiTextField textField;
|
||||
|
||||
public WTextField(int xPos, int yPos, int xSize) {
|
||||
public DTextField(int xPos, int yPos, int xSize) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiInit(JecGui gui) {
|
||||
textField = new GuiTextField(gui.getFontRenderer(), xPos + gui.getGuiLeft() + 1, yPos + gui.getGuiTop() + 1,
|
||||
xSize - 2, 18);
|
||||
textField = new GuiTextField(Minecraft.getMinecraft().fontRenderer, xPos + 1, yPos + 1, xSize - 2, 18);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,34 +1,32 @@
|
||||
package me.towdium.jecalculation.client.gui.guis;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.widgets.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import static me.towdium.jecalculation.client.gui.widget.widgets.WEntry.enumMode.*;
|
||||
import static me.towdium.jecalculation.client.gui.drawables.DLabel.enumMode.*;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/14/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class GuiCalculator extends JecGui {
|
||||
public GuiCalculator(@Nullable GuiScreen parent) {
|
||||
super(parent, true);
|
||||
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, RESULT));
|
||||
wgtMgr.add(new WEntryGroup(7, 31, 8, 1, PICKER));
|
||||
wgtMgr.add(new WEntry(31, 7, 20, 20, SELECTOR));
|
||||
wgtMgr.add(new WLine(52));
|
||||
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));
|
||||
public class GuiCalculator extends DContainer {
|
||||
public GuiCalculator() {
|
||||
add(new DPanel());
|
||||
add(new DTextField(61, 7, 64));
|
||||
add(new DButton(7, 7, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "label")
|
||||
.setListenerLeft(() -> JecGui.displayGui(new GuiLabelPicker())));
|
||||
add(new DButton(130, 7, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "recipe")
|
||||
.setListenerLeft(() -> JecGui.displayGui(new GuiEditor())));
|
||||
add(new DButton(149, 7, 20, 20, Resource.BTN_SEARCH_N, Resource.BTN_SEARCH_F, "search"));
|
||||
add(new DLabelGroup(7, 87, 9, 4, RESULT));
|
||||
add(new DLabelGroup(7, 31, 8, 1, PICKER));
|
||||
add(new DLabel(31, 7, 20, 20, SELECTOR));
|
||||
add(new DLine(52));
|
||||
add(new DIcon(151, 31, 18, 18, Resource.ICN_RECENT_N, Resource.ICN_RECENT_F, "history"));
|
||||
add(new DScroll(7, 56, 162, 5));
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,46 @@
|
||||
package me.towdium.jecalculation.client.gui.guis;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.widgets.*;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static me.towdium.jecalculation.client.gui.widget.widgets.WEntry.enumMode.EDITOR;
|
||||
import static me.towdium.jecalculation.client.gui.drawables.DLabel.enumMode.EDITOR;
|
||||
|
||||
/**
|
||||
* 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, EDITOR);
|
||||
WEntryGroup groupCatalyst = new WEntryGroup(28, 87, 7, 1, 20, 20, EDITOR);
|
||||
WEntryGroup groupOutput = new WEntryGroup(28, 63, 7, 1, 20, 20, EDITOR);
|
||||
WTextField textField = new WTextField(49, 33, 119);
|
||||
WButtonIcon buttonNew = new WButtonIcon(7, 33, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "new")
|
||||
public class GuiEditor extends DContainer {
|
||||
DButton buttonSave = new DButton(26, 33, 20, 20, Resource.BTN_SAVE_N, Resource.BTN_SAVE_F, "save");
|
||||
DButton buttonCopy = new DButton(83, 33, 20, 20, Resource.BTN_COPY_N, Resource.BTN_COPY_F, "copy");
|
||||
DButton buttonDel = new DButton(64, 33, 20, 20, Resource.BTN_DEL_N, Resource.BTN_DEL_F, "clear");
|
||||
DButton buttonLabel = new DButton(45, 33, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "label");
|
||||
DButton buttonYes = new DButton(7, 33, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F, "confirm");
|
||||
DButton buttonNo = new DButton(26, 33, 20, 20, Resource.BTN_NO_N, Resource.BTN_NO_F, "abort");
|
||||
DLabelGroup groupInput = new DLabelGroup(28, 111, 7, 2, 20, 20, EDITOR);
|
||||
DLabelGroup groupCatalyst = new DLabelGroup(28, 87, 7, 1, 20, 20, EDITOR);
|
||||
DLabelGroup groupOutput = new DLabelGroup(28, 63, 7, 1, 20, 20, EDITOR);
|
||||
DTextField textField = new DTextField(49, 33, 119);
|
||||
DButton buttonNew = new DButton(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);
|
||||
public GuiEditor() {
|
||||
add(new DPanel());
|
||||
add(new DScroll(7, 7, 162, 2));
|
||||
add(new DIcon(7, 63, 21, 20, Resource.ICN_OUTPUT_N, Resource.ICN_OUTPUT_F, "output"));
|
||||
add(new DIcon(7, 87, 21, 20, Resource.ICN_CATALYST_N, Resource.ICN_CATALYST_F, "catalyst"));
|
||||
add(new DIcon(7, 111, 21, 40, Resource.ICN_INPUT_N, Resource.ICN_INPUT_F, "input"));
|
||||
add(new DLine(57));
|
||||
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);
|
||||
removeAll(buttonNew, buttonLabel, buttonDel, buttonCopy, buttonSave);
|
||||
addAll(buttonYes, buttonNo, textField);
|
||||
} else {
|
||||
wgtMgr.addAll(buttonNew, buttonLabel, buttonDel, buttonSave); // TODO buttonCopy
|
||||
wgtMgr.removeAll(buttonYes, buttonNo, textField);
|
||||
addAll(buttonNew, buttonLabel, buttonDel, buttonSave); // TODO buttonCopy
|
||||
removeAll(buttonYes, buttonNo, textField);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package me.towdium.jecalculation.client.gui.guis;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.drawables.DContainer;
|
||||
import me.towdium.jecalculation.client.gui.drawables.DPager;
|
||||
import me.towdium.jecalculation.client.gui.drawables.DPanel;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-14.
|
||||
*/
|
||||
public class GuiLabelPicker extends DContainer {
|
||||
public GuiLabelPicker() {
|
||||
add(new DPager());
|
||||
add(new DPanel());
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package me.towdium.jecalculation.client.gui.widget;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
|
||||
public class IDrawable extends Widget {
|
||||
public void onRemoved(JecGui gui) {
|
||||
}
|
||||
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onKey(JecGui gui, char ch, int code) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onGuiInit(JecGui gui) {
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package me.towdium.jecalculation.client.gui.widget;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/14/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class Widget extends Gui {
|
||||
protected static int gl(JecGui gui) {
|
||||
return gui.getGuiLeft();
|
||||
}
|
||||
|
||||
protected static int gt(JecGui gui) {
|
||||
return gui.getGuiTop();
|
||||
}
|
||||
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiButtonExt;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
import me.towdium.jecalculation.utils.ClientUtils;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/14/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WButton extends IDrawable {
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
public Runnable lsnrLeft, lsnrRight;
|
||||
public String text, tooltip;
|
||||
protected GuiButtonExt button;
|
||||
protected Utilities.Timer timer = new Utilities.Timer();
|
||||
|
||||
public WButton(int xPos, int yPos, int xSize, int ySize, String text) {
|
||||
this(xPos, yPos, xSize, ySize, text, null);
|
||||
}
|
||||
|
||||
public WButton(int xPos, int yPos, int xSize, int ySize, String text, @Nullable String tooltip) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.text = text;
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public WButton setListenerLeft(Runnable r) {
|
||||
lsnrLeft = r;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WButton setListenerRight(Runnable r) {
|
||||
lsnrRight = r;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onGuiInit(JecGui gui) {
|
||||
super.onGuiInit(gui);
|
||||
button = new GuiButtonExt(0, xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(), xSize, ySize, text) {
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
gui.buttonList.add(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
if (mouseIn(this.button, xMouse, yMouse) && isEnabled()) {
|
||||
if (button == 0 && lsnrLeft != null) {
|
||||
lsnrLeft.run();
|
||||
ClientUtils.playClickSound(1.0F);
|
||||
return true;
|
||||
} else if (button == 1 && lsnrRight != null) {
|
||||
lsnrLeft.run();
|
||||
ClientUtils.playClickSound(0.8F);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved(JecGui gui) {
|
||||
gui.buttonList.remove(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
if (tooltip != null) {
|
||||
boolean hovered = JecGui.mouseIn(xPos + gl(gui), yPos + gt(gui), xSize, ySize, xMouse, yMouse);
|
||||
timer.setState(hovered);
|
||||
if (timer.getTime() > 500) gui.drawTooltip(xMouse, yMouse, gui.localize("tooltip." + tooltip));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiButtonExt;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WButtonIcon extends WButton {
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
protected Resource normal, focused;
|
||||
|
||||
public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
|
||||
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) {
|
||||
super(xPos, yPos, xSize, ySize, "", tooltip);
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.normal = normal;
|
||||
this.focused = focused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiInit(JecGui gui) {
|
||||
button = new GuiButtonExt(0, xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(), xSize, ySize, "") {
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
final int x = this.xPosition;
|
||||
final int y = this.yPosition;
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
gui.buttonList.add(button);
|
||||
}
|
||||
|
||||
public WButtonIcon setListenerLeft(Runnable r) {
|
||||
return ((WButtonIcon) super.setListenerLeft(r));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
import me.towdium.jecalculation.core.entry.Entry;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WEntry extends IDrawable {
|
||||
static JecGui.Font font;
|
||||
|
||||
static {
|
||||
font = JecGui.Font.DEFAULT_HALF.copy();
|
||||
font.align = JecGui.Font.enumAlign.RIGHT;
|
||||
}
|
||||
|
||||
|
||||
public int xPos, yPos, xSize, ySize;
|
||||
public Entry entry;
|
||||
public enumMode mode;
|
||||
|
||||
public WEntry(int xPos, int yPos, int xSize, int ySize, enumMode mode) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.entry = Entry.EMPTY;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public Entry getEntry() {
|
||||
return entry;
|
||||
}
|
||||
|
||||
public void setEntry(Entry entry) {
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawResourceContinuous(Resource.WGT_SLOT, xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(), xSize, ySize,
|
||||
3, 3, 3, 3);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(xPos + gl(gui) + xSize / 2 - 8, yPos + gt(gui) + ySize / 2 - 8, 0);
|
||||
entry.drawEntry(gui);
|
||||
GlStateManager.popMatrix();
|
||||
if (mode == enumMode.RESULT || mode == enumMode.EDITOR)
|
||||
gui.drawText(gl(gui) + xPos + xSize / 2 + 7.5f, gt(gui) + yPos + ySize / 2 + 7 -
|
||||
(int) (font.size * gui.getFontRenderer().FONT_HEIGHT), font, entry.getAmountString());
|
||||
if (mouseIn(gui, xMouse, yMouse))
|
||||
gui.drawRectangle(gui.getGuiLeft() + xPos + 1, gui.getGuiTop() + yPos + 1, xSize - 2, ySize - 2,
|
||||
0x80FFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
if (mouseIn(gui, xMouse, yMouse)) {
|
||||
switch (mode) {
|
||||
case EDITOR:
|
||||
if (gui.hand != Entry.EMPTY) {
|
||||
entry = gui.hand;
|
||||
gui.hand = Entry.EMPTY;
|
||||
return true;
|
||||
} else if (entry != Entry.EMPTY) {
|
||||
if (button == 0) {
|
||||
if (JecGui.isShiftDown()) entry = entry.increaseAmountLarge();
|
||||
else entry = entry.increaseAmount();
|
||||
return true;
|
||||
} else if (button == 1) {
|
||||
if (JecGui.isShiftDown()) entry = entry.decreaseAmountLarge();
|
||||
else entry = entry.decreaseAmount();
|
||||
return true;
|
||||
}
|
||||
} else return false;
|
||||
case RESULT:
|
||||
return false;
|
||||
case PICKER:
|
||||
if (entry != Entry.EMPTY) {
|
||||
gui.hand = entry.copy();
|
||||
return true;
|
||||
} else return false;
|
||||
case SELECTOR:
|
||||
entry = gui.hand;
|
||||
gui.hand = Entry.EMPTY;
|
||||
return true;
|
||||
default:
|
||||
throw new IllegalPositionException();
|
||||
}
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public boolean mouseIn(JecGui gui, int x, int y) {
|
||||
int xx = x - gui.getGuiLeft() - xPos;
|
||||
int yy = y - gui.getGuiTop() - yPos;
|
||||
return xx >= 0 && xx < xSize && yy >= 0 && yy < ySize;
|
||||
}
|
||||
|
||||
public enum enumMode {
|
||||
/**
|
||||
* Slots in editor gui. Can use to edit amount. Exact amount displayed.
|
||||
*/
|
||||
EDITOR,
|
||||
/**
|
||||
* Slots to display calculate/search result. Rounded amount displayed.
|
||||
*/
|
||||
RESULT,
|
||||
/**
|
||||
* Slots that can pick items from. No amount displayed.
|
||||
*/
|
||||
PICKER,
|
||||
/**
|
||||
* Slots to select items, eg. in calculate and search gui. No amount displayed.
|
||||
*/
|
||||
SELECTOR
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.Widget;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-18.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WLine extends Widget {
|
||||
public int y;
|
||||
|
||||
public WLine(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawResource(Resource.WGT_LINE, 6 + gui.getGuiLeft(), y + gui.getGuiTop() - 1);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-19.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WPager extends IDrawable {
|
||||
public static final int SIZE = 13;
|
||||
|
||||
protected int xPos, xSize, yPos;
|
||||
protected WButtonIcon left, right;
|
||||
protected WRectangle wRect;
|
||||
protected WText wText;
|
||||
protected List<String> keys;
|
||||
protected Utilities.Circulator index;
|
||||
|
||||
public WPager(int xPos, int yPos, int xSize, int total) {
|
||||
this(xPos, yPos, xSize,
|
||||
IntStream.rangeClosed(1, total).mapToObj(i -> i + "/" + total).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public WPager(int xPos, int yPos, int xSize, List<String> keys) {
|
||||
this.xPos = xPos;
|
||||
this.xSize = xSize;
|
||||
this.yPos = yPos;
|
||||
this.keys = keys;
|
||||
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.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,
|
||||
() -> keys.get(index.index()));
|
||||
index = new Utilities.Circulator(keys.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiInit(JecGui gui) {
|
||||
Stream.of(left, right).forEach(w -> w.onGuiInit(gui));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
Stream.of(left, right, wRect, wText).forEach(w -> w.onDraw(gui, xMouse, yMouse));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved(JecGui gui) {
|
||||
Stream.of(left, right).forEach(w -> w.onRemoved(gui));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
return Stream.of(left, right).anyMatch(w -> w.onClicked(gui, xMouse, yMouse, button));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKey(JecGui gui, char ch, int code) {
|
||||
return Stream.of(left, right).anyMatch(w -> w.onKey(gui, ch, code));
|
||||
}
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
package me.towdium.jecalculation.core.entry;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.core.entry.entries.EntryItemStack;
|
||||
import me.towdium.jecalculation.utils.Utilities.Relation;
|
||||
import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/11/17.
|
||||
*/
|
||||
public interface Entry {
|
||||
ItemStack EMPTY_ITEM_STACK = new ItemStack((Item)null);
|
||||
|
||||
EntryMergerRegistry MERGER = EntryMergerRegistry.INSTANCE;
|
||||
Registry REGISTRY = Registry.INSTANCE;
|
||||
Entry EMPTY = new EntryItemStack(Entry.EMPTY_ITEM_STACK, 0);
|
||||
|
||||
Entry increaseAmount();
|
||||
|
||||
Entry increaseAmountLarge();
|
||||
|
||||
Entry decreaseAmount();
|
||||
|
||||
Entry decreaseAmountLarge();
|
||||
|
||||
String getAmountString();
|
||||
|
||||
Entry copy();
|
||||
|
||||
void drawEntry(JecGui gui);
|
||||
|
||||
|
||||
/**
|
||||
* Since {@link Entry} merging is bidirectional, it is redundant to
|
||||
* implement on both side. So this class is created for merging
|
||||
* {@link Entry Entry(s)}.
|
||||
* It uses singleton mode. First register merge functions, then use
|
||||
* {@link #test(Entry, Entry)} and {@link #merge(Entry, Entry, boolean)}
|
||||
* to operate the {@link Entry}.
|
||||
* For registering, see {@link Registry}.
|
||||
*/
|
||||
class EntryMergerRegistry {
|
||||
public static final EntryMergerRegistry INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new EntryMergerRegistry();
|
||||
// register functions here
|
||||
}
|
||||
|
||||
private Relation<String, MergerFunction> functions = new Relation<>();
|
||||
|
||||
private EntryMergerRegistry() {
|
||||
}
|
||||
|
||||
public void register(String a, String b, MergerFunction func) {
|
||||
functions.add(a, b, func);
|
||||
}
|
||||
|
||||
public Pair<Entry, Entry> merge(Entry a, Entry b, boolean add) {
|
||||
return functions.get(REGISTRY.getIdentifier(a), REGISTRY.getIdentifier(b))
|
||||
.orElse((x, y, f) -> new Pair<>(x, y)).merge(a, b, add);
|
||||
}
|
||||
|
||||
public boolean test(Entry a, Entry b) {
|
||||
Optional<MergerFunction> f = functions.get(REGISTRY.getIdentifier(a), REGISTRY.getIdentifier(b));
|
||||
if (!f.isPresent()) return false;
|
||||
else {
|
||||
Pair<Entry, Entry> p = f.get().merge(a, b, true);
|
||||
return (!(p.one == a && p.two == b) && !(p.two == a && p.one == a));
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface MergerFunction {
|
||||
/**
|
||||
* @param a an {@link Entry} to merge
|
||||
* @param b another {@link Entry} to merge
|
||||
* @param add add together or cancel each other
|
||||
* @return merged {@link Entry Entry(s)} if not changed (no matter order), they cannot merge.
|
||||
*/
|
||||
Pair<Entry, Entry> merge(Entry a, Entry b, boolean add);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is used to register an {@link Entry} type.
|
||||
* Here you can find the identifier and deserializer of one type.
|
||||
* For {@link Entry} operations, see {@link EntryMergerRegistry}
|
||||
*/
|
||||
class Registry {
|
||||
public static final String KEY_IDENTIFIER = "identifier";
|
||||
public static final String KEY_CONTENT = "content";
|
||||
public static final Registry INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new Registry();
|
||||
}
|
||||
|
||||
private HashMap<Class<? extends Entry>, Pair<String,
|
||||
Function<NBTTagCompound, Optional<Entry>>>> clazzToData = new HashMap<>();
|
||||
private HashMap<String, Pair<Class<? extends Entry>,
|
||||
Function<NBTTagCompound, Optional<Entry>>>> idToData = new HashMap<>();
|
||||
|
||||
private Registry() {
|
||||
}
|
||||
|
||||
public <T extends Entry> void register(
|
||||
Class<T> clazz, String identifier, Function<NBTTagCompound, Optional<Entry>> deserializer) {
|
||||
clazzToData.put(clazz, new Pair<>(identifier, deserializer));
|
||||
idToData.put(identifier, new Pair<>(clazz, deserializer));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nbt NBT to deserialize
|
||||
* @return the recovered entry
|
||||
* A typical NBT structure of an {@link Entry} is as follows:
|
||||
* <pre>{@code
|
||||
* {
|
||||
* KEY_IDENTIFIER: entry_id
|
||||
* KEY_CONTENT: {
|
||||
* entry_content
|
||||
* }
|
||||
* }
|
||||
* }</pre>
|
||||
*/
|
||||
public Entry deserialization(NBTTagCompound nbt) {
|
||||
String s = nbt.getString(KEY_IDENTIFIER);
|
||||
Optional<Entry> e = idToData.get(s).two.apply(nbt.getCompoundTag(KEY_CONTENT));
|
||||
if (e.isPresent()) return e.get();
|
||||
else throw new RuntimeException("Fail to deserialize entry type: " + s);
|
||||
}
|
||||
|
||||
public String getIdentifier(Entry e) {
|
||||
Pair<String, Function<NBTTagCompound, Optional<Entry>>> p = clazzToData.get(e.getClass());
|
||||
if (p == null) throw new RuntimeException("Unregistered entry type: " + e.getClass());
|
||||
else return p.one;
|
||||
}
|
||||
}
|
||||
|
||||
class ConverterRegistry<T> {
|
||||
List<Function<List<T>, List<Entry>>> handlers = new ArrayList<>();
|
||||
|
||||
private ConverterRegistry() {
|
||||
}
|
||||
|
||||
public Entry toEntry(T ingredient) {
|
||||
return handlers.stream().map(h -> h.apply(Collections.singletonList(ingredient)))
|
||||
.filter(l -> !l.isEmpty()).findFirst().orElse(Collections.singletonList(Entry.EMPTY)).get(0);
|
||||
}
|
||||
|
||||
public List<Entry> toEntry(List<T> ingredients) {
|
||||
return new ReversedIterator<>(handlers).stream().flatMap(h -> h.apply(ingredients).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
void register(Function<List<T>, List<Entry>> handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
}
|
||||
|
||||
class ConverterRegistryItem extends ConverterRegistry<ItemStack> {
|
||||
public static final ConverterRegistryItem INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new ConverterRegistryItem();
|
||||
|
||||
INSTANCE.register(ConverterRegistryItem::convertRawItemStack);
|
||||
}
|
||||
|
||||
private ConverterRegistryItem() {
|
||||
}
|
||||
|
||||
public static List<Entry> convertRawItemStack(List<ItemStack> iss) {
|
||||
return iss.stream().map(EntryItemStack::new).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
class ConverterRegistryFluid extends ConverterRegistry<FluidStack> {
|
||||
public static final ConverterRegistryFluid INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new ConverterRegistryFluid();
|
||||
}
|
||||
|
||||
private ConverterRegistryFluid() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package me.towdium.jecalculation.core.entry.entries;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.core.entry.Entry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/11/17.
|
||||
*/
|
||||
public class EntryItemStack extends EntrySimpleAmount {
|
||||
int amount;
|
||||
ItemStack itemStack;
|
||||
|
||||
public EntryItemStack(ItemStack is) {
|
||||
this(is, is.stackSize); // todo check
|
||||
}
|
||||
|
||||
|
||||
// I will copy it!
|
||||
public EntryItemStack(ItemStack is, int amount) {
|
||||
itemStack = is.copy();
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
private EntryItemStack(EntryItemStack eis) {
|
||||
amount = eis.amount;
|
||||
itemStack = eis.itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry copy() {
|
||||
return new EntryItemStack(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(JecGui gui) {
|
||||
gui.drawItemStack(0, 0, itemStack, false);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package me.towdium.jecalculation.core.entry.entries;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.polyfill.mc.util.NonNullList;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-10.
|
||||
*/
|
||||
public class EntryOreDict extends EntrySimpleAmount {
|
||||
public static final String IDENTIFIER = "ore";
|
||||
|
||||
protected String name;
|
||||
|
||||
public EntryOreDict(String name) {
|
||||
this(name, 1);
|
||||
}
|
||||
|
||||
public EntryOreDict(String name, int amount) {
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public EntryOreDict(EntryOreDict eod) {
|
||||
this.name = eod.name;
|
||||
this.amount = eod.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntryOreDict copy() {
|
||||
return new EntryOreDict(this);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(JecGui gui) {
|
||||
NonNullList<ItemStack> list = NonNullList.create();
|
||||
OreDictionary.getOres(name).forEach(is -> {
|
||||
if (is.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
is.getItem().getSubItems(is.getItem(), CreativeTabs.tabAllSearch, list);
|
||||
} else list.add(is);
|
||||
});
|
||||
long index = System.currentTimeMillis() / 1500;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(1, 1, 0);
|
||||
GlStateManager.scale(14f / 16, 14f / 16, 1);
|
||||
gui.drawItemStack(0, 0, list.get((int) (index % list.size())), false);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
package me.towdium.jecalculation.core.labels;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import me.towdium.jecalculation.client.gui.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelItemStack;
|
||||
import me.towdium.jecalculation.core.labels.labels.LabelOreDict;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.utils.Utilities.Relation;
|
||||
import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/11/17.
|
||||
*/
|
||||
public interface ILabel {
|
||||
RegistryEntryMerger MERGER = RegistryEntryMerger.INSTANCE;
|
||||
RegistryDeserializer DESERIALIZER = RegistryDeserializer.INSTANCE;
|
||||
RegistryConverterItem CONVERTER_ITEM = RegistryConverterItem.INSTANCE;
|
||||
RegistryConverterFluid CONVERTER_FLUID = RegistryConverterFluid.INSTANCE;
|
||||
ILabel EMPTY = new LabelItemStack(ItemStackHelper.EMPTY_ITEM_STACK, 0);
|
||||
|
||||
ILabel increaseAmount();
|
||||
|
||||
ILabel increaseAmountLarge();
|
||||
|
||||
ILabel decreaseAmount();
|
||||
|
||||
ILabel decreaseAmountLarge();
|
||||
|
||||
String getAmountString();
|
||||
|
||||
String getDisplayName();
|
||||
|
||||
default String getIdentifier() {
|
||||
String s = this.getClass().getSimpleName();
|
||||
if (s.startsWith("Label")) s = s.substring(5);
|
||||
return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, s);
|
||||
}
|
||||
|
||||
ILabel copy();
|
||||
|
||||
NBTTagCompound toNBTTagCompound();
|
||||
|
||||
default void drawEntry(JecGui gui, int xPos, int yPos, boolean center) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(center ? xPos - 8 : xPos, center ? yPos - 8 : yPos, 0);
|
||||
drawEntry(gui);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
void drawEntry(JecGui gui);
|
||||
|
||||
/**
|
||||
* Since {@link ILabel} merging is bidirectional, it is redundant to
|
||||
* implement on both side. So this class is created for merging
|
||||
* {@link ILabel ILabel(s)}.
|
||||
* It uses singleton mode. First register merge functions, then use
|
||||
* {@link #test(ILabel, ILabel)} and {@link #merge(ILabel, ILabel, boolean)}
|
||||
* to operate the {@link ILabel}.
|
||||
* For registering, see {@link RegistryDeserializer}.
|
||||
*/
|
||||
class RegistryEntryMerger {
|
||||
public static final RegistryEntryMerger INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new RegistryEntryMerger();
|
||||
// register functions here
|
||||
}
|
||||
|
||||
private Relation<String, MergerFunction> functions = new Relation<>();
|
||||
|
||||
|
||||
private RegistryEntryMerger() {
|
||||
}
|
||||
|
||||
public void register(String a, String b, MergerFunction func) {
|
||||
functions.add(a, b, func);
|
||||
}
|
||||
|
||||
public Pair<ILabel, ILabel> merge(ILabel a, ILabel b, boolean add) {
|
||||
return functions.get(a.getIdentifier(), b.getIdentifier())
|
||||
.orElse((x, y, f) -> new Pair<>(x, y)).merge(a, b, add);
|
||||
}
|
||||
|
||||
public boolean test(ILabel a, ILabel b) {
|
||||
Optional<MergerFunction> f = functions.get(a.getIdentifier(), b.getIdentifier());
|
||||
if (!f.isPresent()) return false;
|
||||
else {
|
||||
Pair<ILabel, ILabel> p = f.get().merge(a, b, true);
|
||||
return (!(p.one == a && p.two == b) && !(p.two == a && p.one == a));
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface MergerFunction {
|
||||
/**
|
||||
* @param a an {@link ILabel} to merge
|
||||
* @param b another {@link ILabel} to merge
|
||||
* @param add add together or cancel each other
|
||||
* @return merged {@link ILabel ILabel(s)} if not changed (no matter order), they cannot merge.
|
||||
*/
|
||||
Pair<ILabel, ILabel> merge(ILabel a, ILabel b, boolean add);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is used to register an {@link ILabel} type.
|
||||
* Here you can find the identifier and deserializer of one type.
|
||||
* For {@link ILabel} operations, see {@link RegistryEntryMerger}
|
||||
*/
|
||||
class RegistryDeserializer {
|
||||
public static final String KEY_IDENTIFIER = "identifier";
|
||||
public static final String KEY_CONTENT = "content";
|
||||
public static final RegistryDeserializer INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new RegistryDeserializer();
|
||||
|
||||
INSTANCE.register("itemStack", LabelOreDict::new);
|
||||
}
|
||||
|
||||
private HashMap<String, Function<NBTTagCompound, ILabel>> idToData = new HashMap<>();
|
||||
|
||||
private RegistryDeserializer() {
|
||||
}
|
||||
|
||||
public void register(String identifier, Function<NBTTagCompound, ILabel> deserializer) {
|
||||
idToData.put(identifier, deserializer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nbt NBT to deserialize
|
||||
* @return the recovered ILabel
|
||||
* A typical NBT structure of an {@link ILabel} is as follows:
|
||||
* <pre>{@code
|
||||
* {
|
||||
* KEY_IDENTIFIER: entry_id
|
||||
* KEY_CONTENT: {
|
||||
* entry_content
|
||||
* }
|
||||
* }
|
||||
* }</pre>
|
||||
*/
|
||||
public ILabel deserialization(NBTTagCompound nbt) {
|
||||
String s = nbt.getString(KEY_IDENTIFIER);
|
||||
ILabel e = idToData.get(s).apply(nbt.getCompoundTag(KEY_CONTENT));
|
||||
if (e != ILabel.EMPTY) return e;
|
||||
else throw new RuntimeException("Fail to deserialize ILabel type: " + s);
|
||||
}
|
||||
}
|
||||
|
||||
class RegistryConverter<T> {
|
||||
List<Function<List<T>, List<ILabel>>> handlers = new ArrayList<>();
|
||||
|
||||
private RegistryConverter() {
|
||||
}
|
||||
|
||||
public ILabel toEntry(T ingredient) {
|
||||
return handlers.stream().map(h -> h.apply(Collections.singletonList(ingredient)))
|
||||
.filter(l -> !l.isEmpty()).findFirst().orElse(Collections.singletonList(ILabel.EMPTY)).get(0);
|
||||
}
|
||||
|
||||
public List<ILabel> toEntry(List<T> ingredients) {
|
||||
return new ReversedIterator<>(handlers).stream().flatMap(h -> h.apply(ingredients).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
void register(Function<List<T>, List<ILabel>> handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
}
|
||||
|
||||
class RegistryConverterItem extends RegistryConverter<ItemStack> {
|
||||
public static final RegistryConverterItem INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new RegistryConverterItem();
|
||||
|
||||
INSTANCE.register(RegistryConverterItem::convertRawItemStack);
|
||||
}
|
||||
|
||||
private RegistryConverterItem() {
|
||||
}
|
||||
|
||||
public static List<ILabel> convertRawItemStack(List<ItemStack> iss) {
|
||||
return iss.stream().map(LabelItemStack::new).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
class RegistryConverterFluid extends RegistryConverter<FluidStack> {
|
||||
public static final RegistryConverterFluid INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new RegistryConverterFluid();
|
||||
}
|
||||
|
||||
private RegistryConverterFluid() {
|
||||
}
|
||||
}
|
||||
|
||||
class RegistryEditor {
|
||||
public static final RegistryEditor INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new RegistryEditor();
|
||||
|
||||
INSTANCE.register(LabelOreDict.getEditor(), "ore_dict", new LabelOreDict("ingotIron"));
|
||||
}
|
||||
|
||||
private ArrayList<Record> records = new ArrayList<>();
|
||||
|
||||
private RegistryEditor() {
|
||||
}
|
||||
|
||||
public void register(IEditor editor, String unlocalizedName, ILabel representation) {
|
||||
records.add(new Record(editor, unlocalizedName, representation));
|
||||
}
|
||||
|
||||
public Collection<Record> getRecords() {
|
||||
return records;
|
||||
}
|
||||
|
||||
public interface IEditor extends IDrawable {
|
||||
void setCallback(Consumer<ILabel> callback);
|
||||
}
|
||||
|
||||
public static class Record {
|
||||
public IEditor editor;
|
||||
public String unlocalizedName;
|
||||
public ILabel representation;
|
||||
|
||||
public Record(IEditor editor, String unlocalizedName, ILabel representation) {
|
||||
this.editor = editor;
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
this.representation = representation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package me.towdium.jecalculation.core.labels.labels;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/11/17.
|
||||
*/
|
||||
public class LabelItemStack extends LabelSimpleAmount {
|
||||
public static final String IDENTIFIER = "oreDict";
|
||||
public static final String KEY_STACK = "stack";
|
||||
public static final String KEY_AMOUNT = "amount";
|
||||
|
||||
ItemStack itemStack;
|
||||
|
||||
public LabelItemStack(ItemStack is) {
|
||||
this(is, is.stackSize);
|
||||
}
|
||||
|
||||
// I will copy it!
|
||||
public LabelItemStack(ItemStack is, int amount) {
|
||||
itemStack = is.copy();
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public LabelItemStack(NBTTagCompound nbt) {
|
||||
itemStack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag(KEY_STACK));
|
||||
amount = nbt.getInteger(KEY_AMOUNT);
|
||||
}
|
||||
|
||||
private LabelItemStack(LabelItemStack eis) {
|
||||
amount = eis.amount;
|
||||
itemStack = eis.itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return itemStack.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel copy() {
|
||||
return new LabelItemStack(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound toNBTTagCompound() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
ret.setTag(KEY_STACK, itemStack.writeToNBT(new NBTTagCompound()));
|
||||
ret.setInteger(KEY_AMOUNT, amount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(JecGui gui) {
|
||||
gui.drawItemStack(0, 0, itemStack, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package me.towdium.jecalculation.core.labels.labels;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.drawables.DContainer;
|
||||
import me.towdium.jecalculation.client.gui.drawables.DText;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.polyfill.mc.util.NonNullList;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-10.
|
||||
*/
|
||||
public class LabelOreDict extends LabelSimpleAmount {
|
||||
public static final String IDENTIFIER = "oreDict";
|
||||
public static final String KEY_NAME = "name";
|
||||
public static final String KEY_AMOUNT = "amount";
|
||||
|
||||
protected String name;
|
||||
|
||||
public LabelOreDict(String name) {
|
||||
this(name, 1);
|
||||
}
|
||||
|
||||
public LabelOreDict(String name, int amount) {
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public LabelOreDict(LabelOreDict eod) {
|
||||
this.name = eod.name;
|
||||
this.amount = eod.amount;
|
||||
}
|
||||
|
||||
public LabelOreDict(NBTTagCompound nbt) {
|
||||
name = nbt.getString(KEY_NAME);
|
||||
amount = nbt.getInteger(KEY_AMOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Ore: " + name; // localization
|
||||
}
|
||||
|
||||
public static RegistryEditor.IEditor getEditor() {
|
||||
return new Editor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelOreDict copy() {
|
||||
return new LabelOreDict(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(JecGui gui) {
|
||||
NonNullList<ItemStack> list = NonNullList.create();
|
||||
OreDictionary.getOres(name).forEach(is -> {
|
||||
if (is.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
is.getItem().getSubItems(is.getItem(), CreativeTabs.tabAllSearch, list);
|
||||
} else list.add(is);
|
||||
});
|
||||
long index = System.currentTimeMillis() / 1500;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(1, 1, 0);
|
||||
GlStateManager.scale(14f / 16, 14f / 16, 1);
|
||||
gui.drawItemStack(0, 0, list.get((int) (index % list.size())), false);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound toNBTTagCompound() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
ret.setString(KEY_NAME, name);
|
||||
ret.setInteger(KEY_AMOUNT, amount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static class Editor extends DContainer implements RegistryEditor.IEditor {
|
||||
Consumer<ILabel> label;
|
||||
|
||||
public Editor() {
|
||||
add(new DText(5, 5, JecGui.Font.DEFAULT_NO_SHADOW, "hello"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCallback(Consumer<ILabel> callback) {
|
||||
label = callback;
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -1,30 +1,30 @@
|
||||
package me.towdium.jecalculation.core.entry.entries;
|
||||
package me.towdium.jecalculation.core.labels.labels;
|
||||
|
||||
import me.towdium.jecalculation.core.entry.Entry;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-11.
|
||||
*/
|
||||
public abstract class EntrySimpleAmount implements Entry {
|
||||
public abstract class LabelSimpleAmount implements ILabel {
|
||||
protected int amount;
|
||||
|
||||
@Override
|
||||
public Entry increaseAmount() {
|
||||
public ILabel increaseAmount() {
|
||||
amount++;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry increaseAmountLarge() {
|
||||
public ILabel increaseAmountLarge() {
|
||||
amount += 10;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry decreaseAmount() {
|
||||
if (amount <= 1) return Entry.EMPTY;
|
||||
public ILabel decreaseAmount() {
|
||||
if (amount <= 1) return ILabel.EMPTY;
|
||||
else {
|
||||
amount--;
|
||||
return this;
|
||||
@@ -32,8 +32,8 @@ public abstract class EntrySimpleAmount implements Entry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry decreaseAmountLarge() {
|
||||
if (amount <= 10) return Entry.EMPTY;
|
||||
public ILabel decreaseAmountLarge() {
|
||||
if (amount <= 10) return ILabel.EMPTY;
|
||||
else {
|
||||
amount -= 10;
|
||||
return this;
|
||||
@@ -22,7 +22,7 @@ public class InputEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onKey(InputEvent.KeyInputEvent event) {
|
||||
if (ProxyClient.keyOpenGui.isPressed() && JustEnoughCalculation.side != JustEnoughCalculation.enumSide.SERVER) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiCalculator(null));
|
||||
JecGui.displayGui(new GuiCalculator());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,26 +10,9 @@ import net.minecraft.item.ItemStack;
|
||||
* @author Towdium
|
||||
*/
|
||||
public class JecaItem extends Item {
|
||||
public static JecaItem INSTANCE = new JecaItem();
|
||||
|
||||
public static final String CRAFTING_NAME = "item_calculator_crafting";
|
||||
public static final String MATH_NAME = "item_calculator_math";
|
||||
|
||||
|
||||
public JecaItem() {
|
||||
setHasSubtypes(true);
|
||||
setMaxStackSize(1);
|
||||
setUnlocalizedName(CRAFTING_NAME);
|
||||
setTextureName(JustEnoughCalculation.Reference.MODID + ":" + CRAFTING_NAME);
|
||||
setCreativeTab(CreativeTabs.tabTools);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
|
||||
// playerIn.openGui(JustEnoughCalculation.INSTANCE, GuiHandler.GuiId.EDITOR, worldIn, 0, 0, 0);
|
||||
// return itemStackIn;
|
||||
// }
|
||||
|
||||
public String getUnlocalizedName(int meta) {
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package me.towdium.jecalculation.item.items;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.guis.GuiCalculator;
|
||||
import me.towdium.jecalculation.item.JecaItem;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -37,4 +41,12 @@ public class ItemCalculator extends JecaItem {
|
||||
items.add(new ItemStack(this, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) {
|
||||
if (JustEnoughCalculation.side != JustEnoughCalculation.enumSide.SERVER) {
|
||||
JecGui.displayGui(new GuiCalculator());
|
||||
}
|
||||
return super.onItemRightClick(p_77659_1_, p_77659_2_, p_77659_3_);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.guis.GuiCalculator;
|
||||
import me.towdium.jecalculation.client.gui.guis.GuiEditor;
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
@@ -31,7 +33,7 @@ public class JecaOverlayHandler implements IOverlayHandler {
|
||||
ItemStack outputStack = recipe.getResultStack(recipeIndex).items[0];
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.displayGuiScreen(new JecGui(firstGui));
|
||||
JecGui.displayGui(new GuiEditor());
|
||||
GuiContainer myGuiContainer = (GuiContainer) mc.currentScreen;
|
||||
if (myGuiContainer != null) {
|
||||
myGuiContainer.inventorySlots.getSlot(0).putStack(outputStack);
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
package me.towdium.jecalculation.nei;
|
||||
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import me.towdium.jecalculation.core.entry.Entry;
|
||||
import me.towdium.jecalculation.core.entry.entries.EntryItemStack;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.core.labels.ILabel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NEIPlugin {
|
||||
public static final Entry.ConverterRegistryItem registryItem = Entry.ConverterRegistryItem.INSTANCE;
|
||||
public static final Entry.ConverterRegistryFluid registryFluid = Entry.ConverterRegistryFluid.INSTANCE;
|
||||
public static final ILabel.RegistryConverterItem registryItem = ILabel.RegistryConverterItem.INSTANCE;
|
||||
public static final ILabel.RegistryConverterFluid registryFluid = ILabel.RegistryConverterFluid.INSTANCE;
|
||||
|
||||
public static void init() {
|
||||
GuiContainerManager.addTooltipHandler(new JecaTooltipHandler());
|
||||
@@ -23,8 +14,8 @@ public class NEIPlugin {
|
||||
|
||||
private static ItemStack currentItemStack;
|
||||
|
||||
public static Entry getEntryUnderMouse() {
|
||||
if (NEIPlugin.currentItemStack == null) return Entry.EMPTY;
|
||||
public static ILabel getEntryUnderMouse() {
|
||||
if (NEIPlugin.currentItemStack == null) return ILabel.EMPTY;
|
||||
else return registryItem.toEntry(NEIPlugin.currentItemStack);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,16 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.event.Handlers;
|
||||
import me.towdium.jecalculation.item.Items;
|
||||
import me.towdium.jecalculation.item.JecaItem;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class ProxyCommon {
|
||||
public void initPre() {
|
||||
JustEnoughCalculation.logger.info("common proxy init pre");
|
||||
GameRegistry.registerItem(JecaItem.INSTANCE, JecaItem.CRAFTING_NAME);
|
||||
for (JecaItem item : Items.items) {
|
||||
GameRegistry.registerItem(item, item.getUnlocalizedName());
|
||||
}
|
||||
Handlers.handlers.forEach(FMLCommonHandler.instance().bus()::register);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package me.towdium.jecalculation.polyfill;
|
||||
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -23,4 +25,5 @@ public class Polyfill {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package me.towdium.jecalculation.utils;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.polyfill.Polyfill;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -13,6 +14,8 @@ import java.util.function.Function;
|
||||
public class ItemStackHelper {
|
||||
public static final String keyAmount = "amount";
|
||||
public static final String keyType = "type";
|
||||
public static final Item EMPTY_ITEM = null;
|
||||
public static final ItemStack EMPTY_ITEM_STACK = new ItemStack((Item)null);
|
||||
|
||||
public enum EnumStackAmountType {
|
||||
INVALID, NUMBER, PERCENTAGE, FLUID;
|
||||
|
||||
@@ -18,15 +18,6 @@ public class Pair<K, V> {
|
||||
return one.hashCode() ^ two.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Pair) {
|
||||
Pair p = (Pair) obj;
|
||||
return one.equals(p.one) && two.equals(p.two);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean swap(Class<? extends K> ke, Class<? extends V> ve) {
|
||||
if (ke.isInstance(one) && ve.isInstance(two)) return true;
|
||||
else if (!(ke.isInstance(two) && ve.isInstance(one))) return false;
|
||||
|
||||
Reference in new issue
Block a user