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 14, 2024
1 parent dcd24c9 commit acb96b2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
22 changes: 6 additions & 16 deletions src/main/java/aeronicamc/mods/mxtune/gui/OverlayManagerScreen.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package aeronicamc.mods.mxtune.gui;

import aeronicamc.mods.mxtune.gui.widget.MXButton;
import aeronicamc.mods.mxtune.init.ModItems;
import aeronicamc.mods.mxtune.items.MusicVenueToolItem;
import aeronicamc.mods.mxtune.render.*;
import aeronicamc.mods.mxtune.util.IInstrument;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;

Expand All @@ -17,8 +13,6 @@ public class OverlayManagerScreen extends MXScreen {

private final OverlayItemGui overlayItemGui;
private final OverlayInstance<?>[] visible = { null, null };
private ItemStack selectedOverlayItem = ItemStack.EMPTY;
private ItemStack lastSelectedOverlayItem = ItemStack.EMPTY;
private final Screen parent;
public OverlayManagerScreen(Screen parent) {
super(StringTextComponent.EMPTY);
Expand All @@ -31,7 +25,6 @@ protected void init() {
super.init();
this.addButton(new MXButton(((width/2) - 25), height-100, 50, 20, new TranslationTextComponent("gui.done"),
done -> onClose()));
selectedOverlayItem = new ItemStack(ModItems.MULTI_INST.get());
}

@Override
Expand Down Expand Up @@ -66,12 +59,11 @@ public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) {
}

@Nullable
private OverlayInstance<?> getOverLayInstance() {
ItemStack stack = selectedOverlayItem;
if (stack.getItem() instanceof IInstrument)
private OverlayInstance<?> getOverLayInstance(int idx) {
if (0 == idx)
return new OverlayInstance<>(overlayItemGui, new OverlayInst());
else if (stack.getItem() instanceof MusicVenueToolItem)
return new OverlayInstance<>(overlayItemGui, new OverlayVenueTool(stack));
else if (1 == idx)
return new OverlayInstance<>(overlayItemGui, new OverlayVenueTool());
return null;
}

Expand All @@ -80,16 +72,14 @@ private void render(MatrixStack pPoseStack) {
OverlayInstance<?> overlayInstance;
for(int instIndex = 0; instIndex < this.visible.length; ++instIndex) {
overlayInstance = null;
if (this.visible[instIndex] == null && getMinecraft().player != null & !selectedOverlayItem.equals(lastSelectedOverlayItem, true)) {
this.visible[instIndex] = getOverLayInstance();
lastSelectedOverlayItem = selectedOverlayItem;
if (this.visible[instIndex] == null && getMinecraft().player != null) {
this.visible[instIndex] = getOverLayInstance(instIndex);
}

if (this.visible[instIndex] != null)
overlayInstance = this.visible[instIndex];
if (overlayInstance != null && overlayInstance.render(getMinecraft().getWindow().getGuiScaledWidth(), getMinecraft().getWindow().getGuiScaledHeight(), instIndex, pPoseStack)) {
this.visible[instIndex] = null;
lastSelectedOverlayItem = ItemStack.EMPTY;
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/gui/widget/MXSlideButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package aeronicamc.mods.mxtune.gui.widget;

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

public class MXSlideButton extends AbstractSlider {

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

@Override
protected void updateMessage() {

}

@Override
protected void applyValue() {

}
}
4 changes: 2 additions & 2 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class OverlayInst implements IOverlayItem {
private final ITextComponent extraText;
private final int totalWidth;
private final int lastSlot;
private boolean managePosition;
private final boolean managePosition;

public OverlayInst(ItemStack itemStack) {
this.lastSlot = RenderHelper.getSelectedSlot();
Expand Down Expand Up @@ -77,7 +77,7 @@ public Visibility render(MatrixStack pPoseStack, long delta) {
mc.font.draw(pPoseStack, extraText, 30.0F, 17.0F, -11534256);

if (managePosition)
return delta - this.lastChanged >= 5000L ? Visibility.HIDE : Visibility.SHOW;
return delta - this.lastChanged >= 1200L ? Visibility.HIDE : Visibility.SHOW;
else
return delta - this.lastChanged >= 5000L || lastSlot != getSelectedSlot() || isNotInstrumentItem() ? Visibility.HIDE : Visibility.SHOW;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import aeronicamc.mods.mxtune.caps.venues.MusicVenueHelper;
import aeronicamc.mods.mxtune.caps.venues.ToolManager;
import aeronicamc.mods.mxtune.caps.venues.ToolState;
import aeronicamc.mods.mxtune.init.ModItems;
import aeronicamc.mods.mxtune.items.MusicVenueToolItem;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
Expand All @@ -22,13 +23,24 @@

public class OverlayVenueTool implements IOverlayItem {
private final ItemStack itemStack;
private long lastChanged;
private boolean changed;
private int totalWidth;
private final int lastSlot;
private final boolean managePosition;

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

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

@Override
Expand All @@ -53,6 +65,10 @@ private boolean isNotToolItem() {
@SuppressWarnings("deprecation")
@Override
public Visibility render(MatrixStack pPoseStack, long delta) {
if (this.changed) {
this.lastChanged = delta;
this.changed = false;
}
final RayTraceResult raytraceresult = mc.hitResult;
final Vector3d vector3d;
final EntityVenueState evs = MusicVenueHelper.getEntityVenueState(getPlayer().level, getPlayer().getId());
Expand Down Expand Up @@ -92,6 +108,9 @@ else if (raytraceresult instanceof EntityRayTraceResult)
mc.font.draw(pPoseStack, blockName, 30.0F, 17.0F, -11534256);
mc.getItemRenderer().renderAndDecorateItem(itemStack, 8, 8);

return lastSlot != getSelectedSlot() || isNotToolItem() ? Visibility.HIDE : Visibility.SHOW;
if (managePosition)
return delta - this.lastChanged >= 800L ? Visibility.HIDE : Visibility.SHOW;
else
return lastSlot != getSelectedSlot() || isNotToolItem() ? Visibility.HIDE : Visibility.SHOW;
}
}

0 comments on commit acb96b2

Please sign in to comment.