277 lines
11 KiB
C#
277 lines
11 KiB
C#
using Assets.Framework.Tool;
|
|
using Assets.MyGame.Scripts.Net;
|
|
using Assets.MyGame.Scripts.Net.APIRequest.Params;
|
|
using Assets.MyGame.Scripts.Net.APIResponses.HomeMain_User;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIHome_BY_EmailPanel : SubUIBase
|
|
{
|
|
public TextMeshProUGUI tMPText_Header;
|
|
public TextMeshProUGUI tMPText_Content;
|
|
public TextMeshProUGUI tMPText_EmailCount;
|
|
public Button btn_Receive;
|
|
public Button btn_Dlete;
|
|
public Button btn_AllDlete;
|
|
public Button btn_AllReceive;
|
|
|
|
public EmalItem itemPrefab;
|
|
public Transform itemPrefabParent;
|
|
public GameObject propPrefab;
|
|
public Transform propPrefabParent;
|
|
public string currEmailID;
|
|
|
|
public Dictionary<string,GetEmailByPageResponse> dic_GetEmailByPageResponses = new Dictionary<string, GetEmailByPageResponse>();
|
|
public Dictionary<string,EmalItem> dic_EmalItems = new Dictionary<string, EmalItem>();
|
|
|
|
public override void Awake()
|
|
{
|
|
base.Awake();
|
|
btn_Receive.onClick.AddListener(() =>
|
|
{
|
|
APIRequestList.RewardEmail(new RewardEmailParam
|
|
{
|
|
id=currEmailID,
|
|
type=1
|
|
}, (str) =>
|
|
{
|
|
UIManager.Instance.ShowBoardError("领取成功");
|
|
RewardEmail(currEmailID);
|
|
});
|
|
});
|
|
btn_AllReceive.onClick.AddListener(() =>
|
|
{
|
|
APIRequestList.RewardEmail(new RewardEmailParam
|
|
{
|
|
id = "",
|
|
type = 2
|
|
}, (str) =>
|
|
{
|
|
UIManager.Instance.ShowBoardError("领取成功");
|
|
foreach (var item in dic_EmalItems.Keys)
|
|
{
|
|
RewardEmail(item);
|
|
}
|
|
//for (int i = 0; i < propPrefabParent.childCount; i++)
|
|
//{
|
|
// propPrefabParent.GetChild(i).GetChild(1).gameObject.SetActive(true);
|
|
//}
|
|
});
|
|
|
|
});
|
|
btn_Dlete.onClick.AddListener(() =>
|
|
{
|
|
APIRequestList.DeleteEmail(new DeleteEmailParam
|
|
{
|
|
id = currEmailID,
|
|
type = 1
|
|
}, (str) =>
|
|
{
|
|
UIManager.Instance.ShowBoardError("删除成功");
|
|
dic_GetEmailByPageResponses.Remove(currEmailID);
|
|
; Destroy(dic_EmalItems[currEmailID].gameObject);
|
|
dic_EmalItems.Remove(currEmailID);
|
|
tMPText_EmailCount.text = itemPrefabParent.childCount.ToString();
|
|
|
|
});
|
|
|
|
});
|
|
btn_AllDlete.onClick.AddListener(() =>
|
|
{
|
|
APIRequestList.DeleteEmail(new DeleteEmailParam
|
|
{
|
|
id = "",
|
|
type = 2
|
|
}, (str) =>
|
|
{
|
|
|
|
UIManager.Instance.ShowBoardError("删除成功");
|
|
|
|
|
|
|
|
|
|
foreach (var item in dic_EmalItems.Keys.ToList())
|
|
{
|
|
if (dic_GetEmailByPageResponses[item].rewardItems !=null&& dic_GetEmailByPageResponses[item].rewardItems.Count > 0|| dic_GetEmailByPageResponses[item].rewardGold>0|| dic_GetEmailByPageResponses[item].rewardDiamond>0)
|
|
{
|
|
if (dic_GetEmailByPageResponses[item].isReward == true)
|
|
{
|
|
Destroy(dic_EmalItems[item].gameObject);
|
|
|
|
dic_GetEmailByPageResponses.Remove(item);
|
|
|
|
dic_EmalItems.Remove(item);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (dic_GetEmailByPageResponses[item].isRead == true)
|
|
{
|
|
Destroy(dic_EmalItems[item].gameObject);
|
|
dic_GetEmailByPageResponses.Remove(item);
|
|
dic_EmalItems.Remove(item);
|
|
}
|
|
}
|
|
}
|
|
tMPText_EmailCount.text = itemPrefabParent.childCount.ToString();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private void RewardEmail(string key)
|
|
{
|
|
|
|
dic_GetEmailByPageResponses[key].isReward = true;
|
|
dic_EmalItems[key].obj_LingQu.SetActive(true);
|
|
btn_Receive.gameObject.SetActive(false);
|
|
btn_Dlete.gameObject.SetActive(true);
|
|
for (int i = 0; i < propPrefabParent.childCount; i++)
|
|
{
|
|
propPrefabParent.GetChild(i).GetChild(1).gameObject.SetActive(true);
|
|
}
|
|
|
|
}
|
|
|
|
protected override void OnShow(object args = null)
|
|
{
|
|
base.OnShow(args);
|
|
|
|
foreach (var item in dic_EmalItems.Values)
|
|
{
|
|
Destroy(item.gameObject);
|
|
}
|
|
dic_GetEmailByPageResponses.Clear();
|
|
dic_EmalItems.Clear();
|
|
if (args != null)
|
|
{
|
|
List<GetEmailByPageResponse> getEmailByPageResponse = (List<GetEmailByPageResponse>)args;
|
|
foreach (var item in getEmailByPageResponse)
|
|
{
|
|
dic_GetEmailByPageResponses[item.id] = item;
|
|
|
|
var emailItem = Instantiate(itemPrefab.gameObject, itemPrefabParent).GetComponent<EmalItem>();
|
|
emailItem.Init(this, item.title, item.sendTime, item.isReward,item.isRead);
|
|
dic_EmalItems[item.id] = emailItem;
|
|
emailItem.GetComponent<Toggle>().onValueChanged.AddListener((a) =>
|
|
{
|
|
if (a)
|
|
{
|
|
currEmailID = item.id;
|
|
tMPText_Header.text = item.title;
|
|
tMPText_Content.text = item.content;
|
|
APIRequestList.GetEmail(new GetEmailParam
|
|
{
|
|
id = currEmailID,
|
|
}, (GetEmailByPageResponse) =>
|
|
{
|
|
dic_EmalItems[ GetEmailByPageResponse.id].obj_YiDu.SetActive(false);
|
|
dic_GetEmailByPageResponses[ GetEmailByPageResponse.id].isRead=(true);
|
|
});
|
|
for (int i = propPrefabParent.childCount; i > 0; i--)
|
|
{
|
|
Destroy(propPrefabParent.GetChild(i-1).gameObject);
|
|
}
|
|
if (item.rewardGold>=0)
|
|
{
|
|
GameObject obj = Instantiate(propPrefab, propPrefabParent);
|
|
Addressables.LoadAssetAsync<Sprite>("Assets/UIResources/Home/邮件/图层 2311.png").Completed+=(AsyncOperationHandle<Sprite> op) =>
|
|
{
|
|
if (op.Status==AsyncOperationStatus.Succeeded)
|
|
{
|
|
obj.transform.GetChild(0).GetComponent<Image>().sprite = op.Result;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("加载失败: " + op.OperationException);
|
|
}
|
|
|
|
};
|
|
obj.transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>().text = item.rewardGold.ToString();
|
|
if (item.isReward)
|
|
{
|
|
obj.transform.GetChild(1).gameObject.SetActive(true);
|
|
btn_Dlete.gameObject.SetActive(true);
|
|
btn_Receive.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
btn_Dlete.gameObject.SetActive(false);
|
|
btn_Receive.gameObject.SetActive(true);
|
|
|
|
}
|
|
}
|
|
if (item.rewardDiamond>=0)
|
|
{
|
|
|
|
GameObject obj = Instantiate(propPrefab, propPrefabParent);
|
|
Addressables.LoadAssetAsync<Sprite>("Assets/UIResources/Home/邮件/图层 2314.png").Completed += (AsyncOperationHandle<Sprite> op) =>
|
|
{
|
|
if (op.Status == AsyncOperationStatus.Succeeded)
|
|
{
|
|
obj.transform.GetChild(0).GetComponent<Image>().sprite = op.Result;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("加载失败: " + op.OperationException);
|
|
}
|
|
|
|
};
|
|
obj.transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>().text = item.rewardDiamond.ToString();
|
|
if (item.isReward)
|
|
{
|
|
obj.transform.GetChild(1).gameObject.SetActive(true);
|
|
btn_Dlete.gameObject.SetActive(true);
|
|
btn_Receive.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
btn_Dlete.gameObject.SetActive(false);
|
|
btn_Receive.gameObject.SetActive(true);
|
|
|
|
}
|
|
}
|
|
if (item.rewardItems.Count>0)
|
|
{
|
|
foreach (var prop in item.rewardItems)
|
|
{
|
|
GameObject obj = Instantiate(propPrefab, propPrefabParent);
|
|
WebTool.DownImage(APIManager.baseURL+ prop.imageUrl, (texture) =>
|
|
{
|
|
obj.transform.GetChild(0).GetComponent<Image>().sprite = Sprite.Create(texture,new Rect(0f,0f,texture.width,texture.height),Vector2.one*0.5f);
|
|
});
|
|
obj.transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>().text = prop.count.ToString();
|
|
if (item.isReward)
|
|
{
|
|
obj.transform.GetChild(1).gameObject.SetActive(true);
|
|
btn_Dlete.gameObject.SetActive(true);
|
|
btn_Receive.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
btn_Dlete.gameObject.SetActive(false);
|
|
btn_Receive.gameObject.SetActive(true);
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
tMPText_EmailCount.text=itemPrefabParent.childCount.ToString();
|
|
}
|
|
|
|
}
|
|
}
|