Properly render tooltips inside litepanes and add a warning label to the experimental skin drop

This commit is contained in:
Sollace 2018-08-14 23:46:27 +02:00
parent 640cf8ef03
commit 79f7de8f51
7 changed files with 73 additions and 11 deletions

View file

@ -29,15 +29,12 @@ public class Button extends GuiButton implements IActionable, IGuiTooltipped {
return this; return this;
} }
@Override
public Button setTooltip(List<String> tooltip) { public Button setTooltip(List<String> tooltip) {
this.tooltip = tooltip; this.tooltip = tooltip;
return this; return this;
} }
public Button setTooltip(String tooltip) {
return setTooltip(Splitter.on("\r\n").splitToList(GameGui.format(tooltip)));
}
@Override @Override
public void renderToolTip(Minecraft mc, int mouseX, int mouseY) { public void renderToolTip(Minecraft mc, int mouseX, int mouseY) {
if (visible && isMouseOver() && tooltip != null) { if (visible && isMouseOver() && tooltip != null) {

View file

@ -2,6 +2,9 @@ package com.minelittlepony.gui;
import com.mumfrey.liteloader.client.gui.GuiCheckbox; import com.mumfrey.liteloader.client.gui.GuiCheckbox;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
/** /**
@ -10,7 +13,9 @@ import net.minecraft.client.resources.I18n;
* @author Sollace * @author Sollace
* *
*/ */
public class Checkbox extends GuiCheckbox implements IActionable { public class Checkbox extends GuiCheckbox implements IActionable, IGuiTooltipped {
private List<String> tooltip = null;
private final IGuiCallback<Boolean> action; private final IGuiCallback<Boolean> action;
@ -25,4 +30,16 @@ public class Checkbox extends GuiCheckbox implements IActionable {
checked = action.perform(!checked); checked = action.perform(!checked);
} }
@Override
public Checkbox setTooltip(List<String> 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);
}
}
} }

View file

@ -2,6 +2,10 @@ package com.minelittlepony.gui;
import org.apache.commons.lang3.text.WordUtils; 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.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;
@ -19,6 +23,23 @@ public abstract class GameGui extends GuiScreen {
return I18n.format(string, pars); 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<String> 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) { protected static String toTitleCase(String string) {
return WordUtils.capitalize(string.toLowerCase()); return WordUtils.capitalize(string.toLowerCase());
} }
@ -26,15 +47,18 @@ public abstract class GameGui extends GuiScreen {
@Override @Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) { public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawContents(mouseX, mouseY, 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 -> { buttonList.forEach(button -> {
if (button instanceof IGuiTooltipped) { if (button instanceof IGuiTooltipped) {
((IGuiTooltipped)button).renderToolTip(mc, mouseX, mouseY); ((IGuiTooltipped)button).renderToolTip(mc, mouseX, mouseY);
} }
}); });
} }
protected void drawContents(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
}
} }

View file

@ -2,6 +2,17 @@ package com.minelittlepony.gui;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import com.google.common.base.Splitter;
import java.util.List;
public interface IGuiTooltipped { public interface IGuiTooltipped {
IGuiTooltipped setTooltip(List<String> 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); void renderToolTip(Minecraft mc, int mouseX, int mouseY);
} }

View file

@ -2,11 +2,15 @@ package com.minelittlepony.gui;
import java.io.IOException; import java.io.IOException;
import com.mumfrey.liteloader.gl.GLClippingPlanes;
import com.mumfrey.liteloader.modconfig.ConfigPanel; import com.mumfrey.liteloader.modconfig.ConfigPanel;
import com.mumfrey.liteloader.modconfig.ConfigPanelHost; import com.mumfrey.liteloader.modconfig.ConfigPanelHost;
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.renderer.GlStateManager;
import org.lwjgl.opengl.GL11;
/** /**
@ -65,7 +69,14 @@ public abstract class SettingsPanel extends GameGui implements ConfigPanel {
@Override @Override
public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) { 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 @Override

View file

@ -26,7 +26,7 @@ public class HDSkinsConfigPanel extends SettingsPanel {
} }
return checked; return checked;
})); })).setTooltip(formatMultiLine("hdskins.warning.experimental", 250));
} }
@Override @Override

View file

@ -30,3 +30,5 @@ hdskins.options.browse=Browse
hdskins.options.skindrops=Experimental Skin Drop hdskins.options.skindrops=Experimental Skin Drop
hdskins.options.cache=Clear Skin Cache 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.