Files
ChunilENG/Assets/Scripts/UI/Canvas_Popup.cs
2025-11-21 13:07:13 +09:00

184 lines
6.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using WI;
using static MQTT;
namespace CHN
{
public class Canvas_Popup : CanvasBase
{
public List<IPopupPanel> popupPanels = new List<IPopupPanel>();
public List<PanelBase> activePanels = new List<PanelBase>();
public List<IProductionPanel> productionPanels = new List<IProductionPanel>();
public PanelBase currentProductionPanel;
public Panel_CompleteAlramHistory panel_completealramhistory;
public Panel_Menu panel_menu;
public Panel_Library panel_library;
public Panel_WorkConditionAnalysis panel_workconditionanalysis;
public Panel_WorkTimeAnalysis panel_worktimeanalysis;
public Panel_InjectionProduction panel_injectionproduction;
public Panel_AssemblyProduction panel_assemblyproduction;
public Panel_WorkProgressStatus panel_workprogressstatus;
public Panel_FinalInspection panel_finalinspection;
public Panel_AssemblyProgressLine panel_assemblyprogressline;
public Panel_MoldDepartment panel_molddepartment;
public Panel_MiniMap panel_minimap;
public Panel_ThermostatControl panel_thermostatcontrol;
public Panel_ExitProgram panel_exitprogram;
public Panel_ToolBarAlarm panel_toolbaralarm;
public Panel_DetailDashBoard panel_detaildashboard;
public Panel_TotalProduction panel_totalproduction;
public Panel_FloorControl panel_floorcontrol;
public Panel_ProductionStatus panel_productionstatus;
public Panel_MachineData panel_machinedata;
public Panel_MachineDeleteRegistration panel_machinedeleteregistration;
public Panel_MachineCorrection panel_machinecorrection;
public Panel_BuildingDeleteRegistration panel_buildingdeleteregistration;
public Panel_BuildingCorrection panel_buildingcorrection;
//public Panel_MachineDashBoard panel_machinedashboard;
public RectTransform dashboardPoint;
private Dictionary<Machine, Panel_MachineDashBoard> machineDashboardTable = new();
public Action<Machine> onClickSimple;
public Action<Machine> onClickDetail;
public Action<Machine,HashSet<string>> simpleView;
public Action onCloseDashBoard;
public Panel_MachineDashBoard currentDashBoard;
public Action onOpenDashboard;
public bool isSimpleDashboardAcitve;
public void ActiveSimpleDashBoard()
{
isSimpleDashboardAcitve = true;
}
public void DeactiveSimpleDashBoard()
{
isSimpleDashboardAcitve = false;
}
public override void AfterAwake()
{
var asset = Resources.Load<Panel_MachineDashBoard>("Prefabs/UI/PRF_Panel_MachineDashBoard");
var machines = FindObjectsByType<Machine>(FindObjectsSortMode.None);
foreach (var machine in machines)
{
var dashboard = Instantiate<Panel_MachineDashBoard>(asset, transform);
dashboard.Close();
dashboard.simpleView += simpleView;
machineDashboardTable.Add(machine, dashboard);
dashboard.onClickSimple += onClickSimple;
dashboard.onClickDetail += onClickDetail;
dashboard.onClose += onCloseDashBoard;
}
productionPanels.Add(panel_assemblyproduction);
productionPanels.Add(panel_injectionproduction);
productionPanels.Add(panel_workprogressstatus);
productionPanels.Add(panel_totalproduction);
productionPanels.Add(panel_finalinspection);
productionPanels.Add(panel_assemblyprogressline);
productionPanels.Add(panel_molddepartment);
popupPanels = transform.GetComponentsInChildren<IPopupPanel>(true).ToList();
popupPanels.RemoveAll(item => productionPanels.Contains(item as IProductionPanel));
}
public void MachineDashBoardOpen(Machine clickMachine)
{
if (!isSimpleDashboardAcitve)
return;
if (currentDashBoard != null)
{
currentDashBoard.SetActive(false);
}
currentDashBoard = machineDashboardTable[clickMachine];
currentDashBoard.OpenFromMachine(clickMachine);
SetDashBoardPosition();
onOpenDashboard?.Invoke();
}
public void SimpleView(Machine machine, SimpleField data)
{
machineDashboardTable[machine].SimpleInfoView(data);
}
public void DetailView(Machine machine, SimpleField data)
{
machineDashboardTable[machine].DetailInfoView(machine, data);
}
public void CurrentDashoboardClose()
{
if (currentDashBoard != null)
{
currentDashBoard.Clear();
currentDashBoard.SetActive(false);
}
}
public void SetDashBoardPosition()
{
currentDashBoard.transform.position = dashboardPoint.transform.position;
currentDashBoard.transform.SetAsLastSibling();
}
public Panel_ControlSetting panel_controlsetting;
public Panel_ProtocolSetting panel_protocolsetting;
public void SetChangedProductionPanel(PanelBase newPanel)
{
if (currentProductionPanel == newPanel)
return;
if (currentProductionPanel is IProductionPanel oldProductionPanel)
{
oldProductionPanel.Close();
}
currentProductionPanel = newPanel;
if (currentProductionPanel is IProductionPanel newProductionPanel)
{
newProductionPanel.Open();
}
}
public void SetDeactivePopupPanels()
{
if (activePanels.Count > 0)
return;
foreach (var popupPanel in popupPanels)
{
if (popupPanel is PanelBase panel && panel.gameObject.activeSelf)
{
activePanels.Add(panel);
if (popupPanel is IPopupPanel popup)
{
popup.Close();
}
}
}
}
public void SetActivePopupPanels()
{
foreach (var panel in activePanels)
{
if (panel is IPopupPanel popup)
{
popup.Open();
}
}
activePanels.Clear();
}
}
}