Various Fixes
Newly created drones now register their origin colony correctly Hauling behavior fixed for multiple items Buttons can't be dragged unless explicitly enabled Inspecting a colony with lots of compound commodities no longer sets your computer on fire
This commit is contained in:
parent
cbebc78af1
commit
1e2b474fc1
11 changed files with 133 additions and 47 deletions
|
|
@ -28,7 +28,7 @@ public abstract class ControllerData : BehaviorData
|
|||
|
||||
public abstract class ControllerBase : IBehavior, IController, IInitializableBehavior
|
||||
{
|
||||
public Guid HomeEntity;
|
||||
protected Guid HomeEntity => (_entity as Ship)?.HomeEntity ?? Guid.Empty;
|
||||
public bool Available => _spaceworthy && Task == Guid.Empty;
|
||||
public abstract TaskType TaskType { get; }
|
||||
public Guid Zone => _entity.Zone;
|
||||
|
|
@ -59,15 +59,24 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh
|
|||
_context = context;
|
||||
_controllerData = data;
|
||||
_entity = entity;
|
||||
entity.GearEvent.OnChanged += () => _spaceworthy = entity.GetBehavior<Thruster>() != null && entity.GetBehavior<Reactor>() != null;
|
||||
entity.GearEvent.OnChanged += () =>
|
||||
{
|
||||
_spaceworthy = entity.GetBehavior<Thruster>() != null && entity.GetBehavior<Reactor>() != null;
|
||||
if(_spaceworthy)
|
||||
CreateBehaviors();
|
||||
};
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
|
||||
public void CreateBehaviors()
|
||||
{
|
||||
Locomotion = new Locomotion(_context, _entity, _controllerData);
|
||||
VelocityMatch = new VelocityMatch(_context, _entity, _controllerData);
|
||||
Aim = new Aim(_context, _entity, _controllerData);
|
||||
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
CreateBehaviors();
|
||||
_context.CorporationControllers[_entity.Corporation].Add(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,8 @@ public class HaulingController : ControllerBase, IBehavior, IPersistentBehavior
|
|||
{
|
||||
var itemMatches = target.Cargo
|
||||
.Select(id => _context.Cache.Get<CraftedItemInstance>(id))
|
||||
.Where(ii => ii != null && ii.Data == haulingTask.ItemType);
|
||||
.Where(ii => ii != null && ii.Data == haulingTask.ItemType)
|
||||
.ToArray();
|
||||
if(!itemMatches.Any())
|
||||
FinishTask();
|
||||
foreach (var match in itemMatches)
|
||||
|
|
|
|||
|
|
@ -68,9 +68,27 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
public Dictionary<Guid, double> IncompleteCargo = new Dictionary<Guid, double>();
|
||||
|
||||
[JsonProperty("active"), Key(18)]
|
||||
public bool Active { get; set; }
|
||||
private bool _active;
|
||||
public bool Active
|
||||
{
|
||||
get => _active;
|
||||
set
|
||||
{
|
||||
_active = value;
|
||||
if (_active)
|
||||
{
|
||||
foreach (var hardpoint in Hardpoints)
|
||||
if(hardpoint.Gear!=null)
|
||||
foreach (var behavior in hardpoint.Behaviors)
|
||||
{
|
||||
if(behavior is IInitializableBehavior initializableBehavior)
|
||||
initializableBehavior.Initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//public List<IncompleteItem> IncompleteCargo = new List<IncompleteItem>();
|
||||
|
||||
|
||||
[IgnoreMember] public Guid Zone;
|
||||
[IgnoreMember] public List<Hardpoint> Hardpoints;
|
||||
[IgnoreMember] public readonly Dictionary<object, float> VisibilitySources = new Dictionary<object, float>();
|
||||
|
|
@ -168,15 +186,16 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
Cargo.Add(remaining);
|
||||
}
|
||||
|
||||
foreach (var hardpoint in Hardpoints)
|
||||
if(hardpoint.Gear!=null)
|
||||
foreach (var behavior in hardpoint.Behaviors)
|
||||
{
|
||||
if(behavior is IPopulationAssignment populationAssignment)
|
||||
PopulationAssignments.Add(populationAssignment);
|
||||
if(behavior is IInitializableBehavior initializableBehavior)
|
||||
initializableBehavior.Initialize();
|
||||
}
|
||||
if (_active)
|
||||
{
|
||||
foreach (var hardpoint in Hardpoints)
|
||||
if(hardpoint.Gear!=null)
|
||||
foreach (var behavior in hardpoint.Behaviors)
|
||||
{
|
||||
if(behavior is IInitializableBehavior initializableBehavior)
|
||||
initializableBehavior.Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
RecalculateMass();
|
||||
}
|
||||
|
|
@ -206,6 +225,11 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
})
|
||||
.ToArray();
|
||||
|
||||
foreach (var behavior in hardpoint.Behaviors)
|
||||
{
|
||||
if(behavior is IPopulationAssignment populationAssignment)
|
||||
PopulationAssignments.Add(populationAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
public void Unequip(Hardpoint hardpoint)
|
||||
|
|
|
|||
|
|
@ -710,7 +710,7 @@ public class GameContext
|
|||
if (hullData.HullType == HullType.Ship)
|
||||
{
|
||||
var entity = CreateShip(hull.ID, gear.Select(g => g.ID),
|
||||
cargo.Select(c => c.ID).Concat(simpleCargo.Select(c => c.ID)), zone, corporation, loadoutData.Name);
|
||||
cargo.Select(c => c.ID).Concat(simpleCargo.Select(c => c.ID)), zone, corporation, Guid.Empty, loadoutData.Name);
|
||||
entity.Active = true;
|
||||
return entity;
|
||||
}
|
||||
|
|
@ -752,12 +752,13 @@ public class GameContext
|
|||
return null;
|
||||
}
|
||||
|
||||
public Ship CreateShip(Guid hull, IEnumerable<Guid> gear, IEnumerable<Guid> cargo, Guid zone, Guid corporation, string typeName)
|
||||
public Ship CreateShip(Guid hull, IEnumerable<Guid> gear, IEnumerable<Guid> cargo, Guid zone, Guid corporation, Guid homeEntity, string typeName)
|
||||
{
|
||||
|
||||
var ship = new Ship(this, hull, gear, cargo, zone, corporation)
|
||||
{
|
||||
Name = $"{typeName} {Random.NextInt(1,255):X}"
|
||||
Name = $"{typeName} {Random.NextInt(1,255):X}",
|
||||
HomeEntity = homeEntity
|
||||
};
|
||||
Cache.Add(ship);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
|
|
@ -16,6 +17,8 @@ public class Ship : Entity
|
|||
|
||||
// [IgnoreMember] public Dictionary<Targetable, float> Contacts = new Dictionary<Targetable, float>();
|
||||
// [IgnoreMember] public Targetable Target;
|
||||
[JsonProperty("homeEntity"), Key(19)]
|
||||
public Guid HomeEntity;
|
||||
|
||||
public Ship(GameContext context, Guid hull, IEnumerable<Guid> gear, IEnumerable<Guid> cargo, Guid zone, Guid corporation) : base(context, hull, gear, cargo, zone, corporation)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -213,6 +213,7 @@ public class StrategyGameManager : MonoBehaviour
|
|||
ZoneTabButton.OnPointerClick(null);
|
||||
|
||||
var entities = new List<Entity>();
|
||||
|
||||
foreach(var loadout in parentCorp.InitialFleet)
|
||||
for(int i=0; i<loadout.Value; i++)
|
||||
entities.Add(_context.CreateEntity(_selectedZone, newCorp.ID, loadout.Key));
|
||||
|
|
@ -220,8 +221,7 @@ public class StrategyGameManager : MonoBehaviour
|
|||
_selectedColony = colony.ID;
|
||||
foreach (var ship in entities.Where(e => e is Ship))
|
||||
{
|
||||
foreach (var controller in ship.GetBehaviors<ControllerBase>())
|
||||
controller.HomeEntity = colony.ID;
|
||||
((Ship)ship).HomeEntity = colony.ID;
|
||||
|
||||
_context.SetParent(ship, colony);
|
||||
}
|
||||
|
|
@ -719,6 +719,7 @@ public class StrategyGameManager : MonoBehaviour
|
|||
var itemData = _context.Cache.Get<SimpleCommodityData>(resource.Key);
|
||||
list.AddProperty(itemData.Name, () => $"{resource.Value:0}");
|
||||
}
|
||||
list.SetExpanded(true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -344,6 +344,7 @@ public class TechTreeMsagl : MonoBehaviour
|
|||
var ingredientData = Context.Cache.Get<ItemData>(ingredient.Key);
|
||||
ingredientsList.AddProperty(ingredientData.Name, () => ingredient.Value.ToString());
|
||||
}
|
||||
ingredientsList.SetExpanded(true, true);
|
||||
|
||||
var dependenciesList = PropertiesPanel.AddList("Dependencies");
|
||||
foreach (var dependency in blueprint.Dependencies)
|
||||
|
|
@ -351,12 +352,14 @@ public class TechTreeMsagl : MonoBehaviour
|
|||
var dependencyBlueprint = Context.Cache.Get<BlueprintData>(dependency);
|
||||
dependenciesList.AddProperty(dependencyBlueprint.Name);
|
||||
}
|
||||
dependenciesList.SetExpanded(true, true);
|
||||
|
||||
var descendantsList = PropertiesPanel.AddList("Descendants");
|
||||
foreach (var descendant in Blueprints.Where(bp => bp.Dependencies.Any(dep => blueprint.ID == dep)))
|
||||
{
|
||||
descendantsList.AddProperty(descendant.Name);
|
||||
}
|
||||
descendantsList.SetExpanded(true, true);
|
||||
};
|
||||
_techInstances.Add(tech.GetComponent<Prototype>());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public class ColonyTab : MonoBehaviour
|
|||
foreach (var attribute in entity.Personality.Keys)
|
||||
personalityList.AddPersonalityProperty(Context.Cache.Get<PersonalityAttribute>(attribute),
|
||||
() => entity.Personality[attribute]);
|
||||
personalityList.SetExpanded(false, true);
|
||||
// personalityList.SetExpanded(false, true);
|
||||
|
||||
var childList = General.AddList("Children");
|
||||
childList.InspectChildren(entity, child =>
|
||||
|
|
@ -96,7 +96,7 @@ public class ColonyTab : MonoBehaviour
|
|||
_selectedChild = child;
|
||||
UpdateInventory(child, ChildInventory);
|
||||
});
|
||||
childList.SetExpanded(false, true);
|
||||
// childList.SetExpanded(false, true);
|
||||
|
||||
General.RefreshValues();
|
||||
}
|
||||
|
|
@ -357,7 +357,7 @@ public class ColonyTab : MonoBehaviour
|
|||
{
|
||||
entity.RemoveCargo(gear);
|
||||
var ship = Context.CreateShip(gear.ID, Enumerable.Empty<Guid>(),
|
||||
Enumerable.Empty<Guid>(), entity.Zone, entity.Corporation, gear.Name);
|
||||
Enumerable.Empty<Guid>(), entity.Zone, entity.Corporation, _parentEntity.ID, gear.Name);
|
||||
_context.SetParent(ship, entity);
|
||||
}
|
||||
else // Equip Item
|
||||
|
|
@ -412,7 +412,7 @@ public class ColonyTab : MonoBehaviour
|
|||
button.DisableClickWhenSelected = false;
|
||||
button.DragSuccess = data => dragSuccess(data, item);
|
||||
}
|
||||
instanceList.SetExpanded(false, true);
|
||||
// instanceList.SetExpanded(false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -443,7 +443,7 @@ public class ColonyTab : MonoBehaviour
|
|||
});
|
||||
|
||||
blueprintList.RefreshValues();
|
||||
blueprintList.SetExpanded(false, true);
|
||||
// blueprintList.SetExpanded(false, true);
|
||||
}
|
||||
Details.RefreshValues();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,11 @@ public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitH
|
|||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (DragSuccess == null || DragObject == null) return;
|
||||
if (DragSuccess == null || DragObject == null)
|
||||
{
|
||||
eventData.pointerDrag = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var canvas = gameObject.FindInParents<Canvas>();
|
||||
if (canvas == null)
|
||||
|
|
|
|||
|
|
@ -14,12 +14,15 @@ public class PropertiesList : PropertiesPanel
|
|||
public VerticalLayoutGroup LayoutGroup;
|
||||
public int FoldedPadding = -8;
|
||||
public int ExpandedPadding = 8;
|
||||
public event Action<bool> OnExpand;
|
||||
|
||||
private bool _expanded = false;
|
||||
private float _targetFoldoutRotation = 0;
|
||||
private float _foldoutRotation = 0;
|
||||
|
||||
public void Start()
|
||||
public bool Expanded => _expanded;
|
||||
|
||||
public new void Awake()
|
||||
{
|
||||
Button.OnClick += _ => ToggleExpand();
|
||||
OnPropertyAdded += go => go.SetActive(_expanded);
|
||||
|
|
@ -49,6 +52,7 @@ public class PropertiesList : PropertiesPanel
|
|||
_foldoutRotation = _targetFoldoutRotation;
|
||||
FoldoutIcon.transform.localRotation = Quaternion.Euler(0,0, _foldoutRotation);
|
||||
}
|
||||
OnExpand?.Invoke(_expanded);
|
||||
}
|
||||
|
||||
// public override PropertyLabel AddProperty(string name, Func<string> read = null, Action<PointerEventData> onClick = null, bool radio = false)
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@ public class PropertiesPanel : MonoBehaviour
|
|||
protected event Action<GameObject> OnPropertyAdded;
|
||||
protected IChangeSource ChangeSource;
|
||||
protected Action OnPropertiesChanged;
|
||||
|
||||
public int Children => Properties.Count + Buttons.Count;
|
||||
|
||||
public void Start()
|
||||
public void Awake()
|
||||
{
|
||||
OnPropertyAdded += go => go.SetActive(true);
|
||||
}
|
||||
|
|
@ -357,11 +359,11 @@ public class PropertiesPanel : MonoBehaviour
|
|||
|
||||
var hardpointList = AddList("Gear");
|
||||
hardpointList.InspectHardpoints(entity);
|
||||
hardpointList.SetExpanded(false,true);
|
||||
//hardpointList.SetExpanded(false,true);
|
||||
|
||||
var cargoList = AddList("Cargo");
|
||||
cargoList.InspectCargo(entity);
|
||||
cargoList.SetExpanded(false,true);
|
||||
//cargoList.SetExpanded(false,true);
|
||||
|
||||
RefreshValues();
|
||||
}
|
||||
|
|
@ -373,7 +375,18 @@ public class PropertiesPanel : MonoBehaviour
|
|||
ChangeSource = entity.GearEvent;
|
||||
OnPropertiesChanged = InspectGearInternal;
|
||||
ChangeSource.OnChanged += OnPropertiesChanged;
|
||||
InspectGearInternal();
|
||||
if (this is PropertiesList list)
|
||||
{
|
||||
if (list.Expanded)
|
||||
InspectGearInternal();
|
||||
else
|
||||
list.OnExpand += b =>
|
||||
{
|
||||
if (b) InspectGearInternal();
|
||||
};
|
||||
}
|
||||
else
|
||||
InspectGearInternal();
|
||||
|
||||
void InspectGearInternal()
|
||||
{
|
||||
|
|
@ -383,7 +396,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
{
|
||||
var propertyList = AddList(hardpoint.Gear.Name);
|
||||
propertyList.Inspect(entity, hardpoint);
|
||||
propertyList.SetExpanded(false,true);
|
||||
//propertyList.SetExpanded(false,true);
|
||||
}
|
||||
RefreshValues();
|
||||
}
|
||||
|
|
@ -396,7 +409,18 @@ public class PropertiesPanel : MonoBehaviour
|
|||
ChangeSource = entity.CargoEvent;
|
||||
OnPropertiesChanged = InspectCargoInternal;
|
||||
ChangeSource.OnChanged += OnPropertiesChanged;
|
||||
InspectCargoInternal();
|
||||
if (this is PropertiesList list)
|
||||
{
|
||||
if (list.Expanded)
|
||||
InspectCargoInternal();
|
||||
else
|
||||
list.OnExpand += b =>
|
||||
{
|
||||
if (b) InspectCargoInternal();
|
||||
};
|
||||
}
|
||||
else
|
||||
InspectCargoInternal();
|
||||
|
||||
void InspectCargoInternal()
|
||||
{
|
||||
|
|
@ -408,7 +432,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
var propertiesList = AddList($"{simpleCommodity.Quantity.ToString()} {data.Name}");
|
||||
propertiesList.AddItemProperties(entity, simpleCommodity);
|
||||
propertiesList.RefreshValues();
|
||||
propertiesList.SetExpanded(false, true);
|
||||
//propertiesList.SetExpanded(false, true);
|
||||
}
|
||||
|
||||
foreach (var group in entity.Cargo
|
||||
|
|
@ -429,19 +453,21 @@ public class PropertiesPanel : MonoBehaviour
|
|||
var propertiesList = AddList(item.Name);
|
||||
propertiesList.AddItemProperties(entity, item);
|
||||
propertiesList.RefreshValues();
|
||||
propertiesList.SetExpanded(false, true);
|
||||
//propertiesList.SetExpanded(false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var instanceList = AddList($"{group.Count().ToString()} {group.Key.Name}");
|
||||
foreach (var item in group)
|
||||
instanceList.OnExpand += b =>
|
||||
{
|
||||
var propertiesList = instanceList.AddList(item.Name);
|
||||
propertiesList.AddItemProperties(entity, item);
|
||||
propertiesList.RefreshValues();
|
||||
propertiesList.SetExpanded(false, true);
|
||||
}
|
||||
instanceList.SetExpanded(false, true);
|
||||
if (!b || instanceList.Children > 0) return;
|
||||
foreach (var item in group)
|
||||
{
|
||||
var propertiesList = instanceList.AddList(item.Name);
|
||||
propertiesList.AddItemProperties(entity, item);
|
||||
propertiesList.RefreshValues();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -527,7 +553,6 @@ public class PropertiesPanel : MonoBehaviour
|
|||
AddProperty(childEntity.Name, null, data => onSelect(childEntity), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Inspect(Entity entity, Hardpoint hardpoint)
|
||||
|
|
@ -539,7 +564,18 @@ public class PropertiesPanel : MonoBehaviour
|
|||
return;
|
||||
OnPropertiesChanged = InspectGearInternal;
|
||||
ChangeSource.OnChanged += OnPropertiesChanged;
|
||||
InspectGearInternal();
|
||||
if (this is PropertiesList list)
|
||||
{
|
||||
if (list.Expanded)
|
||||
InspectGearInternal();
|
||||
else
|
||||
list.OnExpand += b =>
|
||||
{
|
||||
if (b) InspectGearInternal();
|
||||
};
|
||||
}
|
||||
else
|
||||
InspectGearInternal();
|
||||
|
||||
void InspectGearInternal()
|
||||
{
|
||||
|
|
@ -598,7 +634,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
var itemData = Context.Cache.Get<ItemData>(ingredient.Key);
|
||||
ingredientsList.AddProperty(itemData.Name, () => ingredient.Value.ToString());
|
||||
}
|
||||
ingredientsList.SetExpanded(false, true);
|
||||
// ingredientsList.SetExpanded(false, true);
|
||||
ingredientsList.RefreshValues();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue