clean up ui
This commit is contained in:
@@ -29,8 +29,10 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
public event UpdateUIHandler UpdateUIEvent;
|
||||
|
||||
[InfoBox("If a space was generated without any puzzles in it, the engine will try generating another new space. To prevent infinite loops, the amount of retries is bound.")]
|
||||
public int maxSpaceGenerationTries;
|
||||
public Vector3 roomOffset;
|
||||
public int maxSpaceGenerationTries = 1000;
|
||||
[Tooltip("The engine will try to generate a room that takes approximately this many seconds to complete.")]
|
||||
public float initialTargetTime = 5 * 60;
|
||||
public Vector3 roomOffset = new(0, 1000, 0);
|
||||
[Required] public EngineTheme theme;
|
||||
|
||||
public int NumberOfRooms => _rooms.Count;
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using EscapeRoomEngine.Engine.Runtime.Measurements;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.UI;
|
||||
using UnityEngine;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
||||
|
||||
3
Assets/Engine/Runtime/UI.meta
Normal file
3
Assets/Engine/Runtime/UI.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62339e229fef456eb708b30d13ec8d91
|
||||
timeCreated: 1671030929
|
||||
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using EscapeRoomEngine.Engine.Runtime.Measurements;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime
|
||||
namespace EscapeRoomEngine.Engine.Runtime.UI
|
||||
{
|
||||
public enum GameState
|
||||
{
|
||||
@@ -26,20 +27,23 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
}
|
||||
private static GameControl _foundGameControl;
|
||||
|
||||
[BoxGroup("Internal")]
|
||||
[SerializeField]
|
||||
private Button startButton, stopButton, pauseButton, resumeButton, addTimeButton, removeTimeButton;
|
||||
[BoxGroup("Internal")]
|
||||
[SerializeField]
|
||||
private Text timeText;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private Button startButton, stopButton, pauseButton, addTimeButton, removeTimeButton;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private Text timeText, targetTimeText, estimateTimeText;
|
||||
|
||||
[HideInInspector] public GameState gameState = GameState.Stopped;
|
||||
|
||||
private float _timeElapsed;
|
||||
private float _timeElapsed, _targetTime;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_targetTime = Engine.DefaultEngine.initialTargetTime;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetGamemasterTimeText(_timeElapsed);
|
||||
SetTimeText();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -49,16 +53,15 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
{
|
||||
_timeElapsed += Time.deltaTime;
|
||||
|
||||
SetGamemasterTimeText(_timeElapsed);
|
||||
SetTimeText();
|
||||
}
|
||||
|
||||
// Enable or disable buttons
|
||||
startButton.interactable = gameState == GameState.Stopped;
|
||||
stopButton.interactable = gameState != GameState.Stopped;
|
||||
pauseButton.interactable = gameState == GameState.Running;
|
||||
resumeButton.interactable = gameState == GameState.Paused;
|
||||
pauseButton.interactable = gameState is GameState.Running or GameState.Paused;
|
||||
addTimeButton.interactable = gameState != GameState.Stopped;
|
||||
removeTimeButton.interactable = gameState != GameState.Stopped && _timeElapsed >= 10;
|
||||
removeTimeButton.interactable = gameState != GameState.Stopped && _targetTime >= _timeElapsed + 60;
|
||||
}
|
||||
|
||||
#region Time Controls
|
||||
@@ -89,12 +92,18 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
|
||||
public void PauseGame()
|
||||
{
|
||||
gameState = GameState.Paused;
|
||||
}
|
||||
|
||||
public void ResumeGame()
|
||||
{
|
||||
gameState = GameState.Running;
|
||||
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
|
||||
switch (gameState)
|
||||
{
|
||||
case GameState.Running:
|
||||
gameState = GameState.Paused;
|
||||
pauseButton.GetComponent<PauseButton>().Paused = true;
|
||||
break;
|
||||
case GameState.Paused:
|
||||
gameState = GameState.Running;
|
||||
pauseButton.GetComponent<PauseButton>().Paused = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,32 +112,20 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
/// <param name="seconds">The amount of seconds that will be added to the time. Can be negative to remove time.</param>
|
||||
public void ChangeTime(int seconds)
|
||||
{
|
||||
if (_timeElapsed + seconds >= 0)
|
||||
if (_targetTime + seconds >= _timeElapsed)
|
||||
{
|
||||
_timeElapsed += seconds;
|
||||
_targetTime += seconds;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetGamemasterTimeText(float time)
|
||||
private void SetTimeText()
|
||||
{
|
||||
if (timeText != null)
|
||||
{
|
||||
timeText.text = TimeToText(time);
|
||||
}
|
||||
timeText.text = TimeToText(_timeElapsed);
|
||||
targetTimeText.text = TimeToText(_targetTime);
|
||||
estimateTimeText.text = TimeToText(_timeElapsed);
|
||||
}
|
||||
|
||||
private static string TimeToText(float time)
|
||||
{
|
||||
var minutes = (int) (time / 60);
|
||||
var seconds = (int) Math.Ceiling(time - minutes * 60);
|
||||
if (seconds == 60)
|
||||
{
|
||||
minutes += 1;
|
||||
seconds = 0;
|
||||
}
|
||||
|
||||
return $"{minutes:D2}:{seconds:D2}";
|
||||
}
|
||||
private static string TimeToText(float time) => $"{time.ToTimeSpan():mm':'ss}";
|
||||
|
||||
#endregion
|
||||
|
||||
19
Assets/Engine/Runtime/UI/PauseButton.cs
Normal file
19
Assets/Engine/Runtime/UI/PauseButton.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.UI
|
||||
{
|
||||
public class PauseButton : MonoBehaviour
|
||||
{
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private Image icon;
|
||||
[BoxGroup("Internal")] [SerializeField]
|
||||
private Sprite pauseIcon, resumeIcon;
|
||||
|
||||
public bool Paused
|
||||
{
|
||||
set => icon.sprite = value ? resumeIcon : pauseIcon;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Engine/Runtime/UI/PauseButton.cs.meta
Normal file
3
Assets/Engine/Runtime/UI/PauseButton.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 453c346d9a6f46828b7fc21944890efa
|
||||
timeCreated: 1671030945
|
||||
Reference in New Issue
Block a user