// _SelectItemPos 其实就是
// 获取鼠标点击点
// Vector3 position = UICamera.lastWorldPosition;
// 获取鼠标点击点
// Vector3 position = UICamera.lastWorldPosition;
// _SelectItemPos = position;
using UnityEngine;
using System.Collections;
using System.Text;
using System.IO;
using System.Collections.Generic;
using PBClientClass;
using CommonEnum;
// _SelectItemPos 其实就是
// //获取鼠标点击点
// Vector3 position = UICamera.lastWorldPosition;
// _SelectItemPos = position;
public class UIGameTips : UIPanelBase {
private UIGameTipsView _View = null;
private ItemType _ItemType ;
private Vector3 _SelectItemPos ;
private ItemIconInfo _ItemIconInfo;
private int mItemBgHeight = 0;// item背景框高度
void Awake()
{
_View = gameObject.AddComponent<UIGameTipsView>();
}
private void OnClear()
{
_SelectItemPos = Vector3.zero;
_ItemIconInfo = null;
mItemBgHeight = 0;
}
void Update()
{
if(gameObject == null || gameObject.activeSelf == false)
{
return;
}
if(Input.touchCount > 1)
{
CloseSelf();
}
}
public override void OnShow(params object[] paramsList)
{
OnClear();
if (paramsList == null || paramsList.Length == 0)
{
GameUIManager.GetInstance().ClosePanel(UIName.UIGameTips);
return;
}
if (paramsList.Length >= 1)
{
_SelectItemPos = (Vector3)paramsList[0];
}
if (paramsList.Length >= 2)
{
_ItemIconInfo = paramsList[1] as ItemIconInfo;
}
if (_ItemIconInfo == null)
return;
_ItemType = _ItemIconInfo._ItemType;;
if (_ItemType == ItemType.Unknown)
{
CloseSelf();
return;
}
OnSetData();
SetPos();
UITools.setActive(ObjectCommon.GetChild(gameObject, "maskpanel"), false);
}
private void SetDownPos()
{
if (_ItemIconInfo == null)
return;
gameObject.transform.position = _SelectItemPos;
int size = _ItemIconInfo._Size;
Vector3 local_pos = gameObject.transform.localPosition;
local_pos.y -= (size/2) ;
gameObject.transform.localPosition = local_pos;
Vector3 go_pos = gameObject.transform.position;
Camera camera = GameUIManager.GetInstance().GetRootCamera();
Vector3 camera_pos = camera.WorldToScreenPoint(go_pos);
float left = camera_pos.y - mItemBgHeight;
if (left < 0)// 下面越界了 (左右越界 和 上面 越界暂时不考虑 因为现在ui宽够了)
{
local_pos.y = local_pos.y - left;
}
gameObject.transform.localPosition = local_pos;
}
private void SetPos()
{
if (_ItemIconInfo == null)
return;
gameObject.transform.position = _SelectItemPos;
int size = _ItemIconInfo._Size;
Vector3 local_pos = gameObject.transform.localPosition;
local_pos.y += (size/2) ;
local_pos.y += mItemBgHeight ;
gameObject.transform.localPosition = local_pos;
int screenTop = Screen.height/2;
if (local_pos.y > screenTop)// 上面越界了
{
gameObject.transform.localPosition = new Vector3 (local_pos.x,screenTop,local_pos.z);
}
}
public bool IsCanWear(int l)
{
int equiplevel = l;// 装备等级
if (equiplevel <= HeroManager.Instance.PlayerLevel)
return true;
return false;
}
public void OnSetData()
{
if (_ItemIconInfo == null)
return;
int dance = 5;
UITools.SetLabText(_View.info_title_UILabel,GetTitleByType(_ItemType));
UITools.SetLabText(_View.info_name_UILabel,string.Format("[9DE7F2]{0}:{1}[-]",StringManager.GetInstance().GetValue("txt_mingzi"),_ItemIconInfo._Name));
string adddesc = "";
if (_ItemType == ItemType.Equip)
{
EquipmentData _EquipmentData = EquipmentDataProvider.GetInstance().GetDataByID (_ItemIconInfo._ItemID);
if (_EquipmentData != null)
{
string str = "";
str = str+string.Format("[9DE7F2]{0}:{1}[-]",StringManager.GetInstance().GetValue("txt_buwei"),_EquipmentData.GetPosTypeString());// 部位:头盔
str = str+string.Format("[9DE7F2]\n{0}{1}[-]",StringManager.GetInstance().GetValue("txt_peerage_battlescore"),EquipManager.GetInstance().GetFight(_ItemIconInfo._ItemGuid,_ItemIconInfo._ItemID));// 战斗力
string attstr = EquipmentDataProvider.GetInstance().GetAtt(_ItemIconInfo._ItemID);
if (string.IsNullOrEmpty(attstr) == false)
{
str =str+string.Format("[9DE7F2]\n{0}:\n{1}[-]",StringManager.GetInstance().GetValue("txt_shuxing"),attstr);// 属性
}
str = str+string.Format("[9DE7F2]\n{0}:{1}[-]",StringManager.GetInstance().GetValue("txt_miaoshu"),_ItemIconInfo._Desc);// 描述
UITools.SetLabText(_View.info_desc_UILabel,str);
bool iscanwear = IsCanWear(_EquipmentData.level);
if (iscanwear == false)
UITools.SetLabText(_View.info_adddesc_UILabel,string.Format(StringManager.GetInstance().GetValue("txt_jizhuangbei"),_EquipmentData.level));
}
else
{
UITools.ClearLabel(_View.info_desc_UILabel);
UITools.ClearLabel(_View.info_adddesc_UILabel);
}
}
else
{
UITools.SetLabText(_View.info_desc_UILabel,string.Format("[9DE7F2]{0}:{1}[-]",StringManager.GetInstance().GetValue("txt_miaoshu"),_ItemIconInfo._Desc));
UITools.ClearLabel(_View.info_adddesc_UILabel);
}
int aheight = 0;
float x = _View.info_title_UILabel.transform.localPosition.x;
float y = _View.info_title_UILabel.transform.localPosition.y;
aheight += UITools.GetHeightByLab(_View.info_title_UILabel);
// 名字
UITools.SetTransformPosition(_View.info_name_UILabel,new Vector3 (x,(y-aheight-dance),0));
aheight += UITools.GetHeightByLab(_View.info_name_UILabel);
// 描述
UITools.SetTransformPosition(_View.info_desc_UILabel,new Vector3 (x,(y-aheight-dance),0));
// 描述
aheight += UITools.GetHeightByLab(_View.info_desc_UILabel);
UITools.SetTransformPosition(_View.info_desc_UILabel,new Vector3 (x,-63,0));
if (_View.info_bg_UITexture!=null)
{
_View.info_bg_UITexture.height = aheight+35;
}
mItemBgHeight = aheight+35;
}
// 获取tips 的标题 (装备/道具/等)
public string GetTitleByType(ItemType tt)
{
if (tt == ItemType.Equip)
{
return StringManager.GetInstance().GetValue("txt_zhuangbei");
}
else if (tt == ItemType.Goods)
{
return StringManager.GetInstance().GetValue("txt_huowu");
}
else if (tt == ItemType.Item)
{
return StringManager.GetInstance().GetValue("txt_wupin");
}
else if (tt == ItemType.Material)
{
return StringManager.GetInstance().GetValue("txt_cailiao");
}
else if (tt == ItemType.Daoju)
{
return StringManager.GetInstance().GetValue("txt_daoju");
}
else if (tt == ItemType.JiaSuDaoju)
{
return StringManager.GetInstance().GetValue("txt_jiasudaoju");
}
else if (tt == ItemType.Reward)
{
return StringManager.GetInstance().GetValue("txt_jiangli");
}
else if (tt == ItemType.Money)
{
return StringManager.GetInstance().GetValue("txt_huobi");
}
return StringManager.GetInstance().GetValue("txt_null");
}
}