diff options
author | YannickMG <yannickmg@gmail.com> | 2022-01-11 01:38:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-11 07:38:28 +0100 |
commit | 50db93d77aff4c678fffd8604375497ca27845eb (patch) | |
tree | c61df23d450df829f38f73eb4bcb0ae25e07298e /src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java | |
parent | d7ff357419a0589aae2debe6bf5805713aaef64f (diff) | |
download | GT5-Unofficial-50db93d77aff4c678fffd8604375497ca27845eb.tar.gz GT5-Unofficial-50db93d77aff4c678fffd8604375497ca27845eb.tar.bz2 GT5-Unofficial-50db93d77aff4c678fffd8604375497ca27845eb.zip |
The tooltips your mod wishes it had (#858)
* Add network support for chanining GT Tile GUIs
* Implemented Cover Tabs for IGregTechTileEntity
See GTNewHorizons/GT-New-Horizons-Modpack#9367 for details
* Added IGuiIcon
For easier addon extensibility of GT_GuiIcon
Also fixed Ghost Circuit tab tooltip overlapping right-side cover tabs
* Typo fix
* Fixed unintended scala import
* Tabs -> Spaces on the files I've touched
* Propagate needsSteamVenting to UIs
* Note special slot usage
Determine whether a machine's recipe list ever makes use of the special slot
* Add 2 configurable tooltip verbosity levels
* Readability pass
* New tooltip cache for flexibility
It loads a configurable amount of lines per key
based on the user's chosen verbosity levels
* Let GT_GuiTooltipJava to use verbosity and LSHIFT
* "Smart" auto-hiding tooltips
* GT_GUIContainerMetaTile_Machine tooltip support
* Rework Basic Machine tooltips
* Wordy tooltips -> extended tooltips (clearer)
* Fixed off-by-one error on power slot tooltips
* Cleanup
Diffstat (limited to 'src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java')
-rw-r--r-- | src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java | 93 |
1 files changed, 85 insertions, 8 deletions
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java index 6b9e70a71b..815970c754 100644 --- a/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java +++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java @@ -1,38 +1,115 @@ package gregtech.api.gui.widgets; -import java.awt.*; +import java.awt.Rectangle; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import org.lwjgl.input.Keyboard; + +import gregtech.api.util.GT_TooltipDataCache.TooltipData; public class GT_GuiTooltip { protected Rectangle bounds; - private List<String> text; + protected TooltipData data; + private List<String> displayedText; public boolean enabled = true; + /** + * Used to create a tooltip that will appear over the specified bounds. + * This will initially be a "static" tooltip that doesn't respect verbosity levels or respond to the shift key. + * + * @param bounds + * @param text + */ public GT_GuiTooltip(Rectangle bounds, String... text) { this.bounds = bounds; setToolTipText(text); } + /** + * Used to create a tooltip that will appear over the specified bounds. + * This will initially be a "dynamic" tooltip that respects verbosity levels and responds to the shift key. + * + * @param bounds + * @param data + */ + public GT_GuiTooltip(Rectangle bounds, TooltipData data) { + this.bounds = bounds; + // Trust that the tooltips have already been formatted and colored, just make sure it has no nulls + this.data = sanitizeTooltipData(data); + } + + private TooltipData sanitizeTooltipData(TooltipData data) { + if (data.text == null){ + data.text = Arrays.asList(new String[0]); + } + if (data.shiftText == null){ + data.shiftText = Arrays.asList(new String[0]); + } + return data; + } + + /** + * Called before the tooltip manager checks whether this tooltip is enabled + */ + protected void onTick() { + // Switch which of our 2 stored texts we're displaying now. + this.displayedText = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? this.data.shiftText : this.data.text; + // If this text is empty, let's not display a tooltip at all. + this.enabled = this.displayedText.size() != 0; + } + + /** + * Called once this tooltip has been determined to be enabled + */ protected void updateText() { } + /** + * Used to set a "static" tooltip that doesn't respect verbosity levels or respond to the shift key + * + * @param text + */ public void setToolTipText(String... text) { + this.data = formatTooltip(text); + } + + /** + * Used to set a "dynamic" tooltip that respects verbosity levels and responds to the shift key + * + * @param text + */ + public void setToolTipText(TooltipData data) { + // Trust that the tooltips have already been formatted and colored, just make sure it has no nulls + this.data = sanitizeTooltipData(data); + } + + /** + * Apply tooltip colors in case the text doesn't contain them and return as tooltip data + * + * @param text + * @return colored tooltip lines as list + */ + protected TooltipData formatTooltip(String[] text) { + List<String> list; if (text != null) { - this.text = new ArrayList<>(text.length); + list = new ArrayList<>(text.length); for (int i = 0; i < text.length; i++) { if (i == 0) - this.text.add("\u00a7f" + text[i]); + list.add("\u00a7f" + text[i]); else - this.text.add("\u00a77" + text[i]); + list.add("\u00a77" + text[i]); } - } else - this.text = new ArrayList<>(); + } else { + list = Arrays.asList(new String[0]); + } + return new TooltipData(list, list) ; } + public List<String> getToolTipText() { - return text; + return this.displayedText; } public Rectangle getBounds() { |