mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-29 15:37:59 +01:00
Move the GuiItemStackButton to live with the rest of the gui classes and improved error message handling
This commit is contained in:
parent
54e008eb7c
commit
25a501ba34
7 changed files with 153 additions and 150 deletions
|
@ -9,7 +9,7 @@ import net.minecraft.client.gui.GuiButton;
|
||||||
|
|
||||||
public class Button extends GuiButton implements IActionable, IGuiTooltipped {
|
public class Button extends GuiButton implements IActionable, IGuiTooltipped {
|
||||||
|
|
||||||
private IGuiAction<Button> action;
|
protected IGuiAction<Button> action;
|
||||||
|
|
||||||
private List<String> tooltip = null;
|
private List<String> tooltip = null;
|
||||||
|
|
||||||
|
|
31
src/common/java/com/minelittlepony/gui/IconicButton.java
Normal file
31
src/common/java/com/minelittlepony/gui/IconicButton.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package com.minelittlepony.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
public class IconicButton extends Button {
|
||||||
|
|
||||||
|
private ItemStack itemStack = ItemStack.EMPTY;
|
||||||
|
|
||||||
|
public IconicButton(int x, int y, IGuiAction<IconicButton> callback) {
|
||||||
|
super(x, y, 20, 20, "", callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconicButton setIcon(ItemStack stack) {
|
||||||
|
itemStack = stack;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconicButton setIcon(ItemStack stack, int colour) {
|
||||||
|
Items.LEATHER_LEGGINGS.setColor(stack, colour);
|
||||||
|
return setIcon(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||||
|
super.drawButton(mc, mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
|
mc.getRenderItem().renderItemIntoGUI(itemStack, x + 2, y + 2);
|
||||||
|
}
|
||||||
|
}
|
|
@ -254,7 +254,7 @@ public class GLWindow extends DropTarget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setDropTargetListener(DropTargetListener dtl) {
|
public synchronized void setDropTargetListener(FileDropListener dtl) {
|
||||||
try {
|
try {
|
||||||
clearDropTargetListener();
|
clearDropTargetListener();
|
||||||
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.voxelmodpack.hdskins.gui;
|
|
||||||
|
|
||||||
import com.minelittlepony.gui.Button;
|
|
||||||
import com.minelittlepony.gui.IGuiAction;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.init.Items;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public class GuiItemStackButton extends Button {
|
|
||||||
|
|
||||||
private ItemStack itemStack;
|
|
||||||
|
|
||||||
public GuiItemStackButton(int x, int y, ItemStack itemStack, IGuiAction<GuiItemStackButton> callback) {
|
|
||||||
super(x, y, 20, 20, "", callback);
|
|
||||||
this.itemStack = itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiItemStackButton(int x, int y, ItemStack itemStack, int colour, IGuiAction<GuiItemStackButton> callback) {
|
|
||||||
this(x, y, itemStack, callback);
|
|
||||||
Items.LEATHER_LEGGINGS.setColor(itemStack, colour);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
|
||||||
super.drawButton(mc, mouseX, mouseY, partialTicks);
|
|
||||||
|
|
||||||
mc.getRenderItem().renderItemIntoGUI(itemStack, x + 2, y + 2);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,7 +9,9 @@ import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.minelittlepony.gui.Button;
|
import com.minelittlepony.gui.Button;
|
||||||
import com.minelittlepony.gui.GameGui;
|
import com.minelittlepony.gui.GameGui;
|
||||||
|
import com.minelittlepony.gui.IconicButton;
|
||||||
import com.minelittlepony.gui.Label;
|
import com.minelittlepony.gui.Label;
|
||||||
|
import com.minelittlepony.util.math.MathUtil;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||||
|
@ -25,13 +27,14 @@ import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiMainMenu;
|
import net.minecraft.client.gui.GuiMainMenu;
|
||||||
import net.minecraft.client.renderer.RenderHelper;
|
import net.minecraft.client.renderer.RenderHelper;
|
||||||
import net.minecraft.client.renderer.entity.RenderManager;
|
import net.minecraft.client.renderer.entity.RenderManager;
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.init.SoundEvents;
|
import net.minecraft.init.SoundEvents;
|
||||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
|
@ -68,22 +71,29 @@ public class GuiSkins extends GameGui {
|
||||||
|
|
||||||
private DoubleBuffer doubleBuffer;
|
private DoubleBuffer doubleBuffer;
|
||||||
|
|
||||||
@Nullable
|
private boolean showMessage;
|
||||||
private String uploadError;
|
private float uploadOpacity = 0;
|
||||||
private volatile String skinMessage = format("hdskins.choose");
|
|
||||||
private String skinUploadMessage = format("hdskins.request");
|
private String uploadError = "";
|
||||||
|
private String uploadMessage = format("hdskins.request");
|
||||||
|
|
||||||
|
private volatile String localMessage = format("hdskins.choose");
|
||||||
|
|
||||||
private volatile boolean fetchingSkin;
|
private volatile boolean fetchingSkin;
|
||||||
private volatile boolean uploadingSkin;
|
private volatile boolean uploadingSkin;
|
||||||
private volatile boolean pendingRemoteSkinRefresh;
|
private volatile boolean pendingRemoteSkinRefresh;
|
||||||
private volatile boolean throttledByMojang;
|
private volatile boolean throttledByMojang;
|
||||||
|
|
||||||
private int refreshCounter = -1;
|
private int refreshCounter = 0;
|
||||||
|
|
||||||
private ThreadOpenFilePNG openFileThread;
|
private ThreadOpenFilePNG openFileThread;
|
||||||
|
|
||||||
private final Object skinLock = new Object();
|
private final Object skinLock = new Object();
|
||||||
|
|
||||||
private File pendingSkinFile;
|
private File pendingSkinFile;
|
||||||
private File selectedSkin;
|
private File selectedSkin;
|
||||||
private float uploadOpacity = 0;
|
|
||||||
|
|
||||||
|
|
||||||
private int lastMouseX = 0;
|
private int lastMouseX = 0;
|
||||||
|
|
||||||
|
@ -94,6 +104,14 @@ public class GuiSkins extends GameGui {
|
||||||
private MinecraftProfileTexture.Type textureType = SKIN;
|
private MinecraftProfileTexture.Type textureType = SKIN;
|
||||||
private boolean thinArmType = false;
|
private boolean thinArmType = false;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public GuiSkins() {
|
public GuiSkins() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
|
@ -148,8 +166,8 @@ public class GuiSkins extends GameGui {
|
||||||
localPlayer.setLocalTexture(pendingSkinFile, textureType);
|
localPlayer.setLocalTexture(pendingSkinFile, textureType);
|
||||||
selectedSkin = pendingSkinFile;
|
selectedSkin = pendingSkinFile;
|
||||||
pendingSkinFile = null;
|
pendingSkinFile = null;
|
||||||
onSetLocalSkin(textureType);
|
|
||||||
btnUpload.enabled = true;
|
btnUpload.enabled = true;
|
||||||
|
onSetLocalSkin(textureType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,30 +179,27 @@ public class GuiSkins extends GameGui {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (throttledByMojang) {
|
if (throttledByMojang) {
|
||||||
if (refreshCounter == -1) {
|
refreshCounter = (refreshCounter + 1) % 200;
|
||||||
refreshCounter = 200;
|
if (refreshCounter == 0) {
|
||||||
} else if (refreshCounter > 0) {
|
|
||||||
--refreshCounter;
|
|
||||||
} else {
|
|
||||||
refreshCounter = -1;
|
|
||||||
throttledByMojang = false;
|
|
||||||
reloadRemoteSkin();
|
reloadRemoteSkin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onSetRemoteSkin(MinecraftProfileTexture.Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) {
|
protected void onSetRemoteSkin(Type type, ResourceLocation location, MinecraftProfileTexture profileTexture) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onSetLocalSkin(MinecraftProfileTexture.Type type) {
|
protected void onSetLocalSkin(Type type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadRemoteSkin() {
|
private void reloadRemoteSkin() {
|
||||||
|
throttledByMojang = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
remotePlayer.reloadRemoteSkin(this::onSetRemoteSkin);
|
remotePlayer.reloadRemoteSkin(this::onSetRemoteSkin);
|
||||||
} catch (Exception var2) {
|
} catch (Exception e) {
|
||||||
var2.printStackTrace();
|
e.printStackTrace();
|
||||||
throttledByMojang = true;
|
throttledByMojang = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,13 +207,15 @@ public class GuiSkins extends GameGui {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initGui() {
|
public void initGui() {
|
||||||
GLWindow.current().setDropTargetListener((FileDropListener) files -> {
|
GLWindow.current().setDropTargetListener(files -> {
|
||||||
files.stream().findFirst().ifPresent(instance::loadLocalFile);
|
files.stream().findFirst().ifPresent(instance::loadLocalFile);
|
||||||
});
|
});
|
||||||
|
|
||||||
panorama.init();
|
panorama.init();
|
||||||
|
|
||||||
addButton(new Label(width / 2, 10, "hdskins.manager", 0xffffff, true));
|
addButton(new Label(width / 2, 10, "hdskins.manager", 0xffffff, true));
|
||||||
|
addButton(new Label(34, 34, "hdskins.local", 0xffffff));
|
||||||
|
addButton(new Label(width / 2 + 34, 34, "hdskins.server", 0xffffff));
|
||||||
|
|
||||||
addButton(new Button(width / 2 - 150, height - 27, 90, 20, "hdskins.options.browse", sender ->{
|
addButton(new Button(width / 2 - 150, height - 27, 90, 20, "hdskins.options.browse", sender ->{
|
||||||
selectedSkin = null;
|
selectedSkin = null;
|
||||||
|
@ -215,41 +232,35 @@ public class GuiSkins extends GameGui {
|
||||||
})).setEnabled(!mc.isFullScreen());
|
})).setEnabled(!mc.isFullScreen());
|
||||||
|
|
||||||
addButton(btnUpload = new Button(width / 2 - 24, height / 2 - 10, 48, 20, "hdskins.options.chevy", sender -> {
|
addButton(btnUpload = new Button(width / 2 - 24, height / 2 - 10, 48, 20, "hdskins.options.chevy", sender -> {
|
||||||
if (selectedSkin != null) {
|
punchServer("hdskins.upload", selectedSkin.toURI());
|
||||||
punchServer("hdskins.upload", selectedSkin.toURI());
|
})).setEnabled(canUpload()).setTooltip("hdskins.options.chevy.title");
|
||||||
sender.enabled = false;
|
|
||||||
} else {
|
|
||||||
setUploadError(format("hdskins.error.select"));
|
|
||||||
}
|
|
||||||
})).setEnabled(false).setTooltip("hdskins.options.chevy.title");
|
|
||||||
|
|
||||||
addButton(btnClear = new Button(width / 2 + 60, height - 27, 90, 20, "hdskins.options.clear", sender -> {
|
addButton(btnClear = new Button(width / 2 + 60, height - 27, 90, 20, "hdskins.options.clear", sender -> {
|
||||||
if (remotePlayer.isTextureSetupComplete()) {
|
if (remotePlayer.isTextureSetupComplete()) {
|
||||||
punchServer("hdskins.request", null);
|
punchServer("hdskins.request", null);
|
||||||
btnUpload.enabled = selectedSkin != null;
|
|
||||||
}
|
}
|
||||||
}));
|
})).setEnabled(!fetchingSkin);
|
||||||
|
|
||||||
addButton(new Button(width / 2 - 50, height - 25, 100, 20, "hdskins.options.close", sender -> {
|
addButton(new Button(width / 2 - 50, height - 25, 100, 20, "hdskins.options.close", sender -> {
|
||||||
mc.displayGuiScreen(new GuiMainMenu());
|
mc.displayGuiScreen(new GuiMainMenu());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
addButton(btnModeSteve = new GuiItemStackButton(width - 25, 32, new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb, sender -> {
|
addButton(btnModeSteve = new IconicButton(width - 25, 32, sender -> {
|
||||||
switchSkinMode(sender, false);
|
switchSkinMode(false);
|
||||||
})).setEnabled(thinArmType).setTooltip("hdskins.mode.steve");
|
}).setIcon(new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb)).setEnabled(thinArmType).setTooltip("hdskins.mode.steve");
|
||||||
|
|
||||||
addButton(btnModeAlex = new GuiItemStackButton(width - 25, 51, new ItemStack(Items.LEATHER_LEGGINGS), 0xfff500, sender -> {
|
addButton(btnModeAlex = new IconicButton(width - 25, 51, sender -> {
|
||||||
switchSkinMode(sender, true);
|
switchSkinMode(true);
|
||||||
})).setEnabled(!thinArmType).setTooltip("hdskins.mode.alex");
|
}).setIcon(new ItemStack(Items.LEATHER_LEGGINGS), 0xfff500)).setEnabled(!thinArmType).setTooltip("hdskins.mode.alex");
|
||||||
|
|
||||||
|
|
||||||
addButton(btnModeSkin = new GuiItemStackButton(width - 25, 75, new ItemStack(Items.LEATHER_CHESTPLATE), sender -> {
|
addButton(btnModeSkin = new IconicButton(width - 25, 75, sender -> {
|
||||||
switchSkinType(sender, SKIN);
|
switchSkinType(sender, SKIN);
|
||||||
})).setEnabled(textureType == ELYTRA).setTooltip(format("hdskins.mode.skin", toTitleCase(SKIN.name())));
|
}).setIcon(new ItemStack(Items.LEATHER_CHESTPLATE))).setEnabled(textureType == ELYTRA).setTooltip(format("hdskins.mode.skin", toTitleCase(SKIN.name())));
|
||||||
|
|
||||||
addButton(btnModeElytra = new GuiItemStackButton(width - 25, 94, new ItemStack(Items.ELYTRA), sender -> {
|
addButton(btnModeElytra = new IconicButton(width - 25, 94, sender -> {
|
||||||
switchSkinType(sender, ELYTRA);
|
switchSkinType(sender, ELYTRA);
|
||||||
})).setEnabled(textureType == SKIN).setTooltip(format("hdskins.mode.skin", toTitleCase(ELYTRA.name())));
|
}).setIcon(new ItemStack(Items.ELYTRA))).setEnabled(textureType == SKIN).setTooltip(format("hdskins.mode.skin", toTitleCase(ELYTRA.name())));
|
||||||
|
|
||||||
|
|
||||||
addButton(new Button(width - 25, height - 65, 20, 20, "?", sender -> {
|
addButton(new Button(width - 25, height - 65, 20, 20, "?", sender -> {
|
||||||
|
@ -268,28 +279,28 @@ public class GuiSkins extends GameGui {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadLocalFile(File skinFile) {
|
private void loadLocalFile(File skinFile) {
|
||||||
Minecraft.getMinecraft().addScheduledTask(localPlayer::releaseTextures);
|
mc.addScheduledTask(localPlayer::releaseTextures);
|
||||||
|
|
||||||
if (!skinFile.exists()) {
|
if (!skinFile.exists()) {
|
||||||
skinMessage = format("hdskins.error.unreadable");
|
localMessage = format("hdskins.error.unreadable");
|
||||||
} else if (!FilenameUtils.isExtension(skinFile.getName(), new String[]{"png", "PNG"})) {
|
} else if (!FilenameUtils.isExtension(skinFile.getName(), new String[]{"png", "PNG"})) {
|
||||||
skinMessage = format("hdskins.error.ext");
|
localMessage = format("hdskins.error.ext");
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
BufferedImage chosenImage = ImageIO.read(skinFile);
|
BufferedImage chosenImage = ImageIO.read(skinFile);
|
||||||
|
|
||||||
if (chosenImage == null) {
|
if (chosenImage == null) {
|
||||||
skinMessage = format("hdskins.error.open");
|
localMessage = format("hdskins.error.open");
|
||||||
} else if (!acceptsSkinDimensions(chosenImage.getWidth(), chosenImage.getHeight())) {
|
} else if (!acceptsSkinDimensions(chosenImage.getWidth(), chosenImage.getHeight())) {
|
||||||
skinMessage = format("hdskins.error.invalid");
|
localMessage = format("hdskins.error.invalid");
|
||||||
} else {
|
} else {
|
||||||
synchronized (skinLock) {
|
synchronized (skinLock) {
|
||||||
pendingSkinFile = skinFile;
|
pendingSkinFile = skinFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException var6) {
|
} catch (IOException e) {
|
||||||
skinMessage = format("hdskins.error.open");
|
localMessage = format("hdskins.error.open");
|
||||||
var6.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,7 +323,7 @@ public class GuiSkins extends GameGui {
|
||||||
remotePlayer.setItemStackToSlot(EntityEquipmentSlot.CHEST, stack);
|
remotePlayer.setItemStackToSlot(EntityEquipmentSlot.CHEST, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void switchSkinMode(Button sender, boolean thin) {
|
protected void switchSkinMode(boolean thin) {
|
||||||
mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.BLOCK_BREWING_STAND_BREW, 1));
|
mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.BLOCK_BREWING_STAND_BREW, 1));
|
||||||
|
|
||||||
thinArmType = thin;
|
thinArmType = thin;
|
||||||
|
@ -328,22 +339,22 @@ public class GuiSkins extends GameGui {
|
||||||
remotePlayer.setPreviewThinArms(thinArmType);
|
remotePlayer.setPreviewThinArms(thinArmType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean clearMessage() {
|
||||||
|
showMessage = false;
|
||||||
|
|
||||||
|
return uploadOpacity == 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void actionPerformed(GuiButton guiButton) {
|
protected void actionPerformed(GuiButton guiButton) {
|
||||||
if (openFileThread == null && !uploadingSkin) {
|
if (openFileThread == null && !uploadingSkin && clearMessage()) {
|
||||||
if (uploadError != null) {
|
super.actionPerformed(guiButton);
|
||||||
uploadError = null;
|
|
||||||
} else {
|
|
||||||
super.actionPerformed(guiButton);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException {
|
protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException {
|
||||||
if (uploadError != null) {
|
if (clearMessage()) {
|
||||||
uploadError = null;
|
|
||||||
} else {
|
|
||||||
super.mouseClicked(mouseX, mouseY, button);
|
super.mouseClicked(mouseX, mouseY, button);
|
||||||
|
|
||||||
int bottom = height - 40;
|
int bottom = height - 40;
|
||||||
|
@ -360,21 +371,24 @@ public class GuiSkins extends GameGui {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||||
updateCounter -= (lastMouseX - mouseX);
|
if (clearMessage()) {
|
||||||
|
updateCounter -= (lastMouseX - mouseX);
|
||||||
|
}
|
||||||
lastMouseX = mouseX;
|
lastMouseX = mouseX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void keyTyped(char keyChar, int keyCode) throws IOException {
|
protected void keyTyped(char keyChar, int keyCode) throws IOException {
|
||||||
if (openFileThread == null && !uploadingSkin) {
|
if (clearMessage()) {
|
||||||
|
|
||||||
if (keyCode == Keyboard.KEY_LEFT) {
|
if (keyCode == Keyboard.KEY_LEFT) {
|
||||||
updateCounter -= 5;
|
updateCounter -= 5;
|
||||||
} else if (keyCode == Keyboard.KEY_RIGHT) {
|
} else if (keyCode == Keyboard.KEY_RIGHT) {
|
||||||
updateCounter += 5;
|
updateCounter += 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.keyTyped(keyChar, keyCode);
|
if (openFileThread == null && !uploadingSkin) {
|
||||||
|
super.keyTyped(keyChar, keyCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +411,6 @@ public class GuiSkins extends GameGui {
|
||||||
|
|
||||||
super.drawContents(mouseX, mouseY, partialTick);
|
super.drawContents(mouseX, mouseY, partialTick);
|
||||||
|
|
||||||
popAttrib();
|
|
||||||
enableClipping(bottom);
|
enableClipping(bottom);
|
||||||
|
|
||||||
float yPos = height * 0.75F;
|
float yPos = height * 0.75F;
|
||||||
|
@ -406,33 +419,19 @@ public class GuiSkins extends GameGui {
|
||||||
float scale = height / 4;
|
float scale = height / 4;
|
||||||
float lookX = mid - mouseX;
|
float lookX = mid - mouseX;
|
||||||
|
|
||||||
mc.getTextureManager().bindTexture(localPlayer.getLocal(Type.SKIN).getTexture());
|
|
||||||
|
|
||||||
renderPlayerModel(localPlayer, xPos1, yPos, scale, horizon - mouseY, lookX, partialTick);
|
renderPlayerModel(localPlayer, xPos1, yPos, scale, horizon - mouseY, lookX, partialTick);
|
||||||
|
|
||||||
mc.getTextureManager().bindTexture(remotePlayer.getLocal(Type.SKIN).getTexture());
|
|
||||||
|
|
||||||
renderPlayerModel(remotePlayer, xPos2, yPos, scale, horizon - mouseY, lookX, partialTick);
|
renderPlayerModel(remotePlayer, xPos2, yPos, scale, horizon - mouseY, lookX, partialTick);
|
||||||
|
|
||||||
disableClipping();
|
disableClipping();
|
||||||
|
|
||||||
fontRenderer.drawStringWithShadow(format("hdskins.local"), 34, 34, 0xffffff);
|
|
||||||
fontRenderer.drawStringWithShadow(format("hdskins.server"), width / 2 + 34, 34, 0xffffff);
|
|
||||||
|
|
||||||
disableDepth();
|
|
||||||
enableBlend();
|
|
||||||
depthMask(false);
|
|
||||||
|
|
||||||
if (!localPlayer.isUsingLocalTexture()) {
|
if (!localPlayer.isUsingLocalTexture()) {
|
||||||
int opacity = fontRenderer.getStringWidth(skinMessage) / 2;
|
|
||||||
|
|
||||||
Gui.drawRect(40, height / 2 - 12, width / 2 - 40, height / 2 + 12, 0xB0000000);
|
Gui.drawRect(40, height / 2 - 12, width / 2 - 40, height / 2 + 12, 0xB0000000);
|
||||||
fontRenderer.drawStringWithShadow(skinMessage, (int) (xPos1 - opacity), height / 2 - 4, 0xffffff);
|
drawCenteredString(fontRenderer, localMessage, (int)xPos1, height / 2 - 4, 0xffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fetchingSkin) {
|
if (fetchingSkin) {
|
||||||
|
|
||||||
int lineHeight = throttledByMojang ? 16 : 12;
|
int lineHeight = throttledByMojang ? 18 : 12;
|
||||||
|
|
||||||
Gui.drawRect((int) (xPos2 - width / 4 + 40), height / 2 - lineHeight, width - 40, height / 2 + lineHeight, 0xB0000000);
|
Gui.drawRect((int) (xPos2 - width / 4 + 40), height / 2 - lineHeight, width - 40, height / 2 + lineHeight, 0xB0000000);
|
||||||
|
|
||||||
|
@ -444,30 +443,29 @@ public class GuiSkins extends GameGui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uploadingSkin || uploadOpacity > 0) {
|
if (uploadingSkin || showMessage || uploadOpacity > 0) {
|
||||||
if (!uploadingSkin) {
|
if (!uploadingSkin && !showMessage) {
|
||||||
uploadOpacity -= deltaTime / 20;
|
uploadOpacity -= deltaTime / 10;
|
||||||
} else if (uploadOpacity < 1) {
|
} else if (uploadOpacity < 1) {
|
||||||
uploadOpacity += deltaTime / 10;
|
uploadOpacity += deltaTime / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uploadOpacity > 1) {
|
uploadOpacity = MathHelper.clamp(uploadOpacity, 0, 1);
|
||||||
uploadOpacity = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int opacity = Math.min(180, (int) (uploadOpacity * 180)) & 255;
|
|
||||||
if (uploadOpacity > 0) {
|
|
||||||
Gui.drawRect(0, 0, width, height, opacity << 24);
|
|
||||||
if (uploadingSkin) {
|
|
||||||
drawCenteredString(fontRenderer, skinUploadMessage, width / 2, height / 2, opacity << 24 | 0xffffff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uploadError != null) {
|
if (uploadOpacity > 0) {
|
||||||
Gui.drawRect(0, 0, width, height, 0xB0000000);
|
int opacity = (Math.min(180, (int) (uploadOpacity * 180)) & 255) << 24;
|
||||||
drawCenteredString(fontRenderer, format("hdskins.failed"), width / 2, height / 2 - 10, 0xFFFFFF55);
|
|
||||||
drawCenteredString(fontRenderer, uploadError, width / 2, height / 2 + 2, 0xFFFF5555);
|
Gui.drawRect(0, 0, width, height, opacity);
|
||||||
|
|
||||||
|
if (uploadingSkin) {
|
||||||
|
drawCenteredString(fontRenderer, uploadMessage, width / 2, height / 2, 0xffffff);
|
||||||
|
} else if (showMessage) {
|
||||||
|
int blockHeight = (height - fontRenderer.getWordWrappedHeight(uploadError, width - 10)) / 2;
|
||||||
|
|
||||||
|
drawCenteredString(fontRenderer, format("hdskins.failed"), width / 2, blockHeight - fontRenderer.FONT_HEIGHT * 2, 0xffff55);
|
||||||
|
fontRenderer.drawSplitString(uploadError, 5, blockHeight, width - 10, 0xff5555);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
depthMask(true);
|
depthMask(true);
|
||||||
|
@ -475,6 +473,8 @@ public class GuiSkins extends GameGui {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderPlayerModel(EntityPlayerModel thePlayer, float xPosition, float yPosition, float scale, float mouseY, float mouseX, float partialTick) {
|
private void renderPlayerModel(EntityPlayerModel thePlayer, float xPosition, float yPosition, float scale, float mouseY, float mouseX, float partialTick) {
|
||||||
|
mc.getTextureManager().bindTexture(thePlayer.getLocal(Type.SKIN).getTexture());
|
||||||
|
|
||||||
enableColorMaterial();
|
enableColorMaterial();
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
translate(xPosition, yPosition, 300);
|
translate(xPosition, yPosition, 300);
|
||||||
|
@ -505,6 +505,8 @@ public class GuiSkins extends GameGui {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableClipping(int yBottom) {
|
private void enableClipping(int yBottom) {
|
||||||
|
popAttrib();
|
||||||
|
|
||||||
if (doubleBuffer == null) {
|
if (doubleBuffer == null) {
|
||||||
doubleBuffer = BufferUtils.createByteBuffer(32).asDoubleBuffer();
|
doubleBuffer = BufferUtils.createByteBuffer(32).asDoubleBuffer();
|
||||||
}
|
}
|
||||||
|
@ -524,6 +526,10 @@ public class GuiSkins extends GameGui {
|
||||||
private void disableClipping() {
|
private void disableClipping() {
|
||||||
GL11.glDisable(GL11.GL_CLIP_PLANE1);
|
GL11.glDisable(GL11.GL_CLIP_PLANE1);
|
||||||
GL11.glDisable(GL11.GL_CLIP_PLANE0);
|
GL11.glDisable(GL11.GL_CLIP_PLANE0);
|
||||||
|
|
||||||
|
disableDepth();
|
||||||
|
enableBlend();
|
||||||
|
depthMask(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isPowerOfTwo(int number) {
|
private static boolean isPowerOfTwo(int number) {
|
||||||
|
@ -532,7 +538,8 @@ public class GuiSkins extends GameGui {
|
||||||
|
|
||||||
private void punchServer(String uploadMsg, @Nullable URI path) {
|
private void punchServer(String uploadMsg, @Nullable URI path) {
|
||||||
uploadingSkin = true;
|
uploadingSkin = true;
|
||||||
skinUploadMessage = format(uploadMsg);
|
uploadMessage = format(uploadMsg);
|
||||||
|
btnUpload.enabled = canUpload();
|
||||||
|
|
||||||
HDSkinManager.INSTANCE.getGatewayServer()
|
HDSkinManager.INSTANCE.getGatewayServer()
|
||||||
.uploadSkin(mc.getSession(), path, textureType, getMetadata())
|
.uploadSkin(mc.getSession(), path, textureType, getMetadata())
|
||||||
|
@ -544,31 +551,25 @@ public class GuiSkins extends GameGui {
|
||||||
return ImmutableMap.of("model", thinArmType ? "slim" : "default");
|
return ImmutableMap.of("model", thinArmType ? "slim" : "default");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUploadError(@Nullable String error) {
|
|
||||||
uploadError = error;
|
|
||||||
btnUpload.enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Void onUploadFailure(Throwable t) {
|
private Void onUploadFailure(Throwable t) {
|
||||||
t = Throwables.getRootCause(t);
|
t = Throwables.getRootCause(t);
|
||||||
LogManager.getLogger().warn("Upload failed", t);
|
LogManager.getLogger().warn("Upload failed", t);
|
||||||
setUploadError(t.toString());
|
uploadError = t.toString();
|
||||||
|
showMessage = true;
|
||||||
uploadingSkin = false;
|
uploadingSkin = false;
|
||||||
|
btnUpload.enabled = canUpload();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onUploadComplete(SkinUploadResponse response) {
|
private void onUploadComplete(SkinUploadResponse response) {
|
||||||
LiteLoaderLogger.info("Upload completed with: %s", response);
|
LiteLoaderLogger.info("Upload completed with: %s", response);
|
||||||
uploadingSkin = false;
|
|
||||||
pendingRemoteSkinRefresh = true;
|
pendingRemoteSkinRefresh = true;
|
||||||
|
uploadingSkin = false;
|
||||||
|
btnUpload.enabled = canUpload();
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
protected boolean canUpload() {
|
||||||
try {
|
return selectedSkin != null && !uploadingSkin && !pendingRemoteSkinRefresh;
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package com.voxelmodpack.hdskins.mixin;
|
package com.voxelmodpack.hdskins.mixin;
|
||||||
|
|
||||||
|
import com.minelittlepony.gui.IconicButton;
|
||||||
import com.minelittlepony.gui.IActionable;
|
import com.minelittlepony.gui.IActionable;
|
||||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||||
import com.voxelmodpack.hdskins.gui.GuiItemStackButton;
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiMainMenu;
|
import net.minecraft.client.gui.GuiMainMenu;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
@ -18,9 +19,9 @@ public class MixinGuiMainMenu extends GuiScreen {
|
||||||
|
|
||||||
@Inject(method = "initGui()V", at = @At("RETURN"))
|
@Inject(method = "initGui()V", at = @At("RETURN"))
|
||||||
private void onInit(CallbackInfo ci) {
|
private void onInit(CallbackInfo ci) {
|
||||||
addButton(new GuiItemStackButton(width - 50, height - 50, new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb, sender -> {
|
addButton(new IconicButton(width - 50, height - 50, sender -> {
|
||||||
mc.displayGuiScreen(HDSkinManager.INSTANCE.createSkinsGui());
|
mc.displayGuiScreen(HDSkinManager.INSTANCE.createSkinsGui());
|
||||||
}));
|
}).setIcon(new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "actionPerformed(Lnet/minecraft/client/gui/GuiButton;)V", at = @At("RETURN"))
|
@Inject(method = "actionPerformed(Lnet/minecraft/client/gui/GuiButton;)V", at = @At("RETURN"))
|
||||||
|
|
|
@ -3,11 +3,11 @@ package com.minelittlepony.hdskins.gui;
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.MineLittlePony;
|
||||||
import com.minelittlepony.PonyManager;
|
import com.minelittlepony.PonyManager;
|
||||||
import com.minelittlepony.gui.Button;
|
import com.minelittlepony.gui.Button;
|
||||||
|
import com.minelittlepony.gui.IconicButton;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||||
import com.voxelmodpack.hdskins.gui.EntityPlayerModel;
|
import com.voxelmodpack.hdskins.gui.EntityPlayerModel;
|
||||||
import com.voxelmodpack.hdskins.gui.GuiItemStackButton;
|
|
||||||
import com.voxelmodpack.hdskins.gui.GuiSkins;
|
import com.voxelmodpack.hdskins.gui.GuiSkins;
|
||||||
|
|
||||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||||
|
@ -43,13 +43,13 @@ public class GuiSkinsMineLP extends GuiSkins {
|
||||||
public void initGui() {
|
public void initGui() {
|
||||||
super.initGui();
|
super.initGui();
|
||||||
|
|
||||||
addButton(btnModeWet = new GuiItemStackButton(width - 25, 137, new ItemStack(Items.WATER_BUCKET), sender -> {
|
addButton(btnModeWet = new IconicButton(width - 25, 137, sender -> {
|
||||||
setWet(true);
|
setWet(true);
|
||||||
})).setEnabled(!isWet).setTooltip("minelp.mode.wet");
|
}).setIcon(new ItemStack(Items.WATER_BUCKET))).setEnabled(!isWet).setTooltip("minelp.mode.wet");
|
||||||
|
|
||||||
addButton(btnModeDry = new GuiItemStackButton(width - 25, 118, new ItemStack(Items.BUCKET), sender -> {
|
addButton(btnModeDry = new IconicButton(width - 25, 118, sender -> {
|
||||||
setWet(false);
|
setWet(false);
|
||||||
})).setEnabled(isWet).setTooltip("minelp.mode.dry");
|
}).setIcon(new ItemStack(Items.BUCKET))).setEnabled(isWet).setTooltip("minelp.mode.dry");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue