154 lines
4.7 KiB
C#
154 lines
4.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using WI;
|
|
using TMPro;
|
|
using SFB;
|
|
//using static UnityEditor.Progress;
|
|
|
|
namespace CHN
|
|
{
|
|
public class Panel_Library : PanelBase, ISingle
|
|
{
|
|
private GridLayoutGroup Panel_MachineFilter;
|
|
private ScrollRect ScrollView_MachineList;
|
|
private Button Button_Library;
|
|
private Button Button_Close;
|
|
|
|
private UI_LibraryButton prf_LibraryButton;
|
|
private UI_FilterButton prf_FilterToggle;
|
|
|
|
private Dictionary<string, UI_FilterButton> filterToItem = new Dictionary<string, UI_FilterButton>();
|
|
private List<UI_FilterButton> filters = new List<UI_FilterButton>();
|
|
|
|
public UI_FilterButton pre_labelButton;
|
|
public UI_LibraryButton pre_libraryButton;
|
|
|
|
public Action<string> onClickLabelButton;
|
|
public Action<UI_LibraryButton> onClickLibraryButton;
|
|
public Action<UI_LibraryButton> onDeselectLibraryButton;
|
|
public Action onClose;
|
|
public Action<string> onClickLibraryOpenButton;
|
|
public Action<string> onClickLibraryCloseButton;
|
|
|
|
|
|
public Vector3 originPos;
|
|
public Vector3 downPos;
|
|
|
|
public float fadeTime;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
prf_LibraryButton = Resources.Load<UI_LibraryButton>("Prefabs/UI/PRF_UI_LibraryButton");
|
|
prf_FilterToggle = Resources.Load<UI_FilterButton>("Prefabs/UI/PRF_UI_FilterButton");
|
|
Button_Library.onClick.AddListener(OnClickLibraryButton);
|
|
Button_Close.onClick.AddListener(OnClickCloseButton);
|
|
|
|
originPos = rectTransform.position;
|
|
downPos = new Vector3(originPos.x, originPos.y - rectTransform.rect.height, originPos.z);
|
|
}
|
|
|
|
public void UpdateFileterList(string[] filters)
|
|
{
|
|
foreach (var item in filterToItem)
|
|
{
|
|
Destroy(item.Value.gameObject);
|
|
}
|
|
filterToItem.Clear();
|
|
this.filters.Clear();
|
|
|
|
for (int i = 0; i < filters.Length; ++i)
|
|
{
|
|
CreateFilterToggle(filters[i]);
|
|
}
|
|
OnClickLabelButton(this.filters[0]);
|
|
}
|
|
|
|
UI_FilterButton CreateFilterToggle(string label)
|
|
{
|
|
var btn = Instantiate(prf_FilterToggle, Panel_MachineFilter.transform);
|
|
btn.SettingButton(label);
|
|
btn.onClickButton += OnClickLabelButton;
|
|
filterToItem.Add(label, btn);
|
|
filters.Add(btn);
|
|
return btn;
|
|
}
|
|
private void OnClickLabelButton(UI_FilterButton filterLabel)
|
|
{
|
|
if(pre_labelButton != null)
|
|
{
|
|
pre_labelButton.ResetColor();
|
|
}
|
|
pre_labelButton = filterLabel;
|
|
pre_labelButton.SetColor();
|
|
|
|
onClickLabelButton?.Invoke(pre_labelButton.label);
|
|
}
|
|
|
|
public void OnClickLibraryButton()
|
|
{
|
|
onClickLibraryOpenButton?.Invoke("¶óÀ̺귯¸®");
|
|
}
|
|
public void OnClickCloseButton()
|
|
{
|
|
onClickLibraryCloseButton?.Invoke("¶óÀ̺귯¸®");
|
|
}
|
|
public void Open()
|
|
{
|
|
StopAllCoroutines();
|
|
StartCoroutine(MoveAnimation(originPos));
|
|
}
|
|
public void Close()
|
|
{
|
|
onClose?.Invoke();
|
|
StopAllCoroutines();
|
|
StartCoroutine(MoveAnimation(downPos));
|
|
}
|
|
|
|
public void AddLibrarayButtons(HashSet<Machine> machines)
|
|
{
|
|
ScrollView_MachineList.Clear();
|
|
|
|
List<Machine> sortedMachines = new List<Machine>(machines);
|
|
sortedMachines.Sort((x, y) => x.code.CompareTo(y.code));
|
|
|
|
foreach (var machine in sortedMachines)
|
|
{
|
|
var machineButton = Instantiate(prf_LibraryButton, ScrollView_MachineList.content);
|
|
machineButton.SettingButton(machine);
|
|
machineButton.onClickButton += OnClickLibraryButton;
|
|
}
|
|
}
|
|
|
|
|
|
private void OnClickLibraryButton(UI_LibraryButton machineButton)
|
|
{
|
|
if (pre_libraryButton != null)
|
|
{
|
|
onDeselectLibraryButton?.Invoke(pre_libraryButton);
|
|
}
|
|
pre_libraryButton = machineButton;
|
|
onClickLibraryButton?.Invoke(pre_libraryButton);
|
|
}
|
|
|
|
IEnumerator MoveAnimation(Vector3 targetPos)
|
|
{
|
|
float timer = 0f;
|
|
float percent = 0f;
|
|
|
|
while (percent < 1)
|
|
{
|
|
timer += Time.deltaTime;
|
|
percent = timer / fadeTime;
|
|
rectTransform.position = Vector3.Lerp(rectTransform.position, targetPos, percent);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|