76 lines
2.4 KiB
C#
76 lines
2.4 KiB
C#
using Assets.MyGame.Scripts.Net;
|
|
using Assets.MyGame.Scripts.Net.APIRequest.Objs;
|
|
using Assets.MyGame.Scripts.Net.APIRequest.Params;
|
|
using Assets.MyGame.Scripts.Net.APIResponses;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>公告面板</summary>
|
|
public class UIHome_BY_AnnouncementPanel : SubUIBase
|
|
{
|
|
public AnnouncementItem announcementItemPrefab;
|
|
public Transform announcementItemParent;
|
|
public TextMeshProUGUI tmp_TitleLabel;
|
|
public TextMeshProUGUI tmp_Content;
|
|
|
|
private List<NoticeDto> noticeList;
|
|
|
|
protected override void OnShow(object args = null)
|
|
{
|
|
base.OnShow(args);
|
|
LoadNoticeList();
|
|
}
|
|
|
|
private void LoadNoticeList()
|
|
{
|
|
APIRequestList.GetNoticeList(new NoticeListObj
|
|
{
|
|
keyWord = "",
|
|
pageIndex = 0,
|
|
pageSize = 50
|
|
}, list =>
|
|
{
|
|
if (list == null) return;
|
|
noticeList = list;
|
|
|
|
// 清除旧列表
|
|
for (int i = announcementItemParent.childCount - 1; i >= 0; i--)
|
|
Destroy(announcementItemParent.GetChild(i).gameObject);
|
|
|
|
foreach (var item in list)
|
|
{
|
|
var obj = Instantiate(announcementItemPrefab.gameObject, announcementItemParent);
|
|
var tempItem = obj.GetComponent<AnnouncementItem>();
|
|
tempItem.Init(this, item.title, item.createTime);
|
|
tempItem.tMP_Header.text = item.title;
|
|
string noticeId = item.id;
|
|
obj.GetComponent<Toggle>().onValueChanged.RemoveAllListeners();
|
|
obj.GetComponent<Toggle>().onValueChanged.AddListener((isOn) =>
|
|
{
|
|
if (isOn) OnNoticeClick(noticeId);
|
|
});
|
|
}
|
|
|
|
// 默认选中第一条公告
|
|
if (list.Count > 0)
|
|
{
|
|
var firstToggle = announcementItemParent.GetChild(0).GetComponent<Toggle>();
|
|
firstToggle.isOn = true;
|
|
OnNoticeClick(list[0].id);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void OnNoticeClick(string noticeId)
|
|
{
|
|
APIRequestList.GetNotice(new NoticeIdParam { id = noticeId }, notice =>
|
|
{
|
|
if (notice == null) return;
|
|
if (tmp_TitleLabel != null) tmp_TitleLabel.text = notice.title;
|
|
if (tmp_Content != null) tmp_Content.text = notice.content;
|
|
});
|
|
}
|
|
}
|