-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Improve Instrument and MusicVenueTool overlays.
- Loading branch information
Showing
10 changed files
with
224 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/aeronicamc/mods/mxtune/gui/toasts/MXOverlay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IOverlayItem> 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 extends IOverlayItem> T getOverlay(Class<? extends T> 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<T extends IOverlayItem> { | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters