mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-14 01:04:06 +00:00
feat: new amount editing logic
- edit amount by scrolling will not remove the label - now right click in recipe gui will remove the label
This commit is contained in:
1 parent
b6d5a7a9fe
commit
74e43cc883
10 files changed
+75
-38
No files matched your search
@@ -462,9 +462,11 @@ public interface ILabel {
|
||||
|
||||
@Override
|
||||
public ILabel decreaseAmount() {
|
||||
if (getAmount() <= getMultiplier())
|
||||
if (getAmount() <= 0) {
|
||||
return ILabel.EMPTY;
|
||||
else {
|
||||
} if (getAmount() <= getMultiplier()) {
|
||||
return this;
|
||||
} else {
|
||||
return setAmount(getAmount() - getMultiplier());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -39,9 +38,9 @@ public class GuiCraft extends WContainer implements IGui {
|
||||
Calculator calculator = null;
|
||||
RecordCraft record;
|
||||
WLabel label = new WLabel(31, 7, 20, 20, true).setLsnrUpdate((i, v) -> refreshLabel(v, false, true));
|
||||
WLabelGroup recent = new WLabelGroup(7, 31, 8, 1, false).setLsnrClick(
|
||||
WLabelGroup recent = new WLabelGroup(7, 31, 8, 1, false).setLsnrLeftClick(
|
||||
(i, v) -> label.setLabel(i.get(v).getLabel().copy(), true));
|
||||
WLabelScroll result = new WLabelScroll(7, 87, 8, 4, false).setLsnrClick((i, v) -> {
|
||||
WLabelScroll result = new WLabelScroll(7, 87, 8, 4, false).setLsnrLeftClick((i, v) -> {
|
||||
Object rep = i.get(v).getLabel().getRepresentation();
|
||||
NEIPlugin.openRecipeGui(rep, Mouse.getEventButton());
|
||||
}).setFmtAmount(i -> i.getAmountString(true)).setFmtTooltip((i, j) -> i.getToolTip(j, true));
|
||||
|
||||
@@ -86,11 +86,16 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
for (IO j : IO.values()) {
|
||||
getWidget(j).setFmtAmount(i -> i.getAmountString(false))
|
||||
.setFmtTooltip((i, k) -> i.getToolTip(k, true))
|
||||
.setLsnrClick((i, v) -> {
|
||||
.setLsnrLeftClick((i, v) -> {
|
||||
ILabel l = i.get(v).getLabel();
|
||||
if (l != ILabel.EMPTY)
|
||||
setOverlay(new WAmount(j, v));
|
||||
})
|
||||
.setLsnrRightClick((widget, value) -> {
|
||||
ILabel l = widget.get(value).getLabel();
|
||||
if (l != ILabel.EMPTY)
|
||||
widget.get(value).setLabel(ILabel.EMPTY, true);
|
||||
})
|
||||
.setLsnrUpdate((i, v) -> {
|
||||
refresh();
|
||||
removeDisamb(j, v);
|
||||
@@ -321,7 +326,7 @@ public class GuiRecipe extends WContainer implements IGui {
|
||||
temp = new WLabel(x - 1, y - 1, 20, 20, false);
|
||||
temp.setLabel(ref.getLabel().copy());
|
||||
content = new WLabelScroll(x + 8, y - 40, 4, 2, false).setLabels(disamb.get(type).get(idx))
|
||||
.setLsnrClick((i, v) -> {
|
||||
.setLsnrLeftClick((i, v) -> {
|
||||
ref.setLabel(
|
||||
i.get(v).getLabel().copy().multiply(-1),
|
||||
false);
|
||||
|
||||
@@ -24,7 +24,7 @@ import static me.towdium.jecalculation.gui.Resource.*;
|
||||
public class GuiSearch extends WContainer implements IGui {
|
||||
IdentityHashMap<ILabel, Trio<Recipe, String, Integer>> recipes;
|
||||
WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, false)
|
||||
.setLsnrClick((i, v) -> {
|
||||
.setLsnrLeftClick((i, v) -> {
|
||||
ILabel l = i.get(v).getLabel();
|
||||
if (l != ILabel.EMPTY) setOverlay(new Overlay(i.get(v)));
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ import static me.towdium.jecalculation.gui.Resource.ICN_TEXT;
|
||||
public class PickerPlaceholder extends IPicker.Impl implements IGui {
|
||||
public PickerPlaceholder() {
|
||||
WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, false)
|
||||
.setLabels(LPlaceholder.getRecent()).setLsnrClick((i, v) -> notifyLsnr(i.get(v).getLabel()));
|
||||
.setLabels(LPlaceholder.getRecent()).setLsnrLeftClick((i, v) -> notifyLsnr(i.get(v).getLabel()));
|
||||
WTextField create = new WTextField(26, 7, 69).setListener(
|
||||
i -> i.setColor(i.getText().equals("") ? COLOR_TEXT_RED : COLOR_TEXT_WHITE));
|
||||
add(new WSearch(26, 45, 90, scroll));
|
||||
|
||||
@@ -7,7 +7,6 @@ import me.towdium.jecalculation.data.label.labels.LFluidStack;
|
||||
import me.towdium.jecalculation.data.label.labels.LOreDict;
|
||||
import me.towdium.jecalculation.gui.guis.IGui;
|
||||
import me.towdium.jecalculation.gui.widgets.WIcon;
|
||||
import me.towdium.jecalculation.gui.widgets.WLabel;
|
||||
import me.towdium.jecalculation.gui.widgets.WLabelScroll;
|
||||
import me.towdium.jecalculation.gui.widgets.WSearch;
|
||||
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
|
||||
@@ -34,7 +33,7 @@ public class PickerSimple extends IPicker.Impl implements IGui {
|
||||
*/
|
||||
public PickerSimple(List<ILabel> labels) {
|
||||
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, false).setLabels(labels)
|
||||
.setLsnrClick((i, v) -> notifyLsnr(i.get(v).getLabel()));
|
||||
.setLsnrLeftClick((i, v) -> notifyLsnr(i.get(v).getLabel()));
|
||||
add(new WSearch(26, 7, 90, ls));
|
||||
add(new WIcon(7, 7, 20, 20, ICN_TEXT, "common.search"));
|
||||
add(ls);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class WLabel implements IWidget {
|
||||
ILabel label = ILabel.EMPTY;
|
||||
public boolean accept;
|
||||
public ListenerValue<? super WLabel, ILabel> update;
|
||||
public ListenerAction<? super WLabel> click;
|
||||
public ListenerAction<? super WLabel> leftClick, rightClick;
|
||||
Function<ILabel, String> fmtAmount = i -> "";
|
||||
BiConsumer<ILabel, List<String>> fmtTooltip = (i, j) -> i.getToolTip(j, false);
|
||||
protected Timer timer = new Timer();
|
||||
@@ -94,18 +94,22 @@ public class WLabel implements IWidget {
|
||||
|
||||
@Override
|
||||
public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) {
|
||||
if (!mouseIn(xMouse, yMouse) || button == 1)
|
||||
if (!mouseIn(xMouse, yMouse))
|
||||
return false;
|
||||
if(button == 1) {
|
||||
notifyRightClick();
|
||||
return true;
|
||||
}
|
||||
if (accept) {
|
||||
if (gui.hand == ILabel.EMPTY && click != null)
|
||||
notifyClick();
|
||||
if (gui.hand == ILabel.EMPTY && leftClick != null)
|
||||
notifyLeftClick();
|
||||
else {
|
||||
label = gui.hand;
|
||||
gui.hand = label.EMPTY;
|
||||
notifyUpdate();
|
||||
}
|
||||
} else
|
||||
notifyClick();
|
||||
notifyLeftClick();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -114,8 +118,13 @@ public class WLabel implements IWidget {
|
||||
return this;
|
||||
}
|
||||
|
||||
public WLabel setLsnrClick(ListenerAction<? super WLabel> listener) {
|
||||
click = listener;
|
||||
public WLabel setLsnrLeftClick(ListenerAction<? super WLabel> listener) {
|
||||
leftClick = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WLabel setLsnrRightClick(ListenerAction<? super WLabel> listener) {
|
||||
rightClick = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -135,9 +144,14 @@ public class WLabel implements IWidget {
|
||||
return xx >= 0 && xx < xSize && yy >= 0 && yy < ySize;
|
||||
}
|
||||
|
||||
private void notifyClick() {
|
||||
if (click != null)
|
||||
click.invoke(this);
|
||||
private void notifyLeftClick() {
|
||||
if (leftClick != null)
|
||||
leftClick.invoke(this);
|
||||
}
|
||||
|
||||
private void notifyRightClick() {
|
||||
if (rightClick != null)
|
||||
rightClick.invoke(this);
|
||||
}
|
||||
|
||||
private void notifyUpdate() {
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.stream.IntStream;
|
||||
public class WLabelGroup extends WContainer {
|
||||
ArrayList<WLabel> labels = new ArrayList<>();
|
||||
ListenerValue<? super WLabelGroup, Integer> lsnrUpdate;
|
||||
ListenerValue<? super WLabelGroup, Integer> lsnrClick;
|
||||
ListenerValue<? super WLabelGroup, Integer> lsnrLeftClick, lsnrRightClick;
|
||||
|
||||
public WLabelGroup(int xPos, int yPos, int column, int row, boolean accept) {
|
||||
this(xPos, yPos, column, row, 18, 18, accept);
|
||||
@@ -37,9 +37,12 @@ public class WLabelGroup extends WContainer {
|
||||
(i, v) -> {
|
||||
if (lsnrUpdate != null)
|
||||
lsnrUpdate.invoke(this, r * column + c);
|
||||
}).setLsnrClick(i -> {
|
||||
if (lsnrClick != null)
|
||||
lsnrClick.invoke(this, r * column + c);
|
||||
}).setLsnrLeftClick(i -> {
|
||||
if (lsnrLeftClick != null)
|
||||
lsnrLeftClick.invoke(this, r * column + c);
|
||||
}).setLsnrRightClick(i -> {
|
||||
if (lsnrRightClick != null)
|
||||
lsnrRightClick.invoke(this, r * column + c);
|
||||
});
|
||||
labels.add(l);
|
||||
add(l);
|
||||
@@ -69,8 +72,13 @@ public class WLabelGroup extends WContainer {
|
||||
return this;
|
||||
}
|
||||
|
||||
public WLabelGroup setLsnrClick(ListenerValue<? super WLabelGroup, Integer> listener) {
|
||||
lsnrClick = listener;
|
||||
public WLabelGroup setLsnrLeftClick(ListenerValue<? super WLabelGroup, Integer> listener) {
|
||||
lsnrLeftClick = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WLabelGroup setLsnrRightClick(ListenerValue<? super WLabelGroup, Integer> listener) {
|
||||
lsnrRightClick = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class WLabelScroll extends WContainer implements ISearchable {
|
||||
protected String filter = "";
|
||||
protected int xPos, yPos, column, row, current;
|
||||
private ListenerValue<? super WLabelScroll, Integer> lsnrUpdate;
|
||||
private ListenerValue<? super WLabelScroll, Integer> lsnrClick;
|
||||
private ListenerValue<? super WLabelScroll, Integer> lsnrLeftClick, lsnrRightClick;
|
||||
protected final boolean accept;
|
||||
|
||||
public WLabelScroll(int xPos, int yPos, int column, int row, boolean accept) {
|
||||
@@ -39,7 +39,8 @@ public class WLabelScroll extends WContainer implements ISearchable {
|
||||
this.column = column;
|
||||
this.row = row;
|
||||
labelGroup = new WLabelGroup(xPos, yPos, column, row, accept).setLsnrUpdate(this::onUpdate)
|
||||
.setLsnrClick(this::onClick);
|
||||
.setLsnrLeftClick(this::onLeftClick)
|
||||
.setLsnrRightClick(this::onRightClick);
|
||||
scroll = new WScroll(xPos + column * 18 + 4, yPos, row * 18).setListener(i -> update(i.getCurrent()))
|
||||
.setStep(Float.POSITIVE_INFINITY)
|
||||
.setRatio(1);
|
||||
@@ -91,8 +92,13 @@ public class WLabelScroll extends WContainer implements ISearchable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public WLabelScroll setLsnrClick(ListenerValue<? super WLabelScroll, Integer> lsnrClick) {
|
||||
this.lsnrClick = lsnrClick;
|
||||
public WLabelScroll setLsnrLeftClick(ListenerValue<? super WLabelScroll, Integer> lsnrLeftClick) {
|
||||
this.lsnrLeftClick = lsnrLeftClick;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WLabelScroll setLsnrRightClick(ListenerValue<? super WLabelScroll, Integer> lsnrRightClick) {
|
||||
this.lsnrRightClick = lsnrRightClick;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -117,9 +123,14 @@ public class WLabelScroll extends WContainer implements ISearchable {
|
||||
}
|
||||
}
|
||||
|
||||
protected void onClick(WLabelGroup w, int index) {
|
||||
if (lsnrClick != null)
|
||||
lsnrClick.invoke(this, column * current + index);
|
||||
protected void onLeftClick(WLabelGroup w, int index) {
|
||||
if (lsnrLeftClick != null)
|
||||
lsnrLeftClick.invoke(this, column * current + index);
|
||||
}
|
||||
|
||||
protected void onRightClick(WLabelGroup w, int index) {
|
||||
if (lsnrRightClick != null)
|
||||
lsnrRightClick.invoke(this, column * current + index);
|
||||
}
|
||||
|
||||
public WLabelScroll setFmtAmount(Function<ILabel, String> f) {
|
||||
|
||||
Reference in new issue
Block a user