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 2 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,32 @@
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"){

for (setting in it.value.settingList.filter { it.isModified() }) {
val component = TextComponentString("${setting.name} has been changed to ${setting.value}")
// horrible, however this is mojang code that we are working on.
component.style.clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, ";set ${it.value.name} ${setting.name.replace(" ", "")} ${setting.defaultValue}")
component.style.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponentString("Click to reset to default"))
sendChatMessage(component)
}

if (!it.value.settingList.any { it.value != it.defaultValue }){
sendChatMessage("No settings have been changed.")
}
}
}
}
}
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 Down Expand Up @@ -40,4 +41,6 @@ class BindButton(
val posY = renderHeight - 2.0f - FontRenderAdapter.getFontHeight(0.75f)
FontRenderAdapter.drawString(valueText, posX, posY, color = GuiColors.text, scale = 0.75f)
}

override fun isBold() = setting.isModified() and ClickGUI.showModifiedInBold
}
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 Down Expand Up @@ -47,4 +48,6 @@ class EnumSlider(val setting: EnumSetting<*>) : Slider(setting.name, 0.0, settin
val posY = renderHeight - 2.0f - FontRenderAdapter.getFontHeight(0.75f)
FontRenderAdapter.drawString(valueText, posX, posY, color = GuiColors.text, scale = 0.75f)
}

override fun isBold() = setting.isModified() and ClickGUI.showModifiedInBold
}
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.setting.settings.impl.primitive.BooleanSetting
import org.kamiblue.client.util.math.Vec2f

Expand All @@ -20,4 +21,6 @@ class SettingButton(val setting: BooleanSetting) : BooleanSlider(setting.name, 0
setting.value = !setting.value
}
}

override fun isBold() = setting.isModified() and ClickGUI.showModifiedInBold
}
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 @@ -136,4 +137,6 @@ class SettingSlider(val setting: NumberSetting<*>) : Slider(setting.name, 0.0, s
}
}

override fun isBold() = setting.isModified() and ClickGUI.showModifiedInBold

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ open class Slider(
(renderHeight * ClickGUI.getScaleFactor()).roundToInt()
)
}*/
FontRenderAdapter.drawString(name, 1.5f, 1.0f, color = GuiColors.text)
val text = if (isBold()) "§l $name" else name

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

Expand Down Expand Up @@ -164,4 +166,6 @@ open class Slider(
MouseState.HOVER -> GuiColors.hover
else -> GuiColors.click
}

open fun isBold() = false
}
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.setting.settings.impl.primitive.StringSetting
import org.kamiblue.client.util.math.Vec2f
import org.lwjgl.input.Keyboard
Expand Down Expand Up @@ -71,4 +72,6 @@ class StringButton(val setting: StringSetting) : BooleanSlider(setting.name, 1.0
}
}

override fun isBold() = setting.isModified() and ClickGUI.showModifiedInBold

}
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)

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 @@ -48,4 +48,6 @@ abstract class AbstractSetting<T : Any> : Nameable {
val parser = JsonParser()
}

fun isModified() = this.value != this.defaultValue

}
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)
}

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"

}