forked from Shardstone/trail-into-darkness
First commit on my server, yey!
This commit is contained in:
56
Assets/Code/GameState/UI/AdventureView.cs
Normal file
56
Assets/Code/GameState/UI/AdventureView.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Nox.Core;
|
||||
|
||||
namespace Nox.Game.UI {
|
||||
public class AdventureView : IMenuView {
|
||||
private readonly GameDataState gameDataState;
|
||||
private readonly GuiReferences guiReferences;
|
||||
private readonly InputSystem_Actions inputActions;
|
||||
private readonly AdventureData adventureData;
|
||||
private readonly AdventureSettings adventureSettings;
|
||||
private DayPhase dayPhase = DayPhase.Midnight;
|
||||
private int currentDay;
|
||||
|
||||
public AdventureView(
|
||||
GameDataState gameDataState,
|
||||
GuiReferences guiReferences,
|
||||
InputSystem_Actions inputActions,
|
||||
AdventureData adventureData,
|
||||
AdventureSettings adventureSettings) {
|
||||
this.gameDataState = gameDataState;
|
||||
this.guiReferences = guiReferences;
|
||||
this.inputActions = inputActions;
|
||||
this.adventureData = adventureData;
|
||||
this.adventureSettings = adventureSettings;
|
||||
}
|
||||
private void InvokePauseMenu() {
|
||||
gameDataState.ChangePlayMode(PlayMode.PauseMenu);
|
||||
}
|
||||
|
||||
public void Initialize() {
|
||||
guiReferences.pauseMenuButton.onClick.AddListener(InvokePauseMenu);
|
||||
guiReferences.dayText.text = $"Day {adventureData.currentDay}, {adventureData.currentDayPhase.ToString()}";
|
||||
guiReferences.suppliesBar.fillAmount = (float)adventureData.suppliesAvailable / adventureSettings.maxSupplies;
|
||||
guiReferences.suppliesText.text = $"{adventureData.suppliesAvailable}/{adventureSettings.maxSupplies}";
|
||||
}
|
||||
|
||||
public void Show() {
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public void Hide() {
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public void Tick() {
|
||||
if(dayPhase != adventureData.currentDayPhase) {
|
||||
dayPhase = adventureData.currentDayPhase;
|
||||
guiReferences.dayText.text = $"Day {adventureData.currentDay}, {adventureData.currentDayPhase.ToString()}";
|
||||
}
|
||||
|
||||
if(currentDay != adventureData.currentDay) {
|
||||
currentDay = adventureData.currentDay;
|
||||
guiReferences.dayText.text = $"Day {adventureData.currentDay}, {adventureData.currentDayPhase.ToString()}";
|
||||
guiReferences.suppliesBar.fillAmount = (float)adventureData.suppliesAvailable / adventureSettings.maxSupplies;
|
||||
guiReferences.suppliesText.text = $"{adventureData.suppliesAvailable}/{adventureSettings.maxSupplies}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Code/GameState/UI/AdventureView.cs.meta
Normal file
3
Assets/Code/GameState/UI/AdventureView.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd45a685ea554bd7ad15745f836a6de9
|
||||
timeCreated: 1772572300
|
||||
13
Assets/Code/GameState/UI/GuiReferences.cs
Normal file
13
Assets/Code/GameState/UI/GuiReferences.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Nox.Game.UI {
|
||||
public class GuiReferences : MonoBehaviour {
|
||||
public Transform portraitsContainer;
|
||||
public Image suppliesBar;
|
||||
public TextMeshProUGUI suppliesText;
|
||||
public Button pauseMenuButton;
|
||||
public TextMeshProUGUI dayText;
|
||||
}
|
||||
}
|
||||
2
Assets/Code/GameState/UI/GuiReferences.cs.meta
Normal file
2
Assets/Code/GameState/UI/GuiReferences.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ba89f0d55be1ed4bb61a320344f706d
|
||||
9
Assets/Code/GameState/UI/PauseMenuPrefabs.cs
Normal file
9
Assets/Code/GameState/UI/PauseMenuPrefabs.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Nox.Game.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Nox.Game {
|
||||
[CreateAssetMenu(fileName = "PauseMenuPrefabs", menuName = "Nox/PauseMenuPrefabs")]
|
||||
public class PauseMenuPrefabs : ScenePrefabs {
|
||||
public PauseMenuReferences pauseMenuReferencesPrefab;
|
||||
}
|
||||
}
|
||||
3
Assets/Code/GameState/UI/PauseMenuPrefabs.cs.meta
Normal file
3
Assets/Code/GameState/UI/PauseMenuPrefabs.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d58af5e98665467fb7d66e4822775e75
|
||||
timeCreated: 1772571122
|
||||
10
Assets/Code/GameState/UI/PauseMenuReferences.cs
Normal file
10
Assets/Code/GameState/UI/PauseMenuReferences.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Nox.Game.UI {
|
||||
public class PauseMenuReferences : MonoBehaviour {
|
||||
public Button resumeButton;
|
||||
public Button exitButton;
|
||||
public Button saveButton;
|
||||
}
|
||||
}
|
||||
2
Assets/Code/GameState/UI/PauseMenuReferences.cs.meta
Normal file
2
Assets/Code/GameState/UI/PauseMenuReferences.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c881c3395da5194b926ef10f819edd7
|
||||
68
Assets/Code/GameState/UI/PauseMenuView.cs
Normal file
68
Assets/Code/GameState/UI/PauseMenuView.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Nox.Core;
|
||||
using Jovian.SaveSystem;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using Object = UnityEngine.Object;
|
||||
using PlayMode = Nox.Core.PlayMode;
|
||||
|
||||
namespace Nox.Game.UI {
|
||||
public class PauseMenuView: IMenuView {
|
||||
private readonly GameDataState gameDataState;
|
||||
private readonly ISaveSystem saveSystem;
|
||||
private readonly Func<NoxSavedDataSet?> captureSaveData;
|
||||
private PauseMenuReferences? pauseMenu;
|
||||
private PauseMenuPrefabs? pauseMenuPrefabs;
|
||||
|
||||
public PauseMenuView(GameDataState gameDataState, ISaveSystem saveSystem, Func<NoxSavedDataSet?> captureSaveData) {
|
||||
this.gameDataState = gameDataState;
|
||||
this.saveSystem = saveSystem;
|
||||
this.captureSaveData = captureSaveData;
|
||||
pauseMenu ??= Object.FindFirstObjectByType<PauseMenuReferences>();
|
||||
if(pauseMenu) {
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize() {
|
||||
pauseMenuPrefabs ??= Addressables.LoadAssetAsync<PauseMenuPrefabs>("PauseMenuPrefabs").WaitForCompletion();
|
||||
if(!pauseMenu) {
|
||||
pauseMenu = Object.Instantiate(pauseMenuPrefabs.pauseMenuReferencesPrefab);
|
||||
pauseMenu?.resumeButton.onClick.AddListener(() => {gameDataState.ChangePlayMode(gameDataState.PreviousPlayMode);});
|
||||
pauseMenu?.exitButton.onClick.AddListener(() => {
|
||||
OnSaveRequested();
|
||||
gameDataState.ChangeGameState(GameState.MainMenu);
|
||||
});
|
||||
pauseMenu?.saveButton.onClick.AddListener(OnSaveRequested);
|
||||
}
|
||||
Show();
|
||||
}
|
||||
|
||||
private void OnSaveRequested() {
|
||||
if(string.IsNullOrEmpty(gameDataState.activeSessionId)) {
|
||||
Debug.LogWarning("[PauseMenuView] No active session. Cannot save.");
|
||||
return;
|
||||
}
|
||||
|
||||
var data = captureSaveData();
|
||||
if(data == null) {
|
||||
Debug.LogWarning("[PauseMenuView] No save data to capture.");
|
||||
return;
|
||||
}
|
||||
|
||||
saveSystem.Save(gameDataState.activeSessionId, data, SaveSlotType.Auto);
|
||||
}
|
||||
|
||||
public void Show() {
|
||||
pauseMenu?.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Hide() {
|
||||
pauseMenu?.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void Tick() { }
|
||||
}
|
||||
|
||||
}
|
||||
3
Assets/Code/GameState/UI/PauseMenuView.cs.meta
Normal file
3
Assets/Code/GameState/UI/PauseMenuView.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83affb8078c54010ab278ed4be7f15ef
|
||||
timeCreated: 1772373065
|
||||
110
Assets/Code/GameState/UI/ScreenFadeTransition.cs
Normal file
110
Assets/Code/GameState/UI/ScreenFadeTransition.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using Nox.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Nox.Game.UI {
|
||||
public class ScreenFadeTransition : MonoBehaviour, ISceneTransition {
|
||||
private enum FadeState {
|
||||
Idle,
|
||||
FadingOut,
|
||||
FadingIn
|
||||
}
|
||||
|
||||
private const float DefaultFadeDuration = 0.3f;
|
||||
private const int CanvasSortOrder = 999;
|
||||
|
||||
private CanvasGroup canvasGroup;
|
||||
private FadeState fadeState = FadeState.Idle;
|
||||
private float fadeTimer;
|
||||
private float fadeDuration = DefaultFadeDuration;
|
||||
private Action onFadeComplete;
|
||||
|
||||
public bool IsTransitioning => fadeState != FadeState.Idle;
|
||||
|
||||
public void Awake() {
|
||||
DontDestroyOnLoad(gameObject);
|
||||
CreateFadeCanvas();
|
||||
canvasGroup.alpha = 0f;
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
}
|
||||
|
||||
public void FadeOut(Action onComplete = null) {
|
||||
if(fadeState == FadeState.FadingOut) {
|
||||
return;
|
||||
}
|
||||
onFadeComplete = onComplete;
|
||||
fadeState = FadeState.FadingOut;
|
||||
fadeTimer = 0f;
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
}
|
||||
|
||||
public void FadeIn(Action onComplete = null) {
|
||||
if(fadeState == FadeState.FadingIn) {
|
||||
return;
|
||||
}
|
||||
onFadeComplete = onComplete;
|
||||
fadeState = FadeState.FadingIn;
|
||||
fadeTimer = 0f;
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
if(fadeState == FadeState.Idle) {
|
||||
return;
|
||||
}
|
||||
|
||||
fadeTimer += Time.unscaledDeltaTime;
|
||||
float t = Mathf.Clamp01(fadeTimer / fadeDuration);
|
||||
|
||||
switch(fadeState) {
|
||||
case FadeState.FadingOut:
|
||||
canvasGroup.alpha = t;
|
||||
if(t >= 1f) {
|
||||
CompleteFade();
|
||||
}
|
||||
break;
|
||||
case FadeState.FadingIn:
|
||||
canvasGroup.alpha = 1f - t;
|
||||
if(t >= 1f) {
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
CompleteFade();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CompleteFade() {
|
||||
fadeState = FadeState.Idle;
|
||||
fadeTimer = 0f;
|
||||
var callback = onFadeComplete;
|
||||
onFadeComplete = null;
|
||||
callback?.Invoke();
|
||||
}
|
||||
|
||||
private void CreateFadeCanvas() {
|
||||
var canvasObject = new GameObject("FadeCanvas");
|
||||
canvasObject.transform.SetParent(transform);
|
||||
|
||||
var canvas = canvasObject.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
canvas.sortingOrder = CanvasSortOrder;
|
||||
|
||||
canvasObject.AddComponent<CanvasScaler>();
|
||||
|
||||
canvasGroup = canvasObject.AddComponent<CanvasGroup>();
|
||||
|
||||
var imageObject = new GameObject("FadeImage");
|
||||
imageObject.transform.SetParent(canvasObject.transform, false);
|
||||
|
||||
var image = imageObject.AddComponent<Image>();
|
||||
image.color = Color.black;
|
||||
image.raycastTarget = true;
|
||||
|
||||
var rectTransform = image.rectTransform;
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.anchorMax = Vector2.one;
|
||||
rectTransform.offsetMin = Vector2.zero;
|
||||
rectTransform.offsetMax = Vector2.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Code/GameState/UI/ScreenFadeTransition.cs.meta
Normal file
2
Assets/Code/GameState/UI/ScreenFadeTransition.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64d1d810d0e4d0d45bebf3cc276703af
|
||||
Reference in New Issue
Block a user