This commit is contained in:
Discreater committed 2021-05-07 01:48:08 +08:00
1 parent cd92230f07
commit de1c2abe7b
52 files changed
+1046 -643

No files matched your search

@@ -2,6 +2,7 @@ package me.towdium.jecalculation.command.commands;
import me.towdium.jecalculation.command.ISubCommand;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.gui.JecaGui;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
@@ -28,6 +29,6 @@ public class CCraft implements ISubCommand {
@Override
public void execute(ICommandSender sender, String[] args) {
Controller.openGuiCraft(true);
JecaGui.openGuiCraft(true);
}
}
@@ -1,15 +1,10 @@
package me.towdium.jecalculation.command.commands;
import me.towdium.jecalculation.command.ISubCommand;
import me.towdium.jecalculation.data.Controller;
import net.minecraft.command.CommandException;
import me.towdium.jecalculation.gui.JecaGui;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;
/**
* Author: Towdium
@@ -29,6 +24,6 @@ public class CMath implements ISubCommand {
@Override
public void execute(ICommandSender sender, String[] args) {
Controller.openGuiMath(true);
JecaGui.openGuiMath(true);
}
}
@@ -6,9 +6,7 @@ import me.towdium.jecalculation.JecaConfig;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.data.label.labels.LPlaceholder;
import me.towdium.jecalculation.data.structure.*;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.guis.GuiCraft;
import me.towdium.jecalculation.gui.guis.GuiMath;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.client.Minecraft;
@@ -29,6 +27,7 @@ import java.util.stream.Stream;
* Author: towdium
* Date: 17-10-15.
*/
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class Controller {
@@ -227,23 +226,4 @@ public class Controller {
nbt.setTag(KEY_MATH, rMathClient.serialize());
Utilities.Json.write(nbt, file);
}
public static void openGuiCraft() {
openGuiCraft(false);
}
public static void openGuiMath() {
openGuiMath(false);
}
public static void openGuiCraft(boolean scheduled) {
JecaGui.displayGui(true, true, scheduled, new GuiCraft());
}
public static void openGuiMath(boolean scheduled) {
JecaGui.displayGui(true, true, scheduled, new GuiMath());
}
}
@@ -232,6 +232,12 @@ public interface ILabel {
class Converter {
static EnumMap<Priority, ArrayList<ConverterFunction>> handlers;
/**
* Suggest: the suggested type is a very reasonable representation
* Fallback: the suggestion is related, like suggest to tag label
* while input does not contain all entries recorded in tag
* Fallback is also used with one input label to guess possible conventions
*/
public enum Priority {SUGGEST, FALLBACK}
static {
@@ -323,6 +329,10 @@ public interface ILabel {
return l == this;
}
@Override
public void drawLabel(JecaGui gui, int xPos, int yPos, boolean center) {
}
private LEmpty() {
}
@@ -401,9 +411,9 @@ public interface ILabel {
return IDENTIFIER;
}
@Override
public void drawLabel(JecaGui gui, int xPos, int yPos, boolean center) {
}
// @Override
// public void drawLabel(JecaGui gui, int xPos, int yPos, boolean center) {
// }
}
abstract class Impl implements ILabel {
@@ -444,6 +454,8 @@ public interface ILabel {
GlStateManager.popMatrix();
}
abstract protected void drawLabel(JecaGui gui);
@Override
public ILabel increaseAmount() {
return setAmount(getAmount() + getMultiplier());
@@ -572,6 +584,8 @@ public interface ILabel {
return l instanceof Impl && percent == ((Impl) l).percent;
}
abstract protected void drawLabel(JecaGui gui);
//abstract protected void drawLabel(JecaGui gui);
}
}
@@ -40,7 +40,7 @@ public class LItemStack extends ILabel.Impl {
NBTTagCompound nbt;
boolean fMeta;
boolean fNbt;
transient ItemStack temp;
transient ItemStack rep;
// Convert from itemStack
public LItemStack(ItemStack is) {
@@ -71,7 +71,7 @@ public class LItemStack extends ILabel.Impl {
nbt = lis.nbt;
fMeta = lis.fMeta;
fNbt = lis.fNbt;
temp = lis.temp;
rep = lis.rep;
}
private void init(@Nullable Item item, int meta, @Nullable NBTTagCompound nbt, boolean fMeta, boolean fNbt) {
@@ -81,8 +81,8 @@ public class LItemStack extends ILabel.Impl {
this.nbt = fNbt ? null : nbt;
this.fMeta = fMeta;
this.fNbt = fNbt;
temp = new ItemStack(item, 1, this.meta);
temp.setTagCompound(this.nbt);
rep = new ItemStack(item, 1, this.meta);
rep.setTagCompound(this.nbt);
}
@@ -150,8 +150,8 @@ public class LItemStack extends ILabel.Impl {
fMeta = f;
if (f)
meta = 0;
temp = new ItemStack(item, 1, meta);
temp.setTagCompound(nbt);
rep = new ItemStack(item, 1, meta);
rep.setTagCompound(nbt);
return this;
}
@@ -159,13 +159,13 @@ public class LItemStack extends ILabel.Impl {
fNbt = f;
if (f)
nbt = null;
temp = new ItemStack(item, 1, meta);
temp.setTagCompound(nbt);
rep = new ItemStack(item, 1, meta);
rep.setTagCompound(nbt);
return this;
}
public ItemStack getRep() {
return temp;
return rep;
}
@Override
@@ -181,13 +181,13 @@ public class LItemStack extends ILabel.Impl {
@Override
public ItemStack getRepresentation() {
return temp;
return rep;
}
@Override
@SideOnly(Side.CLIENT)
public String getDisplayName() {
return temp.getItem() == null ? "" : temp.getDisplayName();
return rep.getItem() == null ? "" : rep.getDisplayName();
}
@Override
@@ -231,7 +231,7 @@ public class LItemStack extends ILabel.Impl {
@Override
@SideOnly(Side.CLIENT)
public void drawLabel(JecaGui gui) {
gui.drawItemStack(0, 0, temp, false);
gui.drawItemStack(0, 0, rep, false);
// TODO some item won't render correctly with overlay
// if (fNbt || fMeta)
// gui.drawResource(Resource.LBL_FRAME, 0, 0);
@@ -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.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.client.Minecraft;
@@ -11,13 +12,13 @@ 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.IO.INPUT;
import static me.towdium.jecalculation.data.structure.Recipe.IO.OUTPUT;
import static me.towdium.jecalculation.utils.Utilities.stream;
// positive => generate; negative => require
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class CostList {
List<ILabel> labels;
@@ -121,17 +122,22 @@ public class CostList {
int count = 0;
while (next != null) {
CostList original = getCurrent();
List<ILabel> outL = Arrays.stream(next.one.getLabel(OUTPUT))
.filter(i -> i != ILabel.EMPTY).collect(Collectors.toList());
List<ILabel> outL = next.one.getLabel(OUTPUT)
.stream()
.filter(i -> i != ILabel.EMPTY)
.collect(Collectors.toList());
CostList outC = new CostList(outL);
outC.multiply(-next.two);
List<ILabel> inL = Arrays.stream(next.one.getLabel(INPUT))
.filter(i -> i != ILabel.EMPTY).collect(Collectors.toList());
List<ILabel> inL = next.one.getLabel(INPUT)
.stream()
.filter(i -> i != ILabel.EMPTY)
.collect(Collectors.toList());
CostList inC = new CostList(inL);
inC.multiply(next.two);
CostList result = original.merge(outC, false, false);
result.merge(inC, false, true);
if (set.contains(result)) next = find(false);
if (set.contains(result))
next = find(false);
else {
set.add(result);
procedure.add(new Pair<>(result, outC));
@@ -139,8 +145,8 @@ public class CostList {
next = find(true);
}
if (count++ > 1000) {
Minecraft
.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation("jecalculation.chat.max_loop"));
Minecraft.getMinecraft().thePlayer.addChatMessage(
new ChatComponentTranslation("jecalculation.chat.max_loop"));
break;
}
}
@@ -155,21 +161,24 @@ public class CostList {
List<ILabel> labels = getCurrent().labels;
for (; index < labels.size(); index++) {
ILabel label = labels.get(index);
if (label.getAmount() >= 0) continue;
if (label.getAmount() >= 0)
continue;
while (iterator.hasNext()) {
Recipe r = iterator.next();
if (r.matches(label).isPresent()) return new Pair<>(r, r.multiplier(label));
if (r.matches(label).isPresent())
return new Pair<>(r, r.multiplier(label));
}
iterator = Controller.recipeIterator();
}
return null;
}
private void addCatalyst(ILabel[] labels) {
Arrays.stream(labels)
private void addCatalyst(List<ILabel> labels) {
labels.stream()
.filter(i -> i != ILabel.EMPTY)
.forEach(i -> catalysts.stream()
.filter(j -> j.matches(i)).findAny()
.filter(j -> j.matches(i))
.findAny()
.map(j -> j.setAmount(Math.max(i.getAmount(), j.getAmount())))
.orElseGet(Utilities.fake(() -> catalysts.add(i))));
}
@@ -183,23 +192,26 @@ public class CostList {
}
public List<ILabel> getInputs() {
return getCurrent().labels.stream().filter(i -> i.getAmount() < 0).map(i -> i.copy().multiply(-1))
return getCurrent().labels.stream()
.filter(i -> i.getAmount() < 0)
.map(i -> i.copy().multiply(-1))
.collect(Collectors.toList());
}
public List<ILabel> getOutputs(List<ILabel> ignore) { // TODO check logic
public List<ILabel> getOutputs(List<ILabel> ignore) {
return getCurrent().labels.stream()
.map(i -> i.copy().multiply(-1))
.map(i -> ignore.stream().flatMap(j -> stream(ILabel.MERGER.merge(i, j))).findFirst().orElse(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());
}
public List<ILabel> getSteps() {
List<ILabel> ret = procedure.stream()
.map(i -> i.two.labels.get(0))
.collect(Collectors.toList());
List<ILabel> ret = procedure.stream().map(i -> i.two.labels.get(0)).collect(Collectors.toList());
Collections.reverse(ret);
CostList cl = new CostList(ret).multiply(-1);
return new CostList().merge(cl, false, true).labels;
@@ -1,64 +1,62 @@
package me.towdium.jecalculation.data.structure;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.polyfill.NBTHelper;
import me.towdium.jecalculation.utils.IllegalPositionException;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Wrapper;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.function.BiFunction;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* Author: towdium
* Date: 17-10-6.
*/
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class Recipe {
public static final String KEY_INPUT = "input";
public static final String KEY_CATALYST = "catalyst";
public static final String KEY_OUTPUT = "output";
static final ILabel[] EMPTY_ARRAY = new ILabel[0];
ILabel[] input;
ILabel[] catalyst;
ILabel[] output;
List<ILabel> input;
List<ILabel> catalyst;
List<ILabel> output;
public Recipe(NBTTagCompound nbt) {
this(readNbtList(nbt.getTagList(KEY_INPUT, 10)),
readNbtList(nbt.getTagList(KEY_CATALYST, 10)),
this(readNbtList(nbt.getTagList(KEY_INPUT, 10)), readNbtList(nbt.getTagList(KEY_CATALYST, 10)),
readNbtList(nbt.getTagList(KEY_OUTPUT, 10)));
}
public Recipe(List<ILabel> input, List<ILabel> catalyst, List<ILabel> output) {
this(input.toArray(EMPTY_ARRAY), catalyst.toArray(EMPTY_ARRAY), output.toArray(EMPTY_ARRAY));
}
public Recipe(ILabel[] input, ILabel[] catalyst, ILabel[] output) {
BiFunction<ILabel[], Integer, ILabel[]> convert = (ls, i) -> {
ILabel[] ret = new ILabel[i];
if (ls.length > i) throw new RuntimeException("Too many labels");
System.arraycopy(ls, 0, ret, 0, ls.length);
for (int j = ls.length; j < i; j++) ret[j] = ILabel.EMPTY;
return ret;
Consumer<List<ILabel>> check = ls -> {
boolean ret = false;
for (ILabel i : ls) {
Objects.requireNonNull(i);
if (i != ILabel.EMPTY)
ret = true;
}
if (!ret || ls.get(ls.size() - 1) == ILabel.EMPTY)
throw new IllegalArgumentException("Invalid recipe");
};
this.input = convert.apply(input, 14);
this.catalyst = convert.apply(catalyst, 7);
this.output = convert.apply(output, 7);
Stream.of(input, output).forEach(i -> Arrays.stream(i).filter(j -> j != ILabel.EMPTY).findAny()
.orElseThrow(() -> new IllegalArgumentException("Invalid recipe")));
check.accept(input);
check.accept(catalyst);
check.accept(output);
this.input = input;
this.catalyst = catalyst;
this.output = output;
}
static private List<ILabel> readNbtList(NBTTagList list) {
return StreamSupport.stream(NBTHelper.spliterator(list), false)
.filter(n -> n instanceof NBTTagCompound)
@@ -68,29 +66,37 @@ public class Recipe {
@Override
public int hashCode() {
Wrapper<Integer> hash = new Wrapper<>(0);
Consumer<ILabel[]> hasher = (ls) -> Arrays.stream(ls)
.filter(Objects::nonNull).forEach(i -> hash.value ^= i.hashCode());
int[] hash = new int[1];
Consumer<List<ILabel>> hasher = (ls) -> ls.stream()
.filter(Objects::nonNull)
.forEach(i -> hash[0] ^= i.hashCode());
hasher.accept(input);
hasher.accept(catalyst);
hasher.accept(output);
return hash.value;
return hash[0];
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Recipe)) return false;
if (!(obj instanceof Recipe))
return false;
Recipe r = (Recipe) obj;
BiPredicate<ILabel[], ILabel[]> p = (i, j) -> {
if (i.length != j.length) return false;
for (int k = 0; k < i.length; k++)
if (!i[k].equals(j[k])) return false;
BiPredicate<List<ILabel>, List<ILabel>> p = (i, j) -> {
if (i.size() != j.size())
return false;
for (int k = 0; k < i.size(); k++)
if (!i.get(k).equals(j.get(k)))
return false;
return true;
};
return p.test(input, r.input) && p.test(catalyst, r.catalyst) && p.test(output, r.output);
}
public ILabel[] getLabel(IO type) {
public List<ILabel> getLabel(IO type) {
return get(type, input, output, catalyst);
}
public static <T> T get(IO type, T input, T output, T catalyst) {
switch (type) {
case INPUT:
return input;
@@ -99,31 +105,31 @@ public class Recipe {
case CATALYST:
return catalyst;
default:
throw new IllegalPositionException();
throw new RuntimeException("Internal error");
}
}
public ILabel getRep() {
for (int i = 0; i < 8; i++)
if (output[i] != ILabel.EMPTY) return output[i];
if (output.get(i) != ILabel.EMPTY)
return output.get(i);
return ILabel.EMPTY;
}
public NBTTagCompound serialize() {
NBTTagCompound ret = new NBTTagCompound();
Function<ILabel[], NBTTagList> convert = (ls) -> {
Function<List<ILabel>, NBTTagList> convert = (ls) -> {
ArrayList<ILabel> labels = new ArrayList<>();
boolean start = false;
for (int i = ls.length - 1; i >= 0; i--) {
if (start || ls[i] != ILabel.EMPTY) {
labels.add(ls[i]);
for (int i = ls.size() - 1; i >= 0; i--) {
if (start || ls.get(i) != ILabel.EMPTY) {
labels.add(ls.get(i));
start = true;
}
}
NBTTagList r = new NBTTagList();
new Utilities.ReversedIterator<>(labels).stream()
.forEach(l -> r.appendTag(ILabel.SERIALIZER.serialize(l)));
new Utilities.ReversedIterator<>(labels).stream().forEach(l -> r.appendTag(ILabel.SERIALIZER.serialize(l)));
return r;
};
ret.setTag(KEY_INPUT, convert.apply(input));
@@ -133,18 +139,19 @@ public class Recipe {
}
public Optional<ILabel> matches(ILabel label) {
return Arrays.stream(output).filter(i -> ILabel.MERGER.merge(label, i).isPresent()).findAny();
return output.stream().filter(i -> ILabel.MERGER.merge(label, i).isPresent()).findAny();
}
public long multiplier(ILabel label) {
return Arrays.stream(output).filter(i -> ILabel.MERGER.merge(label, i).isPresent()).findAny()
.map(i -> {
long amountA = label.getAmount();
if (!label.isPercent()) amountA = Math.multiplyExact(amountA, 100L);
long amountB = i.getAmount();
if (!i.isPercent()) amountB = Math.multiplyExact(amountB, 100L);
return (amountB + Math.abs(amountA) - 1) / amountB;
}).orElse(0L);
return output.stream().filter(i -> ILabel.MERGER.merge(label, i).isPresent()).findAny().map(i -> {
long amountA = label.getAmount();
if (!label.isPercent())
amountA = Math.multiplyExact(amountA, 100L);
long amountB = i.getAmount();
if (!i.isPercent())
amountB = Math.multiplyExact(amountB, 100L);
return (amountB + Math.abs(amountA) - 1) / amountB;
}).orElse(0L);
}
public enum IO {
@@ -2,11 +2,11 @@ package me.towdium.jecalculation.data.structure;
import me.towdium.jecalculation.JecaConfig;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.polyfill.NBTHelper;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
import me.towdium.jecalculation.utils.wrappers.Pair;
import me.towdium.jecalculation.utils.wrappers.Trio;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -16,10 +16,15 @@ import java.io.File;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* Author: towdium
* Date: 18-8-28.
*/
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class Recipes {
HashMap<String, List<Recipe>> records = new HashMap<>();
@@ -27,7 +32,8 @@ public class Recipes {
public Recipes() {
File file = JecaConfig.defaultFile;
NBTTagCompound nbt = Utilities.Json.read(file);
if (nbt == null) JustEnoughCalculation.logger.info("Failed to load default records at " + file + ".");
if (nbt == null)
JustEnoughCalculation.logger.info("Failed to load default records at " + file + ".");
else {
JustEnoughCalculation.logger.info("Loading default records at " + file + ".");
deserialize(nbt);
@@ -39,11 +45,12 @@ public class Recipes {
}
protected void deserialize(NBTTagCompound nbt) {
//noinspection unchecked
Set<String> keySet = (Set<String>) nbt.func_150296_c();
keySet.stream().sorted().forEach(i -> {
NBTTagList group = nbt.getTagList(i, 10);
StreamSupport.stream(NBTHelper.spliterator(group), false)
.filter(r -> r instanceof NBTTagCompound)
.filter(r -> r instanceof NBTTagCompound)
.forEach(r -> {
try {
add(i, new Recipe((NBTTagCompound) r));
@@ -66,13 +73,19 @@ public class Recipes {
public void modify(String neu, @Nullable String old, int index, @Nullable Recipe recipe) {
if (index == -1) {
if (recipe != null) add(neu, recipe);
else if (old != null) renameGroup(old, neu);
else remove(neu);
if (recipe != null)
add(neu, recipe);
else if (old != null)
renameGroup(old, neu);
else
remove(neu);
} else {
if (recipe == null) remove(neu, index);
else if (old == null || old.equals(neu)) set(neu, index, recipe);
else set(neu, old, index, recipe);
if (recipe == null)
remove(neu, index);
else if (old == null || old.equals(neu))
set(neu, index, recipe);
else
set(neu, old, index, recipe);
}
}
@@ -96,7 +109,8 @@ public class Recipes {
public void remove(String group, int index) {
List<Recipe> l = records.get(group);
l.remove(index);
if (l.isEmpty()) records.remove(group);
if (l.isEmpty())
records.remove(group);
}
public void remove(String group) {
@@ -176,8 +190,9 @@ public class Recipes {
group = i.next();
List<Recipe> rs = records.get(group);
index = rs.size();
j = new Utilities.ReversedIterator<>(rs);
} else return false;
j = new ReversedIterator<>(rs);
} else
return false;
}
return true;
}
@@ -20,16 +20,15 @@ public class RecordCraft implements IRecord {
public static final String KEY_AMOUNT = "amount";
public static final String KEY_INVENTORY = "inventory";
Utilities.Recent<ILabel> record = new Utilities.Recent<>((a, b) ->
a == ILabel.EMPTY || a.equals(b), 9);
Utilities.Recent<ILabel> record = new Utilities.Recent<>((a, b) -> a == ILabel.EMPTY || a.equals(b), 9);
public String amount;
public boolean inventory;
public RecordCraft(NBTTagCompound nbt) {
List<ILabel> ls = StreamSupport.stream(NBTHelper.spliterator(nbt.getTagList(KEY_RECENTS, 10)), false)
.filter(n -> n instanceof NBTTagCompound)
.map(n -> ILabel.SERIALIZER.deserialize((NBTTagCompound) n))
.collect(Collectors.toList());
.filter(n -> n instanceof NBTTagCompound)
.map(n -> ILabel.SERIALIZER.deserialize((NBTTagCompound) n))
.collect(Collectors.toList());
new Utilities.ReversedIterator<>(ls).forEachRemaining(l -> record.push(l, false));
amount = nbt.getString(KEY_AMOUNT);
inventory = nbt.getBoolean(KEY_INVENTORY);
@@ -1,6 +1,5 @@
package me.towdium.jecalculation.data.structure;
import me.towdium.jecalculation.utils.IllegalPositionException;
import net.minecraft.nbt.NBTTagCompound;
import java.math.BigDecimal;
@@ -33,25 +32,37 @@ public class RecordMath implements IRecord {
public BigDecimal operate(BigDecimal a, BigDecimal b) {
switch (this) {
case PLUS: return a.add(b);
case MINUS: return a.subtract(b);
case TIMES: return a.multiply(b);
case DIVIDE: return a.divide(b, context);
case EQUALS: return b;
default: throw new IllegalPositionException();
case PLUS:
return a.add(b);
case MINUS:
return a.subtract(b);
case TIMES:
return a.multiply(b);
case DIVIDE:
return a.divide(b, context);
case EQUALS:
return b;
default:
throw new RuntimeException("Internal Error");
}
}
}
public RecordMath(State state, Operator operator, BigDecimal last,
boolean sign, int dot, List<BigDecimal> numbers) {
public RecordMath(State state,
Operator operator,
BigDecimal last,
boolean sign,
int dot,
List<BigDecimal> numbers) {
this.state = state;
this.operator = operator;
this.last = last;
StringBuilder sb = new StringBuilder();
if (!sign) sb.append('-');
if (!sign)
sb.append('-');
numbers.forEach(i -> sb.append(i.toString()));
if (dot != DOT_NONE) sb.insert(sb.length() - dot, '.');
if (dot != DOT_NONE)
sb.insert(sb.length() - dot, '.');
current = sb.toString();
}
@@ -78,16 +89,19 @@ public class RecordMath implements IRecord {
public LinkedList<BigDecimal> getNumbers() {
LinkedList<BigDecimal> ret = new LinkedList<>();
if (current == null) return ret;
if (current == null)
return ret;
for (int i = 0; i < current.length(); i++) {
char ch = current.charAt(i);
if (ch != '-' && ch != '.') ret.add(new BigDecimal(ch - '0'));
if (ch != '-' && ch != '.')
ret.add(new BigDecimal(ch - '0'));
}
return ret;
}
public int getDot() {
if (current == null) return DOT_NONE;
if (current == null)
return DOT_NONE;
int index = current.indexOf('.');
return index == -1 ? DOT_NONE : current.length() - index - 1;
}
@@ -11,7 +11,7 @@ public class RecordPlayer implements IRecord {
public static final String KEY_LAST = "last";
public Recipes recipes;
public String last;
public String last; // last group edited
public RecordPlayer() {
recipes = new Recipes();
@@ -25,7 +25,8 @@ public class RecordPlayer implements IRecord {
@Override
public NBTTagCompound serialize() {
NBTTagCompound ret = new NBTTagCompound();
if (last != null) ret.setString(KEY_LAST, last);
if (last != null)
ret.setString(KEY_LAST, last);
ret.setTag(KEY_RECIPES, recipes.serialize());
return ret;
}
@@ -32,7 +32,7 @@ public class NEIEventHandler implements IContainerInputHandler {
@Override
public void onMouseUp(GuiContainer guiContainer, int i, int i1, int i2) {
JecaGui.onMouseReleased();
}
@Override
@@ -3,12 +3,12 @@ package me.towdium.jecalculation.gui;
import cpw.mods.fml.client.config.GuiUtils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.label.labels.LItemStack;
import me.towdium.jecalculation.gui.guis.GuiCraft;
import me.towdium.jecalculation.gui.guis.GuiMath;
import me.towdium.jecalculation.gui.guis.IGui;
import me.towdium.jecalculation.gui.widgets.WLabel;
import me.towdium.jecalculation.nei.NEIPlugin;
import me.towdium.jecalculation.network.ClientHandler;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.utils.ItemStackHelper;
import me.towdium.jecalculation.utils.Utilities;
@@ -19,6 +19,7 @@ import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
@@ -37,6 +38,8 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static org.lwjgl.input.Keyboard.KEY_NONE;
/**
* Author: towdium
* Date: 8/12/17.
@@ -44,6 +47,11 @@ import java.util.Optional;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class JecaGui extends GuiContainer {
public static final KeyBinding keyOpenGuiCraft = new KeyBinding("jecalculation.key.gui_craft", KEY_NONE,
"jecalculation.key.category");
public static final KeyBinding keyOpenGuiMath = new KeyBinding("jecalculation.key.gui_math", KEY_NONE,
"jecalculation.key.category");
public static final int COLOR_GUI_GREY = 0xFFA1A1A1;
public static final int COLOR_TEXT_RED = 0xFF0000;
public static final int COLOR_TEXT_GREY = 0x404040;
@@ -64,8 +72,8 @@ public class JecaGui extends GuiContainer {
super(acceptsTransfer ? new ContainerTransfer() : new ContainerNonTransfer());
this.parent = parent;
this.root = root;
if (inventorySlots instanceof JecContainer)
((JecContainer) inventorySlots).setGui(this);
if (inventorySlots instanceof JecaContainer)
((JecaContainer) inventorySlots).setGui(this);
}
public static int getMouseX() {
@@ -87,15 +95,15 @@ public class JecaGui extends GuiContainer {
if (!optionalJecaGui.isPresent())
return false;
JecaGui gui = optionalJecaGui.get();
int mouseX = getMouseX();
int mouseY = getMouseY();
int xMouse = getMouseX();
int yMouse = getMouseY();
int button = Mouse.getEventButton();
if (button == -1) {
int diff = Mouse.getEventDWheel() / 120;
if (diff != 0)
gui.root.onMouseScroll(gui, mouseX, mouseY, diff);
gui.root.onMouseScroll(gui, xMouse, yMouse, diff);
} else if (Mouse.getEventButtonState()) {
if (gui.root.onMouseClicked(gui, mouseX, mouseY, button)) {
if (gui.root.onMouseClicked(gui, xMouse, yMouse, button)) {
return true;
} else if (gui.hand != ILabel.EMPTY) {
gui.hand = button == 0 ? NEIPlugin.getLabelUnderMouse() : ILabel.EMPTY;
@@ -110,6 +118,19 @@ public class JecaGui extends GuiContainer {
}
return false;
}
public static void onMouseReleased() {
Optional<JecaGui> optionalJecaGui = currentJecaGui();
if (!optionalJecaGui.isPresent())
return;
JecaGui gui = optionalJecaGui.get();
int xMouse = getMouseX();
int yMouse = getMouseY();
int button = Mouse.getEventButton();
gui.root.onMouseReleased(gui, xMouse, yMouse, button);
}
@Nullable
@@ -117,16 +138,11 @@ public class JecaGui extends GuiContainer {
IInventory i = new InventoryBasic("", false, 1);
Slot s = new Slot(i, 0, 0, 0);
ILabel l = getLabelUnderMouse();
if (l instanceof LItemStack)
s.putStack(((LItemStack) l).getRep());
Object rep = l == null ? null : l.getRepresentation();
if (rep instanceof ItemStack) s.putStack((ItemStack) rep);
return s;
}
@Override
public void initGui() {
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;
}
public static boolean mouseIn(int xPos, int yPos, int xSize, int ySize, int xMouse, int yMouse) {
return xMouse > xPos && yMouse > yPos && xMouse <= xPos + xSize && yMouse <= yPos + ySize;
@@ -148,7 +164,7 @@ public class JecaGui extends GuiContainer {
};
if (scheduled) {
JecaGui.scheduled = r;
JecaGui.timeout = 2;
JecaGui.timeout = 1;
} else
r.run();
}
@@ -191,28 +207,26 @@ public class JecaGui extends GuiContainer {
}
public static void displayParent() {
// isCallingFromMinecraftThread
if (Minecraft.getMinecraft().func_152345_ab()) {
JecaGui gui = getCurrent().parent;
gui.root.onVisible(gui);
last = gui;
Minecraft.getMinecraft().displayGuiScreen(gui);
}
JecaGui gui = getCurrent().parent;
gui.root.onVisible(gui);
last = gui;
Minecraft.getMinecraft().displayGuiScreen(gui);
}
@Nullable
public ILabel getLabelUnderMouse() {
return root.getLabelUnderMouse(getMouseX(), getMouseY());
WLabel w = root.getLabelUnderMouse(getMouseX(), getMouseY());
return w == null ? null : w.getLabel();
}
/**
* called by {@link me.towdium.jecalculation.event.handlers.FMLBusEventHandler}
*/
public static void onKey() {
if (ClientHandler.keyOpenGuiCraft.isPressed())
Controller.openGuiCraft();
if (ClientHandler.keyOpenGuiMath.isPressed())
Controller.openGuiMath();
if (keyOpenGuiCraft.isPressed())
JecaGui.openGuiCraft(false);
if (keyOpenGuiMath.isPressed())
JecaGui.openGuiMath(false);
}
public static void onGameTick() {
@@ -226,8 +240,14 @@ public class JecaGui extends GuiContainer {
}
}
public static boolean isShiftDown() {
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
@SideOnly(Side.CLIENT)
public static void openGuiCraft(boolean scheduled) {
JecaGui.displayGui(true, true, scheduled, new GuiCraft());
}
@SideOnly(Side.CLIENT)
public static void openGuiMath(boolean scheduled) {
JecaGui.displayGui(true, true, scheduled, new GuiMath());
}
@Override
@@ -243,19 +263,21 @@ public class JecaGui extends GuiContainer {
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
mouseX -= guiLeft;
mouseY -= guiTop;
GlStateManager.pushMatrix();
GlStateManager.translate(guiLeft, guiTop, 0);
GlStateManager.disableLighting();
GlStateManager.disableDepth();
root.onDraw(this, mouseX - guiLeft, mouseY - guiTop);
root.onDraw(this, mouseX, mouseY);
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
GlStateManager.translate(0, 0, 80);
hand.drawLabel(this, mouseX, mouseY, true);
hand.drawLabel(this, mouseX + guiLeft, mouseY + guiTop, true);
GlStateManager.popMatrix();
List<String> tooltip = new ArrayList<>();
root.onTooltip(this, mouseX - guiLeft, mouseY - guiTop, tooltip);
drawHoveringText(tooltip, mouseX, mouseY);
root.onTooltip(this, mouseX, mouseY, tooltip);
drawHoveringText(tooltip, mouseX + guiLeft, mouseY + guiTop);
GlStateManager.enableLighting();
GlStateManager.enableDepth();
}
@@ -332,7 +354,7 @@ public class JecaGui extends GuiContainer {
int borderRight) {
GuiUtils.drawContinuousTexturedBox(r.getResourceLocation(), xPos, yPos, r.getXPos(), r.getYPos(), xSize, ySize,
r.getXSize(), r.getYSize(), borderTop, borderBottom, borderLeft, borderRight,
zLevel);
0);
}
private void setColor(int color) {
@@ -378,10 +400,6 @@ public class JecaGui extends GuiContainer {
return fontRendererObj.getStringWidth(s);
}
public void drawSplitText(float xPos, float yPos, Font f, String s) {
drawSplitText(xPos, yPos, Integer.MAX_VALUE, f, s);
}
public void drawSplitText(float xPos, float yPos, int width, Font f, String s) {
drawSplitText(xPos, yPos, f, Utilities.I18n.wrap(s, width));
}
@@ -390,7 +408,10 @@ public class JecaGui extends GuiContainer {
drawText(xPos, yPos, f, () -> {
int y = 0;
for (String i : ss) {
fontRendererObj.drawString(i, 0, y, f.color, f.shadow);
if (f.shadow)
fontRendererObj.drawStringWithShadow(i, 0, y, f.color);
else
fontRendererObj.drawString(i, 0, y, f.color);
y += fontRendererObj.FONT_HEIGHT + 1;
}
});
@@ -407,7 +428,9 @@ public class JecaGui extends GuiContainer {
int ellipsisWidth = f.getTextWidth("...");
if (strWidth > width && strWidth > ellipsisWidth)
str = f.trimToWidth(str, width - ellipsisWidth).trim() + "...";
fontRendererObj.drawString(str, 0, 0, f.color, f.shadow);
if (f.shadow)
fontRendererObj.drawStringWithShadow(str, 0, 0, f.color);
fontRendererObj.drawString(str, 0, 0, f.color);
});
}
@@ -445,15 +468,11 @@ public class JecaGui extends GuiContainer {
itemRender.zLevel = zLevel - 100F;
}
// @Override
// protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
// JustEnoughCalculation.logger.info("mouse clicked");
// super.mouseClicked(mouseX, mouseY, mouseButton);
// boolean inGui = root.onClicked(this, mouseX - guiLeft, mouseY - guiTop, mouseButton);
// if (!inGui) {
// this.handleMouseEvent();
// }
// }
@Override
public void initGui() {
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;
}
@Override
protected void keyTyped(char typedChar, int keyCode) {
@@ -465,9 +484,9 @@ public class JecaGui extends GuiContainer {
else
super.keyTyped(typedChar, keyCode);
}
}
@SideOnly(Side.CLIENT)
public static class Font {
public static final Font SHADOW = new Font(JecaGui.COLOR_TEXT_WHITE, true, false, false);
public static final Font PLAIN = new Font(JecaGui.COLOR_TEXT_GREY, false, false, false);
@@ -504,7 +523,8 @@ public class JecaGui extends GuiContainer {
}
public static class JecContainer extends Container {
@SideOnly(Side.CLIENT)
public static class JecaContainer extends Container {
JecaGui gui;
public JecaGui getGui() {
@@ -521,10 +541,12 @@ public class JecaGui extends GuiContainer {
}
}
public static class ContainerTransfer extends JecContainer {
@SideOnly(Side.CLIENT)
public static class ContainerTransfer extends JecaContainer {
}
public static class ContainerNonTransfer extends JecContainer {
@SideOnly(Side.CLIENT)
public static class ContainerNonTransfer extends JecaContainer {
}
public void drawHoveringText(List<String> textLines, int x, int y) {
@@ -5,16 +5,19 @@ import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.structure.CostList;
import me.towdium.jecalculation.data.structure.CostList.Calculator;
import me.towdium.jecalculation.data.structure.RecordCraft;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.gui.widgets.*;
import me.towdium.jecalculation.nei.NEIPlugin;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.ItemStackHelper;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
@@ -27,24 +30,28 @@ import java.util.stream.Stream;
* Date: 8/14/17.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class GuiCraft extends WContainer implements IGui {
public class GuiCraft extends WContainer implements IGui {
Mode mode = Mode.INPUT;
CostList.Calculator calculator = null;
RecordCraft record = Controller.getRCraft();
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, "craft.step")
.setListener(i -> setMode(Mode.STEPS));
WButton catalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "common.catalyst")
.setListener(i -> setMode(Mode.CATALYST));
WButton output = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT, "common.output")
.setListener(i -> setMode(Mode.OUTPUT));
WButton input = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN, "common.input")
.setListener(i -> setMode(Mode.INPUT));
WLabel label = new WLabel(31, 7, 20, 20, WLabel.Mode.SELECTOR).setListener((i, v) -> refreshLabel(v, false, true));
ItemStack itemStack;
Calculator calculator = null;
RecordCraft record;
WLabelGroup recent = new WLabelGroup(7, 31, 8, 1, false, false).setLsnrClick(
(i, v) -> JecaGui.getCurrent().hand = i.get(v).getLabel());
WLabelScroll result = new WLabelScroll(7, 87, 8, 4, true, false, false, true).setListener((i, v) -> {
Object rep = i.get(v).getLabel().getRepresentation();
NEIPlugin.openRecipeGui(rep, Mouse.getEventButton());
}).setFormatter(i -> i.getAmountString(true));
WButton steps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST, "craft.step").setListener(
i -> setMode(Mode.STEPS));
WButton catalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "common.catalyst").setListener(
i -> setMode(Mode.CATALYST));
WButton output = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT, "craft.output").setListener(
i -> setMode(Mode.OUTPUT));
WButton input = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN, "common.input").setListener(
i -> setMode(Mode.INPUT));
WLabel label = new WLabel(31, 7, 20, 20, false, true).setLsnrUpdate((i, v) -> refreshLabel(v, false, true));
WButton invE = new WButtonIcon(149, 62, 20, 20, Resource.BTN_INV_E, "craft.inventory_enabled");
WButton invD = new WButtonIcon(149, 62, 20, 20, Resource.BTN_INV_D, "craft.inventory_disabled");
WTextField amount = new WTextField(60, 7, 65).setText(record.amount).setListener(i -> {
@@ -57,15 +64,15 @@ public class GuiCraft extends WContainer implements IGui {
public GuiCraft() {
add(new WHelp("craft"));
add(new WPanel());
add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL, "craft.label")
.setListener(i -> JecaGui.displayGui(new GuiLabel(l -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
}))));
add(new WButtonIcon(130, 7, 20, 20, Resource.BTN_NEW, "craft.recipe")
.setListener(i -> JecaGui.displayGui(true, true, new GuiRecipe())));
add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH, "craft.search")
.setListener(i -> JecaGui.displayGui(new GuiSearch())));
add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL, "craft.label").setListener(
i -> JecaGui.displayGui(new GuiLabel(l -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
}))));
add(new WButtonIcon(130, 7, 20, 20, Resource.BTN_NEW, "craft.recipe").setListener(
i -> JecaGui.displayGui(true, true, new GuiRecipe())));
add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH, "craft.search").setListener(
i -> JecaGui.displayGui(new GuiSearch())));
add(new WText(53, 13, JecaGui.Font.RAW, "x"));
add(new WLine(55));
add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT, "craft.history"));
@@ -125,11 +132,11 @@ public class GuiCraft extends WContainer implements IGui {
List<ILabel> getInventory() {
InventoryPlayer inv = Minecraft.getMinecraft().thePlayer.inventory;
ArrayList<ILabel> labels = new ArrayList<>();
Consumer<Stream<ItemStack>> add = i -> i
.filter(j -> !ItemStackHelper.isEmpty(j))
.forEach(j -> labels.add(ILabel.Converter.from(j)));
add.accept(Arrays.stream(inv.armorInventory));
add.accept(Arrays.stream(inv.mainInventory));
Consumer<ItemStack[]> add = i -> Arrays.stream(i)
.filter(j -> !ItemStackHelper.isEmpty(j))
.forEach(j -> labels.add(ILabel.Converter.from(j)));
add.accept(inv.armorInventory);
add.accept(inv.mainInventory);
return labels;
}
@@ -161,22 +168,25 @@ public class GuiCraft extends WContainer implements IGui {
refreshRecent();
refreshCalculator();
if (suggest && findRecipe(l).isEmpty()) {
Pair<List<ILabel>, List<ILabel>> guess = ILabel.CONVERTER.guess(Collections.singletonList(l));
Pair<List<ILabel>, List<ILabel>> guess = ILabel.CONVERTER.guess(Collections.singletonList(l), null);
LinkedHashSet<ILabel> match = new LinkedHashSet<>();
List<ILabel> fuzzy = new ArrayList<>();
Stream.of(guess.one, guess.two).flatMap(Collection::stream).forEach(i -> {
List<ILabel> list = findRecipe(i);
list.forEach(j -> match.add(j.setPercent(false).setAmount(1)));
if (!list.isEmpty()) fuzzy.add(i);
if (!list.isEmpty())
fuzzy.add(i);
});
match.addAll(fuzzy);
List<ILabel> list = new ArrayList<>(match);
if (!match.isEmpty()) add(new Suggest(list.size() > 3 ? list.subList(0, 3) : list, !dup));
if (!match.isEmpty())
add(new Suggest(list.size() > 3 ? list.subList(0, 3) : list, !dup));
}
}
private static List<ILabel> findRecipe(ILabel l) {
return Controller.recipeIterator().stream()
return Controller.recipeIterator()
.stream()
.map(i -> i.matches(l))
.filter(Optional::isPresent)
.map(Optional::get)
@@ -186,20 +196,20 @@ public class GuiCraft extends WContainer implements IGui {
enum Mode {
INPUT, OUTPUT, CATALYST, STEPS
}
class Suggest extends WOverlay {
boolean replace;
public Suggest(List<ILabel> labels, boolean replace) {
this.replace = replace;
int width = labels.size() * 20;
add(new WPanel(0 - width, 2, 56 + width, 30));
add(new WLabel(31, 7, 20, 20, WLabel.Mode.PICKER).setLabel(label.getLabel())
.setListener((i, v) -> refresh(v)));
add(new WPanel(-width, 2, 56 + width, 30));
add(new WLabel(31, 7, 20, 20, false, false).setLabel(label.getLabel()).setLsnrUpdate((i, v) -> refresh(v)));
add(new WIcon(5 - width, 7, 18, 20, Resource.ICN_HELP, "craft.suggest"));
add(new WLine(26, 7, 20, false));
for (int i = 0; i < labels.size(); i++) {
add(new WLabel(3 - i * 20, 7, 20, 20, WLabel.Mode.PICKER).setLabel(labels.get(i))
.setListener((j, v) -> refresh(v)));
add(new WLabel(3 - i * 20, 7, 20, 20, false, false).setLabel(labels.get(i))
.setLsnrUpdate((j, v) -> refresh(v)));
}
}
@@ -20,26 +20,26 @@ import static me.towdium.jecalculation.gui.Resource.*;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class GuiDisamb extends IPicker.Impl implements IGui {
protected WLabelScroll up = new WLabelScroll(25, 48, 7, 3, WLabel.Mode.PICKER, true);
protected WLabelScroll down = new WLabelScroll(25, 105, 7, 3, WLabel.Mode.PICKER, true);
protected List<List<ILabel>> record;
public GuiDisamb(List<List<ILabel>> record) {
this.record = record;
WSwitcher switcher = new WSwitcher(7, 7, 162, this.record.size()).setListener(i -> setPage(i.getIndex()));
ListenerValue<WLabelScroll, Integer> consumer = (i, v) -> callback.accept(i.get(v).copy().multiply(-1));
add(new WPanel());
add(new WIcon(7, 24, 20, 20, ICN_TEXT, "common.search"));
add(new WIcon(7, 48, 18, 54, ICN_LIST, "disamb.list"));
add(new WIcon(7, 105, 18, 54, ICN_LABEL, "disamb.label"));
add(new WSearch(25, 24, 90, up.setListener(consumer), down.setListener(consumer)));
add(switcher, up, down);
setPage(0);
}
protected void setPage(int n) {
up.setLabels(record.get(n));
down.setLabels(ILabel.CONVERTER.guess(record.get(n)).one);
}
// protected WLabelScroll up = new WLabelScroll(25, 48, 7, 3, WLabel.Mode.PICKER, true);
// protected WLabelScroll down = new WLabelScroll(25, 105, 7, 3, WLabel.Mode.PICKER, true);
// protected List<List<ILabel>> record;
//
// public GuiDisamb(List<List<ILabel>> record) {
// this.record = record;
// WSwitcher switcher = new WSwitcher(7, 7, 162, this.record.size()).setListener(i -> setPage(i.getIndex()));
// ListenerValue<WLabelScroll, Integer> consumer = (i, v) -> callback.accept(i.get(v).copy().multiply(-1));
// add(new WPanel());
// add(new WIcon(7, 24, 20, 20, ICN_TEXT, "common.search"));
// add(new WIcon(7, 48, 18, 54, ICN_LIST, "disamb.list"));
// add(new WIcon(7, 105, 18, 54, ICN_LABEL, "disamb.label"));
// add(new WSearch(25, 24, 90, up.setListener(consumer), down.setListener(consumer)));
// add(switcher, up, down);
// setPage(0);
// }
//
//
// protected void setPage(int n) {
// up.setLabels(record.get(n));
// down.setLabels(ILabel.CONVERTER.guess(record.get(n)).one);
// }
}
@@ -3,9 +3,9 @@ package me.towdium.jecalculation.gui.guis;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.structure.Recipes;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.gui.widgets.*;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.I18n;
import me.towdium.jecalculation.utils.wrappers.Pair;
import me.towdium.jecalculation.utils.wrappers.Quad;
@@ -15,24 +15,24 @@ import java.util.List;
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
*/
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class GuiImport extends WContainer implements IGui, ISearchable {
List<Quad<Boolean, String, String, Recipes>> data; // selected, file, group, recipes
List<Quad<Boolean, String, String, Recipes>> filtered;
WSearch search = new WSearch(26, 25, 90, this);
WSwitcher page;
WButton confirm = new WButtonIcon(149, 25, 20, 20, BTN_YES, "import.confirm").setDisabled(true)
.setListener(i -> {
data.stream().filter(j -> j.one).forEach(j -> Controller.inport(j.four, j.three));
JecaGui.displayParent();
});
WButton confirm = new WButtonIcon(149, 25, 20, 20, BTN_YES, "import.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() {
@@ -40,11 +40,10 @@ public class GuiImport extends WContainer implements IGui, ISearchable {
add(new WIcon(7, 25, 20, 20, ICN_TEXT, "common.search"));
add(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.selected();
confirm.setDisabled(data.stream().noneMatch(k -> k.one));
});
WTick tick = new WTick(7, 49 + 16 * i, 13, 13, "import.tick").setDisabled(true).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, "");
add(tick, text);
content.add(new Pair<>(tick, text));
@@ -53,7 +52,8 @@ public class GuiImport extends WContainer implements IGui, ISearchable {
@Override
public void onVisible(JecaGui gui) {
data = Controller.discover().stream()
data = Controller.discover()
.stream()
.flatMap(i -> i.two.stream().map(j -> new Quad<>(false, i.one, j.one, i.two)))
.collect(Collectors.toList());
search.refresh();
@@ -76,10 +76,12 @@ public class GuiImport extends WContainer implements IGui, ISearchable {
@Override
public boolean setFilter(String s) {
if (s.isEmpty()) filtered = new ArrayList<>(data);
else filtered = data.stream()
.filter(i -> Utilities.I18n.contains(i.two, s) || Utilities.I18n.contains(i.three, s))
.collect(Collectors.toList());
if (s.isEmpty())
filtered = new ArrayList<>(data);
else
filtered = data.stream()
.filter(i -> I18n.contains(i.two, s) || I18n.contains(i.three, s))
.collect(Collectors.toList());
remove(page);
page = new WSwitcher(7, 7, 162, (filtered.size() + 6) / 7).setListener(i -> refresh());
add(page);
@@ -103,7 +105,8 @@ public class GuiImport extends WContainer implements IGui, ISearchable {
if (JecaGui.mouseIn(22, yPos - 2, gui.getStringWidth(key) + 6, 13, xMouse, yMouse)) {
gui.drawRectangle(22, yPos - 2, gui.getStringWidth(key) + 6, 13, JecaGui.COLOR_GUI_GREY);
gui.drawText(25, yPos, JecaGui.Font.SHADOW, key);
} else expand = false;
} else
expand = false;
} else if (JecaGui.mouseIn(22, yPos - 2, 146, 13, xMouse, yMouse) && gui.getStringWidth(key) > 140) {
gui.drawRectangle(22, yPos - 2, gui.getStringWidth(key) + 6, 13, JecaGui.COLOR_GUI_GREY);
gui.drawText(25, yPos, JecaGui.Font.SHADOW, key);
@@ -6,8 +6,9 @@ import com.google.common.cache.LoadingCache;
import com.google.common.cache.Weigher;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.widgets.*;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.widgets.*;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.wrappers.Wrapper;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -17,20 +18,25 @@ import java.util.function.Consumer;
* Author: towdium
* Date: 17-9-14.
*/
@SuppressWarnings("UnstableApiUsage")
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class GuiLabel extends WContainer implements IGui {
WContainer container = new WContainer();
Consumer<ILabel> callback;
LoadingCache<Integer, IWidget> cache = CacheBuilder.newBuilder().concurrencyLevel(1)
.maximumWeight(16).weigher((Weigher<Integer, IWidget>) (key, value) -> 1)
LoadingCache<Integer, IWidget> cache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumWeight(16)
.weigher((Weigher<Integer, IWidget>) (key, value) -> 1)
.build(new CacheLoader<Integer, IWidget>() {
@Override
public IWidget load(Integer i) {
ILabel.RegistryEditor.Record record = ILabel.EDITOR.getRecords().get(i);
return record.editor.get().setCallback(callback);
}
});
@Override
public IWidget load(Integer i) {
ILabel.RegistryEditor.Record record = ILabel.EDITOR.getRecords()
.get(i);
return record.editor.get().setCallback(callback);
}
});
public GuiLabel(Consumer<ILabel> callback) {
this.callback = callback;
@@ -6,6 +6,7 @@ import me.towdium.jecalculation.data.structure.RecordMath.Operator;
import me.towdium.jecalculation.data.structure.RecordMath.State;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.gui.widgets.*;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities;
import org.lwjgl.input.Keyboard;
@@ -22,6 +23,7 @@ import static me.towdium.jecalculation.data.structure.RecordMath.context;
* Date: 19-1-3
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class GuiMath extends WContainer implements IGui {
WLcd lcd = new WLcd(7);
LinkedList<BigDecimal> numbers;
@@ -1,13 +1,14 @@
package me.towdium.jecalculation.gui.guis;
import codechicken.nei.recipe.IRecipeHandler;
import me.towdium.jecalculation.nei.Adapter;
import me.towdium.jecalculation.data.Controller;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.structure.CostList;
import me.towdium.jecalculation.data.structure.Recipe;
import me.towdium.jecalculation.data.structure.Recipe.IO;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.widgets.*;
import me.towdium.jecalculation.nei.Adapter;
import me.towdium.jecalculation.nei.NEIPlugin;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Pair;
@@ -15,9 +16,15 @@ import me.towdium.jecalculation.utils.wrappers.Trio;
import org.lwjgl.input.Keyboard;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
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.PLAIN;
import static me.towdium.jecalculation.gui.Resource.*;
/**
@@ -27,28 +34,34 @@ import static me.towdium.jecalculation.gui.Resource.*;
@ParametersAreNonnullByDefault
public class GuiRecipe extends WContainer implements IGui {
Pair<String, Integer> dest;
HashMap<Integer, List<ILabel>> disambCache = new HashMap<>();
// HashMap<Integer, List<ILabel>> disambCache = new HashMap<>();
WSwitcher group = new WSwitcher(7, 7, 162, Controller.getGroups()).setListener(i -> refresh());
WTextField text = new WTextField(49, 32, 119);
WLabelGroup catalyst = new WLabelGroup(29, 87, 7, 1, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
disambCache.remove(v + 14);
refresh();
});
WLabelGroup input = new WLabelGroup(29, 111, 7, 2, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
disambCache.remove(v);
refresh();
});
WLabelGroup output = new WLabelGroup(29, 63, 7, 1, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
disambCache.remove(v + 21);
refresh();
});
WButton disamb = new WButtonIcon(102, 32, 20, 20, BTN_DISAMB, "recipe.disamb").setListener(i -> {
if (disambCache != null)
JecaGui.displayGui(new GuiDisamb(new ArrayList<>(disambCache.values())).setCallback(l -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
}));
});
List<ILabel> input = new ArrayList<>();
List<ILabel> output = new ArrayList<>();
List<ILabel> catalyst = new ArrayList<>();
WLabelGroup mid = new WLabelGroup(29, 87, 7, 1, 20, 20, true, true);
WLabelGroup down = new WLabelGroup(29, 111, 7, 2, 20, 20, true, true);
WLabelGroup up = new WLabelGroup(29, 63, 7, 1, 20, 20, true, true);
// WLabelGroup catalyst = new WLabelGroup(29, 87, 7, 1, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
// disambCache.remove(v + 14);
// refresh();
// });
// WLabelGroup input = new WLabelGroup(29, 111, 7, 2, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
// disambCache.remove(v);
// refresh();
// });
// WLabelGroup output = new WLabelGroup(29, 63, 7, 1, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
// disambCache.remove(v + 21);
// refresh();
// });
// WButton disamb = new WButtonIcon(102, 32, 20, 20, BTN_DISAMB, "recipe.disamb").setListener(i -> {
// if (disambCache != null)
// JecaGui.displayGui(new GuiDisamb(new ArrayList<>(disambCache.values())).setCallback(l -> {
// JecaGui.displayParent();
// JecaGui.getCurrent().hand = l;
// }));
// });
WButton clear = new WButtonIcon(64, 32, 20, 20, BTN_DEL, "recipe.clear").setListener(i -> reset());
// check duplicate and valid
WButton copy = new WButtonIcon(83, 32, 20, 20, BTN_COPY, "recipe.copy").setListener(i -> {
@@ -85,18 +98,23 @@ public class GuiRecipe extends WContainer implements IGui {
this();
dest = new Pair<>(group, index);
Recipe r = Controller.getRecipe(group, index);
fromRecipe(r);
// fromRecipe(r);
input = r.getLabel(IO.INPUT).stream().map(ILabel::copy).collect(Collectors.toList());
catalyst = r.getLabel(IO.CATALYST).stream().map(ILabel::copy).collect(Collectors.toList());
output = r.getLabel(IO.OUTPUT).stream().map(ILabel::copy).collect(Collectors.toList());
this.group.setIndex(Controller.getGroups().indexOf(group));
refresh();
}
public GuiRecipe() {
for (IO i : IO.values())
setup(getWidget(i), i);
add(new WHelp("recipe"), new WPanel());
add(new WIcon(7, 63, 22, 20, ICN_OUTPUT, "common.output"));
add(new WIcon(7, 87, 22, 20, ICN_CATALYST, "common.catalyst"));
add(new WIcon(7, 111, 22, 40, ICN_INPUT, "common.input"));
add(new WLine(57));
add(input, catalyst, output, group);
add(up, down, mid, group);
if (group.getTexts().isEmpty())
group.setText(Utilities.I18n.get("gui.common.default"));
String last = Controller.getLast();
@@ -107,10 +125,33 @@ public class GuiRecipe extends WContainer implements IGui {
group.setIndex(index);
setNewGroup(false);
copy.setDisabled(true);
disamb.setDisabled(true);
// disamb.setDisabled(true);
text.setListener(i -> yes.setDisabled(i.getText().isEmpty()));
}
public List<ILabel> getLabel(IO type) {
return Recipe.get(type, input, output, catalyst);
}
public WLabelGroup getWidget(IO type) {
return Recipe.get(type, down, up, mid);
}
private void setup(WLabelGroup w, IO type) {
w.setLsnrUpdate((i, v) -> {
List<ILabel> ls = getLabel(type);
while (ls.size() <= v)
ls.add(ILabel.EMPTY);
ls.set(v, i.get(v).getLabel());
trim(ls);
refresh();
}).setLsnrClick((i, v) -> {
ILabel l = i.get(v).getLabel();
if (l != ILabel.EMPTY)
add(new WAmount(i.get(v)));
});
}
@Override
public boolean onKeyPressed(JecaGui gui, char ch, int code) {
if (code == Keyboard.KEY_ESCAPE && contains(text)) {
@@ -120,12 +161,24 @@ public class GuiRecipe extends WContainer implements IGui {
return super.onKeyPressed(gui, ch, code);
}
@Override
public boolean onMouseScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
WLabel w = getLabelUnderMouse(xMouse, yMouse);
if (w == null)
return super.onMouseScroll(gui, xMouse, yMouse, diff);
ILabel l = w.getLabel();
for (int i = 0; i < Math.abs(diff); i++)
l = diff > 0 ? l.increaseAmount() : l.decreaseAmount();
w.setLabel(l, true);
return true;
}
public void setNewGroup(boolean b) {
if (b) {
remove(neu, label, clear, copy, save, disamb);
remove(neu, label, clear, copy, save);
add(yes, no, text);
} else {
add(neu, label, clear, copy, save, disamb);
add(neu, label, clear, copy, save);
remove(yes, no, text);
text.setText("");
yes.setDisabled(true);
@@ -133,10 +186,10 @@ public class GuiRecipe extends WContainer implements IGui {
}
public void reset() {
input.setLabel(Collections.nCopies(14, ILabel.EMPTY), 0);
catalyst.setLabel(Collections.nCopies(7, ILabel.EMPTY), 0);
output.setLabel(Collections.nCopies(7, ILabel.EMPTY), 0);
disambCache.clear();
input = new ArrayList<>();
catalyst = new ArrayList<>();
output = new ArrayList<>();
// disambCache.clear();
refresh();
}
@@ -144,7 +197,7 @@ public class GuiRecipe extends WContainer implements IGui {
// item disamb raw
ArrayList<Trio<ILabel, CostList, CostList>> input = new ArrayList<>();
ArrayList<Trio<ILabel, CostList, CostList>> output = new ArrayList<>();
disambCache = new HashMap<>();
// disambCache = new HashMap<>();
List<Object[]> recipeInputs = new ArrayList<>();
@@ -152,24 +205,28 @@ public class GuiRecipe extends WContainer implements IGui {
Adapter.handleRecipe(recipe, recipeIndex, recipeInputs, recipeOutputs);
// input
recipeInputs.forEach(i -> merge(input, Arrays.asList(i), recipe));
recipeInputs.forEach(i -> merge(input, Arrays.asList(i), recipe, true));
// output
recipeOutputs.forEach(o -> merge(output, Arrays.asList(o), recipe));
recipeOutputs.forEach(o -> merge(output, Arrays.asList(o), recipe, false));
// catalyst. Ignore multiple catalyst
this.catalyst = new ArrayList<>();
NEIPlugin.getCatalyst(recipe)
.map(ILabel.Converter::from)
.ifPresent(catalyst -> this.catalyst.setLabel(catalyst, 0));
.ifPresent(catalyst -> this.catalyst.add(ILabel.CONVERTER.first(Collections.singletonList(catalyst), recipe)));
// other. Unused. For example fuel in furnaces.
// recipe.getOtherStacks(recipeIndex).stream();
this.input.setLabel(sort(input, 0), 0);
this.output.setLabel(sort(output, 21), 0);
this.input = extract(input);
this.output = extract(output);
refresh();
}
private void merge(ArrayList<Trio<ILabel, CostList, CostList>> dst, List<Object> gi, IRecipeHandler context) {
private void merge(ArrayList<Trio<ILabel, CostList, CostList>> dst,
List<Object> gi,
IRecipeHandler context,
boolean input) {
List<ILabel> list = gi.stream()
.map(ILabel.Converter::from)
.filter(i -> i != ILabel.EMPTY)
@@ -185,38 +242,42 @@ public class GuiRecipe extends WContainer implements IGui {
} else
return false;
}).findAny().orElseGet(() -> {
Trio<ILabel, CostList, CostList> ret = new Trio<>(ILabel.CONVERTER.first(list, context), new CostList(list),
new CostList(list));
ILabel rep = ILabel.CONVERTER.first(list, context);
if (!input && list.size() == 1)
rep = list.get(0).copy();
Trio<ILabel, CostList, CostList> ret = new Trio<>(rep, new CostList(list), new CostList(list));
dst.add(ret);
return ret;
});
}
private ArrayList<ILabel> sort(ArrayList<Trio<ILabel, CostList, CostList>> src, int offset) {
private ArrayList<ILabel> extract(ArrayList<Trio<ILabel, CostList, CostList>> src) {
ArrayList<ILabel> ret = new ArrayList<>();
for (int i = 0; i < src.size(); i++) {
Trio<ILabel, CostList, CostList> p = src.get(i);
ret.add(p.one);
if (p.two.getLabels().size() > 1)
disambCache.put(i + offset, p.two.getLabels());
// TODO disamb
// if (p.two.getLabels().size() > 1) disambCache.put(i + offset, p.two.getLabels());
}
return ret;
}
private Recipe toRecipe() {
return new Recipe(input.getLabels(), catalyst.getLabels(), output.getLabels());
private void trim(List<ILabel> ls) {
for (int i = ls.size() - 1; i >= 0; i--) {
if (ls.get(i) == ILabel.EMPTY)
ls.remove(i);
}
}
void fromRecipe(Recipe r) {
input.setLabel(Arrays.stream(r.getLabel(Recipe.IO.INPUT)).map(ILabel::copy).collect(Collectors.toList()), 0);
catalyst.setLabel(Arrays.stream(r.getLabel(Recipe.IO.CATALYST)).map(ILabel::copy).collect(Collectors.toList()),
0);
output.setLabel(Arrays.stream(r.getLabel(Recipe.IO.OUTPUT)).map(ILabel::copy).collect(Collectors.toList()), 0);
private Recipe toRecipe() { // TODO
return new Recipe(input, catalyst, output);
}
void refresh() {
disamb.setDisabled(disambCache.isEmpty());
up.setLabel(output, 0);
mid.setLabel(catalyst, 0);
down.setLabel(input, 0);
try {
Recipe r = toRecipe();
boolean d = dest == null ? Controller.hasDuplicate(r) : Controller.hasDuplicate(r, dest.one, dest.two);
@@ -228,4 +289,81 @@ public class GuiRecipe extends WContainer implements IGui {
copy.setDisabled(true);
}
}
static class WAmount extends WOverlay {
WLabel temp;
WButton number;
WTextField text;
WButton percent;
WButton pick;
WButton yes;
WButton no;
WLabel ref;
public WAmount(WLabel w) {
ref = w;
number = new WButtonText(ref.xPos + ref.xSize + 60, ref.yPos, 20, 20, "#",
"general.to_percent").setListener(i -> {
temp.getLabel().setPercent(true);
update();
});
percent = new WButtonText(ref.xPos + ref.xSize + 60, ref.yPos, 20, 20, "%",
"general.to_percent").setListener(i -> {
temp.getLabel().setPercent(false);
update();
});
temp = new WLabel(ref.xPos, ref.yPos, ref.xSize, ref.ySize, false, true).setLsnrUpdate((i, v) -> update());
temp.setLabel(ref.getLabel().copy());
add(new WPanel(ref.xPos - 5, ref.yPos - 5, ref.xSize + 152, ref.ySize + 10));
add(new WText(ref.xPos + ref.xSize + 3, ref.yPos + 5, PLAIN, "x"));
text = new WTextField(ref.xPos + ref.xSize + 10, ref.yPos + ref.ySize / 2 - WTextField.HEIGHT / 2, 50);
pick = new WButtonIcon(ref.xPos + ref.xSize + 83, ref.yPos, 20, 20, BTN_PICK, "label.pick").setListener(
i -> {
JecaGui.getCurrent().hand = temp.getLabel();
set(ILabel.EMPTY);
});
yes = new WButtonIcon(ref.xPos + ref.xSize + 102, ref.yPos, 20, 20, BTN_YES, "label.confirm").setListener(
i -> set(temp.getLabel()));
no = new WButtonIcon(ref.xPos + ref.xSize + 121, ref.yPos, 20, 20, BTN_NO, "label.delete").setListener(
i -> set(ILabel.EMPTY));
add(temp, text, pick, yes, no);
text.setListener(i -> {
boolean acceptable;
long amount;
try {
amount = Long.parseLong(text.getText());
acceptable = amount > 0;
if (!acceptable)
amount = 1;
} catch (NumberFormatException e) {
acceptable = text.getText().isEmpty();
amount = 1;
}
text.setColor(acceptable ? COLOR_TEXT_WHITE : COLOR_TEXT_RED);
yes.setDisabled(!acceptable);
temp.setLabel(temp.getLabel().setAmount(amount));
});
update();
}
private void set(ILabel l) {
ref.setLabel(l, true);
//refresh();
//disambCache.remove(idx);
JecaGui.getCurrent().root.remove(this);
}
private void update() {
number.setDisabled(!temp.getLabel().acceptPercent());
if (temp.getLabel().isPercent()) {
remove(number);
add(percent);
} else {
remove(percent);
add(number);
}
text.setText(Long.toString(temp.getLabel().getAmount()));
}
}
}
@@ -16,15 +16,16 @@ import java.util.IdentityHashMap;
import java.util.List;
import java.util.function.Consumer;
import static me.towdium.jecalculation.data.Controller.recipeIterator;
import static me.towdium.jecalculation.gui.Resource.*;
import static me.towdium.jecalculation.gui.widgets.WLabel.Mode.PICKER;
@ParametersAreNonnullByDefault
public class GuiSearch extends WContainer implements IGui {
IdentityHashMap<ILabel, Trio<Recipe, String, Integer>> recipes;
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, PICKER, true)
.setListener((i, v) -> add(new Overlay(i.get(v))));
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, false, true, false, true)
.setListener((i, v) -> {
ILabel l = i.get(v).getLabel();
if (l != ILabel.EMPTY) add(new Overlay(i.get(v)));
});
WSwitcher group;
WTextField text = new WTextField(7, 25, 119);
WButton no = new WButtonIcon(130, 25, 20, 20, BTN_NO, "common.cancel")
@@ -137,14 +138,12 @@ public class GuiSearch extends WContainer implements IGui {
}
class Overlay extends WOverlay {
public Overlay(ILabel l) {
Trio<Recipe, String, Integer> recipe = recipes.get(l);
int x = JecaGui.getMouseX();
int y = JecaGui.getMouseY();
x = ((x - 7) / 18) * 18 + 6;
y = ((y - 51) / 18) * 18 + 50;
public Overlay(WLabel l) {
Trio<Recipe, String, Integer> recipe = recipes.get(l.getLabel());
int x = l.xPos - 1;
int y = l.yPos - 1;
add(new WPanel(x - 5, y - 5, 72, 30));
add(new WLabel(x, y, 20, 20, PICKER).setLabel(l));
add(new WLabel(x, y, 20, 20, false, false).setLabel(l.getLabel()));
add(new WButtonIcon(x + 23, y, 20, 20, BTN_EDIT, "search.edit").setListener(i -> {
JecaGui.displayGui(true, true, new GuiRecipe(recipe.two, recipe.three));
GuiSearch.this.remove(this);
@@ -1,5 +1,7 @@
package me.towdium.jecalculation.gui.guis;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.widgets.IContainer;
@@ -7,6 +9,7 @@ import me.towdium.jecalculation.gui.widgets.IContainer;
* Author: Towdium
* Date: 18-9-25
*/
@SideOnly(Side.CLIENT)
public interface IGui extends IContainer {
default void onVisible(JecaGui gui) {
}
@@ -2,10 +2,10 @@ package me.towdium.jecalculation.gui.guis.pickers;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.guis.IGui;
import me.towdium.jecalculation.gui.widgets.IWidget;
import me.towdium.jecalculation.gui.widgets.WContainer;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.guis.IGui;
import me.towdium.jecalculation.gui.widgets.WContainer;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
@@ -15,6 +15,7 @@ import java.util.function.Consumer;
* Date: 17-9-28.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public interface IPicker extends IGui {
IPicker setCallback(Consumer<ILabel> callback);
@@ -29,7 +30,8 @@ public interface IPicker extends IGui {
}
protected void notifyLsnr(ILabel l) {
if (callback != null) callback.accept(l);
if (callback != null && l != ILabel.EMPTY)
callback.accept(l);
}
}
}
@@ -4,14 +4,12 @@ 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.labels.LItemStack;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.gui.guis.IGui;
import me.towdium.jecalculation.gui.widgets.WButton;
import me.towdium.jecalculation.gui.widgets.WButtonIcon;
import me.towdium.jecalculation.gui.widgets.WLabel;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
import static me.towdium.jecalculation.gui.Resource.*;
@@ -22,12 +20,15 @@ import static me.towdium.jecalculation.gui.Resource.*;
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class PickerItemStack extends IPicker.Impl implements IGui {
WLabel label = new WLabel(7, 7, 20, 20, WLabel.Mode.SELECTOR).setListener((i, v) -> update(v));
WButton bConfirm = new WButtonIcon(149, 7, 20, 20, BTN_YES, "item_stack.confirm").setListener(i -> callback.accept(label.getLabel()));
WLabel label = new WLabel(7, 7, 20, 20, false, true).setLsnrUpdate((i, v) -> update(v));
WButton bConfirm = new WButtonIcon(149, 7, 20, 20, BTN_YES, "item_stack.confirm").setListener(
i -> callback.accept(label.getLabel()));
WButton bNbtN = new WButtonIcon(49, 7, 20, 20, BTN_NBT_N, "item_stack.nbt_normal").setListener(i -> setFNbt(true));
WButton bNbtF = new WButtonIcon(49, 7, 20, 20, BTN_NBT_F, "item_stack.nbt_fuzzy").setListener(i -> setFNbt(false));
WButton bMetaN = new WButtonIcon(30, 7, 20, 20, BTN_META_N, "item_stack.meta_normal").setListener(i -> setFMeta(true));
WButton bMetaF = new WButtonIcon(30, 7, 20, 20, BTN_META_F, "item_stack.meta_fuzzy").setListener(i -> setFMeta(false));
WButton bMetaN = new WButtonIcon(30, 7, 20, 20, BTN_META_N, "item_stack.meta_normal").setListener(
i -> setFMeta(true));
WButton bMetaF = new WButtonIcon(30, 7, 20, 20, BTN_META_F, "item_stack.meta_fuzzy").setListener(
i -> setFMeta(false));
ILabel raw = ILabel.EMPTY;
boolean fMeta, fNbt, fCap = false;
@@ -56,8 +57,10 @@ public class PickerItemStack extends IPicker.Impl implements IGui {
private void setF(boolean b, WButton be, WButton bd, Runnable r) {
remove(be, bd);
if (b) add(bd);
else add(be);
if (b)
add(bd);
else
add(be);
r.run();
if (raw instanceof LItemStack) {
LItemStack lis = (LItemStack) raw;
@@ -3,12 +3,12 @@ package me.towdium.jecalculation.gui.guis.pickers;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.labels.LPlaceholder;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.gui.guis.IGui;
import me.towdium.jecalculation.gui.widgets.*;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
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;
@@ -19,19 +19,21 @@ import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
* Date: 17-9-29.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class PickerPlaceholder extends IPicker.Impl implements IGui {
public PickerPlaceholder() {
WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, WLabel.Mode.PICKER, true)
.setLabels(LPlaceholder.getRecent()).setListener((i, v) -> notifyLsnr(i.get(v)));
WTextField create = new WTextField(26, 7, 69)
.setListener(i -> i.setColor(i.getText().equals("") ? COLOR_TEXT_RED : COLOR_TEXT_WHITE));
WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, false, true, false, true).setLabels(
LPlaceholder.getRecent()).setListener((i, v) -> notifyLsnr(i.get(v).getLabel()));
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, ICN_TEXT, "common.search"));
add(new WIcon(7, 7, 20, 20, ICN_TEXT, "placeholder.create"));
add(new WLine(36));
add(new WButtonIcon(95, 7, 20, 20, BTN_YES, "common.confirm").setListener(i -> {
if (!create.getText().equals("")) callback.accept(new LPlaceholder(create.getText(), 1));
if (!create.getText().equals(""))
callback.accept(new LPlaceholder(create.getText(), 1));
}));
add(scroll, create);
}
@@ -10,6 +10,7 @@ import me.towdium.jecalculation.gui.widgets.WIcon;
import me.towdium.jecalculation.gui.widgets.WLabel;
import me.towdium.jecalculation.gui.widgets.WLabelScroll;
import me.towdium.jecalculation.gui.widgets.WSearch;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.oredict.OreDictionary;
@@ -25,15 +26,15 @@ import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
* Date: 17-9-28.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class PickerSimple extends IPicker.Impl implements IGui {
/**
* @param labels label to be displayed for selection
*/
public PickerSimple(List<ILabel> labels) {
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, WLabel.Mode.PICKER, true).setLabels(labels)
.setListener((i, v) -> notifyLsnr(
i.get(v)));
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, false, true, false, true).setLabels(labels)
.setListener((i, v) -> notifyLsnr(i.get(v).getLabel()));
add(new WSearch(26, 7, 90, ls));
add(new WIcon(7, 7, 20, 20, ICN_TEXT, "common.search"));
add(ls);
@@ -1,12 +1,15 @@
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;
/**
* Author: towdium
* Date: 8/14/17.
*/
@ParametersAreNonnullByDefault
public interface IWidget {
void onDraw(JecaGui gui, int xMouse, int yMouse);
@@ -19,6 +22,10 @@ public interface IWidget {
return false;
}
default boolean onMouseReleased(JecaGui gui, int xMouse, int yMouse, int button) {
return false;
}
default boolean onKeyPressed(JecaGui gui, char ch, int code) {
return false;
}
@@ -28,7 +35,7 @@ public interface IWidget {
}
@Nullable
default ILabel getLabelUnderMouse(int xMouse, int yMouse) {
default WLabel getLabelUnderMouse(int xMouse, int yMouse) {
return null;
}
@@ -3,10 +3,8 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.ClientUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import org.lwjgl.input.Keyboard;
import javax.annotation.Nullable;
@@ -21,6 +19,7 @@ import static me.towdium.jecalculation.gui.Resource.*;
* Date: 17-8-17.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public abstract class WButton extends WTooltip {
protected int xPos, yPos, xSize, ySize;
@@ -45,18 +44,22 @@ public abstract class WButton extends WTooltip {
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
super.onDraw(gui, xMouse, yMouse);
boolean hovered = JecaGui.mouseIn(xPos + 1, yPos + 1, xSize - 2, ySize - 2, xMouse, yMouse);
if (keys != null) for (int i : keys) if (Keyboard.isKeyDown(i)) hovered = true;
gui.drawResourceContinuous(disabled ? WGT_BUTTON_D : (hovered ? WGT_BUTTON_F : WGT_BUTTON_N)
, xPos, yPos, xSize, ySize, 5, 5, 5, 5);
if (keys != null)
for (int i : keys)
if (Keyboard.isKeyDown(i))
hovered = true;
gui.drawResourceContinuous(disabled ? WGT_BUTTON_D : (hovered ? WGT_BUTTON_F : WGT_BUTTON_N), xPos, yPos, xSize,
ySize, 5, 5, 5, 5);
}
@Override
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
if (JecaGui.mouseIn(xPos + 1, yPos + 1, xSize - 2, ySize - 2, xMouse, yMouse) &&
!disabled && button == 0 && listener != null) {
if (JecaGui.mouseIn(xPos + 1, yPos + 1, xSize - 2, ySize - 2, xMouse, yMouse) && !disabled && button == 0 &&
listener != null) {
trigger();
return true;
} else return false;
} else
return false;
}
private void trigger() {
@@ -66,13 +69,13 @@ public abstract class WButton extends WTooltip {
@Override
public boolean onKeyPressed(JecaGui gui, char ch, int code) {
// JustEnoughCalculation.logger.info(code);
if (keys != null) for (int i : keys) {
if (i == code) {
trigger();
return true;
if (keys != null)
for (int i : keys) {
if (i == code) {
trigger();
return true;
}
}
}
return false;
}
@@ -2,8 +2,8 @@ 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.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.Nullable;
@@ -18,6 +18,7 @@ import java.util.Objects;
* Date: 17-9-14.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WContainer implements IContainer {
protected List<IWidget> widgets = new ArrayList<>();
@@ -27,13 +28,17 @@ public class WContainer implements IContainer {
}
public void add(IWidget... w) {
if (w.length == 1) widgets.add(w[0]);
else widgets.addAll(Arrays.asList(w));
if (w.length == 1)
widgets.add(w[0]);
else
widgets.addAll(Arrays.asList(w));
}
public void remove(IWidget... w) {
if (w.length == 1) widgets.remove(w[0]);
else widgets.removeAll(Arrays.asList(w));
if (w.length == 1)
widgets.remove(w[0]);
else
widgets.removeAll(Arrays.asList(w));
}
public void clear() {
@@ -57,8 +62,13 @@ public class WContainer implements IContainer {
@Override
public boolean onKeyPressed(JecaGui gui, char ch, int code) {
return new Utilities.ReversedIterator<>(widgets).stream().anyMatch(i -> i.onKeyPressed(gui, ch, code));
}
@Override
public boolean onMouseReleased(JecaGui gui, int xMouse, int yMouse, int button) {
return new Utilities.ReversedIterator<>(widgets).stream()
.anyMatch(i -> i.onKeyPressed(gui, ch, code));
.anyMatch(i -> i.onMouseReleased(gui, xMouse, yMouse, button));
}
@Override
@@ -75,10 +85,11 @@ public class WContainer implements IContainer {
@Nullable
@Override
public ILabel getLabelUnderMouse(int xMouse, int yMouse) {
public WLabel getLabelUnderMouse(int xMouse, int yMouse) {
return new Utilities.ReversedIterator<>(widgets).stream()
.map(i -> i.getLabelUnderMouse(xMouse, yMouse))
.filter(Objects::nonNull)
.findFirst().orElse(null);
.findFirst()
.orElse(null);
}
}
@@ -1,6 +1,7 @@
package me.towdium.jecalculation.gui.widgets;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.I18n;
import org.lwjgl.input.Keyboard;
@@ -16,6 +17,7 @@ import static me.towdium.jecalculation.gui.Resource.*;
* Author: Towdium
* Date: 18-9-23
*/
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class WHelp extends WContainer {
protected String key;
@@ -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.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -15,6 +16,7 @@ import static me.towdium.jecalculation.gui.JecaGui.COLOR_GUI_GREY;
* Date: 17-8-18.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WIcon extends WTooltip {
public int xPos, yPos, xSize, ySize;
@@ -1,50 +1,44 @@
package me.towdium.jecalculation.gui.widgets;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
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.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.utils.IllegalPositionException;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.Timer;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.function.Function;
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.*;
import static me.towdium.jecalculation.gui.Resource.WGT_SLOT;
/**
* Author: towdium
* Date: 17-8-17.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WLabel implements IWidget {
public int xPos, yPos, xSize, ySize;
ILabel label;
public Mode mode;
public ListenerValue<? super WLabel, ILabel> listener;
protected Utilities.Timer timer = new Utilities.Timer();
ILabel label = ILabel.EMPTY;
public boolean multiple, accept;
public ListenerValue<? super WLabel, ILabel> update;
public ListenerAction<? super WLabel> click;
Function<ILabel, String> formatter = i -> i.getAmountString(false);
protected Timer timer = new Timer();
public WLabel(int xPos, int yPos, int xSize, int ySize, Mode mode) {
public WLabel(int xPos, int yPos, int xSize, int ySize, boolean multiple, boolean accept) {
this.xPos = xPos;
this.yPos = yPos;
this.xSize = xSize;
this.ySize = ySize;
this.label = label.EMPTY;
this.mode = mode;
this.multiple = multiple;
this.accept = accept;
}
public ILabel getLabel() {
@@ -52,20 +46,26 @@ public class WLabel implements IWidget {
}
public WLabel setLabel(ILabel label) {
return setLabel(label, false);
}
public WLabel setLabel(ILabel label, boolean notify) {
this.label = label;
if (notify)
notifyUpdate();
return this;
}
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
gui.drawResourceContinuous(Resource.WGT_SLOT, xPos, yPos, xSize, ySize, 3, 3, 3, 3);
gui.drawResourceContinuous(WGT_SLOT, xPos, yPos, xSize, ySize, 3, 3, 3, 3);
label.drawLabel(gui, xPos + xSize / 2, yPos + ySize / 2, true);
if (mode == Mode.RESULT || mode == Mode.EDITOR) {
String s = label.getAmountString(mode == Mode.RESULT);
if (multiple) {
String s = formatter.apply(label);
gui.drawText(xPos + xSize / 2.0f + 8 - HALF.getTextWidth(s),
yPos + ySize / 2.0f + 8.5f - HALF.getTextHeight(), HALF, s);
}
if (mode == Mode.EDITOR || mode == Mode.SELECTOR) {
if (accept) {
timer.setState(gui.hand != ILabel.EMPTY);
int color = 0xFFFFFF + (int) ((-Math.cos(timer.getTime() * Math.PI / 1500) + 1) * 0x40) * 0x1000000;
GuiDraw.drawRect(xPos + 1, yPos + 1, xSize - 2, ySize - 2, color);
@@ -80,80 +80,105 @@ public class WLabel implements IWidget {
return false;
if (label != ILabel.EMPTY) {
tooltip.add(label.getDisplayName());
label.getToolTip(tooltip, mode == Mode.EDITOR || mode == Mode.RESULT);
label.getToolTip(tooltip, multiple);
}
return false;
}
@Override
public boolean onMouseScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
if (mouseIn(xMouse, yMouse)) {
if (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
return false;
}
// TODO
// @Override
// public boolean onMouseScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
// if (mouseIn(xMouse, yMouse)) {
// if (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
// return false;
// }
@Nullable
@Override
public ILabel getLabelUnderMouse(int xMouse, int yMouse) {
return mouseIn(xMouse, yMouse) ? label : null;
public WLabel getLabelUnderMouse(int xMouse, int yMouse) {
return mouseIn(xMouse, yMouse) ? this : null;
}
@Override
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
if (!mouseIn(xMouse, yMouse) || (button == 1 && mode != Mode.RESULT))
if (!mouseIn(xMouse, yMouse) || button == 1)
return false;
switch (mode) {
case EDITOR:
if (gui.hand != label.EMPTY) {
label = gui.hand;
gui.hand = label.EMPTY;
notifyLsnr();
return true;
} else if (label != label.EMPTY) {
gui.root.add(new WAmount());
return true;
} else
return false;
case RESULT:
// open NEI recipe gui
Object item = label.getRepresentation();
if ((item instanceof ItemStack || item instanceof FluidStack)) {
String id = item instanceof ItemStack ? "item" : "liquid";
if (button == 0) {
GuiCraftingRecipe.openRecipeGui(id, item);
return true;
} else if (button == 1) {
GuiUsageRecipe.openRecipeGui(id, item);
return true;
}
} else if (item != null) {
JustEnoughCalculation.logger.warn("unknown label representation " + item);
}
return false;
case PICKER:
if (label != label.EMPTY) {
notifyLsnr();
return true;
} else
return false;
case SELECTOR:
if (accept) {
if (gui.hand == ILabel.EMPTY && click != null)
notifyClick();
else {
label = gui.hand;
gui.hand = label.EMPTY;
notifyLsnr();
return true;
default:
throw new IllegalPositionException();
}
notifyUpdate();
}
} else
notifyClick();
return true;
// if (!mouseIn(xMouse, yMouse) || (button == 1 && mode != Mode.RESULT))
// return false;
// switch (mode) {
// case EDITOR:
// if (gui.hand != label.EMPTY) {
// label = gui.hand;
// gui.hand = label.EMPTY;
// notifyLsnr();
// return true;
// } else if (label != label.EMPTY) {
// gui.root.add(new WAmount());
// return true;
// } else
// return false;
// case RESULT:
// // open NEI recipe gui
// Object item = label.getRepresentation();
// if ((item instanceof ItemStack || item instanceof FluidStack)) {
// String id = item instanceof ItemStack ? "item" : "liquid";
// if (button == 0) {
// GuiCraftingRecipe.openRecipeGui(id, item);
// return true;
// } else if (button == 1) {
// GuiUsageRecipe.openRecipeGui(id, item);
// return true;
// }
// } else if (item != null) {
// JustEnoughCalculation.logger.warn("unknown label representation " + item);
// }
// return false;
// case PICKER:
// if (label != label.EMPTY) {
// notifyLsnr();
// return true;
// } else
// return false;
// case SELECTOR:
// label = gui.hand;
// gui.hand = label.EMPTY;
// notifyLsnr();
// return true;
// default:
// throw new IllegalPositionException();
// }
}
public WLabel setListener(ListenerValue<? super WLabel, ILabel> listener) {
this.listener = listener;
public WLabel setLsnrUpdate(ListenerValue<? super WLabel, ILabel> listener) {
update = listener;
return this;
}
public WLabel setLsnrClick(ListenerAction<? super WLabel> listener) {
click = listener;
return this;
}
public WLabel setFormatter(Function<ILabel, String> f) {
formatter = f;
return this;
}
@@ -163,82 +188,79 @@ public class WLabel implements IWidget {
return xx >= 0 && xx < xSize && yy >= 0 && yy < ySize;
}
void notifyLsnr() {
if (listener != null)
listener.invoke(this, label);
private void notifyClick() {
if (click != null)
click.invoke(this);
}
private void notifyUpdate() {
if (update != null)
update.invoke(this, label);
}
public enum Mode {
EDITOR, // Slots in editor gui. Can use to edit amount. Exact amount displayed.
RESULT, // Slots to display calculate result. Rounded amount displayed.
PICKER, // Slots that can pick items from. No amount displayed.
SELECTOR // Slots to put labels into. No amount displayed.
}
class WAmount extends WOverlay {
WLabel temp = new WLabel(xPos, yPos, xSize, ySize, Mode.PICKER).setListener((i, v) -> update());
WButton number = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "#", "general.to_percent").setListener(i -> {
temp.label.setPercent(true);
update();
});
WTextField text = new WTextField(xPos + xSize + 10, yPos + ySize / 2 - WTextField.HEIGHT / 2, 50);
WButton percent = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "%", "general.to_percent").setListener(i -> {
temp.label.setPercent(false);
update();
});
WButton pick = new WButtonIcon(xPos + xSize + 83, yPos, 20, 20, BTN_PICK, "label.pick").setListener(i -> {
JecaGui.getCurrent().hand = temp.label;
setLabel(ILabel.EMPTY);
notifyLsnr();
JecaGui.getCurrent().root.remove(this);
});
WButton yes = new WButtonIcon(xPos + xSize + 102, yPos, 20, 20, BTN_YES, "label.confirm").setListener(i -> {
setLabel(temp.label);
notifyLsnr();
JecaGui.getCurrent().root.remove(this);
});
WButton no = new WButtonIcon(xPos + xSize + 121, yPos, 20, 20, BTN_NO, "label.delete").setListener(i -> {
setLabel(ILabel.EMPTY);
notifyLsnr();
JecaGui.getCurrent().root.remove(this);
});
public WAmount() {
temp.setLabel(label.copy());
add(new WPanel(xPos - 5, yPos - 5, xSize + 152, ySize + 10));
add(new WText(xPos + xSize + 3, yPos + 5, PLAIN, "x"));
add(temp, text, pick, yes, no);
text.setListener(i -> {
boolean acceptable;
long amount;
try {
amount = Long.parseLong(text.getText());
acceptable = amount > 0;
if (!acceptable)
amount = 1;
} catch (NumberFormatException e) {
acceptable = text.getText().isEmpty();
amount = 1;
}
text.setColor(acceptable ? COLOR_TEXT_WHITE : COLOR_TEXT_RED);
yes.setDisabled(!acceptable);
temp.label = temp.label.setAmount(amount);
});
update();
}
private void update() {
number.setDisabled(!temp.label.acceptPercent());
if (temp.label.isPercent()) {
remove(number);
add(percent);
} else {
remove(percent);
add(number);
}
text.setText(Long.toString(temp.label.getAmount()));
}
}
// class WAmount extends WOverlay {
// WLabel temp = new WLabel(xPos, yPos, xSize, ySize, Mode.PICKER).setListener((i, v) -> update());
// WButton number = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "#", "general.to_percent").setListener(i -> {
// temp.label.setPercent(true);
// update();
// });
// WTextField text = new WTextField(xPos + xSize + 10, yPos + ySize / 2 - WTextField.HEIGHT / 2, 50);
// WButton percent = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "%", "general.to_percent").setListener(i -> {
// temp.label.setPercent(false);
// update();
// });
// WButton pick = new WButtonIcon(xPos + xSize + 83, yPos, 20, 20, BTN_PICK, "label.pick").setListener(i -> {
// JecaGui.getCurrent().hand = temp.label;
// setLabel(ILabel.EMPTY);
// notifyLsnr();
// JecaGui.getCurrent().root.remove(this);
// });
// WButton yes = new WButtonIcon(xPos + xSize + 102, yPos, 20, 20, BTN_YES, "label.confirm").setListener(i -> {
// setLabel(temp.label);
// notifyLsnr();
// JecaGui.getCurrent().root.remove(this);
// });
// WButton no = new WButtonIcon(xPos + xSize + 121, yPos, 20, 20, BTN_NO, "label.delete").setListener(i -> {
// setLabel(ILabel.EMPTY);
// notifyLsnr();
// JecaGui.getCurrent().root.remove(this);
// });
//
// public WAmount() {
// temp.setLabel(label.copy());
// add(new WPanel(xPos - 5, yPos - 5, xSize + 152, ySize + 10));
// add(new WText(xPos + xSize + 3, yPos + 5, PLAIN, "x"));
// add(temp, text, pick, yes, no);
// text.setListener(i -> {
// boolean acceptable;
// long amount;
// try {
// amount = Long.parseLong(text.getText());
// acceptable = amount > 0;
// if (!acceptable)
// amount = 1;
// } catch (NumberFormatException e) {
// acceptable = text.getText().isEmpty();
// amount = 1;
// }
// text.setColor(acceptable ? COLOR_TEXT_WHITE : COLOR_TEXT_RED);
// yes.setDisabled(!acceptable);
// temp.label = temp.label.setAmount(amount);
// });
// update();
// }
//
// private void update() {
// number.setDisabled(!temp.label.acceptPercent());
// if (temp.label.isPercent()) {
// remove(number);
// add(percent);
// } else {
// remove(percent);
// add(number);
// }
// text.setText(Long.toString(temp.label.getAmount()));
// }
// }
}
@@ -3,13 +3,12 @@ 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.utils.wrappers.Wrapper;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -18,27 +17,44 @@ import java.util.stream.IntStream;
* Date: 17-8-17.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WLabelGroup extends WContainer {
ArrayList<WLabel> labels = new ArrayList<>();
ListenerValue<? super WLabelGroup, Integer> listener;
ListenerValue<? super WLabelGroup, Integer> lsnrUpdate;
ListenerValue<? super WLabelGroup, Integer> lsnrClick;
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, boolean multiple, boolean accept) {
this(xPos, yPos, column, row, 18, 18, multiple, accept);
}
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).setListener((i, v) -> {
if (listener != null) listener.invoke(this, r * column + c);
public WLabelGroup(int xPos,
int yPos,
int column,
int row,
int xSize,
int ySize,
boolean multiple,
boolean accept) {
for (int j = 0; j < row; j++) {
int r = j;
IntStream.range(0, column).forEach(c -> {
WLabel l = new WLabel(xPos + c * xSize, yPos + r * ySize, xSize, ySize, multiple, accept).setLsnrUpdate(
(i, v) -> {
if (lsnrUpdate != null)
lsnrUpdate.invoke(this, r * column + c);
}).setLsnrClick(i -> {
if (lsnrClick != null)
lsnrClick.invoke(this, r * column + c);
});
labels.add(l);
add(l);
});
labels.add(l);
add(l);
}));
}
}
public ILabel get(int index) {
return labels.get(index).getLabel();
public WLabel get(int index) {
return labels.get(index);
}
public List<ILabel> getLabels() {
@@ -50,11 +66,22 @@ public class WLabelGroup extends WContainer {
}
public void setLabel(List<ILabel> labels, int start) {
for (WLabel label : this.labels) label.setLabel(start < labels.size() ? labels.get(start++) : ILabel.EMPTY);
for (WLabel label : this.labels)
label.setLabel(start < labels.size() ? labels.get(start++) : ILabel.EMPTY);
}
public WLabelGroup setListener(ListenerValue<? super WLabelGroup, Integer> listener) {
this.listener = listener;
public WLabelGroup setLsnrUpdate(ListenerValue<? super WLabelGroup, Integer> listener) {
lsnrUpdate = listener;
return this;
}
public WLabelGroup setLsnrClick(ListenerValue<? super WLabelGroup, Integer> listener) {
lsnrClick = listener;
return this;
}
public WLabelGroup setFormatter(Function<ILabel, String> f) {
labels.forEach(i -> i.setFormatter(f));
return this;
}
}
@@ -4,12 +4,14 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.I18n;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -17,6 +19,7 @@ import java.util.stream.Collectors;
* Date: 17-9-17.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WLabelScroll extends WContainer implements ISearchable {
protected List<ILabel> labels = new ArrayList<>();
@@ -25,14 +28,18 @@ public class WLabelScroll extends WContainer implements ISearchable {
protected WScroll scroll;
protected int xPos, yPos, column, row, current;
protected String filter = "";
protected ListenerValue<? super WLabelScroll, Integer> lsnrUpdate;
protected ListenerValue<? super WLabelScroll, Integer> listener;
public WLabelScroll(int xPos, int yPos, int column, int row, WLabel.Mode mode, boolean drawConnection) {
public WLabelScroll(int xPos, int yPos, int column, int row, boolean multiple, boolean accurate, boolean accept, boolean drawConnection) {
this.xPos = xPos;
this.yPos = yPos;
this.column = column;
this.row = row;
labelGroup = new WLabelGroup(xPos, yPos, column, row, mode).setListener((i, v) -> {
labelGroup = new WLabelGroup(xPos, yPos, column, row, multiple, accept)
.setLsnrUpdate((i, v) -> {
if (lsnrUpdate != null) lsnrUpdate.invoke(this, column * current + v);
}).setLsnrClick((i, v) -> {
if (listener != null) listener.invoke(this, column * current + v);
});
scroll = new WScroll(xPos + column * 18 + 4, yPos, row * 18).setListener(i -> update(i.getCurrent()));
@@ -61,8 +68,8 @@ public class WLabelScroll extends WContainer implements ISearchable {
return in;
}
public ILabel get(int index) {
return filtered.get(index);
public WLabel get(int index) {
return labelGroup.get(index - column * current);
}
private float getPos(int step) {
@@ -77,19 +84,23 @@ public class WLabelScroll extends WContainer implements ISearchable {
public boolean setFilter(String str) {
filter = str;
filtered = labels.stream().filter(l -> Utilities.I18n.contains(l.getDisplayName().toLowerCase(), str.toLowerCase()))
filtered = labels.stream().filter(l -> I18n.contains(l.getDisplayName().toLowerCase(), str.toLowerCase()))
.collect(Collectors.toList());
scroll.setCurrent(0);
update(0);
return filtered.size() != 0;
}
@SuppressWarnings("UnusedReturnValue")
public WLabelScroll setListener(ListenerValue<? super WLabelScroll, Integer> listener) {
this.listener = listener;
return this;
}
public WLabelScroll setFormatter(Function<ILabel, String> f) {
labelGroup.setFormatter(f);
return this;
}
private int getStepAmount() {
int line = (labels.size() + column - 1) / column;
return Math.max(line - row + 1, 1);
@@ -3,6 +3,7 @@ package me.towdium.jecalculation.gui.widgets;
import me.towdium.jecalculation.data.structure.RecordMath.Operator;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
import java.math.BigDecimal;
@@ -18,6 +19,7 @@ import static me.towdium.jecalculation.data.structure.RecordMath.DOT_NONE;
* Author: Towdium
* Date: 19-1-16
*/
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class WLcd implements IWidget {
static HashMap<Character, boolean[]> PATTERN = new HashMap<>();
@@ -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.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -12,6 +13,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
* Date: 17-8-18.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WLine implements IWidget {
int xPos, yPos, xSize, ySize;
@@ -1,6 +1,7 @@
package me.towdium.jecalculation.gui.widgets;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import org.lwjgl.input.Keyboard;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -9,6 +10,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
* Author: Towdium
* Date: 16/02/19
*/
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class WOverlay extends WContainer {
@Override
@@ -2,21 +2,23 @@ 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.data.label.ILabel.RegistryEditor.Record;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import static me.towdium.jecalculation.gui.Resource.*;
import static me.towdium.jecalculation.gui.Resource.WGT_PAGER_F;
import static me.towdium.jecalculation.gui.Resource.WGT_PANEL_N;
/**
* Author: towdium
* Date: 17-9-16.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WPage extends WTooltip {
protected int index;
@@ -47,7 +49,8 @@ public class WPage extends WTooltip {
@Override
public boolean onMouseClicked(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.invoke(this);
if (ret)
listener.invoke(this);
return ret;
}
@@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
@@ -15,6 +16,7 @@ import java.util.List;
* Base panel of GUIs
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WPanel implements IWidget {
int xPos, yPos, xSize, ySize;
@@ -3,6 +3,7 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -11,6 +12,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
* Date: 17-8-22.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WRectangle implements IWidget {
public int xPos, yPos, xSize, ySize, color;
@@ -4,11 +4,11 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import org.lwjgl.input.Mouse;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
/**
* Author: towdium
@@ -16,6 +16,7 @@ import java.util.function.Consumer;
* Scroll bar
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WScroll implements IWidget {
public int xPos, yPos, ySize, current;
@@ -30,8 +31,10 @@ public class WScroll implements IWidget {
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
if (Mouse.isButtonDown(0) && drag) setCurrent(yMouse - yPos - 9, true);
else drag = false;
if (Mouse.isButtonDown(0) && drag)
setCurrent(yMouse - yPos - 9, true);
else
drag = false;
gui.drawResourceContinuous(Resource.WGT_SLOT, xPos, yPos, 14, ySize, 3, 3, 3, 3);
gui.drawResource(Resource.WGT_SCROLL, xPos, yPos + current);
@@ -40,15 +43,19 @@ public class WScroll implements IWidget {
@Override
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
drag = mouseIn(xMouse, yMouse);
if (drag) setCurrent(yMouse - yPos - 9, true);
if (drag)
setCurrent(yMouse - yPos - 9, true);
return drag;
}
private void setCurrent(int pos, boolean notify) {
current = pos;
if (current < 0) current = 0;
if (current > ySize - 17) current = ySize - 17;
if (notify && listener != null) listener.invoke(this);
if (current < 0)
current = 0;
if (current > ySize - 17)
current = ySize - 17;
if (notify && listener != null)
listener.invoke(this);
}
public float getCurrent() {
@@ -2,11 +2,10 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
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;
@@ -15,6 +14,7 @@ import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_WHITE;
* Date: 17-9-28.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WSearch extends WTextField {
ISearchable[] lss;
@@ -32,7 +32,9 @@ public class WSearch extends WTextField {
public void refresh() {
boolean b = false;
for (ISearchable i : lss) if (i.setFilter(textField.getText())) b = true;
for (ISearchable i : lss)
if (i.setFilter(textField.getText()))
b = true;
setColor(b ? COLOR_TEXT_WHITE : COLOR_TEXT_RED);
}
}
@@ -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.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities.Circulator;
import javax.annotation.Nullable;
@@ -24,6 +25,7 @@ import static me.towdium.jecalculation.gui.Resource.WGT_ARR_R;
* Widget to select page with button for left and right
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WSwitcher extends WContainer {
public static final int SIZE = 13;
@@ -3,6 +3,7 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -11,6 +12,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
* Date: 17-8-21.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WText implements IWidget {
public static final int UNDEFINED = Integer.MAX_VALUE;
@@ -36,7 +38,9 @@ public class WText implements IWidget {
@Override
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
int x = xPos + (centred ? xSize / 2 - font.getTextWidth(key) / 2 : 0);
if (xSize == UNDEFINED) gui.drawText(x, yPos, font, key);
else gui.drawText(x, yPos, xSize, font, key);
if (xSize == UNDEFINED)
gui.drawText(x, yPos, font, key);
else
gui.drawText(x, yPos, xSize, font, key);
}
}
@@ -3,17 +3,18 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiTextField;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
/**
* Author: towdium
* Date: 17-8-18.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class WTextField implements IWidget {
public ListenerAction<? super WTextField> listener;
@@ -46,7 +47,8 @@ public class WTextField implements IWidget {
@Override
public boolean onKeyPressed(JecaGui gui, char ch, int code) {
boolean ret = textField.textboxKeyTyped(ch, code);
if (ret) notifyLsnr();
if (ret)
notifyLsnr();
return ret;
}
@@ -71,6 +73,7 @@ public class WTextField implements IWidget {
}
protected void notifyLsnr() {
if (listener != null) listener.invoke(this);
if (listener != null)
listener.invoke(this);
}
}
@@ -1,14 +1,12 @@
package me.towdium.jecalculation.gui.widgets;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import static me.towdium.jecalculation.gui.Resource.*;
@@ -17,6 +15,7 @@ import static me.towdium.jecalculation.gui.Resource.*;
* Date: 18-12-7
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class WTick extends WContainer {
WButton button;
int xPos, yPos, xSize, ySize;
@@ -44,15 +43,19 @@ public class WTick extends WContainer {
this.listener = listener;
return this;
}
public boolean selected() {
return !(button instanceof Normal);
}
public WTick setSelected(boolean selected) {
if (selected == selected()) return this;
if (selected == selected())
return this;
remove(button);
if (selected) button = new Selected(xPos, yPos, xSize, ySize, name);
else button = new Normal(xPos, yPos, xSize, ySize, name);
if (selected)
button = new Selected(xPos, yPos, xSize, ySize, name);
else
button = new Normal(xPos, yPos, xSize, ySize, name);
add(button);
return this;
}
@@ -92,8 +95,8 @@ public class WTick extends WContainer {
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
super.onDraw(gui, xMouse, yMouse);
boolean hovered = JecaGui.mouseIn(xPos + 1, yPos + 1, xSize - 2, ySize - 2, xMouse, yMouse);
gui.drawResourceContinuous(disabled ? WGT_BUTTON_S_D : (hovered ? WGT_BUTTON_S_F : WGT_BUTTON_S_N)
, xPos, yPos, xSize, ySize, 5, 5, 5, 5);
gui.drawResourceContinuous(disabled ? WGT_BUTTON_S_D : (hovered ? WGT_BUTTON_S_F : WGT_BUTTON_S_N), xPos,
yPos, xSize, ySize, 5, 5, 5, 5);
}
}
}
@@ -3,7 +3,9 @@ package me.towdium.jecalculation.gui.widgets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.Utilities.I18n;
import me.towdium.jecalculation.utils.wrappers.Pair;
import javax.annotation.Nullable;
@@ -19,9 +21,9 @@ import static java.lang.String.join;
* Date: 17-9-16.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public abstract class WTooltip implements IWidget {
@Nullable
public String name;
protected Utilities.Timer timer = new Utilities.Timer();
@@ -38,12 +40,18 @@ public abstract class WTooltip implements IWidget {
@Override
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
if (timer.getTime() > 500) {
List<Pair<String, Boolean>> suffix = getSuffix().stream().map(s -> Utilities.I18n
.search(s.isEmpty() ? join(".", "gui", name) : join(".", "gui", name, s)))
List<Pair<String, Boolean>> suffix = getSuffix().stream()
.map(s -> I18n.search(s.isEmpty() ?
join(".", "gui", name) :
join(".", "gui", name, s)))
.collect(Collectors.toList());
String str = suffix.stream().filter(p -> p.two).findFirst().map(p -> p.one)
String str = suffix.stream()
.filter(p -> p.two)
.findFirst()
.map(p -> p.one)
.orElse(JecaGui.ALWAYS_TOOLTIP ? suffix.get(0).one : null);
if (str != null) Collections.addAll(tooltip, str.split("\n"));
if (str != null)
Collections.addAll(tooltip, str.split("\n"));
}
return false;
}
@@ -1,12 +1,11 @@
package me.towdium.jecalculation.nei;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.HandlerInfo;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import codechicken.nei.recipe.*;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.data.label.ILabel;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import scala.tools.cmd.Opt;
import javax.annotation.Nonnull;
@@ -45,4 +44,20 @@ public class NEIPlugin {
ItemStack itemStack = info.getItemStack();
return Optional.ofNullable(itemStack);
}
public static void openRecipeGui(Object rep, int button) {
if ((rep instanceof ItemStack || rep instanceof FluidStack)) {
String id = rep instanceof ItemStack ? "item" : "liquid";
if (button == 0) {
GuiCraftingRecipe.openRecipeGui(id, rep);
} else if (button == 1) {
GuiUsageRecipe.openRecipeGui(id, rep);
} else {
// TODO check
JustEnoughCalculation.logger.warn("unknown button " + button);
}
} else if (rep != null) {
JustEnoughCalculation.logger.warn("unknown label representation " + rep);
}
}
}
@@ -11,11 +11,11 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.client.ClientCommandHandler;
import org.lwjgl.input.Keyboard;
import static me.towdium.jecalculation.gui.JecaGui.keyOpenGuiCraft;
import static me.towdium.jecalculation.gui.JecaGui.keyOpenGuiMath;
import static org.lwjgl.input.Keyboard.KEY_NONE;
public class ClientHandler {
public static final KeyBinding keyOpenGuiCraft = new KeyBinding("jecalculation.key.gui_craft", KEY_NONE, "jecalculation.key.category");
public static final KeyBinding keyOpenGuiMath = new KeyBinding("jecalculation.key.gui_math", KEY_NONE, "jecalculation.key.category");
public void initPre() {
Handlers.register();
@@ -0,0 +1,27 @@
package me.towdium.jecalculation.polyfill;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* This annotation can be applied to a package, class or method to indicate that
* the method in that element are nonnull by default unless there is:
* <ul>
* <li>An explicit nullness annotation
* <li>The method overrides a method in a superclass (in which case the
* annotation of the corresponding method in the superclass applies)
* <li> there is a default parameter annotation applied to a more tightly nested
* element.
* </ul>
*/
@Documented
@Nonnull
@TypeQualifierDefault(ElementType.METHOD)
// Note: This is a copy of javax.annotation.ParametersAreNonnullByDefault with target changed to METHOD
@Retention(RetentionPolicy.RUNTIME)
public @interface MethodsReturnNonnullByDefault {
}