Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

[enhancement] Add a modified setting command. #1925

Merged
merged 8 commits into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.kamiblue.client.command.commands

import net.minecraft.util.text.TextComponentString
import net.minecraft.util.text.event.ClickEvent
import net.minecraft.util.text.event.HoverEvent
import org.kamiblue.client.command.ClientCommand
import org.kamiblue.client.util.text.MessageSendHelper.sendChatMessage

object ModifiedCommand: ClientCommand(
name = "modified",
description = "View modified settings in a module"
) {
init {
module("module") {
execute("List changed settings") {
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved

scorbett123 marked this conversation as resolved.
Show resolved Hide resolved
var anyChanged = false

for (setting in it.value.settingList) {
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved
if (!setting.isModified) continue
anyChanged = true
val component = TextComponentString("${setting.name} has been changed to ${setting.value}")
// horrible, however this is mojang code that we are working on.
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved
component.style.clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, ";set ${it.value.name} ${setting.name.replace(" ", "")} ${setting.defaultValue}")
5HT2 marked this conversation as resolved.
Show resolved Hide resolved
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved
component.style.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponentString("Click to reset to default"))
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved
sendChatMessage(component)
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved
}

if (!anyChanged) {
sendChatMessage("${it.value.name}'s settings are not modified from default")
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kamiblue.client.gui.rgui.component

import org.kamiblue.client.module.modules.client.ClickGUI
import org.kamiblue.client.module.modules.client.GuiColors
import org.kamiblue.client.setting.settings.impl.other.BindSetting
import org.kamiblue.client.util.graphics.VertexHelper
Expand All @@ -11,6 +12,9 @@ class BindButton(
private val setting: BindSetting
) : Slider(setting.name, 0.0, setting.description, setting.visibility) {

override val isBold
get() = setting.isModified and ClickGUI.showModifiedInBold
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved

override val renderProgress: Double = 0.0

override fun onRelease(mousePos: Vec2f, buttonId: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kamiblue.client.gui.rgui.component

import org.kamiblue.client.module.modules.client.ClickGUI
import org.kamiblue.client.module.modules.client.GuiColors
import org.kamiblue.client.setting.settings.impl.primitive.EnumSetting
import org.kamiblue.client.util.graphics.VertexHelper
Expand All @@ -11,6 +12,9 @@ import kotlin.math.floor
class EnumSlider(val setting: EnumSetting<*>) : Slider(setting.name, 0.0, setting.description, setting.visibility) {
private val enumValues = setting.enumValues

override val isBold
get() = setting.isModified and ClickGUI.showModifiedInBold
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved

override fun onTick() {
super.onTick()
if (mouseState != MouseState.DRAG) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.kamiblue.client.gui.rgui.component

import org.kamiblue.client.module.modules.client.ClickGUI
import org.kamiblue.client.setting.settings.impl.primitive.BooleanSetting
import org.kamiblue.client.util.math.Vec2f

class SettingButton(val setting: BooleanSetting) : BooleanSlider(setting.name, 0.0, setting.description, setting.visibility) {

override val isBold
get() = setting.isModified and ClickGUI.showModifiedInBold
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved

init {
if (setting.value) value = 1.0
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kamiblue.client.gui.rgui.component

import org.kamiblue.client.module.modules.client.ClickGUI
import org.kamiblue.client.module.modules.client.GuiColors
import org.kamiblue.client.setting.settings.impl.number.FloatSetting
import org.kamiblue.client.setting.settings.impl.number.IntegerSetting
Expand Down Expand Up @@ -27,6 +28,9 @@ class SettingSlider(val setting: NumberSetting<*>) : Slider(setting.name, 0.0, s
else -> MathUtils.decimalPlaces(settingStep.toDouble())
}

override val isBold
get() = setting.isModified and ClickGUI.showModifiedInBold
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved

private var preDragMousePos = Vec2f(0.0f, 0.0f)

private fun getDefaultStep() = when (setting) {
Expand Down Expand Up @@ -135,5 +139,4 @@ class SettingSlider(val setting: NumberSetting<*>) : Slider(setting.name, 0.0, s
FontRenderAdapter.drawString(valueText, posX, posY, color = GuiColors.text, scale = 0.75f)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kamiblue.client.gui.rgui.component

import net.minecraft.util.text.TextFormatting
import org.kamiblue.client.gui.rgui.InteractiveComponent
import org.kamiblue.client.module.modules.client.ClickGUI
import org.kamiblue.client.module.modules.client.GuiColors
Expand All @@ -12,6 +13,7 @@ import org.kamiblue.client.util.graphics.font.FontRenderAdapter
import org.kamiblue.client.util.graphics.font.TextComponent
import org.kamiblue.client.util.math.Vec2d
import org.kamiblue.client.util.math.Vec2f
import org.kamiblue.client.util.text.format
import org.lwjgl.opengl.GL11.*

open class Slider(
Expand Down Expand Up @@ -42,6 +44,9 @@ open class Slider(

var listening = false; protected set

open val isBold
get() = false

override fun onClosed() {
super.onClosed()
onStopListening(false)
Expand Down Expand Up @@ -114,7 +119,9 @@ open class Slider(
(renderHeight * ClickGUI.getScaleFactor()).roundToInt()
)
}*/
FontRenderAdapter.drawString(name, 1.5f, 1.0f, color = GuiColors.text)
val text = if (isBold) TextFormatting.BOLD format name else name

FontRenderAdapter.drawString(text, 1.5f, 1.0f, color = GuiColors.text)
//GlStateUtils.popScissor()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.kamiblue.client.gui.rgui.component

import org.kamiblue.client.module.modules.client.ClickGUI
import org.kamiblue.client.setting.settings.impl.primitive.StringSetting
import org.kamiblue.client.util.math.Vec2f
import org.lwjgl.input.Keyboard
import kotlin.math.max

class StringButton(val setting: StringSetting) : BooleanSlider(setting.name, 1.0, setting.description, setting.visibility) {

override val isBold
get() = setting.isModified and ClickGUI.showModifiedInBold
scorbett123 marked this conversation as resolved.
Show resolved Hide resolved

override fun onDisplayed() {
super.onDisplayed()
value = 1.0
Expand Down Expand Up @@ -70,5 +74,4 @@ class StringButton(val setting: StringSetting) : BooleanSlider(setting.name, 1.0
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal object ClickGUI : Module(
val darkness by setting("Darkness", 0.25f, 0.0f..1.0f, 0.05f)
val fadeInTime by setting("Fade In Time", 0.25f, 0.0f..1.0f, 0.05f)
val fadeOutTime by setting("Fade Out Time", 0.1f, 0.0f..1.0f, 0.05f)
val showModifiedInBold by setting("Show Modified In Bold", false, description = "Display modified settings in a bold font")

private var prevScale = scaleSetting.value / 100.0f
private var scale = prevScale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ abstract class AbstractSetting<T : Any> : Nameable {

val isVisible get() = visibility()

val isModified get() = this.value != this.defaultValue

operator fun getValue(thisRef: Any?, property: KProperty<*>) = value

open fun setValue(valueIn: String) {
Expand Down Expand Up @@ -47,5 +49,4 @@ abstract class AbstractSetting<T : Any> : Nameable {
val gson: Gson = GsonBuilder().setPrettyPrinting().create()
val parser = JsonParser()
}

}
14 changes: 14 additions & 0 deletions src/main/kotlin/org/kamiblue/client/util/text/MessageSendHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.kamiblue.client.util.text
import baritone.api.event.events.ChatEvent
import net.minecraft.util.text.ITextComponent
import net.minecraft.util.text.TextComponentBase
import net.minecraft.util.text.TextComponentString
import net.minecraft.util.text.TextFormatting
import org.kamiblue.client.KamiMod
import org.kamiblue.client.command.CommandManager
Expand All @@ -16,6 +17,13 @@ import java.util.regex.Pattern
object MessageSendHelper {
private val mc = Wrapper.minecraft

fun sendChatMessage(message: ITextComponent) {
val component = TextComponentString("")
component.appendSibling(ChatMessage(coloredName('9')))
component.appendSibling(message)
sendRawChatMessage(component)
}
5HT2 marked this conversation as resolved.
Show resolved Hide resolved

fun sendChatMessage(message: String) {
sendRawChatMessage(coloredName('9') + message)
}
Expand Down Expand Up @@ -54,6 +62,11 @@ object MessageSendHelper {
mc.player?.sendMessage(ChatMessage(message))
}

fun sendRawChatMessage(message: ITextComponent?) {
if (message == null) return
mc.ingameGUI.chatGUI.printChatMessage(message)
}

fun Any.sendServerMessage(message: String?): TaskState {
if (message.isNullOrBlank()) return TaskState(true)
val priority = if (this is AbstractModule) modulePriority else 0
Expand Down Expand Up @@ -84,4 +97,5 @@ object MessageSendHelper {
}

private fun coloredName(colorCode: Char) = "&7[&$colorCode" + KamiMod.KAMI_KATAKANA + "&7] &r"

}