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 Mar 11, 2024
1 parent a65d608 commit 4ff7f9b
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 36 deletions.
6 changes: 5 additions & 1 deletion src/generated/resources/assets/mxtune/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/config/MXTuneConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,10 @@ public static class Client
{
public final ConfigValue<Integer> doubleClickTime;
public final ConfigValue<String> site;
public final ConfigValue<IOverlayItem.Position> instrumentOverlayPosition;
public final ConfigValue<Integer> instrumentOverlayPercent;
public final ConfigValue<IOverlayItem.Position> venueToolOverlayPosition;
public final ConfigValue<Integer> venueToolOverlayPercent;

public Client(final ForgeConfigSpec.Builder builder)
{
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
81 changes: 48 additions & 33 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
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;
import net.minecraft.util.math.MathHelper;

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) {
Expand All @@ -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;
}
}
}
Expand All @@ -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 extends IOverlayItem> T getOverlay(Class<? extends T> pIOverlayItem, Object pToken) {
Expand All @@ -73,10 +90,6 @@ private Minecraft getMinecraft() {
return this.minecraft;
}

private ClientPlayerEntity getPlayer() {
return Objects.requireNonNull(getMinecraft().player);
}

class OverlayInstance<T extends IOverlayItem> {
private final T overlayItem;
private long animationTime = -1L;
Expand All @@ -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;
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. <p></p>
* Inspired directly by the vanilla {@link AbstractGui} class instead of dealing w a non-static method.
Expand Down

0 comments on commit 4ff7f9b

Please sign in to comment.