feat: Tweak in GUI

This commit is contained in:
Discreater committed 2021-04-28 23:02:57 +08:00
1 parent 595c0cdcb1
commit 4c45f38d12
21 files changed
+316 -189

No files matched your search

@@ -39,45 +39,58 @@ import java.util.function.Function;
@ParametersAreNonnullByDefault
public class JecGui extends GuiContainer {
public static final int COLOR_GREY = 0xFFA1A1A1;
protected static JecGui last;
public static final boolean ALWAYS_TOOLTIP = false;
protected JecGui parent;
public ILabel hand = ILabel.EMPTY;
public DContainer container = new DContainer();
public IDrawable root;
protected List<Triple<Integer, Integer, List<String>>> tooltipBuffer = new ArrayList<>();
public JecGui(@Nullable JecGui parent, IDrawable... drawables) {
this(parent, false, drawables);
public JecGui(@Nullable JecGui parent, IDrawable root) {
this(parent, false, root);
}
public JecGui(@Nullable JecGui parent, boolean acceptsTransfer, IDrawable... drawables) {
public JecGui(@Nullable JecGui parent, boolean acceptsTransfer, IDrawable root) {
super(acceptsTransfer ? new ContainerTransfer() : new ContainerNonTransfer());
this.parent = parent;
container.addAll(drawables);
this.root = root;
}
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;
}
public static void displayGui(IDrawable... components) {
displayGui(true, false, components);
public static void displayGui(IDrawable root) {
displayGui(true, false, root);
}
public static void displayGui(boolean updateParent, boolean acceptsTransfer, IDrawable... components) {
public static void displayGui(boolean updateParent, boolean acceptsTransfer, IDrawable root) {
// isCallingFromMinecraftThread
if (Minecraft.getMinecraft().func_152345_ab())
displayGuiUnsafe(updateParent, acceptsTransfer, components);
displayGuiUnsafe(updateParent, acceptsTransfer, root);
}
public static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, IDrawable... components) {
public static JecGui getCurrent() {
return last;
}
private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, IDrawable root) {
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));
JecGui toShow = new JecGui(parent, acceptsTransfer, root);
mc.displayGuiScreen(toShow);
last = toShow;
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
last = null;
}
@Override
@@ -97,7 +110,7 @@ public class JecGui extends GuiContainer {
GlStateManager.translate(guiLeft, guiTop, 0);
GlStateManager.disableLighting();
GlStateManager.disableDepth();
container.onDraw(this, mouseX - guiLeft, mouseY - guiTop);
root.onDraw(this, mouseX - guiLeft, mouseY - guiTop);
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
GlStateManager.translate(mouseX - 8, mouseY - 8, 0);
@@ -318,10 +331,6 @@ public class JecGui extends GuiContainer {
RenderHelper.disableStandardItemLighting();
}
public String localize(String key, Object... os) {
return LocalizationHelper.format(this.getClass(), "gui", key, os);
}
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);
@@ -358,7 +367,7 @@ public class JecGui extends GuiContainer {
@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);
boolean inGui = root.onClicked(this, mouseX - guiLeft, mouseY - guiTop, mouseButton);
if(!inGui) {
this.handleMouseEvent();
}
@@ -366,7 +375,7 @@ public class JecGui extends GuiContainer {
@Override
protected void keyTyped(char typedChar, int keyCode) {
if (!container.onKey(this, typedChar, keyCode)) {
if (!root.onKey(this, typedChar, keyCode)) {
if (keyCode == Keyboard.KEY_ESCAPE) {
if (hand != ILabel.EMPTY)
hand = ILabel.EMPTY;
@@ -36,8 +36,9 @@ 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 WGT_PAGER_FN = new Resource(120, 232, 20, 20);
public static final Resource WGT_PAGER_F0 = new Resource(140, 232, 20, 20);
public static final Resource WGT_PAGER_N = new Resource(160, 232, 20, 20);
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);
@@ -46,6 +47,7 @@ public class Resource {
public static final Resource ICN_OUTPUT_F = new Resource(28, 28, 14, 14);
public static final Resource ICN_CATALYST_N = new Resource(42, 42, 14, 14);
public static final Resource ICN_CATALYST_F = new Resource(42, 28, 14, 14);
public static final Resource LBL_ORE_DICT = new Resource(0, 56, 16, 16);
protected int xPos, yPos, xSize, ySize;
protected ResourceLocation rl;
@@ -14,31 +14,17 @@ import javax.annotation.ParametersAreNonnullByDefault;
* Date: 17-8-17.
*/
@ParametersAreNonnullByDefault
public class DButton implements IDrawable {
public abstract class DButton extends DTooltip {
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) {
public DButton(int xPos, int yPos, int xSize, int ySize, @Nullable String name) {
super(name);
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) {
@@ -56,22 +42,6 @@ public class DButton implements IDrawable {
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
@@ -89,4 +59,9 @@ public class DButton implements IDrawable {
}
return false;
}
@Override
boolean mouseIn(int xMouse, int yMouse) {
return JecGui.mouseIn(xPos + 1, yPos + 1, xSize - 2, ySize - 2, xMouse, yMouse);
}
}
@@ -0,0 +1,34 @@
package me.towdium.jecalculation.client.gui.drawables;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-9-16.
*/
@ParametersAreNonnullByDefault
public class DButtonIcon extends DButton {
protected Resource normal, focused;
public DButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
this(xPos, yPos, xSize, ySize, normal, focused, null);
}
public DButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused, @Nullable String name) {
super(xPos, yPos, xSize, ySize, name);
this.normal = normal;
this.focused = focused;
}
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
super.onDraw(gui, xMouse, yMouse);
Resource r = mouseIn(xMouse, yMouse) ? focused : normal;
if (r != null)
gui.drawResource(r, xPos + (xSize - r.getXSize()) / 2, yPos + (ySize - r.getYSize()) / 2);
}
}
@@ -0,0 +1,32 @@
package me.towdium.jecalculation.client.gui.drawables;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.utils.helpers.LocalizationHelper;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-9-16.
*/
@ParametersAreNonnullByDefault
public class DButtonText extends DButton {
public DButtonText(int xPos, int yPos, int xSize, int ySize, String name) {
super(xPos, yPos, xSize, ySize, name);
}
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
super.onDraw(gui, xMouse, yMouse);
int textColor = mouseIn(xMouse, yMouse) ? 16777120 : 0;
String text = LocalizationHelper.format(String.join(".", "gui", name, "text"));
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);
}
}
@@ -34,6 +34,10 @@ public class DContainer implements IDrawable {
remove(aw);
}
public void clear() {
widgets.clear();
}
public void onDraw(JecGui gui, int mouseX, int mouseY) {
widgets.forEach(widget -> widget.onDraw(gui, mouseX, mouseY));
}
@@ -14,37 +14,36 @@ import javax.annotation.ParametersAreNonnullByDefault;
* Date: 17-8-18.
*/
@ParametersAreNonnullByDefault
public class DIcon implements IDrawable {
public class DIcon extends DTooltip {
public int xPos, yPos, xSize, ySize;
public Resource normal, focused;
Timer timer = new Timer();
public String tooltip;
public DIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
this(xPos, yPos, xSize, ySize, normal, focused, null);
}
public DIcon(int xPos, int yPos, int xSize, int ySize,
Resource normal, Resource focused, @Nullable String tooltip) {
Resource normal, Resource focused, @Nullable String name) {
super(name);
this.xPos = xPos;
this.yPos = yPos;
this.xSize = xSize;
this.ySize = ySize;
this.normal = normal;
this.focused = focused;
this.tooltip = tooltip;
}
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
boolean hovered = JecGui.mouseIn(xPos + (xSize - normal.getXSize()) / 2,
yPos + (ySize - normal.getYSize()) / 2, normal.getXSize(), normal.getYSize(), xMouse, yMouse);
super.onDraw(gui, xMouse, yMouse);
gui.drawRectangle(xPos, yPos, xSize, ySize, JecGui.COLOR_GREY);
Resource r = hovered ? focused : normal;
Resource r = mouseIn(xMouse, yMouse) ? focused : normal;
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));
}
}
@Override
boolean mouseIn(int xMouse, int yMouse) {
return JecGui.mouseIn(xPos + (xSize - normal.getXSize()) / 2,
yPos + (ySize - normal.getYSize()) / 2, normal.getXSize(), normal.getYSize(), xMouse, yMouse);
}
}
@@ -0,0 +1,54 @@
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.Utilities;
import me.towdium.jecalculation.utils.helpers.LocalizationHelper;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-9-16.
*/
@ParametersAreNonnullByDefault
public class DPage implements IDrawable {
protected int index;
protected ILabel.RegistryEditor.Record record;
protected Utilities.Timer timer = new Utilities.Timer();
protected boolean focused;
protected Runnable listener;
public DPage(int index, ILabel.RegistryEditor.Record record, boolean focused) {
this.index = index;
this.record = record;
this.focused = focused;
}
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
Resource resource = focused ? (index == 0 ? Resource.WGT_PAGER_F0 : Resource.WGT_PAGER_FN)
: Resource.WGT_PAGER_N;
gui.drawResourceContinuous(resource, index * 24, -21, 24, 25, 4, 4, 4, 4);
record.representation.drawEntry(gui, index * 24 + 4, -17, false);
timer.setState(JecGui.mouseIn(index * 24, -21, 24, 21, xMouse, yMouse));
if (timer.getTime() > 1000)
gui.drawTooltip(xMouse, yMouse, LocalizationHelper.format("gui." + record.localizeKey));
}
@Override
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
boolean ret = JecGui.mouseIn(index * 24, -21, 24, 21, xMouse, yMouse) && listener != null && !focused;
if (ret) listener.run();
return ret;
}
public DPage setListener(Runnable r) {
listener = r;
return this;
}
}
@@ -1,45 +0,0 @@
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;
}
}
}
@@ -36,9 +36,9 @@ public class DScroll implements IDrawable {
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)
left = new DButtonIcon(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,
right = new DButtonIcon(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);
@@ -0,0 +1,38 @@
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.utils.Utilities;
import me.towdium.jecalculation.utils.helpers.LocalizationHelper;
import me.towdium.jecalculation.utils.wrappers.Pair;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-9-16.
*/
@ParametersAreNonnullByDefault
public abstract class DTooltip implements IDrawable {
@Nullable
public String name;
Utilities.Timer timer = new Utilities.Timer();
public DTooltip(@Nullable String name) {
this.name = name;
}
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
if (name != null) {
timer.setState(mouseIn(xMouse, yMouse));
if (timer.getTime() > 500) {
Pair<String, Boolean> str = LocalizationHelper.search(String.join(".", "gui", name, "tooltip"));
if (str.two || JecGui.ALWAYS_TOOLTIP) gui.drawTooltip(xMouse, yMouse, str.one);
}
}
}
abstract boolean mouseIn(int xMouse, int yMouse);
}
@@ -17,16 +17,19 @@ 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 DButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "calculator.label")
.setListenerLeft(() -> JecGui.displayGui(new GuiLabel(l -> {
JecGui.displayGui(this);
JecGui.getCurrent().hand = l;
}))));
add(new DButtonIcon(130, 7, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "calculator.recipe")
.setListenerLeft(() -> JecGui.displayGui(new GuiRecipe())));
add(new DButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH_N, Resource.BTN_SEARCH_F, "calculator.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 DIcon(151, 31, 18, 18, Resource.ICN_RECENT_N, Resource.ICN_RECENT_F, "calculator.history"));
add(new DScroll(7, 56, 162, 5));
}
}
@@ -0,0 +1,53 @@
package me.towdium.jecalculation.client.gui.guis;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.Weigher;
import me.towdium.jecalculation.client.gui.IDrawable;
import me.towdium.jecalculation.client.gui.drawables.DContainer;
import me.towdium.jecalculation.client.gui.drawables.DPage;
import me.towdium.jecalculation.client.gui.drawables.DPanel;
import me.towdium.jecalculation.core.labels.ILabel;
import me.towdium.jecalculation.utils.wrappers.Single;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
/**
* Author: towdium
* Date: 17-9-14.
*/
@ParametersAreNonnullByDefault
public class GuiLabel extends DContainer {
DContainer container = new DContainer();
Consumer<ILabel> callback;
LoadingCache<Integer, IDrawable> cache = CacheBuilder.newBuilder().concurrencyLevel(1)
.maximumWeight(16).weigher((Weigher<Integer, IDrawable>) (key, value) -> 1)
.build(new CacheLoader<Integer, IDrawable>() {
@Override
public IDrawable load(Integer i) {
ILabel.RegistryEditor.Record record = ILabel.EDITOR.getRecords().get(i);
return record.editor.setCallback(callback);
}
});
public GuiLabel(Consumer<ILabel> callback) {
this.callback = callback;
Single<Integer> index = new Single<>(0);
ILabel.EDITOR.getRecords().forEach(r -> {
int i = index.value;
add(new DPage(0, r, false).setListener(() -> refresh(i)));
index.value += 1;
});
add(new DPanel());
add(container);
refresh(0);
}
protected void refresh(int index) {
container.clear();
container.add(cache.getUnchecked(index));
container.add(new DPage(index, ILabel.EDITOR.getRecords().get(index), true));
}
}
@@ -1,16 +0,0 @@
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());
}
}
@@ -9,26 +9,26 @@ import static me.towdium.jecalculation.client.gui.drawables.DLabel.enumMode.EDIT
* Author: towdium
* Date: 17-9-8.
*/
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");
public class GuiRecipe extends DContainer {
DButton buttonSave = new DButtonIcon(26, 33, 20, 20, Resource.BTN_SAVE_N, Resource.BTN_SAVE_F, "recipe.save");
DButton buttonCopy = new DButtonIcon(83, 33, 20, 20, Resource.BTN_COPY_N, Resource.BTN_COPY_F, "recipe.copy");
DButton buttonDel = new DButtonIcon(64, 33, 20, 20, Resource.BTN_DEL_N, Resource.BTN_DEL_F, "recipe.clear");
DButton buttonLabel = new DButtonIcon(45, 33, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "recipe.label");
DButton buttonYes = new DButtonIcon(7, 33, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F, "recipe.confirm");
DButton buttonNo = new DButtonIcon(26, 33, 20, 20, Resource.BTN_NO_N, Resource.BTN_NO_F, "recipe.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")
DButton buttonNew = new DButtonIcon(7, 33, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "recipe.new")
.setListenerLeft(() -> setModeNewGroup(true));
public GuiEditor() {
public GuiRecipe() {
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 DIcon(7, 63, 21, 20, Resource.ICN_OUTPUT_N, Resource.ICN_OUTPUT_F, "recipe.output"));
add(new DIcon(7, 87, 21, 20, Resource.ICN_CATALYST_N, Resource.ICN_CATALYST_F, "recipe.catalyst"));
add(new DIcon(7, 111, 21, 40, Resource.ICN_INPUT_N, Resource.ICN_INPUT_F, "recipe.input"));
add(new DLine(57));
addAll(groupInput, groupCatalyst, groupOutput);
setModeNewGroup(false);
@@ -28,7 +28,10 @@ public interface ILabel {
RegistryDeserializer DESERIALIZER = RegistryDeserializer.INSTANCE;
RegistryConverterItem CONVERTER_ITEM = RegistryConverterItem.INSTANCE;
RegistryConverterFluid CONVERTER_FLUID = RegistryConverterFluid.INSTANCE;
RegistryEditor EDITOR = RegistryEditor.INSTANCE;
ILabel EMPTY = new LabelItemStack(ItemStackHelper.EMPTY_ITEM_STACK, 0);
String LOCALIZE_PREFIX = "label";
String LOCALIZE_SUFFIX = "name";
ILabel increaseAmount();
@@ -215,7 +218,7 @@ public interface ILabel {
static {
INSTANCE = new RegistryEditor();
INSTANCE.register(LabelOreDict.getEditor(), "ore_dict", new LabelOreDict("ingotIron"));
INSTANCE.register(LabelOreDict.getEditor(), "common.label.ore_dict", new LabelOreDict("ingotIron"));
}
private ArrayList<Record> records = new ArrayList<>();
@@ -227,22 +230,22 @@ public interface ILabel {
records.add(new Record(editor, unlocalizedName, representation));
}
public Collection<Record> getRecords() {
public List<Record> getRecords() {
return records;
}
public interface IEditor extends IDrawable {
void setCallback(Consumer<ILabel> callback);
IEditor setCallback(Consumer<ILabel> callback);
}
public static class Record {
public IEditor editor;
public String unlocalizedName;
public String localizeKey;
public ILabel representation;
public Record(IEditor editor, String unlocalizedName, ILabel representation) {
public Record(IEditor editor, String localizeKey, ILabel representation) {
this.editor = editor;
this.unlocalizedName = unlocalizedName;
this.localizeKey = localizeKey;
this.representation = representation;
}
}
@@ -1,6 +1,7 @@
package me.towdium.jecalculation.core.labels.labels;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.client.gui.drawables.DContainer;
import me.towdium.jecalculation.client.gui.drawables.DText;
import me.towdium.jecalculation.core.labels.ILabel;
@@ -11,12 +12,14 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
/**
* Author: towdium
* Date: 17-9-10.
*/
@ParametersAreNonnullByDefault
public class LabelOreDict extends LabelSimpleAmount {
public static final String IDENTIFIER = "oreDict";
public static final String KEY_NAME = "name";
@@ -65,8 +68,9 @@ public class LabelOreDict extends LabelSimpleAmount {
is.getItem().getSubItems(is.getItem(), CreativeTabs.tabAllSearch, list);
} else list.add(is);
});
if(list.isEmpty()) return;
long index = System.currentTimeMillis() / 1500;
gui.drawResource(Resource.LBL_ORE_DICT, 0, 0);
GlStateManager.pushMatrix();
GlStateManager.translate(1, 1, 0);
GlStateManager.scale(14f / 16, 14f / 16, 1);
@@ -83,15 +87,22 @@ public class LabelOreDict extends LabelSimpleAmount {
}
public static class Editor extends DContainer implements RegistryEditor.IEditor {
Consumer<ILabel> label;
Consumer<ILabel> callback;
public Editor() {
add(new DText(5, 5, JecGui.Font.DEFAULT_NO_SHADOW, "hello"));
}
@Override
public void setCallback(Consumer<ILabel> callback) {
label = callback;
public RegistryEditor.IEditor setCallback(Consumer<ILabel> callback) {
this.callback = callback;
return this;
}
@Override
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
callback.accept(new LabelOreDict("plankWood"));
return super.onClicked(gui, xMouse, yMouse, button);
}
}
}
@@ -4,8 +4,7 @@ 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.client.gui.guis.GuiRecipe;
import me.towdium.jecalculation.utils.ItemStackHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
@@ -33,7 +32,7 @@ public class JecaOverlayHandler implements IOverlayHandler {
ItemStack outputStack = recipe.getResultStack(recipeIndex).items[0];
Minecraft mc = Minecraft.getMinecraft();
JecGui.displayGui(new GuiEditor());
JecGui.displayGui(new GuiRecipe());
GuiContainer myGuiContainer = (GuiContainer) mc.currentScreen;
if (myGuiContainer != null) {
myGuiContainer.inventorySlots.getSlot(0).putStack(outputStack);
@@ -23,35 +23,7 @@ public class LocalizationHelper {
return ret;
}
/**
* @param c the (super) class name will be used after prefix translation key
* @param prefix the prefix of translation key
* @param translateKey the body of translation key
* @param parameters format parameters
* @return the localized value
* The localized key is "prefix.className(superClassName).translateKey".
* It will search all the super classes.
*/
public static Pair<String, Boolean> search(Class c, String prefix, String translateKey, Object... parameters) {
String clazz = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, c.getSimpleName());
String key = String.join(".", prefix, clazz, translateKey);
Pair<String, Boolean> ret = LocalizationHelper.search(key, parameters);
if (ret.two || c.equals(Object.class))
return ret;
else {
ret = search(c.getSuperclass(), prefix, translateKey, parameters);
if (ret.two)
return ret;
else
return ret.setOne(key);
}
}
public static String format(String translateKey, Object... parameters) {
return search(translateKey, parameters).one;
}
public static String format(Class c, String prefix, String translateKey, Object... parameters) {
return search(c, prefix, translateKey, parameters).one;
}
}
@@ -10,6 +10,6 @@ command.state.s_client=client only
command.state.s_both=client with server
command.state.s_undefined=error state
gui.gui_calculator.tooltip.new_recipe=New recipe
gui.gui_calculator.name.new_recipe=New recipe
config.force_client=Force Client
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 10 KiB