185 lines
6.0 KiB
C#
185 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 로봇 프로그램(Job 파일)의 생성, 목록 조회, 선택, 불러오기 기능을 담당하는 UI 뷰(View) 클래스
|
|
/// 가상 키패드를 통한 파일명 입력, 스크롤 뷰에 파일 목록 표시 등의 UI 로직을 처리하며,
|
|
/// 사용자의 중요 입력(생성, 로드 등)을 이벤트로 Presenter에게 전달
|
|
/// </summary>
|
|
///
|
|
public class ProgramView : MonoBehaviour
|
|
{
|
|
// --- 프로그램 목록 패널 ---
|
|
[Header("Panels")]
|
|
[SerializeField] private GameObject programSelectPanel; // 프로그램 관리 전체 최상위 패널
|
|
[SerializeField] private GameObject programNewPanel; // '새 프로그램 만들기' 입력 화면
|
|
[SerializeField] private GameObject programListPanel; // '불러오기' 목록 화면
|
|
|
|
[Header("List View Components")]
|
|
[SerializeField] private Transform programButtonContent; // 스크롤 뷰의 Content (버튼들이 생성될 위치)
|
|
[SerializeField] private GameObject programButtonPrefab; // 목록에 추가될 개별 버튼 프리팹
|
|
|
|
[Header("Input UI")]
|
|
[SerializeField] private TextMeshProUGUI programIdText; // 입력된 프로그램 ID가 표시될 텍스트
|
|
[SerializeField] private Button[] numberPadButtons; // 가상 키패드 숫자 버튼 (0~9)
|
|
[SerializeField] private Button backspaceButton; // 지우기 버튼
|
|
|
|
[Header("Action Buttons")]
|
|
[SerializeField] private Button createProgramButton; // 생성 확인 버튼
|
|
[SerializeField] private Button loadProgramButton; // 목록 불러오기 화면으로 전환 버튼
|
|
[SerializeField] private Button openProgramButton; // 선택한 프로그램 열기 버튼
|
|
[SerializeField] private Button closeProgramListButton; // 목록 닫기(뒤로 가기) 버튼
|
|
|
|
// --- Presenter에게 보낼 이벤트 (User Events) ---
|
|
/// <summary>새 프로그램 생성 요청 (인자: 입력된 ID)</summary>
|
|
public event Action<string> OnCreateProgramClicked;
|
|
|
|
/// <summary>저장된 프로그램 목록 데이터 요청</summary>
|
|
public event Action OnLoadProgramListRequested;
|
|
|
|
/// <summary>목록에서 특정 프로그램을 선택함 (인자: 선택된 ID)</summary>
|
|
public event Action<string> OnProgramSelectedToLoad;
|
|
|
|
/// <summary>선택된 프로그램을 실제로 열기 요청</summary>
|
|
public event Action OnOpenProgramClicked;
|
|
|
|
|
|
void Start()
|
|
{
|
|
loadProgramButton.onClick.AddListener(() => OnLoadProgramListRequested?.Invoke());
|
|
openProgramButton.onClick.AddListener(() => OnOpenProgramClicked?.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);
|
|
closeProgramListButton.onClick.AddListener(HideProgramList);
|
|
|
|
programSelectPanel.SetActive(true);
|
|
programNewPanel.SetActive(true);
|
|
programListPanel.SetActive(false);
|
|
SetprogramIdTextEmpty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 입력 텍스트 필드를 초기화
|
|
/// </summary>
|
|
public void SetprogramIdTextEmpty()
|
|
{
|
|
programIdText.text = string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 가상 키패드 입력 처리: 숫자를 텍스트 뒤에 붙임
|
|
/// (최대 4자리까지만 입력 가능하도록 제한)
|
|
/// </summary>
|
|
private void AppendToInput(string number)
|
|
{
|
|
if (programIdText.text.Length < 4)
|
|
{
|
|
programIdText.text += number;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 가상 키패드 지우기 처리: 마지막 글자를 지움
|
|
/// </summary>
|
|
private void HandleBackspace()
|
|
{
|
|
if (programIdText.text.Length > 0)
|
|
{
|
|
programIdText.text = programIdText.text.Substring(0, programIdText.text.Length - 1);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// '생성' 버튼 클릭 시 Presenter에게 입력된 ID와 함께 이벤트를 보냄
|
|
/// </summary>
|
|
private void HandleCreateClick()
|
|
{
|
|
string inputId = programIdText.text;
|
|
OnCreateProgramClicked?.Invoke(inputId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 오류 메시지나 시스템 메시지를 로그로 표시
|
|
/// </summary>
|
|
public void ShowMessage(string message)
|
|
{
|
|
Debug.LogWarning(message);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 프로그램 로드 성공 시 로그를 출력
|
|
/// </summary>
|
|
public void DisplayProgram(string programId)
|
|
{
|
|
if (programId == null)
|
|
{
|
|
Debug.Log("No Program Loaded");
|
|
return;
|
|
}
|
|
Debug.Log($"연결된 프로그램: {programId}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Presenter로부터 받은 프로그램 ID 목록을 스크롤 뷰에 버튼 형태로 표시
|
|
/// </summary>
|
|
/// <param name="programIds">표시할 프로그램 이름 리스트</param>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 프로그램 목록 화면을 닫고 다시 생성 화면으로 돌아옴
|
|
/// </summary>
|
|
public void HideProgramList()
|
|
{
|
|
programListPanel.SetActive(false);
|
|
programNewPanel.SetActive(true);
|
|
SetprogramIdTextEmpty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 프로그램 관리 패널 전체를 숨김 (메인 화면 진입 시 사용)
|
|
/// </summary>
|
|
public void HideProgramSelectPanel()
|
|
{
|
|
programSelectPanel.SetActive(false);
|
|
}
|
|
} |