Repository navigation
feat(hud): add global HUD settings with a master toggle and per-property overrides #1112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v1
Are you sure you want to change the base?
Changes from 3 commits
f0c0710
469fc84
1d77343
6f5e319
e995613
310744b
ddbd4ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
|---|---|---|
|
|
@@ -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), | ||
| ) | ||
| ) | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 [P2] Invalidate the merge fast path when global backgrounds change
|
||
| 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) | ||
|
|
||
There was a problem hiding this comment.
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