636 lines
15 KiB
C#
636 lines
15 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2021-06-08
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "TravelWindow.View" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G.UI
|
|
{
|
|
using DG.Tweening;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
partial class TravelWindow
|
|
{
|
|
#region Auto Generate
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
[KUIFlag]
|
|
GameObject _goL;
|
|
[KUIFlag]
|
|
GameObject _goR;
|
|
[KUIFlag]
|
|
Image _imgL;
|
|
[KUIFlag]
|
|
Image _imgR;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpLName;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpRName;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpContent;
|
|
[KUIFlag]
|
|
Button _btnFrame;
|
|
|
|
[KUIFlag]
|
|
Image _imgBg;
|
|
|
|
[KUIFlag]
|
|
KUIList __goType1;
|
|
[KUIFlag]
|
|
KUIList __goType2;
|
|
|
|
[KUIFlag]
|
|
Button _btnOption1;
|
|
[KUIFlag]
|
|
Button _btnOption2;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpOption1;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpOption2;
|
|
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
#endregion
|
|
|
|
#region Field
|
|
|
|
StoryAction _storyAction;
|
|
Tweener _storyTweener;
|
|
|
|
/// <summary>
|
|
/// 1 剧情 2 选项 3 结束
|
|
/// </summary>
|
|
private int _state;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void InitView()
|
|
{
|
|
SetViewData();
|
|
__goType1.AddTemplate<StarWidget>(true);
|
|
__goType2.AddTemplate<PropWidget>(true);
|
|
_btnFrame.onClick.AddListener(this.OnFrameBtnClick);
|
|
}
|
|
|
|
public void RefreshView()
|
|
{
|
|
if (this.data is CityProxy.CityInfo city)
|
|
{
|
|
var e = city.currCityEvent;
|
|
|
|
__goType1.gameObject.SetActive(false);
|
|
__goType2.gameObject.SetActive(false);
|
|
_btnOption1.gameObject.SetActive(false);
|
|
_btnOption2.gameObject.SetActive(false);
|
|
|
|
if (!string.IsNullOrEmpty(e.bg))
|
|
StartCoroutine(SetBg(e.bg));
|
|
//_imgBg.ShowSprite(Mathf.Max(0, e.type - 1));
|
|
_state = 1;
|
|
StoryProxy.Instance.TriggerStory(e.story, this.OnStoryFinish);
|
|
|
|
KStatistics.Instance.ReportEvent_Travel(city.item.name, e.type, 0, 0);
|
|
}
|
|
}
|
|
|
|
System.Collections.IEnumerator SetBg(string bg)
|
|
{
|
|
_imgBg.CrossFadeAlpha(0.5f, 0.0f, true);
|
|
_imgBg.CrossFadeAlpha(1f, 0.3f, true);
|
|
var ao = AssetProxy.Instance.TryGetTemporaryAssetAsync<Sprite>($"{bg}[{bg}]");
|
|
yield return ao;
|
|
if (ao.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
|
|
_imgBg.overrideSprite = ao.Result;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void OnStoryFinish()
|
|
{
|
|
_state = 2;
|
|
|
|
if (this.data is CityProxy.CityInfo city)
|
|
{
|
|
var e = city.currCityEvent;
|
|
if (e.type == 1)
|
|
{
|
|
int beautyId = e.typeArgs[0];
|
|
int addFriend = e.typeArgs[1];
|
|
|
|
__goType2.gameObject.SetActive(false);
|
|
__goType1.gameObject.SetActive(true);
|
|
__goType1.Clear();
|
|
var beauty = BeautyProxy.Instance.GetBeauty(beautyId);
|
|
var friendMax = beauty.friendMax;
|
|
var friendCur = Mathf.Max(0, beauty.friend) + addFriend;
|
|
for (int i = 0; i < friendMax; i++)
|
|
{
|
|
__goType1.GetItem<StarWidget>().SetGray(i >= friendCur, i == friendCur);
|
|
}
|
|
if (BeautyProxy.Instance.AddFriend(beauty, addFriend))
|
|
{
|
|
OpenWindow<GetBeautyBox>(beauty.item);
|
|
CloseWindow(this);
|
|
}
|
|
else
|
|
_state = 3;
|
|
}
|
|
else if (e.type == 2)
|
|
{
|
|
__goType1.gameObject.SetActive(false);
|
|
__goType2.gameObject.SetActive(false);
|
|
|
|
Battle(e, 0);
|
|
}
|
|
else if (e.type == 3)
|
|
{
|
|
__goType1.gameObject.SetActive(false);
|
|
__goType2.gameObject.SetActive(true);
|
|
|
|
IList<Item.ItemInfo> rewards = null;
|
|
if (e.rewardInfos != null && e.rewardInfos.Length > 0)
|
|
rewards = e.rewardInfos;
|
|
else
|
|
{
|
|
var boxItem = BoxProxy.Instance.GetBoxInfo(e.rewardBox);
|
|
if (boxItem != null)
|
|
{
|
|
rewards = boxItem.GetRndItems();
|
|
}
|
|
}
|
|
|
|
__goType2.Clear();
|
|
if (rewards != null)
|
|
for (int i = 0; i < rewards.Count; i++)
|
|
{
|
|
__goType2.GetItem<PropWidget>().SetItem(rewards[i]);
|
|
}
|
|
|
|
if (rewards != null && rewards.Count > 0)
|
|
{
|
|
RewardProxy.Instance.GetRewardsWithUI(rewards, null);
|
|
}
|
|
CloseWindow(this);
|
|
}
|
|
else if (e.type == 4)
|
|
{
|
|
__goType1.gameObject.SetActive(false);
|
|
__goType2.gameObject.SetActive(true);
|
|
__goType2.Clear();
|
|
|
|
_helper.Clear();
|
|
var rewards = _helper;
|
|
Dig(e, 0, rewards);
|
|
}
|
|
else if (e.type == 5)
|
|
{
|
|
__goType1.gameObject.SetActive(false);
|
|
__goType2.gameObject.SetActive(true);
|
|
__goType2.Clear();
|
|
|
|
var rewards = _helper;
|
|
rewards.Clear();
|
|
rewards.AddRange(e.rewardInfos);
|
|
Bet(e, 0, rewards);
|
|
}
|
|
else if (e.type == 6)
|
|
{
|
|
__goType2.gameObject.SetActive(false);
|
|
__goType1.gameObject.SetActive(true);
|
|
|
|
int petId = e.typeArgs[0];
|
|
int addFriend = e.typeArgs[1];
|
|
|
|
var pet = PetProxy.Instance.GetPet(petId);
|
|
var friendMax = pet.friendMax;
|
|
var friendCur = Mathf.Max(0, pet.friend) + addFriend;
|
|
__goType1.Clear();
|
|
for (int i = 0; i < friendMax; i++)
|
|
{
|
|
__goType1.GetItem<StarWidget>().SetGray(i >= friendCur, i == friendCur);
|
|
}
|
|
|
|
if (pet.AddFriend(addFriend))
|
|
{
|
|
OpenWindow<GetPetBox>(pet);
|
|
CloseWindow(this);
|
|
}
|
|
else
|
|
_state = 3;
|
|
}
|
|
else if (e.type == 7)
|
|
{
|
|
__goType1.gameObject.SetActive(false);
|
|
__goType2.gameObject.SetActive(false);
|
|
|
|
int bookId = e.typeArgs[0];
|
|
var book = BookProxy.Instance.GetBook(bookId);
|
|
if (BookProxy.Instance.UnlockBook(book))
|
|
{
|
|
OpenWindow<GetBookBox>(book);
|
|
CloseWindow(this);
|
|
}
|
|
else
|
|
_state = 3;
|
|
}
|
|
}
|
|
}
|
|
|
|
private readonly List<Item.ItemInfo> _helper = new List<Item.ItemInfo>();
|
|
|
|
/// <summary>
|
|
/// 战斗事件
|
|
/// </summary>
|
|
/// <param name="cityEvent"></param>
|
|
/// <param name="tier"></param>
|
|
private void Battle(ItemCityEvent cityEvent, int tier)
|
|
{
|
|
var option_1 = cityEvent.option_1;
|
|
if (tier < option_1.Length)
|
|
{
|
|
_btnOption1.gameObject.SetActive(true);
|
|
_tmpOption1.text = cityEvent.matter_1[tier];
|
|
|
|
_btnOption1.onClick.RemoveAllListeners();
|
|
_btnOption1.onClick.AddListener(() =>
|
|
{
|
|
if (cityEvent.typeArgs != null && cityEvent.typeArgs.Length > 0)
|
|
{
|
|
LevelProxy.Instance.StartSpecial(cityEvent.typeArgs[0]);
|
|
}
|
|
|
|
KStatistics.Instance.ReportEvent_Travel("", cityEvent.type, 1, tier);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_btnOption1.gameObject.SetActive(false);
|
|
}
|
|
|
|
var option_2 = cityEvent.option_2;
|
|
if (tier < option_2.Length)
|
|
{
|
|
var option = option_2[tier];
|
|
_btnOption2.gameObject.SetActive(true);
|
|
_tmpOption2.text = cityEvent.matter_2[tier];
|
|
|
|
_btnOption2.onClick.RemoveAllListeners();
|
|
_btnOption2.onClick.AddListener(() =>
|
|
{
|
|
if (option != null && option.Length > 0)
|
|
{
|
|
var tag = option[0];
|
|
|
|
if (tag == 1)
|
|
{
|
|
ToastBox.ShowText($"交了{option[1]}个铜板");
|
|
MoneyProxy.Instance.AddCoin(-option[1]);
|
|
CloseWindow(this);
|
|
}
|
|
else if (tag == 2)
|
|
{
|
|
var flag = GlobalUtils.RndHundred < option[1];
|
|
if (flag)
|
|
{
|
|
var rewards = cityEvent.rewardInfos;
|
|
if (rewards != null && rewards.Length > 0)
|
|
{
|
|
RewardProxy.Instance.GetRewardsWithUI(rewards, null);
|
|
CloseWindow(this);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Battle(cityEvent, tier + 1);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CloseWindow(this);
|
|
}
|
|
|
|
KStatistics.Instance.ReportEvent_Travel("", cityEvent.type, 2, tier);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_btnOption2.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="rewards"></param>
|
|
private void Dig(ItemCityEvent cityEvent, int tier, List<Item.ItemInfo> rewards)
|
|
{
|
|
__goType2.Clear();
|
|
for (int i = 0; i < rewards.Count; i++)
|
|
{
|
|
__goType2.GetItem<PropWidget>().SetItem(rewards[i]);
|
|
}
|
|
|
|
if (tier < cityEvent.talk_1.Length)
|
|
{
|
|
_tmpContent.text = cityEvent.talk_1[tier];
|
|
}
|
|
|
|
if (tier < cityEvent.option_1.Length)
|
|
{
|
|
var option = cityEvent.option_1[tier];
|
|
_btnOption1.gameObject.SetActive(true);
|
|
_tmpOption1.text = cityEvent.matter_1[tier];
|
|
|
|
_btnOption1.onClick.RemoveAllListeners();
|
|
_btnOption1.onClick.AddListener(() =>
|
|
{
|
|
bool success = RandomProxy.Instance.GetRandom(option[0]);
|
|
if (success)
|
|
//if (GlobalUtils.RndHundred < option[0])
|
|
{
|
|
//success
|
|
var boxItem = BoxProxy.Instance.GetBoxInfo(cityEvent.rewardBox);
|
|
if (boxItem != null)
|
|
{
|
|
rewards.AddRange(boxItem.GetRndItemsByChapter(tier));
|
|
}
|
|
ToastBox.ShowText(28);
|
|
Dig(cityEvent, tier + 1, rewards);
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(27);
|
|
CloseWindow(this);
|
|
}
|
|
KStatistics.Instance.ReportEvent_Travel("", cityEvent.type, 1, tier);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
if (rewards != null && rewards.Count > 0)
|
|
{
|
|
RewardProxy.Instance.GetRewardsWithUI(rewards, null);
|
|
}
|
|
CloseWindow(this);
|
|
_btnOption1.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (tier < cityEvent.option_2.Length)
|
|
{
|
|
var option = cityEvent.option_2[tier];
|
|
_btnOption2.gameObject.SetActive(true);
|
|
_tmpOption2.text = cityEvent.matter_2[tier];
|
|
|
|
_btnOption2.onClick.RemoveAllListeners();
|
|
_btnOption2.onClick.AddListener(() =>
|
|
{
|
|
if (rewards != null && rewards.Count > 0)
|
|
{
|
|
RewardProxy.Instance.GetRewardsWithUI(rewards, null);
|
|
}
|
|
CloseWindow(this);
|
|
KStatistics.Instance.ReportEvent_Travel("", cityEvent.type, 2, tier);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_btnOption2.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="cityEvent"></param>
|
|
/// <param name="tier"></param>
|
|
/// <param name="rewards"></param>
|
|
private void Bet(ItemCityEvent cityEvent, int tier, List<Item.ItemInfo> rewards)
|
|
{
|
|
__goType2.Clear();
|
|
for (int i = 0; i < rewards.Count; i++)
|
|
{
|
|
__goType2.GetItem<PropWidget>().SetItem(rewards[i]);
|
|
}
|
|
|
|
if (tier < cityEvent.option_1.Length)
|
|
{
|
|
var option = cityEvent.option_1[tier];
|
|
_btnOption1.gameObject.SetActive(true);
|
|
_tmpOption1.text = cityEvent.matter_1[tier];
|
|
|
|
_btnOption1.onClick.RemoveAllListeners();
|
|
_btnOption1.onClick.AddListener(() =>
|
|
{
|
|
bool success = RandomProxy.Instance.GetRandom(option[0]);
|
|
if (success)
|
|
{
|
|
//success
|
|
int multi = Random.Range(option[1], option[2]);
|
|
for (int i = 0; i < rewards.Count; i++)
|
|
{
|
|
var reward = rewards[i];
|
|
reward.Apply(multi);
|
|
rewards[i] = reward;
|
|
}
|
|
ToastBox.ShowText(25);
|
|
if (tier + 1 < cityEvent.option_1.Length)
|
|
Bet(cityEvent, tier + 1, rewards);
|
|
else
|
|
{
|
|
RewardProxy.Instance.GetRewardsWithUI(rewards, null);
|
|
CloseWindow(this);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(26);
|
|
CloseWindow(this);
|
|
}
|
|
|
|
KStatistics.Instance.ReportEvent_Travel("", cityEvent.type, 1, tier);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_btnOption1.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (tier < cityEvent.option_2.Length)
|
|
{
|
|
var option = cityEvent.option_2[tier];
|
|
_btnOption2.gameObject.SetActive(true);
|
|
_tmpOption2.text = cityEvent.matter_2[tier];
|
|
|
|
_btnOption2.onClick.RemoveAllListeners();
|
|
_btnOption2.onClick.AddListener(() =>
|
|
{
|
|
if (rewards != null && rewards.Count > 0)
|
|
{
|
|
RewardProxy.Instance.GetRewardsWithUI(rewards, null);
|
|
}
|
|
CloseWindow(this);
|
|
KStatistics.Instance.ReportEvent_Travel("", cityEvent.type, 2, tier);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_btnOption2.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 剧情
|
|
/// </summary>
|
|
public void DoStory(StoryAction storyAction)
|
|
{
|
|
if (_storyAction != null || storyAction == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_storyAction = storyAction;
|
|
if (_storyAction != null)
|
|
{
|
|
_goL.SetActive(false);
|
|
_goR.SetActive(false);
|
|
_tmpContent.text = "";
|
|
|
|
if (_storyAction.type == 2)
|
|
{
|
|
var talkers = _storyAction.item.talker;
|
|
for (int i = 0; i < talkers.Length; i++)
|
|
{
|
|
var talker = talkers[i];
|
|
if (talker[0] == 1)
|
|
{
|
|
_goL.SetActive(true);
|
|
var npc = ItemProxy.Instance.GetStaticItem<ItemNpc>(talker[1]);
|
|
if (npc != null)
|
|
{
|
|
_tmpLName.text = npc.name;
|
|
if (!string.IsNullOrEmpty(npc.picture))
|
|
IconProxy.Instance.SetSpriteAsync(_imgL, npc.picture);
|
|
else if (npc.icon != null && npc.icon.Length > 0)
|
|
IconProxy.Instance.SetSprite(_imgL, npc.icon);
|
|
}
|
|
_imgL.color = talker[3] == 1 ? Color.white : Color.black;
|
|
|
|
_storyTweener = _tmpContent.DOText(_storyAction.item.talkings, 2f).OnComplete(() =>
|
|
{
|
|
_storyTweener = null;
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_goR.SetActive(true);
|
|
var npc = ItemProxy.Instance.GetStaticItem<ItemNpc>(talker[1]);
|
|
if (npc != null)
|
|
{
|
|
_tmpRName.text = npc.name;
|
|
if (!string.IsNullOrEmpty(npc.picture))
|
|
IconProxy.Instance.SetSpriteAsync(_imgR, npc.picture);
|
|
else if (npc.icon != null && npc.icon.Length > 0)
|
|
IconProxy.Instance.SetSprite(_imgR, npc.icon);
|
|
}
|
|
_imgR.color = talker[3] == 1 ? Color.white : Color.black;
|
|
|
|
_storyTweener = _tmpContent.DOText(_storyAction.item.talkings, 2f).OnComplete(() =>
|
|
{
|
|
_storyTweener = null;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
else if (_storyAction.type == 5)
|
|
{
|
|
_goL.SetActive(false);
|
|
_goR.SetActive(false);
|
|
_storyTweener = _tmpContent.DOText(_storyAction.item.talkings, 2f).OnComplete(() =>
|
|
{
|
|
_storyTweener = null;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void DoResult()
|
|
{
|
|
if (this.data is CityProxy.CityInfo city)
|
|
{
|
|
var e = city.currCityEvent;
|
|
if (e.type == 1)
|
|
{
|
|
CloseWindow(this);
|
|
}
|
|
else if (e.type == 6)
|
|
{
|
|
CloseWindow(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void UpdateView()
|
|
{
|
|
}
|
|
|
|
private float _lastClickTime;
|
|
private void OnFrameBtnClick()
|
|
{
|
|
if (Time.time - _lastClickTime < 0.2f)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_state == 1)
|
|
{
|
|
_lastClickTime = Time.time;
|
|
if (_storyTweener != null)
|
|
{
|
|
_storyTweener.Kill(true);
|
|
_storyTweener = null;
|
|
return;
|
|
}
|
|
|
|
if (_storyAction != null)
|
|
{
|
|
_storyAction.Complete();
|
|
_storyAction = null;
|
|
}
|
|
}
|
|
else if (_state == 3)
|
|
{
|
|
DoResult();
|
|
_state = 0;
|
|
}
|
|
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|