diff --git a/src/hdskins/java/com/minelittlepony/gui/Button.java b/src/hdskins/java/com/minelittlepony/gui/Button.java index da1392a4..7c16bfad 100644 --- a/src/hdskins/java/com/minelittlepony/gui/Button.java +++ b/src/hdskins/java/com/minelittlepony/gui/Button.java @@ -29,15 +29,12 @@ public class Button extends GuiButton implements IActionable, IGuiTooltipped { return this; } + @Override public Button setTooltip(List tooltip) { this.tooltip = tooltip; return this; } - public Button setTooltip(String tooltip) { - return setTooltip(Splitter.on("\r\n").splitToList(GameGui.format(tooltip))); - } - @Override public void renderToolTip(Minecraft mc, int mouseX, int mouseY) { if (visible && isMouseOver() && tooltip != null) { diff --git a/src/hdskins/java/com/minelittlepony/gui/Checkbox.java b/src/hdskins/java/com/minelittlepony/gui/Checkbox.java index cdcf9b64..3c4cd78b 100644 --- a/src/hdskins/java/com/minelittlepony/gui/Checkbox.java +++ b/src/hdskins/java/com/minelittlepony/gui/Checkbox.java @@ -2,6 +2,9 @@ package com.minelittlepony.gui; import com.mumfrey.liteloader.client.gui.GuiCheckbox; +import java.util.List; + +import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; /** @@ -10,7 +13,9 @@ import net.minecraft.client.resources.I18n; * @author Sollace * */ -public class Checkbox extends GuiCheckbox implements IActionable { +public class Checkbox extends GuiCheckbox implements IActionable, IGuiTooltipped { + + private List tooltip = null; private final IGuiCallback action; @@ -25,4 +30,16 @@ public class Checkbox extends GuiCheckbox implements IActionable { checked = action.perform(!checked); } + @Override + public Checkbox setTooltip(List tooltip) { + this.tooltip = tooltip; + return this; + } + + @Override + public void renderToolTip(Minecraft mc, int mouseX, int mouseY) { + if (visible && isMouseOver() && tooltip != null) { + mc.currentScreen.drawHoveringText(tooltip, mouseX, mouseY); + } + } } diff --git a/src/hdskins/java/com/minelittlepony/gui/GameGui.java b/src/hdskins/java/com/minelittlepony/gui/GameGui.java index 93dd6870..5a277771 100644 --- a/src/hdskins/java/com/minelittlepony/gui/GameGui.java +++ b/src/hdskins/java/com/minelittlepony/gui/GameGui.java @@ -2,6 +2,10 @@ package com.minelittlepony.gui; import org.apache.commons.lang3.text.WordUtils; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; @@ -19,6 +23,23 @@ public abstract class GameGui extends GuiScreen { return I18n.format(string, pars); } + /** + * Formats a translation string and returns it in a list wrapped to a given width. + * This can be safely used in initGui, where the fontRenderer is often still null. + */ + protected List formatMultiLine(String string, int width, Object...pars) { + FontRenderer fr = fontRenderer; + + if (fr == null) { + fr = Minecraft.getMinecraft().fontRenderer; + } + + return fr.listFormattedStringToWidth(format(string, pars), width); + } + + /** + * Converts a given string to title case regardless of initial case. + */ protected static String toTitleCase(String string) { return WordUtils.capitalize(string.toLowerCase()); } @@ -26,15 +47,18 @@ public abstract class GameGui extends GuiScreen { @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { drawContents(mouseX, mouseY, partialTicks); + postDrawContents(mouseX, mouseY, partialTicks); + } + protected void drawContents(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + } + + protected void postDrawContents(int mouseX, int mouseY, float partialTicks) { buttonList.forEach(button -> { if (button instanceof IGuiTooltipped) { ((IGuiTooltipped)button).renderToolTip(mc, mouseX, mouseY); } }); } - - protected void drawContents(int mouseX, int mouseY, float partialTicks) { - super.drawScreen(mouseX, mouseY, partialTicks); - } } diff --git a/src/hdskins/java/com/minelittlepony/gui/IGuiTooltipped.java b/src/hdskins/java/com/minelittlepony/gui/IGuiTooltipped.java index edb3acaa..48a47baf 100644 --- a/src/hdskins/java/com/minelittlepony/gui/IGuiTooltipped.java +++ b/src/hdskins/java/com/minelittlepony/gui/IGuiTooltipped.java @@ -2,6 +2,17 @@ package com.minelittlepony.gui; import net.minecraft.client.Minecraft; +import com.google.common.base.Splitter; + +import java.util.List; + public interface IGuiTooltipped { + + IGuiTooltipped setTooltip(List tooltip); + + default IGuiTooltipped setTooltip(String tooltip) { + return setTooltip(Splitter.onPattern("\r?\n|\\\\n").splitToList(GameGui.format(tooltip))); + } + void renderToolTip(Minecraft mc, int mouseX, int mouseY); } diff --git a/src/hdskins/java/com/minelittlepony/gui/SettingsPanel.java b/src/hdskins/java/com/minelittlepony/gui/SettingsPanel.java index e73fd803..f6204d48 100644 --- a/src/hdskins/java/com/minelittlepony/gui/SettingsPanel.java +++ b/src/hdskins/java/com/minelittlepony/gui/SettingsPanel.java @@ -2,11 +2,15 @@ package com.minelittlepony.gui; import java.io.IOException; +import com.mumfrey.liteloader.gl.GLClippingPlanes; import com.mumfrey.liteloader.modconfig.ConfigPanel; import com.mumfrey.liteloader.modconfig.ConfigPanelHost; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.GlStateManager; + +import org.lwjgl.opengl.GL11; /** @@ -65,7 +69,14 @@ public abstract class SettingsPanel extends GameGui implements ConfigPanel { @Override public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) { - drawScreen(mouseX, mouseY, partialTicks); + drawContents(mouseX, mouseY, partialTicks); + + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GLClippingPlanes.glDisableClipping(); + + postDrawContents(mouseX, mouseY, partialTicks); + + GlStateManager.popAttrib(); } @Override diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/HDSkinsConfigPanel.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/HDSkinsConfigPanel.java index 67e6eaa5..56cca71c 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/HDSkinsConfigPanel.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/HDSkinsConfigPanel.java @@ -26,7 +26,7 @@ public class HDSkinsConfigPanel extends SettingsPanel { } return checked; - })); + })).setTooltip(formatMultiLine("hdskins.warning.experimental", 250)); } @Override diff --git a/src/hdskins/resources/assets/hdskins/lang/en_us.lang b/src/hdskins/resources/assets/hdskins/lang/en_us.lang index 30ab5730..ecfa7c51 100644 --- a/src/hdskins/resources/assets/hdskins/lang/en_us.lang +++ b/src/hdskins/resources/assets/hdskins/lang/en_us.lang @@ -30,3 +30,5 @@ hdskins.options.browse=Browse hdskins.options.skindrops=Experimental Skin Drop hdskins.options.cache=Clear Skin Cache + +hdskins.warning.experimental=§6WARNING: This feature is §4experimental§6, meaning things may break or derp or even slurp. Enabling this means you accept responsibility for what may happen to your chickens. \ No newline at end of file