Added Option to save Player Visibility Settings in Replay
This commit is contained in:
@@ -79,4 +79,5 @@ public class GuiConstants {
|
||||
|
||||
public static final int PLAYER_OVERVIEW_HIDE_ALL = 1010;
|
||||
public static final int PLAYER_OVERVIEW_SHOW_ALL = 0101;
|
||||
public static final int PLAYER_OVERVIEW_REMEMBER = -10;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,11 @@ package eu.crushedpixel.replaymod.gui;
|
||||
import com.mojang.realmsclient.util.Pair;
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.mojang.SkinDownloader;
|
||||
import eu.crushedpixel.replaymod.holders.PlayerVisibility;
|
||||
import eu.crushedpixel.replaymod.registry.PlayerHandler;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFile;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -18,9 +21,11 @@ import net.minecraft.entity.player.EnumPlayerModelParts;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.client.config.GuiCheckBox;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -29,11 +34,14 @@ import java.util.List;
|
||||
|
||||
public class GuiPlayerOverview extends GuiScreen {
|
||||
|
||||
public static boolean defaultSave = false;
|
||||
|
||||
private List<Pair<EntityPlayer, ResourceLocation>> players;
|
||||
private List<GuiCheckBox> checkBoxes;
|
||||
private List<Integer> loadedPlayers = new ArrayList<Integer>();
|
||||
|
||||
private GuiCheckBox hideAllBox, showAllBox;
|
||||
private GuiCheckBox rememberHidden;
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
@@ -112,8 +120,8 @@ public class GuiPlayerOverview extends GuiScreen {
|
||||
}
|
||||
int k2 = (int) (this.width * 0.3);
|
||||
|
||||
if(mouseX >= k2 && mouseX <= (this.width * 0.6) && mouseY >= 60 && mouseY <= lowerBound) {
|
||||
int off = mouseY - 60;
|
||||
if(mouseX >= k2 && mouseX <= (this.width * 0.6) && mouseY >= upperBound && mouseY <= lowerBound) {
|
||||
int off = mouseY - upperBound;
|
||||
int p = (off / 21) + upperPlayer;
|
||||
ReplayHandler.spectateEntity(players.get(p).first());
|
||||
mc.displayGuiScreen(null);
|
||||
@@ -175,14 +183,19 @@ public class GuiPlayerOverview extends GuiScreen {
|
||||
if(!initialized) {
|
||||
hideAllBox = new GuiCheckBox(GuiConstants.PLAYER_OVERVIEW_HIDE_ALL, 0, 0, "", false);
|
||||
showAllBox = new GuiCheckBox(GuiConstants.PLAYER_OVERVIEW_SHOW_ALL, 0, 0, "", true);
|
||||
rememberHidden = new GuiCheckBox(GuiConstants.PLAYER_OVERVIEW_REMEMBER, 0, 0, I18n.format("replaymod.gui.playeroverview.remembersettings"), defaultSave);
|
||||
}
|
||||
|
||||
hideAllBox.xPosition = (int)(this.width*0.7)-5;
|
||||
showAllBox.xPosition = (int)(this.width*0.7)-20;
|
||||
hideAllBox.yPosition = showAllBox.yPosition = 45;
|
||||
|
||||
rememberHidden.xPosition = (int)(this.width*0.3);
|
||||
rememberHidden.yPosition = 45;
|
||||
|
||||
buttonList.add(hideAllBox);
|
||||
buttonList.add(showAllBox);
|
||||
buttonList.add(rememberHidden);
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
@@ -207,12 +220,13 @@ public class GuiPlayerOverview extends GuiScreen {
|
||||
PlayerHandler.setIsVisible(players.get(upperPlayer + button.id).first(), ((GuiCheckBox)button).isChecked());
|
||||
}
|
||||
|
||||
private static final int upperBound = 65;
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
this.drawCenteredString(fontRendererObj, screenTitle, this.width / 2, 5, Color.WHITE.getRGB());
|
||||
int k2 = (int)(this.width * 0.3);
|
||||
int l2 = 60;
|
||||
int l3 = l2;
|
||||
int l2 = upperBound;
|
||||
|
||||
drawGradientRect(k2 - 20, 20, (int) (this.width * 0.7) + 20, this.height - 30 - 2 + 10, -1072689136, -804253680);
|
||||
|
||||
@@ -275,8 +289,8 @@ public class GuiPlayerOverview extends GuiScreen {
|
||||
float posPerc = ((float) upperPlayer) / playerCount;
|
||||
int barY = (int) (posPerc * (height - 32 - 32));
|
||||
|
||||
drawRect(k2 - 18, l3 - 2, k2 - 10, this.height - 30 - 2, Color.BLACK.getRGB());
|
||||
drawRect(k2 - 16, l3+2 - 2 + barY, k2 - 12, 30+2 - 1 + barY + barHeight, Color.LIGHT_GRAY.getRGB());
|
||||
drawRect(k2 - 18, upperBound - 2, k2 - 10, this.height - 30 - 2, Color.BLACK.getRGB());
|
||||
drawRect(k2 - 16, upperBound+2 - 2 + barY, k2 - 12, 30+2 - 1 + barY + barHeight, Color.LIGHT_GRAY.getRGB());
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
@@ -288,6 +302,7 @@ public class GuiPlayerOverview extends GuiScreen {
|
||||
|
||||
hideAllBox.drawButton(mc, mouseX, mouseY);
|
||||
showAllBox.drawButton(mc, mouseX, mouseY);
|
||||
rememberHidden.drawButton(mc, mouseX, mouseY);
|
||||
|
||||
if(hideAllBox.isMouseOver()) {
|
||||
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.playeroverview.hideall"), mouseX, mouseY+5, Color.WHITE.getRGB());
|
||||
@@ -297,9 +312,42 @@ public class GuiPlayerOverview extends GuiScreen {
|
||||
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.playeroverview.showall"), mouseX, mouseY+5, Color.WHITE.getRGB());
|
||||
}
|
||||
|
||||
if(rememberHidden.isMouseOver()) {
|
||||
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.playeroverview.remembersettings.description"), mouseX, mouseY+5, Color.WHITE.getRGB());
|
||||
}
|
||||
|
||||
//this is necessary to reset the GL parameters for further GUI rendering
|
||||
drawRect(0, 0, 0, 0, Color.LIGHT_GRAY.getRGB());
|
||||
}
|
||||
|
||||
private PlayerVisibility getVisibilityInstance() {
|
||||
return new PlayerVisibility(PlayerHandler.getHiddenPlayers());
|
||||
}
|
||||
|
||||
|
||||
private void saveOnQuit() {
|
||||
if(rememberHidden.isChecked()) {
|
||||
try {
|
||||
File f = File.createTempFile(ReplayFile.ENTRY_VISIBILITY, "json");
|
||||
ReplayFileIO.writePlayerVisibilityToFile(getVisibilityInstance(), f);
|
||||
ReplayMod.replayFileAppender.registerModifiedFile(f, ReplayFile.ENTRY_VISIBILITY, ReplayHandler.getReplayFile());
|
||||
System.out.println("here");
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
ReplayMod.replayFileAppender.registerModifiedFile(null, ReplayFile.ENTRY_VISIBILITY, ReplayHandler.getReplayFile());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if(keyCode == Keyboard.KEY_ESCAPE) {
|
||||
saveOnQuit();
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
private class PlayerComparator implements Comparator<EntityPlayer> {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user