2021-07-24 09:31:40 +08:00
/******************************************/
2021-05-21 07:24:02 +08:00
/* */
/* Copyright (c) 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
2019-10-22 04:09:04 +08:00
using System.Collections.Generic ;
2019-05-11 04:33:54 +08:00
using UnityEngine ;
using UnityEngine.UI ;
namespace XCharts
{
2019-08-01 23:49:30 +08:00
/// <summary>
/// Tooltip component.
2020-07-11 07:52:08 +08:00
/// 提示框组件。
2019-08-01 23:49:30 +08:00
/// </summary>
2019-05-11 04:33:54 +08:00
[System.Serializable]
2019-10-14 18:13:08 +08:00
public class Tooltip : MainComponent
2019-05-11 04:33:54 +08:00
{
2019-07-18 09:42:36 +08:00
/// <summary>
/// Indicator type.
2019-09-23 09:23:51 +08:00
/// 指示器类型。
2019-07-18 09:42:36 +08:00
/// </summary>
public enum Type
{
/// <summary>
/// line indicator.
2019-08-01 23:49:30 +08:00
/// 直线指示器
2019-07-18 09:42:36 +08:00
/// </summary>
Line ,
/// <summary>
/// shadow crosshair indicator.
2019-08-01 23:49:30 +08:00
/// 阴影指示器
2019-07-18 09:42:36 +08:00
/// </summary>
Shadow ,
/// <summary>
/// no indicator displayed.
2019-08-01 23:49:30 +08:00
/// 无指示器
2019-07-18 09:42:36 +08:00
/// </summary>
None ,
/// <summary>
/// crosshair indicator, which is actually the shortcut of enable two axisPointers of two orthometric axes.
2019-08-01 23:49:30 +08:00
/// 十字准星指示器。坐标轴显示Label和交叉线。
2019-07-18 09:42:36 +08:00
/// </summary>
Corss
}
2019-05-11 04:33:54 +08:00
[SerializeField] private bool m_Show ;
2019-07-18 09:42:36 +08:00
[SerializeField] private Type m_Type ;
2019-09-23 09:23:51 +08:00
[SerializeField] private string m_Formatter ;
2019-12-21 20:12:27 +08:00
[SerializeField] private string m_ItemFormatter ;
[SerializeField] private string m_TitleFormatter ;
2019-09-19 09:06:04 +08:00
[SerializeField] private float m_FixedWidth = 0 ;
[SerializeField] private float m_FixedHeight = 0 ;
[SerializeField] private float m_MinWidth = 0 ;
[SerializeField] private float m_MinHeight = 0 ;
2020-05-04 13:29:56 +08:00
[SerializeField] private string m_NumericFormatter = "" ;
2020-02-11 21:01:01 +08:00
[SerializeField] private float m_PaddingLeftRight = 5f ;
[SerializeField] private float m_PaddingTopBottom = 5f ;
2021-02-21 02:42:45 +08:00
[SerializeField] private bool m_IgnoreDataShow = false ;
2020-03-10 12:35:19 +08:00
[SerializeField] private string m_IgnoreDataDefaultContent = "-" ;
2020-06-05 08:52:36 +08:00
[SerializeField] private bool m_AlwayShow = false ;
2020-07-07 07:16:01 +08:00
[SerializeField] private Vector2 m_Offset = new Vector2 ( 18f , - 25f ) ;
2020-02-11 21:30:20 +08:00
[SerializeField] private Sprite m_BackgroundImage ;
2021-01-11 08:54:28 +08:00
[SerializeField] private TextStyle m_TextStyle = new TextStyle ( ) ;
[SerializeField] private LineStyle m_LineStyle = new LineStyle ( LineStyle . Type . None ) ;
2019-05-11 04:33:54 +08:00
2019-08-01 23:49:30 +08:00
private GameObject m_GameObject ;
private GameObject m_Content ;
2021-01-11 08:54:28 +08:00
private ChartText m_ContentText ;
2020-02-11 21:30:20 +08:00
private Image m_ContentImage ;
2019-08-01 23:49:30 +08:00
private RectTransform m_ContentRect ;
2020-02-11 21:01:01 +08:00
private RectTransform m_ContentTextRect ;
2021-04-27 12:47:46 +08:00
private List < int > lastDataIndex = new List < int > ( ) ;
2019-05-11 04:33:54 +08:00
2019-08-01 23:49:30 +08:00
/// <summary>
/// Whether to show the tooltip component.
/// 是否显示提示框组件。
/// </summary>
2020-03-05 20:25:19 +08:00
public bool show
{
get { return m_Show ; }
2021-01-11 08:54:28 +08:00
set { if ( PropertyUtil . SetStruct ( ref m_Show , value ) ) { SetAllDirty ( ) ; SetActive ( value ) ; } }
2020-03-05 20:25:19 +08:00
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// Indicator type.
/// 提示框指示器类型。
/// </summary>
2020-03-05 20:25:19 +08:00
public Type type
{
get { return m_Type ; }
2021-01-11 08:54:28 +08:00
set { if ( PropertyUtil . SetStruct ( ref m_Type , value ) ) SetAllDirty ( ) ; }
2020-03-05 20:25:19 +08:00
}
2019-09-19 09:06:04 +08:00
/// <summary>
2020-07-11 07:52:08 +08:00
/// A string template formatter for the total content of the prompt box. Support for wrapping lines with \n.
/// When formatter is not null, use formatter first, otherwise use itemFormatter.
/// Template variables are {.}, {a}, {b}, {c}, {d}.
/// {.} is the dot of the corresponding color of a Serie that is currently indicated or whose index is 0.
/// {a} is the series name of the serie that is currently indicated or whose index is 0.
/// {b} is the name of the data item serieData that is currently indicated or whose index is 0, or a category value (such as the X-axis of a line chart).
/// {c} is the value of a Y-dimension (dimesion is 1) from a Serie that is currently indicated or whose index is 0.
/// {d} is the percentage value of Y-dimensions (dimesion is 1) from serie that is currently indicated or whose index is 0, with no % sign.
/// {.1} represents a dot from serie corresponding color that specifies index as 1.
/// 1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.
/// {c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data).
/// {c1:2-2} represents the third data item from serie's third data item indexed to 1 (i.e., which data item must be specified to specify).
/// {d1:2: F2} indicates that a formatted string with a value specified separately is F2 (numericFormatter is used when numericFormatter is not specified).
2020-08-09 18:17:52 +08:00
/// {d:0.##} indicates that a formatted string with a value specified separately is 0.## (used for percentage, reserved 2 valid digits while avoiding the situation similar to "100.00%" when using f2 ).
2020-07-11 07:52:08 +08:00
/// Example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1} : {c1:1-1: f1}"
2020-06-02 12:37:14 +08:00
/// 提示框总内容的字符串模版格式器。支持用 \n 换行。当formatter不为空时, 优先使用formatter, 否则使用itemFormatter。
/// 模板变量有{.}、{a}、{b}、{c}、{d}。
2020-06-12 09:22:51 +08:00
/// {.}为当前所指示或index为0的serie的对应颜色的圆点。
/// {a}为当前所指示或index为0的serie的系列名name。
/// {b}为当前所指示或index为0的serie的数据项serieData的name, 或者类目值( 如折线图的X轴) 。
/// {c}为当前所指示或index为0的serie的y维( dimesion为1) 的数值。
/// {d}为当前所指示或index为0的serie的y维( dimesion为1) 百分比值, 注意不带%号。
2020-06-04 07:22:58 +08:00
/// {.1}表示指定index为1的serie对应颜色的圆点。
2020-06-12 09:22:51 +08:00
/// {a1}、{b1}、{c1}中的1表示指定index为1的serie。
2020-06-11 12:48:00 +08:00
/// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据( 一个数据项有多个数据, index为2表示第3个数据) 。
/// {c1:2-2}表示索引为1的serie的第3个数据项的第3个数据( 也就是要指定第几个数据项时必须要指定第几个数据) 。
2020-06-02 12:37:14 +08:00
/// {d1:2:f2}表示单独指定了数值的格式化字符串为f2( 不指定时用numericFormatter) 。
2020-08-09 18:17:52 +08:00
/// {d:0.##} 表示单独指定了数值的格式化字符串为 0.## ( 用于百分比, 保留2位有效数同时又能避免使用 f2 而出现的类似于"100.00%"的情况 )。
2020-07-11 07:52:08 +08:00
/// 示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}"
2019-09-23 09:23:51 +08:00
/// </summary>
public string formatter { get { return m_Formatter ; } set { m_Formatter = value ; } }
2019-12-21 20:12:27 +08:00
/// <summary>
2020-07-11 07:52:08 +08:00
/// The string template formatter for the tooltip title content. Support for wrapping lines with \n.
/// This is only valid if the itemFormatter is in effect.
/// The placeholder {I} can be set separately to indicate that the title is ignored and not displayed.
2020-06-11 07:44:11 +08:00
/// 提示框标题内容的字符串模版格式器。支持用 \n 换行。仅当itemFormatter生效时才有效。可以单独设置占位符{i}表示忽略不显示title。
2019-12-21 20:12:27 +08:00
/// </summary>
public string titleFormatter { get { return m_TitleFormatter ; } set { m_TitleFormatter = value ; } }
/// <summary>
2020-07-11 07:52:08 +08:00
/// a string template formatter for a single Serie or data item content. Support for wrapping lines with \n.
/// When formatter is not null, use formatter first, otherwise use itemFormatter.
2020-06-02 12:37:14 +08:00
/// 提示框单个serie或数据项内容的字符串模版格式器。支持用 \n 换行。当formatter不为空时, 优先使用formatter, 否则使用itemFormatter。
2019-12-21 20:12:27 +08:00
/// </summary>
public string itemFormatter { get { return m_ItemFormatter ; } set { m_ItemFormatter = value ; } }
2020-02-11 21:01:01 +08:00
2019-09-23 09:23:51 +08:00
/// <summary>
2020-07-15 09:11:35 +08:00
/// Fixed width. Higher priority than minWidth.
2019-09-19 09:06:04 +08:00
/// 固定宽度。比 minWidth 优先。
/// </summary>
public float fixedWidth { get { return m_FixedWidth ; } set { m_FixedWidth = value ; } }
/// <summary>
2020-07-15 09:11:35 +08:00
/// Fixed height. Higher priority than minHeight.
2019-09-19 09:06:04 +08:00
/// 固定高度。比 minHeight 优先。
/// </summary>
public float fixedHeight { get { return m_FixedHeight ; } set { m_FixedHeight = value ; } }
/// <summary>
2020-07-15 09:11:35 +08:00
/// Minimum width. If fixedWidth has a value, get fixedWidth first.
2019-09-19 09:06:04 +08:00
/// 最小宽度。如若 fixedWidth 设有值,优先取 fixedWidth。
/// </summary>
public float minWidth { get { return m_MinWidth ; } set { m_MinWidth = value ; } }
/// <summary>
2020-07-15 09:11:35 +08:00
/// Minimum height. If fixedHeight has a value, take priority over fixedHeight.
2019-09-19 09:06:04 +08:00
/// 最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。
/// </summary>
public float minHeight { get { return m_MinHeight ; } set { m_MinHeight = value ; } }
2019-10-26 05:02:32 +08:00
/// <summary>
2020-07-11 07:52:08 +08:00
/// Standard numeric format string. Used to format numeric values to display as strings.
/// Using 'Axx' form: 'A' is the single character of the format specifier, supporting 'C' currency,
/// 'D' decimal, 'E' exponent, 'F' number of vertices, 'G' regular, 'N' digits, 'P' percentage,
/// 'R' round tripping, 'X' hex etc. 'XX' is the precision specification, from '0' - '99'.
2020-05-04 13:29:56 +08:00
/// 标准数字格式字符串。用于将数值格式化显示为字符串。
/// 使用Axx的形式: A是格式说明符的单字符, 支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明, 从0-99。
/// 参考: https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
2019-10-26 05:02:32 +08:00
/// </summary>
2020-05-04 13:29:56 +08:00
/// <value></value>
public string numericFormatter
{
get { return m_NumericFormatter ; }
2021-01-11 08:54:28 +08:00
set { if ( PropertyUtil . SetClass ( ref m_NumericFormatter , value ) ) SetComponentDirty ( ) ; }
2020-05-04 13:29:56 +08:00
}
2020-02-11 20:37:48 +08:00
/// <summary>
2020-02-11 21:01:01 +08:00
/// the text padding of left and right. defaut:5.
/// 左右边距。
/// </summary>
public float paddingLeftRight { get { return m_PaddingLeftRight ; } set { m_PaddingLeftRight = value ; } }
/// <summary>
/// the text padding of top and bottom. defaut:5.
/// 上下边距。
/// </summary>
public float paddingTopBottom { get { return m_PaddingTopBottom ; } set { m_PaddingTopBottom = value ; } }
/// <summary>
2021-02-21 02:42:45 +08:00
/// Whether to show ignored data on tooltip.
/// 是否显示忽略数据在tooltip上。
/// </summary>
public bool ignoreDataShow { get { return m_IgnoreDataShow ; } set { m_IgnoreDataShow = value ; } }
/// <summary>
2020-07-15 09:11:35 +08:00
/// The default display character information for ignored data.
2020-03-10 09:12:47 +08:00
/// 被忽略数据的默认显示字符信息。
/// </summary>
2020-03-10 12:35:19 +08:00
public string ignoreDataDefaultContent { get { return m_IgnoreDataDefaultContent ; } set { m_IgnoreDataDefaultContent = value ; } }
2020-03-10 09:12:47 +08:00
/// <summary>
2020-02-11 21:30:20 +08:00
/// The image of icon.
/// 图标的图片。
/// </summary>
public Sprite backgroundImage { get { return m_BackgroundImage ; } set { m_BackgroundImage = value ; SetBackground ( m_BackgroundImage ) ; } }
/// <summary>
2020-07-15 09:11:35 +08:00
/// Whether to trigger after always display.
2020-06-04 07:46:07 +08:00
/// 是否触发后一直显示。
/// </summary>
public bool alwayShow { get { return m_AlwayShow ; } set { m_AlwayShow = value ; } }
/// <summary>
2020-07-15 09:11:35 +08:00
/// The position offset of tooltip relative to the mouse position.
2020-07-07 07:16:01 +08:00
/// 提示框相对于鼠标位置的偏移。
/// </summary>
public Vector2 offset { get { return m_Offset ; } set { m_Offset = value ; } }
/// <summary>
2020-07-15 09:11:35 +08:00
/// the text style of content.
2020-02-13 09:23:30 +08:00
/// 提示框内容文本样式。
/// </summary>
2020-03-05 20:25:19 +08:00
public TextStyle textStyle
{
get { return m_TextStyle ; }
set { if ( value ! = null ) { m_TextStyle = value ; SetComponentDirty ( ) ; } }
}
2020-02-13 09:23:30 +08:00
/// <summary>
2020-07-15 09:11:35 +08:00
/// the line style of indicator line.
2020-02-11 20:37:48 +08:00
/// 指示线样式。
/// </summary>
2020-03-05 20:25:19 +08:00
public LineStyle lineStyle
{
get { return m_LineStyle ; }
set { if ( value ! = null ) m_LineStyle = value ; SetComponentDirty ( ) ; }
}
/// <summary>
/// 组件是否需要刷新
/// </summary>
public override bool componentDirty
{
get { return m_ComponentDirty | | lineStyle . componentDirty | | textStyle . componentDirty ; }
}
2021-05-16 23:38:06 +08:00
public override void ClearComponentDirty ( )
2020-03-05 20:25:19 +08:00
{
base . ClearComponentDirty ( ) ;
lineStyle . ClearComponentDirty ( ) ;
textStyle . ClearComponentDirty ( ) ;
}
2020-04-23 13:07:49 +08:00
/// <summary>
/// 当前提示框所指示的Serie索引( 目前只对散点图有效) 。
/// </summary>
2021-04-27 12:47:46 +08:00
public Dictionary < int , List < int > > runtimeSerieIndex = new Dictionary < int , List < int > > ( ) ;
2019-07-18 09:42:36 +08:00
/// <summary>
/// The data index currently indicated by Tooltip.
2019-08-01 23:49:30 +08:00
/// 当前提示框所指示的数据项索引。
2019-07-18 09:42:36 +08:00
/// </summary>
2021-04-27 12:47:46 +08:00
public List < int > runtimeDataIndex { get { return m_RuntimeDateIndex ; } internal set { m_RuntimeDateIndex = value ; } }
private List < int > m_RuntimeDateIndex = new List < int > ( ) { - 1 , - 1 } ;
2019-08-01 23:49:30 +08:00
/// <summary>
/// the value for x indicator label.
/// 指示器X轴上要显示的值。
/// </summary>
2021-07-08 07:19:31 +08:00
public double [ ] runtimeXValues { get { return m_RuntimeXValue ; } internal set { m_RuntimeXValue = value ; } }
private double [ ] m_RuntimeXValue = new double [ 2 ] { - 1 , - 1 } ;
2019-08-01 23:49:30 +08:00
/// <summary>
/// the value for y indicator label.
/// 指示器Y轴上要显示的值。
/// </summary>
2021-07-08 07:19:31 +08:00
public double [ ] runtimeYValues { get { return m_RuntimeYValue ; } internal set { m_RuntimeYValue = value ; } }
private double [ ] m_RuntimeYValue = new double [ 2 ] { - 1 , - 1 } ;
2019-08-01 23:49:30 +08:00
/// <summary>
/// the current pointer position.
/// 当前鼠标位置。
/// </summary>
2019-11-02 08:24:37 +08:00
public Vector2 runtimePointerPos { get ; internal set ; }
2019-08-01 23:49:30 +08:00
/// <summary>
/// the width of tooltip.
/// 提示框宽。
/// </summary>
2019-11-02 08:24:37 +08:00
public float runtimeWidth { get { return m_ContentRect . sizeDelta . x ; } }
2019-08-01 23:49:30 +08:00
/// <summary>
/// the height of tooltip.
/// 提示框高。
/// </summary>
2019-11-02 08:24:37 +08:00
public float runtimeHeight { get { return m_ContentRect . sizeDelta . y ; } }
2019-08-01 23:49:30 +08:00
/// <summary>
/// Whether the tooltip has been initialized.
/// 提示框是否已初始化。
/// </summary>
2019-11-02 08:24:37 +08:00
public bool runtimeInited { get { return m_GameObject ! = null ; } }
2019-08-01 23:49:30 +08:00
/// <summary>
/// the gameObject of tooltip.
/// 提示框的gameObject。
/// </summary>
2019-11-02 08:24:37 +08:00
public GameObject runtimeGameObject { get { return m_GameObject ; } }
2020-07-01 09:38:00 +08:00
/// <summary>
/// 当前指示的角度。
/// </summary>
public float runtimeAngle { get ; internal set ; }
2021-01-11 08:54:28 +08:00
/// <summary>
/// 当前指示的Grid索引。
/// </summary>
public int runtimeGridIndex { get ; internal set ; }
public int runtimePolarIndex { get ; internal set ; }
2019-05-11 04:33:54 +08:00
public static Tooltip defaultTooltip
{
get
{
var tooltip = new Tooltip
{
2021-04-27 12:47:46 +08:00
m_Show = true
2019-05-11 04:33:54 +08:00
} ;
return tooltip ;
}
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 绑定提示框gameObject
/// </summary>
/// <param name="obj"></param>
2019-05-11 04:33:54 +08:00
public void SetObj ( GameObject obj )
{
m_GameObject = obj ;
2019-06-21 09:34:33 +08:00
m_GameObject . SetActive ( false ) ;
2019-05-11 04:33:54 +08:00
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 绑定提示框的文本框gameObject
/// </summary>
/// <param name="content"></param>
2019-05-29 09:53:30 +08:00
public void SetContentObj ( GameObject content )
{
m_Content = content ;
m_ContentRect = m_Content . GetComponent < RectTransform > ( ) ;
2020-02-11 21:30:20 +08:00
m_ContentImage = m_Content . GetComponent < Image > ( ) ;
2020-06-11 06:59:16 +08:00
m_ContentImage . raycastTarget = false ;
2021-01-11 08:54:28 +08:00
m_ContentText = new ChartText ( m_Content ) ;
2020-02-11 21:01:01 +08:00
if ( m_ContentText ! = null )
{
m_ContentTextRect = m_ContentText . gameObject . GetComponentInChildren < RectTransform > ( ) ;
}
2020-02-11 21:30:20 +08:00
SetBackground ( backgroundImage ) ;
2019-05-29 09:53:30 +08:00
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// Keep Tooltiop displayed at the top.
/// 保持Tooltiop显示在最顶上
/// </summary>
2019-07-18 09:42:36 +08:00
public void UpdateToTop ( )
{
2021-01-11 08:54:28 +08:00
if ( m_GameObject = = null ) return ;
2019-07-13 16:38:38 +08:00
int count = m_GameObject . transform . parent . childCount ;
m_GameObject . GetComponent < RectTransform > ( ) . SetSiblingIndex ( count - 1 ) ;
2019-05-11 04:33:54 +08:00
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 设置提示框文本背景色
/// </summary>
/// <param name="color"></param>
2019-05-29 09:53:30 +08:00
public void SetContentBackgroundColor ( Color color )
2019-05-11 04:33:54 +08:00
{
2020-02-11 21:30:20 +08:00
if ( m_ContentImage ! = null )
m_ContentImage . color = color ;
}
/// <summary>
/// 设置提示框文本背景图片
/// </summary>
/// <param name="sprite"></param>
public void SetBackground ( Sprite sprite )
{
if ( m_ContentImage ! = null )
{
m_ContentImage . type = Image . Type . Sliced ;
m_ContentImage . sprite = sprite ;
}
2019-05-29 09:53:30 +08:00
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 设置提示框文本字体颜色
/// </summary>
/// <param name="color"></param>
2019-05-29 09:53:30 +08:00
public void SetContentTextColor ( Color color )
{
2021-01-11 08:54:28 +08:00
if ( m_ContentText ! = null )
2019-05-15 09:44:18 +08:00
{
2021-01-11 08:54:28 +08:00
m_ContentText . SetColor ( color ) ;
2019-05-15 09:44:18 +08:00
}
2019-05-11 04:33:54 +08:00
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 设置提示框文本内容
/// </summary>
/// <param name="txt"></param>
2019-05-29 09:53:30 +08:00
public void UpdateContentText ( string txt )
2019-05-11 04:33:54 +08:00
{
2021-01-11 08:54:28 +08:00
if ( m_ContentText ! = null )
2019-05-15 09:44:18 +08:00
{
2021-01-11 08:54:28 +08:00
m_ContentText . SetText ( txt ) ;
2019-09-19 09:06:04 +08:00
float wid , hig ;
if ( m_FixedWidth > 0 ) wid = m_FixedWidth ;
2021-01-11 08:54:28 +08:00
else if ( m_MinWidth > 0 & & m_ContentText . GetPreferredWidth ( ) < m_MinWidth ) wid = m_MinWidth ;
else wid = m_ContentText . GetPreferredWidth ( ) + m_PaddingLeftRight * 2 ;
2019-09-19 09:06:04 +08:00
if ( m_FixedHeight > 0 ) hig = m_FixedHeight ;
2021-01-11 08:54:28 +08:00
else if ( m_MinHeight > 0 & & m_ContentText . GetPreferredHeight ( ) < m_MinHeight ) hig = m_MinHeight ;
else hig = m_ContentText . GetPreferredHeight ( ) + m_PaddingTopBottom * 2 ;
2020-02-11 21:01:01 +08:00
if ( m_ContentRect ! = null ) m_ContentRect . sizeDelta = new Vector2 ( wid , hig ) ;
if ( m_ContentTextRect ! = null )
{
m_ContentTextRect . anchoredPosition = new Vector3 ( m_PaddingLeftRight , - m_PaddingTopBottom ) ;
}
2019-05-29 09:53:30 +08:00
}
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 清除提示框指示数据
/// </summary>
2019-11-02 08:24:37 +08:00
internal void ClearValue ( )
2019-05-29 09:53:30 +08:00
{
2020-04-08 09:02:46 +08:00
for ( int i = 0 ; i < runtimeDataIndex . Count ; i + + ) runtimeDataIndex [ i ] = - 1 ;
for ( int i = 0 ; i < runtimeXValues . Length ; i + + ) runtimeXValues [ i ] = - 1 ;
for ( int i = 0 ; i < runtimeYValues . Length ; i + + ) runtimeYValues [ i ] = - 1 ;
2019-05-11 04:33:54 +08:00
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 提示框是否显示
/// </summary>
/// <returns></returns>
2019-07-28 00:44:53 +08:00
public bool IsActive ( )
{
return m_GameObject ! = null & & m_GameObject . activeInHierarchy ;
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 设置提示框是否显示
/// </summary>
/// <param name="flag"></param>
2019-05-11 04:33:54 +08:00
public void SetActive ( bool flag )
{
2020-07-01 09:38:00 +08:00
if ( ! flag & & m_AlwayShow ) return ;
2021-04-27 12:47:46 +08:00
if ( lastDataIndex . Count > = 2 )
lastDataIndex [ 0 ] = lastDataIndex [ 1 ] = - 1 ;
2019-06-03 23:15:23 +08:00
if ( m_GameObject & & m_GameObject . activeInHierarchy ! = flag )
2019-05-11 04:33:54 +08:00
m_GameObject . SetActive ( flag ) ;
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 更新文本框位置
/// </summary>
/// <param name="pos"></param>
2019-05-29 09:53:30 +08:00
public void UpdateContentPos ( Vector2 pos )
{
2019-06-21 09:34:33 +08:00
if ( m_Content )
2019-05-29 09:53:30 +08:00
m_Content . transform . localPosition = pos ;
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 获得当前提示框的位置
/// </summary>
/// <returns></returns>
2019-05-29 09:53:30 +08:00
public Vector3 GetContentPos ( )
2019-05-11 04:33:54 +08:00
{
2019-05-29 09:53:30 +08:00
if ( m_Content )
return m_Content . transform . localPosition ;
2019-05-15 09:44:18 +08:00
else
return Vector3 . zero ;
2019-05-11 04:33:54 +08:00
}
2019-07-18 09:42:36 +08:00
2019-08-01 23:49:30 +08:00
/// <summary>
/// Whether the data item indicated by tooltip has changed.
/// 提示框所指示的数据项是否发生变化。
/// </summary>
/// <returns></returns>
2019-07-18 09:42:36 +08:00
public bool IsDataIndexChanged ( )
{
2021-04-28 06:56:28 +08:00
if ( runtimeDataIndex . Count < 2 | | lastDataIndex . Count < 2 ) return false ;
2019-11-02 08:24:37 +08:00
return runtimeDataIndex [ 0 ] ! = lastDataIndex [ 0 ] | |
runtimeDataIndex [ 1 ] ! = lastDataIndex [ 1 ] ;
2019-07-18 09:42:36 +08:00
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 当前索引缓存
/// </summary>
2019-11-02 08:24:37 +08:00
internal void UpdateLastDataIndex ( )
2019-07-18 09:42:36 +08:00
{
2021-05-18 08:34:11 +08:00
if ( lastDataIndex . Count > 0 & & runtimeDataIndex . Count > 0 ) lastDataIndex [ 0 ] = runtimeDataIndex [ 0 ] ;
if ( lastDataIndex . Count > 0 & & runtimeDataIndex . Count > 1 ) lastDataIndex [ 1 ] = runtimeDataIndex [ 1 ] ;
2019-07-18 09:42:36 +08:00
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 当前提示框是否选中数据项
/// </summary>
/// <returns></returns>
2019-07-23 21:43:01 +08:00
public bool IsSelected ( )
{
2021-01-11 08:54:28 +08:00
foreach ( var index in runtimeDataIndex )
if ( index > = 0 ) return true ;
return false ;
2019-07-18 09:42:36 +08:00
}
2019-08-01 23:49:30 +08:00
/// <summary>
/// 指定索引的数据项是否被提示框选中
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public bool IsSelected ( int index )
2019-07-23 21:43:01 +08:00
{
2021-01-11 08:54:28 +08:00
foreach ( var temp in runtimeDataIndex )
if ( temp = = index ) return true ;
return false ;
2019-07-18 09:42:36 +08:00
}
2020-04-23 13:07:49 +08:00
public void ClearSerieDataIndex ( )
{
2020-06-14 18:16:23 +08:00
foreach ( var kv in runtimeSerieIndex )
2020-04-23 13:07:49 +08:00
{
kv . Value . Clear ( ) ;
}
}
public void AddSerieDataIndex ( int serieIndex , int dataIndex )
{
2020-06-14 18:16:23 +08:00
if ( ! runtimeSerieIndex . ContainsKey ( serieIndex ) )
2020-04-23 13:07:49 +08:00
{
2020-06-14 18:16:23 +08:00
runtimeSerieIndex [ serieIndex ] = new List < int > ( ) ;
2020-04-23 13:07:49 +08:00
}
2020-06-14 18:16:23 +08:00
runtimeSerieIndex [ serieIndex ] . Add ( dataIndex ) ;
2020-04-23 13:07:49 +08:00
}
public bool isAnySerieDataIndex ( )
{
2020-06-14 18:16:23 +08:00
foreach ( var kv in runtimeSerieIndex )
2020-04-23 13:07:49 +08:00
{
if ( kv . Value . Count > 0 ) return true ;
}
return false ;
}
2019-05-11 04:33:54 +08:00
}
}