Add player overview extra
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.replaymod.extras;
|
package com.replaymod.extras;
|
||||||
|
|
||||||
import com.replaymod.core.ReplayMod;
|
import com.replaymod.core.ReplayMod;
|
||||||
|
import com.replaymod.extras.playeroverview.PlayerOverview;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
@@ -20,6 +21,7 @@ public class ReplayModExtras {
|
|||||||
private static ReplayMod core;
|
private static ReplayMod core;
|
||||||
|
|
||||||
private static final List<Class<? extends Extra>> builtin = Arrays.asList(
|
private static final List<Class<? extends Extra>> builtin = Arrays.asList(
|
||||||
|
PlayerOverview.class,
|
||||||
FullBrightness.class,
|
FullBrightness.class,
|
||||||
HotkeyButtons.class
|
HotkeyButtons.class
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package com.replaymod.extras.playeroverview;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.replaymod.core.ReplayMod;
|
||||||
|
import com.replaymod.extras.Extra;
|
||||||
|
import com.replaymod.replay.ReplayModReplay;
|
||||||
|
import com.replaymod.replay.camera.CameraEntity;
|
||||||
|
import com.replaymod.replay.events.ReplayCloseEvent;
|
||||||
|
import com.replaymod.replay.events.ReplayOpenEvent;
|
||||||
|
import net.minecraft.client.renderer.entity.RenderManager;
|
||||||
|
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class PlayerOverview implements Extra {
|
||||||
|
@Mod.Instance(ReplayModReplay.MOD_ID)
|
||||||
|
private static ReplayModReplay module;
|
||||||
|
|
||||||
|
private final Set<UUID> hiddenPlayers = new HashSet<>();
|
||||||
|
private boolean savingEnabled;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(final ReplayMod mod) throws Exception {
|
||||||
|
mod.getKeyBindingRegistry().registerKeyBinding("replaymod.input.playeroverview", Keyboard.KEY_B, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (module.getReplayHandler() != null) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<EntityPlayer> players = mod.getMinecraft().theWorld.getPlayers(EntityPlayer.class, new Predicate() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(Object input) {
|
||||||
|
return !(input instanceof CameraEntity); // Exclude the camera entity
|
||||||
|
}
|
||||||
|
});
|
||||||
|
new PlayerOverviewGui(PlayerOverview.this, players).display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
FMLCommonHandler.instance().bus().register(this);
|
||||||
|
|
||||||
|
RenderManager renderManager = mod.getMinecraft().getRenderManager();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, RenderPlayer> skinMap = renderManager.skinMap;
|
||||||
|
skinMap.put("default", new PlayerRenderHook(this, renderManager, false));
|
||||||
|
skinMap.put("slim", new PlayerRenderHook(this, renderManager, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHidden(UUID uuid) {
|
||||||
|
return hiddenPlayers.contains(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHidden(UUID uuid, boolean hidden) {
|
||||||
|
if (hidden) {
|
||||||
|
hiddenPlayers.add(uuid);
|
||||||
|
} else {
|
||||||
|
hiddenPlayers.remove(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onReplayOpen(ReplayOpenEvent.Pre event) throws IOException {
|
||||||
|
Optional<Set<UUID>> savedData = event.getReplayHandler().getReplayFile().getInvisiblePlayers();
|
||||||
|
if (savedData.isPresent()) {
|
||||||
|
hiddenPlayers.addAll(savedData.get());
|
||||||
|
savingEnabled = true;
|
||||||
|
} else {
|
||||||
|
savingEnabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onReplayClose(ReplayCloseEvent.Pre event) throws IOException {
|
||||||
|
hiddenPlayers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSavingEnabled() {
|
||||||
|
return savingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSavingEnabled(boolean savingEnabled) {
|
||||||
|
this.savingEnabled = savingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveHiddenPlayers() {
|
||||||
|
if (savingEnabled) {
|
||||||
|
try {
|
||||||
|
module.getReplayHandler().getReplayFile().writeInvisiblePlayers(hiddenPlayers);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
package com.replaymod.extras.playeroverview;
|
||||||
|
|
||||||
|
import com.replaymod.replay.ReplayModReplay;
|
||||||
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
|
import de.johni0702.minecraft.gui.container.*;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiCheckbox;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiImage;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||||
|
import de.johni0702.minecraft.gui.element.IGuiCheckbox;
|
||||||
|
import de.johni0702.minecraft.gui.function.Closeable;
|
||||||
|
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||||
|
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||||
|
import de.johni0702.minecraft.gui.utils.Colors;
|
||||||
|
import eu.crushedpixel.replaymod.utils.SkinProvider;
|
||||||
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.EnumPlayerModelParts;
|
||||||
|
import net.minecraft.potion.Potion;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.util.Dimension;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PlayerOverviewGui extends GuiScreen implements Closeable {
|
||||||
|
protected static final int ENTRY_WIDTH = 200;
|
||||||
|
|
||||||
|
public final GuiPanel contentPanel = new GuiPanel(this).setBackgroundColor(Colors.DARK_TRANSPARENT);
|
||||||
|
public final GuiLabel spectateLabel = new GuiLabel(contentPanel)
|
||||||
|
.setI18nText("replaymod.gui.playeroverview.spectate");
|
||||||
|
public final GuiLabel visibleLabel = new GuiLabel(contentPanel)
|
||||||
|
.setI18nText("replaymod.gui.playeroverview.visible");
|
||||||
|
public final GuiVerticalList playersScrollable = new GuiVerticalList(contentPanel)
|
||||||
|
.setDrawSlider(true).setDrawShadow(true);
|
||||||
|
public final GuiCheckbox saveCheckbox = new GuiCheckbox(contentPanel)
|
||||||
|
.setI18nLabel("replaymod.gui.playeroverview.remembersettings");
|
||||||
|
public final GuiCheckbox checkAll = new GuiCheckbox(contentPanel){
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(BUTTON_SOUND, 1.0F));
|
||||||
|
playersScrollable.forEach(IGuiCheckbox.class).setChecked(true);
|
||||||
|
}
|
||||||
|
}.setLabel("").setChecked(true);
|
||||||
|
public final GuiCheckbox uncheckAll = new GuiCheckbox(contentPanel){
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(BUTTON_SOUND, 1.0F));
|
||||||
|
playersScrollable.forEach(IGuiCheckbox.class).setChecked(false);
|
||||||
|
}
|
||||||
|
}.setLabel("").setChecked(false);
|
||||||
|
|
||||||
|
{
|
||||||
|
setDrawBackground(false);
|
||||||
|
setTitle(new GuiLabel().setI18nText("replaymod.input.playeroverview"));
|
||||||
|
setLayout(new CustomLayout<GuiScreen>() {
|
||||||
|
@Override
|
||||||
|
protected void layout(GuiScreen container, int width, int height) {
|
||||||
|
size(contentPanel, ENTRY_WIDTH + 30, height - 40);
|
||||||
|
pos(contentPanel, width / 2 - width(contentPanel) / 2, 20);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
contentPanel.setLayout(new CustomLayout<GuiPanel>() {
|
||||||
|
@Override
|
||||||
|
protected void layout(GuiPanel container, int width, int height) {
|
||||||
|
pos(spectateLabel, 10, 10);
|
||||||
|
pos(visibleLabel, width - 10 - width(visibleLabel), 10);
|
||||||
|
pos(playersScrollable, 10, y(spectateLabel) + height(spectateLabel) + 5);
|
||||||
|
size(playersScrollable, width - 10 - 5, height - 15 - height(saveCheckbox) - y(playersScrollable));
|
||||||
|
pos(saveCheckbox, 10, height - 10 - height(saveCheckbox));
|
||||||
|
pos(uncheckAll, width - width(uncheckAll) - 8, height - height(uncheckAll) - 10);
|
||||||
|
pos(checkAll, x(uncheckAll) - 3 - width(checkAll), y(uncheckAll));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private final PlayerOverview extra;
|
||||||
|
|
||||||
|
public PlayerOverviewGui(final PlayerOverview extra, List<EntityPlayer> players) {
|
||||||
|
this.extra = extra;
|
||||||
|
|
||||||
|
Collections.sort(players, new PlayerComparator()); // Sort by name, spectators last
|
||||||
|
for (final EntityPlayer p : players) {
|
||||||
|
final ResourceLocation texture = SkinProvider.getResourceLocationForPlayerUUID(p.getUniqueID());
|
||||||
|
final GuiClickable panel = new GuiClickable().setLayout(new HorizontalLayout().setSpacing(2)).addElements(
|
||||||
|
new HorizontalLayout.Data(0.5), new GuiImage() {
|
||||||
|
@Override
|
||||||
|
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||||
|
renderer.bindTexture(texture);
|
||||||
|
renderer.drawTexturedRect(0, 0, 8, 8, 16, 16, 8, 8, 64, 64);
|
||||||
|
if (p.func_175148_a(EnumPlayerModelParts.HAT)) {
|
||||||
|
renderer.drawTexturedRect(0, 0, 40, 8, size.getWidth(), size.getHeight(), 8, 8, 64, 64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.setSize(16, 16),
|
||||||
|
new GuiLabel().setText(p.getName()).setColor(isSpectator(p) ? Colors.DKGREY : Colors.WHITE)
|
||||||
|
).onClick(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ReplayModReplay.instance.getReplayHandler().spectateEntity(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
final GuiCheckbox checkbox = new GuiCheckbox() {
|
||||||
|
@Override
|
||||||
|
public GuiCheckbox setChecked(boolean checked) {
|
||||||
|
extra.setHidden(p.getUniqueID(), !checked);
|
||||||
|
return super.setChecked(checked);
|
||||||
|
}
|
||||||
|
}.setChecked(!extra.isHidden(p.getUniqueID()));
|
||||||
|
new GuiPanel(playersScrollable.getListPanel()).setLayout(new CustomLayout<GuiPanel>() {
|
||||||
|
@Override
|
||||||
|
protected void layout(GuiPanel container, int width, int height) {
|
||||||
|
pos(panel, 5, 0);
|
||||||
|
pos(checkbox, width - width(checkbox) - 5, height / 2 - height(checkbox) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension calcMinSize(GuiContainer<?> container) {
|
||||||
|
return new Dimension(ENTRY_WIDTH, panel.getMinSize().getHeight());
|
||||||
|
}
|
||||||
|
}).addElements(null, panel, checkbox);
|
||||||
|
}
|
||||||
|
saveCheckbox.setChecked(extra.isSavingEnabled()).onClick(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
extra.setSavingEnabled(saveCheckbox.isChecked());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ReplayModReplay.instance.getReplayHandler().getOverlay().setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
ReplayModReplay.instance.getReplayHandler().getOverlay().setVisible(false);
|
||||||
|
extra.saveHiddenPlayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isSpectator(EntityPlayer e) {
|
||||||
|
return e.isInvisible() && e.getActivePotionEffect(Potion.invisibility) == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class PlayerComparator implements Comparator<EntityPlayer> {
|
||||||
|
@Override
|
||||||
|
public int compare(EntityPlayer o1, EntityPlayer o2) {
|
||||||
|
if (isSpectator(o1) && !isSpectator(o2)) return 1;
|
||||||
|
if (isSpectator(o2) && !isSpectator(o1)) return -1;
|
||||||
|
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.replaymod.extras.playeroverview;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.culling.ICamera;
|
||||||
|
import net.minecraft.client.renderer.entity.RenderManager;
|
||||||
|
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
|
||||||
|
public class PlayerRenderHook extends RenderPlayer {
|
||||||
|
private final PlayerOverview extra;
|
||||||
|
|
||||||
|
public PlayerRenderHook(PlayerOverview extra, RenderManager renderManager, boolean useSmallArms) {
|
||||||
|
super(renderManager, useSmallArms);
|
||||||
|
this.extra = extra;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldRender(Entity entity, ICamera camera, double camX, double camY, double camZ) {
|
||||||
|
return !extra.isHidden(entity.getUniqueID()) && super.shouldRender(entity, camera, camX, camY, camZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.container;
|
||||||
|
|
||||||
|
public class GuiVerticalList extends AbstractGuiVerticalList<GuiVerticalList> {
|
||||||
|
public GuiVerticalList() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuiVerticalList(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuiVerticalList getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -89,7 +89,7 @@ public abstract class AbstractGuiCheckbox<T extends AbstractGuiCheckbox<T>>
|
|||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(BUTTON_SOUND, 1.0F));
|
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(BUTTON_SOUND, 1.0F));
|
||||||
checked = !checked;
|
setChecked(!isChecked());
|
||||||
super.onClick();
|
super.onClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ public class KeybindRegistry {
|
|||||||
|
|
||||||
replayModKeyBindings.add(new KeyBinding(KEY_SYNC_TIMELINE, Keyboard.KEY_V, "replaymod.title"));
|
replayModKeyBindings.add(new KeyBinding(KEY_SYNC_TIMELINE, Keyboard.KEY_V, "replaymod.title"));
|
||||||
|
|
||||||
replayModKeyBindings.add(new KeyBinding(KEY_PLAYER_OVERVIEW, Keyboard.KEY_B, "replaymod.title"));
|
|
||||||
|
|
||||||
replayModKeyBindings.add(new KeyBinding(KEY_ASSET_MANAGER, Keyboard.KEY_G, "replaymod.title"));
|
replayModKeyBindings.add(new KeyBinding(KEY_ASSET_MANAGER, Keyboard.KEY_G, "replaymod.title"));
|
||||||
replayModKeyBindings.add(new KeyBinding(KEY_OBJECT_MANAGER, Keyboard.KEY_F, "replaymod.title"));
|
replayModKeyBindings.add(new KeyBinding(KEY_OBJECT_MANAGER, Keyboard.KEY_F, "replaymod.title"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user