Skip to content

Commit ba7a5fd

Browse files
committed
clickgui is fully rendered, only that it doesnt work
1 parent c063994 commit ba7a5fd

6 files changed

Lines changed: 224 additions & 32 deletions

File tree

src/main/java/dev/nectar/modules/Module.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Module implements ISerializable<Module> {
2626
public enum Category {
2727
COMBAT("Combat"), PLAYER("Player"), MOVEMENT("Movement"), RENDER("Render"), MISC("Misc"), WORLD("World");
2828

29-
public String name;
29+
public final String name;
3030
Category(String name) {
3131
this.name = name;
3232
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package dev.nectar.ui.screens.clickgui;
2+
3+
import dev.nectar.modules.Module;
4+
import net.minecraft.client.gui.DrawContext;
5+
6+
import java.awt.*;
7+
8+
import static dev.nectar.Nectar.mc;
9+
10+
public class CategoryButton extends Component{
11+
12+
private final String categoryName;
13+
public final Module.Category category;
14+
15+
private boolean selected = false;
16+
17+
public CategoryButton(int x, int y, int width, int height, Module.Category category) {
18+
super(x, y, width, height);
19+
20+
this.category = category;
21+
this.categoryName = category.name();
22+
}
23+
24+
public void select() {
25+
selected = true;
26+
}
27+
public void deselect() { selected = false; }
28+
29+
@Override
30+
public void render(DrawContext context, int mouseX, int mouseY) {
31+
if (selected && !isHovered(mouseX, mouseY)) context.fill(x, y, x+width, y+height, new Color(145, 145, 145, 170).getRGB());
32+
else if (selected && isHovered(mouseX, mouseY)) context.fill(x, y, x+width, y+height, new Color(145, 145, 145, 130).getRGB());
33+
else if (isHovered(mouseX, mouseY)) context.fill(x, y, x+width, y+height, new Color(36, 36, 36, 255).getRGB());
34+
else context.fill(x, y, x+width, y+height, new Color(36, 36, 36, 100).getRGB());
35+
36+
context.drawTextWithShadow(
37+
mc.textRenderer,
38+
categoryName,
39+
x+(width/8),
40+
y+(height/2)-(mc.textRenderer.fontHeight/2),
41+
Color.WHITE.getRGB()
42+
);
43+
}
44+
45+
@Override
46+
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
47+
if (isHovered(mouseX, mouseY)) {
48+
if (mouseButton == 0) {
49+
select();
50+
return true;
51+
}
52+
}
53+
54+
return false;
55+
}
56+
57+
}

src/main/java/dev/nectar/ui/screens/clickgui/ClickGUI.java

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,82 @@
55
import net.minecraft.client.gui.DrawContext;
66
import net.minecraft.client.gui.screen.Screen;
77
import net.minecraft.text.Text;
8+
import org.jspecify.annotations.NonNull;
89

910
import java.util.ArrayList;
1011
import java.util.List;
1112

13+
import static dev.nectar.Nectar.mc;
14+
1215
public class ClickGUI extends Screen {
1316

1417
public static final ClickGUI INSTANCE = new ClickGUI();
15-
private final List<Frame> frames = new ArrayList<>();;
18+
private final List<Component> components = new ArrayList<>();
19+
private final List<CategoryButton> categoryButtons = new ArrayList<>();
1620
private final ModulesContainer modulesContainer;
21+
private CategoryButton selectedCategory = null;
1722

1823
private ClickGUI() {
1924
super(Text.literal("ClickGUI"));
2025

21-
int offsetY = 20;
22-
int offsetX = 20;
26+
modulesContainer = initClickGUI();
27+
}
28+
29+
/**
30+
* Init ClickGUI
31+
*
32+
* @return
33+
*/
34+
private @NonNull ModulesContainer initClickGUI() {
35+
final ModulesContainer modulesContainer;
36+
int mcWidth = 500;
37+
int mcHeight = 350;
38+
int modulesWidth = 100;
39+
int modulesHeight = mcHeight / 6;
2340

24-
modulesContainer = new ModulesContainer(20, 20, 500, 350);
41+
int modulesX = mc.getWindow().getWidth() / 2 - mcWidth - (mcWidth / 2) - modulesWidth;
42+
int modulesY = mc.getWindow().getHeight() / 2 - mcHeight - (mcHeight / 4);
2543

2644
for (Module.Category category : Module.Category.values()) {
27-
frames.add(new Frame(offsetX, 20 + offsetY, 100, 20, category));
28-
offsetX += 100;
45+
CategoryButton newButton = new CategoryButton(modulesX, modulesY, modulesWidth, modulesHeight, category);
46+
47+
categoryButtons.add(newButton);
48+
components.add(newButton);
49+
50+
modulesY += modulesHeight;
2951
}
52+
53+
// Select the first category by default
54+
selectedCategory = categoryButtons.getFirst();
55+
selectedCategory.select();
56+
57+
int mcX = modulesX + modulesWidth;
58+
int mcY = mc.getWindow().getHeight() / 2 - mcHeight - (mcHeight / 4);
59+
60+
modulesContainer = new ModulesContainer(mcX, mcY, mcWidth, mcHeight);
61+
components.add(modulesContainer);
62+
63+
return modulesContainer;
3064
}
3165

3266
@Override
3367
public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
34-
modulesContainer.render(context);
35-
36-
for (Frame frame : frames) {
37-
frame.render(context, mouseX, mouseY, deltaTicks);
38-
frame.updatePos(mouseX, mouseY);
39-
}
68+
components.forEach(component -> component.render(context, mouseX, mouseY));
4069
}
4170

4271
@Override
4372
public boolean mouseClicked(Click click, boolean doubled) {
44-
for (Frame frame : frames) {
45-
frame.mouseClicked(click.x(), click.y(), click.button());
46-
}
47-
return true;
48-
}
73+
components.forEach(component -> {
74+
if (!(component instanceof CategoryButton)) component.mouseClicked(click.x(), click.y(), click.button());
4975

50-
@Override
51-
public boolean mouseReleased(Click click) {
52-
for (Frame frame : frames) {
53-
frame.mouseReleased(click.x(), click.y(), click.button());
54-
}
76+
// Handle ModulesButton
77+
if (!component.mouseClicked(click.x(), click.y(), click.button())) return;
78+
79+
// Update the selected category
80+
selectedCategory.deselect();
81+
selectedCategory = (CategoryButton) component;
82+
modulesContainer.updateCategory(selectedCategory.category);
83+
});
5584
return true;
5685
}
5786
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dev.nectar.ui.screens.clickgui;
2+
3+
import net.minecraft.client.gui.DrawContext;
4+
5+
public abstract class Component {
6+
7+
public final int x, y, width, height;
8+
9+
public Component(int x, int y, int width, int height) {
10+
this.x = x;
11+
this.y = y;
12+
this.width = width;
13+
this.height = height;
14+
}
15+
16+
protected abstract void render(DrawContext context, int mouseX, int mouseY);
17+
protected boolean mouseClicked(double mouseX, double mouseY, int mouseButton) { return false; }
18+
19+
public boolean isHovered(double mouseX, double mouseY) {
20+
return mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + height;
21+
}
22+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package dev.nectar.ui.screens.clickgui;
2+
3+
import dev.nectar.Nectar;
4+
import dev.nectar.modules.Module;
5+
import dev.nectar.modules.Modules;
6+
import net.minecraft.client.gui.DrawContext;
7+
8+
import java.awt.*;
9+
10+
import static dev.nectar.Nectar.mc;
11+
12+
public class ModuleButton extends Component {
13+
14+
private final Module module;
15+
16+
public ModuleButton(int x, int y, int width, int height, Module module) {
17+
super(x, y, width, height);
18+
19+
this.module = module;
20+
}
21+
22+
@Override
23+
protected void render(DrawContext context, int mouseX, int mouseY) {
24+
// Background
25+
if (isHovered(mouseX, mouseY)) context.fill(x, y, x+width, y+height, new Color(175, 175, 175, 180).getRGB());
26+
else context.fill(x, y, x+width, y+height, new Color(144, 144, 145, 180).getRGB());
27+
28+
context.drawTextWithShadow(mc.textRenderer, module.getDisplayName(), x + 10, y + height / 2 - (mc.textRenderer.fontHeight / 2), Color.WHITE.getRGB());
29+
}
30+
31+
@Override
32+
protected boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
33+
if (isHovered(mouseX, mouseY)) {
34+
if (mouseButton == 0) {
35+
Modules.get().get(module.getName()).toggle();
36+
return true;
37+
}
38+
}
39+
40+
return false;
41+
}
42+
}
Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,64 @@
11
package dev.nectar.ui.screens.clickgui;
22

3-
import dev.nectar.core.Color;
43
import dev.nectar.modules.Module;
4+
import dev.nectar.modules.Modules;
55
import net.minecraft.client.gui.DrawContext;
66

7-
public class ModulesContainer {
7+
import java.awt.*;
8+
import java.util.ArrayList;
9+
import java.util.List;
810

9-
public final int x, y, width, height;
11+
import static dev.nectar.Nectar.mc;
12+
13+
public class ModulesContainer extends Component {
14+
15+
private final List<ModuleButton> moduleButtons = new ArrayList<>();
1016
public Module.Category currentCategory = null;
17+
private String categoryLabel = "";
1118

1219
public ModulesContainer(int x, int y, int width, int height) {
13-
this.x = x;
14-
this.y = y;
15-
this.width = width;
16-
this.height = height;
20+
super(x, y, width, height);
21+
}
22+
23+
public void updateCategory(Module.Category category) {
24+
currentCategory = category;
25+
categoryLabel = currentCategory.name;
26+
27+
updateModuleButtons();
28+
}
29+
30+
private void updateModuleButtons() {
31+
moduleButtons.clear();
32+
33+
int modX = x + 10;
34+
int modY = y + 30;
35+
int modWidth = 100;
36+
int modHeight = 25;
37+
38+
int xOffset = 10;
39+
int yOffset = 10;
40+
41+
for (Module mod : Modules.get().getModsInCategory(currentCategory)) {
42+
moduleButtons.add(new ModuleButton(modX, modY, modWidth, modHeight, mod));
43+
modY += modHeight + yOffset;
44+
}
45+
}
46+
47+
@Override
48+
protected void render(DrawContext context, int mouseX, int mouseY) {
49+
// Background
50+
context.fill(this.x, y, x + width, y + height, new Color(56, 56, 56, 100).getRGB());
51+
52+
if (currentCategory == null) categoryLabel = "None selected";
53+
54+
// Label
55+
context.drawTextWithShadow(mc.textRenderer, categoryLabel, x + 10, y + 10, Color.WHITE.getRGB());
56+
moduleButtons.forEach((moduleButton) -> moduleButton.render(context, mouseX, mouseY));
1757
}
1858

19-
public void render(DrawContext context) {
20-
context.fill(x, y, x + width, y + height, Color.DARK_GRAY.getPacked());
59+
@Override
60+
protected boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
61+
moduleButtons.forEach((moduleButton) -> moduleButton.mouseClicked(mouseX, mouseY, mouseButton));
62+
return super.mouseClicked(mouseX, mouseY, mouseButton);
2163
}
2264
}

0 commit comments

Comments
 (0)