New GUI base
This commit is contained in:
parent
a3ab8b7238
commit
342909810f
8 changed files with 307 additions and 571 deletions
|
@ -19,8 +19,8 @@ import java.util.ArrayList;
|
|||
@Mod(modid = "baseband")
|
||||
public class BaseBand {
|
||||
public static int majorVersion = 1;
|
||||
public static int buildNumber = 22;
|
||||
public static String hash = "2383d2e8a45e198d";
|
||||
public static int buildNumber = 26;
|
||||
public static String hash = "c1c6db0a68e9c40b";
|
||||
|
||||
public static String name = "BaseBand";
|
||||
public long timeOfCompile = 1694681365260L;
|
||||
|
|
|
@ -1,409 +0,0 @@
|
|||
package com.baseband.client;
|
||||
|
||||
|
||||
import com.baseband.client.module.Module;
|
||||
import com.baseband.client.module.modules.ClickGUI;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class GuiBB extends GuiScreen {
|
||||
|
||||
// The buttons to be rendered (sub buttons are in the button object)
|
||||
// One button per module
|
||||
private Button[] buttons;
|
||||
|
||||
public interface ITheme {
|
||||
int getButtonColor();
|
||||
|
||||
int getSubButtonColor();
|
||||
|
||||
int getTextColor();
|
||||
|
||||
boolean hasShadow();
|
||||
}
|
||||
|
||||
public enum Theme implements ITheme {
|
||||
TTC(0x8000ff00, 0x4000ff00),
|
||||
;
|
||||
|
||||
@Override
|
||||
public int getButtonColor() {
|
||||
return buttonColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSubButtonColor() {
|
||||
return subButtonColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextColor() {
|
||||
return textColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasShadow() {
|
||||
return shadow;
|
||||
}
|
||||
|
||||
public final int buttonColor;
|
||||
public final int subButtonColor;
|
||||
public final int textColor;
|
||||
public final boolean shadow;
|
||||
|
||||
Theme(int buttonColor, int subButtonColor) {
|
||||
this.buttonColor = buttonColor;
|
||||
this.subButtonColor = subButtonColor;
|
||||
this.textColor = 0xffffffff;
|
||||
this.shadow = true;
|
||||
}
|
||||
|
||||
Theme(int buttonColor, int subButtonColor, int textColor) {
|
||||
this.buttonColor = buttonColor;
|
||||
this.subButtonColor = subButtonColor;
|
||||
this.textColor = textColor;
|
||||
this.shadow = true;
|
||||
}
|
||||
|
||||
Theme(int buttonColor, int subButtonColor, int textColor, boolean shadow) {
|
||||
this.buttonColor = buttonColor;
|
||||
this.subButtonColor = subButtonColor;
|
||||
this.textColor = textColor;
|
||||
this.shadow = shadow;
|
||||
}
|
||||
}
|
||||
|
||||
// The mouse X and Y
|
||||
private int cx;
|
||||
private int cy;
|
||||
private int lastScrollPos = Mouse.getEventDWheel();
|
||||
|
||||
public GuiBB() {
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
// This lets you open the gui while being in a portal.
|
||||
return mc.player.timeInPortal != 0;
|
||||
}
|
||||
|
||||
// The initiator, this can, for some reason, not be in the constructor
|
||||
public void initGui() {
|
||||
// Creates buttons
|
||||
buttons = new Button[256];
|
||||
resetButtons();
|
||||
|
||||
// Minecraft wants this
|
||||
super.buttonList.clear();
|
||||
super.buttonList.add(new GuiButton(0, -500, -500, ""));
|
||||
super.initGui();
|
||||
lastScrollPos = Mouse.getEventDWheel();
|
||||
}
|
||||
|
||||
// When ESC is pressed
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
super.onGuiClosed();
|
||||
ClickGUI.getInstance().setEnabled(false);
|
||||
}
|
||||
|
||||
// Called every tick
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
// Minecraft is stupid and sometimes forgets to call initScreen, so this is needed
|
||||
while (buttons == null) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (buttons == null)
|
||||
resetButtons();
|
||||
}
|
||||
// Call onTick on every button
|
||||
for (int i = 0; i < buttons.length; i++) {
|
||||
Button button = buttons[i];
|
||||
if (button != null)
|
||||
button.onTick(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the buttons array
|
||||
private void resetButtons() {
|
||||
System.out.println("Resetting buttons on ClickGUI");
|
||||
for (int i = 0, j = 0; i < BaseBand.INSTANCE.modules.size(); i++) {
|
||||
int x = j / 15;
|
||||
int y = j - x * 15;
|
||||
|
||||
Module module = BaseBand.INSTANCE.modules.get(i);
|
||||
|
||||
// Create the button
|
||||
Button b = new Button(
|
||||
10 + (155 * x), 10 + (y * 25), BaseBand.INSTANCE.modules.get(i).toString() + ": " + BaseBand.INSTANCE.modules.get(i).isEnabled(),
|
||||
(text) -> {
|
||||
module.toggle();
|
||||
text.set(module.toString() + ": " + module.isEnabled());
|
||||
}, module
|
||||
);
|
||||
buttons[i] = b;
|
||||
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset text on the buttons
|
||||
private void updateButtons() {
|
||||
while (buttons == null) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (buttons == null)
|
||||
resetButtons();
|
||||
}
|
||||
for (int i = 0; i < BaseBand.INSTANCE.modules.size(); i++) {
|
||||
if (buttons[i] != null)
|
||||
buttons[i].text.set(BaseBand.INSTANCE.modules.get(i).toString() + ": " + BaseBand.INSTANCE.modules.get(i).isEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
// Called when the user presses a mouse button
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
// Update cx and cy
|
||||
cx = mouseX;
|
||||
cy = mouseY;
|
||||
|
||||
// Notify buttons
|
||||
for (int i = 0; i < buttons.length; i++) {
|
||||
Button button = buttons[i];
|
||||
if (button != null)
|
||||
if (button.mouseClicked(mouseX, mouseY, mouseButton))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update cx and cy
|
||||
@Override
|
||||
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
cx = mouseX;
|
||||
cy = mouseY;
|
||||
}
|
||||
|
||||
// Called when the user releases a mouse button
|
||||
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
super.mouseReleased(mouseX, mouseY, state);
|
||||
|
||||
// Update cx and cy
|
||||
cx = mouseX;
|
||||
cy = mouseY;
|
||||
|
||||
// Notify buttons
|
||||
for (int i = 0; i < buttons.length; i++) {
|
||||
Button button = buttons[i];
|
||||
if (button != null)
|
||||
button.mouseReleased();
|
||||
}
|
||||
}
|
||||
|
||||
// Render the screen
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
updateButtons();
|
||||
|
||||
this.drawDefaultBackground();
|
||||
|
||||
cx = mouseX;
|
||||
cy = mouseY;
|
||||
|
||||
// Ask the buttons to render themselves
|
||||
for (Button button : buttons) {
|
||||
if (button != null)
|
||||
button.draw(this);
|
||||
}
|
||||
|
||||
// TMP fix for a strange bug that causes the mouse to be hidden
|
||||
//if (ClickGUI.getInstance().mouseFix) {
|
||||
// drawRect(mouseX - 2, mouseY - 2, mouseX + 2, mouseY + 2, 0xffffffff);
|
||||
//}
|
||||
int m = -Mouse.getDWheel();
|
||||
if (m != 0) {
|
||||
for (int i = 0; i < buttons.length; i++) {
|
||||
Button button = buttons[i];
|
||||
if (button != null) {
|
||||
button.y += (lastScrollPos - m) / 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
|
||||
public static class Button {
|
||||
public int x, y;
|
||||
public AtomicReference<String> text;
|
||||
// Color for rendering
|
||||
public int color = 0x8000ff00;
|
||||
// The associated module, can be null if it is a sub button
|
||||
public Module module;
|
||||
// Called when the button is clicked
|
||||
ButtonClickEvent event;
|
||||
// If any mouse button is pressed
|
||||
private boolean mouseDown = false;
|
||||
// The mouse button that is pressed
|
||||
private int mouseDownButton = 0;
|
||||
// The sub buttons of the button, null if no module is associated to provide them
|
||||
private Button[] subButtons;
|
||||
|
||||
private boolean display = true;
|
||||
|
||||
// Constructor used for sub buttons
|
||||
public Button(String text, ButtonClickEvent event) {
|
||||
this(0, 0, text, event, null);
|
||||
}
|
||||
|
||||
// Constructor used by GuiTTC to construct a button with an associated module
|
||||
// and main constructor
|
||||
public Button(int x, int y, String text, ButtonClickEvent event, Module module) {
|
||||
if (module != null) {
|
||||
if (module.clickGuiX != null && module.clickGuiY != null) {
|
||||
x = module.clickGuiX;
|
||||
y = module.clickGuiY;
|
||||
}
|
||||
subButtons = module.getButtons().toArray(new Button[0]);
|
||||
display = true; //module.displayOnClickGUI();
|
||||
//TODO: fix
|
||||
}
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.text = new AtomicReference<>(text);
|
||||
this.event = event;
|
||||
this.module = module;
|
||||
if (ClickGUI.getInstance() != null)
|
||||
this.color = Theme.TTC.getButtonColor();
|
||||
}
|
||||
|
||||
// Render the button
|
||||
public void draw(GuiBB gui) {
|
||||
if (!display)
|
||||
return;
|
||||
|
||||
int color = this.color;
|
||||
|
||||
if (gui.cx >= x && gui.cy >= y && gui.cx <= x + 150 && gui.cy <= y + ySize()) {
|
||||
Color c = new Color(color, true);
|
||||
int r, g, b, a;
|
||||
r = c.getRed();
|
||||
g = c.getGreen();
|
||||
b = c.getBlue();
|
||||
a = c.getAlpha();
|
||||
r += 0x20;
|
||||
g += 0x20;
|
||||
b += 0x20;
|
||||
a += 0x20;
|
||||
color = new Color(Math.min(r, 0xff), Math.min(g, 0xff), Math.min(b, 0xff), Math.min(a, 0xff)).getRGB();
|
||||
}
|
||||
|
||||
drawRect(x, y, x + 150, y + ySize(), color);
|
||||
gui.fontRenderer.drawString(text.get(), x + 6, y + ySize() / 2f - 8 / 2f, Theme.TTC.getTextColor(), Theme.TTC.hasShadow());
|
||||
|
||||
// Draw sub buttons
|
||||
if (module != null && (module.showSubButtons)) {
|
||||
subButtons = module.getButtons().toArray(new Button[0]);
|
||||
|
||||
for (int i = 0; i < subButtons.length; i++) {
|
||||
Button b = subButtons[i];
|
||||
if (b != null) {
|
||||
b.x = x;
|
||||
b.y = y + ((i + 1) * 15 + (20 - 15));
|
||||
b.color = Theme.TTC.getSubButtonColor();//ClickGUI.getInstance().getTheme().getSubButtonColor();
|
||||
b.draw(gui);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ySize() {
|
||||
return module == null ? 15 : 20;
|
||||
}
|
||||
|
||||
public boolean mouseClicked(int clickX, int clickY, int button) {
|
||||
if (clickX >= x && clickY >= y) {
|
||||
if (clickX < x + 150 && clickY < y + ySize()) {
|
||||
mouseDown = true;
|
||||
//if(ClickGUI.getInstance().flipButtons) {
|
||||
// button = (button == 0 ? 1 : (button == 1 ? 0 : button));
|
||||
//}
|
||||
//No
|
||||
mouseDownButton = button;
|
||||
click(button);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (module != null && (module.showSubButtons)) {
|
||||
subButtons = module.getButtons().toArray(new Button[0]);
|
||||
|
||||
for (int i = 0; i < subButtons.length; i++) {
|
||||
Button b = subButtons[i];
|
||||
if (b != null) {
|
||||
b.x = x;
|
||||
b.y = y + ((i + 1) * 15 + (20 - 15));
|
||||
b.color = Theme.TTC.getSubButtonColor();
|
||||
if (b.mouseClicked(clickX, clickY, button))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void mouseReleased() {
|
||||
mouseDown = false;
|
||||
if (module != null && (module.showSubButtons)) {
|
||||
subButtons = module.getButtons().toArray(new Button[0]);
|
||||
|
||||
for (Button subButton : subButtons) {
|
||||
subButton.mouseReleased();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// More simple onCLick, only called when the mouse is clicked while on the button
|
||||
protected void click(int button) {
|
||||
if (button == 0)
|
||||
event.run(text);
|
||||
if (button == 2 && module != null)
|
||||
module.showSubButtons = !module.showSubButtons;
|
||||
}
|
||||
|
||||
protected void onTick(GuiBB gui) {
|
||||
this.color = Theme.TTC.getSubButtonColor();
|
||||
if (module != null) {
|
||||
if (mouseDown && mouseDownButton == 1) {
|
||||
x = gui.cx - 150 / 2;
|
||||
y = gui.cy - 10;
|
||||
x = (x / 5) * 5;
|
||||
y = (y / 5) * 5;
|
||||
}
|
||||
module.clickGuiX = x;
|
||||
module.clickGuiY = y;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface ButtonClickEvent {
|
||||
void run(AtomicReference<String> text);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.baseband.client.guirewrite;
|
||||
|
||||
public abstract class Button {
|
||||
|
||||
private int x, y, width, height;
|
||||
private boolean hovered;
|
||||
|
||||
public Button(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public abstract void drawButton(int mouseX, int mouseY, float partialTicks);
|
||||
|
||||
public void onClick(int mouseX, int mouseY) {}
|
||||
|
||||
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||
return mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
}
|
||||
|
||||
public void setHovered(boolean hovered) {
|
||||
this.hovered = hovered;
|
||||
}
|
||||
|
||||
public boolean isHovered() {
|
||||
return hovered;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.baseband.client.guirewrite;
|
||||
|
||||
import com.baseband.client.BaseBand;
|
||||
import com.baseband.client.module.Module;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiBaseBand extends GuiScreen {
|
||||
|
||||
private List<ModuleButton> buttonList = new ArrayList<>();
|
||||
|
||||
public GuiBaseBand() {
|
||||
int y=10;
|
||||
int x=10;
|
||||
|
||||
for (Module m : BaseBand.INSTANCE.modules) {
|
||||
ModuleButton moduleButton = new ModuleButton(x, y, 120, 15, m);
|
||||
addButton(moduleButton);
|
||||
x+=moduleButton.getWidth();
|
||||
}
|
||||
}
|
||||
|
||||
public void addButton(ModuleButton button) {
|
||||
buttonList.add(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
for (ModuleButton m:buttonList) {
|
||||
m.drawButton(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
for (ModuleButton m : buttonList) {
|
||||
m.onClick(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package com.baseband.client.guirewrite;
|
||||
|
||||
import com.baseband.client.module.Module;
|
||||
import com.baseband.client.setting.Setting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.awt.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleButton extends Button {
|
||||
public ModuleButton(int x, int y, int width, int height, Module module) {
|
||||
super(x, y, width, height);
|
||||
this.module = module;
|
||||
int setY = y;
|
||||
|
||||
//Settings, Doomed.
|
||||
Field[] fields = this.module.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
Setting setting = field.getDeclaredAnnotation(Setting.class);
|
||||
if (setting == null)
|
||||
continue;
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
setY=setY+height;
|
||||
settingButtons.add(new SettingButton(x, setY, width, height,this, field, setting.value()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Module module;
|
||||
|
||||
List<SettingButton> settingButtons = new ArrayList<>();
|
||||
|
||||
public boolean isExtended = false;
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
if(isExtended){
|
||||
if(!settingButtons.isEmpty()) {
|
||||
int settingsHeight = 0;
|
||||
for (SettingButton s : settingButtons) {
|
||||
settingsHeight = settingsHeight + s.getHeight();
|
||||
}
|
||||
return super.getHeight() + settingsHeight;
|
||||
}
|
||||
} else {
|
||||
return super.getHeight();
|
||||
}
|
||||
return super.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(int mouseX, int mouseY, float partialTicks) {
|
||||
Gui.drawRect(getX(), getY(), getX() + getWidth(), getY() + getHeight(), Color.GREEN.getRGB());
|
||||
Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(module.toString() + ":" + module.isEnabled(), getX() + (float) (getWidth() - Minecraft.getMinecraft().fontRenderer.getStringWidth(module.toString() + ":" + module.isEnabled())) / 2, getY() + (float) (getHeight() - Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT) / 2, 0xffffffff);
|
||||
if(isExtended) {
|
||||
for (SettingButton s: settingButtons) {
|
||||
s.drawButton(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(int mouseX, int mouseY) {
|
||||
// Toggle showSubButtons when right-clicked
|
||||
if (isMouseOver(mouseX, mouseY)) {
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
if (Mouse.isButtonDown(1)) {
|
||||
this.isExtended = !this.isExtended;
|
||||
} else {
|
||||
for (SettingButton subButton : settingButtons) {
|
||||
subButton.onClick(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.module.toggle();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
package com.baseband.client.guirewrite;
|
||||
|
||||
import com.baseband.client.setting.FloatMeta;
|
||||
import com.baseband.client.setting.IntMeta;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class SettingButton extends Button {
|
||||
public SettingButton(int x, int y, int width, int height, ModuleButton parent, Field setting, String settingName) {
|
||||
super(x, y, width, height);
|
||||
this.parent = parent;
|
||||
field = setting;
|
||||
this.settingName=settingName;
|
||||
}
|
||||
|
||||
ModuleButton parent;
|
||||
String settingName;
|
||||
Field field;
|
||||
|
||||
@Override
|
||||
public void drawButton(int mouseX, int mouseY, float partialTicks) {
|
||||
Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(settingName + ":" + field.getType(), getX() + (float) (getWidth() - Minecraft.getMinecraft().fontRenderer.getStringWidth(settingName + ":" + field.getType())) / 2, getY() + (float) (getHeight() - Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT) / 2, 0xffffffff);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(int mouseX, int mouseY) {
|
||||
if(isMouseOver(mouseX, mouseY)) {
|
||||
try {
|
||||
if (field.getType() == boolean.class) {
|
||||
field.setBoolean(this, !field.getBoolean(this));
|
||||
}
|
||||
if (field.getType() == int.class) {
|
||||
int v = field.getInt(this);
|
||||
String[] expr = field.getAnnotation(IntMeta.class).value().split("([.][.])|(@)");
|
||||
int start = Integer.parseInt(expr[0]),
|
||||
end = Integer.parseInt(expr[1]),
|
||||
step = Integer.parseInt(expr[2]);
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
v -= step;
|
||||
} else {
|
||||
v += step;
|
||||
}
|
||||
if (v > end)
|
||||
v = start;
|
||||
if (v < start)
|
||||
v = end;
|
||||
field.setInt(this, v);
|
||||
}
|
||||
if (field.getType() == float.class) {
|
||||
float v = field.getFloat(this);
|
||||
String[] expr = field.getAnnotation(FloatMeta.class).value().split("([.][.])|(@)");
|
||||
float start = Float.parseFloat(expr[0]),
|
||||
end = Float.parseFloat(expr[1]),
|
||||
step = Float.parseFloat(expr[2]);
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
v -= step;
|
||||
} else {
|
||||
v += step;
|
||||
}
|
||||
if (v > end)
|
||||
v = start;
|
||||
if (v < start)
|
||||
v = end;
|
||||
field.setFloat(this, Math.round(v / step) * step);
|
||||
}
|
||||
if (field.getType() == double.class) {
|
||||
double v = field.getInt(this);
|
||||
String[] expr = field.getAnnotation(FloatMeta.class).value().split("([.][.])|(@)");
|
||||
double start = Double.parseDouble(expr[0]),
|
||||
end = Double.parseDouble(expr[1]),
|
||||
step = Double.parseDouble(expr[2]);
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
v -= step;
|
||||
} else {
|
||||
v += step;
|
||||
}
|
||||
if (v > end)
|
||||
v = start;
|
||||
if (v < start)
|
||||
v = end;
|
||||
field.setDouble(this, Math.round(v / step) * step);
|
||||
}
|
||||
if (field.getType().isEnum()) {
|
||||
Object[] objects = field.getType().getEnumConstants();
|
||||
Object last = objects[objects.length - 1];
|
||||
Object curr = field.get(this);
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
if (objects[i] == curr) {
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
curr = last;
|
||||
} else {
|
||||
curr = objects[(i + 1) % objects.length];
|
||||
}
|
||||
break;
|
||||
}
|
||||
last = objects[i];
|
||||
}
|
||||
field.set(this, curr);
|
||||
}
|
||||
|
||||
String s = field.get(this).toString();
|
||||
if (s.endsWith("999999")) {
|
||||
s = s.substring(0, s.length() - 5);
|
||||
s = Double.toString(Double.parseDouble(s) + 0.0000000001f);
|
||||
while (s.endsWith("0") && s.contains(".00"))
|
||||
s = s.substring(0, s.length() - 1);
|
||||
}
|
||||
if (s.endsWith("000001")) {
|
||||
s = s.substring(0, s.length() - 5);
|
||||
while (s.endsWith("0") && s.contains(".00"))
|
||||
s = s.substring(0, s.length() - 1);
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +1,10 @@
|
|||
package com.baseband.client.module;
|
||||
|
||||
import com.baseband.client.BaseBand;
|
||||
import com.baseband.client.GuiBB;
|
||||
import com.baseband.client.setting.FloatMeta;
|
||||
import com.baseband.client.setting.IntMeta;
|
||||
import com.baseband.client.setting.Setting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import tudbut.obj.Save;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class Module {
|
||||
@Save
|
||||
boolean isEnabled = defaultEnabled();
|
||||
|
@ -35,143 +27,7 @@ public abstract class Module {
|
|||
}
|
||||
}
|
||||
|
||||
public void setup(){
|
||||
if(isEnabled) {
|
||||
try {
|
||||
enable();
|
||||
}catch (Exception ignored){}
|
||||
BaseBand.INSTANCE.eventBus.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
} else {
|
||||
try {
|
||||
disable();
|
||||
}catch (Exception ignored){}
|
||||
BaseBand.INSTANCE.eventBus.unregister(this);
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<GuiBB.Button> buttons;
|
||||
public ArrayList<GuiBB.Button> getButtons() {
|
||||
if(buttons != null) {
|
||||
return buttons;
|
||||
}
|
||||
buttons = new ArrayList<>();
|
||||
Field[] fields = getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
Setting setting = field.getDeclaredAnnotation(Setting.class);
|
||||
if (setting == null)
|
||||
continue;
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
buttons.add(new GuiBB.Button(setting.value() + ": " + field.get(this), text -> {
|
||||
try {
|
||||
if(field.getType() == boolean.class) {
|
||||
field.setBoolean(this, !field.getBoolean(this));
|
||||
}
|
||||
if(field.getType() == int.class) {
|
||||
int v = field.getInt(this);
|
||||
String[] expr = field.getAnnotation(IntMeta.class).value().split("([.][.])|(@)");
|
||||
int start = Integer.parseInt(expr[0]),
|
||||
end = Integer.parseInt(expr[1]),
|
||||
step = Integer.parseInt(expr[2]);
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
v -= step;
|
||||
}
|
||||
else {
|
||||
v += step;
|
||||
}
|
||||
if (v > end)
|
||||
v = start;
|
||||
if (v < start)
|
||||
v = end;
|
||||
field.setInt(this, v);
|
||||
}
|
||||
if(field.getType() == float.class) {
|
||||
float v = field.getFloat(this);
|
||||
String[] expr = field.getAnnotation(FloatMeta.class).value().split("([.][.])|(@)");
|
||||
float start = Float.parseFloat(expr[0]),
|
||||
end = Float.parseFloat(expr[1]),
|
||||
step = Float.parseFloat(expr[2]);
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
v -= step;
|
||||
}
|
||||
else {
|
||||
v += step;
|
||||
}
|
||||
if (v > end)
|
||||
v = start;
|
||||
if (v < start)
|
||||
v = end;
|
||||
field.setFloat(this, Math.round(v / step) * step);
|
||||
}
|
||||
if(field.getType() == double.class) {
|
||||
double v = field.getInt(this);
|
||||
String[] expr = field.getAnnotation(FloatMeta.class).value().split("([.][.])|(@)");
|
||||
double start = Double.parseDouble(expr[0]),
|
||||
end = Double.parseDouble(expr[1]),
|
||||
step = Double.parseDouble(expr[2]);
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
v -= step;
|
||||
}
|
||||
else {
|
||||
v += step;
|
||||
}
|
||||
if (v > end)
|
||||
v = start;
|
||||
if (v < start)
|
||||
v = end;
|
||||
field.setDouble(this, Math.round(v / step) * step);
|
||||
}
|
||||
if(field.getType().isEnum()) {
|
||||
Object[] objects = field.getType().getEnumConstants();
|
||||
Object last = objects[objects.length - 1];
|
||||
Object curr = field.get(this);
|
||||
for(int i = 0; i < objects.length; i++) {
|
||||
if(objects[i] == curr) {
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
curr = last;
|
||||
}
|
||||
else {
|
||||
curr = objects[(i + 1) % objects.length];
|
||||
}
|
||||
break;
|
||||
}
|
||||
last = objects[i];
|
||||
}
|
||||
field.set(this, curr);
|
||||
}
|
||||
|
||||
String s = field.get(this).toString();
|
||||
if(s.endsWith("999999")) {
|
||||
s = s.substring(0, s.length() - 5);
|
||||
s = Double.toString(Double.parseDouble(s) + 0.0000000001f);
|
||||
while(s.endsWith("0") && s.contains(".00"))
|
||||
s = s.substring(0, s.length() - 1);
|
||||
}
|
||||
if(s.endsWith("000001")) {
|
||||
s = s.substring(0, s.length() - 5);
|
||||
while(s.endsWith("0") && s.contains(".00"))
|
||||
s = s.substring(0, s.length() - 1);
|
||||
}
|
||||
text.set(setting.value() + ": " + s);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}));
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return buttons;
|
||||
}
|
||||
@Save
|
||||
public
|
||||
boolean showSubButtons = false;
|
||||
@Save
|
||||
public Integer clickGuiX;
|
||||
@Save
|
||||
public Integer clickGuiY;
|
||||
|
||||
protected static Minecraft mc = Minecraft.getMinecraft();
|
||||
public void setKey(int key) {
|
||||
|
|
|
@ -1,41 +1,28 @@
|
|||
package com.baseband.client.module.modules;
|
||||
|
||||
import com.baseband.client.GuiBB;
|
||||
import com.baseband.client.event.Subscribe;
|
||||
import com.baseband.client.event.events.SafeTickEvent;
|
||||
import com.baseband.client.guirewrite.GuiBaseBand;
|
||||
import com.baseband.client.module.Module;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class ClickGUI extends Module {
|
||||
public static ClickGUI INSTANCE;
|
||||
public ClickGUI() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ClickGUI";
|
||||
}
|
||||
|
||||
public static ClickGUI getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int defaultKey() { return Keyboard.KEY_PERIOD; }
|
||||
|
||||
GuiBB guiBB;
|
||||
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void tick(SafeTickEvent e) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(null);
|
||||
if(guiBB==null) {
|
||||
guiBB = new GuiBB();
|
||||
}
|
||||
Minecraft.getMinecraft().displayGuiScreen(guiBB);
|
||||
//TODO: this existed but it was just the old V/Line gui, *do me proud tud!* :3
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiBaseBand());
|
||||
this.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue