aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt21
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt21
4 files changed, 31 insertions, 30 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt
index 9fca47fbc..1140379b6 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardDisplay.kt
@@ -16,7 +16,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
-import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeUtils.format
@@ -26,7 +25,6 @@ import net.minecraft.client.gui.GuiChat
import net.minecraft.client.gui.inventory.GuiInventory
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.days
-import kotlin.time.Duration.Companion.milliseconds
class BingoCardDisplay {
@@ -101,8 +99,6 @@ class BingoCardDisplay {
return newList
}
- private var lastClick = SimpleTimeMark.farPast()
-
private fun MutableList<Renderable>.addCommunityGoals() {
add(Renderable.string("§6Community Goals:"))
val goals = BingoAPI.communityGoals.toMutableList()
@@ -197,9 +193,6 @@ class BingoCardDisplay {
add("§eClick to $clickName this goal as highlight!")
},
onClick = {
- if (lastClick.passedSince() < 300.milliseconds) return@clickAndHover
- lastClick = SimpleTimeMark.now()
-
it.highlight = !currentlyHighlighted
it.displayName
update()
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt
index 2c265d6a5..32562bde7 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt
@@ -28,9 +28,11 @@ object KeyboardManager {
private fun isControlKeyDown() = Keyboard.KEY_LCONTROL.isKeyHeld() || Keyboard.KEY_RCONTROL.isKeyHeld()
- fun isDeleteWordDown() = Keyboard.KEY_BACK.isKeyHeld() && if (SystemUtils.IS_OS_MAC) isMenuKeyDown() else isControlKeyDown()
+ fun isDeleteWordDown() =
+ Keyboard.KEY_BACK.isKeyHeld() && if (SystemUtils.IS_OS_MAC) isMenuKeyDown() else isControlKeyDown()
- fun isDeleteLineDown() = Keyboard.KEY_BACK.isKeyHeld() && if (SystemUtils.IS_OS_MAC) isCommandKeyDown() else isControlKeyDown() && isShiftKeyDown()
+ fun isDeleteLineDown() =
+ Keyboard.KEY_BACK.isKeyHeld() && if (SystemUtils.IS_OS_MAC) isCommandKeyDown() else isControlKeyDown() && isShiftKeyDown()
fun isShiftKeyDown() = Keyboard.KEY_LSHIFT.isKeyHeld() || Keyboard.KEY_RSHIFT.isKeyHeld()
@@ -111,5 +113,20 @@ object KeyboardManager {
}
}
+ private val pressedKeys = mutableMapOf<Int, Boolean>()
+
+ /** Can only be used once per click. Since the function locks itself until the key is no longer held*/
+ fun Int.isKeyClicked(): Boolean = if (this.isKeyHeld()) {
+ if (pressedKeys[this] != true) {
+ pressedKeys[this] = true
+ true
+ } else {
+ false
+ }
+ } else {
+ pressedKeys[this] = false
+ false
+ }
+
fun getKeyName(keyCode: Int): String = KeybindHelper.getKeyName(keyCode)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
index 128cd4482..a73e408d6 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
@@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.features.chroma.ChromaShaderManager
import at.hannibal2.skyhanni.features.chroma.ChromaType
import at.hannibal2.skyhanni.utils.ColorUtils
import at.hannibal2.skyhanni.utils.ColorUtils.darker
+import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.NEUItems
@@ -28,7 +29,6 @@ import net.minecraft.client.gui.inventory.GuiEditSign
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.item.ItemStack
import net.minecraft.util.ResourceLocation
-import org.lwjgl.input.Mouse
import java.awt.Color
import java.util.Collections
import kotlin.math.max
@@ -131,16 +131,12 @@ interface Renderable {
override val horizontalAlign = render.horizontalAlign
override val verticalAlign = render.verticalAlign
- private var wasDown = false
-
override fun render(posX: Int, posY: Int) {
- val isDown = Mouse.isButtonDown(button)
- if (isDown > wasDown && isHovered(posX, posY) && condition() &&
- shouldAllowLink(true, bypassChecks)
+ if (isHovered(posX, posY) && condition() &&
+ shouldAllowLink(true, bypassChecks) && (button - 100).isKeyClicked()
) {
onClick()
}
- wasDown = isDown
render.render(posX, posY)
}
}
@@ -429,7 +425,7 @@ interface Renderable {
percent.toInt()
}
- private var color = if (texture == null) {
+ private val color = if (texture == null) {
ColorUtils.blendRGB(startColor, endColor, percent)
} else {
startColor
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt
index 46bb84f04..5e15a3a89 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt
@@ -31,8 +31,6 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
val SKYBLOCK_COIN = NEUInternalName.SKYBLOCK_COIN
}
- private var lastClickDelay = 0L
-
fun addCoins(coins: Int) {
addItem(SKYBLOCK_COIN, coins)
}
@@ -131,19 +129,16 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
val lore = buildLore(data, itemProfit, hidden, newDrop, internalName)
val renderable = if (isInventoryOpen()) Renderable.clickAndHover(displayName, lore,
onClick = {
- if (System.currentTimeMillis() > lastClickDelay + 150) {
- if (KeyboardManager.isModifierKeyDown()) {
- data.items.remove(internalName)
- ChatUtils.chat("Removed $cleanName §efrom $name.")
- lastClickDelay = System.currentTimeMillis() + 500
- } else {
- modify {
- it.items[internalName]?.hidden = !hidden
- }
- lastClickDelay = System.currentTimeMillis()
+ if (KeyboardManager.isModifierKeyDown()) {
+ data.items.remove(internalName)
+ ChatUtils.chat("Removed $cleanName §efrom $name.")
+ } else {
+ modify {
+ it.items[internalName]?.hidden = !hidden
}
- update()
}
+ update()
+
}
) else Renderable.string(displayName)