Skip to content

Commit 171742c

Browse files
committed
Updated AutoChat
1 parent a5e4955 commit 171742c

9 files changed

Lines changed: 1830 additions & 147 deletions

File tree

src/main/java/net/wurstclient/clickgui/SettingsWindow.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
public final class SettingsWindow extends Window
1818
{
1919
private final Feature feature;
20+
private boolean rebuilding;
2021

2122
public SettingsWindow(Feature feature, Window parent, int buttonY)
2223
{
@@ -34,14 +35,31 @@ public SettingsWindow(Feature feature, Window parent, int buttonY)
3435

3536
public void rebuild()
3637
{
37-
clearChildren();
38+
if(rebuilding)
39+
return;
3840

39-
Stream<Setting> settings = feature.getSettings().values().stream()
40-
.filter(Setting::isVisibleInGui);
41-
settings.map(Setting::getComponent).filter(Objects::nonNull)
42-
.forEach(this::add);
41+
rebuilding = true;
4342

44-
pack();
43+
try
44+
{
45+
clearChildren();
46+
47+
Stream<Setting> settings = feature.getSettings().values().stream()
48+
.peek(Setting::update).filter(Setting::isVisibleInGui);
49+
settings.map(Setting::getComponent).filter(Objects::nonNull)
50+
.forEach(this::add);
51+
52+
pack();
53+
54+
}finally
55+
{
56+
rebuilding = false;
57+
}
58+
}
59+
60+
public boolean isRebuilding()
61+
{
62+
return rebuilding;
4563
}
4664

4765
private void setInitialPosition(Window parent, int buttonY)

src/main/java/net/wurstclient/clickgui/components/ComboBoxComponent.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public ComboBoxComponent(EnumSetting<T> setting)
4444
public void handleMouseClick(double mouseX, double mouseY, int mouseButton,
4545
MouseButtonEvent context)
4646
{
47-
if(mouseX < getX() + getWidth() - popupWidth - getBoxHeight() - 4)
47+
if(mouseX < getX() + getWidth() - getVisibleValueWidth()
48+
- getBoxHeight() - 4)
4849
return;
4950

5051
switch(mouseButton)
@@ -93,7 +94,8 @@ public void extractRenderState(GuiGraphicsExtractor context, int mouseX,
9394
int x2 = x1 + getWidth();
9495
int boxHeight = getBoxHeight();
9596
int x3 = x2 - boxHeight;
96-
int x4 = x3 - popupWidth - 4;
97+
int valueWidth = getVisibleValueWidth();
98+
int x4 = x3 - valueWidth - 4;
9799
int y1 = getY();
98100
int y2 = y1 + getHeight();
99101

@@ -124,12 +126,27 @@ public void extractRenderState(GuiGraphicsExtractor context, int mouseX,
124126

125127
// text
126128
String name = setting.getName();
127-
String value = "" + setting.getSelected();
129+
String value = trimToWidth("" + setting.getSelected(), valueWidth - 4);
128130
int txtColor = GUI.getTxtColor();
129131
context.text(TR, name, x1, y1 + 2, txtColor, false);
130132
context.text(TR, value, x4 + 2, y1 + 2, txtColor, false);
131133
}
132134

135+
private int getVisibleValueWidth()
136+
{
137+
int maxWidth = getWidth() - getBoxHeight() - 4;
138+
return Math.max(24, Math.min(popupWidth, maxWidth));
139+
}
140+
141+
private static String trimToWidth(String text, int width)
142+
{
143+
if(TR.width(text) <= width)
144+
return text;
145+
146+
return TR.plainSubstrByWidth(text, Math.max(0, width - TR.width("...")))
147+
+ "...";
148+
}
149+
133150
private int getFillColor(boolean hovering)
134151
{
135152
float opacity = GUI.getOpacity() * (hovering ? 1.5F : 1);

0 commit comments

Comments
 (0)