mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-18 19:29:05 +00:00
fix
This commit is contained in:
1 parent
7f525ce264
commit
1d70f6bce9
25 files changed
+534
-252
No files matched your search
@@ -28,6 +28,6 @@ public class CCraft implements ISubCommand {
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) {
|
||||
Controller.openGuiCraft();
|
||||
Controller.openGuiCraft(true);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,6 @@ public class CMath implements ISubCommand {
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) {
|
||||
Controller.openGuiMath();
|
||||
Controller.openGuiMath(true);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -76,25 +77,24 @@ public class Controller {
|
||||
|
||||
public static void inport(Recipes recipes, String group) {
|
||||
ArrayList<Recipe> buffer = new ArrayList<>();
|
||||
recipes.getGroup(group)
|
||||
.forEach(i -> getRecipes().getGroup(group).stream().filter(j -> j.equals(i)).findAny().orElseGet(() -> {
|
||||
buffer.add(i);
|
||||
return null;
|
||||
}));
|
||||
recipes.getGroup(group).stream().filter(i -> !hasDuplicate(i)).forEach(buffer::add);
|
||||
for (Recipe r : buffer)
|
||||
addRecipe(group, r);
|
||||
}
|
||||
|
||||
public static File export(String group) {
|
||||
File f = JecaConfig.getDataFile(group);
|
||||
Utilities.Json.write(getRecipes().serialize(Collections.singleton(group)), f);
|
||||
return f;
|
||||
private static void export(String s, Function<Recipes, NBTTagCompound> r) {
|
||||
File f = JecaConfig.getDataFile(s);
|
||||
Utilities.Json.write(r.apply(getRecipes()), f);
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation(
|
||||
"jecalculation.chat.export", f.getAbsolutePath()));
|
||||
}
|
||||
|
||||
public static File export() {
|
||||
File f = JecaConfig.getDataFile("groups");
|
||||
Utilities.Json.write(getRecipes().serialize(), f);
|
||||
return f;
|
||||
public static void export(String group) {
|
||||
export(group, i -> i.serialize(Collections.singleton(group)));
|
||||
}
|
||||
|
||||
public static void export() {
|
||||
export("groups", Recipes::serialize);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -104,13 +104,25 @@ public class Controller {
|
||||
|
||||
static void setLast(String last) {
|
||||
if (isServerActive()) rPlayerServer.last = last;
|
||||
else rPlayerServer.last = last;
|
||||
else rPlayerClient.last = last;
|
||||
}
|
||||
|
||||
public static List<String> getGroups() {
|
||||
return getRecipes().getGroups();
|
||||
}
|
||||
|
||||
public static void setRecipe(String neu, String old, int index, Recipe recipe) {
|
||||
getRecipes().set(neu, old, index, recipe);
|
||||
setLast(neu);
|
||||
writeToLocal();
|
||||
}
|
||||
|
||||
public static void renameGroup(String old, String neu) {
|
||||
getRecipes().renameGroup(old, neu);
|
||||
setLast(neu);
|
||||
writeToLocal();
|
||||
}
|
||||
|
||||
public static void addRecipe(String group, Recipe recipe) {
|
||||
getRecipes().add(group, recipe);
|
||||
setLast(group);
|
||||
@@ -146,28 +158,59 @@ public class Controller {
|
||||
}
|
||||
|
||||
public static void setRMath(RecordMath math) {
|
||||
rMathClient = math;
|
||||
}
|
||||
|
||||
public static RecordCraft getRCraft() {
|
||||
return rCraftClient;
|
||||
|
||||
setR(math, i -> rMathClient = i, KEY_MATH);
|
||||
}
|
||||
|
||||
public static void setRCraft(RecordCraft rc) {
|
||||
rCraftClient = rc;
|
||||
setR(rc, i -> rCraftClient = i, KEY_CRAFT);
|
||||
}
|
||||
|
||||
public static RecordCraft getRCraft() {
|
||||
return getR(rCraftClient, KEY_CRAFT, RecordCraft::new);
|
||||
}
|
||||
|
||||
public static RecordMath getRMath() {
|
||||
return rMathClient;
|
||||
return getR(rMathClient, KEY_MATH, RecordMath::new);
|
||||
}
|
||||
|
||||
private static <T extends IRecord> void setR(T t, Consumer<T> c, String s) {
|
||||
if (!isServerActive()) c.accept(t);
|
||||
else {
|
||||
Optional<ItemStack> ois = getStack();
|
||||
ois.ifPresent(is -> {
|
||||
Utilities.getTag(is).setTag(s, t.serialize());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getR(T t, String s, Function<NBTTagCompound, T> f) {
|
||||
if (!isServerActive()) return t;
|
||||
else return f.apply(getStack()
|
||||
.map(i -> Utilities.getTag(i).getCompoundTag(s))
|
||||
.orElse(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if recipe has duplications, except the recipe at group->index
|
||||
*
|
||||
* @param r Recipe to check
|
||||
* @param group Group exclusive
|
||||
* @param index Index exclusive
|
||||
* @return if duplicate found
|
||||
*/
|
||||
public static boolean hasDuplicate(Recipe r, String group, int index) {
|
||||
Recipes.RecipeIterator ri = recipeIterator();
|
||||
return ri.stream().anyMatch(i -> {
|
||||
if (ri.getIndex() == index && ri.getGroup().equals(group)) return false;
|
||||
else return i.equals(r);
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean hasDuplicate(Recipe r) {
|
||||
return getRecipes().hasDuplicate(r);
|
||||
return recipeIterator().stream().anyMatch(i -> i.equals(r));
|
||||
}
|
||||
|
||||
|
||||
public static void loadFromLocal() {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
JecaConfig.dataDir.mkdirs();
|
||||
@@ -194,15 +237,25 @@ public class Controller {
|
||||
}
|
||||
|
||||
public static void openGuiCraft() {
|
||||
if (!Controller.isServerActive()) JecaGui.displayGui(true, true, new GuiCraft());
|
||||
else Minecraft.getMinecraft().thePlayer.addChatMessage(
|
||||
new ChatComponentTranslation("jecalculation.chat.server_mode"));
|
||||
openGuiCraft(false);
|
||||
}
|
||||
|
||||
public static void openGuiMath() {
|
||||
if (!Controller.isServerActive()) JecaGui.displayGui(true, true, new GuiMath());
|
||||
openGuiMath(false);
|
||||
}
|
||||
|
||||
public static void openGuiCraft(boolean scheduled) {
|
||||
if (!Controller.isServerActive()) JecaGui.displayGui(true, true, scheduled, new GuiCraft());
|
||||
else Minecraft.getMinecraft().thePlayer.addChatMessage(
|
||||
new ChatComponentTranslation("jecalculation.chat.server_mode"));
|
||||
}
|
||||
|
||||
|
||||
public static void openGuiMath(boolean scheduled) {
|
||||
if (!Controller.isServerActive()) JecaGui.displayGui(true, true, scheduled, new GuiMath());
|
||||
else Minecraft.getMinecraft().thePlayer.addChatMessage(
|
||||
new ChatComponentTranslation("jecalculation.chat.server_mode"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package me.towdium.jecalculation.data.structure;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Author: Towdium
|
||||
* Date: 05/02/19
|
||||
*/
|
||||
public interface IRecord {
|
||||
NBTTagCompound serialize();
|
||||
}
|
||||
@@ -22,8 +22,7 @@ import java.util.stream.StreamSupport;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public class Recipes {
|
||||
LinkedHashMap<String, List<Recipe>> records = new LinkedHashMap<>();
|
||||
HashSet<Recipe> cache = new HashSet<>();
|
||||
HashMap<String, List<Recipe>> records = new HashMap<>();
|
||||
|
||||
public Recipes() {
|
||||
File file = JecaConfig.defaultFile;
|
||||
@@ -57,19 +56,32 @@ public class Recipes {
|
||||
|
||||
public void add(String group, Recipe recipe) {
|
||||
records.computeIfAbsent(group, k -> new ArrayList<>()).add(recipe);
|
||||
cache.add(recipe);
|
||||
}
|
||||
|
||||
public void modify(String group, int index, @Nullable Recipe recipe) {
|
||||
if (index == -1 && recipe != null) add(group, recipe);
|
||||
else if (recipe == null) remove(group, index);
|
||||
else set(group, index, recipe);
|
||||
public void renameGroup(String old, String neu) {
|
||||
List<Recipe> rs = records.get(old);
|
||||
records.remove(old);
|
||||
records.put(neu, rs);
|
||||
}
|
||||
|
||||
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 {
|
||||
if (recipe == null) remove(neu, index);
|
||||
else if (old == null || old.equals(neu)) set(neu, index, recipe);
|
||||
else set(neu, old, index, recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(String group, int index, Recipe recipe) {
|
||||
Recipe r = records.get(group).set(index, recipe);
|
||||
cache.remove(r);
|
||||
cache.add(recipe);
|
||||
records.get(group).set(index, recipe);
|
||||
}
|
||||
|
||||
public void set(String neu, String old, int index, Recipe recipe) {
|
||||
remove(old, index);
|
||||
add(neu, recipe);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
@@ -82,7 +94,7 @@ public class Recipes {
|
||||
|
||||
public void remove(String group, int index) {
|
||||
List<Recipe> l = records.get(group);
|
||||
cache.remove(l.remove(index));
|
||||
l.remove(index);
|
||||
if (l.isEmpty()) records.remove(group);
|
||||
}
|
||||
|
||||
@@ -114,7 +126,7 @@ public class Recipes {
|
||||
|
||||
public NBTTagCompound serialize(Collection<String> groups) {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
groups.stream().sorted().forEach(i -> {
|
||||
groups.forEach(i -> {
|
||||
NBTTagList l = new NBTTagList();
|
||||
getGroup(i).forEach(r -> l.appendTag(r.serialize()));
|
||||
ret.setTag(i, l);
|
||||
@@ -122,13 +134,12 @@ public class Recipes {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getGroups() {
|
||||
return new ArrayList<>(records.keySet());
|
||||
return records.keySet().stream().sorted().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public NBTTagCompound serialize() {
|
||||
return serialize(records.keySet());
|
||||
return serialize(getGroups());
|
||||
}
|
||||
|
||||
public RecipeIterator recipeIterator() {
|
||||
@@ -140,40 +151,50 @@ public class Recipes {
|
||||
}
|
||||
|
||||
public class RecipeIterator implements Iterator<Recipe> {
|
||||
Iterator<Map.Entry<String, List<Recipe>>> i;
|
||||
String group;
|
||||
int index;
|
||||
Iterator<String> i;
|
||||
Iterator<Recipe> j;
|
||||
|
||||
public RecipeIterator() {
|
||||
i = records.entrySet().iterator();
|
||||
i = getGroups().iterator();
|
||||
}
|
||||
|
||||
public RecipeIterator(String group) {
|
||||
HashMap<String, List<Recipe>> tmp = new HashMap<>();
|
||||
tmp.put(group, records.get(group));
|
||||
i = tmp.entrySet().iterator();
|
||||
i = Collections.singleton(group).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
while (j == null || !j.hasNext()) {
|
||||
if (i.hasNext()) j = i.next().getValue().iterator();
|
||||
else return false;
|
||||
if (i.hasNext()) {
|
||||
group = i.next();
|
||||
List<Recipe> rs = records.get(group);
|
||||
index = rs.size();
|
||||
j = new Utilities.ReversedIterator<>(rs);
|
||||
} else return false;
|
||||
}
|
||||
return j.hasNext();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe next() {
|
||||
while (j == null || !j.hasNext()) if (i.hasNext()) j = i.next().getValue().iterator();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
hasNext();
|
||||
index--;
|
||||
return j.next();
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public Stream<Recipe> stream() {
|
||||
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(this, Spliterator.ORDERED), false);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasDuplicate(Recipe r) {
|
||||
return cache.contains(r);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,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.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -14,7 +15,7 @@ import java.util.stream.StreamSupport;
|
||||
* Author: Towdium
|
||||
* Date: 19-1-20
|
||||
*/
|
||||
public class RecordCraft {
|
||||
public class RecordCraft implements IRecord {
|
||||
public static final String KEY_RECENTS = "recents";
|
||||
public static final String KEY_AMOUNT = "amount";
|
||||
public static final String KEY_INVENTORY = "inventory";
|
||||
@@ -25,7 +26,7 @@ public class RecordCraft {
|
||||
public boolean inventory;
|
||||
|
||||
public RecordCraft(NBTTagCompound nbt) {
|
||||
List<ILabel> ls = StreamSupport.stream(nbt.getTagList(KEY_RECENTS, 10).spliterator(), false)
|
||||
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());
|
||||
@@ -46,6 +47,7 @@ public class RecordCraft {
|
||||
return record.size() > 1 ? record.toList().subList(1, record.size()) : new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serialize() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
ret.setBoolean(KEY_INVENTORY, inventory);
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.List;
|
||||
* Author: Towdium
|
||||
* Date: 19-1-20
|
||||
*/
|
||||
public class RecordMath {
|
||||
public class RecordMath implements IRecord {
|
||||
public static MathContext context = new MathContext(7, RoundingMode.HALF_UP);
|
||||
public static final int DOT_NONE = -1;
|
||||
static final String KEY_CURRENT = "current";
|
||||
@@ -62,6 +62,7 @@ public class RecordMath {
|
||||
current = nbt.getString(KEY_CURRENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serialize() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
ret.setString(KEY_CURRENT, current);
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
* Author: Towdium
|
||||
* Date: 19-1-21
|
||||
*/
|
||||
public class RecordPlayer {
|
||||
public class RecordPlayer implements IRecord {
|
||||
public static final String KEY_RECIPES = "recipes";
|
||||
public static final String KEY_LAST = "last";
|
||||
|
||||
@@ -22,6 +22,7 @@ public class RecordPlayer {
|
||||
last = nbt.getString(KEY_LAST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serialize() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
if (last != null) ret.setString(KEY_LAST, last);
|
||||
|
||||
@@ -3,6 +3,7 @@ package me.towdium.jecalculation.event.handlers;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
@@ -31,5 +32,13 @@ public class FMLBusEventHandler {
|
||||
Controller.writeToLocal();
|
||||
LPlaceholder.onLogOut();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGameTick(TickEvent.PlayerTickEvent e) {
|
||||
if (e.player.worldObj.isRemote) {
|
||||
JecaGui.onGameTick();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ public class JecaGui extends GuiContainer {
|
||||
public static final boolean ALWAYS_TOOLTIP = false;
|
||||
public ILabel hand = ILabel.EMPTY;
|
||||
protected static JecaGui last;
|
||||
protected static Runnable scheduled;
|
||||
protected static int timeout;
|
||||
protected JecaGui parent;
|
||||
public IGui root;
|
||||
|
||||
@@ -73,9 +75,19 @@ public class JecaGui extends GuiContainer {
|
||||
}
|
||||
|
||||
public static void displayGui(boolean updateParent, boolean acceptsTransfer, IGui root) {
|
||||
// isCallingFromMinecraftThread
|
||||
if (Minecraft.getMinecraft().func_152345_ab())
|
||||
displayGuiUnsafe(updateParent, acceptsTransfer, root);
|
||||
displayGui(updateParent, acceptsTransfer, false, root);
|
||||
}
|
||||
|
||||
public static void displayGui(boolean updateParent, boolean acceptsTransfer, boolean scheduled, IGui root) {
|
||||
Runnable r = () -> {
|
||||
// isCallingFromMinecraftThread
|
||||
if (Minecraft.getMinecraft().func_152345_ab())
|
||||
displayGuiUnsafe(updateParent, acceptsTransfer, root);
|
||||
};
|
||||
if (scheduled) {
|
||||
JecaGui.scheduled = r;
|
||||
JecaGui.timeout = 2;
|
||||
} else r.run();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,6 +131,16 @@ public class JecaGui extends GuiContainer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void onGameTick() {
|
||||
if (scheduled != null) {
|
||||
if (timeout <= 0) {
|
||||
Runnable r = scheduled;
|
||||
scheduled = null;
|
||||
r.run();
|
||||
} else timeout--;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isShiftDown() {
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
}
|
||||
@@ -334,7 +356,7 @@ public class JecaGui extends GuiContainer {
|
||||
|
||||
private void drawText(float xPos, float yPos, Font f, Runnable r) {
|
||||
boolean unicode = fontRendererObj.getUnicodeFlag();
|
||||
if (f.half) fontRendererObj.setUnicodeFlag(false);
|
||||
if (f.raw) fontRendererObj.setUnicodeFlag(false);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(xPos, yPos, 0);
|
||||
if (f.half) GlStateManager.scale(0.5, 0.5, 1);
|
||||
@@ -379,23 +401,25 @@ public class JecaGui extends GuiContainer {
|
||||
}
|
||||
|
||||
public static class Font {
|
||||
public static final Font SHADOW = new Font(JecaGui.COLOR_TEXT_WHITE, true, false);
|
||||
public static final Font PLAIN = new Font(JecaGui.COLOR_TEXT_GREY, false, false);
|
||||
public static final Font HALF = new Font(JecaGui.COLOR_TEXT_WHITE, true, true);
|
||||
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);
|
||||
public static final Font RAW = new Font(JecaGui.COLOR_TEXT_GREY, false, false, true);
|
||||
public static final Font HALF = new Font(JecaGui.COLOR_TEXT_WHITE, true, true, true);
|
||||
|
||||
public int color;
|
||||
public boolean shadow, half;
|
||||
public boolean shadow, half, raw;
|
||||
|
||||
public Font(int color, boolean shadow, boolean half) {
|
||||
public Font(int color, boolean shadow, boolean half, boolean raw) {
|
||||
this.color = color;
|
||||
this.shadow = shadow;
|
||||
this.half = half;
|
||||
this.raw = raw;
|
||||
}
|
||||
|
||||
public int getTextWidth(String s) {
|
||||
FontRenderer fr = getCurrent().fontRendererObj;
|
||||
boolean flag = fr.getUnicodeFlag();
|
||||
if (half) fr.setUnicodeFlag(false);
|
||||
if (raw) fr.setUnicodeFlag(false);
|
||||
int ret = (int) Math.ceil(fr.getStringWidth(s) * (half ? 0.5f : 1));
|
||||
fr.setUnicodeFlag(flag);
|
||||
return ret;
|
||||
|
||||
@@ -81,6 +81,9 @@ public class Resource {
|
||||
public static final Resource BTN_NBT_F_N = getIcon(5, 4);
|
||||
public static final Resource BTN_NBT_F_F = getIcon(5, 3);
|
||||
public static final Resource BTN_NBT_D = getIcon(4, 5);
|
||||
public static final Resource BTN_EDIT_N = getIcon(6, 4);
|
||||
public static final Resource BTN_EDIT_F = getIcon(6, 3);
|
||||
public static final Resource BTN_EDIT_D = getIcon(6, 5);
|
||||
|
||||
public static final Resource WGT_BUTTON_N = getWidget(0);
|
||||
public static final Resource WGT_BUTTON_F = getWidget(1);
|
||||
@@ -171,13 +174,14 @@ public class Resource {
|
||||
public static final ResourceGroup BTN_EXPORT_1 = new ResourceGroup(BTN_EXPORT_1_N, BTN_EXPORT_1_F, BTN_EXPORT_1_D);
|
||||
public static final ResourceGroup BTN_INV_E = new ResourceGroup(BTN_INV_E_N, BTN_INV_E_F);
|
||||
public static final ResourceGroup BTN_INV_D = new ResourceGroup(BTN_INV_D_N, BTN_INV_D_F);
|
||||
|
||||
public static final ResourceGroup BTN_META_N = new ResourceGroup(BTN_META_N_N, BTN_META_N_F, BTN_META_D);
|
||||
public static final ResourceGroup BTN_CAP_N = new ResourceGroup(BTN_CAP_N_N, BTN_CAP_N_F, BTN_CAP_D);
|
||||
public static final ResourceGroup BTN_NBT_N = new ResourceGroup(BTN_NBT_N_N, BTN_NBT_N_F, BTN_NBT_D);
|
||||
public static final ResourceGroup BTN_META_F = new ResourceGroup(BTN_META_F_N, BTN_META_F_F, BTN_META_D);
|
||||
public static final ResourceGroup BTN_CAP_F = new ResourceGroup(BTN_CAP_F_N, BTN_CAP_F_F, BTN_CAP_D);
|
||||
public static final ResourceGroup BTN_NBT_F = new ResourceGroup(BTN_NBT_F_N, BTN_NBT_F_F, BTN_NBT_D);
|
||||
public static final ResourceGroup BTN_EDIT = new ResourceGroup(BTN_EDIT_N, BTN_EDIT_F, BTN_EDIT_D);
|
||||
|
||||
public static final ResourceGroup WGT_ARR_L = new ResourceGroup(WGT_ARR_L_N, WGT_ARR_L_F, WGT_ARR_L_D);
|
||||
public static final ResourceGroup WGT_ARR_R = new ResourceGroup(WGT_ARR_R_N, WGT_ARR_R_F, WGT_ARR_R_D);
|
||||
public static final ResourceGroup ICN_RECENT = new ResourceGroup(ICN_RECENT_N, ICN_RECENT_F);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class GuiCraft extends WContainer implements IGui {
|
||||
.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.PLAIN, "x"));
|
||||
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"));
|
||||
add(recent, label, input, output, catalyst, steps, result, amount, record.inventory ? invE : invD);
|
||||
|
||||
@@ -20,8 +20,8 @@ import static me.towdium.jecalculation.gui.Resource.*;
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiDisamb extends IPicker.Impl implements IGui {
|
||||
protected WLabelScroll lsUp = new WLabelScroll(25, 48, 7, 3, WLabel.Mode.PICKER, true);
|
||||
protected WLabelScroll lsDown = new WLabelScroll(25, 105, 7, 3, WLabel.Mode.PICKER, true);
|
||||
protected 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) {
|
||||
@@ -32,14 +32,14 @@ public class GuiDisamb extends IPicker.Impl implements IGui {
|
||||
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, lsUp.setListener(consumer), lsDown.setListener(consumer)));
|
||||
add(switcher, lsUp, lsDown);
|
||||
add(new WSearch(25, 24, 90, up.setListener(consumer), down.setListener(consumer)));
|
||||
add(switcher, up, down);
|
||||
setPage(0);
|
||||
}
|
||||
|
||||
|
||||
protected void setPage(int n) {
|
||||
lsUp.setLabels(record.get(n));
|
||||
lsDown.setLabels(ILabel.CONVERTER.guess(record.get(n)).one);
|
||||
up.setLabels(record.get(n));
|
||||
down.setLabels(ILabel.CONVERTER.guess(record.get(n)).one);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ 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.utils.wrappers.Pair;
|
||||
import me.towdium.jecalculation.utils.wrappers.Quad;
|
||||
|
||||
@@ -77,7 +78,7 @@ public class GuiImport extends WContainer implements IGui, ISearchable {
|
||||
public boolean setFilter(String s) {
|
||||
if (s.isEmpty()) filtered = new ArrayList<>(data);
|
||||
else filtered = data.stream()
|
||||
.filter(i -> contains(i.two, s) || contains(i.three, s))
|
||||
.filter(i -> Utilities.I18n.contains(i.two, s) || Utilities.I18n.contains(i.three, s))
|
||||
.collect(Collectors.toList());
|
||||
remove(page);
|
||||
page = new WSwitcher(7, 7, 162, (filtered.size() + 6) / 7).setListener(i -> refresh());
|
||||
|
||||
@@ -34,46 +34,28 @@ public class GuiMath extends WContainer implements IGui {
|
||||
public GuiMath() {
|
||||
add(new WHelp("math"));
|
||||
add(new WPanel(), lcd);
|
||||
add(new WButtonText(7, 67, 28, 20, "7").setListener(i -> append(7))
|
||||
.setKeyBind(Keyboard.KEY_7, Keyboard.KEY_NUMPAD7));
|
||||
add(new WButtonText(39, 67, 28, 20, "8").setListener(i -> append(8))
|
||||
.setKeyBind(Keyboard.KEY_8, Keyboard.KEY_NUMPAD8));
|
||||
add(new WButtonText(71, 67, 28, 20, "9").setListener(i -> append(9))
|
||||
.setKeyBind(Keyboard.KEY_9, Keyboard.KEY_NUMPAD9));
|
||||
add(new WButtonText(7, 91, 28, 20, "4").setListener(i -> append(4))
|
||||
.setKeyBind(Keyboard.KEY_4, Keyboard.KEY_NUMPAD4));
|
||||
add(new WButtonText(39, 91, 28, 20, "5").setListener(i -> append(5))
|
||||
.setKeyBind(Keyboard.KEY_5, Keyboard.KEY_NUMPAD5));
|
||||
add(new WButtonText(71, 91, 28, 20, "6").setListener(i -> append(6))
|
||||
.setKeyBind(Keyboard.KEY_6, Keyboard.KEY_NUMPAD6));
|
||||
add(new WButtonText(7, 115, 28, 20, "1").setListener(i -> append(1))
|
||||
.setKeyBind(Keyboard.KEY_1, Keyboard.KEY_NUMPAD1));
|
||||
add(new WButtonText(39, 115, 28, 20, "2").setListener(i -> append(2))
|
||||
.setKeyBind(Keyboard.KEY_2, Keyboard.KEY_NUMPAD2));
|
||||
add(new WButtonText(71, 115, 28, 20, "3").setListener(i -> append(3))
|
||||
.setKeyBind(Keyboard.KEY_3, Keyboard.KEY_NUMPAD3));
|
||||
add(new WButtonText(7, 139, 28, 20, "0").setListener(i -> append(0))
|
||||
.setKeyBind(Keyboard.KEY_0, Keyboard.KEY_NUMPAD0));
|
||||
add(new WButtonText(39, 139, 28, 20, "00").setListener(i -> {
|
||||
add(new WButtonText(7, 67, 28, 20, "7", null, true).setListener(i -> append(7)).setKeyBind(Keyboard.KEY_7, Keyboard.KEY_NUMPAD7));
|
||||
add(new WButtonText(39, 67, 28, 20, "8", null, true).setListener(i -> append(8)).setKeyBind(Keyboard.KEY_8, Keyboard.KEY_NUMPAD8));
|
||||
add(new WButtonText(71, 67, 28, 20, "9", null, true).setListener(i -> append(9)).setKeyBind(Keyboard.KEY_9, Keyboard.KEY_NUMPAD9));
|
||||
add(new WButtonText(7, 91, 28, 20, "4", null, true).setListener(i -> append(4)).setKeyBind(Keyboard.KEY_4, Keyboard.KEY_NUMPAD4));
|
||||
add(new WButtonText(39, 91, 28, 20, "5", null, true).setListener(i -> append(5)).setKeyBind(Keyboard.KEY_5, Keyboard.KEY_NUMPAD5));
|
||||
add(new WButtonText(71, 91, 28, 20, "6", null, true).setListener(i -> append(6)).setKeyBind(Keyboard.KEY_6, Keyboard.KEY_NUMPAD6));
|
||||
add(new WButtonText(7, 115, 28, 20, "1", null, true).setListener(i -> append(1)).setKeyBind(Keyboard.KEY_1, Keyboard.KEY_NUMPAD1));
|
||||
add(new WButtonText(39, 115, 28, 20, "2", null, true).setListener(i -> append(2)).setKeyBind(Keyboard.KEY_2, Keyboard.KEY_NUMPAD2));
|
||||
add(new WButtonText(71, 115, 28, 20, "3", null, true).setListener(i -> append(3)).setKeyBind(Keyboard.KEY_3, Keyboard.KEY_NUMPAD3));
|
||||
add(new WButtonText(7, 139, 28, 20, "0", null, true).setListener(i -> append(0)).setKeyBind(Keyboard.KEY_0, Keyboard.KEY_NUMPAD0));
|
||||
add(new WButtonText(39, 139, 28, 20, "00", null, true).setListener(i -> {
|
||||
append(0);
|
||||
append(0);
|
||||
}));
|
||||
add(new WButtonText(71, 139, 28, 20, ".").setListener(i -> dot())
|
||||
.setKeyBind(Keyboard.KEY_PERIOD, Keyboard.KEY_DECIMAL));
|
||||
add(new WButtonIcon(109, 67, 28, 20, Resource.WGT_ARR_L).setListener(i -> remove())
|
||||
.setKeyBind(Keyboard.KEY_BACK));
|
||||
add(new WButtonText(141, 67, 28, 20, "+").setListener(i -> operate(Operator.PLUS))
|
||||
.setKeyBind(Keyboard.KEY_EQUALS, Keyboard.KEY_ADD));
|
||||
add(new WButtonText(109, 91, 28, 20, "C").setListener(i -> reset()).setKeyBind(Keyboard.KEY_DELETE));
|
||||
add(new WButtonText(141, 91, 28, 20, "-").setListener(i -> operate(Operator.MINUS))
|
||||
.setKeyBind(Keyboard.KEY_SUBTRACT, Keyboard.KEY_MINUS));
|
||||
add(new WButtonText(109, 115, 28, 44, "=").setListener(i -> operate(Operator.EQUALS))
|
||||
.setKeyBind(Keyboard.KEY_RETURN, Keyboard.KEY_NUMPADENTER,
|
||||
Keyboard.KEY_NUMPADEQUALS));
|
||||
add(new WButtonText(141, 115, 28, 20, "x").setListener(i -> operate(Operator.TIMES))
|
||||
.setKeyBind(Keyboard.KEY_APOSTROPHE, Keyboard.KEY_MULTIPLY));
|
||||
add(new WButtonText(141, 139, 28, 20, "/").setListener(i -> operate(Operator.DIVIDE))
|
||||
.setKeyBind(Keyboard.KEY_SLASH, Keyboard.KEY_DIVIDE));
|
||||
add(new WButtonText(71, 139, 28, 20, ".", null, true).setListener(i -> dot()).setKeyBind(Keyboard.KEY_PERIOD, Keyboard.KEY_DECIMAL));
|
||||
add(new WButtonIcon(109, 67, 28, 20, Resource.WGT_ARR_L).setListener(i -> remove()).setKeyBind(Keyboard.KEY_BACK));
|
||||
add(new WButtonText(141, 67, 28, 20, "+", null, true).setListener(i -> operate(Operator.PLUS)).setKeyBind(Keyboard.KEY_EQUALS, Keyboard.KEY_ADD));
|
||||
add(new WButtonText(109, 91, 28, 20, "C", null, true).setListener(i -> reset()).setKeyBind(Keyboard.KEY_DELETE));
|
||||
add(new WButtonText(141, 91, 28, 20, "-", null, true).setListener(i -> operate(Operator.MINUS)).setKeyBind(Keyboard.KEY_SUBTRACT, Keyboard.KEY_MINUS));
|
||||
add(new WButtonText(109, 115, 28, 44, "=", null, true).setListener(i -> operate(Operator.EQUALS)).setKeyBind(Keyboard.KEY_RETURN, Keyboard.KEY_NUMPADENTER, Keyboard.KEY_NUMPADEQUALS));
|
||||
add(new WButtonText(141, 115, 28, 20, "x", null, true).setListener(i -> operate(Operator.TIMES)).setKeyBind(Keyboard.KEY_APOSTROPHE, Keyboard.KEY_MULTIPLY));
|
||||
add(new WButtonText(141, 139, 28, 20, "/", null, true).setListener(i -> operate(Operator.DIVIDE)).setKeyBind(Keyboard.KEY_SLASH, Keyboard.KEY_DIVIDE));
|
||||
add(new WLine(61), new WLine(103, 61, 98, false), new WLine.Joint(103, 61, false, true, true, true));
|
||||
RecordMath recordMath = Controller.getRMath();
|
||||
state = recordMath.state;
|
||||
|
||||
@@ -12,7 +12,9 @@ import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import me.towdium.jecalculation.utils.wrappers.Trio;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -22,75 +24,73 @@ import static me.towdium.jecalculation.gui.Resource.*;
|
||||
* Author: towdium
|
||||
* Date: 17-9-8.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class GuiRecipe extends WContainer implements IGui {
|
||||
Pair<String, Integer> dest;
|
||||
HashMap<Integer, List<ILabel>> disambiguation = new HashMap<>();
|
||||
WSwitcher switcherGroup = new WSwitcher(7, 7, 162, Controller.getGroups());
|
||||
WTextField textField = new WTextField(49, 31, 119);
|
||||
WLabelGroup groupCatalyst = new WLabelGroup(29, 87, 7, 1, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
|
||||
disambiguation.remove(v + 14);
|
||||
HashMap<Integer, List<ILabel>> disambCache = new HashMap<>();
|
||||
WSwitcher group = new WSwitcher(7, 7, 162, Controller.getGroups()).setListener(i -> refresh());
|
||||
WTextField text = new WTextField(49, 31, 119);
|
||||
WLabelGroup catalyst = new WLabelGroup(29, 87, 7, 1, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
|
||||
disambCache.remove(v + 14);
|
||||
refresh();
|
||||
});
|
||||
WLabelGroup groupInput = new WLabelGroup(29, 111, 7, 2, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
|
||||
disambiguation.remove(v);
|
||||
WLabelGroup input = new WLabelGroup(29, 111, 7, 2, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
|
||||
disambCache.remove(v);
|
||||
refresh();
|
||||
});
|
||||
WLabelGroup groupOutput = new WLabelGroup(29, 63, 7, 1, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
|
||||
disambiguation.remove(v + 21);
|
||||
WLabelGroup output = new WLabelGroup(29, 63, 7, 1, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
|
||||
disambCache.remove(v + 21);
|
||||
refresh();
|
||||
});
|
||||
WButton buttonDisamb = new WButtonIcon(121, 31, 20, 20, BTN_DISAMB, "recipe.disamb").setListener(i -> {
|
||||
if (disambiguation != null) JecaGui.displayGui(new GuiDisamb(new ArrayList<>(disambiguation.values()))
|
||||
.setCallback(l -> {
|
||||
JecaGui.displayParent();
|
||||
JecaGui.getCurrent().hand = l;
|
||||
}));
|
||||
WButton disamb = new WButtonIcon(121, 31, 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 buttonClear = new WButtonIcon(64, 31, 20, 20, BTN_DEL, "recipe.clear").setListener(i -> clear());
|
||||
WButton clear = new WButtonIcon(64, 31, 20, 20, BTN_DEL, "recipe.clear").setListener(i -> reset());
|
||||
// check duplicate and valid
|
||||
WButton buttonCopy = new WButtonIcon(83, 31, 20, 20, BTN_COPY, "recipe.copy").setListener(i -> {
|
||||
Controller.addRecipe(switcherGroup.getText(), toRecipe());
|
||||
WButton copy = new WButtonIcon(83, 31, 20, 20, BTN_COPY, "recipe.copy").setListener(i -> {
|
||||
Controller.addRecipe(group.getText(), toRecipe());
|
||||
JecaGui.displayParent();
|
||||
});
|
||||
WButton buttonLabel = new WButtonIcon(45, 31, 20, 20, BTN_LABEL, "recipe.label").setListener(i ->
|
||||
JecaGui.displayGui(new GuiLabel((l) -> {
|
||||
JecaGui.displayParent();
|
||||
JecaGui.getCurrent().hand = l;
|
||||
})));
|
||||
WButton buttonSave = new WButtonIcon(26, 31, 20, 20, BTN_SAVE, "recipe.save").setDisabled(true).setListener(i -> {
|
||||
WButton label = new WButtonIcon(45, 31, 20, 20, BTN_LABEL, "recipe.label").setListener(i ->
|
||||
JecaGui.displayGui(new GuiLabel((l) -> {
|
||||
JecaGui.displayParent();
|
||||
JecaGui.getCurrent().hand = l;
|
||||
})));
|
||||
WButton save = new WButtonIcon(26, 31, 20, 20, BTN_SAVE, "recipe.save").setDisabled(true).setListener(i -> {
|
||||
if (dest == null)
|
||||
Controller.addRecipe(switcherGroup.getText(), toRecipe());
|
||||
Controller.addRecipe(group.getText(), toRecipe());
|
||||
else {
|
||||
if (textField.getText().equals(dest.one))
|
||||
Controller.setRecipe(dest.one, dest.two, toRecipe());
|
||||
else {
|
||||
Controller.removeRecipe(dest.one, dest.two);
|
||||
Controller.addRecipe(switcherGroup.getText(), toRecipe());
|
||||
}
|
||||
String group = this.group.getText();
|
||||
if (group.equals(dest.one)) Controller.setRecipe(dest.one, dest.two, toRecipe());
|
||||
else Controller.setRecipe(group, dest.one, dest.two, toRecipe());
|
||||
}
|
||||
JecaGui.displayParent();
|
||||
});
|
||||
WButton buttonDel = new WButtonIcon(102, 31, 20, 20, BTN_NO, "recipe.delete").setListener(i -> {
|
||||
WButton delete = new WButtonIcon(102, 31, 20, 20, BTN_NO, "recipe.delete").setListener(i -> {
|
||||
Controller.removeRecipe(dest.one, dest.two);
|
||||
JecaGui.displayParent();
|
||||
});
|
||||
WButton buttonYes = new WButtonIcon(7, 31, 20, 20, BTN_YES, "recipe.confirm").setDisabled(true).setListener(i -> {
|
||||
switcherGroup.setTemp(textField.getText());
|
||||
textField.setText("");
|
||||
WButton yes = new WButtonIcon(7, 31, 20, 20, BTN_YES, "recipe.confirm").setDisabled(true).setListener(i -> {
|
||||
group.setText(text.getText());
|
||||
text.setText("");
|
||||
setNewGroup(false);
|
||||
refresh();
|
||||
});
|
||||
WButton buttonNo = new WButtonIcon(26, 31, 20, 20, BTN_NO, "common.cancel").setListener(i -> setNewGroup(false));
|
||||
WButton buttonNew = new WButtonIcon(7, 31, 20, 20, BTN_NEW, "recipe.new").setListener(i -> setNewGroup(true));
|
||||
WButton no = new WButtonIcon(26, 31, 20, 20, BTN_NO, "common.cancel").setListener(i -> setNewGroup(false));
|
||||
WButton neu = new WButtonIcon(7, 31, 20, 20, BTN_NEW, "recipe.new").setListener(i -> setNewGroup(true));
|
||||
|
||||
public GuiRecipe(String group, int index) {
|
||||
this();
|
||||
dest = new Pair<>(group, index);
|
||||
Recipe r = Controller.getRecipe(group, index);
|
||||
fromRecipe(r);
|
||||
switcherGroup.setIndex(Controller.getGroups().indexOf(group));
|
||||
buttonCopy.setDisabled(false);
|
||||
buttonDel.setDisabled(false);
|
||||
buttonSave.setDisabled(false);
|
||||
this.group.setIndex(Controller.getGroups().indexOf(group));
|
||||
delete.setDisabled(false);
|
||||
refresh();
|
||||
}
|
||||
|
||||
public GuiRecipe() {
|
||||
@@ -99,40 +99,51 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
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(groupInput, groupCatalyst, groupOutput, switcherGroup);
|
||||
if (switcherGroup.getTexts().isEmpty()) switcherGroup.setTemp(Utilities.I18n.get("gui.common.default"));
|
||||
add(input, catalyst, output, group);
|
||||
if (group.getTexts().isEmpty()) group.setText(Utilities.I18n.get("gui.common.default"));
|
||||
String last = Controller.getLast();
|
||||
int index = -1;
|
||||
if (last != null) index = switcherGroup.getTexts().indexOf(last);
|
||||
if (index != -1) switcherGroup.setIndex(index);
|
||||
if (last != null) index = group.getTexts().indexOf(last);
|
||||
if (index != -1) group.setIndex(index);
|
||||
setNewGroup(false);
|
||||
buttonCopy.setDisabled(true);
|
||||
buttonDel.setDisabled(true);
|
||||
buttonDisamb.setDisabled(true);
|
||||
textField.setListener(i -> buttonYes.setDisabled(i.getText().isEmpty()));
|
||||
copy.setDisabled(true);
|
||||
delete.setDisabled(true);
|
||||
disamb.setDisabled(true);
|
||||
text.setListener(i -> yes.setDisabled(i.getText().isEmpty()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKey(JecaGui gui, char ch, int code) {
|
||||
if (code == Keyboard.KEY_ESCAPE && contains(text)) {
|
||||
setNewGroup(false);
|
||||
return true;
|
||||
}
|
||||
return super.onKey(gui, ch, code);
|
||||
}
|
||||
|
||||
public void setNewGroup(boolean b) {
|
||||
if (b) {
|
||||
remove(buttonNew, buttonLabel, buttonClear, buttonCopy, buttonSave, buttonDisamb, buttonDel);
|
||||
add(buttonYes, buttonNo, textField);
|
||||
remove(neu, label, clear, copy, save, disamb, delete);
|
||||
add(yes, no, text);
|
||||
} else {
|
||||
add(buttonNew, buttonLabel, buttonClear, buttonCopy, buttonSave, buttonDisamb, buttonDel);
|
||||
remove(buttonYes, buttonNo, textField);
|
||||
add(neu, label, clear, copy, save, disamb, delete);
|
||||
remove(yes, no, text);
|
||||
text.setText("");
|
||||
yes.setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
groupInput.setLabel(Collections.nCopies(14, ILabel.EMPTY), 0);
|
||||
groupCatalyst.setLabel(Collections.nCopies(7, ILabel.EMPTY), 0);
|
||||
groupOutput.setLabel(Collections.nCopies(7, ILabel.EMPTY), 0);
|
||||
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);
|
||||
}
|
||||
|
||||
public void transfer(IRecipeHandler recipe, int recipeIndex) {
|
||||
// item disamb raw
|
||||
ArrayList<Trio<ILabel, CostList, CostList>> input = new ArrayList<>();
|
||||
ArrayList<Trio<ILabel, CostList, CostList>> output = new ArrayList<>();
|
||||
disambiguation = new HashMap<>();
|
||||
disambCache = new HashMap<>();
|
||||
|
||||
// input
|
||||
List<ItemStack> inputItemStacks = recipe.getIngredientStacks(recipeIndex).stream()
|
||||
@@ -144,11 +155,11 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
|
||||
// catalyst ignore multiple catalyst
|
||||
NEIPlugin.getCatalyst(recipe).map(ILabel.Converter::from).ifPresent(catalyst -> {
|
||||
groupCatalyst.setLabel(catalyst, 0);
|
||||
this.catalyst.setLabel(catalyst, 0);
|
||||
});
|
||||
|
||||
groupInput.setLabel(sort(input, 0), 0);
|
||||
groupOutput.setLabel(sort(output, 21), 0);
|
||||
this.input.setLabel(sort(input, 0), 0);
|
||||
this.output.setLabel(sort(output, 21), 0);
|
||||
refresh();
|
||||
}
|
||||
|
||||
@@ -177,32 +188,36 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
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) disambiguation.put(i + offset, p.two.getLabels());
|
||||
if (p.two.getLabels().size() > 1) disambCache.put(i + offset, p.two.getLabels());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Recipe toRecipe() {
|
||||
return new Recipe(groupInput.getLabels(), groupCatalyst.getLabels(), groupOutput.getLabels());
|
||||
return new Recipe(input.getLabels(), catalyst.getLabels(), output.getLabels());
|
||||
}
|
||||
|
||||
void fromRecipe(Recipe r) {
|
||||
groupInput.setLabel(Arrays.stream(r.getLabel(Recipe.IO.INPUT))
|
||||
.map(ILabel::copy).collect(Collectors.toList()), 0);
|
||||
groupCatalyst.setLabel(Arrays.stream(r.getLabel(Recipe.IO.CATALYST))
|
||||
.map(ILabel::copy).collect(Collectors.toList()), 0);
|
||||
groupOutput.setLabel(Arrays.stream(r.getLabel(Recipe.IO.OUTPUT))
|
||||
.map(ILabel::copy).collect(Collectors.toList()), 0);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void refresh() {
|
||||
buttonDisamb.setDisabled(disambiguation.isEmpty());
|
||||
disamb.setDisabled(disambCache.isEmpty());
|
||||
try {
|
||||
Recipe r = toRecipe();
|
||||
buttonSave.setDisabled(Controller.hasDuplicate(r));
|
||||
boolean d = dest == null ? Controller.hasDuplicate(r) :
|
||||
Controller.hasDuplicate(r, dest.one, dest.two);
|
||||
save.setDisabled(d);
|
||||
if (dest != null) copy.setDisabled(d);
|
||||
} catch (IllegalArgumentException e) {
|
||||
buttonSave.setDisabled(true);
|
||||
save.setDisabled(true);
|
||||
copy.setDisabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package me.towdium.jecalculation.gui.guis;
|
||||
import me.towdium.jecalculation.data.Controller;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.data.structure.Recipe;
|
||||
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.*;
|
||||
@@ -11,7 +12,9 @@ import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Trio;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.IdentityHashMap;
|
||||
@@ -20,29 +23,51 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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 {
|
||||
WSwitcher group;
|
||||
WButton export;
|
||||
List<ILabel> identifiers;
|
||||
IdentityHashMap<ILabel, Trio<Recipe, String, Integer>> recipes;
|
||||
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, PICKER, true).setListener((i, v) -> {
|
||||
Trio<Recipe, String, Integer> recipe = recipes.get(i.get(v));
|
||||
JecaGui.displayGui(true, true, new GuiRecipe(recipe.two, recipe.three));
|
||||
});
|
||||
|
||||
WSwitcher group;
|
||||
WTextField text = new WTextField(7, 25, 119);
|
||||
WButton no = new WButtonIcon(130, 25, 20, 20, BTN_NO, "common.cancel")
|
||||
.setListener(i -> setRename(false));
|
||||
WButton yes = new WButtonIcon(149, 25, 20, 20, BTN_YES, "search.confirm")
|
||||
.setDisabled(true).setListener(i -> {
|
||||
Controller.renameGroup(group.getText(), text.getText());
|
||||
refreshGroups();
|
||||
group.setText(text.getText());
|
||||
refreshDisplay();
|
||||
setRename(false);
|
||||
});
|
||||
WButton exportN = new WButtonIcon(130, 25, 20, 20, BTN_EXPORT_N, "search.export_all")
|
||||
.setListener(i -> Controller.export());
|
||||
WButton export1 = new WButtonIcon(130, 25, 20, 20, BTN_EXPORT_1, "search.export_group")
|
||||
.setListener(i -> Controller.export(group.getText()));
|
||||
WButton inport = new WButtonIcon(112, 25, 20, 20, BTN_IMPORT, "search.import")
|
||||
.setListener(i -> JecaGui.displayGui(new GuiImport()));
|
||||
WButton rename = new WButtonIcon(149, 25, 20, 20, BTN_EDIT, "search.rename")
|
||||
.setListener(i -> setRename(true));
|
||||
WIcon icon = new WIcon(7, 25, 20, 20, ICN_TEXT, "common.search");
|
||||
WSearch search = new WSearch(26, 25, 80, labels);
|
||||
List<ILabel> identifiers;
|
||||
|
||||
public GuiSearch() {
|
||||
text.setListener(i -> {
|
||||
String s = i.getText();
|
||||
yes.setDisabled(s.isEmpty() || Controller.getGroups().contains(s));
|
||||
});
|
||||
add(new WHelp("search"), new WPanel());
|
||||
add(new WSearch(26, 25, 90, labels));
|
||||
add(new WIcon(7, 25, 20, 20, ICN_TEXT, "common.search"));
|
||||
add(new WButtonIcon(131, 25, 20, 20, BTN_IMPORT, "search.import")
|
||||
.setListener(i -> JecaGui.displayGui(new GuiImport())));
|
||||
add(labels);
|
||||
add(labels, icon, search, inport, exportN, rename);
|
||||
}
|
||||
|
||||
|
||||
private void generate() {
|
||||
identifiers = new ArrayList<>();
|
||||
recipes = new IdentityHashMap<>();
|
||||
@@ -52,53 +77,56 @@ public class GuiSearch extends WContainer implements IGui {
|
||||
identifiers.add(id);
|
||||
};
|
||||
|
||||
if (group.getIndex() == 0) {
|
||||
Controller.stream()
|
||||
.flatMap(i -> Streams.mapWithIndex(i.two.stream(), (j, k) -> new Trio<>(j, i.one, (int) k)))
|
||||
.forEach(add);
|
||||
} else {
|
||||
String s = group.getText();
|
||||
Streams.mapWithIndex(Controller.recipeIterator(s).stream(), (j, k) -> new Trio<>(j, s, (int) k))
|
||||
.forEach(add);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void refresh() {
|
||||
remove(export);
|
||||
String tooltip;
|
||||
Supplier<File> func;
|
||||
ResourceGroup texture;
|
||||
generate();
|
||||
if (group.getIndex() == 0) {
|
||||
tooltip = "search.export_all";
|
||||
func = Controller::export;
|
||||
texture = Resource.BTN_EXPORT_N;
|
||||
} else {
|
||||
tooltip = "search.export_group";
|
||||
func = () -> Controller.export(group.getText());
|
||||
texture = Resource.BTN_EXPORT_1;
|
||||
}
|
||||
labels.setLabels(identifiers);
|
||||
export = new WButtonIcon(149, 25, 20, 20, texture, tooltip).setListener(i -> {
|
||||
File f = func.get();
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation(
|
||||
"jecalculation.chat.export", f.getAbsolutePath()));
|
||||
}).setDisabled(recipes.size() == 0);
|
||||
add(export);
|
||||
Recipes.RecipeIterator it = group.getIndex() == 0 ? recipeIterator() : recipeIterator(group.getText());
|
||||
it.stream().map(j -> new Trio<>(j, it.getGroup(), it.getIndex())).forEach(add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVisible(JecaGui gui) {
|
||||
this.remove(group);
|
||||
public boolean onKey(JecaGui gui, char ch, int code) {
|
||||
if (code == Keyboard.KEY_ESCAPE && contains(text)) {
|
||||
setRename(false);
|
||||
return true;
|
||||
}
|
||||
return super.onKey(gui, ch, code);
|
||||
}
|
||||
|
||||
public void refreshDisplay() {
|
||||
remove(exportN, export1);
|
||||
generate();
|
||||
labels.setLabels(identifiers);
|
||||
add(group.getIndex() == 0 ? exportN : export1);
|
||||
exportN.setDisabled(identifiers.size() == 0);
|
||||
rename.setDisabled(group.getIndex() == 0);
|
||||
}
|
||||
|
||||
public void refreshGroups() {
|
||||
remove(group);
|
||||
ArrayList<String> groups = new ArrayList<>();
|
||||
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;
|
||||
group = new WSwitcher(7, 7, 162, groups).setListener(i -> refresh());
|
||||
group = new WSwitcher(7, 7, 162, groups).setListener(i -> refreshDisplay());
|
||||
group.setIndex(index);
|
||||
this.add(group);
|
||||
refresh();
|
||||
add(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVisible(JecaGui gui) {
|
||||
refreshGroups();
|
||||
refreshDisplay();
|
||||
}
|
||||
|
||||
private void setRename(boolean b) {
|
||||
group.setDisabled(b);
|
||||
if (b) {
|
||||
add(yes, no, text);
|
||||
remove(icon, search, inport, export1, exportN, rename);
|
||||
} else {
|
||||
add(icon, search, inport, group.getIndex() == 0 ? exportN : export1, rename);
|
||||
remove(yes, no, text);
|
||||
text.setText("");
|
||||
yes.setDisabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,17 +14,26 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class WButtonText extends WButton {
|
||||
public static final JecaGui.Font focused = new JecaGui.Font(0xFFFFA0, true, false);
|
||||
public static final JecaGui.Font normal = new JecaGui.Font(0xFFFFFF, true, false);
|
||||
public static final JecaGui.Font focused_u = new JecaGui.Font(0xFFFFA0, true, false, false);
|
||||
public static final JecaGui.Font normal_u = new JecaGui.Font(0xFFFFFF, true, false, false);
|
||||
public static final JecaGui.Font focused_r = new JecaGui.Font(0xFFFFA0, true, false, true);
|
||||
public static final JecaGui.Font normal_r = new JecaGui.Font(0xFFFFFF, true, false, true);
|
||||
public String text;
|
||||
protected JecaGui.Font focused, normal;
|
||||
|
||||
public WButtonText(int xPos, int yPos, int xSize, int ySize, String text) {
|
||||
this(xPos, yPos, xSize, ySize, text, null);
|
||||
}
|
||||
|
||||
public WButtonText(int xPos, int yPos, int xSize, int ySize, String text, @Nullable String name) {
|
||||
this(xPos, yPos, xSize, ySize, text, name, false);
|
||||
}
|
||||
|
||||
public WButtonText(int xPos, int yPos, int xSize, int ySize, String text, @Nullable String name, boolean raw) {
|
||||
super(xPos, yPos, xSize, ySize, name);
|
||||
this.text = text;
|
||||
focused = raw ? focused_r : focused_u;
|
||||
normal = raw ? normal_r : normal_u;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,6 +40,10 @@ public class WContainer implements IContainer {
|
||||
widgets.clear();
|
||||
}
|
||||
|
||||
public boolean contains(IWidget w) {
|
||||
return widgets.contains(w);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecaGui gui, int mouseX, int mouseY) {
|
||||
widgets.forEach(widget -> widget.onDraw(gui, mouseX, mouseY));
|
||||
|
||||
@@ -48,11 +48,11 @@ public class WSwitcher extends WContainer {
|
||||
this.keys = keys;
|
||||
left = new WButtonIcon(xPos, yPos, SIZE, SIZE, WGT_ARR_L).setListener(i -> {
|
||||
if (temp == null) move(-1);
|
||||
else setTemp(null);
|
||||
else setText(null);
|
||||
});
|
||||
right = new WButtonIcon(xPos + xSize - SIZE, yPos, SIZE, SIZE, WGT_ARR_R).setListener(i -> {
|
||||
if (temp == null) move(1);
|
||||
else setTemp(null);
|
||||
else setText(null);
|
||||
});
|
||||
wRect = new WRectangle(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, COLOR_GUI_GREY);
|
||||
wText = new WText(xPos + SIZE, yPos + 2, xSize - 2 * SIZE, SHADOW, "", true);
|
||||
@@ -61,6 +61,11 @@ public class WSwitcher extends WContainer {
|
||||
add(left, right, wRect, wText);
|
||||
}
|
||||
|
||||
public WSwitcher setDisabled(boolean b) {
|
||||
left.setDisabled(b);
|
||||
right.setDisabled(b);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void move(int diff) {
|
||||
if (diff == 0) return;
|
||||
@@ -79,12 +84,6 @@ public class WSwitcher extends WContainer {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setTemp(@Nullable String temp) {
|
||||
this.temp = temp;
|
||||
notifyLsnr();
|
||||
refresh();
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return temp == null ? index.current() : -1;
|
||||
}
|
||||
@@ -111,6 +110,15 @@ public class WSwitcher extends WContainer {
|
||||
wText.key = temp == null ? (keys.isEmpty() ? "" : keys.get(index.current())) : temp;
|
||||
}
|
||||
|
||||
public WSwitcher setText(@Nullable String s) {
|
||||
int i = keys.indexOf(s);
|
||||
if (i != -1) setIndex(i);
|
||||
else temp = s;
|
||||
notifyLsnr();
|
||||
refresh();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void notifyLsnr() {
|
||||
if (listener != null) listener.invoke(this);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user