add guard rails into content selection

This commit is contained in:
Nilton Constantino 2026-07-08 17:22:17 +01:00
parent 012842b482
commit aa43d5d199
No known key found for this signature in database
3 changed files with 22 additions and 6 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Intrepid.Diagnostics;
using Intrepid.GameManagers;
using Intrepid.Gameplay.Entities.Player.PDA.Events;
using Intrepid.Gameplay.Entities.Player.PDA.Inputs;
@ -35,9 +36,16 @@ namespace Intrepid.Gameplay.Entities.Player.PDA.UI
if (inputs.Enter())
{
var currentContentFocus = contents.CurrentContentFocus;
if (currentContentFocus is null)
{
DLogger.LogError("we should not be able to enter an application without a content reference");
return;
}
Proxy.Instance.EventBus.Raise(new PDAEnterApplicationEvent
{
ContentTag = contents.CurrentContentFocus.ContentTag,
ContentTag = currentContentFocus.ContentTag,
});
}
}

View File

@ -45,7 +45,10 @@ namespace Intrepid.Gameplay.Entities.Player.PDA.UI
private bool ChangingContentFocus { get; set; }
private List<PDAContentTag> ContentTagsToLoad { get; set; }
private GameObjectPool<PDAContentReferenceUI> Pool { get; set; }
public PDAContentReferenceUI CurrentContentFocus => contentReferences[currentIndex];
public PDAContentReferenceUI CurrentContentFocus => contentReferences
.TryGetValue(currentIndex, out var contentReference)
? contentReference
: null;
private void OnValidate()
{
@ -184,7 +187,7 @@ namespace Intrepid.Gameplay.Entities.Player.PDA.UI
private void GoLeft()
{
if (ChangingContentFocus) return;
if (ChangingContentFocus || numberOfContents <= 0) return;
ContentUnFocus();
if (currentIndex <= 0)
{
@ -205,7 +208,7 @@ namespace Intrepid.Gameplay.Entities.Player.PDA.UI
private void GoRight()
{
if (ChangingContentFocus) return;
if (ChangingContentFocus || numberOfContents <= 0) return;
ContentUnFocus();
if (currentIndex >= numberOfContents - 1)
{
@ -226,6 +229,12 @@ namespace Intrepid.Gameplay.Entities.Player.PDA.UI
private void ContentFocus()
{
var contentReference = CurrentContentFocus;
if (contentReference is null)
{
title.text = "";
description.NotOperational();
return;
}
title.text = contentReference.Title;
description.Operational(contentReference.Description);
contentReference.Focus();
@ -237,7 +246,7 @@ namespace Intrepid.Gameplay.Entities.Player.PDA.UI
description.NotOperational();
if (currentIndex < contentReferences.Count)
{
CurrentContentFocus.UnFocus();
CurrentContentFocus?.UnFocus();
}
}

View File

@ -1,4 +1,3 @@
using System;
using Intrepid.Gameplay.Codex.UI.Components;
using Intrepid.Gameplay.Codex.UI.Controllers;
using Intrepid.Utilities;