77 lines
1.8 KiB
C#
77 lines
1.8 KiB
C#
using UnityEngine;
|
|
|
|
public sealed class FurnacePanelUIController : MonoBehaviour, IGlobalUISectionController
|
|
{
|
|
[SerializeField] private FurnaceController furnace;
|
|
[SerializeField] private FurnacePanelUIView view;
|
|
|
|
private void Reset()
|
|
{
|
|
furnace = GetComponentInParent<FurnaceController>();
|
|
view = GetComponent<FurnacePanelUIView>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (furnace == null)
|
|
furnace = GetComponentInParent<FurnaceController>();
|
|
if (view == null)
|
|
view = GetComponent<FurnacePanelUIView>();
|
|
|
|
if (furnace != null)
|
|
furnace.Changed += Refresh;
|
|
if (view != null)
|
|
view.StartRequested += StartSmelting;
|
|
|
|
GlobalUIController.Instance?.Register(this);
|
|
|
|
Refresh();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (furnace != null)
|
|
furnace.Changed -= Refresh;
|
|
if (view != null)
|
|
view.StartRequested -= StartSmelting;
|
|
|
|
GlobalUIController.Instance?.Unregister(this);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (furnace != null && furnace.IsOperating)
|
|
Refresh();
|
|
}
|
|
|
|
public void SelectRecipe(int recipeIndex)
|
|
{
|
|
furnace?.SelectRecipe(recipeIndex);
|
|
}
|
|
|
|
public void SelectAndStartRecipe(int recipeIndex)
|
|
{
|
|
furnace?.SelectAndStartRecipe(recipeIndex);
|
|
}
|
|
|
|
public void StartSmelting()
|
|
{
|
|
furnace?.StartSmelting();
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
if (furnace == null || view == null)
|
|
return;
|
|
|
|
view.Render(
|
|
furnace.StoredMetal,
|
|
furnace.MetalCapacity,
|
|
furnace.SelectedRecipe,
|
|
furnace.State,
|
|
furnace.ProcessProgress,
|
|
furnace.RemainingSeconds,
|
|
furnace.CanStartSelectedRecipe);
|
|
}
|
|
}
|