Skip to content

Commit

Permalink
using reflect to get all TextBoxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunderblade73 committed Jan 14, 2024
1 parent 018a614 commit c966221
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzKeyPressEvent
import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.getPropertiesWithType
import at.hannibal2.skyhanni.utils.LorenzUtils.isRancherSign
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
Expand Down Expand Up @@ -51,6 +53,7 @@ class GuiEditManager {
}

companion object {

var currentPositions = mutableMapOf<String, Position>()
private var latestPositions = mapOf<String, Position>()
private var currentBorderSize = mutableMapOf<String, Pair<Int, Int>>()
Expand All @@ -77,8 +80,8 @@ class GuiEditManager {
lastHotkeyReminded = SimpleTimeMark.now()
LorenzUtils.chat(
"§eTo edit hidden GUI elements:\n" +
" §7- §e1. Set a key in /sh edit.\n" +
" §7- §e2. Click that key while the GUI element is visible."
" §7- §e1. Set a key in /sh edit.\n" +
" §7- §e2. Click that key while the GUI element is visible."
)
}
}
Expand Down Expand Up @@ -112,7 +115,8 @@ class GuiEditManager {

fun Position.getAbsY() = getAbsY0(getDummySize(true).y)

fun GuiProfileViewer.anyTextBoxFocused() = this.playerNameTextField.focus || this.inventoryTextField.focus || this.killDeathSearchTextField.focus
fun GuiProfileViewer.anyTextBoxFocused() =
this.getPropertiesWithType<GuiElementTextField>().any{it.focus}
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KProperty
import kotlin.reflect.KProperty0
import kotlin.reflect.KProperty1
import kotlin.reflect.full.isSubtypeOf
import kotlin.reflect.full.memberProperties
import kotlin.reflect.full.starProjectedType
import kotlin.reflect.jvm.isAccessible
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

Expand Down Expand Up @@ -501,6 +506,14 @@ object LorenzUtils {
}
}

inline fun <reified T : Any> Any.getPropertiesWithType() =
this::class.memberProperties
.filter { it.returnType.isSubtypeOf(T::class.starProjectedType) }
.map {
it.isAccessible = true
(it as KProperty1<Any, T>).get(this)
}

fun List<String>.nextAfter(after: String, skip: Int = 1) = nextAfter({ it == after }, skip)

fun List<String>.nextAfter(after: (String) -> Boolean, skip: Int = 1): String? {
Expand Down

0 comments on commit c966221

Please sign in to comment.