510 lines
12 KiB
C#
510 lines
12 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-09-12
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "KungfuPanel2" company="KUNPO"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using PureMVC.Interfaces;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using TMPro;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
namespace G.UI
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
partial class KungfuPanel : KUIWidget
|
|||
|
{
|
|||
|
#region Field
|
|||
|
|
|||
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
[KUIFlag]
|
|||
|
KUIToggleGroup _goPages;
|
|||
|
[KUIFlag]
|
|||
|
Toggle _tgShow;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goBookShow;
|
|||
|
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goPanel1;
|
|||
|
[KUIFlag]
|
|||
|
ScrollRect _goScroll;
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listGroup;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnStudy;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnTips;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnL;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnR;
|
|||
|
[KUIFlag]
|
|||
|
GameObject __goStudyCost;
|
|||
|
[KUIFlag]
|
|||
|
GameObject __goStudyCost2;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goStudy;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goLocked;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goMaxGrade;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpLocked;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goAttributes;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpDetailName;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpDetailAttributes;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnDetail;
|
|||
|
|
|||
|
//panel2
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goPanel2;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpBookGroupName;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpBookGroupDescription;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpBookGroupPointer;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpBookGroupProgress;
|
|||
|
[KUIFlag]
|
|||
|
Slider _sldBookGroupProgress;
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listBooks;
|
|||
|
|
|||
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
|
|||
|
CostWidget _priceItem;
|
|||
|
CostWidget _priceItem2;
|
|||
|
|
|||
|
int _curGroupIndex = 0;
|
|||
|
int _maxGroupIndex = 0;
|
|||
|
|
|||
|
int _lastBookGroupIndex = 0;
|
|||
|
|
|||
|
List<GroupWidget> _groupItems = new List<GroupWidget>();
|
|||
|
|
|||
|
int _showPage = 0;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
public override void Refresh()
|
|||
|
{
|
|||
|
if (_showPage == 0)
|
|||
|
ShowKunfu();
|
|||
|
else
|
|||
|
ShowBook();
|
|||
|
}
|
|||
|
|
|||
|
public void ShowPage(int index)
|
|||
|
{
|
|||
|
if (_showPage != index)
|
|||
|
{
|
|||
|
_showPage = index;
|
|||
|
Refresh();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void ShowKunfu()
|
|||
|
{
|
|||
|
_goPanel1.SetActive(true);
|
|||
|
_goPanel2.SetActive(false);
|
|||
|
|
|||
|
_goAttributes.SetActive(false);
|
|||
|
_btnStudy.interactable = true;
|
|||
|
|
|||
|
_curGroupIndex = 0;
|
|||
|
var groups = KungfuProxy.Instance.GetKungfuGroups();
|
|||
|
__listGroup.Clear();
|
|||
|
_groupItems.Clear();
|
|||
|
var groupItem = __listGroup.GetItem<GroupWidget>();
|
|||
|
//groupItem.SetData(group);
|
|||
|
_groupItems.Add(groupItem);
|
|||
|
foreach (var group in groups)
|
|||
|
{
|
|||
|
//var groupItem = __listGroup.GetItem<KungfuGroupItem2>();
|
|||
|
//groupItem.SetData(group);
|
|||
|
//_groupItems.Add(groupItem);
|
|||
|
if (group.isMaxGrade)
|
|||
|
_curGroupIndex += 1;
|
|||
|
}
|
|||
|
_maxGroupIndex = groups.Count - 1;
|
|||
|
SetGroupIndex(_curGroupIndex, false);
|
|||
|
}
|
|||
|
|
|||
|
void ShowBook()
|
|||
|
{
|
|||
|
_goPanel1.SetActive(false);
|
|||
|
_goPanel2.SetActive(true);
|
|||
|
|
|||
|
var groups = BookProxy.Instance.GetBookGroups();
|
|||
|
if (_lastBookGroupIndex > 0)
|
|||
|
{
|
|||
|
_curGroupIndex = _lastBookGroupIndex;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_curGroupIndex = 0;
|
|||
|
foreach (var group in groups)
|
|||
|
{
|
|||
|
if (group.isActive)
|
|||
|
_curGroupIndex += 1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
_maxGroupIndex = groups.Count - 1;
|
|||
|
SetGroupIndex(_curGroupIndex, false);
|
|||
|
}
|
|||
|
|
|||
|
void ShowDetailKungfu(ItemKungfu kungfu)
|
|||
|
{
|
|||
|
if (kungfu.grade > 0)
|
|||
|
{
|
|||
|
_goAttributes.SetActive(true);
|
|||
|
_tmpDetailName.text = kungfu.name + $"({kungfu.grade}级)";
|
|||
|
_tmpDetailAttributes.text = kungfu.ToString2();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void OnStudyBtnClick()
|
|||
|
{
|
|||
|
StartCoroutine(StudyAnimCO());
|
|||
|
//var book = KungfuProxy.Instance.Study(_curGroupIndex);
|
|||
|
//if (book != null)
|
|||
|
//{
|
|||
|
// _groupItems[_curGroupIndex].ShowStudyFx(book);
|
|||
|
//}
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator StudyAnimCO()
|
|||
|
{
|
|||
|
var group = KungfuProxy.Instance.GetKungfuGroupByIndex(_curGroupIndex);
|
|||
|
if (group != null)
|
|||
|
{
|
|||
|
var book = group.GetRndStudy();
|
|||
|
var price = group.curUpgradeCost;
|
|||
|
|
|||
|
var notEnoughId = MoneyProxy.Instance.CheckMoney2(price);
|
|||
|
if (notEnoughId != 0)
|
|||
|
{
|
|||
|
AdMoneyBox.ShowAdMoney(notEnoughId, true);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_goAttributes.SetActive(false);
|
|||
|
_btnStudy.interactable = false;
|
|||
|
yield return _groupItems[0].StudyAnimCO(book);
|
|||
|
//yield return _groupItems[_curGroupIndex].StudyAnimCO(book);
|
|||
|
KungfuProxy.Instance.Study(group, book);
|
|||
|
_btnStudy.interactable = true;
|
|||
|
ShowDetailKungfu(book);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnTipsBtnClick()
|
|||
|
{
|
|||
|
MessageBox.ShowMessage(KLocalization.GetLocalString(54), KLocalization.GetLocalString(55));
|
|||
|
}
|
|||
|
|
|||
|
private void OnBGBtnClick()
|
|||
|
{
|
|||
|
_goAttributes.SetActive(false);
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
//private int _scroll;
|
|||
|
//private float _scrollTarget;
|
|||
|
private void OnLBtnClick()
|
|||
|
{
|
|||
|
if (_curGroupIndex > 0)
|
|||
|
{
|
|||
|
SetGroupIndex(_curGroupIndex - 1);
|
|||
|
}
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
private void OnRBtnClick()
|
|||
|
{
|
|||
|
if (_curGroupIndex < _maxGroupIndex)
|
|||
|
{
|
|||
|
SetGroupIndex(_curGroupIndex + 1);
|
|||
|
}
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
private void SetGroupIndex(int index, bool anim = true)
|
|||
|
{
|
|||
|
_curGroupIndex = Mathf.Clamp(index, 0, _maxGroupIndex);
|
|||
|
|
|||
|
if (_showPage == 0)
|
|||
|
{
|
|||
|
var groups = KungfuProxy.Instance.GetKungfuGroups();
|
|||
|
var kungfuGroup = groups[_curGroupIndex];
|
|||
|
|
|||
|
_groupItems[0].SetData(kungfuGroup);
|
|||
|
|
|||
|
if (_curGroupIndex == 0 || (kungfuGroup.unlockLevel <= LevelProxy.Instance.currentCompletedLevel && groups[_curGroupIndex - 1].isMaxGrade))
|
|||
|
{
|
|||
|
_goLocked.SetActive(false);
|
|||
|
if (kungfuGroup.isMaxGrade)
|
|||
|
{
|
|||
|
_goStudy.SetActive(false);
|
|||
|
_goMaxGrade.SetActive(true);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_goMaxGrade.SetActive(false);
|
|||
|
_goStudy.SetActive(true);
|
|||
|
|
|||
|
var upgradeCost = groups[_curGroupIndex].curUpgradeCost;
|
|||
|
|
|||
|
if (upgradeCost.Length == 1)
|
|||
|
{
|
|||
|
_priceItem.SetPrice(upgradeCost[0], MoneyProxy.Instance.CheckMoney(upgradeCost[0]));
|
|||
|
_priceItem2.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
else if (upgradeCost.Length == 2)
|
|||
|
{
|
|||
|
_priceItem.SetPrice(upgradeCost[0], MoneyProxy.Instance.CheckMoney(upgradeCost[0]));
|
|||
|
_priceItem2.gameObject.SetActive(true);
|
|||
|
_priceItem2.SetPrice(upgradeCost[1], MoneyProxy.Instance.CheckMoney(upgradeCost[1]));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_goMaxGrade.SetActive(false);
|
|||
|
_goStudy.SetActive(false);
|
|||
|
_goLocked.SetActive(true);
|
|||
|
var levelItem = ItemProxy.Instance.GetStaticItem<ItemLevel>(kungfuGroup.unlockLevel);
|
|||
|
if (levelItem != null)
|
|||
|
{
|
|||
|
var unlockStr = $"第{levelItem.id}关";
|
|||
|
_tmpLocked.text = string.Format(KLocalization.GetLocalString(70), unlockStr);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_tmpLocked.text = "暂未开放";
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_lastBookGroupIndex = index;
|
|||
|
|
|||
|
var groups = BookProxy.Instance.GetBookGroups();
|
|||
|
var bookGroup = groups[_curGroupIndex];
|
|||
|
|
|||
|
_tmpBookGroupName.text = bookGroup.name;
|
|||
|
_tmpBookGroupDescription.text = bookGroup.description;
|
|||
|
int activeCount = bookGroup.activeBookCount;
|
|||
|
int maxCount = bookGroup.maxBookCount;
|
|||
|
_tmpBookGroupProgress.text = $"{activeCount}/{maxCount}";
|
|||
|
_sldBookGroupProgress.value = activeCount / (float)maxCount;
|
|||
|
|
|||
|
var chapter = ItemProxy.Instance.GetStaticItem<ItemChapter>(bookGroup.id);
|
|||
|
if (chapter != null)
|
|||
|
_tmpBookGroupPointer.text = string.Format(KLocalization.GetLocalString(30), chapter.name);
|
|||
|
|
|||
|
__listBooks.Clear();
|
|||
|
for (int i = 0; i < bookGroup.books.Length; i++)
|
|||
|
{
|
|||
|
var bookId = bookGroup.books[i];
|
|||
|
__listBooks.GetItem().SetData(ItemProxy.Instance.GetStaticItem<ItemBook>(bookId));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
_btnL.gameObject.SetActive(_curGroupIndex != 0);
|
|||
|
_btnR.gameObject.SetActive(_curGroupIndex != _maxGroupIndex);
|
|||
|
|
|||
|
//_scrollTarget = _curGroupIndex / (float)_maxGroupIndex;
|
|||
|
//if (anim)
|
|||
|
//{
|
|||
|
// _scroll = 1;
|
|||
|
//}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// _scroll = 2;
|
|||
|
// _goScroll.horizontalNormalizedPosition = _scrollTarget;
|
|||
|
//}
|
|||
|
}
|
|||
|
|
|||
|
private void OnShowToggleClick(bool tg)
|
|||
|
{
|
|||
|
if (tg)
|
|||
|
{
|
|||
|
ShowPage(0);
|
|||
|
_goBookShow.SetActive(true);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.文学);
|
|||
|
if (function != null)
|
|||
|
{
|
|||
|
if (function.IsUnlock())
|
|||
|
{
|
|||
|
ShowPage(1);
|
|||
|
_goBookShow.SetActive(false);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_tgShow.isOn = true;
|
|||
|
ToastBox.ShowText(function.lockTips);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
private void OnToggleSelected(int index)
|
|||
|
{
|
|||
|
if (index == 0)
|
|||
|
{
|
|||
|
ShowPage(0);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.文学);
|
|||
|
if (function != null)
|
|||
|
{
|
|||
|
if (function.IsUnlock())
|
|||
|
{
|
|||
|
ShowPage(1);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_goPages.toggles[0].isOn = true;
|
|||
|
ToastBox.ShowText(function.lockTips);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Mediator
|
|||
|
|
|||
|
private readonly int[] _notificationInterests = new int[]
|
|||
|
{
|
|||
|
GlobalDefine.EVENT_KUNGFU_STUDY,
|
|||
|
GlobalDefine.EVENT_KUNGFU_DETAIL,
|
|||
|
};
|
|||
|
|
|||
|
public override IList<int> ListNotificationInterests()
|
|||
|
{
|
|||
|
return _notificationInterests;
|
|||
|
}
|
|||
|
|
|||
|
public override void HandleNotification(INotification notification)
|
|||
|
{
|
|||
|
if (notification.Name == GlobalDefine.EVENT_KUNGFU_STUDY)
|
|||
|
Refresh();
|
|||
|
else if (notification.Name == GlobalDefine.EVENT_KUNGFU_DETAIL)
|
|||
|
ShowDetailKungfu(notification.Body as ItemKungfu);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
_priceItem = __goStudyCost.AddComponent<CostWidget>();
|
|||
|
_priceItem2 = __goStudyCost2.AddComponent<CostWidget>();
|
|||
|
|
|||
|
__listGroup.AddTemplate<GroupWidget>(true);
|
|||
|
_btnStudy.onClick.AddListener(this.OnStudyBtnClick);
|
|||
|
//_btnTips.onClick.AddListener(this.OnTipsBtnClick);
|
|||
|
_btnL.onClick.AddListener(this.OnLBtnClick);
|
|||
|
_btnR.onClick.AddListener(this.OnRBtnClick);
|
|||
|
_btnDetail.onClick.AddListener(this.OnBGBtnClick);
|
|||
|
|
|||
|
//_goScroll.onValueChanged.AddListener(this.OnScrollValueChanged);
|
|||
|
|
|||
|
_goPages.onToggleSelected.AddListener(this.OnToggleSelected);
|
|||
|
_tgShow.onValueChanged.AddListener(this.OnShowToggleClick);
|
|||
|
|
|||
|
__listBooks.AddTemplate<Book2Widget>(true);
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
RegisterThis();
|
|||
|
|
|||
|
Refresh();
|
|||
|
PostNotification(GlobalDefine.EVENT_WINDOW_OPENED, 1, "");
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
UnregisterThis();
|
|||
|
}
|
|||
|
|
|||
|
private void LateUpdate()
|
|||
|
{
|
|||
|
//if (_scroll == 0 && !Input.anyKey)
|
|||
|
//{
|
|||
|
// if (_goScroll.horizontalNormalizedPosition < 0.5f)
|
|||
|
// {
|
|||
|
// if (_goScroll.horizontalNormalizedPosition > 0f)
|
|||
|
// _goScroll.horizontalNormalizedPosition -= Time.deltaTime;
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// if (_goScroll.horizontalNormalizedPosition < 1f)
|
|||
|
// _goScroll.horizontalNormalizedPosition += Time.deltaTime;
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
//if (_scroll == 1)
|
|||
|
//{
|
|||
|
// float diff = _goScroll.horizontalNormalizedPosition - _scrollTarget;
|
|||
|
// if (Mathf.Abs(diff) < 0.1f)
|
|||
|
// {
|
|||
|
// _scroll = 0;
|
|||
|
// _goScroll.horizontalNormalizedPosition = _scrollTarget;
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// if (diff > 0)
|
|||
|
// {
|
|||
|
// _goScroll.horizontalNormalizedPosition -= Time.deltaTime * 2f;
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// _goScroll.horizontalNormalizedPosition += Time.deltaTime * 2f;
|
|||
|
// }
|
|||
|
// }
|
|||
|
//}
|
|||
|
//else if (_scroll == 2)
|
|||
|
//{
|
|||
|
// _scroll = 0;
|
|||
|
// _goScroll.horizontalNormalizedPosition = _scrollTarget;
|
|||
|
//}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|