feat: Gui Disambiguation

This commit is contained in:
Discreater committed 2021-04-28 23:39:49 +08:00
1 parent 4c45f38d12
commit 2ec160b9f0
25 files changed
+362 -133

No files matched your search

@@ -3,14 +3,6 @@ package me.towdium.jecalculation.client.gui;
import me.towdium.jecalculation.client.gui.JecGui;
public interface IDrawable {
static int gl(JecGui gui) {
return gui.getGuiLeft();
}
static int gt(JecGui gui) {
return gui.getGuiTop();
}
void onDraw(JecGui gui, int xMouse, int yMouse);
default boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
@@ -20,4 +12,8 @@ public interface IDrawable {
default boolean onKey(JecGui gui, char ch, int code) {
return false;
}
default boolean onScroll(JecGui gui, int xMouse, int yMouse, int diff) {
return false;
}
}
@@ -7,7 +7,6 @@ import me.towdium.jecalculation.core.labels.ILabel;
import me.towdium.jecalculation.nei.NEIPlugin;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.utils.IllegalPositionException;
import me.towdium.jecalculation.utils.helpers.LocalizationHelper;
import me.towdium.jecalculation.utils.wrappers.Single;
import me.towdium.jecalculation.utils.wrappers.Triple;
import net.minecraft.client.Minecraft;
@@ -38,7 +37,9 @@ import java.util.function.Function;
*/
@ParametersAreNonnullByDefault
public class JecGui extends GuiContainer {
public static final int COLOR_GREY = 0xFFA1A1A1;
public static final int COLOR_GUI_GREY = 0xFFA1A1A1;
public static final int COLOR_TEXT_RED = 0xFF0000;
public static final int COLOR_TEXT_WHITE = 0xFFFFFF;
protected static JecGui last;
public static final boolean ALWAYS_TOOLTIP = false;
@@ -302,11 +303,11 @@ public class JecGui extends GuiContainer {
}
public void drawTooltip(int xPos, int yPos, String... text) {
drawTooltip(xPos + guiLeft, yPos + guiTop, Arrays.asList(text));
drawTooltip(xPos, yPos, Arrays.asList(text));
}
public void drawTooltip(int xPos, int yPos, List<String> text) {
tooltipBuffer.add(new Triple<>(xPos, yPos, text));
tooltipBuffer.add(new Triple<>(xPos + guiLeft, yPos + guiTop, text));
}
protected void drawBufferedTooltip() {
@@ -26,19 +26,22 @@ public class Resource {
public static final Resource BTN_YES_F = new Resource(84, 0, 14, 14);
public static final Resource BTN_NO_N = new Resource(98, 14, 14, 14);
public static final Resource BTN_NO_F = new Resource(98, 0, 14, 14);
public static final Resource WGT_BUTTON_N = new Resource(60, 232, 20, 20);
public static final Resource WGT_BUTTON_F = new Resource(80, 232, 20, 20);
public static final Resource WGT_BUTTON_D = new Resource(100, 232, 20, 20);
public static final Resource WGT_SLOT = new Resource(40, 232, 20, 20);
public static final Resource WGT_BUTTON_N = new Resource(40, 232, 20, 20);
public static final Resource WGT_BUTTON_F = new Resource(60, 232, 20, 20);
public static final Resource WGT_BUTTON_D = new Resource(80, 232, 20, 20);
public static final Resource WGT_SLOT = new Resource(20, 232, 20, 20);
public static final Resource WGT_LINE = new Resource(0, 252, 163, 4);
public static final Resource WGT_PANEL = new Resource(20, 232, 20, 20);
public static final Resource WGT_ARR_L_F = new Resource(0, 232, 9, 9);
public static final Resource WGT_ARR_L_N = new Resource(0, 242, 9, 9);
public static final Resource WGT_ARR_R_F = new Resource(10, 232, 9, 9);
public static final Resource WGT_ARR_R_N = new Resource(10, 242, 9, 9);
public static final Resource 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 WGT_PANEL = new Resource(0, 232, 20, 20);
public static final Resource WGT_PAGER_FN = new Resource(100, 232, 20, 20);
public static final Resource WGT_PAGER_F0 = new Resource(120, 232, 20, 20);
public static final Resource WGT_PAGER_N = new Resource(140, 232, 20, 20);
public static final Resource WGT_ARR_L_F = new Resource(160, 232, 7, 9);
public static final Resource WGT_ARR_L_N = new Resource(167, 232, 7, 9);
public static final Resource WGT_ARR_L_D = new Resource(174, 232, 7, 9);
public static final Resource WGT_ARR_R_F = new Resource(160, 242, 7, 9);
public static final Resource WGT_ARR_R_N = new Resource(167, 242, 7, 9);
public static final Resource WGT_ARR_R_D = new Resource(174, 242, 7, 9);
public static final Resource WGT_SCROLL = new Resource(181, 232, 12, 15);
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);
@@ -47,6 +50,12 @@ 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 ICN_LIST_N = new Resource(56, 42, 14, 14);
public static final Resource ICN_LIST_F = new Resource(56, 28, 14, 14);
public static final Resource ICN_LABEL_N = new Resource(70, 42, 14, 14);
public static final Resource ICN_LABEL_F = new Resource(70, 28, 14, 14);
public static final Resource ICN_HELP_N = new Resource(84, 42, 14, 14);
public static final Resource ICN_HELP_F = new Resource(84, 28, 14, 14);
public static final Resource LBL_ORE_DICT = new Resource(0, 56, 16, 16);
protected int xPos, yPos, xSize, ySize;
@@ -1,7 +1,7 @@
package me.towdium.jecalculation.client.gui.drawables;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.utils.helpers.LocalizationHelper;
import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -19,7 +19,7 @@ public class DButtonText extends DButton {
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"));
String text = Utilities.L18n.format(String.join(".", "gui", name, "text"));
int strWidth = gui.getFontRenderer().getStringWidth(text);
int ellipsisWidth = gui.getFontRenderer().getStringWidth("...");
String str = text;
@@ -38,21 +38,26 @@ public class DContainer implements IDrawable {
widgets.clear();
}
@Override
public void onDraw(JecGui gui, int mouseX, int mouseY) {
widgets.forEach(widget -> widget.onDraw(gui, mouseX, mouseY));
}
@Override
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
for (IDrawable w : widgets) {
if (w.onClicked(gui, xMouse, yMouse, button)) return true;
}
for (IDrawable w : widgets) if (w.onClicked(gui, xMouse, yMouse, button)) return true;
return false;
}
@Override
public boolean onKey(JecGui gui, char ch, int code) {
for (IDrawable w : widgets) {
if (w.onKey(gui, ch, code)) return true;
}
for (IDrawable w : widgets) if (w.onKey(gui, ch, code)) return true;
return false;
}
@Override
public boolean onScroll(JecGui gui, int xMouse, int yMouse, int diff) {
for (IDrawable w : widgets) if (w.onScroll(gui, xMouse, yMouse, diff)) return true;
return false;
}
@@ -36,7 +36,7 @@ public class DIcon extends DTooltip {
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
super.onDraw(gui, xMouse, yMouse);
gui.drawRectangle(xPos, yPos, xSize, ySize, JecGui.COLOR_GREY);
gui.drawRectangle(xPos, yPos, xSize, ySize, JecGui.COLOR_GUI_GREY);
Resource r = mouseIn(xMouse, yMouse) ? focused : normal;
gui.drawResource(r, (xSize - r.getXSize()) / 2 + xPos, (ySize - r.getYSize()) / 2 + yPos);
}
@@ -7,6 +7,7 @@ import me.towdium.jecalculation.core.labels.ILabel;
import me.towdium.jecalculation.utils.IllegalPositionException;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
/**
* Author: towdium
@@ -22,7 +23,7 @@ public class DLabel implements IDrawable {
}
public int xPos, yPos, xSize, ySize;
public ILabel ILabel;
public ILabel label;
public enumMode mode;
public DLabel(int xPos, int yPos, int xSize, int ySize, enumMode mode) {
@@ -30,51 +31,55 @@ public class DLabel implements IDrawable {
this.yPos = yPos;
this.xSize = xSize;
this.ySize = ySize;
this.ILabel = ILabel.EMPTY;
this.label = label.EMPTY;
this.mode = mode;
}
public ILabel getILabel() {
return ILabel;
public ILabel getLabel() {
return label;
}
public void setILabel(ILabel ILabel) {
this.ILabel = ILabel;
public void setLabel(ILabel label) {
this.label = label;
}
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
gui.drawResourceContinuous(Resource.WGT_SLOT, xPos, yPos, xSize, ySize, 3, 3, 3, 3);
ILabel.drawEntry(gui, xPos + xSize / 2, yPos + ySize / 2, true);
label.drawEntry(gui, xPos + xSize / 2, yPos + ySize / 2, true);
if (mode == enumMode.RESULT || mode == enumMode.EDITOR)
gui.drawText(xPos + xSize / 2 + 7.5f,
yPos + ySize / 2 + 7 - (int) (font.size * gui.getFontRenderer().FONT_HEIGHT), font,
ILabel.getAmountString());
if (mouseIn(gui, xMouse, yMouse))
label.getAmountString());
if (mouseIn(xMouse, yMouse)) {
gui.drawRectangle(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF);
ArrayList<String> buf = new ArrayList<>();
buf.add(label.getDisplayName());
gui.drawTooltip(xMouse, yMouse, label.getToolTip(buf));
}
}
@Override
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
if (mouseIn(gui, xMouse, yMouse)) {
if (mouseIn(xMouse, yMouse)) {
switch (mode) {
case EDITOR:
if (gui.hand != ILabel.EMPTY) {
ILabel = gui.hand;
gui.hand = ILabel.EMPTY;
if (gui.hand != label.EMPTY) {
label = gui.hand;
gui.hand = label.EMPTY;
return true;
} else if (ILabel != ILabel.EMPTY) {
} else if (label != label.EMPTY) {
if (button == 0) {
if (JecGui.isShiftDown())
ILabel = ILabel.increaseAmountLarge();
label = label.increaseAmountLarge();
else
ILabel = ILabel.increaseAmount();
label = label.increaseAmount();
return true;
} else if (button == 1) {
if (JecGui.isShiftDown())
ILabel = ILabel.decreaseAmountLarge();
label = label.decreaseAmountLarge();
else
ILabel = ILabel.decreaseAmount();
label = label.decreaseAmount();
return true;
}
} else
@@ -82,14 +87,14 @@ public class DLabel implements IDrawable {
case RESULT:
return false;
case PICKER:
if (ILabel != ILabel.EMPTY) {
gui.hand = ILabel.copy();
if (label != label.EMPTY) {
gui.hand = label.copy();
return true;
} else
return false;
case SELECTOR:
ILabel = gui.hand;
gui.hand = ILabel.EMPTY;
label = gui.hand;
gui.hand = label.EMPTY;
return true;
default:
throw new IllegalPositionException();
@@ -98,7 +103,7 @@ public class DLabel implements IDrawable {
return false;
}
public boolean mouseIn(JecGui gui, int x, int y) {
public boolean mouseIn(int x, int y) {
int xx = x - xPos;
int yy = y - yPos;
return xx >= 0 && xx < xSize && yy >= 0 && yy < ySize;
@@ -1,10 +1,13 @@
package me.towdium.jecalculation.client.gui.drawables;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.IDrawable;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.core.labels.ILabel;
import me.towdium.jecalculation.utils.wrappers.Single;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.IntStream;
@@ -21,8 +24,8 @@ public class DLabelGroup implements IDrawable {
}
public DLabelGroup(int xPos, int yPos, int column, int row, int xSize, int ySize, DLabel.enumMode mode) {
IntStream.range(0, column).forEach(c -> IntStream.range(0, row).forEach(r ->
widgets.add(new DLabel(xPos + c * xSize, yPos + r * ySize, xSize, ySize, mode))));
IntStream.range(0, row).forEach(r -> IntStream.range(0, column).forEach(
c -> widgets.add(new DLabel(xPos + c * xSize, yPos + r * ySize, xSize, ySize, mode))));
}
@Override
@@ -35,7 +38,12 @@ public class DLabelGroup implements IDrawable {
return widgets.stream().anyMatch(w -> w.onClicked(gui, xMouse, yMouse, button));
}
public Optional<DLabel> getEntryAt(JecGui gui, int xMouse, int yMouse) {
return widgets.stream().filter(w -> w.mouseIn(gui, xMouse, yMouse)).findFirst();
public Optional<DLabel> getEntryAt(int xMouse, int yMouse) {
return widgets.stream().filter(w -> w.mouseIn(xMouse, yMouse)).findFirst();
}
public void setLabel(List<ILabel> labels, int start) {
Single<Integer> i = new Single<>(start);
widgets.forEach(l -> l.setLabel(i.value < labels.size() ? labels.get(i.value++) : ILabel.EMPTY));
}
}
@@ -0,0 +1,73 @@
package me.towdium.jecalculation.client.gui.drawables;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.core.labels.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Author: towdium
* Date: 17-9-17.
*/
@ParametersAreNonnullByDefault
public class DLabelScroll extends DContainer {
protected List<ILabel> labels = new ArrayList<>();
protected List<ILabel> filtered = new ArrayList<>();
protected DLabelGroup labelGroup;
protected DScroll scroll;
protected int xPos, yPos, column, row, current;
protected String filter = "";
public DLabelScroll(int xPos, int yPos, int column, int row, DLabel.enumMode mode, boolean drawConnection) {
this.xPos = xPos;
this.yPos = yPos;
this.column = column;
this.row = row;
labelGroup = new DLabelGroup(xPos, yPos, column, row, mode);
scroll = new DScroll(xPos + column * 18 + 4, yPos, row * 18).setLsnrScroll(this::update);
add(labelGroup);
add(scroll);
if (drawConnection) add(new DRectangle(xPos + column * 18, yPos, 4, row * 18, JecGui.COLOR_GUI_GREY));
}
public void update(float f) {
int step = getStepAmount();
current = (int) (step * f);
if (current == step) current--;
labelGroup.setLabel(filtered, current * column);
}
@Override
public boolean onScroll(JecGui gui, int xMouse, int yMouse, int diff) {
boolean in = JecGui.mouseIn(xPos, yPos, column * 18, row * 18, xMouse, yMouse);
if (in) scroll.setCurrent(getPos(current - diff));
return in;
}
private float getPos(int step) {
return 1f / (getStepAmount() - 1) * step;
}
public DLabelScroll setLabels(List<ILabel> labels) {
this.labels = labels;
setFilter(filter);
return this;
}
public boolean setFilter(String str) {
filter = str;
filtered = labels.stream().filter(l -> Utilities.contains(l.getDisplayName(), str))
.collect(Collectors.toList());
scroll.setCurrent(0);
return filtered.size() != 0;
}
private int getStepAmount() {
int line = (labels.size() + column - 1) / column;
return line - row + 1;
}
}
@@ -5,7 +5,6 @@ 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;
@@ -37,7 +36,7 @@ public class DPage implements IDrawable {
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));
gui.drawTooltip(xMouse, yMouse, Utilities.L18n.format("gui." + record.localizeKey));
}
@Override
@@ -4,9 +4,11 @@ import me.towdium.jecalculation.client.gui.IDrawable;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.utils.Utilities.Circulator;
import org.lwjgl.input.Mouse;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@@ -17,48 +19,49 @@ import java.util.stream.Stream;
*/
@ParametersAreNonnullByDefault
public class DScroll implements IDrawable {
public static final int SIZE = 13;
public int xPos, yPos, ySize, current;
public Consumer<Float> lsnrScroll;
protected boolean drag;
protected int xPos, xSize, yPos;
protected DButton left, right;
protected DRectangle wRect;
protected DText dText;
protected List<String> keys;
protected Circulator index;
public DScroll(int xPos, int yPos, int xSize, int total) {
this(xPos, yPos, xSize, IntStream.rangeClosed(1, total)
.mapToObj(i -> i + "/" + total).collect(Collectors.toList()));
}
public DScroll(int xPos, int yPos, int xSize, List<String> keys) {
public DScroll(int xPos, int yPos, int ySize) {
this.xPos = xPos;
this.xSize = xSize;
this.yPos = yPos;
this.keys = keys;
left = new DButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WGT_ARR_L_N, Resource.WGT_ARR_L_F)
.setListenerLeft(() -> index.prev());
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);
dText = new DText(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.Font.DEFAULT_SHADOW,
() -> keys.get(index.index()));
index = new Circulator(keys.size());
this.ySize = ySize;
}
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
Stream.of(left, right, wRect, dText).forEach(w -> w.onDraw(gui, xMouse, yMouse));
if (Mouse.isButtonDown(0) && drag) setCurrent(yMouse);
else drag = false;
gui.drawResourceContinuous(Resource.WGT_SLOT, xPos, yPos, 14, ySize, 3, 3, 3, 3);
gui.drawResource(Resource.WGT_SCROLL, xPos + 1, yPos + 1 + current);
}
@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));
drag = mouseIn(xMouse, yMouse);
if (drag) setCurrent(yMouse - yPos - 9);
return drag;
}
@Override
public boolean onKey(JecGui gui, char ch, int code) {
return Stream.of(left, right).anyMatch(w -> w.onKey(gui, ch, code));
private void setCurrent(int pos) {
current = pos;
if (current < 0) current = 0;
if (current > ySize - 17) current = ySize - 17;
if (lsnrScroll != null) lsnrScroll.accept(current / (ySize - 17f));
}
public void setCurrent(float ratio) {
setCurrent((int) ((ySize - 17) * ratio));
}
public boolean mouseIn(int xMouse, int yMouse) {
return JecGui.mouseIn(xPos + 1, yPos + 1, 12, ySize - 2, xMouse, yMouse);
}
public DScroll setLsnrScroll(Consumer<Float> lsnrScroll) {
this.lsnrScroll = lsnrScroll;
return this;
}
}
@@ -0,0 +1,63 @@
package me.towdium.jecalculation.client.gui.drawables;
import me.towdium.jecalculation.client.gui.IDrawable;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.utils.Utilities.Circulator;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
* Author: towdium
* Date: 17-8-19.
*/
@ParametersAreNonnullByDefault
public class DSwitcher implements IDrawable {
public static final int SIZE = 13;
protected int xPos, xSize, yPos;
protected DButton left, right;
protected DRectangle wRect;
protected DText dText;
protected List<String> keys;
protected Circulator index;
public DSwitcher(int xPos, int yPos, int xSize, int total) {
this(xPos, yPos, xSize, IntStream.rangeClosed(1, total)
.mapToObj(i -> i + "/" + total).collect(Collectors.toList()));
}
public DSwitcher(int xPos, int yPos, int xSize, List<String> keys) {
this.xPos = xPos;
this.xSize = xSize;
this.yPos = yPos;
this.keys = keys;
left = new DButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WGT_ARR_L_N, Resource.WGT_ARR_L_F)
.setListenerLeft(() -> index.prev());
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_GUI_GREY);
dText = new DText(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.Font.DEFAULT_SHADOW,
() -> keys.get(index.index()));
index = new Circulator(keys.size());
}
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
Stream.of(left, right, wRect, dText).forEach(w -> w.onDraw(gui, xMouse, yMouse));
}
@Override
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
return Stream.of(left, right).anyMatch(w -> w.onClicked(gui, xMouse, yMouse, button));
}
@Override
public boolean onKey(JecGui gui, char ch, int code) {
return Stream.of(left, right).anyMatch(w -> w.onKey(gui, ch, code));
}
}
@@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiTextField;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
/**
* Author: towdium
@@ -15,6 +16,8 @@ import javax.annotation.ParametersAreNonnullByDefault;
public class DTextField implements IDrawable {
protected int xPos, yPos, xSize;
GuiTextField textField;
public Consumer<String> lsnrText;
public DTextField(int xPos, int yPos, int xSize) {
this.xPos = xPos;
this.yPos = yPos;
@@ -37,6 +40,19 @@ public class DTextField implements IDrawable {
@Override
public boolean onKey(JecGui gui, char ch, int code) {
return textField.textboxKeyTyped(ch, code);
boolean ret = textField.textboxKeyTyped(ch, code);
if (ret) lsnrText.accept(textField.getText());
return ret;
}
@SuppressWarnings("UnusedReturnValue")
public DTextField setLsnrText(Consumer<String> lsnrText) {
this.lsnrText = lsnrText;
return this;
}
public DTextField setColor(int color) {
textField.setTextColor(color);
return this;
}
}
@@ -3,7 +3,6 @@ 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;
@@ -28,7 +27,7 @@ public abstract class DTooltip implements IDrawable {
if (name != null) {
timer.setState(mouseIn(xMouse, yMouse));
if (timer.getTime() > 500) {
Pair<String, Boolean> str = LocalizationHelper.search(String.join(".", "gui", name, "tooltip"));
Pair<String, Boolean> str = Utilities.L18n.search(String.join(".", "gui", name, "tooltip"));
if (str.two || JecGui.ALWAYS_TOOLTIP) gui.drawTooltip(xMouse, yMouse, str.one);
}
}
@@ -30,6 +30,6 @@ public class GuiCalculator extends DContainer {
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, "calculator.history"));
add(new DScroll(7, 56, 162, 5));
add(new DSwitcher(7, 56, 162, 5));
}
}
@@ -0,0 +1,35 @@
package me.towdium.jecalculation.client.gui.guis;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.client.gui.drawables.*;
import me.towdium.jecalculation.core.labels.ILabel;
import me.towdium.jecalculation.core.labels.labels.LabelOreDict;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
/**
* Author: towdium
* Date: 17-9-16.
*/
public class GuiDisambiguation extends DContainer {
public GuiDisambiguation(List<List<ItemStack>> iss) {
ArrayList<ILabel> labels = new ArrayList<>();
IntStream.range(0, 50).forEach(i -> labels.add(new LabelOreDict(i % 2 == 0 ? "plankWood" : "ingotIron", i)));
DLabelScroll lsUp = new DLabelScroll(25, 48, 7, 3, DLabel.enumMode.RESULT, true).setLabels(labels);
DLabelScroll lsDown = new DLabelScroll(25, 105, 7, 3, DLabel.enumMode.RESULT, true).setLabels(labels);
DTextField tf = new DTextField(25, 24, 90);
tf.setLsnrText(s -> tf.setColor(lsUp.setFilter(s) | lsDown.setFilter(s) ?
JecGui.COLOR_TEXT_WHITE : JecGui.COLOR_TEXT_RED));
add(new DPanel());
add(new DSwitcher(7, 7, 162, 5));
add(new DIcon(149, 24, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "disambiguation.help"));
add(new DIcon(7, 48, 18, 54, Resource.ICN_LIST_N, Resource.ICN_LIST_F, "disambiguation.list"));
add(new DIcon(7, 105, 18, 54, Resource.ICN_LABEL_N, Resource.ICN_LABEL_F, "disambiguation.label"));
addAll(tf, lsUp, lsDown);
}
}
@@ -25,7 +25,7 @@ public class GuiRecipe extends DContainer {
public GuiRecipe() {
add(new DPanel());
add(new DScroll(7, 7, 162, 2));
add(new DSwitcher(7, 7, 162, 2));
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"));
@@ -2,7 +2,7 @@ package me.towdium.jecalculation.command.commands;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.command.SubCommand;
import me.towdium.jecalculation.utils.helpers.LocalizationHelper;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentTranslation;
@@ -28,6 +28,6 @@ public class CommandState implements SubCommand {
@Override
public void execute(ICommandSender sender, String[] args) throws CommandException {
sender.addChatMessage(new ChatComponentTranslation("command.state.desc",
LocalizationHelper.format(JustEnoughCalculation.side.toString())));
Utilities.L18n.format(JustEnoughCalculation.side.toString())));
}
}
@@ -45,6 +45,10 @@ public interface ILabel {
String getDisplayName();
default List<String> getToolTip(List<String> existing) {
return existing;
}
default String getIdentifier() {
String s = this.getClass().getSimpleName();
if (s.startsWith("Label")) s = s.substring(5);
@@ -159,7 +163,7 @@ public interface ILabel {
String s = nbt.getString(KEY_IDENTIFIER);
ILabel e = idToData.get(s).apply(nbt.getCompoundTag(KEY_CONTENT));
if (e != ILabel.EMPTY) return e;
else throw new RuntimeException("Fail to deserialize ILabel type: " + s);
else throw new RuntimeException("Fail to deserialize label type: " + s);
}
}
@@ -2,10 +2,13 @@ package me.towdium.jecalculation.core.labels.labels;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.core.labels.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import java.util.List;
/**
* Author: towdium
* Date: 8/11/17.
@@ -37,9 +40,15 @@ public class LabelItemStack extends LabelSimpleAmount {
itemStack = eis.itemStack;
}
@Override
public List<String> getToolTip(List<String> existing) {
existing.add("&9" + Utilities.getModName(itemStack));
return existing;
}
@Override
public String getDisplayName() {
return itemStack.getDisplayName();
return itemStack.getItem() == null ? "" : itemStack.getDisplayName();
}
@Override
@@ -1,5 +1,6 @@
package me.towdium.jecalculation.core.labels.labels;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.Resource;
import me.towdium.jecalculation.client.gui.drawables.DContainer;
@@ -7,12 +8,14 @@ import me.towdium.jecalculation.client.gui.drawables.DText;
import me.towdium.jecalculation.core.labels.ILabel;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.polyfill.mc.util.NonNullList;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.function.Consumer;
/**
@@ -48,7 +51,13 @@ public class LabelOreDict extends LabelSimpleAmount {
@Override
public String getDisplayName() {
return "Ore: " + name; // localization
return Utilities.L18n.format("label.ore_dict.name", name);
}
@Override
public List<String> getToolTip(List<String> existing) {
existing.add("\u00A79\u00A7o" + JustEnoughCalculation.Reference.MODNAME);
return existing;
}
public static RegistryEditor.IEditor getEditor() {
@@ -6,8 +6,10 @@ import cpw.mods.fml.common.registry.GameData;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.utils.wrappers.Pair;
import me.towdium.jecalculation.utils.wrappers.Single;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import org.apache.commons.lang3.StringEscapeUtils;
import java.util.*;
import java.util.function.BiFunction;
@@ -93,6 +95,10 @@ public class Utilities {
return name;
}
public static boolean contains(String s1, String s2) {
return s1.contains(s2);
}
public static class Timer {
long time = System.currentTimeMillis();
boolean running = false;
@@ -184,4 +190,19 @@ public class Utilities {
return Optional.ofNullable(ret.value);
}
}
public static class L18n {
public static Pair<String, Boolean> search(String translateKey, Object... parameters) {
Pair<String, Boolean> ret = new Pair<>(null, null);
String buffer = I18n.format(translateKey, parameters);
ret.two = !buffer.equals(translateKey);
buffer = StringEscapeUtils.unescapeJava(buffer);
ret.one = buffer.replace("\t", " ");
return ret;
}
public static String format(String translateKey, Object... parameters) {
return search(translateKey, parameters).one;
}
}
}
@@ -1,29 +0,0 @@
package me.towdium.jecalculation.utils.helpers;
import com.google.common.base.CaseFormat;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.client.resources.I18n;
import org.apache.commons.lang3.StringEscapeUtils;
/**
* Author: Towdium
* Created: 2016/6/22.
*/
@SideOnly(Side.CLIENT)
public class LocalizationHelper {
public static Pair<String, Boolean> search(String translateKey, Object... parameters) {
Pair<String, Boolean> ret = new Pair<>(null, null);
String buffer = I18n.format(translateKey, parameters);
ret.two = !buffer.equals(translateKey);
buffer = StringEscapeUtils.unescapeJava(buffer);
ret.one = buffer.replace("\t", " ");
return ret;
}
public static String format(String translateKey, Object... parameters) {
return search(translateKey, parameters).one;
}
}