mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-22 04:52:29 +00:00
feat: math and Chinese
This commit is contained in:
1 parent
1c05e9d154
commit
7f525ce264
30 files changed
+970
-211
No files matched your search
@@ -1,9 +1,9 @@
|
||||
package me.towdium.jecalculation.command;
|
||||
|
||||
import me.towdium.jecalculation.command.commands.CHelp;
|
||||
import me.towdium.jecalculation.command.commands.COreDict;
|
||||
import me.towdium.jecalculation.command.commands.CMath;
|
||||
import me.towdium.jecalculation.command.commands.CState;
|
||||
import me.towdium.jecalculation.command.commands.CUuid;
|
||||
import me.towdium.jecalculation.command.commands.CCraft;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.HashMap;
|
||||
@@ -19,8 +19,8 @@ public class Commands {
|
||||
static {
|
||||
add(new CHelp());
|
||||
add(new CState());
|
||||
add(new COreDict());
|
||||
add(new CUuid());
|
||||
add(new CMath());
|
||||
add(new CCraft());
|
||||
}
|
||||
|
||||
static void add(ISubCommand c) {
|
||||
|
||||
+7
-6
@@ -1,6 +1,7 @@
|
||||
package me.towdium.jecalculation.command.commands;
|
||||
|
||||
import me.towdium.jecalculation.command.ISubCommand;
|
||||
import me.towdium.jecalculation.data.Controller;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -9,24 +10,24 @@ import net.minecraft.util.ChatComponentText;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-10-15.
|
||||
* Author: Towdium
|
||||
* Date: 19-1-20
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class CUuid implements ISubCommand {
|
||||
public class CCraft implements ISubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "uuid";
|
||||
return "craft";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender) {
|
||||
return "/jeca uuid";
|
||||
return "/jeca craft";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) {
|
||||
sender.addChatMessage(new ChatComponentText(sender.getCommandSenderName()));
|
||||
Controller.openGuiCraft();
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -1,8 +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 net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
@@ -10,23 +12,23 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-11.
|
||||
* Author: Towdium
|
||||
* Date: 19-1-21
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class COreDict implements ISubCommand {
|
||||
public class CMath implements ISubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ore";
|
||||
return "math";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender) {
|
||||
return "/jeca ore";
|
||||
return "/jeca math";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) {
|
||||
Arrays.stream(OreDictionary.getOreNames()).forEach(s -> sender.addChatMessage(new ChatComponentText(s)));
|
||||
Controller.openGuiMath();
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,6 @@ public class CState implements ISubCommand {
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) {
|
||||
sender.addChatMessage(new ChatComponentTranslation(getKey("desc"), "inactive"));
|
||||
sender.addChatMessage(new ChatComponentTranslation("inactive"));
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,18 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JecaConfig;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.data.structure.Recents;
|
||||
import me.towdium.jecalculation.data.structure.Recipe;
|
||||
import me.towdium.jecalculation.data.structure.Recipes;
|
||||
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.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@@ -28,16 +31,28 @@ import java.util.stream.Stream;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class Controller {
|
||||
public static final String KEY_RECIPES = "recipes";
|
||||
public static final String KEY_RECENTS = "recents";
|
||||
public static final String KEY_AMOUNT = "amount";
|
||||
public static final String KEY_INVENTORY = "inventory";
|
||||
static Recipes recipesClient;
|
||||
static Recents recentsClient;
|
||||
static boolean inventoryClient;
|
||||
static String amountClient;
|
||||
public static final String KEY_MATH = "math";
|
||||
public static final String KEY_CRAFT = "craft";
|
||||
public static final String KEY_PLAYER = "player";
|
||||
|
||||
static Recipes getRecord() {
|
||||
return recipesClient;
|
||||
static RecordPlayer rPlayerServer;
|
||||
static RecordPlayer rPlayerClient;
|
||||
static RecordCraft rCraftClient;
|
||||
static RecordMath rMathClient;
|
||||
|
||||
public static void setRecordsServer(RecordPlayer r) {
|
||||
rPlayerServer = r;
|
||||
}
|
||||
|
||||
public static boolean isServerActive() {
|
||||
return rPlayerServer != null;
|
||||
}
|
||||
|
||||
static Recipes getRecipes() {
|
||||
if (isServerActive())
|
||||
return rPlayerServer.recipes;
|
||||
else
|
||||
return rPlayerClient.recipes;
|
||||
}
|
||||
|
||||
static Optional<ItemStack> getStack() {
|
||||
@@ -62,7 +77,7 @@ public class Controller {
|
||||
public static void inport(Recipes recipes, String group) {
|
||||
ArrayList<Recipe> buffer = new ArrayList<>();
|
||||
recipes.getGroup(group)
|
||||
.forEach(i -> getRecord().getGroup(group).stream().filter(j -> j.equals(i)).findAny().orElseGet(() -> {
|
||||
.forEach(i -> getRecipes().getGroup(group).stream().filter(j -> j.equals(i)).findAny().orElseGet(() -> {
|
||||
buffer.add(i);
|
||||
return null;
|
||||
}));
|
||||
@@ -72,82 +87,85 @@ public class Controller {
|
||||
|
||||
public static File export(String group) {
|
||||
File f = JecaConfig.getDataFile(group);
|
||||
Utilities.Json.write(getRecord().serialize(Collections.singleton(group)), f);
|
||||
Utilities.Json.write(getRecipes().serialize(Collections.singleton(group)), f);
|
||||
return f;
|
||||
}
|
||||
|
||||
public static File export() {
|
||||
File f = JecaConfig.getDataFile("groups");
|
||||
Utilities.Json.write(getRecord().serialize(), f);
|
||||
Utilities.Json.write(getRecipes().serialize(), f);
|
||||
return f;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getLast() {
|
||||
return isServerActive() ? rPlayerServer.last : rPlayerClient.last;
|
||||
}
|
||||
|
||||
static void setLast(String last) {
|
||||
if (isServerActive()) rPlayerServer.last = last;
|
||||
else rPlayerServer.last = last;
|
||||
}
|
||||
|
||||
public static List<String> getGroups() {
|
||||
return getRecord().getGroups();
|
||||
return getRecipes().getGroups();
|
||||
}
|
||||
|
||||
public static void addRecipe(String group, Recipe recipe) {
|
||||
getRecord().add(group, recipe);
|
||||
getRecipes().add(group, recipe);
|
||||
setLast(group);
|
||||
writeToLocal();
|
||||
}
|
||||
|
||||
public static void setRecipe(String group, int index, Recipe recipe) {
|
||||
getRecord().set(group, index, recipe);
|
||||
getRecipes().set(group, index, recipe);
|
||||
setLast(group);
|
||||
writeToLocal();
|
||||
}
|
||||
|
||||
public static void removeRecipe(String group, int index) {
|
||||
getRecord().remove(group, index);
|
||||
getRecipes().remove(group, index);
|
||||
setLast(group);
|
||||
writeToLocal();
|
||||
}
|
||||
|
||||
public static Recipe getRecipe(String group, int index) {
|
||||
return getRecord().getRecipe(group, index);
|
||||
return getRecipes().getRecipe(group, index);
|
||||
}
|
||||
|
||||
public static Stream<Pair<String, List<Recipe>>> stream() {
|
||||
return getRecord().stream();
|
||||
return getRecipes().stream();
|
||||
}
|
||||
|
||||
public static Recipes.RecipeIterator recipeIterator() {
|
||||
return getRecord().recipeIterator();
|
||||
return getRecipes().recipeIterator();
|
||||
}
|
||||
|
||||
public static List<Recipe> getRecipes() {
|
||||
return getRecord().getRecipes();
|
||||
public static Recipes.RecipeIterator recipeIterator(String group) {
|
||||
return getRecipes().recipeIterator(group);
|
||||
}
|
||||
|
||||
public static List<Recipe> getRecipes(String group) {
|
||||
return getRecord().getRecipes(group);
|
||||
public static void setRMath(RecordMath math) {
|
||||
rMathClient = math;
|
||||
}
|
||||
|
||||
public static String getAmount() {
|
||||
return amountClient;
|
||||
public static RecordCraft getRCraft() {
|
||||
return rCraftClient;
|
||||
|
||||
}
|
||||
|
||||
public static void setAmount(String amount) {
|
||||
amountClient = amount;
|
||||
public static void setRCraft(RecordCraft rc) {
|
||||
rCraftClient = rc;
|
||||
|
||||
}
|
||||
|
||||
public static boolean getDetectInv() {
|
||||
return inventoryClient;
|
||||
public static RecordMath getRMath() {
|
||||
return rMathClient;
|
||||
}
|
||||
|
||||
public static void setDetectInv(boolean b) {
|
||||
inventoryClient = b;
|
||||
}
|
||||
|
||||
public static List<ILabel> getRecent() {
|
||||
return recentsClient.getRecords();
|
||||
}
|
||||
|
||||
public static void setRecent(ILabel label, boolean replace) {
|
||||
recentsClient.push(label, replace);
|
||||
writeToLocal();
|
||||
}
|
||||
|
||||
public static boolean hasDuplicate(Recipe r) {
|
||||
return getRecord().hasDuplicate(r);
|
||||
return getRecipes().hasDuplicate(r);
|
||||
}
|
||||
|
||||
public static void loadFromLocal() {
|
||||
@@ -156,25 +174,35 @@ public class Controller {
|
||||
File file = JecaConfig.recordFile;
|
||||
NBTTagCompound nbt = Utilities.Json.read(file);
|
||||
if (nbt != null) {
|
||||
recipesClient = nbt.hasKey(KEY_RECIPES) ? new Recipes(nbt.getCompoundTag(KEY_RECIPES)) : new Recipes();
|
||||
recentsClient = nbt.hasKey(KEY_RECENTS) ? new Recents(nbt.getTagList(KEY_RECENTS, 10)) : new Recents();
|
||||
amountClient = nbt.hasKey(KEY_AMOUNT) ? nbt.getString(KEY_AMOUNT) : "";
|
||||
inventoryClient = !nbt.hasKey(KEY_INVENTORY) || nbt.getBoolean(KEY_INVENTORY);
|
||||
rCraftClient = new RecordCraft(nbt.getCompoundTag(KEY_CRAFT));
|
||||
rMathClient = new RecordMath(nbt.getCompoundTag(KEY_MATH));
|
||||
rPlayerClient = nbt.hasKey(KEY_PLAYER) ? new RecordPlayer(nbt.getCompoundTag(KEY_PLAYER)) : new RecordPlayer();
|
||||
} else {
|
||||
recipesClient = new Recipes();
|
||||
recentsClient = new Recents();
|
||||
amountClient = "";
|
||||
inventoryClient = true;
|
||||
rPlayerClient = new RecordPlayer();
|
||||
rCraftClient = new RecordCraft(new NBTTagCompound());
|
||||
rMathClient = new RecordMath(new NBTTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeToLocal() {
|
||||
File file = JecaConfig.recordFile;
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setTag(KEY_RECENTS, recentsClient.serialize());
|
||||
nbt.setTag(KEY_RECIPES, recipesClient.serialize());
|
||||
nbt.setString(KEY_AMOUNT, amountClient);
|
||||
nbt.setBoolean(KEY_INVENTORY, inventoryClient);
|
||||
nbt.setTag(KEY_CRAFT, rCraftClient.serialize());
|
||||
nbt.setTag(KEY_PLAYER, rPlayerClient.serialize());
|
||||
nbt.setTag(KEY_MATH, rMathClient.serialize());
|
||||
Utilities.Json.write(nbt, file);
|
||||
}
|
||||
|
||||
public static void openGuiCraft() {
|
||||
if (!Controller.isServerActive()) JecaGui.displayGui(true, true, new GuiCraft());
|
||||
else Minecraft.getMinecraft().thePlayer.addChatMessage(
|
||||
new ChatComponentTranslation("jecalculation.chat.server_mode"));
|
||||
}
|
||||
|
||||
public static void openGuiMath() {
|
||||
if (!Controller.isServerActive()) JecaGui.displayGui(true, true, new GuiMath());
|
||||
else Minecraft.getMinecraft().thePlayer.addChatMessage(
|
||||
new ChatComponentTranslation("jecalculation.chat.server_mode"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
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;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public class Recents {
|
||||
Utilities.Recent<ILabel> record = new Utilities.Recent<>((a, b) -> a == ILabel.EMPTY || a.equals(b), 9);
|
||||
|
||||
public Recents(NBTTagList nbt) {
|
||||
List<ILabel> ls = StreamSupport.stream(NBTHelper.spliterator(nbt), false)
|
||||
.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));
|
||||
}
|
||||
|
||||
public Recents() {
|
||||
}
|
||||
|
||||
public void push(ILabel label, boolean replace) {
|
||||
record.push(label, replace);
|
||||
}
|
||||
|
||||
public ILabel getLatest() {
|
||||
return record.toList().get(0);
|
||||
}
|
||||
|
||||
public List<ILabel> getRecords() {
|
||||
return record.toList();
|
||||
}
|
||||
|
||||
public NBTTagList serialize() {
|
||||
NBTTagList ret = new NBTTagList();
|
||||
record.toList().forEach(l -> ret.appendTag(ILabel.SERIALIZER.serialize(l)));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -135,10 +135,24 @@ public class Recipes {
|
||||
return new RecipeIterator();
|
||||
}
|
||||
|
||||
public RecipeIterator recipeIterator(String group) {
|
||||
return new RecipeIterator(group);
|
||||
}
|
||||
|
||||
public class RecipeIterator implements Iterator<Recipe> {
|
||||
Iterator<Map.Entry<String, List<Recipe>>> i = records.entrySet().iterator();
|
||||
Iterator<Map.Entry<String, List<Recipe>>> i;
|
||||
Iterator<Recipe> j;
|
||||
|
||||
public RecipeIterator() {
|
||||
i = records.entrySet().iterator();
|
||||
}
|
||||
|
||||
public RecipeIterator(String group) {
|
||||
HashMap<String, List<Recipe>> tmp = new HashMap<>();
|
||||
tmp.put(group, records.get(group));
|
||||
i = tmp.entrySet().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
while (j == null || !j.hasNext()) {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package me.towdium.jecalculation.data.structure;
|
||||
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
* Author: Towdium
|
||||
* Date: 19-1-20
|
||||
*/
|
||||
public class RecordCraft {
|
||||
public static final String KEY_RECENTS = "recents";
|
||||
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);
|
||||
public String amount;
|
||||
public boolean inventory;
|
||||
|
||||
public RecordCraft(NBTTagCompound nbt) {
|
||||
List<ILabel> ls = StreamSupport.stream(nbt.getTagList(KEY_RECENTS, 10).spliterator(), false)
|
||||
.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);
|
||||
}
|
||||
|
||||
public boolean push(ILabel label, boolean replace) {
|
||||
return record.push(label, replace);
|
||||
}
|
||||
|
||||
public ILabel getLatest() {
|
||||
return record.size() == 0 ? ILabel.EMPTY : record.toList().get(0);
|
||||
}
|
||||
|
||||
public List<ILabel> getHistory() {
|
||||
return record.size() > 1 ? record.toList().subList(1, record.size()) : new ArrayList<>();
|
||||
}
|
||||
|
||||
public NBTTagCompound serialize() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
ret.setBoolean(KEY_INVENTORY, inventory);
|
||||
ret.setString(KEY_AMOUNT, amount);
|
||||
NBTTagList recent = new NBTTagList();
|
||||
record.toList().forEach(l -> recent.appendTag(ILabel.SERIALIZER.serialize(l)));
|
||||
ret.setTag(KEY_RECENTS, recent);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package me.towdium.jecalculation.data.structure;
|
||||
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author: Towdium
|
||||
* Date: 19-1-20
|
||||
*/
|
||||
public class RecordMath {
|
||||
public static MathContext context = new MathContext(7, RoundingMode.HALF_UP);
|
||||
public static final int DOT_NONE = -1;
|
||||
static final String KEY_CURRENT = "current";
|
||||
static final String KEY_LAST = "last";
|
||||
static final String KEY_OPERATOR = "operator";
|
||||
static final String KEY_STATE = "state";
|
||||
|
||||
public BigDecimal last;
|
||||
public State state;
|
||||
public Operator operator;
|
||||
String current;
|
||||
|
||||
public enum State {INPUT, OUTPUT, ERROR}
|
||||
|
||||
public enum Operator {
|
||||
EQUALS, PLUS, MINUS, TIMES, DIVIDE;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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('-');
|
||||
numbers.forEach(i -> sb.append(i.toString()));
|
||||
if (dot != DOT_NONE) sb.insert(sb.length() - dot, '.');
|
||||
current = sb.toString();
|
||||
}
|
||||
|
||||
public RecordMath(NBTTagCompound nbt) {
|
||||
state = State.values()[nbt.getInteger(KEY_STATE)];
|
||||
operator = Operator.values()[nbt.getInteger(KEY_OPERATOR)];
|
||||
last = nbt.hasKey(KEY_LAST) ? new BigDecimal(nbt.getString(KEY_LAST)) : BigDecimal.ZERO;
|
||||
current = nbt.getString(KEY_CURRENT);
|
||||
}
|
||||
|
||||
public NBTTagCompound serialize() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
ret.setString(KEY_CURRENT, current);
|
||||
ret.setString(KEY_LAST, last.toString());
|
||||
ret.setInteger(KEY_OPERATOR, operator.ordinal());
|
||||
ret.setInteger(KEY_STATE, state.ordinal());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean getSign() {
|
||||
return current == null || current.isEmpty() || current.charAt(0) != '-';
|
||||
}
|
||||
|
||||
public LinkedList<BigDecimal> getNumbers() {
|
||||
LinkedList<BigDecimal> ret = new LinkedList<>();
|
||||
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'));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int getDot() {
|
||||
if (current == null) return DOT_NONE;
|
||||
int index = current.indexOf('.');
|
||||
return index == -1 ? DOT_NONE : current.length() - index - 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package me.towdium.jecalculation.data.structure;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Author: Towdium
|
||||
* Date: 19-1-21
|
||||
*/
|
||||
public class RecordPlayer {
|
||||
public static final String KEY_RECIPES = "recipes";
|
||||
public static final String KEY_LAST = "last";
|
||||
|
||||
public Recipes recipes;
|
||||
public String last;
|
||||
|
||||
public RecordPlayer() {
|
||||
recipes = new Recipes();
|
||||
}
|
||||
|
||||
public RecordPlayer(NBTTagCompound nbt) {
|
||||
recipes = new Recipes(nbt.getCompoundTag(KEY_RECIPES));
|
||||
last = nbt.getString(KEY_LAST);
|
||||
}
|
||||
|
||||
public NBTTagCompound serialize() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
if (last != null) ret.setString(KEY_LAST, last);
|
||||
ret.setTag(KEY_RECIPES, recipes.serialize());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,8 @@ import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.data.Controller;
|
||||
import me.towdium.jecalculation.data.label.labels.LPlaceholder;
|
||||
import me.towdium.jecalculation.gui.JecaGui;
|
||||
import me.towdium.jecalculation.gui.guis.GuiCalculator;
|
||||
import me.towdium.jecalculation.gui.guis.GuiCraft;
|
||||
import me.towdium.jecalculation.network.ClientHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
@@ -23,9 +21,8 @@ public class FMLBusEventHandler {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent(receiveCanceled = true)
|
||||
public void onKey(InputEvent.KeyInputEvent event) {
|
||||
if (ClientHandler.keyOpenGui.isPressed()) {
|
||||
JecaGui.displayGui(true, true, new GuiCalculator());
|
||||
}
|
||||
if (ClientHandler.keyOpenGuiCraft.isPressed()) Controller.openGuiCraft();
|
||||
if (ClientHandler.keyOpenGuiMath.isPressed()) Controller.openGuiMath();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -11,6 +11,7 @@ import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
@@ -152,6 +153,49 @@ public class JecaGui extends GuiContainer {
|
||||
GlStateManager.enableDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
// modified from vanilla
|
||||
public void drawHoveringText(List lines, int x, int y, FontRenderer font) {
|
||||
List<String> textLines = (List<String>) lines;
|
||||
if (!textLines.isEmpty()) {
|
||||
GlStateManager.disableRescaleNormal();
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
int i = 0;
|
||||
for (String s : textLines) {
|
||||
int j = this.fontRendererObj.getStringWidth(s);
|
||||
if (j > i) i = j;
|
||||
}
|
||||
int l1 = x + 12;
|
||||
int i2 = y - 12;
|
||||
int k = 8 + (textLines.size() - 1) * 10;
|
||||
if (l1 + i > this.width) l1 -= 28 + i;
|
||||
if (i2 + k + 6 > this.height) i2 = this.height - k - 6;
|
||||
zLevel = 300.0F;
|
||||
itemRender.zLevel = 300.0F;
|
||||
drawGradientRect(l1 - 3, i2 - 4, l1 + i + 3, i2 - 3, -267386864, -267386864);
|
||||
drawGradientRect(l1 - 3, i2 + k + 3, l1 + i + 3, i2 + k + 4, -267386864, -267386864);
|
||||
drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 + k + 3, -267386864, -267386864);
|
||||
drawGradientRect(l1 - 4, i2 - 3, l1 - 3, i2 + k + 3, -267386864, -267386864);
|
||||
drawGradientRect(l1 + i + 3, i2 - 3, l1 + i + 4, i2 + k + 3, -267386864, -267386864);
|
||||
drawGradientRect(l1 - 3, i2 - 3 + 1, l1 - 3 + 1, i2 + k + 3 - 1, 1347420415, 1344798847);
|
||||
drawGradientRect(l1 + i + 2, i2 - 3 + 1, l1 + i + 3, i2 + k + 3 - 1, 1347420415, 1344798847);
|
||||
drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 - 3 + 1, 1347420415, 1347420415);
|
||||
drawGradientRect(l1 - 3, i2 + k + 2, l1 + i + 3, i2 + k + 3, 1344798847, 1344798847);
|
||||
for (String s1 : textLines) {
|
||||
fontRendererObj.drawStringWithShadow(s1, l1, i2, -1);
|
||||
i2 += 10;
|
||||
}
|
||||
zLevel = 0.0F;
|
||||
itemRender.zLevel = 0.0F;
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.enableDepth();
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function handles events within the interface.
|
||||
* Specifically, handles mouse wheel within interface.
|
||||
@@ -292,7 +336,7 @@ public class JecaGui extends GuiContainer {
|
||||
boolean unicode = fontRendererObj.getUnicodeFlag();
|
||||
if (f.half) fontRendererObj.setUnicodeFlag(false);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(unicode && f.half ? xPos - 5 : xPos, yPos, 0);
|
||||
GlStateManager.translate(xPos, yPos, 0);
|
||||
if (f.half) GlStateManager.scale(0.5, 0.5, 1);
|
||||
r.run();
|
||||
GlStateManager.popMatrix();
|
||||
@@ -349,7 +393,12 @@ public class JecaGui extends GuiContainer {
|
||||
}
|
||||
|
||||
public int getTextWidth(String s) {
|
||||
return (int) Math.ceil(getCurrent().fontRendererObj.getStringWidth(s) * (half ? 0.5f : 1));
|
||||
FontRenderer fr = getCurrent().fontRendererObj;
|
||||
boolean flag = fr.getUnicodeFlag();
|
||||
if (half) fr.setUnicodeFlag(false);
|
||||
int ret = (int) Math.ceil(fr.getStringWidth(s) * (half ? 0.5f : 1));
|
||||
fr.setUnicodeFlag(flag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int getTextHeight() {
|
||||
|
||||
@@ -104,6 +104,26 @@ public class Resource {
|
||||
public static final Resource WGT_SCROLL = new Resource(133, 132, 14, 17);
|
||||
public static final Resource WGT_HELP_F = new Resource(147, 132, 20, 20);
|
||||
public static final Resource WGT_HELP_N = new Resource(167, 132, 20, 20);
|
||||
public static final Resource WGT_LCD_UL_F = new Resource(187, 132, 4, 16);
|
||||
public static final Resource WGT_LCD_UR_F = new Resource(191, 132, 4, 16);
|
||||
public static final Resource WGT_LCD_LL_F = new Resource(195, 132, 4, 16);
|
||||
public static final Resource WGT_LCD_LR_F = new Resource(199, 132, 4, 16);
|
||||
public static final Resource WGT_LCD_H_F = new Resource(187, 148, 12, 4);
|
||||
public static final Resource WGT_LCD_DO_F = new Resource(199, 148, 4, 4);
|
||||
public static final Resource WGT_LCD_UL_N = new Resource(203, 132, 4, 16);
|
||||
public static final Resource WGT_LCD_UR_N = new Resource(207, 132, 4, 16);
|
||||
public static final Resource WGT_LCD_LL_N = new Resource(211, 132, 4, 16);
|
||||
public static final Resource WGT_LCD_LR_N = new Resource(215, 132, 4, 16);
|
||||
public static final Resource WGT_LCD_H_N = new Resource(203, 148, 12, 4);
|
||||
public static final Resource WGT_LCD_DO_N = new Resource(215, 148, 4, 4);
|
||||
public static final Resource WGT_LCD_P_F = new Resource(219, 132, 7, 7);
|
||||
public static final Resource WGT_LCD_M_F = new Resource(226, 132, 7, 7);
|
||||
public static final Resource WGT_LCD_T_F = new Resource(233, 132, 7, 7);
|
||||
public static final Resource WGT_LCD_D_F = new Resource(240, 132, 7, 7);
|
||||
public static final Resource WGT_LCD_P_N = new Resource(219, 139, 7, 7);
|
||||
public static final Resource WGT_LCD_M_N = new Resource(226, 139, 7, 7);
|
||||
public static final Resource WGT_LCD_T_N = new Resource(233, 139, 7, 7);
|
||||
public static final Resource WGT_LCD_D_N = new Resource(240, 139, 7, 7);
|
||||
|
||||
public static final Resource ICN_RECENT_N = getIcon(0, 7);
|
||||
public static final Resource ICN_RECENT_F = getIcon(0, 6);
|
||||
@@ -184,6 +204,10 @@ public class Resource {
|
||||
this(xPos, yPos, xSize, ySize, location);
|
||||
}
|
||||
|
||||
public Resource sub(int xPos, int yPos, int xSize, int ySize) {
|
||||
return new Resource(this.xPos + xPos, this.yPos + yPos, xSize, ySize);
|
||||
}
|
||||
|
||||
public int getXPos() {
|
||||
return xPos;
|
||||
}
|
||||
|
||||
+42
-32
@@ -5,6 +5,7 @@ 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.RecordCraft;
|
||||
import me.towdium.jecalculation.gui.JecaGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.widgets.*;
|
||||
@@ -27,13 +28,14 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiCalculator 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, "calculator.step")
|
||||
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));
|
||||
@@ -41,38 +43,43 @@ public class GuiCalculator extends WContainer implements IGui {
|
||||
.setListener(i -> setMode(Mode.OUTPUT));
|
||||
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());
|
||||
|
||||
WLabel label = new WLabel(31, 7, 20, 20, WLabel.Mode.SELECTOR).setListener((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 -> {
|
||||
record.amount = i.getText();
|
||||
Controller.setRCraft(record);
|
||||
refreshCalculator();
|
||||
});
|
||||
WLabel label = new WLabel(31, 7, 20, 20, WLabel.Mode.SELECTOR).setListener((i, v) -> refreshLabel(v, false));
|
||||
WButton invE = new WButtonIcon(149, 62, 20, 20, Resource.BTN_INV_E, "calculator.inventory_enabled");
|
||||
WButton invD = new WButtonIcon(149, 62, 20, 20, Resource.BTN_INV_D, "calculator.inventory_disabled");
|
||||
|
||||
public GuiCalculator() {
|
||||
add(new WHelp("calculator"));
|
||||
|
||||
public GuiCraft() {
|
||||
add(new WHelp("craft"));
|
||||
add(new WPanel());
|
||||
add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL, "calculator.label")
|
||||
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, "calculator.recipe")
|
||||
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, "calculator.search")
|
||||
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 WLine(55));
|
||||
add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT, "calculator.history"));
|
||||
add(recent, label, input, output, catalyst, steps, result, amount, Controller.getDetectInv() ? invE : invD);
|
||||
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);
|
||||
invE.setListener(i -> {
|
||||
Controller.setDetectInv(false);
|
||||
record.inventory = false;
|
||||
Controller.setRCraft(record);
|
||||
remove(invE);
|
||||
add(invD);
|
||||
refreshCalculator();
|
||||
});
|
||||
invD.setListener(i -> {
|
||||
Controller.setDetectInv(true);
|
||||
record.inventory = true;
|
||||
Controller.setRCraft(record);
|
||||
remove(invD);
|
||||
add(invE);
|
||||
refreshCalculator();
|
||||
@@ -96,9 +103,8 @@ public class GuiCalculator extends WContainer implements IGui {
|
||||
}
|
||||
|
||||
void refreshRecent() {
|
||||
List<ILabel> labels = Controller.getRecent();
|
||||
label.setLabel(labels.isEmpty() ? ILabel.EMPTY : labels.get(0));
|
||||
recent.setLabel(labels.isEmpty() ? new ArrayList<>() : labels.subList(1, labels.size()), 0);
|
||||
label.setLabel(record.getLatest());
|
||||
recent.setLabel(record.getHistory(), 0);
|
||||
}
|
||||
|
||||
void refreshCalculator() {
|
||||
@@ -107,7 +113,7 @@ public class GuiCalculator extends WContainer implements IGui {
|
||||
long i = s.isEmpty() ? 1 : Long.parseLong(amount.getText());
|
||||
amount.setColor(JecaGui.COLOR_TEXT_WHITE);
|
||||
List<ILabel> dest = Collections.singletonList(label.getLabel().copy().setAmount(i));
|
||||
CostList list = Controller.getDetectInv() ? new CostList(getInventory(), dest) : new CostList(dest);
|
||||
CostList list = record.inventory ? new CostList(getInventory(), dest) : new CostList(dest);
|
||||
calculator = list.calculate();
|
||||
} catch (NumberFormatException | ArithmeticException e) {
|
||||
amount.setColor(JecaGui.COLOR_TEXT_RED);
|
||||
@@ -149,11 +155,12 @@ public class GuiCalculator extends WContainer implements IGui {
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshLabel(ILabel l, boolean replace) {
|
||||
Controller.setRecent(l, replace);
|
||||
private void refreshLabel(ILabel l, boolean replace, boolean suggest) {
|
||||
boolean dup = record.push(l, replace);
|
||||
Controller.setRCraft(record);
|
||||
refreshRecent();
|
||||
refreshCalculator();
|
||||
if (findRecipe(l).isEmpty()) {
|
||||
if (suggest && findRecipe(l).isEmpty()) {
|
||||
Pair<List<ILabel>, List<ILabel>> guess = ILabel.CONVERTER.guess(Collections.singletonList(l));
|
||||
LinkedHashSet<ILabel> match = new LinkedHashSet<>();
|
||||
List<ILabel> fuzzy = new ArrayList<>();
|
||||
@@ -164,7 +171,7 @@ public class GuiCalculator extends WContainer implements IGui {
|
||||
});
|
||||
match.addAll(fuzzy);
|
||||
List<ILabel> list = new ArrayList<>(match);
|
||||
if (!match.isEmpty()) add(new Suggest(list.size() > 3 ? list.subList(0, 3) : list));
|
||||
if (!match.isEmpty()) add(new Suggest(list.size() > 3 ? list.subList(0, 3) : list, !dup));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,12 +187,15 @@ public class GuiCalculator extends WContainer implements IGui {
|
||||
INPUT, OUTPUT, CATALYST, STEPS
|
||||
}
|
||||
class Suggest extends WContainer {
|
||||
public Suggest(List<ILabel> labels) {
|
||||
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.SELECTOR).setLabel(label.getLabel())
|
||||
.setListener((i, v) -> refresh(v)));
|
||||
add(new WIcon(5 - width, 7, 18, 20, Resource.ICN_HELP, "calculator.suggest"));
|
||||
add(new WLabel(31, 7, 20, 20, WLabel.Mode.PICKER).setLabel(label.getLabel())
|
||||
.setListener((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))
|
||||
@@ -194,13 +204,13 @@ public class GuiCalculator extends WContainer implements IGui {
|
||||
}
|
||||
|
||||
public void refresh(ILabel l) {
|
||||
GuiCalculator.this.remove(this);
|
||||
refreshLabel(l, true);
|
||||
GuiCraft.this.remove(this);
|
||||
refreshLabel(l, replace, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
|
||||
if (!super.onClicked(gui, xMouse, yMouse, button)) GuiCalculator.this.remove(this);
|
||||
if (!super.onClicked(gui, xMouse, yMouse, button)) GuiCraft.this.remove(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -208,7 +218,7 @@ public class GuiCalculator extends WContainer implements IGui {
|
||||
public boolean onKey(JecaGui gui, char ch, int code) {
|
||||
if (!super.onKey(gui, ch, code)) {
|
||||
if (code == Keyboard.KEY_ESCAPE) {
|
||||
GuiCalculator.this.remove(this);
|
||||
GuiCraft.this.remove(this);
|
||||
return true;
|
||||
} else return false;
|
||||
} else return true;
|
||||
+2
-2
@@ -19,12 +19,12 @@ import static me.towdium.jecalculation.gui.Resource.*;
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiDisambiguation extends IPicker.Impl implements IGui {
|
||||
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 List<List<ILabel>> record;
|
||||
|
||||
public GuiDisambiguation(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));
|
||||
@@ -0,0 +1,189 @@
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import me.towdium.jecalculation.data.Controller;
|
||||
import me.towdium.jecalculation.data.structure.RecordMath;
|
||||
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.utils.Utilities;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.LinkedList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static me.towdium.jecalculation.data.structure.RecordMath.DOT_NONE;
|
||||
import static me.towdium.jecalculation.data.structure.RecordMath.context;
|
||||
|
||||
/**
|
||||
* Author: Towdium
|
||||
* Date: 19-1-3
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class GuiMath extends WContainer implements IGui {
|
||||
WLcd lcd = new WLcd(7);
|
||||
LinkedList<BigDecimal> numbers;
|
||||
BigDecimal last;
|
||||
int dot;
|
||||
boolean sign;
|
||||
Operator operator;
|
||||
State state;
|
||||
|
||||
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 -> {
|
||||
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 WLine(61), new WLine(103, 61, 98, false), new WLine.Joint(103, 61, false, true, true, true));
|
||||
RecordMath recordMath = Controller.getRMath();
|
||||
state = recordMath.state;
|
||||
operator = recordMath.operator;
|
||||
last = recordMath.last;
|
||||
dot = recordMath.getDot();
|
||||
sign = recordMath.getSign();
|
||||
numbers = recordMath.getNumbers();
|
||||
print();
|
||||
}
|
||||
|
||||
private void print() {
|
||||
if (state == State.INPUT) {
|
||||
String s = numbers.isEmpty() ? "0" : numbers.stream().map(Object::toString).collect(Collectors.joining());
|
||||
if (!sign)
|
||||
s = '-' + Utilities.repeat(" ", 6 - s.length()) + s;
|
||||
lcd.text = s;
|
||||
lcd.dot = dot;
|
||||
} else if (state == State.ERROR) {
|
||||
lcd.text = "Error";
|
||||
lcd.dot = DOT_NONE;
|
||||
} else if (state == State.OUTPUT) {
|
||||
lcd.print(last);
|
||||
}
|
||||
lcd.operator = operator;
|
||||
}
|
||||
|
||||
private void append(int i) {
|
||||
if (state != State.INPUT)
|
||||
state = State.INPUT;
|
||||
if ((i != 0 || !numbers.isEmpty()) && numbers.size() < (sign ? 7 : 6)) {
|
||||
numbers.add(new BigDecimal(i));
|
||||
if (dot != DOT_NONE)
|
||||
dot++;
|
||||
}
|
||||
print();
|
||||
sync();
|
||||
}
|
||||
|
||||
private void sync() {
|
||||
Controller.setRMath(new RecordMath(state, operator, last, sign, dot, numbers));
|
||||
}
|
||||
|
||||
private void operate(Operator operator) {
|
||||
if (state == State.INPUT && numbers.isEmpty() && operator == Operator.MINUS)
|
||||
sign = !sign;
|
||||
else {
|
||||
if (state == State.INPUT) {
|
||||
try {
|
||||
last = this.operator.operate(last, convert());
|
||||
} catch (ArithmeticException e) {
|
||||
state = State.ERROR;
|
||||
this.operator = Operator.EQUALS;
|
||||
print();
|
||||
sync();
|
||||
return;
|
||||
} finally {
|
||||
numbers.clear();
|
||||
dot = DOT_NONE;
|
||||
sign = true;
|
||||
}
|
||||
}
|
||||
this.operator = operator;
|
||||
state = State.OUTPUT;
|
||||
}
|
||||
print();
|
||||
sync();
|
||||
}
|
||||
|
||||
private void dot() {
|
||||
if (state != State.INPUT)
|
||||
state = State.INPUT;
|
||||
if (numbers.size() == 0)
|
||||
numbers.add(BigDecimal.ZERO);
|
||||
dot = 0;
|
||||
print();
|
||||
sync();
|
||||
}
|
||||
|
||||
|
||||
private void remove() {
|
||||
if (state != State.INPUT)
|
||||
reset();
|
||||
if (numbers.size() > 0) {
|
||||
numbers.removeLast();
|
||||
if (dot != DOT_NONE)
|
||||
dot--;
|
||||
}
|
||||
print();
|
||||
sync();
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
last = BigDecimal.ZERO;
|
||||
operator = Operator.EQUALS;
|
||||
numbers.clear();
|
||||
dot = DOT_NONE;
|
||||
sign = true;
|
||||
state = State.INPUT;
|
||||
print();
|
||||
sync();
|
||||
}
|
||||
|
||||
private BigDecimal convert() {
|
||||
BigDecimal f = new BigDecimal(0);
|
||||
for (BigDecimal i : numbers)
|
||||
f = f.add(i).multiply(BigDecimal.TEN);
|
||||
f = f.divide(BigDecimal.TEN.pow(Math.max(dot, 0) + 1), context);
|
||||
if (!sign)
|
||||
f = f.negate();
|
||||
return f;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import me.towdium.jecalculation.data.Controller;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
@@ -16,7 +15,7 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static me.towdium.jecalculation.gui.Resource.*;
|
||||
|
||||
/**
|
||||
@@ -41,13 +40,14 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
refresh();
|
||||
});
|
||||
WButton buttonDisamb = new WButtonIcon(121, 31, 20, 20, BTN_DISAMB, "recipe.disamb").setListener(i -> {
|
||||
if (disambiguation != null) JecaGui.displayGui(new GuiDisambiguation(new ArrayList<>(disambiguation.values()))
|
||||
if (disambiguation != null) JecaGui.displayGui(new GuiDisamb(new ArrayList<>(disambiguation.values()))
|
||||
.setCallback(l -> {
|
||||
JecaGui.displayParent();
|
||||
JecaGui.getCurrent().hand = l;
|
||||
}));
|
||||
});
|
||||
WButton buttonClear = new WButtonIcon(64, 31, 20, 20, BTN_DEL, "recipe.clear").setListener(i -> clear());
|
||||
// check duplicate and valid
|
||||
WButton buttonCopy = new WButtonIcon(83, 31, 20, 20, BTN_COPY, "recipe.copy").setListener(i -> {
|
||||
Controller.addRecipe(switcherGroup.getText(), toRecipe());
|
||||
JecaGui.displayParent();
|
||||
@@ -101,6 +101,10 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
add(new WLine(57));
|
||||
add(groupInput, groupCatalyst, groupOutput, switcherGroup);
|
||||
if (switcherGroup.getTexts().isEmpty()) switcherGroup.setTemp(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);
|
||||
setNewGroup(false);
|
||||
buttonCopy.setDisabled(true);
|
||||
buttonDel.setDisabled(true);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class GuiSearch extends WContainer implements IGui {
|
||||
.forEach(add);
|
||||
} else {
|
||||
String s = group.getText();
|
||||
Streams.mapWithIndex(Controller.getRecipes(s).stream(), (j, k) -> new Trio<>(j, s, (int) k))
|
||||
Streams.mapWithIndex(Controller.recipeIterator(s).stream(), (j, k) -> new Trio<>(j, s, (int) k))
|
||||
.forEach(add);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.gui.JecaGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.utils.ClientUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -23,6 +26,7 @@ public abstract class WButton extends WTooltip {
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
protected ListenerAction<? super WButton> listener;
|
||||
protected boolean disabled;
|
||||
protected int[] keys;
|
||||
|
||||
public WButton(int xPos, int yPos, int xSize, int ySize, @Nullable String name) {
|
||||
super(name);
|
||||
@@ -41,16 +45,31 @@ 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
|
||||
if (!disabled && JecaGui.mouseIn(xPos + 1, yPos + 1, xSize - 2, ySize - 2, xMouse, yMouse)) {
|
||||
if (button == 0 && listener != null) {
|
||||
listener.invoke(this);
|
||||
ClientUtils.playClickSound(1.0F);
|
||||
if (JecaGui.mouseIn(xPos + 1, yPos + 1, xSize - 2, ySize - 2, xMouse, yMouse) &&
|
||||
!disabled && button == 0 && listener != null) {
|
||||
trigger();
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
private void trigger() {
|
||||
listener.invoke(this);
|
||||
ClientUtils.playClickSound(1.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKey(JecaGui gui, char ch, int code) {
|
||||
// JustEnoughCalculation.logger.info(code);
|
||||
if (keys != null) for (int i : keys) {
|
||||
if (i == code) {
|
||||
trigger();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -72,4 +91,9 @@ public abstract class WButton extends WTooltip {
|
||||
protected List<String> getSuffix() {
|
||||
return disabled ? Arrays.asList("disabled", "enabled", "") : Arrays.asList("enabled", "");
|
||||
}
|
||||
|
||||
public WButton setKeyBind(int... keys) {
|
||||
this.keys = keys;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.gui.JecaGui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
@@ -12,12 +13,16 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class WButtonText extends WButton { // TODO need rework for text without need for localization
|
||||
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 String text;
|
||||
|
||||
public WButtonText(int xPos, int yPos, int xSize, int ySize, String name, String text) {
|
||||
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) {
|
||||
super(xPos, yPos, xSize, ySize, name);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class WLabel implements IWidget {
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
|
||||
if (!mouseIn(xMouse, yMouse))
|
||||
if (!mouseIn(xMouse, yMouse) || (button == 1 && mode != Mode.RESULT))
|
||||
return false;
|
||||
switch (mode) {
|
||||
case EDITOR:
|
||||
@@ -160,7 +160,7 @@ public class WLabel implements IWidget {
|
||||
|
||||
public enum Mode {
|
||||
EDITOR, // Slots in editor gui. Can use to edit amount. Exact amount displayed.
|
||||
RESULT, // Slots to display calculate/getRecipes result. Rounded amount displayed.
|
||||
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.
|
||||
}
|
||||
@@ -168,10 +168,10 @@ public class WLabel implements IWidget {
|
||||
|
||||
class WAmount extends WContainer {
|
||||
long old = label.getAmount();
|
||||
WButton bAmount = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "general.to_percent", "#")
|
||||
WButton bAmount = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "#", "general.to_percent")
|
||||
.setListener(i -> setPercent(true));
|
||||
WTextField wtf = new WTextField(xPos + xSize + 10, yPos + ySize / 2 - WTextField.HEIGHT / 2, 50);
|
||||
WButton bPercent = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "general.to_percent", "%")
|
||||
WButton bPercent = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "%", "general.to_percent")
|
||||
.setListener(i -> setPercent(false));
|
||||
WLabel wl = new WLabel(xPos, yPos, xSize, ySize, Mode.SELECTOR).setListener((i, v) -> update());
|
||||
WButton bYes = new WButtonIcon(xPos + xSize + 83, yPos, 20, 20, BTN_YES)
|
||||
@@ -205,6 +205,7 @@ public class WLabel implements IWidget {
|
||||
}
|
||||
|
||||
private void update() {
|
||||
label = wl.label;
|
||||
bAmount.setDisabled(!label.acceptPercent());
|
||||
if (label.isPercent()) {
|
||||
remove(bAmount);
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
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 javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
import static me.towdium.jecalculation.data.structure.RecordMath.DOT_NONE;
|
||||
|
||||
|
||||
/**
|
||||
* Author: Towdium
|
||||
* Date: 19-1-16
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WLcd implements IWidget {
|
||||
static HashMap<Character, boolean[]> PATTERN = new HashMap<>();
|
||||
|
||||
|
||||
public int yPos;
|
||||
public String text = "";
|
||||
public int dot = DOT_NONE;
|
||||
static NumberFormat format = new DecimalFormat("0.0E0");
|
||||
public Operator operator = Operator.EQUALS;
|
||||
|
||||
static {
|
||||
PATTERN.put('0', new boolean[]{true, true, true, true, true, true, false});
|
||||
PATTERN.put('1', new boolean[]{false, true, true, false, false, false, false});
|
||||
PATTERN.put('2', new boolean[]{true, true, false, true, true, false, true});
|
||||
PATTERN.put('3', new boolean[]{true, true, true, true, false, false, true});
|
||||
PATTERN.put('4', new boolean[]{false, true, true, false, false, true, true});
|
||||
PATTERN.put('5', new boolean[]{true, false, true, true, false, true, true});
|
||||
PATTERN.put('6', new boolean[]{true, false, true, true, true, true, true});
|
||||
PATTERN.put('7', new boolean[]{true, true, true, false, false, false, false});
|
||||
PATTERN.put('8', new boolean[]{true, true, true, true, true, true, true});
|
||||
PATTERN.put('9', new boolean[]{true, true, true, true, false, true, true});
|
||||
PATTERN.put('E', new boolean[]{true, false, false, true, true, true, true});
|
||||
PATTERN.put('o', new boolean[]{false, false, true, true, true, false, true});
|
||||
PATTERN.put('r', new boolean[]{false, false, false, false, true, false, true});
|
||||
PATTERN.put('-', new boolean[]{false, false, false, false, false, false, true});
|
||||
PATTERN.put(' ', new boolean[]{false, false, false, false, false, false, false});
|
||||
//format.setMinimumIntegerDigits(0);
|
||||
}
|
||||
|
||||
public WLcd(int yPos) {
|
||||
this.yPos = yPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
|
||||
drawBackground(gui);
|
||||
drawStr(gui, text);
|
||||
if (dot != DOT_NONE)
|
||||
drawDot(gui, 6 - dot);
|
||||
drawOperator(gui, operator);
|
||||
}
|
||||
|
||||
protected void drawBackground(JecaGui gui) {
|
||||
gui.drawResourceContinuous(Resource.WGT_LCD_BG, 7, yPos, 162, 50, 8);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
gui.drawResource(Resource.WGT_LCD_UL_N, 16 + i * 21, yPos + 14);
|
||||
gui.drawResource(Resource.WGT_LCD_UR_N, 30 + i * 21, yPos + 14);
|
||||
gui.drawResource(Resource.WGT_LCD_LL_N, 16 + i * 21, yPos + 28);
|
||||
gui.drawResource(Resource.WGT_LCD_LR_N, 30 + i * 21, yPos + 28);
|
||||
gui.drawResource(Resource.WGT_LCD_H_N, 19 + i * 21, yPos + 14);
|
||||
gui.drawResource(Resource.WGT_LCD_H_N, 19 + i * 21, yPos + 27);
|
||||
gui.drawResource(Resource.WGT_LCD_H_N, 19 + i * 21, yPos + 40);
|
||||
gui.drawResource(Resource.WGT_LCD_DO_N, 33 + i * 21, yPos + 40);
|
||||
}
|
||||
gui.drawResource(Resource.WGT_LCD_P_N, 132, yPos + 6);
|
||||
gui.drawResource(Resource.WGT_LCD_M_N, 139, yPos + 6);
|
||||
gui.drawResource(Resource.WGT_LCD_T_N, 146, yPos + 6);
|
||||
gui.drawResource(Resource.WGT_LCD_D_N, 153, yPos + 6);
|
||||
}
|
||||
|
||||
protected void drawChar(JecaGui gui, char ch, int index) {
|
||||
boolean[] pattern = PATTERN.get(ch);
|
||||
Objects.requireNonNull(pattern, "Unsupported char: " + ch + ".");
|
||||
if (pattern[0])
|
||||
gui.drawResource(Resource.WGT_LCD_H_F, 19 + index * 21, yPos + 14);
|
||||
if (pattern[1])
|
||||
gui.drawResource(Resource.WGT_LCD_UR_F, 30 + index * 21, yPos + 14);
|
||||
if (pattern[2])
|
||||
gui.drawResource(Resource.WGT_LCD_LR_F, 30 + index * 21, yPos + 28);
|
||||
if (pattern[3])
|
||||
gui.drawResource(Resource.WGT_LCD_H_F, 19 + index * 21, yPos + 40);
|
||||
if (pattern[4])
|
||||
gui.drawResource(Resource.WGT_LCD_LL_F, 16 + index * 21, yPos + 28);
|
||||
if (pattern[5])
|
||||
gui.drawResource(Resource.WGT_LCD_UL_F, 16 + index * 21, yPos + 14);
|
||||
if (pattern[6])
|
||||
gui.drawResource(Resource.WGT_LCD_H_F, 19 + index * 21, yPos + 27);
|
||||
}
|
||||
|
||||
protected void drawStr(JecaGui gui, String str) {
|
||||
int offset = 7 - str.length();
|
||||
for (int i = offset; i < 7; i++)
|
||||
drawChar(gui, str.charAt(i - offset), i);
|
||||
}
|
||||
|
||||
protected void drawDot(JecaGui gui, int index) {
|
||||
gui.drawResource(Resource.WGT_LCD_DO_F, 33 + index * 21, yPos + 40);
|
||||
}
|
||||
|
||||
protected void drawOperator(JecaGui gui, Operator operator) {
|
||||
switch (operator) {
|
||||
case PLUS:
|
||||
gui.drawResource(Resource.WGT_LCD_P_F, 132, yPos + 6);
|
||||
break;
|
||||
case MINUS:
|
||||
gui.drawResource(Resource.WGT_LCD_M_F, 139, yPos + 6);
|
||||
break;
|
||||
case TIMES:
|
||||
gui.drawResource(Resource.WGT_LCD_T_F, 146, yPos + 6);
|
||||
break;
|
||||
case DIVIDE:
|
||||
gui.drawResource(Resource.WGT_LCD_D_F, 153, yPos + 6);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void print(BigDecimal num) {
|
||||
String s = num.stripTrailingZeros().toPlainString();
|
||||
double f = num.floatValue();
|
||||
int len = f > 0 ? 7 : 6;
|
||||
int sca = num.unscaledValue().abs().toString().length() - num.scale() - 1;
|
||||
if (Math.abs(sca) > len) {
|
||||
String scale = String.valueOf(sca);
|
||||
len -= scale.length() + 2;
|
||||
format.setMaximumFractionDigits(len);
|
||||
s = format.format(num);
|
||||
}
|
||||
int d = s.indexOf('.');
|
||||
if (d >= 0 && d <= 7) {
|
||||
text = s.substring(0, d) + s.substring(d + 1, Math.min(s.length(), 8));
|
||||
dot = text.length() - d;
|
||||
} else {
|
||||
text = s;
|
||||
dot = DOT_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,4 +36,38 @@ public class WLine implements IWidget {
|
||||
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
|
||||
gui.drawResourceContinuous(Resource.WGT_SLOT, xPos, yPos, xSize, ySize, 1);
|
||||
}
|
||||
|
||||
public static class Joint implements IWidget {
|
||||
int xPos, yPos;
|
||||
boolean up, down, left, right;
|
||||
public static Resource u = Resource.WGT_SLOT.sub(9, 0, 2, 1);
|
||||
public static Resource d = Resource.WGT_SLOT.sub(9, 19, 2, 1);
|
||||
public static Resource l = Resource.WGT_SLOT.sub(0, 9, 1, 2);
|
||||
public static Resource r = Resource.WGT_SLOT.sub(19, 9, 1, 2);
|
||||
public static Resource ul = Resource.WGT_SLOT.sub(0, 0, 1, 1);
|
||||
public static Resource ur = Resource.WGT_SLOT.sub(19, 0, 1, 1);
|
||||
public static Resource ll = Resource.WGT_SLOT.sub(0, 19, 1, 1);
|
||||
public static Resource lr = Resource.WGT_SLOT.sub(19, 19, 1, 1);
|
||||
|
||||
public Joint(int xPos, int yPos, boolean up, boolean down, boolean left, boolean right) {
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.up = up;
|
||||
this.down = down;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(JecaGui gui, int xMouse, int yMouse) {
|
||||
if (!up) gui.drawResource(u, xPos, yPos);
|
||||
if (!down) gui.drawResource(d, xPos, yPos + 1);
|
||||
if (!left) gui.drawResource(l, xPos, yPos);
|
||||
if (!right) gui.drawResource(r, xPos + 1, yPos);
|
||||
if (left == up) gui.drawResource(ul, xPos, yPos);
|
||||
if (right == up) gui.drawResource(ur, xPos + 1, yPos);
|
||||
if (left == down) gui.drawResource(ll, xPos, 1 + yPos);
|
||||
if (right == down) gui.drawResource(lr, xPos + 1, yPos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ 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.gui.Resource;
|
||||
|
||||
@@ -42,9 +43,10 @@ public class WPanel implements IWidget {
|
||||
|
||||
@Override
|
||||
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
|
||||
return mouseIn(xMouse, yMouse);
|
||||
boolean ret = mouseIn(xMouse, yMouse);
|
||||
if (ret) gui.hand = ILabel.EMPTY;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean mouseIn(int x, int y) {
|
||||
int xx = x - xPos;
|
||||
int yy = y - yPos;
|
||||
|
||||
@@ -43,8 +43,7 @@ public abstract class WTooltip implements IWidget {
|
||||
.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);
|
||||
if (str != null) Collections.addAll(tooltip, str.split("\n"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,11 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.client.ClientCommandHandler;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import static org.lwjgl.input.Keyboard.KEY_NONE;
|
||||
|
||||
public class ClientHandler {
|
||||
public static final KeyBinding keyOpenGui = new KeyBinding("jecalculation.key.open_gui", Keyboard.KEY_NONE, "jecalculation.key.category");
|
||||
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();
|
||||
@@ -26,7 +29,8 @@ public class ClientHandler {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
ClientRegistry.registerKeyBinding(keyOpenGui);
|
||||
ClientRegistry.registerKeyBinding(keyOpenGuiCraft);
|
||||
ClientRegistry.registerKeyBinding(keyOpenGuiMath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -317,11 +317,12 @@ public class Utilities {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public void push(T obj, boolean replace) {
|
||||
public boolean push(T obj, boolean replace) {
|
||||
if (replace) data.pop();
|
||||
data.removeIf(t -> tester != null ? tester.test(t, obj) : t.equals(obj));
|
||||
boolean ret = data.removeIf(t -> tester != null ? tester.test(t, obj) : t.equals(obj));
|
||||
data.addFirst(obj);
|
||||
if (data.size() > limit) data.removeLast();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<T> toList() {
|
||||
@@ -332,6 +333,10 @@ public class Utilities {
|
||||
public void clear() {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return data.size();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Json {
|
||||
|
||||
Reference in new issue
Block a user