<feat> 스플래쉬 화면전환 및 프로그램 생성
This commit is contained in:
140
Assets/Scripts/View/ProgramView.cs
Normal file
140
Assets/Scripts/View/ProgramView.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class ProgramView : MonoBehaviour
|
||||
{
|
||||
// --- 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 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 closeProgramListButton;
|
||||
|
||||
// --- Presenter에게 보낼 이벤트들 ---
|
||||
public event Action<string> OnCreateProgramClicked;
|
||||
public event Action OnLoadProgramListRequested; // '불러오기' 버튼 클릭
|
||||
public event Action<string> OnProgramSelectedToLoad;
|
||||
public event Action OnSaveClicked;
|
||||
public event Action OnAddPointClicked;
|
||||
|
||||
void Start()
|
||||
{
|
||||
loadProgramButton.onClick.AddListener(() => OnLoadProgramListRequested?.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);
|
||||
|
||||
programListPanel.SetActive(false);
|
||||
loadProgramButton.gameObject.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);
|
||||
}
|
||||
|
||||
private void HandleLoadIconClick()
|
||||
{
|
||||
loadProgramButton.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
// Presenter가 호출할 오류 메시지 표시 함수
|
||||
public void ShowMessage(string message)
|
||||
{
|
||||
Debug.LogWarning(message);
|
||||
}
|
||||
|
||||
public void DisplayProgram(RobotProgram program)
|
||||
{
|
||||
//if (program == null)
|
||||
//{
|
||||
// currentProgramIdText.text = "No Program Loaded";
|
||||
// endpointListText.text = "";
|
||||
// return;
|
||||
//}
|
||||
|
||||
//currentProgramIdText.text = "Current: " + program.programId;
|
||||
|
||||
//System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
||||
//for (int i = 0; i < program.endpointPositions.Count; i++)
|
||||
//{
|
||||
// sb.AppendLine($"P{i + 1}: {program.endpointPositions[i].ToString("F2")}");
|
||||
//}
|
||||
//endpointListText.text = sb.ToString();
|
||||
}
|
||||
|
||||
public void ShowProgramList(List<string> programIds)
|
||||
{
|
||||
foreach (Transform child in programButtonContent)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void HideProgramList()
|
||||
{
|
||||
programListPanel.SetActive(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user