Skip to content

Commit 61a700f

Browse files
committed
Features Added, Version Change:
Max tooltips, Show Time, and Fade Time. Animations updated to be much smoother. Hovering over tooltips will force the oldest tooltips to start fading instantly if there are more than "Max Tooltips" already on screen. After tooltips begin fading, hovering on the tooltip will fade it back in instead of bringing them instantly to full opacity.
1 parent 8804350 commit 61a700f

File tree

16 files changed

+156
-131
lines changed

16 files changed

+156
-131
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The Genuine Open Source License
22

3-
Copyright (c) 2018 Brian Wiegand (GenuineSounds)
3+
Copyright (c) 2019 Brian Wiegand (GenuineSounds)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ World Tooltips is a mod for Minecraft that adds tooltips over items on the groun
44

55
License
66
=======
7-
Copyright (c) 2018 Brian Wiegand (GenuineSounds)
7+
Copyright (c) 2019 Brian Wiegand (GenuineSounds)
88
Licensed for use and redistribution under the "Genuine Open Source License" non-commercial care-free license.
99

1010
Read the full license [here](LICENSE.md).

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ archivesBaseName = "World-Tooltips"
1818

1919
group = "ninja.genuine.tooltips"
2020
ext.revision = 'git rev-list --count HEAD'.execute().text.trim()
21-
version = "1.12.2-1.2.8-${revision}"
21+
version = "1.12.2-1.2.9-${revision}"
2222

2323
sourceCompatibility = targetCompatibility = "1.8"
2424
compileJava {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
22
# This is required to provide enough memory for the Minecraft decompilation process.
3-
org.gradle.jvmargs=-Xmx4G
3+
org.gradle.jvmargs=-Xmx6G

src/main/java/ninja/genuine/tooltips/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ public class Constants {
66
public static final String NAME = "World Tooltips";
77
public static final String GUIID = "worldtooltipsgui";
88
public static final String URL = "http://genuine.ninja/worldtooltips/";
9-
public static final String VERSION = "1.2.8";
9+
public static final String VERSION = "1.2.9";
1010
}

src/main/java/ninja/genuine/tooltips/WorldTooltips.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package ninja.genuine.tooltips;
22

3+
import ninja.genuine.tooltips.client.config.Config;
4+
import ninja.genuine.tooltips.client.gui.GuiConfigTooltips;
5+
import ninja.genuine.tooltips.client.render.TooltipEvent;
6+
import ninja.genuine.utils.ModUtils;
7+
38
import org.lwjgl.input.Keyboard;
49

510
import net.minecraft.client.Minecraft;
@@ -17,18 +22,14 @@
1722
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
1823
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
1924
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
20-
import ninja.genuine.tooltips.client.config.Config;
21-
import ninja.genuine.tooltips.client.gui.GuiConfigTooltips;
22-
import ninja.genuine.tooltips.client.render.RenderEvent;
23-
import ninja.genuine.utils.ModUtils;
2425

2526
@Mod(modid = Constants.MODID, name = Constants.NAME, version = Constants.VERSION, canBeDeactivated = true, clientSideOnly = true, updateJSON = Constants.URL
2627
+ "update.json", useMetadata = true, guiFactory = "ninja.genuine.tooltips.client.TooltipsGuiFactory")
2728
public class WorldTooltips {
2829

2930
@Instance(Constants.MODID)
3031
public static WorldTooltips instance;
31-
private RenderEvent events = new RenderEvent();
32+
private TooltipEvent events = new TooltipEvent();
3233
private KeyBinding configKey = new KeyBinding(Constants.NAME + " Configuration", Keyboard.KEY_SUBTRACT, Constants.NAME);
3334

3435
public WorldTooltips() {
@@ -37,7 +38,8 @@ public WorldTooltips() {
3738

3839
@EventHandler
3940
public void pre(FMLPreInitializationEvent event) {
40-
Config.setConfiguration(new Configuration(event.getSuggestedConfigurationFile(), Constants.VERSION));
41+
Configuration cfg = new Configuration(event.getSuggestedConfigurationFile(), Constants.VERSION);
42+
Config.setConfiguration(cfg);
4143
Config.populate();
4244
Config.save();
4345
ClientRegistry.registerKeyBinding(configKey);

src/main/java/ninja/genuine/tooltips/client/Tooltip.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
import java.util.ArrayList;
88
import java.util.List;
99

10+
import ninja.genuine.tooltips.client.config.Config;
11+
import ninja.genuine.utils.ModUtils;
12+
1013
import net.minecraft.client.Minecraft;
1114
import net.minecraft.client.gui.ScaledResolution;
1215
import net.minecraft.client.util.ITooltipFlag.TooltipFlags;
1316
import net.minecraft.entity.item.EntityItem;
1417
import net.minecraft.entity.player.EntityPlayer;
1518
import net.minecraft.util.text.TextFormatting;
1619
import net.minecraftforge.fml.common.Loader;
17-
import ninja.genuine.tooltips.client.config.Config;
18-
import ninja.genuine.utils.ModUtils;
1920

2021
public class Tooltip implements Comparable<Tooltip> {
2122

@@ -27,20 +28,25 @@ public class Tooltip implements Comparable<Tooltip> {
2728
private TextFormatting textFormatting;
2829
private List<String> text = new ArrayList<>();
2930
private int width, height;
30-
private int tickCount = 240;
31+
private int tickCount;
32+
private int fadeCount;
3133
public double distanceToPlayer;
3234
public double scale;
3335
public int alpha;
3436
public int colorBackground;
3537
public int colorOutline;
3638
public int colorOutlineShade;
39+
private boolean forceFade;
40+
private boolean countDown = true;
3741

3842
public Tooltip(EntityPlayer player, EntityItem entity) {
3943
this.player = player;
4044
this.entity = entity;
4145
textFormatting = entity.getItem().getRarity().rarityColor;
4246
generateTooltip(player);
4347
calculateSize();
48+
fadeCount = cfg.getFadeTime();
49+
tickCount = cfg.getShowTime() + fadeCount;
4450
}
4551

4652
private void generateTooltip(EntityPlayer player) {
@@ -69,7 +75,14 @@ public void tick() {
6975
sr = new ScaledResolution(mc);
7076
if (entity == null || entity.isDead)
7177
tickCount = 0;
72-
tickCount--;
78+
if (countDown)
79+
tickCount--;
80+
else
81+
tickCount += cfg.getFadeTime() / 4;
82+
if (tickCount < 0)
83+
tickCount = 0;
84+
if (tickCount > cfg.getShowTime() + fadeCount)
85+
tickCount = cfg.getShowTime() + fadeCount;
7386
generateTooltip(player);
7487
calculateSize();
7588
distanceToPlayer = entity.getDistance(player);
@@ -84,10 +97,21 @@ public void tick() {
8497
colorBackground = cfg.getBackgroundColor() | alpha;
8598
colorOutline = ((cfg.isOverridingOutline() ? cfg.getOutlineColor() : ModUtils.getRarityColor(this)) | alpha) & 0xFFE0E0E0;
8699
colorOutlineShade = ((colorOutline & 0xFEFEFE) >> 1) | alpha;
100+
countDown = true;
87101
}
88102

89103
public double getFade() {
90-
return Math.abs(Math.pow(-1, 2) * (tickCount / 60D));
104+
if (tickCount > fadeCount)
105+
return 1D;
106+
return Math.abs(Math.pow(-1, 2) * ((double) tickCount / (double) fadeCount));
107+
}
108+
109+
public void forceFade() {
110+
if (forceFade)
111+
return;
112+
tickCount = 10;
113+
fadeCount = 10;
114+
forceFade = true;
91115
}
92116

93117
private boolean modsAreLoaded() {
@@ -99,8 +123,11 @@ public int compareTo(Tooltip o) {
99123
return (int) (o.distanceToPlayer * 10000 - distanceToPlayer * 10000);
100124
}
101125

102-
public void reset() {
103-
tickCount = 240;
126+
public boolean reset() {
127+
if (forceFade)
128+
return false;
129+
countDown = false;
130+
return true;
104131
}
105132

106133
public EntityItem getEntity() {

src/main/java/ninja/genuine/tooltips/client/TooltipsGuiFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import java.util.Set;
44

5+
import ninja.genuine.tooltips.client.gui.GuiConfigTooltips;
6+
57
import net.minecraft.client.Minecraft;
68
import net.minecraft.client.gui.GuiScreen;
79
import net.minecraftforge.fml.client.IModGuiFactory;
8-
import ninja.genuine.tooltips.client.gui.GuiConfigTooltips;
910

1011
public class TooltipsGuiFactory implements IModGuiFactory {
1112

src/main/java/ninja/genuine/tooltips/client/config/ColorEntry.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import static net.minecraft.util.text.TextFormatting.RED;
66
import static net.minecraft.util.text.TextFormatting.WHITE;
77

8+
import ninja.genuine.tooltips.client.gui.GuiColorButton;
9+
import ninja.genuine.tooltips.client.gui.GuiColorPicker;
10+
811
import net.minecraftforge.fml.client.config.GuiConfig;
912
import net.minecraftforge.fml.client.config.GuiConfigEntries;
1013
import net.minecraftforge.fml.client.config.GuiConfigEntries.StringEntry;
1114
import net.minecraftforge.fml.client.config.HoverChecker;
1215
import net.minecraftforge.fml.client.config.IConfigElement;
13-
import ninja.genuine.tooltips.client.gui.GuiColorButton;
14-
import ninja.genuine.tooltips.client.gui.GuiColorPicker;
1516

1617
public class ColorEntry extends StringEntry {
1718

src/main/java/ninja/genuine/tooltips/client/config/Config.java

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,35 @@ public boolean isEnabled() {
4646
}
4747

4848
public int getRenderDistance() {
49-
return base.getInt("Maximum Drawing Distance", category_behavior, 8, 2, 64, "Set the maximum distance that tooltips should be displayed from.");
49+
return base.getInt("Maximum Drawing Distance", category_behavior, 12, 2, 64, "Sets the maximum distance that tooltips will be displayed.");
50+
}
51+
52+
public int getMaxTooltips() {
53+
return base.getInt("Max Tooltips", category_behavior, 4, 0, 999, "Sets the maximum number of tooltips shown on screenat once.");
54+
}
55+
56+
public int getShowTime() {
57+
return base.getInt("Ticks to Show", category_behavior, 40, 0, 1000, "Sets the number of ticks to show the tooltips before they fade.");
58+
}
59+
60+
public int getFadeTime() {
61+
return base.getInt("Fade Duration", category_behavior, 10, 0, 1000, "Sets the duration in ticks for the fading process.");
5062
}
5163

5264
public boolean isOverridingOutline() {
53-
return base.getBoolean("Override Outline Color", category_behavior, false, "If enabled outline color will be manually set instead of default behavior.");
65+
return base.getBoolean("Override Outline Color", category_behavior, false, "Use the custom outline color instead.");
5466
}
5567

5668
public boolean isHidingModName() {
57-
return base.getBoolean("Hide Mod Name", category_behavior, false, "Hide mod names on tooltips. Enable if you see two mod names.");
69+
return base.getBoolean("Hide Mod Name", category_behavior, false, "Hide mod names on tooltips. Enable this if you see two mod names.");
5870
}
5971

6072
public Property getOpacity() {
61-
return base.get(category_appearance, "Tooltip Opacity", 0.75, "Set the opacity for the tooltips; 0 being completely invisible and 1 being completely opaque.", 0.0, 1.0);
73+
return base.get(category_appearance, "Tooltip Opacity", 0.75, "Sets the opacity for the tooltips; 0 being completely invisible and 1 being completely opaque.", 0.0, 1.0);
6274
}
6375

6476
public Property getScale() {
65-
return base.get(category_appearance, "Tooltip Scale", 1.0, "Set the scale for the tooltips; 0.1 being one thenth the size and 4 being four times the size.", 0.1, 4.0);
77+
return base.get(category_appearance, "Tooltip Scale", 1.0, "Sets the scale for the tooltips; 0.1 being one thenth the size and 4 being four times the size.", 0.1, 4.0);
6678
}
6779

6880
public Property getOutline() {
@@ -81,22 +93,25 @@ public int getOutlineColor() {
8193
return decodeProperty(getOutline()) & 0xFFFFFF;
8294
}
8395

84-
private int decodeProperty(Property property) {
85-
try {
86-
return Integer.decode(property.getString());
87-
} catch (NumberFormatException e) {
88-
return Integer.decode(property.getDefault());
89-
}
90-
}
91-
9296
private void internalPopulation() {
9397
isEnabled();
9498
getOpacity().setConfigEntryClass(NumberSliderEntry.class);
9599
getScale().setConfigEntryClass(NumberSliderEntry.class);
96100
getOutline().setConfigEntryClass(ColorEntry.class);
97101
getBackground().setConfigEntryClass(ColorEntry.class);
98102
getRenderDistance();
103+
getMaxTooltips();
104+
getShowTime();
105+
getFadeTime();
99106
isHidingModName();
100107
isOverridingOutline();
101108
}
109+
110+
private int decodeProperty(Property property) {
111+
try {
112+
return Integer.decode(property.getString());
113+
} catch (NumberFormatException e) {
114+
return Integer.decode(property.getDefault());
115+
}
116+
}
102117
}

0 commit comments

Comments
 (0)