26.03.11 - 설비 알람 인코딩 오류 수정 - 설비 상태 인코딩 오류 수정 - AI 시뮬레이션 결과 인코딩 오류 수정 - 생산 현황판 인코딩 오류 수정 - TopMenu 인코딩 오류 수정
237 lines
7.6 KiB
C#
237 lines
7.6 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using Cysharp.Threading.Tasks;
|
|
using AZTECHWB.Constants;
|
|
using AZTECHWB.Management;
|
|
using AZTECHWB.Command;
|
|
using AZTECHWB.Core;
|
|
|
|
namespace AZTECHWB.UI
|
|
{
|
|
public class LibraryPanel : UIPanel
|
|
{
|
|
private RectTransform rectTransform;
|
|
private Button Button_Active;
|
|
private TMP_InputField InputField_MachineSearch;
|
|
private ScrollRect ScrollView_MachineList;
|
|
|
|
private RectTransform Hide;
|
|
private RectTransform Mark;
|
|
|
|
private Vector2 originPos;
|
|
public Vector2 downPos;
|
|
|
|
public float fadeTime;
|
|
private bool isActive;
|
|
private string dataOrder;
|
|
|
|
private string currentSearchKeyword = "";
|
|
|
|
private HashSet<Machine> allMachines = new();
|
|
private HashSet<Machine> filteredMachines = new();
|
|
|
|
|
|
private LibraryButton libraryButton;
|
|
private Dictionary<string, LibraryButton> addLibraryButtons = new();
|
|
private LibraryButton currentLibraryButton;
|
|
|
|
private FilterButton[] filterButtons;
|
|
private FilterButton currentLabelButton;
|
|
|
|
public override async UniTask Init()
|
|
{
|
|
rectTransform = GetComponent<RectTransform>();
|
|
Button_Active = transform.GetComponentInChildren<Button>();
|
|
InputField_MachineSearch = transform.GetComponentInChildren<TMP_InputField>();
|
|
ScrollView_MachineList = transform.GetComponentInChildren<ScrollRect>();
|
|
|
|
Hide = GetElement<RectTransform>(nameof(Hide));
|
|
Mark = GetElement<RectTransform>(nameof(Mark));
|
|
|
|
dataOrder = Resources.Load<TextAsset>($"{ResourceURL.dataFolderPath}DataOrder").text;
|
|
libraryButton = Resources.Load<LibraryButton>($"{ResourceURL.uiPrefabFolderPath}{nameof(LibraryButton)}");
|
|
filterButtons = transform.GetComponentsInChildren<FilterButton>(true);
|
|
|
|
Button_Active.onClick.AddListener(OnClickActiveButton);
|
|
InputField_MachineSearch.onValueChanged.AddListener(OnSearchKeywordChanged);
|
|
|
|
originPos = rectTransform.anchoredPosition;
|
|
isActive = true;
|
|
|
|
await UniTask.CompletedTask;
|
|
}
|
|
public void InitializedLibraryPanel()
|
|
{
|
|
InputField_MachineSearch.text = string.Empty;
|
|
InputField_MachineSearch.ForceLabelUpdate();
|
|
|
|
if (currentLibraryButton != null)
|
|
{
|
|
currentLibraryButton.Image_Selected.gameObject.SetActive(false);
|
|
currentLibraryButton = null;
|
|
}
|
|
|
|
SetFilterButton(0);
|
|
}
|
|
private void SetFilterButton(int index)
|
|
{
|
|
OnClickFilterButton(filterButtons[index]);
|
|
}
|
|
|
|
public void UpdateFileterList(string[] filters)
|
|
{
|
|
for (int i = 0; i < filters.Length; ++i)
|
|
{
|
|
var label = filters[i];
|
|
|
|
var btn = FindFilterButton(label);
|
|
btn.SettingButton(label);
|
|
btn.onClickButton += OnClickFilterButton;
|
|
}
|
|
SetFilterButton(0);
|
|
}
|
|
private FilterButton FindFilterButton(string label)
|
|
{
|
|
FilterButton button = filterButtons.ToList().Find(a => a.label == label);
|
|
return button;
|
|
}
|
|
private void OnClickFilterButton(FilterButton filterLabel)
|
|
{
|
|
if (currentLabelButton != null)
|
|
{
|
|
currentLabelButton.OnDeselected();
|
|
}
|
|
currentLabelButton = filterLabel;
|
|
currentLabelButton.OnSelected();
|
|
|
|
var libraryManager = AZTECHSceneMain.Instance.GetManager<LibraryManager>();
|
|
libraryManager.LibraryFiltering(currentLabelButton.label);
|
|
}
|
|
|
|
public void OnClickActiveButton()
|
|
{
|
|
if (!isActive)
|
|
{
|
|
Open();
|
|
}
|
|
else
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
public override void Open()
|
|
{
|
|
isActive = true;
|
|
Mark.gameObject.SetActive(false);
|
|
Hide.gameObject.SetActive(true);
|
|
|
|
StopAllCoroutines();
|
|
StartCoroutine(MoveAnimation(originPos));
|
|
}
|
|
public override void Close()
|
|
{
|
|
isActive = false;
|
|
Mark.gameObject.SetActive(true);
|
|
Hide.gameObject.SetActive(false);
|
|
|
|
StopAllCoroutines();
|
|
StartCoroutine(MoveAnimation(downPos));
|
|
}
|
|
public void SetAllMachines(HashSet<Machine> machines)
|
|
{
|
|
allMachines = machines;
|
|
}
|
|
private void OnSearchKeywordChanged(string keyword)
|
|
{
|
|
currentSearchKeyword = keyword;
|
|
|
|
if (string.IsNullOrWhiteSpace(currentSearchKeyword))
|
|
{
|
|
UpdateLibraryMachineList(filteredMachines);
|
|
}
|
|
else
|
|
{
|
|
var matched = allMachines
|
|
.Where(machine => machine.machineName.Contains(currentSearchKeyword, StringComparison.OrdinalIgnoreCase))
|
|
.ToHashSet();
|
|
|
|
UpdateLibraryMachineList(matched);
|
|
}
|
|
}
|
|
private void UpdateLibraryMachineList(HashSet<Machine> targetMachines)
|
|
{
|
|
var content = ScrollView_MachineList.content;
|
|
var sorted = SortListByWorkcd(targetMachines);
|
|
|
|
foreach (var item in addLibraryButtons.Values)
|
|
{
|
|
item.gameObject.SetActive(false);
|
|
}
|
|
|
|
foreach (var machine in sorted)
|
|
{
|
|
if (!addLibraryButtons.ContainsKey(machine.machineName))
|
|
{
|
|
var btn = Instantiate(libraryButton, content);
|
|
btn.SettingButton(machine);
|
|
btn.onClickButton += OnClickLibraryButton;
|
|
addLibraryButtons.Add(machine.machineName, btn);
|
|
}
|
|
else
|
|
{
|
|
addLibraryButtons[machine.machineName].gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void AddLibrarayButtons(HashSet<Machine> machines)
|
|
{
|
|
filteredMachines = machines;
|
|
if (string.IsNullOrWhiteSpace(currentSearchKeyword))
|
|
{
|
|
UpdateLibraryMachineList(filteredMachines);
|
|
}
|
|
}
|
|
public List<Machine> SortListByWorkcd(HashSet<Machine> machines)
|
|
{
|
|
var workcdOrder = JsonConvert.DeserializeObject<List<string>>(dataOrder);
|
|
var orderMap = workcdOrder.Select((workcd, index) => new { workcd, index }).ToDictionary(x => x.workcd, x => x.index);
|
|
|
|
return machines.OrderBy(field => orderMap[field.machineName]).ToList();
|
|
}
|
|
|
|
|
|
private void OnClickLibraryButton(LibraryButton machineButton)
|
|
{
|
|
if (currentLibraryButton != null)
|
|
{
|
|
currentLibraryButton.Image_Selected.gameObject.SetActive(false);
|
|
}
|
|
currentLibraryButton = machineButton;
|
|
currentLibraryButton.Image_Selected.gameObject.SetActive(true);
|
|
|
|
new SelectedMachineCommand(machineButton.machine, false).Execute();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
} |