This commit is contained in:
2022-12-15 23:29:02 +01:00
parent 95220bec08
commit 4f57b57a00
24 changed files with 1695 additions and 81 deletions

View File

@@ -1,4 +1,6 @@
using EscapeRoomEngine.Engine.Runtime.Measurements;
using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Measurements;
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using NaughtyAttributes;
using UnityEngine;
@@ -15,20 +17,31 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
{
public static GameControl Instance { get; private set; }
[SerializeField]
private float uiUpdateInterval = 1, planUpdateInterval = 1;
[BoxGroup("Internal")] [SerializeField]
private Button startButton, stopButton, pauseButton, addTimeButton, removeTimeButton;
[BoxGroup("Internal")] [SerializeField]
private Text timeText, roomTimeText, estimateTimeText, targetTimeText;
private Text timeText, roomTimeText, estimateTimeText, targetTimeText, percentileText;
[BoxGroup("Internal")] [SerializeField]
private float uiUpdateInterval = 1;
private PuzzlePlan puzzlePlan;
[HideInInspector] public GameState gameState = GameState.Stopped;
public PuzzleModuleDescription CurrentPuzzle
{
set => puzzlePlan.CurrentPuzzle = value;
}
public List<PuzzleModuleDescription> PlannedPuzzles
{
set => puzzlePlan.Puzzles = value;
}
public float TimeElapsed { get; private set; }
public float TimeInRoom { get; set; }
public float TargetTime { get; private set; }
public float EstimatedTimeRoom { get; private set; }
private float _previousUIUpdate;
private float _previousUIUpdate, _previousPlanUpdate;
private void Awake()
{
@@ -57,6 +70,15 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
_previousUIUpdate = Time.time;
SetTimeText();
UpdateStats();
}
// update plan
if (Time.time > _previousPlanUpdate + planUpdateInterval)
{
_previousPlanUpdate = Time.time;
Engine.Instance.PlanPuzzles();
}
// enable or disable buttons
@@ -129,15 +151,21 @@ namespace EscapeRoomEngine.Engine.Runtime.UI
Engine.Instance.CurrentRoom.Match(some: room =>
{
estimateTimeText.text = TimeToText(
TimeElapsed - TimeInRoom
+ Mathf.Max(TimeInRoom, Measure.AverageTime(room))
+ Engine.Instance.EstimatedTimeRemaining);
EstimatedTimeRoom =
TimeElapsed - TimeInRoom + Mathf.Max(TimeInRoom, Measure.EstimateTime(room));
estimateTimeText.text = TimeToText(EstimatedTimeRoom + Engine.Instance.EstimatedTimeRemaining);
});
}
private void UpdateStats()
{
percentileText.text = PercentageToText(Measure.SessionPercentile());
}
private static string TimeToText(float time) => $"{time.ToTimeSpan():mm':'ss}";
private static string PercentageToText(float percentage) => $"{percentage:P1}";
#endregion
#region Measurements

View File

@@ -0,0 +1,56 @@
using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Modules;
using NaughtyAttributes;
using UnityEngine;
using UnityEngine.UI;
namespace EscapeRoomEngine.Engine.Runtime.UI
{
public class PuzzlePlan : MonoBehaviour
{
[SerializeField]
private Vector2 entryOffset;
[BoxGroup("Internal")] [SerializeField]
private RectTransform plan;
[BoxGroup("Internal")] [SerializeField]
private PuzzlePlanEntry currentPuzzle, entryPrefab;
[BoxGroup("Internal")] [SerializeField]
private GameObject currentPuzzleTitle, planTitle;
public PuzzleModuleDescription CurrentPuzzle
{
set
{
currentPuzzleTitle.SetActive(true);
currentPuzzle.gameObject.SetActive(true);
// set the current puzzle
currentPuzzle.Puzzle = value;
}
}
public List<PuzzleModuleDescription> Puzzles
{
set
{
planTitle.SetActive(true);
plan.gameObject.SetActive(true);
// remove the old children
foreach (RectTransform child in plan)
{
Destroy(child.gameObject);
}
// add the new children
var offset = Vector2.zero;
value.ForEach(puzzle =>
{
var entry = Instantiate(entryPrefab, plan, false);
entry.Position = offset;
entry.Puzzle = puzzle;
offset += entryOffset;
});
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ad95894771b8478591e5f5abbe1d0244
timeCreated: 1671133031

View File

@@ -0,0 +1,32 @@
using System;
using EscapeRoomEngine.Engine.Runtime.Measurements;
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using NaughtyAttributes;
using UnityEngine;
using UnityEngine.UI;
namespace EscapeRoomEngine.Engine.Runtime.UI
{
public class PuzzlePlanEntry : MonoBehaviour
{
[BoxGroup("Internal")] [Required] [SerializeField]
private Text puzzleName, estimatedTime;
public Vector2 Position
{
set
{
puzzleName.rectTransform.anchoredPosition = value;
}
}
public PuzzleModuleDescription Puzzle
{
set
{
puzzleName.text = value.puzzleName;
estimatedTime.text = $"Time Estimate: {Measure.EstimateTime(value).ToTimeSpan():mm':'ss}";
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8ef80fc9016c4a46a190769f3b771bfa
timeCreated: 1671136597