Skip to content

Commit d4f20fc

Browse files
committed
TriggerBot Improvements + Scrollable Drop-Downs
1 parent e32a7c5 commit d4f20fc

File tree

7 files changed

+981
-29
lines changed

7 files changed

+981
-29
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ Examples:
317317

318318
![ESP](https://i.imgur.com/1F7zU31.png)
319319

320+
### TriggerBot Improvements
321+
- Can now select the mob and the desired weapon/tool to use against them and it will quickly auto-switch when detected
322+
- Limited to three different mobs for now to prevent clutter
323+
320324
### Nuker Improvements
321325
- Auto toggle AutoTool option (If it wasn't on already, it will be enabled when using Nuker then turned off with Nuker)
322326

@@ -381,6 +385,7 @@ Examples:
381385

382386
### Usability
383387
- Right-click Area setting resets it to default.
388+
- Can now scroll all drop down/pop ups with your mouse.
384389

385390
### Stability
386391
- Fixed crashes on empty/zero-size shapes.

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ public void handleMouseRelease(double mouseX, double mouseY,
271271

272272
public void handleMouseScroll(double mouseX, double mouseY, double delta)
273273
{
274+
if(delta == 0)
275+
return;
276+
277+
if(handlePopupMouseScroll(mouseX, mouseY, delta))
278+
return;
279+
274280
int dWheel = (int)delta * 4;
275281
if(dWheel == 0)
276282
return;
@@ -369,6 +375,41 @@ private boolean handlePopupMouseClick(double mouseX, double mouseY,
369375
return false;
370376
}
371377

378+
private boolean handlePopupMouseScroll(double mouseX, double mouseY,
379+
double delta)
380+
{
381+
for(int i = popups.size() - 1; i >= 0; i--)
382+
{
383+
Popup popup = popups.get(i);
384+
if(popup.getWidth() <= 0 || popup.getHeight() <= 0)
385+
continue;
386+
387+
Component owner = popup.getOwner();
388+
Window parent = owner.getParent();
389+
390+
int x0 = parent.getX() + owner.getX();
391+
int y0 =
392+
parent.getY() + 13 + parent.getScrollOffset() + owner.getY();
393+
394+
int x1 = x0 + popup.getX();
395+
int y1 = y0 + popup.getY();
396+
int x2 = x1 + popup.getWidth();
397+
int y2 = y1 + popup.getHeight();
398+
399+
if(mouseX < x1 || mouseY < y1)
400+
continue;
401+
if(mouseX >= x2 || mouseY >= y2)
402+
continue;
403+
404+
int cMouseX = (int)(mouseX - x0);
405+
int cMouseY = (int)(mouseY - y0);
406+
if(popup.handleMouseScroll(cMouseX, cMouseY, delta))
407+
return true;
408+
}
409+
410+
return false;
411+
}
412+
372413
private void handleWindowMouseClick(int mouseX, int mouseY, int mouseButton,
373414
Click context)
374415
{

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

Lines changed: 84 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ public final class ComboBoxPopup<T extends Enum<T>> extends Popup
1919
{
2020
private static final ClickGui GUI = WurstClient.INSTANCE.getGui();
2121
private static final TextRenderer TR = WurstClient.MC.textRenderer;
22+
private static final int ROW_HEIGHT = 11;
23+
private static final int MAX_VISIBLE_ROWS = 8;
2224

2325
private final EnumSetting<T> setting;
2426
private final int popupWidth;
27+
private final int totalRows;
28+
private final int visibleRows;
29+
private int scrollOffset;
2530

2631
public ComboBoxPopup(Component owner, EnumSetting<T> setting,
2732
int popupWidth)
@@ -30,6 +35,9 @@ public ComboBoxPopup(Component owner, EnumSetting<T> setting,
3035
this.setting = setting;
3136
this.popupWidth = popupWidth;
3237

38+
totalRows = Math.max(0, setting.getValues().length - 1);
39+
visibleRows = Math.min(MAX_VISIBLE_ROWS, totalRows);
40+
3341
setWidth(getDefaultWidth());
3442
setHeight(getDefaultHeight());
3543

@@ -40,30 +48,47 @@ public ComboBoxPopup(Component owner, EnumSetting<T> setting,
4048
@Override
4149
public void handleMouseClick(int mouseX, int mouseY, int mouseButton)
4250
{
43-
if(mouseButton != GLFW.GLFW_MOUSE_BUTTON_LEFT)
51+
if(mouseButton != GLFW.GLFW_MOUSE_BUTTON_LEFT || visibleRows <= 0)
4452
return;
4553

46-
int yi1 = getY() - 11;
47-
for(T value : setting.getValues())
48-
{
49-
if(value == setting.getSelected())
50-
continue;
51-
52-
yi1 += 11;
53-
int yi2 = yi1 + 11;
54-
55-
if(mouseY < yi1 || mouseY >= yi2)
56-
continue;
57-
58-
setting.setSelected(value);
59-
close();
60-
break;
61-
}
54+
int localX = mouseX - getX();
55+
int localY = mouseY - getY();
56+
if(localX < 0 || localX >= getWidth() || localY < 0
57+
|| localY >= getHeight())
58+
return;
59+
60+
int row = localY / ROW_HEIGHT;
61+
T value = getValueAt(row + scrollOffset);
62+
if(value == null)
63+
return;
64+
65+
setting.setSelected(value);
66+
close();
67+
}
68+
69+
@Override
70+
public boolean handleMouseScroll(int mouseX, int mouseY, double delta)
71+
{
72+
if(totalRows <= visibleRows || visibleRows <= 0)
73+
return false;
74+
75+
int direction = (int)Math.signum(delta);
76+
if(direction == 0)
77+
return false;
78+
79+
scrollOffset -= direction;
80+
clampScroll();
81+
return true;
6282
}
6383

6484
@Override
6585
public void render(DrawContext context, int mouseX, int mouseY)
6686
{
87+
if(visibleRows <= 0)
88+
return;
89+
90+
clampScroll();
91+
6792
int x1 = getX();
6893
int x2 = x1 + getWidth();
6994
int y1 = getY();
@@ -77,14 +102,21 @@ public void render(DrawContext context, int mouseX, int mouseY)
77102
RenderUtils.drawBorder2D(context, x1, y1, x2, y2,
78103
RenderUtils.toIntColor(GUI.getAcColor(), 0.5F));
79104

80-
int yi1 = y1 - 11;
105+
int drawn = 0;
106+
int skipped = 0;
81107
for(T value : setting.getValues())
82108
{
83109
if(value == setting.getSelected())
84110
continue;
85111

86-
yi1 += 11;
87-
int yi2 = yi1 + 11;
112+
if(skipped++ < scrollOffset)
113+
continue;
114+
115+
if(drawn >= visibleRows)
116+
break;
117+
118+
int yi1 = y1 + drawn * ROW_HEIGHT;
119+
int yi2 = yi1 + ROW_HEIGHT;
88120

89121
boolean hValue = hovering && mouseY >= yi1 && mouseY < yi2;
90122
context.fill(x1, yi1, x2, yi2, RenderUtils.toIntColor(
@@ -93,9 +125,40 @@ public void render(DrawContext context, int mouseX, int mouseY)
93125
context.state.goUpLayer();
94126
context.drawText(TR, value.toString(), x1 + 2, yi1 + 2,
95127
GUI.getTxtColor(), false);
128+
129+
drawn++;
96130
}
97131
}
98132

133+
private void clampScroll()
134+
{
135+
int maxOffset = Math.max(0, totalRows - visibleRows);
136+
if(scrollOffset < 0)
137+
scrollOffset = 0;
138+
else if(scrollOffset > maxOffset)
139+
scrollOffset = maxOffset;
140+
}
141+
142+
private T getValueAt(int index)
143+
{
144+
if(index < 0)
145+
return null;
146+
147+
int skipped = 0;
148+
for(T value : setting.getValues())
149+
{
150+
if(value == setting.getSelected())
151+
continue;
152+
153+
if(skipped == index)
154+
return value;
155+
156+
skipped++;
157+
}
158+
159+
return null;
160+
}
161+
99162
private boolean isHovering(int mouseX, int mouseY, int x1, int x2, int y1,
100163
int y2)
101164
{
@@ -111,7 +174,6 @@ public int getDefaultWidth()
111174
@Override
112175
public int getDefaultHeight()
113176
{
114-
int numValues = setting.getValues().length;
115-
return (numValues - 1) * 11;
177+
return visibleRows * ROW_HEIGHT;
116178
}
117179
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public abstract void handleMouseClick(int mouseX, int mouseY,
3333

3434
public abstract int getDefaultHeight();
3535

36+
public boolean handleMouseScroll(int mouseX, int mouseY, double delta)
37+
{
38+
return false;
39+
}
40+
3641
public Component getOwner()
3742
{
3843
return owner;

0 commit comments

Comments
 (0)