Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.util.Collections
import java.util.WeakHashMap
import net.minecraft.client.gui.GuiGraphicsExtractor
import org.apache.logging.log4j.LogManager
import org.polyfrost.oneconfig.api.hud.v1.GlobalHudSettings
import org.polyfrost.oneconfig.api.hud.v1.HudManager
import org.polyfrost.oneconfig.api.hud.v1.LegacyHud

Expand Down Expand Up @@ -45,6 +46,7 @@ object LegacyHudRenderer {
for (hud in HudManager.activeInstances) {
if (hud !is LegacyHud) continue
if (!HudManager.isEditing) {
if (!GlobalHudSettings.enabled) continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 [P2] Apply the master visibility switch to compatibility HUDs

With compatibility-wrapped HUDs such as Skyblocker widgets, disabling the HUD overlay still leaves those elements visible after exiting the editor. They implement LegacyHudMarker, not LegacyHud, so this loop skips them; HudManager also excludes them, while their original rendering hooks only check CompatOverlayRenderer.oneConfigScreenOpen(). Gate the compatibility rendering paths on the master switch too, without overwriting individual HUD visibility preferences.

if (hud.hidden) continue
if (HudManager.isGuiHidden) continue
if (HudManager.isDebugScreenVisible && !hud.showInF3) continue
Expand Down
20 changes: 20 additions & 0 deletions minecraft/src/main/resources/assets/oneconfig/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@
"oneconfig.preferences.hud_marquee_anim_duration.title": "Selection Box Animation Duration (ms)",
"oneconfig.preferences.hud_marquee_anim_duration.description": "The duration of the fade animation for the drag selection rectangle in milliseconds.",

"oneconfig.preferences.category.global_hud": "Global HUD",
"oneconfig.preferences.global_hud_enabled.title": "Enable HUD Overlay",
"oneconfig.preferences.global_hud_enabled.description": "Show or hide every custom HUD element at once.",
"oneconfig.preferences.global_hud_font_override.title": "Override Font",
"oneconfig.preferences.global_hud_font_override.description": "Forces every HUD to use the global font instead of its own.",
"oneconfig.preferences.global_hud_font.title": "Global Font",
"oneconfig.preferences.global_hud_font.description": "The font every HUD uses while the override is on.",
"oneconfig.preferences.global_hud_weight_override.title": "Override Text Weight",
"oneconfig.preferences.global_hud_weight_override.description": "Forces every HUD to use the global weight instead of its own.",
"oneconfig.preferences.global_hud_weight.title": "Global Text Weight",
"oneconfig.preferences.global_hud_weight.description": "The Poppins weight every HUD uses while the override is on.",
"oneconfig.preferences.global_hud_background_override.title": "Override Backgrounds",
"oneconfig.preferences.global_hud_background_override.description": "Forces every HUD to use the global background setting instead of its own.",
"oneconfig.preferences.global_hud_show_background.title": "Show Backgrounds",
"oneconfig.preferences.global_hud_show_background.description": "Whether HUD backgrounds are drawn while the override is on.",
"oneconfig.preferences.global_hud_radius_override.title": "Override Corner Radius",
"oneconfig.preferences.global_hud_radius_override.description": "Forces every HUD background to use the global radius instead of its own.",
"oneconfig.preferences.global_hud_radius.title": "Global Corner Radius",
"oneconfig.preferences.global_hud_radius.description": "The corner radius in pixels every HUD uses while the override is on.",

"oneconfig.preferences.background_blur.title": "Background Blur",
"oneconfig.preferences.background_blur.description": "Blurs the full game background when the OneConfig menu is open.",

Expand Down
28 changes: 28 additions & 0 deletions modules/hud/api/hud.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ public final class org/polyfrost/oneconfig/api/hud/v1/Font : java/lang/Enum {
public static fun values ()[Lorg/polyfrost/oneconfig/api/hud/v1/Font;
}

public final class org/polyfrost/oneconfig/api/hud/v1/GlobalHudSettings {
public static final field $stable I
public static final field INSTANCE Lorg/polyfrost/oneconfig/api/hud/v1/GlobalHudSettings;
public static final fun getBackgroundRadius ()F
public static final fun getEnabled ()Z
public static final fun getFont ()Lorg/polyfrost/oneconfig/api/hud/v1/Font;
public static final fun getOverrideBackgroundRadius ()Z
public static final fun getOverrideFont ()Z
public static final fun getOverrideShowBackground ()Z
public static final fun getOverrideTextWeight ()Z
public static final fun getShowBackground ()Z
public static final fun getTextWeight ()Lorg/polyfrost/oneconfig/api/hud/v1/Weight;
public static final fun setBackgroundRadius (F)V
public static final fun setEnabled (Z)V
public static final fun setFont (Lorg/polyfrost/oneconfig/api/hud/v1/Font;)V
public static final fun setOverrideBackgroundRadius (Z)V
public static final fun setOverrideFont (Z)V
public static final fun setOverrideShowBackground (Z)V
public static final fun setOverrideTextWeight (Z)V
public static final fun setShowBackground (Z)V
public static final fun setTextWeight (Lorg/polyfrost/oneconfig/api/hud/v1/Weight;)V
}

public abstract class org/polyfrost/oneconfig/api/hud/v1/Hud : org/polyfrost/oneconfig/api/config/v1/Config, java/lang/Cloneable {
public static final field $stable I
public field lastLayoutFrame J
Expand Down Expand Up @@ -53,9 +76,13 @@ public abstract class org/polyfrost/oneconfig/api/hud/v1/Hud : org/polyfrost/one
public fun getDescription ()Ljava/lang/String;
public final fun getEffectiveAnchorParent ()Lorg/polyfrost/oneconfig/api/hud/v1/Hud;
public final fun getEffectiveAnchorPoint ()Lorg/polyfrost/oneconfig/api/hud/v1/HudAnchor;
public final fun getEffectiveBackgroundRadius ()F
public final fun getEffectiveFont ()Lorg/polyfrost/oneconfig/api/hud/v1/Font;
public final fun getEffectiveGrowthAnchor ()Lorg/polyfrost/oneconfig/api/hud/v1/HudAnchor;
public final fun getEffectiveScale ()F
public final fun getEffectiveSelfAnchorPoint ()Lorg/polyfrost/oneconfig/api/hud/v1/HudAnchor;
public final fun getEffectiveShowBackground ()Z
public final fun getEffectiveTextWeight ()Lorg/polyfrost/oneconfig/api/hud/v1/Weight;
public final fun getFont ()Lorg/polyfrost/oneconfig/api/hud/v1/Font;
public final fun getGrowthAnchor ()Lorg/polyfrost/oneconfig/api/hud/v1/HudAnchor;
public fun getHidden ()Z
Expand Down Expand Up @@ -307,6 +334,7 @@ public final class org/polyfrost/oneconfig/api/hud/v1/HudManager {
public final fun render (Lorg/polyfrost/compose/render/RenderContext;FF)V
public static final fun setMergeExclusions (Ljava/util/Collection;)V
public final fun setProfileReloadDispatcher (Ljava/util/function/Consumer;)V
public static final fun storeProviderLook (Lorg/polyfrost/oneconfig/api/hud/v1/Hud;)V
public final fun toggleAllHuds (Lorg/polyfrost/oneconfig/api/hud/v1/Hud;Z)V
public final fun toggleEditor ()V
public final fun unregister (Lorg/polyfrost/oneconfig/api/hud/v1/Hud;ZZ)Ljava/util/ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* This file is part of OneConfig.
* OneConfig - Next Generation Config Library for Minecraft: Java Edition
* Copyright (C) 2021~2024 Polyfrost.
* <https://polyfrost.org> <https://github.com/Polyfrost/>
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* OneConfig is licensed under the terms of Version 3 of the GNU Lesser
* General Public License as published by the Free Software Foundation, AND
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
* either version 1.0 of the Additional Terms, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License. If not, see <https://www.gnu.org/licenses/>. You should
* have also received a copy of the Additional Terms Applicable
* to OneConfig, as published by Polyfrost. If not, see
* <https://polyfrost.org/legal/oneconfig/additional-terms>
*/

package org.polyfrost.oneconfig.api.hud.v1

import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf

/**
* User preferences applied on top of every [Hud] at once
*
* Appearance settings pair an override switch with a value: while it is off a HUD keeps its own
* look, while it is on the global value wins through the `effective...` accessors on [Hud], which
* HUDs drawing their own content should read instead of the raw properties
*/
object GlobalHudSettings {
private val _enabled: MutableState<Boolean> = mutableStateOf(true)
private val _overrideFont: MutableState<Boolean> = mutableStateOf(false)
private val _font: MutableState<Font> = mutableStateOf(Font.Minecraft)
private val _overrideTextWeight: MutableState<Boolean> = mutableStateOf(false)
private val _textWeight: MutableState<Weight> = mutableStateOf(Weight.Regular)
private val _overrideShowBackground: MutableState<Boolean> = mutableStateOf(false)
private val _showBackground: MutableState<Boolean> = mutableStateOf(true)
private val _overrideBackgroundRadius: MutableState<Boolean> = mutableStateOf(false)
private val _backgroundRadius: MutableState<Float> = mutableStateOf(4f)

/** Master switch for every custom HUD element; the HUD editor keeps drawing them while it is off */
@JvmStatic
var enabled: Boolean
get() = _enabled.value
set(value) { _enabled.value = value }

/** Whether [font] replaces the per-HUD [Hud.font] everywhere */
@JvmStatic
var overrideFont: Boolean
get() = _overrideFont.value
set(value) { _overrideFont.value = value }

/** The font forced onto every HUD while [overrideFont] is on */
@JvmStatic
var font: Font
get() = _font.value
set(value) { _font.value = value }

/** Whether [textWeight] replaces the per-HUD [Hud.textWeight] everywhere */
@JvmStatic
var overrideTextWeight: Boolean
get() = _overrideTextWeight.value
set(value) { _overrideTextWeight.value = value }

/** The Poppins weight forced onto every HUD while [overrideTextWeight] is on */
@JvmStatic
var textWeight: Weight
get() = _textWeight.value
set(value) { _textWeight.value = value }

/** Whether [showBackground] replaces the per-HUD [Hud.showBackground] everywhere */
@JvmStatic
var overrideShowBackground: Boolean
get() = _overrideShowBackground.value
set(value) { _overrideShowBackground.value = value }

/** Whether HUD backgrounds are drawn while [overrideShowBackground] is on */
@JvmStatic
var showBackground: Boolean
get() = _showBackground.value
set(value) { _showBackground.value = value }

/** Whether [backgroundRadius] replaces the per-HUD [Hud.bgRadius] everywhere */
@JvmStatic
var overrideBackgroundRadius: Boolean
get() = _overrideBackgroundRadius.value
set(value) { _overrideBackgroundRadius.value = value }

/** The background corner radius forced onto every HUD while [overrideBackgroundRadius] is on */
@JvmStatic
var backgroundRadius: Float
get() = _backgroundRadius.value
set(value) { _backgroundRadius.value = value }
}
Original file line number Diff line number Diff line change
Expand Up @@ -878,12 +878,32 @@ abstract class Hud(id: String, title: String, val category: Category) : Cloneabl
return if (gui > 0f) customScale / gui else customScale
}

/**
* The font this HUD renders with right now: the global one while [GlobalHudSettings.overrideFont]
* is on, otherwise this HUD's own [font]
*/
val effectiveFont: Font
get() = if (GlobalHudSettings.overrideFont) GlobalHudSettings.font else font

/** [effectiveFont] for [textWeight]; only applies while the HUD uses Poppins */
val effectiveTextWeight: Weight
get() = if (GlobalHudSettings.overrideTextWeight) GlobalHudSettings.textWeight else textWeight

/** [effectiveFont] for [showBackground] */
val effectiveShowBackground: Boolean
get() = if (GlobalHudSettings.overrideShowBackground) GlobalHudSettings.showBackground else showBackground

/** [effectiveFont] for [bgRadius] */
val effectiveBackgroundRadius: Float
get() = if (GlobalHudSettings.overrideBackgroundRadius) GlobalHudSettings.backgroundRadius else bgRadius

fun getPoppinsFontName(): String {
val weight = effectiveTextWeight
val base = when {
textBold || textWeight == Weight.Bold -> "poppins-bold"
textWeight == Weight.Thin -> "poppins-thin"
textWeight == Weight.Medium -> "poppins-medium"
textWeight == Weight.Black -> "poppins-black"
textBold || weight == Weight.Bold -> "poppins-bold"
weight == Weight.Thin -> "poppins-thin"
weight == Weight.Medium -> "poppins-medium"
weight == Weight.Black -> "poppins-black"
else -> "poppins"
}
return if (textItalic) "$base-italic" else base
Expand Down Expand Up @@ -917,7 +937,7 @@ abstract class Hud(id: String, title: String, val category: Category) : Cloneabl
var keepBgWhenHidden: Boolean get() = _keepBgWhenHidden.value; set(v) { _keepBgWhenHidden.value = v }

internal val keepsHiddenBackground: Boolean
get() = hidden && keepBgWhenHidden && showBackground && mergeBackground &&
get() = hidden && keepBgWhenHidden && effectiveShowBackground && mergeBackground &&
hasBackground() && canMergeBackground() && this !is LegacyHudMarker

/**
Expand Down Expand Up @@ -1175,8 +1195,8 @@ abstract class Hud(id: String, title: String, val category: Category) : Cloneabl
*/
@JvmOverloads
fun hudBackground(modifier: PolyModifier = PolyModifier): PolyModifier =
if (showBackground && hasBackground() && !bgMerged) {
modifier.background(PolyColor(bgColor, bgChroma, bgChromaSpeed), bgRadius)
if (effectiveShowBackground && hasBackground() && !bgMerged) {
modifier.background(PolyColor(bgColor, bgChroma, bgChromaSpeed), effectiveBackgroundRadius)
} else {
modifier
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ internal object HudBackgroundMerge {
for (hud in huds) {
if (hud is LegacyHudMarker) continue
if (!hud.canMergeBackground()) continue
if (!hud.showBackground || !hud.mergeBackground || !hud.hasBackground()) continue
if (!hud.effectiveShowBackground || !hud.mergeBackground || !hud.hasBackground()) continue
if (hud.hidden && !hud.keepBgWhenHidden) continue
val w = hud.renderedW
val h = hud.renderedH
if (w <= 0f || h <= 0f) continue
items.add(
Item(
hud, hud.x, hud.y, w, h, hud.bgRadius * hud.effectiveScale,
hud, hud.x, hud.y, w, h, hud.effectiveBackgroundRadius * hud.effectiveScale,
hud.layoutX(refWidth), hud.layoutY(refHeight),
)
)
Expand Down Expand Up @@ -495,8 +495,8 @@ internal object HudBackgroundMerge {
key = key * 31 + (hud.renderedW * 4f).roundToInt()
key = key * 31 + (hud.renderedH * 4f).roundToInt()
key = key * 31 + hud.bgColor
key = key * 31 + (hud.bgRadius * hud.effectiveScale * 4f).roundToInt()
key = key * 31 + (if (hud.showBackground) 1 else 0)
key = key * 31 + (hud.effectiveBackgroundRadius * hud.effectiveScale * 4f).roundToInt()
key = key * 31 + (if (hud.effectiveShowBackground) 1 else 0)
Comment on lines +500 to +501

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 [P2] Invalidate the merge fast path when global backgrounds change

When the new public API changes background overrides outside the editor, no HUD geometryStamp changes. HudManager.updateBackgroundGroups() consequently returns through its stable fast path before evaluating this updated key. Merged backgrounds retain stale visibility or radius, and newly matching backgrounds do not merge until another geometry change occurs. Include the global background settings in the fast-path invalidation; a targeted radius-override test reproduces the stale groups.

key = key * 31 + (if (hud.mergeBackground) 1 else 0)
key = key * 31 + (if (hud.mergeDiagonally) 1 else 0)
key = key * 31 + (if (hud.hidden) 1 else 0)
Expand Down
Loading
Loading