using UnityEngine;
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
using System;
|
using Snxxz.UI;
|
using System.Collections;
|
using System.Linq;
|
|
namespace Snxxz.UI
|
{
|
public class LingDanTips : MonoBehaviour
|
{
|
[SerializeField]
|
private ScrollerController _danDrugCtrl;
|
|
[SerializeField]
|
private ScrollerController _randomLineCtrl;
|
|
[SerializeField]
|
private List<GameObject> _materiallist = new List<GameObject>();
|
|
[SerializeField]
|
private Button _addSpecMatBtn;
|
|
[SerializeField]
|
private ItemCell _addSpecMatItemCell;
|
|
[SerializeField]
|
private Text _addSpecMatText;
|
|
[SerializeField]
|
private GameObject _addSpecLockObj;
|
|
[SerializeField]
|
private GameObject _noEnoughLVText;
|
|
[SerializeField]
|
private Slider _blastFurnaceExpSlider;
|
|
[SerializeField]
|
private RectTransform _virtualFill;
|
[SerializeField] Text previewNextExpText;
|
[SerializeField]
|
private Text _expValueText;
|
|
[SerializeField]
|
private Text _furnaceLvText;
|
|
[SerializeField]
|
private Button _makeDanBtn;
|
[SerializeField] Button prayDurgBtn;
|
|
[SerializeField] FurnaceFireChooseWin ChooseWin;
|
[SerializeField] UIEffect bgEffect;
|
[SerializeField] UIEffect makeDrugEffect;
|
|
private ToggleGroup _toggleGroup;
|
private int presentIndex = 0;
|
private AlchemyConfig curAlchemyModel;
|
private AlchemySpecConfig chooseSpecModel = null;
|
private List<int> previewDanlist;
|
BlastFurnaceModel _furnaceModel;
|
BlastFurnaceModel FurnaceModel
|
{
|
get
|
{
|
return _furnaceModel ?? (_furnaceModel = ModelCenter.Instance.GetModel<BlastFurnaceModel>());
|
}
|
}
|
|
GetItemPathModel _itemPathModel;
|
GetItemPathModel itemPathModel
|
{
|
get
|
{
|
return _itemPathModel ?? (_itemPathModel = ModelCenter.Instance.GetModel<GetItemPathModel>());
|
}
|
}
|
|
ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
|
PackModel _playerPack;
|
PackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
|
}
|
PrayForDurgModel prayModel { get { return ModelCenter.Instance.GetModel<PrayForDurgModel>(); } }
|
|
private int noEnoughMatID = 0;
|
private bool isEnoughSpecMat = true;
|
AchievementGuideEffect guideEffect = null;
|
public int isJumpToId = 0;
|
private Dictionary<int, int> previewDict = null;
|
|
private void Awake()
|
{
|
_danDrugCtrl.OnRefreshCell += RefreshDandrugCell;
|
_danDrugCtrl.lockType = EnhanceLockType.KeepVertical;
|
_toggleGroup = _danDrugCtrl.GetComponent<ToggleGroup>();
|
_makeDanBtn.onClick.AddListener(OnClickMakeDan);
|
prayDurgBtn.AddListener(ClickPrayDrugBtn);
|
FurnaceModel.RefreshStoveModelEvent += RefreshStoveModel;
|
FurnaceModel.RefreshAddSpecMatEvent += SetSpecMatItemCell;
|
_randomLineCtrl.OnRefreshCell += RefreshRandomLineCell;
|
// makeDrugEffect.OnComplete += OnMakeDrugEffectComplete;
|
|
}
|
|
private void ClickPrayDrugBtn()
|
{
|
if(prayModel.CheckPrayDrugIsOpen())
|
{
|
WindowCenter.Instance.Open<PrayforDrugWin>();
|
}
|
}
|
|
private void OnEnable()
|
{
|
isJumpToId = 0;
|
guideEffect = null;
|
ChangeMakeDanBtn(true);
|
chooseSpecModel = null;
|
ChooseWin.gameObject.SetActive(false);
|
presentIndex = 0;
|
CreateCell();
|
StartCoroutine(CheckJumpToModel());
|
}
|
|
private void OnDisable()
|
{
|
|
}
|
|
IEnumerator CheckJumpToModel()
|
{
|
yield return null;
|
SuccessConfig successConfig = SuccessConfig.Get(AchievementGoto.guideAchievementId);
|
if (successConfig != null &&(successConfig.Type == 51 || successConfig.Type == 115))
|
{
|
bool isMakeDan = false;
|
for (int i = 0; i < FurnaceModel.alchemyModellist.Count; i++)
|
{
|
if (FurnaceModel.danDrugRedPointlist[i].state == RedPointState.Simple)
|
{
|
isJumpToId = FurnaceModel.alchemyModellist[i].AlchemyID;
|
isMakeDan = true;
|
presentIndex = i;
|
int jumpIndex = presentIndex - 1 < 0 ? 0 : presentIndex - 1;
|
_danDrugCtrl.JumpIndex(jumpIndex);
|
_danDrugCtrl.m_Scorller.RefreshActiveCellViews();
|
break;
|
}
|
}
|
|
if (isMakeDan)
|
{
|
guideEffect = AchievementGuideEffectPool.Require(1);
|
guideEffect.transform.SetParentEx(_makeDanBtn.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
else
|
{
|
ServerTipDetails.DisplayNormalTip("Material101");
|
}
|
AchievementGoto.guideAchievementId = 0;
|
}
|
else
|
{
|
if (FurnaceModel.jumpToPrescripe != 0)
|
{
|
for (int i = 0; i < FurnaceModel.alchemyModellist.Count; i++)
|
{
|
if (FurnaceModel.jumpToPrescripe == FurnaceModel.alchemyModellist[i].AlchemyID)
|
{
|
presentIndex = i;
|
break;
|
}
|
}
|
FurnaceModel.jumpToPrescripe = 0;
|
}
|
else
|
{
|
for (int i = 0; i < FurnaceModel.alchemyModellist.Count; i++)
|
{
|
if (FurnaceModel.danDrugRedPointlist[i].state == RedPointState.Simple)
|
{
|
isJumpToId = FurnaceModel.alchemyModellist[i].AlchemyID;
|
presentIndex = i;
|
break;
|
}
|
}
|
}
|
|
int jumpIndex = presentIndex - 1 < 0 ? 0 : presentIndex - 1;
|
_danDrugCtrl.JumpIndex(jumpIndex);
|
_danDrugCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
|
RefreshStoveModel();
|
}
|
|
private void RefreshStoveModel()
|
{
|
_furnaceLvText.text = Language.Get("BlastFurnace101", FurnaceModel.StoveLV);
|
_blastFurnaceExpSlider.minValue = 0;
|
if (FurnaceModel.GetBlastFurnaceUpgradExp() <= 0)
|
{
|
_blastFurnaceExpSlider.maxValue = 1;
|
_blastFurnaceExpSlider.value = 1;
|
}
|
else
|
{
|
_blastFurnaceExpSlider.maxValue = FurnaceModel.GetBlastFurnaceUpgradExp();
|
_blastFurnaceExpSlider.value = FurnaceModel.StoveExp;
|
}
|
|
if(!FurnaceModel.IsReachMaxStoveLv())
|
{
|
_expValueText.text = FurnaceModel.StoveExp + "/" + FurnaceModel.GetBlastFurnaceUpgradExp();
|
}
|
else
|
{
|
_expValueText.text = Language.Get("L1055");
|
}
|
RefreshVirtualFill(_addExp);
|
if (FurnaceModel.StoveIsUpGrade)
|
{
|
ActivateShow.StoveUpgrade(FurnaceModel.StoveLV);
|
CreateCell();
|
OnClickDandrugCell(presentIndex);
|
}
|
else
|
{
|
OnClickDandrugCell(presentIndex);
|
if (chooseSpecModel != null)
|
{
|
int haveCnt = playerPack.GetItemCountByID(PackType.Item, chooseSpecModel.SpecialMaterialD);
|
if (haveCnt <= 0)
|
{
|
SetSpecMatItemCell(null);
|
CreateRandomLineCell();
|
}
|
}
|
}
|
}
|
|
private void RefreshVirtualFill(float value)
|
{
|
if(!FurnaceModel.IsReachMaxStoveLv())
|
{
|
previewNextExpText.gameObject.SetActive(true);
|
previewNextExpText.text = StringUtility.Contact("+", value);
|
}
|
else
|
{
|
previewNextExpText.gameObject.SetActive(false);
|
}
|
|
//_virtualFill.localScale = new Vector3((value + FurnaceModel.StoveExp) /FurnaceModel.GetBlastFurnaceUpgradExp(),1,1);
|
}
|
|
private void CreateCell()
|
{
|
_danDrugCtrl.Refresh();
|
if(FurnaceModel.alchemyModellist != null)
|
{
|
int i = 0;
|
int length = FurnaceModel.alchemyModellist.Count;
|
for(i = 0; i < length; i++)
|
{
|
_danDrugCtrl.AddCell(ScrollerDataType.Header,i);
|
}
|
}
|
_danDrugCtrl.Restart();
|
}
|
|
private void RefreshDandrugCell(ScrollerDataType type, CellView cell)
|
{
|
DandrugCell dandrugCell = cell.GetComponent<DandrugCell>();
|
if(dandrugCell != null)
|
{
|
dandrugCell.SetDisplayModel(cell.index,presentIndex);
|
dandrugCell.cellToggle.RemoveAllListeners();
|
dandrugCell.cellToggle.AddListener(()=>
|
{
|
OnClickDandrugCell(cell.index);
|
});
|
}
|
}
|
|
private void OnClickDandrugCell(int index)
|
{
|
AlchemyConfig alchemyModel = FurnaceModel.alchemyModellist[index];
|
noEnoughMatID = 0;
|
curAlchemyModel = alchemyModel;
|
if(curAlchemyModel.AlchemyID != isJumpToId)
|
{
|
isJumpToId = 0;
|
if(guideEffect != null)
|
{
|
AchievementGuideEffectPool.Recycle(guideEffect);
|
guideEffect = null;
|
}
|
}
|
int i = 0;
|
int length = _materiallist.Count;
|
for( i = 0;i < length;i++)
|
{
|
ItemCell itemCell = _materiallist[i].transform.Find("ItemCell").GetComponent<ItemCell>();
|
GameObject lockImage = _materiallist[i].transform.Find("LockImage").gameObject;
|
FurnaceModel.SetAlchemyMaterial(alchemyModel.AlchemyID);
|
FurnaceModel.GetAlchemyMaterial(i);
|
int materialId = FurnaceModel.materialId;
|
int materialNum = FurnaceModel.materialNum;
|
if (materialId == 0)
|
{
|
itemCell.gameObject.SetActive(false);
|
lockImage.SetActive(true);
|
}
|
else
|
{
|
itemCell.gameObject.SetActive(true);
|
lockImage.SetActive(false);
|
ItemCellModel cellModel = new ItemCellModel(materialId);
|
itemCell.Init(cellModel);
|
itemCell.countText.gameObject.SetActive(true);
|
SinglePack singlePack = playerPack.GetSinglePack(PackType.Item);
|
if (singlePack == null) return;
|
|
int haveMaterCount = singlePack.GetCountById(materialId);
|
|
if(haveMaterCount >= materialNum)
|
{
|
itemCell.countText.text = UIHelper.AppendStringColor(TextColType.White,haveMaterCount.ToString()) +"/" + materialNum;
|
}
|
else
|
{
|
if(noEnoughMatID == 0)
|
{
|
noEnoughMatID = materialId;
|
}
|
itemCell.countText.text = UIHelper.AppendStringColor(TextColType.Red, haveMaterCount.ToString()) + "/" + materialNum;
|
}
|
|
itemCell.cellBtn.RemoveAllListeners();
|
itemCell.cellBtn.AddListener(() =>
|
{
|
itemPathModel.SetChinItemModel(materialId);
|
});
|
}
|
|
}
|
_noEnoughLVText.SetActive(false);
|
|
if (FurnaceModel.StoveLV < alchemyModel.BlastFurnaceLV)
|
{
|
_makeDanBtn.gameObject.SetActive(false);
|
//_noEnoughLVText.SetActive(true);
|
}
|
else
|
{
|
_makeDanBtn.gameObject.SetActive(true);
|
|
}
|
if(presentIndex != index)
|
{
|
chooseSpecModel = null;
|
}
|
SetSpecMatItemCell(chooseSpecModel);
|
CreateRandomLineCell();
|
presentIndex = index;
|
_danDrugCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
private float _addExp = 0;
|
private void SetSpecMatItemCell(AlchemySpecConfig specModel)
|
{
|
chooseSpecModel = specModel;
|
_addSpecMatBtn.onClick.RemoveAllListeners();
|
_addExp = 0;
|
if (chooseSpecModel == null)
|
{
|
_addExp = curAlchemyModel.AlchemyEXP;
|
_addSpecMatItemCell.gameObject.SetActive(false);
|
FurnaceModel.SetAlchemySpecModellist(curAlchemyModel.SpecialItem);
|
if (FurnaceModel.GetAlchemySpecModellist().Count > 0)
|
{
|
_addSpecMatText.gameObject.SetActive(true);
|
_addSpecLockObj.SetActive(false);
|
_addSpecMatBtn.onClick.AddListener(() => { ChooseWin.gameObject.SetActive(true); });
|
}
|
else
|
{
|
|
_addSpecMatText.gameObject.SetActive(false);
|
_addSpecLockObj.SetActive(true);
|
}
|
|
FurnaceModel.SpecMatRedPointCtrl(curAlchemyModel);
|
}
|
else
|
{
|
|
FurnaceModel.SpecMatRedPointCtrl(curAlchemyModel,false);
|
_addExp = specModel.AlchemyEXP + curAlchemyModel.AlchemyEXP;
|
RefreshVirtualFill(curAlchemyModel.AlchemyEXP);
|
_addSpecMatText.gameObject.SetActive(false);
|
_addSpecLockObj.SetActive(false);
|
_addSpecMatItemCell.gameObject.SetActive(true);
|
ItemCellModel cellModel = new ItemCellModel(specModel.SpecialMaterialD);
|
_addSpecMatItemCell.Init(cellModel);
|
_addSpecMatItemCell.countText.gameObject.SetActive(true);
|
int haveNum = playerPack.GetItemCountByID(PackType.Item,specModel.SpecialMaterialD);
|
if (haveNum >= specModel.SpecialMateriaNUM)
|
{
|
isEnoughSpecMat = true;
|
_addSpecMatItemCell.countText.text = UIHelper.AppendStringColor(TextColType.Green, haveNum.ToString(),true) + "/" + specModel.SpecialMateriaNUM;
|
}
|
else
|
{
|
isEnoughSpecMat = false;
|
_addSpecMatItemCell.countText.text = UIHelper.AppendStringColor(TextColType.Red,haveNum.ToString()) + "/" + specModel.SpecialMateriaNUM;
|
}
|
|
_addSpecMatItemCell.reducebtn.gameObject.SetActive(true);
|
_addSpecMatItemCell.reducebtn.RemoveAllListeners();
|
|
_addSpecMatItemCell.reducebtn.AddListener(() => { OnClickReduceBtn(); });
|
|
_addSpecMatBtn.onClick.AddListener(() => { ChooseWin.gameObject.SetActive(true); });
|
CreateRandomLineCell();
|
}
|
|
RefreshVirtualFill(_addExp);
|
|
}
|
|
private void OnClickReduceBtn()
|
{
|
SetSpecMatItemCell(null);
|
CreateRandomLineCell();
|
}
|
|
private void CreateRandomLineCell()
|
{
|
if (chooseSpecModel == null)
|
{
|
previewDict = FurnaceModel.GetPreviewMakeDruglist(curAlchemyModel);
|
previewDanlist = FurnaceModel.GetPreviewIdlist(curAlchemyModel);
|
}
|
else
|
{
|
previewDict = FurnaceModel.GetPreviewSpecMakeDruglist(chooseSpecModel);
|
previewDanlist = FurnaceModel.GetSpecPreviewIdlist(chooseSpecModel);
|
}
|
|
_randomLineCtrl.Refresh();
|
if (previewDanlist.Count > 0)
|
{
|
int line = (int)previewDanlist.Count / 3;
|
float remain = previewDanlist.Count % 3;
|
if (remain > 0)
|
line += 1;
|
|
int i = 0;
|
for (i = 0; i < line; i++)
|
{
|
_randomLineCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
}
|
_randomLineCtrl.Restart();
|
|
}
|
|
private void RefreshRandomLineCell(ScrollerDataType type, CellView cell)
|
{
|
int i = 0;
|
for (i = 0; i < cell.transform.childCount; i++)
|
{
|
int previewIndex = (cell.transform.childCount) * cell.index + i;
|
GameObject randomCell = cell.transform.GetChild(i).gameObject;
|
ItemCell itemCell = randomCell.transform.Find("ItemCell1").GetComponent<ItemCell>();
|
GameObject fullImg = randomCell.transform.Find("FullImg").gameObject;
|
UIEffect effect = randomCell.transform.Find("UIEffect").GetComponent<UIEffect>();
|
if (previewIndex <= previewDanlist.Count - 1)
|
{
|
int itemId = previewDanlist[previewIndex];
|
int effectId = previewDict[itemId];
|
if(effectId != 0)
|
{
|
effect.effect = effectId;
|
effect.gameObject.SetActive(true);
|
}
|
else
|
{
|
effect.gameObject.SetActive(false);
|
}
|
randomCell.SetActive(true);
|
ItemCellModel cellModel = new ItemCellModel(itemId);
|
itemCell.Init(cellModel);
|
AttrFruitConfig fruitConfig = AttrFruitConfig.Get(itemId);
|
if (playerPack.IsReachMaxUseDrug(fruitConfig))
|
{
|
fullImg.SetActive(true);
|
}
|
else
|
{
|
fullImg.SetActive(false);
|
}
|
|
itemCell.cellBtn.RemoveAllListeners();
|
itemCell.cellBtn.AddListener(() =>
|
{
|
ItemAttrData attrData = new ItemAttrData(itemId);
|
itemTipsModel.SetItemTipsModel(attrData);
|
});
|
}
|
else
|
{
|
randomCell.SetActive(false);
|
}
|
}
|
}
|
|
private void OnClickMakeDan()
|
{
|
if(noEnoughMatID != 0)
|
{
|
itemPathModel.SetChinItemModel(noEnoughMatID);
|
}
|
else
|
{
|
if(playerPack.GetEmptyGridCount(PackType.Item) < 1)
|
{
|
SysNotifyMgr.Instance.ShowTip("BagFull");
|
return;
|
}
|
|
if(chooseSpecModel != null)
|
{
|
if(!isEnoughSpecMat)
|
{
|
itemPathModel.SetChinItemModel(chooseSpecModel.SpecialMaterialD);
|
}
|
else
|
{
|
//ChangeMakeDanBtn(false);
|
makeDrugEffect.Play();
|
FurnaceModel.SendMakerDrugQuest((ushort)curAlchemyModel.AlchemyID, (uint)chooseSpecModel.ID);
|
}
|
}
|
else
|
{
|
//ChangeMakeDanBtn(false);
|
makeDrugEffect.Play();
|
FurnaceModel.SendMakerDrugQuest((ushort)curAlchemyModel.AlchemyID, 0);
|
}
|
}
|
}
|
|
private void OnMakeDrugEffectComplete()
|
{
|
//if (!WindowCenter.Instance.CheckOpen<MakerDrugSuccessWin>())
|
//{
|
// WindowCenter.Instance.Open<MakerDrugSuccessWin>();
|
//}
|
}
|
|
private void ChangeMakeDanBtn(bool isCanClick)
|
{
|
_makeDanBtn.interactable = isCanClick;
|
}
|
|
}
|
}
|