move puzzle implementations out of engine

This commit is contained in:
2023-03-22 09:44:17 +01:00
parent e1bfecbd4b
commit 30d8f986df
70 changed files with 82 additions and 46 deletions

View File

@@ -0,0 +1,22 @@
using NaughtyAttributes;
using UnityEngine;
using UnityEngine.UI;
namespace EscapeRoomEngine.Engine.Runtime.UI.Elements
{
/// <summary>
/// This component is responsible to change the icon of the pause button depending on the game state.
/// </summary>
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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 453c346d9a6f46828b7fc21944890efa
timeCreated: 1671030945

View File

@@ -0,0 +1,61 @@
using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Modules.Description;
using NaughtyAttributes;
using UnityEngine;
namespace EscapeRoomEngine.Engine.Runtime.UI.Elements
{
/// <summary>
/// The puzzle plan UI component that displays the current puzzle plan in the game master window.
/// </summary>
public class PuzzlePlan : MonoBehaviour
{
/// <summary>
/// The distance from one entry to the next.
/// </summary>
[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,34 @@
using EscapeRoomEngine.Engine.Runtime.Measurements;
using EscapeRoomEngine.Engine.Runtime.Modules.Description;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using NaughtyAttributes;
using UnityEngine;
using UnityEngine.UI;
namespace EscapeRoomEngine.Engine.Runtime.UI.Elements
{
/// <summary>
/// An entry in the <see cref="PuzzlePlan"/> UI component that displays the name and estimated time for a puzzle.
/// </summary>
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