备份CatanBuilding瘦身独立工程
This commit is contained in:
213
Assets/Scripts/UI/Social/ClubCreatePopupPanel.cs
Normal file
213
Assets/Scripts/UI/Social/ClubCreatePopupPanel.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ClubCreatePopupPanel : MonoBehaviour
|
||||
{
|
||||
public Button btn_mask;
|
||||
public Button btn_close;
|
||||
public Button btn_head;
|
||||
public ClubHead club_head;
|
||||
public TMP_InputField inputField_name;
|
||||
public TMP_InputField inputField_desc;
|
||||
public Button btn_left_type;
|
||||
public TMP_Text text_type;
|
||||
public Button btn_right_type;
|
||||
public Button btn_left_required;
|
||||
public TMP_Text text_required;
|
||||
public Button btn_right_required;
|
||||
public Button btn_create;
|
||||
TMP_Text text_create;
|
||||
public Button btn_save;
|
||||
public TMP_Text text_title;
|
||||
int typeIndex = 0;
|
||||
int requiredLv;
|
||||
ClubSettingData curGroupSettingData;
|
||||
string iconUrl;
|
||||
|
||||
int ClubCreationCashCost;
|
||||
private void Awake()
|
||||
{
|
||||
btn_mask = transform.Find("mask").GetComponent<Button>();
|
||||
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
||||
btn_head = transform.Find("root/btn_head").GetComponent<Button>();
|
||||
club_head = transform.Find("root/btn_head").GetComponent<ClubHead>();
|
||||
inputField_name = transform.Find("root/info/name/InputField_name").GetComponent<TMP_InputField>();
|
||||
inputField_desc = transform.Find("root/info/description/InputField_description").GetComponent<TMP_InputField>();
|
||||
btn_left_type = transform.Find("root/info/type/bg_type/btn_left").GetComponent<Button>();
|
||||
text_type = transform.Find("root/info/type/bg_type/text").GetComponent<TMP_Text>();
|
||||
btn_right_type = transform.Find("root/info/type/bg_type/btn_right").GetComponent<Button>();
|
||||
btn_left_required = transform.Find("root/info/required/bg_grade/btn_left").GetComponent<Button>();
|
||||
text_required = transform.Find("root/info/required/bg_grade/text").GetComponent<TMP_Text>();
|
||||
btn_right_required = transform.Find("root/info/required/bg_grade/btn_right").GetComponent<Button>();
|
||||
btn_create = transform.Find("root/btn_creat/btn_green").GetComponent<Button>();
|
||||
text_create = transform.Find("root/btn_creat/btn_green/Ani_Container/content_cost/cost/p_text_num").GetComponent<TMP_Text>();
|
||||
btn_save = transform.Find("root/btn_save/btn_green").GetComponent<Button>();
|
||||
text_title = transform.Find("root/text_title").GetComponent<TMP_Text>();
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
ClubCreationCashCost = GContext.container.Resolve<Tables>().TbGlobalConfig.ClubCreationCashCost;
|
||||
text_create.text = ClubCreationCashCost.ToString();
|
||||
btn_mask.onClick.AddListener(OnClose);
|
||||
btn_close.onClick.AddListener(OnClose);
|
||||
btn_create.onClick.AddListener(OnCreate);
|
||||
btn_save.onClick.AddListener(OnSave);
|
||||
btn_left_type.onClick.AddListener(OnLeftType);
|
||||
btn_right_type.onClick.AddListener(OnRightType);
|
||||
btn_left_required.onClick.AddListener(OnLeftRequired);
|
||||
btn_right_required.onClick.AddListener(OnRightRequired);
|
||||
//设置字数限制
|
||||
inputField_name.characterLimit = GContext.container.Resolve<Tables>().TbGlobalConfig.ClubNameMaxChar;
|
||||
inputField_desc.characterLimit = GContext.container.Resolve<Tables>().TbGlobalConfig.ClubNoticeMaxChar;
|
||||
|
||||
btn_head.onClick.AddListener(OpenAvatarPanel);
|
||||
//添加事件,当头像改变时,更新头像
|
||||
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
int id = GContext.container.Resolve<Tables>().TbGlobalConfig.ClubInitAvatar;
|
||||
int frameId = GContext.container.Resolve<Tables>().TbGlobalConfig.ClubInitFrame;
|
||||
|
||||
iconUrl = string.Format("{0}#{1}",
|
||||
GContext.container.Resolve<Tables>().TbClubAvatar[id].Avatar,
|
||||
GContext.container.Resolve<Tables>().TbClubFrame[frameId].Frame);
|
||||
btn_save.gameObject.SetActive(GContext.container.Resolve<ClubService>().IsClubJoined());
|
||||
btn_create.gameObject.SetActive(!GContext.container.Resolve<ClubService>().IsClubJoined());
|
||||
if (GContext.container.Resolve<ClubService>().IsClubJoined())
|
||||
{
|
||||
curGroupSettingData = GContext.container.Resolve<ClubService>().myClubInfo.clubSettingData;
|
||||
inputField_name.text = curGroupSettingData.clubName;
|
||||
inputField_desc.text = curGroupSettingData.description;
|
||||
text_type.text = LocalizationMgr.GetText(((EClubType)curGroupSettingData.type).ToString());
|
||||
text_required.text = curGroupSettingData.gradeReq.ToString();
|
||||
typeIndex = curGroupSettingData.type;
|
||||
|
||||
text_title.text = LocalizationMgr.GetText("UI_ClubCreatePopupPanel_8");
|
||||
if (curGroupSettingData != null && !string.IsNullOrEmpty(curGroupSettingData.icon))
|
||||
{
|
||||
iconUrl = curGroupSettingData.icon;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
text_type.text = LocalizationMgr.GetText(((EClubType)typeIndex).ToString());
|
||||
text_title.text = LocalizationMgr.GetText("UI_ClubCreatePopupPanel_1");
|
||||
}
|
||||
club_head.SetData(iconUrl);
|
||||
}
|
||||
void OnClose()
|
||||
{
|
||||
UIManager.Instance.DestroyUI(UITypes.ClubCreatePopupPanel);
|
||||
}
|
||||
async void OpenAvatarPanel()
|
||||
{
|
||||
var panel = await UIManager.Instance.ShowUI(UITypes.ClubHeadPopupPanel);
|
||||
ClubHeadPopupPanel clubHeadPopupPanel = panel.GetComponent<ClubHeadPopupPanel>();
|
||||
clubHeadPopupPanel.OnChange = ChangeAvatar;
|
||||
}
|
||||
void ChangeAvatar(string avatar)
|
||||
{
|
||||
iconUrl = avatar;
|
||||
club_head.SetData(avatar);
|
||||
}
|
||||
async void OnCreate()
|
||||
{
|
||||
//判断消耗品是否足够
|
||||
PlayerData playerData = GContext.container.Resolve<PlayerData>();
|
||||
if (playerData.gold < (ulong)ClubCreationCashCost)
|
||||
{
|
||||
//int required = 100;
|
||||
//GContext.Publish(new SetLackOfResourceEvent(5, required));
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_CampPanel_8"));
|
||||
return;
|
||||
}
|
||||
ClubSettingData groupSettingData = NewClubSettingData();
|
||||
if (groupSettingData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
btn_create.enabled = false;
|
||||
var Result = await GContext.container.Resolve<ClubService>().CreateClub(groupSettingData);
|
||||
if (Result != null)
|
||||
{
|
||||
playerData.SetGold(playerData.gold - (ulong)ClubCreationCashCost);
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_38"));
|
||||
UIManager.Instance.DestroyUI(UITypes.ClubCreatePopupPanel);
|
||||
}
|
||||
else
|
||||
{
|
||||
btn_create.enabled = true;
|
||||
}
|
||||
}
|
||||
async void OnSave()
|
||||
{
|
||||
ClubSettingData groupSettingData = NewClubSettingData();
|
||||
if (groupSettingData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
btn_save.enabled = false;
|
||||
bool result = await GContext.container.Resolve<ClubService>().UpdateClub(groupSettingData);
|
||||
if (result)
|
||||
{
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_36"));
|
||||
}
|
||||
UIManager.Instance.DestroyUI(UITypes.ClubCreatePopupPanel);
|
||||
}
|
||||
ClubSettingData NewClubSettingData()
|
||||
{
|
||||
string clubName = inputField_name.text;
|
||||
string desc = inputField_desc.text;
|
||||
EClubType type = (EClubType)typeIndex;
|
||||
if (string.IsNullOrEmpty(clubName))
|
||||
{
|
||||
//TODO
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_47"));
|
||||
return null;
|
||||
}
|
||||
return new ClubSettingData { clubName = clubName, type = (int)type, gradeReq = requiredLv, description = desc, icon = iconUrl };
|
||||
}
|
||||
void OnLeftType()
|
||||
{
|
||||
typeIndex--;
|
||||
if (typeIndex < 0)
|
||||
{
|
||||
typeIndex = (int)EClubType.UI_ClubCreatePopupPanel_13;
|
||||
}
|
||||
text_type.text = LocalizationMgr.GetText(((EClubType)typeIndex).ToString());
|
||||
}
|
||||
void OnRightType()
|
||||
{
|
||||
typeIndex++;
|
||||
if (typeIndex > (int)EClubType.UI_ClubCreatePopupPanel_13)
|
||||
{
|
||||
typeIndex = 0;
|
||||
}
|
||||
text_type.text = LocalizationMgr.GetText(((EClubType)typeIndex).ToString());
|
||||
}
|
||||
void OnLeftRequired()
|
||||
{
|
||||
requiredLv -= 100;
|
||||
if (requiredLv < 0)
|
||||
{
|
||||
requiredLv = 1000;
|
||||
}
|
||||
text_required.text = requiredLv.ToString();
|
||||
}
|
||||
void OnRightRequired()
|
||||
{
|
||||
requiredLv += 100;
|
||||
if (requiredLv > 1000)
|
||||
{
|
||||
requiredLv = 0;
|
||||
}
|
||||
text_required.text = requiredLv.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user