Skip to content

Commit 1ce4b32

Browse files
committed
3.4.0
closes #126
1 parent 1bfeaaf commit 1ce4b32

13 files changed

Lines changed: 161 additions & 69 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## 3.3.0
2-
- CPS options for Keystrokes
3-
- Background options for Armor Status, Inventory, and Player Preview huds
1+
## 3.4.0
2+
- Facing hud, a text alternative to the Direction compass
3+
- Background merging for the Resource Pack, Item Lore, Clock, Mouse Strokes, Shapes, Potion Effects, Direction, and Position huds

‎build.gradle.kts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ bloom {
2727
}
2828

2929
repositories {
30+
mavenLocal()
3031
mavenCentral()
3132
gradlePluginPortal()
3233
google()

‎src/main/kotlin/org/polyfrost/evergreenhud/client/EvergreenHudClient.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object EvergreenHudClient : ClientModInitializer {
4545
ArmorHud(),
4646
BiomeHud(), BlockAboveHud(),
4747
ClockHud(), DigitalClockHud(), ComboHud(), CpsHud(),
48-
DayHud(), DirectionHud(), EntityCounterHud(), FpsHud(),
48+
DayHud(), DirectionHud(), EntityCounterHud(), FacingHud(), FpsHud(),
4949
InGameTimeHud(), InventoryHud(),
5050
KeystrokesHud(),
5151
LoreHud(), MemoryHud(), MouseStrokesHud(),
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package org.polyfrost.evergreenhud.client.hud
2+
3+
import org.polyfrost.evergreenhud.client.utils.CachedTextHud
4+
import org.polyfrost.evergreenhud.client.utils.Facing
5+
import org.polyfrost.oneconfig.api.config.v1.annotations.Dropdown
6+
import org.polyfrost.oneconfig.api.config.v1.annotations.Switch
7+
import org.polyfrost.oneconfig.utils.v1.dsl.mc
8+
import kotlin.math.roundToInt
9+
import kotlin.time.Duration.Companion.milliseconds
10+
11+
private val CARDINALS = arrayOf(Facing.NORTH, Facing.EAST, Facing.SOUTH, Facing.WEST)
12+
13+
class FacingHud : CachedTextHud(
14+
title = "Facing",
15+
category = Category.INFO,
16+
defaultText = "North"
17+
) {
18+
@Dropdown(title = "Style", options = ["Full", "Abbreviated"])
19+
var style = 0
20+
21+
@Switch(title = "Show Intercardinals", description = "Show North East, South East, South West and North West.")
22+
var showIntercardinals = true
23+
24+
@Switch(title = "Show Bearing", description = "Append the exact bearing in degrees.")
25+
var showBearing = false
26+
27+
@Switch(title = "Show Axis", description = "Append the axis you are travelling towards, such as +X.")
28+
var showAxis = false
29+
30+
override fun setup() {
31+
super.setup()
32+
33+
if (isReal) {
34+
updateWhenChanged("style")
35+
updateWhenChanged("showIntercardinals")
36+
updateWhenChanged("showBearing")
37+
updateWhenChanged("showAxis")
38+
}
39+
}
40+
41+
override fun getText(): String {
42+
val yaw = mc.player?.yRot ?: return defaultText
43+
val bearing = Facing.bearingOf(yaw)
44+
val facing = if (showIntercardinals) {
45+
Facing.parse(yaw)
46+
} else {
47+
CARDINALS[(bearing / 90f).roundToInt() % 4]
48+
}
49+
50+
return buildString {
51+
append(if (style == 1) facing.abbreviated else facing.full)
52+
53+
if (showAxis) {
54+
append(' ').append(axisOf(facing))
55+
}
56+
57+
if (showBearing) {
58+
append(" (").append(bearing.roundToInt() % 360).append("°)")
59+
}
60+
}
61+
}
62+
63+
override fun updateFrequency(): Long = 50.milliseconds.inWholeNanoseconds
64+
65+
private fun axisOf(facing: Facing): String = when (facing) {
66+
Facing.NORTH -> "-Z"
67+
Facing.SOUTH -> "+Z"
68+
Facing.EAST -> "+X"
69+
Facing.WEST -> "-X"
70+
Facing.NORTH_EAST -> "+X -Z"
71+
Facing.SOUTH_EAST -> "+X +Z"
72+
Facing.SOUTH_WEST -> "-X +Z"
73+
Facing.NORTH_WEST -> "-X -Z"
74+
}
75+
}

‎src/main/kotlin/org/polyfrost/evergreenhud/client/hud/ResourcePackHud.kt‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import org.polyfrost.compose.composables.PolyMcText
2020
import org.polyfrost.compose.composables.PolyModifier
2121
import org.polyfrost.compose.composables.PolyRow
2222
import org.polyfrost.compose.composables.PolyText
23-
import org.polyfrost.compose.composables.background
2423
import org.polyfrost.compose.composables.padding
2524
import org.polyfrost.compose.composables.size
2625
import org.polyfrost.compose.mc.McFontQueue
@@ -178,6 +177,8 @@ class ResourcePackHud : Hud(
178177

179178
override fun defaultPosition(): Pair<Float, Float> = 0f to 0f
180179

180+
override fun canMergeBackground(): Boolean = true
181+
181182
override fun updateFrequency(): Long = 1.seconds.inWholeNanoseconds
182183

183184
override fun setup() {
@@ -215,12 +216,7 @@ class ResourcePackHud : Hud(
215216

216217
val lines = wrap(packDescription.value, DESCRIPTION_WIDTH * scale, measure)
217218

218-
var modifier = PolyModifier.padding(padLeft, padTop, padRight, padBottom)
219-
if (showBackground) {
220-
modifier = PolyModifier
221-
.background(PolyColor(bgColor, bgChroma, bgChromaSpeed), bgRadius)
222-
.padding(padLeft, padTop, padRight, padBottom)
223-
}
219+
val modifier = hudBackground().padding(padLeft, padTop, padRight, padBottom)
224220

225221
PolyBox(modifier = modifier) {
226222
PolyRow(gap = GAP * scale) {

‎src/main/kotlin/org/polyfrost/evergreenhud/client/hud/clock/ClockHud.kt‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.compose.runtime.LaunchedEffect
99
import androidx.compose.runtime.withFrameMillis
1010
import org.polyfrost.compose.composables.PolyBox
1111
import org.polyfrost.compose.composables.PolyModifier
12-
import org.polyfrost.compose.composables.background
1312
import org.polyfrost.compose.composables.size
1413
import org.polyfrost.compose.render.PolyColor
1514
import org.polyfrost.evergreenhud.client.utils.copy
@@ -21,6 +20,8 @@ import org.polyfrost.oneconfig.api.hud.v1.Hud
2120
import java.time.LocalTime
2221
import java.time.ZoneId
2322

23+
private const val DEFAULT_SIDE = 64f
24+
2425
private const val DETAIL_FIVE_MINUTE_MARKS = 0
2526
private const val DETAIL_MINUTE_MARKS = 1
2627
private const val DETAIL_NUMBERS = 2
@@ -53,6 +54,12 @@ class ClockHud : Hud(
5354

5455
private var rev = mutableStateOf(0)
5556

57+
private var _staticW = mutableStateOf(DEFAULT_SIDE)
58+
override var staticW: Float get() = _staticW.value; set(v) { _staticW.value = v }
59+
60+
private var _staticH = mutableStateOf(DEFAULT_SIDE)
61+
override var staticH: Float get() = _staticH.value; set(v) { _staticH.value = v }
62+
5663
override fun defaultPosition(): Pair<Float, Float> = 0f to 0f
5764

5865
override fun clone(): Hud = (super.clone() as ClockHud).apply {
@@ -61,6 +68,8 @@ class ClockHud : Hud(
6168
minuteHandColor = this@ClockHud.minuteHandColor.copy()
6269
secondHandColor = this@ClockHud.secondHandColor.copy()
6370
rev = mutableStateOf(0)
71+
_staticW = mutableStateOf(this@ClockHud.staticW)
72+
_staticH = mutableStateOf(this@ClockHud.staticH)
6473
}
6574

6675
fun applyGlobalColor(color: PolyColor) {
@@ -78,17 +87,14 @@ class ClockHud : Hud(
7887
}
7988
}
8089
staticWidth = true
81-
val side = when {
82-
staticW < 16f || staticH < 16f -> 64f
83-
staticW == 200f && staticH == 48f -> 64f
84-
else -> minOf(staticW, staticH)
85-
}
86-
staticW = side
87-
staticH = side
90+
tree?.getProp("staticW")?.addMetadata("default", DEFAULT_SIDE)
91+
tree?.getProp("staticH")?.addMetadata("default", DEFAULT_SIDE)
8892
}
8993

9094
override fun minimumSize(): Pair<Float, Float> = 16f to 16f
9195

96+
override fun canMergeBackground(): Boolean = true
97+
9298
@Composable
9399
override fun Content() {
94100
rev.value
@@ -107,10 +113,9 @@ class ClockHud : Hud(
107113
val detailColor = PolyColor(textColor, textChroma, textChromaSpeed)
108114
val fontName = getPoppinsFontName()
109115
if (showBackground) {
110-
PolyBox(
111-
modifier = sizeModifier
112-
.background(PolyColor(bgColor, bgChroma, bgChromaSpeed), bgRadius)
113-
) {
116+
// when merged, HudManager draws this HUD's background as part of the fused neighbour
117+
// shape, which hudBackground() accounts for
118+
PolyBox(modifier = hudBackground(sizeModifier)) {
114119
Clock(timeMillis, handWidth, ticking, fiveMinuteMarks, minuteMarks, numbers, hourHandColor, minuteHandColor, secondHandColor, detailColor, fontName, bgRadius, sizeModifier)
115120
}
116121
} else {

‎src/main/kotlin/org/polyfrost/evergreenhud/client/hud/direction/DirectionHud.kt‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
44
import androidx.compose.runtime.LaunchedEffect
55
import androidx.compose.runtime.getValue
66
import androidx.compose.runtime.mutableFloatStateOf
7+
import androidx.compose.runtime.mutableStateOf
78
import androidx.compose.runtime.remember
89
import androidx.compose.runtime.withFrameMillis
910
import org.polyfrost.compose.composables.PolyBox
@@ -13,7 +14,6 @@ import org.polyfrost.compose.composables.PolyModifier
1314
import org.polyfrost.compose.composables.PolyText
1415
import org.polyfrost.compose.composables.absoluteAt
1516
import org.polyfrost.compose.composables.align
16-
import org.polyfrost.compose.composables.background
1717
import org.polyfrost.compose.composables.clip
1818
import org.polyfrost.compose.composables.size
1919
import org.polyfrost.compose.layout.PolyAlign
@@ -45,6 +45,10 @@ private const val FADE_START = 0.55f
4545

4646
private const val PREVIEW_BEARING = 22.5f
4747

48+
private const val DEFAULT_WIDTH = 140f
49+
50+
private const val DEFAULT_HEIGHT = 24f
51+
4852
class DirectionHud : Hud(
4953
id = "direction.json",
5054
title = "Direction",
@@ -75,24 +79,30 @@ class DirectionHud : Hud(
7579
@Color(title = "Tick Color")
7680
var tickColor = PolyColor(0xFFAAAAAA.toInt())
7781

82+
private var _staticW = mutableStateOf(DEFAULT_WIDTH)
83+
override var staticW: Float get() = _staticW.value; set(v) { _staticW.value = v }
84+
85+
private var _staticH = mutableStateOf(DEFAULT_HEIGHT)
86+
override var staticH: Float get() = _staticH.value; set(v) { _staticH.value = v }
87+
7888
override fun setup() {
7989
super.setup()
8090
staticWidth = true
81-
if (staticW == 200f && staticH == 48f) {
82-
staticW = 140f
83-
staticH = 24f
84-
}
85-
if (staticW < 32f) staticW = 140f
86-
if (staticH < 12f) staticH = 24f
91+
tree?.getProp("staticW")?.addMetadata("default", DEFAULT_WIDTH)
92+
tree?.getProp("staticH")?.addMetadata("default", DEFAULT_HEIGHT)
8793
}
8894

8995
override fun minimumSize(): Pair<Float, Float> = 32f to 12f
9096

9197
override fun defaultPosition(): Pair<Float, Float> = 0f to 0f
9298

99+
override fun canMergeBackground(): Boolean = true
100+
93101
override fun update(): Boolean = false
94102

95103
override fun clone(): Hud = (super.clone() as DirectionHud).apply {
104+
_staticW = mutableStateOf(this@DirectionHud.staticW)
105+
_staticH = mutableStateOf(this@DirectionHud.staticH)
96106
markerColor = markerColor.copy()
97107
tickColor = tickColor.copy()
98108
}
@@ -110,10 +120,7 @@ class DirectionHud : Hud(
110120
}
111121
val bearing by bearingState
112122

113-
var modifier = PolyModifier.size(scaledWidth, scaledHeight)
114-
if (showBackground) {
115-
modifier = modifier.background(PolyColor(bgColor, bgChroma, bgChromaSpeed), bgRadius)
116-
}
123+
val modifier = hudBackground(PolyModifier.size(scaledWidth, scaledHeight))
117124
PolyBox(modifier = modifier.clip(bgRadius)) {
118125
Compass(bearing)
119126
}

‎src/main/kotlin/org/polyfrost/evergreenhud/client/hud/mouse/MouseStrokesHud.kt‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import org.jetbrains.skia.PathBuilder
1313
import org.polyfrost.compose.composables.PolyBox
1414
import org.polyfrost.compose.composables.PolyCanvas
1515
import org.polyfrost.compose.composables.PolyModifier
16-
import org.polyfrost.compose.composables.background
1716
import org.polyfrost.compose.composables.clip
1817
import org.polyfrost.compose.composables.size
1918
import org.polyfrost.compose.render.PolyColor
@@ -44,6 +43,8 @@ private const val PREVIEW_X = 0.45f
4443

4544
private const val PREVIEW_Y = -0.3f
4645

46+
private const val DEFAULT_SIDE = 48f
47+
4748
class MouseStrokesHud : Hud(
4849
id = "mousestrokes.json",
4950
title = "Mouse Strokes",
@@ -112,15 +113,17 @@ class MouseStrokesHud : Hud(
112113
@Transient
113114
private var lastFrameMs = 0L
114115

116+
private var _staticW = mutableStateOf(DEFAULT_SIDE)
117+
override var staticW: Float get() = _staticW.value; set(v) { _staticW.value = v }
118+
119+
private var _staticH = mutableStateOf(DEFAULT_SIDE)
120+
override var staticH: Float get() = _staticH.value; set(v) { _staticH.value = v }
121+
115122
override fun setup() {
116123
super.setup()
117124
staticWidth = true
118-
if (staticW == 200f && staticH == 48f) {
119-
staticW = 48f
120-
staticH = 48f
121-
}
122-
if (staticW < 16f) staticW = 48f
123-
if (staticH < 16f) staticH = 48f
125+
tree?.getProp("staticW")?.addMetadata("default", DEFAULT_SIDE)
126+
tree?.getProp("staticH")?.addMetadata("default", DEFAULT_SIDE)
124127

125128
if (isReal) {
126129
hideIf("snakeMs") { dotType != SNAKE }
@@ -134,6 +137,8 @@ class MouseStrokesHud : Hud(
134137

135138
override fun defaultPosition(): Pair<Float, Float> = 0f to 0f
136139

140+
override fun canMergeBackground(): Boolean = true
141+
137142
override fun update(): Boolean = false
138143

139144
override fun remove() {
@@ -142,6 +147,8 @@ class MouseStrokesHud : Hud(
142147
}
143148

144149
override fun clone(): Hud = (super.clone() as MouseStrokesHud).apply {
150+
_staticW = mutableStateOf(this@MouseStrokesHud.staticW)
151+
_staticH = mutableStateOf(this@MouseStrokesHud.staticH)
145152
dotColor = dotColor.copy()
146153
}
147154

@@ -157,10 +164,7 @@ class MouseStrokesHud : Hud(
157164
}
158165
val offset by position
159166

160-
var modifier = PolyModifier.size(scaledWidth, scaledHeight)
161-
if (showBackground) {
162-
modifier = modifier.background(PolyColor(bgColor, bgChroma, bgChromaSpeed), bgRadius)
163-
}
167+
val modifier = hudBackground(PolyModifier.size(scaledWidth, scaledHeight))
164168
PolyBox(modifier = modifier.clip(bgRadius)) {
165169
PolyCanvas(PolyModifier.size(scaledWidth, scaledHeight)) { x, y, w, h ->
166170
draw(offset, x, y, w, h)

‎src/main/kotlin/org/polyfrost/evergreenhud/client/hud/potion/PotionEffectsHud.kt‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import org.polyfrost.compose.composables.PolyModifier
1818
import org.polyfrost.compose.composables.PolyRow
1919
import org.polyfrost.compose.composables.PolyText
2020
import org.polyfrost.compose.composables.align
21-
import org.polyfrost.compose.composables.background
2221
import org.polyfrost.compose.composables.padding
2322
import org.polyfrost.compose.composables.size
2423
import org.polyfrost.compose.layout.PolyAlign
@@ -161,6 +160,8 @@ class PotionEffectsHud : Hud(
161160

162161
override fun defaultPosition(): Pair<Float, Float> = 0f to 0f
163162

163+
override fun canMergeBackground(): Boolean = true
164+
164165
override fun update(): Boolean {
165166
syncIcons(mc.resourcePackRepository.selectedPacks.map { it.id })
166167
val next = buildRows()
@@ -230,12 +231,7 @@ class PotionEffectsHud : Hud(
230231
if (list.isEmpty()) return
231232
val scale = textScale.coerceAtLeast(0.01f)
232233

233-
var modifier = PolyModifier.padding(padLeft, padTop, padRight, padBottom)
234-
if (showBackground) {
235-
modifier = PolyModifier
236-
.background(PolyColor(bgColor, bgChroma, bgChromaSpeed), bgRadius)
237-
.padding(padLeft, padTop, padRight, padBottom)
238-
}
234+
val modifier = hudBackground().padding(padLeft, padTop, padRight, padBottom)
239235

240236
PolyBox(modifier = modifier) {
241237
PolyColumn(gap = spacing * scale) {

0 commit comments

Comments
 (0)