Skip to content

Commit 093e8a8

Browse files
committed
format number settings to keep float values concise in the NL click GUI
trim long option labels with tooltips and cap font selector width for better layout add hover tooltips to show full text for truncated string and font options
1 parent f23b306 commit 093e8a8

File tree

6 files changed

+109
-51
lines changed

6 files changed

+109
-51
lines changed

src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/nlclickgui/settings/BoolSetting.kt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* FDPClient Hacked Client
3+
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
4+
* https://github.com/SkidderMC/FDPClient/
5+
*/
16
package net.ccbluex.liquidbounce.ui.client.clickgui.style.styles.nlclickgui.settings
27

38
import net.ccbluex.liquidbounce.config.BoolValue
@@ -18,45 +23,42 @@ class BoolSetting(s: BoolValue, moduleRender: NlModule) : Downward<BoolValue>(s,
1823
private val hoveringAnimation: Animation = DecelerateAnimation(225, 1.0, Direction.BACKWARDS)
1924

2025
override fun draw(mouseX: Int, mouseY: Int) {
21-
val mainx = NeverloseGui.Companion.getInstance().x
22-
val mainy = NeverloseGui.Companion.getInstance().y
26+
val mainx = NeverloseGui.getInstance().x
27+
val mainy = NeverloseGui.getInstance().y
2328

2429
val booly = (y + getScrollY()).toInt()
2530

2631
Fonts.Nl.Nl_16.Nl_16.drawString(
2732
setting.name,
2833
(mainx + 100 + x),
2934
(mainy + booly + 57).toFloat(),
30-
if (NeverloseGui.Companion.getInstance().light) Color(95, 95, 95).rgb else -1
35+
if (NeverloseGui.getInstance().light) Color(95, 95, 95).rgb else -1
3136
)
3237

3338
val darkRectColor = Color(29, 29, 39, 255)
3439
val darkRectHover = RenderUtil.brighter(darkRectColor, .8f)
35-
val accentCircle = RenderUtil.darker(NeverloseGui.Companion.neverlosecolor, .5f)
40+
val accentCircle = RenderUtil.darker(NeverloseGui.neverlosecolor, .5f)
3641

3742
toggleAnimation.direction = if (setting.get()) Direction.FORWARDS else Direction.BACKWARDS
3843

39-
// CORREÇÃO: Adicionado .toFloat() na posição X
4044
hoveringAnimation.direction = if (
4145
RenderUtil.isHovering(
42-
(NeverloseGui.Companion.getInstance().x + 265 - 32 + x).toFloat(),
43-
(NeverloseGui.Companion.getInstance().y + (y + getScrollY()).toInt() + 57).toFloat(),
46+
(NeverloseGui.getInstance().x + 265 - 32 + x).toFloat(),
47+
(NeverloseGui.getInstance().y + (y + getScrollY()).toInt() + 57).toFloat(),
4448
16f,
4549
4.5f,
4650
mouseX,
4751
mouseY
4852
)
4953
) Direction.FORWARDS else Direction.BACKWARDS
5054

51-
// Fundo do Toggle
52-
// CORREÇÃO: Adicionado .toFloat() na posição X
53-
RoundedUtil.Companion.drawRound(
55+
RoundedUtil.drawRound(
5456
(mainx + 265 - 32 + x).toFloat(),
5557
(mainy + booly + 57).toFloat(),
5658
16f,
5759
4.5f,
5860
2f,
59-
if (NeverloseGui.Companion.getInstance().light) {
61+
if (NeverloseGui.getInstance().light) {
6062
RenderUtil.interpolateColorC(
6163
Color(230, 230, 230),
6264
Color(0, 112, 186),
@@ -71,7 +73,6 @@ class BoolSetting(s: BoolValue, moduleRender: NlModule) : Downward<BoolValue>(s,
7173
}
7274
)
7375

74-
// Efeito de Glow
7576
RenderUtil.fakeCircleGlow(
7677
(mainx + 265 + 3 - 32 + x + 11 * toggleAnimation.getOutput()).toFloat(),
7778
(mainy + booly + 59).toFloat(),
@@ -82,16 +83,15 @@ class BoolSetting(s: BoolValue, moduleRender: NlModule) : Downward<BoolValue>(s,
8283

8384
RenderUtil.resetColor()
8485

85-
// Bolinha do Toggle
86-
RoundedUtil.Companion.drawRound(
86+
RoundedUtil.drawRound(
8787
(mainx + 265 - 32 + x + 11 * toggleAnimation.getOutput()).toFloat(),
8888
(mainy + booly + 56).toFloat(),
8989
6.5f,
9090
6.5f,
9191
3f,
9292
if (setting.get()) {
93-
NeverloseGui.Companion.neverlosecolor
94-
} else if (NeverloseGui.Companion.getInstance().light) {
93+
NeverloseGui.neverlosecolor
94+
} else if (NeverloseGui.getInstance().light) {
9595
Color(255, 255, 255)
9696
} else {
9797
Color(
@@ -105,11 +105,10 @@ class BoolSetting(s: BoolValue, moduleRender: NlModule) : Downward<BoolValue>(s,
105105

106106
override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) {
107107
if (mouseButton == 0) {
108-
// CORREÇÃO: Adicionado .toFloat() na posição X
109108
if (
110109
RenderUtil.isHovering(
111-
(NeverloseGui.Companion.getInstance().x + 265 - 32 + x).toFloat(),
112-
(NeverloseGui.Companion.getInstance().y + (y + getScrollY()).toInt() + 57).toFloat(),
110+
(NeverloseGui.getInstance().x + 265 - 32 + x).toFloat(),
111+
(NeverloseGui.getInstance().y + (y + getScrollY()).toInt() + 57).toFloat(),
113112
16f,
114113
4.5f,
115114
mouseX,

src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/nlclickgui/settings/ColorSetting.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class ColorSetting(setting: ColorValue, moduleRender: NlModule) : Downward<Color
2828

2929
val titleColor = if (gui.light) Color(95, 95, 95).rgb else -1
3030

31-
// Verifique se Fonts.Nl_16 existe. Se der erro, mude para Fonts.Nl.Nl_16.Nl_16
3231
Fonts.Nl.Nl_16.Nl_16.drawString(setting.name, (mainx + 100 + x), (mainy + colory + 57).toFloat(), titleColor)
3332

3433
val currentColor = setting.selectedColor()
@@ -104,7 +103,6 @@ class ColorSetting(setting: ColorValue, moduleRender: NlModule) : Downward<Color
104103

105104
val hueColor = Color(Color.HSBtoRGB(setting.hueSliderY, 1f, 1f))
106105

107-
// Chamada da função drawGradientRect (Adicionei a definição lá embaixo)
108106
drawGradientRect(squareX.toInt(), squareY.toInt(), (squareX + squareSize).toInt(), (squareY + squareSize).toInt(), Color.WHITE.rgb, hueColor.rgb)
109107
drawGradientRect(squareX.toInt(), squareY.toInt(), (squareX + squareSize).toInt(), (squareY + squareSize).toInt(), Color(0, 0, 0, 0).rgb, Color(0, 0, 0, 255).rgb)
110108

@@ -197,7 +195,6 @@ class ColorSetting(setting: ColorValue, moduleRender: NlModule) : Downward<Color
197195
return if (gui.light) Color(95, 95, 95).rgb else -1
198196
}
199197

200-
// Esta função foi adicionada para corrigir o erro, pois ela era chamada mas não existia
201198
override fun drawGradientRect(left: Int, top: Int, right: Int, bottom: Int, startColor: Int, endColor: Int) {
202199
val f = (startColor shr 24 and 255).toFloat() / 255.0f
203200
val f1 = (startColor shr 16 and 255).toFloat() / 255.0f

src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/nlclickgui/settings/FontSetting.kt

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import net.ccbluex.liquidbounce.ui.client.clickgui.style.styles.nlclickgui.Rende
1313
import net.ccbluex.liquidbounce.ui.font.Fonts
1414
import java.awt.Color
1515
import kotlin.math.max
16+
import kotlin.math.min
1617

1718
class FontSetting(setting: FontValue, moduleRender: NlModule) : Downward<FontValue>(setting, moduleRender) {
1819

@@ -22,18 +23,15 @@ class FontSetting(setting: FontValue, moduleRender: NlModule) : Downward<FontVal
2223
val mainy = gui.y
2324
val fontY = (y + getScrollY()).toInt()
2425

25-
// Ajuste da Fonte para evitar erro de referência (padronizado com NlModule)
26-
// Se der erro, tente remover o ".Nl_16" extra
2726
Fonts.Nl.Nl_16.Nl_16.drawString(
2827
setting.name,
29-
(mainx + 100 + x),
28+
(mainx + 100 + x).toFloat(),
3029
(mainy + fontY + 57).toFloat(),
3130
if (gui.light) Color(95, 95, 95).rgb else -1
3231
)
3332

34-
val display = setting.displayName
35-
val widthStr = Fonts.Nl_15.stringWidth(display)
36-
val rectWidth = max(100, widthStr + 20)
33+
val (display, truncated) = abbreviate(setting.displayName)
34+
val rectWidth = calculateRectWidth(display)
3735

3836
val rectX = mainx + 170 + x
3937
val rectY = mainy + fontY + 54
@@ -49,25 +47,28 @@ class FontSetting(setting: FontValue, moduleRender: NlModule) : Downward<FontVal
4947
Color(13, 24, 35).rgb
5048
)
5149

52-
Fonts.Nl_15.drawString("<", rectX + 4, (rectY + 5).toFloat(), if (gui.light) Color(95, 95, 95).rgb else -1)
53-
Fonts.Nl_15.drawString(">", rectX + rectWidth - 9, (rectY + 5).toFloat(), if (gui.light) Color(95, 95, 95).rgb else -1)
50+
Fonts.Nl_15.drawString("<", (rectX + 4).toFloat(), (rectY + 5).toFloat(), if (gui.light) Color(95, 95, 95).rgb else -1)
51+
Fonts.Nl_15.drawString(">", (rectX + rectWidth - 9).toFloat(), (rectY + 5).toFloat(), if (gui.light) Color(95, 95, 95).rgb else -1)
5452

5553
Fonts.Nl_15.drawCenteredString(
5654
display,
5755
(rectX + rectWidth / 2f),
5856
(rectY + 5).toFloat(),
5957
if (gui.light) Color(95, 95, 95).rgb else -1
6058
)
59+
60+
if (truncated && RenderUtil.isHovering(rectX.toFloat(), rectY.toFloat(), rectWidth.toFloat(), 14f, mouseX, mouseY)) {
61+
drawTooltip(setting.displayName, mouseX, mouseY)
62+
}
6163
}
6264

6365
override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) {
6466
val gui = NeverloseGui.getInstance()
6567
val rectX = gui.x + 170 + x
6668
val rectY = gui.y + (y + getScrollY()).toInt() + 54
67-
val display = setting.displayName
69+
val display = abbreviate(setting.displayName).first
6870

69-
val widthStr = Fonts.Nl_15.stringWidth(display)
70-
val rectWidth = max(100, widthStr + 20)
71+
val rectWidth = calculateRectWidth(display)
7172

7273
if (mouseButton == 0 && RenderUtil.isHovering(rectX, rectY.toFloat(), rectWidth.toFloat(), 14f, mouseX, mouseY)) {
7374
val relativeX = mouseX - rectX
@@ -80,4 +81,26 @@ class FontSetting(setting: FontValue, moduleRender: NlModule) : Downward<FontVal
8081
}
8182

8283
override fun mouseReleased(mouseX: Int, mouseY: Int, state: Int) {}
84+
85+
private fun abbreviate(value: String): Pair<String, Boolean> {
86+
return if (value.length > 10) {
87+
value.take(10) + "..." to true
88+
} else {
89+
value to false
90+
}
91+
}
92+
93+
private fun calculateRectWidth(display: String): Int {
94+
return max(100, min(140, Fonts.Nl_15.stringWidth(display) + 20))
95+
}
96+
97+
private fun drawTooltip(text: String, mouseX: Int, mouseY: Int) {
98+
val width = Fonts.Nl_15.stringWidth(text) + 6
99+
val height = Fonts.Nl_15.height + 4
100+
val renderX = (mouseX + 6).toFloat()
101+
val renderY = (mouseY - height - 2).toFloat()
102+
103+
RenderUtil.drawRoundedRect(renderX, renderY, width.toFloat(), height.toFloat(), 2f, Color(0, 5, 19).rgb, 1f, Color(13, 24, 35).rgb)
104+
Fonts.Nl_15.drawString(text, renderX + 3f, renderY + 2f, Color.WHITE.rgb)
105+
}
83106
}

src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/nlclickgui/settings/Numbersetting.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import net.minecraft.util.MathHelper
2323
import org.lwjgl.input.Keyboard
2424
import org.lwjgl.opengl.GL11
2525
import java.awt.Color
26+
import java.text.DecimalFormat
27+
import java.text.DecimalFormatSymbols
28+
import java.util.Locale
2629
import kotlin.math.max
2730
import kotlin.math.min
2831
import kotlin.math.roundToInt
@@ -37,6 +40,10 @@ class Numbersetting(s: Value<*>, moduleRender: NlModule) : Downward<Value<*>>(s,
3740

3841
var HoveringAnimation: Animation = DecelerateAnimation(225, 1.0, Direction.BACKWARDS)
3942

43+
private val decimalFormat = DecimalFormat("#.##").also {
44+
it.decimalFormatSymbols = DecimalFormatSymbols(Locale.US)
45+
}
46+
4047
override fun draw(mouseX: Int, mouseY: Int) {
4148
val mainx = getInstance().x
4249
val mainy = getInstance().y
@@ -71,10 +78,9 @@ class Numbersetting(s: Value<*>, moduleRender: NlModule) : Downward<Value<*>>(s,
7178

7279
percent = max(0f, min(1f, (percent + (max(0.0, min(percentBar, 1.0)) - percent) * (0.2 / clamp)).toFloat()))
7380

74-
// Ajuste de fonte padronizado
7581
Fonts.Nl.Nl_16.Nl_16.drawString(
7682
setting.name,
77-
mainx + 100 + x,
83+
(mainx + 100 + x).toFloat(),
7884
(mainy + numbery + 57).toFloat(),
7985
if (getInstance().light) Color(95, 95, 95).rgb else -1
8086
)
@@ -112,7 +118,7 @@ class Numbersetting(s: Value<*>, moduleRender: NlModule) : Downward<Value<*>>(s,
112118
GL11.glTranslatef(0.0f, 0.0f, 2.0f)
113119
}
114120

115-
val displayString = if (isset) "${finalvalue ?: ""}_" else "$current"
121+
val displayString = if (isset) "${finalvalue ?: ""}_" else formatNumber(current)
116122

117123
val stringWidth = Fonts.Nl_15.stringWidth(displayString) + 4
118124

@@ -129,7 +135,7 @@ class Numbersetting(s: Value<*>, moduleRender: NlModule) : Downward<Value<*>>(s,
129135

130136
Fonts.Nl_15.drawString(
131137
displayString,
132-
mainx + 237 + x,
138+
(mainx + 237 + x).toFloat(),
133139
(mainy + numbery + 58).toFloat(),
134140
if (getInstance().light) Color(95, 95, 95).rgb else -1
135141
)
@@ -156,7 +162,7 @@ class Numbersetting(s: Value<*>, moduleRender: NlModule) : Downward<Value<*>>(s,
156162
}
157163
}
158164

159-
val displayString = if (isset) "${finalvalue ?: ""}_" else "$current"
165+
val displayString = if (isset) "${finalvalue ?: ""}_" else formatNumber(current)
160166
val stringWidth = Fonts.Nl_15.stringWidth(displayString) + 4
161167

162168
if (RenderUtil.isHovering(
@@ -169,7 +175,7 @@ class Numbersetting(s: Value<*>, moduleRender: NlModule) : Downward<Value<*>>(s,
169175
)
170176
) {
171177
if (mouseButton == 0) {
172-
finalvalue = current.toString()
178+
finalvalue = formatNumber(current)
173179
isset = true
174180
}
175181
} else {
@@ -226,4 +232,12 @@ class Numbersetting(s: Value<*>, moduleRender: NlModule) : Downward<Value<*>>(s,
226232
fun keynumbers(keyCode: Int): Boolean {
227233
return (keyCode == Keyboard.KEY_0 || keyCode == Keyboard.KEY_1 || keyCode == Keyboard.KEY_2 || keyCode == Keyboard.KEY_3 || keyCode == Keyboard.KEY_4 || keyCode == Keyboard.KEY_6 || keyCode == Keyboard.KEY_5 || keyCode == Keyboard.KEY_7 || keyCode == Keyboard.KEY_8 || keyCode == Keyboard.KEY_9 || keyCode == Keyboard.KEY_PERIOD || keyCode == Keyboard.KEY_MINUS)
228234
}
235+
236+
private fun formatNumber(value: Double): String {
237+
return if (setting is IntValue) {
238+
value.toInt().toString()
239+
} else {
240+
decimalFormat.format(value)
241+
}
242+
}
229243
}

src/main/java/net/ccbluex/liquidbounce/ui/client/clickgui/style/styles/nlclickgui/settings/RangeSetting.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class RangeSetting(
6464
val startX = barX + (60 * percentStart).toFloat()
6565
val endX = barX + (60 * percentEnd).toFloat()
6666

67-
// Fonte Ajustada para o padrão
6867
Fonts.Nl.Nl_16.Nl_16.drawString(
6968
setting.name,
7069
(mainx + 100 + x),

0 commit comments

Comments
 (0)