Skip to content

Commit c7daf65

Browse files
committed
TriggerBot Improvements + Scrollable Drop-Downs
1 parent ccf346a commit c7daf65

7 files changed

Lines changed: 983 additions & 31 deletions

File tree

README.md

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

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

342+
### TriggerBot Improvements
343+
- Can now select the mob and the desired weapon/tool to use against them and it will quickly auto-switch when detected
344+
- Limited to three different mobs for now to prevent clutter
345+
342346
### Nuker Improvements
343347
- Auto toggle AutoTool option (If it wasn't on already, it will be enabled when using Nuker then turned off with Nuker)
344348

@@ -403,6 +407,7 @@ Examples:
403407

404408
### Usability
405409
- Right-click Area setting resets it to default.
410+
- Can now scroll all drop down/pop ups with your mouse.
406411

407412
### Stability
408413
- Fixed crashes on empty/zero-size shapes.

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ public void handleMouseRelease(double mouseX, double mouseY,
267267

268268
public void handleMouseScroll(double mouseX, double mouseY, double delta)
269269
{
270+
if(delta == 0)
271+
return;
272+
273+
if(handlePopupMouseScroll(mouseX, mouseY, delta))
274+
return;
275+
270276
int dWheel = (int)delta * 4;
271277
if(dWheel == 0)
272278
return;
@@ -364,7 +370,43 @@ private boolean handlePopupMouseClick(double mouseX, double mouseY,
364370
return false;
365371
}
366372

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

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

Lines changed: 84 additions & 23 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,10 +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);
96-
context.state.goDownLayer();
128+
129+
drawn++;
97130
}
98131
}
99132

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+
100162
private boolean isHovering(int mouseX, int mouseY, int x1, int x2, int y1,
101163
int y2)
102164
{
@@ -112,7 +174,6 @@ public int getDefaultWidth()
112174
@Override
113175
public int getDefaultHeight()
114176
{
115-
int numValues = setting.getValues().length;
116-
return (numValues - 1) * 11;
177+
return visibleRows * ROW_HEIGHT;
117178
}
118179
}

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)