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 3, 2024
1 parent a751a76 commit 39edf5b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ 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);
return delta - this.lastChanged >= 5000L ? IOverlayItem.Visibility.HIDE : IOverlayItem.Visibility.SHOW;
}

@Override
public int offset() {
return this.width();
public int totalHeight() {
return this.baseWidth();
}

@Override
public int totalWidth() {
return this.baseWidth();
}
}
19 changes: 12 additions & 7 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand All @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<IOverlayItem> queued = Queues.newArrayDeque();

public OverlayItemGui(Minecraft pMinecraft) {
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down

0 comments on commit 39edf5b

Please sign in to comment.