The skins gui will now let you see what your character looks like when sleeping

This commit is contained in:
Sollace 2018-10-20 16:03:53 +02:00
parent 4e674377db
commit 1af726c06a
10 changed files with 189 additions and 52 deletions

View file

@ -5,7 +5,7 @@ import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
public class Button extends GuiButton implements IActionable, IGuiTooltipped {
public class Button extends GuiButton implements IActionable, IGuiTooltipped<Button> {
private int tipX = 0;
private int tipY = 0;
@ -44,7 +44,7 @@ public class Button extends GuiButton implements IActionable, IGuiTooltipped {
}
@Override
public IGuiTooltipped setTooltipOffset(int x, int y) {
public Button setTooltipOffset(int x, int y) {
tipX = x;
tipY = y;
return this;

View file

@ -13,7 +13,7 @@ import net.minecraft.client.resources.I18n;
* @author Sollace
*
*/
public class Checkbox extends GuiCheckbox implements IActionable, IGuiTooltipped {
public class Checkbox extends GuiCheckbox implements IActionable, IGuiTooltipped<Checkbox> {
private int tipX = 0;
private int tipY = 0;
@ -47,7 +47,7 @@ public class Checkbox extends GuiCheckbox implements IActionable, IGuiTooltipped
}
@Override
public IGuiTooltipped setTooltipOffset(int x, int y) {
public Checkbox setTooltipOffset(int x, int y) {
tipX = x;
tipY = y;
return this;

View file

@ -63,7 +63,7 @@ public abstract class GameGui extends GuiScreen {
protected void postDrawContents(int mouseX, int mouseY, float partialTicks) {
buttonList.forEach(button -> {
if (button instanceof IGuiTooltipped) {
((IGuiTooltipped)button).renderToolTip(mc, mouseX, mouseY);
((IGuiTooltipped<?>)button).renderToolTip(mc, mouseX, mouseY);
}
});
}

View file

@ -6,13 +6,13 @@ import com.google.common.base.Splitter;
import java.util.List;
public interface IGuiTooltipped {
public interface IGuiTooltipped<T extends IGuiTooltipped<T>> {
IGuiTooltipped setTooltip(List<String> tooltip);
T setTooltip(List<String> tooltip);
IGuiTooltipped setTooltipOffset(int x, int y);
T setTooltipOffset(int x, int y);
default IGuiTooltipped setTooltip(String tooltip) {
default T setTooltip(String tooltip) {
return setTooltip(Splitter.onPattern("\r?\n|\\\\n").splitToList(GameGui.format(tooltip)));
}

View file

@ -8,7 +8,7 @@ public class IconicButton extends Button {
private ItemStack itemStack = ItemStack.EMPTY;
public IconicButton(int x, int y, IGuiAction<IconicButton> callback) {
public IconicButton(int x, int y, IGuiAction<? extends IconicButton> callback) {
super(x, y, 20, 20, "", callback);
}

View file

@ -0,0 +1,100 @@
package com.minelittlepony.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import java.util.List;
public class IconicToggle extends IconicButton {
private Style onState = new Style();
private Style offState = new Style();
private boolean value;
public IconicToggle(int x, int y, IGuiAction<IconicToggle> callback) {
super(x, y, callback);
}
public boolean getValue() {
return value;
}
public IconicToggle setValue(boolean value) {
if (this.value != value) {
this.value = value;
(value ? onState : offState).apply(this);
}
return this;
}
public IconicToggle setStyle(Style style, boolean value) {
if (value) {
onState = style;
} else {
offState = style;
}
if (this.value == value) {
style.apply(this);
}
return this;
}
@Override
public void perform() {
setValue(!value);
super.perform();
}
public static class Style implements IGuiTooltipped<Style> {
ItemStack icon = ItemStack.EMPTY;
private boolean hasOffset = false;
private int toolTipX = 0;
private int toolTipY = 0;
private List<String> tooltip;
public Style setIcon(ItemStack stack) {
icon = stack;
return this;
}
public Style setIcon(ItemStack stack, int colour) {
Items.LEATHER_LEGGINGS.setColor(stack, colour);
return setIcon(stack);
}
protected void apply(IconicToggle button) {
button.setIcon(icon)
.setTooltip(tooltip);
if (hasOffset) {
button.setTooltipOffset(toolTipX, toolTipY);
}
}
@Override
public Style setTooltip(List<String> tooltip) {
this.tooltip = tooltip;
return this;
}
@Override
public Style setTooltipOffset(int x, int y) {
hasOffset = true;
toolTipX = x;
toolTipY = y;
return this;
}
@Override
public void renderToolTip(Minecraft mc, int mouseX, int mouseY) {
}
}
}

View file

@ -41,6 +41,7 @@ public class EntityPlayerModel extends EntityLivingBase implements IBlankSkinSup
private final GameProfile profile;
protected boolean previewThinArms = false;
protected boolean previewSleeping = false;
public EntityPlayerModel(GameProfile gameprofile) {
super(DummyWorld.INSTANCE);
@ -104,6 +105,20 @@ public class EntityPlayerModel extends EntityLivingBase implements IBlankSkinSup
return previewThinArms;
}
public void setSleeping(boolean sleep) {
previewSleeping = sleep;
}
@Override
public boolean isPlayerSleeping() {
return previewSleeping;
}
@Override
public boolean isSneaking() {
return !previewSleeping && super.isSneaking();
}
public void updateModel() {
prevSwingProgress = swingProgress;
if (isSwingInProgress) {
@ -123,7 +138,7 @@ public class EntityPlayerModel extends EntityLivingBase implements IBlankSkinSup
motionY = 0;
}
if (posY == 0 && isJumping) {
if (posY == 0 && isJumping && !previewSleeping) {
jump();
}

View file

@ -3,6 +3,7 @@ package com.voxelmodpack.hdskins.gui;
import com.minelittlepony.gui.Button;
import com.minelittlepony.gui.GameGui;
import com.minelittlepony.gui.IconicButton;
import com.minelittlepony.gui.IconicToggle;
import com.minelittlepony.gui.Label;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
@ -142,21 +143,23 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler {
addButton(new Label(34, 34, "hdskins.local", 0xffffff));
addButton(new Label(width / 2 + 34, 34, "hdskins.server", 0xffffff));
addButton(btnBrowse = new Button(width / 2 - 150, height - 27, 90, 20, "hdskins.options.browse", sender -> {
chooser.openBrowsePNG(mc, format("hdskins.open.title"));
})).setEnabled(!mc.isFullScreen());
addButton(btnBrowse = new Button(width / 2 - 150, height - 27, 90, 20, "hdskins.options.browse", sender ->
chooser.openBrowsePNG(mc, format("hdskins.open.title"))))
.setEnabled(!mc.isFullScreen());
addButton(btnUpload = new Button(width / 2 - 24, height / 2 - 20, 48, 20, "hdskins.options.chevy", sender -> {
if (uploader.canUpload()) {
punchServer("hdskins.upload");
}
})).setEnabled(uploader.canUpload()).setTooltip("hdskins.options.chevy.title");
})).setEnabled(uploader.canUpload())
.setTooltip("hdskins.options.chevy.title");
addButton(btnDownload = new Button(width / 2 - 24, height / 2 + 20, 48, 20, "hdskins.options.download", sender -> {
if (uploader.canClear()) {
chooser.openSavePNG(mc, format("hdskins.save.title"));
}
})).setEnabled(uploader.canClear()).setTooltip("hdskins.options.download.title");
})).setEnabled(uploader.canClear())
.setTooltip("hdskins.options.download.title");
addButton(btnClear = new Button(width / 2 + 60, height - 27, 90, 20, "hdskins.options.clear", sender -> {
if (uploader.canClear()) {
@ -164,32 +167,51 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler {
}
})).setEnabled(uploader.canClear());
addButton(new Button(width / 2 - 50, height - 25, 100, 20, "hdskins.options.close", sender -> {
mc.displayGuiScreen(new GuiMainMenu());
}));
addButton(new Button(width / 2 - 50, height - 25, 100, 20, "hdskins.options.close", sender ->
mc.displayGuiScreen(new GuiMainMenu())));
addButton(btnModeSteve = new IconicButton(width - 25, 32, sender -> {
switchSkinMode("default");
}).setIcon(new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb)).setEnabled("slim".equals(uploader.getMetadataField("model"))).setTooltip("hdskins.mode.steve").setTooltipOffset(0, 10);
addButton(btnModeSteve = new IconicButton(width - 25, 32, sender -> switchSkinMode("default"))
.setIcon(new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb))
.setEnabled("slim".equals(uploader.getMetadataField("model")))
.setTooltip("hdskins.mode.steve")
.setTooltipOffset(0, 10);
addButton(btnModeAlex = new IconicButton(width - 25, 51, sender -> {
switchSkinMode("slim");
}).setIcon(new ItemStack(Items.LEATHER_LEGGINGS), 0xfff500)).setEnabled("default".equals(uploader.getMetadataField("model"))).setTooltip("hdskins.mode.alex").setTooltipOffset(0, 10);
addButton(btnModeAlex = new IconicButton(width - 25, 51, sender -> switchSkinMode("slim"))
.setIcon(new ItemStack(Items.LEATHER_LEGGINGS), 0xfff500))
.setEnabled("default".equals(uploader.getMetadataField("model")))
.setTooltip("hdskins.mode.alex")
.setTooltipOffset(0, 10);
addButton(btnModeSkin = new IconicButton(width - 25, 75, sender -> uploader.setSkinType(Type.SKIN))
.setIcon(new ItemStack(Items.LEATHER_CHESTPLATE)))
.setEnabled(uploader.getSkinType() == Type.ELYTRA)
.setTooltip(format("hdskins.mode.skin", toTitleCase(Type.SKIN.name())))
.setTooltipOffset(0, 10);
addButton(btnModeSkin = new IconicButton(width - 25, 75, sender -> {
uploader.setSkinType(Type.SKIN);
}).setIcon(new ItemStack(Items.LEATHER_CHESTPLATE))).setEnabled(uploader.getSkinType() == Type.ELYTRA).setTooltip(format("hdskins.mode.skin", toTitleCase(Type.SKIN.name()))).setTooltipOffset(0, 10);
addButton(btnModeElytra = new IconicButton(width - 25, 94, sender -> uploader.setSkinType(Type.ELYTRA))
.setIcon(new ItemStack(Items.ELYTRA)))
.setEnabled(uploader.getSkinType() == Type.SKIN)
.setTooltip(format("hdskins.mode.skin", toTitleCase(Type.ELYTRA.name())))
.setTooltipOffset(0, 10);
addButton(btnModeElytra = new IconicButton(width - 25, 94, sender -> {
uploader.setSkinType(Type.ELYTRA);
}).setIcon(new ItemStack(Items.ELYTRA))).setEnabled(uploader.getSkinType() == Type.SKIN).setTooltip(format("hdskins.mode.skin", toTitleCase(Type.ELYTRA.name()))).setTooltipOffset(0, 10);
addButton(new IconicToggle(width - 25, 118, sender -> {
playSound(SoundEvents.BLOCK_BREWING_STAND_BREW);
localPlayer.setSleeping(sender.getValue());
remotePlayer.setSleeping(sender.getValue());
}))
.setValue(localPlayer.isPlayerSleeping())
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.IRON_BOOTS, 1)).setTooltip("Standing"), false)
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.CLOCK, 1)).setTooltip("Sleeping"), true)
.setTooltipOffset(0, 10);
addButton(new Button(width - 25, height - 65, 20, 20, "?", sender -> {
uploader.cycleGateway();
playSound(SoundEvents.ENTITY_VILLAGER_YES);
sender.setTooltip(uploader.getGateway());
})).setTooltip(uploader.getGateway()).setTooltipOffset(0, 10);
}))
.setTooltip(uploader.getGateway())
.setTooltipOffset(0, 10);
}
@Override

View file

@ -111,7 +111,12 @@ public class RenderPlayerModel<M extends EntityPlayerModel> extends RenderLiving
double offset = entity.getYOffset() + entity.posY;
if (player.isSneak) {
if (entity.isPlayerSleeping()) {
y--;
z += 0.5F;
} else if (player.isSneak) {
y -= 0.125D;
}
@ -120,6 +125,10 @@ public class RenderPlayerModel<M extends EntityPlayerModel> extends RenderLiving
color(1, 1, 1, 0.3F);
translate(0, offset, 0);
if (entity.isPlayerSleeping()) {
GlStateManager.rotate(-90, 1, 0, 0);
}
super.doRender(entity, x, y, z, entityYaw, partialTicks);
color(1, 1, 1, 1);
@ -132,6 +141,10 @@ public class RenderPlayerModel<M extends EntityPlayerModel> extends RenderLiving
scale(1, -1, 1);
translate(0.001, offset, 0.001);
if (entity.isPlayerSleeping()) {
GlStateManager.rotate(-90, 1, 0, 0);
}
super.doRender(entity, x, y, z, entityYaw, partialTicks);
popMatrix();

View file

@ -2,8 +2,7 @@ package com.minelittlepony.hdskins.gui;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyManager;
import com.minelittlepony.gui.Button;
import com.minelittlepony.gui.IconicButton;
import com.minelittlepony.gui.IconicToggle;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
@ -25,9 +24,6 @@ public class GuiSkinsMineLP extends GuiSkins {
private PonyManager ponyManager = MineLittlePony.getInstance().getManager();
private Button btnModeWet;
private Button btnModeDry;
private boolean isWet = false;
private static final String[] panoramas = new String[] {
@ -49,13 +45,11 @@ public class GuiSkinsMineLP extends GuiSkins {
public void initGui() {
super.initGui();
addButton(btnModeWet = new IconicButton(width - 25, 137, sender -> {
setWet(true);
}).setIcon(new ItemStack(Items.WATER_BUCKET))).setEnabled(!isWet).setTooltip("minelp.mode.wet").setTooltipOffset(0, 10);
addButton(btnModeDry = new IconicButton(width - 25, 118, sender -> {
setWet(false);
}).setIcon(new ItemStack(Items.BUCKET))).setEnabled(isWet).setTooltip("minelp.mode.dry").setTooltipOffset(0, 10);
addButton(new IconicToggle(width - 25, 142, sender -> setWet(sender.getValue()))
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.WATER_BUCKET)).setTooltip("minelp.mode.wet"), true)
.setStyle(new IconicToggle.Style().setIcon(new ItemStack(Items.BUCKET)).setTooltip("minelp.mode.dry"), false)
.setValue(isWet)
.setTooltipOffset(0, 10));
}
@Override
@ -66,18 +60,11 @@ public class GuiSkinsMineLP extends GuiSkins {
}
protected void setWet(boolean wet) {
if (wet == isWet) {
return;
}
playSound(SoundEvents.BLOCK_BREWING_STAND_BREW);
isWet = wet;
localPlayer.releaseTextures();
btnModeDry.enabled = isWet;
btnModeWet.enabled = !isWet;
((EntityPonyModel)localPlayer).setWet(isWet);
((EntityPonyModel)remotePlayer).setWet(isWet);
}