@@ -50,6 +50,14 @@ enum class Font {
5050 Poppins ;
5151}
5252
53+ enum class Section {
54+ TopLeft , TopCenter , TopRight ,
55+ CenterLeft , Center , CenterRight ,
56+ BottomLeft , BottomCenter , BottomRight
57+ }
58+
59+ private const val GRID_SIZE = 3
60+
5361@Suppress(" EqualsOrHashCode" , " UnstableApiUsage" )
5462abstract class Hud (id : String , title : String , val category : Category ) : Cloneable, Config(id, null , title, null ) {
5563 private var _staticWidth : MutableState <Boolean > = mutableStateOf(false )
@@ -67,18 +75,103 @@ abstract class Hud(id: String, title: String, val category: Category) : Cloneabl
6775 var toggleKey: Int = - 1
6876 var showKey: Int = - 1
6977
70- private var _x : MutableState <Float > = mutableStateOf(0f )
71- var x : Float get() = _x .value; set(v) { _x .value = v }
78+ private var _section : MutableState <Section > = mutableStateOf(Section . TopLeft )
79+ var section : Section get() = _section .value; set(v) { _section .value = v }
7280
73- private var _y : MutableState <Float > = mutableStateOf(0f )
74- var y: Float get() = _y .value; set(v) { _y .value = v }
81+ private var _relativeX : MutableState <Float > = mutableStateOf(0f )
82+ var relativeX: Float get() = _relativeX .value; set(v) { _relativeX .value = v }
83+
84+ private var _relativeY : MutableState <Float > = mutableStateOf(0f )
85+ var relativeY: Float get() = _relativeY .value; set(v) { _relativeY .value = v }
7586
7687 private var _renderedW : MutableState <Float > = mutableStateOf(0f )
7788 var renderedW: Float get() = _renderedW .value; set(v) { _renderedW .value = v }
7889
7990 private var _renderedH : MutableState <Float > = mutableStateOf(0f )
8091 var renderedH: Float get() = _renderedH .value; set(v) { _renderedH .value = v }
8192
93+ val scaledWidth: Float get() {
94+ val w = if (staticWidth) staticW else renderedW
95+ return if (w > 0f ) w else 1f
96+ }
97+
98+ val scaledHeight: Float get() {
99+ val h = if (staticWidth) staticH else renderedH
100+ return if (h > 0f ) h else 1f
101+ }
102+
103+ var x: Float
104+ get() {
105+ val sw = HudManager .guiScreenWidth
106+ val secPos = (sw / GRID_SIZE * relativeX).toInt()
107+ return when (section) {
108+ Section .TopLeft , Section .CenterLeft , Section .BottomLeft -> secPos.toFloat()
109+ Section .TopCenter , Section .Center , Section .BottomCenter -> (sw - scaledWidth) / 2f + secPos
110+ Section .TopRight , Section .CenterRight , Section .BottomRight -> sw - scaledWidth - secPos
111+ }
112+ }
113+ set(v) { updateRelativeX(v) }
114+
115+ var y: Float
116+ get() {
117+ val sh = HudManager .guiScreenHeight
118+ val secPos = (sh / GRID_SIZE * relativeY).toInt()
119+ return when (section) {
120+ Section .TopLeft , Section .TopCenter , Section .TopRight -> secPos.toFloat()
121+ Section .CenterLeft , Section .Center , Section .CenterRight -> (sh - scaledHeight) / 2f + secPos
122+ Section .BottomLeft , Section .BottomCenter , Section .BottomRight -> sh - scaledHeight - secPos
123+ }
124+ }
125+ set(v) { updateRelativeY(v) }
126+
127+ private fun updateRelativeX (absX : Float ) {
128+ val sw = HudManager .guiScreenWidth
129+ val gridW = sw / GRID_SIZE
130+ relativeX = when (section) {
131+ Section .TopLeft , Section .CenterLeft , Section .BottomLeft -> absX / gridW
132+ Section .TopCenter , Section .Center , Section .BottomCenter -> (absX - (sw - scaledWidth) / 2f ) / gridW
133+ else -> (sw - scaledWidth - absX) / gridW
134+ }.coerceIn(- 1f , 2f )
135+ }
136+
137+ private fun updateRelativeY (absY : Float ) {
138+ val sh = HudManager .guiScreenHeight
139+ val gridH = sh / GRID_SIZE
140+ relativeY = when (section) {
141+ Section .TopLeft , Section .TopCenter , Section .TopRight -> absY / gridH
142+ Section .CenterLeft , Section .Center , Section .CenterRight -> (absY - (sh - scaledHeight) / 2f ) / gridH
143+ else -> (sh - scaledHeight - absY) / gridH
144+ }.coerceIn(- 1f , 2f )
145+ }
146+
147+ fun setAbsolutePosition (absX : Float , absY : Float ) {
148+ val sw = HudManager .guiScreenWidth
149+ val sh = HudManager .guiScreenHeight
150+ val gridW = sw / GRID_SIZE
151+ val gridH = sh / GRID_SIZE
152+
153+ section = when {
154+ absX < gridW -> when {
155+ absY > 2 * gridH -> Section .BottomLeft
156+ absY > gridH -> Section .CenterLeft
157+ else -> Section .TopLeft
158+ }
159+ absX < 2 * gridW -> when {
160+ absY > 2 * gridH -> Section .BottomCenter
161+ absY > gridH -> Section .Center
162+ else -> Section .TopCenter
163+ }
164+ else -> when {
165+ absY > 2 * gridH -> Section .BottomRight
166+ absY > gridH -> Section .CenterRight
167+ else -> Section .TopRight
168+ }
169+ }
170+
171+ updateRelativeX(absX)
172+ updateRelativeY(absY)
173+ }
174+
82175 var hidden: Boolean = false
83176
84177 private var _alignment : MutableState <PolyAlign > = mutableStateOf(PolyAlign .TopLeft )
@@ -123,6 +216,38 @@ abstract class Hud(id: String, title: String, val category: Category) : Cloneabl
123216 private var _textAlign : MutableState <Int > = mutableStateOf(1 )
124217 var textAlign: Int get() = _textAlign .value; set(v) { _textAlign .value = v }
125218
219+ private var _useGuiScale : MutableState <Boolean > = mutableStateOf(true )
220+ var useGuiScale: Boolean get() = _useGuiScale .value; set(v) { _useGuiScale .value = v }
221+
222+ private var _customScale : MutableState <Float > = mutableStateOf(1f )
223+ var customScale: Float get() = _customScale .value; set(v) { _customScale .value = v }
224+
225+ val effectiveScale: Float get() = if (useGuiScale) 1f else customScale
226+
227+ private var _showBackground : MutableState <Boolean > = mutableStateOf(true )
228+ var showBackground: Boolean get() = _showBackground .value; set(v) { _showBackground .value = v }
229+
230+ private var _bgColor : MutableState <Int > = mutableStateOf(0x80000000 .toInt())
231+ var bgColor: Int get() = _bgColor .value; set(v) { _bgColor .value = v }
232+
233+ private var _bgRadius : MutableState <Float > = mutableStateOf(4f )
234+ var bgRadius: Float get() = _bgRadius .value; set(v) { _bgRadius .value = v }
235+
236+ private var _textColor : MutableState <Int > = mutableStateOf(0xFFFFFFFF .toInt())
237+ var textColor: Int get() = _textColor .value; set(v) { _textColor .value = v }
238+
239+ private var _showShadow : MutableState <Boolean > = mutableStateOf(false )
240+ var showShadow: Boolean get() = _showShadow .value; set(v) { _showShadow .value = v }
241+
242+ private var _shadowColor : MutableState <Int > = mutableStateOf(0x40000000 )
243+ var shadowColor: Int get() = _shadowColor .value; set(v) { _shadowColor .value = v }
244+
245+ private var _shadowOffsetX : MutableState <Float > = mutableStateOf(2f )
246+ var shadowOffsetX: Float get() = _shadowOffsetX .value; set(v) { _shadowOffsetX .value = v }
247+
248+ private var _shadowOffsetY : MutableState <Float > = mutableStateOf(2f )
249+ var shadowOffsetY: Float get() = _shadowOffsetY .value; set(v) { _shadowOffsetY .value = v }
250+
126251 override fun addToInitQueue () {}
127252
128253 val isReal get() = tree != null
@@ -156,8 +281,9 @@ abstract class Hud(id: String, title: String, val category: Category) : Cloneabl
156281 tree.addMetadata(" category" , category)
157282 tree.addMetadata(" hidden" , true )
158283 var hidden = { Property .Display .HIDDEN }
159- tree[" x" ] = ktProperty(out ::x).apply { addDisplayCondition(hidden) }
160- tree[" y" ] = ktProperty(out ::y).apply { addDisplayCondition(hidden) }
284+ tree[" section" ] = ktProperty(out ::section).apply { addDisplayCondition(hidden) }
285+ tree[" relativeX" ] = ktProperty(out ::relativeX).apply { addDisplayCondition(hidden) }
286+ tree[" relativeY" ] = ktProperty(out ::relativeY).apply { addDisplayCondition(hidden) }
161287 tree[" toggleKey" ] = ktProperty(out ::toggleKey).apply { addDisplayCondition(hidden) }
162288 tree[" showKey" ] = ktProperty(out ::showKey).apply { addDisplayCondition(hidden) }
163289 tree[" alignment" ] = ktProperty(out ::alignment).apply { addDisplayCondition(hidden) }
@@ -175,6 +301,16 @@ abstract class Hud(id: String, title: String, val category: Category) : Cloneabl
175301 tree[" textItalic" ] = ktProperty(out ::textItalic).apply { addDisplayCondition(hidden) }
176302 tree[" textUnderline" ] = ktProperty(out ::textUnderline).apply { addDisplayCondition(hidden) }
177303 tree[" textAlign" ] = ktProperty(out ::textAlign).apply { addDisplayCondition(hidden) }
304+ tree[" useGuiScale" ] = ktProperty(out ::useGuiScale).apply { addDisplayCondition(hidden) }
305+ tree[" customScale" ] = ktProperty(out ::customScale).apply { addDisplayCondition(hidden) }
306+ tree[" showBackground" ] = ktProperty(out ::showBackground).apply { addDisplayCondition(hidden) }
307+ tree[" bgColor" ] = ktProperty(out ::bgColor).apply { addDisplayCondition(hidden) }
308+ tree[" bgRadius" ] = ktProperty(out ::bgRadius).apply { addDisplayCondition(hidden) }
309+ tree[" textColor" ] = ktProperty(out ::textColor).apply { addDisplayCondition(hidden) }
310+ tree[" showShadow" ] = ktProperty(out ::showShadow).apply { addDisplayCondition(hidden) }
311+ tree[" shadowColor" ] = ktProperty(out ::shadowColor).apply { addDisplayCondition(hidden) }
312+ tree[" shadowOffsetX" ] = ktProperty(out ::shadowOffsetX).apply { addDisplayCondition(hidden) }
313+ tree[" shadowOffsetY" ] = ktProperty(out ::shadowOffsetY).apply { addDisplayCondition(hidden) }
178314 addToSerialized(tree)
179315 tree[" hudClass" ] = simple(value = out ::class .java.name).apply {
180316 addDisplayCondition { Property .Display .HIDDEN }
@@ -216,8 +352,9 @@ abstract class Hud(id: String, title: String, val category: Category) : Cloneabl
216352 showKey = - 1
217353 toggleKey = - 1
218354 _staticWidth = mutableStateOf(this @Hud.staticWidth)
219- _x = mutableStateOf(this @Hud.x)
220- _y = mutableStateOf(this @Hud.y)
355+ _section = mutableStateOf(this @Hud.section)
356+ _relativeX = mutableStateOf(this @Hud.relativeX)
357+ _relativeY = mutableStateOf(this @Hud.relativeY)
221358 _renderedW = mutableStateOf(0f )
222359 _renderedH = mutableStateOf(0f )
223360 _alignment = mutableStateOf(this @Hud.alignment)
@@ -234,6 +371,16 @@ abstract class Hud(id: String, title: String, val category: Category) : Cloneabl
234371 _textItalic = mutableStateOf(this @Hud.textItalic)
235372 _textUnderline = mutableStateOf(this @Hud.textUnderline)
236373 _textAlign = mutableStateOf(this @Hud.textAlign)
374+ _useGuiScale = mutableStateOf(this @Hud.useGuiScale)
375+ _customScale = mutableStateOf(this @Hud.customScale)
376+ _showBackground = mutableStateOf(this @Hud.showBackground)
377+ _bgColor = mutableStateOf(this @Hud.bgColor)
378+ _bgRadius = mutableStateOf(this @Hud.bgRadius)
379+ _textColor = mutableStateOf(this @Hud.textColor)
380+ _showShadow = mutableStateOf(this @Hud.showShadow)
381+ _shadowColor = mutableStateOf(this @Hud.shadowColor)
382+ _shadowOffsetX = mutableStateOf(this @Hud.shadowOffsetX)
383+ _shadowOffsetY = mutableStateOf(this @Hud.shadowOffsetY)
237384 }
238385
239386 class Category (val name : String , val id : Byte ) {
0 commit comments