From 35676b647033d37db145ff028b48e0740af4c283 Mon Sep 17 00:00:00 2001 From: stivais Date: Sun, 1 Dec 2024 23:56:19 +0200 Subject: [PATCH] ported to aurora --- build.gradle.kts | 8 +- .../mixins/MixinRendererLivingEntity.java | 12 +- .../features/impl/floor7/p3/ArrowsDevice.kt | 12 +- .../mixin/mixins/MixinRenderEntityItem.java | 12 +- .../mixins/MixinRendererLivingEntity.java | 12 +- .../features/impl/floor7/p3/ArrowsDevice.kt | 6 +- .../features/impl/floor7/p3/SimonSays.kt | 12 +- .../features/impl/render/ChestEsp.kt | 11 +- .../features/impl/render/EtherWarpHelper.kt | 12 +- .../odinclient/features/impl/render/Ghosts.kt | 3 +- .../features/impl/render/Trajectories.kt | 26 +- .../impl/skyblock/ChocolateFactory.kt | 9 +- src/main/kotlin/com/github/stivais/ui/UI.kt | 145 ----- .../kotlin/com/github/stivais/ui/UIScreen.kt | 117 ---- .../kotlin/com/github/stivais/ui/Window.kt | 6 - .../github/stivais/ui/animation/Animating.kt | 66 -- .../github/stivais/ui/animation/Animation.kt | 35 -- .../github/stivais/ui/animation/animations.kt | 53 -- .../com/github/stivais/ui/color/Color.kt | 275 -------- .../com/github/stivais/ui/color/ColorUtils.kt | 143 ----- .../stivais/ui/constraints/constraints.kt | 40 -- .../com/github/stivais/ui/constraints/dsl.kt | 69 -- .../ui/constraints/measurements/Animatable.kt | 128 ---- .../ui/constraints/measurements/Percent.kt | 13 - .../ui/constraints/measurements/Pixel.kt | 26 - .../ui/constraints/measurements/Undefined.kt | 11 - .../ui/constraints/operational/Additive.kt | 12 - .../ui/constraints/operational/Coerce.kt | 24 - .../constraints/operational/Multiplicative.kt | 16 - .../ui/constraints/operational/Subtractive.kt | 8 - .../ui/constraints/positions/Alignment.kt | 23 - .../ui/constraints/positions/Center.kt | 13 - .../ui/constraints/positions/OldLinked.kt | 35 -- .../ui/constraints/sizes/AspectRatio.kt | 12 - .../stivais/ui/constraints/sizes/Bounding.kt | 33 - .../stivais/ui/constraints/sizes/Copying.kt | 12 - .../stivais/ui/constraints/sizes/Indent.kt | 17 - .../com/github/stivais/ui/elements/Element.kt | 282 --------- .../github/stivais/ui/elements/impl/Block.kt | 69 -- .../github/stivais/ui/elements/impl/Canvas.kt | 25 - .../github/stivais/ui/elements/impl/Column.kt | 83 --- .../github/stivais/ui/elements/impl/Grid.kt | 52 -- .../github/stivais/ui/elements/impl/Group.kt | 13 - .../stivais/ui/elements/impl/ImageElement.kt | 28 - .../github/stivais/ui/elements/impl/Layout.kt | 102 --- .../github/stivais/ui/elements/impl/Popup.kt | 61 -- .../github/stivais/ui/elements/impl/Row.kt | 63 -- .../stivais/ui/elements/impl/Scrollable.kt | 64 -- .../stivais/ui/elements/impl/TextElement.kt | 82 --- .../stivais/ui/elements/scope/ElementScope.kt | 316 ---------- .../stivais/ui/elements/scope/extensions.kt | 81 --- .../stivais/ui/elements/scope/extras.kt | 37 -- .../github/stivais/ui/events/EventManager.kt | 177 ------ .../com/github/stivais/ui/events/events.kt | 119 ---- .../github/stivais/ui/impl/Testing Command.kt | 44 -- .../stivais/ui/operation/UIOperation.kt | 15 - .../com/github/stivais/ui/renderer/Font.kt | 28 - .../github/stivais/ui/renderer/Framebuffer.kt | 3 - .../github/stivais/ui/renderer/Gradient.kt | 5 - .../com/github/stivais/ui/renderer/Image.kt | 69 -- .../github/stivais/ui/renderer/Renderer.kt | 81 --- .../com/github/stivais/ui/renderer/Scissor.kt | 10 - .../stivais/ui/transforms/Transforms.kt | 134 ---- .../kotlin/com/github/stivais/ui/utils/dsl.kt | 54 -- .../com/github/stivais/ui/utils/utils.kt | 43 -- src/main/kotlin/me/odinmain/OdinMain.kt | 4 +- .../me/odinmain/commands/impl/OdinCommand.kt | 10 +- .../odinmain/config/DungeonWaypointConfig.kt | 16 +- .../kotlin/me/odinmain/features/Module.kt | 5 +- .../kotlin/me/odinmain/features/huds/HUD.kt | 58 +- .../me/odinmain/features/huds/HUDManager.kt | 125 ++-- .../features/impl/dungeon/BlessingDisplay.kt | 14 +- .../features/impl/dungeon/BloodCamp.kt | 12 +- .../odinmain/features/impl/dungeon/CanClip.kt | 4 +- .../features/impl/dungeon/KeyHighlight.kt | 12 +- .../features/impl/dungeon/LeapMenu.kt | 122 ++-- .../odinmain/features/impl/dungeon/Mimic.kt | 4 +- .../features/impl/dungeon/SecretClicked.kt | 7 +- .../impl/dungeon/TeammatesHighlight.kt | 17 +- .../features/impl/dungeon/TerracottaTimer.kt | 15 +- .../features/impl/dungeon/WarpCooldown.kt | 43 +- .../dungeonwaypoints/DungeonWaypoints.kt | 14 +- .../impl/dungeon/puzzlesolvers/BeamsSolver.kt | 35 +- .../dungeon/puzzlesolvers/IceFillSolver.kt | 11 +- .../dungeon/puzzlesolvers/PuzzleSolvers.kt | 13 +- .../dungeon/puzzlesolvers/TPMazeSolver.kt | 11 +- .../impl/dungeon/puzzlesolvers/WaterSolver.kt | 4 +- .../features/impl/floor7/DragonBoxes.kt | 19 +- .../features/impl/floor7/DragonHealth.kt | 16 +- .../features/impl/floor7/DragonTimer.kt | 4 +- .../features/impl/floor7/KingRelics.kt | 14 +- .../features/impl/floor7/WitherDragonEnum.kt | 11 +- .../features/impl/floor7/p3/ArrowAlign.kt | 6 +- .../impl/floor7/p3/InactiveWaypoints.kt | 10 +- .../features/impl/floor7/p3/TerminalSolver.kt | 13 +- .../features/impl/nether/BlazeAttunement.kt | 8 +- .../features/impl/nether/BuildHelper.kt | 12 +- .../features/impl/nether/EnrageDisplay.kt | 39 +- .../features/impl/nether/FreshTimer.kt | 13 +- .../features/impl/nether/KuudraDisplay.kt | 11 +- .../features/impl/nether/PearlWaypoints.kt | 2 +- .../features/impl/nether/SupplyHelper.kt | 5 +- .../features/impl/nether/TeamHighlight.kt | 11 +- .../features/impl/render/BPSDisplay.kt | 24 +- .../features/impl/render/BlockOverlay.kt | 7 +- .../features/impl/render/CPSDisplay.kt | 2 +- .../odinmain/features/impl/render/ClickGUI.kt | 281 +++++---- .../features/impl/render/CustomHighlight.kt | 7 +- .../me/odinmain/features/impl/render/DVD.kt | 6 +- .../features/impl/render/DevPlayers.kt | 5 +- .../features/impl/render/DragonHitboxes.kt | 6 +- .../features/impl/render/NameChanger.kt | 2 +- .../features/impl/render/PersonalDragon.kt | 12 +- .../features/impl/render/ServerHud.kt | 52 +- .../features/impl/render/WaypointManager.kt | 10 +- .../features/impl/skyblock/DianaHelper.kt | 9 +- .../features/impl/skyblock/GyroWand.kt | 15 +- .../features/impl/skyblock/ItemsHighlight.kt | 15 +- .../features/impl/skyblock/SpringBoots.kt | 2 +- .../me/odinmain/features/settings/Setting.kt | 75 +-- .../features/settings/impl/BooleanSetting.kt | 51 +- .../features/settings/impl/ColorSetting.kt | 591 ++++++++---------- .../features/settings/impl/DropdownSetting.kt | 26 +- .../features/settings/impl/HUDSetting.kt | 2 +- .../features/settings/impl/KeybindSetting.kt | 95 +-- .../features/settings/impl/ListSetting.kt | 2 +- .../features/settings/impl/NumberSetting.kt | 115 ++-- .../features/settings/impl/SelectorSetting.kt | 76 +-- .../features/settings/impl/StringSetting.kt | 129 ++-- .../features/settings/impl/UISetting.kt | 25 +- .../kotlin/me/odinmain/utils/AutoSessionID.kt | 4 +- .../utils/render/HighlightRenderer.kt | 2 +- .../me/odinmain/utils/render/OutlineUtils.kt | 10 +- .../me/odinmain/utils/render/RenderUtils.kt | 17 +- .../me/odinmain/utils/render/RenderUtils2D.kt | 7 +- .../me/odinmain/utils/render/Renderer.kt | 17 +- .../utils/skyblock/DianaBurrowEstimate.kt | 9 +- .../me/odinmain/utils/skyblock/ItemUtils.kt | 19 +- .../me/odinmain/utils/skyblock/PlayerUtils.kt | 2 +- .../utils/skyblock/dungeon/DungeonEnums.kt | 15 +- .../utils/skyblock/dungeon/DungeonUtils.kt | 7 +- .../kotlin/me/odinmain/utils/ui/Colors.kt | 51 ++ .../odinmain/utils/ui/elements/TextInput.kt | 472 -------------- .../utils/ui/renderer}/NVGRenderer.kt | 204 ++---- .../utils/ui/{ => screens}/UIHandler.kt | 46 +- .../me/odinmain/utils/ui/screens/UIScreen.kt | 273 ++++++++ .../kotlin/me/odinmain/utils/ui/utilities.kt | 83 +-- 147 files changed, 1784 insertions(+), 5453 deletions(-) delete mode 100644 src/main/kotlin/com/github/stivais/ui/UI.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/UIScreen.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/Window.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/animation/Animating.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/animation/Animation.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/animation/animations.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/color/Color.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/color/ColorUtils.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/constraints.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/dsl.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/measurements/Animatable.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/measurements/Percent.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/measurements/Pixel.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/measurements/Undefined.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/operational/Additive.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/operational/Coerce.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/operational/Multiplicative.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/operational/Subtractive.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/positions/Alignment.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/positions/Center.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/positions/OldLinked.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/sizes/AspectRatio.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/sizes/Bounding.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/sizes/Copying.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/constraints/sizes/Indent.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/Element.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/Block.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/Canvas.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/Column.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/Grid.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/Group.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/ImageElement.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/Layout.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/Popup.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/Row.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/Scrollable.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/impl/TextElement.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/scope/ElementScope.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/scope/extensions.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/elements/scope/extras.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/events/EventManager.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/events/events.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/impl/Testing Command.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/operation/UIOperation.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/renderer/Font.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/renderer/Framebuffer.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/renderer/Gradient.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/renderer/Image.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/renderer/Renderer.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/renderer/Scissor.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/transforms/Transforms.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/utils/dsl.kt delete mode 100644 src/main/kotlin/com/github/stivais/ui/utils/utils.kt create mode 100644 src/main/kotlin/me/odinmain/utils/ui/Colors.kt delete mode 100644 src/main/kotlin/me/odinmain/utils/ui/elements/TextInput.kt rename src/main/kotlin/{com/github/stivais/ui/renderer/impl => me/odinmain/utils/ui/renderer}/NVGRenderer.kt (57%) rename src/main/kotlin/me/odinmain/utils/ui/{ => screens}/UIHandler.kt (59%) create mode 100644 src/main/kotlin/me/odinmain/utils/ui/screens/UIScreen.kt diff --git a/build.gradle.kts b/build.gradle.kts index 77987f6c7..b1ce09889 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,9 @@ blossom { allprojects { repositories { +// mavenLocal() mavenCentral() + maven("https://jitpack.io") maven("https://repo.spongepowered.org/maven/") maven("https://repo.essential.gg/repository/maven-public/") } @@ -44,7 +46,11 @@ allprojects { annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT") implementation("org.spongepowered:mixin:0.7.11-SNAPSHOT") { isTransitive = false } - implementation("com.github.odtheking:odin-lwjgl:5065fe5c1e") + //implementation("com.github.stivais:AuroraUI:0.9.1-beta") + // todo: create releases for aurora + implementation("com.github.stivais:AuroraUI:90cb4e84e8") + + implementation("com.github.odtheking:odin-lwjgl:faeaa48b39") sourceSets.main { java.srcDir(file("$projectDir/src/main/kotlin")) diff --git a/odin/src/main/java/me/odin/mixin/mixins/MixinRendererLivingEntity.java b/odin/src/main/java/me/odin/mixin/mixins/MixinRendererLivingEntity.java index d73f888fa..1b9fea682 100644 --- a/odin/src/main/java/me/odin/mixin/mixins/MixinRendererLivingEntity.java +++ b/odin/src/main/java/me/odin/mixin/mixins/MixinRendererLivingEntity.java @@ -1,8 +1,7 @@ package me.odin.mixin.mixins; -import com.github.stivais.ui.color.ColorUtils; +import com.github.stivais.aurora.color.Color; import me.odinmain.events.impl.RenderEntityModelEvent; -import com.github.stivais.ui.color.Color; import me.odinmain.utils.render.HighlightRenderer; import me.odinmain.utils.render.RenderUtils; import net.minecraft.client.model.ModelBase; @@ -23,6 +22,7 @@ import java.nio.FloatBuffer; +import static com.github.stivais.aurora.utils.Color_utilitiesKt.*; import static me.odinmain.utils.Utils.postAndCatch; import static org.lwjgl.opengl.GL11.*; @@ -74,10 +74,10 @@ private void setBrightness(T entity, float partial GL11.glTexEnvi(8960, OpenGlHelper.GL_OPERAND0_ALPHA, 770); this.brightnessBuffer.position(0); Color color = highlightEntity.getColor(); - brightnessBuffer.put(ColorUtils.getRed(color) / 255f); - brightnessBuffer.put(ColorUtils.getGreen(color) / 255f); - brightnessBuffer.put(ColorUtils.getBlue(color) / 255f); - brightnessBuffer.put(ColorUtils.getAlpha(color) / 255f); + brightnessBuffer.put(getRed(color) / 255f); + brightnessBuffer.put(getGreen(color) / 255f); + brightnessBuffer.put(getBlue(color) / 255f); + brightnessBuffer.put(getAlpha(color) / 255f); this.brightnessBuffer.flip(); GL11.glTexEnv(8960, 8705, this.brightnessBuffer); GlStateManager.setActiveTexture(OpenGlHelper.GL_TEXTURE2); diff --git a/odin/src/main/kotlin/me/odin/features/impl/floor7/p3/ArrowsDevice.kt b/odin/src/main/kotlin/me/odin/features/impl/floor7/p3/ArrowsDevice.kt index dc6aed1a7..b33fb7f35 100644 --- a/odin/src/main/kotlin/me/odin/features/impl/floor7/p3/ArrowsDevice.kt +++ b/odin/src/main/kotlin/me/odin/features/impl/floor7/p3/ArrowsDevice.kt @@ -1,18 +1,22 @@ package me.odin.features.impl.floor7.p3 -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.events.impl.BlockChangeEvent import me.odinmain.events.impl.RealServerTick -import me.odinmain.features.Category import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* -import me.odinmain.utils.* +import me.odinmain.features.settings.impl.ActionSetting +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.KeybindSetting +import me.odinmain.utils.distanceSquaredTo +import me.odinmain.utils.equalsOneOf import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.PlayerUtils import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.dungeon.M7Phases import me.odinmain.utils.skyblock.modMessage +import me.odinmain.utils.toVec3 import net.minecraft.entity.item.EntityArmorStand import net.minecraft.init.Blocks import net.minecraft.util.AxisAlignedBB diff --git a/odinclient/src/main/java/me/odinclient/mixin/mixins/MixinRenderEntityItem.java b/odinclient/src/main/java/me/odinclient/mixin/mixins/MixinRenderEntityItem.java index cc8d1a62c..5b1751254 100644 --- a/odinclient/src/main/java/me/odinclient/mixin/mixins/MixinRenderEntityItem.java +++ b/odinclient/src/main/java/me/odinclient/mixin/mixins/MixinRenderEntityItem.java @@ -1,7 +1,6 @@ package me.odinclient.mixin.mixins; -import com.github.stivais.ui.color.Color; -import com.github.stivais.ui.color.ColorUtils; +import com.github.stivais.aurora.color.Color; import me.odinmain.utils.render.HighlightRenderer; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.GlStateManager; @@ -19,6 +18,7 @@ import java.nio.FloatBuffer; +import static com.github.stivais.aurora.utils.Color_utilitiesKt.*; import static org.lwjgl.opengl.GL11.*; @Mixin(RenderEntityItem.class) @@ -70,10 +70,10 @@ private void doRenderInject(EntityItem entity, double x, double y, double z, flo GL11.glTexEnvi(8960, OpenGlHelper.GL_OPERAND0_ALPHA, 770); this.odinMod$brightnessBuffer.position(0); Color color = highlightEntity.getColor(); - odinMod$brightnessBuffer.put(ColorUtils.getRed(color) / 255f); - odinMod$brightnessBuffer.put(ColorUtils.getGreen(color) / 255f); - odinMod$brightnessBuffer.put(ColorUtils.getBlue(color) / 255f); - odinMod$brightnessBuffer.put(ColorUtils.getAlpha(color) / 255f); + odinMod$brightnessBuffer.put(getRed(color) / 255f); + odinMod$brightnessBuffer.put(getGreen(color) / 255f); + odinMod$brightnessBuffer.put(getBlue(color) / 255f); + odinMod$brightnessBuffer.put(getAlpha(color) / 255f); this.odinMod$brightnessBuffer.flip(); GL11.glTexEnv(8960, 8705, this.odinMod$brightnessBuffer); GlStateManager.setActiveTexture(OpenGlHelper.GL_TEXTURE2); diff --git a/odinclient/src/main/java/me/odinclient/mixin/mixins/MixinRendererLivingEntity.java b/odinclient/src/main/java/me/odinclient/mixin/mixins/MixinRendererLivingEntity.java index 26a52f40f..30cdbf4ee 100644 --- a/odinclient/src/main/java/me/odinclient/mixin/mixins/MixinRendererLivingEntity.java +++ b/odinclient/src/main/java/me/odinclient/mixin/mixins/MixinRendererLivingEntity.java @@ -1,7 +1,6 @@ package me.odinclient.mixin.mixins; -import com.github.stivais.ui.color.Color; -import com.github.stivais.ui.color.ColorUtils; +import com.github.stivais.aurora.color.Color; import me.odinmain.events.impl.RenderEntityModelEvent; import me.odinmain.utils.render.HighlightRenderer; import me.odinmain.utils.render.RenderUtils; @@ -23,6 +22,7 @@ import java.nio.FloatBuffer; +import static com.github.stivais.aurora.utils.Color_utilitiesKt.*; import static me.odinmain.utils.Utils.postAndCatch; import static org.lwjgl.opengl.GL11.*; @@ -74,10 +74,10 @@ private void setBrightness(T entity, float partial GL11.glTexEnvi(8960, OpenGlHelper.GL_OPERAND0_ALPHA, 770); this.brightnessBuffer.position(0); Color color = highlightEntity.getColor(); - brightnessBuffer.put(ColorUtils.getRed(color) / 255f); - brightnessBuffer.put(ColorUtils.getGreen(color) / 255f); - brightnessBuffer.put(ColorUtils.getBlue(color) / 255f); - brightnessBuffer.put(ColorUtils.getAlpha(color) / 255f); + brightnessBuffer.put(getRed(color) / 255f); + brightnessBuffer.put(getGreen(color) / 255f); + brightnessBuffer.put(getBlue(color) / 255f); + brightnessBuffer.put(getAlpha(color) / 255f); this.brightnessBuffer.flip(); GL11.glTexEnv(8960, 8705, this.brightnessBuffer); GlStateManager.setActiveTexture(OpenGlHelper.GL_TEXTURE2); diff --git a/odinclient/src/main/kotlin/me/odinclient/features/impl/floor7/p3/ArrowsDevice.kt b/odinclient/src/main/kotlin/me/odinclient/features/impl/floor7/p3/ArrowsDevice.kt index 3d61452b5..9ccc4028f 100644 --- a/odinclient/src/main/kotlin/me/odinclient/features/impl/floor7/p3/ArrowsDevice.kt +++ b/odinclient/src/main/kotlin/me/odinclient/features/impl/floor7/p3/ArrowsDevice.kt @@ -1,6 +1,6 @@ package me.odinclient.features.impl.floor7.p3 -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinclient.utils.skyblock.PlayerUtils.rightClick import me.odinmain.events.impl.BlockChangeEvent import me.odinmain.events.impl.RealServerTick @@ -14,7 +14,9 @@ import me.odinmain.utils.render.RenderUtils.renderY import me.odinmain.utils.render.RenderUtils.renderZ import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.* -import me.odinmain.utils.skyblock.dungeon.* +import me.odinmain.utils.skyblock.dungeon.DungeonClass +import me.odinmain.utils.skyblock.dungeon.DungeonUtils +import me.odinmain.utils.skyblock.dungeon.M7Phases import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.settings.KeyBinding import net.minecraft.entity.item.EntityArmorStand diff --git a/odinclient/src/main/kotlin/me/odinclient/features/impl/floor7/p3/SimonSays.kt b/odinclient/src/main/kotlin/me/odinclient/features/impl/floor7/p3/SimonSays.kt index db43448be..87d2ac1b7 100644 --- a/odinclient/src/main/kotlin/me/odinclient/features/impl/floor7/p3/SimonSays.kt +++ b/odinclient/src/main/kotlin/me/odinclient/features/impl/floor7/p3/SimonSays.kt @@ -1,11 +1,10 @@ package me.odinclient.features.impl.floor7.p3 -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinclient.utils.skyblock.PlayerUtils.rightClick import me.odinmain.events.impl.BlockChangeEvent import me.odinmain.events.impl.PostEntityMetadata -import me.odinmain.features.Category import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency import me.odinmain.features.settings.impl.BooleanSetting @@ -13,9 +12,12 @@ import me.odinmain.features.settings.impl.NumberSetting import me.odinmain.utils.* import me.odinmain.utils.clock.Clock import me.odinmain.utils.render.Renderer -import me.odinmain.utils.skyblock.* +import me.odinmain.utils.skyblock.devMessage import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.dungeon.M7Phases +import me.odinmain.utils.skyblock.getBlockIdAt +import me.odinmain.utils.skyblock.modMessage +import me.odinmain.utils.ui.Colors import net.minecraft.block.BlockButtonStone import net.minecraft.entity.item.EntityItem import net.minecraft.init.Blocks @@ -141,7 +143,7 @@ object SimonSays : Module( val isInSSRange = mc.thePlayer.getDistanceSqToCenter(BlockPos(108, 120, 93)) <= 1.45 * 1.45 Renderer.drawCylinder( Vec3(108.5, 120.0, 93.5), 1.45f, 1.45f, .6f, 35, - 1, 0f, 90f, 90f, (if (isInSSRange) Color.GREEN else Color.MINECRAFT_GOLD).withAlpha(.5f) + 1, 0f, 90f, 90f, (if (isInSSRange) Color.GREEN else Colors.MINECRAFT_GOLD).withAlpha(.5f) ) if ( diff --git a/odinclient/src/main/kotlin/me/odinclient/features/impl/render/ChestEsp.kt b/odinclient/src/main/kotlin/me/odinclient/features/impl/render/ChestEsp.kt index 5d081207e..3532af481 100644 --- a/odinclient/src/main/kotlin/me/odinclient/features/impl/render/ChestEsp.kt +++ b/odinclient/src/main/kotlin/me/odinclient/features/impl/render/ChestEsp.kt @@ -1,14 +1,17 @@ package me.odinclient.features.impl.render -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.events.impl.RenderChestEvent -import me.odinmain.features.Category import me.odinmain.features.Module -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.SelectorSetting import me.odinmain.utils.equalsOneOf import me.odinmain.utils.render.Renderer -import me.odinmain.utils.skyblock.* +import me.odinmain.utils.skyblock.Island +import me.odinmain.utils.skyblock.LocationUtils import me.odinmain.utils.skyblock.dungeon.DungeonUtils +import me.odinmain.utils.skyblock.getBlockAt import me.odinmain.utils.toAABB import net.minecraft.client.renderer.GlStateManager import net.minecraft.init.Blocks diff --git a/odinclient/src/main/kotlin/me/odinclient/features/impl/render/EtherWarpHelper.kt b/odinclient/src/main/kotlin/me/odinclient/features/impl/render/EtherWarpHelper.kt index ab521dfd4..9a1b1d031 100644 --- a/odinclient/src/main/kotlin/me/odinclient/features/impl/render/EtherWarpHelper.kt +++ b/odinclient/src/main/kotlin/me/odinclient/features/impl/render/EtherWarpHelper.kt @@ -1,12 +1,11 @@ package me.odinclient.features.impl.render -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinclient.mixin.accessors.IEntityPlayerSPAccessor import me.odinclient.utils.skyblock.PlayerUtils import me.odinmain.events.impl.ClickEvent import me.odinmain.events.impl.PacketReceivedEvent -import me.odinmain.features.Category import me.odinmain.features.Module import me.odinmain.features.impl.dungeon.dungeonwaypoints.DungeonWaypoints.toBlockPos import me.odinmain.features.impl.dungeon.dungeonwaypoints.DungeonWaypoints.toVec3 @@ -17,11 +16,14 @@ import me.odinmain.utils.* import me.odinmain.utils.clock.Clock import me.odinmain.utils.render.RenderUtils.renderVec import me.odinmain.utils.render.Renderer -import me.odinmain.utils.skyblock.* import me.odinmain.utils.skyblock.EtherWarpHelper import me.odinmain.utils.skyblock.EtherWarpHelper.etherPos +import me.odinmain.utils.skyblock.Island +import me.odinmain.utils.skyblock.LocationUtils import me.odinmain.utils.skyblock.PlayerUtils.playLoudSound import me.odinmain.utils.skyblock.dungeon.DungeonUtils +import me.odinmain.utils.skyblock.usingEtherWarp +import me.odinmain.utils.ui.Colors import net.minecraft.network.play.server.S29PacketSoundEffect import net.minecraft.util.MathHelper import net.minecraft.util.Vec3 @@ -35,7 +37,7 @@ object EtherWarpHelper : Module( ) { private val zeroPing by BooleanSetting("Zero Ping", false, description = "Teleports you to the exact position of the etherwarp.").withDependency { isDev } private val render by BooleanSetting("Show Etherwarp Guess", true, description = "Shows where etherwarp will take you.") - private val color by ColorSetting("Color", Color.MINECRAFT_GOLD.withAlpha(.5f), allowAlpha = true, description = "Color of the box.").withDependency { render } + private val color by ColorSetting("Color", Colors.MINECRAFT_GOLD.withAlpha(.5f), allowAlpha = true, description = "Color of the box.").withDependency { render } private val renderFail by BooleanSetting("Show when failed", true, description = "Shows the box even when the guess failed.").withDependency { render } private val wrongColor by ColorSetting("Wrong Color", Color.RED.withAlpha(.5f), allowAlpha = true, description = "Color of the box if guess failed.").withDependency { renderFail } diff --git a/odinclient/src/main/kotlin/me/odinclient/features/impl/render/Ghosts.kt b/odinclient/src/main/kotlin/me/odinclient/features/impl/render/Ghosts.kt index f86a48098..da9e08009 100644 --- a/odinclient/src/main/kotlin/me/odinclient/features/impl/render/Ghosts.kt +++ b/odinclient/src/main/kotlin/me/odinclient/features/impl/render/Ghosts.kt @@ -1,7 +1,6 @@ package me.odinclient.features.impl.render -import com.github.stivais.ui.color.Color -import me.odinmain.features.Category +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module import me.odinmain.features.settings.impl.BooleanSetting import me.odinmain.utils.addVec diff --git a/odinclient/src/main/kotlin/me/odinclient/features/impl/render/Trajectories.kt b/odinclient/src/main/kotlin/me/odinclient/features/impl/render/Trajectories.kt index fce54d092..c63afc7cb 100644 --- a/odinclient/src/main/kotlin/me/odinclient/features/impl/render/Trajectories.kt +++ b/odinclient/src/main/kotlin/me/odinclient/features/impl/render/Trajectories.kt @@ -1,22 +1,25 @@ package me.odinclient.features.impl.render -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.events.impl.RenderEntityModelEvent -import me.odinmain.features.Category import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* -import me.odinmain.utils.* -import me.odinmain.utils.render.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting +import me.odinmain.utils.addVec +import me.odinmain.utils.render.OutlineUtils +import me.odinmain.utils.render.RenderUtils import me.odinmain.utils.render.RenderUtils.renderVec import me.odinmain.utils.render.RenderUtils.renderX import me.odinmain.utils.render.RenderUtils.renderY import me.odinmain.utils.render.RenderUtils.renderZ +import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.isHolding import me.odinmain.utils.skyblock.isLeap import me.odinmain.utils.skyblock.isShortbow +import me.odinmain.utils.ui.Colors import net.minecraft.entity.Entity import net.minecraft.entity.boss.EntityWither import net.minecraft.entity.item.EntityArmorStand @@ -24,11 +27,16 @@ import net.minecraft.entity.monster.EntityBlaze import net.minecraft.entity.projectile.EntityArrow import net.minecraft.item.ItemBow import net.minecraft.item.ItemEnderPearl -import net.minecraft.util.* +import net.minecraft.util.AxisAlignedBB +import net.minecraft.util.EnumFacing import net.minecraft.util.MathHelper.sqrt_double +import net.minecraft.util.MovingObjectPosition +import net.minecraft.util.Vec3 import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import kotlin.math.* +import kotlin.math.cos +import kotlin.math.sin +import kotlin.math.sqrt object Trajectories : Module( name = "Trajectories", @@ -43,7 +51,7 @@ object Trajectories : Module( private val width by NumberSetting("Line Width", 1f, 0.1f, 5.0, 0.1f, description = "The width of the line.") private val planeSize by NumberSetting("Plane Size", 2f, 0.1f, 5.0, 0.1f, description = "The size of the plane.").withDependency { plane } private val boxSize by NumberSetting("Box Size", 0.5f, 0.5f, 3.0f, 0.1f, description = "The size of the box.").withDependency { boxes } - private val color by ColorSetting("Color", Color.MINECRAFT_AQUA, true, description = "The color of the trajectory.") + private val color by ColorSetting("Color", Colors.MINECRAFT_AQUA, true, description = "The color of the trajectory.") private var boxRenderQueue: MutableList = mutableListOf() private var entityRenderQueue = mutableListOf() diff --git a/odinclient/src/main/kotlin/me/odinclient/features/impl/skyblock/ChocolateFactory.kt b/odinclient/src/main/kotlin/me/odinclient/features/impl/skyblock/ChocolateFactory.kt index ca42a034d..fddebc73b 100644 --- a/odinclient/src/main/kotlin/me/odinclient/features/impl/skyblock/ChocolateFactory.kt +++ b/odinclient/src/main/kotlin/me/odinclient/features/impl/skyblock/ChocolateFactory.kt @@ -1,15 +1,16 @@ package me.odinclient.features.impl.skyblock -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.events.impl.GuiEvent -import me.odinmain.features.Category import me.odinmain.features.Module import me.odinmain.features.settings.impl.BooleanSetting import me.odinmain.features.settings.impl.NumberSetting -import me.odinmain.utils.* +import me.odinmain.utils.name +import me.odinmain.utils.noControlCodes import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.* import me.odinmain.utils.skyblock.PlayerUtils.windowClick +import me.odinmain.utils.ui.Colors import net.minecraft.entity.item.EntityArmorStand import net.minecraft.inventory.Container import net.minecraft.inventory.ContainerChest @@ -132,7 +133,7 @@ object ChocolateFactory : Module( private enum class ChocolateEggs( val texture: String, val type: String, val color: Color, val index: Int ) { - Breakfast(BunnyEggTextures.BREAKFAST_EGG_TEXTURE, "§6Breakfast Egg", Color.MINECRAFT_GOLD, 0), + Breakfast(BunnyEggTextures.BREAKFAST_EGG_TEXTURE, "§6Breakfast Egg", Colors.MINECRAFT_GOLD, 0), Lunch(BunnyEggTextures.LUNCH_EGG_TEXTURE, "§9Lunch Egg ", Color.BLUE, 1), Dinner(BunnyEggTextures.DINNER_EGG_TEXTURE, "§aDinner Egg", Color.GREEN, 2), } diff --git a/src/main/kotlin/com/github/stivais/ui/UI.kt b/src/main/kotlin/com/github/stivais/ui/UI.kt deleted file mode 100644 index 561d58b4d..000000000 --- a/src/main/kotlin/com/github/stivais/ui/UI.kt +++ /dev/null @@ -1,145 +0,0 @@ -package com.github.stivais.ui - -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.constraints.px -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.elements.impl.Group -import com.github.stivais.ui.elements.scope.ElementScope -import com.github.stivais.ui.events.EventManager -import com.github.stivais.ui.events.Lifetime -import com.github.stivais.ui.operation.UIOperation -import com.github.stivais.ui.renderer.Font -import com.github.stivais.ui.renderer.Renderer -import com.github.stivais.ui.renderer.impl.NVGRenderer -import com.github.stivais.ui.utils.loop -import me.odinmain.OdinMain -import me.odinmain.utils.round -import java.util.logging.Logger - -class UI(val renderer: Renderer = NVGRenderer(OdinMain.wrapper)) { - - /** - * Used to reference the handler for this UI - */ - lateinit var window: Window - - /** - * The master element, acts as the background/border - */ - val main: Group = Group(Constraints(0.px, 0.px, 1920.px, 1080.px)) - - /** - * Handles events, like mouse clicks or keyboard presses - */ - var eventManager: EventManager = EventManager(this) - - constructor(renderer: Renderer = NVGRenderer(OdinMain.wrapper), dsl: ElementScope.() -> Unit) : this(renderer) { - main.initialize(this) - ElementScope(main).dsl() - } - - inline val mx get() = eventManager.mouseX - - inline val my get() = eventManager.mouseY - - var operations: ArrayList? = null - - fun initialize(width: Int, height: Int, window: Window? = null) { - window?.let { this.window = it } - main.constraints.width = width.px - main.constraints.height = height.px - - main.initialize(this) - main.size() - main.positionChildren() - main.clip() - - eventManager.dispatchToAll(Lifetime.AfterInitialized, main) - } - - // frame metrics - var performance: String? = null - var lastUpdate = System.nanoTime() - var frames: Int = 0 - var frameTime: Long = 0 - - // rework fbo - fun render() { - operations?.removeAll { - it.run() - } - main.preRender() - renderer.beginFrame(main.width, main.height) - renderer.push() - main.render() - performance?.let { - renderer.text(it, main.width - renderer.textWidth(it, 12f), main.height - 12f, 12f) - } - renderer.pop() - renderer.endFrame() - } - - internal inline fun measureFrametime(block: () -> Unit) { -// if (!debug) return - val start = System.nanoTime() - block() - frameTime += System.nanoTime() - start - frames++ - if (System.nanoTime() - lastUpdate >= 1_000_000_000) { - lastUpdate = System.nanoTime() - val sb = StringBuilder() - sb.append("elements: ${getStats(main, false)}, elements rendering: ${getStats(main, true)},") - sb.append("frame-time avg: ${((frameTime / frames) / 1_000_000.0).round(4)}ms") - performance = sb.toString() - frames = 0 - frameTime = 0 - } - } - - private fun getStats(element: Element, onlyRender: Boolean): Int { - var amount = 0 - if (!(onlyRender && !element.renders)) { - amount++ - element.elements?.loop { amount += getStats(it, onlyRender) } - } - return amount - } - - fun resize(width: Int, height: Int) { - main.constraints.width = width.px - main.constraints.height = height.px - main.redraw = true - } - - fun cleanup() { - unfocus() - eventManager.dispatchToAllReverse(Lifetime.Uninitialized, main) - } - - fun focus(element: Element) { - eventManager.focus(element) - } - - fun unfocus() { - eventManager.unfocus() - } - - fun isFocused(element: Element): Boolean { - return eventManager.focused == element - } - - fun empty() { - cleanup() // might active the event multiple times, look into this - main.removeAll() - operations?.clear() - } - - companion object { - // temp name - // future: maybe make a log handling class, so you can get an element's "errors" and details - val logger: Logger = Logger.getLogger("Odin/UI") - - @JvmField - val defaultFont = Font("Regular", "/assets/odinmain/fonts/Regular.otf") - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/UIScreen.kt b/src/main/kotlin/com/github/stivais/ui/UIScreen.kt deleted file mode 100644 index a4c18e1c8..000000000 --- a/src/main/kotlin/com/github/stivais/ui/UIScreen.kt +++ /dev/null @@ -1,117 +0,0 @@ -package com.github.stivais.ui - -import me.odinmain.OdinMain.display -import me.odinmain.OdinMain.mc -import net.minecraft.client.gui.GuiScreen -import net.minecraftforge.client.event.RenderWorldLastEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.lwjgl.input.Keyboard -import org.lwjgl.input.Mouse -import org.lwjgl.opengl.Display - -open class UIScreen(val ui: UI) : GuiScreen(), Window { - - private var previousWidth: Int = 0 - private var previousHeight: Int = 0 - private val pressedKeys = mutableSetOf() - - fun close() { - if (mc.currentScreen == null) { - // assume current is the ui rendering - closeAnimHandler = null - } else if (mc.currentScreen == this) { - mc.displayGuiScreen(null) - } - } - - override fun initGui() { - val start = System.nanoTime() - ui.initialize(Display.getWidth(), Display.getHeight(), this) - println("UI initialization took: ${System.nanoTime() - start}") - } - - override fun onGuiClosed() { - ui.cleanup() - } - - override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { - ui.measureFrametime { - val w = mc.framebuffer.framebufferWidth - val h = mc.framebuffer.framebufferHeight - if (w != previousWidth || h != previousHeight) { - ui.resize(w, h) - previousWidth = w - previousHeight = h - } - - ui.eventManager.apply { - val mx = Mouse.getX().toFloat() - val my = previousHeight - Mouse.getY() - 1f - - if (this.mouseX != mx || this.mouseY != my || check()) { - onMouseMove(mx, my) - } - } - ui.render() - } - - for (key in pressedKeys.toList()) { - if (!Keyboard.isKeyDown(key)) { - ui.eventManager.onKeyReleased(key) - pressedKeys.remove(key) - } - } - } - - override fun handleMouseInput() { - super.handleMouseInput() - val scroll = Mouse.getEventDWheel() - if (scroll != 0) { - ui.eventManager.onMouseScroll(scroll.toFloat()) - } - } - - override fun mouseClicked(mouseX: Int, mouseY: Int, button: Int) { - ui.eventManager.onMouseClick(button) - } - - override fun mouseReleased(mouseX: Int, mouseY: Int, button: Int) { - ui.eventManager.onMouseRelease(button) - } - - override fun keyTyped(typedChar: Char, keyCode: Int) { - if (ui.eventManager.onKeyType(typedChar)) return - if (ui.eventManager.onKeycodePressed(keyCode)) { - pressedKeys.add(keyCode) - return - } - super.keyTyped(typedChar, keyCode) - } - - override fun doesGuiPauseGame(): Boolean = false - - companion object { - fun open(ui: UI) { - display = UIScreen(ui) - } - - @JvmName("openUI") - fun UI.open() { - open(this) - } - - fun UI.init(): UI { - initialize(Display.getWidth(), Display.getHeight()) - return this - } - - var closeAnimHandler: UIScreen? = null - - @SubscribeEvent - fun onRender(event: RenderWorldLastEvent) { - if (mc.currentScreen == null) { - closeAnimHandler?.drawScreen(0, 0, event.partialTicks) - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/Window.kt b/src/main/kotlin/com/github/stivais/ui/Window.kt deleted file mode 100644 index 4822b6b12..000000000 --- a/src/main/kotlin/com/github/stivais/ui/Window.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.stivais.ui - -/** - * Used to reference the handler for [UI] - */ -interface Window \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/animation/Animating.kt b/src/main/kotlin/com/github/stivais/ui/animation/Animating.kt deleted file mode 100644 index d27caeea9..000000000 --- a/src/main/kotlin/com/github/stivais/ui/animation/Animating.kt +++ /dev/null @@ -1,66 +0,0 @@ -package com.github.stivais.ui.animation - -sealed interface Animating { - - fun animate(duration: Float, type: Animations): Animation? - - interface Swapping : Animating { - - fun swap() - - class Impl(var from: Float, var to: Float) : Swapping { - - private var current: Float = 0f - - private var before: Float? = null - - var animation: Animation? = null - private set - - fun get(): Float { - animation?.let { anim -> - val progress = anim.get() - val from = before ?: from - current = from + (to - from) * progress - - if (anim.finished) { - animation = null - before = null - swap() - } - return current - } - return from - } - - override fun swap() { - val temp = to - to = from - from = temp - } - - override fun animate(duration: Float, type: Animations): Animation? { - if (duration == 0f) { - swap() - } else { - if (animation != null) { - before = current - swap() - animation = Animation(duration * animation!!.get(), type) - } else { - animation = Animation(duration, type) - } - } - return animation - } - } - - companion object { - /** - * Constant version for [Animating.Swapping.Impl], intended for delegating and overriding get() - */ - @JvmStatic - val Impl = Impl(0f, 0f) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/animation/Animation.kt b/src/main/kotlin/com/github/stivais/ui/animation/Animation.kt deleted file mode 100644 index 5bf99a2c7..000000000 --- a/src/main/kotlin/com/github/stivais/ui/animation/Animation.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.stivais.ui.animation - -class Animation( - var duration: Float, - val type: Animations, - var from: Float = 0f, - var to: Float = 1f, -) { - - var time: Long = System.nanoTime() - - private var onFinish: (() -> Unit)? = null - - var finished: Boolean = false - set(value) { - if (value) onFinish?.invoke() - field = value - } - - fun get(): Float { - val percent = ((System.nanoTime() - time) / duration) - if (percent >= 1f) { - finished = true - onFinish?.invoke() - } - return (if (finished) to else from + (to - from) * type.getValue(percent)) - } - - infix fun onFinish(block: () -> Unit): Animation { - onFinish = block - return this - } - - override fun toString(): String = "Animation(duration=$duration)" -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/animation/animations.kt b/src/main/kotlin/com/github/stivais/ui/animation/animations.kt deleted file mode 100644 index 388568d15..000000000 --- a/src/main/kotlin/com/github/stivais/ui/animation/animations.kt +++ /dev/null @@ -1,53 +0,0 @@ -@file:Suppress("UNUSED") - -package com.github.stivais.ui.animation - -import kotlin.math.pow - -private interface Strategy { - fun getValue(percent: Float): Float -} - -/** - * A bunch of animations commonly used in UI - * - * Animations taken from [https://easings.net/](https://easings.net/) - * - * @see Animation - */ -enum class Animations : Strategy { - Linear { - override fun getValue(percent: Float): Float = percent - }, - EaseInQuad { - override fun getValue(percent: Float): Float = percent * percent - }, - EaseOutQuad { - override fun getValue(percent: Float): Float = 1 - (1 - percent) * (1 - percent) - }, - EaseInOutQuad { - override fun getValue(percent: Float): Float { - return if (percent < 0.5) 2 * percent * percent - else 1 - (-2 * percent + 2).pow(2f) / 2 - } - }, - EaseInQuint { - override fun getValue(percent: Float): Float = percent * percent * percent * percent * percent - }, - EaseOutQuint { - override fun getValue(percent: Float): Float = 1 - (1 - percent).pow(5f) - }, - EaseInOutQuint { - override fun getValue(percent: Float): Float { - return if (percent < 0.5f) 16f * percent * percent * percent * percent * percent - else 1 - (-2 * percent + 2).pow(5f) / 2f - } - }, - EaseInBack { - override fun getValue(percent: Float): Float { - val c1 = 1.70158f - val c3 = c1 + 1 - return c3 * percent * percent * percent - c1 * percent * percent - } - }, -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/color/Color.kt b/src/main/kotlin/com/github/stivais/ui/color/Color.kt deleted file mode 100644 index d6f7a2c80..000000000 --- a/src/main/kotlin/com/github/stivais/ui/color/Color.kt +++ /dev/null @@ -1,275 +0,0 @@ -package com.github.stivais.ui.color - -import com.github.stivais.ui.animation.Animating -import com.github.stivais.ui.animation.Animation -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.elements.Element -import kotlin.math.roundToInt -import java.awt.Color as JColor - -/** - * # Color - * - * The color interface is used to represent a 32-bit integer in ARGB format. - * - * It is primarily used in [UIs][com.github.stivais.ui.UI]. - * - * @see Color.RGB - * @see Color.HSB - * @see Color.Animated - */ -interface Color { - - /** - * Integer representation of this color in ARGB format - */ - val rgba: Int - - /** - * Uses internally by [UIs][com.github.stivais.ui.UI] - */ - fun get(element: Element): Int = rgba - - /** - * # Color.RGB - * - * Low cost implementation of [Color], due to Kotlin's inline classes - * - * This is the most common [color][Color], because it mainly represents red, blue and green. - */ - @JvmInline - value class RGB(override val rgba: Int) : Color { - constructor( - red: Int, - green: Int, - blue: Int, - alpha: Float = 1f - ) : this(getRGBA(red, green, blue, (alpha * 255).roundToInt())) - } - - /** - * # Color.HSB - * - * This [Color] implementation represents the color in HSBA format. - * - * It only updates the [rgba][Color.rgba] value if any of the hue, saturation or brightness values have been changed. - */ - open class HSB(hue: Float, saturation: Float, brightness: Float, alpha: Float = 1f) : Color { - - constructor(hsb: FloatArray, alpha: Float = 1f) : this(hsb[0], hsb[1], hsb[2], alpha) - - constructor(other: HSB) : this(other.hue, other.saturation, other.brightness, other.alpha) - - var hue = hue - set(value) { - field = value - needsUpdate = true - } - - var saturation = saturation - set(value) { - field = value - needsUpdate = true - } - - var brightness = brightness - set(value) { - field = value - needsUpdate = true - } - - var alpha = alpha - set(value) { - field = value - needsUpdate = true - } - - @Transient - private var needsUpdate: Boolean = true - - override var rgba: Int = 0 - get() { - if (needsUpdate) { - field = - (JColor.HSBtoRGB(hue, saturation, brightness) and 0X00FFFFFF) or ((alpha * 255).toInt() shl 24) - needsUpdate = false - } - return field - } - set(value) { - if (field != value) { - field = value - val hsb = FloatArray(3) - JColor.RGBtoHSB(value.red, value.blue, value.green, hsb) - hue = hsb[0] - saturation = hsb[1] - brightness = hsb[2] - alpha = value.alpha / 255f - } - } - - - override fun equals(other: Any?): Boolean { - return other is Color && other.rgba == this.rgba - } - - override fun hashCode(): Int { - return rgba.hashCode() - } - } - - /** - * # Color.Animated - * - * This [Color] implementation allows you to animate between 2 different [colors][Color], - * allowing for the outcome to be expected. - * - * This implements the [Animating.Swapping] interface - * - * @see Animating.Swapping - */ - class Animated(from: Color, to: Color) : Color, Animating.Swapping { - - constructor(from: Color, to: Color, swapIf: Boolean) : this(from, to) { - if (swapIf) { - swap() - } - } - /** - * Current animation for this [Color.Animated] - * - * If this is null, that means it isn't animating - */ - var animation: Animation? = null - - /** - * The first color to animate from. - * - * Note: When animating it swaps between [color1] and [color2] - */ - var color1: Color = from - - /** - * The second color to animate from. - * - * Note: When animating it swaps between [color1] and [color2] - */ - var color2: Color = to - - private var current: Int = color1.rgba - private var from: Int = color1.rgba - - override val rgba: Int - get() { - if (animation != null) { - val progress = animation!!.get() - val to = color2.rgba - current = getRGBA( - (from.red + (to.red - from.red) * progress).toInt(), - (from.green + (to.green - from.green) * progress).toInt(), - (from.blue + (to.blue - from.blue) * progress).toInt(), - (from.alpha + (to.alpha - from.alpha) * progress).toInt() - ) - if (animation!!.finished) { - animation = null - swap() - } - return current - } - return color1.rgba - } - - override fun get(element: Element): Int { - // add stuff when fbo - return rgba - } - - override fun animate(duration: Float, type: Animations): Animation? { - if (duration == 0f) { - swap() - current = color1.rgba // here so it updates if you swap a color and want to animate it later - } else { - if (animation != null) { - swap() - animation = Animation(duration * animation!!.get(), type) - from = current - } else { - animation = Animation(duration, type) - from = color1.rgba - } - return animation!! - } - return null - } - - override fun swap() { - val temp = color2 - color2 = color1 - color1 = temp - } - } - - companion object { - @JvmField - val TRANSPARENT = RGB(0, 0, 0, 0f) - - @JvmField - val WHITE = RGB(255, 255, 255) - - @JvmField - val BLACK = RGB(0, 0, 0) - - @JvmField - val RED = RGB(255, 0, 0) - - @JvmField - val BLUE = RGB(0, 0, 255) - - @JvmField - val GREEN = RGB(0, 255, 0) - - // Minecraft colors - - @JvmField - val MINECRAFT_DARK_BLUE = RGB(0, 0, 170) - - @JvmField - val MINECRAFT_DARK_GREEN = RGB(0, 170, 0) - - @JvmField - val MINECRAFT_DARK_AQUA = RGB(0, 170, 170) - - @JvmField - val MINECRAFT_DARK_RED = RGB(170, 0, 0) - - @JvmField - val MINECRAFT_DARK_PURPLE = RGB(170, 0, 170) - - @JvmField - val MINECRAFT_GOLD = RGB(255, 170, 0) - - @JvmField - val MINECRAFT_GRAY = RGB(170, 170, 170) - - @JvmField - val MINECRAFT_DARK_GRAY = RGB(85, 85, 85) - - @JvmField - val MINECRAFT_BLUE = RGB(85, 85, 255) - - @JvmField - val MINECRAFT_GREEN = RGB(85, 255, 85) - - @JvmField - val MINECRAFT_AQUA = RGB(85, 255, 255) - - @JvmField - val MINECRAFT_RED = RGB(255, 85, 85) - - @JvmField - val MINECRAFT_LIGHT_PURPLE = RGB(255, 85, 255) - - @JvmField - val MINECRAFT_YELLOW = RGB(255, 255, 85) - } -} diff --git a/src/main/kotlin/com/github/stivais/ui/color/ColorUtils.kt b/src/main/kotlin/com/github/stivais/ui/color/ColorUtils.kt deleted file mode 100644 index f056263a6..000000000 --- a/src/main/kotlin/com/github/stivais/ui/color/ColorUtils.kt +++ /dev/null @@ -1,143 +0,0 @@ -@file:JvmName("ColorUtils") - -package com.github.stivais.ui.color - -import com.github.stivais.ui.color.Color.Companion.BLACK -import com.google.gson.* -import java.lang.reflect.Type -import kotlin.math.roundToInt - -inline val Int.red - get() = this shr 16 and 0xFF - -inline val Int.green - get() = this shr 8 and 0xFF - -inline val Int.blue - get() = this and 0xFF - -inline val Int.alpha - get() = (this shr 24) and 0xFF - -inline val Color.red - get() = rgba.red - -inline val Color.green - get() = rgba.green - -inline val Color.blue - get() = rgba.blue - -inline val Color.alpha - get() = rgba.alpha - -/** - * Checks if the [Colors][Color] alpha value is 0 - */ -inline val Color.isTransparent: Boolean - get() = alpha == 0 - -fun getRGBA(red: Int, green: Int, blue: Int, alpha: Int): Int { - return ((alpha shl 24) and 0xFF000000.toInt()) or ((red shl 16) and 0x00FF0000) or ((green shl 8) and 0x0000FF00) or (blue and 0x000000FF) -} - -fun getRGBA(red: Int, green: Int, blue: Int, alpha: Float): Int { - return (((alpha * 255).roundToInt() shl 24) and 0xFF000000.toInt()) or ((red shl 16) and 0x00FF0000) or ((green shl 8) and 0x0000FF00) or (blue and 0x000000FF) -} - -/** - * Copies an integer representing a color with a new alpha value provided - */ -fun Int.withAlpha(alpha: Int): Int = getRGBA(red, green, blue, alpha) - -/** - * Copies an integer representing a color with a new alpha value provided - */ -fun Int.withAlpha(alpha: Float): Int = withAlpha((alpha * 255).roundToInt()) - -/** - * Copies a color with the new alpha value provided - */ -fun Color.withAlpha(alpha: Float): Color = Color.RGB(red, green, blue, alpha) - -/** - * Copies a color with the new alpha value provided - */ -fun Color.withAlpha(alpha: Int): Color = Color.RGB(red, green, blue, alpha / 255f) - -/** - * Copies a color, multiplying its alpha value by a certain factor - */ -fun Color.multiplyAlpha(factor: Float): Color = withAlpha((alpha * factor).roundToInt()) - -fun colorFrom(hex: String): Color.RGB = Color.RGB(hexToRGBA(hex)) - -fun hexToRGBA(hex: String): Int { - return when (hex.length) { - 7 -> { - getRGBA( - hex.substring(1, 3).toInt(16), - hex.substring(3, 5).toInt(16), - hex.substring(5, 7).toInt(16), - 255 - ) - } - 9 -> { - getRGBA( - hex.substring(1, 3).toInt(16), - hex.substring(3, 5).toInt(16), - hex.substring(5, 7).toInt(16), - hex.substring(7, 9).toInt(16) - ) - } - else -> throw IllegalArgumentException("Invalid hex color format: $hex. Use #RRGGBB or #RRGGBBAA.") - } -} - -fun Color.toHexString(): String { - return "#" + Integer.toHexString(rgba).substring(2) -} - -fun Color.toHSB(): Color.HSB { - return Color.HSB( - java.awt.Color.RGBtoHSB( - red, - green, - blue, - FloatArray(size = 3) - ), - alpha / 255f - ) -} - -fun Int.brighter(factor: Double = 1.0): Int { - return darker(factor) // temp -} - -fun Int.darker(factor: Double = 1.0): Int { - return getRGBA( - (red * factor).roundToInt().coerceIn(0, 255), - (green * factor).roundToInt().coerceIn(0, 255), - (blue * factor).roundToInt().coerceIn(0, 255), - (alpha * factor).roundToInt().coerceIn(0, 255) - ) -} - -inline fun color(crossinline getter: () -> Int): Color = object : Color { - override val rgba: Int - get() { - return getter() - } -} - -class ColorSerializer : JsonSerializer, JsonDeserializer { - override fun serialize(p0: Color?, p1: Type?, p2: JsonSerializationContext?): JsonElement? { - return JsonPrimitive("#${p0?.toHexString() ?: BLACK.toHexString()}") - } - - override fun deserialize(p0: JsonElement?, p1: Type?, p2: JsonDeserializationContext? - ): Color? { - val hexValue = p0?.asString?.replace("#", "") ?: "00000000" - return colorFrom(hexValue) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/constraints.kt b/src/main/kotlin/com/github/stivais/ui/constraints/constraints.kt deleted file mode 100644 index bcd8dcce3..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/constraints.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.github.stivais.ui.constraints - -import com.github.stivais.ui.constraints.measurements.Undefined -import com.github.stivais.ui.elements.Element - -open class Constraints(var x: Position, var y: Position, var width: Size, var height: Size) - -class Positions(x: Position, y: Position) : Constraints(x, y, Undefined, Undefined) - -// todo: reduce interface usages (however im not sure if its possible) -interface Constraint { - fun get(element: Element, type: Type): Float - - fun reliesOnChild() = false - - companion object { - const val HORIZONTAL: Int = 0 - const val VERTICAL: Int = 1 - } -} - -interface Position : Constraint - -interface Size : Constraint - -interface Measurement : Position, Size - -enum class Type { - X, Y, W, H; - - inline val axis: Int - get() = when (this) { - X, W -> 0 - Y, H -> 1 - } - - - inline val isPosition: Boolean - get() = ordinal < 2 -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/dsl.kt b/src/main/kotlin/com/github/stivais/ui/constraints/dsl.kt deleted file mode 100644 index 729827e69..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/dsl.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.github.stivais.ui.constraints - -import com.github.stivais.ui.constraints.measurements.Percent -import com.github.stivais.ui.constraints.measurements.Pixel -import com.github.stivais.ui.constraints.measurements.Undefined -import com.github.stivais.ui.constraints.operational.Additive -import com.github.stivais.ui.constraints.operational.CoerceMaxOld -import com.github.stivais.ui.constraints.operational.Multiplicative -import com.github.stivais.ui.constraints.operational.Subtractive -import com.github.stivais.ui.constraints.positions.Alignment -import com.github.stivais.ui.constraints.positions.Center -import com.github.stivais.ui.constraints.sizes.Copying -import com.github.stivais.ui.constraints.sizes.Indent - -fun constrain( - x: Position = Undefined, - y: Position = Undefined, - w: Size = Undefined, - h: Size = Undefined -) = Constraints(x, y, w, h) - -fun at(x: Position = Undefined, y: Position = Undefined) = Positions(x, y) - -fun size(w: Size = Undefined, h: Size = Undefined) = Constraints(Undefined, Undefined, w, h) - -val Number.px: Pixel - get() { - val value = this.toFloat() - return Pixel(value) - } - -val Number.percent: Percent - get() { - val value = this.toFloat() / 100f - return Percent(value) - } - -val Number.indent - get() = Indent(this.toFloat()) - -val Position.center - get() = Alignment.Center(this) - -val Position.alignRight - get() = Alignment.Right(this) - -fun center(): Constraints = at(Center, Center) - -fun copies(indent: Number = 0f): Constraints { - if (indent == 0f) { - return Constraints(0.px, 0.px, Copying, Copying) - } - return Constraints(indent.px, indent.px, -(indent.px), -(indent.px)) -} - -fun indent(amount: Number): Constraints { - val indent = amount.indent - return size(indent, indent) -} - -operator fun Position.plus(other: Position?) = if (other == null) this else Additive(this, other) - -operator fun Size.plus(other: Size?) = if (other == null) this else Additive(this, other) - -operator fun Constraint.minus(other: Constraint) = Subtractive(this, other) - -operator fun Constraint.times(other: Constraint) = Multiplicative(this, other) - -fun Constraint.coerce(max: Float) = CoerceMaxOld(max, this) diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Animatable.kt b/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Animatable.kt deleted file mode 100644 index 273584a48..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Animatable.kt +++ /dev/null @@ -1,128 +0,0 @@ -package com.github.stivais.ui.constraints.measurements - -import com.github.stivais.ui.animation.Animating -import com.github.stivais.ui.animation.Animation -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.constraints.Constraint -import com.github.stivais.ui.constraints.Measurement -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -/** - * # Animatable - * - * The animatable constraint allows you to easily implement animations that'll appear exactly how you wanted them to. - * - * It works by animating between 2 different [Constraints][Constraint] provided, swapping between each when animated. - * - * If you need an animating constraint, where you need to animate to any point, look at [Animatable.Raw] - * - * @see Animatable.Raw - */ -class Animatable( - var from: Constraint, - var to: Constraint -): Measurement, Animating.Swapping by Animating.Swapping.Impl { - - constructor(from: Constraint, to: Constraint, swapIf: Boolean) : this(from, to) { - if (swapIf) { - swap() - } - } - - /** - * Current animation for this [Animatable] - * - * If this is null, that means it isn't animating - */ - var animation: Animation? = null - private set - - private var current: Float = 0f - - // used to effectively to smoothly swap animations - private var before: Float? = null - - override fun get(element: Element, type: Type): Float { - if (animation != null) { - element.redraw = true - val progress = animation!!.get() - val from = before ?: from.get(element, type) - current = from + (to.get(element, type) - from) * progress - - if (animation!!.finished) { - animation = null - before = null - swap() - } - return current - } - return from.get(element, type) - } - - override fun animate(duration: Float, type: Animations): Animation? { - if (duration == 0f) { - swap() - } else { - if (animation != null) { - before = current - swap() - animation = Animation(duration * animation!!.get(), type) - } else { - animation = Animation(duration, type) - } - } - return animation - } - - override fun swap() { - val temp = to - to = from - from = temp - } - - override fun reliesOnChild(): Boolean { - return from.reliesOnChild() || to.reliesOnChild() - } - - /** - * # Animatable.Raw - * - * This constraint allows you to animate to any points, used if you need to smoothly move something to a certain point. - * - * Note: The result could be messy - */ - class Raw(start: Float) : Measurement { - - var current: Float = start - - private var animation: Animation? = null - - fun animate(to: Float, duration: Float, type: Animations = Animations.Linear) { - if (animation == null) { - if (duration == 0f) current = to else animation = Animation(duration, type, current, to) - } else { - // continues current animation - animation!!.from = animation!!.get() - animation!!.to = to - animation!!.time = System.nanoTime() - animation!!.duration = duration - } - } - - fun to(to: Float) = if (animation != null) animation!!.to = to else current = to - - override fun get(element: Element, type: Type): Float { - if (animation != null) { - element.redraw = true - val result = animation!!.get() - if (animation!!.finished) { - animation = null - current = result - } - return result - } - return current - } - } -} diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Percent.kt b/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Percent.kt deleted file mode 100644 index 283137fa3..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Percent.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.stivais.ui.constraints.measurements - -import com.github.stivais.ui.constraints.Constraint.Companion.HORIZONTAL -import com.github.stivais.ui.constraints.Measurement -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -class Percent(var percent: Float) : Measurement { - - override fun get(element: Element, type: Type): Float { - return (if (type.axis == HORIZONTAL) element.parent!!.width else element.parent!!.height) * percent - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Pixel.kt b/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Pixel.kt deleted file mode 100644 index ae92c77ab..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Pixel.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.stivais.ui.constraints.measurements - -import com.github.stivais.ui.constraints.Constraint.Companion.HORIZONTAL -import com.github.stivais.ui.constraints.Measurement -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -open class Pixel(var pixels: Float): Measurement { - - override fun get(element: Element, type: Type): Float = pixels - - operator fun unaryMinus(): LeftPixel = LeftPixel(pixels) -} - -// todo: make it work with any position -class LeftPixel(pixels: Float): Pixel(pixels) { - override fun get(element: Element, type: Type): Float { - return if (type.axis == HORIZONTAL) { - val ix = (element.x - (element.parent?.x ?: 0f)) - (element.parent?.width ?: 0f) - (if (type.isPosition) element.width else ix) - pixels - } else { - val iy = (element.x - (element.parent?.x ?: 0f)) - (element.parent?.height ?: 0f) - (if (type.isPosition) element.height else iy) - pixels - } - } -} diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Undefined.kt b/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Undefined.kt deleted file mode 100644 index bfe928e58..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/measurements/Undefined.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.stivais.ui.constraints.measurements - -import com.github.stivais.ui.constraints.Measurement -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -data object Undefined : Measurement { - override fun get(element: Element, type: Type): Float { - return 0f - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/operational/Additive.kt b/src/main/kotlin/com/github/stivais/ui/constraints/operational/Additive.kt deleted file mode 100644 index da0beaa99..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/operational/Additive.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.stivais.ui.constraints.operational - -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.elements.Element - -class Additive(val first: Constraint, val second: Constraint) : Measurement { - override fun get(element: Element, type: Type): Float = first.get(element, type) + second.get(element, type) - - override fun reliesOnChild(): Boolean { - return first.reliesOnChild() || second.reliesOnChild() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/operational/Coerce.kt b/src/main/kotlin/com/github/stivais/ui/constraints/operational/Coerce.kt deleted file mode 100644 index 7eea9221c..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/operational/Coerce.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.stivais.ui.constraints.operational - -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.elements.Element - -class CoerceMaxOld(val amount: Float, val constraint: Constraint) : Measurement { - override fun get(element: Element, type: Type): Float { - return constraint.get(element, type).coerceAtMost(amount) - } - - override fun reliesOnChild(): Boolean { - return constraint.reliesOnChild() - } -} - -class CoerceMax(val constraint: Constraint, val max: Constraint) : Measurement { - override fun get(element: Element, type: Type): Float { - return constraint.get(element, type).coerceAtMost(max.get(element, type)) - } - - override fun reliesOnChild(): Boolean { - return constraint.reliesOnChild() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/operational/Multiplicative.kt b/src/main/kotlin/com/github/stivais/ui/constraints/operational/Multiplicative.kt deleted file mode 100644 index 6534ceb43..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/operational/Multiplicative.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.stivais.ui.constraints.operational - -import com.github.stivais.ui.constraints.Constraint -import com.github.stivais.ui.constraints.Measurement -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -class Multiplicative(val first: Constraint, val second: Constraint) : Measurement { - override fun get(element: Element, type: Type): Float { - return first.get(element, type) * second.get(element, type) - } - - override fun reliesOnChild(): Boolean { - return first.reliesOnChild() || second.reliesOnChild() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/operational/Subtractive.kt b/src/main/kotlin/com/github/stivais/ui/constraints/operational/Subtractive.kt deleted file mode 100644 index 5c70b69b8..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/operational/Subtractive.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.stivais.ui.constraints.operational - -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.elements.Element - -class Subtractive(val first: Constraint, val second: Constraint) : Measurement { - override fun get(element: Element, type: Type): Float = first.get(element, type) - second.get(element, type) -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/positions/Alignment.kt b/src/main/kotlin/com/github/stivais/ui/constraints/positions/Alignment.kt deleted file mode 100644 index 7f85b1094..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/positions/Alignment.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.stivais.ui.constraints.positions - -import com.github.stivais.ui.constraints.Constraint.Companion.HORIZONTAL -import com.github.stivais.ui.constraints.Position -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -sealed interface Alignment : Position { - - val position: Position - - class Center(override val position: Position) : Alignment { - override fun get(element: Element, type: Type): Float { - return position.get(element, type) - (if (type.axis == HORIZONTAL) element.width else element.height) / 2 - } - } - - class Right(override val position: Position) : Alignment { - override fun get(element: Element, type: Type): Float { - return position.get(element, type) - element.width - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/positions/Center.kt b/src/main/kotlin/com/github/stivais/ui/constraints/positions/Center.kt deleted file mode 100644 index afc0ceb1e..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/positions/Center.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.stivais.ui.constraints.positions - -import com.github.stivais.ui.constraints.Constraint.Companion.HORIZONTAL -import com.github.stivais.ui.constraints.Position -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -object Center : Position { - override fun get(element: Element, type: Type): Float { - return if (type.axis == HORIZONTAL) (element.parent?.width ?: 0f) / 2f - element.width / 2f - else (element.parent?.height ?: 0f) / 2f - element.height / 2f - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/positions/OldLinked.kt b/src/main/kotlin/com/github/stivais/ui/constraints/positions/OldLinked.kt deleted file mode 100644 index 76e6123f0..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/positions/OldLinked.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.stivais.ui.constraints.positions - -import com.github.stivais.ui.constraints.Constraint.Companion.HORIZONTAL -import com.github.stivais.ui.constraints.Position -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -// todo: delete -class OldLinked(val element: Element, private val previous: OldLinked?) : Position { - override fun get(element: Element, type: Type): Float { - val link = getNextValid(previous)?.element ?: return 0f - return if (type.axis == HORIZONTAL) { - (link.x - (link.parent?.x ?: 0f)) + link.width - } else { - (link.y - (link.parent?.y ?: 0f)) + link.height - } - } - - private fun getNextValid(previous: OldLinked?): OldLinked? { - if (previous != null) { - return if (previous.element.enabled) previous else getNextValid(previous.previous) - } - return null - } -} - -class Linked(private val link: Element) : Position { - override fun get(element: Element, type: Type): Float { - return if (type.axis == HORIZONTAL) { - (link.x - (link.parent?.x ?: 0f)) + link.screenWidth() - } else { - (link.y - (link.parent?.y ?: 0f)) + link.screenHeight() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/sizes/AspectRatio.kt b/src/main/kotlin/com/github/stivais/ui/constraints/sizes/AspectRatio.kt deleted file mode 100644 index 123fbeb0c..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/sizes/AspectRatio.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.stivais.ui.constraints.sizes - -import com.github.stivais.ui.constraints.Constraint.Companion.HORIZONTAL -import com.github.stivais.ui.constraints.Size -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -class AspectRatio(private val ratio: Float) : Size { - override fun get(element: Element, type: Type): Float { - return if (type.axis == HORIZONTAL) element.height * ratio else element.width / ratio - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/sizes/Bounding.kt b/src/main/kotlin/com/github/stivais/ui/constraints/sizes/Bounding.kt deleted file mode 100644 index 73ebb8326..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/sizes/Bounding.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.stivais.ui.constraints.sizes - -import com.github.stivais.ui.constraints.Constraint.Companion.HORIZONTAL -import com.github.stivais.ui.constraints.Size -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.utils.loop - -object Bounding : Size { - - override fun get(element: Element, type: Type): Float { - if (element.elements == null) return 0f - var value = 0f - element.elements!!.loop { child -> - if (!child.enabled) return@loop - // maybe improve later - var ignoreIfCopying = false - val new = if (type.axis == HORIZONTAL) { - if (child.constraints.width is Copying) ignoreIfCopying = true - (child.x - element.x) + child.width - } else { - if (child.constraints.height is Copying) ignoreIfCopying = true - (child.y - element.y) + child.height - } - if (new > value && !ignoreIfCopying) value = new - } - return value - } - - override fun reliesOnChild(): Boolean { - return true - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/sizes/Copying.kt b/src/main/kotlin/com/github/stivais/ui/constraints/sizes/Copying.kt deleted file mode 100644 index fa99f87ca..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/sizes/Copying.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.stivais.ui.constraints.sizes - -import com.github.stivais.ui.constraints.Constraint.Companion.HORIZONTAL -import com.github.stivais.ui.constraints.Size -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -object Copying : Size { - override fun get(element: Element, type: Type): Float { - return if (type.axis == HORIZONTAL) element.parent!!.width else element.parent!!.height - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/constraints/sizes/Indent.kt b/src/main/kotlin/com/github/stivais/ui/constraints/sizes/Indent.kt deleted file mode 100644 index a05c52bf0..000000000 --- a/src/main/kotlin/com/github/stivais/ui/constraints/sizes/Indent.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.stivais.ui.constraints.sizes - -import com.github.stivais.ui.constraints.Constraint.Companion.HORIZONTAL -import com.github.stivais.ui.constraints.Size -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element - -class Indent(val amount: Float): Size { - - override fun get(element: Element, type: Type): Float { - return if (type.axis == HORIZONTAL) { - (element.parent?.width ?: 0f) - (element.x - (element.parent?.x ?: 0f)) - amount - } else { - (element.parent?.height ?: 0f) - (element.y - (element.parent?.y ?: 0f)) - amount - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/Element.kt b/src/main/kotlin/com/github/stivais/ui/elements/Element.kt deleted file mode 100644 index 8d9b57673..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/Element.kt +++ /dev/null @@ -1,282 +0,0 @@ -package com.github.stivais.ui.elements - -import com.github.stivais.ui.UI -import com.github.stivais.ui.UI.Companion.logger -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.constraints.measurements.Undefined -import com.github.stivais.ui.constraints.positions.Center -import com.github.stivais.ui.elements.scope.ElementScope -import com.github.stivais.ui.events.Event -import com.github.stivais.ui.events.Lifetime -import com.github.stivais.ui.events.Mouse -import com.github.stivais.ui.operation.UIOperation -import com.github.stivais.ui.renderer.Renderer -import com.github.stivais.ui.transforms.Transforms -import com.github.stivais.ui.utils.loop - -abstract class Element(constraints: Constraints?, var color: Color? = null) { - - lateinit var ui: UI - - // rework for constraints to be more flexible? - val constraints: Constraints = constraints ?: Constraints(Undefined, Undefined, Undefined, Undefined) - - val renderer: Renderer - get() = ui.renderer - - // element "hierarchy" - - var parent: Element? = null - - var elements: ArrayList? = null - - // - - // events - - var acceptsInput = false - - var events: HashMap Boolean>>? = null - - // - - // Position - - var x: Float = 0f - var y: Float = 0f - - var width: Float = 0f - set(value) { - field = value.coerceAtLeast(0f) - } - - var height: Float = 0f - set(value) { - field = value.coerceAtLeast(0f) - } - - private var transforms: ArrayList? = null - - // this is needed to track current scale - var scale = 1f - - // - - open var enabled: Boolean = true - - var scissors: Boolean = false - - var renders: Boolean = true - get() { - return enabled && field - } - set(value) { - if (!value) hovered = false - field = value - } - - abstract fun draw() - - fun size() { - if (!enabled) return - preSize() - if (!constraints.width.reliesOnChild()) width = constraints.width.get(this, Type.W) - if (!constraints.height.reliesOnChild()) height = constraints.height.get(this, Type.H) - elements?.loop { it.size() } - } - - fun position(newX: Float, newY: Float) { - x = constraints.x.get(this, Type.X) + newX - y = constraints.y.get(this, Type.Y) + newY - } - - open fun positionChildren() { - if (!enabled) return - elements?.loop { - it.position(x, y) - it.positionChildren() - } - // this causes it to redraw every frame, it will be fixed when official repo comes out with code reorganization - val widthRelies = constraints.width.reliesOnChild() - val heightRelies = constraints.height.reliesOnChild() - if (widthRelies) width = constraints.width.get(this, Type.W) - if (heightRelies) height = constraints.height.get(this, Type.H) - if (widthRelies || heightRelies) parent?.redrawInternal = true - } - - var redrawInternal = true - - var redraw: Boolean - get() = redrawInternal - set(value) { - if (value) { - val element = getElementToRedraw() - element.redrawInternal = true - } - } - - var hovered = false - set(value) { - if (value == field) return - if (value) accept(Mouse.Entered) else accept(Mouse.Exited) - field = value - } - - // rename - private fun getElementToRedraw(): Element { - val p = parent ?: return this - return if (p.constraints.width.reliesOnChild() || p.constraints.height.reliesOnChild()) p.getElementToRedraw() else p - } - - fun clip() { - elements?.loop { - it.renders = it.intersects(x, y, width, height) && !(it.width == 0f && it.height == 0f) - if (it.renders) { - it.clip() - } - } - } - - open fun preSize() {} - - // IDK is it worth - fun preRender() { - if (redrawInternal) { - redrawInternal = false - size() - positionChildren() - clip() - } - preDraw() - elements?.loop { - it.preRender() - } - } - - open fun preDraw() { - - } - - fun render() { - if (!renders) return - renderer.push() - transforms?.loop { - it.apply(this, renderer) - } - draw() - if (scissors) renderer.pushScissor(x, y, width, height) - elements?.loop { element -> - element.render() - } - if (scissors) renderer.popScissor() - renderer.pop() - } - - open fun accept(event: Event): Boolean { - if (events != null) { - events!![event]?.let { actions -> actions.loop { if (it(event)) return true } } - if (event is Lifetime) events!!.remove(event) - } - return false - } - - @Suppress("UNCHECKED_CAST") - fun registerEvent(event: E, block: E.() -> Boolean) { - if (event !is Lifetime) acceptsInput = true - if (events == null) events = HashMap() - events!!.getOrPut(event) { arrayListOf() }.add(block as (Event) -> Boolean) - } - - infix fun E.register(block: (E) -> Boolean) = registerEvent(this, block) - - fun addOperation(operation: UIOperation) { - if (ui.operations == null) ui.operations = arrayListOf() - ui.operations!!.add(operation) - } - - fun addTransform(transform: Transforms) { - if (transforms == null) transforms = arrayListOf() - transforms!!.add(transform) - } - - fun addElement(element: Element) { - onElementAdded(element) - if (elements == null) elements = arrayListOf() - elements!!.add(element) - element.parent = this - if (::ui.isInitialized) { - element.initialize(ui) - } - } - - fun removeElement(element: Element?) { - if (element == null) return logger.warning("Tried removing element, but it doesn't exist") - if (elements.isNullOrEmpty()) return logger.warning("Tried calling \"removeElement\" while there is no elements") - ui.eventManager.remove(element) - ui.eventManager.dispatchToAll(Lifetime.Uninitialized, element) - elements!!.remove(element) - element.parent = null - } - - fun removeAll() { - if (elements == null) return - elements?.removeIf { element -> - ui.eventManager.remove(element) - element.accept(Lifetime.Uninitialized) - element.parent = null - true - } - elements = null - if (::ui.isInitialized) redraw = true - } - - fun initialize(ui: UI) { - this.ui = ui - elements?.loop { it.initialize(ui) } - accept(Lifetime.Initialized) - } - - open fun createScope(): ElementScope<*> { - return ElementScope(this) - } - - // sets up position if element being added has an undefined position - open fun onElementAdded(element: Element) { - val c = element.constraints - if (c.x is Undefined) c.x = Center - if (c.y is Undefined) c.y = Center - } - - fun isInside(x: Float, y: Float): Boolean { - val tx = this.x - val ty = this.y - return x in tx..tx + (width) * scale && y in ty..ty + (height) * scale - } - - fun intersects(other: Element): Boolean { - return intersects(other.x, other.y, other.width, other.height) - } - - private fun intersects(x: Float, y: Float, width: Float, height: Float): Boolean { - val tx = this.x - val ty = this.y - val tw = this.width - val th = this.height - return (x < tx + tw && tx < x + width) && (y < ty + th && ty < y + height) - } - - fun screenWidth(): Float { - return width * scale - } - - fun screenHeight(): Float { - return height * scale - } - - // i dont like name - fun getMousePosPercent(): Pair { - return ((ui.mx - x) / width).coerceIn(0f, 1f) to ((ui.my - y) / height).coerceIn(0f, 1f) - } -} diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/Block.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/Block.kt deleted file mode 100644 index 91daa6b1c..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/Block.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.alpha -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.constraints.Measurement -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.renderer.Gradient as GradientType - - -open class Block( - constraints: Constraints?, - color: Color, - var outlineColor: Color? = null, - var outlineThickness: Measurement? = null, - protected val radius: FloatArray? = null -) : Element(constraints, color) { - - init { - if (radius != null) { - require(radius.size == 4) { "Block radius size must be 4" } - } - } - - override fun draw() { - if (radius == null) { - if (color!!.alpha != 0) { - renderer.rect(x, y, width, height, color!!.get(this)) - } - if (outlineColor != null && outlineColor!!.alpha != 0) { - val thickness = outlineThickness!!.get(this, Type.W) - renderer.hollowRect(x, y, width, height, thickness, outlineColor!!.get(this), 0f) - } - } else { - if (color!!.alpha != 0) { - renderer.rect(x, y, width, height, color!!.rgba, radius[0], radius[1], radius[2], radius[3]) - } - if (outlineColor != null && outlineColor!!.alpha != 0) { - val thickness = outlineThickness!!.get(this, Type.W) - renderer.hollowRect(x, y, width, height, thickness, outlineColor!!.rgba, radius[0], radius[1], radius[2], radius[3]) - } - } - } - - class Gradient( - constraints: Constraints?, - color1: Color, - private val color2: Color, - radius: FloatArray?, - private val gradient: GradientType - ) : Block(constraints, color1, null, null, radius) { - override fun draw() { - if (radius == null) { - renderer.gradientRect(x, y, width, height, color!!.get(this), color2.get(this), gradient) - if (outlineColor != null && outlineColor!!.alpha != 0) { - val thickness = outlineThickness!!.get(this, Type.W) - renderer.hollowRect(x, y, width, height, thickness, outlineColor!!.get(this), 0f) - } - } else { - renderer.gradientRect(x, y, width, height, color!!.rgba, color2.rgba, gradient, radius[0], radius[1], radius[2], radius[3]) - if (outlineColor != null && outlineColor!!.alpha != 0) { - val thickness = outlineThickness!!.get(this, Type.W) - renderer.hollowRect(x, y, width, height, thickness, outlineColor!!.rgba, radius[0], radius[1], radius[2], radius[3]) - } - } - } - } -} diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/Canvas.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/Canvas.kt deleted file mode 100644 index 8eb4b5f26..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/Canvas.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.renderer.Renderer - -abstract class Canvas(constraints: Constraints? = null) : Element(constraints) { - init { - scissors = true - } -} - -inline fun canvas( - constraints: Constraints? = null, - crossinline render: (Renderer) -> Unit -): Canvas { - return object : Canvas(constraints) { - override fun draw() { - renderer.push() - renderer.translate(x, y) - render(renderer) - renderer.pop() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/Column.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/Column.kt deleted file mode 100644 index e373320ed..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/Column.kt +++ /dev/null @@ -1,83 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Undefined -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.constraints.sizes.Copying -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.elements.scope.ElementScope -import com.github.stivais.ui.elements.scope.ScopeDSL -import com.github.stivais.ui.events.Mouse -import com.github.stivais.ui.utils.loop -import com.github.stivais.ui.utils.replaceUndefined - -class Column( - constraints: Constraints, - private val paddingX: Size?, - private val paddingY: Size?, -) : Element(constraints.replaceUndefined(w = Bounding, h = Bounding)) { - - private val positionedElements = hashSetOf() - - init { - this.constraints.apply { - width += paddingX - height += paddingY - } - Mouse.Scrolled(0f).register { (amount) -> - start += amount / 12 - true - } - } - - var start = 0f - - override fun onElementAdded(element: Element) { - val constraints = element.constraints - if (constraints.y is Undefined) { - positionedElements.add(element) - } - } - - override fun positionChildren() { - if (!enabled) return - - val px = paddingX?.get(this, Type.W) ?: 0f - val py = paddingY?.get(this, Type.H) ?: 0f - - var increment = start - elements?.loop { - if (positionedElements.contains(it)) { - it.position(x + px, y + py + increment) - increment += (it.height * it.scale) + py - } else { - it.position(x + px, y + py) - } - it.positionChildren() - } - - val widthRelies = constraints.width.reliesOnChild() - val heightRelies = constraints.height.reliesOnChild() - if (widthRelies) width = constraints.width.get(this, Type.W) - if (heightRelies) height = constraints.height.get(this, Type.H) - if (widthRelies || heightRelies) parent?.redrawInternal = true - } - - override fun draw() { - renderer.hollowRect(x, y, width, height, 1f, Color.WHITE.rgba) - } -} - -class ColumnScope(column: Column) : ElementScope(column) { - @ScopeDSL - fun section( - size: Size, - block: ElementScope.() -> Unit - ) = group(size(Copying, size), block) - - @ScopeDSL - fun divider( - size: Size, - ) = group(size(Copying, size)) -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/Grid.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/Grid.kt deleted file mode 100644 index 31e48872f..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/Grid.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.constraints.measurements.Undefined -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.utils.loop - -class Grid( - constraints: Constraints? -) : Element(constraints) { - - private val positionedElements = hashSetOf() - - override fun onElementAdded(element: Element) { - val constraints = element.constraints - if (constraints.x is Undefined && constraints.y is Undefined) { - positionedElements.add(element) - } - } - - override fun positionChildren() { - if (!enabled) return - - var currX = 0f - var currY = 0f - elements?.loop { - if (positionedElements.contains(it)) { - if (currX + it.width > width) { - currX = 0f - currY += it.height - } - it.position(x + currX, y + currY) - currX += it.width - } else { - it.position(x, y) - } - it.positionChildren() - } - - val widthRelies = constraints.width.reliesOnChild() - val heightRelies = constraints.height.reliesOnChild() - if (widthRelies) width = constraints.width.get(this, Type.W) - if (heightRelies) height = constraints.height.get(this, Type.H) - if (widthRelies || heightRelies) parent?.redrawInternal = true - } - - override fun draw() { - renderer.hollowRect(x, y, width, height, 1f, Color.WHITE.rgba) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/Group.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/Group.kt deleted file mode 100644 index eb4a924ac..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/Group.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.utils.replaceUndefined - - -class Group(constraints: Constraints?) : Element(constraints.replaceUndefined(w = Bounding, h = Bounding)) { - override fun draw() { - // doesn't draw - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/ImageElement.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/ImageElement.kt deleted file mode 100644 index 1d2cf910f..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/ImageElement.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.events.Lifetime -import com.github.stivais.ui.renderer.Image - -class ImageElement( - var image: Image, - constraints: Constraints? = null, - private val radii: FloatArray, -) : Element(constraints) { - - init { - registerEvent(Lifetime.Initialized) { - renderer.createImage(image) - false - } - registerEvent(Lifetime.Uninitialized) { - renderer.deleteImage(image) - false - } - } - - override fun draw() { - renderer.image(image, x, y, width, height, radii[0], radii[1], radii[2], radii[3]) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/Layout.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/Layout.kt deleted file mode 100644 index a91e53962..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/Layout.kt +++ /dev/null @@ -1,102 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.color.alpha -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Percent -import com.github.stivais.ui.constraints.measurements.Pixel -import com.github.stivais.ui.constraints.measurements.Undefined -import com.github.stivais.ui.constraints.positions.Center -import com.github.stivais.ui.constraints.positions.OldLinked -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.utils.replaceUndefined -import org.jetbrains.annotations.MustBeInvokedByOverriders - -// todo: delete -open class Layout( - constraints: Constraints?, - var padding: Size?, -) : Element(constraints?.replaceUndefined(w = Bounding, h = Bounding)) { - - protected var lastLink: OldLinked? = null - - class Row(constraints: Constraints?, padding: Size?) : Layout(constraints, padding) { - - override fun onElementAdded(element: Element) { - val c = element.constraints - if (c.x is Undefined) { - val link = OldLinked(element, lastLink) - c.x = link - lastLink = link - - if (padding != null && element !is Divider) { - val padding = padding as? Percent - if (padding != null) createDivider(amount = padding) - } - } - if (c.y is Undefined) { - c.y = if (constraints.height !is Bounding) Center else Pixel(0f) - } - super.onElementAdded(element) - } - } - - class Column(constraints: Constraints?, padding: Size?) : Layout(constraints, padding) { - - override fun onElementAdded(element: Element) { - val c = element.constraints - if (c.x is Undefined) { - c.x = if (constraints.width !is Bounding) Center else Pixel(0f) - } - if (c.y is Undefined) { - val link = OldLinked(element, lastLink) - c.y = link - lastLink = link - - if (padding != null && element !is Divider && elements != null) { - val padding = padding as? Percent - if (padding != null) createDivider(amount = padding) - } - } - super.onElementAdded(element) - } - } - - override fun draw() { - if (color != null && color!!.rgba.alpha != 0) { - renderer.rect(x, y, width, height, color!!.get(this)) - } - } - - @MustBeInvokedByOverriders - override fun onElementAdded(element: Element) { - val c = element.constraints - if (constraints.width.reliesOnChild() && c.width is Percent) { - c.width = percentFix(c.width as Percent) - } - if (constraints.height.reliesOnChild() && c.height is Percent) { - c.height = percentFix(c.height as Percent) - } - } - - protected fun percentFix(size: Percent, target: Element = parent!!): Size { - val c = target.constraints - if (c.width.reliesOnChild() || c.height.reliesOnChild()) { - return percentFix(size, target.parent!!) - } - val percent = size.percent - return object : Size { - override fun get(element: Element, type: Type): Float { - return (if (type.axis == Constraint.HORIZONTAL) target.width else target.height) * percent - } - } - } - - fun createDivider(amount: Size) = addElement(Divider(amount)) - - internal inner class Divider(amount: Size) : Element( - if (this is Row) size(w = amount) else size(h = amount) - ) { - override fun draw() { /**/ } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/Popup.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/Popup.kt deleted file mode 100644 index a359bf454..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/Popup.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.constraints.size -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.elements.scope.ElementScope -import com.github.stivais.ui.transforms.Transforms.Alpha -import com.github.stivais.ui.transforms.Transforms.Scale -import com.github.stivais.ui.utils.seconds - -class Popup( - element: Group, - private val alphaAnimation: Alpha.Animated, - private val scaleAnimation: Scale.Animated, - private val smooth: Boolean -) : ElementScope(element) { - fun closePopup(smooth: Boolean = this.smooth) { - var finished = false - - if (smooth) { - alphaAnimation.animate(0.25.seconds, Animations.EaseInQuint) - scaleAnimation.animate(0.25.seconds, Animations.EaseInQuint)?.onFinish { - finished = true - } - } else { - finished = true - } - operation { - if (finished) ui.main.removeElement(element) - finished - } - } -} - -fun ElementDSL.popup( - constraints: Constraints? = size(Bounding, Bounding), - smooth: Boolean = false, - block: Popup.() -> Unit, -): Popup { - - val alphaAnimation = Alpha.Animated(from = 0f, to = 1f) - val scaleAnimation = Scale.Animated(from = 0f, to = 1f, centered = true) - - val group = Group(constraints).apply { - addTransform(alphaAnimation) - addTransform(scaleAnimation) - } - ui.main.addElement(group) - redraw() - - if (smooth) { - alphaAnimation.animate(0.25.seconds, Animations.EaseOutQuint) - scaleAnimation.animate(0.25.seconds, Animations.EaseOutQuint) - } else { - alphaAnimation.swap() - scaleAnimation.swap() - } - return Popup(group, alphaAnimation, scaleAnimation, smooth).also(block) -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/Row.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/Row.kt deleted file mode 100644 index 7ff205391..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/Row.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.constraints.Size -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.constraints.measurements.Undefined -import com.github.stivais.ui.constraints.plus -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.utils.loop -import com.github.stivais.ui.utils.replaceUndefined - -class Row( - constraints: Constraints?, - private val paddingX: Size?, - private val paddingY: Size?, -) : Element(constraints?.replaceUndefined(w = Bounding, h = Bounding)) { - - private val positionedElements = hashSetOf() - - init { - this.constraints.apply { - width += paddingX - height += paddingY - } - } - - override fun onElementAdded(element: Element) { - val constraints = element.constraints - if (constraints.x is Undefined) { - positionedElements.add(element) - } - } - - override fun positionChildren() { - if (!enabled) return - - val px = paddingX?.get(this, Type.W) ?: 0f - val py = paddingY?.get(this, Type.H) ?: 0f - - var increment = 0f - elements?.loop { - if (positionedElements.contains(it)) { - it.position(x + px + increment, y + py) - increment += (it.width * it.scale) + py - } else { - it.position(x + px, y + py) - } - it.positionChildren() - } - - val widthRelies = constraints.width.reliesOnChild() - val heightRelies = constraints.height.reliesOnChild() - if (widthRelies) width = constraints.width.get(this, Type.W) - if (heightRelies) height = constraints.height.get(this, Type.H) - if (widthRelies || heightRelies) parent?.redrawInternal = true - } - - override fun draw() { - renderer.hollowRect(x, y, width, height, 1f, Color.WHITE.rgba) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/Scrollable.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/Scrollable.kt deleted file mode 100644 index b55712320..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/Scrollable.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.constraints.Type -import com.github.stivais.ui.constraints.measurements.Animatable -import com.github.stivais.ui.constraints.size -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.elements.scope.ElementScope -import com.github.stivais.ui.utils.loop -import com.github.stivais.ui.utils.replaceUndefined -import com.github.stivais.ui.utils.seconds - -// at the moment only scrolling with bounding is supported -class Scrollable( - constraints: Constraints = size(Bounding, Bounding), -) : Element(constraints.replaceUndefined(w = Bounding, h = Bounding)) { - - init { - scissors = true - } - - private var offset = 0f - set(value) { - if (field == value) return - redraw = true - field = value - } - - private var animation: Animatable.Raw = Animatable.Raw(0f) - - override fun draw() { - offset = animation.get(this, Type.X) -// renderer.hollowRect(x, y, width, height, 1f, Color.WHITE.rgba) - } - - override fun positionChildren() { - if (!enabled) return - elements?.loop { - it.position(x, y + offset) - it.positionChildren() - } - val widthRelies = constraints.width.reliesOnChild() - val heightRelies = constraints.height.reliesOnChild() - if (widthRelies) width = constraints.width.get(this, Type.W) - if (heightRelies) height = constraints.height.get(this, Type.H) - if (widthRelies || heightRelies) parent?.redrawInternal = true - } - - fun scroll(amount: Float) { - animation.animate( - to = (offset + amount).coerceIn(-(height - offset), 0f), - 0.1.seconds, - Animations.EaseOutQuad - ) - } -} - -class ScrollableScope(element: Scrollable) : ElementScope(element) { - fun scroll(amount: Float) { - element.scroll(amount) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/impl/TextElement.kt b/src/main/kotlin/com/github/stivais/ui/elements/impl/TextElement.kt deleted file mode 100644 index efe3eac7e..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/impl/TextElement.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.github.stivais.ui.elements.impl - -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Pixel -import com.github.stivais.ui.constraints.measurements.Undefined -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.elements.scope.ElementScope -import com.github.stivais.ui.renderer.Font - -open class TextElement( - string: String, - val font: Font, - color: Color, - constraints: Positions = at(Undefined, Undefined), - size: Size, -) : Element(constraints, color) { - - private val textWidth = 0.px - - init { - constraints.width = textWidth - constraints.height = size - } - - open var text: String = string - set(value) { - if (field == value) return - field = value - redraw = true - previousHeight = 0f - } - - // uses to check if width should be recalculated as it is expensive to do so - protected var previousHeight = 0f - - override fun preSize() { - height = constraints.height.get(this, Type.H) - if (previousHeight != height) { - previousHeight = height - val newWidth = getTextWidth() - (constraints.width as Pixel).pixels = newWidth - } - } - - open fun getTextWidth(): Float { - return renderer.textWidth(text, height, font) - } - - override fun draw() { - renderer.text(text, x, y, height, color!!.get(this), font) - } - - class Supplied( - val supplier: () -> Any?, - font: Font, - color: Color, - constraints: Positions = at(Undefined, Undefined), - size: Size - ) : TextElement(supplier().toString(), font, color, constraints, size) { - - override fun draw() { - text = supplier().toString() - super.draw() - } - } -} - -class TextScope(text: TextElement) : ElementScope(text) { - - var string: String - get() = element.text - set(value) { - element.text = value - } - - var size: Size - get() = element.constraints.height - set(value) { - element.constraints.height = value - } -} diff --git a/src/main/kotlin/com/github/stivais/ui/elements/scope/ElementScope.kt b/src/main/kotlin/com/github/stivais/ui/elements/scope/ElementScope.kt deleted file mode 100644 index 93581738d..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/scope/ElementScope.kt +++ /dev/null @@ -1,316 +0,0 @@ -package com.github.stivais.ui.elements.scope - -import com.github.stivais.ui.UI -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Undefined -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.constraints.sizes.Copying -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.elements.impl.* -import com.github.stivais.ui.events.* -import com.github.stivais.ui.operation.UIOperation -import com.github.stivais.ui.renderer.Font -import com.github.stivais.ui.renderer.Gradient -import com.github.stivais.ui.renderer.Image -import com.github.stivais.ui.transforms.Transforms -import com.github.stivais.ui.utils.radius - -open class ElementScope(val element: E) { - - val ui: UI - get() = element.ui - - val parent: Element? - get() = element.parent - - val x: Position - get() = element.constraints.x - - val y: Position - get() = element.constraints.y - - val width: Size - get() = element.constraints.width - - val height: Size - get() = element.constraints.height - - var color: Color? - get() = element.color - set(value) { - element.color = value - } - - var enabled: Boolean - get() = element.enabled - set(value) { - element.enabled = value - } - - fun parent(): ElementScope<*>? = parent?.createScope() - - fun child(index: Int): ElementScope<*>? = element.elements?.get(index)?.createScope() - - fun sibling(distance: Int = 1): ElementScope<*>? { - if (element.parent != null) { - val currIndex = element.parent!!.elements!!.indexOf(element) - val sibling = element.parent!!.elements!!.getOrNull(currIndex + distance) ?: return null - return sibling.createScope() - } - return null - } - - @ScopeDSL - fun group( - constraints: Constraints? = null, - block: ElementScope.() -> Unit = {} - ) = create(ElementScope(Group(constraints)), block) - - @ScopeDSL - fun column( - constraints: Constraints? = null, - padding: Size? = null, - block: LayoutScope.() -> Unit = {} - ) = create(LayoutScope(Layout.Column(constraints, padding)), block) - - @ScopeDSL - fun row( - constraints: Constraints? = null, - padding: Size? = null, - block: LayoutScope.() -> Unit = {} - ) = create(LayoutScope(Layout.Row(constraints, padding)), block) - - @ScopeDSL - fun block( - constraints: Constraints? = null, - color: Color, - outlineColor: Color? = null, - outlineThickness: Measurement? = null, - radius: FloatArray? = null, - block: BlockScope.() -> Unit = {} - ) = create(BlockScope(Block(constraints, color, outlineColor, outlineThickness, radius)), block) - - @ScopeDSL - fun block( - constraints: Constraints? = null, - colors: Pair, - radius: FloatArray? = null, - gradient: Gradient, - block: BlockScope.() -> Unit = {} - ) = create(BlockScope(Block.Gradient(constraints, colors.first, colors.second, radius, gradient)), block) - - @ScopeDSL - fun text( - text: String, - font: Font = UI.defaultFont, - pos: Positions = at(Undefined, Undefined), - size: Size = 50.percent, - color: Color = Color.WHITE, - block: TextScope.() -> Unit = {} - ) = create(TextScope(TextElement(text, font, color, pos, size)), block) - - @ScopeDSL - fun text( - text: () -> Any?, - font: Font = UI.defaultFont, - color: Color = Color.WHITE, - pos: Positions = at(Undefined, Undefined), - size: Size = 50.percent, - block: TextScope.() -> Unit = {} - ) = create(TextScope(TextElement.Supplied(text, font, color, pos, size)), block) - - @ScopeDSL - fun image( - image: Image, - constraints: Constraints? = null, - radius: FloatArray = 0.radius(), - dsl: ElementScope.() -> Unit = {} - ) = create(ElementScope(ImageElement(image, constraints, radius)), dsl) - - @ScopeDSL - fun image( - image: String, - constraints: Constraints? = null, - radius: FloatArray = 0.radius(), - dsl: ElementScope.() -> Unit = {} - ) = create(ElementScope(ImageElement(Image(image), constraints, radius)), dsl) - - @ScopeDSL - fun scrollable( - constraints: Constraints = size(Bounding, Bounding), - dsl: ScrollableScope.() -> Unit - ) = create(ScrollableScope(Scrollable(constraints)), dsl) - - fun onCreation(block: () -> Unit) { - element.registerEvent(Lifetime.Initialized) { - block() - false - } - } - - fun afterCreation(block: () -> Unit) { - element.registerEvent(Lifetime.AfterInitialized) { - block() - false - } - } - - fun onRemove(block: () -> Unit) { - element.registerEvent(Lifetime.Uninitialized) { - block() - false - } - } - - fun onClick(button: Int = 0, block: (Mouse.Clicked) -> Boolean) { - element.registerEvent(Mouse.Clicked(button), block) - } - - fun onClick(vararg buttons: Int, block: (Mouse.Clicked) -> Boolean) { - for (i in buttons) { - element.registerEvent(Mouse.Clicked(i), block) - } - } - - fun onFocusedClick(button: Int = 0, block: (Focused.Clicked) -> Boolean) { - element.registerEvent(Focused.Clicked(button), block) - } - - fun onRelease(button: Int = 0, block: (Mouse.Released) -> Unit) { - element.registerEvent(Mouse.Released(button)) { - block(this) - false - } - } - - fun onScroll(block: (Mouse.Scrolled) -> Boolean) { - element.registerEvent(Mouse.Scrolled(0f), block) - } - - fun onKeyPressed(block: (Key.CodePressed) -> Boolean) { - element.registerEvent(Key.CodePressed(-1, true), block) - } - - fun onKeyRelease(block: (Key.CodePressed) -> Boolean) { - element.registerEvent(Key.CodePressed(-1, false), block) - } - - fun onMouseEnter(block: (Event) -> Unit) { - element.registerEvent(Mouse.Entered) { - block(this) - false - } - } - - fun onMouseExit(block: (Event) -> Unit) { - element.registerEvent(Mouse.Exited) { - block(this) - false - } - } - - fun onMouseEnterExit(block: (Event) -> Unit) { - val func: Event.() -> Boolean = { block(this); false } - element.registerEvent(Mouse.Entered, func) - element.registerEvent(Mouse.Exited, func) - } - - fun onMouseMove(block: (Mouse.Moved) -> Boolean) { - element.registerEvent(Mouse.Moved, block) - } - - fun onFocusGain(block: (Event) -> Unit) { - element.registerEvent(Focused.Gained) { - block(this) - false - } - } - - fun onFocusLost(block: (Event) -> Unit) { - element.registerEvent(Focused.Lost) { - block(this) - false - } - } - - fun redraw() { - element.redraw = true - } - - fun scissors() { - element.scissors = true - } - - fun focusThis() { - ui.eventManager.focus(element) - } - - fun > create(scope: S, dsl: S.() -> Unit = {}) : S { - this.element.addElement(scope.element) - scope.dsl() - return scope - } - - fun E.add(): E { - this@ElementScope.element.addElement(this) - return this - } - - fun addElement(element: Element) { - this@ElementScope.element.addElement(element) - } - - fun operation(operation: UIOperation) { - element.addOperation(operation) - } - - fun UIOperation.add() { - element.addOperation(this) - } - - fun transform(transform: Transforms) { - element.addTransform(transform) - } - - fun Element.scope(block: ElementScope<*>.() -> Unit) { - add() - block(createScope()) - } -} - -open class BlockScope(block: Block) : ElementScope(block) { - - val outlineColor: Color? - get() = element.outlineColor - - val outline: Measurement? - get() = element.outlineThickness - - @ScopeDSL - fun outline(color: Color, thickness: Measurement = 1.px) { - element.outlineColor = color - element.outlineThickness = thickness - } -} - -open class LayoutScope(layout: Layout) : ElementScope(layout) { - @ScopeDSL - fun background(color: Color) { - element.color = color - } - - // temporary - @ScopeDSL - fun divider(amount: Size) { - element.createDivider(amount) - } - - @ScopeDSL - fun section(size: Size, block: ElementScope.() -> Unit) = group(size(Copying, size), block) -} - -@DslMarker -annotation class ScopeDSL - -typealias ElementDSL = ElementScope<*> diff --git a/src/main/kotlin/com/github/stivais/ui/elements/scope/extensions.kt b/src/main/kotlin/com/github/stivais/ui/elements/scope/extensions.kt deleted file mode 100644 index f0b631014..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/scope/extensions.kt +++ /dev/null @@ -1,81 +0,0 @@ -package com.github.stivais.ui.elements.scope - -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.color -import com.github.stivais.ui.color.darker -import com.github.stivais.ui.constraints.measurements.Pixel -import com.github.stivais.ui.constraints.px -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.utils.animate -import com.github.stivais.ui.utils.seconds - -fun BlockScope.hoverEffect( - duration: Number = 0.25.seconds, - handler: ElementScope<*> = this, -) { - val before = color!! - val hover = Color.Animated(from = before, to = color { before.rgba.darker(1.25) }) - color = hover - handler.onMouseEnterExit { hover.animate(duration) } -} - -fun ElementDSL.focuses() { - onClick { - focusThis() - true - } -} - -/** - * Incompatible if the parent element size relies on the children - */ -fun ElementDSL.draggable( - button: Int = 0, - acceptsEvent: Boolean = true, - moves: Element = element, - coerce: Boolean = false -) { - val px: Pixel = 0.px - val py: Pixel = 0.px - // note: if parent is Bounding, it can cause issues - afterCreation { - px.pixels = (moves.x - (moves.parent?.x ?: 0f)) - py.pixels = (moves.y - (moves.parent?.y ?: 0f)) - moves.constraints.x = px - moves.constraints.y = py - } - var pressed = false - var x = 0f - var y = 0f - onClick(button) { - pressed = true - x = ui.mx - (moves.x - (moves.parent?.x ?: 0f)) - y = ui.my - (moves.y - (moves.parent?.y ?: 0f)) - acceptsEvent - } - onMouseMove { - if (pressed) { - if (coerce) { - px.pixels = (ui.mx - x).coerceIn(0f, parent?.width) - py.pixels = (ui.my - y).coerceIn(0f, parent?.height) - } else { - px.pixels = ui.mx - x - py.pixels = ui.my - y - } - redraw() - } - acceptsEvent - } - onRelease(button) { - pressed = false - } -} - -fun ElementDSL.animateColor(to: Color, duration: Float, anim: Animations = Animations.Linear) { - color = if (duration == 0f) to else Color.Animated(from = color ?: Color.TRANSPARENT, to = to).apply { - animate(duration, anim)?.onFinish { - color = to - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/elements/scope/extras.kt b/src/main/kotlin/com/github/stivais/ui/elements/scope/extras.kt deleted file mode 100644 index b40152bbf..000000000 --- a/src/main/kotlin/com/github/stivais/ui/elements/scope/extras.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.stivais.ui.elements.scope - -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.constraints.copies -import me.odinmain.utils.round - -fun ElementDSL.slider( - constraints: Constraints? = copies(), - accepts: Boolean = false, - onChange: (x: Float, y: Float, wasClick: Boolean) -> Unit, -) = group(constraints) { - - var dragging = false - - onClick { - onChange( - ((ui.mx - element.x).coerceIn(0f, element.width) / element.width).round(2).toFloat(), - ((ui.my - element.y).coerceIn(0f, element.height) / element.height).round(2).toFloat(), - true - ) - dragging = true - accepts - } - onMouseMove { - if (dragging) { - onChange( - ((ui.mx - element.x).coerceIn(0f, element.width) / element.width).round(2).toFloat(), - ((ui.my - element.y).coerceIn(0f, element.height) / element.height).round(2).toFloat(), - false - ) - } - accepts - } - onRelease { - dragging = false - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/events/EventManager.kt b/src/main/kotlin/com/github/stivais/ui/events/EventManager.kt deleted file mode 100644 index 1dc870936..000000000 --- a/src/main/kotlin/com/github/stivais/ui/events/EventManager.kt +++ /dev/null @@ -1,177 +0,0 @@ -package com.github.stivais.ui.events - -import com.github.stivais.ui.UI -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.utils.loop -import com.github.stivais.ui.utils.reverseLoop - -class EventManager(private val ui: UI) { - - var recalculate = false - - var mouseX: Float = 0f - set(value) { - field = value * ui.main.scale // maybe make mouse scale depending on current hovered element? - } - - var mouseY: Float = 0f - set(value) { - field = value * ui.main.scale // maybe make mouse scale depending on current hovered element? - } - - /** - * Used to dispatch bubbling events - */ - private var hoveredElement: Element? = null - set(value) { - if (value == field) return - field = value - } - - var focused: Element? = null - private set - - fun remove(element: Element?) { - element?.let { - if (it == focused) unfocus() - if (it == hoveredElement) hoveredElement = null - } - } - - fun check(): Boolean { - return recalculate || hoveredElement?.isInside(mouseX, mouseY) == false - } - - // - // Mouse Input - // - - fun onMouseMove(x: Float, y: Float) { - mouseX = x - mouseY = y - hoveredElement = getHoveredElement(x, y, ui.main) - dispatchToAll(Mouse.Moved, ui.main) - } - - fun onMouseClick(button: Int): Boolean { - if (focused != null) { - if (focused!!.isInside(mouseX, mouseY)) { - if (focused!!.accept(Focused.Clicked(button))) { - return true - } - } else { - unfocus() - } - } - return dispatch(Mouse.Clicked(button)) - } - - fun onMouseRelease(button: Int) { - val event = Mouse.Released(button) - dispatchToAll(event, ui.main) - } - - fun onMouseScroll(amount: Float) { - val event = Mouse.Scrolled(amount) - dispatch(event) - } - - // - // Keyboard Input - // - - fun onKeyType(char: Char): Boolean { - val event = Key.Typed(char) - if (focused != null) { - return focused!!.accept(event) - } - return false - } - - fun onKeycodePressed(code: Int): Boolean { - val event = Key.CodePressed(code, true) - if (focused != null) { - return focused!!.accept(event) - } - return false - } - - fun onKeyReleased(code: Int): Boolean { - val event = Key.CodePressed(code, false) - if (focused != null) { - return focused!!.accept(event) - } - return false - } - - // - // - // - - fun focus(element: Element) { - focused?.accept(Focused.Lost) - focused = element - element.accept(Focused.Gained) - } - - fun unfocus() { - focused?.accept(Focused.Lost) - focused = null - } - - private fun getHoveredElement(x: Float, y: Float, element: Element = ui.main): Element? { - var result: Element? = null - if (element.renders && element.isInside(x, y)) { - element.elements?.reverseLoop { it -> - if (result == null) { - getHoveredElement(x, y, it)?.let { - result = it - return@reverseLoop // prevent discarding hovered - } - } - discard(it) - } - if (element.acceptsInput) { - element.hovered = true - if (result == null) result = element - } - } - return result - } - - // TODO: Rename - private fun discard(element: Element) { - // checks if it isn't hovered but acceptsInput to skip checking its children - if (!element.hovered && element.acceptsInput) return - element.hovered = false - element.elements?.loop { discard(it) } - } - - fun dispatch(event: Event, element: Element? = hoveredElement): Boolean { - var current = element - while (current != null) { - if (current.accept(event)) { - current.redraw = true - return true - } - current = current.parent - } - return false - } - - fun dispatchToAll(event: Event, element: Element) { - if (!element.renders) return - element.accept(event) - element.elements?.loop { - dispatchToAll(event, it) - } - } - - // rename i think - fun dispatchToAllReverse(event: Event, element: Element) { - element.elements?.loop { - dispatchToAll(event, it) - } - element.accept(event) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/events/events.kt b/src/main/kotlin/com/github/stivais/ui/events/events.kt deleted file mode 100644 index 6fbe23b52..000000000 --- a/src/main/kotlin/com/github/stivais/ui/events/events.kt +++ /dev/null @@ -1,119 +0,0 @@ -package com.github.stivais.ui.events - -interface Event - -interface Mouse : Event { - - data class Clicked(val button: Int) : Mouse { - - override fun equals(other: Any?): Boolean { // needs to be overridden, so it is recognized in the events Map - if (this === other) return true - if (other !is Clicked) return false - return button == other.button - } - - override fun hashCode(): Int = 31 * (button + 500) - - override fun toString(): String = "MouseClicked(button=$button)" - } - - data class Released(val button: Int) : Mouse { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is Released) return false - return button == other.button - } - - override fun hashCode(): Int = 31 * (button + 250) - - override fun toString(): String = "MouseReleased(button=$button)" - } - - data class Scrolled(val amount: Float) : Mouse { - override fun equals(other: Any?): Boolean { - if (this === other) return true - return other is Scrolled - } - - override fun hashCode(): Int = 28629151 // 31^5 - } - - data object Entered : Mouse - - data object Exited : Mouse - - data object Moved: Mouse -} - -// todo: implement cleaner way? -// todo: implement key mods (i.e indicator for if ctrl and or shift is down) -interface Key : Event { - - data class Typed(val char: Char = ' ') : Key { - override fun equals(other: Any?): Boolean { - if (this === other) return true - return other is Typed - //if (other !is Typed) return false - //return char == other.char - } - - override fun hashCode(): Int { - return 31 - } - } - - - data class CodePressed(val code: Int = -1, private val down: Boolean = true) : Key { - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is CodePressed) return false - return down == other.down - - } - - override fun hashCode(): Int { - return 29791 + down.hashCode()// 31^3 - } - } - - class CodeReleased(val code: Int?) : Key { - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is CodeReleased) return false - return other.code == null || code == other.code - } - - override fun hashCode(): Int { - return 923521 // 31^4 - } - } -} - -interface Focused : Event { - - data class Clicked(val button: Int = 0 /* this doesn't matter for accepting event */) : Focused { - override fun equals(other: Any?): Boolean { - if (this === other) return true - return other is Clicked - } - - override fun hashCode(): Int { - return 992 // 31^2 + 31 - } - } - - data object Gained : Focused - - data object Lost : Focused -} - -interface Lifetime : Event { - - data object Initialized : Lifetime - - data object AfterInitialized : Lifetime - - data object Uninitialized : Lifetime -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/impl/Testing Command.kt b/src/main/kotlin/com/github/stivais/ui/impl/Testing Command.kt deleted file mode 100644 index 4b40b6593..000000000 --- a/src/main/kotlin/com/github/stivais/ui/impl/Testing Command.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.stivais.ui.impl - -import com.github.stivais.ui.UI -import com.github.stivais.ui.UIScreen.Companion.open -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.constrain -import com.github.stivais.ui.constraints.percent -import com.github.stivais.ui.constraints.positions.Center -import com.github.stivais.ui.constraints.size -import com.github.stivais.ui.constraints.sizes.AspectRatio -import com.github.stivais.ui.elements.impl.Grid -import com.github.stivais.ui.utils.radius -import me.odinmain.commands.commodore -import me.odinmain.features.impl.dungeon.LeapMenu.leapMenu -import me.odinmain.features.impl.floor7.p3.TerminalSolver.customGuiColor -import me.odinmain.features.impl.floor7.p3.TerminalSolver.panesColor -import me.odinmain.utils.skyblock.modMessage - - -val `ui command` = commodore("ui") { - literal("test").runs { - open( - UI { - block(constrain(Center, Center, 45.percent, 25.percent), customGuiColor, radius = 12f.radius()) { - Grid(constraints = constrain(Center, Center, 90.percent, 65.percent)).scope { - repeat(18) { index -> - //if (index !in TerminalSolver.currentTerm.solution) return@repeat - block(size(11.11.percent, AspectRatio(1f)), panesColor) { - onClick { - modMessage("Clicked $index") - true - } - }.outline(Color.BLACK) - } - } - } - - } - ) - } - literal("leap").runs { - open(leapMenu()) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/operation/UIOperation.kt b/src/main/kotlin/com/github/stivais/ui/operation/UIOperation.kt deleted file mode 100644 index cf50c1e3e..000000000 --- a/src/main/kotlin/com/github/stivais/ui/operation/UIOperation.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.stivais.ui.operation - -import com.github.stivais.ui.animation.Animation - -fun interface UIOperation { - fun run(): Boolean -} - -class AnimationOperation(val animation: Animation, val block: (percent: Float) -> Unit) : UIOperation { - - override fun run(): Boolean { - block(animation.get()) - return animation.finished - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/renderer/Font.kt b/src/main/kotlin/com/github/stivais/ui/renderer/Font.kt deleted file mode 100644 index 8ce35ef3d..000000000 --- a/src/main/kotlin/com/github/stivais/ui/renderer/Font.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.stivais.ui.renderer - -import org.apache.commons.io.IOUtils -import java.io.FileNotFoundException -import java.nio.ByteBuffer -import java.nio.ByteOrder - -class Font(val name: String, val resourcePath: String) { - - val buffer: ByteBuffer - - init { - val stream = this::class.java.getResourceAsStream(resourcePath) ?: throw FileNotFoundException(resourcePath) - val bytes = IOUtils.toByteArray(stream) - stream.close() - buffer = ByteBuffer.allocateDirect(bytes.size).order(ByteOrder.nativeOrder()).put(bytes) - buffer.flip() - } - - override fun hashCode(): Int { - return resourcePath.hashCode() - } - - override fun equals(other: Any?): Boolean { - if (other !is Font) return false - return other.resourcePath == resourcePath - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/renderer/Framebuffer.kt b/src/main/kotlin/com/github/stivais/ui/renderer/Framebuffer.kt deleted file mode 100644 index 91dafe3ee..000000000 --- a/src/main/kotlin/com/github/stivais/ui/renderer/Framebuffer.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.stivais.ui.renderer - -data class Framebuffer(val width: Float, val height: Float) \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/renderer/Gradient.kt b/src/main/kotlin/com/github/stivais/ui/renderer/Gradient.kt deleted file mode 100644 index 6ce3490ca..000000000 --- a/src/main/kotlin/com/github/stivais/ui/renderer/Gradient.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.stivais.ui.renderer - -enum class Gradient { - LeftToRight, TopToBottom -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/renderer/Image.kt b/src/main/kotlin/com/github/stivais/ui/renderer/Image.kt deleted file mode 100644 index 82037f7c1..000000000 --- a/src/main/kotlin/com/github/stivais/ui/renderer/Image.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.github.stivais.ui.renderer - -import me.odinmain.utils.setupConnection -import org.apache.commons.io.IOUtils -import java.io.File -import java.io.FileNotFoundException -import java.io.InputStream -import java.nio.ByteBuffer -import java.nio.ByteOrder -import java.nio.file.Files - -class Image( - val resourcePath: String, - val type: Type = getType(resourcePath) -) { - var width = 0f - var height = 0f - - val stream: InputStream - - init { - - val trimmedPath = resourcePath.trim() - -// val cachedBuffer = cache[resourcePath] - stream = if (trimmedPath.startsWith("http")) { - setupConnection(trimmedPath, "Odin", 5000, true) - } else { - val file = File(trimmedPath) - if (file.exists() && file.isFile) { - Files.newInputStream(file.toPath()) - } else { - this::class.java.getResourceAsStream(trimmedPath) ?: throw FileNotFoundException(trimmedPath) - } - } - } - - enum class Type { - RASTER, - VECTOR - } - - override fun hashCode() = resourcePath.hashCode() - - override fun equals(other: Any?): Boolean { - if (other === this) return true - if (other !is Image) return false - return resourcePath == other.resourcePath - } - - fun buffer(): ByteBuffer { - val bytes: ByteArray - stream.use { bytes = IOUtils.toByteArray(it) } - val buffer = ByteBuffer.allocateDirect(bytes.size).order(ByteOrder.nativeOrder()).put(bytes).also { it.flip() } - return buffer - } - - companion object { - fun getType(path: String): Type { - return if (path.substringAfterLast('.') == "svg") Type.VECTOR else Type.RASTER - } - } -} - -fun ByteBuffer.asInputStream(): InputStream { - val byteArray = ByteArray(this.remaining()) - this.get(byteArray) - return byteArray.inputStream() -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/renderer/Renderer.kt b/src/main/kotlin/com/github/stivais/ui/renderer/Renderer.kt deleted file mode 100644 index f4e2029cf..000000000 --- a/src/main/kotlin/com/github/stivais/ui/renderer/Renderer.kt +++ /dev/null @@ -1,81 +0,0 @@ -@file:Suppress("UNUSED") - -package com.github.stivais.ui.renderer - -import com.github.stivais.ui.UI -import com.github.stivais.ui.color.Color - -interface Renderer { - - fun beginFrame(width: Float, height: Float) - - fun endFrame() - - fun supportsFramebuffers(): Boolean = false - - fun createFramebuffer(w: Float, h: Float): Framebuffer = Framebuffer(w, h) - - fun destroyFramebuffer(fbo: Framebuffer) {} - - fun drawFramebuffer(fbo: Framebuffer, x: Float, y: Float) {} - - fun bindFramebuffer(fbo: Framebuffer) {} - - fun unbindFramebuffer() {} - - fun push() - - fun pop() - - fun scale(x: Float, y: Float) - - fun translate(x: Float, y: Float) - - fun rotate(amount: Float) - - fun globalAlpha(amount: Float) - - fun pushScissor(x: Float, y: Float, w: Float, h: Float) - - fun popScissor() - - fun line(x1: Float, y1: Float, x2: Float, y2: Float, thickness: Float, color: Int) - - fun rect(x: Float, y: Float, w: Float, h: Float, color: Int) - - fun rect(x: Float, y: Float, w: Float, h: Float, color: Int, tl: Float, bl: Float, br: Float, tr: Float) - - fun rect(x: Float, y: Float, w: Float, h: Float, color: Int, radius: Float) { - rect(x, y, w, h, color, radius, radius, radius, radius) - } - - fun hollowRect(x: Float, y: Float, w: Float, h: Float, thickness: Float, color: Int, tl: Float, bl: Float, br: Float, tr: Float) - - fun hollowRect(x: Float, y: Float, w: Float, h: Float, thickness: Float, color: Int, radius: Float = 0f) { - hollowRect(x, y, w, h, thickness, color, radius, radius, radius, radius) - } - - fun gradientRect(x: Float, y: Float, w: Float, h: Float, color1: Int, color2: Int, direction: Gradient) - - fun gradientRect(x: Float, y: Float, w: Float, h: Float, color1: Int, color2: Int, gradient: Gradient, tl: Float, bl: Float, br: Float, tr: Float) - - fun text(text: String, x: Float, y: Float, size: Float, color: Int = Color.WHITE.rgba, font: Font = UI.defaultFont) - - fun textWidth(text: String, size: Float, font: Font = UI.defaultFont): Float - - fun image(image: Image, x: Float, y: Float, w: Float, h: Float, tl: Float, bl: Float, br: Float, tr: Float) - - fun image(image: Image, x: Float, y: Float, w: Float, h: Float, radius: Float) { - image(image, x, y, w, h, radius, radius, radius, radius) - } - - // should use rc - fun createImage(image: Image) - fun deleteImage(image: Image) - - fun scissor(x: Float, y: Float, width: Float, height: Float): Scissor - - fun resetScissor(scissor: Scissor) - - fun clearScissors() -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/renderer/Scissor.kt b/src/main/kotlin/com/github/stivais/ui/renderer/Scissor.kt deleted file mode 100644 index 58ca6798b..000000000 --- a/src/main/kotlin/com/github/stivais/ui/renderer/Scissor.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.stivais.ui.renderer - -data class Scissor( - var x: Float, - var y: Float, - var width: Float, - var height: Float -) { - constructor(scissor: Scissor) : this(scissor.x, scissor.y, scissor.width, scissor.height) -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/transforms/Transforms.kt b/src/main/kotlin/com/github/stivais/ui/transforms/Transforms.kt deleted file mode 100644 index 405e04f78..000000000 --- a/src/main/kotlin/com/github/stivais/ui/transforms/Transforms.kt +++ /dev/null @@ -1,134 +0,0 @@ -package com.github.stivais.ui.transforms - -import com.github.stivais.ui.animation.Animating -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.renderer.Renderer -import kotlin.reflect.KProperty - -private fun runScale(element: Element, renderer: Renderer, amount: Float, centered: Boolean) { - var x = element.x - var y = element.y - if (centered) { - x += element.width / 2f - y += element.height / 2f - } - renderer.translate(x, y) - renderer.scale(amount, amount) - renderer.translate(-x, -y) -} - -private fun runRotation(element: Element, renderer: Renderer, amount: Float) { - val x = element.x + element.width / 2f - val y = element.y + element.height / 2f - renderer.translate(x, y) - renderer.rotate(Math.toRadians(amount.toDouble()).toFloat()) - renderer.translate(-x, -y) -} - -fun interface Transforms { - - fun apply(element: Element, renderer: Renderer) - - class Scale(var amount: Float, private val centered: Boolean) : Transforms { - override fun apply(element: Element, renderer: Renderer) { - runScale(element, renderer, amount, centered) - element.scale = amount - } - - operator fun getValue(thisRef: Any?, property: KProperty<*>): Float { - return amount - } - - operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Float) { - amount = value - } - - class Animated private constructor( - private val impl: Animating.Swapping.Impl, - private val centered: Boolean - ) : Transforms, Animating.Swapping by impl { - - constructor( - from: Float, - to: Float, - centered: Boolean = true - ) : this(Animating.Swapping.Impl(from, to), centered) - - override fun apply(element: Element, renderer: Renderer) { - val amount = impl.get() - runScale(element, renderer, amount, centered) - element.scale = amount - } - } - } - - class Alpha(var amount: Float) : Transforms { - override fun apply(element: Element, renderer: Renderer) { - if (amount != 1f) { - renderer.globalAlpha(amount) - } - } - - class Animated private constructor( - private val impl: Animating.Swapping.Impl, - ) : Transforms, Animating.Swapping by impl { - - constructor( - from: Float, - to: Float, - ) : this(Animating.Swapping.Impl(from, to)) - - override fun apply(element: Element, renderer: Renderer) { - val amount = impl.get() - if (amount != 1f) { - renderer.globalAlpha(amount) - } - } - } - } - - class Rotation(var amount: Float) : Transforms { - override fun apply(element: Element, renderer: Renderer) { - runRotation(element, renderer, amount) - } - - class Animated private constructor( - private val impl: Animating.Swapping.Impl, - ) : Transforms, Animating.Swapping by impl { - constructor( - from: Float, - to: Float, - ) : this(Animating.Swapping.Impl(from, to)) - - override fun apply(element: Element, renderer: Renderer) { - val amount = impl.get() - runRotation(element, renderer, amount) - } - } - } -} - -fun ElementDSL.scale(from: Float, to: Float, centered: Boolean = true): Transforms.Scale.Animated { - val transform = Transforms.Scale.Animated(from, to, centered) - transform(transform) - return transform -} - -fun ElementDSL.alpha(from: Float, to: Float): Transforms.Alpha.Animated { - val transform = Transforms.Alpha.Animated(from, to) - transform(transform) - return transform -} - -fun ElementDSL.alpha(amount: Float): Transforms.Alpha { - val transform = Transforms.Alpha(amount) - transform(transform) - return transform -} - -fun ElementDSL.rotation(from: Float, to: Float): Transforms.Rotation.Animated { - val transform = Transforms.Rotation.Animated(from, to) - transform(transform) - return transform -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/utils/dsl.kt b/src/main/kotlin/com/github/stivais/ui/utils/dsl.kt deleted file mode 100644 index 67f3e581c..000000000 --- a/src/main/kotlin/com/github/stivais/ui/utils/dsl.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.stivais.ui.utils - -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.Constraint -import com.github.stivais.ui.constraints.measurements.Animatable - -@JvmName("radiiThis") -fun Number.radius() = radius(this) - -/** - * Takes 4 numbers, and creates a [FloatArray] with those values - * - * It is used for rounded elements - */ -fun radius(tl: Number = 0f, tr: Number = 0f, bl: Number = 0f, br: Number = 0f) = floatArrayOf(tl.toFloat(), bl.toFloat(), br.toFloat(), tr.toFloat()) - -/** - * Takes 1 numbers, and converts it into a [FloatArray] with a size of 4 - * - * It is used for rounded elements - */ -fun radius(all: Number): FloatArray { - val value = all.toFloat() - return floatArrayOf(value, value, value, value) -} - -/** - * Convenient function to check and animate a [Color] if you know it is a [Animating Color][Color.Animated] - * - * If the color isn't [animating][Color.Animated], it will not do anything - * - * @param duration How long the animation lasts (in nanoseconds) - * @param type The type of animation done - */ -fun Color.animate(duration: Number, type: Animations = Animations.Linear) { - if (this is Color.Animated) { - animate(duration.toFloat(), type) - } -} - -/** - * Convenient function to check and animate a [Constraint] if you know it is [animating][Animatable] - * - * If the constraint isn't [animating][Animatable], it will not do anything - * - * @param duration How long the animation lasts (in nanoseconds) - * @param type The type of animation done - */ -fun Constraint.animate(duration: Number, type: Animations = Animations.Linear) { - if (this is Animatable) { - animate(duration.toFloat(), type) - } -} diff --git a/src/main/kotlin/com/github/stivais/ui/utils/utils.kt b/src/main/kotlin/com/github/stivais/ui/utils/utils.kt deleted file mode 100644 index 0d8310e01..000000000 --- a/src/main/kotlin/com/github/stivais/ui/utils/utils.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.stivais.ui.utils - -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Undefined - -fun Constraints?.replaceUndefined( - x: Position = Undefined, - y: Position = Undefined, - w: Size = Undefined, - h: Size = Undefined -): Constraints { - if (this == null) return Constraints(x, y, w, h) - return this.apply { - if (this.x is Undefined) this.x = x - if (this.y is Undefined) this.y = y - if (this.width is Undefined) this.width = w - if (this.height is Undefined) this.height = h - } -} - -// using this with an arraylist is just as fast as an iterator, but is more memory efficient -inline fun ArrayList.loop(block: (E) -> Unit) { - if (this.size == 0) return - for (i in 0.. ArrayList.reverseLoop(block: (E) -> Unit) { - if (this.size == 0) return - for (i in this.size - 1 downTo 0) { - block(this[i]) - } -} - -/** - * Multiplies a number by 1_000_000_000 to match nanoseconds - */ -val Number.seconds - get() = this.toFloat() * 1_000_000_000 - -val Number.s - get() = this.toFloat() * 1_000_000_000 \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/OdinMain.kt b/src/main/kotlin/me/odinmain/OdinMain.kt index 5bc10ad02..f6200dfde 100644 --- a/src/main/kotlin/me/odinmain/OdinMain.kt +++ b/src/main/kotlin/me/odinmain/OdinMain.kt @@ -1,7 +1,5 @@ package me.odinmain -import com.github.stivais.ui.UIScreen -import com.github.stivais.ui.impl.`ui command` import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -33,6 +31,7 @@ import me.odinmain.utils.skyblock.PlayerUtils import me.odinmain.utils.skyblock.SkyblockPlayer import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.dungeon.ScanUtils +import me.odinmain.utils.ui.screens.UIScreen import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiScreen import net.minecraftforge.common.MinecraftForge @@ -73,7 +72,6 @@ object OdinMain { devCommand, highlightCommand, waypointCommand, dungeonWaypointsCommand, petCommand, visualWordsCommand, PosMsgCommand, - `ui command` ) } diff --git a/src/main/kotlin/me/odinmain/commands/impl/OdinCommand.kt b/src/main/kotlin/me/odinmain/commands/impl/OdinCommand.kt index e84faba4e..6def745c4 100644 --- a/src/main/kotlin/me/odinmain/commands/impl/OdinCommand.kt +++ b/src/main/kotlin/me/odinmain/commands/impl/OdinCommand.kt @@ -1,7 +1,6 @@ package me.odinmain.commands.impl import com.github.stivais.commodore.utils.GreedyString -import com.github.stivais.ui.UIScreen.Companion.open import me.odinmain.commands.commodore import me.odinmain.features.huds.HUDManager import me.odinmain.features.impl.dungeon.dungeonwaypoints.DungeonWaypoints @@ -12,6 +11,7 @@ import me.odinmain.utils.equalsOneOf import me.odinmain.utils.fillItemFromSack import me.odinmain.utils.skyblock.* import me.odinmain.utils.skyblock.dungeon.DungeonUtils +import me.odinmain.utils.ui.screens.UIScreen.Companion.open import me.odinmain.utils.writeToClipboard import kotlin.math.round @@ -21,7 +21,7 @@ val mainCommand = commodore("od", "odin") { } literal("edithuds").runs { - HUDManager.makeHUDEditor().open() + open(HUDManager.makeHUDEditor()) } literal("ep").runs { @@ -42,7 +42,11 @@ val mainCommand = commodore("od", "odin") { literal("reset") { literal("clickgui").runs { - ClickGUI.getSettingByName("Panel Data")?.reset() + ClickGUI.panelSettings.forEach { (_, value) -> + value.x = value.defaultX + value.y = value.defaultY + value.extended = true // default is always true + } modMessage("Reset ClickGUI panel positions") } literal("hud").runs { diff --git a/src/main/kotlin/me/odinmain/config/DungeonWaypointConfig.kt b/src/main/kotlin/me/odinmain/config/DungeonWaypointConfig.kt index b7f4c94b7..3f47b4837 100644 --- a/src/main/kotlin/me/odinmain/config/DungeonWaypointConfig.kt +++ b/src/main/kotlin/me/odinmain/config/DungeonWaypointConfig.kt @@ -1,7 +1,8 @@ package me.odinmain.config -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.ColorSerializer +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.hexToRGBA +import com.github.stivais.aurora.utils.toHexString import com.google.gson.* import com.google.gson.reflect.TypeToken import kotlinx.coroutines.DelicateCoroutinesApi @@ -133,4 +134,15 @@ object DungeonWaypointConfig { } } + + class ColorSerializer : JsonSerializer, JsonDeserializer { + override fun serialize(p0: Color?, p1: Type?, p2: JsonSerializationContext?): JsonElement { + return JsonPrimitive(p0?.toHexString() ?: "#000000FF") + } + + override fun deserialize(p0: JsonElement?, p1: Type?, p2: JsonDeserializationContext?): Color { + val hexValue = p0?.asString?.replace("#", "") ?: "000000FF" + return Color.RGB(hexToRGBA(hexValue)) + } + } } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/features/Module.kt b/src/main/kotlin/me/odinmain/features/Module.kt index 6c9aed537..4b8dd56cd 100644 --- a/src/main/kotlin/me/odinmain/features/Module.kt +++ b/src/main/kotlin/me/odinmain/features/Module.kt @@ -1,8 +1,8 @@ package me.odinmain.features +import com.github.stivais.aurora.elements.ElementScope import me.odinmain.OdinMain import me.odinmain.features.huds.HUD -import me.odinmain.features.huds.HUDScope import me.odinmain.features.impl.render.ClickGUI import me.odinmain.features.settings.AlwaysActive import me.odinmain.features.settings.Setting @@ -143,7 +143,6 @@ abstract class Module( * * @author Bonsai */ - // todo: use new event stuff fun onMessage(filter: Regex, shouldRun: () -> Boolean = { alwaysActive || enabled }, func: (String) -> Unit) { ModuleManager.messageFunctions.add(ModuleManager.MessageFunction(filter, shouldRun, func)) } @@ -166,7 +165,7 @@ abstract class Module( fun HUD( name: String, - block: HUDScope.() -> Unit + block: ElementScope<*>.() -> Unit ): HUD { return HUD( name, diff --git a/src/main/kotlin/me/odinmain/features/huds/HUD.kt b/src/main/kotlin/me/odinmain/features/huds/HUD.kt index b126323ae..e02f6780b 100644 --- a/src/main/kotlin/me/odinmain/features/huds/HUD.kt +++ b/src/main/kotlin/me/odinmain/features/huds/HUD.kt @@ -1,11 +1,12 @@ package me.odinmain.features.huds -import com.github.stivais.ui.constraints.Constraints -import com.github.stivais.ui.constraints.percent -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.elements.scope.ElementScope -import com.github.stivais.ui.transforms.Transforms +import com.github.stivais.aurora.constraints.Constraints +import com.github.stivais.aurora.constraints.impl.measurements.Undefined +import com.github.stivais.aurora.constraints.impl.size.Bounding +import com.github.stivais.aurora.dsl.percent +import com.github.stivais.aurora.elements.BlankElement +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.transforms.impl.Scale import me.odinmain.features.Module import me.odinmain.features.settings.Setting import me.odinmain.features.settings.impl.NumberSetting @@ -15,7 +16,7 @@ import kotlin.reflect.jvm.isAccessible class HUD( val name: String, val module: Module, - val builder: HUDScope.() -> Unit + val builder: ElementScope.() -> Unit ) { val x = NumberSetting("x", 2.5f, 0f, 100f).hide() val y = NumberSetting("y", 2.5f, 0f, 100f).hide() @@ -56,28 +57,22 @@ class HUD( inner class Representation( val preview: Boolean - ) : Element(Constraints(x.value.percent, y.value.percent, Bounding, Bounding)) { + ) : BlankElement(Constraints(x.value.percent, y.value.percent, Bounding, Bounding)) { override var enabled: Boolean = true get() = field && this@HUD.module.enabled - var scaleTransformation by Transforms.Scale(this@HUD.scale.value, centered = false).also { + var scaleTransformation by Scale(this@HUD.scale.value, centered = false).also { addTransform(it) } - override fun draw() { - // no-op - } - override fun onElementAdded(element: Element) { - // no-op - // elements here shouldn't be centered by default - } + override fun getDefaultPositions() = Pair(Undefined, Undefined) - fun refresh(scope: HUDScope) { - removeAll() + fun refresh(scope: ElementScope) { +// removeAll() builder.invoke(scope) scaleTransformation = this@HUD.scale.value - redrawInternal = true + redraw = true } } @@ -90,22 +85,21 @@ class HUD( } return null } -} - -class HUDScope(element: HUD.Representation) : ElementScope(element) { - inline val preview get() = element.preview + companion object { + inline val ElementScope.preview get() = element.preview - inline fun needs(crossinline block: () -> Boolean) { - if (!element.preview) { - operation { - element.enabled = block() - false + inline fun ElementScope.needs(crossinline block: () -> Boolean) { + if (!preview) { + operation { + element.enabled = block() + false + } } } - } - fun refreshHUD() { - element.refresh(this) + fun ElementScope.refreshHUDs() { + element.refresh(this) + } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/me/odinmain/features/huds/HUDManager.kt b/src/main/kotlin/me/odinmain/features/huds/HUDManager.kt index ee09e3ee6..3ba70b6a6 100644 --- a/src/main/kotlin/me/odinmain/features/huds/HUDManager.kt +++ b/src/main/kotlin/me/odinmain/features/huds/HUDManager.kt @@ -1,31 +1,26 @@ package me.odinmain.features.huds -import com.github.stivais.ui.UI -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Pixel -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.elements.impl.Popup -import com.github.stivais.ui.elements.impl.popup -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.elements.scope.ElementScope -import com.github.stivais.ui.elements.scope.hoverEffect -import com.github.stivais.ui.utils.loop -import com.github.stivais.ui.utils.radius -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.constraints.impl.measurements.Pixel +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.elements.Layout.Companion.section +import com.github.stivais.aurora.elements.impl.Block.Companion.outline +import com.github.stivais.aurora.elements.impl.Popup +import com.github.stivais.aurora.elements.impl.popup +import com.github.stivais.aurora.utils.loop +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.config.Config +import me.odinmain.features.huds.HUD.Companion.refreshHUDs import me.odinmain.features.impl.render.ClickGUI import me.odinmain.features.impl.render.ClickGUI.`gray 26` import me.odinmain.features.impl.render.ClickGUI.`gray 38` import me.odinmain.features.impl.render.ClickGUI.hoverInformation import me.odinmain.features.settings.Setting -import me.odinmain.features.settings.Setting.Renders.Companion.elementWidth import me.odinmain.features.settings.Setting.Renders.Companion.onValueChanged -import me.odinmain.utils.ui.UIHandler -import me.odinmain.utils.ui.outline +import me.odinmain.utils.ui.renderer.NVGRenderer +import me.odinmain.utils.ui.screens.UIHandler import kotlin.math.abs -import kotlin.math.sign object HUDManager { @@ -39,26 +34,24 @@ object HUDManager { private const val SNAP_THRESHOLD = 5f fun setupHUDs() { - UI = UIHandler(UI { + UI = UIHandler(Aurora(renderer = NVGRenderer) { HUDs.loop { hud -> - val representation = hud.Representation(preview = false) - representation.add() - hud.builder(HUDScope(representation)) + hud.Representation(preview = false).scope(hud.builder) } }) UI!!.open() } - fun makeHUDEditor() = UI { - elementWidth = 180.px + fun makeHUDEditor() = Aurora(renderer = NVGRenderer) { var hudOptions: Popup? = null HUDs.loop { hud -> val representation = hud.Representation(preview = true) - representation.add() - hud.builder(HUDScope(representation).apply { - afterCreation { + representation.scope { + hud.builder(this) + + onAdd { element.constraints.x = element.x.px element.constraints.y = element.y.px } @@ -67,9 +60,8 @@ object HUDManager { hud.y.value = (element.y / ui.main.height) * 100f } onScroll { (amount) -> - hud.scale.value += 0.1f * amount.sign + hud.scale.value += 0.1f * amount representation.scaleTransformation = hud.scale.value - true } var removeSelected = false @@ -83,6 +75,7 @@ object HUDManager { removeSelected = true true } + onRelease { if (removeSelected) { selected?.closePopup() @@ -91,16 +84,13 @@ object HUDManager { } } - //-------------// - // hud options // - //-------------// onClick(button = 1) { hudOptions?.closePopup() hudOptions = popup( constraints = at((element.x + element.screenWidth() + 20).px, element.y.px), smooth = true ) { - column(size(Bounding, Bounding)) { + column { block( size(180.px, 35.px), color = `gray 26`, @@ -108,20 +98,17 @@ object HUDManager { ) { text(hud.name) } - column(size(w = 180.px, h = Bounding)) { + column(size(w = 180.px)) { block( copies(), color = Color.RGB(38, 38, 38, 0.7f) ) hud.settings.loop { - if (!it.hidden && it is Setting.Renders) { - it.apply { - - val drawableScope = ElementScope(it.Drawable()).apply { - hoverInformation(it.description) - onValueChanged { refreshHUD() } - } - create(drawableScope).create() + if (it is Setting.Renders && !it.hidden) { + scope(it.Drawable()) { + hoverInformation(description = it.description) + onValueChanged { refreshHUDs() } + it.apply { create() } } } } @@ -132,9 +119,12 @@ object HUDManager { color = `gray 38`, radius = 5.radius() ) { - hoverEffect(0.25.seconds) - outline(ClickGUI.color) - text("Reset") + outline( + ClickGUI.color, + thickness = 1.px + ) + hoverEffect(factor = 1.25f) + text(string = "Reset") onClick { hud.settings.loop { @@ -156,7 +146,7 @@ object HUDManager { } true } - }) + } } // used purely to close hud options/selections @@ -170,7 +160,7 @@ object HUDManager { dragSelection() - onCreation { + onAdd { UI?.close() } onRemove { @@ -179,7 +169,10 @@ object HUDManager { } } - private fun ElementDSL.createSelection(pressed: Boolean, selectedHUDs: ArrayList): Popup { + private fun ElementScope<*>.createSelection( + pressed: Boolean, + selectedHUDs: ArrayList + ): Popup { // get bounding box of selectedHUDs var minX = 9999f; var minY = 9999f // I wish I could rust :( var maxX = 0f; var maxY = 0f @@ -195,8 +188,9 @@ object HUDManager { return popup(constraints = constrain(px, py, (maxX - minX).px, (maxY - minY).px), smooth = true) { outline( - constraints = copies(), - color = Color.WHITE + constraints = copies(), + color = Color.WHITE, + thickness = 1.px ) var mouseDown = pressed @@ -222,8 +216,9 @@ object HUDManager { snapLineX = -1f snapLineY = -1f - val centerX = parent!!.width / 2 - val centerY = parent!!.height / 2 + val parent = element.parent ?: return@onMouseMove false + val centerX = parent.width / 2 + val centerY = parent.height / 2 // Check for center snapLineping if (abs(newX + element.screenWidth() / 2 - centerX) <= SNAP_THRESHOLD) { @@ -235,7 +230,7 @@ object HUDManager { snapLineY = centerY } - parent?.elements?.loop { other -> + parent.children?.loop { other -> if (other is HUD.Representation && !selectedHUDs.contains(other)) { // horizontal edges @@ -267,14 +262,13 @@ object HUDManager { val lastX = px.pixels val lastY = py.pixels - px.pixels = newX.coerceIn(0f, parent!!.width - element.screenWidth()) - py.pixels = newY.coerceIn(0f, parent!!.height - element.screenHeight()) + px.pixels = newX.coerceIn(0f, parent.width - element.screenWidth()) + py.pixels = newY.coerceIn(0f, parent.height - element.screenHeight()) selectedHUDs.loop { if (lastX != px.pixels) (it.constraints.x as Pixel).pixels += px.pixels - lastX if (lastY != py.pixels) (it.constraints.y as Pixel).pixels += py.pixels - lastY } - redraw() true } else { false @@ -283,7 +277,7 @@ object HUDManager { } } - private fun ElementDSL.dragSelection() { + private fun ElementScope<*>.dragSelection() { val x = 0.px val y = 0.px val w = 0.px @@ -293,15 +287,15 @@ object HUDManager { constraints = constrain(x, y, w, h), color = Color.BLUE.withAlpha(0.25f) ) { - outline(Color.BLUE) - enabled = false + outline(Color.BLUE, thickness = 1.px) + toggle() } var clickedX = 0f var clickedY = 0f onClick { - box.enabled = true + box.toggle() clickedX = ui.mx clickedY = ui.my @@ -309,6 +303,7 @@ object HUDManager { y.pixels = clickedY w.pixels = 0f h.pixels = 0f + box.redraw() true } onRelease { @@ -321,16 +316,16 @@ object HUDManager { if (box.enabled) { val selectedHUDs = arrayListOf() - element.elements?.loop { + element.children?.loop { if (it is HUD.Representation && it.enabled && it.intersects(box.element)) { selectedHUDs.add(it) } } selected?.closePopup() selected = createSelection(pressed = false, selectedHUDs) - redraw() - box.enabled = false + box.toggle() + box.redraw() } } onMouseMove { @@ -343,9 +338,7 @@ object HUDManager { h.pixels = abs(newH) box.redraw() true - } else { - false - } + } else false } } } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/BlessingDisplay.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/BlessingDisplay.kt index ab55000c6..cacf87730 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/BlessingDisplay.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/BlessingDisplay.kt @@ -1,25 +1,27 @@ package me.odinmain.features.impl.dungeon -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting import me.odinmain.utils.skyblock.dungeon.Blessing +import me.odinmain.utils.ui.Colors object BlessingDisplay : Module( name = "Blessing Display", description = "Displays the current blessings of the dungeon." ) { private val power by BooleanSetting("Power Blessing", true, description = "Displays the power blessing.") - private val powerColor by ColorSetting("Power Color", Color.MINECRAFT_DARK_RED, true, description = "The color of the power blessing.").withDependency { power } + private val powerColor by ColorSetting("Power Color", Colors.MINECRAFT_DARK_RED, true, description = "The color of the power blessing.").withDependency { power } private val time by BooleanSetting("Time Blessing", true, description = "Displays the time blessing.") - private val timeColor by ColorSetting("Time Color", Color.MINECRAFT_DARK_PURPLE, true, description = "The color of the time blessing.").withDependency { time } + private val timeColor by ColorSetting("Time Color", Colors.MINECRAFT_DARK_PURPLE, true, description = "The color of the time blessing.").withDependency { time } private val stone by BooleanSetting("Stone Blessing", false, description = "Displays the stone blessing.") - private val stoneColor by ColorSetting("Stone Color", Color.MINECRAFT_GRAY, true, description = "The color of the stone blessing.").withDependency { stone } + private val stoneColor by ColorSetting("Stone Color", Colors.MINECRAFT_GRAY, true, description = "The color of the stone blessing.").withDependency { stone } private val life by BooleanSetting("Life Blessing", false, description = "Displays the life blessing.") private val lifeColor by ColorSetting("Life Color", Color.RED, true, description = "The color of the life blessing.").withDependency { life } private val wisdom by BooleanSetting("Wisdom Blessing", false, description = "Displays the wisdom blessing.") - private val wisdomColor by ColorSetting("Wisdom Color", Color.MINECRAFT_BLUE, true, description = "The color of the wisdom blessing.").withDependency { wisdom } + private val wisdomColor by ColorSetting("Wisdom Color", Colors.MINECRAFT_BLUE, true, description = "The color of the wisdom blessing.").withDependency { wisdom } private data class BlessingData(val type: Blessing, val enabled: () -> Boolean, val color: () -> Color) private val blessings = listOf( diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/BloodCamp.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/BloodCamp.kt index 8cc401cc6..28abb02a1 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/BloodCamp.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/BloodCamp.kt @@ -1,13 +1,16 @@ package me.odinmain.features.impl.dungeon -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.OdinMain.isLegitVersion import me.odinmain.events.impl.EntityLeaveWorldEvent import me.odinmain.events.impl.PostEntityMetadata import me.odinmain.events.impl.RealServerTick import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.DropdownSetting +import me.odinmain.features.settings.impl.NumberSetting import me.odinmain.utils.* import me.odinmain.utils.ServerUtils.averagePing import me.odinmain.utils.render.RenderUtils.renderVec @@ -17,6 +20,7 @@ import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.dungeon.DungeonUtils.inBoss import me.odinmain.utils.skyblock.dungeon.DungeonUtils.inDungeons import me.odinmain.utils.skyblock.getSkullValue +import me.odinmain.utils.ui.Colors import net.minecraft.entity.boss.BossStatus import net.minecraft.entity.item.EntityArmorStand import net.minecraft.entity.monster.EntityZombie @@ -37,7 +41,7 @@ object BloodCamp : Module( ) { private val bloodHelper by BooleanSetting("Blood Camp Assist", default = true, description = "Draws boxes to spawning mobs in the blood room. WARNING: not perfectly accurate. Mobs spawn randomly between 37 - 41 ticks, adjust offset to adjust between ticks.") private val pboxColor by ColorSetting("Spawn Color", Color.RED, true, description = "Color for Spawn render box. Set alpha to 0 to disable.").withDependency { bloodHelper } - private val fboxColor by ColorSetting("Final Color", Color.MINECRAFT_AQUA, true, description = "Color for when Spawn and Mob boxes are merged. Set alpha to 0 to disable.").withDependency { bloodHelper } + private val fboxColor by ColorSetting("Final Color", Colors.MINECRAFT_AQUA, true, description = "Color for when Spawn and Mob boxes are merged. Set alpha to 0 to disable.").withDependency { bloodHelper } private val mboxColor by ColorSetting("Position Color", Color.GREEN, true, description = "Color for current position box. Set alpha to 0 to disable.").withDependency { bloodHelper } private val boxSize by NumberSetting("Box Size", default = 1.0, increment = 0.1, min = 0.1, max = 1.0, description = "The size of the boxes. Lower values may seem less accurate.").withDependency { bloodHelper } private val drawLine by BooleanSetting("Line", default = true, description = "Line between Position box and Spawn box.").withDependency { bloodHelper } @@ -185,7 +189,7 @@ object BloodCamp : Module( val timeDisplay = (time.toFloat() - offset) / 1000 val colorTime = when { timeDisplay > 1.5 -> Color.GREEN - timeDisplay in 0.5..1.5 -> Color.MINECRAFT_GOLD + timeDisplay in 0.5..1.5 -> Colors.MINECRAFT_GOLD timeDisplay in 0.0..0.5 -> Color.RED else -> Color.BLUE } diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/CanClip.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/CanClip.kt index 18ed8767c..bd8415857 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/CanClip.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/CanClip.kt @@ -1,9 +1,9 @@ package me.odinmain.features.impl.dungeon -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module import me.odinmain.features.settings.impl.BooleanSetting -import me.odinmain.utils.render.* +import me.odinmain.utils.render.Renderer import me.odinmain.utils.runIn import me.odinmain.utils.skyblock.getBlockAt import me.odinmain.utils.skyblock.isAir diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/KeyHighlight.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/KeyHighlight.kt index e157e058f..3b369892a 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/KeyHighlight.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/KeyHighlight.kt @@ -1,14 +1,18 @@ package me.odinmain.features.impl.dungeon -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.OdinMain.isLegitVersion import me.odinmain.events.impl.PostEntityMetadata import me.odinmain.features.Module -import me.odinmain.features.settings.impl.* -import me.odinmain.utils.* +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting +import me.odinmain.features.settings.impl.SelectorSetting +import me.odinmain.utils.addVec +import me.odinmain.utils.noControlCodes import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils +import me.odinmain.utils.toAABB import net.minecraft.entity.Entity import net.minecraft.entity.item.EntityArmorStand import net.minecraftforge.client.event.RenderWorldLastEvent diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/LeapMenu.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/LeapMenu.kt index e8eda2b9b..ab22e0d1c 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/LeapMenu.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/LeapMenu.kt @@ -1,24 +1,12 @@ package me.odinmain.features.impl.dungeon -import com.github.stivais.ui.UI -import com.github.stivais.ui.UIScreen.Companion.open -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.constrain -import com.github.stivais.ui.constraints.copies -import com.github.stivais.ui.constraints.measurements.Animatable -import com.github.stivais.ui.constraints.percent -import com.github.stivais.ui.constraints.size -import com.github.stivais.ui.elements.impl.Grid -import com.github.stivais.ui.utils.radius -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.color.Color import io.github.moulberry.notenoughupdates.NEUApi import me.odinmain.events.impl.GuiEvent import me.odinmain.features.Module import me.odinmain.features.impl.dungeon.LeapHelper.getPlayer import me.odinmain.features.impl.dungeon.LeapHelper.leapHelperBossChatEvent import me.odinmain.features.impl.dungeon.LeapHelper.worldLoad -import me.odinmain.features.impl.render.ClickGUI.`gray 38` import me.odinmain.features.settings.Setting.Companion.withDependency import me.odinmain.features.settings.impl.* import me.odinmain.utils.equalsOneOf @@ -55,66 +43,66 @@ object LeapMenu : Module( private val EMPTY = DungeonPlayer("Empty", DungeonClass.Unknown) - fun leapMenu() = UI { - Grid(copies()).scope { - leapTeammates.forEachIndexed { index, it -> - if (it == EMPTY) return@forEachIndexed - val x = when (index) { - 0, 2 -> 16.percent - else -> 6.percent - } - - val y = when (index) { - 0, 1 -> 38.percent - else -> 10.percent - } - val sizeX = Animatable(from = 80.percent, to = 83.percent) // this keeps the starting x and y while enlarging the width and height which isnt what we want - val sizeY = Animatable(from = 50.percent, to = 53.percent) - group(size(50.percent, 50.percent)) { - val block = block( - constraints = constrain(x, y, sizeX, sizeY), - color = `gray 38`, - radius = 12.radius() - ) { - - image( - it.skinImage, - constraints = constrain(5.percent, 10.percent, 30.percent, 80.percent), - 12f.radius() - ) - column(constraints = constrain(38.percent, 40.percent)) { - text(it.name, size = 20.percent, color = it.clazz.color) - divider(5.percent) - text(if (it.isDead) "§cDEAD" else it.clazz.name, size = 10.percent, color = Color.WHITE) - } - } - onClick { // make it possible to click any mouse button - handleMouseClick(index) - true - } - onMouseEnter { - sizeX.animate(0.25.seconds, Animations.EaseInOutQuint) - sizeY.animate(0.25.seconds, Animations.EaseInOutQuint) - block.outline(color = Color.WHITE) - redraw() - } - onMouseExit { - sizeX.animate(0.25.seconds, Animations.EaseInOutQuint) - sizeY.animate(0.25.seconds, Animations.EaseInOutQuint) - block.outline(color = Color.TRANSPARENT) - redraw() - } - } - } - } - } +// fun leapMenu() = UI { +// Grid(copies()).scope { +// leapTeammates.forEachIndexed { index, it -> +// if (it == EMPTY) return@forEachIndexed +// val x = when (index) { +// 0, 2 -> 16.percent +// else -> 6.percent +// } +// +// val y = when (index) { +// 0, 1 -> 38.percent +// else -> 10.percent +// } +// val sizeX = Animatable(from = 80.percent, to = 83.percent) // this keeps the starting x and y while enlarging the width and height which isnt what we want +// val sizeY = Animatable(from = 50.percent, to = 53.percent) +// group(size(50.percent, 50.percent)) { +// val block = block( +// constraints = constrain(x, y, sizeX, sizeY), +// color = `gray 38`, +// radius = 12.radius() +// ) { +// +// image( +// it.skinImage, +// constraints = constrain(5.percent, 10.percent, 30.percent, 80.percent), +// 12f.radius() +// ) +// column(constraints = constrain(38.percent, 40.percent)) { +// text(it.name, size = 20.percent, color = it.clazz.color) +// divider(5.percent) +// text(if (it.isDead) "§cDEAD" else it.clazz.name, size = 10.percent, color = Color.WHITE) +// } +// } +// onClick { // make it possible to click any mouse button +// handleMouseClick(index) +// true +// } +// onMouseEnter { +// sizeX.animate(0.25.seconds, Animations.EaseInOutQuint) +// sizeY.animate(0.25.seconds, Animations.EaseInOutQuint) +// block.outline(color = Color.WHITE) +// redraw() +// } +// onMouseExit { +// sizeX.animate(0.25.seconds, Animations.EaseInOutQuint) +// sizeY.animate(0.25.seconds, Animations.EaseInOutQuint) +// block.outline(color = Color.TRANSPARENT) +// redraw() +// } +// } +// } +// } +// } @SubscribeEvent fun guiOpen(event: GuiOpenEvent) { val chest = (event.gui as? GuiChest)?.inventorySlots ?: return if (chest !is ContainerChest || chest.name != "Spirit Leap" || leapTeammates.isEmpty() || leapTeammates.all { it == EMPTY }) return if (Loader.instance().activeModList.any { it.modId == "notenoughupdates" }) NEUApi.setInventoryButtonsToDisabled() - leapMenu().open() +// leapMenu().open() } private fun handleMouseClick(quadrant: Int) { diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/Mimic.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/Mimic.kt index aa035367f..b0eb024b5 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/Mimic.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/Mimic.kt @@ -1,7 +1,7 @@ package me.odinmain.features.impl.dungeon -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.OdinMain.isLegitVersion import me.odinmain.events.impl.EntityLeaveWorldEvent import me.odinmain.events.impl.RenderChestEvent diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/SecretClicked.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/SecretClicked.kt index 7f15a5dbe..e5765bce7 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/SecretClicked.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/SecretClicked.kt @@ -1,7 +1,7 @@ package me.odinmain.features.impl.dungeon -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.events.impl.SecretPickupEvent import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency @@ -13,6 +13,7 @@ import me.odinmain.utils.skyblock.PlayerUtils import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.toAABB import me.odinmain.utils.toBlockPos +import me.odinmain.utils.ui.Colors import net.minecraft.util.BlockPos import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -25,7 +26,7 @@ object SecretClicked : Module( private val boxesDropdown by DropdownSetting("Secret Boxes Dropdown") private val boxes by BooleanSetting("Secret Boxes", true, description = "Whether or not to render boxes around clicked secrets.").withDependency { boxesDropdown } private val style by SelectorSetting("Style", Renderer.DEFAULT_STYLE, Renderer.styles, description = Renderer.STYLE_DESCRIPTION).withDependency { boxesDropdown && boxes } - private val color by ColorSetting("Color", color = Color.MINECRAFT_GOLD.withAlpha(.4f), allowAlpha = true, description = "The color of the box.").withDependency { boxesDropdown && boxes } + private val color by ColorSetting("Color", color = Colors.MINECRAFT_GOLD.withAlpha(.4f), allowAlpha = true, description = "The color of the box.").withDependency { boxesDropdown && boxes } private val lineWidth by NumberSetting("Line Width", 2f, 0.1f, 10f, 0.1f, description = "The width of the box's lines.").withDependency { boxesDropdown && boxes } private val depthCheck by BooleanSetting("Depth check", false, description = "Boxes show through walls.").withDependency { boxesDropdown && boxes } private val lockedColor by ColorSetting("Locked Color", color = Color.RED.withAlpha(.4f), allowAlpha = true, description = "The color of the box when the chest is locked.").withDependency { boxesDropdown && boxes } diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/TeammatesHighlight.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/TeammatesHighlight.kt index b9718f970..27d0bf70c 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/TeammatesHighlight.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/TeammatesHighlight.kt @@ -1,14 +1,21 @@ package me.odinmain.features.impl.dungeon -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.events.impl.RenderOverlayNoCaching import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* -import me.odinmain.utils.render.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting +import me.odinmain.features.settings.impl.SelectorSetting +import me.odinmain.utils.render.HighlightRenderer +import me.odinmain.utils.render.RenderUtils +import me.odinmain.utils.render.RenderUtils2D +import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.dungeon.DungeonUtils.dungeonTeammatesNoSelf +import me.odinmain.utils.ui.Colors import net.minecraft.client.entity.EntityOtherPlayerMP import net.minecraft.util.Vec3 import net.minecraftforge.client.event.RenderLivingEvent @@ -25,7 +32,7 @@ object TeammatesHighlight : Module( private val showHighlight by BooleanSetting("Show highlight", true, description = "Highlights teammates with an outline.") private val showName by BooleanSetting("Show name", true, description = "Highlights teammates with a name tag.") private val nameStyle by SelectorSetting("Name Style", "Plain Text", arrayListOf("Plain Text", "Oringo Style"), description = "The style of the name tag to render.").withDependency { showName } - private val backgroundColor by ColorSetting("Background Color", color = Color.MINECRAFT_DARK_GRAY.withAlpha(0.5f), true, description = "The color of the nametag background").withDependency { showName && nameStyle == 1 } + private val backgroundColor by ColorSetting("Background Color", color = Colors.MINECRAFT_DARK_GRAY.withAlpha(0.5f), true, description = "The color of the nametag background").withDependency { showName && nameStyle == 1 } private val accentColor by ColorSetting("Accent Color", color = Color.BLUE, true, description = "The color of the nametag accent").withDependency { showName && nameStyle == 1 } private val padding by NumberSetting("Padding", default = 5, min = 0, max = 20, increment = 1, description = "The padding around the text of the nametag.").withDependency { showName && nameStyle == 1 } private val scale by NumberSetting("Scale", default = 0.8f, min = 0, max = 2, increment = 0.1, description = "The scale of the nametag").withDependency { showName && nameStyle ==1 } diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/TerracottaTimer.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/TerracottaTimer.kt index d8171cfad..85e223897 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/TerracottaTimer.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/TerracottaTimer.kt @@ -1,16 +1,19 @@ package me.odinmain.features.impl.dungeon -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.events.impl.BlockChangeEvent import me.odinmain.events.impl.RealServerTick import me.odinmain.features.Module -import me.odinmain.utils.* +import me.odinmain.utils.addVec +import me.odinmain.utils.equal import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils +import me.odinmain.utils.toVec3 +import me.odinmain.utils.ui.Colors import net.minecraft.util.Vec3 import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.Locale +import java.util.* import java.util.concurrent.CopyOnWriteArrayList object TerracottaTimer : Module( @@ -47,9 +50,9 @@ object TerracottaTimer : Module( private fun getColor(time: Double): Color { return when { - time > 5.0 -> Color.MINECRAFT_RED - time > 2.0 -> Color.MINECRAFT_GOLD - else -> Color.MINECRAFT_GREEN + time > 5.0 -> Colors.MINECRAFT_RED + time > 2.0 -> Colors.MINECRAFT_GOLD + else -> Colors.MINECRAFT_GREEN } } } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/WarpCooldown.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/WarpCooldown.kt index 4c352319d..6c90d1b78 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/WarpCooldown.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/WarpCooldown.kt @@ -1,10 +1,7 @@ package me.odinmain.features.impl.dungeon -import com.github.stivais.ui.constraints.px import me.odinmain.features.Module import me.odinmain.features.settings.impl.BooleanSetting -import me.odinmain.utils.ui.TextHUD -import me.odinmain.utils.ui.and object WarpCooldown : Module ( name = "Warp Cooldown", @@ -12,26 +9,26 @@ object WarpCooldown : Module ( ) { private val showUnit by BooleanSetting("Show unit", default = false, description = "Displays unit of time for the cooldown.").hide() - private val HUD by TextHUD("Warp HUD") { color, font -> - if (preview) { - text( - "Warp ", - color = color, - font = font, - size = 30.px - ) and text("30${if (showUnit) "s" else ""}", font = font) - } else { - needs { lastUpdate - System.currentTimeMillis() >= 0 } - text( - "Warp ", - color = color, - font = font, - size = 30.px - ) and text({ "${(lastUpdate - System.currentTimeMillis()) / 1000}${if (showUnit) "s" else ""}" }, font = font) - } - }.registerSettings( - ::showUnit - ).setting("Displays the cooldown.") +// private val HUD by TextHUD("Warp HUD") { color, font -> +// if (preview) { +// text( +// "Warp ", +// color = color, +// font = font, +// size = 30.px +// ) and text("30${if (showUnit) "s" else ""}", font = font) +// } else { +// needs { lastUpdate - System.currentTimeMillis() >= 0 } +// text( +// "Warp ", +// color = color, +// font = font, +// size = 30.px +// ) and text({ "${(lastUpdate - System.currentTimeMillis()) / 1000}${if (showUnit) "s" else ""}" }, font = font) +// } +// }.registerSettings( +// ::showUnit +// ).setting("Displays the cooldown.") private var lastUpdate: Long = System.currentTimeMillis() diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/dungeonwaypoints/DungeonWaypoints.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/dungeonwaypoints/DungeonWaypoints.kt index b3c75e0be..1c811b253 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/dungeonwaypoints/DungeonWaypoints.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/dungeonwaypoints/DungeonWaypoints.kt @@ -1,7 +1,7 @@ package me.odinmain.features.impl.dungeon.dungeonwaypoints -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.toHexString +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.toHexString import me.odinmain.config.DungeonWaypointConfig import me.odinmain.events.impl.ClickEvent import me.odinmain.events.impl.RoomEnterEvent @@ -15,14 +15,16 @@ import me.odinmain.features.impl.render.DevPlayers import me.odinmain.features.settings.Setting.Companion.withDependency import me.odinmain.features.settings.impl.* import me.odinmain.utils.* -import me.odinmain.utils.render.* +import me.odinmain.utils.render.RenderUtils import me.odinmain.utils.render.RenderUtils.outlineBounds import me.odinmain.utils.render.RenderUtils.renderVec +import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.* import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getRealCoords import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getRelativeCoords import me.odinmain.utils.skyblock.dungeon.tiles.Room +import me.odinmain.utils.ui.Colors import net.minecraft.block.BlockSign import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen @@ -83,9 +85,9 @@ object DungeonWaypoints : Module( private val selectedColor get() = when (colorPallet) { 0 -> color - 1 -> Color.MINECRAFT_AQUA - 2 -> Color.MINECRAFT_DARK_PURPLE - 3 -> Color.MINECRAFT_YELLOW + 1 -> Colors.MINECRAFT_AQUA + 2 -> Colors.MINECRAFT_DARK_PURPLE + 3 -> Colors.MINECRAFT_YELLOW 4 -> Color.GREEN 5 -> Color.RED else -> color diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/BeamsSolver.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/BeamsSolver.kt index c2ff9f984..1d31f6782 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/BeamsSolver.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/BeamsSolver.kt @@ -1,23 +1,30 @@ package me.odinmain.features.impl.dungeon.puzzlesolvers -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import com.google.gson.GsonBuilder import com.google.gson.reflect.TypeToken import me.odinmain.OdinMain.logger import me.odinmain.events.impl.BlockChangeEvent import me.odinmain.events.impl.RoomEnterEvent import me.odinmain.features.impl.dungeon.puzzlesolvers.PuzzleSolvers.beamsAlpha -import me.odinmain.utils.* +import me.odinmain.utils.addVec +import me.odinmain.utils.equalsOneOf import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getRealCoords import me.odinmain.utils.skyblock.getBlockIdAt +import me.odinmain.utils.toAABB +import me.odinmain.utils.toVec3 +import me.odinmain.utils.ui.Colors import net.minecraft.init.Blocks import net.minecraft.util.BlockPos import java.io.InputStreamReader import java.nio.charset.StandardCharsets import java.util.concurrent.ConcurrentHashMap +import kotlin.collections.component1 +import kotlin.collections.component2 +import kotlin.collections.set object BeamsSolver { private var scanned = false @@ -60,8 +67,14 @@ object BeamsSolver { Renderer.drawStyledBox(positions.key.toAABB(), color, depth = true, style = PuzzleSolvers.beamStyle) Renderer.drawStyledBox(positions.value.first.toAABB(), color, depth = true, style = PuzzleSolvers.beamStyle) - if (PuzzleSolvers.beamsTracer) - Renderer.draw3DLine(listOf(positions.key.toVec3().addVec(0.5, 0.5, 0.5), positions.value.first.toVec3().addVec(0.5, 0.5, 0.5)), color = color.withAlpha(beamsAlpha), depth = false, lineWidth = 2f) + if (PuzzleSolvers.beamsTracer) { + Renderer.draw3DLine( + listOf( + positions.key.toVec3().addVec(0.5, 0.5, 0.5), + positions.value.first.toVec3().addVec(0.5, 0.5, 0.5) + ), color = color.withAlpha(beamsAlpha), depth = false, lineWidth = 2f + ) + } } } @@ -70,7 +83,8 @@ object BeamsSolver { currentLanternPairs.forEach { (key, value) -> if (event.pos.equalsOneOf(key, value.first) && event.update.block != Blocks.sea_lantern && - event.old.block == Blocks.sea_lantern) currentLanternPairs.remove(key) + event.old.block == Blocks.sea_lantern + ) currentLanternPairs.remove(key) } } @@ -80,7 +94,14 @@ object BeamsSolver { } private val colors = listOf( - Color.MINECRAFT_GOLD, Color.GREEN, Color.MINECRAFT_LIGHT_PURPLE, Color.MINECRAFT_AQUA, Color.MINECRAFT_YELLOW, Color.MINECRAFT_DARK_RED, Color.WHITE, Color.MINECRAFT_DARK_PURPLE + Colors.MINECRAFT_GOLD, + Color.GREEN, + Colors.MINECRAFT_LIGHT_PURPLE, + Colors.MINECRAFT_AQUA, + Colors.MINECRAFT_YELLOW, + Colors.MINECRAFT_DARK_RED, + Color.WHITE, + Colors.MINECRAFT_DARK_PURPLE ) } diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/IceFillSolver.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/IceFillSolver.kt index 9c307c3e1..3c5d685f4 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/IceFillSolver.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/IceFillSolver.kt @@ -1,11 +1,13 @@ package me.odinmain.features.impl.dungeon.puzzlesolvers -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import com.google.gson.GsonBuilder import com.google.gson.reflect.TypeToken import me.odinmain.OdinMain.logger import me.odinmain.events.impl.RoomEnterEvent -import me.odinmain.utils.* +import me.odinmain.utils.Vec2 +import me.odinmain.utils.add +import me.odinmain.utils.addVec import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.IceFillFloors import me.odinmain.utils.skyblock.dungeon.DungeonUtils @@ -13,7 +15,10 @@ import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getRealCoords import me.odinmain.utils.skyblock.dungeon.tiles.Rotations import me.odinmain.utils.skyblock.isAir import me.odinmain.utils.skyblock.modMessage -import net.minecraft.util.* +import me.odinmain.utils.toVec3 +import net.minecraft.util.BlockPos +import net.minecraft.util.Vec3 +import net.minecraft.util.Vec3i import java.io.InputStreamReader import java.nio.charset.StandardCharsets diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/PuzzleSolvers.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/PuzzleSolvers.kt index 015226677..d05599878 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/PuzzleSolvers.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/PuzzleSolvers.kt @@ -1,7 +1,7 @@ package me.odinmain.features.impl.dungeon.puzzlesolvers -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.events.impl.BlockChangeEvent import me.odinmain.events.impl.RoomEnterEvent import me.odinmain.features.Module @@ -14,6 +14,7 @@ import me.odinmain.utils.skyblock.Island import me.odinmain.utils.skyblock.LocationUtils import me.odinmain.utils.skyblock.dungeon.DungeonUtils.inBoss import me.odinmain.utils.skyblock.dungeon.DungeonUtils.inDungeons +import me.odinmain.utils.ui.Colors import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement import net.minecraft.network.play.server.S08PacketPlayerPosLook import net.minecraftforge.client.event.RenderWorldLastEvent @@ -29,7 +30,7 @@ object PuzzleSolvers : Module( val showOrder by BooleanSetting("Show Order", true, description = "Shows the order of the levers to click.").withDependency { waterSolver && waterDropDown } val showTracer by BooleanSetting("Show Tracer", true, description = "Shows a tracer to the next lever.").withDependency { waterSolver && waterDropDown } val tracerColorFirst by ColorSetting("Tracer Color First", Color.GREEN, true, description = "Color for the first tracer.").withDependency { showTracer && waterDropDown } - val tracerColorSecond by ColorSetting("Tracer Color Second", Color.MINECRAFT_GOLD, true, description = "Color for the second tracer.").withDependency { showTracer && waterDropDown } + val tracerColorSecond by ColorSetting("Tracer Color Second", Colors.MINECRAFT_GOLD, true, description = "Color for the second tracer.").withDependency { showTracer && waterDropDown } val reset by ActionSetting("Reset", description = "Resets the solver.") { WaterSolver.reset() }.withDependency { waterSolver && waterDropDown } @@ -37,7 +38,7 @@ object PuzzleSolvers : Module( private val mazeDropDown by DropdownSetting("TP Maze") private val tpMaze by BooleanSetting("Teleport Maze", false, description = "Shows you the solution for the TP maze puzzle.").withDependency { mazeDropDown } val mazeColorOne by ColorSetting("Color for one", Color.GREEN.withAlpha(.5f), true, description = "Color for when there is a single solution.").withDependency { tpMaze && mazeDropDown } - val mazeColorMultiple by ColorSetting("Color for multiple", Color.MINECRAFT_GOLD.withAlpha(.5f), true, description = "Color for when there are multiple solutions.").withDependency { tpMaze && mazeDropDown } + val mazeColorMultiple by ColorSetting("Color for multiple", Colors.MINECRAFT_GOLD.withAlpha(.5f), true, description = "Color for when there are multiple solutions.").withDependency { tpMaze && mazeDropDown } val mazeColorVisited by ColorSetting("Color for visited", Color.RED.withAlpha(.5f), true, description = "Color for the already used TP pads.").withDependency { tpMaze && mazeDropDown } private val click by ActionSetting("Reset", description = "Resets the solver.") { TPMazeSolver.reset() @@ -45,7 +46,7 @@ object PuzzleSolvers : Module( private val iceFillDropDown by DropdownSetting("Ice Fill") private val iceFillSolver by BooleanSetting("Ice Fill Solver", false, description = "Solver for the ice fill puzzle.").withDependency { iceFillDropDown } - private val iceFillColor by ColorSetting("Ice Fill Color", Color.MINECRAFT_LIGHT_PURPLE, true, description = "Color for the ice fill solver.").withDependency { iceFillSolver && iceFillDropDown } + private val iceFillColor by ColorSetting("Ice Fill Color", Colors.MINECRAFT_LIGHT_PURPLE, true, description = "Color for the ice fill solver.").withDependency { iceFillSolver && iceFillDropDown } val useOptimizedPatterns by BooleanSetting("Use Optimized Patterns", false, description = "Use optimized patterns for the ice fill solver.").withDependency { iceFillSolver && iceFillDropDown } private val action by ActionSetting("Reset", description = "Resets the solver.") { IceFillSolver.reset() @@ -57,7 +58,7 @@ object PuzzleSolvers : Module( val blazeLineAmount: Int by NumberSetting("Blaze Solver Lines", 1, 1, 10, 1, description = "Amount of lines to show.").withDependency { blazeSolver && blazeDropDown } val blazeStyle by SelectorSetting("Blaze Style", "Outline", arrayListOf("Filled", "Outline", "Filled Outline"), description = "Whether or not the box should be filled.").withDependency { blazeSolver && blazeDropDown } val blazeFirstColor by ColorSetting("First Color", Color.GREEN, true, description = "Color for the first blaze.").withDependency { blazeSolver && blazeDropDown } - val blazeSecondColor by ColorSetting("Second Color", Color.MINECRAFT_GOLD, true, description = "Color for the second blaze.").withDependency { blazeSolver && blazeDropDown } + val blazeSecondColor by ColorSetting("Second Color", Colors.MINECRAFT_GOLD, true, description = "Color for the second blaze.").withDependency { blazeSolver && blazeDropDown } val blazeAllColor by ColorSetting("Other Color", Color.WHITE.withAlpha(.3f), true, description = "Color for the other blazes.").withDependency { blazeSolver && blazeDropDown } val blazeWidth by NumberSetting("Box Width", 1.0, 0.5, 2.0, 0.1, description = "Width of the box.").withDependency { blazeSolver && blazeDropDown } val blazeHeight by NumberSetting("Box Height", 2.0, 1.0, 3.0, 0.1, description = "Height of the box.").withDependency { blazeSolver && blazeDropDown } diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/TPMazeSolver.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/TPMazeSolver.kt index 0fe79d43e..af8d876c5 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/TPMazeSolver.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/TPMazeSolver.kt @@ -1,20 +1,23 @@ package me.odinmain.features.impl.dungeon.puzzlesolvers -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.OdinMain.mc import me.odinmain.events.impl.RoomEnterEvent import me.odinmain.features.impl.dungeon.puzzlesolvers.PuzzleSolvers.mazeColorMultiple import me.odinmain.features.impl.dungeon.puzzlesolvers.PuzzleSolvers.mazeColorOne import me.odinmain.features.impl.dungeon.puzzlesolvers.PuzzleSolvers.mazeColorVisited -import me.odinmain.utils.* +import me.odinmain.utils.isXZInterceptable import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getRealCoords import me.odinmain.utils.skyblock.getBlockAt +import me.odinmain.utils.toAABB import net.minecraft.init.Blocks import net.minecraft.network.play.server.S08PacketPlayerPosLook -import net.minecraft.util.* +import net.minecraft.util.AxisAlignedBB +import net.minecraft.util.BlockPos +import net.minecraft.util.Vec3 import java.util.concurrent.CopyOnWriteArraySet object TPMazeSolver { diff --git a/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/WaterSolver.kt b/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/WaterSolver.kt index ae2873b4d..f3feaa57d 100644 --- a/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/WaterSolver.kt +++ b/src/main/kotlin/me/odinmain/features/impl/dungeon/puzzlesolvers/WaterSolver.kt @@ -1,6 +1,6 @@ package me.odinmain.features.impl.dungeon.puzzlesolvers -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import com.google.gson.JsonObject import com.google.gson.JsonParser import me.odinmain.OdinMain.mc @@ -21,7 +21,7 @@ import net.minecraft.util.BlockPos import net.minecraft.util.Vec3 import java.io.InputStreamReader import java.nio.charset.StandardCharsets -import java.util.Locale +import java.util.* import java.util.concurrent.ConcurrentHashMap import kotlin.collections.component1 import kotlin.collections.component2 diff --git a/src/main/kotlin/me/odinmain/features/impl/floor7/DragonBoxes.kt b/src/main/kotlin/me/odinmain/features/impl/floor7/DragonBoxes.kt index 3bd659b74..591f80682 100644 --- a/src/main/kotlin/me/odinmain/features/impl/floor7/DragonBoxes.kt +++ b/src/main/kotlin/me/odinmain/features/impl/floor7/DragonBoxes.kt @@ -1,14 +1,17 @@ package me.odinmain.features.impl.floor7 -import com.github.stivais.ui.color.multiplyAlpha -import me.odinmain.features.impl.floor7.WitherDragons.lineThickness -import me.odinmain.utils.render.Renderer - object DragonBoxes { fun renderBoxes() { - WitherDragonsEnum.entries.forEach { - if (it.state != WitherDragonState.DEAD) - Renderer.drawBox(it.boxesDimensions, it.color.multiplyAlpha(0.5f), lineThickness, depth = false, fillAlpha = 0) - } +// WitherDragonsEnum.entries.forEach { +// if (it.state != WitherDragonState.DEAD) { +// Renderer.drawBox( +// it.boxesDimensions, +// it.color/*.multiplyAlpha(0.5f)*/, +// lineThickness, +// depth = false, +// fillAlpha = 0 +// ) +// } +// } } } diff --git a/src/main/kotlin/me/odinmain/features/impl/floor7/DragonHealth.kt b/src/main/kotlin/me/odinmain/features/impl/floor7/DragonHealth.kt index 4aefc71fa..e49149356 100644 --- a/src/main/kotlin/me/odinmain/features/impl/floor7/DragonHealth.kt +++ b/src/main/kotlin/me/odinmain/features/impl/floor7/DragonHealth.kt @@ -1,16 +1,24 @@ package me.odinmain.features.impl.floor7 -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.utils.addVec import me.odinmain.utils.render.RenderUtils.renderVec import me.odinmain.utils.render.Renderer -import java.util.Locale +import java.util.* object DragonHealth{ fun renderHP() { DragonCheck.dragonEntityList.forEach { - if (it.health > 0) - Renderer.drawStringInWorld(colorHealth(it.health), it.renderVec.addVec(y = 1.5), Color.WHITE, depth = false, scale = 0.2f, shadow = true) + if (it.health > 0) { + Renderer.drawStringInWorld( + colorHealth(it.health), + it.renderVec.addVec(y = 1.5), + Color.WHITE, + depth = false, + scale = 0.2f, + shadow = true + ) + } } } diff --git a/src/main/kotlin/me/odinmain/features/impl/floor7/DragonTimer.kt b/src/main/kotlin/me/odinmain/features/impl/floor7/DragonTimer.kt index 7ff0ea8c7..bc3fc527b 100644 --- a/src/main/kotlin/me/odinmain/features/impl/floor7/DragonTimer.kt +++ b/src/main/kotlin/me/odinmain/features/impl/floor7/DragonTimer.kt @@ -1,9 +1,9 @@ package me.odinmain.features.impl.floor7 -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.impl.floor7.WitherDragons.addUselessDecimal import me.odinmain.utils.render.Renderer -import java.util.Locale +import java.util.* object DragonTimer { diff --git a/src/main/kotlin/me/odinmain/features/impl/floor7/KingRelics.kt b/src/main/kotlin/me/odinmain/features/impl/floor7/KingRelics.kt index e03fa673b..288e8441c 100644 --- a/src/main/kotlin/me/odinmain/features/impl/floor7/KingRelics.kt +++ b/src/main/kotlin/me/odinmain/features/impl/floor7/KingRelics.kt @@ -1,12 +1,16 @@ package me.odinmain.features.impl.floor7 -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.OdinMain.mc import me.odinmain.features.impl.floor7.WitherDragons.relicAnnounceTime import me.odinmain.features.impl.floor7.WitherDragons.selected import me.odinmain.utils.equalsOneOf import me.odinmain.utils.render.Renderer -import me.odinmain.utils.skyblock.* +import me.odinmain.utils.skyblock.PersonalBest +import me.odinmain.utils.skyblock.getBlockAt +import me.odinmain.utils.skyblock.partyMessage +import me.odinmain.utils.skyblock.skyblockID +import me.odinmain.utils.ui.Colors import net.minecraft.init.Blocks import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement import net.minecraft.util.Vec3 @@ -22,9 +26,9 @@ object KingRelics { val cauldronPosition: Vec3 ) { Green("GREEN_KING_RELIC", 'a', Color.GREEN, Vec3(20.5, 6.5, 94.5), Vec3(49.0, 7.0, 44.0)), - Purple("PURPLE_KING_RELIC", '5', Color.MINECRAFT_DARK_PURPLE, Vec3(56.5, 8.5, 132.5), Vec3(54.0, 7.0, 41.0)), - Blue("BLUE_KING_RELIC", 'b', Color.MINECRAFT_BLUE, Vec3(91.5, 6.5, 94.5), Vec3(59.0, 7.0, 44.0)) , - Orange("ORANGE_KING_RELIC", '6', Color.MINECRAFT_GOLD, Vec3(90.5, 6.5, 56.5), Vec3(57.0, 7.0, 42.0)), + Purple("PURPLE_KING_RELIC", '5', Colors.MINECRAFT_DARK_PURPLE, Vec3(56.5, 8.5, 132.5), Vec3(54.0, 7.0, 41.0)), + Blue("BLUE_KING_RELIC", 'b', Colors.MINECRAFT_BLUE, Vec3(91.5, 6.5, 94.5), Vec3(59.0, 7.0, 44.0)) , + Orange("ORANGE_KING_RELIC", '6', Colors.MINECRAFT_GOLD, Vec3(90.5, 6.5, 56.5), Vec3(57.0, 7.0, 42.0)), Red("RED_KING_RELIC", 'c', Color.RED, Vec3(22.5, 6.5, 59.5), Vec3(51.0, 7.0, 42.0)), None("", 'f', Color.WHITE, Vec3(0.0, 0.0, 0.0), Vec3(0.0, 0.0, 0.0)) } diff --git a/src/main/kotlin/me/odinmain/features/impl/floor7/WitherDragonEnum.kt b/src/main/kotlin/me/odinmain/features/impl/floor7/WitherDragonEnum.kt index d077430c2..b0737f9b0 100644 --- a/src/main/kotlin/me/odinmain/features/impl/floor7/WitherDragonEnum.kt +++ b/src/main/kotlin/me/odinmain/features/impl/floor7/WitherDragonEnum.kt @@ -1,6 +1,6 @@ package me.odinmain.features.impl.floor7 -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.OdinMain.mc import me.odinmain.features.impl.floor7.DragonCheck.dragonEntityList import me.odinmain.features.impl.floor7.DragonCheck.lastDragonDeath @@ -18,9 +18,12 @@ import me.odinmain.features.impl.skyblock.ArrowHit.onDragonSpawn import me.odinmain.features.impl.skyblock.ArrowHit.resetOnDragons import me.odinmain.utils.skyblock.PersonalBest import me.odinmain.utils.skyblock.modMessage +import me.odinmain.utils.ui.Colors import net.minecraft.entity.boss.EntityDragon import net.minecraft.network.play.server.S2APacketParticles -import net.minecraft.util.* +import net.minecraft.util.AxisAlignedBB +import net.minecraft.util.EnumParticleTypes +import net.minecraft.util.Vec3 enum class WitherDragonsEnum ( val spawnPos: Vec3, @@ -41,7 +44,7 @@ enum class WitherDragonsEnum ( Red(Vec3(27.0, 14.0, 59.0), AxisAlignedBB(14.5, 13.0, 45.5, 39.5, 28.0, 70.5),'c', Color.RED, 24.0..30.0, 56.0..62.0, skipKillTime = 50), - Orange(Vec3(85.0, 14.0, 56.0), AxisAlignedBB(72.0, 8.0, 47.0, 102.0,28.0, 77.0),'6', Color.MINECRAFT_GOLD, + Orange(Vec3(85.0, 14.0, 56.0), AxisAlignedBB(72.0, 8.0, 47.0, 102.0,28.0, 77.0),'6', Colors.MINECRAFT_GOLD, 82.0..88.0, 53.0..59.0, skipKillTime = 62), Green(Vec3(27.0, 14.0, 94.0), AxisAlignedBB(7.0, 8.0, 80.0, 37.0, 28.0, 110.0),'a', Color.GREEN, @@ -50,7 +53,7 @@ enum class WitherDragonsEnum ( Blue(Vec3(84.0, 14.0, 94.0), AxisAlignedBB(71.5, 16.0, 82.5, 96.5, 26.0, 107.5),'b', Color.BLUE, 82.0..88.0, 91.0..97.0, skipKillTime = 39), - Purple(Vec3(56.0, 14.0, 125.0), AxisAlignedBB(45.5, 13.0, 113.5,68.5, 23.0, 136.5),'5', Color.MINECRAFT_DARK_PURPLE, + Purple(Vec3(56.0, 14.0, 125.0), AxisAlignedBB(45.5, 13.0, 113.5,68.5, 23.0, 136.5),'5', Colors.MINECRAFT_DARK_PURPLE, 53.0..59.0, 122.0..128.0, skipKillTime = 38), None(Vec3(0.0, 0.0, 0.0), AxisAlignedBB(0.0, 0.0, 0.0, 0.0, 0.0, 0.0), 'f', Color.WHITE, diff --git a/src/main/kotlin/me/odinmain/features/impl/floor7/p3/ArrowAlign.kt b/src/main/kotlin/me/odinmain/features/impl/floor7/p3/ArrowAlign.kt index 7b6285f46..7fa07ec2b 100644 --- a/src/main/kotlin/me/odinmain/features/impl/floor7/p3/ArrowAlign.kt +++ b/src/main/kotlin/me/odinmain/features/impl/floor7/p3/ArrowAlign.kt @@ -1,10 +1,12 @@ package me.odinmain.features.impl.floor7.p3 -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.events.impl.PacketSentEvent import me.odinmain.features.Module import me.odinmain.features.settings.impl.BooleanSetting -import me.odinmain.utils.* +import me.odinmain.utils.addVec +import me.odinmain.utils.distanceSquaredTo +import me.odinmain.utils.flooredVec import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.dungeon.M7Phases diff --git a/src/main/kotlin/me/odinmain/features/impl/floor7/p3/InactiveWaypoints.kt b/src/main/kotlin/me/odinmain/features/impl/floor7/p3/InactiveWaypoints.kt index 62ad3c9d4..f2770e21a 100644 --- a/src/main/kotlin/me/odinmain/features/impl/floor7/p3/InactiveWaypoints.kt +++ b/src/main/kotlin/me/odinmain/features/impl/floor7/p3/InactiveWaypoints.kt @@ -1,10 +1,14 @@ package me.odinmain.features.impl.floor7.p3 -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting +import me.odinmain.features.settings.impl.SelectorSetting import me.odinmain.utils.* -import me.odinmain.utils.render.* +import me.odinmain.utils.render.RenderUtils +import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils import me.odinmain.utils.skyblock.dungeon.M7Phases import net.minecraft.entity.Entity diff --git a/src/main/kotlin/me/odinmain/features/impl/floor7/p3/TerminalSolver.kt b/src/main/kotlin/me/odinmain/features/impl/floor7/p3/TerminalSolver.kt index cbe2fdd88..6d9e6b1fb 100644 --- a/src/main/kotlin/me/odinmain/features/impl/floor7/p3/TerminalSolver.kt +++ b/src/main/kotlin/me/odinmain/features/impl/floor7/p3/TerminalSolver.kt @@ -1,7 +1,7 @@ package me.odinmain.features.impl.floor7.p3 -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import io.github.moulberry.notenoughupdates.NEUApi import me.odinmain.events.impl.GuiEvent import me.odinmain.events.impl.TerminalEvent @@ -16,6 +16,7 @@ import me.odinmain.utils.skyblock.PlayerUtils import me.odinmain.utils.skyblock.PlayerUtils.windowClick import me.odinmain.utils.skyblock.modMessage import me.odinmain.utils.skyblock.unformattedName +import me.odinmain.utils.ui.Colors import net.minecraft.client.gui.Gui import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.renderer.GlStateManager @@ -61,7 +62,7 @@ object TerminalSolver : Module( private val showColors by DropdownSetting("Color Settings") private val backgroundColor by ColorSetting("Background Color", Color.RGB(45, 45, 45), true, description = "Background color of the terminal solver.").withDependency { renderType == 0 && showColors } - val customGuiColor by ColorSetting("Custom Gui Color", Color.MINECRAFT_DARK_GRAY.withAlpha(.8f), true, description = "Color of the custom gui.").withDependency { renderType == 3 && showColors } + val customGuiColor by ColorSetting("Custom Gui Color", Colors.MINECRAFT_DARK_GRAY.withAlpha(.8f), true, description = "Color of the custom gui.").withDependency { renderType == 3 && showColors } val textColor by ColorSetting("Text Color", Color.RGB(220, 220, 220), true, description = "Text color of the terminal solver.").withDependency { showColors } val panesColor by ColorSetting("Panes Color", Color.RGB(0, 170, 170), true, description = "Color of the panes terminal solver.").withDependency { showColors } @@ -79,10 +80,10 @@ object TerminalSolver : Module( val selectColor by ColorSetting("Select Color", Color.RGB(0, 170, 170), true, description = "Color of the select terminal solver.").withDependency { showColors } - val melodyColumColor by ColorSetting("Melody Column Color", Color.MINECRAFT_DARK_PURPLE.withAlpha(0.75f), true, description = "Color of the colum indicator for melody.").withDependency { showColors && !cancelMelodySolver } + val melodyColumColor by ColorSetting("Melody Column Color", Colors.MINECRAFT_DARK_PURPLE.withAlpha(0.75f), true, description = "Color of the colum indicator for melody.").withDependency { showColors && !cancelMelodySolver } val melodyRowColor by ColorSetting("Melody Row Color", Color.GREEN.withAlpha(0.75f), true, description = "Color of the row indicator for melody.").withDependency { showColors && !cancelMelodySolver } - val melodyPressColumColor by ColorSetting("Melody Press Column Color", Color.MINECRAFT_YELLOW.withAlpha(0.75f), true, description = "Color of the location for pressing for melody.").withDependency { showColors && !cancelMelodySolver } - val melodyPressColor by ColorSetting("Melody Press Color", Color.MINECRAFT_AQUA.withAlpha(0.75f), true, description = "Color of the location for pressing for melody.").withDependency { showColors && !cancelMelodySolver } + val melodyPressColumColor by ColorSetting("Melody Press Column Color", Colors.MINECRAFT_YELLOW.withAlpha(0.75f), true, description = "Color of the location for pressing for melody.").withDependency { showColors && !cancelMelodySolver } + val melodyPressColor by ColorSetting("Melody Press Color", Colors.MINECRAFT_AQUA.withAlpha(0.75f), true, description = "Color of the location for pressing for melody.").withDependency { showColors && !cancelMelodySolver } val melodyCorrectRowColor by ColorSetting("Melody Correct Row Color", Color.WHITE.withAlpha(0.75f), true, description = "Color of the whole row for melody.").withDependency { showColors && !cancelMelodySolver } private val zLevel get() = if (renderType == 1 && currentTerm.equalsOneOf(TerminalTypes.STARTS_WITH, TerminalTypes.SELECT)) 100f else 400f diff --git a/src/main/kotlin/me/odinmain/features/impl/nether/BlazeAttunement.kt b/src/main/kotlin/me/odinmain/features/impl/nether/BlazeAttunement.kt index 96bd59473..3eec7a036 100644 --- a/src/main/kotlin/me/odinmain/features/impl/nether/BlazeAttunement.kt +++ b/src/main/kotlin/me/odinmain/features/impl/nether/BlazeAttunement.kt @@ -1,7 +1,7 @@ package me.odinmain.features.impl.nether -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.events.impl.RenderEntityModelEvent import me.odinmain.features.Module import me.odinmain.features.settings.impl.BooleanSetting @@ -13,7 +13,9 @@ import me.odinmain.utils.xzDistance import net.minecraft.client.renderer.GlStateManager import net.minecraft.entity.Entity import net.minecraft.entity.item.EntityArmorStand -import net.minecraft.entity.monster.* +import net.minecraft.entity.monster.EntityBlaze +import net.minecraft.entity.monster.EntityPigZombie +import net.minecraft.entity.monster.EntitySkeleton import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.collections.set diff --git a/src/main/kotlin/me/odinmain/features/impl/nether/BuildHelper.kt b/src/main/kotlin/me/odinmain/features/impl/nether/BuildHelper.kt index 408dc93fa..1a33b0ad6 100644 --- a/src/main/kotlin/me/odinmain/features/impl/nether/BuildHelper.kt +++ b/src/main/kotlin/me/odinmain/features/impl/nether/BuildHelper.kt @@ -1,13 +1,15 @@ package me.odinmain.features.impl.nether -import com.github.stivais.ui.color.Color import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting import me.odinmain.utils.addVec import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.KuudraUtils import me.odinmain.utils.skyblock.PlayerUtils +import me.odinmain.utils.ui.Colors import net.minecraft.util.Vec3 import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -19,7 +21,7 @@ object BuildHelper : Module( private val buildHelperDraw by BooleanSetting("Render on Ballista", false, description = "Draws the build helper.") private val unfinishedWaypoints by BooleanSetting("Unfinished Waypoints", true, description = "Renders the unfinished piles waypoints.") private val fadeWaypoints by BooleanSetting("Fade Waypoints", true, description = "Fades the waypoints when close to them.") - private val buildHelperColor by ColorSetting("Build Helper Color", Color.MINECRAFT_GOLD, description = "Color of the build helper.") + private val buildHelperColor by ColorSetting("Build Helper Color", Colors.MINECRAFT_GOLD, description = "Color of the build helper.") /*private val hud by HudSetting("Build helper HUD", 10f, 10f, 1f, true) { if (it) { text("Build §c50§8%", 1f, 9f, buildHelperColor, 12f, OdinFont.REGULAR, shadow = true) @@ -42,7 +44,7 @@ object BuildHelper : Module( @SubscribeEvent fun renderWorldEvent(event: RenderWorldLastEvent) { if (!KuudraUtils.inKuudra || KuudraUtils.phase != 2) return - if (stunNotification && KuudraUtils.buildDonePercentage > stunNotificationNumber) PlayerUtils.alert("§lGo to stun", playSound = false, color = Color.MINECRAFT_AQUA) + if (stunNotification && KuudraUtils.buildDonePercentage > stunNotificationNumber) PlayerUtils.alert("§lGo to stun", playSound = false, color = Colors.MINECRAFT_AQUA) if (buildHelperDraw) Renderer.drawStringInWorld("Build ${colorBuild(KuudraUtils.buildDonePercentage)}%", Vec3(-101.5, 84.0, -105.5), buildHelperColor, depth = false, scale = 0.15f) @@ -55,7 +57,7 @@ object BuildHelper : Module( private fun renderUnfinishedWaypoints() { KuudraUtils.buildingPiles.forEach { - Renderer.drawCustomBeacon(it.name, it.positionVector.addVec(0.5), Color.MINECRAFT_DARK_RED, true, increase = false, noFade = !fadeWaypoints, distance = false) + Renderer.drawCustomBeacon(it.name, it.positionVector.addVec(0.5), Colors.MINECRAFT_DARK_RED, true, increase = false, noFade = !fadeWaypoints, distance = false) } } diff --git a/src/main/kotlin/me/odinmain/features/impl/nether/EnrageDisplay.kt b/src/main/kotlin/me/odinmain/features/impl/nether/EnrageDisplay.kt index 2ba912739..524cf29a6 100644 --- a/src/main/kotlin/me/odinmain/features/impl/nether/EnrageDisplay.kt +++ b/src/main/kotlin/me/odinmain/features/impl/nether/EnrageDisplay.kt @@ -1,17 +1,14 @@ package me.odinmain.features.impl.nether -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.constraints.px -import com.github.stivais.ui.transforms.Transforms -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.dsl.seconds +import com.github.stivais.aurora.transforms.impl.Alpha import me.odinmain.events.impl.PacketReceivedEvent import me.odinmain.events.impl.RealServerTick import me.odinmain.features.Module import me.odinmain.features.settings.impl.BooleanSetting import me.odinmain.features.settings.impl.SelectorSetting import me.odinmain.utils.skyblock.skyblockID -import me.odinmain.utils.ui.TextHUD -import me.odinmain.utils.ui.and import net.minecraft.network.play.server.S29PacketSoundEffect import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -23,20 +20,20 @@ object EnrageDisplay : Module( private val showUnit by BooleanSetting("Show unit", default = false) // test - private val animation = Transforms.Alpha.Animated(from = 0f, to = 1f) + private val animation = Alpha.Animated(from = 0f, to = 1f) - private val HUD = TextHUD("Enrage Display") { color, font -> - if (!preview) transform(animation) - text( - "Enrage ", - color = color, - font = font, - size = 30.px - ) and text({ getDisplay(if (preview) 120 else enrageTimer) }, font = font) - }.registerSettings( - ::unit, - ::showUnit - ).setting("Displays the duration on screen.") +// private val HUD = TextHUD("Enrage Display") { color, font -> +// if (!preview) transform(animation) +// text( +// "Enrage ", +// color = color, +// font = font, +// size = 30.px +// ) and text({ getDisplay(if (preview) 120 else enrageTimer) }, font = font) +// }.registerSettings( +// ::unit, +// ::showUnit +// ).setting("Displays the duration on screen.") private fun getDisplay(ticks: Int): String { return when (unit) { @@ -57,7 +54,7 @@ object EnrageDisplay : Module( mc.thePlayer?.getCurrentArmor(2)?.skyblockID == "REAPER_CHESTPLATE" ) { enrageTimer = 120 - animation.animate(0.25.seconds, Animations.EaseOutQuint) + animation.animate(0.25.seconds, Animation.Style.EaseOutQuint) } } } @@ -66,7 +63,7 @@ object EnrageDisplay : Module( fun onTick(event: RealServerTick) { enrageTimer-- if (enrageTimer == 0) { - animation.animate(0.25.seconds, Animations.EaseOutQuint) + animation.animate(0.25.seconds, Animation.Style.EaseOutQuint) } } } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/features/impl/nether/FreshTimer.kt b/src/main/kotlin/me/odinmain/features/impl/nether/FreshTimer.kt index 21f5d77ba..266337573 100644 --- a/src/main/kotlin/me/odinmain/features/impl/nether/FreshTimer.kt +++ b/src/main/kotlin/me/odinmain/features/impl/nether/FreshTimer.kt @@ -1,11 +1,14 @@ package me.odinmain.features.impl.nether -import com.github.stivais.ui.color.Color import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting import me.odinmain.utils.runIn -import me.odinmain.utils.skyblock.* +import me.odinmain.utils.skyblock.KuudraUtils +import me.odinmain.utils.skyblock.modMessage +import me.odinmain.utils.skyblock.partyMessage +import me.odinmain.utils.ui.Colors object FreshTimer : Module( name = "Fresh Timer", @@ -13,8 +16,8 @@ object FreshTimer : Module( ){ private val notifyFresh by BooleanSetting("Notify Fresh", true, description = "Notifies your party when you get fresh timer.") val highlightFresh by BooleanSetting("Highlight Fresh", true, description = "Highlights fresh timer users.") - val highlightFreshColor by ColorSetting("Highlight Fresh Color", Color.MINECRAFT_YELLOW, true, description = "Color of the highlight.").withDependency { highlightFresh } - private val freshTimerHUDColor by ColorSetting("Fresh Timer Color", Color.MINECRAFT_GOLD, true, description = "Color of the fresh timer HUD.") + val highlightFreshColor by ColorSetting("Highlight Fresh Color", Colors.MINECRAFT_YELLOW, true, description = "Color of the highlight.").withDependency { highlightFresh } + private val freshTimerHUDColor by ColorSetting("Fresh Timer Color", Colors.MINECRAFT_GOLD, true, description = "Color of the fresh timer HUD.") /*private val hud by HudSetting("Fresh timer HUD", 10f, 10f, 1f, true) { if (it) { text("Fresh§f: 9s", 1f, 9f, freshTimerHUDColor, 12f, OdinFont.REGULAR, shadow = true) diff --git a/src/main/kotlin/me/odinmain/features/impl/nether/KuudraDisplay.kt b/src/main/kotlin/me/odinmain/features/impl/nether/KuudraDisplay.kt index 409fa7097..88709830e 100644 --- a/src/main/kotlin/me/odinmain/features/impl/nether/KuudraDisplay.kt +++ b/src/main/kotlin/me/odinmain/features/impl/nether/KuudraDisplay.kt @@ -1,15 +1,20 @@ package me.odinmain.features.impl.nether -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting +import me.odinmain.features.settings.impl.SelectorSetting import me.odinmain.utils.addVec import me.odinmain.utils.render.RenderUtils.renderBoundingBox import me.odinmain.utils.render.Renderer import me.odinmain.utils.round -import me.odinmain.utils.skyblock.* +import me.odinmain.utils.skyblock.KuudraUtils import me.odinmain.utils.skyblock.KuudraUtils.kuudraEntity +import me.odinmain.utils.skyblock.LocationUtils +import me.odinmain.utils.skyblock.PlayerUtils import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent diff --git a/src/main/kotlin/me/odinmain/features/impl/nether/PearlWaypoints.kt b/src/main/kotlin/me/odinmain/features/impl/nether/PearlWaypoints.kt index a16c00dd2..8befe05d2 100644 --- a/src/main/kotlin/me/odinmain/features/impl/nether/PearlWaypoints.kt +++ b/src/main/kotlin/me/odinmain/features/impl/nether/PearlWaypoints.kt @@ -1,6 +1,6 @@ package me.odinmain.features.impl.nether -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module import me.odinmain.features.settings.impl.BooleanSetting import me.odinmain.utils.render.Renderer diff --git a/src/main/kotlin/me/odinmain/features/impl/nether/SupplyHelper.kt b/src/main/kotlin/me/odinmain/features/impl/nether/SupplyHelper.kt index 234ae14c0..c672052bc 100644 --- a/src/main/kotlin/me/odinmain/features/impl/nether/SupplyHelper.kt +++ b/src/main/kotlin/me/odinmain/features/impl/nether/SupplyHelper.kt @@ -1,6 +1,6 @@ package me.odinmain.features.impl.nether -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module import me.odinmain.features.impl.nether.NoPre.missing import me.odinmain.features.settings.Setting.Companion.withDependency @@ -11,6 +11,7 @@ import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.KuudraUtils import me.odinmain.utils.skyblock.KuudraUtils.SupplyPickUpSpot import me.odinmain.utils.skyblock.modMessage +import me.odinmain.utils.ui.Colors import net.minecraft.util.Vec3 import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.client.event.RenderWorldLastEvent @@ -23,7 +24,7 @@ object SupplyHelper : Module( description = "Helps with supplies in kuudra." ) { private val suppliesWaypoints by BooleanSetting("Supplies Waypoints", true, description = "Renders the supply waypoints.") - private val supplyWaypointColor by ColorSetting("Supply Waypoint Color", Color.MINECRAFT_YELLOW, true, description = "Color of the supply waypoints.").withDependency { suppliesWaypoints } + private val supplyWaypointColor by ColorSetting("Supply Waypoint Color", Colors.MINECRAFT_YELLOW, true, description = "Color of the supply waypoints.").withDependency { suppliesWaypoints } private val supplyDropWaypoints by BooleanSetting("Supply Drop Waypoints", true, description = "Renders the supply drop waypoints.") private val sendSupplyTime by BooleanSetting("Send Supply Time", true, description = "Sends a message when a supply is collected.") diff --git a/src/main/kotlin/me/odinmain/features/impl/nether/TeamHighlight.kt b/src/main/kotlin/me/odinmain/features/impl/nether/TeamHighlight.kt index fab5ff01d..be2826d76 100644 --- a/src/main/kotlin/me/odinmain/features/impl/nether/TeamHighlight.kt +++ b/src/main/kotlin/me/odinmain/features/impl/nether/TeamHighlight.kt @@ -1,16 +1,19 @@ package me.odinmain.features.impl.nether -import com.github.stivais.ui.color.Color import me.odinmain.features.Module import me.odinmain.features.impl.nether.FreshTimer.highlightFresh import me.odinmain.features.impl.nether.FreshTimer.highlightFreshColor import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting +import me.odinmain.features.settings.impl.SelectorSetting import me.odinmain.utils.render.HighlightRenderer import me.odinmain.utils.render.RenderUtils import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.KuudraUtils import me.odinmain.utils.skyblock.KuudraUtils.kuudraTeammates +import me.odinmain.utils.ui.Colors import net.minecraft.client.entity.EntityOtherPlayerMP import net.minecraft.util.Vec3 import net.minecraftforge.client.event.RenderLivingEvent @@ -26,8 +29,8 @@ object TeamHighlight : Module( private val showHighlight by BooleanSetting("Show highlight", true, description = "Highlights teammates with an outline.") private val showName by BooleanSetting("Show name", true, description = "Highlights teammates with a name tag.") private val depthCheck by BooleanSetting("Depth check", false, description = "Highlights teammates only when they are visible.") - private val outlineColor by ColorSetting("Outline Color", Color.MINECRAFT_DARK_PURPLE, true, description = "Color of the player outline.").withDependency { showHighlight } - private val nameColor by ColorSetting("Name Color", Color.MINECRAFT_LIGHT_PURPLE, true, description = "Color of the name highlight.").withDependency { showName } + private val outlineColor by ColorSetting("Outline Color", Colors.MINECRAFT_DARK_PURPLE, true, description = "Color of the player outline.").withDependency { showHighlight } + private val nameColor by ColorSetting("Name Color", Colors.MINECRAFT_LIGHT_PURPLE, true, description = "Color of the name highlight.").withDependency { showName } init { HighlightRenderer.addEntityGetter({ HighlightRenderer.HighlightType.entries[mode] }) { diff --git a/src/main/kotlin/me/odinmain/features/impl/render/BPSDisplay.kt b/src/main/kotlin/me/odinmain/features/impl/render/BPSDisplay.kt index d5af7fe63..45f913c24 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/BPSDisplay.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/BPSDisplay.kt @@ -1,16 +1,12 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.constraints.px import me.odinmain.events.impl.PacketSentEvent import me.odinmain.features.Module import me.odinmain.features.settings.impl.BooleanSetting import me.odinmain.utils.round -import me.odinmain.utils.ui.TextHUD -import me.odinmain.utils.ui.and import net.minecraft.network.play.client.C07PacketPlayerDigging.Action.START_DESTROY_BLOCK import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent -import kotlin.math.roundToInt import net.minecraft.network.play.client.C07PacketPlayerDigging as PacketPlayerDigging // todo: Fix number going to infinity somehow @@ -20,16 +16,16 @@ object BPSDisplay : Module( ) { private val roundNumber by BooleanSetting("Round number", true, description = "If the number should be rounded.") - private val hud by TextHUD("HUD") { color, font -> - text( - text = "BPS ", - font = font, - color = color, - size = 30.px - ) and text({ if (roundNumber) bps.roundToInt() else bps.round(1) }, font = font) - }.registerSettings( - ::roundNumber - ).setting("Displays the BPS on screen.") +// private val hud by TextHUD("HUD") { color, font -> +// text( +// text = "BPS ", +// font = font, +// color = color, +// size = 30.px +// ) and text({ if (roundNumber) bps.roundToInt() else bps.round(1) }, font = font) +// }.registerSettings( +// ::roundNumber +// ).setting("Displays the BPS on screen.") private var bps = 0.0 get() = field.coerceIn(0.0, 20.0) diff --git a/src/main/kotlin/me/odinmain/features/impl/render/BlockOverlay.kt b/src/main/kotlin/me/odinmain/features/impl/render/BlockOverlay.kt index ed9837072..8600ae511 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/BlockOverlay.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/BlockOverlay.kt @@ -1,9 +1,12 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting +import me.odinmain.features.settings.impl.SelectorSetting import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.getBlockAt import net.minecraft.block.material.Material diff --git a/src/main/kotlin/me/odinmain/features/impl/render/CPSDisplay.kt b/src/main/kotlin/me/odinmain/features/impl/render/CPSDisplay.kt index 6b9b89772..5ed03bcb1 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/CPSDisplay.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/CPSDisplay.kt @@ -1,6 +1,6 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.events.impl.PacketSentEvent import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency diff --git a/src/main/kotlin/me/odinmain/features/impl/render/ClickGUI.kt b/src/main/kotlin/me/odinmain/features/impl/render/ClickGUI.kt index 92246f733..1d18b7eae 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/ClickGUI.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/ClickGUI.kt @@ -1,27 +1,21 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.UI -import com.github.stivais.ui.UIScreen.Companion.open -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.blue -import com.github.stivais.ui.color.green -import com.github.stivais.ui.color.red -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Animatable -import com.github.stivais.ui.constraints.positions.Linked -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.elements.impl.Popup -import com.github.stivais.ui.elements.impl.popup -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.elements.scope.ElementScope -import com.github.stivais.ui.elements.scope.draggable -import com.github.stivais.ui.elements.scope.hoverEffect -import com.github.stivais.ui.renderer.Gradient -import com.github.stivais.ui.utils.animate -import com.github.stivais.ui.utils.loop -import com.github.stivais.ui.utils.radius -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.constraints.impl.measurements.Animatable +import com.github.stivais.aurora.constraints.impl.size.Bounding +import com.github.stivais.aurora.constraints.impl.size.Copying +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.elements.impl.Block.Companion.outline +import com.github.stivais.aurora.elements.impl.Popup +import com.github.stivais.aurora.elements.impl.Scrollable.Companion.scroll +import com.github.stivais.aurora.elements.impl.TextInput.Companion.onTextChanged +import com.github.stivais.aurora.elements.impl.popup +import com.github.stivais.aurora.utils.blue +import com.github.stivais.aurora.utils.green +import com.github.stivais.aurora.utils.loop +import com.github.stivais.aurora.utils.red import kotlinx.coroutines.launch import me.odinmain.OdinMain import me.odinmain.OdinMain.scope @@ -33,7 +27,6 @@ import me.odinmain.features.huds.HUDManager import me.odinmain.features.settings.AlwaysActive import me.odinmain.features.settings.Setting import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.Setting.Renders.Companion.elementWidth import me.odinmain.features.settings.impl.* import me.odinmain.utils.capitalizeFirst import me.odinmain.utils.sendDataToServer @@ -43,14 +36,14 @@ import me.odinmain.utils.skyblock.getChatBreak import me.odinmain.utils.skyblock.modMessage import me.odinmain.utils.ui.lifetimeAnimations import me.odinmain.utils.ui.onHover -import me.odinmain.utils.ui.textInput +import me.odinmain.utils.ui.renderer.NVGRenderer +import me.odinmain.utils.ui.screens.UIScreen.Companion.open import net.minecraft.event.ClickEvent import net.minecraft.util.ChatComponentText import org.lwjgl.input.Keyboard -import kotlin.math.sign @AlwaysActive -object ClickGUI: Module( +object ClickGUI : Module( name = "Click GUI", key = Keyboard.KEY_RSHIFT, description = "Allows you to customize the UI." @@ -67,6 +60,7 @@ object ClickGUI: Module( // make useful someday val updateMessage by SelectorSetting("Update Message", arrayListOf("Full", "Beta", "None")).hide() + // needs own module val devMessages by BooleanSetting("Dev Messages", true, description = "Enables dev messages in chat.").withDependency { DevPlayers.isDev } // make dev-specific modules and put this there val devSize by BooleanSetting("Dev Size", true, description = "Toggles client side dev size.").withDependency { DevPlayers.isDev } private val devWings by BooleanSetting("Dev Wings", false, description = "Toggles client side dev wings.").withDependency { DevPlayers.isDev } @@ -74,45 +68,52 @@ object ClickGUI: Module( private val devSizeX by NumberSetting("Dev Size X", 1f, -1f, 3f, 0.1, description = "X scale of the dev size.").withDependency { DevPlayers.isDev && devSize } private val devSizeY by NumberSetting("Dev Size Y", 1f, -1f, 3f, 0.1, description = "Y scale of the dev size.").withDependency { DevPlayers.isDev && devSize } private val devSizeZ by NumberSetting("Dev Size Z", 1f, -1f, 3f, 0.1, description = "Z scale of the dev size.").withDependency { DevPlayers.isDev && devSize } - - // todo: censored option for textinput, max length, etc idk man its so much work private val passcode by StringSetting("Passcode", "odin", description = "Passcode for dev features.").withDependency { DevPlayers.isDev }.censors() val reset by ActionSetting("Send Dev Data") { scope.launch { - modMessage(sendDataToServer(body = "${mc.thePlayer.name}, [${devWingsColor.red},${devWingsColor.green},${devWingsColor.blue}], [$devSizeX,$devSizeY,$devSizeZ], $devWings, $passcode", "https://tj4yzotqjuanubvfcrfo7h5qlq0opcyk.lambda-url.eu-north-1.on.aws/")) + modMessage( + sendDataToServer( + body = "${mc.thePlayer.name}, [${devWingsColor.red},${devWingsColor.green},${devWingsColor.blue}], [$devSizeX,$devSizeY,$devSizeZ], $devWings, $passcode", + "https://tj4yzotqjuanubvfcrfo7h5qlq0opcyk.lambda-url.eu-north-1.on.aws/" + ) + ) DevPlayers.updateDevs() } }.withDependency { DevPlayers.isDev } - val action by ActionSetting("Open HUD Editor", description = "Opens the HUD Editor, allowing you to reposition HUDs") { - HUDManager.makeHUDEditor().open() + val action by ActionSetting( + "Open HUD Editor", + description = "Opens the HUD Editor, allowing you to reposition HUDs" + ) { + open(HUDManager.makeHUDEditor()) } - private val panelSettings by MapSetting("panel.data", mutableMapOf()).also { setting -> - Category.entries.forEach { setting.value[it] = PanelData(x = 10f + 260f * it.ordinal, y = 10f, extended = true) } + val panelSettings by MapSetting("panel.data", mutableMapOf()).also { setting -> + Category.entries.forEach { + setting.value[it] = PanelData(x = 10f + 260f * it.ordinal, y = 10f, extended = true) + } } private var joined by BooleanSetting("first.join", false).hide() - private var warned by BooleanSetting("ui.branch.warning", false).hide() var lastSeenVersion by StringSetting("last.seen.version", "1.0.0").hide() /** - * @see ColorSetting.favoriteColors + * Used in [ColorSetting]. */ val favoriteColors by ListSetting("favorite.colors", mutableListOf()) var firstTimeOnVersion = false init { - // todo: cleanup execute(250) { if (joined) destroyExecutor() if (!LocationUtils.isInSkyblock) return@execute joined = true Config.save() - modMessage(""" + modMessage( + """ ${getChatBreak()} §d§kOdinOnTopWeLoveOdinLiterallyTheBestModAAAAAAAAAAAAAAAA @@ -122,18 +123,21 @@ object ClickGUI: Module( §7Use §d§l/od help §r§7for all of of the commands. §7Join the discord for support and suggestions. - """.trimIndent(), "") + """.trimIndent(), "" + ) mc.thePlayer.addChatMessage( ChatComponentText(" §9https://discord.gg/2nCbC9hkxT") .setChatStyle(createClickStyle(ClickEvent.Action.OPEN_URL, "https://discord.gg/2nCbC9hkxT")) ) - modMessage(""" + modMessage( + """ §d§kOdinOnTopWeLoveOdinLiterallyTheBestModAAAAAAAAAAAAAAAA ${getChatBreak()} - """.trimIndent(), "") + """.trimIndent(), "" + ) } } @@ -154,19 +158,20 @@ object ClickGUI: Module( @JvmField val `gray 38`: Color = Color.RGB(38, 38, 38) - fun clickGUI() = UI { - elementWidth = 240.px + fun clickGUI() = Aurora(renderer = NVGRenderer) { // used for search bar to not require iterating over all elements - val moduleElements = arrayListOf>() + val moduleElements = arrayListOf>>() + onRemove { Config.save() HUDManager.UI?.close() HUDManager.setupHUDs() } + for (panel in Category.entries) { val data = panelSettings[panel] ?: throw NullPointerException("This should never happen") - column(at(x = data.x.px, y = data.y.px)) { + column(constrain(x = data.x.px, y = data.y.px, Bounding, Bounding)) { onRemove { data.x = element.x data.y = element.y @@ -175,29 +180,34 @@ object ClickGUI: Module( val height = Animatable(from = Bounding, to = 0.px, swapIf = !data.extended) // panel header - val header = block( + block( size(240.px, 40.px), color = `gray 26`, radius = radius(tl = 5, tr = 5) ) { text( - text = panel.name.capitalizeFirst(), + string = panel.name.capitalizeFirst(), size = 20.px ) onClick(1) { - height.animate(0.5.seconds, Animations.EaseInOutQuint) + height.animate(0.5.seconds, Animation.Style.EaseInOutQuint) + redraw() data.extended = !data.extended; true } - draggable(moves = parent!!) + draggable(moves = element.parent!!, coerce = false) } //---------// // modules // //---------// - val scrollable = scrollable { + val scrollable = scrollable(size(Bounding, Bounding)) { column(size(h = height)) { - background(color = Color.RGB(38, 38, 38, 0.7f)) - for (module in ModuleManager.modules.sortedByDescending { ui.renderer.textWidth(it.name, 16f) }) { + // bg + block( + copies(), + color = Color.RGB(38, 38, 38, 0.7f) + ) + for (module in ModuleManager.modules) { if (module.category != panel) continue val it = module(module) moduleElements.add(module to it) @@ -212,14 +222,14 @@ object ClickGUI: Module( ) // used for smoother transition between header and modules when they're scrolled - block( - constrain(y = Linked(header.element), w = 240.px, h = 3.px), - colors = `gray 26` to Color.TRANSPARENT, - gradient = Gradient.TopToBottom - ) +// block( +// constrain(y = Linked(header.element), w = 240.px, h = 3.px), +// colors = `gray 26` to Color.TRANSPARENT, +// gradient = Gradient.TopToBottom +// ) onScroll { (amount) -> - scrollable.scroll(amount.sign * 30f) + scrollable.scroll(amount * 75f, style = Animation.Style.EaseOutQuint) true } } @@ -228,124 +238,129 @@ object ClickGUI: Module( //------------// // search bar // //------------// - block(constrain(y = 80.percent, w = 25.percent, h = 5.percent), color = `gray 38`, radius = 10.radius()) { - textInput(placeholder = "Search") { (str) -> - moduleElements.loop { (module, element) -> - element.enabled = module.name.contains(str, true) + block( + constrain(x = 40.percent, y = 90.percent, w = 20.percent, 4.percent), + color = `gray 26`, + radius = 10.radius() + ) { + outline( + this@ClickGUI.color, + thickness = 2.px, + ) + val input = textInput(placeholder = "Search") { + onTextChanged { (string) -> + moduleElements.loop { (module, element) -> + element.enabled = module.name.contains(string, true) || module.description.contains(string, true) + } + this@Aurora.redraw() } - this@UI.redraw() } onClick { - child(0)!!.focusThis(); true + ui.focus(input.element) } - outline(this@ClickGUI.color, thickness = 2.px) draggable(button = 1) } - lifetimeAnimations(duration = 0.5.seconds, Animations.EaseOutQuint, Animations.EaseInBack) - if (!warned) uiBranchWarning() + lifetimeAnimations(duration = 0.5.seconds, Animation.Style.EaseOutQuint, Animation.Style.EaseInBack) } - private fun ElementDSL.module(module: Module) = column(size(h = Animatable(from = 32.px, to = Bounding))) { - // used to lazily load setting elements, as they're not visible until clicked and most of them go unseen + private fun ElementScope<*>.module(module: Module): ElementScope<*> { var loaded = false - + val height = Animatable(from = 32.px, to = Bounding) val color = Color.Animated(from = `gray 26`, to = this@ClickGUI.color, swapIf = module.enabled) - block( - size(240.px, 32.px), - color = color - ) { - hoverInformation(description = module.description) - hoverEffect(0.1.seconds) - text( - text = module.name, - size = 16.px - ) - onClick { - color.animate(0.15.seconds) - module.toggle(); true - } - onClick(button = 1) { - // load settings if haven't yet - if (!loaded) { - loaded = true - module.settings.loop { - if (!it.hidden && it is Setting.Renders) { - it.apply { - val drawableScope = ElementScope(it.Drawable()) - drawableScope.hoverInformation(it.description) - this@column.create(drawableScope).create() + return column(size(w = 240.px, h = height)) { + block( + size(Copying, 32.px), + color + ) { + hoverEffect(factor = 1.2f, style = Animation.Style.Linear) + text( + string = module.name, + size = 50.percent + ) + hoverInformation( + description = module.description + ) + onClick { + color.animate(0.15.seconds, Animation.Style.Linear) + module.toggle() + } + onClick(button = 1) { _ -> + if (!loaded) { + loaded = true + module.settings.loop { setting -> + if (!setting.hidden && setting is Setting.Renders) { + this@column.scope(setting.Drawable()) { + hoverInformation( + description = setting.description + ) + setting.apply { create() } + } } } } + height.animate(0.25.seconds, Animation.Style.EaseInOutQuint) redraw() + true } - parent()!!.height.animate(0.25.seconds, Animations.EaseOutQuint); true } } } - fun ElementDSL.hoverInformation(description: String) { + fun ElementScope<*>.hoverInformation(description: String) { if (description.isEmpty()) return + val lines = arrayListOf() + var lastIndex = 0 + var spaces = 0 + for (index in description.indices) { + if (description[index] == ' ') { + spaces++ + } + if (spaces == 5 || index == description.lastIndex) { + lines.add(description.substring(lastIndex, index + 1)) + lastIndex = index + 1 + spaces = 0 + } + } + var popup: Popup? = null onHover(duration = 1.seconds) { if (popup != null) return@onHover - val x = if (element.x >= ui.main.width / 2f) (element.x - 5).px.alignRight else (element.x + element.width + 5).px - val y = (element.y + 5).px + val it = element + val x = if (it.x >= ui.main.width / 2f) (it.x - 10).px.alignRight else (it.x + it.width + 10).px + val y = (it.y + 5).px popup = popup(constrain(x, y, Bounding, Bounding), smooth = true) { block( - constraints = constrain(0.px, 0.px, Bounding + 10.px, 30.px), + constraints = bounds(padding = 7.5.px), color = `gray 38`, radius = 5.radius() ) { outline(this@ClickGUI.color, 2.px) - text(description, pos = at(x = 6.px)) + column { + lines.loop { + text( + string = it, + size = 15.px + ) + } + } } } - } - onMouseExit { - popup?.let { - it.closePopup() - popup = null - } - } - } - - - // for ui branch warning - private fun ElementDSL.uiBranchWarning() { - popup(copies(), smooth = true) { - column(size(Bounding + 50.px, Bounding + 10.px), padding = 5.px) { - // background - block(copies(), color = `gray 38`, radius = 10.radius()).outline(this@ClickGUI.color, thickness = 3.px) - - divider(15.px) - text("WARNING", size = 30.px) - - text("You are using an extremely unstable branch that shouldn't be unintentionally used.", size = 20.px) - text("If you downloaded this from GitHub Actions, ensure you don't download from the ui branch accidentally.", size = 20.px) - - divider(10.px) - block(size(Bounding + 30.px, Bounding + 10.px), this@ClickGUI.color, radius = 5.radius()) { - text("I understand", size = 25.px) - hoverEffect(0.1.seconds) - onClick { - closePopup() - warned = true; true - } + onMouseExit { + popup?.let { + it.closePopup() + popup = null } } - onMouseEnter { /* silly way to artificially stop inputs */ } } } data class PanelData(var x: Float, var y: Float, var extended: Boolean) { val defaultX = x val defaultY = y - val defaultExtended = extended } -} \ No newline at end of file +} diff --git a/src/main/kotlin/me/odinmain/features/impl/render/CustomHighlight.kt b/src/main/kotlin/me/odinmain/features/impl/render/CustomHighlight.kt index 273b1438e..e315d1688 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/CustomHighlight.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/CustomHighlight.kt @@ -1,13 +1,14 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.OdinMain.isLegitVersion import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency import me.odinmain.features.settings.impl.* import me.odinmain.utils.isOtherPlayer -import me.odinmain.utils.render.* +import me.odinmain.utils.render.HighlightRenderer +import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils import net.minecraft.client.entity.EntityOtherPlayerMP import net.minecraft.entity.Entity diff --git a/src/main/kotlin/me/odinmain/features/impl/render/DVD.kt b/src/main/kotlin/me/odinmain/features/impl/render/DVD.kt index 1ada39eef..de5038a27 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/DVD.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/DVD.kt @@ -1,8 +1,10 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.NumberSetting +import me.odinmain.features.settings.impl.StringSetting import me.odinmain.utils.render.RenderUtils.bind import me.odinmain.utils.skyblock.PlayerUtils import me.odinmain.utils.skyblock.modMessage diff --git a/src/main/kotlin/me/odinmain/features/impl/render/DevPlayers.kt b/src/main/kotlin/me/odinmain/features/impl/render/DevPlayers.kt index 86f4ae8bb..bca14a29b 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/DevPlayers.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/DevPlayers.kt @@ -1,6 +1,9 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.color.* +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.blue +import com.github.stivais.aurora.utils.green +import com.github.stivais.aurora.utils.red import com.google.gson.* import kotlinx.coroutines.* import me.odinmain.OdinMain.mc diff --git a/src/main/kotlin/me/odinmain/features/impl/render/DragonHitboxes.kt b/src/main/kotlin/me/odinmain/features/impl/render/DragonHitboxes.kt index 2813ae9e1..0333cb851 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/DragonHitboxes.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/DragonHitboxes.kt @@ -1,8 +1,10 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils import net.minecraft.entity.boss.EntityDragon diff --git a/src/main/kotlin/me/odinmain/features/impl/render/NameChanger.kt b/src/main/kotlin/me/odinmain/features/impl/render/NameChanger.kt index e70bf1b6b..df191b1f8 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/NameChanger.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/NameChanger.kt @@ -10,7 +10,7 @@ object NameChanger : Module( name = "Name Changer", description = "Replaces your name with the given nick, color codes work (&)." ) { - private val nick by StringSetting("Nick", "Odin", 32, description = "The nick to replace your name with.") + private val nick by StringSetting("Nick", "Odin", length = 32, placeholder = "Name", description = "The nick to replace your name with.") @JvmStatic fun modifyString(string: String?): String? { diff --git a/src/main/kotlin/me/odinmain/features/impl/render/PersonalDragon.kt b/src/main/kotlin/me/odinmain/features/impl/render/PersonalDragon.kt index 607679224..e77701a3a 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/PersonalDragon.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/PersonalDragon.kt @@ -1,11 +1,13 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.blue -import com.github.stivais.ui.color.green -import com.github.stivais.ui.color.red +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.blue +import com.github.stivais.aurora.utils.green +import com.github.stivais.aurora.utils.red import me.odinmain.features.Module -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting import me.odinmain.utils.render.RenderUtils.renderX import me.odinmain.utils.render.RenderUtils.renderY import me.odinmain.utils.render.RenderUtils.renderZ diff --git a/src/main/kotlin/me/odinmain/features/impl/render/ServerHud.kt b/src/main/kotlin/me/odinmain/features/impl/render/ServerHud.kt index c5801be49..2513fe24c 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/ServerHud.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/ServerHud.kt @@ -2,40 +2,36 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.constraints.px import me.odinmain.features.Module -import me.odinmain.utils.ServerUtils -import me.odinmain.utils.ui.TextHUD -import me.odinmain.utils.ui.and object ServerHud : Module( name = "Performance Display", description = "Displays certain performance-related metrics, like ping, TPS and FPS." ) { - private val fpsHUD by TextHUD("FPS") { color, font -> - text( - text = "FPS ", - color = color, - size = 30.px - ) and text({ getFPS() }, font = font) - }.setting("Display's your fps on screen.") - - private val pingHUD by TextHUD("Ping") { color, font -> - text( - text = "FPS ", - color = color, - size = 30.px - ) and text({ ServerUtils.averagePing.toInt() }, font = font) - }.setting("Display's your ping on screen.") - - private val tpsHUD by TextHUD("TPS") { color, font -> - text( - text = "TPS ", - color = color, - size = 30.px, - font = font, - ) and text({ ServerUtils.averageTps.toInt() }, font = font) - }.setting("Display's your tps on screen.") +// private val fpsHUD by TextHUD("FPS") { color, font -> +// text( +// text = "FPS ", +// color = color, +// size = 30.px +// ) and text({ getFPS() }, font = font) +// }.setting("Display's your fps on screen.") +// +// private val pingHUD by TextHUD("Ping") { color, font -> +// text( +// text = "FPS ", +// color = color, +// size = 30.px +// ) and text({ ServerUtils.averagePing.toInt() }, font = font) +// }.setting("Display's your ping on screen.") +// +// private val tpsHUD by TextHUD("TPS") { color, font -> +// text( +// text = "TPS ", +// color = color, +// size = 30.px, +// font = font, +// ) and text({ ServerUtils.averageTps.toInt() }, font = font) +// }.setting("Display's your tps on screen.") fun getFPS() = mc.debug.split(" ")[0].toIntOrNull() ?: 0 } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/features/impl/render/WaypointManager.kt b/src/main/kotlin/me/odinmain/features/impl/render/WaypointManager.kt index 50bef71ca..bad21326c 100644 --- a/src/main/kotlin/me/odinmain/features/impl/render/WaypointManager.kt +++ b/src/main/kotlin/me/odinmain/features/impl/render/WaypointManager.kt @@ -1,11 +1,12 @@ package me.odinmain.features.impl.render -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.utils.clock.Clock import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.Island import me.odinmain.utils.skyblock.LocationUtils.currentArea import me.odinmain.utils.skyblock.modMessage +import me.odinmain.utils.ui.Colors import net.minecraft.util.Vec3 import net.minecraft.util.Vec3i import net.minecraftforge.client.event.RenderWorldLastEvent @@ -13,9 +14,6 @@ import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.math.abs -// TODO: Make changes cuz ngl its kinda eh (eg: good ordered waypoints for mining so people dont need to use ct) -// TODO: Make all waypoint areas constant and make LocationUtils use locraw -// this is o object WaypointManager { private var temporaryWaypoints = mutableListOf>() @@ -30,8 +28,8 @@ object WaypointManager { } private val colors = listOf( - Color.MINECRAFT_GOLD, Color.GREEN, Color.MINECRAFT_LIGHT_PURPLE, Color.MINECRAFT_AQUA, Color.MINECRAFT_YELLOW, Color.MINECRAFT_DARK_RED, Color.WHITE, - Color.MINECRAFT_YELLOW, Color.RED, Color.MINECRAFT_DARK_GREEN, Color.BLUE, Color.MINECRAFT_DARK_PURPLE + Colors.MINECRAFT_GOLD, Color.GREEN, Colors.MINECRAFT_LIGHT_PURPLE, Colors.MINECRAFT_AQUA, Colors.MINECRAFT_YELLOW, Colors.MINECRAFT_DARK_RED, Color.WHITE, + Colors.MINECRAFT_YELLOW, Color.RED, Colors.MINECRAFT_DARK_GREEN, Color.BLUE, Colors.MINECRAFT_DARK_PURPLE ) fun addTempWaypoint(name: String = "§fWaypoint", vec3: Vec3i) { diff --git a/src/main/kotlin/me/odinmain/features/impl/skyblock/DianaHelper.kt b/src/main/kotlin/me/odinmain/features/impl/skyblock/DianaHelper.kt index 6cd2fa5e3..77c45a3f6 100644 --- a/src/main/kotlin/me/odinmain/features/impl/skyblock/DianaHelper.kt +++ b/src/main/kotlin/me/odinmain/features/impl/skyblock/DianaHelper.kt @@ -1,17 +1,20 @@ package me.odinmain.features.impl.skyblock -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.OdinMain.isLegitVersion import me.odinmain.events.impl.ClickEvent import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency import me.odinmain.features.settings.impl.* -import me.odinmain.utils.* +import me.odinmain.utils.addVec import me.odinmain.utils.clock.Clock +import me.odinmain.utils.findNearestGrassBlock import me.odinmain.utils.render.Renderer +import me.odinmain.utils.runIn import me.odinmain.utils.skyblock.* import me.odinmain.utils.skyblock.DianaBurrowEstimate.activeBurrows +import me.odinmain.utils.toVec3 import net.minecraft.network.play.client.C07PacketPlayerDigging import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement import net.minecraft.network.play.server.S29PacketSoundEffect diff --git a/src/main/kotlin/me/odinmain/features/impl/skyblock/GyroWand.kt b/src/main/kotlin/me/odinmain/features/impl/skyblock/GyroWand.kt index 7a911d883..31f22f78c 100644 --- a/src/main/kotlin/me/odinmain/features/impl/skyblock/GyroWand.kt +++ b/src/main/kotlin/me/odinmain/features/impl/skyblock/GyroWand.kt @@ -1,15 +1,20 @@ package me.odinmain.features.impl.skyblock -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting import me.odinmain.utils.clock.Clock import me.odinmain.utils.render.Renderer -import me.odinmain.utils.skyblock.* +import me.odinmain.utils.skyblock.EtherWarpHelper import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getAbilityCooldown +import me.odinmain.utils.skyblock.isAir +import me.odinmain.utils.skyblock.isHolding import me.odinmain.utils.toVec3 +import me.odinmain.utils.ui.Colors import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -17,7 +22,7 @@ object GyroWand : Module( name = "Gyro Wand", description = "Helpful features for the Gyrokinetic Wand." ) { - private val color by ColorSetting("Color", Color.MINECRAFT_DARK_PURPLE.withAlpha(0.5f), allowAlpha = true, description = "The color of the Gyrokinetic Wand range.") + private val color by ColorSetting("Color", Colors.MINECRAFT_DARK_PURPLE.withAlpha(0.5f), allowAlpha = true, description = "The color of the Gyrokinetic Wand range.") private val thickness by NumberSetting("Thickness", 0.4f, 0, 10, 0.05f, description = "The thickness of the Gyrokinetic Wand range.") private val steps by NumberSetting("Smoothness", 40, 20, 80, 1, description = "The amount of steps to use when rendering the Gyrokinetic Wand range.") private val showCooldown by BooleanSetting("Show Cooldown", true, description = "Shows the cooldown of the Gyrokinetic Wand.") diff --git a/src/main/kotlin/me/odinmain/features/impl/skyblock/ItemsHighlight.kt b/src/main/kotlin/me/odinmain/features/impl/skyblock/ItemsHighlight.kt index 7bb05d6ac..f9fe65365 100644 --- a/src/main/kotlin/me/odinmain/features/impl/skyblock/ItemsHighlight.kt +++ b/src/main/kotlin/me/odinmain/features/impl/skyblock/ItemsHighlight.kt @@ -1,16 +1,21 @@ package me.odinmain.features.impl.skyblock -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.features.Module import me.odinmain.features.settings.Setting.Companion.withDependency -import me.odinmain.features.settings.impl.* +import me.odinmain.features.settings.impl.BooleanSetting +import me.odinmain.features.settings.impl.ColorSetting +import me.odinmain.features.settings.impl.NumberSetting +import me.odinmain.features.settings.impl.SelectorSetting import me.odinmain.utils.containsOneOf -import me.odinmain.utils.render.* +import me.odinmain.utils.render.HighlightRenderer +import me.odinmain.utils.render.Renderer import me.odinmain.utils.skyblock.dungeon.DungeonUtils.dungeonItemDrops import me.odinmain.utils.skyblock.getRarity import me.odinmain.utils.skyblock.lore import me.odinmain.utils.skyblock.unformattedName +import me.odinmain.utils.ui.Colors import net.minecraft.entity.item.EntityItem object ItemsHighlight : Module( @@ -47,7 +52,7 @@ object ItemsHighlight : Module( return when (colorStyle){ 0 -> getRarity(entity.entityItem.lore)?.color ?: Color.WHITE 1 -> { - if (entity.ticksExisted <= 11) Color.MINECRAFT_YELLOW + if (entity.ticksExisted <= 11) Colors.MINECRAFT_YELLOW else if (entity.getDistanceToEntity(mc.thePlayer) <= 3.5) Color.GREEN else Color.RED } diff --git a/src/main/kotlin/me/odinmain/features/impl/skyblock/SpringBoots.kt b/src/main/kotlin/me/odinmain/features/impl/skyblock/SpringBoots.kt index 9d724d8e4..97d9153c4 100644 --- a/src/main/kotlin/me/odinmain/features/impl/skyblock/SpringBoots.kt +++ b/src/main/kotlin/me/odinmain/features/impl/skyblock/SpringBoots.kt @@ -1,6 +1,6 @@ package me.odinmain.features.impl.skyblock -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.Module import me.odinmain.features.settings.impl.BooleanSetting import me.odinmain.features.settings.impl.ColorSetting diff --git a/src/main/kotlin/me/odinmain/features/settings/Setting.kt b/src/main/kotlin/me/odinmain/features/settings/Setting.kt index 2b86be7cd..0d04dd009 100644 --- a/src/main/kotlin/me/odinmain/features/settings/Setting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/Setting.kt @@ -1,23 +1,19 @@ package me.odinmain.features.settings -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.constraints.Size -import com.github.stivais.ui.constraints.measurements.Animatable -import com.github.stivais.ui.constraints.measurements.Pixel -import com.github.stivais.ui.constraints.px -import com.github.stivais.ui.constraints.size -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.constraints.sizes.Copying -import com.github.stivais.ui.elements.Element -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.elements.scope.LayoutScope -import com.github.stivais.ui.events.Event -import com.github.stivais.ui.transforms.Transforms -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.constraints.Constraint +import com.github.stivais.aurora.constraints.impl.measurements.Animatable +import com.github.stivais.aurora.constraints.impl.positions.Center +import com.github.stivais.aurora.constraints.impl.size.Bounding +import com.github.stivais.aurora.constraints.impl.size.Copying +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.Element +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.events.AuroraEvent +import com.github.stivais.aurora.transforms.impl.Alpha import com.google.gson.Gson import com.google.gson.GsonBuilder import me.odinmain.features.Module -import me.odinmain.features.settings.Setting.Renders.Companion.elementWidth import kotlin.properties.PropertyDelegateProvider import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty @@ -102,34 +98,25 @@ abstract class Setting ( interface Renders { - fun ElementDSL.create() + fun ElementScope<*>.create() companion object { /** - * Creates a group (or column) with the current width needed according the UIs it's used in. + * Creates a group with the current width needed according the UIs it's used in. */ - fun ElementDSL.setting( - height: Size = 40.px, - scope: ElementDSL.() -> Unit + fun ElementScope<*>.setting( + height: Constraint.Size = 40.px, + scope: ElementScope<*>.() -> Unit ) { - group(size(Copying, height), scope) + group( + size(Copying, height), + scope + ) } - fun ElementDSL.settingColumn( - height: Size = Bounding, - scope: LayoutScope.() -> Unit - ) { - column(size(Copying, height), null, scope) - } - - /** - * Current width for settings elements inside the UIs it's used in - */ - var elementWidth: Pixel = 240.px - - inline fun ElementDSL.onValueChanged(crossinline block: (ValueUpdated) -> Unit) { + inline fun ElementScope<*>.onValueChanged(crossinline block: (ValueUpdated) -> Unit) { element.registerEvent(ValueUpdated) { - block(this) + block(it) redraw() false } @@ -137,18 +124,16 @@ abstract class Setting ( } - data object ValueUpdated : Event + data object ValueUpdated : AuroraEvent } - inner class Drawable : Element(size(elementWidth, Animatable(from = Bounding, to = 0.px))) { + inner class Drawable : Element(constrain(x = Center, w = 95.percent, h = Animatable(from = Bounding, to = 0.px))) { private var visible = visibilityDependency?.invoke() ?: true -// private var lastValue: T = value - private var lastValue: Int = value.hashCode() - private var alphaAnimation = Transforms.Alpha.Animated(to = 0f, from = 1f) + private var alphaAnimation = Alpha.Animated(to = 0f, from = 1f) init { addTransform(alphaAnimation) @@ -156,19 +141,21 @@ abstract class Setting ( (constraints.height as Animatable).swap() alphaAnimation.swap() } + // calc size instantly + width = constraints.width.calculateSize(this, true) } override fun draw() { if ((visibilityDependency?.invoke() != false) != visible) { visible = !visible - (constraints.height as Animatable).animate(0.25.seconds, Animations.EaseInOutQuint) - alphaAnimation.animate(0.25.seconds, Animations.EaseInOutQuint) - redraw = true + (constraints.height as Animatable).animate(0.25.seconds, Animation.Style.EaseInOutQuint) + alphaAnimation.animate(0.25.seconds, Animation.Style.EaseInOutQuint) + parent!!.redraw = true } val hashCode = value.hashCode() if (lastValue != hashCode) { lastValue = hashCode - ui.eventManager.dispatchToAll(Renders.ValueUpdated, this) + ui.eventManager.postToAll(Renders.ValueUpdated, this) } } } diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/BooleanSetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/BooleanSetting.kt index e0cc8ed7f..d16a53ef2 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/BooleanSetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/BooleanSetting.kt @@ -1,15 +1,13 @@ package me.odinmain.features.settings.impl -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.color -import com.github.stivais.ui.color.darker -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Animatable -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.elements.scope.hoverEffect -import com.github.stivais.ui.utils.radius -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.constraints.impl.measurements.Animatable +import com.github.stivais.aurora.constraints.impl.measurements.Pixel +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.elements.impl.Block.Companion.outline +import com.github.stivais.aurora.utils.color import com.google.gson.JsonElement import com.google.gson.JsonPrimitive import me.odinmain.features.impl.render.ClickGUI @@ -41,41 +39,36 @@ class BooleanSetting( } } - override fun ElementDSL.create() = setting { + override fun ElementScope<*>.create() = setting { text( name, - pos = at(x = 6.px), + pos = at(x = Pixel.ZERO), size = 40.percent ) - val pointer = Animatable(from = 30.percent.center, to = 70.percent.center) - val color = Color.Animated(from = `gray 38`, to = ClickGUI.color) - - if (value) { - pointer.swap() - color.swap() - } + val pointer = Animatable(from = 30.percent, to = 70.percent, swapIf = value) + val color = Color.Animated(from = `gray 38`, to = ClickGUI.color, swapIf = value) block( - constrain(x = -(6.px), w = 35.px, h = 50.percent), + constrain(x = Pixel.ZERO.alignOpposite, w = 35.px, h = 50.percent), color, radius = 10.radius() ) { - onClick { - value = !value - true - } + outline(color = color { ClickGUI.color.rgba }, thickness = 1.5.px) + hoverEffect(factor = 1.25f) + block( - constrain(x = pointer, w = 50.percent, h = 80.percent), + constrain(x = pointer.alignCenter, w = 50.percent, h = 80.percent), color = Color.WHITE, radius = 8.radius() ) - outline(color = color { ClickGUI.color.rgba.darker() }, thickness = 1.5.px) - hoverEffect() + onClick { + value = !value + } } onValueChanged { - color.animate(0.25.seconds, Animations.Linear) - pointer.animate(0.25.seconds, Animations.EaseInOutQuint) + color.animate(0.25.seconds, Animation.Style.EaseInOutQuint) + pointer.animate(0.25.seconds, Animation.Style.EaseInOutQuint) } } } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/ColorSetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/ColorSetting.kt index 7b5772168..417f76449 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/ColorSetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/ColorSetting.kt @@ -1,23 +1,23 @@ package me.odinmain.features.settings.impl -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.color.* -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Animatable -import com.github.stivais.ui.constraints.sizes.AspectRatio -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.constraints.sizes.Copying -import com.github.stivais.ui.elements.impl.Popup -import com.github.stivais.ui.elements.impl.popup -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.elements.scope.LayoutScope -import com.github.stivais.ui.elements.scope.draggable -import com.github.stivais.ui.elements.scope.hoverEffect -import com.github.stivais.ui.renderer.Gradient.LeftToRight -import com.github.stivais.ui.renderer.Gradient.TopToBottom -import com.github.stivais.ui.transforms.Transforms -import com.github.stivais.ui.utils.radius -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.constraints.impl.measurements.Animatable +import com.github.stivais.aurora.constraints.impl.measurements.Pixel +import com.github.stivais.aurora.constraints.impl.positions.Center +import com.github.stivais.aurora.constraints.impl.size.AspectRatio +import com.github.stivais.aurora.constraints.impl.size.Bounding +import com.github.stivais.aurora.constraints.impl.size.Fill +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.elements.Layout.Companion.section +import com.github.stivais.aurora.elements.impl.Block.Companion.outline +import com.github.stivais.aurora.elements.impl.Popup +import com.github.stivais.aurora.elements.impl.layout.Column.Companion.sectionRow +import com.github.stivais.aurora.elements.impl.popup +import com.github.stivais.aurora.renderer.data.Gradient +import com.github.stivais.aurora.transforms.impl.Scale +import com.github.stivais.aurora.utils.* import com.google.gson.JsonElement import com.google.gson.JsonPrimitive import me.odinmain.features.impl.render.ClickGUI.favoriteColors @@ -26,9 +26,7 @@ import me.odinmain.features.settings.Saving import me.odinmain.features.settings.Setting import me.odinmain.features.settings.Setting.Renders.Companion.onValueChanged import me.odinmain.features.settings.Setting.Renders.Companion.setting -import me.odinmain.utils.ui.outline -import me.odinmain.utils.ui.passEvent -import me.odinmain.utils.ui.textInput +import me.odinmain.utils.ui.image import java.awt.Color.HSBtoRGB class ColorSetting( @@ -50,7 +48,7 @@ class ColorSetting( override fun read(element: JsonElement?) { if (element?.asString?.startsWith("#") == true) { - value = colorFrom(element.asString).toHSB() + value = Color.RGB(hexToRGBA(element.asString)).toHSB() } else { element?.asInt?.let { value = Color.RGB(it).toHSB() } } @@ -60,20 +58,20 @@ class ColorSetting( return JsonPrimitive(value.toHexString()) } - override fun ElementDSL.create() = setting(40.px) { + override fun ElementScope<*>.create() = setting(40.px) { text( name, - pos = at(x = 6.px), + pos = at(x = Pixel.ZERO), size = 40.percent ) outline( - constrain(-(6.px), w = 30.px, h = 50.percent), + constrain(x = Pixel.ZERO.alignOpposite, w = 30.px, h = 50.percent), color { value.withAlpha(255).rgba }, thickness = 1.px, radius = 5.radius() ) { block( - constraints = indent(2), + constraints = indent(2f), color = value, radius = 4.radius() ) @@ -90,349 +88,270 @@ class ColorSetting( } } - private fun ElementDSL.colorPicker() = popup(smooth = true) { - val mainColor = color { HSBtoRGB(value.hue, value.saturation, 1f) } - val colorHue = color { HSBtoRGB(value.hue, 1f, 1f) } + private fun ElementScope<*>.colorPicker() = popup(constraints = copies(), smooth = true) { + val colorMaxBrightness = color { HSBtoRGB(value.hue, value.saturation, 1f) } + val colorOnlyHue = color { HSBtoRGB(value.hue, 1f, 1f) } - // used to consume event - onClick { false; } - draggable(button = 1) + onClick { + closePopup( ) + popup = null + } block( - copies(), + size(Bounding + 12.px, Bounding + 12.px), color = Color.RGB(22, 22, 22), radius = 10.radius() ) { - outline( - mainColor, - thickness = 1.px - ) - } - - // padding in constructor doesn't work, ill fix it in rewrite - column(size(Bounding, Bounding)) { - divider(10.px) - //------------------------// - // title and close button // - //------------------------// - section(20.px) { - text( - name, - pos = at(5.percent), - size = 75.percent - ) - image( - "/assets/odinmain/clickgui/close_icon.svg", - constrain(x = 95.percent.alignRight, w = AspectRatio(1f), h = 80.percent) - ) { - onClick { - closePopup() - popup = null - true - } - } - } - divider(7.5.px) + draggable() - row(at(x = 12.5.px)) { - saturationBrightness(mainColor, colorHue) - divider(7.5.px) - hueSlider(mainColor) - if (allowAlpha) { - divider(7.5.px) - alphaSlider(mainColor, colorHue) - } - divider(7.5.px) - } - divider(7.5.px) - hexTextInput(mainColor) - divider(7.5.px) - favoriteColors(mainColor) + // consume event so it doesn't pass to background + // when hovering of any part of the color picker. + onClick { true } - divider(12.5.px) - } - } + // TODO: FIX +// Shadow( +// copies(), +// blur = 5f, +// spread = 5f, +// radii = 10.radius(), +// ).add() - private fun ElementDSL.saturationBrightness(mainColor: Color, colorHue: Color) = outline( - size(w = 175.px, h = 175.px), - mainColor, - thickness = 1.px, - radius = 7.5.radius() - ) { - block( - constraints = indent(2), - colors = Color.WHITE to colorHue, - radius = 6.radius(), - gradient = LeftToRight - ) { - block( - constraints = copies(), - colors = transparentFix to Color.BLACK, - radius = 6.radius(), - gradient = TopToBottom + outline( + colorMaxBrightness, + thickness = 1.px, ) - } - - val pointerX = Animatable.Raw((175 * value.saturation).coerceIn(8f, 167f)) - val pointerY = Animatable.Raw((175 * (1f - value.brightness)).coerceIn(8f, 167f)) - - block( - constrain(pointerX.center, pointerY.center, 10.px, 10.px), - color = value, - radius = 5.radius() - ).outline(Color.WHITE) - - pointerHandler( - pointerX, - pointerY, - apply = { px, py -> - value.saturation = px - value.brightness = 1f - py - }, - block = { - value.saturation to 1f - value.brightness - } - ) - } - - private fun ElementDSL.hueSlider(mainColor: Color) = outline( - size(w = 16.px, h = 175.px), - mainColor, - thickness = 1.px, - radius = 6.radius() - ) { - image( - "/assets/odinmain/clickgui/HueGradient.png", - constraints = indent(2), - radius = 5.radius() - ) - - val pointerY = Animatable.Raw((175 * (1f - value.hue)).coerceIn(8f, 167f)) - - block( - constrain(y = pointerY.center, w = 10.px, h = 10.px), - color = value, - radius = 5.radius() - ).outline(Color.WHITE) - - pointerHandler( - pointerX = null, - pointerY, - apply = { _, py -> - value.hue = 1f - py - }, - block = { - 0f to 1f - value.hue - } - ) - } - private fun ElementDSL.alphaSlider(mainColor: Color, colorHue: Color) = outline( - size(w = 16.px, h = 175.px), - mainColor, - thickness = 1.px, - radius = 6.radius() - ) { - block( - constraints = indent(2), - colors = colorHue to transparentFix, - gradient = TopToBottom, - radius = 5.radius(), - ) - - val pointerY = Animatable.Raw((175 * value.alpha).coerceIn(8f, 167f)) + column(padding = 10.px) { + section(20.px) { + text( + "Color", + pos = at(x = Pixel.ZERO), + size = 75.percent + ) + + image( + "clickgui/close_icon.svg".image(), + constrain(x = Pixel.ZERO.alignOpposite, w = AspectRatio(1f), h = 80.percent) + ) { + onClick { + closePopup() + popup = null + true + } + } + } - block( - constrain(y = pointerY.center, w = 10.px, h = 10.px), - color = value, - radius = 5.radius() - ).outline(Color.WHITE) + row(padding = 7.5.px) { + /** + * Saturation and brightness slider + */ + outline( + size(w = 200.px, h = 200.px), + colorMaxBrightness, + thickness = 1.px, + radius = 7.5.radius() + ) { + block( + indent(amount = 2f), + colors = Color.WHITE to colorOnlyHue, + gradient = Gradient.LeftToRight, + radius = 6.radius() + ) + block( + indent(amount = 2f), + colors = Color.TRANSPARENT to Color.BLACK, + gradient = Gradient.TopToBottom, + radius = 6.radius() + ) + + pointer(onlyY = false) { + value.saturation to 1f - value.brightness + } + onMouseDrag { x, y -> + value.saturation = x + value.brightness = 1f - y + true + } + } - pointerHandler( - pointerX = null, - pointerY, - apply = { _, py -> - value.alpha = 1f - py - }, - block = { - 0f to 1f - value.alpha - } - ) - } + /** + * Hue slider + */ + outline( + size(w = 15.px, h = 200.px), + colorMaxBrightness, + thickness = 1.px, + radius = 7.5.radius() + ) { + image( + "clickgui/HueGradient.png".image(), + constraints = indent(amount = 2f), + radius = 5.radius() + ) + pointer(onlyY = true) { + 0f to 1f - value.hue + } + onMouseDrag { _, y -> + value.hue = 1f - y + true + } + } - /** - * Creates a text input that lets you edit this color via hexadecimal input - */ - private fun LayoutScope.hexTextInput(mainColor: Color) = section(30.px) { - text( - "Hex", - pos = at(x = 5.percent), - ) - block( - constrain(x = 95.5.percent.alignRight, w = 70.percent, h = 90.percent), - color = `gray 38`, - radius = 6.radius() - ) { - hoverEffect(0.25.seconds) - outline( - mainColor, - thickness = 1.px - ) - val input = textInput( - default = value.toHexString(), - pos = at(x = 5.percent), - onTextChange = { event -> - val str = event.string - val hexLength = if (allowAlpha) 9 else 7 - // Validate hex input - if (str.length > hexLength || (str.isNotEmpty() && !str.startsWith("#")) || (str.length > 1 && !str.substring(1).all { it.isDigit() || it.lowercaseChar() in 'a'..'f' })) { - event.cancel() - } else if (str.length == hexLength) { - try { - // Parse and update color from hex immediately - val newColor = colorFrom(str).toHSB() - value.hue = newColor.hue - value.saturation = newColor.saturation - value.brightness = newColor.brightness - if (allowAlpha) { - value.alpha = newColor.alpha + /** + * Alpha slider + */ + if (allowAlpha) { + outline( + size(w = 15.px, h = 200.px), + colorMaxBrightness, + thickness = 1.px, + radius = 7.5.radius() + ) { + block( + constraints = indent(2f), + colors = colorOnlyHue to Color.TRANSPARENT, + gradient = Gradient.TopToBottom, + radius = 5.radius(), + ) + + pointer(onlyY = true) { + 0f to 1f - value.alpha } - } catch (_: Exception) {} - } - } - ).apply { - onValueChanged { - this@apply.string = value.toHexString() - } - onFocusLost { - if (this@apply.string.length != (if (allowAlpha) 9 else 7)) { - this@apply.string = value.toHexString() + onMouseDrag { _, y -> + value.alpha = 1f - y + true + } + } } } - } - onClick { - input.focusThis() - true - } - } - } - /** - * Lets you favorite colors, so you can reuse them for other settings - */ - private fun LayoutScope.favoriteColors(mainColor: Color) = row(constrain(x = 12.5.px, w = Copying)) { - block( - size(w = 12.5.percent, h = AspectRatio(1f)), - color = `gray 38`, - radius = 6.radius() - ) { - hoverEffect(0.25.seconds) - outline(mainColor) - - // for "pulse" effect - var clicked = false - val transform = Transforms.Scale.Animated(from = 1f, to = 0.9f,) - image( - "/assets/odinmain/clickgui/heart_icon.svg", - constraints = size(70.percent, 70.percent), - ).transform(transform) - - onClick { - if (!favoriteColors.contains(value)) { - if (favoriteColors.size == 5) favoriteColors.removeLast() - favoriteColors.add(0, Color.HSB(value)) - } - clicked = true - transform.animate(0.1.seconds, Animations.EaseInQuint) - true - } - onRelease { - if (clicked) { - transform.animate(0.15.seconds, Animations.EaseInQuint) - clicked = false + /** + * Hex input + */ + sectionRow(size = 25.px, padding = 10.px) { + text( + "Hex", + pos = at(y = Center), + size = 65.percent, + ) + block( + size(w = Fill, h = 90.percent), + color = `gray 38`, + radius = 6.radius() + ) { + outline( + colorMaxBrightness, + thickness = 1.px, + ) + } } - } - } - repeat(5) { index -> - divider(3.percent) + /** + * Favourite colors. + */ + sectionRow(padding = 3.percent) { + block( + size(w = 14.percent, h = AspectRatio(1f)), + color = Color.RGB(22, 22, 22), + radius = 6.radius() + ) { + outline( + colorMaxBrightness, + thickness = 1.px, + ) + + var clicked = false + val transform = Scale.Animated(from = 1f, to = 0.9f) + + image( + "clickgui/heart_icon.svg".image(), + constraints = size(70.percent, 70.percent), + ).transform(transform) + + onClick { + if (!favoriteColors.contains(value)) { + if (favoriteColors.size == 5) favoriteColors.removeLast() + favoriteColors.add(0, Color.HSB(value)) + } + clicked = true + transform.animate(0.1.seconds, Animation.Style.EaseInQuint) + true + } + onRelease { + if (clicked) { + transform.animate(0.15.seconds, Animation.Style.EaseInQuint) + clicked = false + } + } + } - block( - size(w = 12.5.percent, h = AspectRatio(1f)), - color = Color.RGB(22, 22, 22), - radius = 6.radius() - ) { - outline( - color { (favoriteColors.getOrNull(index) ?: `gray 38`).rgba } - ) - block( - indent(2), - color { (favoriteColors.getOrNull(index) ?: Color.TRANSPARENT).rgba }, - radius = 5.radius() - ) - onClick { - val favoriteColor = favoriteColors.getOrNull(index) - if (favoriteColor != null) { - value.hue = favoriteColor.hue - value.saturation = favoriteColor.saturation - value.brightness = favoriteColor.brightness - if (allowAlpha) value.alpha = favoriteColor.alpha + repeat(5) { index -> + block( + size(w = 14.percent, h = AspectRatio(1f)), + color = Color.RGB(22, 22, 22), + radius = 6.radius() + ) { + outline( + color { (favoriteColors.getOrNull(index) ?: `gray 38`).rgba }, + thickness = 1.px + ) + block( + indent(2f), + color { (favoriteColors.getOrNull(index) ?: Color.TRANSPARENT).rgba }, + radius = 5.radius() + ) + onClick { + val favoriteColor = favoriteColors.getOrNull(index) + if (favoriteColor != null) { + value.hue = favoriteColor.hue + value.saturation = favoriteColor.saturation + value.brightness = favoriteColor.brightness + if (allowAlpha) value.alpha = favoriteColor.alpha + } + true + } + onClick(button = 1) { + if (favoriteColors.size - 1 >= index) { + favoriteColors.removeAt(index) + } + true + } + } } - true } } } } - - /** - * Utility for making sliders - */ - private inline fun ElementDSL.pointerHandler( - pointerX: Animatable.Raw?, - pointerY: Animatable.Raw?, - crossinline apply: (px: Float, py: Float) -> Unit, - crossinline block: () -> Pair + private inline fun ElementScope<*>.pointer( + onlyY: Boolean, + crossinline block: () -> Pair, ) { - var first = false - var dragging = false + val (sx, sy) = block() + val pointerX = if (onlyY) null else Animatable.Raw((sx * 200f).coerceIn(8f, 192f)) + val pointerY = Animatable.Raw((sy * 200f).coerceIn(8f, 192f)) + + var animate = false + + block( + constrain( + x = pointerX?.alignCenter ?: Center, + y = pointerY.alignCenter, + w = 10.px, h = 10.px + ), + color = value, + radius = 5.radius() + ).outline(color = Color.WHITE, thickness = 1.px) onClick { - val (px, py) = element.getMousePosPercent() - apply(px, py) - first = true - dragging = true - true - } - onMouseMove { - if (dragging) { - val (px, py) = element.getMousePosPercent() - apply(px, py) - } - dragging + animate = true } - onRelease { - dragging = false - } - onValueChanged { + val duration = if (animate || !ui.eventManager.mouseDown) 0.15.seconds else 0f val (x, y) = block() - - val toX = (x * element.width).coerceIn(8f, element.width - 8f) - val toY = (y * element.height).coerceIn(8f, element.height - 8f) - if (first || !dragging) { - pointerX?.animate(toX, 0.1.seconds, Animations.EaseOutQuad) - pointerY?.animate(toY, 0.1.seconds, Animations.EaseOutQuad) - } else { - pointerX?.to(toX) - pointerY?.to(toY) - } - redraw() + pointerX?.animate(to = (x * 200f).coerceIn(8f, 192f), duration, Animation.Style.EaseOutQuad) + pointerY.animate(to = (y * 200f).coerceIn(8f, 192f), duration, Animation.Style.EaseOutQuad) + animate = false } } - - private companion object { - @JvmStatic - val transparentFix: Color.RGB = Color.RGB(0, 0, 0, 0.2f) - } } diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/DropdownSetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/DropdownSetting.kt index 602ba8f15..1a6e0b6a4 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/DropdownSetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/DropdownSetting.kt @@ -1,15 +1,12 @@ package me.odinmain.features.settings.impl -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.constraints.at -import com.github.stivais.ui.constraints.constrain -import com.github.stivais.ui.constraints.percent -import com.github.stivais.ui.constraints.px -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.transforms.rotation -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.constraints.impl.measurements.Pixel +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.ElementScope import me.odinmain.features.settings.Setting import me.odinmain.features.settings.Setting.Renders.Companion.setting +import me.odinmain.utils.ui.image /** * A setting intended to show or hide other settings in the GUI. @@ -23,25 +20,24 @@ class DropdownSetting( override var value: Boolean = default - override fun ElementDSL.create() = setting { + override fun ElementScope<*>.create() = setting { text( name, - pos = at(6.px), + pos = at(Pixel.ZERO), size = 40.percent ) image( - image = "/assets/odinmain/clickgui/chevron.svg", - constraints = constrain(-6.px, w = 30.px, h = 30.px) + image = "clickgui/chevron.svg".image(), + constraints = constrain(Pixel.ZERO.alignOpposite, w = 30.px, h = 30.px) ) { val rotate = rotation( from = 270f, to = 90f ) onClick { - rotate.animate(0.25.seconds, Animations.EaseInOutQuint) value = !value - this@setting.redraw() - true + rotate.animate(0.25.seconds, Animation.Style.EaseInOutQuint) + this@create.redraw() } } } diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/HUDSetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/HUDSetting.kt index e28571a9b..80524f283 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/HUDSetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/HUDSetting.kt @@ -1,6 +1,6 @@ package me.odinmain.features.settings.impl -import com.github.stivais.ui.utils.loop +import com.github.stivais.aurora.utils.loop import com.google.gson.JsonElement import com.google.gson.JsonObject import me.odinmain.features.huds.HUD diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/KeybindSetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/KeybindSetting.kt index 6d9676e33..7b94a5063 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/KeybindSetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/KeybindSetting.kt @@ -1,20 +1,21 @@ package me.odinmain.features.settings.impl -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Animatable -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.elements.scope.focuses -import com.github.stivais.ui.elements.scope.hoverEffect -import com.github.stivais.ui.utils.animate -import com.github.stivais.ui.utils.radius -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.constraints.impl.measurements.Animatable +import com.github.stivais.aurora.constraints.impl.measurements.Pixel +import com.github.stivais.aurora.constraints.impl.size.Bounding +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.elements.impl.Block.Companion.outline +import com.github.stivais.aurora.elements.impl.Text.Companion.string +import com.github.stivais.aurora.elements.impl.popup import com.google.gson.JsonElement import com.google.gson.JsonPrimitive import me.odinmain.features.impl.render.ClickGUI import me.odinmain.features.impl.render.ClickGUI.`gray 38` import me.odinmain.features.settings.Saving import me.odinmain.features.settings.Setting +import me.odinmain.features.settings.Setting.Renders.Companion.onValueChanged import me.odinmain.features.settings.Setting.Renders.Companion.setting import org.lwjgl.input.Keyboard.* import org.lwjgl.input.Mouse @@ -60,46 +61,60 @@ class KeybindSetting( } } - override fun ElementDSL.create() = setting { + override fun ElementScope<*>.create() = setting { text( - text = name, - pos = at(x = 6.px), + name, + pos = at(x = Pixel.ZERO), size = 40.percent, ) + + val outline = Animatable(from = 1.px, to = 2.5.px) + block( - constraints = constrain(x = -6.px, w = Bounding + 6.px, h = 70.percent), + constraints = constrain(x = Pixel.ZERO.alignOpposite, w = Bounding + 6.px, h = 70.percent), color = `gray 38`, - radius = radius(5) + radius = 5.radius() ) { - val display = text( - text = keyName, + outline( + color = ClickGUI.color, + thickness = outline ) - onFocusedClick { (button) -> - value.key = -100 + button - ui.unfocus() - true - } - onKeyPressed { (code) -> - value.key = when (code) { - KEY_ESCAPE, KEY_BACK -> 0 - KEY_NUMPADENTER, KEY_RETURN -> value.key - else -> code + hoverEffect( + factor = 1.25f + ) + text( + string = keyName + ) { + onValueChanged { + string = keyName } - ui.unfocus() - true - } - onFocusGain { - outlineColor!!.animate(0.25.seconds) - outline!!.animate(0.25.seconds) } - onFocusLost { - display.string = keyName - outlineColor!!.animate(0.25.seconds) - outline!!.animate(0.25.seconds) + onClick { + // creates a popup which consumes any input and closes the popup and sets the keybind + + val popup = popup(copies(), smooth = false) { + onFocusChanged { + outline.animate(0.25.seconds, style = Animation.Style.Linear) + } + onClick(nonSpecific = true) { (button) -> + value.key = -100 + button + ui.unfocus() + closePopup() + true + } + onKeycodePressed { (code) -> + value.key = when (code) { + KEY_ESCAPE, KEY_BACK -> 0 + KEY_NUMPADENTER, KEY_RETURN -> value.key + else -> code + } + ui.unfocus() + closePopup() + true + } + } + ui.focus(popup.element) } - hoverEffect() - focuses() - outline(color = ClickGUI.color, Animatable(from = 1.px, to = 2.5.px)) } } @@ -114,7 +129,7 @@ class KeybindSetting( } } -class Keybinding(var key: Int) { +data class Keybinding(var key: Int) { /** * Intended to active when keybind is pressed. diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/ListSetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/ListSetting.kt index 40f9ef2d0..af2406b43 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/ListSetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/ListSetting.kt @@ -7,7 +7,7 @@ import me.odinmain.features.settings.Setting import java.lang.reflect.Type /** - * This setting is only designed to store values as a list, and shouldn't be rendered in the gui. + * This setting is only designed to store values as a list. * * @author Stivais */ diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/NumberSetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/NumberSetting.kt index 77783bb6b..603872003 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/NumberSetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/NumberSetting.kt @@ -1,24 +1,22 @@ -package me.odinmain.features.settings.impl +@file:Suppress("always_false") +package me.odinmain.features.settings.impl -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.constraints.at -import com.github.stivais.ui.constraints.constrain -import com.github.stivais.ui.constraints.measurements.Animatable -import com.github.stivais.ui.constraints.percent -import com.github.stivais.ui.constraints.px -import com.github.stivais.ui.constraints.sizes.Copying -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.elements.scope.hoverEffect -import com.github.stivais.ui.utils.radius -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.constraints.impl.measurements.Animatable +import com.github.stivais.aurora.constraints.impl.measurements.Pixel +import com.github.stivais.aurora.constraints.impl.size.Copying +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.elements.impl.Text.Companion.string +import com.github.stivais.aurora.utils.multiply import com.google.gson.JsonElement import com.google.gson.JsonPrimitive import me.odinmain.features.impl.render.ClickGUI import me.odinmain.features.impl.render.ClickGUI.`gray 26` import me.odinmain.features.settings.Saving import me.odinmain.features.settings.Setting -import me.odinmain.features.settings.Setting.Renders.Companion.elementWidth import me.odinmain.features.settings.Setting.Renders.Companion.onValueChanged import me.odinmain.features.settings.Setting.Renders.Companion.setting import me.odinmain.utils.round @@ -26,7 +24,7 @@ import kotlin.math.floor import kotlin.math.round /** - * Setting that lets you pick a value between a range + * Setting that lets you pick a value between a range. * * @param min The minimum a value can be * @param max The maximum a value can be @@ -63,63 +61,64 @@ class NumberSetting( return "$number$unit" } - override fun ElementDSL.create() = setting(45.px) { + override fun ElementScope<*>.create() = setting(45.px) { + + var shouldAnimate = false + val sliderWidth = Animatable.Raw(0f) + + onAdd { + this@create.element.size() + val to = getPercent() * element.width + sliderWidth.to(to) + } + text( name, - pos = at(6.px, 10.px), + pos = at(x = Pixel.ZERO), size = 35.percent ) - val display = text( - text, - pos = at(x = -(6.px), y = 10.px), + text( + string = text, + pos = at(x = Pixel.ZERO.alignOpposite), size = 35.percent - ) - - val sliderWidth = Animatable.Raw((((value.toDouble() - min) / (max - min)) * (elementWidth.pixels * 0.95)).toFloat()) + ) { + onValueChanged { + val to = getPercent() * this@create.element.width + if (shouldAnimate || !element.pressed) { + shouldAnimate = false + sliderWidth.animate(to = to, 0.75.seconds, Animation.Style.EaseOutQuint) + } else { + sliderWidth.to(to = to) + } + string = text + redraw() + } + } block( - constraints = constrain(y = 75.percent, w = 95.percent, h = 20.percent), + constraints = constrain(y = 75.percent, w = Copying, h = 20.percent), color = `gray 26`, - radius = 4.radius() + radius = 5.radius() ) { + val color = Color.Animated( + from = ClickGUI.color, + to = Color.RGB(ClickGUI.color.rgba.multiply(1.2f)) + ) block( - constraints = constrain(0.px, 0.px, sliderWidth, Copying), - color = ClickGUI.color, - radius = 4.radius() - ).hoverEffect(handler = this@block) - - var dragging = false - // used to animate on only click - var first = true - + constrain(0.px, 0.px, sliderWidth, Copying), + color = color, + radius = 5.radius() + ) + onMouseEnterExit { + color.animate(0.25.seconds, Animation.Style.Linear) + } onClick { - first = true - dragging = true - val percent = ((ui.mx - element.x).coerceIn(0f, element.width) / element.width).round(2).toFloat() + shouldAnimate = true + } + onMouseDrag { percent, _ -> set(percent * (max - min) + min) true } - onMouseMove { - if (dragging) { - val percent = ((ui.mx - element.x).coerceIn(0f, element.width) / element.width).round(2).toFloat() - set(percent * (max - min) + min) - } - dragging - } - onRelease { - dragging = false - } - - onValueChanged { - val to = ((value.toDouble() - min) / (max - min) * element.width).toFloat() - if (first || !dragging) { - first = false - sliderWidth.animate(to = to, 0.75.seconds, Animations.EaseOutQuint) - } else { - sliderWidth.to(to = to) - } - display.string = text - } } } @@ -136,4 +135,6 @@ class NumberSetting( fun set(new: Number) { value = (round((new.toDouble() / increment)) * increment).coerceIn(min, max) as E } + + fun getPercent(): Float = ((value.toDouble() - min) / (max - min)).toFloat() } diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/SelectorSetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/SelectorSetting.kt index 48fb988eb..8872752e0 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/SelectorSetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/SelectorSetting.kt @@ -1,16 +1,18 @@ package me.odinmain.features.settings.impl -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Animatable -import com.github.stivais.ui.constraints.sizes.Bounding -import com.github.stivais.ui.constraints.sizes.Copying -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.transforms.Transforms -import com.github.stivais.ui.utils.animate -import com.github.stivais.ui.utils.radius -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.constraints.impl.measurements.Animatable +import com.github.stivais.aurora.constraints.impl.measurements.Pixel +import com.github.stivais.aurora.constraints.impl.size.Bounding +import com.github.stivais.aurora.constraints.impl.size.Copying +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.elements.Layout.Companion.divider +import com.github.stivais.aurora.elements.Layout.Companion.section +import com.github.stivais.aurora.elements.impl.Block.Companion.outline +import com.github.stivais.aurora.elements.impl.Text.Companion.string +import com.github.stivais.aurora.transforms.impl.Alpha import com.google.gson.JsonElement import com.google.gson.JsonPrimitive import me.odinmain.features.impl.render.ClickGUI @@ -72,38 +74,36 @@ class SelectorSetting( return options.map { it.lowercase() }.indexOf(string.lowercase()).coerceIn(0, options.size - 1) } - override fun ElementDSL.create() = setting(height = Bounding) { + override fun ElementScope<*>.create() = setting(height = Bounding) { column(size(w = Copying)) { - val alpha = Transforms.Alpha.Animated(from = 0f, to = 1f) - val height = Animatable(from = 0.px, to = Bounding) + val alpha = Alpha.Animated(from = 0f, to = 1f) + val height = Animatable(from = Pixel.ZERO, to = Bounding) val thickness = Animatable(from = 1.px, to = 1.75.px) section(40.px) { text( name, - pos = at(x = 6.px), + pos = at(x = Pixel.ZERO), size = 40.percent ) block( - constraints = constrain(x = -(6.px), w = Bounding + 6.px, h = 75.percent), + constraints = constrain(x = Pixel.ZERO.alignOpposite, w = Bounding + 6.px, h = 75.percent), color = `gray 38`, radius = 5.radius() ) { outline(ClickGUI.color, thickness = thickness) - val text = text( - options[value], - pos = at(x = 6.px) - ) - onValueChanged { - text.string = options[value] + text(string = options[value]) { + onValueChanged { + string = options[value] + } } onClick { - alpha.animate(0.25.seconds, Animations.EaseInOutQuint) - height.animate(0.25.seconds, Animations.EaseInOutQuint) - thickness.animate(0.25.seconds, Animations.EaseInOutQuint) - this@column.redraw() + alpha.animate(0.25.seconds, Animation.Style.EaseInOutQuint) + height.animate(0.25.seconds, Animation.Style.EaseInOutQuint) + thickness.animate(0.25.seconds, Animation.Style.EaseInOutQuint) + this@setting.redraw() true } } @@ -112,7 +112,7 @@ class SelectorSetting( transform(alpha) divider(10.px) - column(size(w = 95.percent)) { + column(size(w = Copying)) { block( constraints = copies(), color = `gray 38`, @@ -125,24 +125,28 @@ class SelectorSetting( } for ((index, option) in options.withIndex()) { + val color = Color.Animated( + from = Color.TRANSPARENT, + to = Color.RGB(150, 150, 150, 0.2f) + ) block( constraints = size(Copying, h = 32.px), - color = Color.Animated( - from = Color.TRANSPARENT, - to = Color.RGB(150, 150, 150, 0.2f) - ), + color = color, radius = 5.radius() ) { - text(option) + text( + string = option + ) onClick { value = index - alpha.animate(0.25.seconds, Animations.EaseInOutQuint) - height.animate(0.25.seconds, Animations.EaseInOutQuint) - thickness.animate(0.25.seconds, Animations.EaseInOutQuint) + alpha.animate(0.25.seconds, Animation.Style.EaseInOutQuint) + height.animate(0.25.seconds, Animation.Style.EaseInOutQuint) + thickness.animate(0.25.seconds, Animation.Style.EaseInOutQuint) + this@setting.redraw() true } onMouseEnterExit { - color?.animate(duration = 0.05.seconds) + color.animate(duration = 0.05.seconds, Animation.Style.Linear) } } } diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/StringSetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/StringSetting.kt index 7e38d6f27..053338a76 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/StringSetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/StringSetting.kt @@ -1,18 +1,18 @@ package me.odinmain.features.settings.impl -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.brighter -import com.github.stivais.ui.color.color -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.measurements.Animatable -import com.github.stivais.ui.constraints.sizes.AspectRatio -import com.github.stivais.ui.constraints.sizes.Copying -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.renderer.Image -import com.github.stivais.ui.utils.animate -import com.github.stivais.ui.utils.radius -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.constraints.impl.measurements.Animatable +import com.github.stivais.aurora.constraints.impl.measurements.Pixel +import com.github.stivais.aurora.constraints.impl.size.Copying +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.elements.Layout.Companion.section +import com.github.stivais.aurora.elements.impl.Block.Companion.outline +import com.github.stivais.aurora.elements.impl.Text.Companion.string +import com.github.stivais.aurora.elements.impl.TextInput.Companion.maxWidth +import com.github.stivais.aurora.elements.impl.TextInput.Companion.onTextChanged +import com.github.stivais.aurora.utils.multiply import com.google.gson.JsonElement import com.google.gson.JsonPrimitive import me.odinmain.features.impl.render.ClickGUI @@ -20,17 +20,19 @@ import me.odinmain.features.impl.render.ClickGUI.`gray 38` import me.odinmain.features.settings.Saving import me.odinmain.features.settings.Setting import me.odinmain.features.settings.Setting.Renders.Companion.setting -import me.odinmain.utils.ui.elements.TextInput -import me.odinmain.utils.ui.textInput /** - * Setting that lets you type a string. - * @author Aton, Stivais + * Setting that represents a string. + * + * @param default Default value for the setting. + * @param length Maximum length of the string. + * @param placeholder Placeholder string that appears inside the text input. */ class StringSetting( name: String, override val default: String = "", var length: Int = 20, + private val placeholder: String = "", hidden: Boolean = false, description: String = "", ) : Setting(name, hidden, description), Saving, Setting.Renders { @@ -57,71 +59,74 @@ class StringSetting( } } - override fun ElementDSL.create() = setting(60.px) { - column(size(w = Copying)) { + override fun ElementScope<*>.create() = setting(60.px) { + + val thickness = Animatable(1.px, 1.5.px) + val hoverColor = Color.Animated(from = `gray 38`, to = Color.RGB(`gray 38`.rgba.multiply(1.2f))) + + column(size(w = Copying), padding = 2.5.px) { section(size = 20.px) { text( name, - pos = at(x = 6.px), + pos = at(x = Pixel.ZERO), size = 80.percent ) } - val thickness = Animatable(from = 1.px, to = 1.75.px) - val hover = Color.Animated(from = `gray 38`, to = color { `gray 38`.rgba.brighter(1.2) }) - - divider(3.px) block( - size(w = 95.percent, h = 30.px), - color = hover, - outlineColor = ClickGUI.color, - outlineThickness = thickness, + size(w = Copying, h = 30.px), + color = hoverColor, radius = 5.radius() ) { outline( ClickGUI.color, - thickness, + thickness = 1.px ) - onMouseEnterExit { - hover.animate(0.25.seconds, Animations.Linear) - } - val maxWidth = if (censors) 80.percent else 95.percent + val lengthText = text( + "${value.length}/$length", + pos = at(x = 3.percent.alignOpposite), + color = getLengthColor(value), + size = 40.percent, + ).toggle() + val input = textInput( - default = value, - pos = at(x = 6.px), - size = 50.percent, - maxWidth = maxWidth, - censored = censors, - onTextChange = { event -> - val str = event.string - if (str.length <= length) value = str else event.cancel() + value, + placeholder, + pos = at(x = 3.percent), + size = 55.percent, + ) { + // doesn't animate, but used for just swapping + val maxWidth = Animatable(from = 90.percent, to = 75.percent) + maxWidth(maxWidth) + + onTextChanged { event -> + var str = event.string + if (str.length > length) str = str.substring(0, length) + lengthText.string = "${str.length}/$length" + lengthText.element.color = getLengthColor(str) + event.string = str + value = str + } + onFocusChanged { + thickness.animate(0.25.seconds, style = Animation.Style.EaseInOutQuint) + lengthText.toggle() + maxWidth.swap() + this@setting.redraw() } - ).apply { - onFocusGain { thickness.animate(0.25.seconds) } - onFocusLost { thickness.animate(0.25.seconds) } } + onClick { - input.focusThis() - true + ui.focus(input.element) } - if (censors) { - image( - Image("/assets/odinmain/clickgui/visibility-show.svg", type = Image.Type.VECTOR), - constraints = constrain(-6.px, w = AspectRatio(1f), h = 75.percent) - ) { - onClick { - (input.element as TextInput).censorInput = !(input.element).censorInput - if (input.element.censorInput) { - element.image = Image("/assets/odinmain/clickgui/visibility-show.svg") - } else { - element.image = Image("/assets/odinmain/clickgui/visibility-off.svg") - } - true - } - } + + onMouseEnterExit { + hoverColor.animate(0.25.seconds, style = Animation.Style.EaseOutQuad) } } - } + }// } + + private fun getLengthColor(string: String) = + if (string.length > length) Color.RED else Color.RGB(200, 200, 200) } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/features/settings/impl/UISetting.kt b/src/main/kotlin/me/odinmain/features/settings/impl/UISetting.kt index 8b905c4c3..77daa0fdb 100644 --- a/src/main/kotlin/me/odinmain/features/settings/impl/UISetting.kt +++ b/src/main/kotlin/me/odinmain/features/settings/impl/UISetting.kt @@ -1,14 +1,9 @@ package me.odinmain.features.settings.impl -import com.github.stivais.ui.constraints.Size -import com.github.stivais.ui.constraints.percent -import com.github.stivais.ui.constraints.px -import com.github.stivais.ui.constraints.size -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.elements.scope.ElementScope -import com.github.stivais.ui.elements.scope.hoverEffect -import com.github.stivais.ui.utils.radius -import com.github.stivais.ui.utils.seconds +import com.github.stivais.aurora.constraints.Constraint +import com.github.stivais.aurora.dsl.* +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.elements.impl.Block.Companion.outline import me.odinmain.features.impl.render.ClickGUI import me.odinmain.features.impl.render.ClickGUI.`gray 38` import me.odinmain.features.settings.Setting @@ -16,7 +11,7 @@ import me.odinmain.features.settings.Setting.Renders.Companion.setting // doesn't save class UISetting( - height: Size, + height: Constraint.Size, description: String = "", val scope: ElementScope<*>.() -> Unit ) : Setting("", false, description), Setting.Renders { @@ -25,22 +20,22 @@ class UISetting( private val _height = height - override fun ElementDSL.create() = setting(_height, scope) + override fun ElementScope<*>.create() = setting(_height, scope) } @Suppress("FunctionName") -fun ActionSetting( +inline fun ActionSetting( name: String, description: String = "", - action: ElementDSL.() -> Unit + crossinline action: ElementScope<*>.() -> Unit ): UISetting = UISetting(40.px, description) { block( constraints = size(95.percent, 75.percent), color = `gray 38`, radius = 5.radius() ) { - hoverEffect(0.25.seconds) - outline(ClickGUI.color) + hoverEffect(factor = 1.25f) + outline(ClickGUI.color, thickness = 1.px) text(name) onClick { diff --git a/src/main/kotlin/me/odinmain/utils/AutoSessionID.kt b/src/main/kotlin/me/odinmain/utils/AutoSessionID.kt index 254b5214b..b881ffdfa 100644 --- a/src/main/kotlin/me/odinmain/utils/AutoSessionID.kt +++ b/src/main/kotlin/me/odinmain/utils/AutoSessionID.kt @@ -27,4 +27,6 @@ val rat = listOf( "⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", // you can't stop the rat "⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢤⣼⣿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", // right now "⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣦⣤⣤⣤⣶⣦⣿⣿⣶⣾⣿⣥⣤⣤⣬⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿" // bye bye -) \ No newline at end of file +) + +// this rat sucks, old was one was better - stivais \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/utils/render/HighlightRenderer.kt b/src/main/kotlin/me/odinmain/utils/render/HighlightRenderer.kt index 9a3a7ece3..fd4a70e19 100644 --- a/src/main/kotlin/me/odinmain/utils/render/HighlightRenderer.kt +++ b/src/main/kotlin/me/odinmain/utils/render/HighlightRenderer.kt @@ -1,6 +1,6 @@ package me.odinmain.utils.render -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.OdinMain.mc import me.odinmain.events.impl.RenderEntityModelEvent import me.odinmain.events.impl.RenderOverlayNoCaching diff --git a/src/main/kotlin/me/odinmain/utils/render/OutlineUtils.kt b/src/main/kotlin/me/odinmain/utils/render/OutlineUtils.kt index 7617922db..182c008e1 100644 --- a/src/main/kotlin/me/odinmain/utils/render/OutlineUtils.kt +++ b/src/main/kotlin/me/odinmain/utils/render/OutlineUtils.kt @@ -1,10 +1,10 @@ package me.odinmain.utils.render -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.alpha -import com.github.stivais.ui.color.blue -import com.github.stivais.ui.color.green -import com.github.stivais.ui.color.red +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.alpha +import com.github.stivais.aurora.utils.blue +import com.github.stivais.aurora.utils.green +import com.github.stivais.aurora.utils.red import me.odinmain.OdinMain.mc import me.odinmain.events.impl.RenderEntityModelEvent import net.minecraft.client.renderer.OpenGlHelper diff --git a/src/main/kotlin/me/odinmain/utils/render/RenderUtils.kt b/src/main/kotlin/me/odinmain/utils/render/RenderUtils.kt index b6576b886..4da82059a 100644 --- a/src/main/kotlin/me/odinmain/utils/render/RenderUtils.kt +++ b/src/main/kotlin/me/odinmain/utils/render/RenderUtils.kt @@ -1,12 +1,7 @@ package me.odinmain.utils.render -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.alpha -import com.github.stivais.ui.color.blue -import com.github.stivais.ui.color.green -import com.github.stivais.ui.color.isTransparent -import com.github.stivais.ui.color.red -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.* import me.odinmain.OdinMain.mc import me.odinmain.features.impl.dungeon.dungeonwaypoints.DungeonWaypoints.DungeonWaypoint import net.minecraft.client.renderer.GlStateManager @@ -139,7 +134,7 @@ object RenderUtils { * @param depth Whether to enable depth testing. */ fun drawFilledAABB(aabb: AxisAlignedBB, color: Color, depth: Boolean = false) { - if (color.isTransparent) return + if (color.alpha == 0) return GlStateManager.pushMatrix() GlStateManager.disableCull() @@ -163,7 +158,7 @@ object RenderUtils { * @param depth Whether to enable depth testing. */ fun drawOutlinedAABB(aabb: AxisAlignedBB, color: Color, thickness: Number = 3f, depth: Boolean = false, smoothLines: Boolean = true) { - if (color.isTransparent) return + if (color.alpha == 0) return GlStateManager.pushMatrix() preDraw() @@ -352,7 +347,7 @@ object RenderUtils { GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) for (box in boxes) { - if (box.clicked || box.color.isTransparent) continue + if (box.clicked || box.color.alpha == 0) continue (box.depth && !disableDepth).let { if (it) GL11.glEnable(GL11.GL_DEPTH_TEST) else GL11.glDisable(GL11.GL_DEPTH_TEST) @@ -406,7 +401,7 @@ object RenderUtils { * @param depth Whether to enable depth testing. */ fun drawBeaconBeam(vec3: Vec3, color: Color, depth: Boolean = true, height: Int = 300) { - if (color.isTransparent) return + if (color.alpha == 0) return val bottomOffset = 0 val topOffset = bottomOffset + height depth(depth) diff --git a/src/main/kotlin/me/odinmain/utils/render/RenderUtils2D.kt b/src/main/kotlin/me/odinmain/utils/render/RenderUtils2D.kt index ed1ddbb9c..7f065b4ba 100644 --- a/src/main/kotlin/me/odinmain/utils/render/RenderUtils2D.kt +++ b/src/main/kotlin/me/odinmain/utils/render/RenderUtils2D.kt @@ -1,13 +1,14 @@ package me.odinmain.utils.render -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.OdinMain.mc import me.odinmain.utils.corners import me.odinmain.utils.render.RenderUtils.bind import me.odinmain.utils.render.RenderUtils.renderVec import me.odinmain.utils.render.RenderUtils.tessellator import me.odinmain.utils.render.RenderUtils.worldRenderer +import me.odinmain.utils.ui.Colors import net.minecraft.client.gui.ScaledResolution import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.vertex.DefaultVertexFormats @@ -84,7 +85,7 @@ object RenderUtils2D { text: String, entity: Entity, padding: Number, - backgroundColor: Color = Color.MINECRAFT_GRAY.withAlpha(0.5f), + backgroundColor: Color = Colors.MINECRAFT_GRAY.withAlpha(0.5f), accentColor: Color = Color.BLUE, textColor: Color = Color.WHITE, scale: Float = 1f, diff --git a/src/main/kotlin/me/odinmain/utils/render/Renderer.kt b/src/main/kotlin/me/odinmain/utils/render/Renderer.kt index 0101c252d..d447f6474 100644 --- a/src/main/kotlin/me/odinmain/utils/render/Renderer.kt +++ b/src/main/kotlin/me/odinmain/utils/render/Renderer.kt @@ -1,18 +1,23 @@ package me.odinmain.utils.render -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.color.alpha -import com.github.stivais.ui.color.multiplyAlpha -import com.github.stivais.ui.color.withAlpha +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.utils.alpha +import com.github.stivais.aurora.utils.multiplyAlpha +import com.github.stivais.aurora.utils.withAlpha import me.odinmain.OdinMain.mc -import me.odinmain.utils.* +import me.odinmain.utils.addVec +import me.odinmain.utils.fastEyeHeight +import me.odinmain.utils.min import me.odinmain.utils.render.RenderUtils.drawBeaconBeam import me.odinmain.utils.render.RenderUtils.outlineBounds import me.odinmain.utils.render.RenderUtils.renderVec import me.odinmain.utils.skyblock.getBlockAt +import me.odinmain.utils.toAABB import net.minecraft.client.gui.ScaledResolution import net.minecraft.entity.Entity -import net.minecraft.util.* +import net.minecraft.util.AxisAlignedBB +import net.minecraft.util.BlockPos +import net.minecraft.util.Vec3 import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent diff --git a/src/main/kotlin/me/odinmain/utils/skyblock/DianaBurrowEstimate.kt b/src/main/kotlin/me/odinmain/utils/skyblock/DianaBurrowEstimate.kt index 2ec7df54e..cf5c2a877 100644 --- a/src/main/kotlin/me/odinmain/utils/skyblock/DianaBurrowEstimate.kt +++ b/src/main/kotlin/me/odinmain/utils/skyblock/DianaBurrowEstimate.kt @@ -1,11 +1,14 @@ package me.odinmain.utils.skyblock -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.features.impl.skyblock.DianaHelper import me.odinmain.utils.* +import me.odinmain.utils.ui.Colors import net.minecraft.network.play.server.S29PacketSoundEffect import net.minecraft.network.play.server.S2APacketParticles -import net.minecraft.util.* +import net.minecraft.util.BlockPos +import net.minecraft.util.EnumParticleTypes +import net.minecraft.util.Vec3 import java.util.concurrent.ConcurrentHashMap import kotlin.math.* @@ -250,7 +253,7 @@ object DianaBurrowEstimate { enum class BurrowType(val text: String, val color: Color) { START("§aStart", Color.GREEN), MOB("§cMob", Color.RED), - TREASURE("§6Treasure", Color.MINECRAFT_GOLD), + TREASURE("§6Treasure", Colors.MINECRAFT_GOLD), UNKNOWN("§fUnknown?!", Color.WHITE), } } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/utils/skyblock/ItemUtils.kt b/src/main/kotlin/me/odinmain/utils/skyblock/ItemUtils.kt index ea3b92987..e52fe9385 100644 --- a/src/main/kotlin/me/odinmain/utils/skyblock/ItemUtils.kt +++ b/src/main/kotlin/me/odinmain/utils/skyblock/ItemUtils.kt @@ -1,10 +1,11 @@ package me.odinmain.utils.skyblock -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.OdinMain.mc import me.odinmain.utils.equalsOneOf import me.odinmain.utils.noControlCodes import me.odinmain.utils.render.RenderUtils.bind +import me.odinmain.utils.ui.Colors import net.minecraft.client.entity.EntityPlayerSP import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.RenderHelper @@ -142,14 +143,14 @@ enum class ItemRarity( val color: Color ) { COMMON("COMMON", "§f", Color.WHITE), - UNCOMMON("UNCOMMON", "§2", Color.MINECRAFT_GREEN), - RARE("RARE", "§9", Color.MINECRAFT_BLUE), - EPIC("EPIC", "§5", Color.MINECRAFT_DARK_PURPLE), - LEGENDARY("LEGENDARY", "§6", Color.MINECRAFT_GOLD), - MYTHIC("MYTHIC", "§d", Color.MINECRAFT_LIGHT_PURPLE), - DIVINE("DIVINE", "§b", Color.MINECRAFT_AQUA), - SPECIAL("SPECIAL", "§c", Color.MINECRAFT_RED), - VERY_SPECIAL("VERY SPECIAL", "§c", Color.MINECRAFT_DARK_RED); + UNCOMMON("UNCOMMON", "§2", Colors.MINECRAFT_GREEN), + RARE("RARE", "§9", Colors.MINECRAFT_BLUE), + EPIC("EPIC", "§5", Colors.MINECRAFT_DARK_PURPLE), + LEGENDARY("LEGENDARY", "§6", Colors.MINECRAFT_GOLD), + MYTHIC("MYTHIC", "§d", Colors.MINECRAFT_LIGHT_PURPLE), + DIVINE("DIVINE", "§b", Colors.MINECRAFT_AQUA), + SPECIAL("SPECIAL", "§c", Colors.MINECRAFT_RED), + VERY_SPECIAL("VERY SPECIAL", "§c", Colors.MINECRAFT_DARK_RED); } private val rarityRegex: Regex = Regex("§l(?${ItemRarity.entries.joinToString("|") { it.loreName }}) ?(?[A-Z ]+)?(?:§[0-9a-f]§l§ka)?$") diff --git a/src/main/kotlin/me/odinmain/utils/skyblock/PlayerUtils.kt b/src/main/kotlin/me/odinmain/utils/skyblock/PlayerUtils.kt index 6834141ee..c853cb96c 100644 --- a/src/main/kotlin/me/odinmain/utils/skyblock/PlayerUtils.kt +++ b/src/main/kotlin/me/odinmain/utils/skyblock/PlayerUtils.kt @@ -1,6 +1,6 @@ package me.odinmain.utils.skyblock -import com.github.stivais.ui.color.Color +import com.github.stivais.aurora.color.Color import me.odinmain.OdinMain.logger import me.odinmain.OdinMain.mc import me.odinmain.features.impl.floor7.p3.termsim.TermSimGui diff --git a/src/main/kotlin/me/odinmain/utils/skyblock/dungeon/DungeonEnums.kt b/src/main/kotlin/me/odinmain/utils/skyblock/dungeon/DungeonEnums.kt index c868c7923..6bab535be 100644 --- a/src/main/kotlin/me/odinmain/utils/skyblock/dungeon/DungeonEnums.kt +++ b/src/main/kotlin/me/odinmain/utils/skyblock/dungeon/DungeonEnums.kt @@ -1,8 +1,9 @@ package me.odinmain.utils.skyblock.dungeon -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.renderer.Image +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.renderer.data.Image import me.odinmain.utils.skyblock.PersonalBest +import me.odinmain.utils.ui.Colors import net.minecraft.entity.player.EntityPlayer /** @@ -71,11 +72,11 @@ enum class DungeonClass( val defaultQuadrant: Int, var priority: Int, ) { - Archer(Color.MINECRAFT_GOLD, '6', 0, 2), - Berserk(Color.MINECRAFT_DARK_RED, '4', 1, 0), - Healer(Color.MINECRAFT_LIGHT_PURPLE, 'd', 2, 2), - Mage(Color.MINECRAFT_BLUE, 'b', 3, 2), - Tank(Color.MINECRAFT_DARK_GREEN, '2', 3, 1), + Archer(Colors.MINECRAFT_GOLD, '6', 0, 2), + Berserk(Colors.MINECRAFT_DARK_RED, '4', 1, 0), + Healer(Colors.MINECRAFT_LIGHT_PURPLE, 'd', 2, 2), + Mage(Colors.MINECRAFT_BLUE, 'b', 3, 2), + Tank(Colors.MINECRAFT_DARK_GREEN, '2', 3, 1), Unknown(Color.WHITE, 'f', 0, 0) } diff --git a/src/main/kotlin/me/odinmain/utils/skyblock/dungeon/DungeonUtils.kt b/src/main/kotlin/me/odinmain/utils/skyblock/dungeon/DungeonUtils.kt index 0ee077a07..cde069c16 100644 --- a/src/main/kotlin/me/odinmain/utils/skyblock/dungeon/DungeonUtils.kt +++ b/src/main/kotlin/me/odinmain/utils/skyblock/dungeon/DungeonUtils.kt @@ -1,15 +1,18 @@ package me.odinmain.utils.skyblock.dungeon -import com.github.stivais.ui.renderer.Image +import com.github.stivais.aurora.renderer.data.Image import me.odinmain.OdinMain.mc import me.odinmain.events.impl.PacketReceivedEvent import me.odinmain.events.impl.RoomEnterEvent import me.odinmain.features.impl.dungeon.MapInfo.togglePaul import me.odinmain.utils.* -import me.odinmain.utils.skyblock.* +import me.odinmain.utils.skyblock.Island +import me.odinmain.utils.skyblock.LocationUtils import me.odinmain.utils.skyblock.LocationUtils.currentDungeon import me.odinmain.utils.skyblock.PlayerUtils.posY import me.odinmain.utils.skyblock.dungeon.tiles.Room +import me.odinmain.utils.skyblock.getItemSlot +import me.odinmain.utils.skyblock.modMessage import net.minecraft.block.BlockSkull import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks diff --git a/src/main/kotlin/me/odinmain/utils/ui/Colors.kt b/src/main/kotlin/me/odinmain/utils/ui/Colors.kt new file mode 100644 index 000000000..a20e46c95 --- /dev/null +++ b/src/main/kotlin/me/odinmain/utils/ui/Colors.kt @@ -0,0 +1,51 @@ +package me.odinmain.utils.ui + +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.color.Color.RGB + +/** + * Object which contains a list of [Colors][Color] representing color codes in Minecraft. + */ +object Colors { + @JvmField + val MINECRAFT_DARK_BLUE: Color = RGB(0, 0, 170) + + @JvmField + val MINECRAFT_DARK_GREEN: Color = RGB(0, 170, 0) + + @JvmField + val MINECRAFT_DARK_AQUA: Color = RGB(0, 170, 170) + + @JvmField + val MINECRAFT_DARK_RED: Color = RGB(170, 0, 0) + + @JvmField + val MINECRAFT_DARK_PURPLE: Color = RGB(170, 0, 170) + + @JvmField + val MINECRAFT_GOLD: Color = RGB(255, 170, 0) + + @JvmField + val MINECRAFT_GRAY: Color = RGB(170, 170, 170) + + @JvmField + val MINECRAFT_DARK_GRAY: Color = RGB(85, 85, 85) + + @JvmField + val MINECRAFT_BLUE: Color = RGB(85, 85, 255) + + @JvmField + val MINECRAFT_GREEN: Color = RGB(85, 255, 85) + + @JvmField + val MINECRAFT_AQUA: Color = RGB(85, 255, 255) + + @JvmField + val MINECRAFT_RED: Color = RGB(255, 85, 85) + + @JvmField + val MINECRAFT_LIGHT_PURPLE: Color = RGB(255, 85, 255) + + @JvmField + val MINECRAFT_YELLOW: Color = RGB(255, 255, 85) +} \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/utils/ui/elements/TextInput.kt b/src/main/kotlin/me/odinmain/utils/ui/elements/TextInput.kt deleted file mode 100644 index 1038e8df1..000000000 --- a/src/main/kotlin/me/odinmain/utils/ui/elements/TextInput.kt +++ /dev/null @@ -1,472 +0,0 @@ -package me.odinmain.utils.ui.elements - -import com.github.stivais.ui.UI -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.elements.impl.TextElement -import com.github.stivais.ui.events.Event -import com.github.stivais.ui.events.Focused -import com.github.stivais.ui.events.Key -import com.github.stivais.ui.events.Mouse -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.GuiScreen -import net.minecraft.util.ChatAllowedCharacters -import org.lwjgl.input.Keyboard -import kotlin.math.max -import kotlin.math.min - -class TextInput( - text: String, - private val placeholder: String, - position: Positions? = null, - size: Size, - private val widthLimit: Size? = null, - censor: Boolean = false, - private val onlyNumbers: Boolean = false, - onTextChange: (event: TextChanged) -> Unit -) : TextElement(text, UI.defaultFont, Color.WHITE, position ?: at(), size) { - - private val cursorBlinkRate = 500L - private var lastBlinkTime = System.currentTimeMillis() - private var cursorVisible = true - - override var text: String = text - set(value) { - if (field == value) return - val event = TextChanged(value) - accept(event) - if (!event.cancelled) { - field = value - redraw = true - previousHeight = 0f - if (history.last() != value) history.add(value) - if (censorInput) censorCache = "*".repeat(value.length) - updateCaret() - updateSelectionX() - } - } - - private var caretPosition = text.length - set(value) { - field = value.coerceIn(0, text.length) - updateCaret() - lastBlinkTime = System.currentTimeMillis() - cursorVisible = true - } - - private var selectionStart = caretPosition - set(value) { - field = value.coerceIn(0, text.length) - updateSelectionX() - } - - private var caretX = 0f - private var selectionX = 0f - private var dragging = false - var censorInput = censor - private var censorCache: String? = if (censor) "*".repeat(text.length) else null - private val history by lazy { mutableListOf(text) } - private var lastClickTime = 0L - private var clickCount = 0 - private var scrollOfset = 0f - - init { - TextChanged().register { - onTextChange(it) - false - } - - Focused.Gained register { - Keyboard.enableRepeatEvents(true) - updateCaretFromMouse() - selectionStart = caretPosition - false - } - - Focused.Lost register { - selectionStart = caretPosition - Keyboard.enableRepeatEvents(false) - false - } - - Key.CodePressed(-1, true) register { - handleKeyInput(it.code) - true - } - - Mouse.Clicked(0) register { - dragging = true - ui.focus(this) - handleMouseClick() - false - } - - Mouse.Moved register { - if (dragging) { - updateCaretFromMouse() - return@register true - } - lastClickTime = 0L - false - } - - Mouse.Released(0) register { - dragging = false - false - } - } - - override fun draw() { - val currentTime = System.currentTimeMillis() - if (currentTime - lastBlinkTime > cursorBlinkRate) { - cursorVisible = !cursorVisible - lastBlinkTime = currentTime - redraw = true - } - - // Draw selection background - if (selectionStart != caretPosition) { - val startX = x + min(selectionX, caretX) - val endX = x + max(selectionX, caretX) - renderer.rect(startX - scrollOfset, y + 2, endX - startX, height - 2, Color.RGB(0, 120, 215, 0.4f).rgba) - } - - // Draw text or placeholder - when { - text.isEmpty() && !ui.isFocused(this) -> { - renderer.text(placeholder, x, y, height, Color.RGB(169, 169, 169).rgba) - } - censorInput -> { - renderer.text(censorCache!!, x, y, height, color!!.get(this)) - } - else -> { - renderer.text(text, x - scrollOfset, y, height, color!!.get(this)) - } - } - - // Draw cursor - if (ui.isFocused(this) && cursorVisible) { - renderer.rect(x + caretX - scrollOfset, y + 2, 1f, height - 4, Color.WHITE.rgba) - } - } - - override fun getTextWidth(): Float { - return when { - text.isEmpty() -> renderer.textWidth(placeholder, height) - censorInput -> renderer.textWidth(censorCache!!, height) - else -> super.getTextWidth() - } - } - - override fun preSize() { - super.preSize() - if (widthLimit != null) { - val maxW = widthLimit.get(this, Type.W) - if (width >= maxW) { - scrollOfset = width - maxW - width = maxW - } else { - scrollOfset = 0f - } - } - // Adjust scroll offset to work both left and right - val textWidth = getTextWidth() - if (textWidth > width) { - if (caretX - scrollOfset < 0) { - scrollOfset = caretX - } else if (caretX - scrollOfset > width) { - scrollOfset = caretX - width - } - } else { - scrollOfset = 0f - } - } - - private fun updateCaret() { - val visibleText = if (censorInput) censorCache!! else text - val safeCaretPosition = caretPosition.coerceIn(0, visibleText.length) - caretX = renderer.textWidth(visibleText.substring(0, safeCaretPosition), height) - } - - private fun updateSelectionX() { - val visibleText = if (censorInput) censorCache!! else text - val safeSelectionStart = selectionStart.coerceIn(0, visibleText.length) - selectionX = renderer.textWidth(visibleText.substring(0, safeSelectionStart), height) - } - - private fun updateCaretFromMouse() { - val mouseX = ui.mx - x - var newPos = 0 - var currentWidth = 0f - val visibleText = if (censorInput) censorCache!! else text - - for (i in visibleText.indices) { - val charWidth = renderer.textWidth(visibleText[i].toString(), height) - if ((currentWidth - scrollOfset) + (charWidth / 2) > mouseX) break - currentWidth += charWidth - newPos = i + 1 - } - - caretPosition = newPos - if (!isShiftKeyDown() && !dragging) { - selectionStart = caretPosition - } - } - - private fun handleKeyInput(keyCode: Int) { - val char = Keyboard.getEventCharacter() - - when { - isKeyComboCtrlA(keyCode) -> selectAll() - isKeyComboCtrlC(keyCode) -> copySelection() - isKeyComboCtrlV(keyCode) -> paste() - isKeyComboCtrlX(keyCode) -> cut() - isKeyComboCtrlZ(keyCode) -> undo() - - keyCode == Keyboard.KEY_LEFT -> handleLeftArrow() - keyCode == Keyboard.KEY_RIGHT -> handleRightArrow() - keyCode == Keyboard.KEY_HOME -> handleHome() - keyCode == Keyboard.KEY_END -> handleEnd() - keyCode == Keyboard.KEY_BACK -> handleBackspace() - keyCode == Keyboard.KEY_DELETE -> handleDelete() - - keyCode == Keyboard.KEY_RETURN || keyCode == Keyboard.KEY_NUMPADENTER -> ui.unfocus() - keyCode == Keyboard.KEY_ESCAPE -> { - text = history.first() - ui.unfocus() - } - - else -> { - if (ChatAllowedCharacters.isAllowedCharacter(char)) { - if (onlyNumbers) { - if (char.isDigit() || (char == '-' && text.isEmpty()) || (char == '.' && !text.contains('.'))) { - insertText(char.toString()) - } - } else { - insertText(char.toString()) - } - } - } - } - } - - private fun handleMouseClick() { - val current = System.currentTimeMillis() - if (current - lastClickTime < 300) clickCount++ else clickCount = 1 - lastClickTime = current - - when (clickCount) { - 1 -> { - updateCaretFromMouse() - if (!isShiftKeyDown()) selectionStart = caretPosition - } - 2 -> selectWord() - 3 -> selectAll() - } - } - - private fun insertText(str: String) { - val start = min(caretPosition, selectionStart).coerceIn(0, text.length) - val end = max(caretPosition, selectionStart).coerceIn(0, text.length) - - text = text.substring(0, start) + str + text.substring(end) - caretPosition = start + str.length - selectionStart = caretPosition - } - - private fun deleteSelection() { - if (selectionStart == caretPosition) return - val start = min(caretPosition, selectionStart) - val end = max(caretPosition, selectionStart) - text = text.substring(0, start) + text.substring(end) - caretPosition = start - selectionStart = caretPosition - } - - // Helper functions for keyboard shortcuts - private fun selectAll() { - selectionStart = 0 - caretPosition = text.length - } - - private fun copySelection() { - if (selectionStart != caretPosition) { - val start = min(selectionStart, caretPosition) - val end = max(selectionStart, caretPosition) - GuiScreen.setClipboardString(text.substring(start, end)) - } - } - - private fun paste() { - val clipboard = GuiScreen.getClipboardString() - if (clipboard.isNotEmpty()) { - deleteSelection() - insertText(clipboard) - } - } - - private fun cut() { - copySelection() - deleteSelection() - } - - private fun undo() { - if (history.size > 1) { - history.removeAt(history.lastIndex) - text = history.last() - caretPosition = text.length - selectionStart = caretPosition - } - } - - private fun selectWord() { - var start = caretPosition - var end = caretPosition - - // Move start left until a space or the beginning - while (start > 0 && !text[start - 1].isWhitespace()) start-- - // Move end right until a space or the end - while (end < text.length && !text[end].isWhitespace()) end++ - - selectionStart = start - caretPosition = end - } - - // Standard keyboard input handlers - private fun handleLeftArrow() { - if (isCtrlKeyDown()) { - var newPos = caretPosition - // Skip spaces - while (newPos > 0 && text[newPos - 1].isWhitespace()) newPos-- - // Skip word - while (newPos > 0 && !text[newPos - 1].isWhitespace()) newPos-- - if (isShiftKeyDown()) caretPosition = newPos else { - caretPosition = newPos - selectionStart = caretPosition - } - } else { - if (isShiftKeyDown()) caretPosition-- else { - caretPosition-- - selectionStart = caretPosition - } - } - } - - private fun handleRightArrow() { - if (isCtrlKeyDown()) { - var newPos = caretPosition - // Skip spaces - while (newPos < text.length && text[newPos].isWhitespace()) newPos++ - // Skip word - while (newPos < text.length && !text[newPos].isWhitespace()) newPos++ - if (isShiftKeyDown()) caretPosition = newPos else { - caretPosition = newPos - selectionStart = caretPosition - } - } else { - if (isShiftKeyDown()) caretPosition++ else { - caretPosition++ - selectionStart = caretPosition - } - } - } - - private fun handleHome() { - if (isShiftKeyDown()) caretPosition = 0 else { - caretPosition = 0 - selectionStart = 0 - } - } - - private fun handleEnd() { - if (isShiftKeyDown()) caretPosition = text.length else { - caretPosition = text.length - selectionStart = text.length - } - } - - private fun handleBackspace() { - if (selectionStart != caretPosition) { - deleteSelection() - } else if (caretPosition > 0) { - if (isCtrlKeyDown()) { - var newPos = caretPosition - while (newPos > 0 && text[newPos - 1].isWhitespace()) newPos-- - while (newPos > 0 && !text[newPos - 1].isWhitespace()) newPos-- - text = text.substring(0, newPos) + text.substring(caretPosition) - caretPosition = newPos - } else { - text = text.substring(0, caretPosition - 1) + text.substring(caretPosition) - caretPosition-- - } - selectionStart = caretPosition - } - } - - private fun handleDelete() { - if (selectionStart != caretPosition) { - deleteSelection() - } else if (caretPosition < text.length) { - if (isCtrlKeyDown()) { - var newPos = caretPosition - while (newPos < text.length && text[newPos].isWhitespace()) newPos++ - while (newPos < text.length && !text[newPos].isWhitespace()) newPos++ - text = text.substring(0, caretPosition) + text.substring(newPos) - } else { - text = text.substring(0, caretPosition) + text.substring(caretPosition + 1) - } - } - } - - private fun isCtrlKeyDown(): Boolean { - return if (Minecraft.isRunningOnMac) Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220) else Keyboard.isKeyDown( - 29 - ) || Keyboard.isKeyDown(157) - } - - private fun isShiftKeyDown(): Boolean { - return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54) - } - - private fun isAltKeyDown(): Boolean { - return Keyboard.isKeyDown(56) || Keyboard.isKeyDown(184) - } - - private fun isKeyComboCtrlX(keyID: Int): Boolean { - return keyID == 45 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() - } - - private fun isKeyComboCtrlV(keyID: Int): Boolean { - return keyID == 47 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() - } - - private fun isKeyComboCtrlC(keyID: Int): Boolean { - return keyID == 46 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() - } - - private fun isKeyComboCtrlA(keyID: Int): Boolean { - return keyID == 30 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() - } - - private fun isKeyComboCtrlZ(keyID: Int): Boolean { - return keyID == Keyboard.KEY_Z && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() - } - - data class TextChanged(val string: String = "") : Event { - - var cancelled: Boolean = false - - fun cancel() { - cancelled = true - } - - override fun hashCode(): Int { - return 9999 - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - return other is TextChanged - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/github/stivais/ui/renderer/impl/NVGRenderer.kt b/src/main/kotlin/me/odinmain/utils/ui/renderer/NVGRenderer.kt similarity index 57% rename from src/main/kotlin/com/github/stivais/ui/renderer/impl/NVGRenderer.kt rename to src/main/kotlin/me/odinmain/utils/ui/renderer/NVGRenderer.kt index ef9ddefe8..5e651ab63 100644 --- a/src/main/kotlin/com/github/stivais/ui/renderer/impl/NVGRenderer.kt +++ b/src/main/kotlin/me/odinmain/utils/ui/renderer/NVGRenderer.kt @@ -1,112 +1,67 @@ -package com.github.stivais.ui.renderer.impl - -import com.github.stivais.ui.color.alpha -import com.github.stivais.ui.color.blue -import com.github.stivais.ui.color.green -import com.github.stivais.ui.color.red -import com.github.stivais.ui.renderer.* +package me.odinmain.utils.ui.renderer + +import com.github.stivais.aurora.renderer.Renderer +import com.github.stivais.aurora.renderer.data.Font +import com.github.stivais.aurora.renderer.data.Gradient +import com.github.stivais.aurora.renderer.data.Image +import com.github.stivais.aurora.utils.alpha +import com.github.stivais.aurora.utils.blue +import com.github.stivais.aurora.utils.green +import com.github.stivais.aurora.utils.red import me.odin.lwjgl.Lwjgl3Wrapper +import me.odin.lwjgl.Lwjgl3Wrapper.* import me.odin.lwjgl.NanoVGColorWrapper -import me.odin.lwjgl.NanoVGGLUFramebufferWrapper import me.odin.lwjgl.NanoVGPaintWrapper import me.odinmain.OdinMain.mc +import me.odinmain.OdinMain.wrapper +import net.minecraft.client.renderer.GlStateManager import org.lwjgl.opengl.GL11.* -import java.util.* -class NVGRenderer(private val wrapper: Lwjgl3Wrapper) : Renderer, Lwjgl3Wrapper by wrapper { +// TODO: Needs scissors +object NVGRenderer : Renderer, Lwjgl3Wrapper by wrapper { + private val nvgPaint: NanoVGPaintWrapper = createPaint() private val nvgColor: NanoVGColorWrapper = createColor() private val nvgColor2: NanoVGColorWrapper = createColor() private val fonts = HashMap() - // implement image removing with reference counting private val images = HashMap() - // not needed afaik - // private val svgs = HashMap() - - - private val fbos = HashMap() private var vg: Long = -1 // used in getTextWidth to avoid reallocating private val fontBounds = FloatArray(4) - private val scissorStack = Stack() +// private val scissorStack = Stack() private var drawing: Boolean = false init { - vg = nvgCreate(Lwjgl3Wrapper.NVG_ANTIALIAS) + vg = nvgCreate(NVG_ANTIALIAS or NVG_DEBUG) require(vg != -1L) { "Failed to initialize NanoVG" } - check(vg != 0L) { "NanoVG nvgCreate null" } } override fun beginFrame(width: Float, height: Float) { if (drawing) throw IllegalStateException("[NVGRenderer] Already drawing, but called beginFrame") drawing = true + GlStateManager.pushMatrix() if (!mc.framebuffer.isStencilEnabled) mc.framebuffer.enableStencil() glPushAttrib(GL_ALL_ATTRIB_BITS) + GlStateManager.disableAlpha() nvgBeginFrame(vg, width, height, 1f) - nvgTextAlign(vg, Lwjgl3Wrapper.NVG_ALIGN_LEFT or Lwjgl3Wrapper.NVG_ALIGN_TOP) + nvgTextAlign(vg, NVG_ALIGN_LEFT or NVG_ALIGN_TOP) } override fun endFrame() { if (!drawing) throw IllegalStateException("[NVGRenderer] Not drawing, but called endFrame") nvgEndFrame(vg) glPopAttrib() + GlStateManager.enableAlpha() + GlStateManager.popMatrix() drawing = false } - override fun supportsFramebuffers(): Boolean = false // temp - - override fun createFramebuffer(w: Float, h: Float): Framebuffer { - val fbo = Framebuffer(w, h) - fbos[fbo] = nvgluCreateFramebuffer( - vg, - w.toInt(), - h.toInt(), - 0 - ) ?: throw NullPointerException("Error creating nvg fbo") - println("FBO size: ${fbos.size}") - return fbo - } - - override fun drawFramebuffer(fbo: Framebuffer, x: Float, y: Float) { - val nvgFbo = getFramebuffer(fbo) - nvgImagePattern(vg, 0f, 0f, fbo.width, fbo.height, 0f, nvgFbo.image(), 1f, nvgPaint) - nvgBeginPath(vg) - nvgRect(vg, x, y, fbo.width, fbo.height) - nvgFillPaint(vg, nvgPaint) - nvgFill(vg) - nvgClosePath(vg) - } - - override fun bindFramebuffer(fbo: Framebuffer) { - glPushAttrib(GL_ALL_ATTRIB_BITS) - val nvgFbo = getFramebuffer(fbo) - nvgluBindFramebuffer(vg, nvgFbo) - glViewport(0, 0, fbo.width.toInt(), fbo.height.toInt()) - glClearColor(0f, 0f,0f, 0f) - glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT) - } - - override fun unbindFramebuffer() { - nvgluBindFramebuffer(vg, null) - glPopAttrib() - } - - private fun getFramebuffer(fbo: Framebuffer): NanoVGGLUFramebufferWrapper { - return fbos[fbo] ?: throw NullPointerException("Unable to find $fbo") - } - - override fun destroyFramebuffer(fbo: Framebuffer) { - val nvgFbo = fbos[fbo] ?: return - nvgluDeleteFramebuffer(vg, nvgFbo) - fbos.remove(fbo) - } - override fun push() = nvgSave(vg) override fun pop() = nvgRestore(vg) @@ -133,14 +88,6 @@ class NVGRenderer(private val wrapper: Lwjgl3Wrapper) : Renderer, Lwjgl3Wrapper nvgStroke(vg) } - override fun rect(x: Float, y: Float, w: Float, h: Float, color: Int) { - nvgBeginPath(vg) - nvgRect(vg, x, y, w, h + .5f) - color(color) - nvgFillColor(vg, nvgColor) - nvgFill(vg) - } - override fun rect(x: Float, y: Float, w: Float, h: Float, color: Int, tl: Float, bl: Float, br: Float, tr: Float) { nvgBeginPath(vg) nvgRoundedRectVarying(vg, x, y, w, h + .5f, tl, tr, br, bl) @@ -164,7 +111,7 @@ class NVGRenderer(private val wrapper: Lwjgl3Wrapper) : Renderer, Lwjgl3Wrapper nvgBeginPath(vg) nvgRoundedRectVarying(vg, x, y, w, h, tl, tr, br, bl) nvgStrokeWidth(vg, thickness) - nvgPathWinding(vg, Lwjgl3Wrapper.NVG_HOLE) + nvgPathWinding(vg, NVG_HOLE) color(color) nvgStrokeColor(vg, nvgColor) nvgStroke(vg) @@ -177,31 +124,41 @@ class NVGRenderer(private val wrapper: Lwjgl3Wrapper) : Renderer, Lwjgl3Wrapper h: Float, color1: Int, color2: Int, - direction: Gradient + gradient: Gradient, + tl: Float, + bl: Float, + br: Float, + tr: Float ) { nvgBeginPath(vg) - nvgRect(vg, x, y, w, h) - gradient(color1, color2, x, y, w, h, direction) + nvgRoundedRectVarying(vg, x, y, w, h, tl, tr, br, bl) + gradient(color1, color2, x, y, w, h, gradient) nvgFillPaint(vg, nvgPaint) nvgFill(vg) } - override fun gradientRect( + override fun dropShadow( x: Float, y: Float, - w: Float, - h: Float, - color1: Int, - color2: Int, - gradient: Gradient, + width: Float, + height: Float, + color: Int, + blur: Float, + spread: Float, tl: Float, bl: Float, br: Float, tr: Float ) { + nvgRGBA(0, 0, 0, 125, nvgColor) + nvgRGBA(0, 0, 0, 0, nvgColor2) + + // TODO: fix gradient bug i have no clue why its doing that + nvgBoxGradient(vg, x - spread, y - spread, width + 2 * spread, height + 2 * spread, tl + spread, blur, nvgColor, nvgColor2, nvgPaint) nvgBeginPath(vg) - nvgRoundedRectVarying(vg, x, y, w, h, tl, tr, br, bl) - gradient(color1, color2, x, y, w, h, gradient) + nvgRoundedRect(vg, x - spread - blur, y - spread - blur, width + 2 * spread + 2 * blur, height + 2 * spread + 2 * blur, tl + spread) + nvgRoundedRect(vg, x, y, width, height, tl) + nvgPathWinding(vg, NVG_HOLE) nvgFillPaint(vg, nvgPaint) nvgFill(vg) } @@ -212,7 +169,7 @@ class NVGRenderer(private val wrapper: Lwjgl3Wrapper) : Renderer, Lwjgl3Wrapper nvgFontFaceId(vg, getIDFromFont(font)) color(color) nvgFillColor(vg, nvgColor) - nvgText(vg, x, y + 1f, text) + nvgText(vg, x, y + .5f, text) nvgClosePath(vg) } @@ -233,8 +190,7 @@ class NVGRenderer(private val wrapper: Lwjgl3Wrapper) : Renderer, Lwjgl3Wrapper br: Float, tr: Float ) { - val nvgImage = getImage(image) ?: return - nvgImagePattern(vg, x, y, w, h, 0f, nvgImage, 1f, nvgPaint) + nvgImagePattern(vg, x, y, w, h, 0f, getImage(image), 1f, nvgPaint) nvgBeginPath(vg) nvgRoundedRectVarying(vg, x, y, w, h, tl, tr, br, bl) nvgFillPaint(vg, nvgPaint) @@ -262,8 +218,8 @@ class NVGRenderer(private val wrapper: Lwjgl3Wrapper) : Renderer, Lwjgl3Wrapper } } - private fun getImage(image: Image): Int? { - return images[image]?.nvg//throw IllegalStateException("Image (${image.resourcePath}) doesn't exist") + private fun getImage(image: Image): Int { + return images[image]?.nvg ?: throw IllegalStateException("Image (${image.resourcePath}) doesn't exist") } private fun loadImage(image: Image): Int { @@ -281,7 +237,7 @@ class NVGRenderer(private val wrapper: Lwjgl3Wrapper) : Renderer, Lwjgl3Wrapper } private fun loadSVG(image: Image): Int { - val vec = image.stream.bufferedReader().readText() + val vec = image.stream.use { it.bufferedReader().readText() } val svg = nsvgParse(vec, "px", 96f) ?: throw IllegalStateException("Failed to parse ${image.resourcePath}") image.width = svg.width() @@ -296,13 +252,17 @@ class NVGRenderer(private val wrapper: Lwjgl3Wrapper) : Renderer, Lwjgl3Wrapper return nvgImage } - fun color(color: Int) { + private fun color(color: Int) { nvgRGBA(color.red.toByte(), color.green.toByte(), color.blue.toByte(), color.alpha.toByte(), nvgColor) } - private fun gradient(color1: Int, color2: Int, x: Float, y: Float, w: Float, h: Float, direction: Gradient) { + private fun color(color1: Int, color2: Int) { nvgRGBA(color1.red.toByte(), color1.green.toByte(), color1.blue.toByte(), color1.alpha.toByte(), nvgColor) nvgRGBA(color2.red.toByte(), color2.green.toByte(), color2.blue.toByte(), color2.alpha.toByte(), nvgColor2) + } + + private fun gradient(color1: Int, color2: Int, x: Float, y: Float, w: Float, h: Float, direction: Gradient) { + color(color1, color2) when (direction) { Gradient.LeftToRight -> nvgLinearGradient(vg, x, y, x + w, y, nvgColor, nvgColor2, nvgPaint) Gradient.TopToBottom -> nvgLinearGradient(vg, x, y, x, y + h, nvgColor, nvgColor2, nvgPaint) @@ -315,57 +275,5 @@ class NVGRenderer(private val wrapper: Lwjgl3Wrapper) : Renderer, Lwjgl3Wrapper } } - override fun scissor(x: Float, y: Float, width: Float, height: Float): Scissor { - val scissor = Scissor(x, y, width, height) - if (scissor in scissorStack) return scissor - scissorStack.push(scissor) - applyScissors() - return scissor - } - - override fun resetScissor(scissor: Scissor) { - if (scissorStack.isEmpty()) { - nvgResetScissor(vg) - } else { - if (scissorStack.contains(scissor)) { - scissorStack.remove(scissor) - applyScissors() - } - } - } - - override fun clearScissors() { - scissorStack.clear() - nvgResetScissor(vg) - } - - private fun applyScissors() { - nvgResetScissor(vg) - if (scissorStack.isEmpty()) return - if (scissorStack.size == 1) { - val scissor = scissorStack.peek() - nvgScissor(vg, scissor.x, scissor.y, scissor.width, scissor.height) - return - } - val finalScissor = getFinalScissor() - nvgScissor(vg, finalScissor.x, finalScissor.y, finalScissor.width, finalScissor.height) - } - - private fun getFinalScissor(): Scissor { - var finalScissor = Scissor(scissorStack[0]) - for (i in 1 until scissorStack.size) { - val scissor = scissorStack[i] - val rightX = minOf(scissor.x + scissor.width, finalScissor.x + finalScissor.width) - val rightY = minOf(scissor.y + scissor.height, finalScissor.y + finalScissor.height) - finalScissor = Scissor( - x = maxOf(finalScissor.x, scissor.x), - y = maxOf(finalScissor.y, scissor.y), - width = rightX - maxOf(finalScissor.x, scissor.x), - height = rightY - maxOf(finalScissor.y, scissor.y) - ) - } - return finalScissor - } - private data class NVGImage(var count: Int, val nvg: Int) } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/utils/ui/UIHandler.kt b/src/main/kotlin/me/odinmain/utils/ui/screens/UIHandler.kt similarity index 59% rename from src/main/kotlin/me/odinmain/utils/ui/UIHandler.kt rename to src/main/kotlin/me/odinmain/utils/ui/screens/UIHandler.kt index 3df69adc1..d8266fcdf 100644 --- a/src/main/kotlin/me/odinmain/utils/ui/UIHandler.kt +++ b/src/main/kotlin/me/odinmain/utils/ui/screens/UIHandler.kt @@ -1,32 +1,31 @@ -package me.odinmain.utils.ui +package me.odinmain.utils.ui.screens -import com.github.stivais.ui.UI -import com.github.stivais.ui.Window +import com.github.stivais.aurora.AuroraUI +import com.github.stivais.aurora.Window import me.odinmain.OdinMain.mc import me.odinmain.events.impl.GuiEvent +import net.minecraft.client.gui.GuiScreen.getClipboardString +import net.minecraft.client.gui.GuiScreen.setClipboardString import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.lwjgl.input.Mouse import org.lwjgl.opengl.Display -/** - * Class that draws handles a [UI][com.github.stivais.ui.UI] instance via MC events. - * - * It is required to call [open] and [close] otherwise it will mess up with the eventbus. - */ -class UIHandler(private val ui: UI, private val onlyRender: Boolean = false) : Window { +class UIHandler(private val ui: AuroraUI): Window { private var previousWidth: Int = 0 private var previousHeight: Int = 0 - fun open() { - ui.initialize(Display.getWidth(), Display.getHeight(), this) + fun open(init: Boolean = true) { + if (init) { + ui.initialize(Display.getWidth(), Display.getHeight(), this) + } MinecraftForge.EVENT_BUS.register(this) } fun close() { - ui.cleanup() + ui.close() MinecraftForge.EVENT_BUS.unregister(this) } @@ -39,16 +38,11 @@ class UIHandler(private val ui: UI, private val onlyRender: Boolean = false) : W previousWidth = w previousHeight = h } - if (!onlyRender) { - ui.eventManager.apply { - val mx = Mouse.getX().toFloat() - val my = previousHeight - Mouse.getY() - 1f - if (this.mouseX != mx || this.mouseY != my || check()) { - onMouseMove(mx, my) - } - } - } + val mx = Mouse.getX().toFloat() + val my = previousHeight - Mouse.getY() - 1f + ui.eventManager.onMouseMove(mx, my) + ui.render() } @@ -64,6 +58,14 @@ class UIHandler(private val ui: UI, private val onlyRender: Boolean = false) : W @SubscribeEvent fun onKeyboardClick(event: GuiEvent.GuiKeyPressEvent) { - ui.eventManager.onKeyType(event.char) + ui.eventManager.onKeyTyped(event.char) + } + + override fun getClipboard(): String? { + return getClipboardString() + } + + override fun setClipboard(string: String?) { + return setClipboardString(string) } } \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/utils/ui/screens/UIScreen.kt b/src/main/kotlin/me/odinmain/utils/ui/screens/UIScreen.kt new file mode 100644 index 000000000..f84d2fc2c --- /dev/null +++ b/src/main/kotlin/me/odinmain/utils/ui/screens/UIScreen.kt @@ -0,0 +1,273 @@ +package me.odinmain.utils.ui.screens + +import com.github.stivais.aurora.AuroraUI +import com.github.stivais.aurora.Window +import com.github.stivais.aurora.input.Keys +import com.github.stivais.aurora.input.Modifier +import me.odinmain.OdinMain.display +import net.minecraft.client.gui.GuiScreen +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.util.ChatAllowedCharacters +import org.lwjgl.input.Keyboard.* +import org.lwjgl.input.Mouse +import org.lwjgl.opengl.Display +import kotlin.math.sign + +class UIScreen(val ui: AuroraUI) : GuiScreen(), Window { + + private var previousWidth: Int = 0 + private var previousHeight: Int = 0 + + private inline val eventManager + get() = ui.eventManager + + override fun initGui() { + ui.initialize(Display.getWidth(), Display.getHeight(), this) + enableRepeatEvents(true) + } + + override fun onGuiClosed() { + ui.close() + enableRepeatEvents(false) + } + + override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { + GlStateManager.pushMatrix() + val w = mc.framebuffer.framebufferWidth + val h = mc.framebuffer.framebufferHeight + if (w != previousWidth || h != previousHeight) { + previousWidth = w + previousHeight = h + ui.resize(w, h) + } + + val mx = Mouse.getX().toFloat() + val my = previousHeight - Mouse.getY() - 1f + eventManager.onMouseMove(mx, my) + ui.render() + GlStateManager.popMatrix() + } + + override fun handleKeyboardInput() { + super.handleKeyboardInput() + handleModifierReleases() + } + + override fun handleMouseInput() { + super.handleMouseInput() + val scroll = Mouse.getEventDWheel()//.sign + if (scroll != 0) { + ui.eventManager.onMouseScroll(scroll.toFloat().sign) + } + } + + override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) { + ui.eventManager.onMouseClick(mouseButton) + } + + override fun mouseReleased(mouseX: Int, mouseY: Int, button: Int) { + ui.eventManager.onMouseRelease(button) + } + + override fun keyTyped(typedChar: Char, keyCode: Int) { + if (eventManager.onKeycodePressed(keyCode)) { + return + } + + val char = when { + eventManager.modifier.hasControl -> { + if (eventManager.modifier.hasShift) shiftedCharsMap[keyCode] else nonShiftedCharMap[keyCode] + } + else -> if (ChatAllowedCharacters.isAllowedCharacter(typedChar)) typedChar else null + } + if (char != null) { + println(typedChar) + if (eventManager.onKeyTyped(char)) { + return + } + } else { + val key = keyMap[keyCode] + if (key != null && eventManager.onKeyTyped(key)) { + return + } + val mods = modifierMap[keyCode] + if (mods != null) { + eventManager.addModifier(mods.value) + return + } + } + super.keyTyped(typedChar, keyCode) + } + + private fun handleModifierReleases() { + val mod = eventManager.modifier + if (mod.hasLeftShift && !isKeyDown(KEY_LSHIFT)) eventManager.removeModifier(Modifier.LSHIFT.value) + if (mod.hasRightShift && !isKeyDown(KEY_RSHIFT)) eventManager.removeModifier(Modifier.RSHIFT.value) + if (mod.hasLeftControl && !isKeyDown(KEY_LCONTROL)) eventManager.removeModifier(Modifier.LCTRL.value) + if (mod.hasRightControl && !isKeyDown(KEY_RCONTROL)) eventManager.removeModifier(Modifier.RCTRL.value) + if (mod.hasLeftAlt && !isKeyDown(KEY_LMENU)) eventManager.removeModifier(Modifier.LALT.value) + if (mod.hasRightAlt && !isKeyDown(KEY_RMENU)) eventManager.removeModifier(Modifier.RALT.value) + } + + override fun getClipboard(): String? { + return getClipboardString() + } + + override fun setClipboard(string: String?) { + return setClipboardString(string) + } + + override fun doesGuiPauseGame() = false + + companion object { + + fun open(ui: AuroraUI) { + val screen = UIScreen(ui) + display = screen + } + + private val keyMap = hashMapOf( + KEY_ESCAPE to Keys.ESCAPE, + + KEY_F1 to Keys.F1, + KEY_F2 to Keys.F2, + KEY_F3 to Keys.F3, + KEY_F4 to Keys.F4, + KEY_F5 to Keys.F5, + KEY_F6 to Keys.F6, + KEY_F7 to Keys.F7, + KEY_F8 to Keys.F8, + KEY_F9 to Keys.F9, + KEY_F10 to Keys.F10, + KEY_F11 to Keys.F11, + KEY_F12 to Keys.F12, + + KEY_RETURN to Keys.ENTER, + KEY_BACK to Keys.BACKSPACE, + KEY_TAB to Keys.TAB, + + KEY_INSERT to Keys.INSERT, + KEY_DELETE to Keys.DELETE, + KEY_HOME to Keys.HOME, + KEY_END to Keys.END, + KEY_PRIOR to Keys.PAGE_UP, + KEY_NEXT to Keys.PAGE_DOWN, + + KEY_UP to Keys.UP, + KEY_DOWN to Keys.DOWN, + KEY_LEFT to Keys.LEFT, + KEY_RIGHT to Keys.RIGHT, + ) + + private val modifierMap = hashMapOf( + KEY_LSHIFT to Modifier.LSHIFT, + KEY_RSHIFT to Modifier.RSHIFT, + KEY_LCONTROL to Modifier.LCTRL, + KEY_RCONTROL to Modifier.RCTRL, + KEY_LMENU to Modifier.LALT, + KEY_RMENU to Modifier.RALT, + ) + + + // fuck you lwjgl + private val nonShiftedCharMap = hashMapOf( + KEY_1 to '1', + KEY_2 to '2', + KEY_3 to '3', + KEY_4 to '4', + KEY_5 to '5', + KEY_6 to '6', + KEY_7 to '7', + KEY_8 to '8', + KEY_9 to '9', + KEY_0 to '0', + KEY_MINUS to '-', + KEY_EQUALS to '=', + KEY_COMMA to ',', + KEY_PERIOD to '.', + KEY_SLASH to '/', + KEY_SEMICOLON to ';', + KEY_APOSTROPHE to '\'', + KEY_LBRACKET to '[', + KEY_RBRACKET to ']', + KEY_BACKSLASH to '\\', + + KEY_A to 'a', + KEY_B to 'b', + KEY_C to 'c', + KEY_D to 'd', + KEY_E to 'e', + KEY_F to 'f', + KEY_G to 'g', + KEY_H to 'h', + KEY_I to 'i', + KEY_J to 'j', + KEY_K to 'k', + KEY_L to 'l', + KEY_M to 'm', + KEY_N to 'n', + KEY_O to 'o', + KEY_P to 'p', + KEY_Q to 'q', + KEY_R to 'r', + KEY_S to 's', + KEY_T to 't', + KEY_U to 'u', + KEY_V to 'v', + KEY_W to 'w', + KEY_X to 'x', + KEY_Y to 'y', + KEY_Z to 'z', + ) + + private val shiftedCharsMap = hashMapOf( + KEY_1 to '!', + KEY_2 to '@', + KEY_3 to '#', + KEY_4 to '$', + KEY_5 to '%', + KEY_6 to '^', + KEY_7 to '&', + KEY_8 to '*', + KEY_9 to '(', + KEY_0 to ')', + KEY_MINUS to '_', + KEY_EQUALS to '+', + KEY_COMMA to '<', + KEY_PERIOD to '>', + KEY_SLASH to '?', + KEY_SEMICOLON to ':', + KEY_APOSTROPHE to '"', + KEY_LBRACKET to '{', + KEY_RBRACKET to '}', + KEY_BACKSLASH to '|', + + KEY_A to 'A', + KEY_B to 'B', + KEY_C to 'C', + KEY_D to 'D', + KEY_E to 'E', + KEY_F to 'F', + KEY_G to 'G', + KEY_H to 'H', + KEY_I to 'I', + KEY_J to 'J', + KEY_K to 'K', + KEY_L to 'L', + KEY_M to 'M', + KEY_N to 'N', + KEY_O to 'O', + KEY_P to 'P', + KEY_Q to 'Q', + KEY_R to 'R', + KEY_S to 'S', + KEY_T to 'T', + KEY_U to 'U', + KEY_V to 'V', + KEY_W to 'W', + KEY_X to 'X', + KEY_Y to 'Y', + KEY_Z to 'Z', + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/odinmain/utils/ui/utilities.kt b/src/main/kotlin/me/odinmain/utils/ui/utilities.kt index e5d47b294..0384597e1 100644 --- a/src/main/kotlin/me/odinmain/utils/ui/utilities.kt +++ b/src/main/kotlin/me/odinmain/utils/ui/utilities.kt @@ -1,42 +1,33 @@ package me.odinmain.utils.ui -import com.github.stivais.ui.UIScreen -import com.github.stivais.ui.animation.Animations -import com.github.stivais.ui.color.Color -import com.github.stivais.ui.constraints.* -import com.github.stivais.ui.constraints.positions.Linked -import com.github.stivais.ui.elements.impl.TextScope -import com.github.stivais.ui.elements.scope.BlockScope -import com.github.stivais.ui.elements.scope.ElementDSL -import com.github.stivais.ui.events.Event -import com.github.stivais.ui.renderer.Font -import com.github.stivais.ui.transforms.alpha -import com.github.stivais.ui.transforms.scale +import com.github.stivais.aurora.animations.Animation +import com.github.stivais.aurora.color.Color +import com.github.stivais.aurora.dsl.onMouseEnter +import com.github.stivais.aurora.dsl.onRemove +import com.github.stivais.aurora.elements.ElementScope +import com.github.stivais.aurora.renderer.data.Font +import com.github.stivais.aurora.renderer.data.Image +import com.github.stivais.aurora.transforms.impl.Alpha +import com.github.stivais.aurora.transforms.impl.Scale import me.odinmain.features.Module import me.odinmain.features.huds.HUD -import me.odinmain.features.huds.HUDScope import me.odinmain.features.settings.impl.ColorSetting import me.odinmain.features.settings.impl.SelectorSetting -import me.odinmain.utils.ui.elements.TextInput +import me.odinmain.utils.ui.screens.UIHandler val regularFont = Font("Regular", "/assets/odinmain/fonts/Regular.otf") val mcFont = Font("Minecraft", "/assets/odinmain/fonts/Minecraft-Regular.otf") -// todo: better solution -infix fun TextScope.and(other: TextScope) { - other.element.constraints.x = Linked(element) - other.size = size -} +/** + * Utility function to get an image from a string representing a path inside /assets/odinmain/ + */ +fun String.image() = Image("/assets/odinmain/$this") -fun ElementDSL.outline( - constraints: Constraints, - color: Color, - thickness: Measurement = 1.px, - radius: FloatArray? = null, - block: BlockScope.() -> Unit = {} -) { - block(constraints, Color.TRANSPARENT, color, thickness, radius, block) -} +//// todo: better solution +//infix fun TextScope.and(other: TextScope) { +// other.element.constraints.x = Linked(element) +// other.size = size +//} /** * Makes a HUD, that uses common settings found in text-based HUDs. @@ -47,7 +38,7 @@ fun ElementDSL.outline( inline fun Module.TextHUD( name: String, color: Color = Color.RGB(50, 150, 220), - crossinline block: HUDScope.(Color, Font) -> Unit + crossinline block: ElementScope<*>.(Color, Font) -> Unit ): HUD { val colorSetting = ColorSetting("Color", color, allowAlpha = false) val fontSetting = SelectorSetting("Font", arrayListOf("Regular", "Minecraft")) @@ -69,7 +60,7 @@ inline fun Module.TextHUD( /** * Allows code to be run after certain amount of time hovering over the element */ -inline fun ElementDSL.onHover(duration: Float, crossinline block: () -> Unit) { +inline fun ElementScope<*>.onHover(duration: Float, crossinline block: () -> Unit) { onMouseEnter { val start = System.nanoTime() operation { @@ -89,36 +80,26 @@ inline fun ElementDSL.onHover(duration: Float, crossinline block: () -> Unit) { * @param typeInitialized style of the animation when element is created * @param typeUninitialized style of the animation when element is removed */ -fun ElementDSL.lifetimeAnimations( +fun ElementScope<*>.lifetimeAnimations( duration: Float, - typeInitialized: Animations, - typeUninitialized: Animations, + typeInitialized: Animation.Style, + typeUninitialized: Animation.Style, ) { - val scaleAnimation = scale(from = 0f, to = 1f, centered = true) - val alphaAnimation = alpha(from = 0f, to = 1f) + val scaleAnimation = Scale.Animated(from = 0f, to = 1f, centered = true) + val alphaAnimation = Alpha.Animated(from = 0f, to = 1f) + + transform(scaleAnimation) + transform(alphaAnimation) scaleAnimation.animate(duration, typeInitialized) alphaAnimation.animate(duration, typeInitialized) onRemove { - UIScreen.closeAnimHandler = ui.window as UIScreen + val handler = UIHandler(ui) + handler.open(init = false) scaleAnimation.animate(duration, typeUninitialized) alphaAnimation.animate(duration, typeUninitialized)?.onFinish { - UIScreen.closeAnimHandler = null + handler.close() } } -} - -fun ElementDSL.textInput( - default: String = "", - placeholder: String = "", - pos: Positions? = null, - size: Size = 50.percent, - maxWidth: Size? = null, - censored: Boolean = false, - onTextChange: (event: TextInput.TextChanged) -> Unit -) = create(TextScope(TextInput(default, placeholder, pos, size, maxWidth, censored, onTextChange = onTextChange))) - -fun ElementDSL.passEvent(event: Event, to: ElementDSL) { - ui.eventManager.dispatchToAll(event, to.element) } \ No newline at end of file