feat: client only backport finish

This commit is contained in:
Discreater committed 2021-05-02 00:23:13 +08:00
1 parent 1d70f6bce9
commit 33b6ff5467
19 files changed
+296 -186

No files matched your search

@@ -4,6 +4,7 @@ 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.labels.LPlaceholder;
import me.towdium.jecalculation.data.structure.*;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.guis.GuiCraft;
@@ -141,6 +142,11 @@ public class Controller {
writeToLocal();
}
public static void removeGroup(String group) {
getRecipes().remove(group);
setLast(group);
}
public static Recipe getRecipe(String group, int index) {
return getRecipes().getRecipe(group, index);
}
@@ -216,6 +222,8 @@ public class Controller {
JecaConfig.dataDir.mkdirs();
File file = JecaConfig.recordFile;
NBTTagCompound nbt = Utilities.Json.read(file);
boolean s = LPlaceholder.state;
LPlaceholder.state = true;
if (nbt != null) {
rCraftClient = new RecordCraft(nbt.getCompoundTag(KEY_CRAFT));
rMathClient = new RecordMath(nbt.getCompoundTag(KEY_MATH));
@@ -225,6 +233,7 @@ public class Controller {
rCraftClient = new RecordCraft(new NBTTagCompound());
rMathClient = new RecordMath(new NBTTagCompound());
}
LPlaceholder.state = s;
}
public static void writeToLocal() {
@@ -17,7 +17,9 @@ import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.init.Items;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidRegistry;
@@ -245,8 +247,14 @@ public interface ILabel {
return new LItemStack((ItemStack) o);
else if (o instanceof FluidStack)
return new LFluidStack((FluidStack) o);
else
throw new RuntimeException("Unrecognized ingredient type: " + o.getClass());
else if (o instanceof EnchantmentData) {
ItemStack itemStack = new ItemStack(Items.enchanted_book);
new ItemEnchantedBook().addEnchantment(itemStack, (EnchantmentData) o);
return new LItemStack(itemStack);
} else {
JustEnoughCalculation.logger.warn("Unrecognized ingredient type: " + o.getClass());
return ILabel.EMPTY;
}
}
public void register(ConverterFunction handler, Priority priority) {
@@ -57,27 +57,6 @@ public class LOreDict extends ILabel.Impl {
name = nbt.getString(KEY_NAME);
}
@Override
@Nonnull
public ItemStack getRepresentation() {
NonNullList<ItemStack> list = NonNullList.create();
OreDictionary.getOres(name).forEach(is -> {
if (is.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
is.getItem().getSubItems(is.getItem(), CreativeTabs.tabAllSearch, list);
} else
list.add(is);
});
if (list.isEmpty()) return ItemStackHelper.EMPTY_ITEM_STACK;
long index = System.currentTimeMillis() / 1500;
return list.get((int) (index % list.size()));
}
@Override
@SideOnly(Side.CLIENT)
public String getDisplayName() {
return Utilities.I18n.get("label.ore_dict.name", name);
}
public static boolean mergeSame(ILabel a, ILabel b) {
if (a instanceof LOreDict && b instanceof LOreDict) {
LOreDict lodA = (LOreDict) a;
@@ -90,9 +69,9 @@ public class LOreDict extends ILabel.Impl {
if (a instanceof LOreDict && b instanceof LItemStack) {
LOreDict lod = (LOreDict) a;
LItemStack lis = (LItemStack) b;
return OreDictionary.getOres(lod.name).stream()
.map(Converter::from)
.anyMatch(i -> LItemStack.merge(i, lis));
return lod.getAmount() * lis.getAmount() < 0
&& OreDictionary.getOres(lod.name).stream().map(Converter::from)
.anyMatch(i -> LItemStack.merge(i, lis));
}
return false;
}
@@ -137,6 +116,27 @@ public class LOreDict extends ILabel.Impl {
return acceptable.value;
}
@Override
@Nonnull
public ItemStack getRepresentation() {
NonNullList<ItemStack> list = NonNullList.create();
OreDictionary.getOres(name).forEach(is -> {
if (is.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
is.getItem().getSubItems(is.getItem(), CreativeTabs.tabAllSearch, list);
} else list.add(is);
});
if (list.isEmpty()) return ItemStackHelper.EMPTY_ITEM_STACK;
long index = System.currentTimeMillis() / 1500;
return list.get((int) (index % list.size()));
}
@Override
@SideOnly(Side.CLIENT)
public String getDisplayName() {
return Utilities.I18n.get("label.ore_dict.name", name);
}
@Override
public String getIdentifier() {
return IDENTIFIER;
@@ -22,14 +22,20 @@ import java.util.stream.Collectors;
public class LPlaceholder extends ILabel.Impl {
public static final String KEY_NAME = "name";
public static final String IDENTIFIER = "placeholder";
public static boolean state = true; // true for client, false for server
static Utilities.Recent<LPlaceholder> recentClient = new Utilities.Recent<>(100);
static Utilities.Recent<LPlaceholder> recentServer = new Utilities.Recent<>(100);
String name;
static Utilities.Recent<LPlaceholder> getActive() {
return state ? recentClient : recentServer;
}
public LPlaceholder(NBTTagCompound tag) {
super(tag);
name = tag.getString(KEY_NAME);
getActive().push(new LPlaceholder(name, 1, true), false);
}
public LPlaceholder(String name, long amount) {
@@ -39,7 +45,7 @@ public class LPlaceholder extends ILabel.Impl {
public LPlaceholder(String name, long amount, boolean silent) {
super(amount, false);
this.name = name;
if (!silent) getRecord().push(new LPlaceholder(name, 1, true), false);
if (!silent) getActive().push(new LPlaceholder(name, 1, true), false);
}
public LPlaceholder(LPlaceholder label) {
@@ -49,6 +55,7 @@ public class LPlaceholder extends ILabel.Impl {
public static void onLogOut() {
recentServer.clear();
state = true;
}
@Override
@@ -57,11 +64,7 @@ public class LPlaceholder extends ILabel.Impl {
}
public static List<ILabel> getRecent() {
return getRecord().toList().stream().map(LPlaceholder::copy).collect(Collectors.toList());
}
private static Utilities.Recent<LPlaceholder> getRecord() {
return recentClient;
return getActive().toList().stream().map(LPlaceholder::copy).collect(Collectors.toList());
}
@Override
@@ -201,7 +201,8 @@ public class CostList {
.map(i -> i.two.labels.get(0))
.collect(Collectors.toList());
Collections.reverse(ret);
return ret;
CostList cl = new CostList(ret).multiply(-1);
return new CostList().merge(cl, false, true).labels;
}
}
}
@@ -68,6 +68,7 @@ public class Recipes {
if (index == -1) {
if (recipe != null) add(neu, recipe);
else if (old != null) renameGroup(old, neu);
else remove(neu);
} else {
if (recipe == null) remove(neu, index);
else if (old == null || old.equals(neu)) set(neu, index, recipe);
@@ -98,6 +99,10 @@ public class Recipes {
if (l.isEmpty()) records.remove(group);
}
public void remove(String group) {
records.remove(group);
}
public Recipe getRecipe(String group, int index) {
return getGroup(group).get(index);
}
@@ -60,6 +60,17 @@ public class JecaGui extends GuiContainer {
((JecContainer) inventorySlots).setGui(this);
}
public static int getMouseX() {
JecaGui gui = getCurrent();
return Mouse.getEventX() * gui.width / gui.mc.displayWidth - gui.guiLeft;
}
public static int getMouseY() {
JecaGui gui = getCurrent();
return gui.height - Mouse.getEventY() * gui.height / gui.mc.displayHeight - 1 - gui.guiTop;
}
@Override
public void initGui() {
this.guiLeft = (this.width - this.xSize) / 2;
@@ -284,14 +295,18 @@ public class JecaGui extends GuiContainer {
r.getXSize(), r.getYSize(), borderTop, borderBottom, borderLeft, borderRight, zLevel);
}
public void drawFluid(Fluid f, int xPos, int yPos, int xSize, int ySize) {
IIcon fluidStillIcon = f.getStillIcon();
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
int color = f.getColor();
private void setColor(int color) {
float red = (color >> 16 & 0xFF) / 255.0F;
float green = (color >> 8 & 0xFF) / 255.0F;
float blue = (color & 0xFF) / 255.0F;
GlStateManager.color(red, green, blue, 1.0F);
float alpha = (~(color >> 24) & 0xFF) / 255.0F;
GlStateManager.color(red, green, blue, alpha);
}
public void drawFluid(Fluid f, int xPos, int yPos, int xSize, int ySize) {
IIcon fluidStillIcon = f.getStillIcon();
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
setColor(f.getColor() & 0x00FFFFFF);
if (fluidStillIcon != null)
drawTexturedModelRectFromIcon(xPos, yPos, fluidStillIcon, xSize, ySize);
}
@@ -84,6 +84,14 @@ public class Resource {
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 BTN_PICK_N = getIcon(7, 4);
public static final Resource BTN_PICK_F = getIcon(7, 3);
public static final Resource BTN_DELETE_N_N = getIcon(8, 4);
public static final Resource BTN_DELETE_N_F = getIcon(8, 3);
public static final Resource BTN_DELETE_N_D = getIcon(8, 5);
public static final Resource BTN_DELETE_1_N = getIcon(9, 4);
public static final Resource BTN_DELETE_1_F = getIcon(9, 3);
public static final Resource BTN_DELETE_1_D = getIcon(9, 5);
public static final Resource WGT_BUTTON_N = getWidget(0);
public static final Resource WGT_BUTTON_F = getWidget(1);
@@ -181,6 +189,9 @@ public class Resource {
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 BTN_PICK = new ResourceGroup(BTN_PICK_N, BTN_PICK_F);
public static final ResourceGroup BTN_DELETE_N = new ResourceGroup(BTN_DELETE_N_N, BTN_DELETE_N_F, BTN_DELETE_N_D);
public static final ResourceGroup BTN_DELETE_1 = new ResourceGroup(BTN_DELETE_1_N, BTN_DELETE_1_F, BTN_DELETE_1_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);
@@ -186,7 +186,7 @@ public class GuiCraft extends WContainer implements IGui {
enum Mode {
INPUT, OUTPUT, CATALYST, STEPS
}
class Suggest extends WContainer {
class Suggest extends WOverlay {
boolean replace;
public Suggest(List<ILabel> labels, boolean replace) {
@@ -207,21 +207,5 @@ public class GuiCraft extends WContainer implements IGui {
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)) GuiCraft.this.remove(this);
return true;
}
@Override
public boolean onKey(JecaGui gui, char ch, int code) {
if (!super.onKey(gui, ch, code)) {
if (code == Keyboard.KEY_ESCAPE) {
GuiCraft.this.remove(this);
return true;
} else return false;
} else return true;
}
}
}
@@ -29,7 +29,7 @@ public class GuiRecipe extends WContainer implements IGui {
Pair<String, Integer> dest;
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);
WTextField text = new WTextField(49, 32, 119);
WLabelGroup catalyst = new WLabelGroup(29, 87, 7, 1, 20, 20, WLabel.Mode.EDITOR).setListener((i, v) -> {
disambCache.remove(v + 14);
refresh();
@@ -42,46 +42,44 @@ public class GuiRecipe extends WContainer implements IGui {
disambCache.remove(v + 21);
refresh();
});
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 disamb = new WButtonIcon(102, 32, 20, 20, BTN_DISAMB, "recipe.disamb").setListener(i -> {
if (disambCache != null)
JecaGui.displayGui(new GuiDisamb(new ArrayList<>(disambCache.values())).setCallback(l -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
}));
});
WButton clear = new WButtonIcon(64, 31, 20, 20, BTN_DEL, "recipe.clear").setListener(i -> reset());
WButton clear = new WButtonIcon(64, 32, 20, 20, BTN_DEL, "recipe.clear").setListener(i -> reset());
// check duplicate and valid
WButton copy = new WButtonIcon(83, 31, 20, 20, BTN_COPY, "recipe.copy").setListener(i -> {
WButton copy = new WButtonIcon(83, 32, 20, 20, BTN_COPY, "recipe.copy").setListener(i -> {
Controller.addRecipe(group.getText(), toRecipe());
JecaGui.displayParent();
});
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 -> {
WButton label = new WButtonIcon(45, 32, 20, 20, BTN_LABEL, "recipe.label")
.setListener(i -> JecaGui.displayGui(new GuiLabel((l) -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
})));
WButton save = new WButtonIcon(26, 32, 20, 20, BTN_SAVE, "recipe.save").setDisabled(true).setListener(i -> {
if (dest == null)
Controller.addRecipe(group.getText(), toRecipe());
else {
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());
if (group.equals(dest.one))
Controller.setRecipe(dest.one, dest.two, toRecipe());
else
Controller.setRecipe(group, dest.one, dest.two, toRecipe());
}
JecaGui.displayParent();
});
WButton delete = new WButtonIcon(102, 31, 20, 20, BTN_NO, "recipe.delete").setListener(i -> {
Controller.removeRecipe(dest.one, dest.two);
JecaGui.displayParent();
});
WButton yes = new WButtonIcon(7, 31, 20, 20, BTN_YES, "recipe.confirm").setDisabled(true).setListener(i -> {
WButton yes = new WButtonIcon(7, 32, 20, 20, BTN_YES, "recipe.confirm").setDisabled(true).setListener(i -> {
group.setText(text.getText());
text.setText("");
setNewGroup(false);
refresh();
});
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));
WButton no = new WButtonIcon(26, 32, 20, 20, BTN_NO, "common.cancel").setListener(i -> setNewGroup(false));
WButton neu = new WButtonIcon(7, 32, 20, 20, BTN_NEW, "recipe.new").setListener(i -> setNewGroup(true));
public GuiRecipe(String group, int index) {
this();
@@ -89,7 +87,6 @@ public class GuiRecipe extends WContainer implements IGui {
Recipe r = Controller.getRecipe(group, index);
fromRecipe(r);
this.group.setIndex(Controller.getGroups().indexOf(group));
delete.setDisabled(false);
refresh();
}
@@ -100,14 +97,16 @@ public class GuiRecipe extends WContainer implements IGui {
add(new WIcon(7, 111, 22, 40, ICN_INPUT, "common.input"));
add(new WLine(57));
add(input, catalyst, output, group);
if (group.getTexts().isEmpty()) group.setText(Utilities.I18n.get("gui.common.default"));
if (group.getTexts().isEmpty())
group.setText(Utilities.I18n.get("gui.common.default"));
String last = Controller.getLast();
int index = -1;
if (last != null) index = group.getTexts().indexOf(last);
if (index != -1) group.setIndex(index);
if (last != null)
index = group.getTexts().indexOf(last);
if (index != -1)
group.setIndex(index);
setNewGroup(false);
copy.setDisabled(true);
delete.setDisabled(true);
disamb.setDisabled(true);
text.setListener(i -> yes.setDisabled(i.getText().isEmpty()));
}
@@ -123,10 +122,10 @@ public class GuiRecipe extends WContainer implements IGui {
public void setNewGroup(boolean b) {
if (b) {
remove(neu, label, clear, copy, save, disamb, delete);
remove(neu, label, clear, copy, save, disamb);
add(yes, no, text);
} else {
add(neu, label, clear, copy, save, disamb, delete);
add(neu, label, clear, copy, save, disamb);
remove(yes, no, text);
text.setText("");
yes.setDisabled(true);
@@ -137,6 +136,8 @@ public class GuiRecipe extends WContainer implements IGui {
input.setLabel(Collections.nCopies(14, ILabel.EMPTY), 0);
catalyst.setLabel(Collections.nCopies(7, ILabel.EMPTY), 0);
output.setLabel(Collections.nCopies(7, ILabel.EMPTY), 0);
disambCache.clear();
refresh();
}
public void transfer(IRecipeHandler recipe, int recipeIndex) {
@@ -147,7 +148,8 @@ public class GuiRecipe extends WContainer implements IGui {
// input
List<ItemStack> inputItemStacks = recipe.getIngredientStacks(recipeIndex).stream()
.map((positionedStack) -> positionedStack.item).collect(Collectors.toList());
.map((positionedStack) -> positionedStack.item)
.collect(Collectors.toList());
List<ItemStack> outputItemStacks = Collections.singletonList(recipe.getResultStack(recipeIndex).item);
merge(input, inputItemStacks, recipe);
@@ -164,7 +166,8 @@ public class GuiRecipe extends WContainer implements IGui {
}
private void merge(ArrayList<Trio<ILabel, CostList, CostList>> dst, List<ItemStack> gi, IRecipeHandler context) {
List<ILabel> list = gi.stream().map(ILabel.Converter::from).collect(Collectors.toList());
List<ILabel> list = gi.stream().map(ILabel.Converter::from).filter(i -> i != ILabel.EMPTY)
.collect(Collectors.toList());
if (list.isEmpty())
return;
dst.stream().filter(p -> {
@@ -188,7 +191,8 @@ 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) disambCache.put(i + offset, p.two.getLabels());
if (p.two.getLabels().size() > 1)
disambCache.put(i + offset, p.two.getLabels());
}
return ret;
}
@@ -198,12 +202,10 @@ public class GuiRecipe extends WContainer implements IGui {
}
void fromRecipe(Recipe r) {
input.setLabel(Arrays.stream(r.getLabel(Recipe.IO.INPUT))
.map(ILabel::copy).collect(Collectors.toList()), 0);
catalyst.setLabel(Arrays.stream(r.getLabel(Recipe.IO.CATALYST))
.map(ILabel::copy).collect(Collectors.toList()), 0);
output.setLabel(Arrays.stream(r.getLabel(Recipe.IO.OUTPUT))
.map(ILabel::copy).collect(Collectors.toList()), 0);
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);
}
@@ -211,10 +213,10 @@ public class GuiRecipe extends WContainer implements IGui {
disamb.setDisabled(disambCache.isEmpty());
try {
Recipe r = toRecipe();
boolean d = dest == null ? Controller.hasDuplicate(r) :
Controller.hasDuplicate(r, dest.one, dest.two);
boolean d = dest == null ? Controller.hasDuplicate(r) : Controller.hasDuplicate(r, dest.one, dest.two);
save.setDisabled(d);
if (dest != null) copy.setDisabled(d);
if (dest != null)
copy.setDisabled(d);
} catch (IllegalArgumentException e) {
save.setDisabled(true);
copy.setDisabled(true);
@@ -5,23 +5,16 @@ 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.*;
import me.towdium.jecalculation.polyfill.google.common.collect.Streams;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Trio;
import net.minecraft.client.Minecraft;
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;
import java.util.List;
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.*;
@@ -30,10 +23,8 @@ import static me.towdium.jecalculation.gui.widgets.WLabel.Mode.PICKER;
@ParametersAreNonnullByDefault
public class GuiSearch extends WContainer implements IGui {
IdentityHashMap<ILabel, Trio<Recipe, String, Integer>> recipes;
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, PICKER, true).setListener((i, v) -> {
Trio<Recipe, String, Integer> recipe = recipes.get(i.get(v));
JecaGui.displayGui(true, true, new GuiRecipe(recipe.two, recipe.three));
});
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, PICKER, true)
.setListener((i, v) -> add(new Overlay(i.get(v))));
WSwitcher group;
WTextField text = new WTextField(7, 25, 119);
WButton no = new WButtonIcon(130, 25, 20, 20, BTN_NO, "common.cancel")
@@ -46,16 +37,28 @@ public class GuiSearch extends WContainer implements IGui {
refreshDisplay();
setRename(false);
});
WButton exportN = new WButtonIcon(130, 25, 20, 20, BTN_EXPORT_N, "search.export_all")
WButton exportN = new WButtonIcon(111, 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")
WButton export1 = new WButtonIcon(111, 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")
WButton deleteN = new WButtonIcon(130, 25, 20, 20, BTN_DELETE_N, "search.delete_all")
.setListener(i -> {
Controller.getGroups().forEach(Controller::removeGroup);
refreshGroups();
refreshDisplay();
});
WButton delete1 = new WButtonIcon(130, 25, 20, 20, BTN_DELETE_1, "search.delete_group")
.setListener(i -> {
Controller.removeGroup(group.getText());
refreshGroups();
refreshDisplay();
});
WButton inport = new WButtonIcon(92, 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);
WSearch search = new WSearch(26, 25, 61, labels);
List<ILabel> identifiers;
public GuiSearch() {
@@ -64,7 +67,7 @@ public class GuiSearch extends WContainer implements IGui {
yes.setDisabled(s.isEmpty() || Controller.getGroups().contains(s));
});
add(new WHelp("search"), new WPanel());
add(labels, icon, search, inport, exportN, rename);
add(labels, icon, search, inport, exportN, deleteN, rename);
}
@@ -77,7 +80,7 @@ public class GuiSearch extends WContainer implements IGui {
identifiers.add(id);
};
Recipes.RecipeIterator it = group.getIndex() == 0 ? recipeIterator() : recipeIterator(group.getText());
Recipes.RecipeIterator it = group.getIndex() == 0 ? Controller.recipeIterator() : Controller.recipeIterator(group.getText());
it.stream().map(j -> new Trio<>(j, it.getGroup(), it.getIndex())).forEach(add);
}
@@ -91,11 +94,13 @@ public class GuiSearch extends WContainer implements IGui {
}
public void refreshDisplay() {
remove(exportN, export1);
remove(exportN, export1, deleteN, delete1);
generate();
labels.setLabels(identifiers);
add(group.getIndex() == 0 ? exportN : export1);
add(group.getIndex() == 0 ? deleteN : delete1);
exportN.setDisabled(identifiers.size() == 0);
deleteN.setDisabled(identifiers.size() == 0);
rename.setDisabled(group.getIndex() == 0);
}
@@ -105,7 +110,8 @@ public class GuiSearch extends WContainer implements IGui {
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;
if (index >= groups.size())
index = groups.size() - 1;
group = new WSwitcher(7, 7, 162, groups).setListener(i -> refreshDisplay());
group.setIndex(index);
add(group);
@@ -129,4 +135,26 @@ public class GuiSearch extends WContainer implements IGui {
yes.setDisabled(true);
}
}
class Overlay extends WOverlay {
public Overlay(ILabel l) {
Trio<Recipe, String, Integer> recipe = recipes.get(l);
int x = JecaGui.getMouseX();
int y = JecaGui.getMouseY();
x = ((x - 7) / 18) * 18 + 6;
y = ((y - 51) / 18) * 18 + 50;
add(new WPanel(x - 5, y - 5, 72, 30));
add(new WLabel(x, y, 20, 20, PICKER).setLabel(l));
add(new WButtonIcon(x + 23, y, 20, 20, BTN_EDIT, "search.edit").setListener(i -> {
JecaGui.displayGui(true, true, new GuiRecipe(recipe.two, recipe.three));
GuiSearch.this.remove(this);
}));
add(new WButtonIcon(x + 42, y, 20, 20, BTN_NO, "search.delete").setListener(i -> {
Controller.removeRecipe(recipe.two, recipe.three);
GuiSearch.this.remove(this);
refreshGroups();
refreshDisplay();
}));
}
}
}
@@ -20,8 +20,7 @@ import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_RED;
import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_WHITE;
import static me.towdium.jecalculation.gui.JecaGui.Font.HALF;
import static me.towdium.jecalculation.gui.JecaGui.Font.PLAIN;
import static me.towdium.jecalculation.gui.Resource.BTN_NO;
import static me.towdium.jecalculation.gui.Resource.BTN_YES;
import static me.towdium.jecalculation.gui.Resource.*;
/**
* Author: towdium
@@ -96,6 +95,11 @@ public class WLabel implements IWidget {
} else return false;
}
@Nullable
@Override
public ILabel getLabelUnderMouse(int xMouse, int yMouse) {
return mouseIn(xMouse, yMouse) ? label : null;
}
@Override
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
@@ -166,79 +170,70 @@ 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")
.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")
.setListener(i -> setPercent(false));
WLabel wl = new WLabel(xPos, yPos, xSize, ySize, Mode.SELECTOR).setListener((i, v) -> update());
WButton bYes = new WButtonIcon(xPos + xSize + 83, yPos, 20, 20, BTN_YES)
.setListener(i -> JecaGui.getCurrent().root.remove(this));
WButton bNo = new WButtonIcon(xPos + xSize + 102, yPos, 20, 20, BTN_NO).setListener(i -> {
class WAmount extends WOverlay {
WLabel temp = new WLabel(xPos, yPos, xSize, ySize, Mode.PICKER).setListener((i, v) -> update());
WButton number = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "#", "general.to_percent")
.setListener(i -> {
temp.label.setPercent(true);
update();
});
WTextField text = new WTextField(xPos + xSize + 10, yPos + ySize / 2 - WTextField.HEIGHT / 2, 50);
WButton percent = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "%", "general.to_percent")
.setListener(i -> {
temp.label.setPercent(false);
update();
});
WButton pick = new WButtonIcon(xPos + xSize + 83, yPos, 20, 20, BTN_PICK, "label.pick").setListener(i -> {
JecaGui.getCurrent().hand = temp.label;
setLabel(ILabel.EMPTY);
notifyLsnr();
JecaGui.getCurrent().root.remove(this);
});
WButton yes = new WButtonIcon(xPos + xSize + 102, yPos, 20, 20, BTN_YES, "label.confirm").setListener(i -> {
setLabel(temp.label);
notifyLsnr();
JecaGui.getCurrent().root.remove(this);
});
WButton no = new WButtonIcon(xPos + xSize + 121, yPos, 20, 20, BTN_NO, "label.delete").setListener(i -> {
setLabel(ILabel.EMPTY);
notifyLsnr();
JecaGui.getCurrent().root.remove(this);
});
public WAmount() {
wl.setLabel(label);
add(new WPanel(xPos - 5, yPos - 5, xSize + 133, ySize + 10));
temp.setLabel(label.copy());
add(new WPanel(xPos - 5, yPos - 5, xSize + 152, ySize + 10));
add(new WText(xPos + xSize + 3, yPos + 5, PLAIN, "x"));
add(wl, wtf, bYes, bNo);
wtf.setListener(i -> {
add(temp, text, pick, yes, no);
text.setListener(i -> {
boolean acceptable;
long amount;
try {
long n = Long.parseLong(wtf.getText());
label.setAmount(n);
wtf.setColor(COLOR_TEXT_WHITE);
bYes.setDisabled(false);
amount = Long.parseLong(text.getText());
acceptable = amount > 0;
if (!acceptable) amount = 1;
} catch (NumberFormatException e) {
boolean acceptable = wtf.getText().isEmpty();
wtf.setColor(acceptable ? COLOR_TEXT_WHITE : COLOR_TEXT_RED);
bYes.setDisabled(!acceptable);
label.setAmount(acceptable ? 1 : old);
acceptable = text.getText().isEmpty();
amount = 1;
}
notifyLsnr();
text.setColor(acceptable ? COLOR_TEXT_WHITE : COLOR_TEXT_RED);
yes.setDisabled(!acceptable);
temp.label = temp.label.setAmount(amount);
});
update();
}
private void update() {
label = wl.label;
bAmount.setDisabled(!label.acceptPercent());
if (label.isPercent()) {
remove(bAmount);
add(bPercent);
number.setDisabled(!temp.label.acceptPercent());
if (temp.label.isPercent()) {
remove(number);
add(percent);
} else {
remove(bPercent);
add(bAmount);
remove(percent);
add(number);
}
wtf.setText(Long.toString(label.getAmount()));
text.setText(Long.toString(temp.label.getAmount()));
}
private void setPercent(boolean b) {
boolean original = label.isPercent();
if (label.acceptPercent()) label.setPercent(b);
if (b != original) notifyLsnr();
update();
}
@Override
public boolean onKey(JecaGui gui, char ch, int code) {
if (super.onKey(gui, ch, code))
return true;
if (code == Keyboard.KEY_ESCAPE) {
gui.root.remove(this);
return true;
} else
return false;
}
}
@Nullable
@Override
public ILabel getLabelUnderMouse(int xMouse, int yMouse) {
return mouseIn(xMouse, yMouse) ? label : null;
}
}
@@ -0,0 +1,34 @@
package me.towdium.jecalculation.gui.widgets;
import me.towdium.jecalculation.gui.JecaGui;
import org.lwjgl.input.Keyboard;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: Towdium
* Date: 16/02/19
*/
@ParametersAreNonnullByDefault
public class WOverlay extends WContainer {
@Override
public boolean onKey(JecaGui gui, char ch, int code) {
if (super.onKey(gui, ch, code)) return true;
if (code == Keyboard.KEY_ESCAPE) {
gui.root.remove(this);
return true;
} else return false;
}
@Override
public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) {
if (!super.onClicked(gui, xMouse, yMouse, button)) gui.root.remove(this);
return true;
}
@Override
public boolean onScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
if (!super.onScroll(gui, xMouse, yMouse, diff)) gui.root.remove(this);
return true;
}
}
@@ -47,7 +47,7 @@ import static net.minecraft.client.resources.I18n.format;
@ParametersAreNonnullByDefault
public class Utilities {
// FLOAT FORMATTING
public static char[] suffix = new char[]{'K', 'M', 'B', 'G', 'T'};
public static char[] suffix = new char[]{'K', 'M', 'B', 'G', 'T', 'P'};
public static DecimalFormat[] format = new DecimalFormat[]{new DecimalFormat("#."),
new DecimalFormat("#.#"),
new DecimalFormat("#.##"),