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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cce45d5e80938340961575a1e91eb41
|
||||
@@ -0,0 +1,51 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public sealed class FurnacePanelUIView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text metalText;
|
||||
[SerializeField] private TMP_Text selectedRecipeText;
|
||||
[SerializeField] private TMP_Text statusText;
|
||||
[SerializeField] private TMP_Text remainingTimeText;
|
||||
[SerializeField] private Image metalImage;
|
||||
[SerializeField] private Image progressImage;
|
||||
[SerializeField] private Button startButton;
|
||||
|
||||
public void Render(
|
||||
float storedMetal,
|
||||
float metalCapacity,
|
||||
SmeltingRecipe selectedRecipe,
|
||||
FurnaceState state,
|
||||
float processProgress,
|
||||
float remainingSeconds,
|
||||
bool canStart)
|
||||
{
|
||||
if (metalText != null)
|
||||
metalText.text = $"METAL {storedMetal:0.#} / {metalCapacity:0.#}";
|
||||
|
||||
if (metalImage != null)
|
||||
metalImage.fillAmount = metalCapacity > 0f ? storedMetal / metalCapacity : 0f;
|
||||
|
||||
if (selectedRecipeText != null)
|
||||
{
|
||||
selectedRecipeText.text = selectedRecipe != null
|
||||
? $"{selectedRecipe.DisplayName} | {selectedRecipe.MetalCost:0.#} metal"
|
||||
: "NO RECIPE";
|
||||
}
|
||||
|
||||
if (statusText != null)
|
||||
statusText.text = state == FurnaceState.Smelting ? "SMELTING" : "READY";
|
||||
|
||||
if (progressImage != null)
|
||||
progressImage.fillAmount = processProgress;
|
||||
|
||||
if (remainingTimeText != null)
|
||||
remainingTimeText.text = state == FurnaceState.Smelting
|
||||
? $"{remainingSeconds:0.0}s"
|
||||
: string.Empty;
|
||||
|
||||
if (startButton != null)
|
||||
startButton.interactable = canStart;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 871599a5b7d016b45a74a2005a6e22e5
|
||||
Reference in New Issue
Block a user