391 lines
13 KiB
C#
391 lines
13 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-04-25
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "VipWindow.View" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
namespace G.UI
|
|||
|
{
|
|||
|
using TMPro;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
partial class VipWindow
|
|||
|
{
|
|||
|
class TitleWidget : KUIWidget
|
|||
|
{
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpName;
|
|||
|
Image _imgGray;
|
|||
|
Image _imgValid;
|
|||
|
KUIImage _main;
|
|||
|
Toggle _toggle;
|
|||
|
|
|||
|
public override void Refresh()
|
|||
|
{
|
|||
|
if (this.data is ItemVip vipItem)
|
|||
|
{
|
|||
|
int index = vipItem.id - 1;
|
|||
|
if (index >= 0 && index < _main.sprites.Length)
|
|||
|
{
|
|||
|
_imgGray.overrideSprite = _main.sprites[index];
|
|||
|
_imgValid.overrideSprite = _main.sprites[index];
|
|||
|
}
|
|||
|
SetValid(vipItem.isValid);
|
|||
|
vipItem.isSelect = false;
|
|||
|
//_tmpName.text = vipItem.name;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void SetValid(bool value)
|
|||
|
{
|
|||
|
_toggle.isOn = value;
|
|||
|
}
|
|||
|
|
|||
|
public void SetSelect(bool value)
|
|||
|
{
|
|||
|
if (value)
|
|||
|
this.transform.localScale = Vector3.one * 1.3f;
|
|||
|
else
|
|||
|
this.transform.localScale = Vector3.one;
|
|||
|
}
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
//SetViewData();
|
|||
|
_toggle = GetComponent<Toggle>();
|
|||
|
_main = GetComponent<KUIImage>();
|
|||
|
_imgGray = Find<Image>("Background");
|
|||
|
_imgValid = Find<Image>("Background/Checkmark");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
class MissionWidget : KUIWidget
|
|||
|
{
|
|||
|
Slider _slider;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpName;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpProgress;
|
|||
|
|
|||
|
public override void Refresh()
|
|||
|
{
|
|||
|
if (this.data is Mission mission)
|
|||
|
{
|
|||
|
_tmpName.text = mission.name;
|
|||
|
_slider.value = mission.progress;
|
|||
|
_tmpProgress.text = $"{mission.curValue}/{mission.maxValue}";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
_slider = GetComponent<Slider>();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
class RightWidget : KUIWidget
|
|||
|
{
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpName;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpTarget;
|
|||
|
|
|||
|
public override void Refresh()
|
|||
|
{
|
|||
|
if (this.data is int[] rights)
|
|||
|
{
|
|||
|
VipProxy.Instance.GetRightsInfo(rights, out var rightName, out var rightValue);
|
|||
|
_tmpName.text = rightName;
|
|||
|
_tmpTarget.text = rightValue;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region Auto Generate
|
|||
|
|
|||
|
[KUIFlag]
|
|||
|
ScrollRect _goTitle;
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listTitles;
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listMissions;
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listRights;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnPrev;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnNext;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpMissionTitle;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpRightTitle;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnBack;
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listRewards;
|
|||
|
[KUIFlag]
|
|||
|
Button __btnReward;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goRewarded;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Field
|
|||
|
|
|||
|
private const float TITLE_INTERVAL = 1F / 11F;
|
|||
|
|
|||
|
private int _showVip = 1;
|
|||
|
private int _titleMax = 12;
|
|||
|
private float _titleInterval = TITLE_INTERVAL;
|
|||
|
|
|||
|
SmartCostWidget _buySmartCostWidget;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void InitView()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
|
|||
|
_goTitle.horizontalScrollbar.numberOfSteps = 12;
|
|||
|
_goTitle.onValueChanged.AddListener(this.OnScrollValueChanged);
|
|||
|
|
|||
|
__listTitles.AddTemplate<TitleWidget>(true);
|
|||
|
__listMissions.AddTemplate<MissionWidget>(true);
|
|||
|
__listRights.AddTemplate<RightWidget>(true);
|
|||
|
__listRewards.AddTemplate<PropWidget>(true);
|
|||
|
|
|||
|
_buySmartCostWidget = __btnReward.gameObject.AddComponent<SmartCostWidget>();
|
|||
|
|
|||
|
__btnReward.onClick.AddListener(this.OnRewardBtnClick);
|
|||
|
_btnPrev.onClick.AddListener(this.OnPrevBtnClick);
|
|||
|
_btnNext.onClick.AddListener(this.OnNextBtnClick);
|
|||
|
_btnBack.onClick.AddListener(this.OnBackBtnClick);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void RefreshView()
|
|||
|
{
|
|||
|
_showVip = VipProxy.Instance.curVip;
|
|||
|
_titleMax = Mathf.Clamp(_showVip + 2, VipProxy.Instance.minVip, VipProxy.Instance.maxVip);
|
|||
|
|
|||
|
_goTitle.horizontalScrollbar.numberOfSteps = _titleMax;
|
|||
|
_titleInterval = 1f / (_titleMax - 1);
|
|||
|
//var vipItems = ItemProxy.Instance.GetStaticItems<ItemVip>();
|
|||
|
__listTitles.Clear();
|
|||
|
for (int i = 1; i <= _titleMax; i++)
|
|||
|
{
|
|||
|
var vipItem = ItemProxy.Instance.GetStaticItem<ItemVip>(i);
|
|||
|
vipItem.isValid = _showVip >= vipItem.id;
|
|||
|
__listTitles.GetItem().SetData(vipItem);
|
|||
|
}
|
|||
|
|
|||
|
//for (int i = 0; i < vipItems.Count; i++)
|
|||
|
//{
|
|||
|
// var item = vipItems[i];
|
|||
|
// if (item.type == 1 && )
|
|||
|
// {
|
|||
|
// item.isValid = _curVip >= item.id;
|
|||
|
// __listTitles.GetItem().SetData(vipItems[i]);
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
_goTitle.horizontalNormalizedPosition = (_showVip - 1) * _titleInterval; //* TITLE_INTERVAL;
|
|||
|
ShowVip();
|
|||
|
}
|
|||
|
|
|||
|
private void ShowVip()
|
|||
|
{
|
|||
|
__listMissions.Clear();
|
|||
|
__listRights.Clear();
|
|||
|
|
|||
|
var curVipItem = VipProxy.Instance.curVipInfo.item;
|
|||
|
if (curVipItem != null)
|
|||
|
{
|
|||
|
int missionRemain = 0;
|
|||
|
var unlockMissions = VipProxy.GetUnlockMissions(curVipItem);
|
|||
|
if (unlockMissions != null)
|
|||
|
{
|
|||
|
for (int i = 0; i < unlockMissions.Length; i++)
|
|||
|
{
|
|||
|
var mission = MissionProxy.Instance.GetMission(unlockMissions[i]);
|
|||
|
__listMissions.GetItem().SetData(mission);
|
|||
|
missionRemain = Mathf.Max(0, mission.maxValue - mission.curValue);
|
|||
|
}
|
|||
|
|
|||
|
if (KPlatform.Instance.QueryPay())
|
|||
|
{
|
|||
|
var format = KLocalization.GetLocalString(77);
|
|||
|
if (!string.IsNullOrEmpty(format))
|
|||
|
_tmpMissionTitle.text = F.Utils.Text.Format(format, missionRemain.ToString(), (curVipItem.id + 1).ToString());
|
|||
|
else
|
|||
|
_tmpMissionTitle.text = "";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_tmpMissionTitle.text = KLocalization.GetLocalString(79);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var showVipItem = ItemProxy.Instance.GetStaticItem<ItemVip>(_showVip);
|
|||
|
if (showVipItem != null)
|
|||
|
{
|
|||
|
for (int i = 0; i < showVipItem.rights.Length; i++)
|
|||
|
{
|
|||
|
__listRights.GetItem().SetData(showVipItem.rights[i]);
|
|||
|
}
|
|||
|
|
|||
|
_tmpRightTitle.text = $"{showVipItem.name}特权";
|
|||
|
|
|||
|
var tmpT = __listTitles.transform;
|
|||
|
for (int i = 0; i < tmpT.childCount; i++)
|
|||
|
{
|
|||
|
var child = tmpT.GetChild(i);
|
|||
|
child.localScale = (_showVip == i + 1) ? new Vector3(1.3f, 1.3f, 1.3f) : Vector3.one;
|
|||
|
}
|
|||
|
}
|
|||
|
_btnNext.interactable = _showVip < _titleMax;
|
|||
|
_btnPrev.interactable = _showVip > VipProxy.Instance.minVip;
|
|||
|
|
|||
|
ShowVipRewards();
|
|||
|
}
|
|||
|
|
|||
|
void ShowVipRewards()
|
|||
|
{
|
|||
|
int curVipId = VipProxy.Instance.curVip;
|
|||
|
var showVipInfo = VipProxy.Instance.GetVipInfo(_showVip);
|
|||
|
__listRewards.Clear();
|
|||
|
if (_showVip == curVipId && (showVipInfo.freeGiftBoxId <= 0 || !showVipInfo.canBuyFreeGiftBox) && VipProxy.Instance.CheckDailyAdRewards())
|
|||
|
{
|
|||
|
var giftBoxInfo = RmbShopProxy.Instance.GetGiftBoxInfo(showVipInfo.adGiftBoxId);
|
|||
|
|
|||
|
var exchangeProps = giftBoxInfo.exchanges;
|
|||
|
if (exchangeProps != null)
|
|||
|
for (int i = 0; i < exchangeProps.Length; i++)
|
|||
|
{
|
|||
|
__listRewards.GetItem<PropWidget>().SetItem(exchangeProps[i]);
|
|||
|
}
|
|||
|
|
|||
|
__btnReward.gameObject.SetActive(true);
|
|||
|
_goRewarded.SetActive(false);
|
|||
|
_buySmartCostWidget.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var giftBoxInfo = RmbShopProxy.Instance.GetGiftBoxInfo(showVipInfo.freeGiftBoxId);
|
|||
|
var exchangeProps = giftBoxInfo.exchanges;
|
|||
|
if (exchangeProps != null)
|
|||
|
for (int i = 0; i < exchangeProps.Length; i++)
|
|||
|
{
|
|||
|
__listRewards.GetItem<PropWidget>().SetItem(exchangeProps[i]);
|
|||
|
}
|
|||
|
|
|||
|
if (_showVip <= curVipId)
|
|||
|
{
|
|||
|
if (showVipInfo.freeGiftBoxId > 0 && showVipInfo.canBuyFreeGiftBox)
|
|||
|
{
|
|||
|
__btnReward.gameObject.SetActive(true);
|
|||
|
_goRewarded.SetActive(false);
|
|||
|
_buySmartCostWidget.SetFree();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
__btnReward.gameObject.SetActive(false);
|
|||
|
_goRewarded.SetActive(true);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
__btnReward.gameObject.SetActive(false);
|
|||
|
_goRewarded.SetActive(false);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnNextBtnClick()
|
|||
|
{
|
|||
|
if (_showVip < _titleMax)
|
|||
|
{
|
|||
|
_showVip++;
|
|||
|
_goTitle.horizontalNormalizedPosition = (_showVip - 1) * _titleInterval;// * TITLE_INTERVAL;
|
|||
|
ShowVip();
|
|||
|
}
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
private void OnPrevBtnClick()
|
|||
|
{
|
|||
|
if (_showVip > VipProxy.Instance.minVip)
|
|||
|
{
|
|||
|
_showVip--;
|
|||
|
_goTitle.horizontalNormalizedPosition = (_showVip - 1) * _titleInterval;// * TITLE_INTERVAL;
|
|||
|
ShowVip();
|
|||
|
}
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void OnScrollValueChanged(Vector2 vector)
|
|||
|
{
|
|||
|
int index = Mathf.RoundToInt(Mathf.Clamp01(vector.x) * (_titleMax - 1)) + 1;
|
|||
|
//Debug.Log(vector.x + " " + index);
|
|||
|
if (index > 0 && _showVip != index)
|
|||
|
{
|
|||
|
_showVip = index;
|
|||
|
ShowVip();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnBackBtnClick()
|
|||
|
{
|
|||
|
CloseWindow(this);
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
private void OnRewardBtnClick()
|
|||
|
{
|
|||
|
int curVipId = VipProxy.Instance.curVip;
|
|||
|
var showVipInfo = VipProxy.Instance.GetVipInfo(_showVip);
|
|||
|
__listRewards.Clear();
|
|||
|
if (_showVip == curVipId && (showVipInfo.freeGiftBoxId <= 0 || !showVipInfo.canBuyFreeGiftBox) && VipProxy.Instance.CheckDailyAdRewards())
|
|||
|
{
|
|||
|
VipProxy.Instance.GetDailyAdRewards(this.OnRewardCallback);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
VipProxy.Instance.GetFreeRewards(_showVip, this.OnRewardCallback);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void OnRewardCallback(int error, string message)
|
|||
|
{
|
|||
|
if (error == 0)
|
|||
|
ShowVipRewards();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|