Files
RedHotRoast-ios/Assets/Scripts/ModuleUI/GameResult/GameResultUI.cs
T
2026-04-22 09:52:55 +08:00

721 lines
28 KiB
C#

using UnityEngine;
using DG.Tweening;
using System;
using FGUI.P01_Common;
using FairyGUI;
using System.Linq;
using Spine.Unity;
using FGUI.P07_GameEnd;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace FlowerPower
{
public class GameResultUI : BaseUI
{
private GameResultUICtrl ctrl;
private GameResultModel model;
private FGUI.P07_GameEnd.com_end ui;
private bool IsWin;
private bool IsLevelSuccess;
private bool IsH5Reward;
// private float AwardGoldNum = 20;
private Action closeCallback;
private int AwardRate = 1;
private SuccessData successData_;
public GameResultUI(GameResultUICtrl ctrl) : base(ctrl)
{
uiName = UIConst.GameResultUI;
this.ctrl = ctrl;
}
protected override void SetUIInfo(UIInfo uiInfo)
{
uiInfo.packageName = "P07_GameEnd";
uiInfo.assetName = "com_end";
uiInfo.layerType = UILayerType.Popup;
uiInfo.isNeedOpenAnim = false;
uiInfo.isNeedCloseAnim = false;
uiInfo.isNeedUIMask = true;
}
#region
protected override void OnInit()
{
//model = ModuleManager.Instance.GetModel(ModelConst.GameResultModel) as GameResultModel;
}
protected override void OnClose()
{
GameHelper.SetCloseResult(false);
closeCallback?.Invoke();
HallManager.Instance.UpdateSecondEvent -= timeEvent;
if (IsLevelSuccess && !GameHelper.is_first_login) UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open, IsWin);
if (IsH5Reward)
{
GameDispatcher.Instance.Dispatch(GameMsg.resetH5progress);
}
}
//
protected override void OnBind()
{
ui = baseUI as FGUI.P07_GameEnd.com_end;
}
protected override void OnOpenBefore(object args)
{
var fx_coin = FXManager.Instance.SetFx<SkeletonAnimation>(ui.btn_gold.GetChild("ani_node") as GGraph, Fx_Type.fx_coin, ref closeCallback);
fx_coin.state.SetAnimation(0, "animation", true);
ui.tips_text.text = GameHelper.getDesByKey("ww_condition_lv");
var data = args as SuccessData;
successData_ = data;
IsH5Reward = data.IsH5Reward;
IsLevelSuccess = data.IsLevelSuccess;
IsWin = data.IsWin;
if (!GameHelper.IsGiftSwitch()) successData_.ch_number = (int)successData_.ch_number;
if (IsLevelSuccess && !IsH5Reward)
{
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Open);
GameHelper.PlayGameTimeEvent(1, () =>
{
GameHelper.RequestGameConfig();
});
}
else
{
GameHelper.SetCloseResult(true);
}
if (Screen.safeArea.y != 0)
{
ui.btn_gold.y += Screen.safeArea.y;
ui.top_money.y += Screen.safeArea.y;
ui.tips.y += Screen.safeArea.y;
}
var makeupData = ConfigSystem.GetConfig<MakeupModel>().dataList;
for (int i = 0; i < makeupData.Count; i++)
{
var vo = makeupData[i];
int lv = GameHelper.GetLevel();
if (IsLevelSuccess)
{
if (lv - 1 == vo.levels_need)
ui.tips.visible = true;
}
else
{
if (lv == vo.levels_need)
{
ui.tips.visible = true;
}
}
}
HallManager.Instance.UpdateSecondEvent += timeEvent;
if (IsWin)
{
if (AudioManager.Instance.IsOpenEffect)
{
AudioManager.Instance.PlayDynamicEffect(AudioConst.Victory05);
}
ui.win_lose.selectedIndex = ui._Win_lose_win;
var fx_win = FXManager.Instance.SetFx<SkeletonAnimation>(ui.ani_win, Fx_Type.fx_win, ref closeCallback);
fx_win.state.SetAnimation(0, "out", false);
fx_win.state.Complete += (a) =>
{
fx_win.state.SetAnimation(0, "daiji", true);
};
AwardRate = data.rate;
ui.btn_mult.state.selectedIndex = 0;
ui.btn_mult.GetChild("title").text = "Claim X" + AwardRate;
}
else
{
ui.win_lose.selectedIndex = 0;
ui.lab_lose_des.text = GameHelper.getDesByKey("game_resulte_1");
var fx_lose = FXManager.Instance.SetFx<SkeletonAnimation>(ui.ani_lose, Fx_Type.fx_lose, ref closeCallback);
fx_lose.state.SetAnimation(0, "out", false);
fx_lose.state.Complete += (a) =>
{
fx_lose.state.SetAnimation(0, "daiji", true);
};
var fx_lock = FXManager.Instance.SetFx<SkeletonAnimation>(ui.ani_lock, Fx_Type.fx_lock, ref closeCallback);
fx_lock.state.SetAnimation(0, "animation", false);
}
if (GameHelper.IsGiftSwitch())
{
ui.switchgift.selectedIndex = 1;
if (SaveData.GetSaveobject().LargeRewardNum < ConfigSystem.GetConfig<CommonModel>().FreeClaims)
{
ui.btn_mult.state.selectedIndex = 1;
}
else if (ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 1)
{
(ui.btn_mult.GetChild("img_saveingpot") as GImage).visible = true;
}
}
else
{
ui.switchgift.selectedIndex = 0;
}
if (IsWin && IsLevelSuccess)
{
showTujian();
}
ui.btn_restart.SetClick(() =>
{
if (!GameHelper.GetCloseResult()) return;
GameHelper.addInterAdnumber();
if (!IsWin) GameHelper.SetLevelstate(3);
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.LevelSuccessUI_Close);
});
ui.top_money.GetChild("number_text").text = GameHelper.Get102Str();
ui.top_money.GetChild("btn_ch").visible = false;
ui.com_ch.btn_ch.title = GameHelper.getDesByKey("ch_out_1");
float ch_number = data.ch_number;
(ui.btn_claim as FGUI.P07_GameEnd.btn_claim3).text_num.SetVar("bet", GameHelper.GetValueWithSymbol((decimal)ch_number)).FlushVars();
InitView();
if (GameHelper.IsGiftSwitch())
{
if (IsWin) ui.text_award.text = GameHelper.Get102Str((decimal)ch_number);
else
{
ui.text_award.text = GameHelper.Get102Str(PreferencesMgr.Instance.Currency102);
ui.top_money.visible = false;
}
ui.btn_mult.SetClick(() =>
{
if (!GameHelper.GetCloseResult()) return;
if (SaveData.GetSaveobject().LargeRewardNum < ConfigSystem.GetConfig<CommonModel>().FreeClaims)
{
ui.com_ch.btn_ch.SetClick(() => { });
ui.btn_claim.SetClick(() => { });
ui.btn_mult.SetClick(() => { });
StartScroll();
}
else
{
GameHelper.ShowVideoAd("reward_lobby", isSuccess =>
{
if (isSuccess)
{
ui.com_ch.btn_ch.SetClick(() => { });
ui.btn_claim.SetClick(() => { });
ui.btn_mult.SetClick(() => { });
StartScroll();
GameDispatcher.Instance.Dispatch(GameMsg.RefreshMakeupData);
}
});
}
});
ui.btn_claim.SetClick(() =>
{
if (!GameHelper.GetCloseResult()) return;
ui.com_ch.btn_ch.SetClick(() => { });
ui.btn_claim.SetClick(() => { });
ui.btn_mult.SetClick(() => { });
DOVirtual.DelayedCall(2f, () =>
{
GameHelper.addInterAdnumber();
});
GetReward(ch_number);
GameDispatcher.Instance.Dispatch(GameMsg.RefreshMakeupData);
});
var name_index = UnityEngine.Random.Range(0, ConfigSystem.GetConfig<exBrPoolModel>().config_name_list.Count);
var money_index = UnityEngine.Random.Range(0, ConfigSystem.GetConfig<exBrPoolModel>().config_money_list.Count);
System.DateTime oldtime = System.DateTime.Now.AddSeconds(-UnityEngine.Random.Range(1 * 3600, 2 * 3600));
// Debug.Log(ConfigSystem.GetConfig<exBrPoolModel>().config_name_list[name_index]);
string broad_text = String.Format(GameHelper.getDesByKey("makeup_5"), ConfigSystem.GetConfig<exBrPoolModel>().config_name_list[name_index],
ConfigSystem.GetConfig<exBrPoolModel>().config_money_list[money_index]);
ui.com_ch.broad.cast_text.text = broad_text;
var makeupTaskData = PreferencesMgr.Instance.MakeupTaskHistory.Last();
var vo = ConfigSystem.GetConfig<MakeupModel>().GetData(makeupTaskData.tableId);
ui.com_ch.btn_ch.SetClick(() =>
{
if (!GameHelper.GetCloseResult()) return;
ui.com_ch.btn_ch.SetClick(() => { });
ui.btn_claim.SetClick(() => { });
ui.btn_mult.SetClick(() => { });
if (IsWin)
{
DOVirtual.DelayedCall(2f, () =>
{
uiCtrlDispatcher.Dispatch(UICtrlMsg.MakeupConfirmUI_Open, makeupTaskData);
GameHelper.addInterAdnumber();
});
GetReward(ch_number);
GameDispatcher.Instance.Dispatch(GameMsg.RefreshMakeupData);
}
else
{
uiCtrlDispatcher.Dispatch(UICtrlMsg.MakeupConfirmUI_Open, makeupTaskData);
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.LevelSuccessUI_Close);
}
});
ui.top_money.GetChild("btn_ch").SetClick(() =>
{
ui.com_ch.btn_ch.FireClick(false, true);
});
if (GameHelper.GetLevel() <= vo.levels_need)
{
string str = string.Format(GameHelper.getDesByKey("makeup_3"), vo.levels_need);
ui.com_ch.ch_text.text = str;
ui.com_ch.progress.width = 602f * (GameHelper.GetLevel() - 1) / vo.levels_need;
ui.com_ch.progress_text.text = (GameHelper.GetLevel() - 1) + "/" + vo.levels_need;
}
else if ((float)PreferencesMgr.Instance.Currency102 < vo.item_need)
{
string str = string.Format(GameHelper.getDesByKey("makeup_2"), vo.item_need);
ui.com_ch.ch_text.text = str;
if ((float)PreferencesMgr.Instance.Currency102 > vo.item_need)
{
ui.com_ch.progress.width = 602;
ui.com_ch.progress_text.text = GameHelper.Get101Str(vo.item_need) + "/" + GameHelper.Get101Str(vo.item_need);
}
else
{
ui.com_ch.progress.width = 602 * ((float)PreferencesMgr.Instance.Currency102 / vo.item_need);
ui.com_ch.progress_text.text = GameHelper.Get102Str(PreferencesMgr.Instance.Currency102) + "/" + GameHelper.Get102Str(vo.item_need);
}
// Debug.Log((float)PreferencesMgr.Instance.Currency102);
}
// else if ((float)PreferencesMgr.Instance.MakeupTaskH5Time < vo.task_need)
// {
// ui.com_ch.ch_text.text = "Cumulataive " + (vo.task_need / 60) + @" minutes in ""Hall"" to cash out";
// if ((float)PreferencesMgr.Instance.MakeupTaskH5Time > vo.task_need)
// {
// ui.com_ch.progress.width = 602;
// ui.com_ch.progress_text.text = (vo.task_need / 60) + "/" + (vo.task_need / 60);
// }
// else
// {
// ui.com_ch.progress.width = 602 * ((float)PreferencesMgr.Instance.MakeupTaskH5Time / vo.task_need);
// ui.com_ch.progress_text.text = Math.Round(((float)(PreferencesMgr.Instance.MakeupTaskH5Time / 60)), 2) + "/" + (vo.task_need / 60);
// }
//
// }
else if (makeupTaskData.videoCount < vo.ad_need)
{
string str = string.Format(GameHelper.getDesByKey("makeup_1"), vo.ad_need);
ui.com_ch.ch_text.text = str;
if (makeupTaskData.videoCount > vo.ad_need)
{
ui.com_ch.progress.width = 602;
ui.com_ch.progress_text.text = vo.ad_need + "/" + vo.ad_need;
}
else
{
ui.com_ch.progress.width = 602 * ((float)makeupTaskData.videoCount / vo.ad_need);
ui.com_ch.progress_text.text = makeupTaskData.videoCount + "/" + vo.ad_need;
}
}
else
{
string str = string.Format(GameHelper.getDesByKey("makeup_1"), vo.ad_need);
ui.com_ch.ch_text.text = str;
if (makeupTaskData.videoCount > vo.ad_need)
{
ui.com_ch.progress.width = 602;
ui.com_ch.progress_text.text = vo.ad_need + "/" + vo.ad_need;
}
else
{
ui.com_ch.progress.width = 602 * ((float)makeupTaskData.videoCount / vo.ad_need);
ui.com_ch.progress_text.text = makeupTaskData.videoCount + "/" + vo.ad_need;
}
}
}
else
{
ui.text_award.text = ((int)ch_number).ToString();
ui.btn_gold.GetChild("text_gold").text = $"{PreferencesMgr.Instance.Currency101:N0}";
ui.btn_mult.SetClick(() =>
{
if (!GameHelper.GetCloseResult()) return;
GameHelper.ShowVideoAd("reward_lobby", isSuccess =>
{
if (isSuccess)
{
ui.btn_claim.SetClick(() => { });
ui.btn_mult.SetClick(() => { });
// GetReward(AwardGoldNum * AwardRate, 101);
StartScroll();
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
}
});
});
ui.btn_claim.SetClick(() =>
{
if (!GameHelper.GetCloseResult()) return;
ui.btn_claim.SetClick(() => { });
ui.btn_mult.SetClick(() => { });
GetReward(successData_.ch_number, 101);
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
});
}
}
private void GetReward(float awardNum, int id = 102)
{
GObject startObj = id == 102 ? ui.btn_mult : ui.node_start;
var endObj = id == 102 ? ui.top_money : ui.btn_gold;
var pos = GameHelper.GetUICenterPosition(endObj);
var rewardData = new RewardData();
var rewardSingleData = new RewardSingleData(id, (decimal)awardNum, RewardOrigin.Play)
{
startPosition = GameHelper.GetUICenterPosition(startObj),
endPosition = new Vector2(pos.x - 150, pos.y - 136)
};
rewardData.AddReward(rewardSingleData);
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.ValueChange;
rewardData.AddCompleted(success =>
{
if (success)
{
RefreshAwardNum((decimal)awardNum, id);
DOVirtual.DelayedCall(1.5f, () =>
{
CtrlCloseUI();
});
}
});
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
}
private void RefreshAwardNum(decimal num = -1, int id = 102)
{
if (num < 0)
{
num = id == 102 ? PreferencesMgr.Instance.Currency102 : PreferencesMgr.Instance.Currency101;
}
var btnCoin = ui.btn_gold as com_gold;
var money = ui.top_money as com_money;
GTextField gTextField = id == 102 ? money.number_text : btnCoin.text_gold;
CommonHelper.ShowNumAnim(gTextField, num, id);
}
private int time_count = 0;
void timeEvent()
{
time_count++;
if (time_count > 3)
{
time_count = 0;
ui.com_ch.broad.t0.Play(() =>
{
var name_index = UnityEngine.Random.Range(0, ConfigSystem.GetConfig<exBrPoolModel>().config_name_list.Count);
var money_index = UnityEngine.Random.Range(0, ConfigSystem.GetConfig<exBrPoolModel>().config_money_list.Count);
// System.DateTime oldtime = System.DateTime.Now.AddSeconds(-UnityEngine.Random.Range(1 * 3600, 2 * 3600));
// ui.com_ch.broad.cast_text.text = string.Format("Congratulations, [color=#e3a13a]{0}[/color] withdraw [color=#83c93c]{1} [/color]dollars ", ConfigSystem.GetConfig<exBrPoolModel>().config_name_list[name_index],
// ConfigSystem.GetConfig<exBrPoolModel>().config_money_list[money_index]);
//, oldtime.Hour + ":" + (oldtime.Minute > 10 ? oldtime.Minute : "0" + oldtime.Minute)
string broad_text = String.Format(GameHelper.getDesByKey("makeup_5"), ConfigSystem.GetConfig<exBrPoolModel>().config_name_list[name_index],
ConfigSystem.GetConfig<exBrPoolModel>().config_money_list[money_index]);
ui.com_ch.broad.cast_text.text = broad_text;
ui.com_ch.broad.t1.Play();
});
}
}
private void showTujian()
{
int level = GameHelper.GetLevel();
GObject node = getAniNode();
Transition ani = getAniName();
if (node == null || ani == null)
{
if (level > 25)
{
ui.gril9.visible = false;
ui.gril16.visible = true;
ui.gril16.state.selectedIndex = 17;
}
return;
}
GComponent panel = null;
if (level > 10)
{
panel = ui.gril16;
ui.gril9.visible = false;
ui.gril16.state.selectedIndex = level - 9 - 2;
}
else
{
panel = ui.gril9;
ui.gril16.visible = false;
ui.gril9.state.selectedIndex = level - 2;
}
int init_zIndex = panel.GetChildIndex(node);
panel.SetChildIndex(node, panel.GetChildrenCount() + 1);
DOVirtual.DelayedCall(0.2f, () =>
{
ani.Play(() =>
{
panel.SetChildIndex(node, init_zIndex);
if (level > 10)
{
com_gril16 gril16 = panel as com_gril16;
gril16.state.selectedIndex = level - 9 - 1;
}
else
{
com_gril9 gril9 = panel as com_gril9;
gril9.state.selectedIndex = level - 1;
}
if (level == 10)
{
DOVirtual.DelayedCall(0.2f, () =>
{
com_gril9 gril9 = panel as com_gril9;
gril9.state.selectedIndex = 10;
});
}
else if (level >= 26)
{
DOVirtual.DelayedCall(0.2f, () =>
{
com_gril16 gril16 = panel as com_gril16;
gril16.state.selectedIndex = 17;
});
}
});
});
}
private Transition getAniName()
{
int level = GameHelper.GetLevel();
List<Transition> arr = null;
if (level <= 10)
{
arr = ui.gril9.Transitions;
return arr[level - 2];
}
else if (level <= 26)
{
arr = ui.gril16.Transitions;
return arr[level - 9 - 2];
}
return null;
}
private GObject getAniNode()
{
int level = GameHelper.GetLevel();
GObject node = null;
if (level <= 10)
{
node = ui.gril9.GetChild("gril_" + (level - 1));
}
else if (level <= 26)
{
node = ui.gril16.GetChild("gril_" + (level - 9 - 1));
}
return node;
}
protected override void OnOpen(object args)
{
}
protected override void OnHide()
{
}
protected override void OnDisplay(object args)
{
}
#endregion
#region
protected override void AddListener()
{
}
protected override void RemoveListener()
{
}
#endregion
//初始化页面逻辑
private void InitView()
{
if (successData_.boost_array != null)
{
(ui.wheel.GetChild("wheel_") as wheel_).t0.Play(Scroll);
(ui.wheel.GetChild("wheel_") as wheel_).t1.Play(() =>
{
rate_idnex++;
ui.btn_mult.title = GameHelper.GetValueWithSymbol((decimal)successData_.ch_number * successData_.boost_array[rate_idnex % 5]);
});
ui.btn_mult.title = GameHelper.GetValueWithSymbol((decimal)successData_.ch_number * successData_.boost_array[rate_idnex]);
list_1 = new List<item_wheel>() { (ui.wheel.GetChild("wheel_") as wheel_).item_0, (ui.wheel.GetChild("wheel_") as wheel_).item_1, (ui.wheel.GetChild("wheel_") as wheel_).item_2, (ui.wheel.GetChild("wheel_") as wheel_).item_3, (ui.wheel.GetChild("wheel_") as wheel_).item_4, (ui.wheel.GetChild("wheel_") as wheel_).item_5, (ui.wheel.GetChild("wheel_") as wheel_).item_6, (ui.wheel.GetChild("wheel_") as wheel_).item_7, };
// list_1[2].img_light.visible = true;
for (int i = 0; i < list_1.Count; i++)
{
list_1[i].type.selectedIndex = (i + scroll_number) % 3;
list_1[i].text_rate.text = "X" + successData_.boost_array[i % successData_.boost_array.Length];
}
}
}
List<item_wheel> list_1;
private int rate_idnex = 3;
private int scroll_number;
List<int> rate_list = new List<int>();
private int scroll_type = 1;
private void StartScroll()
{
(ui.wheel.GetChild("wheel_") as wheel_).t0.timeScale = (ui.wheel.GetChild("wheel_") as wheel_).t0.timeScale = 5.0f;
scroll_type = 2;
}
private void Scroll()
{
if (scroll_type == 1)
{
scroll_number++;
rate_list.Clear();
for (int i = 0; i < 8; i++)
{
rate_list.Add(successData_.boost_array[(scroll_number + i) % successData_.boost_array.Length]);
}
Debug.Log(JsonConvert.SerializeObject(rate_list));
for (int i = 0; i < list_1.Count; i++)
{
list_1[i].type.selectedIndex = (i + scroll_number) % 3;
list_1[i].text_rate.text = "X" + rate_list[i];
}
(ui.wheel.GetChild("wheel_") as wheel_).t1.Play(() =>
{
rate_idnex++;
ui.btn_mult.title = GameHelper.GetValueWithSymbol((decimal)successData_.ch_number * successData_.boost_array[rate_idnex % successData_.boost_array.Length]);
});
(ui.wheel.GetChild("wheel_") as wheel_).t0.Play(Scroll);
}
else
{
scroll_number++;
rate_list.Clear();
for (int i = 0; i < 8; i++)
{
rate_list.Add(successData_.boost_array[(scroll_number + i) % successData_.boost_array.Length]);
}
// bool need_return = false;
Debug.Log("text_rate = " + list_1[4].text_rate.text);
Debug.Log("successData_.rate = " + successData_.rate);
if (((ui.wheel.GetChild("wheel_") as wheel_).t0.timeScale < 2.2f) && (list_1[4].text_rate.text == ("X" + successData_.rate)))
{
//开始领取
float reward = successData_.ch_number * successData_.rate;
if (GameHelper.IsGiftSwitch()) GetReward(reward);
else GetReward(reward, 101);
GameDispatcher.Instance.Dispatch(GameMsg.RefreshMakeupData);
SaveData.GetSaveobject().LargeRewardNum++;
SaveData.saveDataFunc();
return;
}
for (int i = 0; i < list_1.Count; i++)
{
list_1[i].type.selectedIndex = (i + scroll_number) % 3;
list_1[i].text_rate.text = "X" + rate_list[i];
Debug.Log((ui.wheel.GetChild("wheel_") as wheel_).t0.timeScale);
}
// if (need_return)
// {
// (ui.wheel.GetChild("wheel_") as wheel_).t0.timeScale = 0;
// return;
// }
(ui.wheel.GetChild("wheel_") as wheel_).t1.Play(() =>
{
rate_idnex++;
ui.btn_mult.title = GameHelper.GetValueWithSymbol((decimal)successData_.ch_number * successData_.boost_array[rate_idnex % successData_.boost_array.Length]);
});
(ui.wheel.GetChild("wheel_") as wheel_).t0.Play(Scroll);
(ui.wheel.GetChild("wheel_") as wheel_).t0.timeScale = (ui.wheel.GetChild("wheel_") as wheel_).t0.timeScale - 0.3f;
}
}
}
}