Gear Schematic HUD
Created in-flight equipment HUD & schematic display
This commit is contained in:
parent
6db7c65961
commit
1e273d691e
253 changed files with 19369 additions and 6296 deletions
|
|
@ -30,6 +30,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
public MapRenderer MenuMap;
|
||||
public InventoryMenu Inventory;
|
||||
public InventoryPanel ShipPanel;
|
||||
public ConfirmationDialog ConfirmationDialog;
|
||||
public float2 Sensitivity;
|
||||
|
||||
//public PlayerInput Input;
|
||||
|
|
@ -179,6 +180,9 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
var reactorData = ItemData.GetAll<GearData>().First(x => x.HardpointType == HardpointType.Reactor && x.Shape.Height == 2);
|
||||
ship.TryEquip(ItemManager.CreateInstance(reactorData, .5f, 1) as EquippableItem);
|
||||
|
||||
var cockpitData = ItemData.GetAll<GearData>().First(x => x.Behaviors.Any(b=>b is CockpitData));
|
||||
ship.TryEquip(ItemManager.CreateInstance(cockpitData, .5f, 1) as EquippableItem);
|
||||
//dockingCargo.TryStore(ItemManager.CreateInstance(reactorData, .5f, 1));
|
||||
|
||||
Dock();
|
||||
|
|
@ -228,7 +232,22 @@ public class ActionGameManager : MonoBehaviour
|
|||
public void Undock()
|
||||
{
|
||||
if (_currentShip.Parent == null) return;
|
||||
if (_currentShip.Parent.TryUndock(_currentShip))
|
||||
if (_currentShip.GetBehavior<Cockpit>() == null)
|
||||
{
|
||||
ConfirmationDialog.Title.text = "Can't undock. Missing cockpit component!";
|
||||
ConfirmationDialog.Show();
|
||||
}
|
||||
else if (_currentShip.GetBehavior<Thruster>() == null)
|
||||
{
|
||||
ConfirmationDialog.Title.text = "Can't undock. Missing thruster component!";
|
||||
ConfirmationDialog.Show();
|
||||
}
|
||||
else if (_currentShip.GetBehavior<Reactor>() == null)
|
||||
{
|
||||
ConfirmationDialog.Title.text = "Can't undock. Missing reactor component!";
|
||||
ConfirmationDialog.Show();
|
||||
}
|
||||
else if (_currentShip.Parent.TryUndock(_currentShip))
|
||||
{
|
||||
Menu.gameObject.SetActive(false);
|
||||
_currentShip.Active = true;
|
||||
|
|
@ -242,6 +261,11 @@ public class ActionGameManager : MonoBehaviour
|
|||
_input.Player.Enable();
|
||||
ShipPanel.Display(_currentShip);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfirmationDialog.Title.text = "Can't undock. Must empty docking bay!";
|
||||
ConfirmationDialog.Show();
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveZone() => File.WriteAllBytes(
|
||||
|
|
|
|||
41
Assets/Scripts/Editor/GameplaySettingsEditor.cs
Normal file
41
Assets/Scripts/Editor/GameplaySettingsEditor.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using MessagePack.Formatters;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(GameSettings))]
|
||||
public class GameSettingsEditor : Editor
|
||||
{
|
||||
private bool _showIcons;
|
||||
private bool _showProperties;
|
||||
private bool _showDatabase;
|
||||
|
||||
// private ScriptableItem _prefab;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var data = (GameSettings) target;
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
DrawDefaultInspector();
|
||||
|
||||
var hardpointNames = Enum.GetNames(typeof(HardpointType));
|
||||
if(data.ItemIcons.Length!=hardpointNames.Length)
|
||||
Array.Resize(ref data.ItemIcons, hardpointNames.Length);
|
||||
|
||||
if (GUILayout.Button("Hardpoint Icons", EditorStyles.toolbarButton))
|
||||
_showIcons = !_showIcons;
|
||||
|
||||
if(_showIcons)
|
||||
for (var i = 0; i < data.ItemIcons.Length; i++)
|
||||
data.ItemIcons[i] = (Sprite) EditorGUILayout.ObjectField(hardpointNames[i], data.ItemIcons[i], typeof(Sprite), false);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Editor/GameplaySettingsEditor.cs.meta
Normal file
11
Assets/Scripts/Editor/GameplaySettingsEditor.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6161c03786aebc645a8d8b814afecee2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -24,6 +24,7 @@ public class GameSettings : ScriptableObject
|
|||
public PlanetSettings PlanetSettings;
|
||||
public ZoneGenerationSettings ZoneSettings;
|
||||
public GameplaySettings GameplaySettings;
|
||||
[HideInInspector] public Sprite[] ItemIcons;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
|
|
|||
|
|
@ -45,6 +45,11 @@ public interface IAlwaysUpdatedBehavior
|
|||
void AlwaysUpdate(float delta);
|
||||
}
|
||||
|
||||
public interface IProgressBehavior
|
||||
{
|
||||
float Progress { get; }
|
||||
}
|
||||
|
||||
public interface IOrderedBehavior
|
||||
{
|
||||
int Order { get; }
|
||||
|
|
@ -111,6 +116,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(30, typeof(HaulingControllerData)),
|
||||
Union(31, typeof(CapacitorData)),
|
||||
Union(32, typeof(CockpitData)),
|
||||
Union(33, typeof(HeatsinkData)),
|
||||
JsonConverter(typeof(JsonKnownTypesConverter<BehaviorData>)), JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class BehaviorData
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ public class Cockpit : IBehavior
|
|||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public float Heatstroke { get; private set; }
|
||||
|
||||
public Cockpit(ItemManager context, CockpitData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
|
|
@ -33,10 +35,22 @@ public class Cockpit : IBehavior
|
|||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Heatstroke = 0;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
if (Item.Temperature > Context.GameplaySettings.HeatstrokeTemperature)
|
||||
{
|
||||
Heatstroke = saturate(
|
||||
Heatstroke +
|
||||
pow(Item.Temperature - Context.GameplaySettings.HeatstrokeTemperature, Context.GameplaySettings.HeatstrokeExponent) *
|
||||
Context.GameplaySettings.HeatstrokeMultiplier * delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
Heatstroke = saturate(Heatstroke - Context.GameplaySettings.HeatstrokeRecoverySpeed * delta);
|
||||
}
|
||||
return Heatstroke < Context.GameplaySettings.HeatstrokeControlLimit;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,8 @@ using System;
|
|||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-10), RuntimeInspectable]
|
||||
public class CooldownData : BehaviorData
|
||||
|
|
@ -19,7 +21,7 @@ public class CooldownData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
public class Cooldown : IBehavior, IAlwaysUpdatedBehavior
|
||||
public class Cooldown : IBehavior, IAlwaysUpdatedBehavior, IProgressBehavior
|
||||
{
|
||||
private CooldownData _data;
|
||||
public BehaviorData Data => _data;
|
||||
|
|
@ -30,6 +32,8 @@ public class Cooldown : IBehavior, IAlwaysUpdatedBehavior
|
|||
|
||||
private float _cooldown; // Normalized
|
||||
|
||||
public float Progress => saturate(_cooldown);
|
||||
|
||||
public Cooldown(ItemManager context, CooldownData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
|
|
|
|||
42
Assets/Scripts/ServerShared/Behaviors/Heatsink.cs
Normal file
42
Assets/Scripts/ServerShared/Behaviors/Heatsink.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class HeatsinkData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new Heatsink(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Heatsink : IBehavior
|
||||
{
|
||||
private HeatsinkData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Heatsink(ItemManager context, HeatsinkData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Behaviors/Heatsink.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Behaviors/Heatsink.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0933c645c44822441a0d2d8e06c8d343
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -38,6 +38,8 @@ public class Reactor : IBehavior, IOrderedBehavior
|
|||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public float Surplus { get; private set; }
|
||||
|
||||
public int Order => 100;
|
||||
|
||||
|
|
@ -67,6 +69,8 @@ public class Reactor : IBehavior, IOrderedBehavior
|
|||
|
||||
Item.AddHeat(charge / efficiency);
|
||||
Entity.Energy += charge;
|
||||
|
||||
Surplus = Entity.Energy;
|
||||
|
||||
// We have an energy deficit, try to get some energy out of our capacitors first
|
||||
if (Entity.Energy < 0)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ public abstract class Entity
|
|||
public readonly Dictionary<string, float> Messages = new Dictionary<string, float>();
|
||||
public readonly Dictionary<object, float> VisibilitySources = new Dictionary<object, float>();
|
||||
|
||||
private List<IPopulationAssignment> PopulationAssignments = new List<IPopulationAssignment>();
|
||||
public readonly List<EquippedItem>[] TriggerGroups;
|
||||
|
||||
public List<IPopulationAssignment> PopulationAssignments = new List<IPopulationAssignment>();
|
||||
|
||||
public EquippedItem[,] GearOccupancy;
|
||||
public EquippedItem[,] ThermalOccupancy;
|
||||
|
|
@ -86,14 +88,15 @@ public abstract class Entity
|
|||
Hull = hull;
|
||||
Name = hull.Name;
|
||||
MapShip();
|
||||
TriggerGroups = new List<EquippedItem>[itemManager.GameplaySettings.TriggerGroupCount];
|
||||
for(int i=0; i<itemManager.GameplaySettings.TriggerGroupCount; i++)
|
||||
TriggerGroups[i] = new List<EquippedItem>();
|
||||
}
|
||||
|
||||
private void MapShip()
|
||||
{
|
||||
var hullData = ItemManager.GetData(Hull) as HullData;
|
||||
var hull = new EquippedItem(ItemManager, Hull, int2.zero, this);
|
||||
Equipment.Add(hull);
|
||||
Hydrate(hull);
|
||||
Equipment.Add(new EquippedItem(ItemManager, Hull, int2.zero, this));
|
||||
Mass = hullData.Mass;
|
||||
Temperature = new float[hullData.Shape.Width, hullData.Shape.Height];
|
||||
Conductivity = new float4[hullData.Shape.Width, hullData.Shape.Height];
|
||||
|
|
@ -118,45 +121,25 @@ public abstract class Entity
|
|||
}
|
||||
}
|
||||
|
||||
public void Hydrate(EquippedItem equippedItem)
|
||||
{
|
||||
if (equippedItem.EquippableItem == null)
|
||||
{
|
||||
ItemManager.Log("Attempted to hydrate EquippedGear with no gear on it! This should be impossible!");
|
||||
return;
|
||||
}
|
||||
|
||||
var gearData = ItemManager.GetData(equippedItem.EquippableItem);
|
||||
|
||||
equippedItem.Behaviors = gearData.Behaviors
|
||||
.Select(bd => bd.CreateInstance(ItemManager, this, equippedItem))
|
||||
.ToArray();
|
||||
|
||||
equippedItem.BehaviorGroups = equippedItem.Behaviors
|
||||
.GroupBy(b => b.Data.Group)
|
||||
.OrderBy(g=>g.Key)
|
||||
.Select(g=> new BehaviorGroup {
|
||||
Behaviors = g.ToArray(),
|
||||
//Axis = (IAnalogBehavior) g.FirstOrDefault(b=>b is IAnalogBehavior),
|
||||
Switch = (Switch) g.FirstOrDefault(b=>b is Switch),
|
||||
Trigger = (Trigger) g.FirstOrDefault(b=>b is Trigger)
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
foreach (var behavior in equippedItem.Behaviors)
|
||||
{
|
||||
if (behavior is IOrderedBehavior orderedBehavior)
|
||||
equippedItem.SortPosition = orderedBehavior.Order;
|
||||
if(behavior is IPopulationAssignment populationAssignment)
|
||||
PopulationAssignments.Add(populationAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddHeat(int2 position, float heat)
|
||||
{
|
||||
Temperature[position.x, position.y] += heat / ThermalMass[position.x, position.y];
|
||||
}
|
||||
|
||||
public int CountItemsInCargo(Guid itemDataID)
|
||||
{
|
||||
int sum = 0;
|
||||
foreach (var x in CargoBays)
|
||||
{
|
||||
if (x.ItemsOfType.ContainsKey(itemDataID))
|
||||
{
|
||||
foreach (var i in x.ItemsOfType[itemDataID]) sum += i is SimpleCommodity simpleCommodity ? simpleCommodity.Quantity : 1;
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
public EquippedCargoBay FindItemInCargo(Guid itemDataID)
|
||||
{
|
||||
return CargoBays.FirstOrDefault(c => c.ItemsOfType.ContainsKey(itemDataID));
|
||||
|
|
@ -376,7 +359,6 @@ public abstract class Entity
|
|||
}
|
||||
|
||||
Mass += itemData.Mass;
|
||||
Hydrate(equippedItem);
|
||||
_orderedEquipment = Equipment.OrderBy(x => x.SortPosition).ToArray();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -394,7 +376,6 @@ public abstract class Entity
|
|||
}
|
||||
|
||||
Mass += itemData.Mass;
|
||||
Hydrate(equippedItem);
|
||||
_orderedEquipment = Equipment.OrderBy(x => x.SortPosition).ToArray();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -642,6 +623,29 @@ public class EquippedItem
|
|||
Position = position;
|
||||
var hullData = itemManager.GetData(entity.Hull);
|
||||
InsetShape = hullData.Shape.Inset(_data.Shape, position, item.Rotation);
|
||||
|
||||
Behaviors = _data.Behaviors
|
||||
.Select(bd => bd.CreateInstance(itemManager, entity, this))
|
||||
.ToArray();
|
||||
|
||||
BehaviorGroups = Behaviors
|
||||
.GroupBy(b => b.Data.Group)
|
||||
.OrderBy(g=>g.Key)
|
||||
.Select(g=> new BehaviorGroup {
|
||||
Behaviors = g.ToArray(),
|
||||
//Axis = (IAnalogBehavior) g.FirstOrDefault(b=>b is IAnalogBehavior),
|
||||
Switch = (Switch) g.FirstOrDefault(b=>b is Switch),
|
||||
Trigger = (Trigger) g.FirstOrDefault(b=>b is Trigger)
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
foreach (var behavior in Behaviors)
|
||||
{
|
||||
if (behavior is IOrderedBehavior orderedBehavior)
|
||||
SortPosition = orderedBehavior.Order;
|
||||
if(behavior is IPopulationAssignment populationAssignment)
|
||||
entity.PopulationAssignments.Add(populationAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddHeat(float heat)
|
||||
|
|
|
|||
|
|
@ -79,7 +79,9 @@ public enum SimpleCommodityCategory
|
|||
Metals,
|
||||
Alloys,
|
||||
Compounds,
|
||||
Organics
|
||||
Organics,
|
||||
Ammo,
|
||||
Consumer
|
||||
}
|
||||
|
||||
public enum CompoundCommodityCategory
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ public class ZoneGenerationSettings
|
|||
[Serializable, MessagePackObject(keyAsPropertyName: true), JsonObject]
|
||||
public class GameplaySettings
|
||||
{
|
||||
public int TriggerGroupCount = 6;
|
||||
public float WarpDistance = 25;
|
||||
public float DockingDistance = 25;
|
||||
public int SignificantDigits = 3;
|
||||
|
|
@ -98,5 +99,9 @@ public class GameplaySettings
|
|||
public float HeatRadiationExponent = 1;
|
||||
public float HeatRadiationMultiplier = 1;
|
||||
public float HeatConductionMultiplier = 1;
|
||||
|
||||
public float HeatstrokeTemperature = 330;
|
||||
public float HeatstrokeMultiplier = .00001f;
|
||||
public float HeatstrokeExponent = 2;
|
||||
public float HeatstrokeRecoverySpeed = .2f;
|
||||
public float HeatstrokeControlLimit = .75f;
|
||||
}
|
||||
|
|
@ -49,10 +49,12 @@ public class ConfirmationDialog : PropertiesPanel
|
|||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void Show(Action onConfirm, Action onCancel = null)
|
||||
public void Show(Action onConfirm = null, Action onCancel = null)
|
||||
{
|
||||
_onConfirm = onConfirm;
|
||||
Confirm.gameObject.SetActive(onConfirm!=null);
|
||||
_onCancel = onCancel;
|
||||
Cancel.gameObject.SetActive(onCancel!=null);
|
||||
transform.position = Input.mousePosition;
|
||||
CancelClickCatcher.gameObject.SetActive(true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue