Added full cycle, now the gui shows the proper party data

This commit is contained in:
Sebastian Bularca
2026-04-06 01:27:10 +02:00
parent 50832c491c
commit 236bf1a647
11 changed files with 621 additions and 597 deletions

View File

@@ -147,6 +147,7 @@ namespace Nox.Game {
Role = Role,
Race = Race,
Class = Class,
PortraitIndex = PortraitIndex,
Attributes = new EntityAttributes {
attributes = Attributes?.attributes?.AsValueEnumerable().Select(a => new Attribute(a.attribute, a.value)).ToArray()
},

View File

@@ -3,6 +3,7 @@ using Jovian.ZoneSystem;
using Nox.Core;
using Nox.Platform;
using Nox.Game.UI;
using Nox.UI;
using ZLinq;
using UnityEngine;
using UnityEngine.AddressableAssets;
@@ -37,6 +38,7 @@ namespace Nox.Game {
private AdventureSettings adventureSettings;
private TimeHandler timeHandler;
private PartyInventoryHandler partyInventoryHandler;
private PartyGuiView partyGuiView;
public AdventurePlayMode(
PlatformSettings platformSettings,
@@ -130,6 +132,12 @@ namespace Nox.Game {
adventureView ??= new AdventureView(gameDataState, guiReferences, inputActions, adventureData, adventureSettings);
adventureView.Initialize();
if(partyGuiView == null && guiReferences.partyMemberSlotPrefab != null) {
var portraitsHolder = Addressables.LoadAssetAsync<PortraitsHolder>("PortraitsHolder").WaitForCompletion();
partyGuiView = new PartyGuiView(guiReferences.portraitsContainer, guiReferences.partyMemberSlotPrefab, portraitsHolder);
partyGuiView.Initialize(partyDefinition);
}
IsGameModeInitialized = true;
}
@@ -142,6 +150,7 @@ namespace Nox.Game {
partyInventoryHandler.Tick();
partyMovementHandler.Tick();
adventureView.Tick();
partyGuiView?.Tick();
if(inputActions.UI.PauseMenu.WasPerformedThisFrame()) {
gameDataState.ChangePlayMode(PlayMode.PauseMenu);
@@ -168,6 +177,7 @@ namespace Nox.Game {
public void Dispose() {
cameraController?.Dispose();
partyMovementHandler?.Dispose();
partyGuiView?.Dispose();
}
}

View File

@@ -5,6 +5,7 @@ using UnityEngine.UI;
namespace Nox.Game.UI {
public class GuiReferences : MonoBehaviour {
public Transform portraitsContainer;
public PartyMemberSlot partyMemberSlotPrefab;
public Image suppliesBar;
public TextMeshProUGUI suppliesText;
public Button pauseMenuButton;

View File

@@ -0,0 +1,107 @@
using System.Collections.Generic;
using Nox.UI;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Nox.Game.UI {
public class PartyGuiView {
private readonly Transform portraitsContainer;
private readonly PartyMemberSlot slotPrefab;
private readonly PortraitsHolder portraitsHolder;
private readonly List<PartyMemberSlot> activeSlots = new();
private PartyDefinition trackedParty;
private int trackedMemberCount;
public PartyGuiView(Transform portraitsContainer, PartyMemberSlot slotPrefab, PortraitsHolder portraitsHolder) {
this.portraitsContainer = portraitsContainer;
this.slotPrefab = slotPrefab;
this.portraitsHolder = portraitsHolder;
}
public void Initialize(PartyDefinition party) {
trackedParty = party;
trackedMemberCount = 0;
RebuildSlots();
}
public void Tick() {
if(trackedParty == null) {
return;
}
// Rebuild if member count changed
if(trackedParty.members.Count != trackedMemberCount) {
RebuildSlots();
}
// Update dynamic values (health, mana)
for(int i = 0; i < activeSlots.Count && i < trackedParty.members.Count; i++) {
var member = trackedParty.members[i];
var slot = activeSlots[i];
UpdateSlotStats(slot, member);
}
}
private void RebuildSlots() {
// Clear existing
foreach(var slot in activeSlots) {
Object.Destroy(slot.gameObject);
}
activeSlots.Clear();
if(trackedParty?.members == null) {
return;
}
trackedMemberCount = trackedParty.members.Count;
foreach(var member in trackedParty.members) {
var slot = Object.Instantiate(slotPrefab, portraitsContainer);
slot.gameObject.SetActive(true);
// Portrait
if(portraitsHolder != null && portraitsHolder.portraits.Length > 0) {
var idx = Mathf.Clamp(member.PortraitIndex, 0, portraitsHolder.portraits.Length - 1);
slot.portrait.sprite = portraitsHolder.portraits[idx];
}
// Name
if(slot.nameText != null) {
slot.nameText.text = member.Name;
}
UpdateSlotStats(slot, member);
activeSlots.Add(slot);
}
}
private static void UpdateSlotStats(PartyMemberSlot slot, CharacterDefinition member) {
var health = member.Stats.GetValue(StatType.Health);
var mana = member.Stats.GetValue(StatType.Mana);
if(slot.healthBar != null) {
slot.healthBar.fillAmount = Mathf.Clamp01(health / 100f);
}
if(slot.healthText != null) {
slot.healthText.text = health.ToString();
}
if(slot.manaBar != null) {
slot.manaBar.fillAmount = Mathf.Clamp01(mana / 100f);
}
if(slot.manaText != null) {
slot.manaText.text = mana.ToString();
}
}
public void Dispose() {
foreach(var slot in activeSlots) {
if(slot != null) {
Object.Destroy(slot.gameObject);
}
}
activeSlots.Clear();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a95c5f20aad5baf498f79d7d61049e06

View File

@@ -0,0 +1,14 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Nox.Game.UI {
public class PartyMemberSlot : MonoBehaviour {
public Image portrait;
public Image healthBar;
public Image manaBar;
public TextMeshProUGUI nameText;
public TextMeshProUGUI healthText;
public TextMeshProUGUI manaText;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7cc43dfd6e3e7d644a6cb462d8094164