Various changes to the protocol selection gui:

1. Add button for creating Via dumps and reloading all config files
2. Fix ESC action to actually open the parent screen
3. Made the GUI pretty
This commit is contained in:
FlorianMichael 2023-10-25 03:51:41 +02:00
parent 2e09d167bf
commit 5a4b714bc5
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126

View File

@ -18,21 +18,31 @@
package de.florianmichael.viaforge.gui;
import com.mojang.realmsclient.gui.ChatFormatting;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.util.DumpUtil;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiSlot;
import net.raphimc.vialoader.util.VersionEnum;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
public class GuiProtocolSelector extends GuiScreen {
private final GuiScreen parent;
private SlotList list;
private String status;
private long time;
public GuiProtocolSelector(GuiScreen parent) {
this.parent = parent;
}
@ -40,15 +50,41 @@ public class GuiProtocolSelector extends GuiScreen {
@Override
public void initGui() {
super.initGui();
buttonList.add(new GuiButton(1, width / 2 - 100, height - 27, 200, 20, "Back"));
list = new SlotList(mc, width, height, 32, height - 32, 10);
buttonList.add(new GuiButton(1, 5, height - 25, 20, 20, "<-"));
buttonList.add(new GuiButton(2, width - 105, 5, 100, 20, "Create dump"));
buttonList.add(new GuiButton(3, width - 105, height - 25, 100, 20, "Reload configs"));
list = new SlotList(mc, width, height, 3 + 3 /* start offset */ + (fontRenderer.FONT_HEIGHT + 2) * 3 /* title is 2 */, height - 30, fontRenderer.FONT_HEIGHT + 2);
}
public void setStatus(final String status) {
this.status = status;
this.time = System.currentTimeMillis();
}
@Override
protected void actionPerformed(GuiButton p_actionPerformed_1_) throws IOException {
list.actionPerformed(p_actionPerformed_1_);
protected void actionPerformed(GuiButton button) {
list.actionPerformed(button);
if (p_actionPerformed_1_.id == 1) mc.displayGuiScreen(parent);
if (button.id == 1) {
mc.displayGuiScreen(parent);
} else if (button.id == 2) {
try {
GuiScreen.setClipboardString(DumpUtil.postDump(UUID.randomUUID()).get());
setStatus(ChatFormatting.GREEN + "Dump created and copied to clipboard");
} catch (InterruptedException | ExecutionException e) {
setStatus(ChatFormatting.RED + "Failed to create dump: " + e.getMessage());
}
} else {
Via.getManager().getConfigurationProvider().reloadConfigs();
}
}
@Override
protected void keyTyped(char typedChar, int keyCode) {
if (keyCode == Keyboard.KEY_ESCAPE) {
mc.displayGuiScreen(parent);
}
}
@Override
@ -58,24 +94,28 @@ public class GuiProtocolSelector extends GuiScreen {
}
@Override
public void drawScreen(int p_drawScreen_1_, int p_drawScreen_2_, float p_drawScreen_3_) {
list.drawScreen(p_drawScreen_1_, p_drawScreen_2_, p_drawScreen_3_);
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
if (System.currentTimeMillis() - this.time >= 10_000) {
this.status = null;
}
list.drawScreen(mouseX, mouseY, partialTicks);
GL11.glPushMatrix();
GL11.glScalef(2.0F, 2.0F, 2.0F);
this.drawCenteredString(this.fontRenderer, ChatFormatting.GOLD + "ViaForge", this.width / 4, 6, 16777215);
drawCenteredString(fontRenderer, ChatFormatting.GOLD + "ViaForge", width / 4, 3, 16777215);
GL11.glPopMatrix();
drawString(this.fontRenderer, "by https://github.com/ViaVersion/ViaForge", 1, 1, -1);
drawString(this.fontRenderer, "Discord: florianmichael", 1, 11, -1);
drawCenteredString(fontRenderer, "https://github.com/ViaVersion/ViaForge", width / 2, (fontRenderer.FONT_HEIGHT + 2) * 2 + 3, -1);
drawString(fontRenderer, status != null ? status : "Discord: florianmichael", 3, 3, -1);
super.drawScreen(p_drawScreen_1_, p_drawScreen_2_, p_drawScreen_3_);
super.drawScreen(mouseX, mouseY, partialTicks);
}
class SlotList extends GuiSlot {
public SlotList(Minecraft p_i1052_1_, int p_i1052_2_, int p_i1052_3_, int p_i1052_4_, int p_i1052_5_, int p_i1052_6_) {
super(p_i1052_1_, p_i1052_2_, p_i1052_3_, p_i1052_4_, p_i1052_5_, p_i1052_6_);
public SlotList(Minecraft client, int width, int height, int top, int bottom, int slotHeight) {
super(client, width, height, top, bottom, slotHeight);
}
@Override
@ -84,12 +124,12 @@ public class GuiProtocolSelector extends GuiScreen {
}
@Override
protected void elementClicked(int i, boolean b, int i1, int i2) {
ViaForgeCommon.getManager().setTargetVersion(VersionEnum.SORTED_VERSIONS.get(i));
protected void elementClicked(int index, boolean b, int i1, int i2) {
ViaForgeCommon.getManager().setTargetVersion(VersionEnum.SORTED_VERSIONS.get(index));
}
@Override
protected boolean isSelected(int i) {
protected boolean isSelected(int index) {
return false;
}
@ -99,11 +139,11 @@ public class GuiProtocolSelector extends GuiScreen {
}
@Override
protected void drawSlot(int i, int i1, int i2, int i3, int i4, int i5, float v) {
protected void drawSlot(int index, int x, int y, int slotHeight, int mouseX, int mouseY, float partialTicks) {
final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion();
final VersionEnum version = VersionEnum.SORTED_VERSIONS.get(i);
final VersionEnum version = VersionEnum.SORTED_VERSIONS.get(index);
drawCenteredString(mc.fontRenderer,(targetVersion == version ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + version.getName(), width / 2, i2, -1);
drawCenteredString(mc.fontRenderer,(targetVersion == version ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + version.getName(), width / 2, y, -1);
}
}
}