Skip to content

Commit 002d43c

Browse files
committed
PlayerESP, ClickGUI, OfflineSettings Updates & Fixes
1 parent c0116ac commit 002d43c

File tree

12 files changed

+935
-72
lines changed

12 files changed

+935
-72
lines changed

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import net.minecraft.client.Minecraft;
2929
import net.minecraft.client.gui.Font;
3030
import net.minecraft.client.gui.GuiGraphics;
31+
import net.minecraft.client.input.CharacterEvent;
32+
import net.minecraft.client.input.KeyEvent;
3133
import net.minecraft.client.input.MouseButtonEvent;
3234
import net.wurstclient.Category;
3335
import net.wurstclient.Feature;
@@ -63,6 +65,7 @@ public final class ClickGui
6365
private String tooltip = "";
6466

6567
private boolean leftMouseButtonPressed;
68+
private KeyboardInput keyboardInput;
6669

6770
public ClickGui(Path windowsFile)
6871
{
@@ -359,6 +362,57 @@ public boolean handleNavigatorMouseScroll(double mouseX, double mouseY,
359362
return popupScrolled;
360363
}
361364

365+
public boolean handleKeyPressed(KeyEvent context)
366+
{
367+
if(keyboardInput != null && keyboardInput.onKeyPressed(context))
368+
return true;
369+
370+
if(context.key() == GLFW.GLFW_KEY_ESCAPE && keyboardInput != null)
371+
{
372+
clearKeyboardInput();
373+
return true;
374+
}
375+
376+
return false;
377+
}
378+
379+
public boolean handleCharTyped(CharacterEvent event)
380+
{
381+
return keyboardInput != null && keyboardInput.onCharTyped(event);
382+
}
383+
384+
public void requestKeyboardInput(KeyboardInput handler)
385+
{
386+
if(handler == null || keyboardInput == handler)
387+
return;
388+
389+
if(keyboardInput != null)
390+
clearKeyboardInput();
391+
392+
keyboardInput = handler;
393+
}
394+
395+
public void releaseKeyboardInput(KeyboardInput handler)
396+
{
397+
if(handler != null && keyboardInput == handler)
398+
keyboardInput = null;
399+
}
400+
401+
public void clearKeyboardInput()
402+
{
403+
if(keyboardInput == null)
404+
return;
405+
406+
KeyboardInput handler = keyboardInput;
407+
keyboardInput = null;
408+
handler.onKeyboardFocusLost();
409+
}
410+
411+
public boolean isKeyboardInputCaptured()
412+
{
413+
return keyboardInput != null;
414+
}
415+
362416
public void handleNavigatorMouseClick(double cMouseX, double cMouseY,
363417
int mouseButton, Window window, MouseButtonEvent context)
364418
{
@@ -587,6 +641,9 @@ private void handleComponentMouseClick(Window window, double mouseX,
587641
|| mouseY >= c.getY() + c.getHeight())
588642
continue;
589643

644+
if(keyboardInput != null && keyboardInput != c)
645+
clearKeyboardInput();
646+
590647
c.handleMouseClick(mouseX, mouseY, mouseButton, context);
591648
break;
592649
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2014-2025 Wurst-Imperium and contributors.
3+
*
4+
* This source code is subject to the terms of the GNU General Public
5+
* License, version 3. If a copy of the GPL was not distributed with this
6+
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
7+
*/
8+
package net.wurstclient.clickgui;
9+
10+
import net.minecraft.client.input.CharacterEvent;
11+
import net.minecraft.client.input.KeyEvent;
12+
13+
/**
14+
* Minimal interface for ClickGUI components that want to capture keyboard
15+
* input. Components can request focus through {@link ClickGui} and receive key
16+
* and char events without opening a fullscreen screen.
17+
*/
18+
public interface KeyboardInput
19+
{
20+
boolean onKeyPressed(KeyEvent event);
21+
22+
boolean onCharTyped(CharacterEvent event);
23+
24+
void onKeyboardFocusLost();
25+
}

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

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public final class StringDropdownComponent extends Component
2525
private static final ClickGui GUI = WurstClient.INSTANCE.getGui();
2626
private static final Font TR = WurstClient.MC.font;
2727
private static final int ARROW_SIZE = 11;
28+
private static final int LABEL_HEIGHT = 11;
2829

2930
private final StringDropdownSetting setting;
3031
private StringDropdownPopup popup;
@@ -40,11 +41,16 @@ public StringDropdownComponent(StringDropdownSetting setting)
4041
public void handleMouseClick(double mouseX, double mouseY, int mouseButton,
4142
MouseButtonEvent context)
4243
{
43-
int popupWidth = computePopupWidth();
44+
double localX = mouseX - getX();
45+
double localY = mouseY - getY();
46+
if(localX < 0 || localX >= getWidth())
47+
return;
4448

45-
if(mouseX < getX() + getWidth() - popupWidth - ARROW_SIZE - 4)
49+
if(localY < LABEL_HEIGHT)
4650
return;
4751

52+
int popupWidth = computePopupWidth();
53+
4854
switch(mouseButton)
4955
{
5056
case GLFW.GLFW_MOUSE_BUTTON_LEFT:
@@ -87,35 +93,36 @@ public void render(GuiGraphics context, int mouseX, int mouseY,
8793
int popupWidth = computePopupWidth();
8894
int x1 = getX();
8995
int x2 = x1 + getWidth();
90-
int x3 = x2 - ARROW_SIZE;
91-
int x4 = x3 - popupWidth - 4;
92-
int y1 = getY();
93-
int y2 = y1 + getHeight();
96+
int boxY1 = getY() + LABEL_HEIGHT;
97+
int boxY2 = boxY1 + ARROW_SIZE;
98+
int arrowX1 = x2 - ARROW_SIZE;
99+
int arrowX2 = x2;
94100

95101
boolean hovering = isHovering(mouseX, mouseY);
96-
boolean hText = hovering && mouseX < x4;
97-
boolean hBox = hovering && mouseX >= x4;
102+
boolean hText = hovering && mouseY < boxY1;
103+
boolean hBox = hovering && mouseY >= boxY1;
98104

99105
if(hText)
100106
GUI.setTooltip(setting.getWrappedDescription(200));
101107

102-
context.fill(x1, y1, x4, y2, getFillColor(false));
103-
context.fill(x4, y1, x2, y2, getFillColor(hBox));
108+
context.fill(x1, getY(), x2, boxY1, getFillColor(false));
109+
context.fill(x1, boxY1, x2, boxY2, getFillColor(hBox));
104110

105111
context.guiRenderState.up();
106112

107113
int outlineColor = RenderUtils.toIntColor(GUI.getAcColor(), 0.5F);
108-
RenderUtils.drawBorder2D(context, x4, y1, x2, y2, outlineColor);
109-
RenderUtils.drawLine2D(context, x3, y1, x3, y2, outlineColor);
114+
RenderUtils.drawBorder2D(context, x1, boxY1, x2, boxY2, outlineColor);
115+
RenderUtils.drawLine2D(context, arrowX1, boxY1, arrowX1, boxY2,
116+
outlineColor);
110117

111-
ClickGuiIcons.drawMinimizeArrow(context, x3, y1 + 0.5F, x2, y2 - 0.5F,
112-
hBox, !isPopupOpen());
118+
ClickGuiIcons.drawMinimizeArrow(context, arrowX1, boxY1 + 0.5F, arrowX2,
119+
boxY2 - 0.5F, hBox, !isPopupOpen());
113120

114121
String name = setting.getName();
115122
String value = setting.getSelected();
116123
int txtColor = GUI.getTxtColor();
117-
context.drawString(TR, name, x1, y1 + 2, txtColor, false);
118-
context.drawString(TR, value, x4 + 2, y1 + 2, txtColor, false);
124+
context.drawString(TR, name, x1, getY() + 2, txtColor, false);
125+
context.drawString(TR, value, x1 + 2, boxY1 + 2, txtColor, false);
119126
}
120127

121128
private int computePopupWidth()
@@ -134,12 +141,14 @@ private int getFillColor(boolean hovering)
134141
public int getDefaultWidth()
135142
{
136143
int popupWidth = computePopupWidth();
137-
return TR.width(setting.getName()) + popupWidth + ARROW_SIZE + 6;
144+
int boxWidth = popupWidth + ARROW_SIZE + 6;
145+
int labelWidth = TR.width(setting.getName()) + 4;
146+
return Math.max(labelWidth, boxWidth);
138147
}
139148

140149
@Override
141150
public int getDefaultHeight()
142151
{
143-
return ARROW_SIZE;
152+
return LABEL_HEIGHT + ARROW_SIZE;
144153
}
145154
}

0 commit comments

Comments
 (0)