Skip to content

Commit

Permalink
feat: Reset option to every module.
Browse files Browse the repository at this point in the history
  • Loading branch information
opZywl committed Dec 7, 2024
1 parent 03e167f commit 94b102d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 53 deletions.
18 changes: 18 additions & 0 deletions src/main/java/net/ccbluex/liquidbounce/features/module/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import net.ccbluex.liquidbounce.event.Listenable
import net.ccbluex.liquidbounce.features.module.modules.client.GameDetector
import net.ccbluex.liquidbounce.file.FileManager.modulesConfig
import net.ccbluex.liquidbounce.file.FileManager.saveConfig
import net.ccbluex.liquidbounce.file.FileManager.valuesConfig
import net.ccbluex.liquidbounce.handler.lang.translation
import net.ccbluex.liquidbounce.ui.client.hud.HUD.addNotification
import net.ccbluex.liquidbounce.ui.client.hud.element.elements.*
import net.ccbluex.liquidbounce.utils.ClassUtils
import net.ccbluex.liquidbounce.utils.ClientUtils.LOGGER
import net.ccbluex.liquidbounce.utils.MinecraftInstance
import net.ccbluex.liquidbounce.utils.chat
import net.ccbluex.liquidbounce.utils.extensions.toLowerCamelCase
import net.ccbluex.liquidbounce.utils.misc.RandomUtils.nextFloat
import net.ccbluex.liquidbounce.utils.timing.TickedActions.TickScheduler
Expand Down Expand Up @@ -81,6 +83,21 @@ open class Module(
}
}

private val resetValue: BoolValue = object : BoolValue("Reset", false, subjective = true) {
override fun onChange(oldValue: Boolean, newValue: Boolean): Boolean {
try {
values.forEach { if (it != this) it.reset() else return@forEach }
} catch (any: Exception) {
LOGGER.error("Failed to reset all values", any)
chat("Failed to reset all values: ${any.message}")
} finally {
addNotification(Notification("Successfully reset all settings from ${this@Module.name}", "Successfully reset all settings from ${this@Module.name}", Type.SUCCESS, 1000))
saveConfig(valuesConfig)
}
return false
}
}

var inArray = defaultInArray
set(value) {
field = value
Expand Down Expand Up @@ -193,6 +210,7 @@ open class Module(

if (gameDetecting) orderedValues += onlyInGameValue
if (!hideModule) orderedValues += hideModuleValue
orderedValues += resetValue
} catch (e: Exception) {
LOGGER.error(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import org.lwjgl.opengl.GL11.*

object Breadcrumbs : Module("Breadcrumbs", Category.VISUAL, hideModule = false) {
val rainbow by boolean("Rainbow", false)
val colors = ColorSettingsInteger(this, "Color", withAlpha = false) { !rainbow }
val colors = ColorSettingsInteger(this, "Color", withAlpha = false) { !rainbow }.with(132, 102, 255)
private val lineHeight by float("LineHeight", 0.25F, 0.25F..2F)
private val temporary by boolean("Temporary", true)
private val fade by boolean("Fade", true) { temporary }
private val lifeTime by float("LifeTime", 1F, 0F..10F) { temporary }

private val positions = mutableListOf<PositionData>()

// TODO: Fix player hand being black when rendering
@EventTarget
fun onRender3D(event: Render3DEvent) {
val player = mc.thePlayer ?: return
Expand All @@ -42,12 +43,11 @@ object Breadcrumbs : Module("Breadcrumbs", Category.VISUAL, hideModule = false)
glPushMatrix()

glDisable(GL_TEXTURE_2D)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_LINE_SMOOTH)
glEnable(GL_BLEND)
glDisable(GL_DEPTH_TEST)
glDisable(GL_CULL_FACE)

glEnable(GL_ALPHA_TEST)
glAlphaFunc(GL_GREATER, 0.0f)

Expand Down Expand Up @@ -91,9 +91,9 @@ object Breadcrumbs : Module("Breadcrumbs", Category.VISUAL, hideModule = false)
temporary && timestamp > fadeSeconds
}

glColor4d(1.0, 1.0, 1.0, 1.0)
glEnd()

glColor4d(1.0, 1.0, 1.0, 1.0)
glEnable(GL_CULL_FACE)
glEnable(GL_DEPTH_TEST)
glDisable(GL_ALPHA_TEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@ class MainScreen(private val category: Category) : Screen {
category.drag.onRelease(state)
moduleRects?.forEach { it.mouseReleased(mouseX, mouseY, state) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public void keyTyped(char typedChar, int keyCode) {
return;
}
selectedField.textboxKeyTyped(typedChar, keyCode);
selectedStringSetting.set(selectedField.getText());

selectedStringSetting.set(selectedField.getText(), true);
}
}

Expand Down Expand Up @@ -403,7 +404,7 @@ public void handle(int mouseX, int mouseY, int button, GuiEvents type) {
}
if (type == GuiEvents.CLICK && button == 0 && hoveringMode) {
modeSettingClick.put(modeSetting, !modeSettingClick.get(modeSetting));
modeSetting.set(mode);
modeSetting.set(mode, true);
}

if (openAnimation.isDone() && openAnimation.getDirection().equals(Direction.FORWARDS) || !openAnimation.isDone()) {
Expand Down Expand Up @@ -469,7 +470,7 @@ public void handle(int mouseX, int mouseY, int button, GuiEvents type) {

stringSettingField.drawTextBox();

stringSetting.set(stringSettingField.getText());
stringSetting.set(stringSettingField.getText(), true);

count++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,29 @@
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge by LiquidBounce.
* https://github.com/SkidderMC/FDPClient/
*/
package net.ccbluex.liquidbounce.ui.client.clickgui.style.styles.fdpdropdown.utils.objects;
package net.ccbluex.liquidbounce.ui.client.clickgui.style.styles.fdpdropdown.utils.objects

public class Drag {
class Drag(var x: Float, var y: Float) {
private var startX = 0f
private var startY = 0f
private var dragging = false

private float xPos, yPos;
private float startX, startY;
private boolean dragging;

public Drag(float initialXVal, float initialYVal) {
this.xPos = initialXVal;
this.yPos = initialYVal;
}

public float getX() {
return xPos;
}

public void setX(float x) {
this.xPos = x;
}

public float getY() {
return yPos;
}

public void setY(float y) {
this.yPos = y;
}

public final void onDraw(int mouseX, int mouseY) {
fun onDraw(mouseX: Int, mouseY: Int) {
if (dragging) {
xPos = (mouseX - startX);
yPos = (mouseY - startY);
x = (mouseX - startX)
y = (mouseY - startY)
}
}

public final void onClick(int mouseX, int mouseY, int button, boolean canDrag) {
fun onClick(mouseX: Int, mouseY: Int, button: Int, canDrag: Boolean) {
if (button == 0 && canDrag) {
dragging = true;
startX = (int) (mouseX - xPos);
startY = (int) (mouseY - yPos);
dragging = true
startX = (mouseX - x).toInt().toFloat()
startY = (mouseY - y).toInt().toFloat()
}
}

public final void onRelease(int button) {
if (button == 0) dragging = false;
fun onRelease(button: Int) {
if (button == 0) dragging = false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class ColorSettingsInteger(
fun color() = Color(r, g, b, a)

fun with(r: Int? = null, g: Int? = null, b: Int? = null, a: Int? = null): ColorSettingsInteger {
r?.let { red.set(it) }
g?.let { green.set(it) }
b?.let { blue.set(it) }
a?.let { alpha.set(it) }
r?.let { red.setAndUpdateDefault(it) }
g?.let { green.setAndUpdateDefault(it) }
b?.let { blue.setAndUpdateDefault(it) }
a?.let { alpha.setAndUpdateDefault(it) }

return this
}
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/net/ccbluex/liquidbounce/value/Value.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class Value<T>(
open var value: T,
val subjective: Boolean = false,
var isSupported: (() -> Boolean)? = null,
protected var default: T = value,
) : ReadWriteProperty<Any?, T> {

var excluded: Boolean = false
Expand All @@ -33,7 +34,11 @@ abstract class Value<T>(
var hidden = false
private set

fun set(newValue: T): Boolean {
fun setAndUpdateDefault(new: T): Boolean {
default = new
return set(new)
}
fun set(newValue: T, saveImmediately: Boolean = true): Boolean {
if (newValue == value || hidden || excluded)
return false

Expand All @@ -47,7 +52,9 @@ abstract class Value<T>(
onChanged(oldValue, handledValue)
onUpdate(handledValue)

saveConfig(valuesConfig)
if (saveImmediately) {
saveConfig(valuesConfig)
}
return true
} catch (e: Exception) {
LOGGER.error("[ValueSystem ($name)]: ${e.javaClass.name} (${e.message}) [$oldValue >> $newValue]")
Expand All @@ -61,7 +68,7 @@ abstract class Value<T>(
* [state] the value it will be set to before it is hidden.
*/
fun hideWithState(state: T = value) {
set(state)
setAndUpdateDefault(state)

hidden = true
}
Expand All @@ -72,7 +79,7 @@ abstract class Value<T>(
* [state] the value it will be set to before it is excluded.
*/
fun excludeWithState(state: T = value) {
set(state)
setAndUpdateDefault(state)

excluded = true
}
Expand Down Expand Up @@ -113,6 +120,8 @@ abstract class Value<T>(
}

fun shouldRender() = isSupported() && !hidden

fun reset() = set(default)
}

/**
Expand Down

0 comments on commit 94b102d

Please sign in to comment.