NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/ShowAllCharacter/UILevelUpController.cs

490 lines
15 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using cfg.CharacterCfg;
using Framework;
using Gameplay.Common;
using Gameplay.Net;
using NLDPB;
using System;
using System.Numerics;
using Gameplay;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
using Vector3 = UnityEngine.Vector3;
using Cysharp.Threading.Tasks;
using UnityEngine.UI;
using PhxhSDK;
using LC.Newtonsoft.Json.Bson;
public class UILevelUpController : UIWindow
{
//UI GameObj
///Auto Gen Start///
public Image Image_BG;
public Button Button_Back;
public Button Button_Home;
public Image Image_PointBG;
public TMP_Text Text_ExpPoint;
public TMP_Text Text_UniversalExp;
public TMP_Text Text_Exp_Value;
public Image Image_LevelUPBar;
public Image Image_Poster;
public TMP_Text Text_Level_Now;
public TMP_Text Text_Level_Max;
public Image Image_Hp;
public TMP_Text Text_Hp;
public TMP_Text Text_Hp_Value;
public TMP_Text Text_Change_Hp;
public Image Image_Morale;
public TMP_Text Text_Cultivate_Morale;
public TMP_Text Text_Morale_Value;
public TMP_Text Text_Change_Morale;
public Image Image_Defense;
public TMP_Text Text_Cultivate_Defense;
public TMP_Text Text_Defense_Value;
public TMP_Text Text_Change_Defanse;
public Image Image_Armor;
public TMP_Text Text_Cultivate_Armor;
public TMP_Text Text_Armor_Value;
public TMP_Text Text_Change_Armor;
public Image Image_Attack;
public TMP_Text Text_Cultivate_Attack;
public TMP_Text Text_Attack_Value;
public TMP_Text Text_Change_Attack;
public Image Image_Speed;
public TMP_Text Text_Cultivate_Speed;
public TMP_Text Text_Speed_Value;
public TMP_Text Text_Change_Speed;
public TMP_Text Text_ExpBefore;
public TMP_Text Text_EXP;
public TMP_Text Text_Plus;
public TMP_Text Text_ExpNeed;
public TMP_Text Text_Level_Value;
public TMP_Text Text_LV;
public TMP_Text Text_LevelUpTo;
public Button Button_MAX;
public Button Button_Plus;
public Button Button_Minus;
public Image Image_LevelBar;
public Image Image_LevelArrow;
public TMP_Text Text_Level;
public Button Button_Cannot;
public TMP_Text Text_Cannot_Confirm;
public Button Button_Confirm;
public TMP_Text Text_Confirm;
public Button Button_Cancel;
/// Auto Gen End///
/// <summary>
/// 打开角色升级界面
/// </summary>
public static async UniTask<UIWindow> Open(CharacterDataInfo characterDataInfo)
{
CommonUtils.CaptureScreenshot();
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UILevelUp, characterDataInfo);
}
/// <summary>
/// 台词类
/// </summary>
private class Dialogue : UIGameObjectWrapper
{
/// <summary>
/// 角色名
/// </summary>
private TMP_Text textName;
/// <summary>
/// 角色类型
/// </summary>
private TMP_Text textContent;
public Dialogue(GameObject root) : base(root)
{
textName = GetComponent<TMP_Text>("Text_Name");
textContent = GetComponent<TMP_Text>("Text_Describe");
}
public void SetInfo(string name)
{
textName.text = name;
}
public void SetDialogue(string content)
{
textContent.text = content;
}
}
/// <summary>
/// 高斯模糊遮罩
/// </summary>
private RawImage rawImageGaussianBlurMask;
private int expLast;
CharacterDataInfo mCharacterDataInfo;
private int mCurrentExp;
CharacterLevelExp mCharacterLevelExpCfg;
CharacterBreak mCharacterBreak;
int targetLevel ;
public DragForUI dragForUI;
private AudioInst dialogueAudio;
private Dialogue dialogue;
/// <summary>
/// 是否正在播放台词语音
/// </summary>
public bool IsDialoguePlaying
{
get { return dialogueAudio != null && dialogueAudio.IsPlaying; }
}
// Use this for initialization
public override void OnInit()
{
//bind UI GameObj
UILevelUpBinder.GetComponents(this);
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
rawImageGaussianBlurMask.texture = CommonUtils.screenTexture;
dialogue = new(FindObj("Image_ActorLineBG"));
BindButton(Button_Back, OnButton_BackClick);
BindButton(Button_Plus, OnButton_PlusClick);
BindButton(Button_Minus, OnButton_MinusClick);
BindButton(Button_MAX, OnButton_MAXClick);
BindButton(Button_Cancel, OnButton_CancelClick);
BindButton(Button_Confirm, OnButton_ConfirmClick);
BindButton(Button_Home, OnClickHome);
dragForUI = CommonUtils.GetComponent<DragForUI>(this.gameObject,"Drag");
dragForUI.OnDragStarted += ondragStart;
dragForUI.OnDraging += ondrag;
dragForUI.OnDragCompleted += ondragend;
RegisterEvent();
}
UnityEngine.Vector2 startPos;
float interval;//滑动的间隔
float levelCursor;//将等级想象成游标进行滑动
private void ondragend(PointerEventData eventData)
{
}
private void ondrag(PointerEventData eventData)
{
//float offset = eventData.position.y - startPos.y;
float offset = eventData.delta.y;
if (offset < 0)
{
if (targetLevel <= mCharacterDataInfo.Level)
{
return;
}
levelCursor += interval * offset;
targetLevel = (int)levelCursor;
if (targetLevel <= mCharacterDataInfo.Level)
targetLevel = (int)mCharacterDataInfo.Level;
//targetLevel--;
RefreshAfterChangeValue();
RefreshLevelUpBtn();
}
else
{
if (mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel) == null)
{
DebugUtil.LogError("没有配置Id {0} 突破等级 {1}", mCharacterDataInfo.ID, mCharacterDataInfo.BreakLevel);
return;
}
if (targetLevel >= mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit)
{
return;
}
levelCursor += interval * offset;
targetLevel = (int)levelCursor;
if (targetLevel >= mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit)
targetLevel = mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit;
//targetLevel++;
RefreshAfterChangeValue();
RefreshLevelUpBtn();
}
}
private void ondragStart(PointerEventData eventData)
{
startPos = eventData.position;
interval = (mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit - mCharacterDataInfo.Level) / 400f;
levelCursor = targetLevel;
}
private void OnClickHome()
{
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel);
}
private void RegisterEvent()
{
EventManager.Instance.Register(EventManager.EventName.EN_CharacterLevelUp,(Action<UpgradeType>)OnCharacterLevelup);
}
private async void OnCharacterLevelup(UpgradeType type)
{
if (type != UpgradeType.UtLevel)
{
return;
}
mCharacterDataInfo = CharacterDataInfoManager.Instance.GetCharacterInfo(mCharacterDataInfo.ID);
targetLevel = (int)mCharacterDataInfo.Level;
RefreshUI();
RefreshAfterChangeValue();
dialogueAudio?.Stop();
dialogueAudio = await DialogueManager.Instance.PlayDiaogue((int)mCharacterDataInfo.Uid,
cfg.DialogueCfg.E_DialogueType.UpLevel,
(content) => { dialogue.SetDialogue(content); });
}
private void UnregisterEvent()
{
EventManager.Instance.Unregister(EventManager.EventName.EN_CharacterLevelUp,(Action<UpgradeType>)OnCharacterLevelup);
}
private void RefreshLevelUpBtn()
{
Button_Cannot.gameObject.SetActive(targetLevel == mCharacterDataInfo.Level);
Button_Confirm.gameObject.SetActive(targetLevel != mCharacterDataInfo.Level);
Button_Cancel.gameObject.SetActive(targetLevel != mCharacterDataInfo.Level);
}
private void OnButton_ConfirmClick()
{
if(targetLevel==mCharacterDataInfo.Level)
{
return;
}
if (targetLevel >= expLast)
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_expDontFull"));
return;
}
if (Actor.Instance.Item.GetItemCount(GLConfig.Inst.data.HeroExpItem)< expLast)
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_expDontFull"));
return;
}
NetHelper.CharacterUpgrade(mCharacterDataInfo.ID,NLDPB.UpgradeType.UtLevel,(uint)targetLevel);
}
private void OnButton_CancelClick()
{
if(targetLevel==mCharacterDataInfo.Level)
{
return;
}
targetLevel = (int)mCharacterDataInfo.Level;
RefreshAfterChangeValue();
}
private void OnButton_MAXClick()
{
if (targetLevel > mCharacterDataInfo.Cfg.Hp.Count)
{
DebugUtil.LogError("levelexp表和各种属性没有该突破等级的等级限制等级");
return;
}
if (targetLevel >= mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit)
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_LevelUpMAX"));
return;
}
targetLevel = mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit;
RefreshAfterChangeValue();
RefreshLevelUpBtn();
}
private void OnButton_MinusClick()
{
if (targetLevel <= mCharacterDataInfo.Level)
{
CommonUtils.ShowMessageTips("cultivate_LevelUpMIN");
return;
}
targetLevel--;
RefreshAfterChangeValue();
RefreshLevelUpBtn();
}
private void OnButton_PlusClick()
{
if(mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel)==null)
{
DebugUtil.LogError("没有配置Id {0} 突破等级 {1}",mCharacterDataInfo.ID, mCharacterDataInfo.BreakLevel);
return;
}
if(targetLevel>= mCharacterBreak.Get((int)mCharacterDataInfo.ID,(int)mCharacterDataInfo.BreakLevel).LevelLimit)
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_LevelUpMAX"));
return;
}
targetLevel++;
RefreshAfterChangeValue();
RefreshLevelUpBtn();
}
private void OnButton_BackClick()
{
CloseWindow();
}
private void LoadCfg()
{
OnLoadCfg(TableManager.Instance.Tables.CharacterLevelExp);
}
private void OnLoadCfg(CharacterLevelExp characterLevelExp)
{
mCharacterLevelExpCfg=characterLevelExp;
mCharacterBreak = TableManager.Instance.Tables.CharacterBreak;
RefreshUI();
RefreshAfterChangeValue();
}
//invoke when open window
protected override void OnShowWindow(object data = null)
{
base.OnShowWindow(data);
mCharacterDataInfo = data as CharacterDataInfo;
if (mCharacterDataInfo != null)
targetLevel = (int)mCharacterDataInfo.Level;
LoadCfg();
expLast = 0;
dialogue.SetInfo(mCharacterDataInfo.Name);
InputManager.Instance.OnFingersMove += OnFingersHover;
}
private void OnFingersHover(float delta)
{
}
private async void RefreshUI()
{
string imgPath = CommonUtils.GetCharacterPicPath(mCharacterDataInfo.Cfg.RoleID, CommonUtils.ECharacterPicPathType.LevelUp);
var sprite = await LoadAssetAsync<Sprite>(imgPath);
CommonUtils.RefreshCharacter2DPic(Image_Poster, sprite);
RefresLevelUpBar(mCharacterDataInfo.Level);
RefreshLevelUpBtn();
}
private void RefresLevelUpBar(uint targetRefreshLevel)
{
uint nowLevel =targetRefreshLevel;
int maxLevel = (int)mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit;
Text_Level_Now.text = nowLevel.ToString();
Text_Level_Max.text ="/" +maxLevel.ToString();
Text_Level_Value.text = targetRefreshLevel.ToString();
Image_LevelBar.fillAmount = nowLevel / (float)maxLevel;
Text_Hp_Value.text = mCharacterDataInfo.HP().ToString();
Text_Morale_Value.text = mCharacterDataInfo.Cfg.MaxMorale.ToString();
Text_Defense_Value.text = mCharacterDataInfo.Defence().ToString();
Text_Armor_Value.text= mCharacterDataInfo.Armor().ToString();
Text_Attack_Value.text=mCharacterDataInfo.Attack().ToString();
Text_Speed_Value.text=mCharacterDataInfo.MoveSpeed().ToString();
Text_Exp_Value.text = Actor.Instance.Item.GetItemCount(GLConfig.Inst.data.HeroExpItem).ToString(); ;
}
private void RefreshAfterChangeValue()
{
float changeHp = mCharacterDataInfo.HpLevelUp((int)targetLevel) - mCharacterDataInfo.HpLevelUp((int)mCharacterDataInfo.Level);
float changeMorale = 0;
float changeDefense = mCharacterDataInfo.DefenceLevelUp((int)targetLevel) - mCharacterDataInfo.DefenceLevelUp((int)mCharacterDataInfo.Level);
float changeArmor = 0;
float changeAttack = mCharacterDataInfo.AttackLevelUp((int)targetLevel) - mCharacterDataInfo.AttackLevelUp((int)mCharacterDataInfo.Level);
float changespeed = 0;
Text_Change_Hp.gameObject.SetActive(changeHp != 0);
Text_Change_Hp.text = "+" + changeHp.ToString();
Text_Change_Morale.gameObject.SetActive(changeMorale != 0);
Text_Change_Morale.text = "+" + changeMorale.ToString();
Text_Change_Defanse.gameObject.SetActive(changeDefense != 0);
Text_Change_Defanse.text = "+" + changeDefense.ToString();
Text_Change_Armor.gameObject.SetActive(changeArmor != 0);
Text_Change_Armor.text = "+" + changeArmor.ToString();
Text_Change_Attack.gameObject.SetActive(changeAttack != 0);
Text_Change_Attack.text = "+" + changeAttack.ToString();
Text_Change_Speed.gameObject.SetActive(changespeed != 0);
Text_Change_Speed.text = "+" + changespeed.ToString();
expLast = 0;
for (int i = (int)mCharacterDataInfo.Level; i < targetLevel; i++)
{
if (mCharacterLevelExpCfg.GetOrDefault((i + 1)) != null)
{
expLast += mCharacterLevelExpCfg.GetOrDefault((i + 1)).EXP;
}
else
{
DebugUtil.LogError("CharacterLevelExpCfg的等级不够了");
}
}
expLast -= (int)mCharacterDataInfo.Exp;
Text_ExpNeed.gameObject.SetActive(expLast > 0);
Text_ExpNeed.text = expLast.ToString();
Text_Level_Now.text = targetLevel.ToString();
Text_ExpBefore.text = mCharacterDataInfo.Exp.ToString();
Image_LevelBar.fillAmount = targetLevel / (float)mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit;
}
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
}
protected override void OnUpdate()
{
base.OnUpdate();
dialogue.IsScaleShow = IsDialoguePlaying;
}
//invoke when close window
protected override void OnHideWindow()
{
EventManager.Instance.Send(EventManager.EventName.EN_UIControllCultivateMainInput, true);
AudioManager.Instance.AudioMgrObj.StopAllSounds();
base.OnHideWindow();
}
public override void OnRelease()
{
base.OnRelease();
UnregisterEvent();
}
}