566 lines
19 KiB
C#
566 lines
19 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.UI;
|
|
|
|
public class AppearancePanel : BasePanel
|
|
{
|
|
[NonSerialized]
|
|
public AppearanceOpenType appearanceOpenType;
|
|
List<Toggle> toggles = new List<Toggle>();
|
|
List<GameObject> selected_tab = new List<GameObject>();
|
|
List<GameObject> redpoint = new List<GameObject>();
|
|
TMP_Text text_name;
|
|
TMP_Text text_title;
|
|
Button btn_close;
|
|
Button btn_equip;
|
|
Button btn_unequip;
|
|
GameObject equipped;
|
|
GameObject waytoget;
|
|
TMP_Text text_waytoget;
|
|
Transform content;
|
|
GameObject item;
|
|
List<AppearanceItem> appearanceItems = new List<AppearanceItem>();
|
|
|
|
List<RodAccessoriesData> rodAccessoriesDatas;
|
|
List<GloveData> gloveDatas;
|
|
List<RodSkinData> rodSkinDatas;
|
|
int curDataCount;
|
|
|
|
int curEqIndex;
|
|
|
|
int skinCount;
|
|
int gloveCount;
|
|
int accessoriesCount;
|
|
|
|
int curMainIndex = 0;
|
|
int curSubIndex = -1;
|
|
|
|
Tables tables;
|
|
IUIService uiService;
|
|
FishingBehaviorB fishingBehavior;
|
|
PlayerFishData playerFishData;
|
|
GameObject fishingSkinTool;
|
|
int rodID;
|
|
bool unlockRod;
|
|
Button btn_yugan;
|
|
Button btn_view;
|
|
Image bg_hud_god_image;
|
|
Image rawImage;
|
|
TMP_Text text_grade_rod;
|
|
TMP_Text text_star_rod;
|
|
string[] bg_hud_gods = { "bg_hud_god_blue", "bg_hud_god_blue", "bg_hud_god_purple", "bg_hud_god_yellow" };
|
|
|
|
CanvasGroup root;
|
|
Button btn_close_view;
|
|
|
|
AppearanceRodChangePanel rodChangePanel;
|
|
private void Awake()
|
|
{
|
|
playerFishData = GContext.container.Resolve<PlayerFishData>();
|
|
GetFishingBehaviorB getFishingBehavior = new GetFishingBehaviorB();
|
|
GContext.Publish(getFishingBehavior);
|
|
fishingBehavior = getFishingBehavior.fishingBehavior;
|
|
fishingBehavior.gameObject.SetActive(false);
|
|
|
|
uiService = GContext.container.Resolve<IUIService>();
|
|
tables = GContext.container.Resolve<Tables>();
|
|
gloveDatas = tables.TbGloveData.DataList;
|
|
gloveCount = playerFishData.rodAccessoriesData.GloveIds.Count;
|
|
|
|
rodAccessoriesDatas = tables.TbRodAccessoriesData.DataList;
|
|
|
|
root = transform.Find("root").GetComponent<CanvasGroup>();
|
|
btn_close_view = transform.Find("btn_close").GetComponent<Button>();
|
|
btn_view = transform.Find("root/btn_view").GetComponent<Button>();
|
|
text_name = transform.Find("root/name/text_name").GetComponent<TMP_Text>();
|
|
text_title = transform.Find("root/bg_title/text_title").GetComponent<TMP_Text>();
|
|
btn_close = transform.Find("root/btn_close").GetComponent<Button>();
|
|
btn_equip = transform.Find("root/btn_equip/btn_green").GetComponent<Button>();
|
|
btn_unequip = transform.Find("root/btn_unequip/btn_green").GetComponent<Button>();
|
|
equipped = transform.Find("root/equipped").gameObject;
|
|
waytoget = transform.Find("root/waytoget").gameObject;
|
|
text_waytoget = transform.Find("root/waytoget/text_waytoget").GetComponent<TMP_Text>();
|
|
content = transform.Find("root/layout_item");
|
|
item = transform.Find("root/layout_item/item").gameObject;
|
|
item.SetActive(false);
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
redpoint.Add(transform.Find($"root/tab/redpoint_tab{i + 1}").gameObject);
|
|
selected_tab.Add(transform.Find($"root/tab/selected_tab{i + 1}").gameObject);
|
|
toggles.Add(transform.Find($"root/tab/normal_tab{i + 1}").GetComponent<Toggle>());
|
|
Toggle toggle = toggles[i];
|
|
int index = i;
|
|
toggle.onValueChanged.AddListener((isOn) =>
|
|
{
|
|
selected_tab[index].SetActive(isOn);
|
|
if (isOn)
|
|
{
|
|
OnToggleChange(index);
|
|
}
|
|
});
|
|
selected_tab[i].SetActive(i == curMainIndex);
|
|
toggle.isOn = i == curMainIndex;
|
|
}
|
|
btn_yugan = transform.Find("root/btn_yugan").GetComponent<Button>();
|
|
bg_hud_god_image = transform.Find("root/btn_yugan/bg").GetComponent<Image>();
|
|
rawImage = transform.Find("root/btn_yugan/mask/icon").GetComponent<Image>();
|
|
text_grade_rod = transform.Find("root/btn_yugan/text_grade").GetComponent<TMP_Text>();
|
|
text_star_rod = transform.Find("root/btn_yugan/bg_star/text_star").GetComponent<TMP_Text>();
|
|
|
|
OnChangeRod(GContext.container.Resolve<PlayerData>().equipRodID);
|
|
rodChangePanel = transform.Find("AppearanceRodChangePanel").GetComponent<AppearanceRodChangePanel>();
|
|
rodChangePanel.gameObject.SetActive(false);
|
|
rodChangePanel.OnChangeRod = OnChangeRod;
|
|
rodChangePanel.rodId = rodID;
|
|
LoadFishingSkinTool();
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
redpoint[1].SetActive(playerFishData.rodAccessoriesData.GloveNewIds.Count > 0);
|
|
base.Start();
|
|
btn_yugan.onClick.AddListener(() => rodChangePanel.gameObject.SetActive(true));
|
|
btn_close.onClick.AddListener(OnClickClose);
|
|
btn_equip.onClick.AddListener(OnClickEquip);
|
|
btn_unequip.onClick.AddListener(OnClickUnequip);
|
|
btn_view.onClick.AddListener(ClickView);
|
|
btn_close_view.onClick.AddListener(CloseView);
|
|
}
|
|
void ClickView()
|
|
{
|
|
root.alpha = 0;
|
|
root.blocksRaycasts = false;
|
|
btn_close_view.gameObject.SetActive(true);
|
|
}
|
|
void CloseView()
|
|
{
|
|
root.alpha = 1;
|
|
root.blocksRaycasts = true;
|
|
btn_close_view.gameObject.SetActive(false);
|
|
}
|
|
async void LoadFishingSkinTool()
|
|
{
|
|
fishingSkinTool = await Addressables.InstantiateAsync("FishingSkinTool").Task;
|
|
}
|
|
#region 装备、卸下
|
|
void OnClickEquip()
|
|
{
|
|
switch (curMainIndex)
|
|
{
|
|
case (int)RodSkinType.skin:
|
|
EquipSkin(true);
|
|
break;
|
|
case (int)RodSkinType.glove:
|
|
EquipGlove(true);
|
|
break;
|
|
//case (int)RodSkinType.accessories:
|
|
// EquipAccessories(true);
|
|
// break;
|
|
}
|
|
OnEquip();
|
|
}
|
|
void OnClickUnequip()
|
|
{
|
|
switch (curMainIndex)
|
|
{
|
|
case (int)RodSkinType.skin:
|
|
EquipSkin(false);
|
|
break;
|
|
case (int)RodSkinType.glove:
|
|
EquipGlove(false);
|
|
break;
|
|
//case (int)RodSkinType.accessories:
|
|
// EquipAccessories(false);
|
|
// break;
|
|
}
|
|
}
|
|
void EquipSkin(bool iseq)
|
|
{
|
|
if (iseq)
|
|
{
|
|
playerFishData.SetRodSkin(rodID, rodSkinDatas[curSubIndex].ID);
|
|
}
|
|
else
|
|
{
|
|
playerFishData.SetRodSkin(rodID, 0);
|
|
}
|
|
OnSelectSkin();
|
|
GContext.Publish(new ChangeSkinEvent(RodSkinType.skin));
|
|
}
|
|
|
|
void EquipGlove(bool iseq)
|
|
{
|
|
if (iseq)
|
|
{
|
|
if (playerFishData.rodAccessoriesData.GloveID != gloveDatas[curSubIndex].ID)
|
|
{
|
|
playerFishData.rodAccessoriesData.GloveID = gloveDatas[curSubIndex].ID;
|
|
playerFishData.SaveInitRodAccessoriesData();
|
|
OnSelectGlove();
|
|
GContext.Publish(new ChangeSkinEvent(RodSkinType.glove));
|
|
}
|
|
}
|
|
}
|
|
//void EquipAccessories(bool iseq)
|
|
//{
|
|
// OnSelectAccessories();
|
|
//}
|
|
void OnEquip()
|
|
{
|
|
appearanceItems[curEqIndex].equipped.SetActive(false);
|
|
curEqIndex = curSubIndex;
|
|
appearanceItems[curEqIndex].equipped.SetActive(true);
|
|
}
|
|
#endregion 装备、卸下
|
|
#region 切换鱼杆
|
|
void OnChangeRod(int rodId)
|
|
{
|
|
rodID = rodId;
|
|
unlockRod = !playerFishData.NotRod(rodID);
|
|
RodData rodData = tables.TbRodData[rodID];
|
|
List<int> SkinList = rodData.SkinList;
|
|
rodSkinDatas = new List<RodSkinData>();
|
|
skinCount = 0;
|
|
int id;
|
|
for (int i = 0; i < SkinList.Count; i++)
|
|
{
|
|
id = SkinList[i];
|
|
RodSkinData rodSkinData = tables.TbRodSkinData.GetOrDefault(id);
|
|
if (rodSkinData != null)
|
|
{
|
|
rodSkinDatas.Add(rodSkinData);
|
|
if (unlockRod)
|
|
{
|
|
if (id == rodID || playerFishData.IsSkinUnlocked(id))
|
|
{
|
|
skinCount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (curMainIndex == (int)RodSkinType.skin)
|
|
{
|
|
ChangeMainIndex();
|
|
}
|
|
else
|
|
{
|
|
ChangeRodNotSkin();
|
|
}
|
|
InitRodData();
|
|
}
|
|
void ChangeRodNotSkin()
|
|
{
|
|
int curRodSkinId = playerFishData.GetRodSkin(rodID);
|
|
GContext.Publish(new SelectSkinEvent(curRodSkinId));
|
|
}
|
|
#endregion
|
|
#region 选中杆皮肤、手
|
|
void OnToggleChange(int index)
|
|
{
|
|
if (curMainIndex != index)
|
|
{
|
|
curMainIndex = index;
|
|
ChangeMainIndex();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 选中页签
|
|
/// </summary>
|
|
void ChangeMainIndex()
|
|
{
|
|
curSubIndex = -1;
|
|
switch (curMainIndex)
|
|
{
|
|
case (int)RodSkinType.skin:
|
|
curDataCount = rodSkinDatas.Count;
|
|
break;
|
|
case (int)RodSkinType.glove:
|
|
curDataCount = gloveDatas.Count;
|
|
break;
|
|
//case (int)RodSkinType.accessories:
|
|
// curDataCount = rodAccessoriesDatas.Count;
|
|
// break;
|
|
}
|
|
|
|
int length = appearanceItems.Count;
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
appearanceItems[i].gameObject.SetActive(false);
|
|
}
|
|
if (curDataCount > length)
|
|
{
|
|
for (int i = length; i < curDataCount; i++)
|
|
{
|
|
GameObject go = Instantiate(item, content);
|
|
AppearanceItem appearanceItem = go.GetComponent<AppearanceItem>();
|
|
appearanceItems.Add(appearanceItem);
|
|
appearanceItem.index = i;
|
|
appearanceItem.action = OnClickItem;
|
|
}
|
|
}
|
|
|
|
btn_equip.gameObject.SetActive(false);
|
|
btn_unequip.gameObject.SetActive(false);
|
|
equipped.gameObject.SetActive(false);
|
|
waytoget.gameObject.SetActive(false);
|
|
|
|
//设置列表
|
|
switch (curMainIndex)
|
|
{
|
|
case (int)RodSkinType.skin:
|
|
SetSkin();
|
|
break;
|
|
case (int)RodSkinType.glove:
|
|
SetGlove();
|
|
break;
|
|
//case (int)RodSkinType.accessories:
|
|
// SetAccessories();
|
|
// break;
|
|
}
|
|
redpoint[curMainIndex].SetActive(false);
|
|
}
|
|
|
|
void SetGlove()
|
|
{
|
|
int index = 0;
|
|
bool isUnlock;
|
|
bool isEq;
|
|
bool isNew;
|
|
int gloveID;
|
|
int curID = playerFishData.rodAccessoriesData.GloveID;
|
|
text_title.text = $"Outfit({gloveCount}/{curDataCount})";
|
|
for (int i = 0; i < curDataCount; i++)
|
|
{
|
|
gloveID = gloveDatas[i].ID;
|
|
appearanceItems[i].gameObject.SetActive(true);
|
|
appearanceItems[i].reward.icon.gameObject.SetActive(true);
|
|
appearanceItems[i].reward.icon_rod.gameObject.SetActive(false);
|
|
uiService.SetImageSprite(appearanceItems[i].reward.icon, gloveDatas[i].Icon);
|
|
isUnlock = gloveID == tables.TbGlobalConfig.InitGloveID || playerFishData.IsGloveUnlocked(gloveID);
|
|
appearanceItems[i].unlock.SetActive(!isUnlock);
|
|
isNew = playerFishData.IsNewGlove(gloveID);
|
|
appearanceItems[i].newGo.SetActive(isNew);
|
|
isEq = curID == gloveID;
|
|
appearanceItems[i].equipped.SetActive(isEq);
|
|
if (isEq)
|
|
{
|
|
curEqIndex = i;
|
|
index = i;
|
|
}
|
|
appearanceItems[i].selected.SetActive(false);
|
|
}
|
|
OnClickItem(index);
|
|
playerFishData.RemoveGloveNewId();
|
|
}
|
|
void SetSkin()
|
|
{
|
|
text_title.text = $"Outfit({skinCount}/{curDataCount})";
|
|
int index = 0;
|
|
bool isUnlock;
|
|
bool isEq;
|
|
int skinId;
|
|
bool isNew;
|
|
int curRodSkinId = playerFishData.GetRodSkin(rodID);
|
|
for (int i = 0; i < curDataCount; i++)
|
|
{
|
|
appearanceItems[i].gameObject.SetActive(true);
|
|
appearanceItems[i].reward.icon.gameObject.SetActive(false);
|
|
appearanceItems[i].reward.icon_rod.gameObject.SetActive(true);
|
|
uiService.SetImageSprite(appearanceItems[i].reward.icon_rod, rodSkinDatas[i].Avatar);
|
|
skinId = rodSkinDatas[i].ID;
|
|
appearanceItems[i].selected.SetActive(false);
|
|
if (unlockRod)
|
|
{
|
|
isEq = curRodSkinId == rodSkinDatas[i].ID;
|
|
if (isEq)
|
|
{
|
|
curEqIndex = i;
|
|
index = i;
|
|
}
|
|
isUnlock = skinId == rodID || playerFishData.IsSkinUnlocked(skinId);
|
|
appearanceItems[i].unlock.SetActive(!isUnlock);
|
|
isNew = playerFishData.IsNewSkin(skinId);
|
|
appearanceItems[i].newGo.SetActive(isNew);
|
|
appearanceItems[i].equipped.SetActive(isEq);
|
|
}
|
|
else
|
|
{
|
|
appearanceItems[i].newGo.SetActive(false);
|
|
appearanceItems[i].unlock.SetActive(true);
|
|
appearanceItems[i].equipped.SetActive(false);
|
|
}
|
|
}
|
|
OnClickItem(index);
|
|
}
|
|
//void SetAccessories()
|
|
//{
|
|
// text_title.text = $"Outfit({accessoriesCount}/{curDataCount})";
|
|
// for (int i = 0; i < curDataCount; i++)
|
|
// {
|
|
// appearanceItems[i].gameObject.SetActive(true);
|
|
// uiService.SetImageSprite(appearanceItems[i].icon, rodAccessoriesDatas[i].Icon);
|
|
// }
|
|
// OnClickItem(0);
|
|
//}
|
|
#endregion 选中杆皮肤、手
|
|
|
|
#region 选中Item
|
|
/// <summary>
|
|
/// 选中列表中某个元素
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
void OnClickItem(int index)
|
|
{
|
|
if (curSubIndex == index)
|
|
{
|
|
return;
|
|
}
|
|
if (curSubIndex >= 0)
|
|
{
|
|
appearanceItems[curSubIndex].selected.SetActive(false);
|
|
}
|
|
curSubIndex = index;
|
|
appearanceItems[curSubIndex].selected.SetActive(true);
|
|
appearanceItems[curSubIndex].newGo.SetActive(false);
|
|
if (curDataCount > 0)
|
|
{
|
|
switch (curMainIndex)
|
|
{
|
|
case (int)RodSkinType.skin:
|
|
OnSelectSkin();
|
|
break;
|
|
case (int)RodSkinType.glove:
|
|
OnSelectGlove();
|
|
break;
|
|
//case (int)RodSkinType.accessories:
|
|
// OnSelectAccessories();
|
|
// break;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 选中某个皮肤
|
|
/// </summary>
|
|
void OnSelectSkin()
|
|
{
|
|
RodSkinData rodSkinData = rodSkinDatas[curSubIndex];
|
|
text_name.text = LocalizationMgr.GetText(rodSkinData.Name_l10n_key);
|
|
if (rodSkinData.ID == rodID)
|
|
{
|
|
text_waytoget.text = LocalizationMgr.GetText("UI_AppearancePanel_2");
|
|
}
|
|
else
|
|
{
|
|
text_waytoget.text = LocalizationMgr.GetText("UI_AppearancePanel_1");
|
|
}
|
|
if (unlockRod)
|
|
{
|
|
bool idHas = rodSkinData.ID == rodID || playerFishData.IsSkinUnlocked(rodSkinData.ID);
|
|
if (!idHas)
|
|
{
|
|
ShowPack();
|
|
}
|
|
else
|
|
{
|
|
int curId = playerFishData.GetRodSkin(rodID);
|
|
btn_equip.gameObject.SetActive(curId != rodSkinData.ID);
|
|
equipped.gameObject.SetActive(curId == rodSkinData.ID);
|
|
waytoget.SetActive(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShowPack();
|
|
}
|
|
GContext.Publish(new SelectSkinEvent(rodSkinData.ID));
|
|
}
|
|
/// <summary>
|
|
/// 选中某个手
|
|
/// </summary>
|
|
void OnSelectGlove()
|
|
{
|
|
GloveData gloveData = gloveDatas[curSubIndex];
|
|
text_name.text = LocalizationMgr.GetText(gloveData.Name_l10n_key);
|
|
bool idHas = gloveData.ID == tables.TbGlobalConfig.InitGloveID || playerFishData.IsGloveUnlocked(gloveData.ID);
|
|
if (!idHas)
|
|
{
|
|
text_waytoget.text = LocalizationMgr.GetText("UI_AppearancePanel_1");
|
|
ShowPack();
|
|
}
|
|
else
|
|
{
|
|
int curId = playerFishData.rodAccessoriesData.GloveID;
|
|
btn_equip.gameObject.SetActive(curId != gloveData.ID);
|
|
equipped.gameObject.SetActive(curId == gloveData.ID);
|
|
waytoget.SetActive(false);
|
|
}
|
|
GContext.Publish(new SelectGloveEvent(gloveData.ID));
|
|
}
|
|
/// <summary>
|
|
/// 当没有解锁时
|
|
/// </summary>
|
|
void ShowPack()
|
|
{
|
|
btn_equip.gameObject.SetActive(false);
|
|
btn_unequip.gameObject.SetActive(false);
|
|
equipped.gameObject.SetActive(false);
|
|
waytoget.SetActive(true);
|
|
}
|
|
/// <summary>
|
|
/// 选中某个挂件
|
|
/// </summary>
|
|
//void OnSelectAccessories()
|
|
//{
|
|
// RodAccessoriesData rodAccessoriesData = rodAccessoriesDatas[curSubIndex];
|
|
// text_name.text = LocalizationMgr.GetText(rodAccessoriesData.Name_l10n_key);
|
|
// //btn_equip.gameObject.SetActive(curId != rodSkinData.ID);
|
|
// //btn_unequip.gameObject.SetActive(curId == rodSkinData.ID);
|
|
// GContext.Publish(new SelectAccessoriesEvent(rodAccessoriesData.ID));
|
|
//}
|
|
#endregion 选中Item
|
|
async void OnClickClose()
|
|
{
|
|
Addressables.Release(fishingSkinTool);
|
|
UIManager.Instance.DestroyUI(UITypes.AppearancePanel);
|
|
switch (appearanceOpenType)
|
|
{
|
|
case AppearanceOpenType.FishingRodPanel:
|
|
await UIManager.Instance.ShowUI(UITypes.FishingRodPanel);
|
|
GContext.Publish(new MapShowEvent() { isShow = false });
|
|
break;
|
|
default:
|
|
GContext.Publish(new RestartShowHomeUIEvent());
|
|
GContext.Publish(new ActChangeRodDataEvent(GContext.container.Resolve<PlayerData>().equipRodID));
|
|
break;
|
|
}
|
|
fishingBehavior.gameObject.SetActive(true);
|
|
}
|
|
|
|
|
|
|
|
public void InitRodData()
|
|
{
|
|
RodData rod = tables.GetRodData(rodID);
|
|
text_grade_rod.text = LocalizationMgr.GetFormatTextValue("UI_PlayerGradePanel_2", playerFishData.GetRodLevel(rod.ID) + 1);
|
|
text_star_rod.text = playerFishData.GetRodPiece(rod.ID).ToString();
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(bg_hud_god_image, bg_hud_gods[rod.Quality - 1], "HomePanel");
|
|
int skindID = GContext.container.Resolve<PlayerFishData>().GetRodSkin(rod.ID);
|
|
if (skindID <= 0)
|
|
{
|
|
return;
|
|
}
|
|
var fishRodSkinData = tables.TbRodSkinData.GetOrDefault(skindID);
|
|
if (fishRodSkinData == null)
|
|
{
|
|
return;
|
|
}
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(rawImage, fishRodSkinData.Avatar, "HomePanel");
|
|
}
|
|
}
|