Skip to content

Commit

Permalink
> vC1.4.0a
Browse files Browse the repository at this point in the history
Additions:
- CountOwn option for PopCount
- Themes
- Middle clicking buttons to show/hide sub buttons

Deletions:
none

Other:
none

Notes:
- Time taken: ~4 hours

https://discord.gg/2WsVCQDpwy
  • Loading branch information
tudbut committed Feb 28, 2021
1 parent 86697bb commit 4948064
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 45 deletions.
2 changes: 1 addition & 1 deletion help.chat.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
§k||||||||||||||||||||||||||||||||
§c§lTTC Client
§k||||||||||||||||||||||||||||||||
§avC1.3.1a
§avC1.4.0a
§a§lHelp

§aCurrent prefix: %p
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/tudbut/mod/client/ttc/TTC.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@

import javax.swing.*;
import java.io.IOException;
import java.util.Date;
import java.util.Map;
import java.util.Objects;
import java.util.*;

@Mod(modid = TTC.MODID, name = TTC.NAME, version = TTC.VERSION)
public class TTC {
// FML stuff and version
public static final String MODID = "ttc";
public static final String NAME = "TTC Client";
public static final String VERSION = "vC1.3.1a";
public static final String VERSION = "vC1.4.0a";

// Registered modules, will make an api for it later
public static Module[] modules;
Expand Down Expand Up @@ -141,10 +139,10 @@ public void init(FMLInitializationEvent event) {
new Bright(),
new Freecam(),
new LSD(),
new ClickGUI(),
new Bind(),
new PopCount(),
new Takeoff()
new Takeoff(),
new ClickGUI()
};
sa = new Date().getTime() - sa;
System.out.println("Done in " + sa + "ms");
Expand Down Expand Up @@ -228,7 +226,13 @@ public void loadConfig() {
public static boolean isIngame() {
return mc.world != null && mc.player != null ;
}


public static void addModule(Module module) {
List<Module> list = Arrays.asList(modules);
list.add(module);
modules = list.toArray(new Module[0]);
}

public static <T extends Module> T getModule(Class<? extends T> module) {
for (int i = 0; i < modules.length; i++) {
if(modules[i].getClass() == module) {
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/tudbut/mod/client/ttc/gui/GuiPlayerSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public void updateScreen() {
if (buttons == null)
resetButtons();
}

for (int i = 0; i < buttons.length; i++) {
if(buttons[i] != null)
buttons[i].onTick();
}
}

// Reset the buttons array
Expand Down Expand Up @@ -195,6 +200,7 @@ public Button(int x, int y, String text, GuiTTC.ButtonClickEvent event) {
this.y = y;
this.text = new AtomicReference<>(text);
this.event = event;
this.color = ClickGUI.getInstance().getTheme().buttonColor;
}

// Render the button
Expand All @@ -216,7 +222,7 @@ public void draw(GuiPlayerSelect gui) {
}

drawRect(x, y, x + 150, y + 20, color);
gui.drawString(gui.fontRenderer, text.get(), x + 6, y + 6, 0xffffffff);
gui.fontRenderer.drawString(text.get(), x + 6, y + 6, ClickGUI.getInstance().getTheme().textColor, ClickGUI.getInstance().getTheme().shadow);
}

public boolean mouseClicked(int clickX, int clickY, int button) {
Expand All @@ -234,7 +240,10 @@ protected void click(int button) {
if (button == 0)
event.run(text);
}


public void onTick() {
this.color = ClickGUI.getInstance().getTheme().buttonColor;
}
}

public interface ButtonClickEvent {
Expand Down
81 changes: 70 additions & 11 deletions src/main/java/tudbut/mod/client/ttc/gui/GuiTTC.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package tudbut.mod.client.ttc.gui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.MouseHelper;
import org.lwjgl.input.Mouse;
import tudbut.mod.client.ttc.TTC;
import tudbut.mod.client.ttc.mods.ClickGUI;
Expand All @@ -17,9 +19,51 @@ public class GuiTTC extends GuiScreen {
// One button per module
private Button[] buttons;

// Theme
public enum Theme {
TTC(0x8000ff00, 0x4000ff00),
BARTENDER(0xff2d1537, 0xff0d0a0a),
ETERNAL_BLUE(0xff0000ff, 0xff000080),
DARK(0xff202020, 0xff000000),
LIGHT(0xffcccccc, 0xff999999, 0xff000000, false),
HACKER(0xff202020, 0xff000000, 0xff00ff00),
BLOOD(0xffaa0000, 0xff880000, 0xff00ffff, false),
SKY(0xff00cccc, 0xff009999, 0x000000, false),
KAMI_BLUE(0xbb353642, 0xbb353642, 0xffbbbbbb, false),
SCHLONGHAX(0xbb553662, 0xbb553662, 0xffbbbbbb, false),
ORANGE(0xffcc8000, 0xff996000, 0xff404040, false),

;

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 GuiTTC() {
this.mc = TTC.mc;
Expand All @@ -46,15 +90,14 @@ public void initGui() {
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().enabled = false;
// Minecraft wants this
mc.mouseHelper.grabMouseCursor();
}

// Called every tick, idk why its called update tho
Expand Down Expand Up @@ -82,8 +125,8 @@ public void updateScreen() {
private void resetButtons() {
System.out.println("Resetting buttons on ClickGUI");
for (int i = 0, j = 0; i < TTC.modules.length; i++) {
int x = j / 6;
int y = j - x * 6;
int x = j / 10;
int y = j - x * 10;

// Don't add the button if it isn't requested
if (!TTC.modules[i].displayOnClickGUI())
Expand All @@ -92,7 +135,7 @@ private void resetButtons() {
// Create the button
int r = i;
Button b = new Button(
10 + (160 * x), 10 + (y * 30), TTC.modules[r].getClass().getSimpleName() + ": " + TTC.modules[r].enabled,
10 + (155 * x), 10 + (y * 25), TTC.modules[r].getClass().getSimpleName() + ": " + TTC.modules[r].enabled,
(text) -> {
if (TTC.modules[r].enabled = !TTC.modules[r].enabled)
TTC.modules[r].onEnable();
Expand Down Expand Up @@ -184,6 +227,14 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
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++) {
if(buttons[i] != null) {
buttons[i].x += (lastScrollPos - m) / 3;
}
}
}

super.drawScreen(mouseX, mouseY, partialTicks);
}
Expand Down Expand Up @@ -228,6 +279,8 @@ public Button(int x, int y, String text, ButtonClickEvent event, Module module)
this.text = new AtomicReference<>(text);
this.event = event;
this.module = module;
if(ClickGUI.getInstance() != null)
this.color = ClickGUI.getInstance().getTheme().buttonColor;
}

// Render the button
Expand All @@ -236,7 +289,7 @@ public void draw(GuiTTC gui) {
return;

int color = this.color;

if (gui.cx >= x && gui.cy >= y && gui.cx <= x + 150 && gui.cy <= y + 20) {
Color c = new Color(color, true);
int r, g, b, a;
Expand All @@ -252,17 +305,17 @@ public void draw(GuiTTC gui) {
}

drawRect(x, y, x + 150, y + 20, color);
gui.drawString(gui.fontRenderer, text.get(), x + 6, y + 6, 0xffffffff);
gui.fontRenderer.drawString(text.get(), x + 6, y + 6, ClickGUI.getInstance().getTheme().textColor, ClickGUI.getInstance().getTheme().shadow);

// Draw sub buttons
if (module != null && module.enabled) {
if (module != null && (module.enabled ^ module.clickGuiShow)) {
subButtons = module.getSubButtons();

for (int i = 0; i < subButtons.length; i++) {
Button b = subButtons[i];
b.x = x;
b.y = y + ((i + 1) * 20);
b.color = 0x4000ff00;
b.color = ClickGUI.getInstance().getTheme().subButtonColor;
b.draw(gui);
}
}
Expand All @@ -272,12 +325,15 @@ public boolean mouseClicked(int clickX, int clickY, int button) {
if (clickX >= x && clickY >= y) {
if (clickX <= x + 150 && clickY <= y + 20) {
mouseDown = true;
if(ClickGUI.getInstance().flipButtons) {
button = (button == 0 ? 1 : (button == 1 ? 0 : button));
}
mouseDownButton = button;
click(button);
return true;
}
}
if (module != null && module.enabled) {
if (module != null && (module.enabled ^ module.clickGuiShow)) {
subButtons = module.getSubButtons();

for (int i = 0; i < subButtons.length; i++) {
Expand All @@ -290,7 +346,7 @@ public boolean mouseClicked(int clickX, int clickY, int button) {

public void mouseReleased() {
mouseDown = false;
if (module != null && module.enabled) {
if (module != null && (module.enabled ^ module.clickGuiShow)) {
subButtons = module.subButtons.toArray(new Button[0]);

for (int i = 0; i < subButtons.length; i++) {
Expand All @@ -304,9 +360,12 @@ public void mouseReleased() {
protected void click(int button) {
if (button == 0)
event.run(text);
if (button == 2 && module != null)
module.clickGuiShow = !module.clickGuiShow;
}

protected void onTick(GuiTTC gui) {
this.color = ClickGUI.getInstance().getTheme().buttonColor;
if (module != null) {
if (mouseDown && mouseDownButton == 1) {
x = gui.cx - 150 / 2;
Expand Down
57 changes: 43 additions & 14 deletions src/main/java/tudbut/mod/client/ttc/mods/ClickGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import tudbut.mod.client.ttc.gui.GuiTTC;
import tudbut.mod.client.ttc.utils.ChatUtils;
import tudbut.mod.client.ttc.utils.Module;
import tudbut.mod.client.ttc.utils.ThreadManager;
import tudbut.mod.client.ttc.utils.Utils;

import java.io.IOException;
Expand All @@ -17,9 +16,47 @@ public class ClickGUI extends Module {
// TMP fix for mouse not showing
public boolean mouseFix = false;

public boolean flipButtons = false;

public int themeID = 0;

public GuiTTC.Theme getTheme() {
return GuiTTC.Theme.values()[themeID];
}

private int confirmInstance = 0;

{
updateButtons();
}

public ClickGUI() {
instance = this;
}

public static ClickGUI getInstance() {
return instance;
}

private void updateButtons() {
subButtons.clear();
subButtons.add(new GuiTTC.Button("Flip buttons: " + flipButtons, text -> {
flipButtons = !flipButtons;
text.set("Flip buttons: " + flipButtons);
}));
subButtons.add(new GuiTTC.Button("Theme: " + getTheme(), text -> {
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
themeID--;
else
themeID++;

if(themeID < 0)
themeID = GuiTTC.Theme.values().length - 1;
if(themeID > GuiTTC.Theme.values().length - 1)
themeID = 0;

text.set("Theme: " + getTheme());
}));
subButtons.add(new GuiTTC.Button("Reset layout", text -> {
displayConfirmation = true;
confirmInstance = 0;
Expand All @@ -34,18 +71,6 @@ public class ClickGUI extends Module {
}));
}

public ClickGUI() {
instance = this;
}

public static ClickGUI getInstance() {
return instance;
}

private void updateButtons() {
subButtons.get(1).text.set("Mouse fix: " + mouseFix);
}

@Override
public void onEnable() {
ChatUtils.print("Showing ClickGUI");
Expand Down Expand Up @@ -130,14 +155,18 @@ public void onChat(String s, String[] args) {

@Override
public void loadConfig() {
mouseFix = Boolean.getBoolean(cfg.get("mouseFix"));
mouseFix = Boolean.parseBoolean(cfg.get("mouseFix"));
flipButtons = Boolean.parseBoolean(cfg.get("flipButtons"));
themeID = Integer.parseInt(cfg.get("theme"));

updateButtons();
}

@Override
public void updateConfig() {
cfg.put("mouseFix", String.valueOf(mouseFix));
cfg.put("flipButtons", flipButtons + "");
cfg.put("theme", themeID + "");
}

@Override
Expand Down
Loading

0 comments on commit 4948064

Please sign in to comment.