472 lines
16 KiB
C#
472 lines
16 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using Games.Item;
|
|
using System.Collections.Generic;
|
|
using GCGame.Table;
|
|
using Games.GlobeDefine;
|
|
|
|
public class EquipEnhanceHecheng : UIControllerBase<EquipEnhanceHecheng>
|
|
{
|
|
private void Awake()
|
|
{
|
|
radius = (modelPoint.position - centerPoint.position).y;
|
|
}
|
|
|
|
void OnEnable ()
|
|
{
|
|
SetInstance(this);
|
|
HechengInit();
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
_HechengItemContainer.gameObject.SetActive(false);
|
|
SetInstance(null);
|
|
_DefaultSelectItem = -1;
|
|
}
|
|
|
|
public EquipEnhanceRoot _EquipEnhanceRoot;
|
|
|
|
public void UpdateItem()
|
|
{
|
|
//HechengPageInner(_TagPage.GetShowingPage(), _SelectItem);
|
|
if (_TabCombine != null)
|
|
{
|
|
OnHechengItemSelect(_TabCombine);
|
|
|
|
foreach (var subMenu in _HechengItemContainer.SubBtns)
|
|
{
|
|
//if (subMenu.Key.IsSelected())
|
|
// continue;
|
|
|
|
int canCombineTotal = 0;
|
|
if (_OnlyShowEnough)
|
|
{
|
|
foreach (var combineItem in subMenu.Value)
|
|
{
|
|
var combineNum = ((EquipHechengItem)combineItem).GetItemCanCombineCnt();
|
|
canCombineTotal += combineNum;
|
|
if (combineNum > 0)
|
|
{
|
|
combineItem.ShowMenu();
|
|
|
|
}
|
|
else
|
|
{
|
|
combineItem.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
if (canCombineTotal > 0)
|
|
{
|
|
subMenu.Key.gameObject.SetActive(true);
|
|
((EquipHechengItem)subMenu.Key).SetCombineTip(canCombineTotal);
|
|
}
|
|
else
|
|
{
|
|
subMenu.Key.gameObject.SetActive(false);
|
|
((EquipHechengItem)subMenu.Key).SetCombineTip(0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var combineItem in subMenu.Value)
|
|
{
|
|
var combineNum = ((EquipHechengItem)combineItem).GetItemCanCombineCnt();
|
|
canCombineTotal += combineNum;
|
|
}
|
|
((EquipHechengItem)subMenu.Key).SetCombineTip(canCombineTotal);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
var targetCnt = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(_TargetDataID);
|
|
if (targetCnt > _TargetDataCnt)
|
|
{
|
|
string name = TableManager.GetCommonItemByID(_TargetDataID, 0).Name;
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{5332}", name, (targetCnt - _TargetDataCnt)));
|
|
}
|
|
}
|
|
|
|
public static void SetDefaultSelected(int dataID)
|
|
{
|
|
_DefaultSelectItem = dataID;
|
|
}
|
|
|
|
#region
|
|
|
|
private Dictionary<string, List<Tab_ItemCombine>> _ItemCombineDict;
|
|
private static int _DefaultSelectItem = -1;
|
|
|
|
public void InitCombineTable()
|
|
{
|
|
if (_ItemCombineDict != null)
|
|
return;
|
|
|
|
_ItemCombineDict = new Dictionary<string, List<Tab_ItemCombine>>();
|
|
var tabCombineItem = TableManager.GetItemCombine().Values;
|
|
foreach (var tabCombineTab in tabCombineItem)
|
|
{
|
|
if (tabCombineTab.Profession >= 0 && tabCombineTab.Profession != GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession)
|
|
continue;
|
|
|
|
if (!_ItemCombineDict.ContainsKey(tabCombineTab.Class))
|
|
{
|
|
_ItemCombineDict.Add(tabCombineTab.Class, new List<Tab_ItemCombine>());
|
|
}
|
|
_ItemCombineDict[tabCombineTab.Class].Add(tabCombineTab);
|
|
}
|
|
|
|
foreach (var hechengClass in _ItemCombineDict)
|
|
{
|
|
//hechengClass.Value.Reverse();
|
|
_HechengItemContainer.PushMenu(hechengClass.Key, hechengClass.Value.ToArray());
|
|
}
|
|
}
|
|
|
|
public void HechengInit()
|
|
{
|
|
_EquipEnhanceRoot._EquipContainer.gameObject.SetActive(false);
|
|
_EquipEnhanceRoot._EquipContainer._IsMultiSelect = false;
|
|
_HechengItemContainer.gameObject.SetActive(true);
|
|
_BtnHecheng.gameObject.SetActive(false);
|
|
_DisableBtn.SetActive(true);
|
|
//_TagPage.ShowPage(0);
|
|
|
|
_OnlyShoEnoughToggle.isOn = false;
|
|
_OnlyShowEnough = false;
|
|
|
|
OnHechengPage(0);
|
|
}
|
|
|
|
public void OnHechengPage(int page)
|
|
{
|
|
HechengPageInner(page, _DefaultSelectItem);
|
|
|
|
}
|
|
|
|
private void HechengPageInner(int page, int itemdate = -1)
|
|
{
|
|
if (itemdate > 0)
|
|
{
|
|
SetOnlyShowEnought(false);
|
|
}
|
|
InitCombineTable();
|
|
object showMenu1 = null;
|
|
object showMenu2 = null;
|
|
int canCombineTotal = 0;
|
|
|
|
foreach (var subMenu in _HechengItemContainer.SubBtns)
|
|
{
|
|
canCombineTotal = 0;
|
|
if (_OnlyShowEnough)
|
|
{
|
|
subMenu.Key.gameObject.SetActive(false);
|
|
subMenu.Key.UnSelected();
|
|
|
|
foreach (var combineItem in subMenu.Value)
|
|
{
|
|
var combineNum = ((EquipHechengItem)combineItem).GetItemCanCombineCnt();
|
|
canCombineTotal += combineNum;
|
|
if(combineNum > 0)
|
|
{
|
|
//combineItem.ShowMenu();
|
|
combineItem.gameObject.SetActive(false);
|
|
combineItem.UnSelected();
|
|
}
|
|
else
|
|
{
|
|
combineItem.gameObject.SetActive(false);
|
|
combineItem.UnSelected();
|
|
}
|
|
}
|
|
|
|
if (canCombineTotal > 0)
|
|
{
|
|
subMenu.Key.gameObject.SetActive(true);
|
|
((EquipHechengItem)subMenu.Key).SetCombineTip(canCombineTotal);
|
|
}
|
|
else
|
|
{
|
|
subMenu.Key.gameObject.SetActive(false);
|
|
((EquipHechengItem)subMenu.Key).SetCombineTip(0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
subMenu.Key.gameObject.SetActive(true);
|
|
((EquipHechengItem)subMenu.Key).SetCombineTip(0);
|
|
subMenu.Key.UnSelected();
|
|
foreach (var combineItem in subMenu.Value)
|
|
{
|
|
if (((EquipHechengItem)combineItem).GetItemDataID() == itemdate)
|
|
{
|
|
showMenu1 = subMenu.Key.MenuObj;
|
|
showMenu2 = combineItem.MenuObj;
|
|
}
|
|
|
|
var combineNum = ((EquipHechengItem)combineItem).GetItemCanCombineCnt();
|
|
canCombineTotal += combineNum;
|
|
|
|
combineItem.gameObject.SetActive(false);
|
|
combineItem.UnSelected();
|
|
|
|
}
|
|
|
|
((EquipHechengItem)subMenu.Key).SetCombineTip(canCombineTotal);
|
|
}
|
|
}
|
|
|
|
OnHechengItemSelect(null);
|
|
_HechengItemContainer.ClearSelect(1);
|
|
_HechengItemContainer.ClearSelect(2);
|
|
_HechengItemContainer.ShowMenu(showMenu1, showMenu2);
|
|
//_HechengItemContainer.ShowDefaultFirst();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region
|
|
|
|
public UISubScollMenu _HechengItemContainer;
|
|
public CommonItemMaterialSlot[] _HechengMaterial;
|
|
public CommonItemPlotBase _HechengResult;
|
|
public UINumBoardInput _NumInput;
|
|
public Toggle _OnlyShoEnoughToggle;
|
|
//public Text _BindCnt;
|
|
//public Text _NoBindCnt;
|
|
//public Toggle _UseBindFirst;
|
|
public Button _BtnHecheng; // 合成按钮
|
|
public GameObject _DisableBtn; // 失活的合成按钮
|
|
public Transform centerPoint; // 中心点
|
|
public Transform modelPoint; // 用于获得新位置的代替物
|
|
public float intervalAngle; // 间隔角度
|
|
|
|
private float radius; // 半径
|
|
private GameItem _SelectItem;
|
|
private int _TargetDataID;
|
|
private int _TargetDataCnt;
|
|
private Tab_ItemCombine _TabCombine;
|
|
private bool _OnlyShowEnough;
|
|
public bool OnlyShowEnough
|
|
{
|
|
get
|
|
{
|
|
return _OnlyShowEnough;
|
|
}
|
|
}
|
|
|
|
public void OnHechengItemSelect(object itemObj)
|
|
{
|
|
bool hasChangeCombineItem = true;
|
|
if (_TabCombine == itemObj)
|
|
{
|
|
hasChangeCombineItem = false;
|
|
}
|
|
_TabCombine = itemObj as Tab_ItemCombine;
|
|
if (_TabCombine == null)
|
|
{
|
|
for (int i = 0; i < _HechengMaterial.Length; ++i)
|
|
{
|
|
_HechengMaterial[i].gameObject.SetActive(false);
|
|
}
|
|
_HechengResult.ShowItem(null);
|
|
//_BindCnt.gameObject.SetActive(false);
|
|
//_NoBindCnt.gameObject.SetActive(false);
|
|
_NumInput.gameObject.SetActive(false);
|
|
_BtnHecheng.gameObject.SetActive(false);
|
|
_DisableBtn.SetActive(true);
|
|
return;
|
|
}
|
|
|
|
_BtnHecheng.gameObject.SetActive(true);
|
|
_DisableBtn.SetActive(false);
|
|
_TargetDataID = _TabCombine.ItemID;
|
|
_TargetDataCnt = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(_TargetDataID);
|
|
|
|
int combineCnt = 999;
|
|
int num = 0;
|
|
for (int i = 0; i < _HechengMaterial.Length; ++i)
|
|
{
|
|
if (_TabCombine.GetSrcItemIDbyIndex(i) > 0)
|
|
{
|
|
++num;
|
|
var materialCnt = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(_TabCombine.GetSrcItemIDbyIndex(i));
|
|
int canCombineCnt = materialCnt / _TabCombine.GetNeedNumbyIndex(i);
|
|
combineCnt = Mathf.Min(combineCnt, canCombineCnt);
|
|
_HechengMaterial[i].gameObject.SetActive(true);
|
|
_HechengMaterial[i].InitMaterial(_TabCombine.GetSrcItemIDbyIndex(i), _TabCombine.GetNeedNumbyIndex(i));
|
|
}
|
|
else
|
|
{
|
|
_HechengMaterial[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
UpdateMaterialsPos(num);
|
|
|
|
GameItem targetItem = new GameItem();
|
|
targetItem.DataID = _TabCombine.ItemID;
|
|
targetItem.StackCount = 1;
|
|
_HechengResult.ShowItem(targetItem);
|
|
|
|
//int itemCnt = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(_SelectItem.DataID);
|
|
//int itemBindCnt = GameManager.gameManager.PlayerDataPool.BackPack.GetBindItemCountByDataId(_SelectItem.DataID);
|
|
//if (itemBindCnt > 0)
|
|
//{
|
|
// _BindCnt.gameObject.SetActive(true);
|
|
// _BindCnt.text = itemBindCnt.ToString();
|
|
// _NoBindCnt.gameObject.SetActive(true);
|
|
// _NoBindCnt.text = (itemCnt - itemBindCnt).ToString();
|
|
|
|
// //if (itemBindCnt != itemCnt)
|
|
// //{
|
|
// // _UseBindFirst.gameObject.SetActive(true);
|
|
// // _UseBindFirst.isOn = true;
|
|
// //}
|
|
// //else
|
|
// //{
|
|
// // _UseBindFirst.gameObject.SetActive(false);
|
|
// //}
|
|
//}
|
|
//else
|
|
//{
|
|
// _BindCnt.gameObject.SetActive(false);
|
|
// _NoBindCnt.gameObject.SetActive(false);
|
|
// _UseBindFirst.gameObject.SetActive(false);
|
|
//}
|
|
|
|
_NumInput.gameObject.SetActive(true);
|
|
if (hasChangeCombineItem)
|
|
{
|
|
_NumInput.Init(1, 1, Mathf.Max(combineCnt, 1));
|
|
}
|
|
else
|
|
{
|
|
if (_NumInput.Value > combineCnt)
|
|
{
|
|
_NumInput.Init(1, 1, Mathf.Max(combineCnt, 1));
|
|
}
|
|
}
|
|
|
|
if (combineCnt < 1)
|
|
{
|
|
_BtnHecheng.gameObject.SetActive(false);
|
|
_DisableBtn.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
_BtnHecheng.gameObject.SetActive(true);
|
|
_DisableBtn.SetActive(false);
|
|
}
|
|
}
|
|
|
|
// 更具合成材料数目调整素材显示位置
|
|
private void UpdateMaterialsPos(int num)
|
|
{
|
|
if(num <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 初始化位置
|
|
modelPoint.position = centerPoint.position + Vector3.up * radius;
|
|
// 起始位置
|
|
float startAngle = -(intervalAngle * (num - 1)) / 2.0f - intervalAngle;
|
|
modelPoint.RotateAround(centerPoint.position, Vector3.forward, startAngle);
|
|
for (int i = 0; i < num; ++i)
|
|
{
|
|
modelPoint.RotateAround(centerPoint.position, Vector3.forward, intervalAngle);
|
|
_HechengMaterial[i].transform.position = modelPoint.position;
|
|
}
|
|
}
|
|
|
|
public void OnHeChengClick()
|
|
{
|
|
Tab_CommonItem tabItem = TableManager.GetCommonItemByID(_TabCombine.ItemID, 0);
|
|
|
|
if (tabItem.ClassID == (int)ItemClass.STRENGTHEN && tabItem.SubClassID == (int)StrengthenSubClass.KAIKONG)
|
|
{
|
|
Tab_CommonItem targetItem = TableManager.GetCommonItemByID(_TabCombine.ItemID, 0);
|
|
Tab_CommonItem srcItem = TableManager.GetCommonItemByID(_TabCombine.GetSrcItemIDbyIndex(0), 0);
|
|
string tips = StrDictionary.GetClientDictionaryString("#{5371}", _NumInput.Value * _TabCombine.GetNeedNumbyIndex(0), srcItem.Name, _NumInput.Value, targetItem.Name);
|
|
MessageBoxLogic.OpenOKCancelBox(tips, "", OnHeChengClickOk, null, GlobeVar.INVALID_ID, MessageBoxLogic.PASSWORD.INVALID, 3);
|
|
}
|
|
else
|
|
{
|
|
OnHeChengClickOk();
|
|
}
|
|
}
|
|
|
|
public void OnHeChengClickOk()
|
|
{
|
|
if (_NumInput.Value == 0)
|
|
return;
|
|
|
|
CG_QIANKUNDAI_COMBINE packet = (CG_QIANKUNDAI_COMBINE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_QIANKUNDAI_COMBINE);
|
|
packet.Dataid = _TabCombine.ItemID;
|
|
packet.Desproductcount = _NumInput.Value;
|
|
|
|
packet.SendPacket();
|
|
}
|
|
|
|
public void OnOnlyShowEnough(bool isOnlyShow)
|
|
{
|
|
if (isOnlyShow)
|
|
_DefaultSelectItem = -1;
|
|
_OnlyShowEnough = isOnlyShow;
|
|
OnHechengPage(0);
|
|
}
|
|
|
|
public void SetOnlyShowEnought(bool isOnlyShow)
|
|
{
|
|
_OnlyShowEnough = isOnlyShow;
|
|
_OnlyShoEnoughToggle.isOn = isOnlyShow;
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 当合成界面不显示时的合成界面红点结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static void RetTipsUpdate()
|
|
{
|
|
// 强化界面显示时,不进行判断,因为界面内已有其他判断。
|
|
if(EquipEnhanceHecheng.Instance() != null && EquipEnhanceHecheng.Instance().gameObject.activeInHierarchy == true)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 存储所有可合成的物体
|
|
List<Tab_ItemCombine> itemsCanComebine = new List<Tab_ItemCombine>();
|
|
var tabCombineItem = TableManager.GetItemCombine().Values;
|
|
foreach (var tabCombineTab in tabCombineItem)
|
|
{
|
|
itemsCanComebine.Add(tabCombineTab);
|
|
}
|
|
|
|
// 检测素有合成物体的素材是否足够
|
|
for(int i = 0; i < itemsCanComebine.Count; ++i)
|
|
{
|
|
for (int j = 0; j < itemsCanComebine[i].getNeedNumCount(); ++j)
|
|
{
|
|
if (itemsCanComebine[i].GetSrcItemIDbyIndex(i) > 0)
|
|
{
|
|
var materialCnt = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(itemsCanComebine[i].GetSrcItemIDbyIndex(i));
|
|
if (materialCnt > itemsCanComebine[i].GetNeedNumbyIndex(i))
|
|
{
|
|
// 发现一个满足即可
|
|
|
|
//return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//return false;
|
|
}
|
|
}
|