1828 lines
50 KiB
C#
1828 lines
50 KiB
C#
using System.Collections.Generic;
|
||
using cfg.CharacterCfg;
|
||
using cfg.ShowCfg;
|
||
using Cysharp.Threading.Tasks;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using Button = UnityEngine.UI.Button;
|
||
using Image = UnityEngine.UI.Image;
|
||
using Framework;
|
||
using Gameplay;
|
||
using Gameplay.SubSystems;
|
||
using PhxhSDK;
|
||
using System.Threading;
|
||
using UnityEngine.EventSystems;
|
||
using UnityEngine.Events;
|
||
using System;
|
||
using cfg.ActorCfg;
|
||
|
||
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;
|
||
|
||
public Button Button_ChangeLocation;
|
||
public Button Button_HidePic;
|
||
public Button Button_HidePicDown;
|
||
|
||
///Auto Gen End///
|
||
#endregion
|
||
|
||
public static async UniTask<UIWindow> Open()
|
||
{
|
||
await CommonUtils.CaptureScreenshot();
|
||
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UICameraAndPosterChange);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 在首页编辑完成看板娘之后重新激活显示此界面
|
||
/// </summary>
|
||
/// <param name="deltaPos"></param>
|
||
/// <param name="scale"></param>
|
||
public static void ShowWindowInactived(Vector2 deltaPos, float scale)
|
||
{
|
||
UIManager.Instance.Show(UINameConst.UICameraAndPosterChange, isMainCameraClose: false);//显示弹窗界面时关闭主相机
|
||
EventManager.Instance.Send(EventManager.EventName.MainPanelPosterRelocate, new MainPanelSceneStoreData(0, 0, 0, 0, deltaPos, scale));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 背景模糊
|
||
/// </summary>
|
||
private RawImage rawImageGaussianBlurMask;
|
||
|
||
//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;
|
||
|
||
//立绘切换页面
|
||
private RecycleView _scrollPosterPool;
|
||
|
||
//private PhxhScrollView _scrollSkin;
|
||
//private GameObject _skinItemTemp;
|
||
|
||
private List<uint> _charIDList;
|
||
private List<uint> _displayIDList;
|
||
private int _curSelect; //当前选择的角色
|
||
private int _curSelectSkin; //当前选择的皮肤
|
||
private List<DataCharacterSkin> _skinDataList; //当前选择角色的皮肤列表
|
||
|
||
private bool _isHidePoster = false;//立绘显示开关
|
||
|
||
private bool PosterHide
|
||
{
|
||
set
|
||
{
|
||
_isHidePoster = value;
|
||
RefreshPosterHideButton();
|
||
}
|
||
}
|
||
|
||
private MainPanelSceneStoreData _saveData;
|
||
|
||
// deal with input data
|
||
public override void PreLoad(object data = null)
|
||
{
|
||
|
||
}
|
||
|
||
// Use this for initialization
|
||
public override void OnInit()
|
||
{
|
||
CommonUtils.ScreenshotReset();
|
||
//bind UI GameObj
|
||
UICameraAndPosterChangeBinder.GetComponents(this);
|
||
|
||
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
|
||
_sceneObj = FindObj("ImageBG/SceneChange");
|
||
_posterObj = FindObj("ImageBG/PosterChange");
|
||
|
||
rawImageGaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
|
||
|
||
SceneScrollView.SetScrollRect(GetComponent<PhxhScrollView>("ImageBG/SceneChange/SceneScrollView"));
|
||
SceneScrollView.InitItemCellList(SceneScrollView.SceneItemCount());
|
||
|
||
_scrollPosterPool = GetComponent<RecycleView>("ImageBG/PosterChange/ChangeHeadPic/PosterScrollView");
|
||
|
||
SkinScrollView.SetScrollRect(GetComponent<PhxhScrollView>("ImageBG/PosterChange/ChangeSkin/ScrollView"));
|
||
|
||
_charIDList = new List<uint>();
|
||
var charList = CharacterDataInfoManager.Instance.DataList;
|
||
for (int i = 0; i < charList.Count; i++)
|
||
{
|
||
_charIDList.Add(charList[i].Uid);
|
||
}
|
||
|
||
BindSceneScrollView();
|
||
|
||
BindSkinScrollView();
|
||
|
||
BindButton(Button_Back, _OnClickClose);
|
||
BindButton(Button_ChangePoster, _OnClickPosterTab);
|
||
BindButton(Button_ChangeScene, _OnClickSceneTab);
|
||
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, _OnClickSortBtn, SortType.Likely);
|
||
|
||
BindButton(Button_HidePic, OnClickHideKanbanban);
|
||
BindButton(Button_HidePicDown, OnClickHideKanbanban);
|
||
|
||
BindButton(Button_ChangeLocation, OnClickAdjustPoster);
|
||
|
||
EventManager.Instance.Register<MainPanelSceneStoreData>(EventManager.EventName.MainPanelPosterRelocate, ResetPosterPosition);
|
||
}
|
||
|
||
//invoke when open window
|
||
protected override void OnShowWindow(object data = null)
|
||
{
|
||
base.OnShowWindow(data);
|
||
_InitSceneScroll();
|
||
_InitPosterScroll();
|
||
_Refresh();
|
||
}
|
||
|
||
|
||
//invoke when reload window
|
||
protected override void OnReloadWindow(object data = null)
|
||
{
|
||
|
||
}
|
||
|
||
//invoke when close window
|
||
protected override void OnHideWindow()
|
||
{
|
||
|
||
}
|
||
|
||
//invoke when destroy
|
||
public override void OnRelease()
|
||
{
|
||
base.OnRelease();
|
||
SceneScrollView.Release();
|
||
SkinScrollView.Release();
|
||
EventManager.Instance.Unregister<MainPanelSceneStoreData>(EventManager.EventName.MainPanelPosterRelocate, ResetPosterPosition);
|
||
}
|
||
|
||
#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:
|
||
{
|
||
int index = _curSceneIndex;
|
||
Button_ChangePoster.gameObject.SetActive(false);
|
||
Button_ChangeScene.gameObject.SetActive(true);
|
||
_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);
|
||
|
||
_SetPosYListData();
|
||
SceneScrollView.UpdateData();
|
||
//await UniTask.DelayFrame(1);
|
||
SceneScrollView.ScrollTo(index);
|
||
//LayoutRebuilder.ForceRebuildLayoutImmediate(_sceneScrollContent.GetComponent<RectTransform>());
|
||
break;
|
||
}
|
||
case PageEnum.Poster:
|
||
{
|
||
int index = _curSelectSkin;
|
||
Button_ChangePoster.gameObject.SetActive(true);
|
||
Button_ChangeScene.gameObject.SetActive(false);
|
||
_sceneObj.SetActive(false);
|
||
_posterObj.SetActive(true);
|
||
Image_CBG.gameObject.SetActive(true);
|
||
_RefreshPosterButton();
|
||
|
||
SkinScrollView.UpdateData();
|
||
//await UniTask.DelayFrame(1);
|
||
SkinScrollView.ScrollTo(index);
|
||
break;
|
||
}
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
#region DropDown
|
||
|
||
private void _DropDown()
|
||
{
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 更换场景
|
||
/// </summary>
|
||
#region ScenePage
|
||
|
||
void BindSceneScrollView()
|
||
{
|
||
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");
|
||
|
||
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);
|
||
}
|
||
|
||
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");
|
||
var imgMaskBg = CommonUtils.GetGameObject(goViewList[i], "ImageBlackCover");
|
||
|
||
imgSelect.SetActive(_curCameraPosIdx == i);
|
||
imgGray.SetActive(_curCameraPosIdx != i);
|
||
imgMaskBg.SetActive(_curCameraPosIdx == i);
|
||
}
|
||
}
|
||
|
||
private void _OnScrollViewValChange(Vector2 pos)
|
||
{
|
||
var curIndex = SceneScrollView.GetClosestIdx(_curSceneIndex);
|
||
if (curIndex == _curSceneIndex)
|
||
{
|
||
return;
|
||
}
|
||
|
||
_curSceneIndex = curIndex;
|
||
_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)
|
||
{
|
||
item.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
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;
|
||
}
|
||
}
|
||
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;
|
||
}
|
||
}
|
||
|
||
private async void _InitSceneScroll()
|
||
{
|
||
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],
|
||
CommonUtils.ECharacterPicPathType.Poster, _curSelectSkin + 1);
|
||
var posterSprite = await LoadAssetAsync<Sprite>(posterPath);
|
||
Image_CBG.sprite = posterSprite;
|
||
}
|
||
|
||
private void _RefreshCharList()
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
private void _RefreshPosterPanel()
|
||
{
|
||
_RefreshCharList();
|
||
|
||
MainPanelSceneStoreData data;
|
||
if (_saveData != null)
|
||
{
|
||
data = _saveData;
|
||
}
|
||
else
|
||
{
|
||
data = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
|
||
}
|
||
if (data != null)
|
||
{
|
||
_curSelect = GetPosterIndexByID(data.PosterID);
|
||
_curSelectSkin = data.PosterSkinIdx;
|
||
|
||
if (CategoryManager.Instance.TryGetSkinItemInfo(data.PosterID, _curSelectSkin + 1, out DataItem dataItem))
|
||
{
|
||
if (CategoryManager.Instance.GetItemCount(dataItem.ID) == 0)
|
||
{
|
||
_curSelectSkin = 0;
|
||
}
|
||
}
|
||
PosterHide = data.hideKanbanban;
|
||
}
|
||
|
||
_RefreshImageMenu();
|
||
_RefreshPoolScroll();
|
||
//_RefreshSkinScroll();
|
||
_RefreshPosterButton();
|
||
SkinScrollView.UpdateData();
|
||
}
|
||
|
||
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()
|
||
{
|
||
// var content = CommonUtils.GetGameObject(_scrollPosterPool.gameObject, "Viewport/Content");
|
||
// if (content)
|
||
// {
|
||
// CommonUtils.DestoryAllChildGameObject(content);
|
||
// }
|
||
_scrollPosterPool.Init(_RefreshPoolItem);
|
||
_RefreshPoolScroll();
|
||
}
|
||
|
||
private void _RefreshPoolScroll()
|
||
{
|
||
// _scrollPosterPool.SetUpdateFunc(_RefreshPoolItem);
|
||
// _scrollPosterPool.SetItemCountFunc(_GetPoolCountFunc);
|
||
// _scrollPosterPool.UpdateData(false);
|
||
// _scrollPosterPool.SetButton(_SetPoolItemButton);
|
||
_scrollPosterPool.ShowList(_GetPoolCountFunc());
|
||
}
|
||
|
||
private async void _RefreshPoolItem(GameObject go, int index)
|
||
{
|
||
//var go = item.gameObject;
|
||
var uid = _charIDList[index];
|
||
var headPicPath = CommonUtils.GetDefaultHeadPathByUid(uid);
|
||
|
||
var imgHead = CommonUtils.GetComponent<Image>(go, "ImageHead");
|
||
var btn = CommonUtils.GetComponent<Button>(go, "ImageHead");
|
||
var goSelect = CommonUtils.GetGameObject(go, "ImageHead/ImageChooseRect");
|
||
|
||
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);
|
||
}
|
||
|
||
//_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 async void _RefreshSkinItem(int index, RectTransform item)
|
||
{
|
||
var go = item.gameObject;
|
||
go.SetActive(true);
|
||
|
||
//if (_curSelectSkin == index)
|
||
//{
|
||
//TODO 目前半身图使用好感度图片路径
|
||
var posterPic =
|
||
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 = 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);
|
||
//}
|
||
}
|
||
|
||
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)
|
||
{
|
||
if (_curSelect == index)
|
||
{
|
||
return;
|
||
}
|
||
|
||
_curSelect = index;
|
||
_curSelectSkin = 0;
|
||
_skinDataList = CommonUtils.GetCharacterSkinCfgList((int)_charIDList[_curSelect]);
|
||
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;
|
||
PosterHide = storeData.hideKanbanban;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_curSelect = GetPosterIndexByID(_saveData.PosterID);
|
||
_curSelectSkin = _saveData.PosterSkinIdx;
|
||
PosterHide = _saveData.hideKanbanban;
|
||
}
|
||
_skinDataList = CommonUtils.GetCharacterSkinCfgList((int)_charIDList[_curSelect]);
|
||
}
|
||
|
||
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)
|
||
{
|
||
if (_curSelect == GetPosterIndexByID(_saveData.PosterID) && _curSelectSkin == _saveData.PosterSkinIdx)//当前展示角色
|
||
{
|
||
Button_Confirm01.gameObject.SetActive(false);
|
||
Button_Cancel01.gameObject.SetActive(true);
|
||
Button_ChangeLocation.gameObject.SetActive(true);
|
||
Button_HidePic.gameObject.SetActive(!_isHidePoster);
|
||
Button_HidePicDown.gameObject.SetActive(_isHidePoster);
|
||
}
|
||
else//非当前展示角色
|
||
{
|
||
Button_Confirm01.gameObject.SetActive(true);
|
||
Button_Cancel01.gameObject.SetActive(false);
|
||
Button_ChangeLocation.gameObject.SetActive(false);
|
||
Button_HidePic.gameObject.SetActive(false);
|
||
Button_HidePicDown.gameObject.SetActive(false);
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
var storeData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
|
||
if (storeData != null)
|
||
{
|
||
if (_curSelect == GetPosterIndexByID(storeData.PosterID) && _curSelectSkin == storeData.PosterSkinIdx)//当前展示角色
|
||
{
|
||
Button_Confirm01.gameObject.SetActive(false);
|
||
Button_Cancel01.gameObject.SetActive(true);
|
||
Button_ChangeLocation.gameObject.SetActive(true);
|
||
Button_HidePic.gameObject.SetActive(!_isHidePoster);
|
||
Button_HidePicDown.gameObject.SetActive(_isHidePoster);
|
||
}
|
||
else//非当前展示角色
|
||
{
|
||
Button_Confirm01.gameObject.SetActive(true);
|
||
Button_Cancel01.gameObject.SetActive(false);
|
||
Button_ChangeLocation.gameObject.SetActive(false);
|
||
Button_HidePic.gameObject.SetActive(false);
|
||
Button_HidePicDown.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void RefreshPosterHideButton()
|
||
{
|
||
Button_HidePic.gameObject.SetActive(!_isHidePoster);
|
||
Button_HidePicDown.gameObject.SetActive(_isHidePoster);
|
||
}
|
||
|
||
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为空,重新赋值");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
#endregion
|
||
|
||
#region class
|
||
|
||
|
||
/// <summary>
|
||
/// 场景切换列表类
|
||
/// </summary>
|
||
class ScenePanelScrollView : IPanelScrollView
|
||
{
|
||
public override void SetScrollRect(PhxhScrollView scrollRect)
|
||
{
|
||
base.SetScrollRect(scrollRect);
|
||
|
||
SetItemRectTrans(CommonUtils.GetComponent<RectTransform>(_scrollRect.itemTemplate.gameObject, "ButtonScene"),
|
||
CommonUtils.GetComponent<RectTransform>(_scrollRect.itemTemplate.gameObject, "ButtonSceneFull"));
|
||
|
||
SetPaddingSize(new Vector2(590, 300));
|
||
}
|
||
|
||
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()
|
||
{
|
||
_CheckAndSaveChange();
|
||
CloseWindow();
|
||
}
|
||
|
||
private void _OnClickSceneConfirm()
|
||
{
|
||
_ConfirmChangeMainScene();
|
||
}
|
||
|
||
private async void _OnClickPoolHeadItem(int index)
|
||
{
|
||
if (index != _curSelect)
|
||
{
|
||
_ChangeSelectCharacter(index);
|
||
//_scrollPosterPool.UpdateData();
|
||
_RefreshPoolScroll();
|
||
//_RefreshSkinScroll();
|
||
SkinScrollView.UpdateData();
|
||
_RefreshPosterButton();
|
||
|
||
var posterPath = CommonUtils.GetCharacterPicPath((int)_charIDList[_curSelect],
|
||
CommonUtils.ECharacterPicPathType.Poster, _curSelectSkin + 1);
|
||
var posterSprite = await LoadAssetAsync<Sprite>(posterPath);
|
||
Image_CBG.sprite = posterSprite;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 看板娘调整位置
|
||
/// </summary>
|
||
private void OnClickAdjustPoster()
|
||
{
|
||
if (_saveData != null)
|
||
{
|
||
UIManager.Instance.Hide(UINameConst.UICameraAndPosterChange, isMainCameraActive: true);
|
||
_saveData.hideKanbanban = false;
|
||
PosterHide = false;
|
||
EventManager.Instance.Send(EventManager.EventName.PreviewMainPanelPoster, _saveData);
|
||
}
|
||
else
|
||
{
|
||
var sendData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
|
||
UIManager.Instance.Hide(UINameConst.UICameraAndPosterChange, isMainCameraActive: true);
|
||
sendData.hideKanbanban = false;
|
||
PosterHide = false;
|
||
EventManager.Instance.Send(EventManager.EventName.PreviewMainPanelPoster, sendData);
|
||
}
|
||
}
|
||
private void OnClickHideKanbanban()
|
||
{
|
||
PosterHide = !_isHidePoster;
|
||
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);
|
||
}
|
||
|
||
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()
|
||
{
|
||
_CheckAndSaveChange();
|
||
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel);
|
||
}
|
||
|
||
private void _OnClickSortBtn(SortType sortType)
|
||
{
|
||
if (_sortType == sortType)
|
||
{
|
||
_isUpSort = !_isUpSort;
|
||
}
|
||
else
|
||
{
|
||
//非先前选择方式,默认以降序排列
|
||
_isUpSort = false;
|
||
_sortType = sortType;
|
||
}
|
||
_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;
|
||
_saveData.hideKanbanban = false;
|
||
PosterHide = false;
|
||
}
|
||
|
||
_RefreshPosterButton();
|
||
}
|
||
|
||
private void _CheckAndSaveChange()
|
||
{
|
||
|
||
var oldSaveData = StorageMgr.Instance.GetStorage<MainPanelSceneStoreData>("MainPanelSceneStoreData");
|
||
if (oldSaveData != null && _saveData != null)
|
||
{
|
||
bool refreshPoster = false;
|
||
if (CheckIsPosterChange(_saveData, oldSaveData))//更换看板娘或调整位置
|
||
{
|
||
oldSaveData.PosterID = _saveData.PosterID;
|
||
oldSaveData.PosterSkinIdx = _saveData.PosterSkinIdx;
|
||
oldSaveData.deltaPos = _saveData.deltaPos;
|
||
oldSaveData.scale = _saveData.scale;
|
||
|
||
refreshPoster = true;
|
||
DebugUtil.Log("保存看板娘调整数据");
|
||
}
|
||
if (oldSaveData.hideKanbanban != _isHidePoster)//隐藏看板娘
|
||
{
|
||
oldSaveData.hideKanbanban = _isHidePoster;
|
||
|
||
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;
|
||
LoadingExecutorManager.Instance.ExecuteLoading(new MainSceneReLoadingExecutor()).Forget();
|
||
DebugUtil.Log("保存场景调整数据,当前场景: " + _saveData.SceneIdx);
|
||
}
|
||
StorageMgr.Instance.SyncForce = true;
|
||
}
|
||
}
|
||
|
||
private bool CheckIsSceneChange(MainPanelSceneStoreData newStoreData, MainPanelSceneStoreData oldStoreData)
|
||
{
|
||
if (newStoreData.SceneIdx != oldStoreData.SceneIdx)
|
||
{
|
||
return true;
|
||
}
|
||
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;
|
||
}
|
||
|
||
if (newStoreData.deltaPos[0] != oldStoreData.deltaPos[0] || newStoreData.deltaPos[1] != oldStoreData.deltaPos[1])
|
||
{
|
||
return true;
|
||
}
|
||
if (newStoreData.scale != oldStoreData.scale)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
private void _OnClickCameraPos(int index)
|
||
{
|
||
if (_curCameraPosIdx == index)
|
||
{
|
||
return;
|
||
}
|
||
|
||
_curCameraPosIdx = index;
|
||
_RefreshItemView(SceneScrollView._itemCells[_curSceneIndex].GoRoot);
|
||
_RefreshSceneButtons();
|
||
}
|
||
}
|
||
|
||
public class MainPanelSceneStoreData
|
||
{
|
||
public int SceneIdx = 0;
|
||
public int CameraPosIdx = 0;
|
||
public int PosterID = 0;
|
||
public int PosterSkinIdx = 0;
|
||
|
||
//看板娘自定义数据
|
||
public float[] deltaPos = new float[2] { 0, 0 };//位置偏移量
|
||
public float scale = 0f;//缩放比例指数,底数为2
|
||
public bool hideKanbanban = false;//是否隐藏看板娘
|
||
|
||
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;
|
||
}
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
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);
|
||
|
||
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
|
||
}
|