mirror of https://github.com/kami-blue/client
[enhancement] Added HudElement searching to HudEditor
This commit is contained in:
parent
3d8e0f1fd0
commit
087f76e075
|
@ -58,6 +58,8 @@ abstract class AbstractKamiGui<S : SettingWindow<*>, E : Any> : GuiScreen() {
|
|||
}
|
||||
private val renderStringPosX
|
||||
get() = AnimationUtils.exponent(AnimationUtils.toDeltaTimeFloat(lastTypedTime), 250.0f, prevStringWidth, stringWidth)
|
||||
val searching
|
||||
get() = typedString.isNotEmpty()
|
||||
|
||||
// Shader
|
||||
private val blurShader = ShaderHelper(ResourceLocation("shaders/post/kawase_blur_6.json"), "final")
|
||||
|
@ -231,6 +233,22 @@ abstract class AbstractKamiGui<S : SettingWindow<*>, E : Any> : GuiScreen() {
|
|||
hoveredWindow?.onKeyInput(keyCode, keyState)
|
||||
if (settingWindow != hoveredWindow) settingWindow?.onKeyInput(keyCode, keyState)
|
||||
}
|
||||
|
||||
override fun keyTyped(typedChar: Char, keyCode: Int) {
|
||||
when {
|
||||
keyCode == Keyboard.KEY_BACK || keyCode == Keyboard.KEY_DELETE -> {
|
||||
typedString = ""
|
||||
lastTypedTime = 0L
|
||||
stringWidth = 0.0f
|
||||
prevStringWidth = 0.0f
|
||||
}
|
||||
typedChar.isLetter() || typedChar == ' ' -> {
|
||||
typedString += typedChar
|
||||
stringWidth = FontRenderAdapter.getStringWidth(typedString, 2.0f)
|
||||
lastTypedTime = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
}
|
||||
// End of keyboard input
|
||||
|
||||
// Rendering
|
||||
|
@ -299,10 +317,10 @@ abstract class AbstractKamiGui<S : SettingWindow<*>, E : Any> : GuiScreen() {
|
|||
if (typedString.isNotBlank() && System.currentTimeMillis() - lastTypedTime <= 5000L) {
|
||||
val scaledResolution = ScaledResolution(mc)
|
||||
val posX = scaledResolution.scaledWidth / 2.0f - renderStringPosX / 2.0f
|
||||
val posY = scaledResolution.scaledHeight / 2.0f - FontRenderAdapter.getFontHeight(3.0f) / 2.0f
|
||||
val posY = scaledResolution.scaledHeight / 2.0f - FontRenderAdapter.getFontHeight(2.0f) / 2.0f
|
||||
val color = GuiColors.text
|
||||
color.a = AnimationUtils.halfSineDec(AnimationUtils.toDeltaTimeFloat(lastTypedTime), 5000.0f, 0.0f, 255.0f).toInt()
|
||||
FontRenderAdapter.drawString(typedString, posX, posY, color = color, scale = 1.666f)
|
||||
FontRenderAdapter.drawString(typedString, posX, posY, color = color, scale = 2.0f)
|
||||
}
|
||||
}
|
||||
// End of rendering
|
||||
|
|
|
@ -8,7 +8,6 @@ import me.zeroeightsix.kami.gui.rgui.windows.ListWindow
|
|||
import me.zeroeightsix.kami.module.Module
|
||||
import me.zeroeightsix.kami.module.ModuleManager
|
||||
import me.zeroeightsix.kami.module.modules.client.ClickGUI
|
||||
import me.zeroeightsix.kami.util.graphics.font.FontRenderAdapter
|
||||
import me.zeroeightsix.kami.util.math.Vec2f
|
||||
import org.lwjgl.input.Keyboard
|
||||
|
||||
|
@ -50,50 +49,33 @@ object KamiClickGui : AbstractKamiGui<ModuleSettingWindow, Module>() {
|
|||
|
||||
override fun onGuiClosed() {
|
||||
super.onGuiClosed()
|
||||
setModuleVisibility { true }
|
||||
setModuleButtonVisibility { true }
|
||||
}
|
||||
|
||||
override fun newSettingWindow(element: Module, mousePos: Vec2f): ModuleSettingWindow {
|
||||
return ModuleSettingWindow(element, mousePos.x, mousePos.y)
|
||||
}
|
||||
|
||||
|
||||
override fun handleKeyboardInput() {
|
||||
super.handleKeyboardInput()
|
||||
val keyCode = Keyboard.getEventKey()
|
||||
|
||||
if (settingWindow?.listeningChild == null && (keyCode == Keyboard.KEY_BACK || keyCode == Keyboard.KEY_DELETE)) {
|
||||
typedString = ""
|
||||
lastTypedTime = 0L
|
||||
stringWidth = 0.0f
|
||||
prevStringWidth = 0.0f
|
||||
|
||||
setModuleVisibility { true }
|
||||
}
|
||||
}
|
||||
|
||||
// Check for typedString added to resolve #1793. TODO: Better solution suggested in #1803
|
||||
override fun keyTyped(typedChar: Char, keyCode: Int) {
|
||||
if (keyCode == Keyboard.KEY_ESCAPE || (keyCode == ClickGUI.bind.value.key && typedString.isEmpty())) {
|
||||
if (keyCode == Keyboard.KEY_ESCAPE || keyCode == ClickGUI.bind.value.key && !searching) {
|
||||
ClickGUI.disable()
|
||||
} else if (settingWindow?.listeningChild == null) {
|
||||
when {
|
||||
typedChar.isLetter() || typedChar == ' ' -> {
|
||||
typedString += typedChar
|
||||
stringWidth = FontRenderAdapter.getStringWidth(typedString, 1.666f)
|
||||
lastTypedTime = System.currentTimeMillis()
|
||||
} else {
|
||||
super.keyTyped(typedChar, keyCode)
|
||||
|
||||
val string = typedString.replace(" ", "")
|
||||
setModuleVisibility { moduleButton ->
|
||||
moduleButton.module.name.contains(string, true)
|
||||
|| moduleButton.module.alias.any { it.contains(string, true) }
|
||||
}
|
||||
val string = typedString.replace(" ", "")
|
||||
|
||||
if (string.isNotEmpty()) {
|
||||
setModuleButtonVisibility { moduleButton ->
|
||||
moduleButton.module.name.contains(string, true)
|
||||
|| moduleButton.module.alias.any { it.contains(string, true) }
|
||||
}
|
||||
} else {
|
||||
setModuleButtonVisibility { true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setModuleVisibility(function: (ModuleButton) -> Boolean) {
|
||||
private fun setModuleButtonVisibility(function: (ModuleButton) -> Boolean) {
|
||||
windowList.filterIsInstance<ListWindow>().forEach {
|
||||
for (child in it.children) {
|
||||
if (child !is ModuleButton) continue
|
||||
|
|
|
@ -35,15 +35,40 @@ object KamiHudGui : AbstractKamiGui<HudSettingWindow, HudElement>() {
|
|||
windowList.addAll(GuiManager.hudElementsMap.values)
|
||||
}
|
||||
|
||||
override fun onGuiClosed() {
|
||||
super.onGuiClosed()
|
||||
setHudButtonVisibility { true }
|
||||
}
|
||||
|
||||
override fun newSettingWindow(element: HudElement, mousePos: Vec2f): HudSettingWindow {
|
||||
return HudSettingWindow(element, mousePos.x, mousePos.y)
|
||||
}
|
||||
|
||||
override fun keyTyped(typedChar: Char, keyCode: Int) {
|
||||
if (keyCode == Keyboard.KEY_ESCAPE || HudEditor.bind.value.isDown(keyCode)) {
|
||||
if (keyCode == Keyboard.KEY_ESCAPE || HudEditor.bind.value.isDown(keyCode) && !searching) {
|
||||
HudEditor.disable()
|
||||
} else {
|
||||
super.keyTyped(typedChar, keyCode)
|
||||
|
||||
val string = typedString.replace(" ", "")
|
||||
|
||||
if (string.isNotEmpty()) {
|
||||
setHudButtonVisibility { hudButton ->
|
||||
hudButton.hudElement.name.contains(string, true)
|
||||
|| hudButton.hudElement.alias.any { it.contains(string, true) }
|
||||
}
|
||||
} else {
|
||||
setHudButtonVisibility { true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setHudButtonVisibility(function: (HudButton) -> Boolean) {
|
||||
windowList.filterIsInstance<ListWindow>().forEach {
|
||||
for (child in it.children) {
|
||||
if (child !is HudButton) continue
|
||||
child.visible = function(child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue