NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UICameraAndPosterChangeCont...

1978 lines
55 KiB
C#
Raw Normal View History

using cfg.ActorCfg;
using cfg.CharacterCfg;
using cfg.ShowCfg;
2024-03-18 16:20:35 +08:00
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay;
using Gameplay.SubSystems;
using PhxhSDK;
using System;
using System.Collections.Generic;
using System.Threading;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
public class UICameraAndPosterChangeController : UIWindow
{
# region UI GameObj
///Auto Gen Start///
public Image Image_CBG;
public Button Button_Back;
public TMP_Text Text_Back;
public Button Button_Home;
public Button Button_Scene01;
public Button Button_Scene02;
public Image Image_View01;
public Image Image_View02;
public Image Image_View03;
public TMP_Text Text_ChangeThisScene;
public Button Button_Scene03;
public Button Button_Scene04;
public Button Button_Confirm;
public TMP_Text Text_BtnConfirm;
public Button Button_Cancel;
public Button Button_ChangePoster;
public TMP_Text Text_ChangePoster;
public Button Button_ChangeScene;
public TMP_Text Text_ChangeScene;
public Image Image_Menu;
public Button Button_Rarity;
public TMP_Text Text_Rarity;
public TMP_Text Text_RaritySelect;
public Button Button_Level;
public TMP_Text Text_Lv;
public TMP_Text Text_LvSelect;
public Image Image_Lv;
//public Image Image_Down1;
public Button Button_AdvanceLevel;
public TMP_Text Text_AdvSelect;
public TMP_Text Text_Advance;
//public Image Image_Down2;
public TMP_Dropdown Dropdown_ChangeLevel;
public TMP_Text Text_Profession;
public Button Button_Confirm01;
public TMP_Text Text_Confirm;
public Button Button_Cancel01;
2024-04-22 14:51:37 +08:00
2024-06-04 14:10:39 +08:00
public Button Button_ChangeLocation;
public Button Button_HidePic;
public Button Button_HidePicDown;
2024-06-04 14:10:39 +08:00
///Auto Gen End///
#endregion
private UITextDropdown<int> otherDropDown;
2024-06-04 14:10:39 +08:00
public static async UniTask<UIWindow> Open()
2024-04-22 14:51:37 +08:00
{
2024-09-18 16:03:02 +08:00
CommonUtils.CaptureScreenshot(false);
2024-04-22 14:51:37 +08:00
2024-05-16 12:40:15 +08:00
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UICameraAndPosterChange);
2024-04-22 14:51:37 +08:00
}
/// <summary>
/// 在首页编辑完成看板娘之后重新激活显示此界面
/// </summary>
/// <param name="deltaPos"></param>
/// <param name="scale"></param>
2024-06-04 14:10:39 +08:00
public static void ShowWindowInactived(Vector2 deltaPos, float scale)
{
UIManager.Instance.Show(UINameConst.UICameraAndPosterChange, isMainCameraClose: false);//显示弹窗界面时关闭主相机
2024-06-04 14:10:39 +08:00
EventManager.Instance.Send(EventManager.EventName.MainPanelPosterRelocate, new MainPanelSceneStoreData(0, 0, 0, 0, deltaPos, scale));
}
/// <summary>
/// 背景模糊
/// </summary>
private RawImage rawImageGaussianBlurMask;
2024-04-22 14:51:37 +08:00
//test data
private List<string> _testImgList = new()
{
"Assets/Art/UI/Texture/CameraChange/NewCameraChange/UI_Pic01.png",
"Assets/Art/UI/Texture/CameraChange/NewCameraChange/UI_Pic02.png",
"Assets/Art/UI/Texture/CameraChange/NewCameraChange/UI_Pic03.png",
"Assets/Art/UI/Texture/CameraChange/NewCameraChange/UI_Pic04.png",
};
private enum PageEnum
{
Scene,
Poster
}
private enum SortType
{
None,
Rarity,
Level,
Likely
}
private PageEnum _curPage = PageEnum.Poster;//当前切页
private GameObject _sceneObj;
private GameObject _posterObj;
private SortType _sortType = SortType.None;
private bool _isUpSort = true;
private ScenePanelScrollView SceneScrollView = new();//场景切换页面列表类
private SkinPanelScrollView SkinScrollView = new();//看板娘皮肤切换列表类
private int _curSceneIndex;
private int _curCameraPosIdx;
//立绘切换页面
2024-04-02 19:02:09 +08:00
private RecycleView _scrollPosterPool;
//private PhxhScrollView _scrollSkin;
//private GameObject _skinItemTemp;
///// <summary>
///// 所有角色列表
///// </summary>
//private List<CharacterDataInfo> listAllCharacter = new();
private List<uint> _charIDList;
private List<uint> _displayIDList;
private int _curSelect; //当前选择的角色
private int _curSelectSkin; //当前选择的皮肤
private List<DataCharacterSkin> _skinDataList; //当前选择角色的皮肤列表
private List<string> _skinPathList;//预加载的皮肤图片路径
2024-06-07 15:07:29 +08:00
private bool _isHidePoster = false;//立绘显示开关
2024-06-07 16:00:18 +08:00
private bool inPosterEdit = false;//是否在编辑立绘
2024-06-07 16:00:18 +08:00
private bool PosterHide
{
set
{
_isHidePoster = value;
2024-08-23 13:11:56 +08:00
Image_CBG.gameObject.SetActive(!_isHidePoster);
RefreshPosterHideButton();
2024-06-07 16:00:18 +08:00
}
}
2024-06-07 15:07:29 +08:00
private MainPanelSceneStoreData _saveData;
// deal with input data
public override void PreLoad(object data = null)
{
_charIDList = new List<uint>();
var charList = CharacterDataInfoManager.Instance.DataList;
for (int i = 0; i < charList.Count; i++)
{
_charIDList.Add(charList[i].Uid);
//listAllCharacter.Add(charList[i]);
}
var storeData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
if (storeData != null)
{
_curSelect = GetPosterIndexByID(storeData.PosterID);
_curSelectSkin = storeData.PosterSkinIdx;
}
#region 首个角色半身图片预加载
_skinDataList = CommonUtils.GetCharacterSkinCfgList((int)_charIDList[_curSelect]);
_skinPathList = new();
PreLoadCurCharacterSkin();
#endregion
}
/// <summary>
/// 当_skinDataList变更时预加载所需的图片
/// </summary>
void PreLoadCurCharacterSkin()
{
for (int i = 1; i <= _skinDataList.Count; i++)
{
var posterPic = CommonUtils.GetCharacterPicPath((int)_charIDList[_curSelect], CommonUtils.ECharacterPicPathType.Favorable, i);
if (!_skinPathList.Contains(posterPic))
{
_skinPathList.Add(posterPic);
AssetManager.Instance.PostPreload<Sprite>(posterPic).Forget();
}
}
}
// Use this for initialization
public override void OnInit()
{
2024-08-09 18:05:11 +08:00
CommonUtils.ScreenshotReset();
//bind UI GameObj
UICameraAndPosterChangeBinder.GetComponents(this);
2024-04-22 14:51:37 +08:00
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
_sceneObj = FindObj("ImageBG/SceneChange");
_posterObj = FindObj("ImageBG/PosterChange");
rawImageGaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
2024-04-22 14:51:37 +08:00
SceneScrollView.SetScrollRect(GetComponent<PhxhScrollView>("ImageBG/SceneChange/SceneScrollView"));
SceneScrollView.InitItemCellList(SceneScrollView.SceneItemCount());
2024-04-02 19:02:09 +08:00
_scrollPosterPool = GetComponent<RecycleView>("ImageBG/PosterChange/ChangeHeadPic/PosterScrollView");
SkinScrollView.SetScrollRect(GetComponent<PhxhScrollView>("ImageBG/PosterChange/ChangeSkin/ScrollView"));
BindSceneScrollView();
BindSkinScrollView();
BindButton(Button_Back, _OnClickClose);
BindButton(Button_ChangePoster, _OnClickPosterTab);
Button_ChangePoster.gameObject.SetActive(false);
BindButton(Button_ChangeScene, _OnClickSceneTab);
Button_ChangeScene.gameObject.SetActive(false);
DebugUtil.Log("暂时关闭切换场景功能");
BindButton(Button_Confirm, _OnClickSceneConfirm);
BindButton(Button_Confirm01, _OnClickPosterConfirm);
BindButton(Button_Home, _OnClickHome);
BindButton(Button_Rarity, _OnClickSortBtn, SortType.Rarity);
BindButton(Button_Level, _OnClickSortBtn, SortType.Level);
BindButton(Button_AdvanceLevel, _OnClickAdvanceButton);
2024-06-07 15:07:29 +08:00
BindButton(Button_HidePic, OnClickHideKanbanban);
BindButton(Button_HidePicDown, OnClickHideKanbanban);
2024-06-07 15:07:29 +08:00
BindButton(Button_ChangeLocation, OnClickAdjustPoster);
2024-06-04 14:10:39 +08:00
otherDropDown = new UITextDropdown<int>(FindObj("ImageBG/PosterChange/Image_Menu/Dropdown_ChangeLevel"), FindObj("ImageBG/PosterChange/Image_Menu/Button_AdvanceLevel/Text_Advance"), OtherDropdownValueChanged, OtherDropdownData2Text);
List<int> listDropDownData = new();
foreach (SortType sortType in Enum.GetValues(typeof(SortType)))
{
if (sortType == SortType.None)
continue;
if (sortType == SortType.Rarity)
continue;
if (sortType == SortType.Level)
continue;
listDropDownData.Add((int)sortType);
}
otherDropDown.SetData(listDropDownData);
EventManager.Instance.Register<MainPanelSceneStoreData>(EventManager.EventName.MainPanelPosterRelocate, ResetPosterPosition);
}
//invoke when open window
protected override void OnShowWindow(object data = null)
{
base.OnShowWindow(data);
_InitSceneScroll();
_InitPosterScroll();
2024-10-14 12:17:03 +08:00
_Refresh();
CameraManager.Instance.SetMainCameraActive(false);
}
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
}
//invoke when close window
protected override void OnHideWindow()
{
2024-10-14 12:17:03 +08:00
CameraManager.Instance.SetMainCameraActive(true);
}
//invoke when destroy
public override void OnRelease()
{
base.OnRelease();
SceneScrollView.Release();
SkinScrollView.Release();
EventManager.Instance.Unregister<MainPanelSceneStoreData>(EventManager.EventName.MainPanelPosterRelocate, ResetPosterPosition);
#region 卸载预加载内容
foreach (var path in _skinPathList)
{
AssetManager.Instance.Unload(path);
}
#endregion
2024-06-04 14:10:39 +08:00
}
public override UniTask<bool> OnBack(object data = null)
{
if (inPosterEdit)
{
EventManager.Instance.Send(EventManager.EventName.MainPanelPosterRelocateCancel);
return new UniTask<bool>(true);
}
if (_CheckAndSaveChange())
return new UniTask<bool>(true);
return base.OnBack(data);
}
#region #Event Function
protected override void OnUpdate()
{
base.OnUpdate();
}
#endregion
/// <summary>
/// 刷新界面
/// </summary>
#region RefreshPanel
private void _Refresh()
{
_RefreshTab();
}
private void _RefreshTab()
{
switch (_curPage)
{
case PageEnum.Scene:
2024-06-04 14:10:39 +08:00
{
int index = _curSceneIndex;
//暂时关闭切换功能
//Button_ChangePoster.gameObject.SetActive(false);
//Button_ChangeScene.gameObject.SetActive(true);
//
2024-06-04 14:10:39 +08:00
_sceneObj.SetActive(true);
_posterObj.SetActive(false);
Image_CBG.gameObject.SetActive(false);
Button_ChangeLocation.gameObject.SetActive(false);
Button_HidePic.gameObject.SetActive(false);
Button_HidePicDown.gameObject.SetActive(false);
2024-06-04 14:10:39 +08:00
_SetPosYListData();
SceneScrollView.UpdateData();
//await UniTask.DelayFrame(1);
SceneScrollView.ScrollTo(index);
//LayoutRebuilder.ForceRebuildLayoutImmediate(_sceneScrollContent.GetComponent<RectTransform>());
2024-06-04 14:10:39 +08:00
break;
}
case PageEnum.Poster:
2024-06-04 14:10:39 +08:00
{
int index = _curSelectSkin;
//暂时关闭切换功能
//Button_ChangePoster.gameObject.SetActive(true);
//Button_ChangeScene.gameObject.SetActive(false);
2024-06-04 14:10:39 +08:00
_sceneObj.SetActive(false);
_posterObj.SetActive(true);
2024-08-23 13:11:56 +08:00
Image_CBG.gameObject.SetActive(!_isHidePoster);
2024-06-04 14:10:39 +08:00
_RefreshPosterButton();
SkinScrollView.UpdateData();
//await UniTask.DelayFrame(1);
SkinScrollView.ScrollTo(index);
break;
2024-06-04 14:10:39 +08:00
}
default:
break;
}
}
#region DropDown
private void _DropDown()
{
}
private void OtherDropdownValueChanged(int value)
{
advanceSortType = (SortType)value;
}
private string OtherDropdownData2Text(int value)
{
return GetCharactererSortTypeLocalize((SortType)value);
}
string GetCharactererSortTypeLocalize(SortType type)
{
return type switch
{
SortType.Rarity => CommonUtils.GetLocalizeText("cultivate_Button_Rarity"),
SortType.Level => CommonUtils.GetLocalizeText("cultivate_Button_Level"),
SortType.Likely => CommonUtils.GetLocalizeText("culitivate_likely"),
_ => "",
};
}
#endregion
/// <summary>
/// 更换场景
/// </summary>
#region ScenePage
void BindSceneScrollView()
{
2024-09-04 13:25:48 +08:00
//SceneScrollView.AddValueChangeListener(_OnScrollViewValChange);
SceneScrollView.SetItemCountFunc(SceneScrollView.SceneItemCount);
SceneScrollView.SetItemSizeFunc((index) => SceneScrollView.SceneItemSize(index, _curSceneIndex));//GetItemSizeFromList(index));//
SceneScrollView.SetUpdateFunc(_RefreshSceneItem);
}
private void _RefreshSceneButtons()
{
if (_saveData != null)
{
if (_curSceneIndex == _saveData.SceneIdx && _curCameraPosIdx == _saveData.CameraPosIdx)
{
Button_Confirm.gameObject.SetActive(false);
Button_Cancel.gameObject.SetActive(true);
}
else
{
Button_Confirm.gameObject.SetActive(true);
Button_Cancel.gameObject.SetActive(false);
}
return;
}
var storeData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
if (storeData != null)
{
if (_curSceneIndex == storeData.SceneIdx && _curCameraPosIdx == storeData.CameraPosIdx)
{
Button_Confirm.gameObject.SetActive(false);
Button_Cancel.gameObject.SetActive(true);
}
else
{
Button_Confirm.gameObject.SetActive(true);
Button_Cancel.gameObject.SetActive(false);
}
}
}
private void _RefreshSingleItem(GameObject go, int index)
{
var btnScene = CommonUtils.GetComponent<Button>(go, "ButtonScene");
var btnFull = CommonUtils.GetComponent<Button>(go, "ButtonSceneFull");
2024-03-18 16:20:35 +08:00
List<Button> btnViewList = new List<Button>();
for (int i = 0; i < 3; i++)
{
var btn = CommonUtils.GetComponent<Button>(go, "ButtonSceneFull/ImageView" + i);
btnViewList.Add(btn);
}
if (_curSceneIndex + 1 == index)
{
btnFull.gameObject.SetActive(true);
btnScene.gameObject.SetActive(false);
_RefreshItemView(go);
}
else
{
btnScene.gameObject.SetActive(true);
btnFull.gameObject.SetActive(false);
}
2024-03-18 16:20:35 +08:00
for (int i = 0; i < btnViewList.Count; i++)
{
var imgSelect = CommonUtils.GetGameObject(btnViewList[i].gameObject, "ImageYellow");
var imgGray = CommonUtils.GetGameObject(btnViewList[i].gameObject, "ImageGrey");
imgSelect.SetActive(_curCameraPosIdx == i);
imgGray.SetActive(_curCameraPosIdx != i);
ClearBind(btnViewList[i]);
BindButton(btnViewList[i], _OnClickCameraPos, i);
}
}
private void _RefreshItemView(GameObject go)
{
List<GameObject> goViewList = new List<GameObject>();
for (int i = 0; i < 3; i++)
{
var obj = CommonUtils.GetGameObject(go, "ButtonSceneFull/ImageView" + i);
goViewList.Add(obj);
}
for (int i = 0; i < goViewList.Count; i++)
{
var imgSelect = CommonUtils.GetGameObject(goViewList[i], "ImageYellow");
var imgGray = CommonUtils.GetGameObject(goViewList[i], "ImageGrey");
2024-04-02 14:07:26 +08:00
var imgMaskBg = CommonUtils.GetGameObject(goViewList[i], "ImageBlackCover");
2024-03-18 16:20:35 +08:00
imgSelect.SetActive(_curCameraPosIdx == i);
imgGray.SetActive(_curCameraPosIdx != i);
2024-04-02 14:07:26 +08:00
imgMaskBg.SetActive(_curCameraPosIdx == i);
2024-03-18 16:20:35 +08:00
}
}
private void _OnScrollViewValChange(Vector2 pos)
{
var curIndex = SceneScrollView.GetClosestIdx(_curSceneIndex);
if (curIndex == _curSceneIndex)
{
return;
}
_curSceneIndex = curIndex;
2024-03-18 16:20:35 +08:00
_curCameraPosIdx = 0;
_SetPosYListData();
_RefreshSceneButtons();
SceneScrollView.UpdateData();
}
//#if UNITY_EDITOR
// void SceneItemDebugText(RectTransform item)
// {
// if (CommonUtils.GetGameObject(item.gameObject, "txt") == null)
// {
// GameObject txt = new GameObject("txt");
// txt.transform.SetParent(item);
// txt.transform.localPosition = Vector3.zero;
// txt.transform.localScale = Vector3.one;
// var TXT = txt.AddComponent<TextMeshProUGUI>();
// txt.AddComponent<LayoutElement>().ignoreLayout = true;
// txt.AddComponent<AspectRatioFitter>().aspectMode = AspectRatioFitter.AspectMode.FitInParent;
// TXT.color = Color.red;
// TXT.enableAutoSizing = true;
// }
// }
//#endif
private void _RefreshSceneItem(int index, RectTransform item)
{
if (index == 0 || index == SceneScrollView.SceneItemCount() - 1)
{
if (item.GetComponent<CanvasGroup>() == null)
{
item.gameObject.AddComponent<CanvasGroup>();
}
item.GetComponent<CanvasGroup>().alpha = 0;
return;
}
if(item.GetComponent<CanvasGroup>() != null)
{
item.GetComponent<CanvasGroup>().alpha = 1;
}
var go = item.gameObject;
go.SetActive(true);
_RefreshSingleItem(go, index);
foreach (var cell in SceneScrollView._itemCells)
{
if (cell.index == index)
{
cell.GoRoot = go;
if (SceneScrollView._shownItemList.ContainsKey(go.GetInstanceID()))
{
SceneScrollView._shownItemList[go.GetInstanceID()] = cell;
}
else
{
SceneScrollView._shownItemList.Add(go.GetInstanceID(), cell);
}
break;
}
}
int id = index - 1;
ClearBind(CommonUtils.GetComponent<Button>(go, "ButtonScene"));
BindButton(CommonUtils.GetComponent<Button>(go, "ButtonScene"), () =>
{
_curSceneIndex = id;
_curCameraPosIdx = 0;
_SetPosYListData();
_RefreshSceneButtons();
SceneScrollView.AnimScrollTo(id);
});
}
private void _SetPosYListData()
{
var posY = 0f;
for (int i = 1; i < SceneScrollView.SceneItemCount() - 1; i++)
{
Vector2 size = SceneScrollView.SceneItemSize(i, _curSceneIndex);
posY -= size.y / 2;
SceneScrollView._itemCells[i - 1].localPosY = posY;
posY -= size.y / 2;
}
}
private void _SetSkinPosYListData(bool setSize = true)
{
if (setSize)
{
for (int i = 0; i < _GetSkinItemFunc(); i++)
{
Vector2 size;
if (CategoryManager.Instance.TryGetSkinItemInfo((int)_charIDList[_curSelect], i + 1, out DataItem dataItem))//物品类皮肤
{
if (CategoryManager.Instance.GetItemCount(dataItem.ID) != 0 || i == 0)
{
size = SkinScrollView.SkinItemSize(i, _curSelectSkin);
}
else
{
size = Vector2.zero;
}
}
2024-06-24 13:53:23 +08:00
else
{
if (i != 0)
{
DebugUtil.LogError("这个皮肤并未在Item表内配置并且它不是初始皮肤SkinID" + (i + 1));
}
size = SkinScrollView.SkinItemSize(i, _curSelectSkin);
}
SkinScrollView._itemCells[i].size = size;
}
}
var posY = 0f;
for (int i = 0; i < _GetSkinItemFunc(); i++)
{
Vector2 size = SkinScrollView._itemCells[i].size;
posY -= size.y / 2;
SkinScrollView._itemCells[i].localPosY = posY;
posY -= size.y / 2;
}
}
2024-03-18 16:20:35 +08:00
private async void _InitSceneScroll()
{
2024-03-18 16:20:35 +08:00
var storeData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
_curSceneIndex = storeData.SceneIdx;
_curCameraPosIdx = storeData.CameraPosIdx;
await UniTask.DelayFrame(1);
_RefreshSceneButtons();
}
#endregion
/// <summary>
/// 更换看板娘
/// </summary>
#region PosterPage
private void _InitPosterScroll()
{
_InitSelectCharacter();
_CreatePoolScroll();
_CreateSkinScroll();
_InitPosterImg();
SkinScrollView.InitItemCellList(_GetSkinItemFunc());
_SetSkinPosYListData();
}
void BindSkinScrollView()
{
//SkinScrollView.AddValueChangeListener(_OnSkinScrollViewValChange);
SkinScrollView.SetItemCountFunc(_GetSkinItemFunc);
SkinScrollView.SetItemSizeFunc((index) => SkinScrollView.GetItemSizeFromList(index));//SkinItemSize(index, _curSelectSkin));
SkinScrollView.SetUpdateFunc(_RefreshSkinItem);
}
private async void _InitPosterImg()
{
var posterPath = CommonUtils.GetCharacterPicPath((int)_charIDList[_curSelect],
2024-06-21 18:11:19 +08:00
CommonUtils.ECharacterPicPathType.Poster, _curSelectSkin + 1);
2024-05-07 14:09:50 +08:00
var posterSprite = await LoadAssetAsync<Sprite>(posterPath);
Image_CBG.sprite = posterSprite;
}
private void _RefreshCharList()
{
_charIDList.Clear();
var charaList = CharacterDataInfoManager.Instance.DataList;
for (int i = 0; i < charaList.Count; i++)
{
_charIDList.Add(charaList[i].Uid);
}
switch (_sortType)
{
case SortType.Level:
{
_charIDList.Sort((a, b) =>
{
var dataA = CharacterDataInfoManager.Instance.DataDic[a];
var dataB = CharacterDataInfoManager.Instance.DataDic[b];
if (dataA.Level > dataB.Level)
{
return _isUpSort? 1 : -1;
}
if (dataA.Level < dataB.Level)
{
return _isUpSort? -1 : 1;
}
return 0;
});
break;
}
case SortType.Rarity:
{
_charIDList.Sort((a, b) =>
{
var dataA = CharacterDataInfoManager.Instance.DataDic[a];
var dataB = CharacterDataInfoManager.Instance.DataDic[b];
return _isUpSort ? dataA.Cfg.StartStar.CompareTo(dataB.Cfg.StartStar) :
dataB.Cfg.StartStar.CompareTo(dataA.Cfg.StartStar);
});
break;
}
case SortType.Likely:
{
_charIDList.Sort((a, b) =>
{
var dataA = CharacterDataInfoManager.Instance.DataDic[a];
var dataB = CharacterDataInfoManager.Instance.DataDic[b];
return _isUpSort ? dataA.LikelyLevel.CompareTo(dataB.LikelyLevel) :
dataB.LikelyLevel.CompareTo(dataA.LikelyLevel);
});
break;
}
default:
{
_charIDList.Clear();
var charList = CharacterDataInfoManager.Instance.DataList;
for (int i = 0; i < charList.Count; i++)
{
_charIDList.Add(charList[i].Uid);
}
break;
}
}
}
/// <summary>
/// 点击排序后重刷角色列表,此时将会选中保存的角色
/// </summary>
private async void _RefreshPosterPanel()
{
_RefreshCharList();
MainPanelSceneStoreData data;
if (_saveData != null)
{
data = _saveData;
}
else
{
data = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
}
if (data != null)
{
_ChangeSelectCharacter(GetPosterIndexByID(data.PosterID), data.PosterSkinIdx);
if (CategoryManager.Instance.TryGetSkinItemInfo(data.PosterID, _curSelectSkin + 1, out DataItem dataItem))
{
if (CategoryManager.Instance.GetItemCount(dataItem.ID) == 0)
{
_curSelectSkin = 0;
}
}
2024-06-07 16:00:18 +08:00
PosterHide = data.hideKanbanban;
}
_RefreshImageMenu();
_RefreshPoolScroll();
//_RefreshSkinScroll();
_RefreshPosterButton();
SkinScrollView.UpdateData();
var posterPath = CommonUtils.GetCharacterPicPath((int)_charIDList[_curSelect],
CommonUtils.ECharacterPicPathType.Poster, _curSelectSkin + 1);
var posterSprite = await LoadAssetAsync<Sprite>(posterPath);
Image_CBG.sprite = posterSprite;
}
private void _RefreshImageMenu()
{
Text_RaritySelect.gameObject.SetActive(_sortType == SortType.Rarity);
Text_LvSelect.gameObject.SetActive(_sortType == SortType.Level);
Text_AdvSelect.gameObject.SetActive(_sortType == SortType.Likely);
var imgUpRarity = CommonUtils.GetGameObject(Button_Rarity.gameObject, "ImageDefault/ImageUP");
var imgDownRarity = CommonUtils.GetGameObject(Button_Rarity.gameObject, "ImageDefault/ImageDown");
var imgUpLevel = CommonUtils.GetGameObject(Image_Lv.gameObject, "ImageUP");
var imgDownLevel = CommonUtils.GetGameObject(Image_Lv.gameObject, "ImageDown");
var imgUpLikely = CommonUtils.GetGameObject(Button_AdvanceLevel.gameObject, "ImageDefault/ImageUP");
var imgDownLikely = CommonUtils.GetGameObject(Button_AdvanceLevel.gameObject, "ImageDefault/ImageDown");
imgUpRarity.SetActive(_sortType == SortType.Rarity && _isUpSort);
imgDownRarity.SetActive(_sortType == SortType.Rarity && !_isUpSort);
imgUpLevel.SetActive(_sortType == SortType.Level && _isUpSort);
imgDownLevel.SetActive(_sortType == SortType.Level && !_isUpSort);
imgUpLikely.SetActive(_sortType == SortType.Likely && _isUpSort);
imgDownLikely.SetActive(_sortType == SortType.Likely && !_isUpSort);
}
//右侧角色池列表
private void _CreatePoolScroll()
{
2024-04-02 19:02:09 +08:00
// var content = CommonUtils.GetGameObject(_scrollPosterPool.gameObject, "Viewport/Content");
// if (content)
// {
// CommonUtils.DestoryAllChildGameObject(content);
// }
_scrollPosterPool.Init(_RefreshPoolItem);
_RefreshPoolScroll();
}
private void _RefreshPoolScroll()
{
2024-04-02 19:02:09 +08:00
// _scrollPosterPool.SetUpdateFunc(_RefreshPoolItem);
// _scrollPosterPool.SetItemCountFunc(_GetPoolCountFunc);
// _scrollPosterPool.UpdateData(false);
// _scrollPosterPool.SetButton(_SetPoolItemButton);
_scrollPosterPool.ShowList(_GetPoolCountFunc());
}
2024-04-02 19:02:09 +08:00
private async void _RefreshPoolItem(GameObject go, int index)
{
2024-04-02 19:02:09 +08:00
//var go = item.gameObject;
var uid = _charIDList[index];
var headPicPath = CommonUtils.GetCharacterPicPath((int)uid, CommonUtils.ECharacterPicPathType.HeadPic);//GetDefaultHeadPathByUid(uid);
var imgHead = CommonUtils.GetComponent<Image>(go, "ImageHead");
var btn = CommonUtils.GetComponent<Button>(go, "ImageHead");
var goSelect = CommonUtils.GetGameObject(go, "ImageHead/ImageChooseRect");
2024-05-07 14:09:50 +08:00
imgHead.sprite = await LoadAssetAsync<Sprite>(headPicPath);
goSelect.SetActive(_curSelect == index);
ClearBind(btn);
BindButton(btn, _OnClickPoolHeadItem, index);
go.SetActive(true);
}
private int _GetPoolCountFunc()
{
return _charIDList.Count;
}
//左侧角色皮肤列表
private void _CreateSkinScroll()
{
var content = SkinScrollView._scrollContent;//CommonUtils.GetGameObject(_scrollSkin.gameObject, "Viewport/Content");
if (content)
{
CommonUtils.DestoryAllChildGameObject(content);
}
2024-04-02 19:02:09 +08:00
//_RefreshSkinScroll();
}
//private async void _RefreshSkinScroll()
//{
// // _scrollSkin.SetUpdateFunc(_RefreshSkinItem);
// // _scrollSkin.SetItemCountFunc(_GetSkinItemFunc);
// // _scrollSkin.UpdateData(false);
// // _scrollSkin.SetButton(_SetSkinItemButton);
// var content = CommonUtils.GetGameObject(_scrollSkin.gameObject, "Viewport/Content");
// if (content)
// {
// CommonUtils.DestoryAllChildGameObject(content);
// }
//
// var contentTrans = content.transform;
// int count = _GetSkinItemFunc();
// for (int i = 0; i < count; i++)
// {
// var goItem = Instantiate(_skinItemTemp);
// goItem.transform.SetParent(contentTrans);
// await _RefreshSkinItem(i, goItem);
// //LayoutRebuilder.ForceRebuildLayoutImmediate(goItem.GetComponent<RectTransform>());
// }
// await UniTask.DelayFrame(1);
// LayoutRebuilder.ForceRebuildLayoutImmediate(content.GetComponent<RectTransform>());
//}
private void _RefreshSkinItem(int index, RectTransform item)
{
var go = item.gameObject;
2024-04-02 19:02:09 +08:00
go.SetActive(true);
//if (_curSelectSkin == index)
//{
//TODO 目前半身图使用好感度图片路径
var posterPic =
2024-04-02 19:02:09 +08:00
CommonUtils.GetCharacterPicPath((int)_charIDList[_curSelect], CommonUtils.ECharacterPicPathType.Favorable, index + 1);
var imgSkin = CommonUtils.GetComponent<Image>(go, "ButtonChange/ImageSkin");
var imgSelect = CommonUtils.GetGameObject(go, "ButtonChange/ImageChooseRect");
var imgDoSelect = CommonUtils.GetGameObject(go, "ButtonChange/ImageCover");
var btnChange = CommonUtils.GetComponent<Button>(go, "ButtonChange");
var btnNotSelect = CommonUtils.GetComponent<Button>(go, "ButtonNotSelect");
//DebugUtil.Log("目前半身图暂用使用路径为:" + posterPic + ",请待补充相关资源与更新配置表后在此处更新相关代码");
imgSkin.sprite = AssetManager.Instance.GetPreLoadResult<Sprite>(posterPic);//await LoadAssetAsync<Sprite>(posterPic);
btnChange.gameObject.SetActive(true);
btnNotSelect.gameObject.SetActive(false);
imgSelect.SetActive(_curSelectSkin == index);
imgDoSelect.SetActive(_curSelectSkin != index);
ClearBind(btnChange);
ClearBind(btnNotSelect);
BindButton(btnChange, _OnClickSkinItem, index);
btnChange.GetComponent<RectTransform>().sizeDelta = SkinScrollView.GetItemSizeFromList(index);
//}
//else
//{
// var imgSkin = CommonUtils.GetComponent<Image>(go, "ButtonNotSelect/ImageSkin");
// //var imgSelect = CommonUtils.GetGameObject(go, "ButtonNotSelect/ImageChooseRect");
//
// var posterPic =
// CommonUtils.GetCharacterPicPath((int)_charIDList[_curSelect], CommonUtils.ECharacterPicPathType.Favorable, index + 1);
// var sprite = await LoadAssetAsync<Sprite>(posterPic);
// var rect = imgSkin.GetComponent<RectTransform>().rect;
// //sprtie.rect.Set(sprtie.rect.x, sprtie.rect.y, rect.width, rect.height);
// //sprite = _CropSprite(sprite, new Rect(sprite.rect.x, sprite.rect.y, rect.width, rect.height));
// imgSkin.sprite = sprite;
//
// var btnChange = CommonUtils.GetComponent<Button>(go, "ButtonChange");
// var btnNotSelect = CommonUtils.GetComponent<Button>(go, "ButtonNotSelect");
//
// btnChange.gameObject.SetActive(false);
// btnNotSelect.gameObject.SetActive(true);
// ClearBind(btnNotSelect);
// BindButton(btnNotSelect, _OnClickSkinItem, index);
//}
}
2024-04-11 13:19:47 +08:00
private Sprite _CropSprite(Sprite sprite, Rect rect)
{
Texture2D texture = sprite.texture;
Texture2D croppedTexture = new Texture2D((int)rect.width, (int)rect.height);
Color[] pixels = texture.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
croppedTexture.SetPixels(pixels);
croppedTexture.Apply();
Sprite croppedSprite = Sprite.Create(croppedTexture, new Rect(0, 0, rect.width, rect.height), Vector2.one * 0.5f);
return croppedSprite;
}
private void _OnSkinScrollViewValChange(Vector2 pos)
{
var curIndex = SkinScrollView.GetClosestIdx(_curSelectSkin);
if (curIndex == _curSelectSkin)
{
return;
}
// _curSelectSkin = curIndex;
SkinItemChangeShow(_curSelectSkin, curIndex);
//SkinScrollView.UpdateData();
}
void SkinItemChangeShow(int from, int to, Action callback = null)
{
if (from == to)
{
return;
}
_curSelectSkin = to;
_InitPosterImg();
_RefreshPosterButton();
SkinScrollView.DoTwoItemScale(to, from, SkinScrollView.ItemFullRectTrans.rect.size, SkinScrollView.ItemRectTrans.rect.size, 0.1f,
() =>
{
_SetSkinPosYListData(false);
}, callback);
}
private int _GetSkinItemFunc()
{
return _skinDataList.Count;
}
private void _ChangeSelectCharacter(int index, int SelectSkin = 0)
{
if (_curSelect == index)
{
return;
}
_curSelect = index;
_curSelectSkin = SelectSkin;
_skinDataList = CommonUtils.GetCharacterSkinCfgList((int)_charIDList[_curSelect]);
PreLoadCurCharacterSkin();
SkinScrollView._itemCells.Clear();
SkinScrollView.InitItemCellList(_GetSkinItemFunc());
_SetSkinPosYListData();
}
private void _InitSelectCharacter()
{
if (_saveData == null)
{
var storeData =
StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
if (storeData != null)
{
_curSelect = GetPosterIndexByID(storeData.PosterID);
_curSelectSkin = storeData.PosterSkinIdx;
2024-06-07 16:00:18 +08:00
PosterHide = storeData.hideKanbanban;
2024-06-07 15:07:29 +08:00
}
}
else
{
_curSelect = GetPosterIndexByID(_saveData.PosterID);
_curSelectSkin = _saveData.PosterSkinIdx;
2024-06-07 16:00:18 +08:00
PosterHide = _saveData.hideKanbanban;
}
}
private int GetPosterIndexByID(int id)
{
var idx = _charIDList.IndexOf((uint)id);
if (idx < 0)
{
DebugUtil.LogError($"当前选择Poster Uid: {id}不在列表中!!!");
return 0;
}
return idx;
}
private void _RefreshPosterButton()
{
if (_saveData != null)
{
2024-06-04 14:10:39 +08:00
if (_curSelect == GetPosterIndexByID(_saveData.PosterID) && _curSelectSkin == _saveData.PosterSkinIdx)//当前展示角色
{
Button_Confirm01.gameObject.SetActive(false);
Button_Cancel01.gameObject.SetActive(true);
2024-06-04 14:10:39 +08:00
Button_ChangeLocation.gameObject.SetActive(true);
Button_HidePic.gameObject.SetActive(!_isHidePoster);
Button_HidePicDown.gameObject.SetActive(_isHidePoster);
2024-06-04 14:10:39 +08:00
}
else//非当前展示角色
{
Button_Confirm01.gameObject.SetActive(true);
Button_Cancel01.gameObject.SetActive(false);
2024-06-04 14:10:39 +08:00
Button_ChangeLocation.gameObject.SetActive(false);
Button_HidePic.gameObject.SetActive(false);
Button_HidePicDown.gameObject.SetActive(false);
2024-06-04 14:10:39 +08:00
}
return;
}
var storeData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
if (storeData != null)
{
2024-06-04 14:10:39 +08:00
if (_curSelect == GetPosterIndexByID(storeData.PosterID) && _curSelectSkin == storeData.PosterSkinIdx)//当前展示角色
{
Button_Confirm01.gameObject.SetActive(false);
Button_Cancel01.gameObject.SetActive(true);
2024-06-04 14:10:39 +08:00
Button_ChangeLocation.gameObject.SetActive(true);
Button_HidePic.gameObject.SetActive(!_isHidePoster);
Button_HidePicDown.gameObject.SetActive(_isHidePoster);
2024-06-04 14:10:39 +08:00
}
else//非当前展示角色
{
Button_Confirm01.gameObject.SetActive(true);
Button_Cancel01.gameObject.SetActive(false);
2024-06-04 14:10:39 +08:00
Button_ChangeLocation.gameObject.SetActive(false);
Button_HidePic.gameObject.SetActive(false);
Button_HidePicDown.gameObject.SetActive(false);
2024-06-04 14:10:39 +08:00
}
}
}
2024-06-07 16:00:18 +08:00
private void RefreshPosterHideButton()
{
Button_HidePic.gameObject.SetActive(!_isHidePoster);
Button_HidePicDown.gameObject.SetActive(_isHidePoster);
2024-06-07 16:00:18 +08:00
}
2024-06-04 14:10:39 +08:00
private void ResetPosterPosition(MainPanelSceneStoreData data)
{
if (_saveData != null)
{
_saveData.deltaPos = data.deltaPos;
_saveData.scale = data.scale;
//DebugUtil.Log("调整看板娘位置,saveData不为空在原先数据更改");
}
else
{
_saveData = new MainPanelSceneStoreData(_curSceneIndex, _curCameraPosIdx, (int)_charIDList[_curSelect], _curSelectSkin, data.PositionDelta(), data.scale);
//DebugUtil.Log("调整看板娘位置,saveData为空重新赋值");
}
inPosterEdit = false;
}
#endregion
#endregion
#region class
/// <summary>
/// 场景切换列表类
/// </summary>
class ScenePanelScrollView : IPanelScrollView
{
public override void SetScrollRect(PhxhScrollView scrollRect)
{
2024-09-04 13:25:48 +08:00
canDrag = false;//不可拖动
centerAnchor = false;
Self_aligning = false;
base.SetScrollRect(scrollRect);
SetItemRectTrans(CommonUtils.GetComponent<RectTransform>(_scrollRect.itemTemplate.gameObject, "ButtonScene"),
CommonUtils.GetComponent<RectTransform>(_scrollRect.itemTemplate.gameObject, "ButtonSceneFull"));
2024-09-04 13:25:48 +08:00
SetPaddingSize(new Vector2(590, 100));
}
public void InitItemCellList(int count)
{
_itemCells.Clear();
for (int i = 1; i < count - 1; i++)//由于有上下padding的空item所以需要减去2
{
UIScrollViewItemCell cell = new UIScrollViewItemCell();
cell.index = i;
_itemCells.Add(cell);
}
}
public int SceneItemCount()
{
return TableManager.Instance.Tables.MainSceneConfig.DataList.Count + 2;//+2是上下两个空白item作为padding
}
public Vector2 SceneItemSize(int index, int curIndex)
{
if (index == 0 || index == SceneItemCount() - 1)//两个inactive的item作为padding
{
return ScrollPaddingSize;
}
else
{
if (index != curIndex + 1)
{
return ItemRectTrans.rect.size;
}
else
{
return ItemFullRectTrans.rect.size;
}
}
}
}
class SkinPanelScrollView : IPanelScrollView
{
public override void SetScrollRect(PhxhScrollView scrollRect)
{
centerAnchor = true;
canDrag = false;
Self_aligning = false;
base.SetScrollRect(scrollRect);
SetItemRectTrans(CommonUtils.GetComponent<RectTransform>(_scrollRect.itemTemplate.gameObject, "ButtonNotSelect"),
CommonUtils.GetComponent<RectTransform>(_scrollRect.itemTemplate.gameObject, "ButtonChange"));
}
public Vector2 SkinItemSize(int index, int curIndex)
{
//if(CategoryManager.Instance.TryGetSkinItemInfo(c))
if (index == curIndex)
{
return _itemFullRectTrans.rect.size;
}
else
{
return _itemRectTrans.rect.size;
}
}
/// <summary>
/// 注意操作完请调用_SetSkinPosYListData
/// </summary>
/// <param name="count"></param>
public void InitItemCellList(int count)
{
_itemCells.Clear();
for (int i = 0; i < count; i++)
{
UIScrollViewItemCell cell = new UIScrollViewItemCell();
cell.index = i;
_itemCells.Add(cell);
}
}
/// <summary>
/// 这个函数用于缓动动画动态的设置需要缩放的item的大小
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public Vector2 GetItemSizeFromList(int index)
{
if (index < _itemCells.Count)
{
return _itemCells[index].size;
}
else
{
DebugUtil.LogError("GetItemSizeFromList index out of range");
return default;
}
}
}
#endregion
#region ClickEvent
private void _OnClickClose()
{
2024-08-29 15:50:43 +08:00
if (_CheckAndSaveChange())
return;
CloseWindow();
}
private void _OnClickSceneConfirm()
{
_ConfirmChangeMainScene();
}
private async void _OnClickPoolHeadItem(int index)
{
if (index != _curSelect)
{
_ChangeSelectCharacter(index);
2024-04-02 19:02:09 +08:00
//_scrollPosterPool.UpdateData();
_RefreshPoolScroll();
//_RefreshSkinScroll();
SkinScrollView.UpdateData();
_RefreshPosterButton();
var posterPath = CommonUtils.GetCharacterPicPath((int)_charIDList[_curSelect],
2024-06-21 18:11:19 +08:00
CommonUtils.ECharacterPicPathType.Poster, _curSelectSkin + 1);
2024-05-07 14:09:50 +08:00
var posterSprite = await LoadAssetAsync<Sprite>(posterPath);
Image_CBG.sprite = posterSprite;
}
}
/// <summary>
/// 看板娘调整位置
/// </summary>
2024-06-04 14:10:39 +08:00
private void OnClickAdjustPoster()
{
if (_saveData != null)
{
UIManager.Instance.Hide(UINameConst.UICameraAndPosterChange, isMainCameraActive: true);
2024-06-07 16:00:18 +08:00
_saveData.hideKanbanban = false;
PosterHide = false;
2024-06-04 14:10:39 +08:00
EventManager.Instance.Send(EventManager.EventName.PreviewMainPanelPoster, _saveData);
}
else
{
var sendData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
UIManager.Instance.Hide(UINameConst.UICameraAndPosterChange, isMainCameraActive: true);
2024-06-07 16:00:18 +08:00
sendData.hideKanbanban = false;
PosterHide = false;
2024-06-04 14:10:39 +08:00
EventManager.Instance.Send(EventManager.EventName.PreviewMainPanelPoster, sendData);
}
inPosterEdit = true;
2024-06-07 15:07:29 +08:00
}
private void OnClickHideKanbanban()
{
2024-06-07 16:00:18 +08:00
PosterHide = !_isHidePoster;
2024-06-07 15:07:29 +08:00
if (_saveData == null)
{
var storeData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
_saveData = new MainPanelSceneStoreData(_curSceneIndex, _curCameraPosIdx, (int)_charIDList[_curSelect], _curSelectSkin, storeData.PositionDelta(), storeData.scale);
}
_saveData.hideKanbanban = _isHidePoster;
DebugUtil.Log("poster hide: "+_isHidePoster);
2024-06-04 14:10:39 +08:00
}
private void _OnClickSkinItem(int index)
{
SkinItemChangeShow(_curSelectSkin, index, callback: () => SkinScrollView.AnimScrollTo(index));
//_curSelectSkin = index;
//_RefreshPosterButton();
//_SetSkinPosYListData();
//SkinScrollView.UpdateData();
}
private void _OnClickPosterConfirm()
{
_ConfirmChangePoster();
_RefreshPosterButton();
}
private void _OnClickPosterTab()
{
_curPage = PageEnum.Scene;
_RefreshTab();
}
private void _OnClickSceneTab()
{
_curPage = PageEnum.Poster;
_RefreshTab();
}
private void _OnClickHome()
{
2024-08-29 15:50:43 +08:00
if (_CheckAndSaveChange())
return;
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel);
}
private void _OnClickSortBtn(SortType sortType)
{
if (_sortType == sortType)
{
_isUpSort = !_isUpSort;
}
else
{
2024-08-02 15:57:31 +08:00
//非先前选择方式,默认以降序排列
_isUpSort = false;
_sortType = sortType;
}
_RefreshPosterPanel();
}
SortType advanceSortType = SortType.Likely;
private void _OnClickAdvanceButton()
{
if (_sortType == advanceSortType)
{
_isUpSort = !_isUpSort;
}
else
{
//非先前选择方式,默认以降序排列
_isUpSort = false;
_sortType = advanceSortType;
}
_RefreshPosterPanel();
}
#endregion
private void _ConfirmChangeMainScene()
{
if (_saveData == null)
{
var storeData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
_saveData = new MainPanelSceneStoreData(_curSceneIndex, _curCameraPosIdx, (int)_charIDList[_curSelect], _curSelectSkin, storeData.PositionDelta(), storeData.scale);
}
else
{
_saveData.SceneIdx = _curSceneIndex;
_saveData.CameraPosIdx = _curCameraPosIdx;
}
_RefreshSceneButtons();
}
private void _ConfirmChangePoster()
{
if (_saveData == null)
{
_saveData = new MainPanelSceneStoreData(_curSceneIndex, _curCameraPosIdx, (int)_charIDList[_curSelect], _curSelectSkin);
PosterHide = false;
}
else
{
_saveData.PosterID = (int)_charIDList[_curSelect];
_saveData.PosterSkinIdx = _curSelectSkin;
_saveData.deltaPos = new float[2] { 0, 0 };
_saveData.scale = 0;
2024-06-07 16:00:18 +08:00
_saveData.hideKanbanban = false;
PosterHide = false;
}
_RefreshPosterButton();
}
2024-08-29 15:50:43 +08:00
private bool _CheckAndSaveChange()
{
var oldSaveData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
if (oldSaveData != null && _saveData != null)
{
2024-06-07 16:00:18 +08:00
bool refreshPoster = false;
if (CheckIsPosterChange(_saveData, oldSaveData))//更换看板娘或调整位置
{
oldSaveData.PosterID = _saveData.PosterID;
oldSaveData.PosterSkinIdx = _saveData.PosterSkinIdx;
2024-06-04 14:10:39 +08:00
oldSaveData.deltaPos = _saveData.deltaPos;
oldSaveData.scale = _saveData.scale;
2024-06-07 16:00:18 +08:00
refreshPoster = true;
2024-06-04 14:10:39 +08:00
DebugUtil.Log("保存看板娘调整数据");
}
2024-06-07 16:00:18 +08:00
if (oldSaveData.hideKanbanban != _isHidePoster)//隐藏看板娘
{
oldSaveData.hideKanbanban = _isHidePoster;
2024-06-04 14:10:39 +08:00
2024-06-07 16:00:18 +08:00
refreshPoster = true;
DebugUtil.Log("保存看板娘隐藏数据");
}
if (refreshPoster)
{
ShowManager.Instance.RefreshShow(E_ShowSceneType.Main);
EventManager.Instance.Send(EventManager.EventName.ChangeMainPanelPoster);
}
if (CheckIsSceneChange(_saveData, oldSaveData))
{
oldSaveData.SceneIdx = _saveData.SceneIdx;
oldSaveData.CameraPosIdx = _saveData.CameraPosIdx;
2024-08-28 17:03:50 +08:00
LoadingManager.Instance.ExecuteLoading(new MainSceneReLoadingExecutor()).Forget();
2024-09-03 12:37:52 +08:00
DebugUtil.Log("保存场景调整数据,当前场景: " + _saveData.SceneIdx + "相机机位:" + _saveData.CameraPosIdx);
StorageMgr.Instance.SyncForce = true;
return true;
2024-06-07 16:00:18 +08:00
}
StorageMgr.Instance.SyncForce = true;
}
2024-08-29 15:50:43 +08:00
return false;
}
private bool CheckIsSceneChange(MainPanelSceneStoreData newStoreData, MainPanelSceneStoreData oldStoreData)
{
if (newStoreData.SceneIdx != oldStoreData.SceneIdx)
{
return true;
}
2024-06-11 20:01:38 +08:00
if (newStoreData.CameraPosIdx != oldStoreData.CameraPosIdx)
{
return true;
}
return false;
}
private bool CheckIsPosterChange(MainPanelSceneStoreData newStoreData, MainPanelSceneStoreData oldStoreData)
{
if (newStoreData.PosterID != oldStoreData.PosterID)
{
return true;
}
if (newStoreData.PosterSkinIdx != oldStoreData.PosterSkinIdx)
{
return true;
}
2024-06-04 14:10:39 +08:00
if (newStoreData.deltaPos[0] != oldStoreData.deltaPos[0] || newStoreData.deltaPos[1] != oldStoreData.deltaPos[1])
2024-06-04 14:10:39 +08:00
{
return true;
}
if (newStoreData.scale != oldStoreData.scale)
{
return true;
}
return false;
}
2024-03-18 16:20:35 +08:00
private void _OnClickCameraPos(int index)
{
if (_curCameraPosIdx == index)
{
return;
}
_curCameraPosIdx = index;
_RefreshItemView(SceneScrollView._itemCells[_curSceneIndex].GoRoot);
2024-06-11 20:01:38 +08:00
_RefreshSceneButtons();
2024-03-18 16:20:35 +08:00
}
}
public class MainPanelSceneStoreData
{
public int SceneIdx = 0;
public int CameraPosIdx = 0;
public int PosterID = 0;
public int PosterSkinIdx = 0;
2024-06-04 15:22:09 +08:00
//看板娘自定义数据
public float[] deltaPos = new float[2] { 0, 0 };//位置偏移量
public float scale = 0f;//缩放比例指数底数为2
2024-06-07 15:07:29 +08:00
public bool hideKanbanban = false;//是否隐藏看板娘
2024-06-04 14:10:39 +08:00
public MainPanelSceneStoreData()
{
}
public MainPanelSceneStoreData(int sceneIdx, int cameraPosIdx, int posterID, int posterSkinIdx)
{
SceneIdx = sceneIdx;
CameraPosIdx = cameraPosIdx;
if (posterID <= 0)
{
if (CharacterDataInfoManager.Instance.DataList.Count > 0)
{
PosterID = CharacterDataInfoManager.Instance.DataList[0].Cfg.RoleID;
}
else
{
DebugUtil.LogError("初始角色为空咯!!!请检查数据!!!");
}
}
else
{
PosterID = posterID;
}
PosterSkinIdx = posterSkinIdx;
}
2024-06-04 14:10:39 +08:00
public MainPanelSceneStoreData(int sceneIdx, int cameraPosIdx, int posterID, int posterSkinIdx, Vector2 deltaPos, float scale)
{
SceneIdx = sceneIdx;
CameraPosIdx = cameraPosIdx;
if (posterID <= 0)
{
if (CharacterDataInfoManager.Instance.DataList.Count > 0)
{
PosterID = CharacterDataInfoManager.Instance.DataList[0].Cfg.RoleID;
}
else
{
DebugUtil.LogError("初始角色为空咯!!!请检查数据!!!");
}
}
else
{
PosterID = posterID;
}
PosterSkinIdx = posterSkinIdx;
this.deltaPos = new float[2] { deltaPos.x, deltaPos.y };
this.scale = scale;
}
public Vector2 PositionDelta()
{
return new Vector2(deltaPos[0], deltaPos[1]);
}
}
public class UIScrollViewItemCell
{
public int index;
public float localPosY;
public Vector2 size;
public GameObject GoRoot;
}
/// <summary>
/// 对列表中一项进行放大的同时缩小另一项
/// </summary>
public class ScrollingItemSizeFitter
{
CancellationTokenSource cts;
UIScrollViewItemCell magnifyCell;
UIScrollViewItemCell shrinkCell;
Vector2 magnifySize;
Vector2 shrinkSize;
Action onComplete;
PhxhScrollView DoingScrollview;
public void DOScale(PhxhScrollView scrollView, UIScrollViewItemCell magnify, UIScrollViewItemCell shrink, Vector2 magnifySize, Vector2 shrinkSize, float duration,
Action OnValueChange = null, Action callback = null)
{
if (cts != null)
{
cts.Cancel();
}
cts = new CancellationTokenSource();
DoingScrollview = scrollView;
this.magnifyCell = magnify;
this.shrinkCell = shrink;
this.magnifySize = magnifySize;
this.shrinkSize = shrinkSize;
onComplete = callback;
ScaleAsync(magnify.size, shrink.size, duration, cts.Token, OnValueChange).Forget();
}
async UniTask ScaleAsync(Vector2 startMagnifySize, Vector2 startShrinkSize, float duration, CancellationToken token, Action OnValueChange)
{
float time = 0;
while (time < duration)
{
if (token.IsCancellationRequested)
return;
time += Time.deltaTime;
float t = time / duration;
Vector2 MagSize = Vector2.Lerp(startMagnifySize, magnifySize, t);
magnifyCell.size = MagSize;
Vector2 ShrSize = Vector2.Lerp(startShrinkSize, shrinkSize, t);
shrinkCell.size = ShrSize;
OnValueChange?.Invoke();
if(DoingScrollview != null)
DoingScrollview.UpdateData();
await UniTask.Yield();
}
if (DoingScrollview != null)
DoingScrollview.UpdateData();
DoingScrollview = null;
onComplete?.Invoke();
onComplete = null;
}
public void DoComplete()
{
if(DoingScrollview != null)
{
cts.Cancel();
magnifyCell.size = magnifySize;
shrinkCell.size = shrinkSize;
DoingScrollview.UpdateData();
DoingScrollview = null;
onComplete?.Invoke();
onComplete = null;
}
}
}
2024-06-21 17:14:19 +08:00
public class PosterFader
{
CancellationTokenSource cts = new CancellationTokenSource();
Image img;
float target;
Action completedCallback;
public void DoFade(Image img,float value, float duration, Action OnCompleted = null)
{
if (cts != null)
{
cts.Cancel();
}
cts = new CancellationTokenSource();
this.img = img;
target = Math.Clamp(value, 0f, 1f);
completedCallback = OnCompleted;
FadeImageAlphaAsync(duration, cts.Token).Forget();
}
async UniTask FadeImageAlphaAsync(float duration,CancellationToken cancellationToken)
{
float time = 0;
float startAlpha = img.color.a;
while (time < duration)
{
if (cts.IsCancellationRequested)
{
return;
}
time += Time.deltaTime;
float t = time / duration;
float a = Mathf.Lerp(startAlpha, target, t);
2024-06-21 17:14:19 +08:00
img.color = new Color(img.color.r, img.color.g, img.color.b, a);
await UniTask.Yield();
}
img = null;
completedCallback?.Invoke();
completedCallback = null;
}
public void DoKill()
{
if(cts != null)
{
cts.Cancel();
img = null;
completedCallback = null;
}
}
public void DoComplete()
{
if (img != null)
{
cts.Cancel(true);
img.color = new Color(img.color.r, img.color.g, img.color.b, target);
img = null;
completedCallback?.Invoke();
completedCallback = null;
}
}
}
public class ScrollEaseFitter
{
CancellationTokenSource cts;
PhxhScrollView scrollingRt = null;//用于记录是否正在进行动画
float target;
Action completedCallback;
public void DoScrollTo(PhxhScrollView scrollRect, float startPosY, float targetPosY, float duration, Action OnCompleted = null)
{
if (cts != null)
{
cts.Cancel();
}
cts = new CancellationTokenSource();
target = targetPosY;
completedCallback = OnCompleted;
VerticalScrollToAsync(scrollRect, startPosY, targetPosY, duration, cts.Token).Forget();
}
async UniTask VerticalScrollToAsync(PhxhScrollView scrollRect, float startPosY, float targetPosY, float duration, CancellationToken token)
{
float time = 0;
scrollingRt = scrollRect;
while (time < duration)
{
if (token.IsCancellationRequested)
{
return;
}
time += Time.deltaTime;
float t = time / duration;
float pos = Mathf.Lerp(startPosY, targetPosY, t);
scrollingRt.ScrollToNormalizedPostion(pos, 1);//1 is vertical
await UniTask.Yield();
}
scrollingRt.ScrollToNormalizedPostion(targetPosY, 1);
completedCallback?.Invoke();
scrollingRt = null;
completedCallback = null;
}
public void DoKill()
{
if (cts != null)
{
cts.Cancel();
scrollingRt = null;
completedCallback = null;
}
}
public void DoComplete()
{
if (scrollingRt != null)
{
cts.Cancel();
completedCallback?.Invoke();
scrollingRt.ScrollToNormalizedPostion(target, 1);
scrollingRt = null;
completedCallback = null;
}
}
}
/// <summary>
/// 包含吸附与缩放的滑动列表类
/// </summary>
public class IPanelScrollView
{
public PhxhScrollView _scrollRect;
public GameObject _scrollContent;
protected bool canDrag = true;
protected bool centerAnchor = false;//是否居中对齐
protected bool Self_aligning = true;//自动回正(吸附)
/// <summary>
/// 滚动列表中有obj的item
/// </summary>
public Dictionary<int, UIScrollViewItemCell> _shownItemList = new();
/// <summary>
/// 所有的item
/// </summary>
public List<UIScrollViewItemCell> _itemCells = new List<UIScrollViewItemCell>();
protected ScrollEaseFitter easeFitter = new ScrollEaseFitter();
protected ScrollingItemSizeFitter itemSizeFitter = new ScrollingItemSizeFitter();
protected RectTransform _itemFullRectTrans;
public RectTransform ItemFullRectTrans
{
get => _itemFullRectTrans;
}
protected RectTransform _itemRectTrans;
public RectTransform ItemRectTrans
{
get => _itemRectTrans;
}
protected Vector2 ScrollViewPaddingSize = Vector2.zero;
public Vector2 ScrollPaddingSize
{
get => ScrollViewPaddingSize;
}
protected float _scrollMidPosY;
protected int curSelectIndex;
#region public
/// <summary>
/// 初始化设置滚动列表
/// </summary>
/// <param name="scrollRect"></param>
public virtual void SetScrollRect(PhxhScrollView scrollRect)
{
_scrollRect = scrollRect;
_scrollContent = scrollRect.content.gameObject;
if (!canDrag)
{
_scrollContent.AddComponent<DragForUI>();
}
_scrollMidPosY = -_scrollRect.GetComponent<RectTransform>().rect.height * 0.5f;
DragForUI drag = _scrollRect.GetComponent<DragForUI>();
if (drag == null)
{
drag = _scrollRect.gameObject.AddComponent<DragForUI>();
}
drag.OnDragStarted += OnDragStart;
drag.OnDragCompleted += OnDragEnd;
}
public virtual void Release()
{
_shownItemList.Clear();
_itemCells.Clear();
}
/// <summary>
/// 获取当前viewport内最接近scrollMidPosY(中央)的item的index
/// </summary>
/// <param name="curIndex"></param>
/// <returns></returns>
public int GetClosestIdx(int curIndex)
{
curSelectIndex = curIndex;
int closest = curSelectIndex;
var minDis = _itemRectTrans.rect.height;
var maxDis = _itemFullRectTrans.rect.height;
var contentOffset = _scrollContent.GetComponent<RectTransform>().localPosition.y;
for (int i = 0; i < _itemCells.Count; i++)
{
var posY = _itemCells[i].localPosY - ScrollViewPaddingSize.y;//去除顶部第一个padding的距离
var start = contentOffset + posY + minDis / 2;
var end = start - minDis;
if (curSelectIndex == i)
{
start = contentOffset + posY + maxDis / 2;
end = start - maxDis;
}
if (i == 0)
{
start += maxDis;
}
if (i == _itemCells.Count - 1)
{
end -= maxDis;
}
if (_scrollMidPosY < start && _scrollMidPosY > end)
{
closest = i;
}
}
if (closest < 0 || closest >= _itemCells.Count)
{
DebugUtil.LogError("closest index out of range");
return curIndex;
}
return closest;
}
public void AddValueChangeListener(UnityAction<Vector2> action) => _scrollRect.onValueChanged.AddListener(action);
public void SetItemCountFunc(Func<int> func) => _scrollRect.SetItemCountFunc(func);
public void SetItemSizeFunc(Func<int, Vector2> func) => _scrollRect.SetItemSizeFunc(func);
public void SetUpdateFunc(Action<int, RectTransform> action) => _scrollRect.SetUpdateFunc(action);
public void UpdateData() => _scrollRect.UpdateData();
/// <summary>
/// 动画滚动到指定index
/// </summary>
/// <param name="index"></param>
public void AnimScrollTo(int index, float duration = 0.1f, Action OnComplete = null)
{
curSelectIndex = index;
easeFitter.DoKill();
UpdateData();
float pos = centerAnchor ? _scrollRect.NormalizedPositionByCenter(curSelectIndex) : _scrollRect.NormalizedScrollPosition(curSelectIndex);//
easeFitter.DoScrollTo(_scrollRect, _scrollRect.normalizedPosition.y, pos, duration, OnComplete);
}
/// <summary>
/// 跳转到指定index
/// </summary>
/// <param name="index"></param>
public void ScrollTo(int index)
{
curSelectIndex = index;
float pos = centerAnchor ? _scrollRect.NormalizedPositionByCenter(curSelectIndex) : _scrollRect.NormalizedScrollPosition(curSelectIndex);
_scrollRect.ScrollToNormalizedPostion(pos, 1);
//_scrollRect.ScrollTo(index);
UpdateData();
}
public void DoTwoItemScale(int magnifyIndex, int shrinkIndex, Vector2 magnifySize, Vector2 shrinkSize, float duration, Action OnValueChange, Action OnComplete = null)
{
var magnify = _itemCells[magnifyIndex];
var shrink = _itemCells[shrinkIndex];
itemSizeFitter.DoComplete();
itemSizeFitter.DOScale(_scrollRect, magnify, shrink, magnifySize, shrinkSize, duration, OnValueChange, OnComplete);
}
#endregion
#region protected
protected void SetItemRectTrans(RectTransform itemRectTrans, RectTransform fullRectTrans)
{
_itemRectTrans = itemRectTrans;
_itemFullRectTrans = fullRectTrans;
}
/// <summary>
/// 设置空白item作为padding的大小
/// </summary>
/// <param name="v"></param>
protected void SetPaddingSize(Vector2 v)
{
ScrollViewPaddingSize = v;
}
#endregion
#region private
void OnDragEnd(PointerEventData data)
{
if (Self_aligning)
{
easeFitter.DoKill();
float pos = centerAnchor ? _scrollRect.NormalizedPositionByCenter(curSelectIndex) :_scrollRect.NormalizedScrollPosition(curSelectIndex);//
easeFitter.DoScrollTo(_scrollRect, _scrollRect.normalizedPosition.y, pos, 0.1f);
}
}
void OnDragStart(PointerEventData data)
{
easeFitter.DoKill();
}
#endregion
}