diff --git a/src/generated/resources/assets/mxtune/lang/en_us.json b/src/generated/resources/assets/mxtune/lang/en_us.json index 7abd53a2..6ef284ed 100644 --- a/src/generated/resources/assets/mxtune/lang/en_us.json +++ b/src/generated/resources/assets/mxtune/lang/en_us.json @@ -10,10 +10,14 @@ "commands.mxtune.music.dump": "Wrote %s records", "commands.mxtune.music.load": "Read %s records", "config.mxtune.client.double_click_time_ms": "Double-click time in milliseconds for GUI widgets", + "config.mxtune.client.instrument_overlay_percent": "Instrument Overlay Percent down screen", + "config.mxtune.client.instrument_overlay_position": "Instrument Overlay Position", "config.mxtune.client.mml_Link": "MML Site Link", + "config.mxtune.client.venue_tool_overlay_percent": "Venue Tool Overlay Percent down screen", + "config.mxtune.client.venue_tool_overlay_position": "Venue Tool Overlay Position", "config.mxtune.server.listener_range": "Listener Range", "config.mxtune.server.sheet_music_expires": "Sheet Music Expires", - "config.mxtune.server.sheet_music_life_in_days": "Sheet Music Life in Days.", + "config.mxtune.server.sheet_music_life_in_days": "Sheet Music Life in Days", "container.mxtune.block_music.more": "%s More", "entity.mxtune.music_source": "[MusicSource]", "entity.mxtune.music_venue_info": "Music Venue Info Panel", diff --git a/src/main/java/aeronicamc/mods/mxtune/config/MXTuneConfig.java b/src/main/java/aeronicamc/mods/mxtune/config/MXTuneConfig.java index 3d203057..1403458e 100644 --- a/src/main/java/aeronicamc/mods/mxtune/config/MXTuneConfig.java +++ b/src/main/java/aeronicamc/mods/mxtune/config/MXTuneConfig.java @@ -17,6 +17,7 @@ package aeronicamc.mods.mxtune.config; +import aeronicamc.mods.mxtune.render.IOverlayItem; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; import net.minecraftforge.common.ForgeConfigSpec.IntValue; @@ -34,6 +35,10 @@ public static class Client { public final ConfigValue doubleClickTime; public final ConfigValue site; + public final ConfigValue instrumentOverlayPosition; + public final ConfigValue instrumentOverlayPercent; + public final ConfigValue venueToolOverlayPosition; + public final ConfigValue venueToolOverlayPercent; public Client(final ForgeConfigSpec.Builder builder) { @@ -50,6 +55,26 @@ public Client(final ForgeConfigSpec.Builder builder) .translation("config.mxtune.client.mml_Link") .define("site", "https://mabibeats.com/"); + instrumentOverlayPosition = builder + .comment("Instrument Overlay Position") + .translation("config.mxtune.client.instrument_overlay_position") + .defineEnum("instrumentOverlayPosition", IOverlayItem.Position.LEFT); + + instrumentOverlayPercent = builder + .comment("Instrument Overlay Percent down screen") + .translation("config.mxtune.client.instrument_overlay_percent") + .defineInRange("instrumentOverlayPercent", 0, 0, 100); + + venueToolOverlayPosition = builder + .comment("Venue Tool Overlay Position") + .translation("config.mxtune.client.venue_tool_overlay_position") + .defineEnum("venueToolOverlayPosition", IOverlayItem.Position.CENTER); + + venueToolOverlayPercent = builder + .comment("Venue Tool Overlay Percent down screen") + .translation("config.mxtune.client.venue_tool_overlay_percent") + .defineInRange("venueToolOverlayPercent", 70, 0, 100); + builder.pop(); } } @@ -95,6 +120,14 @@ public Server(final ForgeConfigSpec.Builder builder) public static String getMmlLink() { return CLIENT.site.get(); } + public static IOverlayItem.Position getInstrumentOverlayPosition() { return CLIENT.instrumentOverlayPosition.get(); } + + public static int getInstrumentOverlayPercent() { return CLIENT.instrumentOverlayPercent.get(); } + + public static IOverlayItem.Position getVenueToolOverlayPosition() { return CLIENT.venueToolOverlayPosition.get(); } + + public static int getVenueToolOverlayPercent() { return CLIENT.venueToolOverlayPercent.get(); } + private static final ForgeConfigSpec serverSpec; public static final Server SERVER; static { diff --git a/src/main/java/aeronicamc/mods/mxtune/datagen/MXTuneLanguageProvider.java b/src/main/java/aeronicamc/mods/mxtune/datagen/MXTuneLanguageProvider.java index c0bcfd79..a3fe593e 100644 --- a/src/main/java/aeronicamc/mods/mxtune/datagen/MXTuneLanguageProvider.java +++ b/src/main/java/aeronicamc/mods/mxtune/datagen/MXTuneLanguageProvider.java @@ -263,9 +263,13 @@ private void addConfigs() { addConfig("client.double_click_time_ms", "Double-click time in milliseconds for GUI widgets"); addConfig("client.mml_Link", "MML Site Link"); + addConfig("client.instrument_overlay_position", "Instrument Overlay Position"); + addConfig("client.instrument_overlay_percent", "Instrument Overlay Percent down screen"); + addConfig("client.venue_tool_overlay_position", "Venue Tool Overlay Position"); + addConfig("client.venue_tool_overlay_percent", "Venue Tool Overlay Percent down screen"); addConfig("server.listener_range", "Listener Range"); addConfig("server.sheet_music_expires", "Sheet Music Expires"); - addConfig("server.sheet_music_life_in_days", "Sheet Music Life in Days."); + addConfig("server.sheet_music_life_in_days", "Sheet Music Life in Days"); } private void addEntities() diff --git a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java index fc40ffcc..f269a032 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java @@ -43,7 +43,7 @@ private Visibility(SoundEvent pSoundEvent) { } public void playSound(SoundHandler pHandler) { - pHandler.play(SimpleSound.forUI(this.soundEvent, 1.0F, 1.0F)); + pHandler.play(SimpleSound.forUI(this.soundEvent, 1.2F, 0.80F)); } } diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java index 43cc9187..a264eddd 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java @@ -1,11 +1,11 @@ package aeronicamc.mods.mxtune.render; +import aeronicamc.mods.mxtune.config.MXTuneConfig; 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.entity.player.ClientPlayerEntity; import net.minecraft.client.gui.AbstractGui; import net.minecraft.item.ItemStack; import net.minecraft.util.Util; @@ -13,12 +13,11 @@ import javax.annotation.Nullable; import java.util.Arrays; -import java.util.Objects; public class OverlayItemGui extends AbstractGui { private final Minecraft minecraft; - private final OverlayInstance[] visible = { null }; + private final OverlayInstance[] visible = { null, null }; private int lastSlot = -1; public OverlayItemGui(Minecraft pMinecraft) { @@ -28,17 +27,17 @@ public OverlayItemGui(Minecraft pMinecraft) { public void render(MatrixStack pPoseStack) { if (!this.minecraft.options.hideGui) { OverlayInstance overlayInstance; - for(int i = 0; i < this.visible.length; ++i) { + for(int instIndex = 0; instIndex < this.visible.length; ++instIndex) { overlayInstance = null; - if (this.visible[i] == null && getMinecraft().player != null && lastSlot != RenderHelper.getSelectedSlot()) { + if (this.visible[instIndex] == null && getMinecraft().player != null && lastSlot != RenderHelper.getSelectedSlot()) { lastSlot = RenderHelper.getSelectedSlot(); - this.visible[i] = getOverLayInstance(); + this.visible[instIndex] = getOverLayInstance(); } - if (this.visible[i] != null) - overlayInstance = this.visible[i]; - if (overlayInstance != null && overlayInstance.render(this.minecraft.getWindow().getGuiScaledWidth(), i, pPoseStack)) { - this.visible[i] = null; + if (this.visible[instIndex] != null) + overlayInstance = this.visible[instIndex]; + if (overlayInstance != null && overlayInstance.render(this.minecraft.getWindow().getGuiScaledWidth(), this.minecraft.getWindow().getGuiScaledHeight(), instIndex, pPoseStack)) { + this.visible[instIndex] = null; } } } @@ -54,6 +53,24 @@ else if (stack.getItem() instanceof MusicVenueToolItem) return null; } + private IOverlayItem.Position getPosition(IOverlayItem overlayItem) { + if (overlayItem.getItemStack().getItem() instanceof IInstrument) + return MXTuneConfig.getInstrumentOverlayPosition(); + else if (overlayItem.getItemStack().getItem() instanceof MusicVenueToolItem) + return MXTuneConfig.getVenueToolOverlayPosition(); + else + return IOverlayItem.Position.LEFT; + } + + private float getPercent(IOverlayItem overlayItem) { + if (overlayItem.getItemStack().getItem() instanceof IInstrument) + return MXTuneConfig.getInstrumentOverlayPercent(); + else if (overlayItem.getItemStack().getItem() instanceof MusicVenueToolItem) + return MXTuneConfig.getVenueToolOverlayPercent(); + else + return 0F; + } + @SuppressWarnings("unchecked") @Nullable public T getOverlay(Class pIOverlayItem, Object pToken) { @@ -73,10 +90,6 @@ private Minecraft getMinecraft() { return this.minecraft; } - private ClientPlayerEntity getPlayer() { - return Objects.requireNonNull(getMinecraft().player); - } - class OverlayInstance { private final T overlayItem; private long animationTime = -1L; @@ -99,54 +112,56 @@ private float getVisibility(long milliseconds) { /** * Render an overlay instance. - * @param x screen right. - * @param y render top. + * + * @param x screen right. + * @param y render top. + * @param instIndex 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(); + public boolean render(int x, int y, int instIndex, MatrixStack pPoseStack) { + long ms = Util.getMillis(); if (this.animationTime == -1L) { - this.animationTime = i; + this.animationTime = ms; this.visibility.playSound(OverlayItemGui.this.minecraft.getSoundManager()); } - if (this.visibility == IOverlayItem.Visibility.SHOW && i - this.animationTime <= 600L) { - this.visibleTime = i; + if (this.visibility == IOverlayItem.Visibility.SHOW && ms - this.animationTime <= 600L) { + this.visibleTime = ms; } - IOverlayItem.Position position = IOverlayItem.Position.LEFT; + IOverlayItem.Position position = getPosition(this.overlayItem); + float ratio = Math.max(Math.min(Math.abs(getPercent(this.overlayItem)/100F), 1F), 0F); float xPos; - float yPos; + float yPos = 0F + (y * ratio) - (y * ratio > this.overlayItem.totalHeight() ? this.overlayItem.totalHeight() : 0); + switch (position) { case LEFT: - xPos = 0F - this.overlayItem.totalWidth() + ((float)this.overlayItem.totalWidth() * this.getVisibility(i)); - yPos = 0F; + xPos = 0F - this.overlayItem.totalWidth() + ((float)this.overlayItem.totalWidth() * this.getVisibility(ms)); break; case CENTER: xPos = (x * 0.5F) - this.overlayItem.totalWidth() * 0.5F; - yPos = 0F - this.overlayItem.totalHeight() + ((float) this.overlayItem.totalHeight() * this.getVisibility(i)); -// yPos = 0F - this.overlayItem.totalHeight() + (getMinecraft().getWindow().getGuiScaledHeight() * 0.5F + this.overlayItem.totalHeight() * 0.5F) * this.getVisibility(i); + yPos = 0F - this.overlayItem.totalHeight() + (y * ratio + this.overlayItem.totalHeight() * ratio) * this.getVisibility(ms); break; case RIGHT: - xPos = (float)x - (float)this.overlayItem.totalWidth() * this.getVisibility(i); - yPos = 0F; + xPos = (float)x - (float)this.overlayItem.totalWidth() * this.getVisibility(ms); break; default: throw new IllegalStateException("Unexpected value: " + position); } + RenderSystem.pushMatrix(); - RenderSystem.translatef(xPos, yPos, 800F + y); - IOverlayItem.Visibility overlayVisibility = this.overlayItem.render(pPoseStack, OverlayItemGui.this, i - this.visibleTime); + RenderSystem.translatef(xPos, yPos, 800F + instIndex); + IOverlayItem.Visibility overlayVisibility = this.overlayItem.render(pPoseStack, OverlayItemGui.this, ms - this.visibleTime); RenderSystem.popMatrix(); if (overlayVisibility != this.visibility) { - this.animationTime = i - (long)((int)((1.0F - this.getVisibility(i)) * 600.0F)); + this.animationTime = ms - (long)((int)((1.0F - this.getVisibility(ms)) * 600.0F)); this.visibility = overlayVisibility; this.visibility.playSound(OverlayItemGui.this.minecraft.getSoundManager()); } - return this.visibility == IOverlayItem.Visibility.HIDE && i - this.animationTime > 600L; + return this.visibility == IOverlayItem.Visibility.HIDE && ms - this.animationTime > 600L; } } } \ No newline at end of file diff --git a/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java b/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java index 06108a3d..afb5f357 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java @@ -11,6 +11,7 @@ import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.debug.DebugRenderer; import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.ISelectionContext; @@ -50,6 +51,10 @@ static int getSelectedSlot() { return getPlayer().inventory.selected; } + static ItemStack getSelectedStack() { + return getPlayer().inventory.getSelected(); + } + /** * Defaults to 256x256 texture sheet for use with the vanilla toast textures.

* Inspired directly by the vanilla {@link AbstractGui} class instead of dealing w a non-static method.