mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-14 01:04:06 +00:00
feat: more Gui
This commit is contained in:
1 parent
42bf760bcb
commit
4e290dde6d
30 files changed
+516
-859
No files matched your search
@@ -1,10 +1,11 @@
|
||||
package me.towdium.jecalculation.client.gui;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiUtils;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.resource.Resource;
|
||||
import me.towdium.jecalculation.client.widget.Widget;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
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;
|
||||
@@ -15,7 +16,9 @@ import net.minecraft.util.ResourceLocation;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
@@ -23,6 +26,9 @@ import java.util.List;
|
||||
*/
|
||||
@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 widgetManager = new WidgetManager();
|
||||
@@ -44,18 +50,20 @@ public class JecGui extends GuiContainer {
|
||||
widgetManager.onInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
GlStateManager.disableLighting();
|
||||
widgetManager.onDraw(mouseX, mouseY);
|
||||
GlStateManager.enableLighting();
|
||||
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
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
drawTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID,
|
||||
"textures/gui/" + getBackground() + ".png"), guiLeft, guiTop, 0, 0, this.xSize, this.ySize);
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
widgetManager.onDraw(mouseX, mouseY);
|
||||
drawExtra();
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.enableDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,22 +71,37 @@ public class JecGui extends GuiContainer {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
drawResourceContinuous(Resource.WIDGET_PANEL, guiLeft, guiTop, xSize, ySize, 5, 5, 5, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
// here I haven't copied the event thingy, don't think anyone will use it
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
widgetManager.onClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
// new functions
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
widgetManager.onKey(typedChar, keyCode);
|
||||
}
|
||||
|
||||
public FontRenderer getFontRenderer() {
|
||||
return fontRendererObj;
|
||||
}
|
||||
|
||||
public void drawResource(Resource r, int xPos, int yPos) {
|
||||
drawTexture(Resource.location, xPos, yPos, r.getXPos(), r.getYPos(), r.getXSize(), r.getYSize());
|
||||
drawTexture(r.getResourceLocation(), xPos, yPos, r.getXPos(), r.getYPos(), r.getXSize(), r.getYSize());
|
||||
}
|
||||
|
||||
public void drawResourceContinuous(
|
||||
Resource r, int xPos, int yPos, int xSize, int ySize,
|
||||
int borderTop, int borderBottom, int borderLeft, int borderRight) {
|
||||
drawTextureContinuous(Resource.location, xPos, yPos, xSize, ySize,
|
||||
drawTextureContinuous(r.getResourceLocation(), xPos, yPos, xSize, ySize,
|
||||
r.getXPos(), r.getYPos(), r.getXSize(), r.getYSize(),
|
||||
borderTop, borderBottom, borderLeft, borderRight);
|
||||
}
|
||||
@@ -98,8 +121,99 @@ public class JecGui extends GuiContainer {
|
||||
sourceXSize, sourceYSize, borderTop, borderBottom, borderLeft, borderRight, zLevel);
|
||||
}
|
||||
|
||||
protected String getBackground() {
|
||||
return "error";
|
||||
public void drawRectangle(int xPos, int yPos, int xSize, int ySize, int color) {
|
||||
drawRect(xPos, yPos, xPos + xSize, yPos + ySize, color);
|
||||
}
|
||||
|
||||
public void drawText(int xPos, int yPos, Font f, String... text) {
|
||||
drawText(xPos, yPos, f, (s) -> 0, text);
|
||||
}
|
||||
|
||||
public void drawText(int xPos, int yPos, Font f, Function<String, Integer> indenter, String... text) {
|
||||
Single<Integer> y = new Single<>(0);
|
||||
boolean unicode = fontRendererObj.getUnicodeFlag();
|
||||
if (!f.unicode) fontRendererObj.setUnicodeFlag(false);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(xPos, yPos, 0);
|
||||
GlStateManager.scale(f.size, f.size, 1);
|
||||
Arrays.stream(text).forEachOrdered(s -> {
|
||||
fontRendererObj.drawString(s, indenter.apply(s), y.value, f.color, f.shadow);
|
||||
y.value += fontRendererObj.FONT_HEIGHT;
|
||||
});
|
||||
GlStateManager.popMatrix();
|
||||
fontRendererObj.setUnicodeFlag(unicode);
|
||||
}
|
||||
|
||||
public void drawText(int xPos, int yPos, int xSize, Font f, String... text) {
|
||||
float sizeScaled = xSize / f.size;
|
||||
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) + "...";
|
||||
}).toArray(String[]::new);
|
||||
if (f.centred) {
|
||||
drawText(xPos, yPos, f, (s) -> (int) ((sizeScaled - fontRendererObj.getStringWidth(s)) / 2), ss);
|
||||
} else {
|
||||
int maxLen = Arrays.stream(ss).mapToInt(s -> fontRendererObj.getStringWidth(s)).max().orElse(0);
|
||||
int xOffset = (int) ((sizeScaled - maxLen) / 2);
|
||||
drawText(xPos, yPos, f, (s) -> xOffset, ss);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawText(int xPos, int yPos, int xSize, int ySize, Font f, String... text) {
|
||||
int yOffset = (ySize - (int) (text.length * fontRendererObj.FONT_HEIGHT * f.size)) / 2;
|
||||
drawText(xPos, yPos + yOffset, xSize, f, text);
|
||||
}
|
||||
|
||||
public void drawTooltip(int xPos, int yPos, String... text) {
|
||||
drawTooltip(xPos, yPos, Arrays.asList(text));
|
||||
}
|
||||
|
||||
public void drawTooltip(int xPos, int yPos, List<String> text) {
|
||||
drawHoveringText(text, xPos, yPos);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
}
|
||||
|
||||
public void localize(String key) {
|
||||
//LocalizationHelper.format(this.getClass(), )
|
||||
}
|
||||
|
||||
// function to override
|
||||
|
||||
protected void drawExtra() {
|
||||
}
|
||||
|
||||
public static class Font {
|
||||
public static final Font DEFAULT_SHADOW = new Font(0xFFFFFF, true, true, false, true, 1);
|
||||
public static final Font DEFAULT_NO_SHADOW = new Font(0x404040, false, true, false, true, 1);
|
||||
public static final Font DEFAULT_HALF = new Font(0xFFFFFF, true, true, true, true, 0.5f);
|
||||
|
||||
public int color;
|
||||
public boolean shadow, cut, unicode, centred;
|
||||
public float size;
|
||||
|
||||
/**
|
||||
* @param color foreground color
|
||||
* @param shadow whether to draw shadow
|
||||
* @param cut whether to cut string when exceed xSize
|
||||
* @param unicode if false, FORCE NOT UNICODE
|
||||
* @param size font size, 1 for default font size
|
||||
*/
|
||||
public Font(int color, boolean shadow, boolean cut, boolean unicode, boolean centred, float size) {
|
||||
this.color = color;
|
||||
this.shadow = shadow;
|
||||
this.cut = cut;
|
||||
this.size = size;
|
||||
this.unicode = unicode;
|
||||
this.centred = centred;
|
||||
}
|
||||
|
||||
public Font copy() {
|
||||
return new Font(color, shadow, cut, unicode, centred, size);
|
||||
}
|
||||
}
|
||||
|
||||
public class WidgetManager {
|
||||
@@ -111,22 +225,39 @@ public class JecGui extends GuiContainer {
|
||||
|
||||
public void remove(Widget w) {
|
||||
widgets.remove(w);
|
||||
w.onRemoved(JecGui.this);
|
||||
if (w instanceof Widget.Advanced) ((Widget.Advanced) w).onRemoved(JecGui.this);
|
||||
}
|
||||
|
||||
public void onInit() {
|
||||
widgets.forEach(w -> w.onGuiInit(JecGui.this));
|
||||
widgets.stream().filter(w -> w instanceof Widget.Advanced)
|
||||
.forEach(w -> ((Widget.Advanced) w).onGuiInit(JecGui.this));
|
||||
}
|
||||
|
||||
public void onDraw(int mouseX, int mouseY) {
|
||||
widgets.forEach(widget -> widget.onDraw(JecGui.this, mouseX, mouseY));
|
||||
}
|
||||
|
||||
public void onClick(int xMouse, int yMouse, int button) {
|
||||
widgets.forEach(w -> w.onClicked(JecGui.this, xMouse, yMouse, button));
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public boolean onClick(int xMouse, int yMouse, int button) {
|
||||
return widgets.stream().filter(w -> w instanceof Widget.Advanced)
|
||||
.anyMatch(w -> ((Widget.Advanced) w).onClicked(JecGui.this, xMouse, yMouse, button));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public boolean onKey(char ch, int code) {
|
||||
return widgets.stream().filter(w -> w instanceof Widget.Advanced)
|
||||
.anyMatch(w -> ((Widget.Advanced) w).onKey(JecGui.this, ch, code));
|
||||
}
|
||||
}
|
||||
|
||||
public int getGuiLeft() { return guiLeft; }
|
||||
public int getGuiTop() { return guiTop; }
|
||||
|
||||
public void drawHoveringText(String text, int x, int y) {
|
||||
super.drawHoveringText(Arrays.asList(text), x, y, fontRendererObj);
|
||||
}
|
||||
|
||||
public void drawHoveringText(List<String> textLines, int x, int y) {
|
||||
super.drawHoveringText(textLines, x, y, fontRendererObj);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,7 @@ package me.towdium.jecalculation.client.gui.guis;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.resource.Resource;
|
||||
import me.towdium.jecalculation.client.widget.widgets.WButtonIcon;
|
||||
import me.towdium.jecalculation.client.widget.widgets.WEntryGroup;
|
||||
import me.towdium.jecalculation.client.widget.widgets.WLine;
|
||||
import me.towdium.jecalculation.client.widget.widgets.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
@@ -19,17 +17,17 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
public class GuiCalculator extends JecGui {
|
||||
public GuiCalculator(@Nullable GuiScreen parent) {
|
||||
super(parent);
|
||||
widgetManager.add(new WButtonIcon(7, 7, Resource.LABEL_NORMAL, Resource.LABEL_FOCUSED)
|
||||
.setListenerLeft(() -> Minecraft.getMinecraft().displayGuiScreen(null))
|
||||
.setListenerRight(() -> Minecraft.getMinecraft().displayGuiScreen(null)));
|
||||
widgetManager.add(new WButtonIcon(130, 7, Resource.NEW_NORMAL, Resource.NEW_FOCUSED));
|
||||
widgetManager.add(new WButtonIcon(149, 7, Resource.SEARCH_NORMAL, Resource.SEARCH_FOCUSED));
|
||||
widgetManager.add(new WButtonIcon(7, 7, 20, 20, Resource.BUTTON_LABEL_N, Resource.BUTTON_LABEL_F)
|
||||
.setListenerLeft(() -> Minecraft.getMinecraft().displayGuiScreen(null))
|
||||
.setListenerRight(() -> Minecraft.getMinecraft().displayGuiScreen(null)));
|
||||
widgetManager.add(new WButtonIcon(130, 7, 20, 20, Resource.BUTTON_NEW_N, Resource.BUTTON_NEW_F));
|
||||
widgetManager.add(new WButtonIcon(149, 7, 20, 20, Resource.BUTTON_SEARCH_N, Resource.BUTTON_SEARCH_F));
|
||||
widgetManager.add(new WEntryGroup(7, 87, 9, 4));
|
||||
widgetManager.add(new WEntryGroup(7, 31, 8, 1));
|
||||
widgetManager.add(new WEntry(31, 7, 20, 20));
|
||||
widgetManager.add(new WLine(52));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBackground() {
|
||||
return "gui_calculator";
|
||||
widgetManager.add(new WTextField(62, 7, 63));
|
||||
widgetManager.add(new WIcon(151, 31, 18, 18, Resource.ICON_RECENT_N, Resource.ICON_RECENT_F));
|
||||
widgetManager.add(new WPager(7, 56, 162));
|
||||
}
|
||||
}
|
||||
@@ -10,24 +10,37 @@ import net.minecraft.util.ResourceLocation;
|
||||
public class Resource {
|
||||
public static final ResourceLocation location = new ResourceLocation(
|
||||
JustEnoughCalculation.Reference.MODID, "textures/gui/resources.png");
|
||||
public static final Resource LABEL_NORMAL = new Resource(0, 14, 14, 14);
|
||||
public static final Resource LABEL_FOCUSED = new Resource(0, 0, 14, 14);
|
||||
public static final Resource NEW_NORMAL = new Resource(14, 14, 14, 14);
|
||||
public static final Resource NEW_FOCUSED = new Resource(14, 0, 14, 14);
|
||||
public static final Resource SEARCH_NORMAL = new Resource(28, 14, 14, 14);
|
||||
public static final Resource SEARCH_FOCUSED = new Resource(28, 0, 14, 14);
|
||||
public static final Resource BUTTON_NORMAL = new Resource(216, 0, 20, 20);
|
||||
public static final Resource BUTTON_FOCUSED = new Resource(236, 0, 20, 20);
|
||||
public static final Resource SLOT = new Resource(196, 0, 20, 20);
|
||||
public static final Resource LINE = new Resource(0, 28, 163, 4);
|
||||
public static final Resource BUTTON_LABEL_N = new Resource(0, 14, 14, 14);
|
||||
public static final Resource BUTTON_LABEL_F = new Resource(0, 0, 14, 14);
|
||||
public static final Resource BUTTON_NEW_N = new Resource(14, 14, 14, 14);
|
||||
public static final Resource BUTTON_NEW_F = new Resource(14, 0, 14, 14);
|
||||
public static final Resource BUTTON_SEARCH_N = new Resource(28, 14, 14, 14);
|
||||
public static final Resource BUTTON_SEARCH_F = new Resource(28, 0, 14, 14);
|
||||
public static final Resource WIDGET_BUTTON_N = new Resource(216, 0, 20, 20);
|
||||
public static final Resource WIDGET_BUTTON_F = new Resource(236, 0, 20, 20);
|
||||
public static final Resource WIDGET_SLOT = new Resource(196, 0, 20, 20);
|
||||
public static final Resource WIDGET_LINE = new Resource(0, 28, 163, 4);
|
||||
public static final Resource WIDGET_PANEL = new Resource(176, 0, 20, 20);
|
||||
public static final Resource WIDGET_ARR_L_F = new Resource(156, 0, 9, 9);
|
||||
public static final Resource WIDGET_ARR_L_N = new Resource(156, 10, 9, 9);
|
||||
public static final Resource WIDGET_ARR_R_F = new Resource(166, 0, 9, 9);
|
||||
public static final Resource WIDGET_ARR_R_N = new Resource(166, 10, 9, 9);
|
||||
public static final Resource ICON_RECENT_N = new Resource(0, 46, 14, 14);
|
||||
public static final Resource ICON_RECENT_F = new Resource(0, 32, 14, 14);
|
||||
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
protected ResourceLocation rl;
|
||||
|
||||
public Resource(int xPos, int yPos, int xSize, int ySize) {
|
||||
public Resource(int xPos, int yPos, int xSize, int ySize, ResourceLocation rl) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.rl = rl;
|
||||
}
|
||||
|
||||
public Resource(int xPos, int yPos, int xSize, int ySize) {
|
||||
this(xPos, yPos, xSize, ySize, location);
|
||||
}
|
||||
|
||||
public int getXPos() {
|
||||
@@ -45,4 +58,8 @@ public class Resource {
|
||||
public int getYSize() {
|
||||
return ySize;
|
||||
}
|
||||
|
||||
public ResourceLocation getResourceLocation() {
|
||||
return rl;
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,49 @@ import net.minecraft.client.gui.Gui;
|
||||
* Date: 8/14/17.
|
||||
*/
|
||||
public class Widget extends Gui {
|
||||
public void onGuiInit(JecGui 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) {
|
||||
}
|
||||
|
||||
public void onRemoved(JecGui gui) {
|
||||
public static class Advanced 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) {
|
||||
}
|
||||
}
|
||||
|
||||
public void onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
public class Timer {
|
||||
long time = System.currentTimeMillis();
|
||||
boolean running = false;
|
||||
|
||||
public void setState(boolean b) {
|
||||
if (!b && running)
|
||||
running = false;
|
||||
if (b && !running) {
|
||||
running = true;
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return running ? System.currentTimeMillis() - time : 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import net.minecraft.client.Minecraft;
|
||||
* Author: towdium
|
||||
* Date: 8/14/17.
|
||||
*/
|
||||
public class WButton extends Widget {
|
||||
public class WButton extends Widget.Advanced {
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
protected Runnable lsnrLeft, lsnrRight;
|
||||
protected String text;
|
||||
@@ -34,24 +34,42 @@ public class WButton extends Widget {
|
||||
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);
|
||||
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 void onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
if (this.button.mousePressed(Minecraft.getMinecraft(), xMouse, yMouse)) {
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
if (mouseIn(this.button, 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved(JecGui gui) {
|
||||
gui.buttonList.remove(button);
|
||||
}
|
||||
}
|
||||
@@ -10,37 +10,38 @@ import net.minecraft.client.Minecraft;
|
||||
* Date: 17-8-17.
|
||||
*/
|
||||
public class WButtonIcon extends WButton {
|
||||
protected int xPos, yPos;
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
protected Resource normal, focused;
|
||||
|
||||
public WButtonIcon(int xPos, int yPos, Resource normal, Resource focused) {
|
||||
super(xPos, yPos, 20, 20, "");
|
||||
public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
|
||||
super(xPos, yPos, xSize, ySize, "");
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.normal = normal;
|
||||
this.focused = focused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiInit(JecGui gui) {
|
||||
super.onGuiInit(gui);
|
||||
gui.buttonList.add(new GuiButtonExt(0, xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(), 20, 20, "") {
|
||||
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;
|
||||
this.field_146123_n = mouseX > x + 1 && mouseY > y + 1 && mouseX <= x + width - 1 && mouseY <= y + height - 1;
|
||||
boolean hovered = this.field_146123_n;
|
||||
gui.drawResource(hovered ? Resource.BUTTON_FOCUSED : Resource.BUTTON_NORMAL, x, y);
|
||||
String text = displayString;
|
||||
int strWidth = mc.fontRenderer.getStringWidth(text);
|
||||
int ellipsisWidth = mc.fontRenderer.getStringWidth("...");
|
||||
if (strWidth > width - 6 && strWidth > ellipsisWidth)
|
||||
text = mc.fontRenderer.trimStringToWidth(text, width - 6 - ellipsisWidth).trim() + "...";
|
||||
this.drawCenteredString(mc.fontRenderer, text, x + this.width / 2, y + (this.height - 8) / 2,
|
||||
hovered ? 16777120 : 14737632);
|
||||
gui.drawResource(hovered ? focused : normal, x + 3, y + 3);
|
||||
gui.drawResourceContinuous(hovered ? Resource.WIDGET_BUTTON_F : Resource.WIDGET_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);
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,9 @@ import me.towdium.jecalculation.core.entry.Entry;
|
||||
* Author: towdium
|
||||
* Date: 17-8-17.
|
||||
*/
|
||||
public class WEntry extends Widget {
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
protected Entry entry;
|
||||
public class WEntry extends Widget.Advanced {
|
||||
public int xPos, yPos, xSize, ySize;
|
||||
public Entry entry;
|
||||
|
||||
public WEntry(int xPos, int yPos, int xSize, int ySize) {
|
||||
this.xPos = xPos;
|
||||
@@ -30,10 +30,11 @@ public class WEntry extends Widget {
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawResourceContinuous(Resource.SLOT, xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(),
|
||||
gui.drawResourceContinuous(Resource.WIDGET_SLOT, xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(),
|
||||
xSize, ySize, 3, 3, 3, 3);
|
||||
if (mouseIn(gui, xMouse, yMouse)) drawRect(gui.getGuiLeft() + xPos + 1, gui.getGuiTop() + yPos + 1,
|
||||
gui.getGuiLeft() + xPos + xSize - 1, gui.getGuiTop() + yPos + ySize - 1, 0x80FFFFFF);
|
||||
// TODO draw itemStack
|
||||
}
|
||||
|
||||
public boolean mouseIn(JecGui gui, int x, int y) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.stream.IntStream;
|
||||
* Author: towdium
|
||||
* Date: 17-8-17.
|
||||
*/
|
||||
public class WEntryGroup extends Widget {
|
||||
public class WEntryGroup extends Widget.Advanced {
|
||||
ArrayList<WEntry> widgets = new ArrayList<>();
|
||||
|
||||
public WEntryGroup(int xPos, int yPos, int column, int row) {
|
||||
@@ -38,7 +38,7 @@ public class WEntryGroup extends Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
widgets.forEach(w -> w.onClicked(gui, xMouse, yMouse, button));
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
return widgets.stream().anyMatch(w -> w.onClicked(gui, xMouse, yMouse, button));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.resource.Resource;
|
||||
import me.towdium.jecalculation.client.widget.Widget;
|
||||
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-18.
|
||||
*/
|
||||
public class WIcon extends Widget {
|
||||
public int xPos, yPos, xSize, ySize;
|
||||
public Resource normal, focused;
|
||||
Timer timer = new Timer();
|
||||
|
||||
public WIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.normal = normal;
|
||||
this.focused = focused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
boolean hovered = JecGui.mouseIn(xPos + gl(gui), yPos + gt(gui), xSize, ySize, xMouse, yMouse);
|
||||
gui.drawRectangle(xPos + gl(gui), yPos + gt(gui), xSize, ySize,
|
||||
hovered ? JecGui.COLOR_BLUE : JecGui.COLOR_GREY);
|
||||
Resource r = hovered ? focused : normal;
|
||||
gui.drawResource(r, (xSize - r.getXSize()) / 2 + xPos + gl(gui), (ySize - r.getYSize()) / 2 + yPos + gt(gui));
|
||||
timer.setState(hovered);
|
||||
if (timer.getTime() > 500) gui.drawTooltip(xMouse, yMouse,"hahaa"); // TODO hover
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import me.towdium.jecalculation.client.widget.Widget;
|
||||
* Date: 17-8-18.
|
||||
*/
|
||||
public class WLine extends Widget {
|
||||
protected int y;
|
||||
public int y;
|
||||
|
||||
public WLine(int y) {
|
||||
this.y = y;
|
||||
@@ -17,6 +17,6 @@ public class WLine extends Widget {
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawResource(Resource.LINE, 6 + gui.getGuiLeft(), y + gui.getGuiTop() - 1);
|
||||
gui.drawResource(Resource.WIDGET_LINE, 6 + gui.getGuiLeft(), y + gui.getGuiTop() - 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.resource.Resource;
|
||||
import me.towdium.jecalculation.client.widget.Widget;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-19.
|
||||
*/
|
||||
public class WPager extends Widget.Advanced {
|
||||
public static final int SIZE = 13;
|
||||
|
||||
protected int xPos, xSize, yPos;
|
||||
protected WButtonIcon left, right;
|
||||
protected Widget wRect, wText;
|
||||
|
||||
public WPager(int xPos, int yPos, int xSize) {
|
||||
this.xPos = xPos;
|
||||
this.xSize = xSize;
|
||||
this.yPos = yPos;
|
||||
left = new WButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WIDGET_ARR_L_N, Resource.WIDGET_ARR_L_F);
|
||||
right = new WButtonIcon(xPos + xSize - SIZE, yPos, SIZE, SIZE,
|
||||
Resource.WIDGET_ARR_R_N, Resource.WIDGET_ARR_R_F);
|
||||
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, "test"); // TODO input
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.widget.Widget;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-22.
|
||||
*/
|
||||
public class WRectangle extends Widget {
|
||||
public int xPos, yPos, xSize, ySize, color;
|
||||
|
||||
public WRectangle(int xPos, int yPos, int xSize, int ySize, int color) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawRectangle(xPos + gl(gui), yPos + gt(gui), xSize, ySize, color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.widget.Widget;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-21.
|
||||
*/
|
||||
public class WText extends Widget {
|
||||
public static final int UNDEFINED = Integer.MAX_VALUE;
|
||||
|
||||
int xPos, yPos, xSize, ySize;
|
||||
JecGui.Font font;
|
||||
String key;
|
||||
|
||||
public WText(int xPos, int yPos, JecGui.Font font, String key) {
|
||||
this(xPos, yPos, UNDEFINED, UNDEFINED, font, key);
|
||||
}
|
||||
|
||||
public WText(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, int ySize, JecGui.Font font, String key) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.font = font;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
int gl = gl(gui);
|
||||
int gt = gt(gui);
|
||||
String[] text = key.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.widget.Widget;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-18.
|
||||
*/
|
||||
public class WTextField extends Widget.Advanced {
|
||||
protected int xPos, yPos, xSize;
|
||||
GuiTextField textField;
|
||||
|
||||
public WTextField(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(), yPos + gui.getGuiTop(), xSize, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
boolean flag = xMouse >= textField.xPosition && xMouse < textField.xPosition + textField.width && yMouse >= textField.yPosition && yMouse < textField.yPosition + textField.height;
|
||||
textField.mouseClicked(xMouse, yMouse, button);
|
||||
return textField.isFocused() && flag && button == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
textField.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKey(JecGui gui, char ch, int code) {
|
||||
return textField.textboxKeyTyped(ch, code);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ public class InputEventHandler {
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
|
||||
public void onKey(InputEvent.KeyInputEvent event) {
|
||||
if (ProxyClient.keyOpenGui.isPressed() && JustEnoughCalculation.side != JustEnoughCalculation.enumSide.SERVER) {
|
||||
JustEnoughCalculation.logger.info("key pressed");
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiCalculator(null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package me.towdium.jecalculation.gui;
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import me.towdium.jecalculation.gui.guis.GuiCalculator;
|
||||
import me.towdium.jecalculation.gui.guis.GuiEditor;
|
||||
import me.towdium.jecalculation.gui.guis.GuiRecipeSearch;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class GuiHandler implements IGuiHandler {
|
||||
public static final class GuiId {
|
||||
public static final int CALCULATOR = 0;
|
||||
public static final int RECIPE_SEARCH = 1;
|
||||
public static final int EDITOR = 2;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
|
||||
switch (id) {
|
||||
case GuiId.CALCULATOR:
|
||||
return new GuiCalculator(null);
|
||||
case GuiId.RECIPE_SEARCH:
|
||||
return new GuiRecipeSearch(Minecraft.getMinecraft().currentScreen);
|
||||
case GuiId.EDITOR:
|
||||
return new GuiEditor(null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package me.towdium.jecalculation.gui;
|
||||
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.polyfill.ClickType;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class JecaContainer extends Container {
|
||||
InventoryBasic inventory;
|
||||
List<int[]> slotBuffer = new ArrayList<>();
|
||||
|
||||
public enum EnumSlotType {SELECT, AMOUNT, DISABLED}
|
||||
|
||||
public JecaContainer() {
|
||||
addSlots();
|
||||
int count = 0;
|
||||
int current = -1;
|
||||
for (int[] record : slotBuffer) {
|
||||
count += (record[4] * record[5]);
|
||||
}
|
||||
inventory = new InventoryBasic("Temp", false, count);
|
||||
for (int[] record : slotBuffer) {
|
||||
for (int a = 0; a < record[4]; a++) {
|
||||
for (int b = 0; b < record[5]; b++) {
|
||||
addSlotToContainer(
|
||||
new Slot(inventory, ++current, record[0] + b * record[2], record[1] + a * record[3]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityPlayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int dragType, int clickTypeIn, EntityPlayer player) {
|
||||
// PICKUP = 0
|
||||
// QUICK_MOVE = 1
|
||||
// SWAP = 2
|
||||
// CLONE = 3
|
||||
// THROW = 4
|
||||
// QUICK_CRAFT = 5
|
||||
// PICKUP_ALL = 6
|
||||
if (slotId >= 0 && getSlotType(slotId) == EnumSlotType.AMOUNT) {
|
||||
ItemStack itemStack = getSlot(slotId).getStack();
|
||||
if (itemStack != null) {
|
||||
itemStack = itemStack.copy();
|
||||
if (dragType == 0 && clickTypeIn == ClickType.PICKUP) {
|
||||
itemStack = ItemStackHelper.Click.leftClick(itemStack);
|
||||
} else if (dragType == 0 && clickTypeIn == ClickType.QUICK_MOVE) {
|
||||
itemStack = ItemStackHelper.Click.leftShift(itemStack);
|
||||
} else if (dragType == 1 && clickTypeIn == ClickType.PICKUP) {
|
||||
itemStack = ItemStackHelper.Click.rightClick(itemStack);
|
||||
} else if (dragType == 1 && clickTypeIn == ClickType.QUICK_MOVE) {
|
||||
itemStack = ItemStackHelper.Click.rightShift(itemStack);
|
||||
}
|
||||
getSlot(slotId).putStack(itemStack);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void addSlotSingle(int left, int top) {
|
||||
slotBuffer.add(new int[]{left, top, 0, 0, 1, 1});
|
||||
}
|
||||
|
||||
protected void addSlotGroup(int left, int top, int intervalH, int intervalV, int sizeH, int sizeV) {
|
||||
slotBuffer.add(new int[]{left, top, intervalH, intervalV, sizeH, sizeV});
|
||||
}
|
||||
|
||||
|
||||
protected abstract void addSlots();
|
||||
|
||||
public abstract EnumSlotType getSlotType(int index);
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
package me.towdium.jecalculation.gui;
|
||||
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.polyfill.SoundEvents;
|
||||
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.entity.RenderItem;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class JecaGuiContainer extends GuiContainer {
|
||||
GuiScreen parent;
|
||||
int activeSlot = -1;
|
||||
long timeStart = 0;
|
||||
ItemStack temp;
|
||||
|
||||
public JecaGuiContainer(Container inventorySlotsIn, GuiScreen parent) {
|
||||
super(inventorySlotsIn);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public boolean setActiveSlot(int id) {
|
||||
if (id == -1 || ((JecaContainer) inventorySlots).getSlotType(id) != JecaContainer.EnumSlotType.DISABLED) {
|
||||
activeSlot = id;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorldAndResolution(Minecraft mc, int width, int height) {
|
||||
super.setWorldAndResolution(mc, width, height);
|
||||
//TODO check
|
||||
itemRender = new JecaRenderItem();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
RenderHelper.disableStandardItemLighting(); // ?
|
||||
|
||||
drawTooltipScreen(mouseX, mouseY);
|
||||
RenderHelper.enableStandardItemLighting(); // >
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
if (activeSlot != -1) {
|
||||
drawSlotOverlay(activeSlot, 0x60aeff00);
|
||||
}
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
if (keyCode == 1) {
|
||||
if (activeSlot != -1) {
|
||||
inventorySlots.getSlot(activeSlot).putStack(temp);
|
||||
setActiveSlot(-1);
|
||||
} else {
|
||||
mc.displayGuiScreen(parent);
|
||||
}
|
||||
} else {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int i1, int i2, int i3) {
|
||||
if (activeSlot == -1) {
|
||||
Slot slot = getSlotUnderMouse();
|
||||
if (slot != null) {
|
||||
switch (((JecaContainer) inventorySlots).getSlotType(slot.getSlotIndex())) {
|
||||
case SELECT:
|
||||
temp = slot.getStack();
|
||||
if (setActiveSlot(slot.getSlotIndex())) {
|
||||
mc.thePlayer.playSound(SoundEvents.UI_BUTTON_CLICK, 0.2f, 1f);
|
||||
}
|
||||
break;
|
||||
case AMOUNT:
|
||||
temp = slot.getStack();
|
||||
if (!slot.getHasStack() && setActiveSlot(slot.getSlotIndex())) {
|
||||
mc.thePlayer.playSound(SoundEvents.UI_BUTTON_CLICK, 0.2f, 1f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
super.mouseClicked(i1, i2, i3);
|
||||
} else {
|
||||
Slot active = inventorySlots.getSlot(activeSlot);
|
||||
active.putStack(ItemStackHelper.toItemStackJEC(active.getStack()));
|
||||
activeSlot = -1;
|
||||
mc.thePlayer.playSound(SoundEvents.UI_BUTTON_CLICK, 0.2f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called by NEI when need display item name or tool tip
|
||||
*
|
||||
* @param stack current mouse over item
|
||||
*/
|
||||
public void handleMouseOverNEIItemPanel(ItemStack stack) {
|
||||
if (activeSlot != -1) {
|
||||
inventorySlots.getSlot(activeSlot)
|
||||
.putStack(stack == null ? null : ItemStackHelper.toItemStackJEC(stack.copy()));
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawTooltipScreen(int mouseX, int mouseY) {
|
||||
boolean flagUnicode = mc.fontRenderer.getUnicodeFlag();
|
||||
boolean flagOver = false;
|
||||
mc.fontRenderer.setUnicodeFlag(true);
|
||||
//noinspection unchecked
|
||||
for (GuiButton button : (List<GuiButton>) buttonList) {
|
||||
String tooltip = getButtonTooltip(button.id);
|
||||
if (tooltip != null) {
|
||||
mc.fontRenderer
|
||||
.drawStringWithShadow("?", button.xPosition + button.getButtonWidth() - 7, button.yPosition + 1,
|
||||
0xE0E0E0);
|
||||
if (isMouseOver(button, mouseX, mouseY)) {
|
||||
flagOver = true;
|
||||
mc.fontRenderer.drawStringWithShadow("\247b?", button.xPosition + button.getButtonWidth() - 7,
|
||||
button.yPosition + 1, 16777215);
|
||||
mc.fontRenderer.setUnicodeFlag(flagUnicode);
|
||||
if (timeStart == 0) {
|
||||
timeStart = System.currentTimeMillis();
|
||||
} else if (System.currentTimeMillis() - timeStart > 1000) {
|
||||
drawHoveringText(Arrays.asList(tooltip.split("\\\\n")), mouseX, mouseY, mc.fontRenderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!flagOver) {
|
||||
timeStart = 0;
|
||||
mc.fontRenderer.setUnicodeFlag(flagUnicode);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawSlotOverlay(int index, int color) {
|
||||
Slot slot = inventorySlots.getSlot(index);
|
||||
int size = getSizeSlot(index);
|
||||
int move = (size - 16) / 2;
|
||||
drawRect(slot.xDisplayPosition - move, slot.yDisplayPosition - move, slot.xDisplayPosition + size - move,
|
||||
slot.yDisplayPosition + size - move, color);
|
||||
}
|
||||
|
||||
public void drawCenteredStringMultiLine(FontRenderer fontRendererIn,
|
||||
String text,
|
||||
int x1,
|
||||
int x2,
|
||||
int y1,
|
||||
int y2,
|
||||
int color) {
|
||||
String[] buffer = text.split("\\n");
|
||||
float x = (x1 + x2) / 2.0f;
|
||||
float y = (y1 + y2 - buffer.length * 10 + 2) / 2.0f - 10;
|
||||
for (String s : buffer) {
|
||||
fontRendererIn
|
||||
.drawStringWithShadow(s, (int) x - fontRendererIn.getStringWidth(s) / 2, (int) (y += 10), color);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isMouseOver(GuiButton button, int mouseX, int mouseY) {
|
||||
return mouseX >= button.xPosition + button.getButtonWidth() - 10 &&
|
||||
mouseX <= button.xPosition + button.getButtonWidth() && mouseY >= button.yPosition &&
|
||||
mouseY <= button.yPosition + 10;
|
||||
}
|
||||
|
||||
protected void drawCenteredStringWithoutShadow(FontRenderer fontRendererIn, String text, int x, int y, int color) {
|
||||
fontRendererIn.drawString(text, x - fontRendererIn.getStringWidth(text) / 2, y, color);
|
||||
}
|
||||
|
||||
protected abstract String getButtonTooltip(int buttonId);
|
||||
|
||||
protected abstract int getSizeSlot(int index);
|
||||
|
||||
protected Slot getSlotUnderMouse() {
|
||||
Slot theSlot = null;
|
||||
try {
|
||||
Field field = JecaGuiContainer.class.getSuperclass().getDeclaredField("theSlot");
|
||||
field.setAccessible(true);
|
||||
theSlot = (Slot) field.get(this);
|
||||
field.setAccessible(false);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return theSlot;
|
||||
}
|
||||
|
||||
static class RenderItemSupplier implements Supplier<RenderItem> {
|
||||
@Override
|
||||
public RenderItem get() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package me.towdium.jecalculation.gui;
|
||||
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class JecaRenderItem extends RenderItem {
|
||||
@Override
|
||||
public void renderItemOverlayIntoGUI(FontRenderer fr,
|
||||
TextureManager textureManager,
|
||||
ItemStack stack,
|
||||
int xPosition,
|
||||
int yPosition,
|
||||
String text) {
|
||||
boolean b = fr.getUnicodeFlag();
|
||||
fr.setUnicodeFlag(true);
|
||||
String customText = stack == null ?
|
||||
"" :
|
||||
ItemStackHelper.NBT.getType(stack)
|
||||
.getDisplayString(ItemStackHelper.NBT.getAmount(stack));
|
||||
System.out.println("render " + customText);
|
||||
super.renderItemOverlayIntoGUI(fr, textureManager, stack, xPosition, yPosition, customText);
|
||||
fr.setUnicodeFlag(b);
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.gui.JecaContainer;
|
||||
import me.towdium.jecalculation.gui.JecaGuiContainer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class GuiCalculator extends JecaGuiContainer {
|
||||
GuiTextField textFieldAmount;
|
||||
|
||||
GuiButton buttonSearch;
|
||||
GuiButton buttonAdd;
|
||||
GuiButton buttonView;
|
||||
GuiButton buttonSettings;
|
||||
GuiButton buttonLeft;
|
||||
GuiButton buttonRight;
|
||||
GuiButton buttonMode;
|
||||
GuiButton buttonStock;
|
||||
|
||||
int activeSlot = -1;
|
||||
int page = 1;
|
||||
int total = 0;
|
||||
EnumMode mode = EnumMode.INPUT;
|
||||
|
||||
@SuppressWarnings("DuplicateBranchesInSwitch")
|
||||
public enum EnumMode {
|
||||
INPUT, PROCEDURE, OUTPUT, CATALYST;
|
||||
|
||||
int toInt() {
|
||||
switch (this) {
|
||||
case INPUT:
|
||||
return 1;
|
||||
case PROCEDURE:
|
||||
return 2;
|
||||
case OUTPUT:
|
||||
return 3;
|
||||
case CATALYST:
|
||||
return 4;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static EnumMode fromInt(int i) {
|
||||
switch (i) {
|
||||
case 1:
|
||||
return INPUT;
|
||||
case 2:
|
||||
return PROCEDURE;
|
||||
case 3:
|
||||
return OUTPUT;
|
||||
case 4:
|
||||
return CATALYST;
|
||||
default:
|
||||
return INPUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GuiCalculator(GuiScreen parent) {
|
||||
super(new ContainerCalculator(), parent);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonSearch = new GuiButton(1, guiLeft + 119, guiTop + 7, 50, 20, "search");
|
||||
buttonAdd = new GuiButton(2, guiLeft + 7, guiTop + 53, 52, 20, "Add");
|
||||
buttonView = new GuiButton(3, guiLeft + 63, guiTop + 53, 52, 20, "Records");
|
||||
buttonSettings = new GuiButton(4, guiLeft + 119, guiTop + 53, 50, 20, "Settings");
|
||||
buttonLeft = new GuiButton(5, guiLeft + 7, guiTop + 139, 14, 20, "<");
|
||||
buttonRight = new GuiButton(6, guiLeft + 45, guiTop + 139, 14, 20, ">");
|
||||
buttonMode = new GuiButton(7, guiLeft + 63, guiTop + 139, 52, 20, "Catalyst");
|
||||
buttonStock = new GuiButton(8, guiLeft + 119, guiTop + 139, 50, 20, "Stock");
|
||||
buttonList.add(buttonSearch);
|
||||
buttonList.add(buttonAdd);
|
||||
buttonList.add(buttonView);
|
||||
buttonList.add(buttonSettings);
|
||||
buttonList.add(buttonLeft);
|
||||
buttonList.add(buttonRight);
|
||||
buttonList.add(buttonMode);
|
||||
buttonList.add(buttonStock);
|
||||
textFieldAmount = new GuiTextField(fontRendererObj, guiLeft + 39, guiTop + 8, 75, 18);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(
|
||||
new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/gui_calculator.png"));
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
textFieldAmount.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
fontRendererObj.drawString("x", 30, 13, 0x404040);
|
||||
drawCenteredStringWithoutShadow(fontRendererObj, "Recent", 144, 36, 0x404040);
|
||||
drawCenteredString(fontRendererObj, page + "/" + total, 33, 145, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
//noinspection SwitchStatementWithTooFewBranches
|
||||
switch (button.id) {
|
||||
case 1: mc.displayGuiScreen(new GuiRecipeSearch(this));
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("SwitchStatementWithTooFewBranches")
|
||||
@Override
|
||||
protected String getButtonTooltip(int buttonId) {
|
||||
switch (buttonId) {
|
||||
case 4:
|
||||
return "Hello\\nShit";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSizeSlot(int index) {
|
||||
return index == 0 ? 20: 0;
|
||||
}
|
||||
|
||||
public static class ContainerCalculator extends JecaContainer {
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
addSlotSingle(9, 9);
|
||||
addSlotGroup(8, 32, 18, 18, 1, 6);
|
||||
addSlotGroup(8, 82, 18, 18, 3, 9);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSlotType getSlotType(int index) {
|
||||
return index == 0 ? EnumSlotType.SELECT : EnumSlotType.DISABLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiButtonExt;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.JecaTranslator;
|
||||
import me.towdium.jecalculation.gui.JecaContainer;
|
||||
import me.towdium.jecalculation.gui.JecaGuiContainer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GuiEditor extends JecaGuiContainer {
|
||||
ArrayList<GuiButton> buttonMode;
|
||||
GuiButton buttonLeft;
|
||||
GuiButton buttonRight;
|
||||
GuiButton buttonNew;
|
||||
GuiButton buttonHelp;
|
||||
GuiButton buttonSave;
|
||||
GuiButton buttonClear;
|
||||
|
||||
|
||||
public GuiEditor(GuiScreen parent) {
|
||||
super(new ContainerEditor(), parent);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonMode = new ArrayList<>();
|
||||
int count = -1;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
buttonMode.add(new GuiButtonExt(++count, 44 + j * 21 + guiLeft, 51 + i * 33 + guiTop, 10, 10, "#"));
|
||||
buttonMode.add(new GuiButtonExt(++count, 54 + j * 21 + guiLeft, 51 + i * 33 + guiTop, 10, 10, "I"));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 6; j++) {
|
||||
buttonMode.add(new GuiButtonExt(++count, 44 + j * 21 + guiLeft, 117 + i * 32 + guiTop, 10, 10, "#"));
|
||||
buttonMode.add(new GuiButtonExt(++count, 54 + j * 21 + guiLeft, 117 + i * 32 + guiTop, 10, 10, "I"));
|
||||
}
|
||||
}
|
||||
buttonLeft = new GuiButtonExt(40, guiLeft + 7, guiTop + 7, 14, 20, "<");
|
||||
buttonRight = new GuiButtonExt(41, guiLeft + 90, guiTop + 7, 14, 20, ">");
|
||||
buttonNew = new GuiButtonExt(42, guiLeft + 108, guiTop + 7, 61, 20,
|
||||
JecaTranslator.format("gui.editor.newGroup"));
|
||||
buttonHelp = new GuiButtonExt(43, guiLeft + 131, guiTop + 75, 38, 18, JecaTranslator.format("gui.editor.help"));
|
||||
buttonSave = new GuiButtonExt(44, guiLeft + 131, guiTop + 31, 38, 18, JecaTranslator.format("gui.editor.save"));
|
||||
buttonClear = new GuiButtonExt(45, guiLeft + 131, guiTop + 53, 38, 18,
|
||||
JecaTranslator.format("gui.editor.clear"));
|
||||
buttonList.addAll(buttonMode);
|
||||
buttonList.add(buttonLeft);
|
||||
buttonList.add(buttonRight);
|
||||
buttonList.add(buttonNew);
|
||||
buttonList.add(buttonHelp);
|
||||
buttonList.add(buttonSave);
|
||||
buttonList.add(buttonClear);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
drawCenteredStringMultiLine(fontRendererObj, JecaTranslator.format("gui.editor.output"), 7, 44, 31, 61,
|
||||
0xFFFFFF);
|
||||
drawCenteredStringMultiLine(fontRendererObj, JecaTranslator.format("gui.editor.catalyst"), 7, 44, 64, 94,
|
||||
0xFFFFFF);
|
||||
drawCenteredStringMultiLine(fontRendererObj, JecaTranslator.format("gui.editor.input"), 7, 44, 97, 159,
|
||||
0xFFFFFF);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected String getButtonTooltip(int buttonId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSizeSlot(int index) {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
this.mc.getTextureManager()
|
||||
.bindTexture(new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiEditor.png"));
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
}
|
||||
|
||||
public static class ContainerEditor extends JecaContainer {
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
addSlotGroup(46, 33, 21, 33, 1, 4);
|
||||
addSlotGroup(46, 66, 21, 33, 1, 4);
|
||||
addSlotGroup(46, 99, 21, 32, 2, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSlotType getSlotType(int index) {
|
||||
return EnumSlotType.AMOUNT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiButtonExt;
|
||||
import me.towdium.jecalculation.gui.JecaContainer;
|
||||
import me.towdium.jecalculation.gui.JecaGuiContainer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
public abstract class GuiRecipeList extends JecaGuiContainer {
|
||||
|
||||
public GuiRecipeList(Container inventorySlotsIn, GuiScreen parent) {
|
||||
super(inventorySlotsIn, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSizeSlot(int index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
buttonList.add(new GuiButtonExt(2 * i, guiLeft + 83, guiTop + 32 + 21 * i, 41, 18, "edit"));
|
||||
buttonList.add(new GuiButtonExt(1 + 2 * i, guiLeft + 128, guiTop + 32 + 21 * i, 41, 18, "delete"));
|
||||
}
|
||||
buttonList.add(new GuiButtonExt(10, guiLeft + 7, guiTop + 139, 20, 20, "<"));
|
||||
buttonList.add(new GuiButtonExt(11, guiLeft + 149, guiTop + 139, 20, 20, ">"));
|
||||
}
|
||||
|
||||
protected static abstract class ContainerRecipeList extends JecaContainer {
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
addSlotGroup(8, 33, 18, 21, 5, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GuiRecipeSearch extends GuiRecipeList {
|
||||
GuiButton buttonMode;
|
||||
GuiButton buttonSearch;
|
||||
EnumMode mode = EnumMode.OUT;
|
||||
|
||||
enum EnumMode {
|
||||
IN, OUT, IO;
|
||||
|
||||
EnumMode next() {
|
||||
switch (this) {
|
||||
case OUT:
|
||||
return IN;
|
||||
case IN:
|
||||
return IO;
|
||||
case IO:
|
||||
return OUT;
|
||||
default:
|
||||
return OUT;
|
||||
}
|
||||
}
|
||||
|
||||
EnumMode last() {
|
||||
switch (this) {
|
||||
case OUT:
|
||||
return IO;
|
||||
case IN:
|
||||
return OUT;
|
||||
case IO:
|
||||
return IN;
|
||||
default:
|
||||
return OUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GuiRecipeSearch(GuiScreen parent) {
|
||||
super(new ContainerRecipeList() {
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
super.addSlots();
|
||||
addSlotSingle(9, 9);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSlotType getSlotType(int index) {
|
||||
return index == 20 ? EnumSlotType.SELECT : EnumSlotType.DISABLED;
|
||||
}
|
||||
}, parent);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
buttonMode = new GuiButton(12, 31 + guiLeft, 7 + guiTop, 84, 20, "mode");
|
||||
buttonSearch = new GuiButton(13, 119 + guiLeft, 7 + guiTop, 50, 20, "search");
|
||||
buttonList.add(buttonMode);
|
||||
buttonList.add(buttonSearch);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getButtonTooltip(int buttonId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
this.mc.getTextureManager().bindTexture(
|
||||
new ResourceLocation(JustEnoughCalculation.Reference.MODID, "textures/gui/guiRecipeSearch.png"));
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSizeSlot(int index) {
|
||||
return index == 20 ? 20 : 18;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package me.towdium.jecalculation.item;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.gui.GuiHandler;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,6 @@ import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.gui.guis.GuiEditor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -15,36 +14,36 @@ import java.util.List;
|
||||
public class JecaOverlayHandler implements IOverlayHandler {
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
if(firstGui instanceof GuiEditor) {
|
||||
List<ItemStack> inputStacks = new ArrayList<>();
|
||||
LOOP:
|
||||
for (PositionedStack positionedStack : recipe.getIngredientStacks(recipeIndex)) {
|
||||
ItemStack itemStack = positionedStack.items[0];
|
||||
for (ItemStack exist : inputStacks) {
|
||||
if (ItemStackHelper.isTypeEqual(exist, itemStack)) {
|
||||
exist.stackSize += itemStack.stackSize;
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
inputStacks.add(itemStack.copy());
|
||||
}
|
||||
ItemStack outputStack = recipe.getResultStack(recipeIndex).items[0];
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.displayGuiScreen(new GuiEditor(firstGui));
|
||||
GuiContainer myGuiContainer = (GuiContainer) mc.currentScreen;
|
||||
if (myGuiContainer != null) {
|
||||
myGuiContainer.inventorySlots.getSlot(0).putStack(outputStack);
|
||||
for (int i = 8; i <= 8 + inputStacks.size() - 1 && i <= 19; i++) {
|
||||
myGuiContainer.inventorySlots.getSlot(i).putStack(inputStacks.get(i - 8));
|
||||
}
|
||||
//crafting item, nei may not have
|
||||
// myGuiContainer.inventorySlots.getSlot(4).putStack();
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.println(firstGui.getClass().toString());
|
||||
}
|
||||
// if(firstGui instanceof GuiEditor) {
|
||||
// List<ItemStack> inputStacks = new ArrayList<>();
|
||||
// LOOP:
|
||||
// for (PositionedStack positionedStack : recipe.getIngredientStacks(recipeIndex)) {
|
||||
// ItemStack itemStack = positionedStack.items[0];
|
||||
// for (ItemStack exist : inputStacks) {
|
||||
// if (ItemStackHelper.isTypeEqual(exist, itemStack)) {
|
||||
// exist.stackSize += itemStack.stackSize;
|
||||
// continue LOOP;
|
||||
// }
|
||||
// }
|
||||
// inputStacks.add(itemStack.copy());
|
||||
// }
|
||||
// ItemStack outputStack = recipe.getResultStack(recipeIndex).items[0];
|
||||
//
|
||||
// Minecraft mc = Minecraft.getMinecraft();
|
||||
// mc.displayGuiScreen(new GuiEditor(firstGui));
|
||||
// GuiContainer myGuiContainer = (GuiContainer) mc.currentScreen;
|
||||
// if (myGuiContainer != null) {
|
||||
// myGuiContainer.inventorySlots.getSlot(0).putStack(outputStack);
|
||||
// for (int i = 8; i <= 8 + inputStacks.size() - 1 && i <= 19; i++) {
|
||||
// myGuiContainer.inventorySlots.getSlot(i).putStack(inputStacks.get(i - 8));
|
||||
// }
|
||||
// //crafting item, nei may not have
|
||||
// // myGuiContainer.inventorySlots.getSlot(4).putStack();
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// System.out.println(firstGui.getClass().toString());
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package me.towdium.jecalculation.nei;
|
||||
|
||||
import codechicken.nei.guihook.IContainerTooltipHandler;
|
||||
import me.towdium.jecalculation.gui.JecaGuiContainer;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -15,9 +14,9 @@ public class JecaTooltipHandler implements IContainerTooltipHandler {
|
||||
|
||||
@Override
|
||||
public List<String> handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List<String> currenttip) {
|
||||
if (gui instanceof JecaGuiContainer) {
|
||||
((JecaGuiContainer)gui).handleMouseOverNEIItemPanel(itemstack);
|
||||
}
|
||||
// if (gui instanceof JecaGuiContainer) {
|
||||
// ((JecaGuiContainer)gui).handleMouseOverNEIItemPanel(itemstack);
|
||||
// }
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@@ -27,9 +26,9 @@ public class JecaTooltipHandler implements IContainerTooltipHandler {
|
||||
int mousex,
|
||||
int mousey,
|
||||
List<String> currenttip) {
|
||||
if (gui instanceof JecaGuiContainer) {
|
||||
((JecaGuiContainer)gui).handleMouseOverNEIItemPanel(itemstack);
|
||||
}
|
||||
// if (gui instanceof JecaGuiContainer) {
|
||||
// ((JecaGuiContainer)gui).handleMouseOverNEIItemPanel(itemstack);
|
||||
// }
|
||||
return currenttip;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package me.towdium.jecalculation.nei;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.gui.guis.GuiEditor;
|
||||
|
||||
public class NEICalculatorConfig implements IConfigureNEI {
|
||||
|
||||
@@ -11,10 +10,10 @@ public class NEICalculatorConfig implements IConfigureNEI {
|
||||
public void loadConfig() {
|
||||
System.out.println("loaded nei config");
|
||||
String [] recipeType = new String[]{ "crafting", "crafting2x2", "smelting", "fuel", "brewing"};
|
||||
for (String ident : recipeType) {
|
||||
API.registerGuiOverlay(GuiEditor.class, ident);
|
||||
API.registerGuiOverlayHandler(GuiEditor.class, new JecaOverlayHandler(), ident);
|
||||
}
|
||||
// for (String ident : recipeType) {
|
||||
// API.registerGuiOverlay(GuiEditor.class, ident);
|
||||
// API.registerGuiOverlayHandler(GuiEditor.class, new JecaOverlayHandler(), ident);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,6 @@ package me.towdium.jecalculation.nei;
|
||||
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import me.towdium.jecalculation.gui.guis.GuiEditor;
|
||||
|
||||
public class NEIPlugin {
|
||||
public static void init() {
|
||||
|
||||
Reference in new issue
Block a user