mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-11 13:04:05 +01:00
Fixed item tooltips
This commit is contained in:
parent
fb626eac1b
commit
5401d96942
@ -35,7 +35,7 @@ public class ItemDescription {
|
||||
|
||||
public static final ItemDescription MISSING = new ItemDescription(null);
|
||||
public static ITextComponent trim =
|
||||
new StringTextComponent(WHITE + "" + STRIKETHROUGH + " ");
|
||||
new StringTextComponent(" ").formatted(WHITE, STRIKETHROUGH);
|
||||
|
||||
public enum Palette {
|
||||
|
||||
@ -82,7 +82,7 @@ public class ItemDescription {
|
||||
SpeedLevel minimumRequiredSpeedLevel =
|
||||
isEngine ? SpeedLevel.NONE : ((IRotate) block).getMinimumRequiredSpeedLevel();
|
||||
boolean hasSpeedRequirement = minimumRequiredSpeedLevel != SpeedLevel.NONE;
|
||||
ResourceLocation id = ((Block) block).getRegistryName();
|
||||
ResourceLocation id = block.getRegistryName();
|
||||
Map<ResourceLocation, ConfigValue<Double>> impacts = config.stressValues.getImpacts();
|
||||
Map<ResourceLocation, ConfigValue<Double>> capacities = config.stressValues.getCapacities();
|
||||
boolean hasStressImpact = impacts.containsKey(id) && impacts.get(id)
|
||||
@ -178,9 +178,9 @@ public class ItemDescription {
|
||||
boolean hasControls = !linesOnCtrl.isEmpty();
|
||||
|
||||
if (hasDescription || hasControls) {
|
||||
String[] holdKey = Lang.translate("tooltip.holdKey", "$").getUnformattedComponentText()
|
||||
String[] holdKey = TooltipHelper.getUnformattedDeepText(Lang.translate("tooltip.holdKey", "$"))
|
||||
.split("\\$");
|
||||
String[] holdKeyOrKey = Lang.translate("tooltip.holdKeyOrKey", "$", "$").getUnformattedComponentText()
|
||||
String[] holdKeyOrKey = TooltipHelper.getUnformattedDeepText(Lang.translate("tooltip.holdKeyOrKey", "$", "$"))
|
||||
.split("\\$");
|
||||
ITextComponent keyShift = Lang.translate("tooltip.keyShift");
|
||||
ITextComponent keyCtrl = Lang.translate("tooltip.keyCtrl");
|
||||
@ -193,30 +193,23 @@ public class ItemDescription {
|
||||
continue;
|
||||
}
|
||||
|
||||
StringBuilder tabBuilder = new StringBuilder();
|
||||
tabBuilder.append(DARK_GRAY);
|
||||
IFormattableTextComponent tabBuilder = StringTextComponent.EMPTY.copy();
|
||||
if (hasDescription && hasControls) {
|
||||
tabBuilder.append(holdKeyOrKey[0]);
|
||||
tabBuilder.append(shift ? palette.hColor : palette.color);
|
||||
tabBuilder.append(keyShift);
|
||||
tabBuilder.append(DARK_GRAY);
|
||||
tabBuilder.append(keyShift.copy().formatted(shift ? palette.hColor : palette.color));
|
||||
tabBuilder.append(holdKeyOrKey[1]);
|
||||
tabBuilder.append(ctrl ? palette.hColor : palette.color);
|
||||
tabBuilder.append(keyCtrl);
|
||||
tabBuilder.append(DARK_GRAY);
|
||||
tabBuilder.append(keyCtrl.copy().formatted(ctrl ? palette.hColor : palette.color));
|
||||
tabBuilder.append(holdKeyOrKey[2]);
|
||||
|
||||
} else {
|
||||
tabBuilder.append(holdKey[0]);
|
||||
tabBuilder.append((hasDescription ? shift : ctrl) ? palette.hColor : palette.color);
|
||||
tabBuilder.append(hasDescription ? keyShift : keyCtrl);
|
||||
tabBuilder.append(DARK_GRAY);
|
||||
tabBuilder.append((hasDescription ? keyShift : keyCtrl).copy().formatted((hasDescription ? shift : ctrl) ? palette.hColor : palette.color));
|
||||
tabBuilder.append(holdKey[1]);
|
||||
}
|
||||
|
||||
list.add(0, new StringTextComponent(tabBuilder.toString()));
|
||||
tabBuilder.formatted(DARK_GRAY);
|
||||
list.add(0, tabBuilder);
|
||||
if (shift || ctrl)
|
||||
list.add(1, new StringTextComponent(""));
|
||||
list.add(1, StringTextComponent.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class TooltipHelper {
|
||||
lineStart.formatted(defaultColor);
|
||||
|
||||
List<ITextComponent> lines = new ArrayList<>();
|
||||
String rawText = c.getUnformattedComponentText();
|
||||
String rawText = getUnformattedDeepText(c);
|
||||
String[] words = rawText.split(" ");
|
||||
String word;
|
||||
IFormattableTextComponent currentLine = lineStart.copy();
|
||||
@ -251,4 +251,13 @@ public class TooltipHelper {
|
||||
return l.get();
|
||||
}
|
||||
|
||||
public static String getUnformattedDeepText(ITextComponent component) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append(component.getString());
|
||||
component.getSiblings().forEach(c -> {
|
||||
b.append(getUnformattedDeepText(c));
|
||||
});
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,14 +30,13 @@ public class WipScription extends ItemDescription {
|
||||
|
||||
@Override
|
||||
public List<ITextComponent> addInformation(List<ITextComponent> tooltip) {
|
||||
tooltip.set(0, new StringTextComponent(decorateName(tooltip.get(0).getString())));
|
||||
tooltip.set(0, decorateName(tooltip.get(0)));
|
||||
tooltip.addAll(getLines());
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
public static String decorateName(String name) {
|
||||
return TextFormatting.GRAY + "" + TextFormatting.STRIKETHROUGH + name + TextFormatting.GOLD + " "
|
||||
+ Lang.translate("tooltip.wip");
|
||||
public static ITextComponent decorateName(ITextComponent name) {
|
||||
return StringTextComponent.EMPTY.copy().append(name.copy().formatted(TextFormatting.GRAY, TextFormatting.STRIKETHROUGH)).append(" ").append(Lang.translate("tooltip.wip").formatted(TextFormatting.GOLD));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user