Skip to content

Commit

Permalink
WIP: Improve Instrument and MusicVenueTool overlays.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeronica committed Mar 15, 2024
1 parent acb96b2 commit 57c4bee
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

public class MXTuneConfig
{
public static final Object SYNC = new Object();
public static final int SHEET_MUSIC_MAX_DAYS = 999999;
private MXTuneConfig() { /* NOP */ }

Expand Down
24 changes: 22 additions & 2 deletions src/main/java/aeronicamc/mods/mxtune/gui/OverlayManagerScreen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package aeronicamc.mods.mxtune.gui;

import aeronicamc.mods.mxtune.config.MXTuneConfig;
import aeronicamc.mods.mxtune.gui.widget.MXButton;
import aeronicamc.mods.mxtune.gui.widget.MXSlideButton;
import aeronicamc.mods.mxtune.render.*;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.gui.screen.Screen;
Expand All @@ -23,8 +25,25 @@ public OverlayManagerScreen(Screen parent) {
@Override
protected void init() {
super.init();
this.addButton(new MXButton(((width/2) - 25), height-100, 50, 20, new TranslationTextComponent("gui.done"),
done -> onClose()));
MXButton doneButton = new MXButton(((width/2) - 25), height-100, 50, 20, new TranslationTextComponent("gui.done"),
done -> onClose());
addButton(doneButton);
MXSlideButton toolPosSlider = new MXSlideButton((p, v)->applyToolPos(v));
toolPosSlider.setLayout( doneButton.getRight() + 4, height-100, 150, 20);
toolPosSlider.setValue(MXTuneConfig.getVenueToolOverlayPercent()/100D);
toolPosSlider.setMessage(new StringTextComponent("Venue Tool VPos"));
addButton(toolPosSlider);
}

private int count;
private double lastCount;
private void applyToolPos(double value) {
synchronized (MXTuneConfig.SYNC) {
if ((100 * value) != lastCount) {
count = ((int) (100 * value));
lastCount = (100 * value);
}
}
}

@Override
Expand All @@ -35,6 +54,7 @@ public boolean isPauseScreen()

@Override
public void onClose() {
MXTuneConfig.CLIENT.venueToolOverlayYPercent.set(count);
getMinecraft().setScreen(parent);
}

Expand Down
107 changes: 106 additions & 1 deletion src/main/java/aeronicamc/mods/mxtune/gui/widget/MXSlideButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,125 @@

import net.minecraft.client.gui.widget.AbstractSlider;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;

public class MXSlideButton extends AbstractSlider {
import java.util.ArrayList;
import java.util.List;

public class MXSlideButton extends AbstractSlider implements ILayout, IHooverText {
protected int padding = 0;
private final List<ITextComponent> hooverTexts = new ArrayList<>();
private boolean hooverTextsOverride;
private IPressable onApply;
private ITextComponent sliderText;

public MXSlideButton(IPressable onApply) {
super(0,0,0,50, StringTextComponent.EMPTY, 0F);
this.onApply = onApply;
sliderText = StringTextComponent.EMPTY;
}

public MXSlideButton(int pX, int pY, int pWidth, int pHeight, ITextComponent pMessage, double pValue) {
super(pX, pY, pWidth, pHeight, pMessage, pValue);
}

@Override
public void setMessage(ITextComponent pMessage) {
sliderText = pMessage;
super.setMessage(pMessage);
this.updateMessage();
}

@Override
protected void updateMessage() {
ITextComponent itextcomponent = new StringTextComponent((int)(this.value * 100.0D) + "%");
super.setMessage((new StringTextComponent(sliderText.getString()).append(": ").append(itextcomponent)));
}

public double getValue() {
return this.value;
}

public void setValue(double value) {
this.value = value;
}

@Override
protected void applyValue() {
this.onApply.onPress(this, this.value);
}

@Override
public void addHooverText(boolean clearAll, ITextComponent hooverText) {
if (clearAll) hooverTexts.clear();
hooverTexts.add(hooverText);
}

@Override
public boolean isMouseOverWidget(double mouseX, double mouseY) {
return this.visible && mouseX >= this.x && mouseY >= this.y && mouseX < (this.x + this.width) && mouseY < (this.y + this.height);
}

@Override
public List<ITextComponent> getHooverTexts() {
return this.hooverTexts;
}

@Override
public boolean isHooverTextOverride() {
return this.hooverTextsOverride;
}

@Override
public void setHooverTextOverride(boolean override) {
this.hooverTextsOverride = override;
}

@Override
public void setPosition(int pX, int pY) {
this.x = pX;
this.y = pY;
}

@Override
public void setLayout(int pX, int pY, int pWidth, int pHeight) {
this.x = pX;
this.y = pY;
this.width = pWidth;
this.height = pHeight;
}

@Override
public int getLeft() {
return this.x;
}

@Override
public int getTop() {
return this.y;
}

@Override
public int getRight() {
return this.x + this.width + padding;
}

@Override
public int getBottom() {
return this.y + this.height + padding;
}

@Override
public int getPadding() {
return padding;
}

@Override
public void setPadding(int padding) {
this.padding = padding;
}

public interface IPressable {
void onPress(MXSlideButton onPress, double value);
}
}
2 changes: 2 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ default Object getToken() {

ItemStack getItemStack();

boolean isManagedPosition();

default int baseWidth() {
return 160;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public ItemStack getItemStack() {
return itemStack;
}

@Override
public boolean isManagedPosition() {
return this.managePosition;
}

@Override
public int totalHeight() {
return this.baseHeight();
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,25 @@ else if (stack.getItem() instanceof MusicVenueToolItem)
}

public IOverlayItem.Position getPosition(IOverlayItem overlayItem) {
if (overlayItem.getItemStack().getItem() instanceof IInstrument)
return MXTuneConfig.getInstrumentOverlayPosition();
else if (overlayItem.getItemStack().getItem() instanceof MusicVenueToolItem)
return MXTuneConfig.getVenueToolOverlayPosition();
else
return IOverlayItem.Position.LEFT;
synchronized (MXTuneConfig.SYNC) {
if (overlayItem.getItemStack().getItem() instanceof IInstrument)
return MXTuneConfig.getInstrumentOverlayPosition();
else if (overlayItem.getItemStack().getItem() instanceof MusicVenueToolItem)
return MXTuneConfig.getVenueToolOverlayPosition();
else
return IOverlayItem.Position.LEFT;
}
}

public float getPercent(IOverlayItem overlayItem) {
if (overlayItem.getItemStack().getItem() instanceof IInstrument)
return MXTuneConfig.getInstrumentOverlayPercent();
else if (overlayItem.getItemStack().getItem() instanceof MusicVenueToolItem)
return MXTuneConfig.getVenueToolOverlayPercent();
else
return 0F;
synchronized (MXTuneConfig.SYNC) {
if (overlayItem.getItemStack().getItem() instanceof IInstrument)
return MXTuneConfig.getInstrumentOverlayPercent();
else if (overlayItem.getItemStack().getItem() instanceof MusicVenueToolItem)
return MXTuneConfig.getVenueToolOverlayPercent();
else
return 0F;
}
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,32 @@ public class OverlayVenueTool implements IOverlayItem {
private boolean changed;
private int totalWidth;
private final int lastSlot;
private final boolean managePosition;
private final boolean managedPosition;

public OverlayVenueTool(ItemStack itemStack) {
this.lastSlot = RenderHelper.getSelectedSlot();
this.itemStack = itemStack;
this.totalWidth = this.baseWidth();
this.managePosition = false;
this.managedPosition = false;
}

public OverlayVenueTool() {
this.lastSlot = -1;
this.itemStack = new ItemStack(ModItems.MUSIC_VENUE_TOOL.get(), 1);
this.totalWidth = this.baseWidth();
this.managePosition = true;
this.managedPosition = true;
}

@Override
public ItemStack getItemStack() {
return itemStack;
}

@Override
public boolean isManagedPosition() {
return this.managedPosition;
}

@Override
public int totalHeight() {
return this.baseHeight();
Expand Down Expand Up @@ -108,7 +113,7 @@ else if (raytraceresult instanceof EntityRayTraceResult)
mc.font.draw(pPoseStack, blockName, 30.0F, 17.0F, -11534256);
mc.getItemRenderer().renderAndDecorateItem(itemStack, 8, 8);

if (managePosition)
if (managedPosition)
return delta - this.lastChanged >= 800L ? Visibility.HIDE : Visibility.SHOW;
else
return lastSlot != getSelectedSlot() || isNotToolItem() ? Visibility.HIDE : Visibility.SHOW;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import aeronicamc.mods.mxtune.Reference;
import aeronicamc.mods.mxtune.entity.MusicVenueInfoEntity;
import aeronicamc.mods.mxtune.gui.OverlayManagerScreen;
import aeronicamc.mods.mxtune.init.ModBlocks;
import aeronicamc.mods.mxtune.init.ModItems;
import aeronicamc.mods.mxtune.items.MusicVenueInfoItem;
Expand Down Expand Up @@ -36,7 +37,10 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static aeronicamc.mods.mxtune.render.ModRenderType.*;
import static aeronicamc.mods.mxtune.render.RenderHelper.getPlayer;
Expand Down Expand Up @@ -130,6 +134,21 @@ public static void event(DrawHighlightEvent.HighlightEntity event)
RenderHelper.renderEdges(matrixStack, vertexBuilder2, entityRayTraceResult.getEntity().getBoundingBox().inflate(0.001D), camera.x(), camera.y(), camera.z(), 1.0F, 0.0F, 1.0F, 0.4F);
}

private static final Set<RenderGameOverlayEvent.ElementType> NO_RENDER_ELEMENTS = new HashSet<>(Arrays.asList(
RenderGameOverlayEvent.ElementType.HOTBAR, RenderGameOverlayEvent.ElementType.FOOD,
RenderGameOverlayEvent.ElementType.HEALTH, RenderGameOverlayEvent.ElementType.ARMOR,
RenderGameOverlayEvent.ElementType.HELMET, RenderGameOverlayEvent.ElementType.EXPERIENCE)
);
@SubscribeEvent
public static void event(RenderGameOverlayEvent.Pre event)
{
if (event.isCancelable() && mc.screen instanceof OverlayManagerScreen)
{
if (NO_RENDER_ELEMENTS.contains(event.getType()))
event.setCanceled(true);
}
}

@SubscribeEvent
public static void event(RenderGameOverlayEvent.Post event)
{
Expand Down

0 comments on commit 57c4bee

Please sign in to comment.