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