forked from Shardstone/trail-into-darkness
added a disfunctionalk popup system
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using Jovian.PopupSystem;
|
||||
using Jovian.PopupSystem.UI;
|
||||
using Jovian.SaveSystem;
|
||||
using Jovian.ZoneSystem;
|
||||
using Nox.Core;
|
||||
@@ -39,6 +41,7 @@ namespace Nox.Game {
|
||||
private TimeHandler timeHandler;
|
||||
private PartyInventoryHandler partyInventoryHandler;
|
||||
private PartyGuiView partyGuiView;
|
||||
private IPopupSystem popupSystem;
|
||||
|
||||
public AdventurePlayMode(
|
||||
PlatformSettings platformSettings,
|
||||
@@ -134,7 +137,16 @@ namespace Nox.Game {
|
||||
|
||||
if(partyGuiView == null && guiReferences.partyMemberSlotPrefab != null) {
|
||||
var portraitsHolder = Addressables.LoadAssetAsync<PortraitsHolder>("PortraitsHolder").WaitForCompletion();
|
||||
partyGuiView = new PartyGuiView(guiReferences.portraitsContainer, guiReferences.partyMemberSlotPrefab, portraitsHolder);
|
||||
|
||||
if(popupSystem == null) {
|
||||
var popupSettings = Addressables.LoadAssetAsync<PopupSettings>("PopupSettings").WaitForCompletion();
|
||||
var popupViewPrefab = Addressables.LoadAssetAsync<GameObject>("PopupReferencePrefab").WaitForCompletion().GetComponent<PopupReference>();
|
||||
var guiCanvas = guiReferences.GetComponentInParent<Canvas>().transform;
|
||||
popupSystem = new PopupSystem(popupSettings, popupViewPrefab, guiCanvas);
|
||||
popupSystem.RegisterCategory(PopupCategory.Character, priority: 10);
|
||||
}
|
||||
|
||||
partyGuiView = new PartyGuiView(guiReferences.portraitsContainer, guiReferences.partyMemberSlotPrefab, portraitsHolder, popupSystem);
|
||||
partyGuiView.Initialize(partyDefinition);
|
||||
}
|
||||
|
||||
@@ -151,6 +163,7 @@ namespace Nox.Game {
|
||||
partyMovementHandler.Tick();
|
||||
adventureView.Tick();
|
||||
partyGuiView?.Tick();
|
||||
popupSystem?.Tick(Time.deltaTime);
|
||||
|
||||
if(inputActions.UI.PauseMenu.WasPerformedThisFrame()) {
|
||||
gameDataState.ChangePlayMode(PlayMode.PauseMenu);
|
||||
@@ -178,6 +191,7 @@ namespace Nox.Game {
|
||||
cameraController?.Dispose();
|
||||
partyMovementHandler?.Dispose();
|
||||
partyGuiView?.Dispose();
|
||||
popupSystem?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using Jovian.Logger;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Jovian.PopupSystem;
|
||||
using Jovian.PopupSystem.UI;
|
||||
using Nox.UI;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -8,15 +12,17 @@ namespace Nox.Game.UI {
|
||||
private readonly Transform portraitsContainer;
|
||||
private readonly PartyMemberSlot slotPrefab;
|
||||
private readonly PortraitsHolder portraitsHolder;
|
||||
private readonly IPopupSystem popupSystem;
|
||||
private readonly List<PartyMemberSlot> activeSlots = new();
|
||||
|
||||
private PartyDefinition trackedParty;
|
||||
private int trackedMemberCount;
|
||||
|
||||
public PartyGuiView(Transform portraitsContainer, PartyMemberSlot slotPrefab, PortraitsHolder portraitsHolder) {
|
||||
public PartyGuiView(Transform portraitsContainer, PartyMemberSlot slotPrefab, PortraitsHolder portraitsHolder, IPopupSystem popupSystem = null) {
|
||||
this.portraitsContainer = portraitsContainer;
|
||||
this.slotPrefab = slotPrefab;
|
||||
this.portraitsHolder = portraitsHolder;
|
||||
this.popupSystem = popupSystem;
|
||||
}
|
||||
|
||||
public void Initialize(PartyDefinition party) {
|
||||
@@ -74,6 +80,72 @@ namespace Nox.Game.UI {
|
||||
UpdateSlotStats(slot, member);
|
||||
activeSlots.Add(slot);
|
||||
}
|
||||
|
||||
// Initialize all popup triggers under the container
|
||||
if(popupSystem != null) {
|
||||
popupSystem.InitializeTriggersInChildren(portraitsContainer, trigger => {
|
||||
var slot = trigger.GetComponentInParent<PartyMemberSlot>();
|
||||
if(slot == null) {
|
||||
return;
|
||||
}
|
||||
var slotIndex = activeSlots.IndexOf(slot);
|
||||
if(slotIndex < 0 || slotIndex >= trackedParty.members.Count) {
|
||||
return;
|
||||
}
|
||||
var member = trackedParty.members[slotIndex];
|
||||
trigger.Initialize(popupSystem, builder => BuildCharacterPopup(builder, member));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildCharacterPopup(PopupContentBuilder builder, CharacterDefinition member) {
|
||||
GlobalLogger.LogInfo($"Building character popup for {member.Name}", LogCategory.UI);
|
||||
|
||||
// Header
|
||||
builder.AddHeader(member.Name);
|
||||
builder.AddText($"{member.Race} {member.Class}", "#CCCCCC");
|
||||
builder.AddText($"Role: {member.Role}");
|
||||
builder.AddSeparator();
|
||||
|
||||
// Stats
|
||||
if(member.Stats?.stats != null) {
|
||||
foreach(var stat in member.Stats.stats) {
|
||||
if(stat.stat == StatType.None) {
|
||||
continue;
|
||||
}
|
||||
builder.AddStat(stat.stat.ToString(), stat.value);
|
||||
}
|
||||
}
|
||||
builder.AddSeparator();
|
||||
|
||||
// Attributes
|
||||
if(member.Attributes?.attributes != null) {
|
||||
foreach(var attr in member.Attributes.attributes) {
|
||||
if(attr.attribute == AttributeType.None) {
|
||||
continue;
|
||||
}
|
||||
builder.AddStat(attr.attribute.ToString(), attr.value);
|
||||
}
|
||||
}
|
||||
builder.AddSeparator();
|
||||
|
||||
// Perks
|
||||
if(member.Perks?.perks != null && member.Perks.perks.Count > 0) {
|
||||
builder.AddText("Perks", "#FFD700");
|
||||
foreach(var perk in member.Perks.perks) {
|
||||
builder.AddText($" {perk.Name}");
|
||||
}
|
||||
builder.AddSeparator();
|
||||
}
|
||||
|
||||
// Modifiers
|
||||
if(member.Modifiers?.modifiers is { Count: > 0 }) {
|
||||
builder.AddText("Modifiers", "#87CEEB");
|
||||
foreach(var mod in member.Modifiers.modifiers) {
|
||||
var target = mod.Target != null ? mod.Target.ToString() : "";
|
||||
builder.AddText($" {mod.Name} ({mod.Operation} {mod.Value} {target})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateSlotStats(PartyMemberSlot slot, CharacterDefinition member) {
|
||||
|
||||
Reference in New Issue
Block a user