Skip to content

Instantly share code, notes, and snippets.

@superblaubeere27
Last active December 5, 2022 04:54
Show Gist options
  • Save superblaubeere27/49a4a281632bab06dbd44c9b92b34ead to your computer and use it in GitHub Desktop.
Save superblaubeere27/49a4a281632bab06dbd44c9b92b34ead to your computer and use it in GitHub Desktop.
Code for my ClickGUI Video
/*
* Copyright (c) 2018 superblaubeere27
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.superblaubeere27.clientbase.gui.clickgui;
import me.superblaubeere27.clickgui.IRenderer;
import me.superblaubeere27.clickgui.Window;
import me.superblaubeere27.clickgui.components.Button;
import me.superblaubeere27.clickgui.components.Label;
import me.superblaubeere27.clickgui.components.*;
import me.superblaubeere27.clickgui.layout.GridLayout;
import net.minecraft.client.gui.GuiScreen;
import net.superblaubeere27.clientbase.ClientBase;
import net.superblaubeere27.clientbase.modules.Module;
import net.superblaubeere27.clientbase.modules.ModuleCategory;
import net.superblaubeere27.clientbase.utils.Utils;
import net.superblaubeere27.clientbase.utils.fontRenderer.GlyphPageFontRenderer;
import net.superblaubeere27.clientbase.valuesystem.BooleanValue;
import net.superblaubeere27.clientbase.valuesystem.ModeValue;
import net.superblaubeere27.clientbase.valuesystem.NumberValue;
import net.superblaubeere27.clientbase.valuesystem.Value;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ClickGUI extends GuiScreen {
private final GlyphPageFontRenderer consolas;
private final Pane spoilerPane;
private final HashMap<ModuleCategory, Pane> categoryPaneMap;
private Window window;
private IRenderer renderer;
private List<ActionEventListener> onRenderListeners = new ArrayList<>();
public ClickGUI() {
consolas = GlyphPageFontRenderer.create("Consolas", 15, false, false, false);
renderer = new ClientBaseRendererImpl(consolas);
window = new Window(ClientBase.CLIENT_NAME, 50, 50, 900, 400);
Pane conentPane = new me.superblaubeere27.clickgui.components.ScrollPane(renderer, new me.superblaubeere27.clickgui.layout.GridLayout(1));
Pane buttonPane = new Pane(renderer, new me.superblaubeere27.clickgui.layout.FlowLayout());
HashMap<ModuleCategory, List<Module>> moduleCategoryMap = new HashMap<>();
categoryPaneMap = new HashMap<>();
for (Module module : ClientBase.INSTANCE.moduleManager.getModules()) {
if (!moduleCategoryMap.containsKey(module.getCategory())) {
moduleCategoryMap.put(module.getCategory(), new ArrayList<>());
}
moduleCategoryMap.get(module.getCategory()).add(module);
}
HashMap<ModuleCategory, Pane> paneMap = new HashMap<>();
List<Spoiler> spoilers = new ArrayList<>();
List<Pane> paneList = new ArrayList<>();
for (Map.Entry<ModuleCategory, List<Module>> moduleCategoryListEntry : moduleCategoryMap.entrySet()) {
Pane spoilerPane = new Pane(renderer, new GridLayout(1));
for (Module module : moduleCategoryListEntry.getValue()) {
Pane settingPane = new Pane(renderer, new me.superblaubeere27.clickgui.layout.GridLayout(4));
{
settingPane.addComponent(new Label(renderer, "State"));
CheckBox cb;
settingPane.addComponent(cb = new CheckBox(renderer, "Enabled"));
onRenderListeners.add(() -> cb.setSelected(module.getState()));
cb.setListener(val -> {
module.setState(val);
return true;
});
}
{
settingPane.addComponent(new Label(renderer, "Keybind"));
KeybindButton kb;
settingPane.addComponent(kb = new KeybindButton(renderer, Keyboard::getKeyName));
onRenderListeners.add(() -> kb.setValue(module.getKeybind()));
kb.setListener(val -> {
module.setKeybind(val);
System.out.println();
return true;
});
}
List<Value> values = ClientBase.INSTANCE.valueManager.getAllValuesFrom(module.getName());
if (values != null) {
for (Value value : values) {
if (value instanceof BooleanValue) {
settingPane.addComponent(new Label(renderer, value.getName()));
CheckBox cb;
settingPane.addComponent(cb = new CheckBox(renderer, "Enabled"));
cb.setListener(value::setObject);
onRenderListeners.add(() -> cb.setSelected(((BooleanValue) value).getObject()));
}
if (value instanceof ModeValue) {
settingPane.addComponent(new Label(renderer, value.getName()));
ComboBox cb;
settingPane.addComponent(cb = new ComboBox(renderer, ((ModeValue) value).getModes(), ((ModeValue) value).getObject()));
cb.setListener(object -> {
value.setObject(object);
System.out.println("lol");
return true;
});
onRenderListeners.add(() -> cb.setSelectedIndex(((ModeValue) value).getObject()));
}
if (value instanceof NumberValue) {
settingPane.addComponent(new Label(renderer, value.getName()));
Slider cb;
Slider.NumberType type = Slider.NumberType.DECIMAL;
if (value.getObject() instanceof Integer) {
type = Slider.NumberType.INTEGER;
} else if (value.getObject() instanceof Long) {
type = Slider.NumberType.TIME;
} else if (value.getObject() instanceof Float && ((NumberValue) value).getMin().intValue() == 0 && ((NumberValue) value).getMax().intValue() == 100) {
type = Slider.NumberType.PERCENT;
}
settingPane.addComponent(cb = new Slider(renderer, ((Number) value.getObject()).doubleValue(), ((NumberValue) value).getMin().doubleValue(), ((NumberValue) value).getMax().doubleValue(), type));
cb.setListener(val -> {
if (value.getObject() instanceof Integer) {
value.setObject(val.intValue());
}
if (value.getObject() instanceof Float) {
value.setObject(val.floatValue());
}
if (value.getObject() instanceof Long) {
value.setObject(val.longValue());
}
if (value.getObject() instanceof Double) {
value.setObject(val.doubleValue());
}
return true;
});
onRenderListeners.add(() -> cb.setValue(((Number) value.getObject()).doubleValue()));
}
}
}
Spoiler spoiler = new Spoiler(renderer, module.getName(), width, settingPane);
paneList.add(settingPane);
spoilers.add(spoiler);
spoilerPane.addComponent(spoiler);
paneMap.put(moduleCategoryListEntry.getKey(), spoilerPane);
}
categoryPaneMap.put(moduleCategoryListEntry.getKey(), spoilerPane);
}
spoilerPane = new Pane(renderer, new GridLayout(1));
for (ModuleCategory moduleCategory : categoryPaneMap.keySet()) {
Button button;
buttonPane.addComponent(button = new me.superblaubeere27.clickgui.components.Button(renderer, moduleCategory.toString()));
button.setOnClickListener(() -> setCurrentCategory(moduleCategory));
}
conentPane.addComponent(buttonPane);
int maxWidth = Integer.MIN_VALUE;
for (Pane pane : paneList) {
maxWidth = Math.max(maxWidth, pane.getWidth());
}
window.setWidth(28 + maxWidth);
for (Spoiler spoiler : spoilers) {
spoiler.preferredWidth = maxWidth;
spoiler.setWidth(maxWidth);
}
spoilerPane.setWidth(maxWidth);
buttonPane.setWidth(maxWidth);
conentPane.addComponent(spoilerPane);
conentPane.updateLayout();
window.setContentPane(conentPane);
if (categoryPaneMap.keySet().size() > 0)
setCurrentCategory(categoryPaneMap.keySet().iterator().next());
}
private void setCurrentCategory(ModuleCategory category) {
spoilerPane.clearComponents();
spoilerPane.addComponent(categoryPaneMap.get(category));
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
for (ActionEventListener onRenderListener : onRenderListeners) {
onRenderListener.onActionEvent();
}
Point point = Utils.calculateMouseLocation();
window.mouseMoved(point.x * 2, point.y * 2);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glLineWidth(1.0f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_TEXTURE_2D);
window.render(renderer);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_TEXTURE_2D);
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
window.mouseMoved(mouseX * 2, mouseY * 2);
window.mousePressed(mouseButton, mouseX * 2, mouseY * 2);
super.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
window.mouseMoved(mouseX * 2, mouseY * 2);
window.mouseReleased(state, mouseX * 2, mouseY * 2);
super.mouseReleased(mouseX, mouseY, state);
}
@Override
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
window.mouseMoved(mouseX * 2, mouseY * 2);
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
}
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
int eventDWheel = Mouse.getEventDWheel();
window.mouseWheel(eventDWheel);
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
window.keyPressed(keyCode, typedChar);
super.keyTyped(typedChar, keyCode);
}
}
/*
* Copyright (c) 2018 superblaubeere27
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.superblaubeere27.clientbase.modules.modules.render;
import net.superblaubeere27.clientbase.gui.clickgui.ClickGUI;
import net.superblaubeere27.clientbase.modules.Module;
import net.superblaubeere27.clientbase.modules.ModuleCategory;
import org.lwjgl.input.Keyboard;
public class ClickGUIModule extends Module {
private static final ClickGUI clickGui = new ClickGUI();
public ClickGUIModule() {
super("ClickGUI", "The click gui", ModuleCategory.RENDER, true, true, Keyboard.KEY_RSHIFT);
}
@Override
protected void onEnable() {
mc.displayGuiScreen(clickGui);
setState(false);
}
}
package net.superblaubeere27.clientbase.gui.clickgui;
import me.superblaubeere27.clickgui.IRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.superblaubeere27.clientbase.utils.GLUtil;
import net.superblaubeere27.clientbase.utils.fontRenderer.GlyphPageFontRenderer;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
import static org.lwjgl.opengl.GL41.glClearDepthf;
public class ClientBaseRendererImpl implements IRenderer {
private GlyphPageFontRenderer renderer;
public ClientBaseRendererImpl(GlyphPageFontRenderer renderer) {
this.renderer = renderer;
}
@Override
public void drawRect(double x, double y, double w, double h, Color c) {
GLUtil.drawRect(GL11.GL_QUADS, x / 2.0, y / 2.0, x / 2.0 + w / 2.0, y / 2.0 + h / 2.0, GLUtil.toRGBA(c));
}
@Override
public void drawOutline(double x, double y, double w, double h, float lineWidth, Color c) {
GL11.glLineWidth(lineWidth);
GLUtil.drawRect(GL11.GL_LINE_LOOP, x / 2.0, y / 2.0, x / 2.0 + w / 2.0, y / 2.0 + h / 2.0, GLUtil.toRGBA(c));
}
@Override
public void setColor(Color c) {
GLUtil.setColor(c);
}
@Override
public void drawString(int x, int y, String text, Color color) {
renderer.drawString(text, x / 2f, y / 2f, GLUtil.toRGBA(color), false);
}
@Override
public int getStringWidth(String str) {
return renderer.getStringWidth(str) * 2;
}
@Override
public int getStringHeight(String str) {
return renderer.getFontHeight() * 2;
}
@Override
public void drawTriangle(double x1, double y1, double x2, double y2, double x3, double y3, Color color) {
// Tessellator tessellator = Tessellator.getInstance();
// WorldRenderer worldrenderer = tessellator.getWorldRenderer();
// GlStateManager.enableBlend();
// GlStateManager.disableTexture2D();
// GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
//
// setColor(color);
//
// worldrenderer.begin(GL_TRIANGLES, DefaultVertexFormats.POSITION);
// worldrenderer.pos(x1, y1, 0.0D).endVertex();
// worldrenderer.pos(x2, y2, 0.0D).endVertex();
// worldrenderer.pos(x3, y3, 0.0D).endVertex();
// tessellator.draw();
// GlStateManager.enableTexture2D();
// GlStateManager.disableBlend();
}
@Override
public void initMask() {
glClearDepthf(1.0f);
glClear(GL_DEPTH_BUFFER_BIT);
glColorMask(false, false, false, false);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glDepthMask(true);
}
@Override
public void useMask() {
glColorMask(true, true, true, true);
glDepthMask(true);
glDepthFunc(GL_EQUAL);
}
@Override
public void disableMask() {
glClearDepthf(1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDepthMask(false);
}
}
@LeshaLeyx
Copy link

xyi

@LeshaLeyx
Copy link

ezz click gui sps bro eblan typiop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment