From 39edf5bfee5413223cd941786b51f598986a1001 Mon Sep 17 00:00:00 2001 From: Aeronica Date: Sun, 3 Mar 2024 14:56:45 -0600 Subject: [PATCH] WIP: Improve Instrument and MusicVenueTool overlays. --- .../mods/mxtune/gui/TestScreen.java | 4 ++-- .../mods/mxtune/render/IOverlayItem.java | 8 +++++--- .../mods/mxtune/render/MXOverlay.java | 11 ++++++++--- .../mods/mxtune/render/OverlayInst.java | 19 ++++++++++++------- .../mods/mxtune/render/OverlayItemGui.java | 14 ++++++++++++-- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java b/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java index e6e4f751..d4bd95d5 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java +++ b/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java @@ -61,8 +61,8 @@ public void init() buttonFile.setLayout(this.width - 105, (this.height / 6 + 168) - 40, 100, 20); buttonFile.setMessage(new TranslationTextComponent("gui.mxtune.gui_file_importer.title")); addButton(buttonFile); - buttonOpen.setLayout(this.width - 55, (this.height / 6 + 168) - 20, 50, 20); - buttonOpen.setMessage(new TranslationTextComponent("gui.mxtune.button.open")); + buttonOpen.setLayout(this.width - 105, (this.height / 6 + 168) - 20, 100, 20); + buttonOpen.setMessage(new StringTextComponent("Test Misc")); addButton(buttonOpen); this.addButton(new MXButton(buttonOpen.getLeft(), buttonOpen.getBottom(), 50, 20, new TranslationTextComponent("gui.done"), diff --git a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java index 9a1db70d..371cfa13 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java @@ -17,15 +17,17 @@ default Object getToken() { return NO_TOKEN; } - default int width() { + default int baseWidth() { return 160; } - default int height() { + default int baseHeight() { return 32; } - int offset(); + int totalHeight(); + + int totalWidth(); enum Visibility { SHOW(SoundEvents.UI_TOAST_IN), diff --git a/src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java b/src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java index c3d27ce9..d1ffe769 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java @@ -23,7 +23,7 @@ public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponen } 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.blit(pPoseStack, 0, 0, 0, 0, this.baseWidth(), this.baseHeight()); pOverlayComponent.getMinecraft().font.draw(pPoseStack, TITLE_TEXT, 30.0F, 7.0F, -11534256); pOverlayComponent.getMinecraft().getItemRenderer().renderAndDecorateItem(itemStack, 8, 8); @@ -31,7 +31,12 @@ public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponen } @Override - public int offset() { - return this.width(); + public int totalHeight() { + return this.baseWidth(); + } + + @Override + public int totalWidth() { + return this.baseWidth(); } } diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java index 01d91a38..41b6659c 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java @@ -16,7 +16,7 @@ public class OverlayInst implements IOverlayItem { private ItemStack sheetMusic; private ITextComponent titleText; private ITextComponent extraText; - private int offset; + private int totalWidth; private OverlayInst() { this.itemStack = ItemStack.EMPTY; @@ -27,12 +27,17 @@ public OverlayInst(ItemStack itemStack) { this.sheetMusic = SheetMusicHelper.getIMusicFromIInstrument(itemStack); this.titleText = SheetMusicHelper.getFormattedMusicTitle(sheetMusic); this.extraText = SheetMusicHelper.getFormattedExtraText(sheetMusic); - offset = Math.max(Math.max(mc.font.width(titleText), mc.font.width(extraText)) + 40, this.width()); + this.totalWidth = Math.max(Math.max(mc.font.width(titleText), mc.font.width(extraText)) + 40, this.baseWidth()); } @Override - public int offset() { - return this.offset; + public int totalHeight() { + return this.baseHeight(); + } + + @Override + public int totalWidth() { + return this.totalWidth; } @SuppressWarnings("deprecation") @@ -44,9 +49,9 @@ public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponen } 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()); + RenderHelper.blit(pPoseStack, 0, 0, 0, 0, this.baseWidth(), this.baseHeight()); + RenderHelper.blit(pPoseStack, ((totalWidth - this.baseWidth())/2) + 5, 0, 10, 0, this.baseWidth() -10, this.baseHeight()); + RenderHelper.blit(pPoseStack, totalWidth - this.baseWidth() + 10, 0, 10, 0, this.baseWidth(), this.baseHeight()); mc.getItemRenderer().renderAndDecorateItem(itemStack, 8, 8); mc.font.draw(pPoseStack, titleText, 30.0F, 7.0F, -11534256); diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java index 73dffbbb..81378821 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java @@ -16,7 +16,7 @@ public class OverlayItemGui extends AbstractGui { private final Minecraft minecraft; - private final OverlayInstance[] visible = new OverlayInstance[5]; + private final OverlayInstance[] visible = new OverlayInstance[1]; private final Deque queued = Queues.newArrayDeque(); public OverlayItemGui(Minecraft pMinecraft) { @@ -90,6 +90,13 @@ private float getVisibility(long p_193686_1_) { return this.visibility == IOverlayItem.Visibility.HIDE ? 1.0F - f : f; } + /** + * Render an overlay instance. + * @param x screen right. + * @param y render top. + * @param pPoseStack matrix. + * @return true when rendering is done for this instance. Slide in, pause, slide out. + */ @SuppressWarnings("deprecation") public boolean render(int x, int y, MatrixStack pPoseStack) { long i = Util.getMillis(); @@ -102,8 +109,11 @@ public boolean render(int x, int y, MatrixStack pPoseStack) { this.visibleTime = i; } + float right = (float)x - (float)this.overlayItem.totalHeight(); + float center = (x * 0.5F) - this.overlayItem.totalHeight() * 0.5F; + float left = 0F; RenderSystem.pushMatrix(); - RenderSystem.translatef((float)x - (float)this.overlayItem.offset() * this.getVisibility(i), (float)(y * this.overlayItem.height()), (float)(800 + y)); + RenderSystem.translatef(left, ((float)y * 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) {