#1913 Improved in-game documentation via tooltips for both machines & upgrades and solar panel exception fix (#1917)

* Overclocker and energy storage tooltip added

* Add default constructor to fix NoSuchMethodException

java.lang.NoSuchMethodException when loading world with existing solar panels

* Base Upgrade tooltips (Might move to reborn core)

* Migrated to tooltip callback and added most machine infos

* Optimize imports of stuff previously touched

* Added more informationtips and cleanup

* Revert itemUpgrade formatting

* Final touches

* Readd easter eggs, multi-line tips and translation updates

Easter egg tooltips are now restricted to only ctrl-hover
This commit is contained in:
Justin Vitale 2019-12-23 09:53:01 +11:00 committed by modmuss50
parent 34074d7a8a
commit 3dbc7feb62
11 changed files with 229 additions and 28 deletions

View file

@ -0,0 +1,100 @@
package techreborn.utils;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
import java.util.ArrayList;
import java.util.List;
public class DocumentAssistUtils {
// Colour constants
private static final Formatting instructColour = Formatting.BLUE;
private static final Formatting infoColour = Formatting.GOLD;
private static final Formatting statColour = Formatting.GOLD;
private static final Formatting posColour = Formatting.GREEN;
private static final Formatting negColour = Formatting.RED;
public static List<Text> getUpgradeStats(TRContent.Upgrades upgradeType, int count, boolean shiftHeld) {
List<Text> tips = new ArrayList<>();
boolean shouldStackCalculate = true;
switch (upgradeType) {
case OVERCLOCKER:
tips.add(getPositive("Speed increase", calculateValue(TechRebornConfig.overclockerSpeed * 100, count, shiftHeld), "%"));
tips.add(getNegative("Energy increase", calculateValue(TechRebornConfig.overclockerPower * 100, count, shiftHeld), "%"));
break;
case TRANSFORMER:
shouldStackCalculate = false;
break;
case ENERGY_STORAGE:
tips.add(getPositive("Storage increase", calculateValue(TechRebornConfig.energyStoragePower, count, shiftHeld), " E"));
break;
case SUPERCONDUCTOR:
tips.add(getPositive("Increased flow by: ", calculateValue(Math.pow(2, (TechRebornConfig.superConductorCount + 2)) * 100, count, shiftHeld), "%"));
break;
}
// Add reminder that they can use shift to calculate the entire stack
if(shouldStackCalculate && !shiftHeld){
tips.add(new LiteralText(instructColour + "Hold shift for stack calculation"));
}
return tips;
}
public static void addInfo(String inKey, List<Text> list){
addInfo(inKey, list, true);
}
public static void addInfo(String inKey, List<Text> list, boolean hidden){
String key = ("techreborn.message.info." + inKey);
if(I18n.hasTranslation(key)){
if(!hidden || Screen.hasShiftDown()){
String info = new TranslatableText(key).asString();
String infoLines[] = info.split("\\r?\\n");
for (String infoLine: infoLines) {
list.add(new LiteralText(infoColour + infoLine));
}
}else{
list.add(new LiteralText(instructColour + "Hold shift for info"));
}
}
}
private static int calculateValue(double value, int count, boolean shiftHeld) {
int calculatedVal;
if (shiftHeld) {
calculatedVal = (int) value * count;
} else {
calculatedVal = (int) value;
}
return calculatedVal;
}
private static Text getPositive(String text, int value, String unit) {
return new LiteralText(posColour + getStatStringUnit(text, value, unit));
}
private static Text getNegative(String text, int value, String unit) {
return new LiteralText(negColour + getStatStringUnit(text, value, unit));
}
private static String getStatStringUnit(String text, int value, String unit) {
return text + ": " + statColour + value + unit;
}
}