diff options
author | msg-programs <msgdoesstuff@gmail.com> | 2023-08-10 22:15:09 +0200 |
---|---|---|
committer | msg-programs <msgdoesstuff@gmail.com> | 2023-08-10 22:15:09 +0200 |
commit | bb37c6d9c0bbf6ee42c9201c383e1bac4160bd8e (patch) | |
tree | 8d511bbcd8451870538c1c467626f7f1ccb5eb06 /src | |
parent | 812ade9e227715161c417a1aafc0e846d9af55a0 (diff) | |
download | Skyblocker-bb37c6d9c0bbf6ee42c9201c383e1bac4160bd8e.tar.gz Skyblocker-bb37c6d9c0bbf6ee42c9201c383e1bac4160bd8e.tar.bz2 Skyblocker-bb37c6d9c0bbf6ee42c9201c383e1bac4160bd8e.zip |
Implement missing arguments (top, bot) for collide op
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/pipeline/CollideStage.java | 58 | ||||
-rw-r--r-- | src/main/resources/assets/skyblocker/tabhud/readme.md | 2 |
2 files changed, 56 insertions, 4 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/pipeline/CollideStage.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/pipeline/CollideStage.java index e2911070..187dc9f9 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/pipeline/CollideStage.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screenbuilder/pipeline/CollideStage.java @@ -13,7 +13,9 @@ public class CollideStage extends PipelineStage { private enum CollideDirection { LEFT("left"), - RIGHT("right"); + RIGHT("right"), + TOP("top"), + BOT("bot"); private String str; @@ -55,6 +57,12 @@ public class CollideStage extends PipelineStage { case RIGHT: primary.forEach(w -> collideAgainstR(screenW, w)); break; + case TOP: + primary.forEach(w -> collideAgainstT(screenH, w)); + break; + case BOT: + primary.forEach(w -> collideAgainstB(screenH, w)); + break; } } @@ -64,7 +72,6 @@ public class CollideStage extends PipelineStage { int xCor = screenW / 2; - // assume others to be sorted top-bottom. for (Widget other : secondary) { if (other.getY() + other.getHeight() + ScreenConst.WIDGET_PAD < yMin) { // too high, next one @@ -88,7 +95,6 @@ public class CollideStage extends PipelineStage { int xCor = screenW / 2; - // assume others to be sorted top-bottom. for (Widget other : secondary) { if (other.getY() + other.getHeight() + ScreenConst.WIDGET_PAD < yMin) { // too high, next one @@ -106,4 +112,50 @@ public class CollideStage extends PipelineStage { w.setX(xCor); } + public void collideAgainstT(int screenH, Widget w) { + int xMin = w.getX(); + int xMax = w.getX() + w.getWidth(); + + int yCor = screenH / 2; + + for (Widget other : secondary) { + if (other.getX() + other.getWidth() + ScreenConst.WIDGET_PAD < xMin) { + // too far left, next one + continue; + } + + if (other.getX() - ScreenConst.WIDGET_PAD > xMax) { + // too far right, next + continue; + } + + int yPos = other.getY() - ScreenConst.WIDGET_PAD - w.getHeight(); + yCor = Math.min(yCor, yPos); + } + w.setY(yCor); + } + + public void collideAgainstB(int screenH, Widget w) { + int xMin = w.getX(); + int xMax = w.getX() + w.getWidth(); + + int yCor = screenH / 2; + + for (Widget other : secondary) { + if (other.getX() + other.getWidth() + ScreenConst.WIDGET_PAD < xMin) { + // too far left, next one + continue; + } + + if (other.getX() - ScreenConst.WIDGET_PAD > xMax) { + // too far right, next + continue; + } + + int yPos = other.getY() + other.getHeight() + ScreenConst.WIDGET_PAD; + yCor = Math.max(yCor, yPos); + } + w.setY(yCor); + } + } diff --git a/src/main/resources/assets/skyblocker/tabhud/readme.md b/src/main/resources/assets/skyblocker/tabhud/readme.md index 8ba473fd..800a69d2 100644 --- a/src/main/resources/assets/skyblocker/tabhud/readme.md +++ b/src/main/resources/assets/skyblocker/tabhud/readme.md @@ -133,7 +133,7 @@ Example: align A and B with "horizontalCenter" #### Collide - op: `collideAgainst` -- direction: One of `left`, `right` +- direction: One of `left`, `right`, `top`, `bot` - widgets: List of widgets to individually move. - colliders: List static reference widgets to "collide against". - Moves a widget in the `direction` until it would overlap with any one of the colliders. Doesn't move the widget in the other direction, doesn't move the widget if it wouldn't collide with anything. |