Skip to content

Commit

Permalink
- fixed a few bugs with scrollable lists
Browse files Browse the repository at this point in the history
- made ItrUtil work with Iterables in general not just ArrayLists
  • Loading branch information
kurrycat committed Jul 10, 2023
1 parent 79da03c commit 3c5c092
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 135 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/io/github/kurrycat/mpkmod/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void loaded() {
EventAPI.addListener(EventAPI.EventListener.onTickStart(e -> API.tickTime++));
EventAPI.addListener(EventAPI.EventListener.onTickStart(e -> {
TickThread.setTickables(
ArrayListUtil.getAllOfType(TickThread.Tickable.class, mainGUI.movableComponents)
ItrUtil.getAllOfType(TickThread.Tickable.class, mainGUI.movableComponents)
);
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.github.kurrycat.mpkmod.gui.interfaces.KeyInputListener;
import io.github.kurrycat.mpkmod.gui.interfaces.MouseInputListener;
import io.github.kurrycat.mpkmod.gui.interfaces.MouseScrollListener;
import io.github.kurrycat.mpkmod.util.ArrayListUtil;
import io.github.kurrycat.mpkmod.util.ItrUtil;
import io.github.kurrycat.mpkmod.util.BoundingBox2D;
import io.github.kurrycat.mpkmod.util.Mouse;
import io.github.kurrycat.mpkmod.util.Vector2D;
Expand All @@ -33,7 +33,7 @@ public abstract class ComponentScreen extends MPKGuiScreen implements PaneHolder
private Vector2D holdingSetPosOffset = null;

public void postMessage(String receiverID, String content, boolean highlighted) {
MessageQueue q = MessageQueue.getReceiverFor(receiverID, ArrayListUtil.getAllOfType(MessageQueue.class, movableComponents));
MessageQueue q = MessageQueue.getReceiverFor(receiverID, ItrUtil.getAllOfType(MessageQueue.class, movableComponents));
if (q != null)
q.postMessage(content, highlighted);
}
Expand Down Expand Up @@ -251,8 +251,8 @@ public void onMouseScroll(Vector2D mousePos, int delta) {
public boolean handleMouseScroll(Vector2D mousePos, int delta) {
if (!openPanes.isEmpty())
openPanes.get(openPanes.size() - 1).handleMouseScroll(mousePos, delta);
return ArrayListUtil.orMap(
ArrayListUtil.getAllOfType(MouseScrollListener.class, components, movableComponents),
return ItrUtil.orMap(
ItrUtil.getAllOfType(MouseScrollListener.class, components, movableComponents),
b -> b.handleMouseScroll(mousePos, delta)
);
}
Expand Down Expand Up @@ -327,8 +327,8 @@ public boolean handleMouseInput(Mouse.State state, Vector2D mousePos, Mouse.Butt
topPane.handleMouseInput(state, mousePos, button);
if (topPane.isLoaded()) return true;
}
return ArrayListUtil.orMap(
ArrayListUtil.getAllOfType(MouseInputListener.class, components, movableComponents),
return ItrUtil.orMap(
ItrUtil.getAllOfType(MouseInputListener.class, components, movableComponents),
b -> b.handleMouseInput(state, mousePos, button)
);
}
Expand Down Expand Up @@ -380,8 +380,8 @@ private void cleanupScreen() {
public boolean handleKeyInput(int keyCode, int scanCode, int modifiers, boolean isCharTyped) {
if (!openPanes.isEmpty())
openPanes.get(openPanes.size() - 1).handleKeyInput(keyCode, scanCode, modifiers, isCharTyped);
return ArrayListUtil.orMap(
ArrayListUtil.getAllOfType(KeyInputListener.class, components, movableComponents),
return ItrUtil.orMap(
ItrUtil.getAllOfType(KeyInputListener.class, components, movableComponents),
b -> b.handleKeyInput(keyCode, scanCode, modifiers, isCharTyped)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.github.kurrycat.mpkmod.gui.interfaces.KeyInputListener;
import io.github.kurrycat.mpkmod.gui.interfaces.MouseInputListener;
import io.github.kurrycat.mpkmod.gui.interfaces.MouseScrollListener;
import io.github.kurrycat.mpkmod.util.ArrayListUtil;
import io.github.kurrycat.mpkmod.util.ItrUtil;
import io.github.kurrycat.mpkmod.util.ColorUtil;
import io.github.kurrycat.mpkmod.util.Mouse;
import io.github.kurrycat.mpkmod.util.Vector2D;
Expand Down Expand Up @@ -114,13 +114,13 @@ public boolean handleKeyInput(int keyCode, int scanCode, int modifiers, boolean

@Override
public boolean handleMouseInput(Mouse.State state, Vector2D mousePos, Mouse.Button button) {
return ArrayListUtil.orMapAll(ArrayListUtil.getAllOfType(MouseInputListener.class, this.red, this.green, this.blue, this.alpha, this.color),
return ItrUtil.orMapAll(ItrUtil.getAllOfType(MouseInputListener.class, this.red, this.green, this.blue, this.alpha, this.color),
listener -> listener.handleMouseInput(state, mousePos, button));
}

@Override
public boolean handleMouseScroll(Vector2D mousePos, int delta) {
return ArrayListUtil.orMapAll(Arrays.asList(this.red, this.green, this.blue, this.alpha),
return ItrUtil.orMapAll(Arrays.asList(this.red, this.green, this.blue, this.alpha),
slider -> slider.handleMouseScroll(mousePos, delta));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,15 @@ public void passPositionTo(ComponentHolder child, int percentFlag) {
}

public void passPositionTo(ComponentHolder child) {
child.root = root;
child.parent = this;

child.setParent(this);
child.updatePosAndSize();
}

public void setParent(ComponentHolder parent) {
root = parent.root;
this.parent = parent;
}

public void stretchXBetween(ComponentHolder child, ComponentHolder min, ComponentHolder max) {
child.minX = min;
child.maxX = max;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.github.kurrycat.mpkmod.gui.interfaces.KeyInputListener;
import io.github.kurrycat.mpkmod.gui.interfaces.MouseInputListener;
import io.github.kurrycat.mpkmod.gui.interfaces.MouseScrollListener;
import io.github.kurrycat.mpkmod.util.ArrayListUtil;
import io.github.kurrycat.mpkmod.util.ItrUtil;
import io.github.kurrycat.mpkmod.util.Mouse;
import io.github.kurrycat.mpkmod.util.Vector2D;

Expand Down Expand Up @@ -160,24 +160,24 @@ public void render(Vector2D mouse) {

@Override
public boolean handleKeyInput(int keyCode, int scanCode, int modifiers, boolean isCharTyped) {
return ArrayListUtil.orMapAll(
ArrayListUtil.getAllOfType(KeyInputListener.class, components),
return ItrUtil.orMapAll(
ItrUtil.getAllOfType(KeyInputListener.class, components),
e -> e.handleKeyInput(keyCode, scanCode, modifiers, isCharTyped)
);
}

@Override
public boolean handleMouseInput(Mouse.State state, Vector2D mousePos, Mouse.Button button) {
return ArrayListUtil.orMapAll(
ArrayListUtil.getAllOfType(MouseInputListener.class, components),
return ItrUtil.orMapAll(
ItrUtil.getAllOfType(MouseInputListener.class, components),
e -> e.handleMouseInput(state, mousePos, button)
);
}

@Override
public boolean handleMouseScroll(Vector2D mousePos, int delta) {
return ArrayListUtil.orMapAll(
ArrayListUtil.getAllOfType(MouseScrollListener.class, components),
return ItrUtil.orMapAll(
ItrUtil.getAllOfType(MouseScrollListener.class, components),
e -> e.handleMouseScroll(mousePos, delta)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.github.kurrycat.mpkmod.gui.infovars.InfoVar;
import io.github.kurrycat.mpkmod.gui.interfaces.MouseInputListener;
import io.github.kurrycat.mpkmod.gui.screens.main_gui.MainGuiScreen;
import io.github.kurrycat.mpkmod.util.ArrayListUtil;
import io.github.kurrycat.mpkmod.util.ItrUtil;
import io.github.kurrycat.mpkmod.util.Colors;
import io.github.kurrycat.mpkmod.util.Mouse;
import io.github.kurrycat.mpkmod.util.Vector2D;
Expand Down Expand Up @@ -101,9 +101,11 @@ public InfoVarList(InputField inputField, Vector2D pos, Vector2D size) {
}

public void updateSearchFilter(String searchString) {
items = allItems.stream()
.filter(i -> i.containsSearchString(searchString))
.collect(Collectors.toList());
items.clear();
for(InfoVarListItem item : allItems) {
if(item.containsSearchString(searchString))
items.add(item);
}
}

@Override
Expand Down Expand Up @@ -263,7 +265,7 @@ public int getHeight() {
public boolean handleMouseInput(Mouse.State state, Vector2D mousePos, Mouse.Button button) {
return addButton.handleMouseInput(state, mousePos, button) ||
showCollapseButton && collapseButton.handleMouseInput(state, mousePos, button) ||
!collapsed && ArrayListUtil.orMap(children, c -> c.handleMouseInput(state, mousePos, button));
!collapsed && ItrUtil.orMap(children, c -> c.handleMouseInput(state, mousePos, button));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public void render(Vector2D mouse) {

Renderer2D.drawRectWithEdge(rectPos.round(), rectSize.round(), 1, normalColor, edgeColor);

cursorPos = MathUtil.constrain(cursorPos, 0, content.length());
highlightStart = MathUtil.constrain(highlightStart, 0, content.length());
highlightEnd = MathUtil.constrain(highlightEnd, 0, content.length());

FontRenderer.drawString(
content.substring(0, highlightStart),
rectPos.add(2, 2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.github.kurrycat.mpkmod.gui.interfaces.KeyInputListener;
import io.github.kurrycat.mpkmod.gui.interfaces.MouseInputListener;
import io.github.kurrycat.mpkmod.gui.interfaces.MouseScrollListener;
import io.github.kurrycat.mpkmod.util.ArrayListUtil;
import io.github.kurrycat.mpkmod.util.ItrUtil;
import io.github.kurrycat.mpkmod.util.Colors;
import io.github.kurrycat.mpkmod.util.Mouse;
import io.github.kurrycat.mpkmod.util.Vector2D;
Expand Down Expand Up @@ -49,8 +49,8 @@ public void render(Vector2D mousePos) {

public boolean handleMouseInput(Mouse.State state, Vector2D mousePos, Mouse.Button button) {
if (this.loaded) {
return ArrayListUtil.orMapAll(
ArrayListUtil.getAllOfType(MouseInputListener.class, components),
return ItrUtil.orMapAll(
ItrUtil.getAllOfType(MouseInputListener.class, components),
b -> b.handleMouseInput(state, mousePos, button)
);
}
Expand All @@ -59,8 +59,8 @@ public boolean handleMouseInput(Mouse.State state, Vector2D mousePos, Mouse.Butt

public boolean handleMouseScroll(Vector2D mousePos, int delta) {
if (this.loaded) {
return ArrayListUtil.orMapAll(
ArrayListUtil.getAllOfType(MouseScrollListener.class, components),
return ItrUtil.orMapAll(
ItrUtil.getAllOfType(MouseScrollListener.class, components),
b -> b.handleMouseScroll(mousePos, delta)
);
}
Expand Down Expand Up @@ -92,8 +92,8 @@ public void addTitle(String title) {

public boolean handleKeyInput(int keyCode, int scanCode, int modifiers, boolean isCharTyped) {
if (this.loaded) {
return ArrayListUtil.orMapAll(
ArrayListUtil.getAllOfType(KeyInputListener.class, components),
return ItrUtil.orMapAll(
ItrUtil.getAllOfType(KeyInputListener.class, components),
b -> b.handleKeyInput(keyCode, scanCode, modifiers, isCharTyped)
);
}
Expand Down
Loading

0 comments on commit 3c5c092

Please sign in to comment.