184 lines
5.7 KiB
C#
184 lines
5.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using WI;
|
|
using TMPro;
|
|
using SFB;
|
|
using Newtonsoft.Json;
|
|
using System.Linq;
|
|
//using static UnityEditor.Progress;
|
|
|
|
namespace CHN
|
|
{
|
|
public class Panel_Library : PanelBase, ISingle, IPopupPanel
|
|
{
|
|
private GridLayoutGroup Panel_MachineFilter;
|
|
private ScrollRect ScrollView_MachineList;
|
|
private Button Button_Active;
|
|
private Image Image_Open;
|
|
private Image Image_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 Action<string> onClickLabelButton;
|
|
public Action<Machine> onClickLibraryButton;
|
|
public Action<Machine> onClickDeleteRegistration;
|
|
public Action<Machine> onClickCorrection;
|
|
|
|
|
|
public Vector2 originPos;
|
|
public Vector2 downPos;
|
|
|
|
public float fadeTime;
|
|
public bool isActive;
|
|
private string dataOrder;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
dataOrder = Resources.Load<TextAsset>("DataOrder").text;
|
|
prf_LibraryButton = Resources.Load<UI_LibraryButton>("Prefabs/UI/PRF_UI_LibraryButton");
|
|
prf_FilterToggle = Resources.Load<UI_FilterButton>("Prefabs/UI/PRF_UI_FilterButton");
|
|
Button_Active.onClick.AddListener(OnClickActiveButton);
|
|
|
|
originPos = rectTransform.anchoredPosition;
|
|
downPos = originPos - new Vector2(0f, rectTransform.rect.height);
|
|
|
|
isActive = true;
|
|
}
|
|
|
|
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 OnClickActiveButton()
|
|
{
|
|
if (!isActive)
|
|
{
|
|
Open();
|
|
}
|
|
else
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
public void Open()
|
|
{
|
|
isActive = true;
|
|
Image_Open.gameObject.SetActive(false);
|
|
Image_Close.gameObject.SetActive(true);
|
|
|
|
StopAllCoroutines();
|
|
StartCoroutine(MoveAnimation(originPos));
|
|
}
|
|
public void Close()
|
|
{
|
|
isActive = false;
|
|
Image_Open.gameObject.SetActive(true);
|
|
Image_Close.gameObject.SetActive(false);
|
|
|
|
StopAllCoroutines();
|
|
StartCoroutine(MoveAnimation(downPos));
|
|
}
|
|
|
|
public void AddLibrarayButtons(HashSet<Machine> machines)
|
|
{
|
|
ScrollView_MachineList.Clear();
|
|
|
|
var sortedMachines = SortListByWorkcd(machines);
|
|
|
|
foreach (var machine in sortedMachines)
|
|
{
|
|
var machineButton = Instantiate(prf_LibraryButton, ScrollView_MachineList.content);
|
|
machineButton.SettingButton(machine);
|
|
machineButton.onClickButton += OnClickLibraryButton;
|
|
machineButton.onClickDeleteRegistration += OnClickDeleteRegistrationButton;
|
|
machineButton.onClickCorrection += OnClickCorrectionButton;
|
|
}
|
|
}
|
|
public List<Machine> SortListByWorkcd(HashSet<Machine> machines)
|
|
{
|
|
List<string> workcdOrder = JsonConvert.DeserializeObject<List<string>>(dataOrder);
|
|
|
|
Dictionary<string, int> orderMap = workcdOrder
|
|
.Select((workcd, index) => new { workcd, index })
|
|
.ToDictionary(x => x.workcd, x => x.index);
|
|
|
|
return machines
|
|
.OrderBy(field => orderMap[field.code])
|
|
.ToList();
|
|
}
|
|
|
|
|
|
private void OnClickLibraryButton(UI_LibraryButton machineButton)
|
|
{
|
|
onClickLibraryButton?.Invoke(machineButton.machine);
|
|
}
|
|
private void OnClickDeleteRegistrationButton(UI_LibraryButton machineButton)
|
|
{
|
|
onClickDeleteRegistration?.Invoke(machineButton.machine);
|
|
}
|
|
private void OnClickCorrectionButton(UI_LibraryButton machineButton)
|
|
{
|
|
onClickCorrection?.Invoke(machineButton.machine);
|
|
}
|
|
|
|
IEnumerator MoveAnimation(Vector2 targetPos)
|
|
{
|
|
float timer = 0f;
|
|
float percent = 0f;
|
|
|
|
while (percent < 1)
|
|
{
|
|
timer += Time.deltaTime;
|
|
percent = timer / fadeTime;
|
|
rectTransform.anchoredPosition = Vector2.Lerp(rectTransform.anchoredPosition, targetPos, percent);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|