diff --git a/src/main/java/aeronicamc/mods/mxtune/MXTune.java b/src/main/java/aeronicamc/mods/mxtune/MXTune.java index 7f2724e5..5a38caff 100644 --- a/src/main/java/aeronicamc/mods/mxtune/MXTune.java +++ b/src/main/java/aeronicamc/mods/mxtune/MXTune.java @@ -30,6 +30,7 @@ import aeronicamc.mods.mxtune.managers.PlayManager; import aeronicamc.mods.mxtune.network.MultiPacketStringManager; import aeronicamc.mods.mxtune.network.PacketDispatcher; +import aeronicamc.mods.mxtune.render.RenderHelper; import aeronicamc.mods.mxtune.render.blockentity.MusicBlockEntityRenderer; import aeronicamc.mods.mxtune.render.entity.InfoRenderer; import aeronicamc.mods.mxtune.render.entity.MusicVenueInfoRenderer; @@ -123,6 +124,7 @@ private void clientSetup(final FMLClientSetupEvent event) RenderTypeLookup.setRenderLayer(ModBlocks.MUSIC_BLOCK.get(), RenderType.cutoutMipped()); ClientRegistry.bindTileEntityRenderer(ModBlockEntities.INV_MUSIC_BLOCK.get(), MusicBlockEntityRenderer::new); new InfoRenderer(Minecraft.getInstance().getTextureManager()); + RenderHelper.init(); } private void modLoadingComplete(FMLLoadCompleteEvent event) diff --git a/src/main/java/aeronicamc/mods/mxtune/events/ClientEvents.java b/src/main/java/aeronicamc/mods/mxtune/events/ClientEvents.java index 9a9286c5..b9c72e3f 100644 --- a/src/main/java/aeronicamc/mods/mxtune/events/ClientEvents.java +++ b/src/main/java/aeronicamc/mods/mxtune/events/ClientEvents.java @@ -4,6 +4,7 @@ import aeronicamc.mods.mxtune.managers.GroupClient; import aeronicamc.mods.mxtune.network.PacketDispatcher; import aeronicamc.mods.mxtune.network.messages.SyncRequestMessage; +import aeronicamc.mods.mxtune.render.RenderHelper; import aeronicamc.mods.mxtune.render.entity.InfoRenderer; import aeronicamc.mods.mxtune.sound.ClientAudio; import net.minecraftforge.api.distmarker.Dist; @@ -20,12 +21,14 @@ private ClientEvents() { /* NOOP */ } public static void event(ClientPlayerNetworkEvent.LoggedInEvent event) { GroupClient.clear(); + RenderHelper.getOverlayItem().clear(); PacketDispatcher.sendToServer(new SyncRequestMessage()); } @SubscribeEvent public static void event(ClientPlayerNetworkEvent.LoggedOutEvent event) { + RenderHelper.getOverlayItem().clear(); InfoRenderer.getInstance().clearInfoRendererInstances(); } @@ -34,6 +37,7 @@ public static void event(ClientPlayerNetworkEvent.RespawnEvent event) { GroupClient.clear(); ClientAudio.stopAll(); + RenderHelper.getOverlayItem().clear(); PacketDispatcher.sendToServer(new SyncRequestMessage()); } } diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java b/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java index 52480471..a0f834c1 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java +++ b/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java @@ -3,12 +3,14 @@ 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.render.RenderHelper; import aeronicamc.mods.mxtune.util.Misc; import com.mojang.blaze3d.matrix.MatrixStack; import net.minecraft.client.gui.screen.Screen; @@ -88,7 +90,7 @@ public void init() public void onButtonOpen() { - LOGGER.debug("Nothing to do :P"); + RenderHelper.getOverlayItem().addOverlay(new MXOverlay()); } public void onButtonFile() diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/toasts/MXOverlay.java b/src/main/java/aeronicamc/mods/mxtune/gui/toasts/MXOverlay.java new file mode 100644 index 00000000..c52f66ff --- /dev/null +++ b/src/main/java/aeronicamc/mods/mxtune/gui/toasts/MXOverlay.java @@ -0,0 +1,34 @@ +package aeronicamc.mods.mxtune.gui.toasts; + +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; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.TranslationTextComponent; + +public class MXOverlay implements IOverlayItem { + private static final ITextComponent TITLE_TEXT = new TranslationTextComponent("itemGroup.mxtune").withStyle(TextFormatting.YELLOW); + private final ItemStack itemStack = ModItems.getMultiInst(27); + private long lastChanged; + private boolean changed; + + @SuppressWarnings("deprecation") + @Override + public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponent, long delta) { + if (this.changed) { + this.lastChanged = delta; + this.changed = false; + } + pOverlayComponent.getMinecraft().getTextureManager().bind(TEXTURE); + RenderSystem.color3f(1.0F, 1.0F, 1.0F); + pOverlayComponent.blit(pPoseStack, 0, 0, 0, 0, this.width(), this.height()); + pOverlayComponent.getMinecraft().font.draw(pPoseStack, TITLE_TEXT, 30.0F, 7.0F, -11534256); + + pOverlayComponent.getMinecraft().getItemRenderer().renderAndDecorateItem(itemStack, 8, 8); + return delta - this.lastChanged >= 5000L ? IOverlayItem.Visibility.HIDE : IOverlayItem.Visibility.SHOW; + } +} diff --git a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java new file mode 100644 index 00000000..96732c86 --- /dev/null +++ b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java @@ -0,0 +1,42 @@ +package aeronicamc.mods.mxtune.render; + +import com.mojang.blaze3d.matrix.MatrixStack; +import net.minecraft.client.audio.SimpleSound; +import net.minecraft.client.audio.SoundHandler; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.SoundEvents; + +public interface IOverlayItem { + ResourceLocation TEXTURE = new ResourceLocation("textures/gui/toasts.png"); + Object NO_TOKEN = new Object(); + + IOverlayItem.Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponent, long delta); + + default Object getToken() { + return NO_TOKEN; + } + + default int width() { + return 160; + } + + default int height() { + return 32; + } + + enum Visibility { + SHOW(SoundEvents.UI_TOAST_IN), + HIDE(SoundEvents.UI_TOAST_OUT); + + private final SoundEvent soundEvent; + + private Visibility(SoundEvent pSoundEvent) { + this.soundEvent = pSoundEvent; + } + + public void playSound(SoundHandler pHandler) { + pHandler.play(SimpleSound.forUI(this.soundEvent, 1.0F, 1.0F)); + } + } +} \ No newline at end of file diff --git a/src/main/java/aeronicamc/mods/mxtune/render/InstrumentOverlayRenderer.java b/src/main/java/aeronicamc/mods/mxtune/render/InstrumentOverlayRenderer.java index 307dd27f..3533b2b1 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/InstrumentOverlayRenderer.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/InstrumentOverlayRenderer.java @@ -6,6 +6,7 @@ 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; @@ -30,7 +31,7 @@ public static void render(ItemStack itemStack, RenderGameOverlayEvent.Post event final int offset = Math.max(Math.max(mc.font.width(titleText), mc.font.width(isPlacardInHotBar() ? infoText : extraText)) + 40, RenderHelper.WIDTH); final MatrixStack pPoseStack = event.getMatrixStack(); - mc.getTextureManager().bind(RenderHelper.TEXTURE); + mc.getTextureManager().bind(IToast.TEXTURE); RenderSystem.color3f(1.0F, 1.0F, 1.0F); RenderHelper.blit(pPoseStack, 0, 0, 0, 0, RenderHelper.WIDTH, RenderHelper.HEIGHT); diff --git a/src/main/java/aeronicamc/mods/mxtune/render/MusicVenueToolOverlayRenderer.java b/src/main/java/aeronicamc/mods/mxtune/render/MusicVenueToolOverlayRenderer.java index 6abd3acb..2f6108a3 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/MusicVenueToolOverlayRenderer.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/MusicVenueToolOverlayRenderer.java @@ -8,6 +8,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.entity.player.ClientPlayerEntity; +import net.minecraft.client.gui.toasts.IToast; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; @@ -56,7 +57,7 @@ else if (raytraceresult instanceof EntityRayTraceResult) else blockName = new StringTextComponent("---").withStyle(TextFormatting.AQUA); - mc.getTextureManager().bind(RenderHelper.TEXTURE); + mc.getTextureManager().bind(IToast.TEXTURE); RenderSystem.color3f(1.0F, 1.0F, 1.0F); RenderHelper.blit(pPoseStack, 0, 0, 0, 0, RenderHelper.WIDTH, RenderHelper.HEIGHT); RenderHelper.blit(pPoseStack, ((offset - RenderHelper.WIDTH)/2) + 5, 0, 10, 0, RenderHelper.WIDTH -10, RenderHelper.HEIGHT); diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java new file mode 100644 index 00000000..71e82df5 --- /dev/null +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java @@ -0,0 +1,118 @@ +package aeronicamc.mods.mxtune.render; + +import com.google.common.collect.Queues; +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.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[5]; + private final Deque queued = Queues.newArrayDeque(); + + public OverlayItemGui(Minecraft pMinecraft) { + this.minecraft = pMinecraft; + } + + public void render(MatrixStack pPoseStack) { + if (!this.minecraft.options.hideGui) { + 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; + } + + if (this.visible[i] == null && !this.queued.isEmpty()) { + this.visible[i] = new OverlayInstance<>(this.queued.removeFirst()); + } + } + + } + } + + @SuppressWarnings("unchecked") + @Nullable + public T getOverlay(Class pIOverlayItem, Object pToken) { + for(OverlayInstance overlayInstance : this.visible) { + if (overlayInstance != null && pIOverlayItem.isAssignableFrom(overlayInstance.getOverlayItem().getClass()) && overlayInstance.getOverlayItem().getToken().equals(pToken)) { + return (T)overlayInstance.getOverlayItem(); + } + } + + 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(); + } + + public void addOverlay(IOverlayItem overlayItem) { + this.queued.add(overlayItem); + } + + public Minecraft getMinecraft() { + return this.minecraft; + } + + class OverlayInstance { + private final T overlayItem; + private long animationTime = -1L; + private long visibleTime = -1L; + private IOverlayItem.Visibility visibility = IOverlayItem.Visibility.SHOW; + + private OverlayInstance(T pOverlayItem) { + this.overlayItem = pOverlayItem; + } + + public T getOverlayItem() { + return this.overlayItem; + } + + private float getVisibility(long p_193686_1_) { + float f = MathHelper.clamp((float)(p_193686_1_ - this.animationTime) / 600.0F, 0.0F, 1.0F); + f = f * f; + return this.visibility == IOverlayItem.Visibility.HIDE ? 1.0F - f : f; + } + + @SuppressWarnings("deprecation") + public boolean render(int x, int y, MatrixStack pPoseStack) { + long i = Util.getMillis(); + if (this.animationTime == -1L) { + this.animationTime = i; + this.visibility.playSound(OverlayItemGui.this.minecraft.getSoundManager()); + } + + if (this.visibility == IOverlayItem.Visibility.SHOW && i - this.animationTime <= 600L) { + this.visibleTime = i; + } + + 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.popMatrix(); + if (itoast$visibility != this.visibility) { + this.animationTime = i - (long)((int)((1.0F - this.getVisibility(i)) * 600.0F)); + this.visibility = itoast$visibility; + this.visibility.playSound(OverlayItemGui.this.minecraft.getSoundManager()); + } + + return this.visibility == IOverlayItem.Visibility.HIDE && i - this.animationTime > 600L; + } + } +} \ No newline at end of file diff --git a/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java b/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java index c530efec..a1deed40 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java @@ -32,6 +32,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.DrawHighlightEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -139,6 +140,13 @@ public static void event(RenderGameOverlayEvent.Post event) MusicVenueToolOverlayRenderer.render(getPlayer(), itemStack, event); } + @SubscribeEvent + public static void event(TickEvent.RenderTickEvent event) { + if (TickEvent.Phase.END.equals(event.phase)) { + RenderHelper.getOverlayItem().render(new MatrixStack()); + } + } + static void renderGroupStatusPlacard(MatrixStack pMatrixStack, IRenderTypeBuffer.Impl pBuffer, ActiveRenderInfo pActiveRenderInfo, float pPartialTicks, ClippingHelper pClippingHelper) { if (GroupClient.hasGroups()) diff --git a/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java b/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java index 0575f00a..cbc0c971 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java @@ -11,7 +11,6 @@ import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.debug.DebugRenderer; import net.minecraft.entity.Entity; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.ISelectionContext; @@ -28,10 +27,18 @@ @SuppressWarnings("unused") public class RenderHelper { - static final ResourceLocation TEXTURE = new ResourceLocation("textures/gui/toasts.png"); static final int WIDTH = 160; static final int HEIGHT = 32; static final Minecraft mc = Minecraft.getInstance(); + private static OverlayItemGui overlayItem; + + public static void init() { + overlayItem = new OverlayItemGui(mc); + } + + public static OverlayItemGui getOverlayItem() { + return overlayItem; + } static ClientPlayerEntity getPlayer() { return Objects.requireNonNull(mc.player);