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 6, 2024
1 parent 415e416 commit 674781d
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 221 deletions.
4 changes: 1 addition & 3 deletions src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import aeronicamc.mods.mxtune.gui.widget.list.SoundFontList;
import aeronicamc.mods.mxtune.init.ModItems;
import aeronicamc.mods.mxtune.inventory.MultiInstInventory;
import aeronicamc.mods.mxtune.render.OverlayInst;
import aeronicamc.mods.mxtune.render.RenderHelper;
import aeronicamc.mods.mxtune.util.Misc;
import aeronicamc.mods.mxtune.util.SoundFontProxyManager;
import com.mojang.blaze3d.matrix.MatrixStack;
Expand Down Expand Up @@ -98,7 +96,7 @@ public void onButtonOpen()
m.setItem(0, Objects.requireNonNull(getMinecraft().player).inventory.getSelected());
m.setChanged();
ModItems.MULTI_INST.get().setPatch(itemStack, RandomUtils.nextInt(0, SoundFontProxyManager.getProxies().size()));
RenderHelper.getOverlayItemGui().addOverlay(new OverlayInst(itemStack));
// RenderHelper.getOverlayItemGui().addOverlay(new OverlayInst(itemStack));
}

public void onButtonFile()
Expand Down

This file was deleted.

47 changes: 0 additions & 47 deletions src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 4 additions & 1 deletion src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;

import static aeronicamc.mods.mxtune.render.RenderHelper.getSelectedSlot;
import static aeronicamc.mods.mxtune.render.RenderHelper.mc;

public class OverlayInst implements IOverlayItem {
Expand All @@ -16,12 +17,14 @@ public class OverlayInst implements IOverlayItem {
private ITextComponent titleText;
private ITextComponent extraText;
private int totalWidth;
private int lastSlot;

private OverlayInst() {
this.itemStack = ItemStack.EMPTY;
}

public OverlayInst(ItemStack itemStack) {
this.lastSlot = RenderHelper.getSelectedSlot();
this.itemStack = itemStack;
ItemStack sheetMusic = SheetMusicHelper.getIMusicFromIInstrument(itemStack);
this.titleText = SheetMusicHelper.getFormattedMusicTitle(sheetMusic);
Expand Down Expand Up @@ -61,6 +64,6 @@ public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponen
mc.font.draw(pPoseStack, titleText, 30.0F, 7.0F, -11534256);
mc.font.draw(pPoseStack, extraText, 30.0F, 17.0F, -11534256);

return delta - this.lastChanged >= 5000L ? Visibility.HIDE : Visibility.SHOW;
return delta - this.lastChanged >= 5000L || lastSlot != getSelectedSlot() ? Visibility.HIDE : Visibility.SHOW;
}
}
54 changes: 35 additions & 19 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,59 @@
package aeronicamc.mods.mxtune.render;

import com.google.common.collect.Queues;
import aeronicamc.mods.mxtune.items.MusicVenueToolItem;
import aeronicamc.mods.mxtune.util.IInstrument;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Deque;

;

public class OverlayItemGui extends AbstractGui {
private final Minecraft minecraft;
private final OverlayInstance<?>[] visible = new OverlayInstance[4];
private final Deque<IOverlayItem> queued = Queues.newArrayDeque();
private final OverlayInstance<?>[] visible = { null, null, null, null };

public OverlayItemGui(Minecraft pMinecraft) {
this.minecraft = pMinecraft;
}

private int lastSlot = -1;

public void render(MatrixStack pPoseStack) {
if (!this.minecraft.options.hideGui) {
OverlayInstance<?> overlayInstance;
for(int i = 0; i < this.visible.length; ++i) {
OverlayInstance<?> overlayInstance = this.visible[i];
if (overlayInstance != null && overlayInstance.render(this.minecraft.getWindow().getGuiScaledWidth(), i, pPoseStack)) {
this.visible[i] = null;
overlayInstance = null;
if (this.visible[i] == null && getMinecraft().player != null && lastSlot != RenderHelper.getSelectedSlot()) {
lastSlot = RenderHelper.getSelectedSlot();
this.visible[i] = getOverLayInstance();
}

if (this.visible[i] == null && !this.queued.isEmpty()) {
this.visible[i] = new OverlayInstance<>(this.queued.removeFirst());
if (this.visible[i] != null)
overlayInstance = this.visible[i];
if (overlayInstance != null && overlayInstance.render(this.minecraft.getWindow().getGuiScaledWidth(), i, pPoseStack)) {
this.visible[i] = null;
}
}
}
}

@Nullable
private OverlayInstance<?> getOverLayInstance() {
ItemStack stack = RenderHelper.getPlayer().inventory.getSelected();
if (stack.getItem() instanceof IInstrument)
return new OverlayInstance<>(new OverlayInst(stack));
else if (stack.getItem() instanceof MusicVenueToolItem)
return new OverlayInstance<>(new OverlayVenueTool(stack));
return null;
}

@SuppressWarnings("unchecked")
@Nullable
public <T extends IOverlayItem> T getOverlay(Class<? extends T> pIOverlayItem, Object pToken) {
Expand All @@ -47,23 +63,23 @@ public <T extends IOverlayItem> T getOverlay(Class<? extends T> pIOverlayItem, O
}
}

for(IOverlayItem overlayItem : this.queued) {
if (pIOverlayItem.isAssignableFrom(overlayItem.getClass()) && overlayItem.getToken().equals(pToken)) {
return (T)overlayItem;
}
}
// for(IOverlayItem overlayItem : this.queued) {
// if (pIOverlayItem.isAssignableFrom(overlayItem.getClass()) && overlayItem.getToken().equals(pToken)) {
// return (T)overlayItem;
// }
// }

return (T)null;
}

public void clear() {
Arrays.fill(this.visible, (Object)null);
this.queued.clear();
// this.queued.clear();
}

public void addOverlay(IOverlayItem overlayItem) {
this.queued.add(overlayItem);
}
// public void addOverlay(IOverlayItem overlayItem) {
// this.queued.add(overlayItem);
// }

public Minecraft getMinecraft() {
return this.minecraft;
Expand Down Expand Up @@ -112,7 +128,7 @@ public boolean render(int x, int y, MatrixStack pPoseStack) {
float center = (x * 0.5F) - this.overlayItem.totalHeight() * 0.5F;
float left = 0F;
RenderSystem.pushMatrix();
RenderSystem.translatef(left, ((float)y * this.overlayItem.baseHeight() - this.overlayItem.baseHeight()) + ((float)(this.overlayItem.baseHeight()) * this.getVisibility(i)), (float)(800 + y));
RenderSystem.translatef(left, ((float)0 * this.overlayItem.baseHeight() - this.overlayItem.baseHeight()) + ((float)(this.overlayItem.baseHeight()) * this.getVisibility(i)), (float)(800 + y));
IOverlayItem.Visibility overlayVisibility = this.overlayItem.render(pPoseStack, OverlayItemGui.this, i - this.visibleTime);
RenderSystem.popMatrix();
if (overlayVisibility != this.visibility) {
Expand Down
Loading

0 comments on commit 674781d

Please sign in to comment.