Rewrite GuiSkins

This commit is contained in:
Sollace 2018-07-27 15:45:16 +02:00
parent 34dae0168d
commit 83659d80ca
14 changed files with 200 additions and 191 deletions

View file

@ -1,14 +1,22 @@
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;
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) {
super(0, x, y, width, height, GameGui.translate(label));
action = callback;
private List<String> tooltip = null;
@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
@ -16,4 +24,24 @@ public class Button extends GuiButton implements IActionable {
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);
}
}
}

View file

@ -12,9 +12,9 @@ import net.minecraft.client.resources.I18n;
*/
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));
action = callback;
checked = value;

View file

@ -1,7 +1,5 @@
package com.minelittlepony.gui;
import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
@ -9,13 +7,13 @@ import net.minecraft.client.resources.I18n;
public abstract class GameGui extends GuiScreen {
@Override
protected void actionPerformed(GuiButton button) throws IOException {
protected void actionPerformed(GuiButton button) {
if (button instanceof IActionable) {
((IActionable)button).perform();
}
}
protected static String translate(String string) {
protected static String format(String string) {
return I18n.format(string);
}
}

View 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);
}

View 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);
}

View file

@ -2,7 +2,6 @@ package com.minelittlepony.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
/**
* 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) {
if (center) {
drawCenteredString(mc.fontRenderer, I18n.format(text), x, y, color);
drawCenteredString(mc.fontRenderer, GameGui.format(text), x, y, color);
} else {
drawString(mc.fontRenderer, I18n.format(text), x, y, color);
drawString(mc.fontRenderer, GameGui.format(text), x, y, color);
}
}
}

View file

@ -20,7 +20,7 @@ public abstract class SettingsPanel extends GameGui implements ConfigPanel {
@Override
public String getPanelTitle() {
return translate(getTitle());
return format(getTitle());
}
@Override

View file

@ -13,7 +13,7 @@ public class Slider extends GuiSlider {
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);
callback.owner = this;
callback = null;
@ -21,11 +21,11 @@ public class Slider extends GuiSlider {
private static final class Responder implements GuiResponder {
private final IGUIAction<Float> action;
private final IGuiCallback<Float> action;
private Slider owner;
private Responder(IGUIAction<Float> callback) {
private Responder(IGuiCallback<Float> callback) {
action = callback;
}

View file

@ -1,18 +1,26 @@
package com.voxelmodpack.hdskins.gui;
import com.minelittlepony.gui.Button;
import com.minelittlepony.gui.IGuiAction;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
public class GuiItemStackButton extends GuiButton {
public class GuiItemStackButton extends Button {
private ItemStack itemStack;
public GuiItemStackButton(int buttonId, int x, int y, ItemStack itemStack) {
super(buttonId, x, y, 20, 20, "");
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);

View file

@ -7,6 +7,9 @@ import static net.minecraft.client.renderer.GlStateManager.*;
import com.google.common.base.Splitter;
import com.google.common.base.Throwables;
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.minecraft.MinecraftProfileTexture;
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.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
@ -43,23 +44,19 @@ import java.util.Map;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
public class GuiSkins extends GuiScreen {
public class GuiSkins extends GameGui {
private static final int MAX_SKIN_DIMENSION = 1024;
private int updateCounter = 0;
private GuiButton btnBrowse;
private GuiButton btnUpload;
private GuiButton btnClear;
private GuiButton btnBack;
private GuiButton btnModeSkin;
private GuiButton btnModeSkinnySkin;
private GuiButton btnModeElytra;
private Button btnUpload;
private Button btnClear;
private GuiButton btnAbout;
private Button btnModeSkin;
private Button btnModeSkinnySkin;
private Button btnModeElytra;
protected EntityPlayerModel localPlayer;
protected EntityPlayerModel remotePlayer;
@ -68,8 +65,8 @@ public class GuiSkins extends GuiScreen {
@Nullable
private String uploadError;
private volatile String skinMessage = I18n.format("hdskins.choose");
private String skinUploadMessage = I18n.format("hdskins.request");
private volatile String skinMessage = format("hdskins.choose");
private String skinUploadMessage = format("hdskins.request");
private volatile boolean fetchingSkin;
private volatile boolean uploadingSkin;
@ -196,29 +193,57 @@ public class GuiSkins extends GuiScreen {
panorama.init();
buttonList.clear();
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"));
addButton(new Label(width / 2, 10, "hdskins.manager", 0xffffff));
ItemStack skin = new ItemStack(Items.LEATHER_LEGGINGS);
Items.LEATHER_LEGGINGS.setColor(skin, 0x3c5dcb);
buttonList.add(btnModeSkin = new GuiItemStackButton(4, 2, 2, skin));
skin = new ItemStack(Items.LEATHER_LEGGINGS);
Items.LEATHER_LEGGINGS.setColor(skin, 0xfff500);
buttonList.add(btnModeElytra = new GuiItemStackButton(5, 2, 52, new ItemStack(Items.ELYTRA)));
buttonList.add(btnModeSkinnySkin = new GuiItemStackButton(6, 2, 21, skin));
addButton(new Button(30, height - 36, 60, 20, "Browse...", sender ->{
selectedSkin = null;
localPlayer.releaseTextures();
openFileThread = new ThreadOpenFilePNG(mc, format("hdskins.open.title"), (fileDialog, dialogResult) -> {
openFileThread = null;
sender.enabled = true;
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;
btnBrowse.enabled = !mc.isFullScreen();
addButton(btnClear = new Button(width - 90, height - 36, 60, 20, "Clear", sender -> {
if (remotePlayer.isTextureSetupComplete()) {
punchServer("hdskins.request", null);
btnUpload.enabled = selectedSkin != null;
}
}));
btnModeSkin.enabled = thinArmType;
btnModeSkinnySkin.enabled = !thinArmType;
btnModeElytra.enabled = textureType == SKIN;
addButton(new Button(width / 2 - 50, height - 36, 100, 20, "Close", sender -> {
mc.displayGuiScreen(new GuiMainMenu());
}));
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
@ -231,36 +256,28 @@ public class GuiSkins extends GuiScreen {
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) {
Minecraft.getMinecraft().addScheduledTask(localPlayer::releaseTextures);
if (!skinFile.exists()) {
skinMessage = I18n.format("hdskins.error.unreadable");
skinMessage = format("hdskins.error.unreadable");
} else if (!FilenameUtils.isExtension(skinFile.getName(), new String[]{"png", "PNG"})) {
skinMessage = I18n.format("hdskins.error.ext");
skinMessage = format("hdskins.error.ext");
} else {
try {
BufferedImage chosenImage = ImageIO.read(skinFile);
if (chosenImage == null) {
skinMessage = I18n.format("hdskins.error.open");
skinMessage = format("hdskins.error.open");
} else if (!acceptsSkinDimensions(chosenImage.getWidth(), chosenImage.getHeight())) {
skinMessage = I18n.format("hdskins.error.invalid");
skinMessage = format("hdskins.error.invalid");
} else {
synchronized (skinLock) {
pendingSkinFile = skinFile;
}
}
} catch (IOException var6) {
skinMessage = I18n.format("hdskins.error.open");
skinMessage = format("hdskins.error.open");
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;
}
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
protected void actionPerformed(GuiButton guiButton) {
if (openFileThread == null && !uploadingSkin) {
if (uploadError != null) {
uploadError = null;
} else {
if (guiButton.id == btnBrowse.id) {
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);
}
super.actionPerformed(guiButton);
}
}
}
@ -408,10 +397,8 @@ public class GuiSkins extends GuiScreen {
disableClipping();
drawCenteredString(fontRenderer, I18n.format("hdskins.manager"), width / 2, 10, 0xffffff);
fontRenderer.drawStringWithShadow(I18n.format("hdskins.local"), 34, 34, 0xffffff);
fontRenderer.drawStringWithShadow(I18n.format("hdskins.server"), width / 2 + 34, 34, 0xffffff);
fontRenderer.drawStringWithShadow(format("hdskins.local"), 34, 34, 0xffffff);
fontRenderer.drawStringWithShadow(format("hdskins.server"), width / 2 + 34, 34, 0xffffff);
disableDepth();
enableBlend();
@ -423,23 +410,6 @@ public class GuiSkins extends GuiScreen {
Gui.drawRect(40, height / 2 - 12, width / 2 - 40, height / 2 + 12, 0xB0000000);
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) {
@ -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);
if (throttledByMojang) {
drawCenteredString(fontRenderer, I18n.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"), (int)xPos2, height / 2 - 10, 0xffffff);
drawCenteredString(fontRenderer, format("hdskins.error.mojang.wait"), (int)xPos2, height / 2 + 2, 0xffffff);
} 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) {
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);
}
@ -543,7 +513,7 @@ public class GuiSkins extends GuiScreen {
private void punchServer(String uploadMsg, @Nullable URI path) {
uploadingSkin = true;
skinUploadMessage = I18n.format(uploadMsg);
skinUploadMessage = format(uploadMsg);
HDSkinManager.INSTANCE.getGatewayServer()
.uploadSkin(mc.getSession(), path, textureType, getMetadata())

View file

@ -1,5 +1,6 @@
package com.voxelmodpack.hdskins.mixin;
import com.minelittlepony.gui.IActionable;
import com.voxelmodpack.hdskins.HDSkinManager;
import com.voxelmodpack.hdskins.gui.GuiItemStackButton;
import net.minecraft.client.gui.GuiButton;
@ -15,19 +16,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GuiMainMenu.class)
public class MixinGuiMainMenu extends GuiScreen {
private static final int SKINS = 5000;
@Inject(method = "initGui()V", at = @At("RETURN"))
private void onInit(CallbackInfo ci) {
ItemStack itemStack = new ItemStack(Items.LEATHER_LEGGINGS);
Items.LEATHER_LEGGINGS.setColor(itemStack, 0x3c5dcb);
this.buttonList.add(new GuiItemStackButton(SKINS, width - 50, height - 50, itemStack));
addButton(new GuiItemStackButton(width - 50, height - 50, new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb, sender -> {
mc.displayGuiScreen(HDSkinManager.INSTANCE.createSkinsGui());
}));
}
@Inject(method = "actionPerformed(Lnet/minecraft/client/gui/GuiButton;)V", at = @At("RETURN"))
private void onActionPerformed(GuiButton button, CallbackInfo ci) {
if (button.id == SKINS) {
this.mc.displayGuiScreen(HDSkinManager.INSTANCE.createSkinsGui());
if (button instanceof IActionable) {
((IActionable)button).perform();
}
}
}

View file

@ -38,7 +38,7 @@ public class GuiPonySettings extends SettingsPanel {
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) -> {
return translate(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase());
return format(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase());
}, v -> {
PonyLevel level = PonyLevel.valueFor(v);
config.setPonyLevel(level);

View file

@ -2,6 +2,7 @@ package com.minelittlepony.hdskins.gui;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyManager;
import com.minelittlepony.gui.Button;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
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.GuiSkins;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
@ -22,8 +21,8 @@ public class GuiSkinsMineLP extends GuiSkins {
private PonyManager ponyManager = MineLittlePony.getInstance().getManager();
private GuiButton btnModeWet;
private GuiButton btnModeDry;
private Button btnModeWet;
private Button btnModeDry;
private boolean isWet = false;
@ -42,11 +41,14 @@ public class GuiSkinsMineLP extends GuiSkins {
public void initGui() {
super.initGui();
buttonList.add(btnModeWet = new GuiItemStackButton(7, 2, 99, new ItemStack(Items.WATER_BUCKET)));
buttonList.add(btnModeDry = new GuiItemStackButton(8, 2, 80, new ItemStack(Items.BUCKET)));
addButton(btnModeWet = new GuiItemStackButton(2, 99, new ItemStack(Items.WATER_BUCKET), sender -> {
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;
btnModeWet.enabled = !isWet;
setWet(false);
}
@Override
@ -56,40 +58,15 @@ public class GuiSkinsMineLP extends GuiSkins {
panorama.setSource(panoramas[i]);
}
@Override
protected void actionPerformed(GuiButton guiButton) {
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();
}
protected void setWet(boolean wet) {
isWet = wet;
localPlayer.releaseTextures();
btnModeDry.enabled = isWet;
btnModeWet.enabled = !isWet;
((EntityPonyModel)this.localPlayer).setWet(isWet);
((EntityPonyModel)this.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);
};
((EntityPonyModel)localPlayer).setWet(isWet);
((EntityPonyModel)remotePlayer).setWet(isWet);
}
@Override

View file

@ -1,6 +1,6 @@
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.
@ -17,7 +17,7 @@ public abstract class SensibleConfig {
instance = this;
}
public interface Setting extends IGUIAction<Boolean> {
public interface Setting extends IGuiCallback<Boolean> {
String name();
/**