GameVsJam/3d Prototyp/Assets/Scripts/UiController.cs

123 lines
4.1 KiB
C#
Raw Normal View History

2024-04-06 18:08:54 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
2024-04-07 00:09:53 +02:00
using Interaction;
2024-04-06 18:08:54 +02:00
using TMPro;
using UnityEngine;
2024-04-08 21:24:13 +02:00
using UnityEngine.SceneManagement;
2024-04-07 00:09:53 +02:00
using UnityEngine.Serialization;
2024-04-06 18:08:54 +02:00
using UnityEngine.UI;
public class UiController : MonoBehaviour
{
2024-04-07 00:09:53 +02:00
[FormerlySerializedAs("_pickupper")]
2024-04-06 18:08:54 +02:00
[Header("Objects")]
[SerializeField]
2024-04-07 00:09:53 +02:00
private InteractionHandler interactionHandler;
2024-04-06 18:08:54 +02:00
[Header("UI Elements")]
[SerializeField]
private GameObject _actionDisplay;
[SerializeField]
private TextMeshProUGUI _actionText;
[SerializeField]
private Button _prevActionButton;
[SerializeField]
private Button _nextActionButton;
2024-04-08 19:08:37 +02:00
[SerializeField]
private Image _progressBarImage;
[SerializeField]
private Image _progressBarBorder;
2024-04-06 18:08:54 +02:00
2024-04-08 19:08:37 +02:00
[SerializeField] private TextMeshProUGUI _progressText;
[SerializeField] private TextMeshProUGUI _deadlineText;
[SerializeField] private TextMeshProUGUI _currentDateText;
[SerializeField] private TextMeshProUGUI _predictedEndText;
[SerializeField] private Gradient _deadlineTextColors;
2024-04-08 21:24:13 +02:00
public GameObject WinScreen;
public GameObject LoseScreen;
2024-04-09 02:47:54 +02:00
public GameObject StartScreen;
2024-04-08 19:08:37 +02:00
2024-04-06 18:08:54 +02:00
void Update()
{
2024-04-09 02:47:54 +02:00
StartScreen.SetActive(!GameManager.Instance.IsStarted);
2024-04-06 18:08:54 +02:00
UpdateActionDisplay();
2024-04-08 19:08:37 +02:00
UpdateProgressBar();
UpdateDeadlineDateStuffTexts();
2024-04-08 21:24:13 +02:00
WinScreen.SetActive(GameManager.Instance.Won);
LoseScreen.SetActive(GameManager.Instance.Lost);
2024-04-08 19:08:37 +02:00
}
private void UpdateProgressBar()
{
Vector3 scale = _progressBarImage.rectTransform.localScale;
scale.x = (float)GameManager.Instance.GameProgress;
_progressBarImage.rectTransform.localScale = scale;
_progressBarImage.pixelsPerUnitMultiplier = _progressBarBorder.pixelsPerUnitMultiplier * scale.x;
_progressText.text = $"Entwicklungsfortschritt: {GameManager.Instance.GameProgress:##0%}";
}
private void UpdateDeadlineDateStuffTexts()
{
_currentDateText.text = $"Aktuelle Zeit: {TimeManager.Instance.CurrentDate: dddd dd.MM.yy hh U\\hr}";
_deadlineText.text = $"Deadline: {TimeManager.Instance.Deadline: dddd dd.MM.yy hh U\\hr}";
2024-04-08 20:33:29 +02:00
_predictedEndText.text = $"Vorraussichtlich fertig: {(TimeManager.Instance.PredictedEndDate == DateTime.MaxValue ? "Nie" : TimeManager.Instance.PredictedEndDate.ToString("dddd dd.MM.yy hh U\\hr"))}";
2024-04-08 19:08:37 +02:00
_predictedEndText.color = _deadlineTextColors.Evaluate(TimeManager.Instance.PredictedMissesDeadline ? 0.0f : 1.0f);
2024-04-06 18:08:54 +02:00
}
private void UpdateActionDisplay()
{
2024-04-07 00:09:53 +02:00
bool show = interactionHandler.InteractionsInRange.Count > 0;
2024-04-06 18:08:54 +02:00
_actionDisplay.SetActive(show);
if (!show)
return;
2024-04-07 00:09:53 +02:00
switch (interactionHandler.SelectedAction)
{
case PickupInteractible pickup:
_actionText.text = $"Hebe {pickup.Name} auf";
break;
case UseInteractible usable:
_actionText.text = usable.UseText;
break;
case GiveItemInteractible giveItem:
_actionText.text = $"Gebe {GameManager.Instance.Player.CarriedItem?.Name ?? "keinen Gegenstand"} an {giveItem.Developer.Name}";
break;
default:
_actionText.text = $"Unbekannte Aktion";
break;
// case InteractibleType.Use:
// _actionText.text = $"{_pickupper.Selected.Name} benutzen";
// break;
// case InteractibleType.Give:
// _actionText.text = $"An {_pickupper.Selected.Name} geben";
// break;
}
2024-04-06 18:08:54 +02:00
2024-04-07 00:09:53 +02:00
//_prevActionButton.interactable = _pickupper.CanSelectPrevious;
//_nextActionButton.interactable = _pickupper.CanSelectNext;
2024-04-06 18:08:54 +02:00
}
2024-04-08 21:24:13 +02:00
public void Replay()
{
string currentSceneName = SceneManager.GetActiveScene().name;
SceneManager.LoadScene(currentSceneName);
}
public void Exit()
{
2024-04-09 02:47:54 +02:00
//UnityEditor.EditorApplication.isPlaying = false;
2024-04-08 21:24:13 +02:00
Application.Quit();
}
2024-04-06 18:08:54 +02:00
}