From 21ac01303438b8554f246d785e72a42d085f690d Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 20 Oct 2018 16:57:49 +0200 Subject: [PATCH] Add support for more than two states, and added a riding pose --- .../com/minelittlepony/gui/IStyleFactory.java | 6 ++ .../com/minelittlepony/gui/IconicToggle.java | 97 ++++++------------- .../java/com/minelittlepony/gui/Style.java | 55 +++++++++++ .../hdskins/gui/EntityPlayerModel.java | 16 ++- .../voxelmodpack/hdskins/gui/GuiSkins.java | 19 ++-- .../hdskins/util/MoreStreams.java | 12 +++ .../hdskins/gui/GuiSkinsMineLP.java | 9 +- .../model/AbstractPonyModel.java | 2 +- 8 files changed, 134 insertions(+), 82 deletions(-) create mode 100644 src/hdskins/java/com/minelittlepony/gui/IStyleFactory.java create mode 100644 src/hdskins/java/com/minelittlepony/gui/Style.java diff --git a/src/hdskins/java/com/minelittlepony/gui/IStyleFactory.java b/src/hdskins/java/com/minelittlepony/gui/IStyleFactory.java new file mode 100644 index 00000000..58611cb4 --- /dev/null +++ b/src/hdskins/java/com/minelittlepony/gui/IStyleFactory.java @@ -0,0 +1,6 @@ +package com.minelittlepony.gui; + +@FunctionalInterface +public interface IStyleFactory { + Style getStyle(); +} diff --git a/src/hdskins/java/com/minelittlepony/gui/IconicToggle.java b/src/hdskins/java/com/minelittlepony/gui/IconicToggle.java index 8dda7b42..a246c38e 100644 --- a/src/hdskins/java/com/minelittlepony/gui/IconicToggle.java +++ b/src/hdskins/java/com/minelittlepony/gui/IconicToggle.java @@ -1,41 +1,50 @@ package com.minelittlepony.gui; -import net.minecraft.client.Minecraft; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; - -import java.util.List; +import com.voxelmodpack.hdskins.util.MoreStreams; public class IconicToggle extends IconicButton { - private Style onState = new Style(); - private Style offState = new Style(); + private Style[] styles; - private boolean value; + private int value; - public IconicToggle(int x, int y, IGuiAction callback) { + public IconicToggle(int x, int y, int states, IGuiAction callback) { super(x, y, callback); + styles = new Style[states]; + for (int i = 0; i < styles.length; i++) { + styles[i] = new Style(); + } } - public boolean getValue() { + public int getValue() { return value; } - public IconicToggle setValue(boolean value) { + public IconicToggle setValue(int value) { if (this.value != value) { - this.value = value; - (value ? onState : offState).apply(this); + this.value = value % styles.length; + styles[this.value].apply(this); } return this; } - public IconicToggle setStyle(Style style, boolean value) { - if (value) { - onState = style; - } else { - offState = style; - } + public IconicToggle setStyles(IStyleFactory... styles) { + this.styles = MoreStreams.map(styles, IStyleFactory::getStyle, Style[]::new); + + return this; + } + + public IconicToggle setStyles(Style... styles) { + this.styles = styles; + + return this; + } + + public IconicToggle setStyle(Style style, int value) { + value %= styles.length; + + styles[value] = style; if (this.value == value) { style.apply(this); @@ -46,55 +55,7 @@ public class IconicToggle extends IconicButton { @Override public void perform() { - setValue(!value); + setValue(value + 1); super.perform(); } - - public static class Style implements IGuiTooltipped