11package net .cyberflame .viewmodel .gui ;
22
3+ import net .cyberflame .viewmodel .config .SaveConfig ;
34import net .cyberflame .viewmodel .settings .FloatSetting ;
45import net .minecraft .client .gui .DrawContext ;
56import net .minecraft .util .math .MathHelper ;
910import java .math .BigDecimal ;
1011import java .math .RoundingMode ;
1112
12- /**
13- * Современный слайдер с эффектом Liquid Glass в стиле iOS.
14- */
1513public class Slider implements ViewmodelGuiObj {
1614
1715 private final FloatSetting setting ;
1816 private final int x , y , width , height ;
1917 private final float min , max ;
2018 private boolean isDragging = false ;
2119 private boolean isHovered = false ;
22- private String tooltip = "" ;
2320 private float hoverAnimation = 0.0f ;
2421
2522 public Slider (@ NotNull FloatSetting setting , int x , int y , int width , int height ) {
2623 this .setting = setting ;
2724 this .x = x ;
28- this .y = y ;
25+ this .y = y + 30 ; // Смещаем вниз для текста сверху
2926 this .width = width ;
30- this .height = height ;
27+ this .height = 16 ; // Фиксированная высота слайдера
3128 this .min = setting .getMin ();
3229 this .max = setting .getMax ();
3330 }
3431
35- public void setTooltip (String tooltip ) {
36- this .tooltip = tooltip ;
37- }
38-
3932 private static float round (float value ) {
4033 BigDecimal bd = new BigDecimal (value );
4134 bd = bd .setScale (2 , RoundingMode .HALF_UP );
@@ -50,6 +43,8 @@ public final void mouseScrolled(double mx, double my, float incx, float incy) {
5043 float increment = (this .max - this .min ) * 0.01f ;
5144 float newValue = this .setting .getValue () + delta * increment ;
5245 this .setting .setValue (MathHelper .clamp (newValue , this .min , this .max ));
46+
47+ SaveConfig .saveAllSettings ();
5348 }
5449
5550 @ Override
@@ -76,14 +71,15 @@ private void updateValue(double mx) {
7671 float ratio = (float ) MathHelper .clamp ((mx - this .x ) / this .width , 0.0 , 1.0 );
7772 float newValue = this .min + ratio * (this .max - this .min );
7873 this .setting .setValue (MathHelper .clamp (newValue , this .min , this .max ));
74+
75+ SaveConfig .saveAllSettings ();
7976 }
8077
8178 @ Override
8279 public final void render (@ NotNull DrawContext context , int mouseX , int mouseY ) {
8380 boolean wasHovered = isHovered ;
8481 isHovered = isWithin (mouseX , mouseY );
8582
86- // Плавная анимация hover - уменьшается только если НЕ перетаскиваем
8783 if (isHovered || isDragging ) {
8884 hoverAnimation = Math .min (1.0f , hoverAnimation + 0.15f );
8985 } else {
@@ -93,52 +89,50 @@ public final void render(@NotNull DrawContext context, int mouseX, int mouseY) {
9389 String settingName = this .setting .getName ();
9490 float settingValue = this .setting .getValue ();
9591
96- // Название слева с иконкой для вложенных настроек
92+ // Текст сверху слева
9793 int nameColor = isHovered ? 0xFFFFFFFF : 0xFFCCCCCC ;
9894 context .drawTextWithShadow (
9995 ViewmodelScreen .mc .textRenderer ,
10096 settingName ,
101- this .x - ViewmodelScreen . mc . textRenderer . getWidth ( settingName ) - 10 ,
102- this .y + this . height / 2 - ViewmodelScreen . mc . textRenderer . fontHeight / 2 ,
97+ this .x ,
98+ this .y - 15 ,
10399 nameColor
104100 );
105101
106- // Glass card фон
102+ // Значение сверху справа
103+ String valueStr = String .valueOf (round (settingValue ));
104+ int valueWidth = ViewmodelScreen .mc .textRenderer .getWidth (valueStr );
105+ int valueColor = isDragging ? 0xFF66B2FF : (isHovered ? 0xFFFFFFFF : 0xFFCCCCCC );
106+ context .drawTextWithShadow (
107+ ViewmodelScreen .mc .textRenderer ,
108+ valueStr ,
109+ this .x + this .width - valueWidth + 32 ,
110+ this .y + 4 ,
111+ valueColor
112+ );
113+
107114 int cardAlpha = (int ) (0x35 + hoverAnimation * 0x15 );
108115 int bgColor = (cardAlpha << 24 ) | 0xFFFFFF ;
109116
110- // Тень
111117 context .fill (this .x + 1 , this .y + 1 , this .x + this .width + 1 , this .y + this .height + 1 , 0x40000000 );
112-
113- // Основной фон с градиентом
114118 context .fill (this .x , this .y , this .x + this .width , this .y + this .height , bgColor );
115119
116- // Верхний блик (glass эффект)
117- context .fill (this .x , this .y , this .x + this .width , this .y + this .height / 3 , 0x15FFFFFF );
118-
119- // Прогресс бар с градиентом
120120 float ratio = (settingValue - this .min ) / (this .max - this .min );
121121 int filledWidth = (int ) (this .width * ratio );
122122
123123 if (filledWidth > 0 ) {
124- // Цветной градиент в зависимости от значения
125124 int progressColor ;
126125 if (isDragging ) {
127- progressColor = 0xFF66B2FF ; // Яркий синий при перетаскивании
126+ progressColor = 0xFF66B2FF ;
128127 } else if (isHovered ) {
129- progressColor = 0xFF4A9EE0 ; // Средний синий при наведении
128+ progressColor = 0xFF4A9EE0 ;
130129 } else {
131- progressColor = 0xFF3A8ED0 ; // Базовый синий
130+ progressColor = 0xFF3A8ED0 ;
132131 }
133132
134- // Основной прогресс
135133 context .fill (this .x , this .y , this .x + filledWidth , this .y + this .height , progressColor );
136-
137- // Блик на прогрессе
138- context .fill (this .x , this .y , this .x + filledWidth , this .y + this .height / 3 , 0x30FFFFFF );
139134 }
140135
141- // СНАЧАЛА рисуем рамку
142136 int borderColor ;
143137 if (isDragging ) {
144138 borderColor = 0xFF66B2FF ;
@@ -149,109 +143,40 @@ public final void render(@NotNull DrawContext context, int mouseX, int mouseY) {
149143 }
150144 drawBorder (context , this .x , this .y , this .width , this .height , borderColor );
151145
152- // ПОТОМ анимированную ручку слайдера (поверх всего) - более округлую
153146 int handleX = this .x + filledWidth ;
154- int baseHandleSize = this .height + 4 ; // Базовый размер больше высоты
155- int handleSize = baseHandleSize + (int ) (hoverAnimation * 3 ); // Меньше увеличение
156- int handleY = this .y - 2 - (int ) (hoverAnimation * 1.5f ); // Меньше смещение
147+ int baseHandleSize = this .height + 4 ;
148+ int handleSize = baseHandleSize + (int ) (hoverAnimation * 3 );
149+ int handleY = this .y - 2 - (int ) (hoverAnimation * 1.5f );
157150
158- // Ограничиваем ручку, чтобы не выпирала
159151 int handleHalfSize = handleSize / 2 ;
160152 handleX = Math .max (this .x + handleHalfSize , Math .min (this .x + this .width - handleHalfSize , handleX ));
161153
162- // Рисуем более округлую ручку
163154 drawRoundedHandle (context , handleX - handleHalfSize , handleY , handleSize , handleSize ,
164155 isDragging ? 0xFFFFFFFF : 0xFFF0F0F0 );
165-
166- // Значение справа с glass подложкой
167- String valueStr = String .valueOf (round (settingValue ));
168- int valueWidth = ViewmodelScreen .mc .textRenderer .getWidth (valueStr );
169- int valueX = this .x + this .width + 8 ;
170- int valueY = this .y + this .height / 2 - ViewmodelScreen .mc .textRenderer .fontHeight / 2 ;
171-
172- // Glass подложка для значения
173- if (isHovered || isDragging ) {
174- context .fill (valueX - 3 , valueY - 2 , valueX + valueWidth + 3 ,
175- valueY + ViewmodelScreen .mc .textRenderer .fontHeight + 2 , 0x30FFFFFF );
176- }
177-
178- int valueColor = isDragging ? 0xFF66B2FF : (isHovered ? 0xFFFFFFFF : 0xFFCCCCCC );
179- context .drawTextWithShadow (ViewmodelScreen .mc .textRenderer , valueStr , valueX , valueY , valueColor );
180-
181- // Подсказка при наведении
182- if (isHovered && !tooltip .isEmpty () && !isDragging ) {
183- renderTooltip (context , mouseX , mouseY );
184- }
185156 }
186157
187- /**
188- * Рисует округлую ручку слайдера
189- */
190158 private void drawRoundedHandle (DrawContext context , int x , int y , int width , int height , int color ) {
191- // Тень
192159 drawCircle (context , x + 1 , y + 1 , width , height , 0x60000000 );
193-
194- // Основа ручки
195160 drawCircle (context , x , y , width , height , color );
196-
197- // Блик (верхняя половина)
198- int blickHeight = height / 2 ;
199- drawCircle (context , x , y , width , blickHeight , 0x40FFFFFF );
200- }
201-
202- /**
203- * Рисует подсказку с glass эффектом
204- */
205- private void renderTooltip (DrawContext context , int mouseX , int mouseY ) {
206- int tooltipWidth = ViewmodelScreen .mc .textRenderer .getWidth (tooltip );
207- int tooltipX = mouseX + 10 ;
208- int tooltipY = mouseY - 20 ;
209-
210- // Проверка границ экрана
211- if (tooltipX + tooltipWidth + 8 > ViewmodelScreen .mc .getWindow ().getScaledWidth ()) {
212- tooltipX = mouseX - tooltipWidth - 10 ;
213- }
214-
215- // Glass фон
216- context .fill (tooltipX - 4 , tooltipY - 3 , tooltipX + tooltipWidth + 4 ,
217- tooltipY + ViewmodelScreen .mc .textRenderer .fontHeight + 3 , 0x90000000 );
218- context .fill (tooltipX - 4 , tooltipY - 3 , tooltipX + tooltipWidth + 4 ,
219- tooltipY + 2 , 0x30FFFFFF );
220-
221- // Рамка
222- drawBorder (context , tooltipX - 4 , tooltipY - 3 , tooltipWidth + 8 ,
223- ViewmodelScreen .mc .textRenderer .fontHeight + 6 , 0x60FFFFFF );
224-
225- // Текст
226- context .drawTextWithShadow (ViewmodelScreen .mc .textRenderer , tooltip ,
227- tooltipX , tooltipY , 0xFFFFFFFF );
228161 }
229162
230- /**
231- * Рисует рамку
232- */
233163 private void drawBorder (DrawContext context , int x , int y , int width , int height , int color ) {
234164 context .fill (x , y , x + width , y + 1 , color );
235165 context .fill (x , y + height - 1 , x + width , y + height , color );
236166 context .fill (x , y , x + 1 , y + height , color );
237167 context .fill (x + width - 1 , y , x + width , y + height , color );
238168 }
239169
240- /**
241- * Рисует круг/овал (имитация)
242- */
243170 private void drawCircle (DrawContext context , int x , int y , int width , int height , int color ) {
244171 int rx = width / 2 ;
245172 int ry = height / 2 ;
246173 int cx = x + rx ;
247174 int cy = y + ry ;
248175
249- // Основной прямоугольник
250176 context .fill (x + 2 , y , x + width - 2 , y + height , color );
251177 context .fill (x , y + 2 , x + 2 , y + height - 2 , color );
252178 context .fill (x + width - 2 , y + 2 , x + width , y + height - 2 , color );
253179
254- // Сглаживание углов для более круглой формы
255180 context .fill (x + 1 , y + 1 , x + 3 , y + 3 , color );
256181 context .fill (x + width - 3 , y + 1 , x + width - 1 , y + 3 , color );
257182 context .fill (x + 1 , y + height - 3 , x + 3 , y + height - 1 , color );
0 commit comments