shaoxiadiablo/Assets/AGame/Scripts/UI/MainWindow/MainWindow.FunctionWidget.cs
2025-05-18 01:04:31 +08:00

705 lines
26 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-04-12
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "MainWindow" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections.Generic;
using DG.Tweening;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
partial class MainWindow
{
/// <summary>
///
/// </summary>
class FunctionWidget : KUIWidget
{
#region Atuo Generate
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Button _btnSystem;
[KUIFlag]
Image _imgSystem;
[KUIFlag]
TextMeshProUGUI _tmpSystem;
[KUIFlag]
GameObject _goExtends;
[KUIFlag]
Button _btnExtend;
[KUIFlag]
Button _btnSetting;
[KUIFlag]
Button _btnNotice;
[KUIFlag]
Button _btnMail;
[KUIFlag]
Button _btnRanking;
[KUIFlag]
Button _btnMission;
[KUIFlag]
Button _btnSignin;
[KUIFlag]
Button _btnPet;
[KUIFlag]
Image _imgPet;
[KUIFlag]
Button _btnTitle;
[KUIFlag]
Button _btnBeauty;
[KUIFlag]
Button _btnVip;
[KUIFlag]
Button _btnBattlepass;
[KUIFlag]
Button _btnActivity;
[KUIFlag]
Button _btnEndless;
[KUIFlag]
Button _btnWorld;
[KUIFlag]
Transform _beautyRoot;
[KUIFlag]
Button _btnMore;
[KUIFlag]
Button _btnHelp;
[KUIFlag]
Button _btnFudai;
[KUIFlag]
TextMeshProUGUI _tmpFudaiCount;
[KUIFlag]
Button _btnRmbShop;
[KUIFlag]
Button _btnMianGuangGao;
[KUIFlag]
Button _btnFriendRanking;
[KUIFlag]
Button _btnShareGame;
[KUIFlag]
Image _imgShareGameIcon;
[KUIFlag]
TextMeshProUGUI _tmpShareGameName;
[KUIFlag]
Button _btnFirstPay;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
#endregion
#region Method
public override void Refresh()
{
if (this.data is FunctionProxy.Function function)
{
_btnSystem.gameObject.SetActive(true);
IconProxy.Instance.SetSprite(_imgSystem, function.icon);
_tmpSystem.text = function.name;
}
else
{
var functionInfo = FunctionProxy.Instance.GetRewarfdFunction();
if (functionInfo == null)
{
_btnSystem.gameObject.SetActive(false);
}
else
{
_btnSystem.gameObject.SetActive(true);
IconProxy.Instance.SetSprite(_imgSystem, functionInfo.icon);
_tmpSystem.text = functionInfo.name;
}
}
RefreshFudai();
RefreshSystem();
RefreshFirstPay();
}
void RefreshFudai()
{
_tmpFudaiCount.text = "x" + MoneyProxy.Instance.GetMoney(Item.Id.kLuckyBag).ToString();
}
void RefreshShareGame()
{
if (_shareGameInfo != null)
{
_btnShareGame.gameObject.SetActive(true);
_tmpShareGameName.text = _shareGameInfo.gameName;
_shareGameInfo.GetSprite((error, message, data) =>
{
if (error == 0)
_imgShareGameIcon.overrideSprite = data as Sprite;
});
}
else
{
_btnShareGame.gameObject.SetActive(false);
}
}
void RefreshFirstPay()
{
if (FirstPayProxy.Instance.IsOpenBtnFunction() && FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.))
{
_btnFirstPay.gameObject.SetActive(true);
}
else
{
_btnFirstPay.gameObject.SetActive(false);
}
}
/// <summary>
/// button
/// </summary>
private void RefreshSystem()
{
SetSystemUnlock(FunctionProxy.FunctionId.Jingjie, _btnTitle.gameObject);
SetSystemUnlock(FunctionProxy.FunctionId., _btnBattlepass.gameObject);
SetSystemUnlock(FunctionProxy.FunctionId.Vip, _btnVip.gameObject);
SetSystemUnlock(FunctionProxy.FunctionId., _btnMission.gameObject);
SetSystemUnlock(FunctionProxy.FunctionId., _btnFriendRanking.gameObject);
SetSystemUnlock(FunctionProxy.FunctionId., _btnMore.gameObject);
SetSystemUnlock(FunctionProxy.FunctionId., _btnFudai.gameObject);
if (SetSystemUnlock(FunctionProxy.FunctionId., _btnWorld.gameObject))
{
_beautyRoot.GetChild(0).gameObject.SetActive(false);
if (_beautyRoot.childCount > 1)
{
_beautyRoot.GetChild(1).gameObject.SetActive(true);
}
}
else
{
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.);
if (function.showPreview)
{
_btnWorld.gameObject.SetActive(true);
_beautyRoot.GetChild(0).gameObject.SetActive(true);
if (_beautyRoot.childCount > 1)
{
_beautyRoot.GetChild(1).gameObject.SetActive(false);
}
}
}
if (SetSystemUnlock(FunctionProxy.FunctionId., _btnRanking.gameObject))
{
_btnEndless.transform.GetChild(0).gameObject.SetActive(true);
_btnEndless.transform.GetChild(1).gameObject.SetActive(false);
}
else
{
_btnEndless.transform.GetChild(0).gameObject.SetActive(false);
_btnEndless.transform.GetChild(1).gameObject.SetActive(true);
}
SetSystemUnlock(FunctionProxy.FunctionId., _btnSignin.gameObject);
SetSystemUnlock(FunctionProxy.FunctionId., _btnActivity.gameObject);
if (SetSystemUnlock(FunctionProxy.FunctionId.Pet, _btnPet.gameObject))
{
var battlePet = PetProxy.Instance.battlePet;
if (battlePet != null)
IconProxy.Instance.SetSprite(_imgPet, battlePet.icon);
}
else
{
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.Pet);
if (function.showPreview)
{
_btnPet.gameObject.SetActive(true);
}
}
_btnBeauty.gameObject.SetActive(false);
if (!ActivityProxy.Instance.sevenSignActivity.isValid)
{
_btnSignin.gameObject.SetActive(false);
}
if (KPlatform.Instance.QueryPay())
{
_btnRmbShop.gameObject.SetActive(FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.Shop) && FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.));
if (FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.))
{
_btnMianGuangGao.gameObject.SetActive(!RmbShopProxy.Instance.IsRemoveAd());
}
else
{
_btnMianGuangGao.gameObject.SetActive(false);
}
}
else
{
_btnRmbShop.gameObject.SetActive(false);
_btnMianGuangGao.gameObject.SetActive(false);
}
}
private bool SetSystemUnlock(FunctionProxy.FunctionId functionId, GameObject go1)
{
var function = FunctionProxy.Instance.GetFunction(functionId);
var unlock = function.IsUnlock();
//var isNew = function.isNew;
//if (isNew)
//{
// go1.SetActive(unlock);
// var rectT = go1.GetComponent<RectTransform>();
// var pos = rectT.anchoredPosition;
// rectT.anchoredPosition = new Vector2(-454, 639);
// rectT.DOAnchorPos(pos, 2f);
//}
//else
go1.SetActive(unlock);
return unlock;
}
private System.Collections.IEnumerator ShowUnlockWithAnim(GameObject go)
{
yield return null;
}
private void SetSystemUnlock(FunctionProxy.FunctionId functionId, GameObject go1, GameObject go2)
{
var unlock = FunctionProxy.Instance.GetFunctionUnlock(functionId);
go1.SetActive(unlock);
go2.SetActive(unlock);
}
private void OnSystemBtnClick()
{
OpenWindow<FunctionRewardsWindow>();
//if (this.data is FunctionProxy.Function function)
//{
// //ToastBox.ShowText(function.lockTips);
//}
}
private void OnNoticeBtnClick()
{
OpenWindow<NoticeBox>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Notice", "main_w_btn");
}
private void OnMailBtnClick()
{
OpenWindow<MailWindow>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Mail", "main_w_btn");
}
private void OnRankingBtnClick()
{
OpenWindow<RankingWindow>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Ranking", "main_w_btn");
}
private void OnActivityBtnClick()
{
OpenWindow<EnergyActivityBox>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Activity", "main_w_btn");
}
private void OnMissionBtnClick()
{
OpenWindow<MissionWindow>(UI.MissionWindow.DAILY_PANEL);
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Mission", "main_w_btn");
}
private void OnSigninBtnClick()
{
OpenWindow<SigninActivityBox>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Signin", "main_w_btn");
}
private void OnPetBtnClick()
{
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.Pet);
if (function != null && function.IsUnlock())
{
OpenWindow<PetWindow>();
}
else
{
ToastBox.ShowText(function.lockTips);
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Pet", "main_w_btn");
}
private void OnTitleBtnClick()
{
OpenWindow<SwordWindow>();
//var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.Jingjie);
//if (function != null && function.IsUnlock())
//{
//OpenWindow<TitleWindow>();
//}
//else
//{
// MessageBox.ShowMessage(function.name, function.lockTips, onConfirm: () =>
// {
// });
//}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Title", "main_w_btn");
}
private void OnBeautyBtnClick()
{
OpenWindow<BeautyWindow>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Beauty", "main_w_btn");
}
private void OnVipBtnClick()
{
OpenWindow<VipWindow>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Vip", "main_w_btn");
}
private void OnBattlePassBtnClick()
{
OpenWindow<BattlePassWindow>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "BattlePass", "main_w_btn");
}
private void OnEndlessBtnClick()
{
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.);
if (function != null && function.IsUnlock())
{
OpenWindow<EndlessWindow>();
}
else
{
ToastBox.ShowText(function.lockTips);
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Endless", "main_w_btn");
}
private void OnSettingBtnClick()
{
OpenWindow<SettingWindow>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Setting", "main_w_btn");
}
/// <summary>
///
/// </summary>
private void OnWorldBtnClick()
{
var function = FunctionProxy.Instance.GetFunction(FunctionProxy.FunctionId.);
if (!function.IsUnlock() && function.showPreview)
{
_beautyRoot.GetChild(0).GetComponent<Spine.Unity.SkeletonGraphic>().AnimationState.SetAnimation(0, "UI_kunbang_chouqi", false).Complete += OnBeautyAnimComplete; ;
ToastBox.ShowText(function.lockTips);
return;
}
OpenWindow<BusinessWindow>();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
PostNotification(GlobalDefine.EVENT_BUTTON_CLICK, "Home", "main_w_btn");
}
private void OnBeautyAnimComplete(Spine.TrackEntry trackEntry)
{
Debug.Log(trackEntry.ToString());
_beautyRoot.GetChild(0).GetComponent<Spine.Unity.SkeletonGraphic>().AnimationState.SetAnimation(0, "UI_kunbang_idle", false);
}
private void OnExtendBtnClick()
{
_btnExtend.interactable = false;
var fadeImage = _btnExtend.targetGraphic;
var extendsRT = _goExtends.transform.parent as RectTransform;
if (_goExtends.activeSelf)
{
fadeImage.raycastTarget = false;
fadeImage.DOFade(0f, 0.25f);
extendsRT.DOAnchorPosX(-200f, 0.3f, true).OnComplete(() =>
{
_goExtends.SetActive(false);
_btnExtend.transform.GetChild(1).Rotate(Vector3.forward, 180);
_btnExtend.interactable = true;
fadeImage.enabled = false;
}).SetEase(Ease.InOutQuad);
}
else
{
_goExtends.SetActive(true);
fadeImage.enabled = true;
fadeImage.raycastTarget = false;
fadeImage.DOFade(0.618f, 0.25f);
extendsRT.DOAnchorPosX(0, 0.3f, true).OnComplete(() =>
{
_btnExtend.transform.GetChild(1).Rotate(Vector3.forward, 180);
_btnExtend.interactable = true;
fadeImage.raycastTarget = true;
}).SetEase(Ease.InOutQuad);
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
void OnMoreBtnClick()
{
//OpenWindow<WheelWindow>();
if (KPlatform.Instance.IsAbConfig("expt_share", "1"))
OpenWindow<WheelWindow>();
else
OpenWindow<UI.ShareWindow>();
//KPlatform.Instance.OppoLeisureJump();
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
void OnFudaiBtnClick()
{
var cost = new Item.ItemInfo()
{
id = Item.Id.kLuckyBag,
count = 1,
};
if (MoneyProxy.Instance.CheckAndCostMoney(cost))
{
RefreshFudai();
//var boxId = LevelProxy.Instance.GetCurrentLevelBoxId(4);
var boxId = LevelProxy.Instance.GetCurrentChapterBoxId(0);
if (boxId > 0)
{
var dropBox = BoxProxy.Instance.GetBoxInfo(boxId);
if (dropBox != null)
{
var rnd = dropBox.GetRndItem();
var propItem = rnd.propItem;
if (propItem.quality >= Item.Quality.kYellow)
RewardProxy.Instance.GetRewardWithUI(rnd, (error, message) => { });
else
{
RewardProxy.Instance.GetReward(rnd);
ToastBox.ShowProp(propItem.name, rnd.count, propItem.quality, propItem.icon);
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
}
}
}
}
else
{
ToastBox.ShowText(31);
}
}
void OnShareGameBtnClick()
{
if (_shareGameInfo != null)
KPlatform.Instance.JumpToApp(_shareGameInfo.appId, _shareGameInfo.extraData);
}
void OnHelpBtnClick()
{
KPlatform.Instance.OpenCustomerServiceConversation();
}
void OnRmbShopBtnClick()
{
OpenWindow<RmbShopWindow>();
}
void OnMianGuangGaoBtnClick()
{
OpenWindow<RmbShopWindow>("special");
}
void OnFriendRankingBtnClick()
{
OpenWindow<OpenDataWindow>();
}
void OnFirstPayBtnClick()
{
OpenWindow<FirstPayBox>();
}
private KRemoteConfig.ShareGameInfo _shareGameInfo;
private int _shareGameIndex;
private float _lastShareTime;
void UpdateView()
{
if (Time.unscaledTime - _lastShareTime > 10f)
{
_lastShareTime = Time.unscaledTime;
if (KRemoteConfig.Instance && KRemoteConfig.Instance.supportShareGame)
{
var shareGameInfos = KRemoteConfig.Instance.remoteConfig.shareGameInfos;
if (shareGameInfos == null || shareGameInfos.Length == 0)
return;
int count = 0;
do
{
count++;
_shareGameInfo = shareGameInfos[(_shareGameIndex++) % shareGameInfos.Length];
}
while (_shareGameInfo != null && !_shareGameInfo.isValid && count <= shareGameInfos.Length);
RefreshShareGame();
}
}
}
#endregion
#region Unity
/// <summary>
///
/// </summary>
private void Awake()
{
SetViewData();
_btnSystem.onClick.AddListener(this.OnSystemBtnClick);
_btnNotice.onClick.AddListener(this.OnNoticeBtnClick);
_btnMail.onClick.AddListener(this.OnMailBtnClick);
_btnRanking.onClick.AddListener(this.OnRankingBtnClick);//活动
_btnSignin.onClick.AddListener(this.OnSigninBtnClick);
_btnMission.onClick.AddListener(this.OnMissionBtnClick);
_btnPet.onClick.AddListener(this.OnPetBtnClick);
_btnBeauty.onClick.AddListener(this.OnBeautyBtnClick);
_btnTitle.onClick.AddListener(this.OnTitleBtnClick);
_btnActivity.onClick.AddListener(this.OnActivityBtnClick);
_btnVip.onClick.AddListener(this.OnVipBtnClick);
_btnBattlepass.onClick.AddListener(this.OnBattlePassBtnClick);
_btnEndless.onClick.AddListener(this.OnEndlessBtnClick);
_btnExtend.onClick.AddListener(this.OnExtendBtnClick);
_btnSetting.onClick.AddListener(this.OnSettingBtnClick);
_btnWorld.onClick.AddListener(this.OnWorldBtnClick);
_btnFudai.onClick.AddListener(this.OnFudaiBtnClick);
if (true || KPlatform.Instance.IsOppoLeisureChannel())
{
_btnMore.gameObject.SetActive(true);
_btnMore.onClick.AddListener(this.OnMoreBtnClick);
}
else
{
_btnMore.gameObject.SetActive(false);
}
_btnShareGame.onClick.AddListener(this.OnShareGameBtnClick);
_btnHelp.onClick.AddListener(this.OnHelpBtnClick);
_btnRmbShop.onClick.AddListener(this.OnRmbShopBtnClick);
_btnMianGuangGao.onClick.AddListener(this.OnMianGuangGaoBtnClick);
_btnFriendRanking.onClick.AddListener(this.OnFriendRankingBtnClick);
_btnFirstPay.onClick.AddListener(this.OnFirstPayBtnClick);
}
private System.Collections.IEnumerator Start()
{
var beautyInfo = BeautyProxy.Instance.GetBeauty(1);
var skinAsset = beautyInfo.skinItem.asset;
if (!string.IsNullOrEmpty(skinAsset))
{
var handle = AssetProxy.Instance.InstantiateAsync(skinAsset, _beautyRoot);
yield return handle;
var skeleton = handle.Result.GetComponent<Spine.Unity.SkeletonGraphic>();
skeleton.raycastTarget = false;
handle.Result.SetActive(FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.));
}
}
private void OnEnable()
{
RegisterThis();
Refresh();
}
private void OnDisable()
{
UnregisterThis();
}
float _lastUpdateTime;
private void Update()
{
if (Time.time - _lastUpdateTime > 1f)
{
_lastUpdateTime = Time.time;
UpdateView();
}
}
#endregion
#region Mediator
readonly int[] _notificationInterests = new int[]
{
//GlobalDefine.EVENT_MAIN_WINDOW_FUNCTION,
GlobalDefine.EVENT_MONEY_CHANGED,
};
public override IList<int> ListNotificationInterests()
{
return _notificationInterests;
}
public override void HandleNotification(PureMVC.Interfaces.INotification notification)
{
if (notification.Name == GlobalDefine.EVENT_MONEY_CHANGED)
{
RefreshFudai();
}
else
{
if (notification.Type == "open")
{
if ("endless".Equals(notification.Body))
{
OpenWindow<EndlessWindow>();
}
}
}
}
#endregion
}
}
}