using UnityEngine; using UnityEngine.UI; using TableConfig; 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 _materiallist = new List(); [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] FurnaceFireChooseWin ChooseWin; [SerializeField] UIEffect bgEffect; [SerializeField] UIEffect makeDrugEffect; private ToggleGroup _toggleGroup; private int presentIndex = 0; private AlchemyConfig curAlchemyModel; private AlchemySpecConfig chooseSpecModel = null; private List previewDanlist; BlastFurnaceModel _furnaceModel; BlastFurnaceModel FurnaceModel { get { return _furnaceModel ?? (_furnaceModel = ModelCenter.Instance.GetModel()); } } GetItemPathModel _itemPathModel; GetItemPathModel itemPathModel { get { return _itemPathModel ?? (_itemPathModel = ModelCenter.Instance.GetModel()); } } ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel(); } } PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } private int noEnoughMatID = 0; private bool isEnoughSpecMat = true; AchievementGuideEffect guideEffect = null; public int isJumpToId = 0; private void Awake() { _danDrugCtrl.OnRefreshCell += RefreshDandrugCell; _danDrugCtrl.lockType = EnhanceLockType.KeepVertical; _toggleGroup = _danDrugCtrl.GetComponent(); _makeDanBtn.onClick.AddListener(OnClickMakeDan); FurnaceModel.RefreshStoveModelEvent += RefreshStoveModel; playerPack.RefreshItemCountAct += RefreshItemCnt; FurnaceModel.RefreshAddSpecMatEvent += SetSpecMatItemCell; _randomLineCtrl.OnRefreshCell += RefreshRandomLineCell; // makeDrugEffect.OnComplete += OnMakeDrugEffectComplete; } private void OnEnable() { isJumpToId = 0; guideEffect = null; ChangeMakeDanBtn(true); chooseSpecModel = null; ChooseWin.gameObject.SetActive(false); RefreshStoveModel(); presentIndex = 0; CreateCell(); StartCoroutine(CheckJumpToModel()); } private void OnDisable() { } IEnumerator CheckJumpToModel() { yield return null; SuccessConfig successConfig = Config.Instance.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; _danDrugCtrl.JumpIndex(presentIndex - 1); _danDrugCtrl.m_Scorller.RefreshActiveCellViews(); break; } } if (isMakeDan) { guideEffect = AchievementGuideEffectPool.Require(1); guideEffect.transform.SetParentEx(_makeDanBtn.transform, Vector3.zero, Quaternion.identity, Vector3.one); } else { MessageWin.Inst.ShowFixedTip("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; } } } _danDrugCtrl.JumpIndex(presentIndex - 1); _danDrugCtrl.m_Scorller.RefreshActiveCellViews(); } OnClickDandrugCell(presentIndex); } 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); } } 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 RefreshItemCnt(PackType type, int index, int id) { CreateCell(); OnClickDandrugCell(presentIndex); } private void RefreshDandrugCell(ScrollerDataType type, CellView cell) { DandrugCell dandrugCell = cell.GetComponent(); 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(); 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); SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.rptItem); if (singlePack == null) return; int haveMaterCount = singlePack.GetItemCountByID(materialId); if(haveMaterCount >= materialNum) { itemCell.countText.text = UIHelper.GetTextColorByItemColor(TextColType.White,haveMaterCount.ToString()) +"/" + materialNum; } else { if(noEnoughMatID == 0) { noEnoughMatID = materialId; } itemCell.countText.text = UIHelper.GetTextColorByItemColor(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.rptItem,specModel.SpecialMaterialD); if (haveNum >= specModel.SpecialMateriaNUM) { isEnoughSpecMat = true; _addSpecMatItemCell.countText.text = UIHelper.GetTextColorByItemColor(TextColType.Green, haveNum.ToString(),true) + "/" + specModel.SpecialMateriaNUM; } else { isEnoughSpecMat = false; _addSpecMatItemCell.countText.text = UIHelper.GetTextColorByItemColor(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) previewDanlist = FurnaceModel.GetPreviewMakeDruglist(curAlchemyModel).Keys.ToList(); else previewDanlist = FurnaceModel.GetPreviewSpecMakeDruglist(chooseSpecModel).Keys.ToList(); _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(); GameObject fullImg = randomCell.transform.Find("FullImg").gameObject; UIEffect effect = randomCell.transform.Find("UIEffect").GetComponent(); if (previewIndex <= previewDanlist.Count - 1) { int itemId = previewDanlist[previewIndex]; int effectId = FurnaceModel.GetEffectIdByItemId(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 = Config.Instance.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.GetReaminGridCount(PackType.rptItem) < 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()) //{ // WindowCenter.Instance.Open(); //} } private void ChangeMakeDanBtn(bool isCanClick) { _makeDanBtn.interactable = isCanClick; } } }