Skip to content

Commit

Permalink
remove clickgui.json module opening
Browse files Browse the repository at this point in the history
  • Loading branch information
MukjepScarlet committed Feb 8, 2025
1 parent 7b29fb7 commit 01637a5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open class Configurable(
) {

// TODO: hide in clickGUI
var isExpanded by boolean("Expanded", false)
var isExpanded by boolean("Expanded", false).subjective()

val values: List<Value<*>>
get() = this.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object Scaffold : Module("Scaffold", Category.WORLD, Keyboard.KEY_I) {
private val towerMode by Tower.towerModeValues

init {
addValues(Tower.values)
+Tower
}

// <--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import net.ccbluex.liquidbounce.LiquidBounce.clickGui
import net.ccbluex.liquidbounce.file.FileConfig
import net.ccbluex.liquidbounce.file.FileManager.PRETTY_GSON
import net.ccbluex.liquidbounce.ui.client.clickgui.ClickGui
import net.ccbluex.liquidbounce.ui.client.clickgui.elements.ModuleElement
import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER
import net.ccbluex.liquidbounce.utils.io.json
import net.ccbluex.liquidbounce.utils.io.readJson
import java.io.*

Expand All @@ -38,20 +38,6 @@ class ClickGuiConfig(file: File) : FileConfig(file) {
panel.isVisible = panelObject["visible"].asBoolean
panel.x = panelObject["posX"].asInt
panel.y = panelObject["posY"].asInt

for (element in panel.elements) {
if (element !is ModuleElement) continue
if (!panelObject.has(element.module.name)) continue
try {
val elementObject = panelObject.getAsJsonObject(element.module.name)
element.showSettings = elementObject["Settings"].asBoolean
} catch (e: Exception) {
LOGGER.error(
"Error while loading clickgui module element with the name '" + element.module.getName() + "' (Panel Name: " + panel.name + ").",
e
)
}
}
} catch (e: Exception) {
LOGGER.error("Error while loading clickgui panel with the name '" + panel.name + "'.", e)
}
Expand All @@ -65,23 +51,15 @@ class ClickGuiConfig(file: File) : FileConfig(file) {
*/
@Throws(IOException::class)
override fun saveConfig() {
val jsonObject = JsonObject()

for (panel in clickGui.panels) {
val panelObject = JsonObject()
panelObject.run {
addProperty("open", panel.open)
addProperty("visible", panel.isVisible)
addProperty("posX", panel.x)
addProperty("posY", panel.y)
}
for (element in panel.elements) {
if (element !is ModuleElement) continue
val elementObject = JsonObject()
elementObject.addProperty("Settings", element.showSettings)
panelObject.add(element.module.name, elementObject)
val jsonObject = json {
for (panel in clickGui.panels) {
panel.name to json {
"open" to panel.open
"visible" to panel.isVisible
"posX" to panel.x
"posY" to panel.y
}
}
jsonObject.add(panel.name, panelObject)
}

file.writeText(PRETTY_GSON.toJson(jsonObject))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,32 @@ object ClickGui : GuiScreen() {

private fun setupTargetsPanel(xPos: Int = 100, yPos: Int, width: Int, height: Int) =
Panel("Targets", xPos, yPos, width, height, false, listOf(
ButtonElement("Players", { if (Targets.player) guiColor else Int.MAX_VALUE }) {
ButtonElement("Players") {
Targets.player = !Targets.player
},
ButtonElement("Mobs", { if (Targets.mob) guiColor else Int.MAX_VALUE }) {
}.color { if (Targets.player) guiColor else Int.MAX_VALUE },
ButtonElement("Mobs") {
Targets.mob = !Targets.mob
},
ButtonElement("Animals", { if (Targets.animal) guiColor else Int.MAX_VALUE }) {
}.color { if (Targets.mob) guiColor else Int.MAX_VALUE },
ButtonElement("Animals") {
Targets.animal = !Targets.animal
},
ButtonElement("Invisible", { if (Targets.invisible) guiColor else Int.MAX_VALUE }) {
}.color { if (Targets.animal) guiColor else Int.MAX_VALUE },
ButtonElement("Invisible") {
Targets.invisible = !Targets.invisible
},
ButtonElement("Dead", { if (Targets.dead) guiColor else Int.MAX_VALUE }) {
}.color { if (Targets.invisible) guiColor else Int.MAX_VALUE },
ButtonElement("Dead") {
Targets.dead = !Targets.dead
},
}.color { if (Targets.dead) guiColor else Int.MAX_VALUE },
))

private fun setupSettingsPanel(xPos: Int = 100, yPos: Int, width: Int, height: Int): Panel {
val list = autoSettingsList?.map { setting ->
ButtonElement(setting.name, { Integer.MAX_VALUE }) {
ButtonElement(setting.name, buildString {
appendLine("§7Description: §e${setting.description.ifBlank { "No description available" }}")
appendLine("§7Type: §e${setting.type.displayName}")
appendLine("§7Contributors: §e${setting.contributors}")
appendLine("§7Last updated: §e${setting.date}")
append("§7Status: §e${setting.statusType.displayName} §a(${setting.statusDate})")
}) {
SharedScopes.IO.launch {
try {
chat("Loading settings...")
Expand All @@ -136,14 +142,6 @@ object ClickGui : GuiScreen() {
chat("Failed to load settings: ${e.message}")
}
}
}.apply {
this.hoverText = buildString {
appendLine("§7Description: §e${setting.description.ifBlank { "No description available" }}")
appendLine("§7Type: §e${setting.type.displayName}")
appendLine("§7Contributors: §e${setting.contributors}")
appendLine("§7Last updated: §e${setting.date}")
append("§7Status: §e${setting.statusType.displayName} §a(${setting.statusDate})")
}
}
} ?: run {
// Try load settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ import net.ccbluex.liquidbounce.LiquidBounce.clickGui
import net.ccbluex.liquidbounce.ui.client.clickgui.ClickGui
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly
import java.util.function.IntSupplier

@SideOnly(Side.CLIENT)
open class ButtonElement(
open val displayName: String,
val stateDependingColor: () -> Int = { Int.MAX_VALUE },
val buttonAction: () -> Unit
val hoverText: String = "",
val onClick: () -> Unit
) : Element() {

private var colorSupplier = IntSupplier { Int.MAX_VALUE }

val color
get() = stateDependingColor()
get() = colorSupplier.asInt

open var hoverText: String = ""
fun color(supplier: IntSupplier) = apply {
this.colorSupplier = supplier
}

var hoverTime = 0
set(value) {
Expand All @@ -36,7 +41,7 @@ open class ButtonElement(

override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int): Boolean {
if (mouseButton == 0 && isHovered(mouseX, mouseY)) {
buttonAction()
onClick()
ClickGui.style.clickSound()
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly

@SideOnly(Side.CLIENT)
class ModuleElement(val module: Module) : ButtonElement(module.name, buttonAction = {
class ModuleElement(val module: Module) : ButtonElement(module.name, module.description, onClick = {
// This module element handles the click action itself.
}) {
override val displayName
get() = module.getName(spacedModules)

override var hoverText = ""
get() = module.description
// delegate to module.isExpanded
var showSettings: Boolean
get() = module.isExpanded
set(value) {
module.isExpanded = value
}

var showSettings = false
var settingsWidth = 0
set(value) {
if (value > settingsWidth) {
Expand Down

0 comments on commit 01637a5

Please sign in to comment.