157 lines
5.1 KiB
C#
157 lines
5.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
public interface IProgramView
|
|
{
|
|
void ShowMessage(string message);
|
|
void DisplayProgram(string programId);
|
|
void ShowProgramList(List<string> programIds);
|
|
void HideProgramList();
|
|
void HideProgramSelectPanel();
|
|
|
|
public event Action<string> OnCreateProgramClicked;
|
|
public event Action OnLoadProgramListRequested; // '불러오기' 버튼 클릭
|
|
public event Action<string> OnProgramSelectedToLoad;
|
|
public event Action OnOpenProgramClicked;
|
|
public event Action OnSaveClicked;
|
|
public event Action OnAddPointClicked;
|
|
}
|
|
|
|
public class ProgramView : MonoBehaviour, IProgramView
|
|
{
|
|
// --- UI 요소 참조 ---
|
|
//[SerializeField] private Button loadIconButton;
|
|
[SerializeField] private Button loadProgramButton;
|
|
//[SerializeField] private Button saveProgramButton;
|
|
//[SerializeField] private Button addPointButton; // UI상 위치를 찍는 버튼
|
|
//[SerializeField] private TextMeshProUGUI currentProgramIdText;
|
|
//[SerializeField] private TextMeshProUGUI endpointListText;
|
|
|
|
// --- 프로그램 목록 패널 ---
|
|
[SerializeField] private GameObject programSelectPanel;
|
|
[SerializeField] private GameObject programNewPanel;
|
|
[SerializeField] private GameObject programListPanel;
|
|
[SerializeField] private Transform programButtonContent;
|
|
[SerializeField] private GameObject programButtonPrefab;
|
|
|
|
[SerializeField] private TextMeshProUGUI programIdText;
|
|
[SerializeField] private Button[] numberPadButtons; // 0-9까지의 버튼 배열
|
|
[SerializeField] private Button backspaceButton;
|
|
[SerializeField] private Button createProgramButton;
|
|
[SerializeField] private Button openProgramButton;
|
|
[SerializeField] private Button closeProgramListButton;
|
|
|
|
// --- Presenter에게 보낼 이벤트들 ---
|
|
public event Action<string> OnCreateProgramClicked;
|
|
public event Action OnLoadProgramListRequested; // '불러오기' 버튼 클릭
|
|
public event Action<string> OnProgramSelectedToLoad;
|
|
public event Action OnOpenProgramClicked;
|
|
public event Action OnSaveClicked;
|
|
public event Action OnAddPointClicked;
|
|
|
|
|
|
void Start()
|
|
{
|
|
loadProgramButton.onClick.AddListener(() => OnLoadProgramListRequested?.Invoke());
|
|
openProgramButton.onClick.AddListener(() => OnOpenProgramClicked?.Invoke());
|
|
//saveProgramButton.onClick.AddListener(() => OnSaveClicked?.Invoke());
|
|
//addPointButton.onClick.AddListener(() => OnAddPointClicked?.Invoke());
|
|
|
|
for (int i = 0; i < numberPadButtons.Length; i++)
|
|
{
|
|
string number = numberPadButtons[i].GetComponentInChildren<TextMeshProUGUI>().text;
|
|
numberPadButtons[i].onClick.AddListener(() => AppendToInput(number));
|
|
}
|
|
|
|
backspaceButton.onClick.AddListener(HandleBackspace);
|
|
createProgramButton.onClick.AddListener(HandleCreateClick);
|
|
//loadIconButton.onClick.AddListener(HandleLoadIconClick);
|
|
closeProgramListButton.onClick.AddListener(HideProgramList);
|
|
|
|
programSelectPanel.SetActive(true);
|
|
programNewPanel.SetActive(true);
|
|
programListPanel.SetActive(false);
|
|
programIdText.text = string.Empty;
|
|
}
|
|
|
|
private void AppendToInput(string number)
|
|
{
|
|
programIdText.text += number;
|
|
}
|
|
|
|
private void HandleBackspace()
|
|
{
|
|
if (programIdText.text.Length > 0)
|
|
{
|
|
programIdText.text = programIdText.text.Substring(0, programIdText.text.Length - 1);
|
|
}
|
|
}
|
|
|
|
private void HandleCreateClick()
|
|
{
|
|
string inputId = programIdText.text;
|
|
OnCreateProgramClicked?.Invoke(inputId);
|
|
}
|
|
|
|
// Presenter가 호출할 오류 메시지 표시 함수
|
|
public void ShowMessage(string message)
|
|
{
|
|
Debug.LogWarning(message);
|
|
}
|
|
|
|
public void DisplayProgram(string programId)
|
|
{
|
|
if (programId == null)
|
|
{
|
|
Debug.Log("No Program Loaded");
|
|
return;
|
|
}
|
|
Debug.Log($"연결된 프로그램: {programId}");
|
|
}
|
|
|
|
public void ShowProgramList(List<string> programIds)
|
|
{
|
|
foreach (Transform child in programButtonContent)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
|
|
programIds.Sort();
|
|
foreach (string id in programIds)
|
|
{
|
|
GameObject buttonGO = Instantiate(programButtonPrefab, programButtonContent);
|
|
|
|
TextMeshProUGUI buttonText = buttonGO.GetComponentInChildren<TextMeshProUGUI>();
|
|
if (buttonText != null)
|
|
{
|
|
buttonText.text = id;
|
|
}
|
|
|
|
Button button = buttonGO.GetComponent<Button>();
|
|
if (button != null)
|
|
{
|
|
string currentId = id;
|
|
button.onClick.AddListener(() =>
|
|
{
|
|
OnProgramSelectedToLoad?.Invoke(currentId);
|
|
});
|
|
}
|
|
}
|
|
programListPanel.SetActive(true);
|
|
programNewPanel.SetActive(false);
|
|
}
|
|
|
|
public void HideProgramList()
|
|
{
|
|
programListPanel.SetActive(false);
|
|
programNewPanel.SetActive(true);
|
|
}
|
|
|
|
public void HideProgramSelectPanel()
|
|
{
|
|
programSelectPanel.SetActive(false);
|
|
}
|
|
} |