养成基本完毕,新UI,修bug,装备初步,

This commit is contained in:
2026-03-23 22:37:14 +08:00
parent 49e45ac464
commit dd205b6cb4
2349 changed files with 261722 additions and 283 deletions
@@ -94,13 +94,13 @@ namespace EasyChart
var state = label.userData as AppliedState;
int themeId = theme != null ? theme.GetInstanceID() : 0;
UnityEngine.Object fontObj = theme != null ? theme.primaryFont : null;
UnityEngine.Object fontObj = ResolveRoleFontObject(theme, role);
int fontId = fontObj != null ? fontObj.GetInstanceID() : 0;
float scale = theme != null ? theme.fontScale : 1f;
float roleSizeOverride = ResolveRoleFontSizeOverride(theme, role);
float appliedRoleSizeOverride = roleSizeOverride;
if (roleSizeOverride >= 0f && HasInlineFontSize(label))
if (role != ChartTextRole.Tooltip && roleSizeOverride >= 0f && HasInlineFontSize(label))
{
appliedRoleSizeOverride = -1f;
}
@@ -225,6 +225,18 @@ namespace EasyChart
}
}
private static UnityEngine.Object ResolveRoleFontObject(ChartTheme theme, ChartTextRole role)
{
if (theme == null) return null;
if (role == ChartTextRole.Tooltip && theme.tooltipFont != null)
{
return theme.tooltipFont;
}
return theme.primaryFont;
}
private static void ApplyFont(Label label, UnityEngine.Object fontObj)
{
if (label == null) return;
@@ -6,6 +6,12 @@ namespace EasyChart
{
internal sealed class ChartTooltipModule : IChartModule
{
private static readonly Color DefaultTooltipTextColor = Color.white;
private static readonly Color DefaultTooltipBackgroundColor = new Color(0f, 0f, 0f, 0.8f);
private static readonly Color DefaultTooltipBorderColor = new Color(0f, 0f, 0f, 0f);
private static readonly Vector4 DefaultTooltipPadding = new Vector4(8f, 8f, 4f, 4f);
private const float DefaultTooltipCornerRadius = 4f;
private ChartElement _owner;
private VisualElement _cursorLine;
private Label _tooltip;
@@ -37,25 +43,15 @@ namespace EasyChart
{
_tooltip = new Label();
_tooltip.style.position = Position.Absolute;
_tooltip.style.backgroundColor = new Color(0, 0, 0, 0.8f);
_tooltip.style.color = Color.white;
_tooltip.style.paddingTop = 4;
_tooltip.style.paddingBottom = 4;
_tooltip.style.paddingLeft = 8;
_tooltip.style.paddingRight = 8;
_tooltip.style.borderTopLeftRadius = 4;
_tooltip.style.borderTopRightRadius = 4;
_tooltip.style.borderBottomLeftRadius = 4;
_tooltip.style.borderBottomRightRadius = 4;
_tooltip.visible = false;
_tooltip.userData = _owner;
ChartTextStyleApplier.ApplyLabel(_tooltip, _owner, ChartTextRole.Tooltip);
ApplyTooltipStyle(_tooltip, _owner);
chartArea.Add(_tooltip);
}
else if (_tooltip.parent == null)
{
_tooltip.userData = _owner;
ChartTextStyleApplier.ApplyLabel(_tooltip, _owner, ChartTextRole.Tooltip);
ApplyTooltipStyle(_tooltip, _owner);
chartArea.Add(_tooltip);
}
@@ -71,5 +67,46 @@ namespace EasyChart
_owner = null;
}
internal static void ApplyTooltipStyle(Label tooltip, ChartElement owner)
{
if (tooltip == null) return;
tooltip.style.position = Position.Absolute;
var theme = owner != null ? owner.GetEffectiveThemeInternal() : ChartThemeRegistry.GlobalTheme;
Color textColor = theme != null ? theme.tooltipTextColor : DefaultTooltipTextColor;
Color backgroundColor = theme != null ? theme.tooltipBackgroundColor : DefaultTooltipBackgroundColor;
Color borderColor = theme != null ? theme.tooltipBorderColor : DefaultTooltipBorderColor;
float borderWidth = theme != null ? Mathf.Max(0f, theme.tooltipBorderWidth) : 0f;
Vector4 padding = theme != null ? theme.tooltipPadding : DefaultTooltipPadding;
float cornerRadius = theme != null ? Mathf.Max(0f, theme.tooltipCornerRadius) : DefaultTooltipCornerRadius;
tooltip.style.color = textColor;
tooltip.style.backgroundColor = backgroundColor;
tooltip.style.paddingLeft = padding.x;
tooltip.style.paddingRight = padding.y;
tooltip.style.paddingTop = padding.z;
tooltip.style.paddingBottom = padding.w;
tooltip.style.borderTopLeftRadius = cornerRadius;
tooltip.style.borderTopRightRadius = cornerRadius;
tooltip.style.borderBottomLeftRadius = cornerRadius;
tooltip.style.borderBottomRightRadius = cornerRadius;
tooltip.style.borderLeftWidth = borderWidth;
tooltip.style.borderRightWidth = borderWidth;
tooltip.style.borderTopWidth = borderWidth;
tooltip.style.borderBottomWidth = borderWidth;
tooltip.style.borderLeftColor = borderColor;
tooltip.style.borderRightColor = borderColor;
tooltip.style.borderTopColor = borderColor;
tooltip.style.borderBottomColor = borderColor;
tooltip.userData = owner;
ChartTextStyleApplier.ApplyLabel(tooltip, owner, ChartTextRole.Tooltip);
}
}
}