mirror of
https://github.com/Wurst-Imperium/Wurst7.git
synced 2024-09-20 01:12:13 +02:00
Add SliderSetting and fix ClickGui bugs
This commit is contained in:
parent
cb0d272c55
commit
1f49516847
@ -127,8 +127,8 @@ public enum WurstClient
|
||||
{
|
||||
if(!guiInitialized)
|
||||
{
|
||||
gui.init();
|
||||
guiInitialized = true;
|
||||
gui.init();
|
||||
}
|
||||
|
||||
return gui;
|
||||
|
@ -9,15 +9,14 @@ package net.wurstclient.clickgui;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.wurstclient.WurstClient;
|
||||
import net.wurstclient.settings.CheckboxSetting;
|
||||
|
||||
public final class CheckboxComponent extends Component
|
||||
{
|
||||
private static final ClickGui GUI = WurstClient.INSTANCE.getGui();
|
||||
private static final TextRenderer TEXT_RENDERER =
|
||||
WurstClient.MC.textRenderer;
|
||||
private final MinecraftClient MC = WurstClient.MC;
|
||||
private final ClickGui GUI = WurstClient.INSTANCE.getGui();
|
||||
|
||||
private final CheckboxSetting setting;
|
||||
|
||||
@ -181,7 +180,7 @@ public final class CheckboxComponent extends Component
|
||||
int tx = x3 + 2;
|
||||
int ty = y1 - 1;
|
||||
int color = setting.isLocked() ? 0xAAAAAA : 0xF0F0F0;
|
||||
TEXT_RENDERER.draw(name, tx, ty, color);
|
||||
MC.textRenderer.draw(name, tx, ty, color);
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
@ -189,7 +188,7 @@ public final class CheckboxComponent extends Component
|
||||
@Override
|
||||
public int getDefaultWidth()
|
||||
{
|
||||
return TEXT_RENDERER.getStringWidth(setting.getName()) + 13;
|
||||
return MC.textRenderer.getStringWidth(setting.getName()) + 13;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,6 +15,8 @@ import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@ -27,10 +29,12 @@ import net.wurstclient.Feature;
|
||||
import net.wurstclient.WurstClient;
|
||||
import net.wurstclient.hack.HackCategory;
|
||||
import net.wurstclient.hacks.ClickGuiHack;
|
||||
import net.wurstclient.settings.Setting;
|
||||
import net.wurstclient.util.json.JsonUtils;
|
||||
|
||||
public final class ClickGui
|
||||
{
|
||||
private static final WurstClient WURST = WurstClient.INSTANCE;
|
||||
private static final MinecraftClient MC = WurstClient.MC;
|
||||
|
||||
private final ArrayList<Window> windows = new ArrayList<>();
|
||||
@ -41,7 +45,7 @@ public final class ClickGui
|
||||
private float[] acColor = new float[3];
|
||||
private float opacity;
|
||||
|
||||
private String tooltip;
|
||||
private String tooltip = "";
|
||||
|
||||
private boolean leftMouseButtonPressed;
|
||||
|
||||
@ -58,9 +62,9 @@ public final class ClickGui
|
||||
windowMap.put(category, new Window(category.getName()));
|
||||
|
||||
ArrayList<Feature> features = new ArrayList<>();
|
||||
features.addAll(WurstClient.INSTANCE.getHax().getAllHax());
|
||||
features.addAll(WurstClient.INSTANCE.getCmds().getAllCmds());
|
||||
// features.addAll(WurstClient.INSTANCE.special.getAllFeatures());
|
||||
features.addAll(WURST.getHax().getAllHax());
|
||||
features.addAll(WURST.getCmds().getAllCmds());
|
||||
// features.addAll(WURST.special.getAllFeatures());
|
||||
|
||||
for(Feature f : features)
|
||||
if(f.getCategory() != null)
|
||||
@ -69,9 +73,9 @@ public final class ClickGui
|
||||
windows.addAll(windowMap.values());
|
||||
|
||||
Window uiSettings = new Window("UI Settings");
|
||||
// for(Setting setting : WurstClient.INSTANCE.getHax().clickGuiHack
|
||||
// .getSettings())
|
||||
// uiSettings.add(setting.getComponent());
|
||||
ClickGuiHack clickGuiHack = WURST.getHax().clickGuiHack;
|
||||
Stream<Setting> settings = clickGuiHack.getSettings().values().stream();
|
||||
settings.map(Setting::getComponent).forEach(c -> uiSettings.add(c));
|
||||
windows.add(uiSettings);
|
||||
|
||||
for(Window window : windows)
|
||||
@ -440,7 +444,7 @@ public final class ClickGui
|
||||
break;
|
||||
}
|
||||
|
||||
tooltip = null;
|
||||
tooltip = "";
|
||||
for(Window window : windows)
|
||||
{
|
||||
if(window.isInvisible())
|
||||
@ -497,7 +501,7 @@ public final class ClickGui
|
||||
}
|
||||
|
||||
// tooltip
|
||||
if(tooltip != null)
|
||||
if(!tooltip.isEmpty())
|
||||
{
|
||||
String[] lines = tooltip.split("\n");
|
||||
TextRenderer fr = MC.textRenderer;
|
||||
@ -566,7 +570,7 @@ public final class ClickGui
|
||||
|
||||
public void updateColors()
|
||||
{
|
||||
ClickGuiHack clickGui = WurstClient.INSTANCE.getHax().clickGuiHack;
|
||||
ClickGuiHack clickGui = WURST.getHax().clickGuiHack;
|
||||
|
||||
opacity = clickGui.getOpacity();
|
||||
bgColor = clickGui.getBgColor();
|
||||
@ -596,7 +600,7 @@ public final class ClickGui
|
||||
y2 = y3;
|
||||
|
||||
if(mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2)
|
||||
tooltip = null;
|
||||
tooltip = "";
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
@ -1094,7 +1098,7 @@ public final class ClickGui
|
||||
|
||||
public void setTooltip(String tooltip)
|
||||
{
|
||||
this.tooltip = tooltip;
|
||||
this.tooltip = Objects.requireNonNull(tooltip);
|
||||
}
|
||||
|
||||
public void addWindow(Window window)
|
||||
@ -1106,4 +1110,9 @@ public final class ClickGui
|
||||
{
|
||||
popups.add(popup);
|
||||
}
|
||||
|
||||
public boolean isLeftMouseButtonPressed()
|
||||
{
|
||||
return leftMouseButtonPressed;
|
||||
}
|
||||
}
|
||||
|
114
src/main/java/net/wurstclient/clickgui/EditSliderScreen.java
Normal file
114
src/main/java/net/wurstclient/clickgui/EditSliderScreen.java
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2014 - 2019 | Wurst-Imperium | All rights reserved.
|
||||
*
|
||||
* This source code is subject to the terms of the GNU General Public
|
||||
* License, version 3. If a copy of the GPL was not distributed with this
|
||||
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
package net.wurstclient.clickgui;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.wurstclient.settings.SliderSetting;
|
||||
import net.wurstclient.settings.SliderSetting.ValueDisplay;
|
||||
import net.wurstclient.util.MathUtils;
|
||||
|
||||
public final class EditSliderScreen extends Screen
|
||||
{
|
||||
private final Screen prevScreen;
|
||||
private final SliderSetting slider;
|
||||
|
||||
private TextFieldWidget valueField;
|
||||
private ButtonWidget doneButton;
|
||||
|
||||
public EditSliderScreen(Screen prevScreen, SliderSetting slider)
|
||||
{
|
||||
super(new TextComponent(""));
|
||||
this.prevScreen = prevScreen;
|
||||
this.slider = slider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
int x1 = width / 2 - 100;
|
||||
int y1 = 60;
|
||||
int y2 = height / 3 * 2;
|
||||
|
||||
TextRenderer tr = minecraft.textRenderer;
|
||||
ValueDisplay vd = ValueDisplay.DECIMAL;
|
||||
String valueString = vd.getValueString(slider.getValue());
|
||||
|
||||
valueField = new TextFieldWidget(tr, x1, y1, 200, 20, "");
|
||||
valueField.setText(valueString);
|
||||
valueField.setCursor(0);
|
||||
|
||||
children.add(valueField);
|
||||
setInitialFocus(valueField);
|
||||
valueField.method_1876(true);
|
||||
|
||||
doneButton = new ButtonWidget(x1, y2, 200, 20, "Done", b -> done());
|
||||
addButton(doneButton);
|
||||
}
|
||||
|
||||
private void done()
|
||||
{
|
||||
String value = valueField.getText();
|
||||
|
||||
if(MathUtils.isDouble(value))
|
||||
slider.setValue(Double.parseDouble(value));
|
||||
|
||||
minecraft.openScreen(prevScreen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int int_3)
|
||||
{
|
||||
switch(keyCode)
|
||||
{
|
||||
case GLFW.GLFW_KEY_ENTER:
|
||||
done();
|
||||
break;
|
||||
|
||||
case GLFW.GLFW_KEY_ESCAPE:
|
||||
minecraft.openScreen(prevScreen);
|
||||
break;
|
||||
}
|
||||
|
||||
return super.keyPressed(keyCode, scanCode, int_3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
valueField.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
renderBackground();
|
||||
drawCenteredString(minecraft.textRenderer, slider.getName(), width / 2,
|
||||
20, 0xFFFFFF);
|
||||
|
||||
valueField.render(mouseX, mouseY, partialTicks);
|
||||
super.render(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPauseScreen()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCloseOnEsc()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
@ -7,17 +7,19 @@
|
||||
*/
|
||||
package net.wurstclient.clickgui;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.wurstclient.Feature;
|
||||
import net.wurstclient.WurstClient;
|
||||
|
||||
public final class FeatureButton extends Component
|
||||
{
|
||||
private static final ClickGui GUI = WurstClient.INSTANCE.getGui();
|
||||
private static final TextRenderer TEXT_RENDERER =
|
||||
WurstClient.MC.textRenderer;
|
||||
private final MinecraftClient MC = WurstClient.MC;
|
||||
private final ClickGui GUI = WurstClient.INSTANCE.getGui();
|
||||
|
||||
private final Feature feature;
|
||||
private final boolean hasSettings;
|
||||
@ -26,7 +28,7 @@ public final class FeatureButton extends Component
|
||||
|
||||
public FeatureButton(Feature feature)
|
||||
{
|
||||
this.feature = feature;
|
||||
this.feature = Objects.requireNonNull(feature);
|
||||
setWidth(getDefaultWidth());
|
||||
setHeight(getDefaultHeight());
|
||||
hasSettings = !feature.getSettings().isEmpty();
|
||||
@ -234,12 +236,13 @@ public final class FeatureButton extends Component
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
TextRenderer tr = MC.textRenderer;
|
||||
String name = feature.getName();
|
||||
int nameWidth = TEXT_RENDERER.getStringWidth(name);
|
||||
int nameWidth = tr.getStringWidth(name);
|
||||
int tx = x1 + (x3 - x1 - nameWidth) / 2;
|
||||
int ty = y1 + 2;
|
||||
|
||||
TEXT_RENDERER.draw(name, tx, ty, 0xF0F0F0);
|
||||
tr.draw(name, tx, ty, 0xF0F0F0);
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
@ -248,7 +251,8 @@ public final class FeatureButton extends Component
|
||||
public int getDefaultWidth()
|
||||
{
|
||||
String name = feature.getName();
|
||||
int width = TEXT_RENDERER.getStringWidth(name) + 2;
|
||||
TextRenderer tr = MC.textRenderer;
|
||||
int width = tr.getStringWidth(name) + 2;
|
||||
if(hasSettings)
|
||||
width += 11;
|
||||
|
||||
|
293
src/main/java/net/wurstclient/clickgui/SliderComponent.java
Normal file
293
src/main/java/net/wurstclient/clickgui/SliderComponent.java
Normal file
@ -0,0 +1,293 @@
|
||||
/*
|
||||
* Copyright (C) 2014 - 2019 | Wurst-Imperium | All rights reserved.
|
||||
*
|
||||
* This source code is subject to the terms of the GNU General Public
|
||||
* License, version 3. If a copy of the GPL was not distributed with this
|
||||
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
package net.wurstclient.clickgui;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.wurstclient.WurstClient;
|
||||
import net.wurstclient.settings.SliderSetting;
|
||||
|
||||
public final class SliderComponent extends Component
|
||||
{
|
||||
private final MinecraftClient MC = WurstClient.MC;
|
||||
private final ClickGui GUI = WurstClient.INSTANCE.getGui();
|
||||
|
||||
private final SliderSetting setting;
|
||||
private boolean dragging;
|
||||
|
||||
public SliderComponent(SliderSetting setting)
|
||||
{
|
||||
this.setting = setting;
|
||||
setWidth(getDefaultWidth());
|
||||
setHeight(getDefaultHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseClick(int mouseX, int mouseY, int mouseButton)
|
||||
{
|
||||
if(mouseY < getY() + 11)
|
||||
return;
|
||||
|
||||
switch(mouseButton)
|
||||
{
|
||||
case 0:
|
||||
handleLeftClick();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
handleRightClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLeftClick()
|
||||
{
|
||||
if(Screen.hasControlDown())
|
||||
MC.openScreen(new EditSliderScreen(MC.currentScreen, setting));
|
||||
else
|
||||
dragging = true;
|
||||
}
|
||||
|
||||
private void handleRightClick()
|
||||
{
|
||||
setting.setValue(setting.getDefaultValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
int x1 = getX();
|
||||
int x2 = x1 + getWidth();
|
||||
int x3 = x1 + 2;
|
||||
int x4 = x2 - 2;
|
||||
int y1 = getY();
|
||||
int y2 = y1 + getHeight();
|
||||
int y3 = y1 + 11;
|
||||
int y4 = y3 + 4;
|
||||
int y5 = y2 - 4;
|
||||
|
||||
handleDragging(mouseX, x3, x4);
|
||||
|
||||
boolean hovering = isHovering(mouseX, mouseY, x1, x2, y1, y2);
|
||||
boolean hSlider = hovering && mouseY >= y3 || dragging;
|
||||
boolean renderAsDisabled = setting.isDisabled() || setting.isLocked();
|
||||
|
||||
if(hovering && mouseY < y3)
|
||||
setTooltip();
|
||||
|
||||
if(renderAsDisabled)
|
||||
{
|
||||
hovering = false;
|
||||
hSlider = false;
|
||||
}
|
||||
|
||||
drawBackground(x1, x2, x3, x4, y1, y2, y4, y5);
|
||||
drawRail(x3, x4, y4, y5, hSlider, renderAsDisabled);
|
||||
drawKnob(x1, x2, y2, y3, hSlider, renderAsDisabled);
|
||||
drawNameAndValue(x1, x2, y1, renderAsDisabled);
|
||||
}
|
||||
|
||||
private void handleDragging(int mouseX, int x3, int x4)
|
||||
{
|
||||
if(!dragging)
|
||||
return;
|
||||
|
||||
if(!GUI.isLeftMouseButtonPressed())
|
||||
{
|
||||
dragging = false;
|
||||
return;
|
||||
}
|
||||
|
||||
double sliderStartX = x3;
|
||||
double sliderWidth = x4 - x3;
|
||||
double mousePercentage = (mouseX - sliderStartX) / sliderWidth;
|
||||
|
||||
double min = setting.getMinimum();
|
||||
double range = setting.getRange();
|
||||
double value = min + range * mousePercentage;
|
||||
|
||||
setting.setValue(value);
|
||||
}
|
||||
|
||||
private boolean isHovering(int mouseX, int mouseY, int x1, int x2, int y1,
|
||||
int y2)
|
||||
{
|
||||
Window parent = getParent();
|
||||
boolean scrollEnabled = parent.isScrollingEnabled();
|
||||
int scroll = scrollEnabled ? parent.getScrollOffset() : 0;
|
||||
|
||||
return mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2
|
||||
&& mouseY >= -scroll && mouseY < parent.getHeight() - 13 - scroll;
|
||||
}
|
||||
|
||||
private void setTooltip()
|
||||
{
|
||||
String tooltip = setting.getDescription();
|
||||
|
||||
if(setting.isLocked())
|
||||
{
|
||||
tooltip += "\n\nThis slider is locked to ";
|
||||
tooltip += setting.getValueString() + ".";
|
||||
|
||||
}else if(setting.isDisabled())
|
||||
tooltip += "\n\nThis slider is disabled.";
|
||||
|
||||
GUI.setTooltip(tooltip);
|
||||
}
|
||||
|
||||
private void drawBackground(int x1, int x2, int x3, int x4, int y1, int y2,
|
||||
int y4, int y5)
|
||||
{
|
||||
float[] bgColor = GUI.getBgColor();
|
||||
float opacity = GUI.getOpacity();
|
||||
|
||||
GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], opacity);
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
|
||||
GL11.glVertex2i(x1, y1);
|
||||
GL11.glVertex2i(x1, y4);
|
||||
GL11.glVertex2i(x2, y4);
|
||||
GL11.glVertex2i(x2, y1);
|
||||
|
||||
GL11.glVertex2i(x1, y5);
|
||||
GL11.glVertex2i(x1, y2);
|
||||
GL11.glVertex2i(x2, y2);
|
||||
GL11.glVertex2i(x2, y5);
|
||||
|
||||
GL11.glVertex2i(x1, y4);
|
||||
GL11.glVertex2i(x1, y5);
|
||||
GL11.glVertex2i(x3, y5);
|
||||
GL11.glVertex2i(x3, y4);
|
||||
|
||||
GL11.glVertex2i(x4, y4);
|
||||
GL11.glVertex2i(x4, y5);
|
||||
GL11.glVertex2i(x2, y5);
|
||||
GL11.glVertex2i(x2, y4);
|
||||
|
||||
GL11.glEnd();
|
||||
}
|
||||
|
||||
private void drawRail(int x3, int x4, int y4, int y5, boolean hSlider,
|
||||
boolean renderAsDisabled)
|
||||
{
|
||||
float[] bgColor = GUI.getBgColor();
|
||||
float[] acColor = GUI.getAcColor();
|
||||
float opacity = GUI.getOpacity();
|
||||
|
||||
double xl1 = x3;
|
||||
double xl2 = x4;
|
||||
if(!renderAsDisabled && setting.isLimited())
|
||||
{
|
||||
double ratio = (x4 - x3) / setting.getRange();
|
||||
xl1 += ratio * (setting.getUsableMin() - setting.getMinimum());
|
||||
xl2 += ratio * (setting.getUsableMax() - setting.getMaximum());
|
||||
}
|
||||
|
||||
// limit
|
||||
GL11.glColor4f(1, 0, 0, hSlider ? opacity * 1.5F : opacity);
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glVertex2d(x3, y4);
|
||||
GL11.glVertex2d(x3, y5);
|
||||
GL11.glVertex2d(xl1, y5);
|
||||
GL11.glVertex2d(xl1, y4);
|
||||
GL11.glVertex2d(xl2, y4);
|
||||
GL11.glVertex2d(xl2, y5);
|
||||
GL11.glVertex2d(x4, y5);
|
||||
GL11.glVertex2d(x4, y4);
|
||||
GL11.glEnd();
|
||||
|
||||
// background
|
||||
GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2],
|
||||
hSlider ? opacity * 1.5F : opacity);
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glVertex2d(xl1, y4);
|
||||
GL11.glVertex2d(xl1, y5);
|
||||
GL11.glVertex2d(xl2, y5);
|
||||
GL11.glVertex2d(xl2, y4);
|
||||
GL11.glEnd();
|
||||
|
||||
// outline
|
||||
GL11.glColor4f(acColor[0], acColor[1], acColor[2], 0.5F);
|
||||
GL11.glBegin(GL11.GL_LINE_LOOP);
|
||||
GL11.glVertex2i(x3, y4);
|
||||
GL11.glVertex2i(x3, y5);
|
||||
GL11.glVertex2i(x4, y5);
|
||||
GL11.glVertex2i(x4, y4);
|
||||
GL11.glEnd();
|
||||
}
|
||||
|
||||
private void drawKnob(int x1, int x2, int y2, int y3, boolean hSlider,
|
||||
boolean renderAsDisabled)
|
||||
{
|
||||
double percentage = (setting.getValue() - setting.getMinimum())
|
||||
/ (setting.getMaximum() - setting.getMinimum());
|
||||
double xk1 = x1 + (x2 - x1 - 8) * percentage;
|
||||
double xk2 = xk1 + 8;
|
||||
double yk1 = y3 + 1.5;
|
||||
double yk2 = y2 - 1.5;
|
||||
|
||||
// knob
|
||||
if(renderAsDisabled)
|
||||
GL11.glColor4f(0.5F, 0.5F, 0.5F, 0.75F);
|
||||
else
|
||||
{
|
||||
float f = (float)(2 * percentage);
|
||||
GL11.glColor4f(f, 2 - f, 0, hSlider ? 1 : 0.75F);
|
||||
}
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glVertex2d(xk1, yk1);
|
||||
GL11.glVertex2d(xk1, yk2);
|
||||
GL11.glVertex2d(xk2, yk2);
|
||||
GL11.glVertex2d(xk2, yk1);
|
||||
GL11.glEnd();
|
||||
|
||||
// outline
|
||||
GL11.glColor4f(0.0625F, 0.0625F, 0.0625F, 0.5F);
|
||||
GL11.glBegin(GL11.GL_LINE_LOOP);
|
||||
GL11.glVertex2d(xk1, yk1);
|
||||
GL11.glVertex2d(xk1, yk2);
|
||||
GL11.glVertex2d(xk2, yk2);
|
||||
GL11.glVertex2d(xk2, yk1);
|
||||
GL11.glEnd();
|
||||
}
|
||||
|
||||
private void drawNameAndValue(int x1, int x2, int y1,
|
||||
boolean renderAsDisabled)
|
||||
{
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
TextRenderer tr = MC.textRenderer;
|
||||
String name = setting.getName();
|
||||
String value = setting.getValueString();
|
||||
int valueWidth = tr.getStringWidth(value);
|
||||
int color = renderAsDisabled ? 0xAAAAAA : 0xF0F0F0;
|
||||
tr.draw(name, x1, y1 - 1, color);
|
||||
tr.draw(value, x2 - valueWidth, y1 - 1, color);
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultWidth()
|
||||
{
|
||||
TextRenderer tr = MC.textRenderer;
|
||||
int nameWitdh = tr.getStringWidth(setting.getName());
|
||||
int valueWidth = tr.getStringWidth(setting.getValueString());
|
||||
return nameWitdh + valueWidth + 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultHeight()
|
||||
{
|
||||
return 22;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2014 - 2018 | Wurst-Imperium | All rights reserved.
|
||||
* Copyright (C) 2014 - 2019 | Wurst-Imperium | All rights reserved.
|
||||
*
|
||||
* This source code is subject to the terms of the GNU General Public
|
||||
* License, version 3. If a copy of the GPL was not distributed with this
|
||||
@ -10,37 +10,39 @@ package net.wurstclient.hacks;
|
||||
import net.wurstclient.clickgui.ClickGuiScreen;
|
||||
import net.wurstclient.hack.DontSaveState;
|
||||
import net.wurstclient.hack.Hack;
|
||||
import net.wurstclient.settings.SliderSetting;
|
||||
import net.wurstclient.settings.SliderSetting.ValueDisplay;
|
||||
|
||||
@DontSaveState
|
||||
public final class ClickGuiHack extends Hack
|
||||
{
|
||||
// private final SliderSetting opacity = new SliderSetting("Opacity", 0.5,
|
||||
// 0.15, 0.85, 0.01, ValueDisplay.PERCENTAGE);
|
||||
//
|
||||
// private final SliderSetting bgRed = new SliderSetting("BG red",
|
||||
// "Background red", 64, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
// private final SliderSetting bgGreen = new SliderSetting("BG green",
|
||||
// "Background green", 64, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
// private final SliderSetting bgBlue = new SliderSetting("BG blue",
|
||||
// "Background blue", 64, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
//
|
||||
// private final SliderSetting acRed = new SliderSetting("AC red",
|
||||
// "Accent red", 16, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
// private final SliderSetting acGreen = new SliderSetting("AC green",
|
||||
// "Accent green", 16, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
// private final SliderSetting acBlue = new SliderSetting("AC blue",
|
||||
// "Accent blue", 16, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
private final SliderSetting opacity = new SliderSetting("Opacity", 0.5,
|
||||
0.15, 0.85, 0.01, ValueDisplay.PERCENTAGE);
|
||||
|
||||
private final SliderSetting bgRed = new SliderSetting("BG red",
|
||||
"Background red", 64, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
private final SliderSetting bgGreen = new SliderSetting("BG green",
|
||||
"Background green", 64, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
private final SliderSetting bgBlue = new SliderSetting("BG blue",
|
||||
"Background blue", 64, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
|
||||
private final SliderSetting acRed = new SliderSetting("AC red",
|
||||
"Accent red", 16, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
private final SliderSetting acGreen = new SliderSetting("AC green",
|
||||
"Accent green", 16, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
private final SliderSetting acBlue = new SliderSetting("AC blue",
|
||||
"Accent blue", 16, 0, 255, 1, ValueDisplay.INTEGER);
|
||||
|
||||
public ClickGuiHack()
|
||||
{
|
||||
super("ClickGUI", "Window-based ClickGUI.");
|
||||
// addSetting(opacity);
|
||||
// addSetting(bgRed);
|
||||
// addSetting(bgGreen);
|
||||
// addSetting(bgBlue);
|
||||
// addSetting(acRed);
|
||||
// addSetting(acGreen);
|
||||
// addSetting(acBlue);
|
||||
addSetting(opacity);
|
||||
addSetting(bgRed);
|
||||
addSetting(bgGreen);
|
||||
addSetting(bgBlue);
|
||||
addSetting(acRed);
|
||||
addSetting(acGreen);
|
||||
addSetting(acBlue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,23 +54,22 @@ public final class ClickGuiHack extends Hack
|
||||
|
||||
public float getOpacity()
|
||||
{
|
||||
// return opacity.getValueF();
|
||||
return 0.5F;
|
||||
return opacity.getValueF();
|
||||
}
|
||||
|
||||
public float[] getBgColor()
|
||||
{
|
||||
return new float[]{0.25F, 0.25F, 0.25F};
|
||||
// return new float[]{bgRed.getValueI() / 255F, bgGreen.getValueI() /
|
||||
// 255F,
|
||||
// bgBlue.getValueI() / 255F};
|
||||
float red = bgRed.getValueI() / 255F;
|
||||
float green = bgGreen.getValueI() / 255F;
|
||||
float blue = bgBlue.getValueI() / 255F;
|
||||
return new float[]{red, green, blue};
|
||||
}
|
||||
|
||||
public float[] getAcColor()
|
||||
{
|
||||
return new float[]{0.125F, 0.125F, 0.125F};
|
||||
// return new float[]{acRed.getValueI() / 255F, acGreen.getValueI() /
|
||||
// 255F,
|
||||
// acBlue.getValueI() / 255F};
|
||||
float red = acRed.getValueI() / 255F;
|
||||
float green = acGreen.getValueI() / 255F;
|
||||
float blue = acBlue.getValueI() / 255F;
|
||||
return new float[]{red, green, blue};
|
||||
}
|
||||
}
|
||||
|
13
src/main/java/net/wurstclient/settings/SliderLock.java
Normal file
13
src/main/java/net/wurstclient/settings/SliderLock.java
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (C) 2014 - 2019 | Wurst-Imperium | All rights reserved.
|
||||
*
|
||||
* This source code is subject to the terms of the GNU General Public
|
||||
* License, version 3. If a copy of the GPL was not distributed with this
|
||||
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
package net.wurstclient.settings;
|
||||
|
||||
public interface SliderLock
|
||||
{
|
||||
public double getValue();
|
||||
}
|
287
src/main/java/net/wurstclient/settings/SliderSetting.java
Normal file
287
src/main/java/net/wurstclient/settings/SliderSetting.java
Normal file
@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright (C) 2014 - 2019 | Wurst-Imperium | All rights reserved.
|
||||
*
|
||||
* This source code is subject to the terms of the GNU General Public
|
||||
* License, version 3. If a copy of the GPL was not distributed with this
|
||||
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
package net.wurstclient.settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import net.wurstclient.WurstClient;
|
||||
import net.wurstclient.clickgui.Component;
|
||||
import net.wurstclient.clickgui.SliderComponent;
|
||||
import net.wurstclient.keybinds.PossibleKeybind;
|
||||
import net.wurstclient.util.MathUtils;
|
||||
import net.wurstclient.util.json.JsonUtils;
|
||||
|
||||
public class SliderSetting extends Setting implements SliderLock
|
||||
{
|
||||
private double value;
|
||||
private final double defaultValue;
|
||||
private final double minimum;
|
||||
private final double maximum;
|
||||
private final double increment;
|
||||
private final ValueDisplay display;
|
||||
|
||||
private SliderLock lock;
|
||||
private boolean disabled;
|
||||
private double usableMin;
|
||||
private double usableMax;
|
||||
|
||||
private int navigatorPosY;
|
||||
|
||||
public SliderSetting(String name, String description, double value,
|
||||
double minimum, double maximum, double increment, ValueDisplay display)
|
||||
{
|
||||
super(name, description);
|
||||
this.value = value;
|
||||
defaultValue = value;
|
||||
|
||||
this.minimum = minimum;
|
||||
this.maximum = maximum;
|
||||
|
||||
usableMin = minimum;
|
||||
usableMax = maximum;
|
||||
|
||||
this.increment = increment;
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public SliderSetting(String name, double value, double minimum,
|
||||
double maximum, double increment, ValueDisplay display)
|
||||
{
|
||||
this(name, "", value, minimum, maximum, increment, display);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final double getValue()
|
||||
{
|
||||
double value = isLocked() ? lock.getValue() : this.value;
|
||||
return MathUtils.clamp(value, usableMin, usableMax);
|
||||
}
|
||||
|
||||
public final float getValueF()
|
||||
{
|
||||
return (float)getValue();
|
||||
}
|
||||
|
||||
public final int getValueI()
|
||||
{
|
||||
return (int)getValue();
|
||||
}
|
||||
|
||||
public final double getDefaultValue()
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public final String getValueString()
|
||||
{
|
||||
return display.getValueString(getValue());
|
||||
}
|
||||
|
||||
public final void setValue(double value)
|
||||
{
|
||||
if(disabled || isLocked())
|
||||
return;
|
||||
|
||||
setValueIgnoreLock(value);
|
||||
}
|
||||
|
||||
private void setValueIgnoreLock(double value)
|
||||
{
|
||||
value = (int)(value / increment) * increment;
|
||||
value = MathUtils.clamp(value, usableMin, usableMax);
|
||||
|
||||
this.value = value;
|
||||
update();
|
||||
|
||||
WurstClient.INSTANCE.saveSettings();
|
||||
}
|
||||
|
||||
public final void increaseValue()
|
||||
{
|
||||
setValue(getValue() + increment);
|
||||
}
|
||||
|
||||
public final void decreaseValue()
|
||||
{
|
||||
setValue(getValue() - increment);
|
||||
}
|
||||
|
||||
public final double getMinimum()
|
||||
{
|
||||
return minimum;
|
||||
}
|
||||
|
||||
public final double getMaximum()
|
||||
{
|
||||
return maximum;
|
||||
}
|
||||
|
||||
public final double getRange()
|
||||
{
|
||||
return maximum - minimum;
|
||||
}
|
||||
|
||||
public final double getIncrement()
|
||||
{
|
||||
return increment;
|
||||
}
|
||||
|
||||
public final float getPercentage()
|
||||
{
|
||||
return (float)((getValue() - minimum) / getRange());
|
||||
}
|
||||
|
||||
public final boolean isLocked()
|
||||
{
|
||||
return lock != null;
|
||||
}
|
||||
|
||||
public final void lock(SliderLock lock)
|
||||
{
|
||||
this.lock = lock;
|
||||
update();
|
||||
}
|
||||
|
||||
public final void unlock()
|
||||
{
|
||||
lock = null;
|
||||
update();
|
||||
}
|
||||
|
||||
public final boolean isDisabled()
|
||||
{
|
||||
return disabled;
|
||||
}
|
||||
|
||||
public final void setDisabled(boolean disabled)
|
||||
{
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
public final boolean isLimited()
|
||||
{
|
||||
return usableMax != maximum || usableMin != minimum;
|
||||
}
|
||||
|
||||
public final double getUsableMin()
|
||||
{
|
||||
return usableMin;
|
||||
}
|
||||
|
||||
public final void setUsableMin(double usableMin)
|
||||
{
|
||||
if(usableMin < minimum)
|
||||
throw new IllegalArgumentException("usableMin < minimum");
|
||||
|
||||
this.usableMin = usableMin;
|
||||
update();
|
||||
}
|
||||
|
||||
public final void resetUsableMin()
|
||||
{
|
||||
usableMin = minimum;
|
||||
update();
|
||||
}
|
||||
|
||||
public final double getUsableMax()
|
||||
{
|
||||
return usableMax;
|
||||
}
|
||||
|
||||
public final void setUsableMax(double usableMax)
|
||||
{
|
||||
if(usableMax > maximum)
|
||||
throw new IllegalArgumentException("usableMax > maximum");
|
||||
|
||||
this.usableMax = usableMax;
|
||||
update();
|
||||
}
|
||||
|
||||
public final void resetUsableMax()
|
||||
{
|
||||
usableMax = maximum;
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Component getComponent()
|
||||
{
|
||||
return new SliderComponent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void fromJson(JsonElement json)
|
||||
{
|
||||
if(!JsonUtils.isNumber(json))
|
||||
return;
|
||||
|
||||
double value = json.getAsDouble();
|
||||
if(value > maximum || value < minimum)
|
||||
return;
|
||||
|
||||
setValueIgnoreLock(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final JsonElement toJson()
|
||||
{
|
||||
return new JsonPrimitive(Math.round(value * 1e6) / 1e6);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public final void addToFeatureScreen(NavigatorFeatureScreen
|
||||
// featureScreen)
|
||||
// {
|
||||
// featureScreen.addText("\n" + getName() + ":");
|
||||
// navigatorPosY = 60 + featureScreen.getTextHeight();
|
||||
// featureScreen.addText("\n");
|
||||
//
|
||||
// featureScreen.addSlider(this);
|
||||
// }
|
||||
|
||||
public final int getNavigatorPosY()
|
||||
{
|
||||
return navigatorPosY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ArrayList<PossibleKeybind> getPossibleKeybinds(
|
||||
String featureName)
|
||||
{
|
||||
String fullName = featureName + " " + getName();
|
||||
|
||||
String command = ".setslider " + featureName.toLowerCase() + " ";
|
||||
command += getName().toLowerCase().replace(" ", "_") + " ";
|
||||
|
||||
ArrayList<PossibleKeybind> pkb = new ArrayList<>();
|
||||
pkb.add(new PossibleKeybind(command + "more", "Increase " + fullName));
|
||||
pkb.add(new PossibleKeybind(command + "less", "Decrease " + fullName));
|
||||
|
||||
return pkb;
|
||||
}
|
||||
|
||||
public static interface ValueDisplay
|
||||
{
|
||||
public static final ValueDisplay DECIMAL =
|
||||
v -> Math.round(v * 1e6) / 1e6 + "";
|
||||
|
||||
public static final ValueDisplay INTEGER = v -> (int)v + "";
|
||||
|
||||
public static final ValueDisplay PERCENTAGE =
|
||||
v -> (int)(Math.round(v * 1e8) / 1e6) + "%";
|
||||
|
||||
public static final ValueDisplay DEGREES = v -> (int)v + "°";
|
||||
|
||||
public static final ValueDisplay NONE = v -> "";
|
||||
|
||||
public String getValueString(double value);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user