button expands when you click it :D also add some autogen javadocs

This commit is contained in:
janeptrv 2020-10-07 15:47:23 -04:00
parent cafd3700aa
commit f9a2fb60ad
7 changed files with 258 additions and 23 deletions

View file

@ -15,11 +15,11 @@ import net.minecraft.server.integrated.IntegratedServer;
import pm.j4.petroleum.modules.ExampleModule;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.modules.bindings.BindingManager;
import pm.j4.petroleum.util.config.ConfigHolder;
import pm.j4.petroleum.util.config.ConfigManager;
import pm.j4.petroleum.modules.list.ModList;
import pm.j4.petroleum.modules.menu.ModMenu;
import pm.j4.petroleum.modules.splash.SplashText;
import pm.j4.petroleum.util.config.ConfigHolder;
import pm.j4.petroleum.util.config.ConfigManager;
//TODO:
@ -33,6 +33,7 @@ import pm.j4.petroleum.modules.splash.SplashText;
// [ ] elytra bhop
// [ ] boatfly
// [ ] anti anti cheat
/**
* The type Petroleum mod.
*/

View file

@ -11,7 +11,13 @@ import net.minecraft.text.TranslatableText;
import pm.j4.petroleum.PetroleumMod;
import pm.j4.petroleum.util.config.ConfigManager;
/**
* The type P mod menu screen.
*/
public class PModMenuScreen extends Screen {
/**
* Instantiates a new P mod menu screen.
*/
public PModMenuScreen() {
super(new TranslatableText("petroleum.modlist"));
}
@ -25,7 +31,7 @@ public class PModMenuScreen extends Screen {
@Override
protected void init() {
this.addButton(new PMovableButton(10, 10, PetroleumMod.getActiveMods().get(0)));
this.addButton(new PMovableButton(10, 10, "Test", PetroleumMod.getActiveMods()));
}
@Override
@ -40,10 +46,10 @@ public class PModMenuScreen extends Screen {
BufferBuilder buffer = t_1.getBuffer();
RenderSystem.enableBlend();
buffer.begin(7, VertexFormats.POSITION_COLOR);
buffer.vertex(0,this.height, 0.0D).color(0.1F, 0.1F, 0.1F, 0.3F).next();
buffer.vertex(0, this.height, 0.0D).color(0.1F, 0.1F, 0.1F, 0.3F).next();
buffer.vertex(this.width, this.height, 0.0D).color(0.1F, 0.1F, 0.1F, 0.3F).next();
buffer.vertex(this.width, 0, 0.0D).color(0.1F, 0.1F, 0.1F, 0.3F).next();
buffer.vertex(0,0,0.0D).color(0.1F, 0.1F, 0.1F, 0.3F).next();
buffer.vertex(0, 0, 0.0D).color(0.1F, 0.1F, 0.1F, 0.3F).next();
t_1.draw();
RenderSystem.disableBlend();
}

View file

@ -1,45 +1,271 @@
package pm.j4.petroleum.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.List;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.text.LiteralText;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Matrix4f;
import pm.j4.petroleum.modules.base.ModuleBase;
/**
* The type P movable button.
*/
public class PMovableButton extends AbstractButtonWidget {
public PMovableButton(int x, int y, ModuleBase module) {
super(x, y, 0, 0, module.getReadableName());
int w = MinecraftClient.getInstance().textRenderer.getWidth(module.getReadableName()) + 8;
/**
* The Expanded.
*/
private boolean expanded;
/**
* The Collapsed width.
*/
private final int collapsedWidth;
/**
* The Expanded width.
*/
private int expandedWidth;
/**
* The Collapsed height.
*/
private final int collapsedHeight;
/**
* The Expanded height.
*/
private int expandedHeight;
/**
* The Module height.
*/
private final int moduleHeight;
/**
* The Modules.
*/
private final List<ModuleBase> modules;
/**
* The Stored x.
*/
private int storedX;
/**
* The Stored y.
*/
private int storedY;
/**
* The Padding.
*/
private final int padding = 5;
/**
* Instantiates a new P movable button.
*
* @param x the x
* @param y the y
* @param categoryName the category name
* @param modules the modules
*/
public PMovableButton(int x, int y, String categoryName, List<ModuleBase> modules) {
super(x, y, 0, 0, new LiteralText(categoryName));
int w = MinecraftClient.getInstance().textRenderer.getWidth(categoryName) + 8;
int h = MinecraftClient.getInstance().textRenderer.fontHeight + 8;
this.width = w;
this.collapsedWidth = w;
this.expandedWidth = 0;
this.height = h;
this.collapsedHeight = h;
this.expandedHeight = 0;
this.moduleHeight = h;
this.modules = modules;
}
@Override
public void onClick(double mouseX, double mouseY) {
this.storedX = (int) mouseX;
this.storedY = (int) mouseY;
super.onClick(mouseX, mouseY);
}
@Override
public void onRelease(double mouseX, double mouseY) {
int mx = (int) mouseX;
int my = (int) mouseY;
if (storedX + padding > mx && storedX - padding < mx &&
storedY + padding > my && storedY - padding < my) {
this.expanded = !this.expanded;
}
}
@Override
protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {
this.x += (int)deltaX;
this.y += (int)deltaY;
this.x += (int) deltaX;
this.y += (int) deltaY;
}
// fuck click sounds
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (this.active && this.visible) {
if (this.isValidClickButton(button)) {
boolean bl = this.clicked(mouseX, mouseY);
if (bl) {
this.onClick(mouseX, mouseY);
return true;
}
}
return false;
} else {
return false;
}
}
/**
* Transition max width.
*
* @param width the width
*/
private void transitionMaxWidth(int width) {
double increment = ((width - this.width) / 20.0);
int sign = (width > this.width) ? 1 : -1;
if (increment == 0) {
this.width = width;
} else if (increment < 1 && increment > -1) {
this.width += sign;
} else {
this.width += (int) increment;
}
}
/**
* Transition max height.
*
* @param height the height
*/
private void transitionMaxHeight(int height) {
double increment = ((height - this.height) / 20.0);
int sign = (height > this.height) ? 1 : -1;
if (increment == 0) {
this.height = height;
} else if (increment < 1 && increment > -1) {
this.height += sign;
} else {
this.height += (int) increment;
}
}
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
// CURRENT BUTTON RENDERING
//TODO just do some shit with Tessellator and BufferBuilder to draw the lines around the button
if (this.expandedWidth == 0 || this.expandedHeight == 0) {
this.expandedHeight = this.collapsedHeight + ((this.moduleHeight + 4) * modules.size());
modules.forEach(module -> {
int w = MinecraftClient.getInstance().textRenderer.getWidth(module.getReadableName()) + 8;
if (w > this.expandedWidth) {
this.expandedWidth = w;
}
});
}
MinecraftClient minecraftClient = MinecraftClient.getInstance();
TextRenderer textRenderer = minecraftClient.textRenderer;
minecraftClient.getTextureManager().bindTexture(WIDGETS_LOCATION);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, this.alpha);
int i = this.getYImage(this.isHovered());
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();
this.drawTexture(matrices, this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height);
this.drawTexture(matrices, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
this.renderBg(matrices, minecraftClient, mouseX, mouseY);
float brightness = this.isFocused() ? 1.0F : 0.5F;
RenderSystem.color4f(brightness, brightness, brightness, 1.0F);
Matrix4f matrix = matrices.peek().getModel();
int buttonLeft = this.x;
int buttonRight = this.x + width + 2;
int buttonTop = this.y;
int buttonBottom = this.y + this.collapsedHeight;
int buttonExpandedBottom = this.y + this.height;
Tessellator t_1 = Tessellator.getInstance();
BufferBuilder buffer = t_1.getBuffer();
RenderSystem.color4f(0.5F, 0.5F, 0.5F, 0.5F);
drawBox(t_1, buffer, matrix, buttonLeft, buttonRight, buttonTop - 2, buttonBottom + 2);
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 0.3F);
drawBox(t_1, buffer, matrix, buttonLeft + 1, buttonRight - 1, buttonTop - 1, buttonBottom + 1);
int j = this.active ? 16777215 : 10526880;
drawCenteredText(matrices, textRenderer, this.getMessage(), this.x + this.width / 2, this.y + (this.height - 8) / 2, j | MathHelper.ceil(this.alpha * 255.0F) << 24);
if (this.expanded) {
if (this.width != this.expandedWidth || this.height != this.expandedHeight) {
transitionMaxWidth(this.expandedWidth);
transitionMaxHeight(this.expandedHeight);
RenderSystem.color4f(0.5F, 0.5F, 0.5F, 0.5F);
drawBox(t_1, buffer, matrix, buttonLeft, buttonRight, buttonBottom + 1, buttonExpandedBottom + 2);
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 0.3F);
drawBox(t_1, buffer, matrix, buttonLeft + 1, buttonRight - 1, buttonBottom + 2, buttonExpandedBottom + 1);
if ((this.height - 8) / 2 > (this.collapsedHeight)) {
drawCenteredText(matrices, textRenderer, new LiteralText("..."), this.x + this.width / 2, this.y + (this.height - 8) / 2, j | MathHelper.ceil(this.alpha * 255.0F) << 24);
}
} else {
for (int i = 0; i < modules.size(); i++) {
int adjustedIndex = i + 1;
int previousBottom = buttonBottom + (i * (this.moduleHeight + 4));
int currentBottom = buttonBottom + ((i + 1) * (this.moduleHeight + 4));
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.color4f(0.5F, 0.5F, 0.5F, 0.5F);
drawBox(t_1, buffer, matrix, buttonLeft, buttonRight, previousBottom + 1, currentBottom + 2);
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 0.3F);
drawBox(t_1, buffer, matrix, buttonLeft + 1, buttonRight - 1, previousBottom + 2, currentBottom + 1);
drawCenteredText(matrices,
textRenderer,
modules.get(i).getReadableName(),
this.x + this.width / 2,
this.y + ((this.collapsedHeight - 8) / 2 + ((moduleHeight + 4) * adjustedIndex)),
j | MathHelper.ceil(this.alpha * 255.0F) << 24);
}
}
} else {
if (this.width != this.collapsedWidth || this.height != this.collapsedHeight) {
transitionMaxWidth(this.collapsedWidth);
transitionMaxHeight(this.collapsedHeight);
RenderSystem.color4f(0.5F, 0.5F, 0.5F, 0.5F);
drawBox(t_1, buffer, matrix, buttonLeft, buttonRight, buttonBottom + 1, buttonExpandedBottom + 2);
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 0.3F);
drawBox(t_1, buffer, matrix, buttonLeft + 1, buttonRight - 1, buttonBottom + 2, buttonExpandedBottom + 1);
if ((this.height - 8) / 2 > (this.collapsedHeight)) {
drawCenteredText(matrices, textRenderer, new LiteralText("..."), this.x + this.width / 2, this.y + (this.height - 8) / 2, j | MathHelper.ceil(this.alpha * 255.0F) << 24);
}
}
}
RenderSystem.enableTexture();
drawCenteredText(matrices, textRenderer, this.getMessage(), this.x + this.width / 2, this.y + (this.collapsedHeight - 8) / 2, j | MathHelper.ceil(this.alpha * 255.0F) << 24);
}
/**
* Draw box.
*
* @param t_1 the t 1
* @param buffer the buffer
* @param matrix the matrix
* @param buttonLeft the button left
* @param buttonRight the button right
* @param buttonTop the button top
* @param buttonBottom the button bottom
*/
private void drawBox(Tessellator t_1, BufferBuilder buffer, Matrix4f matrix, int buttonLeft, int buttonRight, int buttonTop, int buttonBottom) {
buffer.begin(7, VertexFormats.POSITION);
buffer.vertex(matrix, buttonLeft, buttonBottom, 0.0F).next();
buffer.vertex(matrix, buttonRight, buttonBottom, 0.0F).next();
buffer.vertex(matrix, buttonRight, buttonTop, 0.0F).next();
buffer.vertex(matrix, buttonLeft, buttonTop, 0.0F).next();
t_1.draw();
}
}

View file

@ -9,9 +9,9 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import pm.j4.petroleum.modules.splash.SplashText;
import pm.j4.petroleum.util.config.ConfigHolder;
import pm.j4.petroleum.util.config.ConfigManager;
import pm.j4.petroleum.modules.splash.SplashText;
/**
* The type Debug hud mixin.

View file

@ -16,9 +16,9 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.modules.list.ModList;
import pm.j4.petroleum.util.config.ConfigHolder;
import pm.j4.petroleum.util.config.ConfigManager;
import pm.j4.petroleum.modules.list.ModList;
/**
* The type Mod list mixin.

View file

@ -10,9 +10,9 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import pm.j4.petroleum.modules.splash.SplashText;
import pm.j4.petroleum.util.config.ConfigHolder;
import pm.j4.petroleum.util.config.ConfigManager;
import pm.j4.petroleum.modules.splash.SplashText;
/**
@ -66,7 +66,7 @@ public class TitleScreenMixin extends Screen {
@Inject(method = "render",
at = @At(
value = "INVOKE_ASSIGN",
target = "Lcom/mojang/bridge/game/GameVersion;getName()Ljava/lang/String;",
target = "Lcom/mojang/bridge/game/GameVersion;getName()Ljava/lang/String;",
ordinal = 0),
locals = LocalCapture.CAPTURE_FAILSOFT)
private void render(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci, float f, int i, int j, float g, int l) {

View file

@ -38,6 +38,8 @@ public abstract class ModuleBase {
/**
* Activate. Should be overridden.
*
* @param client the client
*/
public void activate(MinecraftClient client) {
this.toggle();