Weapon Scripting Overhaul
Weapons are now monolithic behaviors Various new weapon behavior types implemented All weapons have optional magazine and reload mechanic Visibility now decays globally
This commit is contained in:
parent
48abee4847
commit
357f9db329
95 changed files with 2571 additions and 754 deletions
23
Assets/Scripts/UI/InventoryCell.cs
Normal file
23
Assets/Scripts/UI/InventoryCell.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* 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;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UniRx.Triggers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class InventoryCell : MonoBehaviour
|
||||
{
|
||||
public Image Background;
|
||||
public Image Icon;
|
||||
|
||||
public ObservablePointerClickTrigger PointerClickTrigger;
|
||||
public ObservableBeginDragTrigger BeginDragTrigger;
|
||||
public ObservableDragTrigger DragTrigger;
|
||||
public ObservableEndDragTrigger EndDragTrigger;
|
||||
public ObservablePointerEnterTrigger PointerEnterTrigger;
|
||||
public ObservablePointerExitTrigger PointerExitTrigger;
|
||||
}
|
||||
11
Assets/Scripts/UI/InventoryCell.cs.meta
Normal file
11
Assets/Scripts/UI/InventoryCell.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e28c3f1c546ff7544a127c24a6ee3091
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
333
Assets/Scripts/UI/InventoryMenu.cs
Normal file
333
Assets/Scripts/UI/InventoryMenu.cs
Normal file
|
|
@ -0,0 +1,333 @@
|
|||
/* 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;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UniRx;
|
||||
using UniRx.Triggers;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class InventoryMenu : MonoBehaviour
|
||||
{
|
||||
public InventoryPanel[] InventoryPanels;
|
||||
public PropertiesPanel PropertiesPanel;
|
||||
public ActionGameManager GameManager;
|
||||
public RectTransform DragParent;
|
||||
public ConfirmationDialog Dialog;
|
||||
public ObservablePointerEnterTrigger BackgroundEntered;
|
||||
public ObservablePointerExitTrigger BackgroundExited;
|
||||
|
||||
private int _currentPanel = -1;
|
||||
|
||||
private int2 _selectedPosition;
|
||||
private InventoryPanel _selectedPanel;
|
||||
private ItemInstance _selectedItem;
|
||||
private ItemData _selectedItemData;
|
||||
|
||||
private ItemInstance _dragItem;
|
||||
private Transform[] _dragCells;
|
||||
private Vector2[] _dragOffsets;
|
||||
private int2 _dragCellOffset;
|
||||
private ItemRotation _originalRotation;
|
||||
//private Shape _previousFakeOccupancy;
|
||||
private Shape _originalOccupancy;
|
||||
private EquippedItem _originalEquippedItem;
|
||||
private InventoryPanel _originalPanel;
|
||||
|
||||
private InventoryPanel _dragTargetPanel;
|
||||
private int2 _dragTargetPosition;
|
||||
private int2 _lastDragPosition;
|
||||
private bool _dragTargetValid;
|
||||
private bool _destroyItem;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
BackgroundEntered.gameObject.SetActive(true);
|
||||
|
||||
BackgroundEntered.OnPointerEnterAsObservable().Subscribe(enter =>
|
||||
{
|
||||
_destroyItem = true;
|
||||
});
|
||||
BackgroundExited.OnPointerExitAsObservable().Subscribe(enter =>
|
||||
{
|
||||
_destroyItem = false;
|
||||
});
|
||||
var cargo = GameManager.DockingBay ?? GameManager.CurrentShip.CargoBays.FirstOrDefault();
|
||||
if (cargo!=null)
|
||||
InventoryPanels[0].Display(cargo);
|
||||
InventoryPanels[1].Display(GameManager.CurrentShip);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
BackgroundEntered.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
PropertiesPanel.Context = GameManager.ItemManager;
|
||||
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 = GameManager.ItemManager.GetData(item);
|
||||
|
||||
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<ObservableTriggerBase>())
|
||||
component.enabled = false;
|
||||
cell.GetComponentInChildren<Image>().raycastTarget = false;
|
||||
}
|
||||
_dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray();
|
||||
panel.IgnoreOccupancy = _originalOccupancy;
|
||||
panel.RefreshCells(_originalOccupancy.Expand().Coordinates);
|
||||
}
|
||||
}
|
||||
else if (data is InventoryEntityEventData entityEvent)
|
||||
{
|
||||
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<ObservableTriggerBase>())
|
||||
component.enabled = false;
|
||||
cell.GetComponentInChildren<Image>().raycastTarget = false;
|
||||
}
|
||||
_dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray();
|
||||
panel.IgnoreOccupancy = _originalOccupancy;
|
||||
panel.RefreshCells(_originalOccupancy.Expand().Coordinates);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
else if (data is InventoryEntityEventData entityEvent)
|
||||
{
|
||||
if (entityEvent.Entity.Unequip(_originalEquippedItem) != null)
|
||||
{
|
||||
_dragTargetPanel.DropItem(_dragItem, _dragTargetPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to move item!";
|
||||
Dialog.AddProperty("Verify that cargo bays are empty before un-equipping them.");
|
||||
Dialog.Show();
|
||||
}
|
||||
}
|
||||
|
||||
_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.Unequip(_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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
panel.IgnoreOccupancy = null;
|
||||
panel.RefreshCells();
|
||||
if(_dragTargetPanel!=panel)
|
||||
_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 = GameManager.ItemManager.GetData(_dragItem);
|
||||
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 = GameManager.ItemManager.GetData(_dragItem);
|
||||
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(data =>
|
||||
{
|
||||
if (data is InventoryCargoEventData cargoEvent)
|
||||
{
|
||||
var item = cargoEvent.CargoBay.Occupancy[cargoEvent.Position.x, cargoEvent.Position.y];
|
||||
if(item!=null)
|
||||
{
|
||||
if (_selectedPanel != null)
|
||||
{
|
||||
foreach (var v in _selectedItemData.Shape.Coordinates)
|
||||
{
|
||||
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
|
||||
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2);
|
||||
}
|
||||
}
|
||||
_selectedPanel = panel;
|
||||
_selectedPosition = cargoEvent.Position;
|
||||
PropertiesPanel.Clear();
|
||||
PropertiesPanel.AddItemProperties(item);
|
||||
_selectedPanel = panel;
|
||||
_selectedPosition = cargoEvent.CargoBay.Cargo[item];
|
||||
_selectedItem = item;
|
||||
_selectedItemData = GameManager.ItemManager.GetData(item);
|
||||
foreach (var v in _selectedItemData.Shape.Coordinates)
|
||||
{
|
||||
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
|
||||
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (data is InventoryEntityEventData entityEvent)
|
||||
{
|
||||
var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y];
|
||||
if (item != null)
|
||||
{
|
||||
if (_selectedPanel != null)
|
||||
{
|
||||
foreach (var v in _selectedItemData.Shape.Coordinates)
|
||||
{
|
||||
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
|
||||
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2);
|
||||
}
|
||||
}
|
||||
PropertiesPanel.Inspect(entityEvent.Entity, item);
|
||||
_selectedPanel = panel;
|
||||
_selectedPosition = item.Position;
|
||||
_selectedItem = item.EquippableItem;
|
||||
_selectedItemData = GameManager.ItemManager.GetData(item.EquippableItem);
|
||||
foreach (var v in _selectedItemData.Shape.Coordinates)
|
||||
{
|
||||
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
|
||||
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/InventoryMenu.cs.meta
Normal file
11
Assets/Scripts/UI/InventoryMenu.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 238f19b944b59394481b32a38d68dc0f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -12,7 +12,7 @@ public class PlaceUIElementWorldspace : MonoBehaviour
|
|||
{
|
||||
public float NoiseAmplitude;
|
||||
public float NoiseFrequency;
|
||||
public RectTransform CanvasRectTransform;
|
||||
public Canvas Canvas;
|
||||
public float BorderPixels = 10;
|
||||
|
||||
public Vector3 Target;
|
||||
|
|
@ -20,12 +20,14 @@ public class PlaceUIElementWorldspace : MonoBehaviour
|
|||
private RectTransform _rectTransform;
|
||||
private Transform _cameraTransform;
|
||||
private float _noiseOffset;
|
||||
private RectTransform _canvasRectTransform;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Get the rect transform
|
||||
_rectTransform = GetComponent<RectTransform>();
|
||||
_cameraTransform = Camera.main.transform;
|
||||
_canvasRectTransform = Canvas.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
|
|
@ -38,15 +40,12 @@ public class PlaceUIElementWorldspace : MonoBehaviour
|
|||
/// </summary>
|
||||
void LateUpdate()
|
||||
{
|
||||
if (Target == null)
|
||||
return;
|
||||
|
||||
_noiseOffset += Time.deltaTime * NoiseFrequency;
|
||||
|
||||
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, Target);
|
||||
screenPoint *= Mathf.Sign(Vector3.Dot(_cameraTransform.forward, Target - _cameraTransform.position));
|
||||
screenPoint += new Vector2(noise(_noiseOffset), noise(10 + _noiseOffset)) * NoiseAmplitude;
|
||||
screenPoint = new Vector2(Mathf.Clamp(screenPoint.x, BorderPixels, Screen.width - BorderPixels),Mathf.Clamp(screenPoint.y, BorderPixels, Screen.height - BorderPixels));
|
||||
_rectTransform.anchoredPosition = screenPoint - CanvasRectTransform.sizeDelta / 2f;
|
||||
_rectTransform.anchoredPosition = screenPoint / Canvas.scaleFactor - _canvasRectTransform.sizeDelta / 2f;
|
||||
}
|
||||
}
|
||||
290
Assets/Scripts/UI/SchematicDisplay.cs
Normal file
290
Assets/Scripts/UI/SchematicDisplay.cs
Normal file
|
|
@ -0,0 +1,290 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class SchematicDisplay : MonoBehaviour
|
||||
{
|
||||
public GameSettings Settings;
|
||||
public Prototype ListElementPrototype;
|
||||
public Prototype TriggerGroupPrototype;
|
||||
|
||||
public TextMeshProUGUI EnergyLabel;
|
||||
public TextMeshProUGUI CockpitTemperatureLabel;
|
||||
public TextMeshProUGUI RadiatorTemperatureLabel;
|
||||
public TextMeshProUGUI HeatsinkTemperatureLabel;
|
||||
public TextMeshProUGUI CargoTemperatureLabel;
|
||||
public TextMeshProUGUI VisibilityLabel;
|
||||
public TextMeshProUGUI HullDurabilityLabel;
|
||||
public TextMeshProUGUI DistanceLabel;
|
||||
|
||||
public RectTransform EnergyFill;
|
||||
public RectTransform HullDurabilityFill;
|
||||
public RectTransform HeatstrokeMeterFill;
|
||||
public RectTransform HeatstrokeLimitFill;
|
||||
|
||||
public CanvasGroup TriggerGroups;
|
||||
public float TriggerGroupsFadeDuration = .5f;
|
||||
public float TriggerGroupsPersistDuration = 5f;
|
||||
|
||||
public Color TriggerGroupColor;
|
||||
|
||||
private Entity _entity;
|
||||
private EquippableItem _hull;
|
||||
private Radiator[] _radiators;
|
||||
private Cockpit _cockpit;
|
||||
private Reactor _reactor;
|
||||
private Capacitor[] _capacitors;
|
||||
private Heatsink[] _heatsinks;
|
||||
private EquippedCargoBay[] _cargoBays;
|
||||
private SchematicDisplayItem[] _schematicItems;
|
||||
private Graphic[] _groupGraphics;
|
||||
|
||||
private int _selectedGroupIndex;
|
||||
private int _selectedItemIndex;
|
||||
private bool _triggerGroupsVisible;
|
||||
private float _triggerGroupsFadeOutTime;
|
||||
|
||||
private bool _enemy;
|
||||
private Entity _player;
|
||||
|
||||
public SchematicDisplayItem[] SchematicItems
|
||||
{
|
||||
get { return _schematicItems; }
|
||||
}
|
||||
|
||||
public int SelectedItemIndex
|
||||
{
|
||||
get => _selectedItemIndex;
|
||||
set
|
||||
{
|
||||
_selectedItemIndex = (value + _schematicItems.Length) % _schematicItems.Length;
|
||||
UpdateTriggerGroups();
|
||||
}
|
||||
}
|
||||
|
||||
public int SelectedGroupIndex
|
||||
{
|
||||
get => _selectedGroupIndex;
|
||||
set
|
||||
{
|
||||
_selectedGroupIndex = (value + Settings.GameplaySettings.TriggerGroupCount) % Settings.GameplaySettings.TriggerGroupCount;
|
||||
UpdateTriggerGroups();
|
||||
}
|
||||
}
|
||||
|
||||
public class SchematicDisplayItem
|
||||
{
|
||||
public EquippedItem Item;
|
||||
public SchematicListElement ListElement;
|
||||
public SchematicTriggerGroupElement TriggerGroupElement;
|
||||
public IProgressBehavior Cooldown;
|
||||
// public ItemUsage ItemUsage;
|
||||
public Weapon Weapon;
|
||||
}
|
||||
|
||||
public void ShowShip(Entity entity, Entity player = null)
|
||||
{
|
||||
_enemy = player != null;
|
||||
_player = player;
|
||||
if (_schematicItems != null)
|
||||
foreach (var item in _schematicItems)
|
||||
{
|
||||
item.ListElement.GetComponent<Prototype>().ReturnToPool();
|
||||
item.TriggerGroupElement?.GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
|
||||
_entity = entity;
|
||||
if (!_enemy)
|
||||
{
|
||||
_cockpit = entity.GetBehavior<Cockpit>();
|
||||
_reactor = entity.GetBehavior<Reactor>();
|
||||
_capacitors = entity.GetBehaviors<Capacitor>().ToArray();
|
||||
|
||||
_radiators = entity.GetBehaviors<Radiator>().ToArray();
|
||||
if (_radiators.Length == 0)
|
||||
RadiatorTemperatureLabel.text = "N/A";
|
||||
|
||||
_heatsinks = entity.GetBehaviors<Heatsink>().ToArray();
|
||||
if (_heatsinks.Length == 0)
|
||||
HeatsinkTemperatureLabel.text = "N/A";
|
||||
|
||||
_cargoBays = entity.CargoBays.ToArray();
|
||||
if (_cargoBays.Length == 0)
|
||||
CargoTemperatureLabel.text = "N/A";
|
||||
}
|
||||
|
||||
_schematicItems = entity.Equipment
|
||||
.Where(x => x.Behaviors.Any(b => b.Data is WeaponData))
|
||||
.Select(x => new SchematicDisplayItem
|
||||
{
|
||||
Item = x,
|
||||
ListElement = ListElementPrototype.Instantiate<SchematicListElement>(),
|
||||
TriggerGroupElement = _enemy ? null : TriggerGroupPrototype.Instantiate<SchematicTriggerGroupElement>(),
|
||||
Cooldown = _enemy ? null : (IProgressBehavior) x.Behaviors.FirstOrDefault(b=> b is IProgressBehavior),
|
||||
// ItemUsage = _enemy ? null : (ItemUsage) x.Behaviors.FirstOrDefault(b=> b is ItemUsage),
|
||||
Weapon = (Weapon) x.Behaviors.FirstOrDefault(b=>b is Weapon)
|
||||
})
|
||||
.ToArray();
|
||||
foreach (var x in _schematicItems)
|
||||
{
|
||||
x.ListElement.Icon.sprite = Settings.ItemIcons[(int) (entity.Hardpoints[x.Item.Position.x, x.Item.Position.y]?.Type ?? HardpointType.Tool)];
|
||||
x.ListElement.Label.text = x.Item.EquippableItem.Name;
|
||||
if (!_enemy)
|
||||
{
|
||||
x.ListElement.InfiniteAmmoIcon.gameObject.SetActive(x.Weapon.WeaponData.AmmoType == Guid.Empty);
|
||||
x.ListElement.AmmoLabel.gameObject.SetActive(x.Weapon.WeaponData.AmmoType != Guid.Empty);
|
||||
foreach (var group in x.TriggerGroupElement.GroupBackgrounds)
|
||||
group.color = TriggerGroupColor;
|
||||
}
|
||||
}
|
||||
if (!_enemy)
|
||||
UpdateTriggerGroups();
|
||||
}
|
||||
|
||||
public void UpdateTriggerGroups()
|
||||
{
|
||||
if (!_triggerGroupsVisible)
|
||||
{
|
||||
StartCoroutine(FadeInTriggerGroups());
|
||||
_triggerGroupsVisible = true;
|
||||
}
|
||||
_triggerGroupsFadeOutTime = Time.time + TriggerGroupsPersistDuration;
|
||||
for (var itemIndex = 0; itemIndex < _schematicItems.Length; itemIndex++)
|
||||
{
|
||||
var item = _schematicItems[itemIndex];
|
||||
for (var groupIndex = 0; groupIndex < item.TriggerGroupElement.GroupBackgrounds.Length; groupIndex++)
|
||||
{
|
||||
var backgroundColor = TriggerGroupColor;
|
||||
if (_selectedGroupIndex == groupIndex)
|
||||
backgroundColor.a *= 2;
|
||||
if (_selectedItemIndex == itemIndex)
|
||||
backgroundColor.a *= 2;
|
||||
item.TriggerGroupElement.GroupBackgrounds[groupIndex].color = backgroundColor;
|
||||
item.TriggerGroupElement.GroupLabel[groupIndex].color =
|
||||
_entity.TriggerGroups[groupIndex].items.Contains(item.Item) ? Color.white : Color.gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator FadeInTriggerGroups()
|
||||
{
|
||||
var startTime = Time.time;
|
||||
while (Time.time - startTime < TriggerGroupsFadeDuration)
|
||||
{
|
||||
var lerp = (Time.time - startTime) / TriggerGroupsFadeDuration;
|
||||
TriggerGroups.alpha = lerp;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
TriggerGroups.alpha = 1;
|
||||
}
|
||||
|
||||
IEnumerator FadeOutTriggerGroups()
|
||||
{
|
||||
var startTime = Time.time;
|
||||
while (Time.time - startTime < TriggerGroupsFadeDuration)
|
||||
{
|
||||
var lerp = (Time.time - startTime) / TriggerGroupsFadeDuration;
|
||||
TriggerGroups.alpha = 1-lerp;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
TriggerGroups.alpha = 0;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_triggerGroupsVisible && _triggerGroupsFadeOutTime < Time.time)
|
||||
{
|
||||
_triggerGroupsVisible = false;
|
||||
StartCoroutine(FadeOutTriggerGroups());
|
||||
}
|
||||
if (_entity != null)
|
||||
{
|
||||
if (!_enemy)
|
||||
{
|
||||
|
||||
if (_radiators.Length == 1)
|
||||
RadiatorTemperatureLabel.text = $"{(_radiators[0].Item.Temperature - 273.15f).SignificantDigits(3)}°C";
|
||||
else if (_radiators.Length > 1)
|
||||
RadiatorTemperatureLabel.text =
|
||||
$"{(_radiators.Min(r => r.Item.Temperature) - 273.15f).SignificantDigits(3)}-" +
|
||||
$"{(_radiators.Max(r => r.Item.Temperature) - 273.15f).SignificantDigits(3)}°C";
|
||||
|
||||
if (_heatsinks.Length == 1)
|
||||
HeatsinkTemperatureLabel.text = $"{(_heatsinks[0].Item.Temperature - 273.15f).SignificantDigits(3)}°C";
|
||||
else if (_heatsinks.Length > 1)
|
||||
HeatsinkTemperatureLabel.text =
|
||||
$"{(_heatsinks.Min(r => r.Item.Temperature) - 273.15f).SignificantDigits(3)}-" +
|
||||
$"{(_heatsinks.Max(r => r.Item.Temperature) - 273.15f).SignificantDigits(3)}°C";
|
||||
|
||||
if (_cargoBays.Length == 1)
|
||||
CargoTemperatureLabel.text = $"{(_cargoBays[0].Temperature - 273.15f).SignificantDigits(3)}°C";
|
||||
else if (_cargoBays.Length > 1)
|
||||
CargoTemperatureLabel.text =
|
||||
$"{(_cargoBays.Min(r => r.Temperature) - 273.15f).SignificantDigits(3)}-" +
|
||||
$"{(_cargoBays.Max(r => r.Temperature) - 273.15f).SignificantDigits(3)}°C";
|
||||
|
||||
CockpitTemperatureLabel.text = $"{(_cockpit.Item.Temperature - 273.15f).SignificantDigits(3)}°C";
|
||||
|
||||
HeatstrokeMeterFill.anchorMax = new Vector2(_cockpit.Heatstroke, 1);
|
||||
HeatstrokeLimitFill.anchorMax = new Vector2(_cockpit.Item.Temperature / Settings.GameplaySettings.HeatstrokeTemperature, 1);
|
||||
|
||||
if (_capacitors.Length == 0)
|
||||
{
|
||||
EnergyFill.anchorMax = Vector2.up;
|
||||
EnergyLabel.text = _reactor.Surplus.SignificantDigits(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
var charge = _capacitors.Sum(x => x.Charge);
|
||||
var maxCharge = _capacitors.Sum(x => x.Capacity);
|
||||
EnergyFill.anchorMax = new Vector2(charge / maxCharge, 1);
|
||||
EnergyLabel.text = $"{charge.SignificantDigits(3)}/{maxCharge.SignificantDigits(3)} ({_reactor.Surplus.SignificantDigits(3)})";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DistanceLabel.text = $"{(int)length(_entity.Position - _player.Position)}";
|
||||
}
|
||||
|
||||
VisibilityLabel.text = ((int)_entity.Visibility).ToString();
|
||||
|
||||
_hull = _entity.Hull;
|
||||
var hullData = _entity.ItemManager.GetData(_hull);
|
||||
var dur = _hull.Durability / hullData.Durability;
|
||||
HullDurabilityFill.anchorMax = new Vector2(dur, 1);
|
||||
HullDurabilityLabel.text = $"{(dur*100).SignificantDigits(3)}%";
|
||||
|
||||
foreach (var x in _schematicItems)
|
||||
{
|
||||
if (!_enemy)
|
||||
{
|
||||
var itemData = _entity.ItemManager.GetData(x.Item.EquippableItem);
|
||||
x.ListElement.HeatFill.anchorMax = new Vector2(unlerp(itemData.MinimumTemperature, itemData.MaximumTemperature, x.Item.Temperature), 0);
|
||||
if (x.Cooldown != null)
|
||||
x.ListElement.CooldownFill.anchorMax = new Vector2(x.Cooldown.Progress, 1);
|
||||
x.ListElement.DurabilityLabel.text = $"{(int)(x.Item.EquippableItem.Durability / itemData.Durability * 100)}%";
|
||||
if (x.Weapon.WeaponData.AmmoType != Guid.Empty)
|
||||
{
|
||||
if(x.Weapon.WeaponData.MagazineSize > 1)
|
||||
x.ListElement.AmmoLabel.text = x.Weapon.Ammo.ToString();
|
||||
else
|
||||
x.ListElement.AmmoLabel.text = _entity.CountItemsInCargo(x.Weapon.WeaponData.AmmoType).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
if (x.Weapon.WeaponData != null)
|
||||
{
|
||||
x.ListElement.RangeLabel.text = ((int) _entity.ItemManager.Evaluate(x.Weapon.WeaponData.Range, x.Item.EquippableItem, _entity)).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/SchematicDisplay.cs.meta
Normal file
11
Assets/Scripts/UI/SchematicDisplay.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 296faceaa1771414f8744840ecaa026c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/UI/SchematicListElement.cs
Normal file
17
Assets/Scripts/UI/SchematicListElement.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SchematicListElement : MonoBehaviour
|
||||
{
|
||||
public Image Icon;
|
||||
public TextMeshProUGUI Label;
|
||||
public TextMeshProUGUI DurabilityLabel;
|
||||
public TextMeshProUGUI RangeLabel;
|
||||
public TextMeshProUGUI AmmoLabel;
|
||||
public Image InfiniteAmmoIcon;
|
||||
public RectTransform CooldownFill;
|
||||
public RectTransform HeatFill;
|
||||
}
|
||||
11
Assets/Scripts/UI/SchematicListElement.cs.meta
Normal file
11
Assets/Scripts/UI/SchematicListElement.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6755ecd82e50a5d4bada4d900b47eeb4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Scripts/UI/SchematicTriggerGroupElement.cs
Normal file
10
Assets/Scripts/UI/SchematicTriggerGroupElement.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SchematicTriggerGroupElement : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI[] GroupLabel;
|
||||
public Image[] GroupBackgrounds;
|
||||
}
|
||||
3
Assets/Scripts/UI/SchematicTriggerGroupElement.cs.meta
Normal file
3
Assets/Scripts/UI/SchematicTriggerGroupElement.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8f090c2738224f698bdfa545978f4d5a
|
||||
timeCreated: 1609423819
|
||||
26
Assets/Scripts/UI/SizeFilter.cs
Normal file
26
Assets/Scripts/UI/SizeFilter.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SizeFilter : MonoBehaviour
|
||||
{
|
||||
public TMP_InputField Width;
|
||||
public TMP_InputField Height;
|
||||
public Button DisableButton;
|
||||
|
||||
public event Action OnDisable;
|
||||
|
||||
void Start()
|
||||
{
|
||||
DisableButton.onClick.AddListener(() =>
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
OnDisable?.Invoke();
|
||||
OnDisable = null;
|
||||
});
|
||||
//gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/SizeFilter.cs.meta
Normal file
11
Assets/Scripts/UI/SizeFilter.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8417880965a8e3a4e8d2586ab3ab0367
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
199
Assets/Scripts/UI/Spreadsheet.cs
Normal file
199
Assets/Scripts/UI/Spreadsheet.cs
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class Spreadsheet : MonoBehaviour
|
||||
{
|
||||
public Prototype ColumnDividerPrototype;
|
||||
public Prototype ColumnHeaderPrototype;
|
||||
public Prototype RowPrototype;
|
||||
public Color OddRowBackground;
|
||||
public Color EvenRowBackground;
|
||||
public int MinimumColumnSize = 50;
|
||||
|
||||
private List<RectTransform> _columnDividerInstances = new List<RectTransform>();
|
||||
private List<SpreadsheetRow> _rowInstances = new List<SpreadsheetRow>();
|
||||
private List<SpreadsheetColumnHeader> _columnInstances = new List<SpreadsheetColumnHeader>();
|
||||
private List<SpreadsheetEntryRow> _data = new List<SpreadsheetEntryRow>();
|
||||
private int[] _columnSizes;
|
||||
private int _sortColumn = -1;
|
||||
private bool _sortAscending = false;
|
||||
private Vector2 _dragStartPosition;
|
||||
private int _dragStartColumnSize;
|
||||
private int _dragStartNextColumnSize;
|
||||
|
||||
public void ShowData(string[] columnNames, int[] columnSizePriorities, IEnumerable<SpreadsheetEntryRow> data)
|
||||
{
|
||||
foreach(var col in _columnInstances)
|
||||
{
|
||||
col.Button.onClick.RemoveAllListeners();
|
||||
col.GetComponent<Prototype>().ReturnToPool();
|
||||
}
|
||||
_columnInstances.Clear();
|
||||
|
||||
foreach(var row in _rowInstances)
|
||||
row.GetComponent<Prototype>().ReturnToPool();
|
||||
_rowInstances.Clear();
|
||||
|
||||
foreach(var div in _columnDividerInstances)
|
||||
div.GetComponent<Prototype>().ReturnToPool();
|
||||
_columnDividerInstances.Clear();
|
||||
|
||||
_data.Clear();
|
||||
_data.AddRange(data);
|
||||
|
||||
_sortColumn = -1;
|
||||
|
||||
if(columnNames.Length != columnSizePriorities.Length)
|
||||
throw new ArgumentException("Spreadsheet column names and sizes do not match!");
|
||||
|
||||
foreach(var d in _data)
|
||||
if(columnNames.Length!=d.Columns.Length)
|
||||
throw new ArgumentException("Spreadsheet column names and row data do not match!");
|
||||
|
||||
var totalPriority = columnSizePriorities.Sum();
|
||||
var totalSize = Mathf.RoundToInt(GetComponent<RectTransform>().rect.width);
|
||||
_columnSizes = columnSizePriorities.Select(p => (int)((float) p / totalPriority * totalSize)).ToArray();
|
||||
|
||||
for (var i = 0; i < columnNames.Length; i++)
|
||||
{
|
||||
var columnHeader = ColumnHeaderPrototype.Instantiate<SpreadsheetColumnHeader>();
|
||||
columnHeader.SortIcon.gameObject.SetActive(false);
|
||||
columnHeader.Title.text = columnNames[i];
|
||||
var columnIndex = i;
|
||||
columnHeader.Button.onClick.AddListener(() =>
|
||||
{
|
||||
if (_sortColumn != -1)
|
||||
{
|
||||
_columnInstances[_sortColumn].SortIcon.gameObject.SetActive(false);
|
||||
}
|
||||
_sortAscending = _sortColumn == columnIndex && !_sortAscending;
|
||||
if(_sortAscending)
|
||||
_data.Sort((row1, row2) => row2.Columns[columnIndex].SortKey.CompareTo(row1.Columns[columnIndex].SortKey));
|
||||
else _data.Sort((row1, row2) => row1.Columns[columnIndex].SortKey.CompareTo(row2.Columns[columnIndex].SortKey));
|
||||
_sortColumn = columnIndex;
|
||||
_columnInstances[_sortColumn].SortIcon.gameObject.SetActive(true);
|
||||
_columnInstances[_sortColumn].SortIcon.rectTransform.rotation = Quaternion.Euler(0,0, _sortAscending ? -90 : 90);
|
||||
RefreshData();
|
||||
RepositionColumns();
|
||||
});
|
||||
columnHeader.ResizeBeginDragTrigger.OnBeginDragAsObservable().Subscribe(e =>
|
||||
{
|
||||
_dragStartPosition = e.position;
|
||||
_dragStartColumnSize = _columnSizes[columnIndex];
|
||||
_dragStartNextColumnSize = columnIndex != columnNames.Length-1 ? _columnSizes[columnIndex + 1] : 0;
|
||||
});
|
||||
columnHeader.ResizeDragTrigger.OnDragAsObservable().Subscribe(e =>
|
||||
{
|
||||
var delta = e.position.x - _dragStartPosition.x;
|
||||
if (_dragStartColumnSize + (int) delta < MinimumColumnSize ||
|
||||
columnIndex != columnNames.Length - 1 && _dragStartNextColumnSize - (int) delta < MinimumColumnSize)
|
||||
return;
|
||||
_columnSizes[columnIndex] = _dragStartColumnSize + (int) delta;
|
||||
if(columnIndex != columnNames.Length-1)
|
||||
_columnSizes[columnIndex+1] = _dragStartNextColumnSize - (int) delta;
|
||||
RepositionColumns();
|
||||
});
|
||||
_columnInstances.Add(columnHeader);
|
||||
if (i != columnNames.Length-1)
|
||||
{
|
||||
var columnDivider = ColumnDividerPrototype.Instantiate<RectTransform>();
|
||||
_columnDividerInstances.Add(columnDivider);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < _data.Count; i++)
|
||||
{
|
||||
var rowInstance = RowPrototype.Instantiate<SpreadsheetRow>();
|
||||
rowInstance.Background.color = i % 2 == 0 ? EvenRowBackground : OddRowBackground;
|
||||
_rowInstances.Add(rowInstance);
|
||||
}
|
||||
|
||||
RefreshData();
|
||||
|
||||
RepositionColumns();
|
||||
}
|
||||
|
||||
private void RefreshData()
|
||||
{
|
||||
for (var i = 0; i < _data.Count; i++)
|
||||
{
|
||||
var rowIndex = i;
|
||||
_rowInstances[i].ShowData(_data[i]);
|
||||
_rowInstances[i].ClickTrigger.Reset();
|
||||
_rowInstances[i].ClickTrigger.OnPointerClickAsObservable().Subscribe(e =>
|
||||
{
|
||||
if (e.button == PointerEventData.InputButton.Right)
|
||||
_data[rowIndex].OnRightClick?.Invoke();
|
||||
else
|
||||
{
|
||||
if (e.clickCount == 2)
|
||||
{
|
||||
_data[rowIndex].OnDoubleClick?.Invoke();
|
||||
}
|
||||
else _data[rowIndex].OnClick?.Invoke();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void RepositionColumns()
|
||||
{
|
||||
var distance = 0;
|
||||
for (var i = 0; i < _columnSizes.Length; i++)
|
||||
{
|
||||
_columnInstances[i].Rect.anchoredPosition = Vector2.right * distance;
|
||||
_columnInstances[i].Rect.sizeDelta = Vector2.right * _columnSizes[i];
|
||||
distance += _columnSizes[i];
|
||||
if (i != _columnSizes.Length-1)
|
||||
_columnDividerInstances[i].anchoredPosition = Vector2.right * distance;
|
||||
}
|
||||
foreach(var row in _rowInstances)
|
||||
row.ApplyColumnSizes(_columnSizes);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// ShowData(
|
||||
// new []{"Column 1", "Column 2", "Column 3", "Column 4", "Column 5"},
|
||||
// new []{2,1,1,1,1},
|
||||
// Enumerable.Range(0,10)
|
||||
// .Select(i=>new SpreadsheetEntryRow
|
||||
// {
|
||||
// Columns = Enumerable.Range(0,5).Select(j=>
|
||||
// {
|
||||
// var value = Random.Range(0, 10000);
|
||||
// return new SpreadsheetEntryColumn
|
||||
// {
|
||||
// Output = () => $"c{(j+1).ToString()}:{value.ToString()}",
|
||||
// SortKey = value
|
||||
// };
|
||||
// }).ToArray()
|
||||
// }).ToArray()
|
||||
// );
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class SpreadsheetEntryRow
|
||||
{
|
||||
public SpreadsheetEntryColumn[] Columns;
|
||||
public Action OnClick;
|
||||
public Action OnDoubleClick;
|
||||
public Action OnRightClick;
|
||||
}
|
||||
|
||||
public class SpreadsheetEntryColumn
|
||||
{
|
||||
public IComparable SortKey;
|
||||
public Func<string> Output;
|
||||
}
|
||||
11
Assets/Scripts/UI/Spreadsheet.cs.meta
Normal file
11
Assets/Scripts/UI/Spreadsheet.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ed0409b21bd8a5b4dae4c406c4a88134
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Scripts/UI/SpreadsheetColumnHeader.cs
Normal file
30
Assets/Scripts/UI/SpreadsheetColumnHeader.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UniRx.Triggers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpreadsheetColumnHeader : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Title;
|
||||
public RectTransform Rect;
|
||||
|
||||
public Button Button;
|
||||
public Image SortIcon;
|
||||
|
||||
public ObservableBeginDragTrigger ResizeBeginDragTrigger;
|
||||
public ObservableDragTrigger ResizeDragTrigger;
|
||||
public ObservableEndDragTrigger ResizeEndDragTrigger;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/SpreadsheetColumnHeader.cs.meta
Normal file
11
Assets/Scripts/UI/SpreadsheetColumnHeader.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c76217e77ad445d4fbdbdc7241eabbc2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/Scripts/UI/SpreadsheetRow.cs
Normal file
40
Assets/Scripts/UI/SpreadsheetRow.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UniRx.Triggers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpreadsheetRow : MonoBehaviour
|
||||
{
|
||||
public Prototype Column;
|
||||
public Image Background;
|
||||
public ObservablePointerClickTrigger ClickTrigger;
|
||||
|
||||
private List<RectTransform> _entries = new List<RectTransform>();
|
||||
|
||||
public void ShowData(SpreadsheetEntryRow data)
|
||||
{
|
||||
foreach(var entry in _entries)
|
||||
entry.GetComponent<Prototype>().ReturnToPool();
|
||||
_entries.Clear();
|
||||
|
||||
foreach (var column in data.Columns)
|
||||
{
|
||||
var entry = Column.Instantiate<RectTransform>();
|
||||
entry.GetComponent<TextMeshProUGUI>().text = column.Output();
|
||||
_entries.Add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyColumnSizes(int[] sizes)
|
||||
{
|
||||
var distance = 0;
|
||||
for (int i = 0; i < sizes.Length; i++)
|
||||
{
|
||||
_entries[i].anchoredPosition = Vector2.right * distance;
|
||||
_entries[i].sizeDelta = Vector2.right * sizes[i];
|
||||
distance += sizes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/SpreadsheetRow.cs.meta
Normal file
11
Assets/Scripts/UI/SpreadsheetRow.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ffbf236e994f734449d5eec120c36177
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue