Skip to content

Commit

Permalink
Improvement: Focus Mode Options (#2844)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
hannibal002 and hannibal002 authored Oct 27, 2024
1 parent 45d20d1 commit 50ee0e0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
import io.github.notenoughupdates.moulconfig.annotations.SearchTag;
import org.lwjgl.input.Keyboard;

public class FocusModeConfig {

@Expose
@ConfigOption(name = "Enabled", desc = "In focus mode you only see the name of the item instead of the whole description.")
@ConfigOption(name = "Enabled", desc = "In focus mode you only see the name of the item instead of the whole description. §eSet a Toggle key below to use.")
@SearchTag("compact hide")
@ConfigEditorBoolean
@FeatureToggle
public boolean enabled = false;
Expand All @@ -19,4 +21,14 @@ public class FocusModeConfig {
@ConfigOption(name = "Toggle Key", desc = "Key to toggle the focus mode on and off.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
public int toggleKey = Keyboard.KEY_NONE;

@Expose
@ConfigOption(name = "Disable Hint", desc = "Disable the line in item tooltips that show how to enable or disable this feature via key press.")
@ConfigEditorBoolean
public boolean disableHint = false;

@Expose
@ConfigOption(name = "Always Enabled", desc = "Ignore the keybind and enable this feature all the time.")
@ConfigEditorBoolean
public boolean alwaysEnabled = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked
import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraftforge.fml.common.eventhandler.EventPriority
Expand All @@ -15,20 +16,36 @@ object FocusMode {

private val config get() = SkyHanniMod.feature.inventory.focusMode

private var toggle = true
private var active = false

@SubscribeEvent(priority = EventPriority.LOWEST)
fun onLorenzToolTip(event: LorenzToolTipEvent) {
if (!isEnabled() || !toggle) return
if (!isEnabled()) return
if (event.toolTip.isEmpty()) return
event.toolTip = mutableListOf(event.toolTip.first())
val keyName = KeyboardManager.getKeyName(config.toggleKey)

val hint = !config.disableHint && !config.alwaysEnabled && keyName != "NONE"
if (active || config.alwaysEnabled) {
event.toolTip = buildList {
add(event.toolTip.first())
if (hint) {
add("§7Focus Mode from SkyHanni active!")
add("Press $keyName to disable!")
}
}.toMutableList()
} else {
if (hint) {
event.toolTip.add(1, "§7Press $keyName to enable Focus Mode from SkyHanni!")
}
}
}

@SubscribeEvent
fun onLorenzTick(event: LorenzTickEvent) {
if (!isEnabled()) return
if (config.alwaysEnabled) return
if (!config.toggleKey.isKeyClicked()) return
toggle = !toggle
active = !active
}

fun isEnabled() = LorenzUtils.inSkyBlock && InventoryUtils.inContainer() && config.enabled
Expand Down

0 comments on commit 50ee0e0

Please sign in to comment.