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

490 lines
15 KiB
C#
Raw Normal View History

2023-10-19 15:00:19 +08:00
using cfg.CharacterCfg;
2023-08-22 19:08:45 +08:00
using Framework;
using Gameplay.Common;
using Gameplay.Net;
2023-10-19 15:00:19 +08:00
using NLDPB;
2023-08-22 19:08:45 +08:00
using System;
2023-11-30 16:18:57 +08:00
using System.Numerics;
using Gameplay;
2023-08-22 19:08:45 +08:00
using TMPro;
2023-11-30 16:18:57 +08:00
using UnityEngine;
using UnityEngine.EventSystems;
2023-08-22 19:08:45 +08:00
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
2023-11-30 16:18:57 +08:00
using Vector3 = UnityEngine.Vector3;
2024-03-28 18:58:39 +08:00
using Cysharp.Threading.Tasks;
using UnityEngine.UI;
2024-04-28 18:47:34 +08:00
using PhxhSDK;
using LC.Newtonsoft.Json.Bson;
2023-08-22 19:08:45 +08:00
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;
2024-03-28 18:58:39 +08:00
/// Auto Gen End///
2023-08-22 19:08:45 +08:00
2024-03-28 18:58:39 +08:00
/// <summary>
/// 打开角色升级界面
/// </summary>
public static async UniTask<UIWindow> Open(CharacterDataInfo characterDataInfo)
{
CommonUtils.CaptureScreenshot();
2024-05-16 12:40:15 +08:00
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UILevelUp, characterDataInfo);
2024-03-28 18:58:39 +08:00
}
2024-04-28 18:47:34 +08:00
/// <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;
}
}
2024-03-28 18:58:39 +08:00
/// <summary>
/// 高斯模糊遮罩
/// </summary>
private RawImage rawImageGaussianBlurMask;
private int expLast;
2023-08-22 19:08:45 +08:00
CharacterDataInfo mCharacterDataInfo;
private int mCurrentExp;
CharacterLevelExp mCharacterLevelExpCfg;
CharacterBreak mCharacterBreak;
int targetLevel ;
2023-11-30 16:18:57 +08:00
public DragForUI dragForUI;
private AudioInst dialogueAudio;
2024-04-28 18:47:34 +08:00
private Dialogue dialogue;
2024-04-28 17:27:23 +08:00
/// <summary>
/// 是否正在播放台词语音
/// </summary>
public bool IsDialoguePlaying
{
get { return dialogueAudio != null && dialogueAudio.IsPlaying; }
}
2023-08-22 19:08:45 +08:00
// Use this for initialization
2024-01-23 12:25:47 +08:00
public override void OnInit()
2023-08-22 19:08:45 +08:00
{
//bind UI GameObj
UILevelUpBinder.GetComponents(this);
2024-03-28 18:58:39 +08:00
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
rawImageGaussianBlurMask.texture = CommonUtils.screenTexture;
2024-04-28 18:47:34 +08:00
dialogue = new(FindObj("Image_ActorLineBG"));
2024-03-28 18:58:39 +08:00
BindButton(Button_Back, OnButton_BackClick);
2023-08-22 19:08:45 +08:00
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);
2023-11-21 15:18:32 +08:00
BindButton(Button_Home, OnClickHome);
dragForUI = CommonUtils.GetComponent<DragForUI>(this.gameObject,"Drag");
2023-11-30 16:18:57 +08:00
dragForUI.OnDragStarted += ondragStart;
dragForUI.OnDraging += ondrag;
dragForUI.OnDragCompleted += ondragend;
RegisterEvent();
2023-11-30 16:18:57 +08:00
}
UnityEngine.Vector2 startPos;
float interval;//滑动的间隔
float levelCursor;//将等级想象成游标进行滑动
2023-11-30 16:18:57 +08:00
private void ondragend(PointerEventData eventData)
{
}
private void ondrag(PointerEventData eventData)
{
//float offset = eventData.position.y - startPos.y;
float offset = eventData.delta.y;
2023-11-30 16:18:57 +08:00
if (offset < 0)
{
if (targetLevel <= mCharacterDataInfo.Level)
{
return;
}
levelCursor += interval * offset;
targetLevel = (int)levelCursor;
if (targetLevel <= mCharacterDataInfo.Level)
targetLevel = (int)mCharacterDataInfo.Level;
//targetLevel--;
RefreshAfterChangeValue();
2023-11-30 16:18:57 +08:00
RefreshLevelUpBtn();
}
else
{
2023-11-30 16:18:57 +08:00
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();
2023-11-30 16:18:57 +08:00
RefreshLevelUpBtn();
}
}
private void ondragStart(PointerEventData eventData)
{
startPos = eventData.position;
interval = (mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit - mCharacterDataInfo.Level) / 400f;
levelCursor = targetLevel;
2023-11-21 15:18:32 +08:00
}
2023-11-30 16:18:57 +08:00
2023-11-21 15:18:32 +08:00
private void OnClickHome()
{
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel);
}
2023-08-22 19:08:45 +08:00
private void RegisterEvent()
{
2023-10-19 15:00:19 +08:00
EventManager.Instance.Register(EventManager.EventName.EN_CharacterLevelUp,(Action<UpgradeType>)OnCharacterLevelup);
2023-08-22 19:08:45 +08:00
}
2023-10-19 15:00:19 +08:00
2024-04-24 14:31:42 +08:00
private async void OnCharacterLevelup(UpgradeType type)
2023-10-19 15:00:19 +08:00
{
2024-04-28 17:27:23 +08:00
if (type != UpgradeType.UtLevel)
{
return;
}
2023-10-19 15:00:19 +08:00
mCharacterDataInfo = CharacterDataInfoManager.Instance.GetCharacterInfo(mCharacterDataInfo.ID);
2023-08-22 19:08:45 +08:00
targetLevel = (int)mCharacterDataInfo.Level;
RefreshUI();
RefreshAfterChangeValue();
2024-04-24 14:31:42 +08:00
2024-04-28 18:47:34 +08:00
dialogueAudio?.Stop();
dialogueAudio = await DialogueManager.Instance.PlayDiaogue((int)mCharacterDataInfo.Uid,
2024-04-28 17:27:23 +08:00
cfg.DialogueCfg.E_DialogueType.UpLevel,
2024-04-28 18:47:34 +08:00
(content) => { dialogue.SetDialogue(content); });
2023-08-22 19:08:45 +08:00
}
2023-10-19 15:00:19 +08:00
2023-08-22 19:08:45 +08:00
private void UnregisterEvent()
{
2023-10-19 15:00:19 +08:00
EventManager.Instance.Unregister(EventManager.EventName.EN_CharacterLevelUp,(Action<UpgradeType>)OnCharacterLevelup);
2023-08-22 19:08:45 +08:00
}
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;
2023-10-19 15:00:19 +08:00
}
if (targetLevel >= expLast)
{
2023-12-21 15:59:18 +08:00
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_expDontFull"));
2023-10-19 15:00:19 +08:00
return;
}
if (Actor.Instance.Item.GetItemCount(GLConfig.Inst.data.HeroExpItem)< expLast)
2023-12-21 15:59:18 +08:00
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_expDontFull"));
2023-10-19 15:00:19 +08:00
return;
}
2023-08-22 19:08:45 +08:00
NetHelper.CharacterUpgrade(mCharacterDataInfo.ID,NLDPB.UpgradeType.UtLevel,(uint)targetLevel);
}
private void OnButton_CancelClick()
{
if(targetLevel==mCharacterDataInfo.Level)
{
return;
}
targetLevel = (int)mCharacterDataInfo.Level;
RefreshAfterChangeValue();
}
2023-10-19 15:00:19 +08:00
private void OnButton_MAXClick()
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
if (targetLevel > mCharacterDataInfo.Cfg.Hp.Count)
{
DebugUtil.LogError("levelexp表和各种属性没有该突破等级的等级限制等级");
return;
}
2023-08-22 19:08:45 +08:00
if (targetLevel >= mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit)
{
2023-12-21 15:59:18 +08:00
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_LevelUpMAX"));
2023-08-22 19:08:45 +08:00
return;
}
targetLevel = mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit;
RefreshAfterChangeValue();
RefreshLevelUpBtn();
}
private void OnButton_MinusClick()
{
if (targetLevel <= mCharacterDataInfo.Level)
{
2023-12-21 15:59:18 +08:00
CommonUtils.ShowMessageTips("cultivate_LevelUpMIN");
2023-08-22 19:08:45 +08:00
return;
}
targetLevel--;
RefreshAfterChangeValue();
RefreshLevelUpBtn();
}
private void OnButton_PlusClick()
{
if(mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel)==null)
{
2023-10-19 15:00:19 +08:00
DebugUtil.LogError("没有配置Id {0} 突破等级 {1}",mCharacterDataInfo.ID, mCharacterDataInfo.BreakLevel);
2023-08-22 19:08:45 +08:00
return;
}
if(targetLevel>= mCharacterBreak.Get((int)mCharacterDataInfo.ID,(int)mCharacterDataInfo.BreakLevel).LevelLimit)
{
2023-12-21 15:59:18 +08:00
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_LevelUpMAX"));
2023-10-19 15:00:19 +08:00
return;
2023-08-22 19:08:45 +08:00
}
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)
2023-08-22 19:08:45 +08:00
{
2024-06-03 15:57:43 +08:00
base.OnShowWindow(data);
2023-08-22 19:08:45 +08:00
mCharacterDataInfo = data as CharacterDataInfo;
2024-04-28 18:47:34 +08:00
if (mCharacterDataInfo != null)
targetLevel = (int)mCharacterDataInfo.Level;
2023-08-22 19:08:45 +08:00
LoadCfg();
2023-10-19 15:00:19 +08:00
expLast = 0;
2024-04-28 18:47:34 +08:00
dialogue.SetInfo(mCharacterDataInfo.Name);
2023-10-19 15:00:19 +08:00
2024-04-28 18:47:34 +08:00
InputManager.Instance.OnFingersMove += OnFingersHover;
2023-10-19 15:00:19 +08:00
}
private void OnFingersHover(float delta)
{
2023-08-22 19:08:45 +08:00
}
2024-05-08 16:16:50 +08:00
private async void RefreshUI()
2023-08-22 19:08:45 +08:00
{
2024-05-08 17:04:37 +08:00
string imgPath = CommonUtils.GetCharacterPicPath(mCharacterDataInfo.Cfg.RoleID, CommonUtils.ECharacterPicPathType.LevelUp);
var sprite = await LoadAssetAsync<Sprite>(imgPath);
CommonUtils.RefreshCharacter2DPic(Image_Poster, sprite);
2023-08-22 19:08:45 +08:00
RefresLevelUpBar(mCharacterDataInfo.Level);
RefreshLevelUpBtn();
}
2023-10-19 15:00:19 +08:00
private void RefresLevelUpBar(uint targetRefreshLevel)
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
uint nowLevel =targetRefreshLevel;
2023-08-22 19:08:45 +08:00
int maxLevel = (int)mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit;
Text_Level_Now.text = nowLevel.ToString();
Text_Level_Max.text ="/" +maxLevel.ToString();
2023-10-19 15:00:19 +08:00
Text_Level_Value.text = targetRefreshLevel.ToString();
2023-08-22 19:08:45 +08:00
Image_LevelBar.fillAmount = nowLevel / (float)maxLevel;
2023-08-22 19:08:45 +08:00
Text_Hp_Value.text = mCharacterDataInfo.HP().ToString();
2023-08-22 19:08:45 +08:00
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();
2023-10-19 15:00:19 +08:00
Text_Exp_Value.text = Actor.Instance.Item.GetItemCount(GLConfig.Inst.data.HeroExpItem).ToString(); ;
2023-08-22 19:08:45 +08:00
}
private void RefreshAfterChangeValue()
{
float changeHp = mCharacterDataInfo.HpLevelUp((int)targetLevel) - mCharacterDataInfo.HpLevelUp((int)mCharacterDataInfo.Level);
2023-08-22 19:08:45 +08:00
float changeMorale = 0;
float changeDefense = mCharacterDataInfo.DefenceLevelUp((int)targetLevel) - mCharacterDataInfo.DefenceLevelUp((int)mCharacterDataInfo.Level);
2023-08-22 19:08:45 +08:00
float changeArmor = 0;
2023-10-19 15:00:19 +08:00
float changeAttack = mCharacterDataInfo.AttackLevelUp((int)targetLevel) - mCharacterDataInfo.AttackLevelUp((int)mCharacterDataInfo.Level);
float changespeed = 0;
2023-08-22 19:08:45 +08:00
Text_Change_Hp.gameObject.SetActive(changeHp != 0);
Text_Change_Hp.text = "+" + changeHp.ToString();
2023-08-22 19:08:45 +08:00
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)
{
2023-10-19 15:00:19 +08:00
expLast += mCharacterLevelExpCfg.GetOrDefault((i + 1)).EXP;
}
else
{
DebugUtil.LogError("CharacterLevelExpCfg的等级不够了");
}
}
expLast -= (int)mCharacterDataInfo.Exp;
Text_ExpNeed.gameObject.SetActive(expLast > 0);
2023-10-19 15:00:19 +08:00
Text_ExpNeed.text = expLast.ToString();
2023-08-22 19:08:45 +08:00
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;
2023-08-22 19:08:45 +08:00
}
2023-08-22 19:08:45 +08:00
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
}
2024-04-28 17:27:23 +08:00
protected override void OnUpdate()
{
base.OnUpdate();
2024-04-28 18:47:34 +08:00
dialogue.IsScaleShow = IsDialoguePlaying;
2024-04-28 17:27:23 +08:00
}
//invoke when close window
protected override void OnHideWindow()
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
EventManager.Instance.Send(EventManager.EventName.EN_UIControllCultivateMainInput, true);
2024-04-28 17:27:23 +08:00
AudioManager.Instance.AudioMgrObj.StopAllSounds();
2024-06-03 15:57:43 +08:00
base.OnHideWindow();
2023-08-22 19:08:45 +08:00
}
public override void OnRelease()
{
base.OnRelease();
UnregisterEvent();
}
2023-08-22 19:08:45 +08:00
}