Merge branch 'dev'
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
#nullable enable
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma;
|
||||
|
||||
partial class HighlightAction : EventAction
|
||||
partial class TutorialHighlightAction : EventAction
|
||||
{
|
||||
partial void SetHighlightProjSpecific(Entity entity, IEnumerable<Character>? targetCharacters)
|
||||
{
|
||||
if (targetCharacters != null && !targetCharacters.Contains(Character.Controlled))
|
||||
{
|
||||
return;
|
||||
}
|
||||
private static readonly Color highlightColor = Color.Orange;
|
||||
|
||||
partial void UpdateProjSpecific()
|
||||
{
|
||||
if (GameMain.GameSession?.GameMode is not TutorialMode) { return; }
|
||||
foreach (var target in ParentEvent.GetTargets(TargetTag))
|
||||
{
|
||||
SetHighlight(target);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetHighlight(Entity entity)
|
||||
{
|
||||
if (entity is Item i)
|
||||
{
|
||||
SetItemHighlight(i);
|
||||
@@ -1540,23 +1540,6 @@ namespace Barotrauma
|
||||
RemoveFromDroppedStack(allowClientExecute: true);
|
||||
}
|
||||
break;
|
||||
case EventType.SetHighlight:
|
||||
bool isTargetedForThisClient = msg.ReadBoolean();
|
||||
if (isTargetedForThisClient)
|
||||
{
|
||||
bool highlight = msg.ReadBoolean();
|
||||
ExternalHighlight = highlight;
|
||||
if (highlight)
|
||||
{
|
||||
Color highlightColor = msg.ReadColorR8G8B8A8();
|
||||
HighlightColor = highlightColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
HighlightColor = null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Exception($"Malformed incoming item event: unsupported event type {eventType}");
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#nullable enable
|
||||
using Barotrauma.Networking;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma;
|
||||
|
||||
partial class HighlightAction : EventAction
|
||||
{
|
||||
partial void SetHighlightProjSpecific(Entity entity, IEnumerable<Character>? targetCharacters)
|
||||
{
|
||||
if (entity is Item item && GameMain.Server != null)
|
||||
{
|
||||
IEnumerable<Client>? targetClients = null;
|
||||
if (targetCharacters != null)
|
||||
{
|
||||
targetClients = targetCharacters
|
||||
.Select(c => GameMain.Server.ConnectedClients.FirstOrDefault(client => client.Character == c))
|
||||
.Where(c => c != null)!;
|
||||
}
|
||||
GameMain.Server?.CreateEntityEvent(item, new Item.SetHighlightEventData(State, highlightColor, targetClients));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,20 +161,6 @@ namespace Barotrauma
|
||||
msg.WriteUInt16(droppedItem.ID);
|
||||
}
|
||||
break;
|
||||
case SetHighlightEventData highlightEventData:
|
||||
bool isTargetedForClient =
|
||||
highlightEventData.TargetClients.IsEmpty ||
|
||||
highlightEventData.TargetClients.Contains(c);
|
||||
msg.WriteBoolean(isTargetedForClient);
|
||||
if (isTargetedForClient)
|
||||
{
|
||||
msg.WriteBoolean(highlightEventData.Highlighted);
|
||||
if (highlightEventData.Highlighted)
|
||||
{
|
||||
msg.WriteColorR8G8B8A8(highlightEventData.Color);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw error($"Unsupported event type {itemEventData.GetType().Name}");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#nullable enable
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
||||
@@ -19,20 +16,4 @@ partial class Item
|
||||
Items = items.Distinct().ToImmutableArray();
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct SetHighlightEventData : IEventData
|
||||
{
|
||||
public EventType EventType => EventType.SetHighlight;
|
||||
public readonly bool Highlighted;
|
||||
public readonly Color Color;
|
||||
|
||||
public readonly ImmutableArray<Client> TargetClients;
|
||||
|
||||
public SetHighlightEventData(bool highlighted, Color color, IEnumerable<Client>? targetClients)
|
||||
{
|
||||
Highlighted = highlighted;
|
||||
Color = color;
|
||||
TargetClients = (targetClients ?? Enumerable.Empty<Client>()).ToImmutableArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,11 +140,7 @@ namespace Barotrauma
|
||||
Identifier typeName = element.Name.ToString().ToIdentifier();
|
||||
if (typeName == "TutorialSegmentAction")
|
||||
{
|
||||
typeName = nameof(EventObjectiveAction).ToIdentifier();
|
||||
}
|
||||
else if (typeName == "TutorialHighlightAction")
|
||||
{
|
||||
typeName = nameof(HighlightAction).ToIdentifier();
|
||||
typeName = "EventObjectiveAction".ToIdentifier();
|
||||
}
|
||||
actionType = Type.GetType("Barotrauma." + typeName, throwOnError: true, ignoreCase: true);
|
||||
if (actionType == null) { throw new NullReferenceException(); }
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#nullable enable
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma;
|
||||
|
||||
partial class HighlightAction : EventAction
|
||||
{
|
||||
private static readonly Color highlightColor = Color.Orange;
|
||||
|
||||
[Serialize("", IsPropertySaveable.Yes)]
|
||||
public Identifier TargetTag { get; set; }
|
||||
|
||||
[Serialize("", IsPropertySaveable.Yes, description: "Only the player controlling this character will see the highlight. If empty, all players will see it.")]
|
||||
public Identifier TargetCharacter { get; set; }
|
||||
|
||||
[Serialize(true, IsPropertySaveable.Yes)]
|
||||
public bool State { get; set; }
|
||||
|
||||
private bool isFinished;
|
||||
|
||||
public HighlightAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (isFinished) { return; }
|
||||
var targetCharacters = TargetCharacter.IsEmpty ? null : ParentEvent.GetTargets(TargetCharacter).OfType<Character>();
|
||||
foreach (var target in ParentEvent.GetTargets(TargetTag))
|
||||
{
|
||||
SetHighlightProjSpecific(target, targetCharacters);
|
||||
}
|
||||
isFinished = true;
|
||||
}
|
||||
|
||||
partial void SetHighlightProjSpecific(Entity entity, IEnumerable<Character>? targetCharacters);
|
||||
|
||||
public override bool IsFinished(ref string goToLabel) => isFinished;
|
||||
|
||||
public override void Reset() => isFinished = false;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace Barotrauma;
|
||||
|
||||
partial class TutorialHighlightAction : EventAction
|
||||
{
|
||||
[Serialize("", IsPropertySaveable.Yes)]
|
||||
public Identifier TargetTag { get; set; }
|
||||
|
||||
[Serialize(true, IsPropertySaveable.Yes)]
|
||||
public bool State { get; set; }
|
||||
|
||||
private bool isFinished;
|
||||
|
||||
public TutorialHighlightAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
|
||||
{
|
||||
if (GameMain.NetworkMember != null)
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": {nameof(TutorialHighlightAction)} is not supported in multiplayer.");
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (isFinished) { return; }
|
||||
UpdateProjSpecific();
|
||||
isFinished = true;
|
||||
}
|
||||
|
||||
partial void UpdateProjSpecific();
|
||||
|
||||
public override bool IsFinished(ref string goToLabel) => isFinished;
|
||||
|
||||
public override void Reset() => isFinished = false;
|
||||
}
|
||||
@@ -294,11 +294,6 @@ namespace Barotrauma.Extensions
|
||||
.Where(nullable => nullable.HasValue)
|
||||
.Select(nullable => nullable.Value);
|
||||
|
||||
public static IEnumerable<T> NotNull<T>(this IEnumerable<T> source) where T : class
|
||||
=> source
|
||||
.Where(nullable => nullable != null)
|
||||
.Select(nullable => nullable!);
|
||||
|
||||
public static IEnumerable<T> NotNone<T>(this IEnumerable<Option<T>> source)
|
||||
{
|
||||
foreach (var o in source)
|
||||
|
||||
@@ -23,10 +23,9 @@ namespace Barotrauma
|
||||
Upgrade = 8,
|
||||
ItemStat = 9,
|
||||
DroppedStack = 10,
|
||||
SetHighlight = 11,
|
||||
|
||||
MinValue = 0,
|
||||
MaxValue = 11
|
||||
MaxValue = 10
|
||||
}
|
||||
|
||||
public interface IEventData : NetEntityEvent.IData
|
||||
|
||||
Reference in New Issue
Block a user