412 lines
9.6 KiB
C#
Raw Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-03-28
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "SwordWindow.View" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G.UI
{
using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
///
/// </summary>
partial class SwordWindow
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
GameObject _goPanel1;
[KUIFlag]
GameObject __goPanel2;
[KUIFlag]
GameObject __goSwordUpgrade;
[KUIFlag]
GameObject __goSwordReward;
[KUIFlag]
Button _btnBack;
[KUIFlag]
TextMeshProUGUI _tmpCombatValue;
[KUIFlag]
GameObject __goCurrTitle;
[KUIFlag]
GameObject __goNextTitle;
[KUIFlag]
GameObject __listSwords;
[KUIFlag]
Button _btnBattle;
[KUIFlag]
TextMeshProUGUI _tmpBattle;
[KUIFlag]
GameObject __goBattleReward;
[KUIFlag]
Button _btnTips;
[KUIFlag]
GameObject _goGains;
[KUIFlag]
Button _btnGains;
[KUIFlag]
Button _btnAdGains;
[KUIFlag]
TextMeshProUGUI _tmpGains;
[KUIFlag]
KUIImage _imgGainStates;
[KUIFlag]
TextMeshProUGUI _tmpSwordLevel;
[KUIFlag]
GameObject __goToggles;
[KUIFlag]
TextMeshProUGUI _tmpRequire;
[KUIFlag]
Button _btnRanking;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private TitleWidget _currTitleWidget;
private TitleWidget _nextTitleWidget;
private SwordWidget[] _swordWidgets;
private Toggle[] __toggles;
private TitleStudyWidget _titleStudyWidget;
private SwordUpgradePanel _swordUpgradePanel;
private SwordAdRewardBox _swordRewardBox;
private PropWidget _battleReward;
#endregion
#region Method
/// <summary>
///
/// </summary>
public void InitView()
{
SetViewData();
_btnBack.onClick.AddListener(this.OnBackBtnClick);
_btnBattle.onClick.AddListener(this.OnBattleBtnClick);
_btnTips.onClick.AddListener(this.OnTipsBtnClick);
_btnGains.onClick.AddListener(this.OnGainsBtnClick);
_btnAdGains.onClick.AddListener(this.OnAdGainsBtnClick);
_btnRanking.onClick.AddListener(this.OnRankingBtnClick);
_currTitleWidget = __goCurrTitle.AddComponent<TitleWidget>();
_nextTitleWidget = __goNextTitle.AddComponent<TitleWidget>();
__toggles = __goToggles.GetComponentsInChildren<Toggle>();
for (int i = 0; i < __toggles.Length; i++)
{
__toggles[i].onValueChanged.AddListener(this.OnToggleValueChanged);
}
var swordRoot = __listSwords.transform;
_swordWidgets = new SwordWidget[swordRoot.childCount];
for (int i = 0; i < swordRoot.childCount; i++)
{
_swordWidgets[i] = swordRoot.GetChild(i).gameObject.AddComponent<SwordWidget>();
_swordWidgets[i].index = i;
_swordWidgets[i].SetData(SwordProxy.Instance.GetSwordInfo(i + 1));
}
_battleReward = __goBattleReward.AddComponent<PropWidget>();
_swordUpgradePanel = __goSwordUpgrade.AddComponent<SwordUpgradePanel>();
_swordRewardBox = __goSwordReward.AddComponent<SwordAdRewardBox>();
_titleStudyWidget = __goPanel2.AddComponent<TitleStudyWidget>();
_goPanel1.SetActive(true);
__goPanel2.SetActive(false);
__goSwordUpgrade.SetActive(false);
}
/// <summary>
///
/// </summary>
public void RefreshView()
{
RefreshLevel();
RefreshTitle();
RefreshGains();
RefreshCombatValue();
RefreshSword();
var studyTitle = SwordProxy.Instance.GetStudyTitle();
if (studyTitle == null)
{
if (!__toggles[0].isOn)
{
__toggles[0].isOn = true;
}
}
}
/// <summary>
///
/// </summary>
private void RefreshGains()
{
var minuteRewards = SwordProxy.Instance.minuteRewards;
if (minuteRewards.count > 0)
{
_goGains.SetActive(true);
_tmpGains.text = $"{minuteRewards.count * 60}/时";
var accumMinute = SwordProxy.Instance.accumMinute;
if (accumMinute > 0)
{
_btnGains.gameObject.SetActive(true);
var totalMinute = SwordProxy.Instance.totalMinute;
if (accumMinute >= totalMinute)
_imgGainStates.ShowSprite(2);
else if ((accumMinute + accumMinute) >= totalMinute)
_imgGainStates.ShowSprite(1);
else
_imgGainStates.ShowSprite(0);
}
else
{
_btnGains.gameObject.SetActive(false);
}
}
else
{
_goGains.SetActive(false);
}
}
private void RefreshTitle()
{
var currTitle = SwordProxy.Instance.GetTitle();
_currTitleWidget.SetData(currTitle);
var nextTitle = currTitle.nextTitle;
if (nextTitle != null)
{
_nextTitleWidget.SetData(nextTitle);
__goNextTitle.SetActive(true);
}
else
{
__goNextTitle.SetActive(false);
}
}
private void RefreshLevel()
{
var swordLevel = SwordProxy.Instance.swordLevel;
var swordLevelMax = SwordProxy.Instance.swordLevelMax;
_tmpSwordLevel.text = $"当前层数:{swordLevel}";
if (swordLevel < swordLevelMax)
{
var swordLevelItem = ItemProxy.Instance.GetStaticItem<ItemSwordLevel>(Mathf.Max(swordLevel, 1));
_btnBattle.interactable = true;
_tmpBattle.text = "挑战";
_tmpRequire.transform.parent.gameObject.SetActive(true);
_tmpRequire.text = $"需求战力: {swordLevelItem.requirementCV}";
_tmpRequire.color = PlayerProxy.Instance.combatValue >= swordLevelItem.requirementCV ? Color.white : Color.red;
_battleReward.gameObject.SetActive(true);
_battleReward.SetItem(SwordProxy.Instance.completedReward);
}
else
{
_tmpRequire.transform.parent.gameObject.SetActive(false);
_btnBattle.interactable = false;
_tmpBattle.text = "已登顶";
_battleReward.gameObject.SetActive(false);
}
}
private void RefreshCombatValue()
{
_tmpCombatValue.text = SwordProxy.Instance.GetTitleCombatValue().ToString();
}
private void RefreshSword()
{
for (int i = 0; i < _swordWidgets.Length; i++)
{
_swordWidgets[i].Refresh();
}
}
/// <summary>
///
/// </summary>
public void UpdateView()
{
RefreshGains();
}
void ShowSwordDetail(SwordProxy.SwordInfo swordInfo)
{
if (swordInfo != null)
{
__listSwords.SetActive(false);
__goSwordUpgrade.SetActive(true);
_swordUpgradePanel.SetData(swordInfo);
for (int i = 0; i < _swordWidgets.Length; i++)
{
_swordWidgets[i].transform.SetParent(__listSwords.transform);
}
int swordIndex = swordInfo.id - 1;
_swordWidgets[swordIndex].transform.SetParent(_swordUpgradePanel.swordRoot, false);
_swordWidgets[swordIndex].transform.localPosition = Vector3.zero;
_swordWidgets[swordIndex].SetScale(1.5f);
}
}
void HideSwordDetail()
{
__listSwords.SetActive(true);
for (int i = 0; i < _swordWidgets.Length; i++)
{
_swordWidgets[i].transform.SetParent(__listSwords.transform);
_swordWidgets[i].transform.SetSiblingIndex(i);
_swordWidgets[i].ResetPosition();
_swordWidgets[i].SetScale(1f);
}
}
private void OnBackBtnClick()
{
CloseWindow(this);
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnBattleBtnClick()
{
if (SwordProxy.Instance.QuickBattle() > 0)
{
var rewards = SwordProxy.Instance.GetSettleRewards();
if (rewards.count > 0)
{
RewardWindow.ShowReward(rewards, null);
}
ToastBox.ShowText($"直升 {SwordProxy.Instance.swordLevel}");
RefreshView();
return;
}
SwordProxy.Instance.StartBattle((error, message) =>
{
});
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnTipsBtnClick()
{
MessageBox.ShowMessage(KLocalization.GetLocalString(56), KLocalization.GetLocalString(57));
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
void OnGainsBtnClick()
{
SwordProxy.Instance.GetAccumulateGains((error, message) =>
{
if (error == 0)
{
}
else
{
PostNotification(GlobalDefine.EVENT_SHOW_TOAST, message);
}
});
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
void OnAdGainsBtnClick()
{
__goSwordReward.SetActive(true);
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
bool _ignoreToggle;
private void OnToggleValueChanged(bool value)
{
if (value && !_ignoreToggle)
{
int index = 0;
for (int i = 0; i < __toggles.Length; i++)
{
if (__toggles[i].isOn)
{
index = i;
break;
}
}
if (index == 1)
{
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.);
if (function == null || function.IsUnlock())
{
var studyTitle = SwordProxy.Instance.GetStudyTitle();
if (studyTitle == null)
{
var title = SwordProxy.Instance.GetTitle();
if (title.studyAdd != null && title.studyAdd.Length > 0)
{
studyTitle = SwordProxy.Instance.SetStudyTitle();
}
}
if (studyTitle != null)
{
_goPanel1.SetActive(false);
__goPanel2.SetActive(true);
_titleStudyWidget.SetData(studyTitle);
}
}
else
{
_ignoreToggle = true;
__toggles[0].isOn = true;
__toggles[1].isOn = false;
_ignoreToggle = false;
ToastBox.ShowText(function.lockTips);
}
}
else
{
_goPanel1.SetActive(true);
__goPanel2.SetActive(false);
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
}
void OnRankingBtnClick()
{
OpenWindow<RankingWindow>("sword");
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
#endregion
}
}