chore: clean up

This commit is contained in:
Discreater committed 2021-05-01 20:49:01 +08:00
1 parent 6c80a421fe
commit ea1eab8685
32 files changed
+418 -358

No files matched your search

@@ -83,7 +83,6 @@ public interface ILabel {
boolean isPercent();
static void initServer() {
// TODO handle invalid items
SERIALIZER.register(LFluidStack.IDENTIFIER, LFluidStack::new);
SERIALIZER.register(LItemStack.IDENTIFIER, LItemStack::new);
SERIALIZER.register(LOreDict.IDENTIFIER, LOreDict::new);
@@ -121,13 +120,13 @@ public interface ILabel {
* For registering, see {@link Serializer}.
*/
class Merger {
private HashMap<Pair<String, String>, MergerFunction> functions = new HashMap<>();
private Utilities.Relation<String, MergerFunction> functions = new Utilities.Relation<>();
private Merger() {
}
public void register(String a, String b, MergerFunction func) {
functions.put(new Pair<>(a, b), func);
functions.put(a, b, func);
}
/**
@@ -140,22 +139,11 @@ public interface ILabel {
* So generally speaking, a and b has no priority in this function
*/
public Optional<ILabel> merge(ILabel a, ILabel b) {
BiFunction<ILabel, ILabel, ILabel> get = (c, d) -> {
MergerFunction mf = functions.get(new Pair<>(c.getIdentifier(), d.getIdentifier()));
if (mf != null) return mf.merge(c, d);
else return null;
};
return new Wrapper<ILabel>(null)
.or(() -> get.apply(a, b))
.or(() -> get.apply(b, a))
.ifPresent(i -> {
if (i != ILabel.EMPTY && (i == a || i == b))
throw new RuntimeException("Merger should not modify the given label.");
})
.toOptional();
MergerFunction mf = functions.get(a.getIdentifier(), b.getIdentifier());
if (mf == null) return Optional.empty();
return Optional.ofNullable(mf.merge(a, b));
}
@FunctionalInterface
public interface MergerFunction {
/**
@@ -205,12 +193,12 @@ public interface ILabel {
public ILabel deserialize(NBTTagCompound nbt) {
String s = nbt.getString(KEY_IDENTIFIER);
Function<NBTTagCompound, ILabel> func = idToData.get(s);
if (func != null)
if (func == null) JustEnoughCalculation.logger.warn("Unrecognized identifier \"" + s + "\", abort");
else try {
return func.apply(nbt.getCompoundTag(KEY_CONTENT));
else {
JustEnoughCalculation.logger.warn("Unrecognized type identifier \"" + s + "\", use empty instead.");
return ILabel.EMPTY;
} catch (SerializationException ignored) {
}
return EMPTY;
}
public NBTTagCompound serialize(ILabel label) {
@@ -219,6 +207,13 @@ public interface ILabel {
ret.setTag(KEY_CONTENT, label.toNbt());
return ret;
}
public static class SerializationException extends RuntimeException {
public SerializationException(String s) {
super(s);
JustEnoughCalculation.logger.warn(s);
}
}
}
/**
@@ -431,9 +426,18 @@ public interface ILabel {
}
}
@Override
public int hashCode() {
return (int) (amount ^ (percent ? 1 : 0));
}
protected static Merger.MergerFunction form(Class a, Class b, BiPredicate<ILabel, ILabel> p) {
return (c, d) -> {
if (c == EMPTY || d == EMPTY) return null;
if (a.isInstance(d) && b.isInstance(c)) {
ILabel tmp = c;
c = d;
d = tmp;
}
if (a.isInstance(c) && b.isInstance(d) && p.test(c, d)) {
long amountC = c.isPercent() ? c.getAmount() : Math.multiplyExact(c.getAmount(), 100);
long amountD = d.isPercent() ? d.getAmount() : Math.multiplyExact(d.getAmount(), 100);
@@ -55,8 +55,10 @@ public class LFluidStack extends ILabel.Impl {
public LFluidStack(NBTTagCompound nbt) {
super(nbt);
init(FluidRegistry.getFluid(nbt.getString(KEY_FLUID)),
nbt.hasKey(KEY_NBT) ? nbt.getCompoundTag(KEY_NBT) : null);
String id = nbt.getString(KEY_FLUID);
Fluid f = FluidRegistry.getFluid(id);
if (f == null) throw new Serializer.SerializationException("Fluid " + id + " cannot be resolved, ignoring");
init(f, nbt.hasKey(KEY_NBT) ? nbt.getCompoundTag(KEY_NBT) : null);
}
private void init(Fluid fluid, @Nullable NBTTagCompound nbt) {
@@ -47,9 +47,15 @@ public class LItemStack extends ILabel.Impl {
public LItemStack(NBTTagCompound tag) {
super(tag);
init(Item.getItemById(tag.getInteger(KEY_ITEM)), tag.getInteger(KEY_META),
tag.hasKey(KEY_NBT) ? tag.getCompoundTag(KEY_NBT) : null, tag.getBoolean(KEY_F_META),
tag.getBoolean(KEY_F_CAP), tag.getBoolean(KEY_F_NBT));
String id = tag.getString(KEY_ITEM);
Item i = Item.getItemById(tag.getInteger(KEY_ITEM));
if (i == null) throw new Serializer.SerializationException("Item " + id + " cannot be resolved, ignoring");
init(i, tag.getInteger(KEY_META),
tag.hasKey(KEY_NBT) ? tag.getCompoundTag(KEY_NBT) : null,
tag.getBoolean(KEY_F_META),
tag.getBoolean(KEY_F_CAP),
tag.getBoolean(KEY_F_NBT)
);
}
private LItemStack(LItemStack lis) {
@@ -85,20 +91,12 @@ public class LItemStack extends ILabel.Impl {
if (a instanceof LItemStack && b instanceof LItemStack) {
LItemStack lisA = (LItemStack) a;
LItemStack lisB = (LItemStack) b;
if (!lisA.fMeta && lisA.meta != WILDCARD_VALUE && lisA.meta != lisB.meta)
return false;
if (!lisA.fNbt) {
if (lisB.fNbt)
return false;
else if (lisA.nbt == null) {
if (lisB.nbt != null)
return false;
} else if (lisB.nbt == null || !lisA.nbt.equals(lisB.nbt))
return false;
}
if (!lisA.fCap) {
if (lisB.fCap)
return false;
if (lisA.meta != lisB.meta && !lisA.fMeta && lisA.meta != WILDCARD_VALUE
&& !lisB.fMeta && lisB.meta != WILDCARD_VALUE) return false;
if (!lisA.fNbt && !lisB.fNbt) {
if (lisA.nbt == null) {
if (lisB.nbt != null) return false;
} else if (lisB.nbt == null || !lisA.nbt.equals(lisB.nbt)) return false;
}
return lisA.item == lisB.item;
}
@@ -90,8 +90,6 @@ public class LOreDict extends ILabel.Impl {
if (a instanceof LOreDict && b instanceof LItemStack) {
LOreDict lod = (LOreDict) a;
LItemStack lis = (LItemStack) b;
if (lod.getAmount() > 0)
return false;
return OreDictionary.getOres(lod.name).stream()
.map(Converter::from)
.anyMatch(i -> LItemStack.merge(i, lis));
@@ -200,7 +198,7 @@ public class LOreDict extends ILabel.Impl {
@Override
public int hashCode() {
return name.hashCode() ^ (int) amount;
return name.hashCode() ^ super.hashCode();
}
public String getName() {
@@ -80,7 +80,7 @@ public class LPlaceholder extends ILabel.Impl {
@Override
public int hashCode() {
return name.hashCode() ^ (int) amount;
return name.hashCode() ^ super.hashCode();
}
@Nullable
@@ -2,6 +2,7 @@ package me.towdium.jecalculation.data.structure;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ChatComponentTranslation;
@@ -10,9 +11,11 @@ import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static me.towdium.jecalculation.data.structure.Recipe.enumIoType.INPUT;
import static me.towdium.jecalculation.data.structure.Recipe.enumIoType.OUTPUT;
import static me.towdium.jecalculation.data.structure.Recipe.IO.INPUT;
import static me.towdium.jecalculation.data.structure.Recipe.IO.OUTPUT;
import static me.towdium.jecalculation.utils.Utilities.stream;
// positive => generate; negative => require
@ParametersAreNonnullByDefault
@@ -135,7 +138,7 @@ public class CostList {
else {
set.add(result);
procedure.add(new Pair<>(result, difference));
addCatalyst(next.one.getLabel(Recipe.enumIoType.CATALYST));
addCatalyst(next.one.getLabel(Recipe.IO.CATALYST));
next = find(true);
}
if (count++ > 1000) {
@@ -148,8 +151,7 @@ public class CostList {
@Nullable
private Pair<Recipe, Long> find(boolean reset) {
if (reset)
index = 0;
index = reset ? 0 : index + 1;
List<ILabel> labels = getCurrent().labels;
for (; index < labels.size(); index++) {
ILabel label = labels.get(index);
@@ -162,16 +164,12 @@ public class CostList {
}
private void addCatalyst(ILabel[] labels) {
LOOP:
for (ILabel i : labels) {
for (ILabel j : catalysts) {
if (j.matches(i)) {
j.setAmount(Math.max(i.getAmount(), j.getAmount()));
continue LOOP;
}
}
catalysts.add(i.copy());
}
Arrays.stream(labels)
.filter(i -> i != ILabel.EMPTY)
.forEach(i -> catalysts.stream()
.filter(j -> j.matches(i)).findAny()
.map(j -> j.setAmount(Math.max(i.getAmount(), j.getAmount())))
.orElseGet(Utilities.fake(() -> catalysts.add(i))));
}
private CostList getCurrent() {
@@ -190,13 +188,7 @@ public class CostList {
public List<ILabel> getOutputs(List<ILabel> ignore) {
return getCurrent().labels.stream()
.map(i -> i.copy().multiply(-1))
.map(i -> {
for (ILabel j : ignore) {
Optional<ILabel> merged = ILabel.MERGER.merge(i, j);
if (merged.isPresent()) i = merged.get();
}
return i;
})
.map(i -> ignore.stream().flatMap(j -> stream(ILabel.MERGER.merge(i, j))).findFirst().orElse(i))
.filter(i -> i != ILabel.EMPTY && i.getAmount() < 0)
.map(i -> i.multiply(-1))
.collect(Collectors.toList());
@@ -91,7 +91,7 @@ public class Recipe {
return p.test(input, r.input) && p.test(catalyst, r.catalyst) && p.test(output, r.output);
}
public ILabel[] getLabel(enumIoType type) {
public ILabel[] getLabel(IO type) {
switch (type) {
case INPUT:
return input;
@@ -148,7 +148,7 @@ public class Recipe {
}).orElse(0L);
}
public enum enumIoType {
public enum IO {
INPUT, OUTPUT, CATALYST;
public int getSize() {
@@ -28,50 +28,47 @@ import java.util.stream.Stream;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class GuiCalculator extends WContainer implements IGui {
enumMode mode = enumMode.INPUT;
Mode mode = Mode.INPUT;
CostList.Calculator calculator = null;
WLabelGroup recent = new WLabelGroup(7, 31, 8, 1, WLabel.enumMode.PICKER);
WLabel label = new WLabel(31, 7, 20, 20, WLabel.enumMode.SELECTOR);
WLabelScroll result = new WLabelScroll(7, 87, 8, 4, WLabel.enumMode.RESULT, true);
WButton input = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN, "calculator.input")
.setLsnrLeft(() -> setMode(enumMode.INPUT));
WButton output = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT, "calculator.output")
.setLsnrLeft(() -> setMode(enumMode.OUTPUT));
WButton catalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "calculator.catalyst")
.setLsnrLeft(() -> setMode(enumMode.CATALYST));
WLabelGroup recent = new WLabelGroup(7, 31, 8, 1, WLabel.Mode.PICKER)
.setListener((i, v) -> JecaGui.getCurrent().hand = i.get(v));
WLabelScroll result = new WLabelScroll(7, 87, 8, 4, WLabel.Mode.RESULT, true);
WButton steps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST, "calculator.step")
.setLsnrLeft(() -> setMode(enumMode.STEPS));
WTextField amount = new WTextField(60, 7, 65);
.setListener(i -> setMode(Mode.STEPS));
WButton catalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "calculator.catalyst")
.setListener(i -> setMode(Mode.CATALYST));
WButton output = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT, "calculator.output")
.setListener(i -> setMode(Mode.OUTPUT));
WButton input = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN, "calculator.input")
.setListener(i -> setMode(Mode.INPUT));
WTextField amount = new WTextField(60, 7, 65).setText(Controller.getAmount()).setListener(i -> {
Controller.setAmount(i.getText());
refreshCalculator();
});
WLabel label = new WLabel(31, 7, 20, 20, WLabel.Mode.SELECTOR).setListener((i, v) -> {
Controller.setRecent(v);
refreshRecent();
refreshCalculator();
});
public GuiCalculator() {
amount.setText(Controller.getAmount());
label.setLsnrUpdate(() -> {
Controller.setRecent(label.label);
refreshRecent();
refreshCalculator();
});
recent.setLsnrUpdate(l -> JecaGui.getCurrent().hand = recent.getLabelAt(l));
amount.setLsnrText(s -> {
Controller.setAmount(s);
refreshCalculator();
});
add(new WHelp("calculator"));
add(new WPanel());
add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL, "calculator.label")
.setLsnrLeft(() -> JecaGui.displayGui(new GuiLabel(l -> {
.setListener(i -> JecaGui.displayGui(new GuiLabel(l -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
}))));
add(new WButtonIcon(130, 7, 20, 20, Resource.BTN_NEW, "calculator.recipe")
.setLsnrLeft(() -> JecaGui.displayGui(true, true, new GuiRecipe())));
.setListener(i -> JecaGui.displayGui(true, true, new GuiRecipe())));
add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH, "calculator.search")
.setLsnrLeft(() -> JecaGui.displayGui(new GuiSearch())));
.setListener(i -> JecaGui.displayGui(new GuiSearch())));
add(new WText(53, 13, JecaGui.Font.PLAIN, "x"));
add(new WLine(55));
add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT, "calculator.history"));
addAll(recent, label, input, output, catalyst, steps, result, amount);
refreshRecent();
setMode(enumMode.INPUT);
setMode(Mode.INPUT);
}
@Override
@@ -79,12 +76,12 @@ public class GuiCalculator extends WContainer implements IGui {
refreshCalculator();
}
void setMode(enumMode mode) {
void setMode(Mode mode) {
this.mode = mode;
input.setDisabled(mode == enumMode.INPUT);
output.setDisabled(mode == enumMode.OUTPUT);
catalyst.setDisabled(mode == enumMode.CATALYST);
steps.setDisabled(mode == enumMode.STEPS);
input.setDisabled(mode == Mode.INPUT);
output.setDisabled(mode == Mode.OUTPUT);
catalyst.setDisabled(mode == Mode.CATALYST);
steps.setDisabled(mode == Mode.STEPS);
refreshResult();
}
@@ -141,7 +138,7 @@ public class GuiCalculator extends WContainer implements IGui {
}
}
enum enumMode {
enum Mode {
INPUT, OUTPUT, CATALYST, STEPS
}
}
@@ -11,6 +11,9 @@ import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.function.Consumer;
import static me.towdium.jecalculation.gui.Resource.ICN_LABEL;
import static me.towdium.jecalculation.gui.Resource.ICN_LIST;
/**
* Author: towdium
* Date: 17-9-16.
@@ -18,26 +21,23 @@ import java.util.function.Consumer;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class GuiDisambiguation extends IPicker.Impl implements IGui {
protected WLabelScroll lsUp;
protected WLabelScroll lsDown;
protected WSwitcher switcher;
protected WLabelScroll lsUp = new WLabelScroll(25, 48, 7, 3, WLabel.Mode.PICKER, true);
protected WLabelScroll lsDown = new WLabelScroll(25, 105, 7, 3, WLabel.Mode.PICKER, true);
protected List<List<ILabel>> record;
public GuiDisambiguation(List<List<ILabel>> record) {
this.record = record;
lsUp = new WLabelScroll(25, 48, 7, 3, WLabel.enumMode.PICKER, true);
lsDown = new WLabelScroll(25, 105, 7, 3, WLabel.enumMode.PICKER, true);
switcher = new WSwitcher(7, 7, 162, this.record.size()).setListener(() -> setPage(switcher.getIndex()));
Consumer<ILabel> consumer = i -> callback.accept(i.copy().multiply(-1));
WSwitcher switcher = new WSwitcher(7, 7, 162, this.record.size()).setListener(i -> setPage(i.getIndex()));
ListenerValue<IWidget, ILabel> consumer = (i, v) -> callback.accept(v.copy().multiply(-1));
add(new WPanel());
add(new WIcon(7, 48, 18, 54, Resource.ICN_LIST, "disambiguation.list"));
add(new WIcon(7, 105, 18, 54, Resource.ICN_LABEL, "disambiguation.label"));
add(new WSearch(25, 24, 90, lsUp.setLsnrUpdate(consumer), lsDown.setLsnrUpdate(consumer)));
add(new WIcon(7, 48, 18, 54, ICN_LIST, "disambiguation.list"));
add(new WIcon(7, 105, 18, 54, ICN_LABEL, "disambiguation.label"));
add(new WSearch(25, 24, 90, lsUp.setListener(consumer), lsDown.setListener(consumer)));
addAll(switcher, lsUp, lsDown);
setPage(0);
}
protected void setPage(int n) {
lsUp.setLabels(record.get(n));
lsDown.setLabels(ILabel.CONVERTER.guess(record.get(n)));
@@ -15,7 +15,8 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static me.towdium.jecalculation.utils.Utilities.I18n.contains;
import static me.towdium.jecalculation.gui.Resource.BTN_YES;
import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
/**
* Author: Towdium
* Date: 18-12-6
@@ -26,23 +27,23 @@ public class GuiImport extends WContainer implements IGui, ISearchable {
List<Quad<Boolean, String, String, Recipes>> filtered;
WSearch search = new WSearch(25, 25, 90, this);
WSwitcher page;
WButton confirm = new WButtonIcon(149, 25, 20, 20, Resource.BTN_YES, "common.confirm").setDisabled(true)
.setLsnrLeft(() -> {
data.stream().filter(i -> i.one).forEach(i -> Controller.inport(i.four, i.three));
JecaGui.displayParent();
});
WButton confirm = new WButtonIcon(149, 25, 20, 20, BTN_YES, "common.confirm").setDisabled(true)
.setListener(i -> {
data.stream().filter(j -> j.one).forEach(j -> Controller.inport(j.four, j.three));
JecaGui.displayParent();
});
List<Pair<WTick, WText>> content = new ArrayList<>();
public GuiImport() {
add(new WPanel());
add(new WIcon(7, 25, 20, 20, Resource.ICN_TEXT, "common.search"));
add(new WIcon(7, 25, 20, 20, ICN_TEXT, "common.search"));
addAll(search, confirm);
IntStream.range(0, 7).forEach(i -> {
WTick tick = new WTick(7, 49 + 16 * i, 13, 13, "import.tick").setDisabled(true)
.setListener(j -> {
filtered.get(page.getIndex() * 7 + i).one = j;
confirm.setDisabled(data.stream().noneMatch(k -> k.one));
});
.setListener(j -> {
filtered.get(page.getIndex() * 7 + i).one = j.selected();
confirm.setDisabled(data.stream().noneMatch(k -> k.one));
});
WText text = new WTextExpand(49 + 16 * i, "");
addAll(tick, text);
content.add(new Pair<>(tick, text));
@@ -76,10 +77,10 @@ public class GuiImport extends WContainer implements IGui, ISearchable {
public boolean setFilter(String s) {
if (s.isEmpty()) filtered = new ArrayList<>(data);
else filtered = data.stream()
.filter(i -> contains(i.two, s) || contains(i.three, s))
.collect(Collectors.toList());
.filter(i -> contains(i.two, s) || contains(i.three, s))
.collect(Collectors.toList());
remove(page);
page = new WSwitcher(7, 7, 162, (filtered.size() + 6) / 7).setListener(this::refresh);
page = new WSwitcher(7, 7, 162, (filtered.size() + 6) / 7).setListener(i -> refresh());
add(page);
refresh();
return !filtered.isEmpty();
@@ -37,7 +37,7 @@ public class GuiLabel extends WContainer implements IGui {
Wrapper<Integer> index = new Wrapper<>(0);
ILabel.EDITOR.getRecords().forEach(r -> {
int i = index.value;
add(new WPage(i, r, false).setListener(() -> refresh(i)));
add(new WPage(i, r, false).setListener(j -> refresh(i)));
index.value += 1;
});
addAll(new WHelp("label"), new WPanel());
@@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: towdium
@@ -27,34 +28,33 @@ public class GuiRecipe extends WContainer implements IGui {
HashMap<Integer, List<ILabel>> disambiguation = new HashMap<>();
WSwitcher switcherGroup = new WSwitcher(7, 7, 162, Controller.getGroups());
WTextField textField = new WTextField(49, 33, 119);
WButton buttonCopy = new WButtonIcon(83, 33, 20, 20, Resource.BTN_COPY, "recipe.copy").setLsnrLeft(() -> {
WLabelGroup groupCatalyst = new WLabelGroup(28, 87, 7, 1, 20, 20, WLabel.Mode.EDITOR);
WButton buttonDisamb = new WButtonIcon(121, 33, 20, 20, BTN_DISAMB, "recipe.disamb").setListener(i -> {
if (disambiguation != null) JecaGui.displayGui(new GuiDisambiguation(new ArrayList<>(disambiguation.values()))
.setCallback(l -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
}));
});
WLabelGroup groupInput = new WLabelGroup(28, 111, 7, 2, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
disambiguation.remove(v);
refresh();
});
WLabelGroup groupOutput = new WLabelGroup(28, 63, 7, 1, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
disambiguation.remove(v + 21);
refresh();
});
WButton buttonClear = new WButtonIcon(64, 33, 20, 20, BTN_DEL, "recipe.clear").setListener(i -> clear());
WButton buttonCopy = new WButtonIcon(83, 33, 20, 20, BTN_COPY, "recipe.copy").setListener(i -> {
Controller.addRecipe(switcherGroup.getText(), toRecipe());
JecaGui.displayParent();
});
WLabelGroup groupCatalyst = new WLabelGroup(28, 87, 7, 1, 20, 20, WLabel.enumMode.EDITOR);
WButton buttonDisamb = new WButtonIcon(121, 33, 20, 20, Resource.BTN_DISAMB, "recipe.disamb").setLsnrLeft(() -> {
if (disambiguation != null)
JecaGui.displayGui(new GuiDisambiguation(new ArrayList<>(disambiguation.values())).setCallback(l -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
}));
});
WLabelGroup groupInput = new WLabelGroup(28, 111, 7, 2, 20, 20, WLabel.enumMode.EDITOR).setLsnrUpdate(i -> {
disambiguation.remove(i);
refresh();
});
WLabelGroup groupOutput = new WLabelGroup(28, 63, 7, 1, 20, 20, WLabel.enumMode.EDITOR).setLsnrUpdate(i -> {
disambiguation.remove(i + 21);
refresh();
});
WButton buttonClear = new WButtonIcon(64, 33, 20, 20, Resource.BTN_DEL, "recipe.clear").setLsnrLeft(this::clear);
WButton buttonLabel = new WButtonIcon(45, 33, 20, 20, Resource.BTN_LABEL, "recipe.label")
.setLsnrLeft(() -> JecaGui.displayGui(new GuiLabel((l) -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
})));
WButton buttonSave = new WButtonIcon(26, 33, 20, 20, Resource.BTN_SAVE, "recipe.save").setLsnrLeft(() -> {
WButton buttonLabel = new WButtonIcon(45, 33, 20, 20, BTN_LABEL, "recipe.label").setListener(i ->
JecaGui.displayGui(new GuiLabel((l) -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
})));
WButton buttonSave = new WButtonIcon(26, 33, 20, 20, BTN_SAVE, "recipe.save").setListener(i -> {
if (dest == null)
Controller.addRecipe(switcherGroup.getText(), toRecipe());
else {
@@ -67,24 +67,17 @@ public class GuiRecipe extends WContainer implements IGui {
}
JecaGui.displayParent();
});
WButton buttonDel = new WButtonIcon(102, 33, 20, 20, Resource.BTN_NO, "recipe.delete").setLsnrLeft(() -> {
WButton buttonDel = new WButtonIcon(102, 33, 20, 20, BTN_NO, "recipe.delete").setListener(i -> {
Controller.removeRecipe(dest.one, dest.two);
JecaGui.displayParent();
});
WButton buttonNew = new WButtonIcon(7, 33, 20, 20, Resource.BTN_NEW, "recipe.new")
.setLsnrLeft(() -> setModeNewGroup(true));
WButton buttonYes = new WButtonIcon(7, 33, 20, 20, Resource.BTN_YES, "recipe.confirm").setDisabled(true)
.setLsnrLeft(() -> {
switcherGroup.setTemp(
textField
.getText());
textField.setText("");
setModeNewGroup(false);
});
WButton buttonNo = new WButtonIcon(26, 33, 20, 20, Resource.BTN_NO, "recipe.cancel")
.setLsnrLeft(() -> setModeNewGroup(false));
WButton buttonYes = new WButtonIcon(7, 33, 20, 20, BTN_YES, "recipe.confirm").setDisabled(true).setListener(i -> {
switcherGroup.setTemp(textField.getText());
textField.setText("");
setNewGroup(false);
});
WButton buttonNo = new WButtonIcon(26, 33, 20, 20, BTN_NO, "recipe.cancel").setListener(i -> setNewGroup(false));
WButton buttonNew = new WButtonIcon(7, 33, 20, 20, BTN_NEW, "recipe.new").setListener(i -> setNewGroup(true));
public GuiRecipe(String group, int index) {
this();
@@ -98,21 +91,20 @@ public class GuiRecipe extends WContainer implements IGui {
public GuiRecipe() {
addAll(new WHelp("recipe"), new WPanel());
add(new WIcon(7, 63, 21, 20, Resource.ICN_OUTPUT, "recipe.output"));
add(new WIcon(7, 87, 21, 20, Resource.ICN_CATALYST, "recipe.catalyst"));
add(new WIcon(7, 111, 21, 40, Resource.ICN_INPUT, "recipe.input"));
add(new WIcon(7, 63, 21, 20, ICN_OUTPUT, "recipe.output"));
add(new WIcon(7, 87, 21, 20, ICN_CATALYST, "recipe.catalyst"));
add(new WIcon(7, 111, 21, 40, ICN_INPUT, "recipe.input"));
add(new WLine(57));
addAll(groupInput, groupCatalyst, groupOutput, switcherGroup);
if (switcherGroup.getTexts().isEmpty())
switcherGroup.setTemp(Utilities.I18n.format("common.default"));
setModeNewGroup(false);
if (switcherGroup.getTexts().isEmpty()) switcherGroup.setTemp(Utilities.I18n.format("common.default"));
setNewGroup(false);
buttonCopy.setDisabled(true);
buttonDel.setDisabled(true);
buttonDisamb.setDisabled(true);
textField.setLsnrText(s -> buttonYes.setDisabled(s.isEmpty()));
textField.setListener(i -> buttonYes.setDisabled(i.getText().isEmpty()));
}
public void setModeNewGroup(boolean b) {
public void setNewGroup(boolean b) {
if (b) {
removeAll(buttonNew, buttonLabel, buttonClear, buttonCopy, buttonSave, buttonDisamb, buttonDel);
addAll(buttonYes, buttonNo, textField);
@@ -188,13 +180,12 @@ public class GuiRecipe extends WContainer implements IGui {
}
void fromRecipe(Recipe r) {
groupInput.setLabel(
Arrays.stream(r.getLabel(Recipe.enumIoType.INPUT)).map(ILabel::copy).collect(Collectors.toList()), 0);
groupCatalyst.setLabel(
Arrays.stream(r.getLabel(Recipe.enumIoType.CATALYST)).map(ILabel::copy).collect(Collectors.toList()),
0);
groupOutput.setLabel(
Arrays.stream(r.getLabel(Recipe.enumIoType.OUTPUT)).map(ILabel::copy).collect(Collectors.toList()), 0);
groupInput.setLabel(Arrays.stream(r.getLabel(Recipe.IO.INPUT))
.map(ILabel::copy).collect(Collectors.toList()), 0);
groupCatalyst.setLabel(Arrays.stream(r.getLabel(Recipe.IO.CATALYST))
.map(ILabel::copy).collect(Collectors.toList()), 0);
groupOutput.setLabel(Arrays.stream(r.getLabel(Recipe.IO.OUTPUT))
.map(ILabel::copy).collect(Collectors.toList()), 0);
}
@@ -14,24 +14,25 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static me.towdium.jecalculation.gui.Resource.*;
import static me.towdium.jecalculation.gui.widgets.WLabel.Mode.PICKER;
public class GuiSearch extends WContainer implements IGui {
List<Trio<Recipe, String, Integer>> content;
WSwitcher group;
WLabelScroll labels;
WButton export;
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, PICKER, true).setListener((i, v) -> content.stream()
.filter(j -> j.one.getRep() == v)
.findFirst()
.ifPresent(j -> JecaGui.displayGui(true, true, new GuiRecipe(j.two, j.three))));
public GuiSearch() {
labels = new WLabelScroll(7, 51, 8, 6, WLabel.enumMode.PICKER, true);
labels.setLsnrUpdate(i -> content.stream()
.filter(j -> j.one.getRep() == i)
.findFirst()
.ifPresent(j -> JecaGui.displayGui(true, true, new GuiRecipe(j.two, j.three))));
add(new WPanel());
add(new WSearch(25, 25, 90, labels));
add(new WIcon(7, 25, 20, 20, Resource.ICN_TEXT, "common.search"));
add(new WButtonIcon(131, 25, 20, 20, Resource.BTN_IN, "search.import")
.setLsnrLeft(() -> JecaGui.displayGui(new GuiImport())));
add(new WIcon(7, 25, 20, 20, ICN_TEXT, "common.search"));
add(new WButtonIcon(131, 25, 20, 20, BTN_IN, "search.import")
.setListener(i -> JecaGui.displayGui(new GuiImport())));
add(labels);
}
@@ -52,7 +53,7 @@ public class GuiSearch extends WContainer implements IGui {
name = Controller.getGroups().get(iGroup - 1);
recipes = Controller.getRecipes(name);
}
export = new WButtonIcon(149, 25, 20, 20, Resource.BTN_OUT, tooltip).setLsnrLeft(() -> {
export = new WButtonIcon(149, 25, 20, 20, BTN_OUT, tooltip).setListener(i -> {
File f = iGroup == 0 ? Controller.export() : Controller.export(name);
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation(
"jecalculation.chat.export", f.getAbsolutePath()));
@@ -68,7 +69,7 @@ public class GuiSearch extends WContainer implements IGui {
groups.addAll(Controller.getGroups());
int index = group == null ? 0 : group.getIndex();
if (index >= groups.size()) index = groups.size() - 1;
group = new WSwitcher(7, 7, 162, groups).setListener(this::refresh);
group = new WSwitcher(7, 7, 162, groups).setListener(i -> refresh());
group.setIndex(index);
addAll(group);
refresh();
@@ -13,6 +13,8 @@ import me.towdium.jecalculation.gui.widgets.WLabel;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: Towdium
* Date: 18-9-18
@@ -20,14 +22,14 @@ import java.util.function.Consumer;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class PickerItemStack extends IPicker.Impl implements IGui {
WLabel label = new WLabel(7, 7, 20, 20, WLabel.enumMode.SELECTOR).setLsnrUpdate(this::update);
WButton bConfirm = new WButtonIcon(149, 7, 20, 20, Resource.BTN_YES).setLsnrLeft(() -> callback.accept(label.getLabel()));
WButton bNbtF = new WButtonIcon(49, 7, 20, 20, Resource.BTN_NBT_F).setLsnrLeft(() -> setFNbt(false));
WButton bBbtN = new WButtonIcon(49, 7, 20, 20, Resource.BTN_NBT_N).setLsnrLeft(() -> setFNbt(true));
WButton bCapF = new WButtonIcon(68, 7, 20, 20, Resource.BTN_CAP_F).setLsnrLeft(() -> setFCap(false));
WButton bCapN = new WButtonIcon(68, 7, 20, 20, Resource.BTN_CAP_N).setLsnrLeft(() -> setFCap(true));
WButton bMetaF = new WButtonIcon(30, 7, 20, 20, Resource.BTN_META_F).setLsnrLeft(() -> setFMeta(false));
WButton bMetaN = new WButtonIcon(30, 7, 20, 20, Resource.BTN_META_N).setLsnrLeft(() -> setFMeta(true));
WLabel label = new WLabel(7, 7, 20, 20, WLabel.Mode.SELECTOR).setListener((i, v) -> update());
WButton bConfirm = new WButtonIcon(149, 7, 20, 20, BTN_YES).setListener(i -> callback.accept(label.getLabel()));
WButton bBbtN = new WButtonIcon(49, 7, 20, 20, BTN_NBT_N).setListener(i -> setFNbt(true));
WButton bNbtF = new WButtonIcon(49, 7, 20, 20, BTN_NBT_F).setListener(i -> setFNbt(false));
WButton bCapN = new WButtonIcon(68, 7, 20, 20, BTN_CAP_N).setListener(i -> setFCap(true));
WButton bCapF = new WButtonIcon(68, 7, 20, 20, BTN_CAP_F).setListener(i -> setFCap(false));
WButton bMetaN = new WButtonIcon(30, 7, 20, 20, BTN_META_N).setListener(i -> setFMeta(true));
WButton bMetaF = new WButtonIcon(30, 7, 20, 20, BTN_META_F).setListener(i -> setFMeta(false));
public PickerItemStack() {
addAll(label, bConfirm);
@@ -9,6 +9,10 @@ import me.towdium.jecalculation.gui.guis.IGui;
import me.towdium.jecalculation.gui.widgets.*;
import javax.annotation.ParametersAreNonnullByDefault;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_RED;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_WHITE;
import static me.towdium.jecalculation.gui.Resource.BTN_YES;
import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
/**
* Author: towdium
@@ -18,15 +22,15 @@ import javax.annotation.ParametersAreNonnullByDefault;
@SideOnly(Side.CLIENT)
public class PickerPlaceholder extends IPicker.Impl implements IGui {
public PickerPlaceholder() {
WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, WLabel.enumMode.PICKER, true)
.setLabels(LPlaceholder.getRecent()).setLsnrUpdate(this::notifyLsnr);
WTextField create = new WTextField(26, 7, 69);
create.setLsnrText(s -> create.setColor(s.equals("") ? JecaGui.COLOR_TEXT_RED : JecaGui.COLOR_TEXT_WHITE));
WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, WLabel.Mode.PICKER, true)
.setLabels(LPlaceholder.getRecent()).setListener((i, v) -> notifyLsnr(v));
WTextField create = new WTextField(26, 7, 69)
.setListener(i -> i.setColor(i.getText().equals("") ? COLOR_TEXT_RED : COLOR_TEXT_WHITE));
add(new WSearch(26, 45, 90, scroll));
add(new WIcon(7, 45, 20, 20, Resource.ICN_TEXT, "picker_placeholder.text_search"));
add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT, "picker_placeholder.text_create"));
add(new WIcon(7, 45, 20, 20, ICN_TEXT, "picker_placeholder.text_search"));
add(new WIcon(7, 7, 20, 20, ICN_TEXT, "picker_placeholder.text_create"));
add(new WLine(36));
add(new WButtonIcon(95, 7, 20, 20, Resource.BTN_YES).setLsnrLeft(() -> {
add(new WButtonIcon(95, 7, 20, 20, BTN_YES).setListener(i -> {
if (!create.getText().equals("")) callback.accept(new LPlaceholder(create.getText(), 1));
}));
addAll(scroll, create);
@@ -16,6 +16,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
/**
* Author: towdium
@@ -30,10 +31,10 @@ public class PickerSimple extends IPicker.Impl implements IGui {
* entire key should be "gui.l18nKey.help.tooltip"
*/
public PickerSimple(List<ILabel> labels, String l18nKey) {
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, WLabel.enumMode.PICKER, true)
.setLabels(labels).setLsnrUpdate(this::notifyLsnr);
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, WLabel.Mode.PICKER, true).setLabels(labels)
.setListener((i, v) -> notifyLsnr(v));
add(new WSearch(26, 7, 90, ls));
add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT, l18nKey + ".text"));
add(new WIcon(7, 7, 20, 20, ICN_TEXT, l18nKey + ".text"));
add(ls);
}
@@ -1,12 +1,14 @@
package me.towdium.jecalculation.gui.widgets;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
@ParametersAreNonnullByDefault
public interface IWidget { // TODO unify listener behavior when manually set and pass instance to listener
public interface IWidget {
void onDraw(JecaGui gui, int xMouse, int yMouse);
default boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
@@ -24,4 +26,19 @@ public interface IWidget { // TODO unify listener behavior when manually set and
default boolean onScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
return false;
}
@Nullable
default ILabel getLabelUnderMouse(int xMouse, int yMouse) {
return null;
}
@FunctionalInterface
interface ListenerValue<W extends IWidget, V> {
void invoke(W widget, V value);
}
@FunctionalInterface
interface ListenerAction<W extends IWidget> {
void invoke(W widget);
}
}
@@ -5,7 +5,6 @@ import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.utils.ClientUtils;
import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -13,6 +12,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: towdium
* Date: 17-8-17.
@@ -21,8 +22,7 @@ import java.util.List;
@SideOnly(Side.CLIENT)
public abstract class WButton extends WTooltip {
protected int xPos, yPos, xSize, ySize;
protected Runnable lsnrLeft, lsnrRight;
protected Utilities.Timer timer = new Utilities.Timer();
protected ListenerAction<? super WButton> listener;
protected boolean disabled;
public WButton(int xPos, int yPos, int xSize, int ySize, @Nullable String name) {
@@ -33,26 +33,21 @@ public abstract class WButton extends WTooltip {
this.ySize = ySize;
}
public WButton setLsnrLeft(Runnable r) {
lsnrLeft = r;
return this;
}
public WButton setLsnrRight(Runnable r) {
lsnrRight = r;
public WButton setListener(ListenerAction<? super WButton> r) {
listener = r;
return this;
}
protected Resource getDisabled() {
return Resource.WGT_BUTTON_D;
return WGT_BUTTON_D;
}
protected Resource getNormal() {
return Resource.WGT_BUTTON_N;
return WGT_BUTTON_N;
}
protected Resource getFocused() {
return Resource.WGT_BUTTON_F;
return WGT_BUTTON_F;
}
@Override
@@ -66,14 +61,10 @@ public abstract class WButton extends WTooltip {
@Override
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
if (!disabled && JecaGui.mouseIn(xPos + 1, yPos + 1, xSize - 2, ySize - 2, xMouse, yMouse)) {
if (button == 0 && lsnrLeft != null) {
lsnrLeft.run();
if (button == 0 && listener != null) {
listener.invoke(this);
ClientUtils.playClickSound(1.0F);
return true;
} else if (button == 1 && lsnrRight != null) {
lsnrLeft.run();
ClientUtils.playClickSound(0.8F);
return true;
}
}
return false;
@@ -2,12 +2,15 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Author: towdium
@@ -47,29 +50,34 @@ public class WContainer implements IContainer {
@Override
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
Utilities.ReversedIterator<IWidget> i = new Utilities.ReversedIterator<>(widgets);
while (i.hasNext()) if (i.next().onClicked(gui, xMouse, yMouse, button)) return true;
return false;
return new Utilities.ReversedIterator<>(widgets).stream()
.anyMatch(i -> i.onClicked(gui, xMouse, yMouse, button));
}
@Override
public boolean onKey(JecaGui gui, char ch, int code) {
Utilities.ReversedIterator<IWidget> i = new Utilities.ReversedIterator<>(widgets);
while (i.hasNext()) if (i.next().onKey(gui, ch, code)) return true;
return false;
return new Utilities.ReversedIterator<>(widgets).stream()
.anyMatch(i -> i.onKey(gui, ch, code));
}
@Override
public boolean onScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
Utilities.ReversedIterator<IWidget> i = new Utilities.ReversedIterator<>(widgets);
while (i.hasNext()) if (i.next().onScroll(gui, xMouse, yMouse, diff)) return true;
return false;
return new Utilities.ReversedIterator<>(widgets).stream()
.anyMatch(i -> i.onScroll(gui, xMouse, yMouse, diff));
}
@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;
return new Utilities.ReversedIterator<>(widgets).stream()
.anyMatch(i -> i.onTooltip(gui, xMouse, yMouse, tooltip));
}
@Nullable
@Override
public ILabel getLabelUnderMouse(int xMouse, int yMouse) {
return new Utilities.ReversedIterator<>(widgets).stream()
.map(i -> i.getLabelUnderMouse(xMouse, yMouse))
.filter(Objects::nonNull)
.findFirst().orElse(null);
}
}
@@ -1,7 +1,6 @@
package me.towdium.jecalculation.gui.widgets;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.utils.Utilities.I18n;
import org.lwjgl.input.Keyboard;
@@ -9,6 +8,10 @@ import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import static me.towdium.jecalculation.gui.JecaGui.Font.PLAIN;
import static me.towdium.jecalculation.gui.JecaGui.Font.SHADOW;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: Towdium
* Date: 18-9-23
@@ -24,8 +27,8 @@ public class WHelp extends WTooltip {
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
gui.drawResourceContinuous(Resource.WGT_PANEL_N, -21, 0, 25, 24, 4);
gui.drawResource(Resource.WGT_HELP_N, -19, 2);
gui.drawResourceContinuous(WGT_PANEL_N, -21, 0, 25, 24, 4);
gui.drawResource(WGT_HELP_N, -19, 2);
}
@Override
@@ -36,7 +39,8 @@ public class WHelp extends WTooltip {
@Override
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
boolean ret = mouseIn(xMouse, yMouse);
if (ret) gui.root.add(new Doc());
if (ret)
gui.root.add(new Doc());
return ret;
}
@@ -44,14 +48,15 @@ public class WHelp extends WTooltip {
public Doc() {
Text tContent = new Text();
WSwitcher sPage = new WSwitcher(7, 146, 162, tContent.amount());
sPage.setListener(() -> tContent.setPage(sPage.getIndex()));
WText tTitle = new WText(7, 7, JecaGui.Font.SHADOW, I18n.format("gui." + WHelp.this.key + ".title"));
sPage.setListener(i -> tContent.setPage(i.getIndex()));
WText tTitle = new WText(7, 7, SHADOW, I18n.format("gui." + WHelp.this.key + ".title"));
addAll(new WPanel(), new Icon(), tTitle, tContent, sPage);
}
@Override
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
if (!super.onClicked(gui, xMouse, yMouse, button)) gui.root.remove(this);
if (!super.onClicked(gui, xMouse, yMouse, button))
gui.root.remove(this);
return true;
}
@@ -79,12 +84,13 @@ public class WHelp extends WTooltip {
count++;
}
}
if (!tmp.isEmpty()) pages.add(tmp);
if (!tmp.isEmpty())
pages.add(tmp);
}
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
gui.drawSplitText(7, 21, JecaGui.Font.PLAIN, pages.get(page));
gui.drawSplitText(7, 21, PLAIN, pages.get(page));
}
public int amount() {
@@ -103,14 +109,15 @@ public class WHelp extends WTooltip {
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
gui.drawResourceContinuous(Resource.WGT_HELP_B, -21, 0, 25, 24, 4);
gui.drawResource(Resource.WGT_HELP_F, -19, 2);
gui.drawResourceContinuous(WGT_HELP_B, -21, 0, 25, 24, 4);
gui.drawResource(WGT_HELP_F, -19, 2);
}
@Override
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
boolean ret = mouseIn(xMouse, yMouse);
if (ret) gui.root.remove(Doc.this);
if (ret)
gui.root.remove(Doc.this);
return ret;
}
@@ -121,11 +128,13 @@ public class WHelp extends WTooltip {
@Override
public boolean onKey(JecaGui gui, char ch, int code) {
if (super.onKey(gui, ch, code)) return true;
if (super.onKey(gui, ch, code))
return true;
if (code == Keyboard.KEY_ESCAPE) {
gui.root.remove(Doc.this);
return true;
} else return false;
} else
return false;
}
}
}
@@ -7,6 +7,7 @@ import me.towdium.jecalculation.gui.Resource;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_GUI_GREY;
/**
@@ -41,7 +42,7 @@ public class WIcon extends WTooltip {
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
super.onDraw(gui, xMouse, yMouse);
gui.drawRectangle(xPos, yPos, xSize, ySize, JecaGui.COLOR_GUI_GREY);
gui.drawRectangle(xPos, yPos, xSize, ySize, COLOR_GUI_GREY);
Resource r = mouseIn(xMouse, yMouse) ? focused : normal;
gui.drawResource(r, (xSize - r.getXSize()) / 2 + xPos, (ySize - r.getYSize()) / 2 + yPos);
}
@@ -11,11 +11,17 @@ import me.towdium.jecalculation.utils.IllegalPositionException;
import me.towdium.jecalculation.utils.Utilities;
import org.lwjgl.input.Keyboard;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.stream.IntStream;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_RED;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_WHITE;
import static me.towdium.jecalculation.gui.JecaGui.Font.HALF;
import static me.towdium.jecalculation.gui.JecaGui.Font.PLAIN;
import static me.towdium.jecalculation.gui.Resource.BTN_NO;
import static me.towdium.jecalculation.gui.Resource.BTN_YES;
/**
* Author: towdium
@@ -26,11 +32,12 @@ import static me.towdium.jecalculation.gui.JecaGui.Font.HALF;
public class WLabel implements IWidget {
public int xPos, yPos, xSize, ySize;
public ILabel label;
public enumMode mode;
public Runnable lsnrUpdate;
public Mode mode;
public ListenerValue<? super WLabel, ILabel> listener;
protected Utilities.Timer timer = new Utilities.Timer();
public WLabel(int xPos, int yPos, int xSize, int ySize, enumMode mode) {
public WLabel(int xPos, int yPos, int xSize, int ySize, Mode mode) {
this.xPos = xPos;
this.yPos = yPos;
this.xSize = xSize;
@@ -51,12 +58,12 @@ public class WLabel implements IWidget {
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
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) {
String s = label.getAmountString(mode == enumMode.RESULT);
if (mode == Mode.RESULT || mode == Mode.EDITOR) {
String s = label.getAmountString(mode == Mode.RESULT);
gui.drawText(xPos + xSize / 2.0f + 8 - HALF.getTextWidth(s),
yPos + ySize / 2.0f + 8.5f - HALF.getTextHeight(), HALF, s);
}
if (mode == enumMode.EDITOR || mode == enumMode.SELECTOR) {
if (mode == Mode.EDITOR || mode == Mode.SELECTOR) {
timer.setState(gui.hand != ILabel.EMPTY);
int color = 0xFFFFFF + (int) ((-Math.cos(timer.getTime() * Math.PI / 1500) + 1) * 0x40) * 0x1000000;
gui.drawRectangle(xPos + 1, yPos + 1, xSize - 2, ySize - 2, color);
@@ -71,16 +78,16 @@ public class WLabel implements IWidget {
return false;
if (label != ILabel.EMPTY) {
tooltip.add(label.getDisplayName());
label.getToolTip(tooltip, mode == enumMode.EDITOR || mode == enumMode.RESULT);
label.getToolTip(tooltip, mode == Mode.EDITOR || mode == Mode.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 -> label = diff > 0 ? label.increaseAmount() : label.decreaseAmount());
if (mouseIn(xMouse, yMouse) && mode == Mode.EDITOR && label != ILabel.EMPTY) {
for (int i = 0; i < Math.abs(diff); i++)
label = diff > 0 ? label.increaseAmount() : label.decreaseAmount();
notifyLsnr();
return true;
} else
@@ -133,8 +140,8 @@ public class WLabel implements IWidget {
}
}
public WLabel setLsnrUpdate(Runnable lsnr) {
lsnrUpdate = lsnr;
public WLabel setListener(ListenerValue<? super WLabel, ILabel> listener) {
this.listener = listener;
return this;
}
@@ -145,12 +152,11 @@ public class WLabel implements IWidget {
}
void notifyLsnr() {
if (lsnrUpdate != null)
lsnrUpdate.run();
if (listener != null) listener.invoke(this, label);
}
public enum enumMode {
public enum Mode {
EDITOR, // Slots in editor gui. Can use to edit amount. Exact amount displayed.
RESULT, // Slots to display calculate/getRecipes result. Rounded amount displayed.
PICKER, // Slots that can pick items from. No amount displayed.
@@ -159,17 +165,18 @@ public class WLabel implements IWidget {
class WAmount extends WContainer {
WLabel wl = new WLabel(xPos, yPos, xSize, ySize, enumMode.SELECTOR).setLsnrUpdate(this::update);
WButton bAmount = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "general.to_percent", "#")
.setListener(i -> setPercent(true));
WTextField wtf = new WTextField(xPos + xSize + 10, yPos + ySize / 2 - WTextField.HEIGHT / 2, 50);
WButton bPercent = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "general.to_percent", "%")
.setLsnrLeft(() -> setPercent(false));
WButton bAmount = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "general.to_percent", "#")
.setLsnrLeft(() -> setPercent(true));
WButton bYes = new WButtonIcon(xPos + xSize + 83, yPos, 20, 20, Resource.BTN_YES).setLsnrLeft(() -> {
setLabel(wl.getLabel().setAmount(wtf.getText().isEmpty() ? 0 : Integer.parseInt(wtf.getText())));
.setListener(i -> setPercent(false));
WLabel wl = new WLabel(xPos, yPos, xSize, ySize, Mode.SELECTOR).setListener((i, v) -> update());
WButton bYes = new WButtonIcon(xPos + xSize + 83, yPos, 20, 20, BTN_YES).setListener(i -> {
setLabel(wl.getLabel().setAmount(
wtf.getText().isEmpty() ? 0 : Integer.parseInt(wtf.getText())));
JecaGui.getCurrent().root.remove(this);
});
WButton bNo = new WButtonIcon(xPos + xSize + 102, yPos, 20, 20, Resource.BTN_NO).setLsnrLeft(() -> {
WButton bNo = new WButtonIcon(xPos + xSize + 102, yPos, 20, 20, BTN_NO).setListener(i -> {
setLabel(ILabel.EMPTY);
JecaGui.getCurrent().root.remove(this);
});
@@ -177,16 +184,16 @@ public class WLabel implements IWidget {
public WAmount() {
wl.setLabel(label);
add(new WPanel(xPos - 5, yPos - 5, xSize + 133, ySize + 10));
add(new WText(xPos + xSize + 3, yPos + 5, JecaGui.Font.PLAIN, "x"));
add(new WText(xPos + xSize + 3, yPos + 5, PLAIN, "x"));
addAll(wl, wtf, bYes, bNo);
wtf.setLsnrText(i -> {
wtf.setListener(i -> {
try {
Integer.parseInt(wtf.getText());
wtf.setColor(JecaGui.COLOR_TEXT_WHITE);
wtf.setColor(COLOR_TEXT_WHITE);
bYes.setDisabled(false);
} catch (NumberFormatException e) {
boolean acceptable = wtf.getText().isEmpty();
wtf.setColor(acceptable ? JecaGui.COLOR_TEXT_WHITE : JecaGui.COLOR_TEXT_RED);
wtf.setColor(acceptable ? COLOR_TEXT_WHITE : COLOR_TEXT_RED);
bYes.setDisabled(!acceptable);
}
});
@@ -222,4 +229,10 @@ public class WLabel implements IWidget {
return false;
}
}
@Nullable
@Override
public ILabel getLabelUnderMouse(int xMouse, int yMouse) {
return mouseIn(xMouse, yMouse) ? label : null;
}
}
@@ -21,30 +21,26 @@ import java.util.stream.IntStream;
@SideOnly(Side.CLIENT)
public class WLabelGroup extends WContainer {
ArrayList<WLabel> labels = new ArrayList<>();
Consumer<Integer> lsnrUpdate;
ListenerValue<? super WLabelGroup, Integer> listener;
public WLabelGroup(int xPos, int yPos, int column, int row, WLabel.enumMode mode) {
public WLabelGroup(int xPos, int yPos, int column, int row, WLabel.Mode mode) {
this(xPos, yPos, column, row, 18, 18, mode);
}
public WLabelGroup(int xPos, int yPos, int column, int row, int xSize, int ySize, WLabel.enumMode mode) {
public WLabelGroup(int xPos, int yPos, int column, int row, int xSize, int ySize, WLabel.Mode mode) {
IntStream.range(0, row).forEach(r -> IntStream.range(0, column).forEach(c -> {
WLabel l = new WLabel(xPos + c * xSize, yPos + r * ySize, xSize, ySize, mode).setLsnrUpdate(() -> {
if (lsnrUpdate != null) lsnrUpdate.accept(r * column + c);
WLabel l = new WLabel(xPos + c * xSize, yPos + r * ySize, xSize, ySize, mode).setListener((i, v) -> {
if (listener != null) listener.invoke(this, r * column + c);
});
labels.add(l);
add(l);
}));
}
public ILabel getLabelAt(int index) {
public ILabel get(int index) {
return labels.get(index).getLabel();
}
public Optional<ILabel> getLabelAt(int xMouse, int yMouse) {
return labels.stream().filter(w -> w.mouseIn(xMouse, yMouse)).findFirst().map(WLabel::getLabel);
}
public List<ILabel> getLabels() {
return labels.stream().map(WLabel::getLabel).collect(Collectors.toList());
}
@@ -57,8 +53,8 @@ public class WLabelGroup extends WContainer {
for (WLabel label : this.labels) label.setLabel(start < labels.size() ? labels.get(start++) : ILabel.EMPTY);
}
public WLabelGroup setLsnrUpdate(Consumer<Integer> listener) {
lsnrUpdate = listener;
public WLabelGroup setListener(ListenerValue<? super WLabelGroup, Integer> listener) {
this.listener = listener;
return this;
}
}
@@ -25,18 +25,17 @@ public class WLabelScroll extends WContainer implements ISearchable {
protected WScroll scroll;
protected int xPos, yPos, column, row, current;
protected String filter = "";
protected Consumer<ILabel> lsnrUpdate;
protected ListenerValue<? super WLabelScroll, ILabel> listener;
public WLabelScroll(int xPos, int yPos, int column, int row, WLabel.enumMode mode, boolean drawConnection) {
public WLabelScroll(int xPos, int yPos, int column, int row, WLabel.Mode mode, boolean drawConnection) {
this.xPos = xPos;
this.yPos = yPos;
this.column = column;
this.row = row;
labelGroup = new WLabelGroup(xPos, yPos, column, row, mode)
.setLsnrUpdate(i -> {
if (lsnrUpdate != null) lsnrUpdate.accept(labels.get(i + current * column));
});
scroll = new WScroll(xPos + column * 18 + 4, yPos, row * 18).setLsnrScroll(this::update);
labelGroup = new WLabelGroup(xPos, yPos, column, row, mode).setListener((i, v) -> {
if (listener != null) listener.invoke(this, i.get(v));
});
scroll = new WScroll(xPos + column * 18 + 4, yPos, row * 18).setListener(i -> update(i.getCurrent()));
add(labelGroup);
add(scroll);
if (drawConnection) add(new WRectangle(xPos + column * 18, yPos, 4, row * 18, JecaGui.COLOR_GUI_GREY));
@@ -82,16 +81,11 @@ public class WLabelScroll extends WContainer implements ISearchable {
}
@SuppressWarnings("UnusedReturnValue")
public WLabelScroll setLsnrUpdate(Consumer<ILabel> lsnr) {
lsnrUpdate = lsnr;
public WLabelScroll setListener(ListenerValue<? super WLabelScroll, ILabel> listener) {
this.listener = listener;
return this;
}
public ILabel getLabelAt(int index) {
return labelGroup.getLabelAt(index - current * column);
}
private int getStepAmount() {
int line = (labels.size() + column - 1) / column;
return Math.max(line - row + 1, 1);
@@ -6,7 +6,7 @@ import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import javax.annotation.ParametersAreNonnullByDefault;
import static me.towdium.jecalculation.gui.Resource.WGT_LINE;
/**
* Author: towdium
* Date: 17-8-18.
@@ -22,6 +22,6 @@ public class WLine implements IWidget {
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
gui.drawResource(Resource.WGT_LINE, 6, y - 1);
gui.drawResource(WGT_LINE, 6, y - 1);
}
}
@@ -10,6 +10,7 @@ import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: towdium
@@ -17,14 +18,14 @@ import java.util.List;
*/
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class WPage implements IWidget {
public class WPage extends WTooltip {
protected int index;
protected ILabel.RegistryEditor.Record record;
protected Utilities.Timer timer = new Utilities.Timer();
protected Record record;
protected boolean focused;
protected Runnable listener;
protected ListenerAction<? super WPage> listener;
public WPage(int index, Record record, boolean focused) {
super(record.localizeKey);
this.index = index;
this.record = record;
this.focused = focused;
@@ -32,30 +33,25 @@ 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_PANEL_N;
Resource resource = focused ? (index == 0 ? WGT_PAGER_F0 : WGT_PAGER_FN) : WGT_PANEL_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));
super.onDraw(gui, xMouse, yMouse);
}
@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.invoke(this);
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 boolean mouseIn(int xMouse, int yMouse) {
return JecaGui.mouseIn(index * 24, -21, 24, 21, xMouse, yMouse);
}
public WPage setListener(Runnable r) {
public WPage setListener(ListenerAction<? super WPage> r) {
listener = r;
return this;
}
@@ -19,7 +19,7 @@ import java.util.function.Consumer;
@SideOnly(Side.CLIENT)
public class WScroll implements IWidget {
public int xPos, yPos, ySize, current;
public Consumer<Float> lsnrScroll;
public ListenerAction<? super WScroll> listener;
protected boolean drag;
public WScroll(int xPos, int yPos, int ySize) {
@@ -48,7 +48,11 @@ public class WScroll implements IWidget {
current = pos;
if (current < 0) current = 0;
if (current > ySize - 17) current = ySize - 17;
if (notify && lsnrScroll != null) lsnrScroll.accept(current / (ySize - 17f));
if (notify && listener != null) listener.invoke(this);
}
public float getCurrent() {
return current / (ySize - 17f);
}
public void setCurrent(float ratio) {
@@ -59,8 +63,8 @@ public class WScroll implements IWidget {
return JecaGui.mouseIn(xPos + 1, yPos + 1, 12, ySize - 2, xMouse, yMouse);
}
public WScroll setLsnrScroll(@Nullable Consumer<Float> lsnrScroll) {
this.lsnrScroll = lsnrScroll;
public WScroll setListener(@Nullable ListenerAction<? super WScroll> listener) {
this.listener = listener;
return this;
}
}
@@ -7,6 +7,8 @@ import me.towdium.jecalculation.data.label.ILabel;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_RED;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_WHITE;
/**
* Author: towdium
@@ -31,6 +33,6 @@ public class WSearch extends WTextField {
public void refresh() {
boolean b = false;
for (ISearchable i : lss) if (i.setFilter(textField.getText())) b = true;
setColor(b ? JecaGui.COLOR_TEXT_WHITE : JecaGui.COLOR_TEXT_RED);
setColor(b ? COLOR_TEXT_WHITE : COLOR_TEXT_RED);
}
}
@@ -12,6 +12,12 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_GUI_GREY;
import static me.towdium.jecalculation.gui.JecaGui.Font.SHADOW;
import static me.towdium.jecalculation.gui.Resource.WGT_ARR_L;
import static me.towdium.jecalculation.gui.Resource.WGT_ARR_R;
/**
* Author: towdium
* Date: 17-8-19.
@@ -21,7 +27,7 @@ import java.util.stream.IntStream;
@SideOnly(Side.CLIENT)
public class WSwitcher extends WContainer {
public static final int SIZE = 13;
public Runnable listener;
public ListenerAction<? super WSwitcher> listener;
protected int xPos, xSize, yPos;
protected WButton left, right;
protected WRectangle wRect;
@@ -40,16 +46,16 @@ public class WSwitcher extends WContainer {
this.xSize = xSize;
this.yPos = yPos;
this.keys = keys;
left = new WButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WGT_ARR_L).setLsnrLeft(() -> {
left = new WButtonIcon(xPos, yPos, SIZE, SIZE, WGT_ARR_L).setListener(i -> {
if (temp == null) move(false);
else setTemp(null);
});
right = new WButtonIcon(xPos + xSize - SIZE, yPos, SIZE, SIZE, Resource.WGT_ARR_R).setLsnrLeft(() -> {
right = new WButtonIcon(xPos + xSize - SIZE, yPos, SIZE, SIZE, WGT_ARR_R).setListener(i -> {
if (temp == null) move(true);
else setTemp(null);
});
wRect = new WRectangle(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecaGui.COLOR_GUI_GREY);
wText = new WText(xPos + SIZE, yPos + 2, xSize - 2 * SIZE, JecaGui.Font.SHADOW, "", true);
wRect = new WRectangle(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, COLOR_GUI_GREY);
wText = new WText(xPos + SIZE, yPos + 2, xSize - 2 * SIZE, SHADOW, "", true);
index = new Circulator(keys.size());
refresh();
addAll(left, right, wRect, wText);
@@ -68,7 +74,7 @@ public class WSwitcher extends WContainer {
refresh();
}
public WSwitcher setListener(Runnable listener) {
public WSwitcher setListener(ListenerAction<? super WSwitcher> listener) {
this.listener = listener;
return this;
}
@@ -106,6 +112,6 @@ public class WSwitcher extends WContainer {
}
public void notifyLsnr() {
if (listener != null) listener.run();
if (listener != null) listener.invoke(this);
}
}
@@ -16,7 +16,7 @@ import java.util.function.Consumer;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class WTextField implements IWidget {
public Consumer<String> lsnrText;
public ListenerAction<? super WTextField> listener;
protected int xPos, yPos, xSize;
GuiTextField textField;
public static final int HEIGHT = 20;
@@ -50,14 +50,14 @@ public class WTextField implements IWidget {
return textField.getText();
}
public void setText(String s) {
public WTextField setText(String s) {
textField.setText(s);
notifyLsnr();
return this;
}
@SuppressWarnings("UnusedReturnValue")
public WTextField setLsnrText(Consumer<String> lsnrText) {
this.lsnrText = lsnrText;
public WTextField setListener(ListenerAction<? super WTextField> listener) {
this.listener = listener;
return this;
}
@@ -67,6 +67,6 @@ public class WTextField implements IWidget {
}
protected void notifyLsnr() {
if (lsnrText != null) lsnrText.accept(textField.getText());
if (listener != null) listener.invoke(this);
}
}
}
@@ -8,6 +8,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: Towdium
* Date: 18-12-7
@@ -18,7 +20,8 @@ public class WTick extends WContainer {
int xPos, yPos, xSize, ySize;
String name;
boolean disabled;
Consumer<Boolean> lsnr;
ListenerAction<? super WTick> listener;
public WTick(int xPos, int yPos, int xSize, int ySize, @Nullable String name) {
this.xPos = xPos;
@@ -35,11 +38,10 @@ public class WTick extends WContainer {
return this;
}
public WTick setListener(Consumer<Boolean> listener) {
lsnr = listener;
public WTick setListener(ListenerAction<? super WTick> listener) {
this.listener = listener;
return this;
}
public boolean selected() {
return !(button instanceof Normal);
}
@@ -56,9 +58,9 @@ public class WTick extends WContainer {
private class Normal extends WButton {
public Normal(int xPos, int yPos, int xSize, int ySize, @Nullable String name) {
super(xPos, yPos, xSize, ySize, name + ".normal");
lsnrLeft = () -> {
listener = i -> {
setSelected(true);
lsnr.accept(true);
WTick.this.listener.invoke(WTick.this);
};
disabled = WTick.this.disabled;
}
@@ -72,26 +74,26 @@ public class WTick extends WContainer {
private class Selected extends WButton {
public Selected(int xPos, int yPos, int xSize, int ySize, @Nullable String name) {
super(xPos, yPos, xSize, ySize, name + ".selected");
lsnrLeft = () -> {
listener = i -> {
setSelected(false);
lsnr.accept(false);
WTick.this.listener.invoke(WTick.this);
};
disabled = WTick.this.disabled;
}
@Override
protected Resource getDisabled() {
return Resource.WGT_BUTTON_S_D;
return WGT_BUTTON_S_D;
}
@Override
protected Resource getNormal() {
return Resource.WGT_BUTTON_S_N;
return WGT_BUTTON_S_N;
}
@Override
protected Resource getFocused() {
return Resource.WGT_BUTTON_S_F;
return WGT_BUTTON_S_F;
}
@Override
@@ -32,6 +32,7 @@ import java.util.*;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@@ -56,6 +57,18 @@ public class Utilities {
else return form.apply(f / (float) Math.pow(1000, scale), size - 1) + suffix[scale - 1];
}
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public static <T> Stream<T> stream(Optional<T> o) {
return o.map(Stream::of).orElse(Stream.empty());
}
public static <T> Supplier<T> fake(Runnable r) {
return () -> {
r.run();
return null;
};
}
// MOD NAME
@Nullable
@@ -78,6 +91,23 @@ public class Utilities {
return NBTHelper.getOrCreateSubCompound(is, JustEnoughCalculation.Reference.MODID);
}
public static class Relation<K, V> {
public HashMap<Pair<K, K>, V> data = new HashMap<>();
public void put(K a, K b, V v) {
Pair<K, K> pair = new Pair<>(a, b);
V tmp = data.get(pair);
data.put(tmp == null ? new Pair<>(b, a) : pair, v);
}
@Nullable
public V get(K a, K b) {
V ret = data.get(new Pair<>(a, b));
if (ret == null) data.get(new Pair<>(b, a));
return ret;
}
}
public static class Timer {
long time = System.currentTimeMillis();
boolean running = false;