Files
Studio/Assets/TMPFolder/Panel_Repository.cs

154 lines
5.7 KiB
C#
Raw Normal View History

2025-05-22 18:29:09 +09:00
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
2025-05-22 16:12:56 +09:00
using Studio;
using Studio.Setting.Connect;
using Studio.UI;
using TMPro;
using UnityEngine;
using XRLib.UI;
2025-05-22 18:29:09 +09:00
using Newtonsoft.Json;
using Best.HTTP.JSON;
using UnityEngine.UI;
2025-05-23 12:33:04 +09:00
using System.Collections.Generic;
2025-05-23 13:59:45 +09:00
using System;
2025-05-22 16:12:56 +09:00
namespace XED.UI
{
public class Panel_Repository : PanelBase
{
2025-05-23 12:33:04 +09:00
UI_BaseDataButton apiDataButtonPrefab;
UI_MQTTDataButton mqttDataButtonPrefab;
2025-05-22 16:12:56 +09:00
2025-05-23 13:59:45 +09:00
RectTransform APIDataList;
RectTransform MQTTDataList;
RectTransform Panel_APIInfo;
RectTransform Panel_APIDataInfo;
RectTransform Panel_MQTTInfo;
RectTransform Panel_MQTTDataInfo;
2025-05-22 16:12:56 +09:00
TextMeshProUGUI TotalRequestPacketSize;
TextMeshProUGUI AverageRequestPacketSize;
TextMeshProUGUI TotalResponsePacketSize;
TextMeshProUGUI AverageResponsePacketSize;
TextMeshProUGUI MaximumResponseTime;
TextMeshProUGUI AverageResponseTime;
TextMeshProUGUI MaximumRequestPacketAPI;
TextMeshProUGUI MaximumResponsePacketAPI;
TextMeshProUGUI MaximumResponseTimeAPI;
2025-05-23 12:33:04 +09:00
LayoutGroup[] layoutGroups;
Dictionary<string, UI_BaseDataButton> apiButtons = new();
2025-05-23 13:59:45 +09:00
Dictionary<string, UI_MQTTDataButton> mqttButtons = new();
2025-05-23 12:33:04 +09:00
2025-05-22 16:12:56 +09:00
public override void AfterAwake()
{
UI_ProtocolLabel[] protocolLabels = GetComponentsInChildren<UI_ProtocolLabel>();
foreach (UI_ProtocolLabel label in protocolLabels)
{
label.panel_Repository = this;
}
2025-05-23 14:52:29 +09:00
StudioService.Instance.onAPIDataLoaded += UpdateAPIDataButton;
StudioService.Instance.onMQTTDataLoaded += UpdateMQTTDataButton;
2025-05-22 16:12:56 +09:00
2025-05-23 12:33:04 +09:00
apiDataButtonPrefab = Resources.Load<UI_BaseDataButton>("Prefabs/UI/Button/UI_BaseDataButton");
mqttDataButtonPrefab = Resources.Load<UI_MQTTDataButton>("Prefabs/UI/Button/UI_MQTTDataButton");
2025-05-22 18:29:09 +09:00
2025-05-23 12:33:04 +09:00
layoutGroups = GetComponentsInChildren<LayoutGroup>();
2025-05-22 16:12:56 +09:00
}
2025-05-23 12:33:04 +09:00
2025-05-23 13:59:45 +09:00
void UpdateAPIDataButton(string name, StudioEntityWithState<object> value)
2025-05-22 16:12:56 +09:00
{
2025-05-23 12:33:04 +09:00
if (!apiButtons.ContainsKey(name))
{
// <20><>ư <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
var button = Instantiate(apiDataButtonPrefab, APIDataList.transform);
apiButtons.Add(name, button);
button.panel_Repository = this;
button.SetButtonData(name, value);
2025-05-22 18:29:09 +09:00
2025-05-23 12:33:04 +09:00
RebuildLayout();
}
else
{
// <20><>ư <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ
apiButtons[name].SetButtonData(name, value);
}
2025-05-22 16:12:56 +09:00
}
2025-05-23 13:59:45 +09:00
void UpdateMQTTDataButton(string name, Dictionary<string, Dictionary<string, string>> value, TimeSpan elapsedTime)
2025-05-23 12:33:04 +09:00
{
2025-05-23 13:59:45 +09:00
if (!mqttButtons.ContainsKey(name))
{
var button = Instantiate(mqttDataButtonPrefab, MQTTDataList.transform);
mqttButtons.Add(name, button);
button.panel_Repository = this;
button.SetButtonData(name, value, elapsedTime);
2025-05-22 16:12:56 +09:00
2025-05-23 13:59:45 +09:00
RebuildLayout();
}
else
{
mqttButtons[name].SetButtonData(name, value, elapsedTime);
}
2025-05-23 12:33:04 +09:00
}
public void RebuildLayout()
2025-05-22 18:29:09 +09:00
{
2025-05-23 12:33:04 +09:00
foreach (var layout in layoutGroups)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(layout.GetComponent<RectTransform>());
}
2025-05-22 18:29:09 +09:00
}
2025-05-22 16:12:56 +09:00
public void ShowInformation_API()
{
APITotalBoardEntity info = StudioService.Instance.GetAPIStatusBoarder();
TotalRequestPacketSize.text = info.TotalRequestPacketSize.ToString();
AverageRequestPacketSize.text = info.AverageRequestPacketSize.ToString();
TotalResponsePacketSize.text = info.TotalResponsePacketSize.ToString();
AverageResponsePacketSize.text = info.AverageResponsePacketSize.ToString();
MaximumResponseTime.text = info.MaximumResponseTime.ToString();
AverageResponseTime.text = info.AverageResponseTime.ToString();
MaximumRequestPacketAPI.text = info.MaximumRequestPacketAPI;
MaximumResponsePacketAPI.text = info.MaximumResponsePacketAPI;
MaximumResponseTimeAPI.text = info.MaximumResponseTimeAPI;
2025-05-23 13:59:45 +09:00
Panel_APIInfo.gameObject.SetActive(true);
Panel_APIDataInfo.gameObject.SetActive(false);
Panel_MQTTInfo.gameObject.SetActive(false);
Panel_MQTTDataInfo.gameObject.SetActive(false);
2025-05-22 16:12:56 +09:00
}
2025-05-23 12:33:04 +09:00
public void ShowInformation_APIData(StudioEntityWithState<object> baseDataValue)
2025-05-22 16:12:56 +09:00
{
2025-05-23 13:59:45 +09:00
Panel_APIDataInfo.GetComponent<Panel_APIDataInfo>().ShowData(baseDataValue);
Panel_APIInfo.gameObject.SetActive(false);
Panel_APIDataInfo.gameObject.SetActive(true);
Panel_MQTTInfo.gameObject.SetActive(false);
Panel_MQTTDataInfo.gameObject.SetActive(false);
2025-05-23 12:33:04 +09:00
}
public void ShowInformation_MQTT()
{
2025-05-23 13:59:45 +09:00
Panel_APIInfo.gameObject.SetActive(false);
Panel_APIDataInfo.gameObject.SetActive(false);
Panel_MQTTInfo.gameObject.SetActive(true);
Panel_MQTTDataInfo.gameObject.SetActive(false);
2025-05-23 12:33:04 +09:00
}
2025-05-23 13:59:45 +09:00
public void ShowInformation_MQTTData(Dictionary<string, Dictionary<string, string>> data, TimeSpan elapsedTime)
2025-05-23 12:33:04 +09:00
{
2025-05-23 13:59:45 +09:00
Panel_MQTTDataInfo.GetComponent<Panel_MQTTDataInfo>().ShowData(data, elapsedTime);
2025-05-23 12:33:04 +09:00
2025-05-23 13:59:45 +09:00
Panel_APIInfo.gameObject.SetActive(false);
Panel_APIDataInfo.gameObject.SetActive(false);
Panel_MQTTInfo.gameObject.SetActive(false);
Panel_MQTTDataInfo.gameObject.SetActive(true);
2025-05-22 18:29:09 +09:00
}
2025-05-22 16:12:56 +09:00
}
}