Skip to content

Commit

Permalink
feat(injector): change cancel and clear icons in the wheel menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Feb 11, 2024
1 parent 161b5da commit 72844fb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Matrix4f;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import software.bernie.geckolib3.core.util.Color;

public class DevCannonScreen extends Screen {

public static final int CANCEL_ID = -1;
static final float DIAGONAL_OF_ITEM = Mth.SQRT_OF_TWO * 32; // 16 * 2
static final int DURATION = 10;
private ItemStack cachedBarrierStack = ItemStack.EMPTY;
private int ticks;
private InteractionHand itemHoldingHand;
private final InteractionHand itemHoldingHand;

public DevCannonScreen(InteractionHand hand) {
super(ComponentUtil.translatable("biomancy.dev.wheel_menu"));
Expand All @@ -39,7 +37,6 @@ public DevCannonScreen(InteractionHand hand) {
@Override
protected void init() {
ticks = 0;
cachedBarrierStack = new ItemStack(Items.BARRIER);

//move mouse up, to make cancel action selected by default
double x = minecraft.getWindow().getScreenWidth() / 2d;
Expand All @@ -54,7 +51,6 @@ public boolean isPauseScreen() {

@Override
public void onClose() {
cachedBarrierStack = ItemStack.EMPTY;
super.onClose();
}

Expand Down Expand Up @@ -137,6 +133,7 @@ private void renderWheel(PoseStack poseStack, int mouseX, int mouseY, float pct)
float y = height / 2f;

int radius = Mth.floor(baseRadius * pct);
int blitOffset = 0;

float upperBound = segments * angleIncrement - Mth.HALF_PI + angleIncrement / 2f;
float lowerBound = -Mth.HALF_PI - angleIncrement / 2f;
Expand All @@ -160,7 +157,10 @@ private void renderWheel(PoseStack poseStack, int mouseX, int mouseY, float pct)
float v = x + radius * Mth.cos(currentAngle); //polar to cartesian
float w = y + radius * Mth.sin(currentAngle);

if (idx == 0) itemRenderer.renderAndDecorateFakeItem(cachedBarrierStack, Mth.floor(v - 8), Mth.floor(w - 8));
if (idx == 0) {
RenderSystem.setShaderTexture(0, InjectorScreen.ICONS);
GuiComponent.blit(poseStack, Mth.floor(v - 8), Mth.floor(w - 8), 16, 0, 16, 16, 32, 16);
}
else {
int argb = Color.HSBtoRGB(idx / (float) segments, 0.75f, 0.5f);
GuiRenderUtil.fill(poseStack, v - 8, w - 8, v + 8, w + 8, getBlitOffset(), argb);
Expand Down Expand Up @@ -196,12 +196,12 @@ private void renderWheel(PoseStack poseStack, int mouseX, int mouseY, float pct)
float minY = yt - font.lineHeight / 2f - 3;
float maxX = xt + lineWidth + 2;
float maxY = yt + font.lineHeight / 2f + 2;
GuiRenderUtil.fill(poseStack, minX, minY, maxX, maxY, getBlitOffset(), ColorStyles.GENERIC_TOOLTIP.backgroundColor() & 0xE0FFFFFF);
font.drawShadow(poseStack, text, xt, yt - font.lineHeight / 2f, ColorStyles.WHITE_ARGB);
GuiRenderUtil.fill(poseStack, minX, minY, maxX, maxY, blitOffset, ColorStyles.GENERIC_TOOLTIP.backgroundColor() & 0xE0FFFFFF);
font.drawShadow(poseStack, text, (int) xt, (int) (yt - font.lineHeight / 2f), ColorStyles.WHITE_ARGB);
poseStack.popPose();
}

public void drawSegment(PoseStack poseStack, float x, float y, float radius, float startAngle, float endAngle, int argbColor, int blitOffset) {
public void drawSegment(PoseStack poseStack, float x, float y, float radius, float startAngle, float endAngle, int argbColor, int z) {
Matrix4f matrix4f = poseStack.last().pose();

RenderSystem.enableBlend();
Expand All @@ -213,12 +213,12 @@ public void drawSegment(PoseStack poseStack, float x, float y, float radius, flo
bufferBuilder.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR);

float innerRadius = Math.max(radius - 16, 0);
bufferBuilder.vertex(matrix4f, x + innerRadius * Mth.cos(startAngle), y + innerRadius * Mth.sin(startAngle), blitOffset).color(argbColor).endVertex();
bufferBuilder.vertex(matrix4f, x + innerRadius * Mth.cos(endAngle), y + innerRadius * Mth.sin(endAngle), blitOffset).color(argbColor).endVertex();
bufferBuilder.vertex(matrix4f, x + innerRadius * Mth.cos(startAngle), y + innerRadius * Mth.sin(startAngle), z).color(argbColor).endVertex();
bufferBuilder.vertex(matrix4f, x + innerRadius * Mth.cos(endAngle), y + innerRadius * Mth.sin(endAngle), z).color(argbColor).endVertex();

float outerRadius = radius + 16;
bufferBuilder.vertex(matrix4f, x + outerRadius * Mth.cos(endAngle), y + outerRadius * Mth.sin(endAngle), blitOffset).color(argbColor).endVertex();
bufferBuilder.vertex(matrix4f, x + outerRadius * Mth.cos(startAngle), y + outerRadius * Mth.sin(startAngle), blitOffset).color(argbColor).endVertex();
bufferBuilder.vertex(matrix4f, x + outerRadius * Mth.cos(endAngle), y + outerRadius * Mth.sin(endAngle), z).color(argbColor).endVertex();
bufferBuilder.vertex(matrix4f, x + outerRadius * Mth.cos(startAngle), y + outerRadius * Mth.sin(startAngle), z).color(argbColor).endVertex();

BufferUploader.draw(bufferBuilder.end());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.elenterius.biomancy.client.gui;

import com.github.elenterius.biomancy.BiomancyMod;
import com.github.elenterius.biomancy.api.serum.Serum;
import com.github.elenterius.biomancy.api.serum.SerumContainer;
import com.github.elenterius.biomancy.client.util.GuiRenderUtil;
Expand All @@ -17,11 +18,13 @@
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -31,14 +34,16 @@

public class InjectorScreen extends Screen {

public static final ResourceLocation ICONS = BiomancyMod.createRL("textures/gui/wheel_icons.png");

public static final int CANCEL_ID = -1;
public static final int CLEAR_ID = -2;
static final float DIAGONAL_OF_ITEM = Mth.SQRT_OF_TWO * 32; // 16 * 2
static final int DURATION = 10;
private Object2IntMap<ItemStack> cachedStacks;
private int ticks;
private int refreshCacheTicks;
private InteractionHand itemHoldingHand;
private final InteractionHand itemHoldingHand;

public InjectorScreen(InteractionHand hand) {
super(ComponentUtil.translatable("biomancy.injector.wheel_menu"));
Expand Down Expand Up @@ -183,10 +188,22 @@ private void renderWheel(PoseStack poseStack, int mouseX, int mouseY, float pct)

float v = x + radius * Mth.cos(currentAngle); //polar to cartesian
float w = y + radius * Mth.sin(currentAngle);
itemRenderer.renderAndDecorateFakeItem(entry.getKey(), Mth.floor(v - 8), Mth.floor(w - 8));

ItemStack currentStack = entry.getKey();
if (currentStack.isEmpty()) {
RenderSystem.setShaderTexture(0, InjectorScreen.ICONS);
GuiComponent.blit(poseStack, Mth.floor(v - 8), Mth.floor(w - 8), 0, 0, 16, 16, 32, 16);
}
else if (currentStack.getItem() == Items.BARRIER) {
RenderSystem.setShaderTexture(0, InjectorScreen.ICONS);
GuiComponent.blit(poseStack, Mth.floor(v - 8), Mth.floor(w - 8), 16, 0, 16, 16, 32, 16);
}
else {
itemRenderer.renderAndDecorateFakeItem(entry.getKey(), Mth.floor(v - 8), Mth.floor(w - 8));
}

if (isMouseInSection) {
stack = entry.getKey();
stack = currentStack;
textAngle = currentAngle;
}

Expand Down Expand Up @@ -222,13 +239,19 @@ else if (stack.getItem() == Items.BARRIER) {
xt -= lineWidth;
}

drawItemLabel(poseStack, xt, yt, blitOffset, text, lineWidth);
}

private void drawItemLabel(PoseStack poseStack, float x, float y, int zDepth, MutableComponent text, int lineWidth) {
poseStack.pushPose();
float minX = xt - 3;
float minY = yt - font.lineHeight / 2f - 3;
float maxX = xt + lineWidth + 2;
float maxY = yt + font.lineHeight / 2f + 2;
GuiRenderUtil.fill(poseStack, minX, minY, maxX, maxY, blitOffset, ColorStyles.GENERIC_TOOLTIP.backgroundColor() & 0xE0_FFFFFF);
font.drawShadow(poseStack, text, xt, yt - font.lineHeight / 2f, ColorStyles.WHITE_ARGB);

int minX = (int) x;
int minY = (int) (y - font.lineHeight / 2f);
int maxX = minX + lineWidth;
int maxY = (int) (y + font.lineHeight / 2f);

GuiRenderUtil.fill(poseStack, minX - 3f, minY - 3f, maxX + 2f, maxY + 1.5f, zDepth, ColorStyles.GENERIC_TOOLTIP.backgroundColor() & 0xE0_FFFFFF);
font.drawShadow(poseStack, text, minX, minY, ColorStyles.WHITE_ARGB);
poseStack.popPose();
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 72844fb

Please sign in to comment.