fix: scroll on overlay won't affect bottom label

This commit is contained in:
Discreater committed 2021-05-08 03:03:47 +08:00
1 parent 5df4fafc5b
commit 98ee8a04d4
8 files changed
+46 -139

No files matched your search

@@ -36,7 +36,6 @@ import static me.towdium.jecalculation.data.structure.RecordCraft.Mode.*;
@MethodsReturnNonnullByDefault
@SideOnly(Side.CLIENT)
public class GuiCraft extends WContainer implements IGui {
ItemStack itemStack;
Calculator calculator = null;
RecordCraft record;
WLabel label = new WLabel(31, 7, 20, 20, true).setLsnrUpdate((i, v) -> refreshLabel(v, false, true));
@@ -208,7 +207,7 @@ public class GuiCraft extends WContainer implements IGui {
public Suggest(List<ILabel> labels, boolean replace) {
this.replace = replace;
int width = labels.size() * 20;
add(new WPanel(-width, 2, 56 + width, 30));
addPanel(new WPanel(-width, 2, 56 + width, 30));
add(new WLabel(31, 7, 20, 20, false).setLabel(label.getLabel()).setLsnrUpdate((i, v) -> refresh(v)));
add(new WIcon(5 - width, 7, 18, 20, Resource.ICN_HELP, "craft.suggest"));
add(new WLine(26, 7, 20, false));
@@ -250,7 +250,7 @@ public class GuiRecipe extends WContainer implements IGui {
});
temp = new WLabel(x - 1, y - 1, 20, 20, true).setLsnrUpdate((i, v) -> update());
temp.setLabel(ref.getLabel().copy());
add(new WPanel(x - 7, y - 30, 111, 55));
addPanel(new WPanel(x - 7, y - 30, 111, 55));
add(new WText(x + 21, y + 5, PLAIN, "x"));
text = new WTextField(x + 28, y + 9 - WTextField.HEIGHT / 2, 50);
pick = new WButtonIcon(x + 21, y - 24, 20, 20, BTN_PICK, "recipe.pick").setListener(i -> {
@@ -317,7 +317,7 @@ public class GuiRecipe extends WContainer implements IGui {
ref = getWidget(type).get(idx);
int x = ref.xPos;
int y = ref.yPos;
add(new WPanel(x - 7, y - 46, 111, 71));
addPanel(new WPanel(x - 7, y - 46, 111, 71));
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))
@@ -144,7 +144,7 @@ public class GuiSearch extends WContainer implements IGui {
Trio<Recipe, String, Integer> recipe = recipes.get(l.getLabel());
int x = l.xPos - 1;
int y = l.yPos - 1;
add(new WPanel(x - 5, y - 5, 72, 30));
addPanel(new WPanel(x - 5, y - 5, 72, 30));
add(new WLabel(x, y, 20, 20, false).setLabel(l.getLabel()));
add(new WButtonIcon(x + 23, y, 20, 20, BTN_EDIT, "search.edit").setListener(i -> {
JecaGui.displayGui(true, true, new GuiRecipe(recipe.two, recipe.three));
@@ -11,5 +11,5 @@ public interface IContainer extends IWidget {
void clear();
void setOverlay(IWidget w);
void setOverlay(WOverlay w);
}
@@ -22,7 +22,7 @@ import java.util.Objects;
@SideOnly(Side.CLIENT)
public class WContainer implements IContainer {
protected List<IWidget> widgets = new ArrayList<>();
protected IWidget overlay = null;
protected WOverlay overlay = null;
public void add(IWidget w) {
widgets.add(w);
@@ -42,7 +42,7 @@ public class WContainer implements IContainer {
widgets.removeAll(Arrays.asList(w));
}
public void setOverlay(@Nullable IWidget overlay) {
public void setOverlay(@Nullable WOverlay overlay) {
this.overlay = overlay;
}
@@ -107,10 +107,14 @@ public class WContainer implements IContainer {
@Nullable
@Override
public WLabel getLabelUnderMouse(int xMouse, int yMouse) {
return new Utilities.ReversedIterator<>(widgets).stream()
.map(i -> i.getLabelUnderMouse(xMouse, yMouse))
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
if(overlay != null && overlay.mouseIn(xMouse, yMouse)) {
return overlay.getLabelUnderMouse(xMouse, yMouse);
} else {
return new Utilities.ReversedIterator<>(widgets).stream()
.map(i -> i.getLabelUnderMouse(xMouse, yMouse))
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
}
}
}
@@ -86,21 +86,6 @@ public class WLabel implements IWidget {
return false;
}
// TODO
// @Override
// public boolean onMouseScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
// if (mouseIn(xMouse, yMouse)) {
// if (mode == Mode.EDITOR && label != ILabel.EMPTY) {
// for (int i = 0; i < Math.abs(diff); i++)
// label = diff > 0 ? label.increaseAmount() : label.decreaseAmount();
// notifyLsnr();
// }
// return true;
// } else
// return false;
// }
@Nullable
@Override
public WLabel getLabelUnderMouse(int xMouse, int yMouse) {
@@ -122,50 +107,6 @@ public class WLabel implements IWidget {
} else
notifyClick();
return true;
// if (!mouseIn(xMouse, yMouse) || (button == 1 && mode != Mode.RESULT))
// return false;
// switch (mode) {
// case EDITOR:
// if (gui.hand != label.EMPTY) {
// label = gui.hand;
// gui.hand = label.EMPTY;
// notifyLsnr();
// return true;
// } else if (label != label.EMPTY) {
// gui.root.add(new WAmount());
// return true;
// } else
// return false;
// case RESULT:
// // open NEI recipe gui
// Object item = label.getRepresentation();
// if ((item instanceof ItemStack || item instanceof FluidStack)) {
// String id = item instanceof ItemStack ? "item" : "liquid";
// if (button == 0) {
// GuiCraftingRecipe.openRecipeGui(id, item);
// return true;
// } else if (button == 1) {
// GuiUsageRecipe.openRecipeGui(id, item);
// return true;
// }
// } else if (item != null) {
// JustEnoughCalculation.logger.warn("unknown label representation " + item);
// }
// return false;
// case PICKER:
// if (label != label.EMPTY) {
// notifyLsnr();
// return true;
// } else
// return false;
// case SELECTOR:
// label = gui.hand;
// gui.hand = label.EMPTY;
// notifyLsnr();
// return true;
// default:
// throw new IllegalPositionException();
// }
}
public WLabel setLsnrUpdate(ListenerValue<? super WLabel, ILabel> listener) {
@@ -203,70 +144,4 @@ public class WLabel implements IWidget {
if (update != null)
update.invoke(this, label);
}
// 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() {
// 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(temp, text, pick, yes, no);
// text.setListener(i -> {
// boolean acceptable;
// long amount;
// try {
// amount = Long.parseLong(text.getText());
// acceptable = amount > 0;
// if (!acceptable)
// amount = 1;
// } catch (NumberFormatException e) {
// acceptable = text.getText().isEmpty();
// amount = 1;
// }
// text.setColor(acceptable ? COLOR_TEXT_WHITE : COLOR_TEXT_RED);
// yes.setDisabled(!acceptable);
// temp.label = temp.label.setAmount(amount);
// });
// update();
// }
//
// private void update() {
// number.setDisabled(!temp.label.acceptPercent());
// if (temp.label.isPercent()) {
// remove(number);
// add(percent);
// } else {
// remove(percent);
// add(number);
// }
// text.setText(Long.toString(temp.label.getAmount()));
// }
// }
}
@@ -13,7 +13,12 @@ import javax.annotation.ParametersAreNonnullByDefault;
*/
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class WOverlay extends WContainer {
public abstract class WOverlay extends WContainer {
/**
* For checking whether the mouse in the overlay
*/
protected WPanel panel;
@Override
public boolean onKeyPressed(JecaGui gui, char ch, int code) {
if (super.onKeyPressed(gui, ch, code)) return true;
@@ -43,4 +48,14 @@ public class WOverlay extends WContainer {
GlStateManager.popMatrix();
return false;
}
protected void addPanel(WPanel panel) {
this.panel = panel;
add(panel);
}
protected boolean mouseIn(int x, int y) {
if(panel == null) return false;
return panel.mouseIn(x, y);
}
}
@@ -50,6 +50,20 @@ public class WPanel implements IWidget {
if (ret) gui.hand = ILabel.EMPTY;
return ret;
}
/**
* Assuming Panel will be the first widget in the container's widgets.
* @param gui gui
* @param xMouse mouse x
* @param yMouse mouse y
* @param diff different
* @return true to stop the event
*/
@Override
public boolean onMouseScroll(JecaGui gui, int xMouse, int yMouse, int diff) {
return mouseIn(xMouse, yMouse);
}
public boolean mouseIn(int x, int y) {
int xx = x - xPos;
int yy = y - yPos;