From 518a50d166edf617a818fa9adc8324db32bff7fc Mon Sep 17 00:00:00 2001 From: Aeronica Date: Wed, 13 Mar 2024 08:02:41 -0500 Subject: [PATCH] WIP: Improve Instrument and MusicVenueTool overlays. --- .../aeronicamc/mods/mxtune/gui/MXScreen.java | 21 +- .../mods/mxtune/gui/group/GuiGroup.java | 240 ++---------------- .../mods/mxtune/gui/group/GuiPin.java | 2 +- .../mods/mxtune/gui/group/MemberDisplay.java | 120 +++++++++ .../mods/mxtune/gui/group/MemberInfo.java | 66 +++++ .../mods/mxtune/gui/mml/GuiFileImporter.java | 2 +- .../mods/mxtune/gui/mml/GuiMXT.java | 40 ++- .../mods/mxtune/gui/mml/GuiMusicLibrary.java | 2 +- .../mods/mxtune/managers/Group.java | 1 + .../mods/mxtune/render/OverlayInst.java | 3 +- .../mods/mxtune/render/OverlayItemGui.java | 8 +- .../mods/mxtune/render/OverlayVenueTool.java | 3 +- 12 files changed, 258 insertions(+), 250 deletions(-) create mode 100644 src/main/java/aeronicamc/mods/mxtune/gui/group/MemberDisplay.java create mode 100644 src/main/java/aeronicamc/mods/mxtune/gui/group/MemberInfo.java diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/MXScreen.java b/src/main/java/aeronicamc/mods/mxtune/gui/MXScreen.java index b8c9f472..8ae249aa 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/MXScreen.java +++ b/src/main/java/aeronicamc/mods/mxtune/gui/MXScreen.java @@ -2,10 +2,14 @@ import com.mojang.blaze3d.matrix.MatrixStack; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.widget.Widget; import net.minecraft.util.text.ITextComponent; +import java.util.Objects; + public class MXScreen extends Screen { protected MXScreen(ITextComponent pTitle) @@ -13,6 +17,11 @@ protected MXScreen(ITextComponent pTitle) super(pTitle); } + @Override + public T addButton(T pButton) { + return super.addButton(pButton); + } + @Override public void render(MatrixStack pMatrixStack, int pMouseX, int pMouseY, float pPartialTicks) { @@ -20,14 +29,18 @@ public void render(MatrixStack pMatrixStack, int pMouseX, int pMouseY, float pPa ModGuiHelper.drawHooveringHelp(pMatrixStack, this, children, pMouseX, pMouseY); } - public static Minecraft getMC() - { + @Override + public Minecraft getMinecraft() { return Minecraft.getInstance(); } - public static FontRenderer getFont() + public ClientPlayerEntity getPlayer() + { + return Objects.requireNonNull(getMinecraft().player); + } + public FontRenderer getFont() { - return getMC().font; + return Objects.requireNonNull(getMinecraft()).font; } } diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/group/GuiGroup.java b/src/main/java/aeronicamc/mods/mxtune/gui/group/GuiGroup.java index 0b848c20..305de557 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/group/GuiGroup.java +++ b/src/main/java/aeronicamc/mods/mxtune/gui/group/GuiGroup.java @@ -2,7 +2,6 @@ import aeronicamc.mods.mxtune.gui.MXScreen; import aeronicamc.mods.mxtune.gui.ModGuiHelper; -import aeronicamc.mods.mxtune.gui.TextColorFg; import aeronicamc.mods.mxtune.gui.widget.GuiHelpButton; import aeronicamc.mods.mxtune.gui.widget.IHooverText; import aeronicamc.mods.mxtune.gui.widget.MXButton; @@ -13,17 +12,13 @@ import aeronicamc.mods.mxtune.network.messages.GroupCmdMessage; import aeronicamc.mods.mxtune.util.IGroupClientChangedCallback; import com.mojang.blaze3d.matrix.MatrixStack; -import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.gui.DialogTexts; import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.entity.Entity; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TranslationTextComponent; -import java.util.ArrayList; -import java.util.List; import java.util.Objects; import static aeronicamc.mods.mxtune.gui.ModGuiHelper.*; @@ -47,7 +42,7 @@ public class GuiGroup extends MXScreen implements IGroupClientChangedCallback private static final ITextComponent DISBAND_HELP03 = new TranslationTextComponent("gui.mxtune.button.disband.help03").withStyle(TextFormatting.YELLOW); private static final int PADDING = 4; - private Group.Mode groupMode = Group.Mode.PIN; + Group.Mode groupMode = Group.Mode.PIN; private final MXButton buttonNewPin = new MXButton(p -> newPin()); private final MXButton buttonGroupMode = new MXButton(p -> modeToggle()); private final MXButton buttonDone = new MXButton(p -> done()); @@ -61,30 +56,30 @@ public class GuiGroup extends MXScreen implements IGroupClientChangedCallback private Group group = Group.EMPTY; private int groupId; private int lastHash; - private final int lineHeight; - private final int nameWidth; + final int lineHeight; + final int nameWidth; public GuiGroup() { super(StringTextComponent.EMPTY); lineHeight = getFont().lineHeight + 6; nameWidth = getFont().width("MMMMMMMMMMMM") + 4; - memberDisplayLeft = new MemberDisplay(this, MemberDisplay.Split.M01_M08); - memberDisplayRight = new MemberDisplay(this, MemberDisplay.Split.M09_M16); + memberDisplayLeft = new MemberDisplay(this, this, MemberDisplay.Split.M01_M08); + memberDisplayRight = new MemberDisplay(this, this, MemberDisplay.Split.M09_M16); GroupClient.setCallback(this); } - private int getGroupId() + int getGroupId() { return this.groupId; } - private int getLineHeight() + int getLineHeight() { return this.lineHeight; } - private int getNameWidth() + int getNameWidth() { return this.nameWidth; } @@ -93,13 +88,13 @@ private int getNameWidth() protected void init() { super.init(); - group = GroupClient.getGroup(player().getId()); + group = GroupClient.getGroup(getPlayer().getId()); groupId = group.getGroupId(); - PacketDispatcher.sendToServer(new GroupCmdMessage("", Cmd.PIN, player().getId())); + PacketDispatcher.sendToServer(new GroupCmdMessage("", Cmd.PIN, getPlayer().getId())); setMode(GroupClient.getGroupById(groupId).getMode()); groupDisplay.setCentered(true); - int groupDisplayWidth = getWidth(GuiPin.getGroupLeaderInfo(groupDisplay, player(), groupId)); + int groupDisplayWidth = getWidth(GuiPin.getGroupLeaderInfo(groupDisplay, getPlayer(), groupId)); int leftSideWidth = memberDisplayLeft.getWidth(); int middleWidth = groupDisplayWidth + 50; int rightSideWidth = memberDisplayRight.getWidth(); @@ -110,7 +105,7 @@ protected void init() int leftRight = memberDisplayLeft.getRight() + PADDING; groupDisplay.setLayout(leftRight, top, middleWidth, 20); - ITextComponent msg = GuiPin.getGroupLeaderInfo(groupDisplay, player(), groupId); + ITextComponent msg = GuiPin.getGroupLeaderInfo(groupDisplay, getPlayer(), groupId); lastHash = msg.hashCode(); groupDisplay.setLabelText(msg); @@ -199,19 +194,19 @@ private void updateButtonState() .forEach(b -> ((IHooverText) b).setHooverTextOverride(helpButton.isHelpEnabled())); } - private void promote(Button button) + void promote(Button button) { MXButton mxButton = (MXButton) button; PacketDispatcher.sendToServer(new GroupCmdMessage(null, Cmd.PROMOTE, mxButton.getIndex())); } - private void remove(Button button) + void remove(Button button) { MXButton mxButton = (MXButton) button; PacketDispatcher.sendToServer(new GroupCmdMessage(null, Cmd.REMOVE, mxButton.getIndex())); } - private void modeToggle() + void modeToggle() { Cmd cmd = Cmd.NIL; if (Objects.requireNonNull(groupMode) == Group.Mode.PIN) { @@ -221,7 +216,7 @@ private void modeToggle() setMode(Group.Mode.PIN); cmd = Cmd.MODE_PIN; } - PacketDispatcher.sendToServer(new GroupCmdMessage(null, cmd, player().getId())); + PacketDispatcher.sendToServer(new GroupCmdMessage(null, cmd, getPlayer().getId())); updateButtonState(); } @@ -231,9 +226,9 @@ private void setMode(Group.Mode mode) groupMode = mode; buttonGroupMode.setMessage(getGroupModeName(groupMode)); - buttonNewPin.active = mode.equals(Group.Mode.PIN) && player().getId() == groupLocal.getLeader(); - buttonGroupMode.active = player().getId() == groupLocal.getLeader(); - buttonDisband.active = player().getId() == groupLocal.getLeader(); + buttonNewPin.active = mode.equals(Group.Mode.PIN) && getPlayer().getId() == groupLocal.getLeader(); + buttonGroupMode.active = getPlayer().getId() == groupLocal.getLeader(); + buttonDisband.active = getPlayer().getId() == groupLocal.getLeader(); } private ITextComponent getGroupModeName(Group.Mode mode) @@ -252,17 +247,17 @@ private ITextComponent getPinText(String text) private void makeGroup() { - PacketDispatcher.sendToServer(new GroupCmdMessage(null, Cmd.CREATE_GROUP, player().getId())); + PacketDispatcher.sendToServer(new GroupCmdMessage(null, Cmd.CREATE_GROUP, getPlayer().getId())); } private void newPin() { - PacketDispatcher.sendToServer(new GroupCmdMessage(null, Cmd.NEW_PIN, player().getId())); + PacketDispatcher.sendToServer(new GroupCmdMessage(null, Cmd.NEW_PIN, getPlayer().getId())); } private void disband() { - PacketDispatcher.sendToServer(new GroupCmdMessage(null, Cmd.DISBAND, player().getId())); + PacketDispatcher.sendToServer(new GroupCmdMessage(null, Cmd.DISBAND, getPlayer().getId())); this.onClose(); } @@ -293,7 +288,7 @@ public void tick() { if (counter++ % 20 == 0) { - ITextComponent msg = GuiPin.getGroupLeaderInfo(groupDisplay, player(), groupId); + ITextComponent msg = GuiPin.getGroupLeaderInfo(groupDisplay, getPlayer(), groupId); groupDisplay.setLabelText(msg); if (lastHash != msg.hashCode()) { @@ -317,195 +312,8 @@ public boolean isPauseScreen() return false; } - private static ClientPlayerEntity player() - { - return Objects.requireNonNull(getMC().player); - } - - private static int getWidth(ITextComponent pText) + private int getWidth(ITextComponent pText) { return getFont().width(pText); } - - @SuppressWarnings("unused") - private static class MemberDisplay - { - private final GuiGroup parent; - private final List memberButtons = new ArrayList<>(); - int xPos; - int yPos; - int padding = 0; - final int maxWidth; - final int maxHeight; - final Split split; - int indexSplit; - - MemberDisplay(GuiGroup parent, Split split) - { - this.parent = parent; - this.split = split; - maxHeight = (this.parent.getLineHeight() * 8); - maxWidth = this.parent.getNameWidth() + 40; - } - - private void initMemberDisplay(int posX, int posY) - { - this.xPos = posX; - this.yPos = posY + 2; - int y = this.yPos; - indexSplit = 0; - - memberButtons.clear(); - Group group = GroupClient.getGroupById(parent.getGroupId()); - - if (Split.M01_M08.equals(split)) - y = leaderFirst(posX + padding, y + padding, group.getLeader()); - for (Integer memberId : GroupClient.getGroupById(parent.getGroupId()).getMembers()) - { - if (!GroupClient.isLeader(memberId) && split.inSplit(indexSplit)) - { - MemberInfo memberInfo = new MemberInfo(posX + padding, y + padding, parent, memberId, parent::promote, parent::remove); - parent.addButton(memberInfo.buttonPromote); - parent.addButton(memberInfo.buttonRemove); - memberButtons.add(memberInfo); - y += parent.getLineHeight(); - } - if (!GroupClient.isLeader(memberId)) - indexSplit++; - } - } - - public int getLeft() - { - return xPos; - } - - public int getTop() - { - return yPos; - } - - public int getRight() - { - return xPos + maxWidth + padding; - } - - public int getBottom() - { - return yPos + maxHeight + padding; - } - - public int getPadding() - { - return padding; - } - - public int getHeight() - { - return maxHeight + padding; - } - - public int getWidth() - { - return maxWidth + padding; - } - - public void setPadding(int padding) - { - this.padding = padding; - } - - private int leaderFirst(int posX, int y, int memberId) - { - MemberInfo memberInfo = new MemberInfo(posX, y, parent, memberId, parent::promote, parent::remove); - memberInfo.buttonPromote.active = false; - memberInfo.buttonPromote.visible = false; - memberInfo.buttonRemove.active = player().getId() == memberId; - memberInfo.buttonRemove.visible = player().getId() == memberId; - parent.addButton(memberInfo.buttonPromote); - parent.addButton(memberInfo.buttonRemove); - memberButtons.add(memberInfo); - indexSplit++; - return y + parent.getLineHeight(); - } - - private void renderMemberDisplay(MatrixStack pMatrixStack, int pMouseX, int pMouseY, float pPartialTicks) - { - fill(pMatrixStack, xPos + padding - 1, yPos + padding - 1, xPos + padding + maxWidth + 1, yPos + padding + maxHeight + 1, -6250336); - fill(pMatrixStack, xPos + padding, yPos + padding, xPos + padding + maxWidth, yPos + padding + maxHeight, -16777216); - memberButtons.forEach(p -> p.memberDraw(pMatrixStack, pMouseX, pMouseY, pPartialTicks)); - } - - enum Split - { - M01_M08(0, 7), M09_M16(7, 15); - final int start; - final int end; - - Split(int start, int end) - { - this.start = start; - this.end = end; - } - boolean inSplit(int index) - { - return index >= start && index <= end; - } - } - } - - private static class MemberInfo - { - static final ITextComponent PROMOTE = new StringTextComponent("▲").withStyle(TextFormatting.GREEN, TextFormatting.BOLD); // '▲' dec: 9650 hex: 25B2 BLACK UP-POINTING TRIANGLE - static final ITextComponent REMOVE = new StringTextComponent("x").withStyle(TextFormatting.RED, TextFormatting.BOLD); // 'x' - static final ITextComponent PROMOTE_HELP01 = new TranslationTextComponent("gui.mxtune.button.member_promote.help01").withStyle(TextFormatting.RESET).append(PROMOTE); - static final ITextComponent PROMOTE_HELP02 = new TranslationTextComponent("gui.mxtune.button.member_promote.help02").withStyle(TextFormatting.GREEN); - static final ITextComponent PROMOTE_HELP03 = new TranslationTextComponent("gui.mxtune.button.member_promote.help03").withStyle(TextFormatting.YELLOW); - static final ITextComponent REMOVE_HELP01 = new TranslationTextComponent("gui.mxtune.button.member_remove.help01").withStyle(TextFormatting.RESET).append(REMOVE); - static final ITextComponent REMOVE_HELP02 = new TranslationTextComponent("gui.mxtune.button.member_remove.help02").withStyle(TextFormatting.GREEN); - static final ITextComponent REMOVE_HELP03 = new TranslationTextComponent("gui.mxtune.button.member_remove.help03").withStyle(TextFormatting.YELLOW); - - final int xPosMember; - final int yPosMember; - final MXButton buttonPromote; - final MXButton buttonRemove; - final int memberId; - final ITextComponent name; - - MemberInfo(int xPosMember, int yPosMember, GuiGroup parent, int memberId, Button.IPressable pPromote, Button.IPressable pRemove) - { - this.xPosMember = xPosMember; - this.yPosMember = yPosMember; - int nameWidth = parent.nameWidth; - int lineHeight = parent.lineHeight; - this.memberId = memberId; - Entity entity = player().level.getEntity(memberId); - this.name = entity != null ? entity.getDisplayName() : StringTextComponent.EMPTY; - buttonPromote = new MXButton(pPromote); - buttonPromote.setMessage(MemberInfo.PROMOTE); - buttonPromote.setLayout(xPosMember + nameWidth, yPosMember, 20, lineHeight); - buttonPromote.setIndex(memberId); - buttonPromote.addHooverText(true, PROMOTE_HELP01); - buttonPromote.addHooverText(false, PROMOTE_HELP02); - buttonPromote.addHooverText(false, PROMOTE_HELP03); - buttonPromote.active = GroupClient.isLeader(player().getId()); - buttonPromote.visible = GroupClient.isLeader(player().getId()); - - buttonRemove = new MXButton(pRemove); - buttonRemove.setMessage(MemberInfo.REMOVE); - buttonRemove.setLayout(buttonPromote.x + 20, yPosMember, 20, lineHeight); - buttonRemove.setIndex(memberId); - buttonRemove.addHooverText(true, REMOVE_HELP01); - buttonRemove.addHooverText(false, REMOVE_HELP02); - buttonRemove.addHooverText(false, REMOVE_HELP03); - buttonRemove.active = GroupClient.isLeader(player().getId()) || memberId == player().getId(); - buttonRemove.visible = GroupClient.isLeader(player().getId()) || memberId == player().getId(); - } - - @SuppressWarnings("unused") - void memberDraw(MatrixStack pMatrixStack, int pMouseX, int pMouseY, float pPartialTicks) - { - getFont().draw(pMatrixStack, name, (float) xPosMember + 2, (float) yPosMember + 2, GroupClient.isLeader(memberId) ? TextColorFg.YELLOW: TextColorFg.WHITE); - } - } } diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/group/GuiPin.java b/src/main/java/aeronicamc/mods/mxtune/gui/group/GuiPin.java index 81f25efe..baddd26c 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/group/GuiPin.java +++ b/src/main/java/aeronicamc/mods/mxtune/gui/group/GuiPin.java @@ -199,6 +199,6 @@ public boolean isPauseScreen() private ClientPlayerEntity player() { - return Objects.requireNonNull(getMC().player); + return Objects.requireNonNull(getMinecraft().player); } } diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/group/MemberDisplay.java b/src/main/java/aeronicamc/mods/mxtune/gui/group/MemberDisplay.java new file mode 100644 index 00000000..86a81fd2 --- /dev/null +++ b/src/main/java/aeronicamc/mods/mxtune/gui/group/MemberDisplay.java @@ -0,0 +1,120 @@ +package aeronicamc.mods.mxtune.gui.group; + +import aeronicamc.mods.mxtune.managers.Group; +import aeronicamc.mods.mxtune.managers.GroupClient; +import com.mojang.blaze3d.matrix.MatrixStack; +import net.minecraft.client.gui.AbstractGui; + +import java.util.ArrayList; +import java.util.List; + +public class MemberDisplay { + private final GuiGroup guiGroup; + private final GuiGroup parent; + private final List memberButtons = new ArrayList<>(); + int xPos; + int yPos; + int padding = 0; + final int maxWidth; + final int maxHeight; + final Split split; + int indexSplit; + + MemberDisplay(GuiGroup guiGroup, GuiGroup parent, Split split) { + this.guiGroup = guiGroup; + this.parent = parent; + this.split = split; + maxHeight = (this.parent.getLineHeight() * 8); + maxWidth = this.parent.getNameWidth() + 40; + } + + void initMemberDisplay(int posX, int posY) { + this.xPos = posX; + this.yPos = posY + 2; + int y = this.yPos; + indexSplit = 0; + + memberButtons.clear(); + Group group = GroupClient.getGroupById(parent.getGroupId()); + + if (Split.M01_M08.equals(split)) + y = leaderFirst(posX + padding, y + padding, group.getLeader()); + for (Integer memberId : GroupClient.getGroupById(parent.getGroupId()).getMembers()) { + if (!GroupClient.isLeader(memberId) && split.inSplit(indexSplit)) { + MemberInfo memberInfo = new MemberInfo(posX + padding, y + padding, parent, memberId, parent::promote, parent::remove); + parent.addButton(memberInfo.buttonPromote); + parent.addButton(memberInfo.buttonRemove); + memberButtons.add(memberInfo); + y += parent.getLineHeight(); + } + if (!GroupClient.isLeader(memberId)) + indexSplit++; + } + } + + public int getLeft() { + return xPos; + } + + public int getTop() { + return yPos; + } + + public int getRight() { + return xPos + maxWidth + padding; + } + + public int getBottom() { + return yPos + maxHeight + padding; + } + + public int getPadding() { + return padding; + } + + public int getHeight() { + return maxHeight + padding; + } + + public int getWidth() { + return maxWidth + padding; + } + + public void setPadding(int padding) { + this.padding = padding; + } + + int leaderFirst(int posX, int y, int memberId) { + MemberInfo memberInfo = new MemberInfo(posX, y, parent, memberId, parent::promote, parent::remove); + memberInfo.buttonPromote.active = false; + memberInfo.buttonPromote.visible = false; + memberInfo.buttonRemove.active = guiGroup.getPlayer().getId() == memberId; + memberInfo.buttonRemove.visible = guiGroup.getPlayer().getId() == memberId; + parent.addButton(memberInfo.buttonPromote); + parent.addButton(memberInfo.buttonRemove); + memberButtons.add(memberInfo); + indexSplit++; + return y + parent.getLineHeight(); + } + + void renderMemberDisplay(MatrixStack pMatrixStack, int pMouseX, int pMouseY, float pPartialTicks) { + AbstractGui.fill(pMatrixStack, xPos + padding - 1, yPos + padding - 1, xPos + padding + maxWidth + 1, yPos + padding + maxHeight + 1, -6250336); + AbstractGui.fill(pMatrixStack, xPos + padding, yPos + padding, xPos + padding + maxWidth, yPos + padding + maxHeight, -16777216); + memberButtons.forEach(p -> p.memberDraw(pMatrixStack, pMouseX, pMouseY, pPartialTicks)); + } + + enum Split { + M01_M08(0, 7), M09_M16(7, 15); + final int start; + final int end; + + Split(int start, int end) { + this.start = start; + this.end = end; + } + + boolean inSplit(int index) { + return index >= start && index <= end; + } + } +} diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/group/MemberInfo.java b/src/main/java/aeronicamc/mods/mxtune/gui/group/MemberInfo.java new file mode 100644 index 00000000..4fcc7ac9 --- /dev/null +++ b/src/main/java/aeronicamc/mods/mxtune/gui/group/MemberInfo.java @@ -0,0 +1,66 @@ +package aeronicamc.mods.mxtune.gui.group; + +import aeronicamc.mods.mxtune.gui.TextColorFg; +import aeronicamc.mods.mxtune.gui.widget.MXButton; +import aeronicamc.mods.mxtune.managers.GroupClient; +import com.mojang.blaze3d.matrix.MatrixStack; +import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.entity.Entity; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.TranslationTextComponent; + +public class MemberInfo { + static final ITextComponent PROMOTE = new StringTextComponent("▲").withStyle(TextFormatting.GREEN, TextFormatting.BOLD); // '▲' dec: 9650 hex: 25B2 BLACK UP-POINTING TRIANGLE + static final ITextComponent REMOVE = new StringTextComponent("x").withStyle(TextFormatting.RED, TextFormatting.BOLD); // 'x' + static final ITextComponent PROMOTE_HELP01 = new TranslationTextComponent("gui.mxtune.button.member_promote.help01").withStyle(TextFormatting.RESET).append(PROMOTE); + static final ITextComponent PROMOTE_HELP02 = new TranslationTextComponent("gui.mxtune.button.member_promote.help02").withStyle(TextFormatting.GREEN); + static final ITextComponent PROMOTE_HELP03 = new TranslationTextComponent("gui.mxtune.button.member_promote.help03").withStyle(TextFormatting.YELLOW); + static final ITextComponent REMOVE_HELP01 = new TranslationTextComponent("gui.mxtune.button.member_remove.help01").withStyle(TextFormatting.RESET).append(REMOVE); + static final ITextComponent REMOVE_HELP02 = new TranslationTextComponent("gui.mxtune.button.member_remove.help02").withStyle(TextFormatting.GREEN); + static final ITextComponent REMOVE_HELP03 = new TranslationTextComponent("gui.mxtune.button.member_remove.help03").withStyle(TextFormatting.YELLOW); + + private final GuiGroup parent; + final int xPosMember; + final int yPosMember; + final MXButton buttonPromote; + final MXButton buttonRemove; + final int memberId; + final ITextComponent name; + + MemberInfo(int xPosMember, int yPosMember, GuiGroup parent, int memberId, Button.IPressable pPromote, Button.IPressable pRemove) { + this.xPosMember = xPosMember; + this.yPosMember = yPosMember; + this.parent = parent; + int nameWidth = parent.nameWidth; + int lineHeight = parent.lineHeight; + this.memberId = memberId; + Entity entity = parent.getPlayer().level.getEntity(memberId); + this.name = entity != null ? entity.getDisplayName() : StringTextComponent.EMPTY; + buttonPromote = new MXButton(pPromote); + buttonPromote.setMessage(MemberInfo.PROMOTE); + buttonPromote.setLayout(xPosMember + nameWidth, yPosMember, 20, lineHeight); + buttonPromote.setIndex(memberId); + buttonPromote.addHooverText(true, PROMOTE_HELP01); + buttonPromote.addHooverText(false, PROMOTE_HELP02); + buttonPromote.addHooverText(false, PROMOTE_HELP03); + buttonPromote.active = GroupClient.isLeader(parent.getPlayer().getId()); + buttonPromote.visible = GroupClient.isLeader(parent.getPlayer().getId()); + + buttonRemove = new MXButton(pRemove); + buttonRemove.setMessage(MemberInfo.REMOVE); + buttonRemove.setLayout(buttonPromote.x + 20, yPosMember, 20, lineHeight); + buttonRemove.setIndex(memberId); + buttonRemove.addHooverText(true, REMOVE_HELP01); + buttonRemove.addHooverText(false, REMOVE_HELP02); + buttonRemove.addHooverText(false, REMOVE_HELP03); + buttonRemove.active = GroupClient.isLeader(parent.getPlayer().getId()) || memberId == parent.getPlayer().getId(); + buttonRemove.visible = GroupClient.isLeader(parent.getPlayer().getId()) || memberId == parent.getPlayer().getId(); + } + + @SuppressWarnings("unused") + void memberDraw(MatrixStack pMatrixStack, int pMouseX, int pMouseY, float pPartialTicks) { + parent.getFont().draw(pMatrixStack, name, (float) xPosMember + 2, (float) yPosMember + 2, GroupClient.isLeader(memberId) ? TextColorFg.YELLOW : TextColorFg.WHITE); + } +} diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiFileImporter.java b/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiFileImporter.java index e4915a9b..acebb0c8 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiFileImporter.java +++ b/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiFileImporter.java @@ -303,7 +303,7 @@ private void selectDone(boolean doubleClicked) if (selectedEntry != null) ActionGet.INSTANCE.select(ImportHelper.importToMXTFile(selectedEntry.getPath())); if (doubleClicked) - getMC().mouseHandler.releaseMouse(); + getMinecraft().mouseHandler.releaseMouse(); onClose(); } diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiMXT.java b/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiMXT.java index 6e477d39..e2d864de 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiMXT.java +++ b/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiMXT.java @@ -34,7 +34,10 @@ import org.apache.logging.log4j.Logger; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; import java.util.stream.IntStream; import static aeronicamc.mods.mxtune.Reference.*; @@ -93,7 +96,7 @@ public GuiMXT(Screen parent) { super(new TranslationTextComponent("gui.mxtune.gui_mxt.title")); this.parent = parent; - this.player = getMC().player; + this.player = getMinecraft().player; for (int i = 0; i < MAX_TABS; i++) { childTabs[i] = new GuiMXTPartTab(this); @@ -106,7 +109,7 @@ protected void init() super.init(); children.clear(); buttons.clear(); - getMC().keyboardHandler.setSendRepeatsToGui(true); + getMinecraft().keyboardHandler.setSendRepeatsToGui(true); int singleLineHeight = getFont().lineHeight + 2; int titleWidth = width - PADDING * 2; @@ -230,7 +233,7 @@ private void buttonAccept(Widget widget) { this.activeChildIndex = ((MXButton)widget).getIndex(); widget.active = true; - this.childTabs[activeChildIndex].init(getMC(), width, height); + this.childTabs[activeChildIndex].init(getMinecraft(), width, height); updateState(); } @@ -524,8 +527,8 @@ private void helpToggled() @Override public void onClose() { - getMC().keyboardHandler.setSendRepeatsToGui(false); - getMC().setScreen(parent); + getMinecraft().keyboardHandler.setSendRepeatsToGui(false); + getMinecraft().setScreen(parent); } @Override @@ -544,12 +547,12 @@ private void newAction() { stop(); updateState(); - getMC().setScreen(new ConfirmScreen(this::newCallback, new TranslationTextComponent("gui.mxtune.confirm.new.text01"), new TranslationTextComponent("gui.mxtune.new.text02"))); + getMinecraft().setScreen(new ConfirmScreen(this::newCallback, new TranslationTextComponent("gui.mxtune.confirm.new.text01"), new TranslationTextComponent("gui.mxtune.new.text02"))); } private void newCallback(boolean result) { - getMC().setScreen(this); + getMinecraft().setScreen(this); if (result) { mxTuneFile = null; @@ -569,7 +572,7 @@ private void importAction() ActionGet.INSTANCE.clear(); ActionGet.INSTANCE.setFileImport(); viewableTabCount = MIN_TABS; - getMC().setScreen(new GuiFileImporter(this)); + getMinecraft().setScreen(new GuiFileImporter(this)); } private void openAction() @@ -578,7 +581,7 @@ private void openAction() ActionGet.INSTANCE.clear(); ActionGet.INSTANCE.setFileOpen(); viewableTabCount = MIN_TABS; - getMC().setScreen(new GuiMusicLibrary(this)); + getMinecraft().setScreen(new GuiMusicLibrary(this)); } private void saveAction() @@ -637,7 +640,7 @@ private void createMxt() private void writeSheetMusic() { if (makeSheetMusic()) - getMC().setScreen(parent); + getMinecraft().setScreen(parent); } /** @@ -646,13 +649,13 @@ private void writeSheetMusic() private void writeMusicScore() { if (makeMusicScore()) - getMC().setScreen(parent); + getMinecraft().setScreen(parent); } private void cancelAction() { stop(); - getMC().setScreen(parent); + getMinecraft().setScreen(parent); } private void openMmlUrl() @@ -755,7 +758,7 @@ public String getMML() private void stop() { - getMC().submitAsync(()->ClientAudio.fadeOut(playId, 1)); + getMinecraft().submitAsync(()->ClientAudio.fadeOut(playId, 1)); isPlaying = false; playId = PlayIdSupplier.INVALID; @@ -767,7 +770,7 @@ private void stop() private boolean mmlPlay(String mmlIn) { playId = PlayIdSupplier.PlayType.PERSONAL.getAsInt(); - getMC().submitAsync(()->ClientAudio.playLocal(durationTotal, playId, mmlIn, this)); + getMinecraft().submitAsync(()->ClientAudio.playLocal(durationTotal, playId, mmlIn, this)); updateState(); return true; } @@ -792,11 +795,4 @@ public void statusCallBack(ClientAudio.Status status, int playId) stop(); } } - - private PlayerEntity getPlayer() - { - return Objects.requireNonNull(player); - } - - } diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiMusicLibrary.java b/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiMusicLibrary.java index 05b2c060..1c51a651 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiMusicLibrary.java +++ b/src/main/java/aeronicamc/mods/mxtune/gui/mml/GuiMusicLibrary.java @@ -336,7 +336,7 @@ private void selectDone(boolean doubleClicked) if (fileDataListWidget.getSelected() != null) ActionGet.INSTANCE.select(fileDataListWidget.getSelected().getPath()); if (doubleClicked) - getMC().mouseHandler.releaseMouse(); + getMinecraft().mouseHandler.releaseMouse(); onClose(); } diff --git a/src/main/java/aeronicamc/mods/mxtune/managers/Group.java b/src/main/java/aeronicamc/mods/mxtune/managers/Group.java index 4ad613d6..e16edc87 100644 --- a/src/main/java/aeronicamc/mods/mxtune/managers/Group.java +++ b/src/main/java/aeronicamc/mods/mxtune/managers/Group.java @@ -171,6 +171,7 @@ public String getHelp02Key() { return help02Key; } + } @Override diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java index 90744f98..7c354973 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java @@ -4,7 +4,6 @@ import aeronicamc.mods.mxtune.util.SheetMusicHelper; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.gui.toasts.IToast; import net.minecraft.item.ItemStack; import net.minecraft.util.text.ITextComponent; @@ -58,7 +57,7 @@ public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponen this.lastChanged = delta; this.changed = false; } - mc.getTextureManager().bind(IToast.TEXTURE); + mc.getTextureManager().bind(IOverlayItem.TEXTURE); RenderSystem.color3f(1.0F, 1.0F, 1.0F); 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()); diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java index e7503131..56d7ab46 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java @@ -6,6 +6,7 @@ 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,6 +14,7 @@ import javax.annotation.Nullable; import java.util.Arrays; +import java.util.Objects; public class OverlayItemGui extends AbstractGui { @@ -45,7 +47,7 @@ public void render(MatrixStack pPoseStack) { @Nullable private OverlayInstance getOverLayInstance() { - ItemStack stack = RenderHelper.getPlayer().inventory.getSelected(); + ItemStack stack = getPlayer().inventory.getSelected(); if (stack.getItem() instanceof IInstrument) return new OverlayInstance<>(new OverlayInst(stack)); else if (stack.getItem() instanceof MusicVenueToolItem) @@ -90,6 +92,10 @@ private Minecraft getMinecraft() { return this.minecraft; } + private ClientPlayerEntity getPlayer() { + return Objects.requireNonNull(this.minecraft.player); + } + class OverlayInstance { private final T overlayItem; private long animationTime = -1L; diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java index 5a60571d..7f559c6c 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java @@ -7,7 +7,6 @@ import aeronicamc.mods.mxtune.items.MusicVenueToolItem; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.gui.toasts.IToast; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; @@ -83,7 +82,7 @@ else if (raytraceresult instanceof EntityRayTraceResult) else blockName = new StringTextComponent("---").withStyle(TextFormatting.AQUA); - mc.getTextureManager().bind(IToast.TEXTURE); + mc.getTextureManager().bind(IOverlayItem.TEXTURE); RenderSystem.color3f(1.0F, 1.0F, 1.0F); 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());