diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java b/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java index a0f834c1..e6e4f751 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java +++ b/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java @@ -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; @@ -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() diff --git a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java index 96732c86..9a1db70d 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java @@ -25,6 +25,8 @@ default int height() { return 32; } + int offset(); + enum Visibility { SHOW(SoundEvents.UI_TOAST_IN), HIDE(SoundEvents.UI_TOAST_OUT); diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/toasts/MXOverlay.java b/src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java similarity index 90% rename from src/main/java/aeronicamc/mods/mxtune/gui/toasts/MXOverlay.java rename to src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java index c52f66ff..c3d27ce9 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/toasts/MXOverlay.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java @@ -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; @@ -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(); + } } diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java new file mode 100644 index 00000000..fbd3d314 --- /dev/null +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java @@ -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; + } +} diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java index 71e82df5..73dffbbb 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java @@ -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()); } diff --git a/src/main/java/aeronicamc/mods/mxtune/util/IInstrument.java b/src/main/java/aeronicamc/mods/mxtune/util/IInstrument.java index 9b149ca2..e19e2a71 100644 --- a/src/main/java/aeronicamc/mods/mxtune/util/IInstrument.java +++ b/src/main/java/aeronicamc/mods/mxtune/util/IInstrument.java @@ -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);