using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
[ExecuteInEditMode]
public class HyperText : HyperTextBase
{
protected override void OnEnable()
{
base.OnEnable();
string regexPattern = "]*href\\s*=\\s*[\"'](?[^\"']*)[\"'][^>]*>(?.*?)";
this.SetClickableByRegex(regexPattern, new Action(this.OnClickHyperLink), new Action(this.OnEnterHyperLink), new Action(this.OnExitHyperLink));
}
public void SetClickableByRegex(string regexPattern, Action onClick, Action onEnter, Action onExit)
{
this.SetClickableByRegex(regexPattern, Color.cyan, onClick, onEnter, onExit);
}
public void SetClickableByRegex(string regexPattern, Color color, Action onClick, Action onEnter, Action onExit)
{
if (string.IsNullOrEmpty(regexPattern) || onClick == null)
{
return;
}
this._entryTable[regexPattern] = new HyperText.Entry(regexPattern, color, onClick, onEnter, onExit);
}
public override void RemoveClickable()
{
base.RemoveClickable();
this._entryTable.Clear();
}
protected override void RegisterClickable()
{
foreach (HyperText.Entry entry in this._entryTable.Values)
{
Regex regex = new Regex(entry.RegexPattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
IEnumerator enumerator2 = regex.Matches(base.text.text).GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
object obj = enumerator2.Current;
Match match = (Match)obj;
Group group = match.Groups["text"];
Group group2 = match.Groups["href"];
base.RegisterClickable(group.Index, group.Value.Length, group2.Value, entry.Color, entry.OnClick, entry.OnEnter, entry.OnExit);
}
}
finally
{
IDisposable disposable;
if ((disposable = (enumerator2 as IDisposable)) != null)
{
disposable.Dispose();
}
}
}
}
private void OnClickHyperLink(string href)
{
if (GameMain.Instance.CMSystem.NetUse)
{
Application.OpenURL(href);
}
else
{
Debug.Log("リンク先:" + href);
}
}
private void OnEnterHyperLink(HyperTextBase.ClickableEntry entry)
{
}
private void OnExitHyperLink(HyperTextBase.ClickableEntry entry)
{
}
private readonly Dictionary _entryTable = new Dictionary();
private struct Entry
{
public Entry(string regexPattern, Color color, Action onClick, Action onEnter, Action onExit)
{
this.RegexPattern = regexPattern;
this.Color = color;
this.OnClick = onClick;
this.OnEnter = onEnter;
this.OnExit = onExit;
}
public string RegexPattern;
public Color Color;
public Action OnClick;
public Action OnEnter;
public Action OnExit;
}
}