Added Furnance and smelting
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
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;
|
||||
|
||||
GlobalUIController.Instance?.Register(this);
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (furnace != null)
|
||||
furnace.Changed -= Refresh;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user