diff --git a/Aetheria.Shared.Unity.csproj b/Aetheria.Shared.Unity.csproj index 74e3a3fee..985828c98 100644 --- a/Aetheria.Shared.Unity.csproj +++ b/Aetheria.Shared.Unity.csproj @@ -109,8 +109,8 @@ - + diff --git a/Assets/Prefabs/UI/Properties Panel/Fancy/Weapon Groups.prefab b/Assets/Prefabs/UI/Properties Panel/Fancy/Weapon Groups.prefab index 4c7acce17..77e704a12 100644 --- a/Assets/Prefabs/UI/Properties Panel/Fancy/Weapon Groups.prefab +++ b/Assets/Prefabs/UI/Properties Panel/Fancy/Weapon Groups.prefab @@ -65,7 +65,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: Stat Name + m_text: Weapon Groups m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 53555f7a2d5e745428813f1b1118734f, type: 2} m_sharedMaterial: {fileID: -2804126062856497447, guid: 53555f7a2d5e745428813f1b1118734f, diff --git a/Assets/Scenes/ARPG.unity b/Assets/Scenes/ARPG.unity index e3e1f83a0..9d198c947 100644 --- a/Assets/Scenes/ARPG.unity +++ b/Assets/Scenes/ARPG.unity @@ -5592,6 +5592,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Dialog: {fileID: 0} + DragParent: {fileID: 0} Flip: 1 Settings: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2} GameManager: {fileID: 1009503729} @@ -9907,6 +9908,11 @@ PrefabInstance: value: objectReference: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2} + - target: {fileID: 2279630453886260054, guid: aac073da6df367d499834c926930dd84, + type: 3} + propertyPath: DragParent + value: + objectReference: {fileID: 245842385} - target: {fileID: 2279630453886260054, guid: aac073da6df367d499834c926930dd84, type: 3} propertyPath: ContextMenu @@ -31053,6 +31059,11 @@ PrefabInstance: value: objectReference: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2} + - target: {fileID: 2279630453886260054, guid: aac073da6df367d499834c926930dd84, + type: 3} + propertyPath: DragParent + value: + objectReference: {fileID: 245842385} - target: {fileID: 2279630453886260054, guid: aac073da6df367d499834c926930dd84, type: 3} propertyPath: ContextMenu @@ -36242,6 +36253,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Dialog: {fileID: 0} + DragParent: {fileID: 0} Flip: 0 Settings: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2} GameManager: {fileID: 1009503729} diff --git a/Assets/Scripts/Gameplay/ActionBarSlot.cs b/Assets/Scripts/Gameplay/ActionBarSlot.cs index b871a0554..16c08517a 100644 --- a/Assets/Scripts/Gameplay/ActionBarSlot.cs +++ b/Assets/Scripts/Gameplay/ActionBarSlot.cs @@ -147,15 +147,16 @@ public class ActionBarGearBinding : ActionBarBinding public ActionBarGearBinding(Entity entity, ActionBarSlot slot, EquippedItem item, IActivatedBehavior behavior) : base(entity, slot) { Item = item; + var data = item.EquippableItem.Data.Value as EquippableItemData; Behavior = behavior; Slot.QuantityRemaining.gameObject.SetActive(false); - if(!string.IsNullOrEmpty(Item.Data.ActionBarIcon)) - { - Slot.Label.gameObject.SetActive(false); - Slot.Icon.gameObject.SetActive(true); + Slot.Icon.gameObject.SetActive(true); + Slot.Label.gameObject.SetActive(false); + if (!string.IsNullOrEmpty(Item.Data.ActionBarIcon)) Slot.Icon.texture = Resources.Load(Item.Data.ActionBarIcon.Substring("Assets/Resources/".Length).Split('.').First()); - } - else Slot.Icon.gameObject.SetActive(false); + else if (data is WeaponItemData weaponItemData) + Slot.Icon.texture = ActionGameManager.Instance.Settings.GetIcon(weaponItemData.WeaponType).texture; + else Slot.Icon.texture = ActionGameManager.Instance.Settings.GetIcon(data.HardpointType).texture; } public override void Activate() diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 26437e6dc..771f2c677 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -166,8 +166,8 @@ public class ActionGameManager : MonoBehaviour (float2(0, -1), "Rear") }; - private DragAction _dragAction; - private Action _endDragCallback; + public DragObject DragObject { get; private set; } + private Func _endDragCallback; private List _stories = new List(); @@ -242,7 +242,7 @@ public class ActionGameManager : MonoBehaviour Input.Global.Dock.performed += context => { - if (EventSystem.current.currentSelectedGameObject?.GetComponent() != null) return; + if (EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.GetComponent() != null) return; if (MainMenu.gameObject.activeSelf) return; if (CurrentEntity == null) { @@ -356,13 +356,18 @@ public class ActionGameManager : MonoBehaviour //Debug.Log("Registering binding!"); switch (dragAction) { - case EquippedItemDragAction equippedItemDragAction: - break; - case ItemInstanceDragAction itemInstanceDragAction: - break; - case WeaponGroupDragAction weaponGroupDragAction: + case EquippedItemDragObject equippedItemDragAction: + var trigger = equippedItemDragAction.EquippedItem.GetBehavior(); + if (trigger == null) return false; + slot.Binding = new ActionBarGearBinding(CurrentEntity, slot, equippedItemDragAction.EquippedItem, trigger); + return true; + case ItemInstanceDragObject itemInstanceDragAction: + if (!(itemInstanceDragAction.Item.Data.Value is ConsumableItemData consumable)) return false; + slot.Binding = new ActionBarConsumableBinding(CurrentEntity, slot, consumable); + return true; + case WeaponGroupDragObject weaponGroupDragAction: slot.Binding = new ActionBarWeaponGroupBinding(CurrentEntity, slot, weaponGroupDragAction.Group); - break; + return true; default: throw new ArgumentOutOfRangeException(nameof(dragAction)); } @@ -511,12 +516,12 @@ public class ActionGameManager : MonoBehaviour }); } - public void BeginDrag(DragAction dragAction) + public void BeginDrag(DragObject dragObject) { - _dragAction = dragAction; + this.DragObject = dragObject; } - public void RegisterDragTarget(Action onEndDrag) + public void RegisterDragTarget(Func onEndDrag) { _endDragCallback = onEndDrag; } @@ -526,10 +531,11 @@ public class ActionGameManager : MonoBehaviour _endDragCallback = null; } - public void EndDrag() + public bool EndDrag() { - _endDragCallback?.Invoke(_dragAction); - _dragAction = null; + var success = _endDragCallback?.Invoke(DragObject); + DragObject = null; + return success ?? false; } public void EnablePlayerInput() @@ -606,7 +612,7 @@ public class ActionGameManager : MonoBehaviour private void ToggleMainMenu() { - if (EventSystem.current.currentSelectedGameObject?.GetComponent() != null) return; + if (EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.GetComponent() != null) return; if (CurrentEntity == null) return; if (MainMenu.gameObject.activeSelf) { @@ -645,7 +651,7 @@ public class ActionGameManager : MonoBehaviour private void ToggleMenuTab(MenuTab tab) { - if (EventSystem.current.currentSelectedGameObject?.GetComponent() != null) return; + if (EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.GetComponent() != null) return; if (MainMenu.gameObject.activeSelf) return; if (Menu.gameObject.activeSelf && Menu.CurrentTab == tab) { @@ -1082,11 +1088,11 @@ public class ActionGameManager : MonoBehaviour } } -public abstract class DragAction{} +public abstract class DragObject{} -public class WeaponGroupDragAction : DragAction +public class WeaponGroupDragObject : DragObject { - public WeaponGroupDragAction(int group) + public WeaponGroupDragObject(int group) { Group = group; } @@ -1094,22 +1100,36 @@ public class WeaponGroupDragAction : DragAction public int Group { get; } } -public class ItemInstanceDragAction : DragAction +public abstract class ItemDragObject : DragObject { - public ItemInstanceDragAction(ItemInstance item) + protected ItemDragObject(int2 originCellOffset, ItemInstance item) { + OriginCellOffset = originCellOffset; Item = item; } public ItemInstance Item { get; } + public int2 OriginCellOffset { get; } } -public class EquippedItemDragAction : DragAction +public class ItemInstanceDragObject : ItemDragObject { - public EquippedItemDragAction(EquippedItem item) + public ItemInstanceDragObject(ItemInstance item, EquippedCargoBay originInventory, int2 originCellOffset) : base(originCellOffset, item) { - Item = item; + OriginInventory = originInventory; } - public EquippedItem Item { get; } + public EquippedCargoBay OriginInventory { get; } +} + +public class EquippedItemDragObject : ItemDragObject +{ + public EquippedItemDragObject(EquippedItem item, Entity originEntity, int2 originCellOffset) : base(originCellOffset, item.EquippableItem) + { + EquippedItem = item; + OriginEntity = originEntity; + } + + public EquippedItem EquippedItem { get; } + public Entity OriginEntity { get; } } \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/GameSettings.cs b/Assets/Scripts/Gameplay/GameSettings.cs index a655de366..7b2520200 100644 --- a/Assets/Scripts/Gameplay/GameSettings.cs +++ b/Assets/Scripts/Gameplay/GameSettings.cs @@ -43,6 +43,7 @@ public class GameSettings : ScriptableObject [HideInInspector] public Sprite[] WeaponFireTypeIcons; [HideInInspector] public Sprite[] WeaponModifierIcons; + public Sprite GetIcon(HardpointType type) => ItemIcons[(int) type]; public Sprite GetIcon(WeaponType type) => WeaponTypeIcons[(int) type]; public Sprite GetIcon(WeaponRange range) => WeaponRangeIcons[(int) range]; public Sprite GetIcon(WeaponCaliber caliber) => WeaponCaliberIcons[(int) caliber]; diff --git a/Assets/Scripts/ServerShared/Behaviors/AetherDrive.cs b/Assets/Scripts/ServerShared/Behaviors/AetherDrive.cs index 834d7e37b..92e2ed5ec 100644 --- a/Assets/Scripts/ServerShared/Behaviors/AetherDrive.cs +++ b/Assets/Scripts/ServerShared/Behaviors/AetherDrive.cs @@ -22,19 +22,22 @@ public class AetherDriveData : BehaviorData [Inspectable, JsonProperty("couplingLambdas"), Key(4)] public float3 CouplingLambda; - [Inspectable, JsonProperty("couplingEfficiency"), Key(5), RuntimeInspectable] + [Inspectable, JsonProperty("lambdaMultiplier"), Key(5)] + public PerformanceStat LambdaMultiplier; + + [Inspectable, JsonProperty("couplingEfficiency"), Key(6), RuntimeInspectable] public PerformanceStat CouplingEfficiency; - [Inspectable, JsonProperty("torque"), Key(6), RuntimeInspectable] + [Inspectable, JsonProperty("torque"), Key(7), RuntimeInspectable] public PerformanceStat Torque; - [Inspectable, JsonProperty("torqueProfile"), Key(7), RuntimeInspectable] + [Inspectable, JsonProperty("torqueProfile"), Key(8), RuntimeInspectable] public BezierCurve TorqueProfile; - [Inspectable, JsonProperty("draw"), Key(8), RuntimeInspectable] + [Inspectable, JsonProperty("draw"), Key(9), RuntimeInspectable] public PerformanceStat EnergyDraw; - [Inspectable, JsonProperty("passiveCoupling"), Key(9), RuntimeInspectable] + [Inspectable, JsonProperty("passiveCoupling"), Key(10), RuntimeInspectable] public PerformanceStat PassiveCoupling; public override Behavior CreateInstance(EquippedItem item) @@ -88,7 +91,7 @@ public class AetherDrive : Behavior Thrust = (Rpm - AetheriaMath.Decay(Rpm, _data.CouplingLambda, dt)) * _data.RotorMass * efficiency; - var couplingLambda = _data.CouplingLambda * max(abs(_axis), Evaluate(_data.PassiveCoupling)); + var couplingLambda = _data.CouplingLambda * Item.Evaluate(_data.LambdaMultiplier) * max(abs(_axis), Evaluate(_data.PassiveCoupling)); var previousRpm = Rpm; Rpm = AetheriaMath.Decay(Rpm, couplingLambda, dt); var rpmLoss = previousRpm - Rpm; diff --git a/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs b/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs index 353de0850..6d29d5472 100644 --- a/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs +++ b/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs @@ -34,7 +34,7 @@ public class StatModifierData : BehaviorData } [Order(-4)] -public class StatModifier : Behavior, IInitializableBehavior, IDisposable +public class StatModifier : Behavior, IInitializableBehavior, IDisposable, IAlwaysUpdatedBehavior { private StatModifierData _data; @@ -42,6 +42,9 @@ public class StatModifier : Behavior, IInitializableBehavior, IDisposable private static Type[] _statObjects; + private bool _applied; + private bool _executed; + private static Type[] StatObjects => _statObjects = _statObjects ?? typeof(BehaviorData).GetAllChildClasses() .Concat(typeof(EquippableItemData).GetAllChildClasses()).ToArray(); @@ -83,19 +86,41 @@ public class StatModifier : Behavior, IInitializableBehavior, IDisposable } } - public override bool Execute(float dt) + private void ApplyModifier() { + _applied = true; foreach (var stat in _stats) (_data.Type == StatModifierType.Constant ? stat.GetConstantModifiers(Entity) : stat.GetScaleModifiers(Entity))[this] = Evaluate(_data.Modifier); + } + + private void RemoveModifier() + { + _applied = false; + foreach (var stat in _stats) + (_data.Type == StatModifierType.Constant ? stat.GetConstantModifiers(Entity) : stat.GetScaleModifiers(Entity)).Remove(this); + } + + public override bool Execute(float dt) + { + _executed = true; return true; } public void Dispose() { - foreach (var stat in _stats) - (_data.Type == StatModifierType.Constant ? stat.GetConstantModifiers(Entity) : stat.GetScaleModifiers(Entity)).Remove(this); + if(_applied) + RemoveModifier(); + } + + public void Update(float delta) + { + if(_executed && !_applied) + ApplyModifier(); + if(!_executed && _applied) + RemoveModifier(); + _executed = false; } } diff --git a/Assets/Scripts/ServerShared/Behaviors/Switch.cs b/Assets/Scripts/ServerShared/Behaviors/Switch.cs index d76ce8a9c..4795a2b2e 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Switch.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Switch.cs @@ -20,7 +20,7 @@ public class SwitchData : BehaviorData } } -public class Switch : Behavior +public class Switch : Behavior, IActivatedBehavior { private SwitchData _data; @@ -39,4 +39,14 @@ public class Switch : Behavior { return Activated; } + + public void Activate() + { + Activated = true; + } + + public void Deactivate() + { + Activated = false; + } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/CultCache/Serialization/TypeFormatterResolver.cs b/Assets/Scripts/ServerShared/CultCache/Serialization/TypeFormatterResolver.cs index 55edebfb8..2f8860f64 100644 --- a/Assets/Scripts/ServerShared/CultCache/Serialization/TypeFormatterResolver.cs +++ b/Assets/Scripts/ServerShared/CultCache/Serialization/TypeFormatterResolver.cs @@ -14,17 +14,18 @@ public class TypeFormatter : MessagePack.Formatters.IMessagePackFormatter public void Serialize(ref MessagePackWriter writer, Type value, MessagePackSerializerOptions options) { - writer.Write(value.AssemblyQualifiedName); + writer.Write(value == null ? "" : value.AssemblyQualifiedName); } public Type Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.IsNil) { - throw new InvalidOperationException("typecode is null, struct not supported"); + return null; //throw new InvalidOperationException("typecode is null, struct not supported"); } var assemblyQualifiedName = reader.ReadString(); + if (string.IsNullOrEmpty(assemblyQualifiedName)) return null; return Type.GetType(assemblyQualifiedName); } diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index 0777aceea..d1f44d509 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -992,7 +992,7 @@ public class ConsumableItemEffect Data = (ConsumableItemData) item.Data.Value; RemainingDuration = Data.Duration; - Behaviors = Data.StatModifiers + Behaviors = Data.Behaviors .Select(bd => bd.CreateInstance(this)) .ToArray(); } @@ -1117,7 +1117,8 @@ public class EquippedItem var quality = pow(EquippableItem.Quality, stat.QualityExponent); var scaleModifier = 1.0f; - foreach (var value in stat.GetScaleModifiers(Entity).Values) scaleModifier = scaleModifier * value; + var scaleModifiers = stat.GetScaleModifiers(Entity).Values; + foreach (var value in scaleModifiers) scaleModifier *= value; float constantModifier = 0; foreach (var value in stat.GetConstantModifiers(Entity).Values) constantModifier += value; @@ -1150,9 +1151,6 @@ public class EquippedItem public void Update(float delta) { - foreach (var behavior in Behaviors) - if(behavior is IAlwaysUpdatedBehavior alwaysUpdatedBehavior) alwaysUpdatedBehavior.Update(delta); - if (Active.Value) { foreach (var group in BehaviorGroups.Values) @@ -1164,9 +1162,12 @@ public class EquippedItem } } } + + foreach (var behavior in Behaviors) + if(behavior is IAlwaysUpdatedBehavior alwaysUpdatedBehavior) alwaysUpdatedBehavior.Update(delta); } - public T GetBehavior() where T : Behavior + public T GetBehavior() where T : class { foreach (var behavior in Behaviors) if (behavior is T b) diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index f2cffbd28..102a5d0ef 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -302,7 +302,7 @@ public class CompoundCommodityData : CraftedItemData public class ConsumableItemData : CraftedItemData { [Inspectable, JsonProperty("behaviors"), Key(10)] - public List StatModifiers = new List(); + public List Behaviors = new List(); [Inspectable, JsonProperty("stackable"), Key(11)] public bool Stackable; diff --git a/Assets/Scripts/ServerShared/Ship.cs b/Assets/Scripts/ServerShared/Ship.cs index 6dd7f00a1..f125fb887 100644 --- a/Assets/Scripts/ServerShared/Ship.cs +++ b/Assets/Scripts/ServerShared/Ship.cs @@ -281,7 +281,7 @@ public class Ship : Entity deltaRot = 0; Direction = lerp(Direction, look, min(delta, 1)); } - deltaRot = pow(abs(deltaRot), .75f) * sign(deltaRot); + deltaRot = pow(abs(deltaRot), .5f) * sign(deltaRot); foreach (var thruster in _clockwiseThrusters) thruster.Axis += deltaRot; foreach (var thruster in _counterClockwiseThrusters) thruster.Axis += -deltaRot; diff --git a/Assets/Scripts/UI/InventoryMenu.cs b/Assets/Scripts/UI/InventoryMenu.cs index 2a6c76cf5..659cfcc34 100644 --- a/Assets/Scripts/UI/InventoryMenu.cs +++ b/Assets/Scripts/UI/InventoryMenu.cs @@ -79,213 +79,6 @@ public class InventoryMenu : MonoBehaviour PropertiesPanel.GameManager = GameManager; foreach (var panel in InventoryPanels) { - panel.OnBeginDragAsObservable().Subscribe(data => - { - //Debug.Log($"Begin drag on panel {panel.name}"); - if (data is InventoryCargoEventData cargoEvent) - { - var item = cargoEvent.CargoBay.Occupancy[cargoEvent.Position.x, cargoEvent.Position.y]; - if (item != null) - { - var itemData = item.Data.Value; - - var itemPosition = cargoEvent.CargoBay.Cargo[item]; - _originalOccupancy = cargoEvent.CargoBay.Data.InteriorShape.Inset(itemData.Shape, itemPosition, item.Rotation); - _originalRotation = item.Rotation; - _originalPanel = panel; - _dragItem = item; - _dragCellOffset = itemPosition - cargoEvent.Position; - _dragCells = _originalOccupancy.Coordinates - .Select(v => Instantiate(panel.CellInstances[v], DragParent, true).transform).ToArray(); - foreach(var cell in _dragCells) - { - foreach (var component in cell.GetComponentsInChildren()) - component.enabled = false; - cell.GetComponentInChildren().raycastTarget = false; - } - _dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray(); - panel.IgnoreOccupancy = _originalOccupancy; - panel.RefreshCells(_originalOccupancy.Expand().Coordinates); - AkSoundEngine.PostEvent("Pickup", gameObject); - } - } - else if (data is InventoryEntityEventData entityEvent) - { - if(!entityEvent.Entity.Active) - { - var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y]; - if (item != null) - { - var itemData = GameManager.ItemManager.GetData(item.EquippableItem); - var hullData = GameManager.ItemManager.GetData(entityEvent.Entity.Hull); - - _originalRotation = item.EquippableItem.Rotation; - _originalEquippedItem = entityEvent.Entity.GearOccupancy[data.Position.x, data.Position.y]; - _originalOccupancy = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation); - _originalPanel = panel; - _dragItem = item.EquippableItem; - _dragCellOffset = item.Position - entityEvent.Position; - _dragCells = _originalOccupancy.Coordinates - .Select(v => Instantiate(panel.CellInstances[v], DragParent, true).transform).ToArray(); - foreach (var cell in _dragCells) - { - foreach (var component in cell.GetComponentsInChildren()) - component.enabled = false; - cell.GetComponentInChildren().raycastTarget = false; - } - - _dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray(); - panel.IgnoreOccupancy = _originalOccupancy; - panel.RefreshCells(_originalOccupancy.Expand().Coordinates); - AkSoundEngine.PostEvent("Pickup", gameObject); - } - } - } - }); - - - panel.OnDragAsObservable().Subscribe(data => - { - if (_dragItem == null) return; - for (var i = 0; i < _dragCells.Length; i++) - _dragCells[i].position = new Vector3( - data.PointerEventData.position.x + _dragOffsets[i].x, - data.PointerEventData.position.y + _dragOffsets[i].y, - _dragCells[i].position.z); - }); - - - panel.OnEndDragAsObservable().Subscribe(data => - { - if (_dragItem == null) return; - if (_dragTargetValid) - { - if (data is InventoryCargoEventData cargoEvent) - { - cargoEvent.CargoBay.Remove(_dragItem); - _dragTargetPanel.DropItem(_dragItem, _dragTargetPosition); - if(_dragTargetPanel.Target == InventoryPanelTarget.Cargo) - AkSoundEngine.PostEvent("Drop", gameObject); - else - AkSoundEngine.PostEvent("Equip", gameObject); - } - else if (data is InventoryEntityEventData entityEvent) - { - if (entityEvent.Entity.TryUnequip(_originalEquippedItem) != null) - { - _dragTargetPanel.DropItem(_dragItem, _dragTargetPosition); - AkSoundEngine.PostEvent("Unequip", gameObject); - } - else - { - AkSoundEngine.PostEvent("UI_Fail", gameObject); - Dialog.Clear(); - Dialog.Title.text = "Unable to move item!"; - Dialog.AddProperty("Verify that cargo bays are empty before un-equipping them."); - Dialog.Show(); - Dialog.MoveToCursor(); - } - } - - _dragTargetPanel.FakeOccupancy = null; - } - else - { - _dragItem.Rotation = _originalRotation; - } - - if (_destroyItem) - { - if (data is InventoryCargoEventData cargoEvent) - { - cargoEvent.CargoBay.Remove(_dragItem); - } - else if (data is InventoryEntityEventData entityEvent) - { - if (entityEvent.Entity.TryUnequip(_originalEquippedItem) == null) - { - Dialog.Clear(); - Dialog.Title.text = "Unable to destroy item!"; - Dialog.AddProperty("Verify that cargo bays are empty before un-equipping them."); - Dialog.Show(); - Dialog.MoveToCursor(); - } - } - } - - panel.IgnoreOccupancy = null; - panel.RefreshCells(); - if(_dragTargetPanel!=panel && _dragTargetPanel != null) - _dragTargetPanel.RefreshCells(); - - _dragItem = null; - foreach (var cell in _dragCells) Destroy(cell.gameObject); - }); - - Action floatCells = () => - { - foreach (var cell in _dragCells) cell.gameObject.SetActive(true); - _dragTargetValid = false; - }; - - panel.OnPointerEnterAsObservable().Subscribe(data => - { - if (_dragItem == null) return; - - // Debug.Log($"Pointer entered {data.Position}"); - // if(panel != _originalPanel) - // _originalPanel.RefreshCells(); - - _dragTargetPanel = panel; - _lastDragPosition = data.Position; - _dragTargetPosition = data.Position + _dragCellOffset; - if (data is InventoryCargoEventData cargoEvent) - { - if (cargoEvent.CargoBay.ItemFits(_dragItem, _dragTargetPosition)) - { - foreach (var cell in _dragCells) cell.gameObject.SetActive(false); - var itemData = _dragItem.Data.Value; - panel.FakeItem = _dragItem; - panel.FakeOccupancy = cargoEvent.CargoBay.Data.InteriorShape.Inset(itemData.Shape, _dragTargetPosition, _dragItem.Rotation); - _dragTargetValid = true; - panel.RefreshCells(); - } - } - else if (data is InventoryEntityEventData entityEvent) - { - var eqItem = _dragItem as EquippableItem; - var hullData = GameManager.ItemManager.GetData(entityEvent.Entity.Hull); - if (eqItem != null && entityEvent.Entity.ItemFits(eqItem, _dragTargetPosition)) - { - foreach (var cell in _dragCells) cell.gameObject.SetActive(false); - var itemData = _dragItem.Data.Value; - panel.FakeEquipment = _originalEquippedItem; - panel.FakeOccupancy = hullData.Shape.Inset(itemData.Shape, _dragTargetPosition, _dragItem.Rotation); - _dragTargetValid = true; - panel.RefreshCells(); - } - } - }); - - panel.OnPointerExitAsObservable().Subscribe(data => - { - if (_dragItem == null) return; - - if (data.Position.Equals(_lastDragPosition) || !_dragTargetValid) - { - panel.FakeItem = null; - panel.FakeOccupancy = null; - panel.RefreshCells(); - // if (_originalPanel != panel) - // { - // _originalPanel.FakeItem = null; - // _originalPanel.FakeOccupancy = null; - // _originalPanel.RefreshCells(); - // } - floatCells(); - } - }); - panel.OnClickAsObservable().Subscribe(e => { if (e.data is InventoryCargoEventData cargoEvent) diff --git a/Assets/Scripts/UI/InventoryPanel.cs b/Assets/Scripts/UI/InventoryPanel.cs index 2ac8f62bc..2482fff24 100644 --- a/Assets/Scripts/UI/InventoryPanel.cs +++ b/Assets/Scripts/UI/InventoryPanel.cs @@ -21,6 +21,7 @@ using int2 = Unity.Mathematics.int2; public class InventoryPanel : MonoBehaviour, IPointerClickHandler { public ConfirmationDialog Dialog; + public RectTransform DragParent; public bool Flip; public GameSettings Settings; public ActionGameManager GameManager; @@ -52,19 +53,18 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler public float DoubleClickTime = .5f; public float HitDamageThreshold = 1; - Subject _onBeginDrag; - Subject _onDrag; - Subject _onEndDrag; + // Subject _onBeginDrag; + // Subject _onDrag; + // Subject _onEndDrag; Subject<(InventoryEventData data, int clickCount)> _onClick; - Subject _onPointerEnter; - Subject _onPointerExit; + // Subject _onPointerEnter; + // Subject _onPointerExit; private Entity _displayedEntity; private EquippedCargoBay _displayedCargo; private Texture2D _temperatureTexture; private RectTransform _firstRect; - public EquippedItem FakeEquipment; public ItemInstance FakeItem; public Shape FakeOccupancy; public Shape IgnoreOccupancy; @@ -268,6 +268,10 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler public void Display(Entity entity, bool hud = false, bool thermal = false) { Clear(); + + _subscriptions.Add(entity.Equipment.ObserveAdd().Subscribe(_ => RefreshCells())); + _subscriptions.Add(entity.Equipment.ObserveRemove().Subscribe(_ => RefreshCells())); + _thermal = thermal; _hud = hud; @@ -352,15 +356,105 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler _onClick?.OnNext((new InventoryEntityEventData(data, v, entity), _clickCount)); }); cell.BeginDragTrigger.OnBeginDragAsObservable() - .Subscribe(data => _onBeginDrag?.OnNext(new InventoryEntityEventData(data, v, entity))); + .Subscribe(data => + { + //Debug.Log("Entity Drag Start"); + var item = entity.GearOccupancy[v.x, v.y]; + if (item != null) + { + var originalOccupancy = hullData.Shape.Inset(item.Data.Shape, item.Position, item.EquippableItem.Rotation); + _dragCells = originalOccupancy.Coordinates + .Select(v1 => Instantiate(CellInstances[v1], DragParent, true).transform).ToArray(); + foreach(var dragCell in _dragCells) + { + DestroyImmediate(dragCell.GetComponent()); + foreach (var component in dragCell.GetComponentsInChildren()) + component.enabled = false; + foreach (var img in dragCell.GetComponentsInChildren()) + img.color = new Color(img.color.r, img.color.g, img.color.b, img.color.a * .5f); + dragCell.GetComponentInChildren().raycastTarget = false; + } + _dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.position).ToArray(); + IgnoreOccupancy = originalOccupancy; + RefreshCells(); + _originalRotation = item.EquippableItem.Rotation; + GameManager.BeginDrag(new EquippedItemDragObject(item, entity, item.Position - v)); + AkSoundEngine.PostEvent("Pickup", gameObject); + } + }); cell.DragTrigger.OnDragAsObservable() - .Subscribe(data => _onDrag?.OnNext(new InventoryEntityEventData(data, v, entity))); + .Subscribe(data => + { + for (var i = 0; i < _dragCells.Length; i++) + _dragCells[i].position = new Vector3( + data.position.x + _dragOffsets[i].x, + data.position.y + _dragOffsets[i].y, + _dragCells[i].position.z); + }); cell.EndDragTrigger.OnEndDragAsObservable() - .Subscribe(data => _onEndDrag?.OnNext(new InventoryEntityEventData(data, v, entity))); + .Subscribe(data => + { + //Debug.Log("Entity Drag End"); + IgnoreOccupancy = null; + if (!GameManager.EndDrag()) + entity.GearOccupancy[v.x, v.y].EquippableItem.Rotation = _originalRotation; + foreach(var dragObject in _dragCells) + Destroy(dragObject.gameObject); + _dragCells = null; + RefreshCells(); + }); cell.PointerEnterTrigger.OnPointerEnterAsObservable() - .Subscribe(data => _onPointerEnter?.OnNext(new InventoryEntityEventData(data, v, entity))); + .Subscribe(data => + { + //Debug.Log("Entity Pointer Enter"); + if (!(GameManager.DragObject is ItemDragObject itemDragObject)) return; + var item = itemDragObject.Item; + var itemData = item.Data.Value; + if (!(item is EquippableItem equippableItem)) return; + var placementPosition = v + itemDragObject.OriginCellOffset; + if (entity.ItemFits(equippableItem, placementPosition)) + { + //foreach (var cell in _dragCells) cell.gameObject.SetActive(false); + FakeItem = item; + FakeOccupancy = hullData.Shape.Inset(itemData.Shape, placementPosition, item.Rotation); + RefreshCells(); + GameManager.RegisterDragTarget(drag => + { + //Debug.Log("Entity Drag Callback"); + if (GameManager.DragObject is EquippedItemDragObject equippedItemDragObject) + { + if(equippedItemDragObject.OriginEntity.TryUnequip(equippedItemDragObject.EquippedItem) == null) + { + AkSoundEngine.PostEvent("UI_Fail", gameObject); + Dialog.Clear(); + Dialog.Title.text = "Unable to move item!"; + Dialog.AddProperty("Verify that cargo bays are empty before un-equipping them."); + Dialog.Show(); + Dialog.MoveToCursor(); + } + else + AkSoundEngine.PostEvent("Unequip", gameObject); + } + else if (GameManager.DragObject is ItemInstanceDragObject itemInstanceDragObject) + itemInstanceDragObject.OriginInventory.Remove(itemInstanceDragObject.Item); + + FakeOccupancy = null; + entity.TryEquip(equippableItem, placementPosition); + RefreshCells(); + AkSoundEngine.PostEvent("Equip", gameObject); + return false; + }); + } + }); cell.PointerExitTrigger.OnPointerExitAsObservable() - .Subscribe(data => _onPointerExit?.OnNext(new InventoryEntityEventData(data, v, entity))); + .Subscribe(data => + { + if (!(GameManager.DragObject is ItemDragObject)) return; + FakeItem = null; + FakeOccupancy = null; + RefreshCells(); + GameManager.UnregisterDragTarget(); + }); } } else @@ -448,6 +542,9 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler { Clear(); + _subscriptions.Add(cargo.Cargo.ObserveAdd().Subscribe(_ => RefreshCells())); + _subscriptions.Add(cargo.Cargo.ObserveRemove().Subscribe(_ => RefreshCells())); + _displayedCargo = cargo; _displayedEntity = null; @@ -479,15 +576,103 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler _onClick?.OnNext((new InventoryCargoEventData(data, v, cargo), _clickCount)); }); cell.BeginDragTrigger.OnBeginDragAsObservable() - .Subscribe(data => _onBeginDrag?.OnNext(new InventoryCargoEventData(data, v, cargo))); + .Subscribe(data => + { + //Debug.Log("Inventory Drag Start"); + var item = cargo.Occupancy[v.x, v.y]; + if (item != null) + { + var itemPosition = cargo.Cargo[item]; + var itemData = item.Data.Value; + var originalOccupancy = cargo.Data.InteriorShape.Inset(itemData.Shape, itemPosition, item.Rotation); + _dragCells = originalOccupancy.Coordinates + .Select(v1 => Instantiate(CellInstances[v1], DragParent, true).transform).ToArray(); + foreach(var dragCell in _dragCells) + { + DestroyImmediate(dragCell.GetComponent()); + foreach (var component in dragCell.GetComponentsInChildren()) + component.enabled = false; + foreach (var img in dragCell.GetComponentsInChildren()) + img.color = new Color(img.color.r, img.color.g, img.color.b, img.color.a * .5f); + dragCell.GetComponentInChildren().raycastTarget = false; + } + _dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.position).ToArray(); + IgnoreOccupancy = originalOccupancy; + RefreshCells(); + _originalRotation = item.Rotation; + GameManager.BeginDrag(new ItemInstanceDragObject(item, cargo, cargo.Cargo[item] - v)); + AkSoundEngine.PostEvent("Pickup", gameObject); + } + }); cell.DragTrigger.OnDragAsObservable() - .Subscribe(data => _onDrag?.OnNext(new InventoryCargoEventData(data, v, cargo))); + .Subscribe(data => + { + for (var i = 0; i < _dragCells.Length; i++) + _dragCells[i].position = new Vector3( + data.position.x + _dragOffsets[i].x, + data.position.y + _dragOffsets[i].y, + _dragCells[i].position.z); + }); cell.EndDragTrigger.OnEndDragAsObservable() - .Subscribe(data => _onEndDrag?.OnNext(new InventoryCargoEventData(data, v, cargo))); + .Subscribe(data => + { + //Debug.Log("Inventory Drag End"); + IgnoreOccupancy = null; + GameManager.EndDrag(); + foreach(var dragObject in _dragCells) + Destroy(dragObject.gameObject); + _dragCells = null; + }); cell.PointerEnterTrigger.OnPointerEnterAsObservable() - .Subscribe(data => _onPointerEnter?.OnNext(new InventoryCargoEventData(data, v, cargo))); + .Subscribe(data => + { + //Debug.Log("Inventory Pointer Enter"); + if (!(GameManager.DragObject is ItemDragObject itemDragObject)) return; + var item = itemDragObject.Item; + var itemData = item.Data.Value; + var placementPosition = v + itemDragObject.OriginCellOffset; + if (cargo.ItemFits(item, placementPosition)) + { + //foreach (var cell in _dragCells) cell.gameObject.SetActive(false); + FakeItem = item; + FakeOccupancy = cargo.Data.InteriorShape.Inset(itemData.Shape, placementPosition, item.Rotation); + RefreshCells(); + GameManager.RegisterDragTarget(drag => + { + //Debug.Log("Inventory Drag Callback"); + if (GameManager.DragObject is EquippedItemDragObject equippedItemDragObject) + { + if(equippedItemDragObject.OriginEntity.TryUnequip(equippedItemDragObject.EquippedItem) == null) + { + AkSoundEngine.PostEvent("UI_Fail", gameObject); + Dialog.Clear(); + Dialog.Title.text = "Unable to move item!"; + Dialog.AddProperty("Verify that cargo bays are empty before un-equipping them."); + Dialog.Show(); + Dialog.MoveToCursor(); + } + else + AkSoundEngine.PostEvent("Unequip", gameObject); + } + else if (GameManager.DragObject is ItemInstanceDragObject itemInstanceDragObject) + itemInstanceDragObject.OriginInventory.Remove(itemInstanceDragObject.Item); + cargo.TryStore(item, placementPosition); + FakeOccupancy = null; + AkSoundEngine.PostEvent("Drop", gameObject); + return true; + }); + } + }); cell.PointerExitTrigger.OnPointerExitAsObservable() - .Subscribe(data => _onPointerExit?.OnNext(new InventoryCargoEventData(data, v, cargo))); + .Subscribe(data => + { + if (!(GameManager.DragObject is ItemDragObject)) return; + FakeItem = null; + FakeOccupancy = null; + RefreshCells(); + GameManager.UnregisterDragTarget(); + }); + CellInstances.Add(v, cell); } } @@ -511,7 +696,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler var spriteIndex = 0; var interior = hullData.InteriorCells[v]; - var item = FakeOccupancy?[v]??false ? FakeEquipment : IgnoreOccupancy?[v]??false ? null : _displayedEntity.GearOccupancy[v.x, v.y]; + var item = FakeOccupancy?[v]??false ? FakeItem : IgnoreOccupancy?[v]??false ? null : _displayedEntity.GearOccupancy[v.x, v.y]?.EquippableItem; var hardpoint = _displayedEntity.Hardpoints[v.x, v.y]; bool HardpointMatch(int2 offset) @@ -520,7 +705,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler return !( hullData.Shape[v2] && _displayedEntity.Hardpoints[v2.x, v2.y] == hardpoint && - (FakeOccupancy?[v2]??false ? FakeEquipment : IgnoreOccupancy?[v2]??false ? null : _displayedEntity.GearOccupancy[v2.x, v2.y]) == item + (FakeOccupancy?[v2]??false ? FakeItem : IgnoreOccupancy?[v2]??false ? null : _displayedEntity.GearOccupancy[v2.x, v2.y]?.EquippableItem) == item ); } @@ -531,7 +716,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler hullData.Shape[v2] && ( !interior && !hullData.InteriorCells[v2] && _displayedEntity.Hardpoints[v2.x, v2.y] == null || interior && item != null && - (FakeOccupancy?[v2]??false ? FakeEquipment : IgnoreOccupancy?[v2]??false ? null : _displayedEntity.GearOccupancy[v2.x, v2.y]) == item + (FakeOccupancy?[v2]??false ? FakeItem : IgnoreOccupancy?[v2]??false ? null : _displayedEntity.GearOccupancy[v2.x, v2.y]?.EquippableItem) == item ) ); } @@ -619,14 +804,15 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler var hullData = GameManager.ItemManager.GetData(_displayedEntity.Hull) as HullData; var interior = hullData.InteriorCells[position]; var hardpoint = _displayedEntity.Hardpoints[position.x, position.y]; - var item = FakeOccupancy?[position] ?? false ? FakeEquipment : IgnoreOccupancy?[position] ?? false ? null : _displayedEntity.GearOccupancy[position.x, position.y]; + var item = (FakeOccupancy?[position] ?? false ? FakeItem : + IgnoreOccupancy?[position] ?? false ? null : _displayedEntity.GearOccupancy[position.x, position.y]?.EquippableItem) as EquippableItem; if (_hud) { if (_displayedEntity.Armor[position.x, position.y] > .01f) return Settings.ArmorGradient.Evaluate(_displayedEntity.Armor[position.x, position.y] / _displayedEntity.MaxArmor[position.x, position.y]); - if (item != null) return Settings.DurabilityGradient.Evaluate(item.EquippableItem.Durability / _displayedEntity.ItemManager.GetData(item.EquippableItem).Durability); + if (item != null) return Settings.DurabilityGradient.Evaluate(item.Durability / _displayedEntity.ItemManager.GetData(item).Durability); return float3(.25f).ToColor(); } @@ -671,21 +857,6 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler } } - public bool DropItem(ItemInstance item, int2 position) - { - if (_displayedEntity != null && item is EquippableItem equippableItem) - { - return _displayedEntity.TryEquip(equippableItem, position); - } - - if(_displayedCargo != null) - { - return _displayedCargo.TryStore(item, position); - } - - return false; - } - public bool CanDropItem(ItemInstance item) { if (_displayedEntity != null && item is EquippableItem equippableItem) @@ -717,12 +888,16 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler } public Subject OnBackgroundClick = new Subject(); + private Transform[] _dragCells; + private Vector2[] _dragOffsets; + private ItemRotation _originalRotation; + public Subject<(InventoryEventData data, int clickCount)> OnClickAsObservable() => _onClick ?? (_onClick = new Subject<(InventoryEventData data, int clickCount)>()); - public UniRx.IObservable OnBeginDragAsObservable() => _onBeginDrag ?? (_onBeginDrag = new Subject()); - public UniRx.IObservable OnDragAsObservable() => _onDrag ?? (_onDrag = new Subject()); - public UniRx.IObservable OnEndDragAsObservable() => _onEndDrag ?? (_onEndDrag = new Subject()); - public UniRx.IObservable OnPointerEnterAsObservable() => _onPointerEnter ?? (_onPointerEnter = new Subject()); - public UniRx.IObservable OnPointerExitAsObservable() => _onPointerExit ?? (_onPointerExit = new Subject()); + // public UniRx.IObservable OnBeginDragAsObservable() => _onBeginDrag ?? (_onBeginDrag = new Subject()); + // public UniRx.IObservable OnDragAsObservable() => _onDrag ?? (_onDrag = new Subject()); + // public UniRx.IObservable OnEndDragAsObservable() => _onEndDrag ?? (_onEndDrag = new Subject()); + // public UniRx.IObservable OnPointerEnterAsObservable() => _onPointerEnter ?? (_onPointerEnter = new Subject()); + // public UniRx.IObservable OnPointerExitAsObservable() => _onPointerExit ?? (_onPointerExit = new Subject()); public void OnPointerClick(PointerEventData eventData) { diff --git a/Assets/Scripts/UI/PropertiesPanel.cs b/Assets/Scripts/UI/PropertiesPanel.cs index 8ae518863..0f32b38ba 100644 --- a/Assets/Scripts/UI/PropertiesPanel.cs +++ b/Assets/Scripts/UI/PropertiesPanel.cs @@ -478,7 +478,7 @@ public class PropertiesPanel : MonoBehaviour weaponGroups.OnBeginDragAsObservable().Subscribe(x => { //Debug.Log($"Began dragging weapon group {x.group}"); - GameManager.BeginDrag(new WeaponGroupDragAction(x.group)); + GameManager.BeginDrag(new WeaponGroupDragObject(x.group)); dragObject = Instantiate(weaponGroups.Groups[x.group], DragParent, true).transform; dragOffset = (Vector2)dragObject.position - x.pointerEventData.position; }); diff --git a/Assets/Scripts/UI/SchematicTriggerGroupElement.cs b/Assets/Scripts/UI/SchematicTriggerGroupElement.cs deleted file mode 100644 index ff078b3c7..000000000 --- a/Assets/Scripts/UI/SchematicTriggerGroupElement.cs +++ /dev/null @@ -1,10 +0,0 @@ - -using TMPro; -using UnityEngine; -using UnityEngine.UI; - -public class SchematicTriggerGroupElement : MonoBehaviour -{ - public TextMeshProUGUI[] GroupLabel; - public Image[] GroupBackgrounds; -} \ No newline at end of file diff --git a/Assets/Scripts/UI/SchematicTriggerGroupElement.cs.meta b/Assets/Scripts/UI/SchematicTriggerGroupElement.cs.meta deleted file mode 100644 index af88b8c6b..000000000 --- a/Assets/Scripts/UI/SchematicTriggerGroupElement.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 8f090c2738224f698bdfa545978f4d5a -timeCreated: 1609423819 \ No newline at end of file diff --git a/GameData/AetherDB.msgpack b/GameData/AetherDB.msgpack index 100658701..ed9524939 100644 --- a/GameData/AetherDB.msgpack +++ b/GameData/AetherDB.msgpack @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a607d2435f93eae73a274ae8247c7aa47e1962fadef282db240705970b1d12bc -size 75659 +oid sha256:38a1e181ae301b90f0af33b0f91fd79d8c8d4e16cc93f2e85656dee0ad043c86 +size 75924 diff --git a/GameData/PlayerSettings.msgpack b/GameData/PlayerSettings.msgpack index a9d771654..5c15013a1 100644 --- a/GameData/PlayerSettings.msgpack +++ b/GameData/PlayerSettings.msgpack @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e65428c99ca8688be45695ee938703cc2cfb82f7c0a41594ccbfaecad24ec2e3 -size 17318 +oid sha256:b9ec5cef84e135dc355753ec7e782a6867dec6728e12c463e559a8bbb0a63770 +size 26003 diff --git a/RethinkDB.csproj b/RethinkDB.csproj index b5ef29462..f6faae674 100644 --- a/RethinkDB.csproj +++ b/RethinkDB.csproj @@ -241,8 +241,8 @@ - + @@ -295,8 +295,8 @@ - +