feat: new texture

This commit is contained in:
Discreater committed 2021-05-01 01:16:04 +08:00
1 parent 5d86a1e2ad
commit 85ba97338c
17 files changed
+209 -130

No files matched your search

@@ -42,12 +42,8 @@ public interface ILabel {
ILabel increaseAmount();
ILabel increaseAmountLarge();
ILabel decreaseAmount();
ILabel decreaseAmountLarge();
ILabel invertAmount();
int getAmount();
@@ -73,7 +69,7 @@ public interface ILabel {
String getDisplayName();
List<String> getToolTip(List<String> existing, boolean detailed);
void getToolTip(List<String> existing, boolean detailed);
ILabel copy();
@@ -244,21 +240,11 @@ public interface ILabel {
return this;
}
@Override
public ILabel increaseAmountLarge() {
return this;
}
@Override
public ILabel decreaseAmount() {
return this;
}
@Override
public ILabel decreaseAmountLarge() {
return this;
}
@Override
public ILabel invertAmount() {
return this;
@@ -285,8 +271,7 @@ public interface ILabel {
}
@Override
public List<String> getToolTip(List<String> existing, boolean detailed) {
return new ArrayList<>();
public void getToolTip(List<String> existing, boolean detailed) {
}
@Override
@@ -348,12 +333,6 @@ public interface ILabel {
return this;
}
@Override
public ILabel increaseAmountLarge() {
setAmount(getAmount() + 10 * getMultiplier());
return this;
}
@Override
public ILabel decreaseAmount() {
if (getAmount() <= getMultiplier()) return ILabel.EMPTY;
@@ -363,15 +342,6 @@ public interface ILabel {
}
}
@Override
public ILabel decreaseAmountLarge() {
if (getAmount() <= 10 * getMultiplier()) return ILabel.EMPTY;
else {
setAmount(getAmount() - 10 * getMultiplier());
return this;
}
}
@Override
public ILabel invertAmount() {
setAmount(-getAmount());
@@ -380,10 +350,9 @@ public interface ILabel {
@Override
@SideOnly(Side.CLIENT)
public List<String> getToolTip(List<String> existing, boolean detailed) {
public void getToolTip(List<String> existing, boolean detailed) {
if (detailed) existing.add(FORMAT_GREY +
Utilities.I18n.format("label.common.tooltip.amount", getAmountString()));
return existing;
}
@Override
@@ -102,11 +102,10 @@ public class LFluidStack extends ILabel.Impl {
@Override
@SideOnly(Side.CLIENT)
public List<String> getToolTip(List<String> existing, boolean detailed) {
public void getToolTip(List<String> existing, boolean detailed) {
if (detailed) existing.add(FORMAT_GREY +
Utilities.I18n.format("label.common.tooltip.amount", Integer.toString(getAmount())) + "mB");
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(fluid));
return existing;
}
@@ -83,10 +83,9 @@ public class LItemStack extends ILabel.Impl {
@Override
@SideOnly(Side.CLIENT)
public List<String> getToolTip(List<String> existing, boolean detailed) {
public void getToolTip(List<String> existing, boolean detailed) {
super.getToolTip(existing, detailed);
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(item));
return existing;
}
@Override
@@ -163,10 +163,9 @@ public class LOreDict extends ILabel.Impl {
@Override
@SideOnly(Side.CLIENT)
public List<String> getToolTip(List<String> existing, boolean detailed) {
public void getToolTip(List<String> existing, boolean detailed) {
super.getToolTip(existing, detailed);
existing.add(FORMAT_BLUE + FORMAT_ITALIC + JustEnoughCalculation.Reference.MODNAME);
return existing;
}
@Override
@@ -100,9 +100,8 @@ public class LPlaceholder extends ILabel.Impl {
@Override
@SideOnly(Side.CLIENT)
public List<String> getToolTip(List<String> existing, boolean detailed) {
public void getToolTip(List<String> existing, boolean detailed) {
super.getToolTip(existing, detailed);
existing.add(FORMAT_BLUE + FORMAT_ITALIC + JustEnoughCalculation.Reference.MODNAME);
return existing;
}
}
@@ -22,7 +22,7 @@ public interface IWPicker extends IWidget {
protected Consumer<ILabel> callback;
@Override
public IWPicker setCallback(Consumer<ILabel> callback) {
public Impl setCallback(Consumer<ILabel> callback) {
this.callback = callback;
return this;
}
@@ -1,8 +1,14 @@
package me.towdium.jecalculation.gui;
import java.util.List;
public interface IWidget {
void onDraw(JecaGui gui, int xMouse, int yMouse);
default boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
return false;
}
default boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
return false;
}
@@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.drawables.WContainer;
import me.towdium.jecalculation.nei.NEIPlugin;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.utils.IllegalPositionException;
@@ -46,15 +47,14 @@ public class JecaGui extends GuiContainer {
public static final int COLOR_TEXT_WHITE = 0xFFFFFF;
public static final boolean ALWAYS_TOOLTIP = false;
public ILabel hand = ILabel.EMPTY;
public IWidget root;
public WContainer root;
protected JecaGui parent;
protected List<Triple<Integer, Integer, List<String>>> tooltipBuffer = new ArrayList<>();
public JecaGui(@Nullable JecaGui parent, IWidget root) {
public JecaGui(@Nullable JecaGui parent, WContainer root) {
this(parent, false, root);
}
public JecaGui(@Nullable JecaGui parent, boolean acceptsTransfer, IWidget root) {
public JecaGui(@Nullable JecaGui parent, boolean acceptsTransfer, WContainer root) {
super(acceptsTransfer ? new ContainerTransfer() : new ContainerNonTransfer());
this.parent = parent;
this.root = root;
@@ -66,11 +66,11 @@ public class JecaGui extends GuiContainer {
return xMouse > xPos && yMouse > yPos && xMouse <= xPos + xSize && yMouse <= yPos + ySize;
}
public static void displayGui(IWidget root) {
public static void displayGui(WContainer root) {
displayGui(true, false, root);
}
public static void displayGui(boolean updateParent, boolean acceptsTransfer, IWidget root) {
public static void displayGui(boolean updateParent, boolean acceptsTransfer, WContainer root) {
// isCallingFromMinecraftThread
if (Minecraft.getMinecraft().func_152345_ab())
displayGuiUnsafe(updateParent, acceptsTransfer, root);
@@ -88,7 +88,7 @@ public class JecaGui extends GuiContainer {
return ret;
}
private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, IWidget root) {
private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, WContainer root) {
Minecraft mc = Minecraft.getMinecraft();
JecaGui parent;
if (mc.currentScreen == null)
@@ -137,7 +137,9 @@ public class JecaGui extends GuiContainer {
GlStateManager.translate(0, 0, 80);
hand.drawLabel(this, mouseX, mouseY, true);
GlStateManager.popMatrix();
drawBufferedTooltip();
List<String> tooltip = new ArrayList<>();
root.onTooltip(this, mouseX - guiLeft, mouseY - guiTop, tooltip);
drawHoveringText(tooltip, mouseX, mouseY);
GlStateManager.enableLighting();
GlStateManager.enableDepth();
}
@@ -363,23 +365,6 @@ public class JecaGui extends GuiContainer {
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) {
tooltipBuffer.add(new Triple<>(xPos + guiLeft, yPos + guiTop, text));
}
protected void drawBufferedTooltip() {
tooltipBuffer.forEach(i -> {
drawHoveringText(i.three, i.one, i.two);
GlStateManager.disableLighting();
GlStateManager.disableDepth();
});
tooltipBuffer.clear();
}
public void drawItemStack(int xPos, int yPos, ItemStack is, boolean centred) {
if (is.getItem() == null) {
return;
@@ -31,12 +31,25 @@ public class Resource {
public static final Resource BTN_DEL_F = new Resource(70, 0, 14, 14);
public static final Resource BTN_YES_N = new Resource(84, 14, 14, 14);
public static final Resource BTN_YES_F = new Resource(84, 0, 14, 14);
public static final Resource BTN_YES_D = new Resource(228, 14, 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 BTN_NO_D = new Resource(228, 0, 14, 14);
public static final Resource BTN_DISAMB_N = new Resource(112, 14, 14, 14);
public static final Resource BTN_DISAMB_F = new Resource(112, 0, 14, 14);
public static final Resource BTN_DISAMB_D = new Resource(242, 0, 14, 14);
public static final Resource BTN_IN_N = new Resource(126, 14, 14, 14);
public static final Resource BTN_IN_F = new Resource(126, 0, 14, 14);
public static final Resource BTN_IN_D = new Resource(200, 0, 14, 14);
public static final Resource BTN_OUT_N = new Resource(140, 14, 14, 14);
public static final Resource BTN_OUT_F = new Resource(140, 0, 14, 14);
public static final Resource BTN_OUT_D = new Resource(214, 0, 14, 14);
public static final Resource BTN_CAT_N = new Resource(154, 14, 14, 14);
public static final Resource BTN_CAT_F = new Resource(154, 0, 14, 14);
public static final Resource BTN_CAT_D = new Resource(200, 14, 14, 14);
public static final Resource BTN_LIST_N = new Resource(168, 14, 14, 14);
public static final Resource BTN_LIST_F = new Resource(168, 0, 14, 14);
public static final Resource BTN_LIST_D = new Resource(214, 14, 14, 14);
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);
@@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.IWidget;
import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
@@ -16,7 +17,6 @@ import java.util.List;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class WContainer implements IWidget {
boolean modified = false;
protected List<IWidget> widgets = new ArrayList<>();
public void add(IWidget w) {
@@ -63,4 +63,11 @@ public class WContainer implements IWidget {
for (IWidget w : widgets) if (w.onScroll(gui, xMouse, yMouse, diff)) return true;
return false;
}
@Override
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
Utilities.ReversedIterator<IWidget> i = new Utilities.ReversedIterator<>(widgets);
while (i.hasNext()) if (i.next().onTooltip(gui, xMouse, yMouse, tooltip)) return true;
return false;
}
}
@@ -2,16 +2,16 @@ package me.towdium.jecalculation.gui.drawables;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.IWidget;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.IllegalPositionException;
import me.towdium.jecalculation.utils.Utilities;
import org.lwjgl.input.Keyboard;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
/**
@@ -49,8 +49,8 @@ public class WLabel implements IWidget {
public void setLabel(ILabel label) {
this.label = label;
// if (mode == enumMode.EDITOR || mode == enumMode.SELECTOR)
// notifyLsnr();
// if (mode == enumMode.EDITOR || mode == enumMode.SELECTOR)
// notifyLsnr();
}
@Override
@@ -58,16 +58,11 @@ public class WLabel implements IWidget {
gui.drawResourceContinuous(Resource.WGT_SLOT, xPos, yPos, xSize, ySize, 3, 3, 3, 3);
label.drawLabel(gui, xPos + xSize / 2, yPos + ySize / 2, true);
if (mode == enumMode.RESULT || mode == enumMode.EDITOR)
gui.drawText(xPos + xSize / 2.0f + 7.5f, yPos + ySize / 2 + 7 -
(int) (font.size * gui.getFontRenderer().FONT_HEIGHT), font, label.getAmountString());
gui.drawText(xPos + xSize / 2.0f + 7.5f,
yPos + ySize / 2 + 7 - (int) (font.size * gui.getFontRenderer().FONT_HEIGHT), font,
label.getAmountString());
if (mouseIn(xMouse, yMouse)) {
gui.drawRectangle(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF);
if (label != ILabel.EMPTY) {
ArrayList<String> buf = new ArrayList<>();
buf.add(label.getDisplayName());
gui.drawTooltip(xMouse, yMouse,
label.getToolTip(buf, mode == enumMode.EDITOR || mode == enumMode.RESULT));
}
}
if (mode == enumMode.EDITOR || mode == enumMode.SELECTOR) {
timer.setState(gui.hand != ILabel.EMPTY);
@@ -76,16 +71,26 @@ public class WLabel implements IWidget {
}
}
@Override
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
if (mouseIn(xMouse, yMouse)) {
if (label != ILabel.EMPTY) {
tooltip.add(label.getDisplayName());
label.getToolTip(tooltip, mode == enumMode.EDITOR || mode == enumMode.RESULT);
}
}
return false;
}
@Override
public boolean onScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
if (mouseIn(xMouse, yMouse) && mode == enumMode.EDITOR && label != ILabel.EMPTY) {
IntStream.range(0, Math.abs(diff)).forEach(i -> {
if (JecaGui.isShiftDown()) label = diff > 0 ? label.increaseAmountLarge() : label.decreaseAmountLarge();
else label = diff > 0 ? label.increaseAmount() : label.decreaseAmount();
});
IntStream.range(0, Math.abs(diff))
.forEach(i -> label = diff > 0 ? label.increaseAmount() : label.decreaseAmount());
notifyLsnr();
return true;
} else return false;
} else
return false;
}
@@ -101,18 +106,18 @@ public class WLabel implements IWidget {
return true;
} else if (label != label.EMPTY) {
if (button == 0) {
if (JecaGui.isShiftDown())
label = label.increaseAmountLarge();
else
if (JecaGui.isShiftDown()) gui.root.add(new WAmount());
else {
label = label.increaseAmount();
notifyLsnr();
notifyLsnr();
}
return true;
} else if (button == 1) {
if (JecaGui.isShiftDown())
label = label.decreaseAmountLarge();
else
if (JecaGui.isShiftDown()) gui.root.add(new WAmount());
else {
label = label.decreaseAmount();
notifyLsnr();
notifyLsnr();
}
return true;
}
} else
@@ -149,7 +154,8 @@ public class WLabel implements IWidget {
}
void notifyLsnr() {
if (lsnrUpdate != null) lsnrUpdate.run();
if (lsnrUpdate != null)
lsnrUpdate.run();
}
@@ -171,4 +177,49 @@ public class WLabel implements IWidget {
*/
SELECTOR
}
class WAmount extends WContainer {
public WAmount() {
WLabel w = WLabel.this;
int xAlign = w.xPos + w.xSize;
WLabel wl = new WLabel(w.xPos, w.yPos, w.xSize, w.ySize, enumMode.SELECTOR);
wl.setLabel(w.getLabel());
WTextField wtf = new WTextField(xAlign + 10, w.yPos + w.ySize / 2 - WTextField.HEIGHT / 2, 50);
WButton wby = new WButtonIcon(xAlign + 60, w.yPos, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F,
Resource.BTN_YES_D).setListenerLeft(() -> {
w.setLabel(wl.getLabel().setAmount(
wtf.getText().isEmpty() ? 0 : Integer.parseInt(wtf.getText())));
JecaGui.getCurrent().root.remove(this);
});
WButton wbn = new WButtonIcon(xAlign + 79, w.yPos, 20, 20, Resource.BTN_NO_N, Resource.BTN_NO_F)
.setListenerLeft(() -> {
w.setLabel(ILabel.EMPTY);
JecaGui.getCurrent().root.remove(this);
});
wtf.setText(Integer.toString(w.getLabel().getAmount()));
wtf.setLsnrText(i -> {
try {
Integer.parseInt(wtf.getText());
wtf.setColor(JecaGui.COLOR_TEXT_WHITE);
wby.setDisabled(false);
} catch (NumberFormatException e) {
boolean acceptable = wtf.getText().isEmpty();
wtf.setColor(acceptable ? JecaGui.COLOR_TEXT_WHITE : JecaGui.COLOR_TEXT_RED);
wby.setDisabled(!acceptable);
}
});
add(new WPanel(w.xPos - 5, w.yPos - 5, w.xSize + 110, w.ySize + 10));
add(new WText(xAlign + 3, w.yPos + 5, JecaGui.Font.DEFAULT_NO_SHADOW, "x"));
addAll(wl, wtf, wby, wbn);
}
@Override
public boolean onKey(JecaGui gui, char ch, int code) {
if (super.onKey(gui, ch, code)) return true;
if (code == Keyboard.KEY_ESCAPE) {
gui.root.remove(this);
return true;
} else return false;
}
}
}
@@ -2,13 +2,15 @@ package me.towdium.jecalculation.gui.drawables;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.label.ILabel.RegistryEditor.Record;
import me.towdium.jecalculation.gui.IWidget;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
/**
* Author: towdium
@@ -17,15 +19,13 @@ import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class WPage implements IWidget {
protected int index;
protected ILabel.RegistryEditor.Record record;
protected Utilities.Timer timer = new Utilities.Timer();
protected boolean focused;
protected Runnable listener;
public WPage(int index, ILabel.RegistryEditor.Record record, boolean focused) {
public WPage(int index, Record record, boolean focused) {
this.index = index;
this.record = record;
this.focused = focused;
@@ -33,22 +33,29 @@ public class WPage implements IWidget {
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
Resource resource = focused ? (index == 0 ? Resource.WGT_PAGER_F0 : Resource.WGT_PAGER_FN)
: Resource.WGT_PAGER_N;
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.drawLabel(gui, index * 24 + 4, -17, false);
timer.setState(JecaGui.mouseIn(index * 24, -21, 24, 21, xMouse, yMouse));
if (timer.getTime() > 1000)
gui.drawTooltip(xMouse, yMouse, Utilities.I18n.format("gui." + record.localizeKey));
}
@Override
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
boolean ret = JecaGui.mouseIn(index * 24, -21, 24, 21, xMouse, yMouse) && listener != null && !focused;
if (ret) listener.run();
if (ret)
listener.run();
return ret;
}
@Override
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
if (timer.getTime() > 1000 && !focused)
tooltip.add(Utilities.I18n.format("gui." + record.localizeKey));
return false;
}
public WPage setListener(Runnable r) {
listener = r;
return this;
@@ -7,6 +7,7 @@ import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
/**
* Author: towdium
@@ -16,8 +17,33 @@ import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class WPanel implements IWidget {
int xPos, yPos, xSize, ySize;
public WPanel(int xPos, int yPos, int xSize, int ySize) {
this.xPos = xPos;
this.yPos = yPos;
this.xSize = xSize;
this.ySize = ySize;
}
public WPanel() {
this(0, 0, 176, 166);
}
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
gui.drawResourceContinuous(Resource.WGT_PANEL, 0, 0, gui.getXSize(), gui.getYSize(), 5, 5, 5, 5);
gui.drawResourceContinuous(Resource.WGT_PANEL, xPos, yPos, xSize, ySize, 5, 5, 5, 5);
}
@Override
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
return mouseIn(xMouse, yMouse);
}
public boolean mouseIn(int x, int y) {
int xx = x - xPos;
int yy = y - yPos;
return xx >= 0 && xx < xSize && yy >= 0 && yy < ySize;
}
}
@@ -20,6 +20,7 @@ public class WTextField implements IWidget {
public Consumer<String> lsnrText;
protected int xPos, yPos, xSize;
GuiTextField textField;
public static final int HEIGHT = 20;
public WTextField(int xPos, int yPos, int xSize) {
this.xPos = xPos;
@@ -28,15 +28,18 @@ public abstract class WTooltip implements IWidget {
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
if (name != null) {
timer.setState(mouseIn(xMouse, yMouse));
if (timer.getTime() > 500) {
String str = getSuffix().stream().map(s -> Utilities.I18n.search(String.join(".", "gui", name, s)))
.filter(p -> p.two).findFirst().map(p -> p.one)
.orElse(JecaGui.ALWAYS_TOOLTIP ? String.join(".", "gui", name, getSuffix().get(0)) : null);
if (str != null) gui.drawTooltip(xMouse, yMouse, str);
}
if (name != null) timer.setState(mouseIn(xMouse, yMouse));
}
@Override
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
if (timer.getTime() > 500) {
String str = getSuffix().stream().map(s -> Utilities.I18n.search(String.join(".", "gui", name, s)))
.filter(p -> p.two).findFirst().map(p -> p.one)
.orElse(JecaGui.ALWAYS_TOOLTIP ? String.join(".", "gui", name, getSuffix().get(0)) : null);
if (str != null) tooltip.add(str);
}
return false;
}
protected List<String> getSuffix() {
@@ -20,8 +20,21 @@ import java.util.List;
public class GuiCalculator extends WContainer {
WLabelGroup wRecent = new WLabelGroup(7, 31, 8, 1, WLabel.enumMode.PICKER);
WLabel wLabel = new WLabel(31, 7, 20, 20, WLabel.enumMode.SELECTOR);
WButton btnSteps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST_N, Resource.BTN_LIST_F,
Resource.BTN_LIST_D, "calculator.step").setListenerLeft(() -> setMode(enumMode.STEPS));
WButton btnCatalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT_N, Resource.BTN_CAT_F,
Resource.BTN_CAT_D, "calculator.catalyst").setListenerLeft(() -> setMode(enumMode.CATALYST));
WButton btnOutput = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT_N, Resource.BTN_OUT_F,
Resource.BTN_OUT_D, "calculator.output").setListenerLeft(() -> setMode(enumMode.OUTPUT));
WButton btnInput = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN_N, Resource.BTN_IN_F,
Resource.BTN_IN_D, "calculator.input").setListenerLeft(() -> setMode(enumMode.INPUT));
public GuiCalculator() {
wLabel.setLsnrUpdate(() -> {
Controller.setRecent(wLabel.label);
refreshRecent();
});
wRecent.setLsnrUpdate(l -> JecaGui.getCurrent().hand = wRecent.getLabelAt(l));
add(new WPanel());
add(new WTextField(61, 7, 64));
add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "calculator.label")
@@ -33,25 +46,27 @@ public class GuiCalculator extends WContainer {
.setListenerLeft(() -> JecaGui.displayGui(true, true, new GuiRecipe())));
add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH_N, Resource.BTN_SEARCH_F, "calculator.search")
.setListenerLeft(() -> JecaGui.displayGui(new GuiSearch())));
add(new WLabelGroup(7, 87, 9, 4, WLabel.enumMode.RESULT));
add(wRecent);
add(wLabel);
add(new WLine(52));
add(new WLine(55));
add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT_N, Resource.ICN_RECENT_F, "calculator.history"));
add(new WSwitcher(7, 56, 162, 5));
refresh();
List<ILabel> recent = Controller.getRecent();
if (recent.size() > 0) wLabel.setLabel(Controller.getRecent().get(0));
wLabel.setLsnrUpdate(() -> {
Controller.setRecent(wLabel.label);
refresh();
});
wRecent.setLsnrUpdate(l -> JecaGui.getCurrent().hand = wRecent.getLabelAt(l));
add(new WLabelScroll(7, 87, 8, 4, WLabel.enumMode.RESULT, true));
addAll(wRecent, wLabel, btnInput, btnOutput, btnCatalyst, btnSteps);
refreshRecent();
setMode(enumMode.INPUT);
}
void refresh() {
void setMode(enumMode mode) {
btnInput.setDisabled(mode == enumMode.INPUT);
btnOutput.setDisabled(mode == enumMode.OUTPUT);
btnCatalyst.setDisabled(mode == enumMode.CATALYST);
btnSteps.setDisabled(mode == enumMode.STEPS);
}
void refreshRecent() {
List<ILabel> recent = Controller.getRecent();
if (recent.size() > 1)
wRecent.setLabel(recent.subList(1, recent.size()), 0);
if (recent.size() > 1) wRecent.setLabel(recent.subList(1, recent.size()), 0);
}
enum enumMode {
INPUT, OUTPUT, CATALYST, STEPS
}
}