Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8fdf23d
chore: add javadocs to BaseWidget
UndercoverGoose Aug 28, 2025
e4c1ee1
chore: add javadocs to TextWidget
UndercoverGoose Aug 28, 2025
180a48e
chore: add javadocs to PassthroughWidget
UndercoverGoose Aug 28, 2025
60dc379
chore: add javadocs to ScrollableWidget
UndercoverGoose Aug 28, 2025
9e8628c
chore: add javadocs to ColorSquareWidget
UndercoverGoose Oct 2, 2025
67992b6
chore: add javadocs to DropdownWidget
UndercoverGoose Oct 2, 2025
ff73111
chore: add javadocs to ColorDropdownWidget
UndercoverGoose Oct 2, 2025
10e83dd
chore: add javadocs to DraggableWidget
UndercoverGoose Oct 2, 2025
0400ae7
chore: add javadocs to SliderWidget
UndercoverGoose Oct 2, 2025
f2b6874
chore: add javadocs to ToggleWidget
UndercoverGoose Oct 2, 2025
6f263f0
chore: add javadocs to KeybindWidget
UndercoverGoose Oct 2, 2025
bcce83b
chore: add javadocs to ToggleKeybindWidget
UndercoverGoose Oct 2, 2025
ce7b54d
chore: format unformatted javadocs
UndercoverGoose Oct 2, 2025
6fef9df
chore: add most javadocs to CigaretteScreen
UndercoverGoose Oct 3, 2025
6923ad4
chore: add javadocs to Scissor
UndercoverGoose Oct 3, 2025
2f2f6f4
chore: add remaining javadocs to widget class definitions
UndercoverGoose Oct 3, 2025
96ba29d
chore: add javadocs to CategoryInstance
UndercoverGoose Oct 3, 2025
c1108af
chore: add javadocs to RenderUtil
UndercoverGoose Oct 3, 2025
f63bfb6
chore: fix missing javadoc and errors
UndercoverGoose Oct 3, 2025
c4e0f09
replace code docs with links where applicable
UndercoverGoose Oct 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/main/java/dev/cigarette/gui/CategoryInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,30 @@

import java.util.HashSet;

/**
* A category that groups modules together to be rendered by the GUI.
*/
public class CategoryInstance {
/**
* The root widget that contains each module's top-level widget for rendering.
*/
public final ScrollableWidget<BaseWidget<?>> widget;
/**
* The list of each module attached to this category.
*/
public final HashSet<BaseModule<?, ?>> children = new HashSet<>();
/**
* Whether this category is expanded or collapsed.
*/
public boolean expanded = false;

/**
* Creates a new category to group modules.
*
* @param displayName The text to display in the header of the category.
* @param x The initial X position of this category
* @param y The initial Y position of this category
*/
public CategoryInstance(String displayName, int x, int y) {
this.widget = new ScrollableWidget<>(x, y);
this.widget.setHeader(displayName, () -> {
Expand All @@ -19,6 +38,11 @@ public CategoryInstance(String displayName, int x, int y) {
this.widget.alphabetic();
}

/**
* Attaches a list of modules to this category.
*
* @param children The list of modules to attach
*/
public void attach(BaseModule<?, ?>... children) {
BaseWidget<?>[] childWidgets = new BaseWidget[children.length];
for (int i = 0; i < children.length; i++) {
Expand Down
74 changes: 74 additions & 0 deletions src/main/java/dev/cigarette/gui/CigaretteScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.cigarette.gui.widget.BaseWidget;
import dev.cigarette.gui.widget.KeybindWidget;
import dev.cigarette.gui.widget.ScrollableWidget;
import dev.cigarette.gui.widget.ToggleKeybindWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Element;
Expand All @@ -16,32 +17,88 @@
import java.util.Stack;

public class CigaretteScreen extends Screen {
/**
* Primary feature color. (Orange)
*/
public static final int PRIMARY_COLOR = 0xFFFE5F00;
/**
* Secondary feature color. (Brown)
*/
public static final int SECONDARY_COLOR = 0xFFC44700;
/**
* Primary text color. (White)
*/
public static final int PRIMARY_TEXT_COLOR = 0xFFFFFFFF;
/**
* Primary background color. (Dark Gray)
*/
public static final int BACKGROUND_COLOR = 0xFF1A1A1A;
/**
* Dark background color usually used in gradients with {@link #BACKGROUND_COLOR}. (Black)
*/
public static final int DARK_BACKGROUND_COLOR = 0xFF000000;
/**
* Color of enabled things. (Bright Green)
*/
public static final int ENABLED_COLOR = 0xFF3AFC3A;
/**
* Reference to the hovered widget.
*/
public static @Nullable Object hoverHandled = null;
/**
* An ordered list of the widgets on the screen. Ordered by time of focus descending. Event propagation starts with the most recent focused to the last focused.
*/
private final Stack<BaseWidget<?>> priority = new Stack<>();
/**
* The screen that was being rendered before this GUI was opened.
*/
private Screen parent = null;
/**
* Whether the GUI is in process of opening.
*/
private boolean begin = false;
/**
* The time at which the GUI was opened.
*/
private long openStartNanos = 0L;
/**
* Whether the GUI is in process of closing.
*/
private boolean closing = false;
/**
* The time at which the GUI was closed.
*/
private long closeStartNanos = 0L;
/**
* The length of the opening animation in seconds.
*/
private static final double OPEN_DURATION_S = 0.4;
private static final double OPEN_STAGGER_S = 0.06;
private static final int OPEN_DISTANCE_PX = 24;

/**
* The length of the closing animation as a multiplier of {@link #OPEN_DURATION_S}.
*/
private static final double CLOSE_DURATION_FACTOR = 0.6;
private static final double CLOSE_STAGGER_FACTOR = 0.6;
/**
* The total number of categories in the GUI.
*/
private int categoryCount = 0;
/**
* Reference to a {@link KeybindWidget} or {@link ToggleKeybindWidget} that is actively listening for keys to bind.
*/
public static @Nullable KeybindWidget bindingKey = null;

protected CigaretteScreen() {
super(Text.literal("Cigarette Client"));
}

/**
* Called when the GUI is being opened to set the previous screen.
*
* @param parent The parent screen that will be reverted to on close
*/
public void setParent(@Nullable Screen parent) {
this.parent = parent;
}
Expand Down Expand Up @@ -120,6 +177,9 @@ public void mouseMoved(double mouseX, double mouseY) {
}
}

/**
* Called when the GUI should be closed.
*/
@Override
public void close() {
assert client != null;
Expand All @@ -143,6 +203,12 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return true;
}

/**
* {@return whether the provided widget can be hovered} If so, that widget is set as the hovered widget.
* <p>A widget must call {@link BaseWidget#captureHover() captureHover()} to be hoverable.</p>
*
* @param obj The widget to check if it can be hovered
*/
public static boolean isHoverable(Object obj) {
if (hoverHandled == null) {
hoverHandled = obj;
Expand All @@ -151,6 +217,14 @@ public static boolean isHoverable(Object obj) {
return hoverHandled == obj;
}

/**
* Replaces the built-in {@link Screen#render(DrawContext, int, int, float) Screen.render()} method. Handles animations and category rendering for the GUI.
*
* @param context The current draw context
* @param mouseX Current mouse X position
* @param mouseY Current mouse Y position
* @param deltaTicks Current delta ticks
*/
@Override
public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
this.renderBackground(context, mouseX, mouseY, deltaTicks);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dev/cigarette/gui/RenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

import com.mojang.blaze3d.systems.RenderSystem;

/**
* Custom utilities for screen rendering.
*/
public final class RenderUtil {
private RenderUtil() {}

/**
* Set the opacity of the renderer.
*
* @param alpha The opacity to set, between 0 and 1
*/
public static void pushOpacity(float alpha) {
if (alpha < 0f) alpha = 0f;
if (alpha > 1f) alpha = 1f;
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, alpha);
}

/**
* Reset the opacity of the renderer.
*/
public static void popOpacity() {
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
}
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/dev/cigarette/gui/Scissor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,44 @@

import java.util.Stack;

/**
* Custom scissor utility for screen rendering.
*/
public class Scissor {
/**
* An exclusive (non-additive) scissor. Use {@link #apply()} to activate and {@link #remove()} to deactivate.
*/
private static class Bound {
/**
* The draw context this scissor is attached to.
*/
DrawContext context;
/**
* The left edge of this bounding box.
*/
int left;
/**
* The top edge of this bounding box.
*/
int top;
/**
* The right edge of this bounding box.
*/
int right;
/**
* The bottom edge of this bounding box.
*/
int bottom;

/**
* Creates a new exclusive scissor.
*
* @param context The draw context to apply the scissor to
* @param left The left edge of the bounding box
* @param top The top edge of the bounding box
* @param right The right edge of the bounding box
* @param bottom The bottom edge of the bounding box
*/
Bound(DrawContext context, int left, int top, int right, int bottom) {
this.context = context;
this.left = left;
Expand All @@ -20,11 +50,17 @@ private static class Bound {
this.bottom = bottom;
}

/**
* Activate this scissor. This does not deactivate any other scissors that are applied.
*/
void apply() {
if (this.context == null) return;
this.context.enableScissor(left, top, right, bottom);
}

/**
* Deactivate this scissor.
*/
void remove() {
if (this.context == null) return;
this.context.disableScissor();
Expand All @@ -33,6 +69,15 @@ void remove() {

private static final Stack<Bound> exclusiveScissors = new Stack<>();

/**
* Push an exclusive (non-additive) scissor to a {@link DrawContext}.
*
* @param context The draw context to activate the scissor on
* @param left The left edge of the bounding box
* @param top The top edge of the bounding box
* @param right The right edge of the bounding box
* @param bottom The bottom edge of the bounding box
*/
public static void pushExclusive(DrawContext context, int left, int top, int right, int bottom) {
Bound bound = new Bound(context, left, top, right, bottom);

Expand All @@ -45,6 +90,9 @@ public static void pushExclusive(DrawContext context, int left, int top, int rig
bound.apply();
}

/**
* Pop the top-most exclusive scissor from the stack.
*/
public static void popExclusive() {
if (exclusiveScissors.isEmpty()) return;
Bound latest = exclusiveScissors.pop();
Expand Down
Loading