init
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace VOID.UserInterface.Game.GameLog
|
||||
{
|
||||
[Serializable]
|
||||
public class GameLogMessageUI
|
||||
{
|
||||
private VisualElement _parentElement;
|
||||
private VisualElement _templateElement;
|
||||
private Label _timeLabel;
|
||||
private Label _contentLabel;
|
||||
|
||||
public void InitNew(VisualElement parentWrapperElement, string message)
|
||||
{
|
||||
_parentElement = parentWrapperElement;
|
||||
_templateElement = GameLogUI.current.messageTemplate.CloneTree().contentContainer;
|
||||
_parentElement.Add(_templateElement);
|
||||
_timeLabel = _templateElement.Q<Label>(className: "time");
|
||||
_timeLabel.text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]";
|
||||
_contentLabel = _templateElement.Q<Label>(className: "content");
|
||||
_contentLabel.text = message;
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
_parentElement.Remove(_templateElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b47d387d194747409fe3eb3e285bfcef
|
||||
timeCreated: 1698946541
|
||||
@@ -0,0 +1,7 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" editor-extension-mode="False">
|
||||
<Style src="project://database/Assets/92%20-%20UserInterface/Generic/Game/GameLog/GameLogMessageUIStyle.uss?fileID=7433441132597879392&guid=6ff0b7b338887ab498883e9cfff6cb62&type=3#GameLogMessageUIStyle" />
|
||||
<ui:VisualElement name="root-game-log-message" class="message">
|
||||
<ui:Label tabindex="-1" text="[21:00:37]" enable-rich-text="false" class="time" />
|
||||
<ui:Label tabindex="-1" text="<u>DUMMY</u> dealt <u>5 fire</u> dmg to <u>TARGET</u> LOREM IPSUMIPSUM 123 LOREM IPSUM 456 LOREM IPSUM 789" parse-escape-sequences="true" display-tooltip-when-elided="true" class="content" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 648cfbe70d29b664a946fe7b43eebb89
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
@@ -0,0 +1,38 @@
|
||||
#root-game-log-message {
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
padding-top: 2px;
|
||||
padding-bottom: 2px;
|
||||
flex-direction: row;
|
||||
align-items: stretch;
|
||||
flex-wrap: wrap;
|
||||
align-self: stretch;
|
||||
}
|
||||
|
||||
#root-game-log-message > .time {
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
padding-left: 0;
|
||||
padding-right: 3px;
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
#root-game-log-message > .content {
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
padding-left: 0;
|
||||
padding-right: 3px;
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
white-space: normal;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ff0b7b338887ab498883e9cfff6cb62
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
|
||||
disableValidation: 0
|
||||
@@ -0,0 +1,159 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using VOID.Generic.Objects.Abstract.Events;
|
||||
using VOID.Generic.Objects.Item.Events;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
using VOID.Generic.Objects.Unit.Actions.Exceptions;
|
||||
using VOID.Generic.Objects.Unit.Events;
|
||||
using VOID.Generic.Objects.Usable.Events;
|
||||
using VOID.Generic.Objects.Wearable.Events;
|
||||
using VOID.Generic.Player;
|
||||
|
||||
namespace VOID.UserInterface.Game.GameLog
|
||||
{
|
||||
public class GameLogUI : MonoBehaviour
|
||||
{
|
||||
public static GameLogUI current { get; private set; }
|
||||
|
||||
// Configuration
|
||||
[SerializeField, MinValue(10)] private int _messageLimit = 100;
|
||||
[SerializeField] private string SENDER_PREFIX = "<b>{0}:<b> ";
|
||||
[SerializeField] private string STATUS_START_MESSAGE = "Got status <u>{0}</u> for <u>{1} turns</u>.";
|
||||
[SerializeField] private string STATUS_END_MESSAGE = "Status <u>{0}</u> ended.";
|
||||
[SerializeField] private string DEATH_MESSAGE = "Died!";
|
||||
[SerializeField] private string DAMAGED_MESSAGE = "Received <u>{0} {1}</u> damage from <u>{2}</u>.";
|
||||
[SerializeField] private string DAMAGE_MESSAGE = "Dealt <u>{0} {1}</u> damage to <u>{2}</u>.";
|
||||
[SerializeField] private string ABILITY_CAST_MESSAGE = "Casted <u>{0}</u>.";
|
||||
[SerializeField] private string TAKE_MESSAGE = "Took <u>{0}</u>.";
|
||||
[SerializeField] private string DROP_MESSAGE = "Dropped <u>{0}</u>.";
|
||||
[SerializeField] private string EQUIP_MESSAGE = "Equipped <u>{0}</u>.";
|
||||
[SerializeField] private string UNEQUIP_MESSAGE = "Unequipped <u>{0}</u>.";
|
||||
[SerializeField] private string USE_MESSAGE = "Used <u>{0}</u>.";
|
||||
[SerializeField] private string ACTION_ERROR_MESSAGE = "Action prevented: <u>{0}</u>.";
|
||||
|
||||
// Message template
|
||||
public VisualTreeAsset messageTemplate => _messageTemplate;
|
||||
[SerializeField, Required] private VisualTreeAsset _messageTemplate;
|
||||
|
||||
// Visual Elements
|
||||
private VisualElement _messageWrapper;
|
||||
private Scroller _scroller;
|
||||
private readonly List<GameLogMessageUI> _messages = new();
|
||||
|
||||
// Units which we listen to
|
||||
private UnitObject _mainUnit;
|
||||
private UnitObject _subUnit;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
current = this;
|
||||
|
||||
var uiDocument = gameObject.GetComponent<UIDocument>();
|
||||
var templateElement = uiDocument.rootVisualElement;
|
||||
_messageWrapper = templateElement.Q("message-wrapper");
|
||||
_messageWrapper.Clear();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
PlayerController.current.OnMainUnitChange += OnMainUnitChange;
|
||||
PlayerController.current.OnSubUnitChange += OnSubUnitChange;
|
||||
}
|
||||
|
||||
private void OnMainUnitChange(UnitObject unit)
|
||||
{
|
||||
if (_mainUnit) StopListenFor(_mainUnit);
|
||||
_mainUnit = unit;
|
||||
if (unit) ListenFor(unit);
|
||||
}
|
||||
|
||||
private void OnSubUnitChange(UnitObject unit)
|
||||
{
|
||||
if (_subUnit) StopListenFor(_subUnit);
|
||||
_subUnit = unit;
|
||||
if (unit) ListenFor(unit);
|
||||
}
|
||||
|
||||
private void ListenFor(UnitObject unit)
|
||||
{
|
||||
unit.basicEvents.onStatusStart.AddListener(OnStatusStart);
|
||||
unit.basicEvents.onStatusEnd.AddListener(OnStatusEnd);
|
||||
unit.basicEvents.onDeathAfter.AddListener(OnDeathAfter);
|
||||
unit.basicEvents.onDamagedAfter.AddListener(OnDamagedAfter);
|
||||
unit.unitEvents.onDamageAfter.AddListener(OnDamageAfter);
|
||||
unit.unitEvents.onStartAbilityAfter.AddListener(OnAbilityCastAfter);
|
||||
unit.unitEvents.onTakeAfter.AddListener(OnTakeAfter);
|
||||
unit.unitEvents.onDropAfter.AddListener(OnDropAfter);
|
||||
unit.unitEvents.onEquipAfter.AddListener(OnEquipAfter);
|
||||
unit.unitEvents.onUnEquipAfter.AddListener(OnUnEquipAfter);
|
||||
unit.unitEvents.onUseAfter.AddListener(OnUseAfter);
|
||||
unit.unitEvents.onActionError.AddListener(OnActionError);
|
||||
}
|
||||
|
||||
private void StopListenFor(UnitObject unit)
|
||||
{
|
||||
unit.basicEvents.onStatusStart.RemoveListener(OnStatusStart);
|
||||
unit.basicEvents.onStatusEnd.RemoveListener(OnStatusEnd);
|
||||
unit.basicEvents.onDeathAfter.RemoveListener(OnDeathAfter);
|
||||
unit.basicEvents.onDamagedAfter.RemoveListener(OnDamagedAfter);
|
||||
unit.unitEvents.onDamageAfter.RemoveListener(OnDamageAfter);
|
||||
unit.unitEvents.onStartAbilityAfter.RemoveListener(OnAbilityCastAfter);
|
||||
unit.unitEvents.onTakeAfter.RemoveListener(OnTakeAfter);
|
||||
unit.unitEvents.onDropAfter.RemoveListener(OnDropAfter);
|
||||
unit.unitEvents.onEquipAfter.RemoveListener(OnEquipAfter);
|
||||
unit.unitEvents.onUnEquipAfter.RemoveListener(OnUnEquipAfter);
|
||||
unit.unitEvents.onUseAfter.RemoveListener(OnUseAfter);
|
||||
unit.unitEvents.onActionError.RemoveListener(OnActionError);
|
||||
}
|
||||
|
||||
private void AddError(string richText)
|
||||
{
|
||||
AddMessage($"<color=#D33>{richText}</color>");
|
||||
}
|
||||
|
||||
private void AddMessage(string richText)
|
||||
{
|
||||
var message = new GameLogMessageUI();
|
||||
message.InitNew(_messageWrapper, richText);
|
||||
_messages.Add(message);
|
||||
|
||||
if (_messages.Count > _messageLimit) RemoveLastMessage();
|
||||
}
|
||||
|
||||
private void RemoveLastMessage()
|
||||
{
|
||||
var lastMessage = _messages.Last();
|
||||
lastMessage.Destroy();
|
||||
_messages.RemoveAt(_messages.Count-1);
|
||||
}
|
||||
|
||||
/* EVENTS BELOW */
|
||||
/* for register and unregister */
|
||||
|
||||
private void OnStatusStart(StatusEvent e)
|
||||
{
|
||||
if (e.status.hidden) return;
|
||||
AddMessage(string.Format(SENDER_PREFIX, e.obj.basicData.finalName) + string.Format(STATUS_START_MESSAGE, e.status.displayName, e.status.durationInTurns));
|
||||
}
|
||||
|
||||
private void OnStatusEnd(StatusEvent e)
|
||||
{
|
||||
if (e.status.hidden) return;
|
||||
AddMessage(string.Format(SENDER_PREFIX, e.obj.basicData.finalName) + string.Format(STATUS_END_MESSAGE, e.status.displayName));
|
||||
}
|
||||
|
||||
private void OnDeathAfter(DeathEvent e) => AddMessage(string.Format(SENDER_PREFIX, e.obj.basicData.finalName) + string.Format(DEATH_MESSAGE));
|
||||
private void OnDamagedAfter(DamageEvent e) => AddMessage(string.Format(SENDER_PREFIX, e.target.basicData.finalName) + string.Format(DAMAGED_MESSAGE, e.amount, e.damageType, e.attacker?.basicData.finalName ?? "unknown"));
|
||||
private void OnDamageAfter(DamageEvent e) => AddMessage(string.Format(SENDER_PREFIX, e.attacker.basicData.finalName) + string.Format(DAMAGE_MESSAGE, e.amount, e.damageType, e.target.basicData.finalName));
|
||||
private void OnAbilityCastAfter(AbilityCastEvent e) => AddMessage(string.Format(SENDER_PREFIX, e.caster.basicData.finalName) + string.Format(ABILITY_CAST_MESSAGE, e.ability.displayName));
|
||||
private void OnTakeAfter(PickEvent e) => AddMessage(string.Format(SENDER_PREFIX, e.unit.basicData.finalName) + string.Format(TAKE_MESSAGE, e.item.basicData.finalName));
|
||||
private void OnDropAfter(DropEvent e) => AddMessage(string.Format(SENDER_PREFIX, e.unit.basicData.finalName) + string.Format(DROP_MESSAGE, e.item.basicData.finalName));
|
||||
private void OnEquipAfter(EquipEvent e) => AddMessage(string.Format(SENDER_PREFIX, e.unit.basicData.finalName) + string.Format(EQUIP_MESSAGE, e.wearable.basicData.finalName));
|
||||
private void OnUnEquipAfter(UnEquipEvent e) => AddMessage(string.Format(SENDER_PREFIX, e.unit.basicData.finalName) + string.Format(UNEQUIP_MESSAGE, e.wearable.basicData.finalName));
|
||||
private void OnUseAfter(UseEvent e) => AddMessage(string.Format(SENDER_PREFIX, e.usedBy.basicData.finalName) + string.Format(USE_MESSAGE, e.usedObject.basicData.finalName));
|
||||
private void OnActionError(ActionErrorEvent e) => AddError(string.Format(SENDER_PREFIX, e.unit.basicData.finalName) + string.Format(ACTION_ERROR_MESSAGE, UnitActionErrorMessage.Get(e.cause)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 939ec691a5854e6ba2b35b9a1029c2d9
|
||||
timeCreated: 1698862707
|
||||
@@ -0,0 +1,19 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
engine="UnityEngine.UIElements" editor="UnityEditor.UIElements"
|
||||
noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||
<ui:Template name="GameLogMessageUI" src="project://database/Assets/92%20-%20UserInterface/Generic/Game/GameLog/GameLogMessageUI.uxml?fileID=9197481963319205126&guid=648cfbe70d29b664a946fe7b43eebb89&type=3#GameLogMessageUI" />
|
||||
<Style src="project://database/Assets/92%20-%20UserInterface/Generic/Game/GameLog/GameLogUIStyle.uss?fileID=7433441132597879392&guid=f8003f5e38dbaa841a5394fb4bfc6aae&type=3#GameLogUIStyle" />
|
||||
<ui:VisualElement name="root-game-log">
|
||||
<ui:ScrollView horizontal-scroller-visibility="Hidden" name="message-scroller" vertical-scroller-visibility="AlwaysVisible">
|
||||
<ui:VisualElement name="message-wrapper" style="flex-grow: 1;">
|
||||
<ui:Instance template="GameLogMessageUI" />
|
||||
<ui:Instance template="GameLogMessageUI" />
|
||||
<ui:Instance template="GameLogMessageUI" />
|
||||
<ui:Instance template="GameLogMessageUI" />
|
||||
<ui:Instance template="GameLogMessageUI" />
|
||||
<ui:Instance template="GameLogMessageUI" />
|
||||
<ui:Instance template="GameLogMessageUI" />
|
||||
</ui:VisualElement>
|
||||
</ui:ScrollView>
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3516f8d2aa647d442a6178d9a8379ee6
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
@@ -0,0 +1,20 @@
|
||||
#root-game-log {
|
||||
position: absolute;
|
||||
bottom: 70px;
|
||||
right: 5px;
|
||||
width: 450px;
|
||||
height: 300px;
|
||||
padding-left: 3px;
|
||||
padding-right: 3px;
|
||||
padding-top: 3px;
|
||||
padding-bottom: 3px;
|
||||
background-color: rgba(69, 69, 69, 0.48);
|
||||
}
|
||||
|
||||
#root-game-log > #message-scroller {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
#root-game-log > #message-scroller > #message-wrapper {
|
||||
flex-grow: 1;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8003f5e38dbaa841a5394fb4bfc6aae
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
|
||||
disableValidation: 0
|
||||
Reference in New Issue
Block a user