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 Feb 27, 2024
1 parent 044530c commit abec3f7
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 11 deletions.
12 changes: 10 additions & 2 deletions src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
import aeronicamc.mods.mxtune.Reference;
import aeronicamc.mods.mxtune.gui.mml.GuiFileImporter;
import aeronicamc.mods.mxtune.gui.mml.GuiMXT;
import aeronicamc.mods.mxtune.gui.toasts.MXOverlay;
import aeronicamc.mods.mxtune.gui.toasts.MXToast;
import aeronicamc.mods.mxtune.gui.widget.MXButton;
import aeronicamc.mods.mxtune.gui.widget.MXLabel;
import aeronicamc.mods.mxtune.gui.widget.MXTextFieldWidget;
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;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import org.apache.commons.lang3.RandomUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -90,7 +93,12 @@ public void init()

public void onButtonOpen()
{
RenderHelper.getOverlayItem().addOverlay(new MXOverlay());
ItemStack itemStack = new ItemStack(ModItems.getMultiInst(1).getItem(),1);
MultiInstInventory m = new MultiInstInventory(itemStack);
m.setItem(0, Objects.requireNonNull(getMinecraft().player).inventory.getSelected());
m.setChanged();
ModItems.MULTI_INST.get().setPatch(itemStack, RandomUtils.nextInt(0, SoundFontProxyManager.getProxies().size()));
RenderHelper.getOverlayItem().addOverlay(new OverlayInst(itemStack));
}

public void onButtonFile()
Expand Down
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 @@ -25,6 +25,8 @@ default int height() {
return 32;
}

int offset();

enum Visibility {
SHOW(SoundEvents.UI_TOAST_IN),
HIDE(SoundEvents.UI_TOAST_OUT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package aeronicamc.mods.mxtune.gui.toasts;
package aeronicamc.mods.mxtune.render;

import aeronicamc.mods.mxtune.init.ModItems;
import aeronicamc.mods.mxtune.render.IOverlayItem;
import aeronicamc.mods.mxtune.render.OverlayItemGui;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -31,4 +29,9 @@ public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponen
pOverlayComponent.getMinecraft().getItemRenderer().renderAndDecorateItem(itemStack, 8, 8);
return delta - this.lastChanged >= 5000L ? IOverlayItem.Visibility.HIDE : IOverlayItem.Visibility.SHOW;
}

@Override
public int offset() {
return this.width();
}
}
80 changes: 80 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package aeronicamc.mods.mxtune.render;

import aeronicamc.mods.mxtune.init.ModItems;
import aeronicamc.mods.mxtune.sound.ClientAudio;
import aeronicamc.mods.mxtune.util.SheetMusicHelper;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.toasts.IToast;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;

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

public class OverlayInst implements IOverlayItem {
private static final ItemStack PLACARD_ITEM = new ItemStack(ModItems.PLACARD_ITEM.get());
private final ItemStack itemStack;
private long lastChanged;
private boolean changed;

private ItemStack sheetMusic;
private ITextComponent titleText;
private ITextComponent extraText;
private ITextComponent infoText;


private int offset;

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

public OverlayInst(ItemStack itemStack) {
this.itemStack = itemStack;
this.sheetMusic = SheetMusicHelper.getIMusicFromIInstrument(itemStack);
this.titleText = SheetMusicHelper.getFormattedMusicTitle(sheetMusic);
this.extraText = SheetMusicHelper.getFormattedExtraText(sheetMusic);
this.infoText = new StringTextComponent("").append(SheetMusicHelper.getFormattedMusicDuration(sheetMusic))
.append(String.format(" %s %s", mc.getSoundManager().getDebugString(), ClientAudio.getDebugString())).withStyle(TextFormatting.WHITE);
offset = Math.max(Math.max(mc.font.width(titleText), mc.font.width(isPlacardInHotBar() ? infoText : extraText)) + 40, this.width());
}

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

@SuppressWarnings("deprecation")
@Override
public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponent, long delta) {
if (this.changed) {
this.lastChanged = delta;
this.changed = false;
}
mc.getTextureManager().bind(IToast.TEXTURE);
RenderSystem.color3f(1.0F, 1.0F, 1.0F);
RenderHelper.blit(pPoseStack, 0, 0, 0, 0, this.width(), this.height());
RenderHelper.blit(pPoseStack, ((offset - this.width())/2) + 5, 0, 10, 0, this.width() -10, this.height());
RenderHelper.blit(pPoseStack, offset - this.width() + 10, 0, 10, 0, this.width(), this.height());
mc.getItemRenderer().renderAndDecorateItem(itemStack, 8, 8);

mc.font.draw(pPoseStack, titleText, 30.0F, 7.0F, -11534256);
mc.font.draw(pPoseStack, isPlacardInHotBar() ? infoText : extraText, 30.0F, 17.0F, -11534256);

if (isPlacardInHotBar()) {
final int[] posY = { 0 };
posY[0] = (25);
ClientAudio.getAudioData()
.forEach(audioData -> mc.font.drawShadow(pPoseStack, audioData.getInfo(), 5, posY[0] += 10, -11534256));
}

return delta - this.lastChanged >= 5000L ? Visibility.HIDE : Visibility.SHOW;
}
private static boolean isPlacardInHotBar() {
int slot = getPlayer().inventory.findSlotMatchingItem(PLACARD_ITEM);
return slot >= 0 && slot < 9;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ public boolean render(int x, int y, MatrixStack pPoseStack) {
}

RenderSystem.pushMatrix();
RenderSystem.translatef((float)x - (float)this.overlayItem.width() * this.getVisibility(i), (float)(y * this.overlayItem.height()), (float)(800 + y));
IOverlayItem.Visibility itoast$visibility = this.overlayItem.render(pPoseStack, OverlayItemGui.this, i - this.visibleTime);
RenderSystem.translatef((float)x - (float)this.overlayItem.offset() * this.getVisibility(i), (float)(y * this.overlayItem.height()), (float)(800 + y));
IOverlayItem.Visibility overlayVisibility = this.overlayItem.render(pPoseStack, OverlayItemGui.this, i - this.visibleTime);
RenderSystem.popMatrix();
if (itoast$visibility != this.visibility) {
if (overlayVisibility != this.visibility) {
this.animationTime = i - (long)((int)((1.0F - this.getVisibility(i)) * 600.0F));
this.visibility = itoast$visibility;
this.visibility = overlayVisibility;
this.visibility.playSound(OverlayItemGui.this.minecraft.getSoundManager());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/aeronicamc/mods/mxtune/util/IInstrument.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public interface IInstrument
{
static final String PATCH = "MXTunePatch";
static final String KEY_AUTO_SELECT = "MXTuneAutoSelect";
String PATCH = "MXTunePatch";
String KEY_AUTO_SELECT = "MXTuneAutoSelect";
int getPatch(ItemStack itemStack);
void setPatch(ItemStack itemStack, int patch);
boolean getAutoSelect(ItemStack itemStack);
Expand Down

0 comments on commit abec3f7

Please sign in to comment.