Skip to content

Commit d9d2da7

Browse files
committed
Updated
1 parent d92bd9e commit d9d2da7

File tree

11 files changed

+190
-557
lines changed

11 files changed

+190
-557
lines changed

.idea/jarRepositories.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradle.properties

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
# suppress inspection "AlphaUnsortedPropertiesFile" for whole file
2-
# Done to increase the memory available to gradle.
3-
org.gradle.jvmargs=-Xmx4G
4-
1+
org.gradle.jvmargs=-Xmx4G -Dfabric.skipXStartOnFirstThread=true
52
# Fabric Properties
63
# check these on https://modmuss50.me/fabric.html
74
minecraft_version=1.21.8
85
yarn_mappings=1.21.8+build.1
9-
loader_version=0.17.2
6+
loader_version=0.18.4
107
# Mod Properties
118
mod_version=1.10.7
129
maven_group=net.cyberflame
1310
archives_base_name=viewmodel
1411
# Dependencies
1512
# check this on https://modmuss50.me/fabric.html
16-
fabric_version=0.133.4+1.21.8
13+
fabric_version=0.136.1+1.21.8

src/main/java/net/cyberflame/viewmodel/config/LoadConfig.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
import java.nio.file.Path;
1515
import java.nio.file.Paths;
1616

17-
/**
18-
* @author ChiquitaV2
19-
*/
2017
public class LoadConfig {
2118

2219
public LoadConfig() throws IOException {
@@ -40,7 +37,7 @@ private void loadAllSettings() throws IOException {
4037
for (Setting value : Viewmodel.getSettings()) {
4138
JsonElement valueElement = viewmodelObj.get(value.getName());
4239
if (null == valueElement) continue;
43-
value.setValue(valueElement); // Polymorphism handles the specific type internally
40+
value.setValue(valueElement);
4441
}
4542

4643
inputStream.close();
@@ -51,6 +48,4 @@ private void loadAllSettings() throws IOException {
5148
inputStreamReader.close();
5249
}
5350
}
54-
55-
56-
}
51+
}

src/main/java/net/cyberflame/viewmodel/config/SaveConfig.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,22 @@
55
import com.google.gson.JsonObject;
66
import com.google.gson.JsonParser;
77
import net.cyberflame.viewmodel.Viewmodel;
8-
import net.cyberflame.viewmodel.util.Stopwatch;
98

109
import java.io.*;
1110
import java.nio.charset.StandardCharsets;
1211
import java.nio.file.Files;
1312
import java.nio.file.Path;
1413
import java.nio.file.Paths;
1514

16-
/**
17-
* @author ChiquitaV2
18-
*/
1915
public class SaveConfig {
2016

21-
private static Stopwatch saveTimer;
22-
2317
public SaveConfig() throws IOException {
2418
super();
2519
this.saveConfig();
2620
saveAllSettings();
27-
saveTimer = new Stopwatch();
28-
timedSave();
2921
}
3022

31-
static final String folderName = "Viewmodel/";
23+
public static final String folderName = "Viewmodel/";
3224

3325
private void saveConfig() throws IOException {
3426
Path dir = Paths.get(folderName);
@@ -42,12 +34,12 @@ public static void saveAllSettings() {
4234
makeFile(null, "Viewmodel");
4335

4436
Gson gson = new GsonBuilder().setPrettyPrinting().create();
45-
OutputStreamWriter fileOutStreamWriter = new OutputStreamWriter(new FileOutputStream(folderName + Viewmodel.VIEWMODEL_JSON), StandardCharsets.UTF_8);
37+
OutputStreamWriter fileOutStreamWriter = new OutputStreamWriter(
38+
new FileOutputStream(folderName + Viewmodel.VIEWMODEL_JSON), StandardCharsets.UTF_8);
4639
JsonObject viewmodelObj = new JsonObject();
4740

4841
Viewmodel.getSettings().forEach(value -> viewmodelObj.add(value.getName(), value.toJson()));
4942

50-
5143
String jsonString = gson.toJson(JsonParser.parseString(viewmodelObj.toString()));
5244
fileOutStreamWriter.write(jsonString);
5345
fileOutStreamWriter.close();
@@ -80,13 +72,5 @@ private static void makeFile(String location, String name) throws IOException {
8072
}
8173
Files.createFile(path);
8274
}
83-
84-
}
85-
86-
private static void timedSave() {
87-
if (saveTimer.passed(5000)) {
88-
saveAllSettings();
89-
saveTimer.reset();
90-
}
9175
}
92-
}
76+
}

src/main/java/net/cyberflame/viewmodel/gui/Slider.java

Lines changed: 28 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.cyberflame.viewmodel.gui;
22

3+
import net.cyberflame.viewmodel.config.SaveConfig;
34
import net.cyberflame.viewmodel.settings.FloatSetting;
45
import net.minecraft.client.gui.DrawContext;
56
import net.minecraft.util.math.MathHelper;
@@ -9,33 +10,25 @@
910
import java.math.BigDecimal;
1011
import java.math.RoundingMode;
1112

12-
/**
13-
* Современный слайдер с эффектом Liquid Glass в стиле iOS.
14-
*/
1513
public 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

Comments
 (0)