2025-11-12 16:48:34 +09:00
|
|
|
using Cysharp.Threading.Tasks;
|
2025-11-12 12:28:17 +09:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace SHI.modal
|
|
|
|
|
{
|
2025-11-12 16:48:34 +09:00
|
|
|
public class BlockDetailModal : MonoBehaviour
|
2025-11-12 12:28:17 +09:00
|
|
|
{
|
2025-11-12 16:48:34 +09:00
|
|
|
[Header("References")]
|
2025-11-12 12:28:17 +09:00
|
|
|
[SerializeField]
|
|
|
|
|
private Button closeButton;
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
2025-11-12 16:48:34 +09:00
|
|
|
private ModelDetailListView listView;
|
2025-11-12 12:28:17 +09:00
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private ModelDetailView modelView;
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
2025-11-12 16:48:34 +09:00
|
|
|
private ModelDetailChartView chartView;
|
2025-11-12 12:28:17 +09:00
|
|
|
|
2025-11-12 16:48:34 +09:00
|
|
|
[Header("UI Controls")]
|
2025-11-12 12:28:17 +09:00
|
|
|
[SerializeField]
|
|
|
|
|
private Button modelViewExpandButton;
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private Button chartViewExpandButton;
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private Button dragButton;
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
2025-11-12 16:48:34 +09:00
|
|
|
private Button showListButton;
|
|
|
|
|
|
|
|
|
|
// cached layout elements for split control
|
|
|
|
|
private LayoutElement _modelLayout;
|
|
|
|
|
private LayoutElement _chartLayout;
|
|
|
|
|
|
|
|
|
|
private enum ExpandedSide { None, Model, Chart }
|
|
|
|
|
private ExpandedSide _expanded = ExpandedSide.None;
|
|
|
|
|
|
|
|
|
|
private RectTransform ModelRect => modelView != null ? modelView.GetComponent<RectTransform>() : null;
|
|
|
|
|
private RectTransform ChartRect => chartView != null ? chartView.GetComponent<RectTransform>() : null;
|
|
|
|
|
private HorizontalSplitDrag _splitter;
|
2025-11-12 12:28:17 +09:00
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
2025-11-12 16:48:34 +09:00
|
|
|
// Close
|
|
|
|
|
if (closeButton != null)
|
|
|
|
|
{
|
|
|
|
|
closeButton.onClick.AddListener(() => gameObject.SetActive(false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// list show 버튼
|
|
|
|
|
if (showListButton != null && listView != null)
|
|
|
|
|
showListButton.onClick.AddListener(() =>
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("BlockDetailModal: Show List View");
|
|
|
|
|
listView.gameObject.SetActive(true);
|
|
|
|
|
showListButton.gameObject.SetActive(false);
|
|
|
|
|
if (_splitter != null) _splitter.RefreshPosition();
|
|
|
|
|
});
|
|
|
|
|
showListButton.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
|
|
// Selection wiring: list -> model/chart
|
|
|
|
|
if (listView != null)
|
|
|
|
|
{
|
|
|
|
|
listView.OnItemSelected += data =>
|
|
|
|
|
{
|
|
|
|
|
if (modelView != null) modelView.FocusItem(data);
|
|
|
|
|
if (chartView != null) chartView.SelectByItem(data.Name);
|
|
|
|
|
};
|
|
|
|
|
listView.OnClosed += () =>
|
|
|
|
|
{
|
|
|
|
|
if (showListButton != null) showListButton.gameObject.SetActive(true);
|
|
|
|
|
if (_splitter != null) _splitter.RefreshPosition();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Selection wiring: model -> list/chart
|
|
|
|
|
if (modelView != null)
|
|
|
|
|
{
|
|
|
|
|
modelView.OnItemSelected += data =>
|
|
|
|
|
{
|
|
|
|
|
if (listView != null) listView.SelectItem(data.Name);
|
|
|
|
|
if (chartView != null) chartView.SelectByItem(data.Name);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Chart -> list/model
|
|
|
|
|
if (chartView != null)
|
|
|
|
|
{
|
|
|
|
|
chartView.OnRowClicked += name =>
|
|
|
|
|
{
|
|
|
|
|
if (listView != null) listView.SelectItem(name);
|
|
|
|
|
if (modelView != null) modelView.FocusItemName(name);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Expand buttons
|
|
|
|
|
if (modelViewExpandButton != null)
|
|
|
|
|
modelViewExpandButton.onClick.AddListener(ToggleExpandModel);
|
|
|
|
|
if (chartViewExpandButton != null)
|
|
|
|
|
chartViewExpandButton.onClick.AddListener(ToggleExpandChart);
|
|
|
|
|
|
|
|
|
|
// Drag splitter
|
|
|
|
|
SetupSplitControls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetupSplitControls()
|
|
|
|
|
{
|
|
|
|
|
var modelRect = ModelRect;
|
|
|
|
|
var chartRect = ChartRect;
|
|
|
|
|
if (modelRect == null || chartRect == null || dragButton == null) return;
|
|
|
|
|
|
|
|
|
|
_modelLayout = modelRect.GetComponent<LayoutElement>();
|
|
|
|
|
if (_modelLayout == null) _modelLayout = modelRect.gameObject.AddComponent<LayoutElement>();
|
|
|
|
|
|
|
|
|
|
_chartLayout = chartRect.GetComponent<LayoutElement>();
|
|
|
|
|
if (_chartLayout == null) _chartLayout = chartView.gameObject.AddComponent<LayoutElement>();
|
|
|
|
|
|
|
|
|
|
// initial split50/50
|
|
|
|
|
_modelLayout.flexibleWidth = 1f;
|
|
|
|
|
_chartLayout.flexibleWidth = 1f;
|
|
|
|
|
|
|
|
|
|
// attach drag handler
|
|
|
|
|
_splitter = dragButton.gameObject.GetComponent<HorizontalSplitDrag>();
|
|
|
|
|
if (_splitter == null) _splitter = dragButton.gameObject.AddComponent<HorizontalSplitDrag>();
|
|
|
|
|
var leftFixed = listView != null ? listView.GetComponent<RectTransform>() : null;
|
|
|
|
|
_splitter.Initialize(modelRect, chartRect, leftFixed);
|
|
|
|
|
//시간이 좀 필요 함
|
|
|
|
|
UniTask.DelayFrame(1).ContinueWith(() => _splitter.RefreshPosition());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToggleExpandModel()
|
|
|
|
|
{
|
|
|
|
|
if (ModelRect == null || chartView == null) return;
|
|
|
|
|
if (_expanded == ExpandedSide.Model) { ResetSplit(); return; }
|
|
|
|
|
_expanded = ExpandedSide.Model;
|
|
|
|
|
ModelRect.gameObject.SetActive(true);
|
|
|
|
|
chartView.gameObject.SetActive(false);
|
|
|
|
|
if (_splitter != null) _splitter.gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToggleExpandChart()
|
|
|
|
|
{
|
|
|
|
|
if (ModelRect == null || chartView == null) return;
|
|
|
|
|
if (_expanded == ExpandedSide.Chart) { ResetSplit(); return; }
|
|
|
|
|
_expanded = ExpandedSide.Chart;
|
|
|
|
|
ModelRect.gameObject.SetActive(false);
|
|
|
|
|
chartView.gameObject.SetActive(true);
|
|
|
|
|
if (_splitter != null) _splitter.gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetSplit()
|
|
|
|
|
{
|
|
|
|
|
_expanded = ExpandedSide.None;
|
|
|
|
|
if (ModelRect != null) ModelRect.gameObject.SetActive(true);
|
|
|
|
|
if (chartView != null) chartView.gameObject.SetActive(true);
|
|
|
|
|
if (_modelLayout != null) _modelLayout.flexibleWidth = 1f;
|
|
|
|
|
if (_chartLayout != null) _chartLayout.flexibleWidth = 1f;
|
|
|
|
|
if (_splitter != null)
|
|
|
|
|
{
|
|
|
|
|
_splitter.gameObject.SetActive(true);
|
|
|
|
|
_splitter.RefreshPosition();
|
|
|
|
|
}
|
2025-11-12 12:28:17 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|