Hypothermia & UI Fixes

Implemented hypothermia death, with associated postprocessing and HUD UI
Fixed heatstroke and hypothermia not triggering death events
Fixed target inventory dropdown not working in trade menu
Added ability to rename ship
Added player death on cockpit destruction
Fixed confirmation dialog not using onconfirm callback
Fixed faulty double click in inventory panel
Fading out heat texture when ship has uniform temperature
Fixed inventory panel displaying incorrect default when no cargo bay equipped
Fixed incorrect state for console and weapon effect managers when restarting from in-game menu
Fixed save/reload when ship is docked at a station
This commit is contained in:
Reinier Vens 2021-04-10 01:47:16 +01:00
commit 62d4221958
26 changed files with 867 additions and 138 deletions

View file

@ -27,7 +27,7 @@ public class ConfirmationDialog : PropertiesPanel
private void Start()
{
Cancel.onClick.AddListener(() => End());
Confirm.onClick.AddListener(() => End());
Confirm.onClick.AddListener(() => End(true));
if (CancelClickCatcher != null)
CancelClickCatcher.OnClick += data =>
{

View file

@ -29,6 +29,11 @@ public class ConsoleController
get => _instance ?? (_instance = new ConsoleController());
}
public static void ClearCommands()
{
_commands.Clear();
}
public static void AddCommand(string command, Action<string[]> action)
{
var lower = command.ToLowerInvariant();

View file

@ -62,6 +62,7 @@ public class InventoryMenu : MonoBehaviour
var cargo = GameManager.DockingBay ?? GameManager.CurrentEntity.CargoBays.FirstOrDefault();
if (cargo!=null)
InventoryPanels[0].Display(cargo);
else InventoryPanels[0].Clear();
if(GameManager.CurrentEntity != null)
InventoryPanels[1].Display(GameManager.CurrentEntity);
else InventoryPanels[1].Clear();
@ -285,14 +286,14 @@ public class InventoryMenu : MonoBehaviour
}
});
panel.OnClickAsObservable().Subscribe(data =>
panel.OnClickAsObservable().Subscribe(e =>
{
if (data is InventoryCargoEventData cargoEvent)
if (e.data is InventoryCargoEventData cargoEvent)
{
var item = cargoEvent.CargoBay.Occupancy[cargoEvent.Position.x, cargoEvent.Position.y];
if(item!=null)
{
if (Mouse.current.clickCount.ReadValue() == 2)
if (e.clickCount == 2)
{
var otherPanel = panel == InventoryPanels[0] ? InventoryPanels[1] : InventoryPanels[0];
if (otherPanel.CanDropItem(item))
@ -335,12 +336,12 @@ public class InventoryMenu : MonoBehaviour
}
}
}
else if (data is InventoryEntityEventData entityEvent)
else if (e.data is InventoryEntityEventData entityEvent)
{
var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y];
if (item != null)
{
if (Mouse.current.clickCount.ReadValue() == 2)
if (e.clickCount == 2)
{
var otherPanel = panel == InventoryPanels[0] ? InventoryPanels[1] : InventoryPanels[0];
if (otherPanel.CanDropItem(item.EquippableItem))

View file

@ -20,7 +20,7 @@ using int2 = Unity.Mathematics.int2;
public class InventoryPanel : MonoBehaviour, IPointerClickHandler
{
[FormerlySerializedAs("ConfirmationDialog")] public ConfirmationDialog Dialog;
public ConfirmationDialog Dialog;
public bool Flip;
public GameSettings Settings;
public ActionGameManager GameManager;
@ -30,6 +30,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
public TextMeshProUGUI MaxTempLabel;
public GameObject TemperatureRange;
public Button Dropdown;
public Button EditName;
public Button Current;
public Button Thermal;
public GridLayoutGroup Grid;
@ -47,12 +48,13 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
public Color ToggleEnabledColor;
public Color ToggleDisabledColor;
public Color CellBackgroundColor = new Color(0, 0, 0, .75f);
public float MinTempRange;
public float MinTempRange = 1;
public float DoubleClickTime = .5f;
Subject<InventoryEventData> _onBeginDrag;
Subject<InventoryEventData> _onDrag;
Subject<InventoryEventData> _onEndDrag;
Subject<InventoryEventData> _onClick;
Subject<(InventoryEventData data, int clickCount)> _onClick;
Subject<InventoryEventData> _onPointerEnter;
Subject<InventoryEventData> _onPointerExit;
@ -72,6 +74,9 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
private Dictionary<int2, int> _cellAnimationSequence = new Dictionary<int2, int>();
private int _hitSequence = 0;
private bool _thermal = false;
private int _clickCount;
private InventoryCell _clickCell;
private float _clickTime;
private bool _hud;
@ -122,6 +127,23 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
}
});
}
if (EditName)
{
EditName.onClick.AddListener(() =>
{
Dialog.Clear();
var entityName = _displayedEntity.Name;
Dialog.AddField("Name", () => entityName, s => entityName = s);
Dialog.Show(() =>
{
_displayedEntity.Name = entityName;
Title.text = _displayedEntity.Name;
});
Dialog.MoveToCursor();
});
}
if(Dropdown)
{
Dropdown.onClick.AddListener(() =>
@ -134,7 +156,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
var options = entity.CargoBays
.Where(bay => bay != _displayedCargo)
.Select<EquippedCargoBay, (string text, Action action, bool enabled)>((bay, index) =>
($"Bay {index}", () => Display(bay), true));
($"Bay {index+1}", () => Display(bay), true));
if(entity != _displayedEntity) options = options.Prepend(("Equipment", () => Display(entity), true));
ContextMenu.AddDropdown(entity.Name, options);
}
@ -180,6 +202,8 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
{
if (_displayedEntity != null && TemperatureDisplay)
{
var tempRange = _displayedEntity.MaxTemp - _displayedEntity.MinTemp;
var opacity = smoothstep(0, MinTempRange, tempRange);
if(MinTempLabel)
{
MinTempLabel.text = $"{((int) (_displayedEntity.MinTemp - 273.15f)).ToString()}°C";
@ -194,7 +218,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
{
var temp = (_displayedEntity.Temperature[x - 1, y - 1] - _displayedEntity.MinTemp) / (_displayedEntity.MaxTemp-_displayedEntity.MinTemp);
var color = TemperatureColor.GetPixelBilinear(TemperatureColorCurve.Evaluate(temp), 0);
color.a = TemperatureAlphaCurve.Evaluate(temp);
color.a = TemperatureAlphaCurve.Evaluate(temp) * opacity;
_temperatureTexture.SetPixel(x,y,color);
}
else
@ -230,17 +254,12 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
_subscriptions.Clear();
if (Current)
Current.gameObject.SetActive(false);
if (Thermal)
Thermal.gameObject.SetActive(false);
if (Current) Current.gameObject.SetActive(false);
if (Thermal) Thermal.gameObject.SetActive(false);
if (TemperatureRange) TemperatureRange.SetActive(false);
if(TemperatureDisplay) TemperatureDisplay.gameObject.SetActive(false);
if (EditName) EditName.gameObject.SetActive(false);
if (TemperatureRange)
TemperatureRange.SetActive(false);
if(TemperatureDisplay)
TemperatureDisplay.gameObject.SetActive(false);
if(Title)
Title.text = "None";
}
@ -261,6 +280,11 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
if(Title)
Title.text = entity.Name;
if (EditName)
{
EditName.gameObject.SetActive(true);
}
var hullData = GameManager.ItemManager.GetData(entity.Hull) as HullData;
if (FitToContent)
@ -317,7 +341,15 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
if(cell.PointerClickTrigger)
{
cell.PointerClickTrigger.OnPointerClickAsObservable()
.Subscribe(data => _onClick?.OnNext(new InventoryEntityEventData(data, v, entity)));
.Subscribe(data =>
{
if (cell != _clickCell || Time.time - _clickTime > DoubleClickTime)
_clickCount = 0;
_clickCell = cell;
_clickTime = Time.time;
_clickCount++;
_onClick?.OnNext((new InventoryEntityEventData(data, v, entity), _clickCount));
});
cell.BeginDragTrigger.OnBeginDragAsObservable()
.Subscribe(data => _onBeginDrag?.OnNext(new InventoryEntityEventData(data, v, entity)));
cell.DragTrigger.OnDragAsObservable()
@ -436,7 +468,15 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
{
var cell = NodePrototype.Instantiate<InventoryCell>();
cell.PointerClickTrigger.OnPointerClickAsObservable()
.Subscribe(data => _onClick?.OnNext(new InventoryCargoEventData(data, v, cargo)));
.Subscribe(data =>
{
if (cell != _clickCell || Time.time - _clickTime > DoubleClickTime)
_clickCount = 0;
_clickCell = cell;
_clickTime = Time.time;
_clickCount++;
_onClick?.OnNext((new InventoryCargoEventData(data, v, cargo), _clickCount));
});
cell.BeginDragTrigger.OnBeginDragAsObservable()
.Subscribe(data => _onBeginDrag?.OnNext(new InventoryCargoEventData(data, v, cargo)));
cell.DragTrigger.OnDragAsObservable()
@ -676,7 +716,7 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
}
public Subject<PointerEventData> OnBackgroundClick = new Subject<PointerEventData>();
public UniRx.IObservable<InventoryEventData> OnClickAsObservable() => _onClick ?? (_onClick = new Subject<InventoryEventData>());
public Subject<(InventoryEventData data, int clickCount)> OnClickAsObservable() => _onClick ?? (_onClick = new Subject<(InventoryEventData data, int clickCount)>());
public UniRx.IObservable<InventoryEventData> OnBeginDragAsObservable() => _onBeginDrag ?? (_onBeginDrag = new Subject<InventoryEventData>());
public UniRx.IObservable<InventoryEventData> OnDragAsObservable() => _onDrag ?? (_onDrag = new Subject<InventoryEventData>());
public UniRx.IObservable<InventoryEventData> OnEndDragAsObservable() => _onEndDrag ?? (_onEndDrag = new Subject<InventoryEventData>());

View file

@ -36,6 +36,7 @@ public class SchematicDisplay : MonoBehaviour
public RectTransform EnergyFill;
public RectTransform HullDurabilityFill;
public RectTransform HeatstrokeMeterFill;
public RectTransform HypothermiaMeterFill;
public RectTransform HeatstrokeLimitFill;
public CanvasGroup TriggerGroups;
@ -249,7 +250,8 @@ public class SchematicDisplay : MonoBehaviour
CockpitTemperatureLabel.text = $"{((int) (_cockpit.Item.Temperature - 273.15f)).ToString()}°C";
HeatstrokeMeterFill.anchorMax = new Vector2(_entity.Heatstroke, 1);
HeatstrokeLimitFill.anchorMax = new Vector2(_cockpit.Item.Temperature / Settings.GameplaySettings.HeatstrokeTemperature, 1);
HypothermiaMeterFill.anchorMax = new Vector2(_entity.Hypothermia, 1);
HeatstrokeLimitFill.anchorMax = new Vector2(unlerp(Settings.GameplaySettings.HypothermiaTemperature, Settings.GameplaySettings.HeatstrokeTemperature, _cockpit.Item.Temperature), 1);
}
SensorCooldownFill.anchorMax = new Vector2(_entity.Sensor?.Cooldown ?? 0, 1);

View file

@ -69,7 +69,7 @@ public class TradeMenu : MonoBehaviour
ContextMenu.AddDropdown("Gear Type", hardpointTypes
.Select<HardpointType, (string, Action, bool)>(x => (Enum.GetName(typeof(HardpointType), x), () =>
{
if (_hardpointFilter.filter == null)
if (!_hardpointFilter.filter)
{
_hardpointFilter.filter = FilterPrototype.Instantiate<ItemFilter>();
_hardpointFilter.filter.OnDisable += () =>
@ -78,12 +78,12 @@ public class TradeMenu : MonoBehaviour
Populate();
};
}
if(_commodityFilter.filter != null)
if(_commodityFilter.filter)
{
_commodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
_commodityFilter.filter = null;
}
if(_compoundCommodityFilter.filter != null)
if(_compoundCommodityFilter.filter)
{
_compoundCommodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
_compoundCommodityFilter.filter = null;
@ -96,7 +96,7 @@ public class TradeMenu : MonoBehaviour
ContextMenu.AddDropdown("Simple Commodity", commodityTypes
.Select<SimpleCommodityCategory, (string, Action, bool)>(x => (Enum.GetName(typeof(SimpleCommodityCategory), x), () =>
{
if (_commodityFilter.filter == null)
if (!_commodityFilter.filter)
{
_commodityFilter.filter = FilterPrototype.Instantiate<ItemFilter>();
_commodityFilter.filter.OnDisable += () =>
@ -105,12 +105,12 @@ public class TradeMenu : MonoBehaviour
Populate();
};
}
if(_hardpointFilter.filter != null)
if(_hardpointFilter.filter)
{
_hardpointFilter.filter.GetComponent<Prototype>().ReturnToPool();
_hardpointFilter.filter = null;
}
if(_compoundCommodityFilter.filter != null)
if(_compoundCommodityFilter.filter)
{
_compoundCommodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
_compoundCommodityFilter.filter = null;
@ -123,7 +123,7 @@ public class TradeMenu : MonoBehaviour
ContextMenu.AddDropdown("Compound Commodity", compoundCommodityTypes
.Select<CompoundCommodityCategory, (string, Action, bool)>(x => (Enum.GetName(typeof(CompoundCommodityCategory), x), () =>
{
if (_compoundCommodityFilter.filter == null)
if (!_compoundCommodityFilter.filter)
{
_compoundCommodityFilter.filter = FilterPrototype.Instantiate<ItemFilter>();
_compoundCommodityFilter.filter.OnDisable += () =>
@ -132,12 +132,12 @@ public class TradeMenu : MonoBehaviour
Populate();
};
}
if(_hardpointFilter.filter != null)
if(_hardpointFilter.filter)
{
_hardpointFilter.filter.GetComponent<Prototype>().ReturnToPool();
_hardpointFilter.filter = null;
}
if(_commodityFilter.filter != null)
if(_commodityFilter.filter)
{
_commodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
_commodityFilter.filter = null;
@ -449,13 +449,19 @@ public class TradeMenu : MonoBehaviour
foreach (var ship in GameManager.CurrentEntity.Parent.Children.Where(e => e is Ship {IsPlayerShip: true}))
{
foreach (var bay in ship.CargoBays.Select((bay, index) => (bay, index)))
ContextMenu.AddOption($"{ship.Name} Bay {bay.index}",
() =>
{
_targetCargo = bay.bay;
TargetCargoLabel.text = $"{ship.Name} Bay {bay.index}";
});
{
if(_targetCargo != bay.bay)
{
ContextMenu.AddOption($"{ship.Name} Bay {bay.index+1}",
() =>
{
_targetCargo = bay.bay;
TargetCargoLabel.text = $"{ship.Name} Bay {bay.index+1}";
});
}
}
}
ContextMenu.Show();
});
}