/*-------------------------------------------------------------------------------------
--- 创建人:
--- 描 述:
--- 创建时间: 2024年5月20日
-------------------------------------------------------------------------------------*/
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Text;
namespace Game.HotFix
{
public enum PCHoverNormalType
{
///
/// 无
///
None,
///
/// 属性信息
///
AttInfo,
}
///
/// xx 功能界面
///
public class TipsNormalPCHoverUI : UIBase
{
//UIAutoBuild_CtrlDefine
public TextMeshProUGUI tmpContent;
//UIAutoBuild_CtrlDefine
public RectTransform rectTrans;
#region 通用信号
static long LastFlag_skillClientid = -1;
public static void SetHoldData(bool Enter, string pStr)
{
if (Enter)
{
TipsNormalPCHoverUI ui;
if (HotfixEntry.UI.IsOpen())
ui = HotfixEntry.UI.GetUI();
else
ui = HotfixEntry.UI.OpenUI(eUINodeType.NodeTip) as TipsNormalPCHoverUI;
ui.StartShow(pStr);
ui.transform.SetAsLastSibling();
}
else
{
if (HotfixEntry.UI.IsOpen())
HotfixEntry.UI.Hide();
}
}
public static void SetHoldData(bool Enter, int pID, PCHoverNormalType pType, string pValue = "")
{
if (pID <= 0)
return;
if (Enter)
{
TipsNormalPCHoverUI ui;
if (HotfixEntry.UI.IsOpen())
ui = HotfixEntry.UI.GetUI();
else
ui = HotfixEntry.UI.OpenUI(eUINodeType.NodeTip) as TipsNormalPCHoverUI;
string tStr = string.Empty;
switch (pType)
{
case PCHoverNormalType.None:
break;
case PCHoverNormalType.AttInfo:
//AttEnumData tData = HotfixEntry.Luban.GetAttEnumData(pID);
//if(tData != null)
//{
// tStr = tData.Describe;
//}
tStr = GetAttStr(pID, pValue);
break;
default:
break;
}
ui.StartShow(tStr);
ui.transform.SetAsLastSibling();
}
else
{
if (HotfixEntry.UI.IsOpen())
HotfixEntry.UI.Hide();
}
}
#endregion
public override void Awake()
{
//UIAutoBuild_CtrlBind
base.Awake();
Transform tf = transform;
tmpContent = tf.Find("tmpContent").GetComponent();
//UIAutoBuild_CtrlBind
rectTrans = tf.GetComponent();
}
void OnEnable()
{
//UIAutoBuild_EventReg
//UIAutoBuild_EventReg
}
void OnDisable()
{
//UIAutoBuild_EventUnReg
//UIAutoBuild_EventUnReg
}
void Start()
{
}
// 每次显示都执行, 可定义参数
public override void Show(params object[] _params)
{
base.Show(_params);
}
private void Update()
{
SetPos();
}
void StartShow(string pStr)
{
SetData(pStr);
LayoutRebuilder.ForceRebuildLayoutImmediate(rectTrans);
}
Vector2 sizeDelta;
void SetPos()
{
Vector2 mousepos = Input.mousePosition;
Vector3 newVec;
RectTransformUtility.ScreenPointToWorldPointInRectangle(rectTrans, mousepos, UIMgr.Instance.m_camera, out newVec);
rectTrans.position = newVec;
Vector2 anPos = rectTrans.anchoredPosition;
if (anPos.y - rectTrans.sizeDelta.y < 0)
{
anPos.y = rectTrans.sizeDelta.y;
}
//if (anPos.x + rectTrans.sizeDelta.x > Screen.width)
if (anPos.x + rectTrans.sizeDelta.x > Common.GetCurrScreenSize().x)
{
//pos.x = pos.x - (rectTrans.sizeDelta.x * 1.3f);
anPos.x = anPos.x - rectTrans.sizeDelta.x;
}
rectTrans.anchoredPosition = anPos;
}
public void SetData(string pStr)
{
tmpContent.text = pStr;
SetPos();
}
///
/// 获取属性字段详细描述
///
///
///
///
private static string GetAttStr(int pID, string pValue)
{
StringBuilder tStr = new StringBuilder();
//AttEnumData tData = HotfixEntry.Luban.GetAttEnumData(pID);
//if (tData != null)
//{
// switch (pID)
// {
// //攻击:
// case 115://物理攻击
// case 130://法术攻击
// case 118://火法攻击
// case 121://冰法攻击
// case 124://闪法攻击
// case 127://毒法攻击
// tStr.Append($"{tData.Describe}{pValue}");
// break;
// //POWER(属性数值,附加属性幂系数)*附加属性乘系数+附加属性加系数
// case 137://火焰攻击
// case 138://冰冻攻击
// case 139://闪电攻击
// case 140://毒素攻击
// if(!string.IsNullOrEmpty(pValue))
// {
// string[] tS1 = pValue.Split('-');
// if(tS1.Length > 0)
// {
// int num1 = int.Parse(tS1[0]);
// //int num2 = int.Parse(tS1[1]);
// int pMi = 0;
// int pCheng = 0;
// int pJia = 0;
// if (pID == 137)//火
// {
// pMi = ConstMgr.GetVal("huo_Power_coefficient");
// pCheng = ConstMgr.GetVal("huo_Multiplication_coefficient");
// pJia = ConstMgr.GetVal("huo_Additive_coefficient");
// }
// else if (pID == 139)//雷
// {
// pMi = ConstMgr.GetVal("lei_Power_coefficient");
// pCheng = ConstMgr.GetVal("lei_Multiplication_coefficient");
// pJia = ConstMgr.GetVal("lei_Additive_coefficient");
// }
// else if (pID == 138)//冰
// {
// pMi = ConstMgr.GetVal("bing_Power_coefficient");
// pCheng = ConstMgr.GetVal("bing_Multiplication_coefficient");
// pJia = ConstMgr.GetVal("bing_Additive_coefficient");
// }
// else if (pID == 140)//毒
// {
// pMi = ConstMgr.GetVal("du_Power_coefficient");
// pCheng = ConstMgr.GetVal("du_Multiplication_coefficient");
// pJia = ConstMgr.GetVal("du_Additive_coefficient");
// }
// float t1 = GetValue_Att(num1, pMi, pCheng, pJia) * 100;
// //float t2 = GetValue_Att(num2, pMi, pCheng, pJia);
// tStr.Append(string.Format($"{tData.Describe}", t1.ToString("0.00")));
// }
// else
// tStr.Append(tData.Describe);//数据异常
// }
// break;
// //防御:防御免伤百分比 =防御值/(防御值*倍系数2/10000 + power(防御等级系数,防御次方系数/10000)*倍系数/10000)
// case 131://物理防御
// case 133://火法防御
// case 134://冰法防御
// case 135://电法防御
// case 136://毒法防御
// if (!string.IsNullOrEmpty(pValue))
// {
// string[] tS1 = pValue.Split('-');
// if (tS1.Length == 2)
// {
// int num1 = int.Parse(tS1[0]);
// int num2 = int.Parse(tS1[1]);
// int pBei2 = 0;
// int pLv = 0;
// int pCiFang = 0;
// int pBei1 = 0;
// pBei2 = ConstMgr.GetVal("Defense_Multiple_two");
// pLv = HotfixEntry.MainPlayer.self.lv;
// pCiFang = ConstMgr.GetVal("Defense_Power_coefficient");
// pBei1 = ConstMgr.GetVal("Defense_Multiple_one");
// float pMax = ConstMgr.GetVal("Level_Total_Value") * 0.01f;
// float t1 = GetValue_Def(num1, pBei2, pLv, pCiFang, pBei1) * 100;
// float t2 = GetValue_Def(num2, pBei2, pLv, pCiFang, pBei1) * 100;
// if (t1 > pMax)
// t1 = pMax;
// if (t2 > pMax)
// t2 = pMax;
// //tStr.Append(string.Format($"{tData.Describe}", (t1 * 100).ToString("0.00")));
// tStr.Append(string.Format($"{tData.Describe}", $"{t1.ToString("0.00")}%-{t2.ToString("0.00")}%", $"{pMax}%"));
// }
// else
// tStr.Append(tData.Describe);//数据异常
// }
// break;
// //命中、闪避:玩家当前命中值/(power(玩家当前命中值,次方系数/10000)*倍系数+命中系数)
// case 141://命中
// case 142://闪避
// if (!string.IsNullOrEmpty(pValue))
// {
// string[] tS1 = pValue.Split('-');
// if (tS1.Length > 0)
// {
// int num1 = int.Parse(tS1[0]);
// int pCiFang = 0;
// int pBei = 0;
// int pXi = 0;
// pCiFang = ConstMgr.GetVal("Hit_Power");
// pBei = ConstMgr.GetVal("Dodge_Multiple");
// pXi = pID == 141 ? ConstMgr.GetVal("Hit_Coefficient") : ConstMgr.GetVal("Dodge_Coefficient");
// float t1 = GetValue_HitAndDot(num1, pCiFang, pBei, pXi) * 100;
// //tStr.Append(string.Format($"{tData.Describe}", (t1 * 100).ToString("0.00")));
// tStr.Append($"{tData.Describe}{t1.ToString("0.00")}%");
// }
// else
// tStr.Append(tData.Describe);//数据异常
// }
// break;
// //其他
// default:
// tStr.Append($"{tData.Describe}{pValue}");
// break;
// }
//}
return tStr.ToString();
}
private static float GetValue_Att(int pValue1, int pMi, int pCheng, int pJia)
{
if (pValue1 == 0) return 0;
return Mathf.Pow(pValue1, pMi * 0.0001f) * (pCheng * 0.0001f) + (pJia * 0.0001f);
}
private static float GetValue_Def(int pValue1, int pBei2, int pLv, int pCiFang, int pBei1)
{
return pValue1 / (pValue1 * pBei2 * 0.0001f + Mathf.Pow(pLv, pCiFang * 0.0001f) * pBei1 * 0.0001f);
}
private static float GetValue_HitAndDot(int pValue1, int pCiFang, int pBei, int pXi)
{
return pValue1 / (Mathf.Pow(pValue1, pCiFang * 0.0001f) * pBei + pXi);
}
}
}