mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-29 23:48:00 +01:00
Rewrite GuiSkins
This commit is contained in:
parent
34dae0168d
commit
83659d80ca
14 changed files with 200 additions and 191 deletions
|
@ -1,14 +1,22 @@
|
||||||
package com.minelittlepony.gui;
|
package com.minelittlepony.gui;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
|
|
||||||
public class Button extends GuiButton implements IActionable {
|
public class Button extends GuiButton implements IActionable {
|
||||||
|
|
||||||
private IGUIAction<Button> action;
|
private IGuiAction<Button> action;
|
||||||
|
|
||||||
public Button(int x, int y, int width, int height, String label, IGUIAction<Button> callback) {
|
private List<String> tooltip = null;
|
||||||
super(0, x, y, width, height, GameGui.translate(label));
|
|
||||||
action = callback;
|
@SuppressWarnings("unchecked")
|
||||||
|
public Button(int x, int y, int width, int height, String label, IGuiAction<? extends Button> callback) {
|
||||||
|
super(0, x, y, width, height, GameGui.format(label));
|
||||||
|
action = (IGuiAction<Button>)callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,4 +24,24 @@ public class Button extends GuiButton implements IActionable {
|
||||||
action.perform(this);
|
action.perform(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Button setEnabled(boolean enable) {
|
||||||
|
enabled = enable;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button setTooltip(List<String> tooltip) {
|
||||||
|
this.tooltip = tooltip;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button setTooltip(String tooltip) {
|
||||||
|
return setTooltip(Splitter.on("\r\n").splitToList(GameGui.format(tooltip)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||||
|
super.drawButton(mc, mouseX, mouseY, partialTicks);
|
||||||
|
if (visible && isMouseOver() && tooltip != null) {
|
||||||
|
mc.currentScreen.drawHoveringText(tooltip, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@ import net.minecraft.client.resources.I18n;
|
||||||
*/
|
*/
|
||||||
public class Checkbox extends GuiCheckbox implements IActionable {
|
public class Checkbox extends GuiCheckbox implements IActionable {
|
||||||
|
|
||||||
private final IGUIAction<Boolean> action;
|
private final IGuiCallback<Boolean> action;
|
||||||
|
|
||||||
public Checkbox(int x, int y, String displayString, boolean value, IGUIAction<Boolean> callback) {
|
public Checkbox(int x, int y, String displayString, boolean value, IGuiCallback<Boolean> callback) {
|
||||||
super(0, x, y, I18n.format(displayString));
|
super(0, x, y, I18n.format(displayString));
|
||||||
action = callback;
|
action = callback;
|
||||||
checked = value;
|
checked = value;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package com.minelittlepony.gui;
|
package com.minelittlepony.gui;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
|
@ -9,13 +7,13 @@ import net.minecraft.client.resources.I18n;
|
||||||
public abstract class GameGui extends GuiScreen {
|
public abstract class GameGui extends GuiScreen {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void actionPerformed(GuiButton button) throws IOException {
|
protected void actionPerformed(GuiButton button) {
|
||||||
if (button instanceof IActionable) {
|
if (button instanceof IActionable) {
|
||||||
((IActionable)button).perform();
|
((IActionable)button).perform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String translate(String string) {
|
protected static String format(String string) {
|
||||||
return I18n.format(string);
|
return I18n.format(string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
15
src/common/java/com/minelittlepony/gui/IGuiAction.java
Normal file
15
src/common/java/com/minelittlepony/gui/IGuiAction.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package com.minelittlepony.gui;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response actions for UI events.
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface IGuiAction<T> {
|
||||||
|
/**
|
||||||
|
* Performs this action now.
|
||||||
|
*
|
||||||
|
* @param value New Value of the field being changed
|
||||||
|
* @return Adjusted value the field must take on
|
||||||
|
*/
|
||||||
|
void perform(T sender);
|
||||||
|
}
|
15
src/common/java/com/minelittlepony/gui/IGuiCallback.java
Normal file
15
src/common/java/com/minelittlepony/gui/IGuiCallback.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package com.minelittlepony.gui;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response actions for UI events.
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface IGuiCallback<T> {
|
||||||
|
/**
|
||||||
|
* Performs this action now.
|
||||||
|
*
|
||||||
|
* @param value New Value of the field being changed
|
||||||
|
* @return Adjusted value the field must take on
|
||||||
|
*/
|
||||||
|
T perform(T value);
|
||||||
|
}
|
|
@ -2,7 +2,6 @@ package com.minelittlepony.gui;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple label for drawing text to a gui screen.
|
* A simple label for drawing text to a gui screen.
|
||||||
|
@ -35,9 +34,9 @@ public class Label extends GuiButton {
|
||||||
|
|
||||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||||
if (center) {
|
if (center) {
|
||||||
drawCenteredString(mc.fontRenderer, I18n.format(text), x, y, color);
|
drawCenteredString(mc.fontRenderer, GameGui.format(text), x, y, color);
|
||||||
} else {
|
} else {
|
||||||
drawString(mc.fontRenderer, I18n.format(text), x, y, color);
|
drawString(mc.fontRenderer, GameGui.format(text), x, y, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public abstract class SettingsPanel extends GameGui implements ConfigPanel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPanelTitle() {
|
public String getPanelTitle() {
|
||||||
return translate(getTitle());
|
return format(getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class Slider extends GuiSlider {
|
||||||
|
|
||||||
private static Responder callback;
|
private static Responder callback;
|
||||||
|
|
||||||
public Slider(int x, int y, float minIn, float maxIn, float defaultValue, GuiSlider.FormatHelper formatter, IGUIAction<Float> action) {
|
public Slider(int x, int y, float minIn, float maxIn, float defaultValue, GuiSlider.FormatHelper formatter, IGuiCallback<Float> action) {
|
||||||
super(callback = new Responder(action), 0, x, y, "", minIn, maxIn, defaultValue, formatter);
|
super(callback = new Responder(action), 0, x, y, "", minIn, maxIn, defaultValue, formatter);
|
||||||
callback.owner = this;
|
callback.owner = this;
|
||||||
callback = null;
|
callback = null;
|
||||||
|
@ -21,11 +21,11 @@ public class Slider extends GuiSlider {
|
||||||
|
|
||||||
private static final class Responder implements GuiResponder {
|
private static final class Responder implements GuiResponder {
|
||||||
|
|
||||||
private final IGUIAction<Float> action;
|
private final IGuiCallback<Float> action;
|
||||||
|
|
||||||
private Slider owner;
|
private Slider owner;
|
||||||
|
|
||||||
private Responder(IGUIAction<Float> callback) {
|
private Responder(IGuiCallback<Float> callback) {
|
||||||
action = callback;
|
action = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,26 @@
|
||||||
package com.voxelmodpack.hdskins.gui;
|
package com.voxelmodpack.hdskins.gui;
|
||||||
|
|
||||||
|
import com.minelittlepony.gui.Button;
|
||||||
|
import com.minelittlepony.gui.IGuiAction;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class GuiItemStackButton extends GuiButton {
|
public class GuiItemStackButton extends Button {
|
||||||
|
|
||||||
private ItemStack itemStack;
|
private ItemStack itemStack;
|
||||||
|
|
||||||
public GuiItemStackButton(int buttonId, int x, int y, ItemStack itemStack) {
|
public GuiItemStackButton(int x, int y, ItemStack itemStack, IGuiAction<GuiItemStackButton> callback) {
|
||||||
super(buttonId, x, y, 20, 20, "");
|
super(x, y, 20, 20, "", callback);
|
||||||
this.itemStack = itemStack;
|
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
|
@Override
|
||||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||||
super.drawButton(mc, mouseX, mouseY, partialTicks);
|
super.drawButton(mc, mouseX, mouseY, partialTicks);
|
||||||
|
|
|
@ -7,6 +7,9 @@ import static net.minecraft.client.renderer.GlStateManager.*;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Throwables;
|
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.GameGui;
|
||||||
|
import com.minelittlepony.gui.Label;
|
||||||
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;
|
||||||
|
@ -19,10 +22,8 @@ import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.Gui;
|
import net.minecraft.client.gui.Gui;
|
||||||
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.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.inventory.EntityEquipmentSlot;
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -43,23 +44,19 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JFileChooser;
|
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
public class GuiSkins extends GuiScreen {
|
public class GuiSkins extends GameGui {
|
||||||
|
|
||||||
private static final int MAX_SKIN_DIMENSION = 1024;
|
private static final int MAX_SKIN_DIMENSION = 1024;
|
||||||
private int updateCounter = 0;
|
private int updateCounter = 0;
|
||||||
|
|
||||||
private GuiButton btnBrowse;
|
private Button btnUpload;
|
||||||
private GuiButton btnUpload;
|
private Button btnClear;
|
||||||
private GuiButton btnClear;
|
|
||||||
private GuiButton btnBack;
|
|
||||||
private GuiButton btnModeSkin;
|
|
||||||
private GuiButton btnModeSkinnySkin;
|
|
||||||
private GuiButton btnModeElytra;
|
|
||||||
|
|
||||||
private GuiButton btnAbout;
|
private Button btnModeSkin;
|
||||||
|
private Button btnModeSkinnySkin;
|
||||||
|
private Button btnModeElytra;
|
||||||
|
|
||||||
protected EntityPlayerModel localPlayer;
|
protected EntityPlayerModel localPlayer;
|
||||||
protected EntityPlayerModel remotePlayer;
|
protected EntityPlayerModel remotePlayer;
|
||||||
|
@ -68,8 +65,8 @@ public class GuiSkins extends GuiScreen {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String uploadError;
|
private String uploadError;
|
||||||
private volatile String skinMessage = I18n.format("hdskins.choose");
|
private volatile String skinMessage = format("hdskins.choose");
|
||||||
private String skinUploadMessage = I18n.format("hdskins.request");
|
private String skinUploadMessage = format("hdskins.request");
|
||||||
|
|
||||||
private volatile boolean fetchingSkin;
|
private volatile boolean fetchingSkin;
|
||||||
private volatile boolean uploadingSkin;
|
private volatile boolean uploadingSkin;
|
||||||
|
@ -196,29 +193,57 @@ public class GuiSkins extends GuiScreen {
|
||||||
|
|
||||||
panorama.init();
|
panorama.init();
|
||||||
|
|
||||||
buttonList.clear();
|
addButton(new Label(width / 2, 10, "hdskins.manager", 0xffffff));
|
||||||
buttonList.add(btnBrowse = new GuiButton(0, 30, height - 36, 60, 20, "Browse..."));
|
|
||||||
buttonList.add(btnUpload = new GuiButton(1, width / 2 - 24, height / 2 - 10, 48, 20, ">>"));
|
|
||||||
buttonList.add(btnClear = new GuiButton(2, width - 90, height - 36, 60, 20, "Clear"));
|
|
||||||
buttonList.add(btnBack = new GuiButton(3, width / 2 - 50, height - 36, 100, 20, "Close"));
|
|
||||||
|
|
||||||
ItemStack skin = new ItemStack(Items.LEATHER_LEGGINGS);
|
addButton(new Button(30, height - 36, 60, 20, "Browse...", sender ->{
|
||||||
Items.LEATHER_LEGGINGS.setColor(skin, 0x3c5dcb);
|
selectedSkin = null;
|
||||||
buttonList.add(btnModeSkin = new GuiItemStackButton(4, 2, 2, skin));
|
localPlayer.releaseTextures();
|
||||||
skin = new ItemStack(Items.LEATHER_LEGGINGS);
|
openFileThread = new ThreadOpenFilePNG(mc, format("hdskins.open.title"), (fileDialog, dialogResult) -> {
|
||||||
Items.LEATHER_LEGGINGS.setColor(skin, 0xfff500);
|
openFileThread = null;
|
||||||
buttonList.add(btnModeElytra = new GuiItemStackButton(5, 2, 52, new ItemStack(Items.ELYTRA)));
|
sender.enabled = true;
|
||||||
buttonList.add(btnModeSkinnySkin = new GuiItemStackButton(6, 2, 21, skin));
|
if (dialogResult == 0) {
|
||||||
|
loadLocalFile(fileDialog.getSelectedFile());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
openFileThread.start();
|
||||||
|
sender.enabled = false;
|
||||||
|
})).setEnabled(!mc.isFullScreen());
|
||||||
|
|
||||||
buttonList.add(btnAbout = new GuiButton(-1, width - 25, height - 25, 20, 20, "?"));
|
addButton(btnUpload = new Button(width / 2 - 24, height / 2 - 10, 48, 20, ">>", sender -> {
|
||||||
|
if (selectedSkin != null) {
|
||||||
|
punchServer("hdskins.upload", selectedSkin.toURI());
|
||||||
|
sender.enabled = false;
|
||||||
|
} else {
|
||||||
|
setUploadError(format("hdskins.error.select"));
|
||||||
|
}
|
||||||
|
})).setEnabled(false);
|
||||||
|
|
||||||
btnUpload.enabled = false;
|
addButton(btnClear = new Button(width - 90, height - 36, 60, 20, "Clear", sender -> {
|
||||||
btnBrowse.enabled = !mc.isFullScreen();
|
if (remotePlayer.isTextureSetupComplete()) {
|
||||||
|
punchServer("hdskins.request", null);
|
||||||
|
btnUpload.enabled = selectedSkin != null;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
btnModeSkin.enabled = thinArmType;
|
addButton(new Button(width / 2 - 50, height - 36, 100, 20, "Close", sender -> {
|
||||||
btnModeSkinnySkin.enabled = !thinArmType;
|
mc.displayGuiScreen(new GuiMainMenu());
|
||||||
btnModeElytra.enabled = textureType == SKIN;
|
}));
|
||||||
|
|
||||||
|
addButton(btnModeSkin = new GuiItemStackButton(2, 2, new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb, sender -> {
|
||||||
|
switchSkinMode(sender, false, SKIN, ItemStack.EMPTY);
|
||||||
|
})).setEnabled(thinArmType).setTooltip("hdskins.mode.skin");
|
||||||
|
|
||||||
|
addButton(btnModeElytra = new GuiItemStackButton(2, 52, new ItemStack(Items.ELYTRA), sender -> {
|
||||||
|
switchSkinMode(sender, thinArmType, ELYTRA, new ItemStack(Items.ELYTRA));
|
||||||
|
})).setEnabled(textureType == SKIN).setTooltip("hdskins.mode.elytra");
|
||||||
|
|
||||||
|
addButton(btnModeSkinnySkin = new GuiItemStackButton(2, 21, new ItemStack(Items.LEATHER_LEGGINGS), 0xfff500, sender -> {
|
||||||
|
switchSkinMode(sender, true, SKIN, ItemStack.EMPTY);
|
||||||
|
})).setEnabled(!thinArmType).setTooltip("hdskins.mode.skinny");
|
||||||
|
|
||||||
|
addButton(new Button(width - 25, height - 25, 20, 20, "?", sender -> {
|
||||||
|
|
||||||
|
})).setTooltip(Splitter.on("\r\n").splitToList(HDSkinManager.INSTANCE.getGatewayServer().toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -231,36 +256,28 @@ public class GuiSkins extends GuiScreen {
|
||||||
GLWindow.current().clearDropTargetListener();
|
GLWindow.current().clearDropTargetListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onFileOpenDialogClosed(JFileChooser fileDialog, int dialogResult) {
|
|
||||||
openFileThread = null;
|
|
||||||
btnBrowse.enabled = true;
|
|
||||||
if (dialogResult == 0) {
|
|
||||||
loadLocalFile(fileDialog.getSelectedFile());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadLocalFile(File skinFile) {
|
private void loadLocalFile(File skinFile) {
|
||||||
Minecraft.getMinecraft().addScheduledTask(localPlayer::releaseTextures);
|
Minecraft.getMinecraft().addScheduledTask(localPlayer::releaseTextures);
|
||||||
|
|
||||||
if (!skinFile.exists()) {
|
if (!skinFile.exists()) {
|
||||||
skinMessage = I18n.format("hdskins.error.unreadable");
|
skinMessage = 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 = I18n.format("hdskins.error.ext");
|
skinMessage = 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 = I18n.format("hdskins.error.open");
|
skinMessage = format("hdskins.error.open");
|
||||||
} else if (!acceptsSkinDimensions(chosenImage.getWidth(), chosenImage.getHeight())) {
|
} else if (!acceptsSkinDimensions(chosenImage.getWidth(), chosenImage.getHeight())) {
|
||||||
skinMessage = I18n.format("hdskins.error.invalid");
|
skinMessage = format("hdskins.error.invalid");
|
||||||
} else {
|
} else {
|
||||||
synchronized (skinLock) {
|
synchronized (skinLock) {
|
||||||
pendingSkinFile = skinFile;
|
pendingSkinFile = skinFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException var6) {
|
} catch (IOException var6) {
|
||||||
skinMessage = I18n.format("hdskins.error.open");
|
skinMessage = format("hdskins.error.open");
|
||||||
var6.printStackTrace();
|
var6.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,63 +287,35 @@ public class GuiSkins extends GuiScreen {
|
||||||
return isPowerOfTwo(w) && w == h * 2 || w == h && w <= MAX_SKIN_DIMENSION && h <= MAX_SKIN_DIMENSION;
|
return isPowerOfTwo(w) && w == h * 2 || w == h && w <= MAX_SKIN_DIMENSION && h <= MAX_SKIN_DIMENSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void switchSkinMode(Button sender, boolean thin, Type newType, ItemStack stack) {
|
||||||
|
thinArmType = thin;
|
||||||
|
textureType = newType;
|
||||||
|
|
||||||
|
btnModeSkin.enabled = thinArmType;
|
||||||
|
btnModeSkinnySkin.enabled = !thinArmType;
|
||||||
|
btnModeElytra.enabled = textureType == SKIN;
|
||||||
|
|
||||||
|
sender.enabled = false;
|
||||||
|
|
||||||
|
// clear currently selected skin
|
||||||
|
selectedSkin = null;
|
||||||
|
localPlayer.releaseTextures();
|
||||||
|
|
||||||
|
// put on or take off the elytra
|
||||||
|
localPlayer.setItemStackToSlot(EntityEquipmentSlot.CHEST, stack);
|
||||||
|
remotePlayer.setItemStackToSlot(EntityEquipmentSlot.CHEST, stack);
|
||||||
|
|
||||||
|
localPlayer.setPreviewThinArms(thinArmType);
|
||||||
|
remotePlayer.setPreviewThinArms(thinArmType);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void actionPerformed(GuiButton guiButton) {
|
protected void actionPerformed(GuiButton guiButton) {
|
||||||
if (openFileThread == null && !uploadingSkin) {
|
if (openFileThread == null && !uploadingSkin) {
|
||||||
if (uploadError != null) {
|
if (uploadError != null) {
|
||||||
uploadError = null;
|
uploadError = null;
|
||||||
} else {
|
} else {
|
||||||
if (guiButton.id == btnBrowse.id) {
|
super.actionPerformed(guiButton);
|
||||||
selectedSkin = null;
|
|
||||||
localPlayer.releaseTextures();
|
|
||||||
openFileThread = new ThreadOpenFilePNG(mc, I18n.format("hdskins.open.title"), this::onFileOpenDialogClosed);
|
|
||||||
openFileThread.start();
|
|
||||||
guiButton.enabled = false;
|
|
||||||
} else if (guiButton.id == btnUpload.id) {
|
|
||||||
if (selectedSkin != null) {
|
|
||||||
punchServer("hdskins.upload", selectedSkin.toURI());
|
|
||||||
btnUpload.enabled = false;
|
|
||||||
} else {
|
|
||||||
setUploadError(I18n.format("hdskins.error.select"));
|
|
||||||
}
|
|
||||||
} else if (guiButton.id == btnClear.id && remotePlayer.isTextureSetupComplete()) {
|
|
||||||
punchServer("hdskins.request", null);
|
|
||||||
btnUpload.enabled = selectedSkin != null;
|
|
||||||
} else if (guiButton.id == btnBack.id) {
|
|
||||||
mc.displayGuiScreen(new GuiMainMenu());
|
|
||||||
} else if (guiButton.id == btnModeSkin.id || guiButton.id == btnModeElytra.id || guiButton.id == btnModeSkinnySkin.id) {
|
|
||||||
ItemStack stack;
|
|
||||||
|
|
||||||
if (guiButton.id == btnModeSkin.id) {
|
|
||||||
thinArmType = false;
|
|
||||||
textureType = SKIN;
|
|
||||||
stack = ItemStack.EMPTY;
|
|
||||||
} else if (guiButton.id == btnModeSkinnySkin.id) {
|
|
||||||
thinArmType = true;
|
|
||||||
textureType = SKIN;
|
|
||||||
stack = ItemStack.EMPTY;
|
|
||||||
} else {
|
|
||||||
textureType = ELYTRA;
|
|
||||||
stack = new ItemStack(Items.ELYTRA);
|
|
||||||
}
|
|
||||||
|
|
||||||
btnModeSkin.enabled = thinArmType;
|
|
||||||
btnModeSkinnySkin.enabled = !thinArmType;
|
|
||||||
btnModeElytra.enabled = textureType == SKIN;
|
|
||||||
|
|
||||||
guiButton.enabled = false;
|
|
||||||
// clear currently selected skin
|
|
||||||
selectedSkin = null;
|
|
||||||
localPlayer.releaseTextures();
|
|
||||||
|
|
||||||
// put on or take off the elytra
|
|
||||||
localPlayer.setItemStackToSlot(EntityEquipmentSlot.CHEST, stack);
|
|
||||||
remotePlayer.setItemStackToSlot(EntityEquipmentSlot.CHEST, stack);
|
|
||||||
|
|
||||||
localPlayer.setPreviewThinArms(thinArmType);
|
|
||||||
remotePlayer.setPreviewThinArms(thinArmType);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -408,10 +397,8 @@ public class GuiSkins extends GuiScreen {
|
||||||
|
|
||||||
disableClipping();
|
disableClipping();
|
||||||
|
|
||||||
drawCenteredString(fontRenderer, I18n.format("hdskins.manager"), width / 2, 10, 0xffffff);
|
fontRenderer.drawStringWithShadow(format("hdskins.local"), 34, 34, 0xffffff);
|
||||||
|
fontRenderer.drawStringWithShadow(format("hdskins.server"), width / 2 + 34, 34, 0xffffff);
|
||||||
fontRenderer.drawStringWithShadow(I18n.format("hdskins.local"), 34, 34, 0xffffff);
|
|
||||||
fontRenderer.drawStringWithShadow(I18n.format("hdskins.server"), width / 2 + 34, 34, 0xffffff);
|
|
||||||
|
|
||||||
disableDepth();
|
disableDepth();
|
||||||
enableBlend();
|
enableBlend();
|
||||||
|
@ -423,23 +410,6 @@ public class GuiSkins extends GuiScreen {
|
||||||
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);
|
fontRenderer.drawStringWithShadow(skinMessage, (int) (xPos1 - opacity), height / 2 - 4, 0xffffff);
|
||||||
}
|
}
|
||||||
if (btnModeSkin.isMouseOver() || btnModeElytra.isMouseOver() || btnModeSkinnySkin.isMouseOver()) {
|
|
||||||
int y = Math.max(mouseY, 16);
|
|
||||||
String text;
|
|
||||||
|
|
||||||
if (btnModeSkin.isMouseOver()) {
|
|
||||||
text = "hdskins.mode.skin";
|
|
||||||
} else if (btnModeSkinnySkin.isMouseOver()) {
|
|
||||||
text = "hdskins.mode.skinny";
|
|
||||||
} else {
|
|
||||||
text = "hdskins.mode.elytra";
|
|
||||||
}
|
|
||||||
|
|
||||||
drawHoveringText(I18n.format(text), mouseX, y);
|
|
||||||
}
|
|
||||||
if (btnAbout.isMouseOver()) {
|
|
||||||
drawHoveringText(Splitter.on("\r\n").splitToList(HDSkinManager.INSTANCE.getGatewayServer().toString()), mouseX, mouseY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fetchingSkin) {
|
if (fetchingSkin) {
|
||||||
|
|
||||||
|
@ -448,10 +418,10 @@ public class GuiSkins extends GuiScreen {
|
||||||
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);
|
||||||
|
|
||||||
if (throttledByMojang) {
|
if (throttledByMojang) {
|
||||||
drawCenteredString(fontRenderer, I18n.format("hdskins.error.mojang"), (int)xPos2, height / 2 - 10, 0xffffff);
|
drawCenteredString(fontRenderer, format("hdskins.error.mojang"), (int)xPos2, height / 2 - 10, 0xffffff);
|
||||||
drawCenteredString(fontRenderer, I18n.format("hdskins.error.mojang.wait"), (int)xPos2, height / 2 + 2, 0xffffff);
|
drawCenteredString(fontRenderer, format("hdskins.error.mojang.wait"), (int)xPos2, height / 2 + 2, 0xffffff);
|
||||||
} else {
|
} else {
|
||||||
drawCenteredString(fontRenderer, I18n.format("hdskins.fetch"), (int)xPos2, height / 2 - 4, 0xffffff);
|
drawCenteredString(fontRenderer, format("hdskins.fetch"), (int)xPos2, height / 2 - 4, 0xffffff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +447,7 @@ public class GuiSkins extends GuiScreen {
|
||||||
|
|
||||||
if (uploadError != null) {
|
if (uploadError != null) {
|
||||||
Gui.drawRect(0, 0, width, height, 0xB0000000);
|
Gui.drawRect(0, 0, width, height, 0xB0000000);
|
||||||
drawCenteredString(fontRenderer, I18n.format("hdskins.failed"), width / 2, height / 2 - 10, 0xFFFFFF55);
|
drawCenteredString(fontRenderer, format("hdskins.failed"), width / 2, height / 2 - 10, 0xFFFFFF55);
|
||||||
drawCenteredString(fontRenderer, uploadError, width / 2, height / 2 + 2, 0xFFFF5555);
|
drawCenteredString(fontRenderer, uploadError, width / 2, height / 2 + 2, 0xFFFF5555);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,7 +513,7 @@ public class GuiSkins extends GuiScreen {
|
||||||
|
|
||||||
private void punchServer(String uploadMsg, @Nullable URI path) {
|
private void punchServer(String uploadMsg, @Nullable URI path) {
|
||||||
uploadingSkin = true;
|
uploadingSkin = true;
|
||||||
skinUploadMessage = I18n.format(uploadMsg);
|
skinUploadMessage = format(uploadMsg);
|
||||||
|
|
||||||
HDSkinManager.INSTANCE.getGatewayServer()
|
HDSkinManager.INSTANCE.getGatewayServer()
|
||||||
.uploadSkin(mc.getSession(), path, textureType, getMetadata())
|
.uploadSkin(mc.getSession(), path, textureType, getMetadata())
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.voxelmodpack.hdskins.mixin;
|
package com.voxelmodpack.hdskins.mixin;
|
||||||
|
|
||||||
|
import com.minelittlepony.gui.IActionable;
|
||||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||||
import com.voxelmodpack.hdskins.gui.GuiItemStackButton;
|
import com.voxelmodpack.hdskins.gui.GuiItemStackButton;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
|
@ -15,19 +16,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
@Mixin(GuiMainMenu.class)
|
@Mixin(GuiMainMenu.class)
|
||||||
public class MixinGuiMainMenu extends GuiScreen {
|
public class MixinGuiMainMenu extends GuiScreen {
|
||||||
|
|
||||||
private static final int SKINS = 5000;
|
|
||||||
|
|
||||||
@Inject(method = "initGui()V", at = @At("RETURN"))
|
@Inject(method = "initGui()V", at = @At("RETURN"))
|
||||||
private void onInit(CallbackInfo ci) {
|
private void onInit(CallbackInfo ci) {
|
||||||
ItemStack itemStack = new ItemStack(Items.LEATHER_LEGGINGS);
|
addButton(new GuiItemStackButton(width - 50, height - 50, new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb, sender -> {
|
||||||
Items.LEATHER_LEGGINGS.setColor(itemStack, 0x3c5dcb);
|
mc.displayGuiScreen(HDSkinManager.INSTANCE.createSkinsGui());
|
||||||
this.buttonList.add(new GuiItemStackButton(SKINS, width - 50, height - 50, itemStack));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "actionPerformed(Lnet/minecraft/client/gui/GuiButton;)V", at = @At("RETURN"))
|
@Inject(method = "actionPerformed(Lnet/minecraft/client/gui/GuiButton;)V", at = @At("RETURN"))
|
||||||
private void onActionPerformed(GuiButton button, CallbackInfo ci) {
|
private void onActionPerformed(GuiButton button, CallbackInfo ci) {
|
||||||
if (button.id == SKINS) {
|
if (button instanceof IActionable) {
|
||||||
this.mc.displayGuiScreen(HDSkinManager.INSTANCE.createSkinsGui());
|
((IActionable)button).perform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class GuiPonySettings extends SettingsPanel {
|
||||||
|
|
||||||
addButton(new Label(LEFT, row += 15, PONY_LEVEL, -1));
|
addButton(new Label(LEFT, row += 15, PONY_LEVEL, -1));
|
||||||
addButton(new Slider(LEFT, row += 15, 0, 2, config.getPonyLevel().ordinal(), (int id, String name, float value) -> {
|
addButton(new Slider(LEFT, row += 15, 0, 2, config.getPonyLevel().ordinal(), (int id, String name, float value) -> {
|
||||||
return translate(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase());
|
return format(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase());
|
||||||
}, v -> {
|
}, v -> {
|
||||||
PonyLevel level = PonyLevel.valueFor(v);
|
PonyLevel level = PonyLevel.valueFor(v);
|
||||||
config.setPonyLevel(level);
|
config.setPonyLevel(level);
|
||||||
|
|
|
@ -2,6 +2,7 @@ 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.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;
|
||||||
|
@ -9,8 +10,6 @@ import com.voxelmodpack.hdskins.gui.EntityPlayerModel;
|
||||||
import com.voxelmodpack.hdskins.gui.GuiItemStackButton;
|
import com.voxelmodpack.hdskins.gui.GuiItemStackButton;
|
||||||
import com.voxelmodpack.hdskins.gui.GuiSkins;
|
import com.voxelmodpack.hdskins.gui.GuiSkins;
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
@ -22,8 +21,8 @@ public class GuiSkinsMineLP extends GuiSkins {
|
||||||
|
|
||||||
private PonyManager ponyManager = MineLittlePony.getInstance().getManager();
|
private PonyManager ponyManager = MineLittlePony.getInstance().getManager();
|
||||||
|
|
||||||
private GuiButton btnModeWet;
|
private Button btnModeWet;
|
||||||
private GuiButton btnModeDry;
|
private Button btnModeDry;
|
||||||
|
|
||||||
private boolean isWet = false;
|
private boolean isWet = false;
|
||||||
|
|
||||||
|
@ -42,11 +41,14 @@ public class GuiSkinsMineLP extends GuiSkins {
|
||||||
public void initGui() {
|
public void initGui() {
|
||||||
super.initGui();
|
super.initGui();
|
||||||
|
|
||||||
buttonList.add(btnModeWet = new GuiItemStackButton(7, 2, 99, new ItemStack(Items.WATER_BUCKET)));
|
addButton(btnModeWet = new GuiItemStackButton(2, 99, new ItemStack(Items.WATER_BUCKET), sender -> {
|
||||||
buttonList.add(btnModeDry = new GuiItemStackButton(8, 2, 80, new ItemStack(Items.BUCKET)));
|
setWet(false);
|
||||||
|
})).setTooltip("minelp.mode.wet");
|
||||||
|
addButton(btnModeDry = new GuiItemStackButton(2, 80, new ItemStack(Items.BUCKET), sender -> {
|
||||||
|
setWet(true);
|
||||||
|
})).setTooltip("minelp.mode.dry");
|
||||||
|
|
||||||
btnModeDry.enabled = isWet;
|
setWet(false);
|
||||||
btnModeWet.enabled = !isWet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,40 +58,15 @@ public class GuiSkinsMineLP extends GuiSkins {
|
||||||
panorama.setSource(panoramas[i]);
|
panorama.setSource(panoramas[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setWet(boolean wet) {
|
||||||
@Override
|
isWet = wet;
|
||||||
protected void actionPerformed(GuiButton guiButton) {
|
localPlayer.releaseTextures();
|
||||||
super.actionPerformed(guiButton);
|
|
||||||
|
|
||||||
if (guiButton.id == this.btnModeDry.id) {
|
|
||||||
this.isWet = false;
|
|
||||||
this.localPlayer.releaseTextures();
|
|
||||||
} else if (guiButton.id == this.btnModeWet.id) {
|
|
||||||
this.isWet = true;
|
|
||||||
this.localPlayer.releaseTextures();
|
|
||||||
}
|
|
||||||
|
|
||||||
btnModeDry.enabled = isWet;
|
btnModeDry.enabled = isWet;
|
||||||
btnModeWet.enabled = !isWet;
|
btnModeWet.enabled = !isWet;
|
||||||
|
|
||||||
((EntityPonyModel)this.localPlayer).setWet(isWet);
|
((EntityPonyModel)localPlayer).setWet(isWet);
|
||||||
((EntityPonyModel)this.remotePlayer).setWet(isWet);
|
((EntityPonyModel)remotePlayer).setWet(isWet);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawScreen(int mouseX, int mouseY, float partialTick) {
|
|
||||||
super.drawScreen(mouseX, mouseY, partialTick);
|
|
||||||
|
|
||||||
if (btnModeDry.isMouseOver() || btnModeWet.isMouseOver()) {
|
|
||||||
int y = Math.max(mouseY, 16);
|
|
||||||
String text;
|
|
||||||
if (btnModeDry.isMouseOver()) {
|
|
||||||
text = "minelp.mode.dry";
|
|
||||||
} else {
|
|
||||||
text = "minelp.mode.wet";
|
|
||||||
}
|
|
||||||
this.drawHoveringText(I18n.format(text), mouseX, y);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.minelittlepony.settings;
|
package com.minelittlepony.settings;
|
||||||
|
|
||||||
import com.minelittlepony.gui.IGUIAction;
|
import com.minelittlepony.gui.IGuiCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A sensible config container that actually lets us programatically index values by a key.
|
* A sensible config container that actually lets us programatically index values by a key.
|
||||||
|
@ -17,7 +17,7 @@ public abstract class SensibleConfig {
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Setting extends IGUIAction<Boolean> {
|
public interface Setting extends IGuiCallback<Boolean> {
|
||||||
String name();
|
String name();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue