Skip to content

Commit

Permalink
Added onKeyReleased to UIScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
odtheking committed Nov 12, 2024
1 parent 8efac98 commit 3f8e315
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 46 deletions.
22 changes: 13 additions & 9 deletions src/main/kotlin/com/github/stivais/ui/UIScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import me.odinmain.OdinMain.mc
import net.minecraft.client.gui.GuiScreen
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.input.Keyboard
import org.lwjgl.input.Mouse
import org.lwjgl.opengl.Display

open class UIScreen(val ui: UI) : GuiScreen(), Window {

private var previousWidth: Int = 0
private var previousHeight: Int = 0
private val pressedKeys = mutableSetOf<Int>()

fun close() {
if (mc.currentScreen == null) {
Expand Down Expand Up @@ -52,6 +54,13 @@ open class UIScreen(val ui: UI) : GuiScreen(), Window {
}
ui.render()
}

for (key in pressedKeys.toList()) {
if (!Keyboard.isKeyDown(key)) {
ui.eventManager.onKeyReleased(key)
pressedKeys.remove(key)
}
}
}

override fun handleMouseInput() {
Expand All @@ -72,18 +81,13 @@ open class UIScreen(val ui: UI) : GuiScreen(), Window {

override fun keyTyped(typedChar: Char, keyCode: Int) {
if (ui.eventManager.onKeyType(typedChar)) return
if (ui.eventManager.onKeycodePressed(keyCode)) return
if (ui.eventManager.onKeycodePressed(keyCode)) {
pressedKeys.add(keyCode)
return
}
super.keyTyped(typedChar, keyCode)
}

// no key released because 1.8.9 doesn't have it and I don't want to manually recreate it
// override fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
// if (ui.eventManager?.onKeyReleased(keyCode) == true) {
// return true
// }
// return super.keyPressed(keyCode, scanCode, modifiers)
// }

override fun doesGuiPauseGame(): Boolean = false

companion object {
Expand Down
37 changes: 0 additions & 37 deletions src/main/kotlin/me/odinmain/features/impl/skyblock/Ragaxe.kt

This file was deleted.

0 comments on commit 3f8e315

Please sign in to comment.