mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-18 11:19:30 +00:00
chore: clean up
This commit is contained in:
1 parent
ea1eab8685
commit
d6ead4a4e9
22 files changed
+341
-141
No files matched your search
@@ -23,6 +23,7 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
@@ -64,11 +65,11 @@ public class Controller {
|
||||
|
||||
public static void inport(Recipes recipes, String group) {
|
||||
ArrayList<Recipe> buffer = new ArrayList<>();
|
||||
recipes.flatStream(group).forEach(i ->
|
||||
getRecord().flatStream(group).filter(j -> j.one.equals(i.one)).findAny().orElseGet(() -> {
|
||||
buffer.add(i.one);
|
||||
return null;
|
||||
}));
|
||||
recipes.getGroup(group).forEach(i ->
|
||||
getRecord().getGroup(group).stream().filter(j -> j.equals(i)).findAny().orElseGet(() -> {
|
||||
buffer.add(i);
|
||||
return null;
|
||||
}));
|
||||
for (Recipe r : buffer) addRecipe(group, r);
|
||||
}
|
||||
|
||||
@@ -107,18 +108,22 @@ public class Controller {
|
||||
return getRecord().getRecipe(group, index);
|
||||
}
|
||||
|
||||
public static List<Trio<Recipe, String, Integer>> getRecipes() {
|
||||
public static Stream<Pair<String, List<Recipe>>> stream() {
|
||||
return getRecord().stream();
|
||||
}
|
||||
|
||||
public static Recipes.RecipeIterator recipeIterator() {
|
||||
return getRecord().recipeIterator();
|
||||
}
|
||||
|
||||
public static List<Recipe> getRecipes() {
|
||||
return getRecord().getRecipes();
|
||||
}
|
||||
|
||||
public static List<Trio<Recipe, String, Integer>> getRecipes(String group) {
|
||||
public static List<Recipe> getRecipes(String group) {
|
||||
return getRecord().getRecipes(group);
|
||||
}
|
||||
|
||||
public static Optional<Recipe> getRecipe(ILabel label) {
|
||||
return getRecord().getRecipe(label);
|
||||
}
|
||||
|
||||
public static String getAmount() {
|
||||
return amountClient;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ import me.towdium.jecalculation.gui.guis.pickers.PickerSimple;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
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.Wrapper;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -29,7 +27,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -464,7 +461,7 @@ public interface ILabel {
|
||||
public void getToolTip(List<String> existing, boolean detailed) {
|
||||
if (detailed)
|
||||
existing.add(
|
||||
FORMAT_GREY + Utilities.I18n.format("label.common.tooltip.amount", getAmountString(false)));
|
||||
FORMAT_GREY + Utilities.I18n.get("label.common.tooltip.amount", getAmountString(false)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -122,7 +122,7 @@ public class LFluidStack extends ILabel.Impl {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getToolTip(List<String> existing, boolean detailed) {
|
||||
if (detailed) existing.add(FORMAT_GREY +
|
||||
Utilities.I18n.format("label.common.tooltip.amount", Long.toString(getAmount())) + "mB");
|
||||
Utilities.I18n.get("label.common.tooltip.amount", Long.toString(getAmount())) + "mB");
|
||||
existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(fluid));
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class LOreDict extends ILabel.Impl {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getDisplayName() {
|
||||
return Utilities.I18n.format("label.ore_dict.name", name);
|
||||
return Utilities.I18n.get("label.ore_dict.name", name);
|
||||
}
|
||||
|
||||
public static boolean mergeSame(ILabel a, ILabel b) {
|
||||
|
||||
@@ -92,7 +92,7 @@ public class LPlaceholder extends ILabel.Impl {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getDisplayName() {
|
||||
return Utilities.I18n.format("label.placeholder.name", name);
|
||||
return Utilities.I18n.get("label.placeholder.name", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,10 +26,6 @@ public class CostList {
|
||||
labels = new ArrayList<>();
|
||||
}
|
||||
|
||||
public CostList(ILabel label) {
|
||||
labels = Collections.singletonList(label.copy().multiply(-1));
|
||||
}
|
||||
|
||||
public CostList(List<ILabel> labels) {
|
||||
this.labels = labels.stream()
|
||||
.filter(i -> i != ILabel.EMPTY)
|
||||
@@ -43,12 +39,6 @@ public class CostList {
|
||||
merge(new CostList(negative), false, true);
|
||||
}
|
||||
|
||||
|
||||
public CostList(Recipe recipe) {
|
||||
this(Arrays.stream(recipe.getLabel(OUTPUT)).filter(i -> i != ILabel.EMPTY).collect(Collectors.toList()),
|
||||
Arrays.stream(recipe.getLabel(INPUT)).filter(i -> i != ILabel.EMPTY).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public CostList merge(CostList costList, boolean strict, boolean inplace) {
|
||||
CostList ret = inplace ? this : copy();
|
||||
@@ -121,6 +111,7 @@ public class CostList {
|
||||
public class Calculator {
|
||||
ArrayList<Pair<CostList, CostList>> procedure = new ArrayList<>();
|
||||
ArrayList<ILabel> catalysts = new ArrayList<>();
|
||||
Recipes.RecipeIterator iterator = Controller.recipeIterator();
|
||||
private int index;
|
||||
|
||||
public Calculator() throws ArithmeticException {
|
||||
@@ -130,14 +121,20 @@ public class CostList {
|
||||
int count = 0;
|
||||
while (next != null) {
|
||||
CostList original = getCurrent();
|
||||
CostList difference = new CostList(next.one);
|
||||
difference.multiply(next.two);
|
||||
CostList result = original.merge(difference, false, false);
|
||||
if (set.contains(result))
|
||||
next = find(false);
|
||||
List<ILabel> outL = Arrays.stream(next.one.getLabel(OUTPUT))
|
||||
.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());
|
||||
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);
|
||||
else {
|
||||
set.add(result);
|
||||
procedure.add(new Pair<>(result, difference));
|
||||
procedure.add(new Pair<>(result, outC));
|
||||
addCatalyst(next.one.getLabel(Recipe.IO.CATALYST));
|
||||
next = find(true);
|
||||
}
|
||||
@@ -151,14 +148,19 @@ public class CostList {
|
||||
|
||||
@Nullable
|
||||
private Pair<Recipe, Long> find(boolean reset) {
|
||||
index = reset ? 0 : index + 1;
|
||||
if (reset) {
|
||||
index = 0;
|
||||
iterator = Controller.recipeIterator();
|
||||
}
|
||||
List<ILabel> labels = getCurrent().labels;
|
||||
for (; index < labels.size(); index++) {
|
||||
ILabel label = labels.get(index);
|
||||
if (label.getAmount() >= 0)
|
||||
continue;
|
||||
Optional<Recipe> recipe = Controller.getRecipe(label);
|
||||
if (recipe.isPresent()) return new Pair<>(recipe.get(), recipe.get().multiplier(label));
|
||||
if (label.getAmount() >= 0) continue;
|
||||
while (iterator.hasNext()) {
|
||||
Recipe r = iterator.next();
|
||||
if (r.matches(label)) return new Pair<>(r, r.multiplier(label));
|
||||
}
|
||||
iterator = Controller.recipeIterator();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -195,9 +197,8 @@ public class CostList {
|
||||
}
|
||||
|
||||
public List<ILabel> getSteps() {
|
||||
//noinspection OptionalGetWithoutIsPresent
|
||||
List<ILabel> ret = procedure.stream()
|
||||
.map(i -> i.two.labels.stream().filter(l -> l.getAmount() > 0).findFirst().get())
|
||||
.map(i -> i.two.labels.get(0))
|
||||
.collect(Collectors.toList());
|
||||
Collections.reverse(ret);
|
||||
return ret;
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.towdium.jecalculation.data.structure;
|
||||
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.polyfill.NBTHelper;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import me.towdium.jecalculation.utils.wrappers.Trio;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -60,19 +61,8 @@ public class Recipes {
|
||||
return records.size();
|
||||
}
|
||||
|
||||
public Stream<Map.Entry<String, List<Recipe>>> stream() {
|
||||
return records.entrySet().stream();
|
||||
}
|
||||
|
||||
public Stream<Trio<Recipe, String, Integer>> flatStream() {
|
||||
return records.entrySet().stream().flatMap(i ->
|
||||
IntStream.range(0, i.getValue().size()).mapToObj(j ->
|
||||
new Trio<>(i.getValue().get(j), i.getKey(), j)));
|
||||
}
|
||||
|
||||
public Stream<Trio<Recipe, String, Integer>> flatStream(String group) {
|
||||
List<Recipe> l = records.get(group);
|
||||
return IntStream.range(0, l.size()).mapToObj(j -> new Trio<>(l.get(j), group, j));
|
||||
public Stream<Pair<String, List<Recipe>>> stream() {
|
||||
return records.entrySet().stream().map(i -> new Pair<>(i.getKey(), i.getValue()));
|
||||
}
|
||||
|
||||
public void remove(String group, int index) {
|
||||
@@ -85,17 +75,14 @@ public class Recipes {
|
||||
return getGroup(group).get(index);
|
||||
}
|
||||
|
||||
public List<Trio<Recipe, String, Integer>> getRecipes() {
|
||||
return flatStream().collect(Collectors.toCollection(ArrayList::new));
|
||||
public List<Recipe> getRecipes() {
|
||||
return records.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Trio<Recipe, String, Integer>> getRecipes(String group) {
|
||||
return flatStream(group).collect(Collectors.toCollection(ArrayList::new));
|
||||
public List<Recipe> getRecipes(String group) {
|
||||
return records.get(group);
|
||||
}
|
||||
|
||||
public Optional<Recipe> getRecipe(ILabel label) {
|
||||
return flatStream().map(i -> i.one).filter(i -> i.matches(label)).findFirst();
|
||||
}
|
||||
public void forEach(BiConsumer<String, List<Recipe>> consumer) {
|
||||
records.forEach(consumer);
|
||||
}
|
||||
@@ -116,10 +103,34 @@ public class Recipes {
|
||||
|
||||
|
||||
public List<String> getGroups() {
|
||||
return records.keySet().stream().sorted().collect(Collectors.toList());
|
||||
return new ArrayList<>(records.keySet());
|
||||
}
|
||||
|
||||
public NBTTagCompound serialize() {
|
||||
return serialize(records.keySet());
|
||||
}
|
||||
|
||||
public RecipeIterator recipeIterator() {
|
||||
return new RecipeIterator();
|
||||
}
|
||||
|
||||
public class RecipeIterator implements Iterator<Recipe> {
|
||||
Iterator<Map.Entry<String, List<Recipe>>> i = records.entrySet().iterator();
|
||||
Iterator<Recipe> j;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
while (j == null || !j.hasNext()) {
|
||||
if (i.hasNext()) j = i.next().getValue().iterator();
|
||||
else return false;
|
||||
}
|
||||
return j.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe next() {
|
||||
while (j == null || !j.hasNext()) if (i.hasNext()) j = i.next().getValue().iterator();
|
||||
return j.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,11 +35,11 @@ public class GuiCalculator extends WContainer implements IGui {
|
||||
WLabelScroll result = new WLabelScroll(7, 87, 8, 4, WLabel.Mode.RESULT, true);
|
||||
WButton steps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST, "calculator.step")
|
||||
.setListener(i -> setMode(Mode.STEPS));
|
||||
WButton catalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "calculator.catalyst")
|
||||
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, "calculator.output")
|
||||
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, "calculator.input")
|
||||
WButton input = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN, "common.input")
|
||||
.setListener(i -> setMode(Mode.INPUT));
|
||||
WTextField amount = new WTextField(60, 7, 65).setText(Controller.getAmount()).setListener(i -> {
|
||||
Controller.setAmount(i.getText());
|
||||
|
||||
@@ -28,7 +28,7 @@ public class GuiDisambiguation extends IPicker.Impl implements IGui {
|
||||
public GuiDisambiguation(List<List<ILabel>> record) {
|
||||
this.record = record;
|
||||
WSwitcher switcher = new WSwitcher(7, 7, 162, this.record.size()).setListener(i -> setPage(i.getIndex()));
|
||||
ListenerValue<IWidget, ILabel> consumer = (i, v) -> callback.accept(v.copy().multiply(-1));
|
||||
ListenerValue<WLabelScroll, Integer> consumer = (i, v) -> callback.accept(i.get(v).copy().multiply(-1));
|
||||
add(new WPanel());
|
||||
add(new WIcon(7, 48, 18, 54, ICN_LIST, "disambiguation.list"));
|
||||
add(new WIcon(7, 105, 18, 54, ICN_LABEL, "disambiguation.label"));
|
||||
|
||||
@@ -53,8 +53,8 @@ public class GuiImport extends WContainer implements IGui, ISearchable {
|
||||
@Override
|
||||
public void onVisible(JecaGui gui) {
|
||||
data = Controller.discover().stream()
|
||||
.flatMap(i -> i.two.stream().map(j -> new Quad<>(false, i.one, j.getKey(), i.two)))
|
||||
.collect(Collectors.toList());
|
||||
.flatMap(i -> i.two.stream().map(j -> new Quad<>(false, i.one, j.one, i.two)))
|
||||
.collect(Collectors.toList());
|
||||
search.refresh();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ 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.gui.JecaGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.widgets.*;
|
||||
import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
@@ -76,7 +75,7 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
textField.setText("");
|
||||
setNewGroup(false);
|
||||
});
|
||||
WButton buttonNo = new WButtonIcon(26, 33, 20, 20, BTN_NO, "recipe.cancel").setListener(i -> setNewGroup(false));
|
||||
WButton buttonNo = new WButtonIcon(26, 33, 20, 20, BTN_NO, "common.cancel").setListener(i -> setNewGroup(false));
|
||||
WButton buttonNew = new WButtonIcon(7, 33, 20, 20, BTN_NEW, "recipe.new").setListener(i -> setNewGroup(true));
|
||||
|
||||
public GuiRecipe(String group, int index) {
|
||||
@@ -91,12 +90,12 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
|
||||
public GuiRecipe() {
|
||||
addAll(new WHelp("recipe"), new WPanel());
|
||||
add(new WIcon(7, 63, 21, 20, ICN_OUTPUT, "recipe.output"));
|
||||
add(new WIcon(7, 87, 21, 20, ICN_CATALYST, "recipe.catalyst"));
|
||||
add(new WIcon(7, 111, 21, 40, ICN_INPUT, "recipe.input"));
|
||||
add(new WIcon(7, 63, 21, 20, ICN_OUTPUT, "common.output"));
|
||||
add(new WIcon(7, 87, 21, 20, ICN_CATALYST, "common.catalyst"));
|
||||
add(new WIcon(7, 111, 21, 40, ICN_INPUT, "common.input"));
|
||||
add(new WLine(57));
|
||||
addAll(groupInput, groupCatalyst, groupOutput, switcherGroup);
|
||||
if (switcherGroup.getTexts().isEmpty()) switcherGroup.setTemp(Utilities.I18n.format("common.default"));
|
||||
if (switcherGroup.getTexts().isEmpty()) switcherGroup.setTemp(Utilities.I18n.get("gui.common.default"));
|
||||
setNewGroup(false);
|
||||
buttonCopy.setDisabled(true);
|
||||
buttonDel.setDisabled(true);
|
||||
|
||||
@@ -3,8 +3,8 @@ package me.towdium.jecalculation.gui.guis;
|
||||
import me.towdium.jecalculation.data.Controller;
|
||||
import me.towdium.jecalculation.data.structure.Recipe;
|
||||
import me.towdium.jecalculation.gui.JecaGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.widgets.*;
|
||||
import me.towdium.jecalculation.polyfill.google.common.collect.Streams;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Trio;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -13,19 +13,17 @@ import net.minecraft.util.ChatComponentTranslation;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import static me.towdium.jecalculation.gui.Resource.*;
|
||||
import static me.towdium.jecalculation.gui.widgets.WLabel.Mode.PICKER;
|
||||
|
||||
public class GuiSearch extends WContainer implements IGui {
|
||||
List<Trio<Recipe, String, Integer>> content;
|
||||
WSwitcher group;
|
||||
WButton export;
|
||||
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, PICKER, true).setListener((i, v) -> content.stream()
|
||||
.filter(j -> j.one.getRep() == v)
|
||||
.findFirst()
|
||||
.ifPresent(j -> JecaGui.displayGui(true, true, new GuiRecipe(j.two, j.three))));
|
||||
|
||||
List<Trio<Recipe, String, Integer>> recipes;
|
||||
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, PICKER, true).setListener((i, v) ->
|
||||
JecaGui.displayGui(true, true, new GuiRecipe(recipes.get(v).two, recipes.get(v).three)));
|
||||
|
||||
public GuiSearch() {
|
||||
add(new WPanel());
|
||||
@@ -36,25 +34,34 @@ public class GuiSearch extends WContainer implements IGui {
|
||||
add(labels);
|
||||
}
|
||||
|
||||
private void generate() {
|
||||
if (group.getIndex() == 0) {
|
||||
recipes = Controller.stream()
|
||||
.flatMap(i -> Streams.mapWithIndex(i.two.stream(), (j, k) -> new Trio<>(j, i.one, (int) k)))
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
String s = group.getText();
|
||||
recipes = Streams.mapWithIndex(Controller.getRecipes(s).stream(), (i, j) -> new Trio<>(i, s, (int) j))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void refresh() {
|
||||
int iGroup = group.getIndex();
|
||||
content = iGroup == 0 ? Controller.getRecipes() : Controller.getRecipes(group.getText());
|
||||
labels.setLabels(content.stream().map(i -> i.one.getRep()).collect(Collectors.toCollection(ArrayList::new)));
|
||||
remove(export);
|
||||
String tooltip, name;
|
||||
List<Trio<Recipe, String, Integer>> recipes;
|
||||
if (iGroup == 0) {
|
||||
String tooltip;
|
||||
Supplier<File> func;
|
||||
generate();
|
||||
if (group.getIndex() == 0) {
|
||||
tooltip = "search.export_all";
|
||||
name = null;
|
||||
recipes = Controller.getRecipes();
|
||||
func = Controller::export;
|
||||
} else {
|
||||
tooltip = "search.export_group";
|
||||
name = Controller.getGroups().get(iGroup - 1);
|
||||
recipes = Controller.getRecipes(name);
|
||||
func = () -> Controller.export(group.getText());
|
||||
}
|
||||
labels.setLabels(recipes.stream().map(i -> i.one.getRep()).collect(Collectors.toList()));
|
||||
export = new WButtonIcon(149, 25, 20, 20, BTN_OUT, tooltip).setListener(i -> {
|
||||
File f = iGroup == 0 ? Controller.export() : Controller.export(name);
|
||||
File f = func.get();
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation(
|
||||
"jecalculation.chat.export", f.getAbsolutePath()));
|
||||
}).setDisabled(recipes.size() == 0);
|
||||
@@ -65,7 +72,7 @@ public class GuiSearch extends WContainer implements IGui {
|
||||
public void onVisible(JecaGui gui) {
|
||||
removeAll(group);
|
||||
ArrayList<String> groups = new ArrayList<>();
|
||||
groups.add(Utilities.I18n.format("gui.search.all"));
|
||||
groups.add(Utilities.I18n.get("gui.search.all"));
|
||||
groups.addAll(Controller.getGroups());
|
||||
int index = group == null ? 0 : group.getIndex();
|
||||
if (index >= groups.size()) index = groups.size() - 1;
|
||||
|
||||
@@ -23,14 +23,14 @@ import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
|
||||
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(v));
|
||||
.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));
|
||||
add(new WSearch(26, 45, 90, scroll));
|
||||
add(new WIcon(7, 45, 20, 20, ICN_TEXT, "picker_placeholder.text_search"));
|
||||
add(new WIcon(7, 7, 20, 20, ICN_TEXT, "picker_placeholder.text_create"));
|
||||
add(new 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).setListener(i -> {
|
||||
add(new WButtonIcon(95, 7, 20, 20, BTN_YES, "common.confirm").setListener(i -> {
|
||||
if (!create.getText().equals("")) callback.accept(new LPlaceholder(create.getText(), 1));
|
||||
}));
|
||||
addAll(scroll, create);
|
||||
|
||||
@@ -27,29 +27,26 @@ import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
|
||||
public class PickerSimple extends IPicker.Impl implements IGui {
|
||||
/**
|
||||
* @param labels label to be displayed for selection
|
||||
* @param l18nKey localization key for help string,
|
||||
* entire key should be "gui.l18nKey.help.tooltip"
|
||||
*/
|
||||
public PickerSimple(List<ILabel> labels, String l18nKey) {
|
||||
public PickerSimple(List<ILabel> labels) {
|
||||
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, WLabel.Mode.PICKER, true).setLabels(labels)
|
||||
.setListener((i, v) -> notifyLsnr(v));
|
||||
.setListener((i, v) -> notifyLsnr(i.get(v)));
|
||||
add(new WSearch(26, 7, 90, ls));
|
||||
add(new WIcon(7, 7, 20, 20, ICN_TEXT, l18nKey + ".text"));
|
||||
add(new WIcon(7, 7, 20, 20, ICN_TEXT, "common.search"));
|
||||
add(ls);
|
||||
}
|
||||
|
||||
|
||||
public static class FluidStack extends PickerSimple {
|
||||
public FluidStack() {
|
||||
super(FluidRegistry.getRegisteredFluids().values().stream()
|
||||
.map(fluid -> new LFluidStack(1000, fluid)).collect(Collectors.toList()),
|
||||
"picker_fluid_stack");
|
||||
super(FluidRegistry.getRegisteredFluids().entrySet().stream()
|
||||
.map(e -> new LFluidStack(1000, e.getValue())).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class OreDict extends PickerSimple {
|
||||
public OreDict() {
|
||||
super(generate(), "picker_ore_dict");
|
||||
super(generate());
|
||||
}
|
||||
|
||||
static List<ILabel> generate() {
|
||||
|
||||
@@ -9,7 +9,6 @@ import me.towdium.jecalculation.utils.ClientUtils;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static me.towdium.jecalculation.gui.Resource.*;
|
||||
@@ -83,6 +82,6 @@ public abstract class WButton extends WTooltip {
|
||||
|
||||
@Override
|
||||
protected List<String> getSuffix() {
|
||||
return disabled ? Arrays.asList("disabled", "active") : Collections.singletonList("active");
|
||||
return disabled ? Arrays.asList("disabled", "active", "") : Arrays.asList("active", "");
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public class WHelp extends WTooltip {
|
||||
|
||||
@Override
|
||||
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
|
||||
super.onDraw(gui, xMouse, yMouse);
|
||||
gui.drawResourceContinuous(WGT_PANEL_N, -21, 0, 25, 24, 4);
|
||||
gui.drawResource(WGT_HELP_N, -19, 2);
|
||||
}
|
||||
@@ -49,7 +50,7 @@ public class WHelp extends WTooltip {
|
||||
Text tContent = new Text();
|
||||
WSwitcher sPage = new WSwitcher(7, 146, 162, tContent.amount());
|
||||
sPage.setListener(i -> tContent.setPage(i.getIndex()));
|
||||
WText tTitle = new WText(7, 7, SHADOW, I18n.format("gui." + WHelp.this.key + ".title"));
|
||||
WText tTitle = new WText(7, 7, SHADOW, I18n.get("gui." + WHelp.this.key + ".title"));
|
||||
addAll(new WPanel(), new Icon(), tTitle, tContent, sPage);
|
||||
}
|
||||
|
||||
@@ -65,7 +66,7 @@ public class WHelp extends WTooltip {
|
||||
int page;
|
||||
|
||||
public Text() {
|
||||
List<String> ss = I18n.wrap(I18n.format("gui." + WHelp.this.key + ".help"), 162);
|
||||
List<String> ss = I18n.wrap(I18n.get("gui." + WHelp.this.key + ".help"), 162);
|
||||
List<String> tmp = new ArrayList<>();
|
||||
int count = 0;
|
||||
for (String s : ss) {
|
||||
@@ -109,10 +110,17 @@ public class WHelp extends WTooltip {
|
||||
|
||||
@Override
|
||||
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
|
||||
super.onDraw(gui, xMouse, yMouse);
|
||||
gui.drawResourceContinuous(WGT_HELP_B, -21, 0, 25, 24, 4);
|
||||
gui.drawResource(WGT_HELP_F, -19, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
|
||||
super.onTooltip(gui, xMouse, yMouse, tooltip);
|
||||
return mouseIn(xMouse, yMouse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
|
||||
boolean ret = mouseIn(xMouse, yMouse);
|
||||
|
||||
@@ -25,7 +25,7 @@ public class WLabelScroll extends WContainer implements ISearchable {
|
||||
protected WScroll scroll;
|
||||
protected int xPos, yPos, column, row, current;
|
||||
protected String filter = "";
|
||||
protected ListenerValue<? super WLabelScroll, ILabel> listener;
|
||||
protected ListenerValue<? super WLabelScroll, Integer> listener;
|
||||
|
||||
public WLabelScroll(int xPos, int yPos, int column, int row, WLabel.Mode mode, boolean drawConnection) {
|
||||
this.xPos = xPos;
|
||||
@@ -33,7 +33,7 @@ public class WLabelScroll extends WContainer implements ISearchable {
|
||||
this.column = column;
|
||||
this.row = row;
|
||||
labelGroup = new WLabelGroup(xPos, yPos, column, row, mode).setListener((i, v) -> {
|
||||
if (listener != null) listener.invoke(this, i.get(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()));
|
||||
add(labelGroup);
|
||||
@@ -61,6 +61,10 @@ public class WLabelScroll extends WContainer implements ISearchable {
|
||||
return in;
|
||||
}
|
||||
|
||||
public ILabel get(int index) {
|
||||
return filtered.get(index);
|
||||
}
|
||||
|
||||
private float getPos(int step) {
|
||||
return 1f / (getStepAmount() - 1) * step;
|
||||
}
|
||||
@@ -81,7 +85,7 @@ public class WLabelScroll extends WContainer implements ISearchable {
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public WLabelScroll setListener(ListenerValue<? super WLabelScroll, ILabel> listener) {
|
||||
public WLabelScroll setListener(ListenerValue<? super WLabelScroll, Integer> listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,11 @@ public class WPage extends WTooltip {
|
||||
super.onDraw(gui, xMouse, yMouse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
|
||||
return super.onTooltip(gui, xMouse, yMouse, tooltip) || mouseIn(xMouse, yMouse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
|
||||
boolean ret = JecaGui.mouseIn(index * 24, -21, 24, 21, xMouse, yMouse) && listener != null && !focused;
|
||||
|
||||
@@ -4,11 +4,15 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.gui.JecaGui;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.lang.String.join;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
@@ -27,22 +31,26 @@ public abstract class WTooltip implements IWidget {
|
||||
|
||||
@Override
|
||||
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
|
||||
if (name != null) timer.setState(mouseIn(xMouse, yMouse));
|
||||
if (name != null)
|
||||
timer.setState(mouseIn(xMouse, yMouse));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List<String> tooltip) {
|
||||
if (timer.getTime() > 500) {
|
||||
String str = getSuffix().stream().map(s -> Utilities.I18n.search(String.join(".", "gui", name, s)))
|
||||
.filter(p -> p.two).findFirst().map(p -> p.one)
|
||||
.orElse(JecaGui.ALWAYS_TOOLTIP ? String.join(".", "gui", name, getSuffix().get(0)) : null);
|
||||
if (str != null) tooltip.add(str);
|
||||
List<Pair<String, Boolean>> suffix = getSuffix().stream().map(s -> Utilities.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)
|
||||
.orElse(JecaGui.ALWAYS_TOOLTIP ? suffix.get(0).one : null);
|
||||
if (str != null)
|
||||
tooltip.add(str);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected List<String> getSuffix() {
|
||||
return Collections.singletonList("tooltip");
|
||||
return Collections.singletonList("");
|
||||
}
|
||||
|
||||
public abstract boolean mouseIn(int xMouse, int yMouse);
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package me.towdium.jecalculation.polyfill.google.common.collect;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Spliterator;
|
||||
import java.util.Spliterators;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class Streams {
|
||||
public interface FunctionWithIndex<T, R> {
|
||||
/** Applies this function to the given argument and its index within a stream. */
|
||||
R apply(T from, long index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream consisting of the results of applying the given function to the elements of
|
||||
* {@code stream} and their indices in the stream. For example,
|
||||
*
|
||||
* <pre>{@code
|
||||
* mapWithIndex(
|
||||
* Stream.of("a", "b", "c"),
|
||||
* (str, index) -> str + ":" + index)
|
||||
* }</pre>
|
||||
*
|
||||
* <p>would return {@code Stream.of("a:0", "b:1", "c:2")}.
|
||||
*
|
||||
* <p>The resulting stream is <a
|
||||
* href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a>
|
||||
* if and only if {@code stream} was efficiently splittable and its underlying spliterator
|
||||
* reported {@link Spliterator#SUBSIZED}. This is generally the case if the underlying stream
|
||||
* comes from a data structure supporting efficient indexed random access, typically an array or
|
||||
* list.
|
||||
*
|
||||
* <p>The order of the resulting stream is defined if and only if the order of the original stream
|
||||
* was defined.
|
||||
*/
|
||||
public static <T, R> Stream<R> mapWithIndex(
|
||||
Stream<T> stream, FunctionWithIndex<? super T, ? extends R> function) {
|
||||
checkNotNull(stream);
|
||||
checkNotNull(function);
|
||||
boolean isParallel = stream.isParallel();
|
||||
Spliterator<T> fromSpliterator = stream.spliterator();
|
||||
|
||||
if (!fromSpliterator.hasCharacteristics(Spliterator.SUBSIZED)) {
|
||||
Iterator<T> fromIterator = Spliterators.iterator(fromSpliterator);
|
||||
return StreamSupport.stream(
|
||||
new Spliterators.AbstractSpliterator<R>(
|
||||
fromSpliterator.estimateSize(),
|
||||
fromSpliterator.characteristics() & (Spliterator.ORDERED | Spliterator.SIZED)) {
|
||||
long index = 0;
|
||||
|
||||
@Override
|
||||
public boolean tryAdvance(Consumer<? super R> action) {
|
||||
if (fromIterator.hasNext()) {
|
||||
action.accept(function.apply(fromIterator.next(), index++));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
isParallel);
|
||||
}
|
||||
class Splitr extends MapWithIndexSpliterator<Spliterator<T>, R, Splitr> implements Consumer<T> {
|
||||
T holder;
|
||||
|
||||
Splitr(Spliterator<T> splitr, long index) {
|
||||
super(splitr, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@Nullable T t) {
|
||||
this.holder = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryAdvance(Consumer<? super R> action) {
|
||||
if (fromSpliterator.tryAdvance(this)) {
|
||||
try {
|
||||
action.accept(function.apply(holder, index++));
|
||||
return true;
|
||||
} finally {
|
||||
holder = null;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
Splitr createSplit(Spliterator<T> from, long i) {
|
||||
return new Splitr(from, i);
|
||||
}
|
||||
}
|
||||
return StreamSupport.stream(new Splitr(fromSpliterator, 0), isParallel);
|
||||
}
|
||||
|
||||
private abstract static class MapWithIndexSpliterator<
|
||||
F extends Spliterator<?>, R, S extends MapWithIndexSpliterator<F, R, S>>
|
||||
implements Spliterator<R> {
|
||||
final F fromSpliterator;
|
||||
long index;
|
||||
|
||||
MapWithIndexSpliterator(F fromSpliterator, long index) {
|
||||
this.fromSpliterator = fromSpliterator;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
abstract S createSplit(F from, long i);
|
||||
|
||||
@Override
|
||||
public S trySplit() {
|
||||
@SuppressWarnings("unchecked")
|
||||
F split = (F) fromSpliterator.trySplit();
|
||||
if (split == null) {
|
||||
return null;
|
||||
}
|
||||
S result = createSplit(split, index);
|
||||
this.index += split.getExactSizeIfKnown();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long estimateSize() {
|
||||
return fromSpliterator.estimateSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int characteristics() {
|
||||
return fromSpliterator.characteristics()
|
||||
& (Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,9 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
@@ -24,7 +26,6 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.BreakIterator;
|
||||
import java.text.DecimalFormat;
|
||||
@@ -36,6 +37,8 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import static net.minecraft.client.resources.I18n.format;
|
||||
|
||||
/**
|
||||
* Author: Towdium
|
||||
* Date: 2016/6/25.
|
||||
@@ -45,16 +48,19 @@ import java.util.stream.StreamSupport;
|
||||
public class Utilities {
|
||||
// FLOAT FORMATTING
|
||||
public static char[] suffix = new char[]{'K', 'M', 'B', 'G', 'T'};
|
||||
public static DecimalFormat[] format = new DecimalFormat[]{
|
||||
new DecimalFormat("#."), new DecimalFormat("#.#"), new DecimalFormat("#.##"),
|
||||
new DecimalFormat("#.###"), new DecimalFormat("#.####")
|
||||
};
|
||||
public static DecimalFormat[] format = new DecimalFormat[]{new DecimalFormat("#."),
|
||||
new DecimalFormat("#.#"),
|
||||
new DecimalFormat("#.##"),
|
||||
new DecimalFormat("#.###"),
|
||||
new DecimalFormat("#.####")};
|
||||
|
||||
public static String cutNumber(float f, int size) {
|
||||
BiFunction<Float, Integer, String> form = (fl, len) -> format[len - 1 - (int) Math.log10(fl)].format(fl);
|
||||
int scale = (int) Math.log10(f) / 3;
|
||||
if (scale == 0) return form.apply(f, size);
|
||||
else return form.apply(f / (float) Math.pow(1000, scale), size - 1) + suffix[scale - 1];
|
||||
if (scale == 0)
|
||||
return form.apply(f, size);
|
||||
else
|
||||
return form.apply(f / (float) Math.pow(1000, scale), size - 1) + suffix[scale - 1];
|
||||
}
|
||||
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
@@ -103,7 +109,7 @@ public class Utilities {
|
||||
@Nullable
|
||||
public V get(K a, K b) {
|
||||
V ret = data.get(new Pair<>(a, b));
|
||||
if (ret == null) data.get(new Pair<>(b, a));
|
||||
if (ret == null) ret = data.get(new Pair<>(b, a));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -212,14 +218,14 @@ public class Utilities {
|
||||
public static Pair<String, Boolean> search(String translateKey, Object... parameters) {
|
||||
Pair<String, Boolean> ret = new Pair<>(null, null);
|
||||
translateKey = "jecalculation." + translateKey;
|
||||
String buffer = net.minecraft.client.resources.I18n.format(translateKey, parameters);
|
||||
String buffer = format(translateKey, parameters);
|
||||
ret.two = !buffer.equals(translateKey);
|
||||
buffer = StringEscapeUtils.unescapeJava(buffer);
|
||||
ret.one = buffer.replace("\t", " ");
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String format(String translateKey, Object... parameters) {
|
||||
public static String get(String translateKey, Object... parameters) {
|
||||
return search(translateKey, parameters).one;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user