In Game Input Screen
Implemented saving/loading of custom input settings Incorporated Input Screen in game Organized UI scripts into folders Deleted some unused UI scripts Reimplemented Fog Blur (by copying modified DoF to assets)
This commit is contained in:
parent
d47c32dfcf
commit
81acaf2a47
173 changed files with 8236 additions and 7329 deletions
9
Assets/Scripts/UI/Menu/ChoicePrefab.cs
Normal file
9
Assets/Scripts/UI/Menu/ChoicePrefab.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ChoicePrefab : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public Button Button;
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/ChoicePrefab.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/ChoicePrefab.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 369e33e0c70b03740a9f757c5a1a9dac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Scripts/UI/Menu/InventoryCell.cs
Normal file
23
Assets/Scripts/UI/Menu/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/Menu/InventoryCell.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/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:
|
||||
210
Assets/Scripts/UI/Menu/InventoryMenu.cs
Normal file
210
Assets/Scripts/UI/Menu/InventoryMenu.cs
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
/* 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.InputSystem;
|
||||
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()
|
||||
{
|
||||
AkSoundEngine.RegisterGameObj(gameObject);
|
||||
BackgroundEntered.gameObject.SetActive(true);
|
||||
|
||||
BackgroundEntered.OnPointerEnterAsObservable().Subscribe(enter =>
|
||||
{
|
||||
_destroyItem = true;
|
||||
});
|
||||
BackgroundExited.OnPointerExitAsObservable().Subscribe(enter =>
|
||||
{
|
||||
_destroyItem = false;
|
||||
});
|
||||
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();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
AkSoundEngine.UnregisterGameObj(gameObject);
|
||||
BackgroundEntered.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
PropertiesPanel.GameManager = GameManager;
|
||||
foreach (var panel in InventoryPanels)
|
||||
{
|
||||
panel.OnClickAsObservable().Subscribe(e =>
|
||||
{
|
||||
if (e.data is InventoryCargoEventData cargoEvent)
|
||||
{
|
||||
var item = cargoEvent.CargoBay.Occupancy[cargoEvent.Position.x, cargoEvent.Position.y];
|
||||
if(item!=null)
|
||||
{
|
||||
if (e.clickCount == 2)
|
||||
{
|
||||
var otherPanel = panel == InventoryPanels[0] ? InventoryPanels[1] : InventoryPanels[0];
|
||||
if (otherPanel.CanDropItem(item))
|
||||
{
|
||||
otherPanel.DropItem(item);
|
||||
AkSoundEngine.PostEvent("Equip", gameObject);
|
||||
cargoEvent.CargoBay.Remove(item);
|
||||
panel.RefreshCells();
|
||||
otherPanel.RefreshCells();
|
||||
}
|
||||
else AkSoundEngine.PostEvent("UI_Fail", gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_selectedPanel != null)
|
||||
{
|
||||
if (_selectedPanel.CellInstances.ContainsKey(_selectedPosition))
|
||||
{
|
||||
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.Inspect(item);
|
||||
_selectedPanel = panel;
|
||||
_selectedPosition = cargoEvent.CargoBay.Cargo[item];
|
||||
_selectedItem = item;
|
||||
_selectedItemData = item.Data.Value;
|
||||
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);
|
||||
}
|
||||
AkSoundEngine.PostEvent("UI_Success", gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e.data is InventoryEntityEventData entityEvent)
|
||||
{
|
||||
var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y];
|
||||
if (item != null)
|
||||
{
|
||||
if (e.clickCount == 2)
|
||||
{
|
||||
var otherPanel = panel == InventoryPanels[0] ? InventoryPanels[1] : InventoryPanels[0];
|
||||
if (otherPanel.CanDropItem(item.EquippableItem))
|
||||
{
|
||||
if (!entityEvent.Entity.Active)
|
||||
{
|
||||
if (entityEvent.Entity.TryUnequip(item) != null)
|
||||
{
|
||||
otherPanel.DropItem(item.EquippableItem);
|
||||
AkSoundEngine.PostEvent("Unequip", gameObject);
|
||||
panel.RefreshCells();
|
||||
otherPanel.RefreshCells();
|
||||
}
|
||||
else AkSoundEngine.PostEvent("UI_Fail", gameObject);
|
||||
}
|
||||
else AkSoundEngine.PostEvent("UI_Fail", gameObject);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_selectedPanel != null)
|
||||
{
|
||||
if (_selectedPanel.CellInstances.ContainsKey(_selectedPosition))
|
||||
{
|
||||
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(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);
|
||||
}
|
||||
AkSoundEngine.PostEvent("UI_Success", gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
panel.OnBackgroundClick.Subscribe(data =>
|
||||
{
|
||||
if (GameManager.CurrentEntity == null) return; // Only show ship settings if there's a ship, duh!
|
||||
|
||||
PropertiesPanel.Clear();
|
||||
PropertiesPanel.AddField("Shutdown Threshold",
|
||||
() => GameManager.CurrentEntity.Settings.ShutdownPerformance,
|
||||
f => GameManager.CurrentEntity.Settings.ShutdownPerformance = f,
|
||||
0,
|
||||
1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Keyboard.current.qKey.wasPressedThisFrame && _dragItem != null)
|
||||
{
|
||||
_dragItem.Rotation = (ItemRotation) (((int) _dragItem.Rotation + 1) % 4);
|
||||
}
|
||||
if (Keyboard.current.eKey.wasPressedThisFrame && _dragItem != null)
|
||||
{
|
||||
_dragItem.Rotation = (ItemRotation) (((int) _dragItem.Rotation + 3) % 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/InventoryMenu.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/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:
|
||||
947
Assets/Scripts/UI/Menu/InventoryPanel.cs
Normal file
947
Assets/Scripts/UI/Menu/InventoryPanel.cs
Normal file
|
|
@ -0,0 +1,947 @@
|
|||
/* 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 TMPro;
|
||||
using UniRx;
|
||||
using UniRx.Triggers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.Serialization;
|
||||
using static Unity.Mathematics.math;
|
||||
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;
|
||||
public ContextMenu ContextMenu;
|
||||
public TextMeshProUGUI Title;
|
||||
public TextMeshProUGUI MinTempLabel;
|
||||
public TextMeshProUGUI MaxTempLabel;
|
||||
public GameObject TemperatureRange;
|
||||
public Button Dropdown;
|
||||
public Button EditName;
|
||||
public Button Current;
|
||||
public Button Thermal;
|
||||
public GridLayoutGroup Grid;
|
||||
public Sprite[] NodeBackgroundTextures;
|
||||
public Sprite[] NodeTextures;
|
||||
public Sprite[] ThermalTextures;
|
||||
public float ThermalToggleRegionSize = .2f;
|
||||
public Prototype NodePrototype;
|
||||
public RawImage TemperatureDisplay;
|
||||
public Texture2D TemperatureColor;
|
||||
public ExponentialLerp TemperatureColorCurve;
|
||||
public ExponentialLerp TemperatureAlphaCurve;
|
||||
public bool FitToContent;
|
||||
public float CellHitPulseTime;
|
||||
public Color ToggleEnabledColor;
|
||||
public Color ToggleDisabledColor;
|
||||
public Color CellBackgroundColor = new Color(0, 0, 0, .75f);
|
||||
public float MinTempRange = 1;
|
||||
public float DoubleClickTime = .5f;
|
||||
public float HitDamageThreshold = 1;
|
||||
|
||||
// Subject<InventoryEventData> _onBeginDrag;
|
||||
// Subject<InventoryEventData> _onDrag;
|
||||
// Subject<InventoryEventData> _onEndDrag;
|
||||
Subject<(InventoryEventData data, int clickCount)> _onClick;
|
||||
// Subject<InventoryEventData> _onPointerEnter;
|
||||
// Subject<InventoryEventData> _onPointerExit;
|
||||
|
||||
private Entity _displayedEntity;
|
||||
private EquippedCargoBay _displayedCargo;
|
||||
private Texture2D _temperatureTexture;
|
||||
private RectTransform _firstRect;
|
||||
|
||||
public ItemInstance FakeItem;
|
||||
public Shape FakeOccupancy;
|
||||
public Shape IgnoreOccupancy;
|
||||
public List<GameObject> EmptyCells = new List<GameObject>();
|
||||
public Dictionary<int2, InventoryCell> CellInstances = new Dictionary<int2, InventoryCell>();
|
||||
|
||||
private List<IDisposable> _subscriptions = new List<IDisposable>();
|
||||
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;
|
||||
|
||||
private int2[] _offsets = {
|
||||
int2(0, 1),
|
||||
int2(1, 0),
|
||||
int2(0, -1),
|
||||
int2(-1, 0),
|
||||
int2(1, 1),
|
||||
int2(1, -1),
|
||||
int2(-1, -1),
|
||||
int2(-1, 1)
|
||||
};
|
||||
|
||||
public InventoryPanelTarget Target =>
|
||||
_displayedEntity != null ? InventoryPanelTarget.Equipment :
|
||||
_displayedCargo != null ? InventoryPanelTarget.Cargo : InventoryPanelTarget.None;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (Thermal)
|
||||
{
|
||||
Thermal.onClick.AddListener(() =>
|
||||
{
|
||||
Display(_displayedEntity, false, !_thermal);
|
||||
});
|
||||
}
|
||||
|
||||
if (Current)
|
||||
{
|
||||
Current.onClick.AddListener(() =>
|
||||
{
|
||||
if (_displayedEntity != GameManager.CurrentEntity)
|
||||
{
|
||||
if(_displayedEntity is Ship ship)
|
||||
{
|
||||
GameManager.CurrentEntity = ship;
|
||||
GameManager.DockingBay.DockedShip = ship;
|
||||
Current.targetGraphic.color = ToggleEnabledColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Can't select entity, you can only pilot a ship!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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(() =>
|
||||
{
|
||||
ContextMenu.Clear();
|
||||
foreach (var entity in GameManager.AvailableEntities())
|
||||
{
|
||||
if (entity.CargoBays.Any())
|
||||
{
|
||||
var options = entity.CargoBays
|
||||
.Where(bay => bay != _displayedCargo)
|
||||
.Select<EquippedCargoBay, (string text, Action action, bool enabled)>((bay, index) =>
|
||||
($"Bay {index+1}", () => Display(bay), true));
|
||||
if(entity != _displayedEntity) options = options.Prepend(("Equipment", () => Display(entity), true));
|
||||
ContextMenu.AddDropdown(entity.Name, options);
|
||||
}
|
||||
else if(entity != _displayedEntity) ContextMenu.AddOption(entity.Name, () => Display(entity));
|
||||
}
|
||||
|
||||
if(GameManager.DockingBay!=null && _displayedCargo!=GameManager.DockingBay)
|
||||
ContextMenu.AddOption(GameManager.DockingBay.Name, () => Display(GameManager.DockingBay));
|
||||
|
||||
ContextMenu.AddOption("Save Loadout",
|
||||
() =>
|
||||
{
|
||||
GameManager.SaveLoadout(EntitySerializer.Pack(_displayedEntity));
|
||||
});
|
||||
|
||||
if (GameManager.Loadouts.Any())
|
||||
{
|
||||
ContextMenu.AddDropdown("Restore Loadout",
|
||||
GameManager.Loadouts.Select<EntityPack, (string text, Action action, bool enabled)>(pack =>
|
||||
(
|
||||
$"{pack.Name} - {pack.Price(GameManager.ItemManager):n0}", () =>
|
||||
{
|
||||
var entity = EntitySerializer.Unpack(GameManager.ItemManager, GameManager.Zone, pack, true);
|
||||
entity.SetParent(GameManager.DockedEntity);
|
||||
GameManager.Credits -= pack.Price(GameManager.ItemManager);
|
||||
GameManager.CurrentEntity = entity;
|
||||
if(entity is Ship ship)
|
||||
{
|
||||
ship.IsPlayerShip = true;
|
||||
GameManager.DockingBay.DockedShip = ship;
|
||||
}
|
||||
Display(entity);
|
||||
}, pack.Price(GameManager.ItemManager) < GameManager.Credits
|
||||
)));
|
||||
}
|
||||
|
||||
ContextMenu.Show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_displayedEntity != null && TemperatureDisplay)
|
||||
{
|
||||
var tempRange = _displayedEntity.MaxTemp - _displayedEntity.MinTemp;
|
||||
var opacity = smoothstep(0, MinTempRange, tempRange);
|
||||
if(MinTempLabel)
|
||||
{
|
||||
MinTempLabel.text = ActionGameManager.PlayerSettings.FormatTemperature(_displayedEntity.MinTemp);
|
||||
MaxTempLabel.text = ActionGameManager.PlayerSettings.FormatTemperature(_displayedEntity.MaxTemp);
|
||||
}
|
||||
var hullData = GameManager.ItemManager.GetData(_displayedEntity.Hull) as HullData;
|
||||
for(var x = 0; x < _temperatureTexture.width; x++)
|
||||
{
|
||||
for (var y = 0; y < _temperatureTexture.height; y++)
|
||||
{
|
||||
if (hullData.Shape[int2(x-1, y-1)])
|
||||
{
|
||||
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) * opacity;
|
||||
_temperatureTexture.SetPixel(x,y,color);
|
||||
}
|
||||
else
|
||||
_temperatureTexture.SetPixel(x,y,new Color(0,0,0,0));
|
||||
}
|
||||
}
|
||||
_temperatureTexture.Apply();
|
||||
TemperatureDisplay.rectTransform.anchoredPosition = _firstRect.anchoredPosition - Vector2.one * Grid.cellSize * 1.5f;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_displayedCargo = null;
|
||||
_displayedEntity = null;
|
||||
|
||||
foreach(var empty in EmptyCells)
|
||||
Destroy(empty);
|
||||
EmptyCells.Clear();
|
||||
|
||||
foreach(var node in CellInstances.Values)
|
||||
node.GetComponent<Prototype>().ReturnToPool();
|
||||
CellInstances.Clear();
|
||||
|
||||
foreach(var s in _subscriptions)
|
||||
s.Dispose();
|
||||
|
||||
_subscriptions.Clear();
|
||||
|
||||
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(Title)
|
||||
Title.text = "None";
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
_displayedEntity = entity;
|
||||
_displayedCargo = null;
|
||||
_firstRect = null;
|
||||
|
||||
if (TemperatureRange)
|
||||
TemperatureRange.SetActive(true);
|
||||
|
||||
if(Title)
|
||||
Title.text = entity.Name;
|
||||
|
||||
if (EditName)
|
||||
{
|
||||
EditName.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
var hullData = GameManager.ItemManager.GetData(entity.Hull) as HullData;
|
||||
|
||||
if (FitToContent)
|
||||
{
|
||||
var gridRect = Grid.GetComponent<RectTransform>();
|
||||
var rect = gridRect.rect;
|
||||
Grid.cellSize = Vector2.one * (int) min(rect.width / (hullData.Shape.Width + 1), rect.height / (hullData.Shape.Height + 1));
|
||||
}
|
||||
|
||||
if(TemperatureDisplay)
|
||||
{
|
||||
_temperatureTexture = new Texture2D(
|
||||
hullData.Shape.Width + 2,
|
||||
hullData.Shape.Height + 2,
|
||||
TextureFormat.RGBA32,
|
||||
false,
|
||||
false);
|
||||
TemperatureDisplay.gameObject.SetActive(true);
|
||||
TemperatureDisplay.texture = _temperatureTexture;
|
||||
var tempRect = TemperatureDisplay.rectTransform;
|
||||
tempRect.sizeDelta = Grid.cellSize * new Vector2(hullData.Shape.Width + 2, hullData.Shape.Height + 2);
|
||||
}
|
||||
|
||||
if (Current)
|
||||
{
|
||||
Current.gameObject.SetActive(true);
|
||||
Current.targetGraphic.color = entity == GameManager.CurrentEntity ? ToggleEnabledColor : ToggleDisabledColor;
|
||||
}
|
||||
if (Thermal)
|
||||
{
|
||||
Thermal.gameObject.SetActive(true);
|
||||
Thermal.targetGraphic.color = thermal ? ToggleEnabledColor : ToggleDisabledColor;
|
||||
}
|
||||
|
||||
Grid.constraintCount = hullData.Shape.Width;
|
||||
foreach (var v in hullData.Shape.AllCoordinates)
|
||||
{
|
||||
if (!hullData.Shape[v])
|
||||
{
|
||||
var empty = new GameObject("Empty Node", typeof(RectTransform));
|
||||
empty.transform.SetParent(Grid.transform);
|
||||
if (!_firstRect)
|
||||
_firstRect = empty.GetComponent<RectTransform>();
|
||||
EmptyCells.Add(empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cell = NodePrototype.Instantiate<InventoryCell>();
|
||||
cell.Background.color = CellBackgroundColor;
|
||||
if (!_firstRect)
|
||||
_firstRect = cell.GetComponent<RectTransform>();
|
||||
if (!thermal)
|
||||
{
|
||||
if(cell.PointerClickTrigger)
|
||||
{
|
||||
cell.PointerClickTrigger.OnPointerClickAsObservable()
|
||||
.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 =>
|
||||
{
|
||||
//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<Prototype>());
|
||||
foreach (var component in dragCell.GetComponentsInChildren<ObservableTriggerBase>())
|
||||
component.enabled = false;
|
||||
foreach (var img in dragCell.GetComponentsInChildren<Image>())
|
||||
img.color = new Color(img.color.r, img.color.g, img.color.b, img.color.a * .5f);
|
||||
dragCell.GetComponentInChildren<Image>().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 =>
|
||||
{
|
||||
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 =>
|
||||
{
|
||||
//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 =>
|
||||
{
|
||||
//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 =>
|
||||
{
|
||||
if (!(GameManager.DragObject is ItemDragObject)) return;
|
||||
FakeItem = null;
|
||||
FakeOccupancy = null;
|
||||
RefreshCells();
|
||||
GameManager.UnregisterDragTarget();
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.PointerClickTrigger.OnPointerClickAsObservable().Subscribe(data =>
|
||||
{
|
||||
var rect = cell.GetComponent<RectTransform>();
|
||||
var point = Rect.PointToNormalized(rect.rect, rect.InverseTransformPoint(data.position));
|
||||
// Debug.Log($"Clicked at pos {data.position}, normalized {point}");
|
||||
if (hullData.Shape[int2(v.x - 1, v.y)] && point.x < ThermalToggleRegionSize)
|
||||
{
|
||||
entity.HullConductivity[v.x - 1, v.y].x = !entity.HullConductivity[v.x - 1, v.y].x;
|
||||
RefreshCells(new []{v,int2(v.x - 1, v.y)});
|
||||
}
|
||||
if (hullData.Shape[int2(v.x + 1, v.y)] && point.x > 1 - ThermalToggleRegionSize)
|
||||
{
|
||||
entity.HullConductivity[v.x, v.y].x = !entity.HullConductivity[v.x, v.y].x;
|
||||
RefreshCells(new []{v,int2(v.x + 1, v.y)});
|
||||
}
|
||||
if (hullData.Shape[int2(v.x, v.y - 1)] && point.y < ThermalToggleRegionSize)
|
||||
{
|
||||
entity.HullConductivity[v.x, v.y - 1].y = !entity.HullConductivity[v.x, v.y - 1].y;
|
||||
RefreshCells(new []{v,int2(v.x, v.y - 1)});
|
||||
}
|
||||
if (hullData.Shape[int2(v.x, v.y + 1)] && point.y > 1 - ThermalToggleRegionSize)
|
||||
{
|
||||
entity.HullConductivity[v.x, v.y].y = !entity.HullConductivity[v.x, v.y].y;
|
||||
RefreshCells(new []{v,int2(v.x, v.y + 1)});
|
||||
}
|
||||
});
|
||||
}
|
||||
CellInstances.Add(v, cell);
|
||||
}
|
||||
}
|
||||
RefreshCells(CellInstances.Keys);
|
||||
|
||||
_subscriptions.Add(entity.ArmorDamage.Subscribe(hit =>
|
||||
{
|
||||
var hitCells = new[] { hit.pos };
|
||||
StartCoroutine(Pulse(hitCells, HitType.Armor, _hitSequence++));
|
||||
RefreshCells(hitCells);
|
||||
}));
|
||||
|
||||
_subscriptions.Add(entity.ItemDamage.Where(hit=>hit.damage > HitDamageThreshold).Subscribe(hit =>
|
||||
{
|
||||
var hitCells = hit.item.InsetShape.Coordinates;
|
||||
if(gameObject.activeInHierarchy)
|
||||
StartCoroutine(Pulse(hitCells, HitType.Armor, _hitSequence++));
|
||||
RefreshCells(hitCells);
|
||||
}));
|
||||
}
|
||||
|
||||
private IEnumerator Pulse(int2[] cells, HitType hitType, int sequence)
|
||||
{
|
||||
foreach (var cell in cells)
|
||||
{
|
||||
if(_cellAnimationSequence.ContainsKey(cell))
|
||||
_cellAnimationSequence[cell] = max(_cellAnimationSequence[cell], sequence);
|
||||
else
|
||||
_cellAnimationSequence[cell] = sequence;
|
||||
}
|
||||
var hitColor = hitType switch
|
||||
{
|
||||
HitType.Armor => Settings.ArmorHitColor,
|
||||
HitType.Hardpoint => Settings.HardpointHitColor,
|
||||
HitType.Gear => Settings.GearHitColor,
|
||||
_ => Color.white
|
||||
};
|
||||
float startTime = Time.time;
|
||||
while (Time.time - startTime < CellHitPulseTime)
|
||||
{
|
||||
var lerp = (Time.time - startTime) / CellHitPulseTime;
|
||||
foreach(var cell in cells)
|
||||
if(_cellAnimationSequence[cell] == sequence)
|
||||
if(CellInstances.ContainsKey(cell))
|
||||
CellInstances[cell].Background.color = Color.Lerp(hitColor, CellBackgroundColor, lerp);
|
||||
yield return null;
|
||||
}
|
||||
foreach (var cell in cells)
|
||||
if(CellInstances.ContainsKey(cell))
|
||||
CellInstances[cell].Background.color = CellBackgroundColor;
|
||||
}
|
||||
|
||||
public void Display(EquippedCargoBay cargo)
|
||||
{
|
||||
Clear();
|
||||
|
||||
_subscriptions.Add(cargo.Cargo.ObserveAdd().Subscribe(_ => RefreshCells()));
|
||||
_subscriptions.Add(cargo.Cargo.ObserveRemove().Subscribe(_ => RefreshCells()));
|
||||
|
||||
_displayedCargo = cargo;
|
||||
_displayedEntity = null;
|
||||
|
||||
if(Title)
|
||||
Title.text = cargo.Name;
|
||||
|
||||
// FakeOccupancy = new Shape(cargo.Data.InteriorShape.Width, cargo.Data.InteriorShape.Height);
|
||||
// IgnoreOccupancy = new Shape(cargo.Data.InteriorShape.Width, cargo.Data.InteriorShape.Height);
|
||||
Grid.constraintCount = cargo.Data.InteriorShape.Width;
|
||||
foreach (var v in cargo.Data.InteriorShape.AllCoordinates)
|
||||
{
|
||||
if (!cargo.Data.InteriorShape[v])
|
||||
{
|
||||
var empty = new GameObject("Empty Node", typeof(RectTransform));
|
||||
empty.transform.SetParent(Grid.transform);
|
||||
EmptyCells.Add(empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cell = NodePrototype.Instantiate<InventoryCell>();
|
||||
cell.PointerClickTrigger.OnPointerClickAsObservable()
|
||||
.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 =>
|
||||
{
|
||||
//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<Prototype>());
|
||||
foreach (var component in dragCell.GetComponentsInChildren<ObservableTriggerBase>())
|
||||
component.enabled = false;
|
||||
foreach (var img in dragCell.GetComponentsInChildren<Image>())
|
||||
img.color = new Color(img.color.r, img.color.g, img.color.b, img.color.a * .5f);
|
||||
dragCell.GetComponentInChildren<Image>().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 =>
|
||||
{
|
||||
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 =>
|
||||
{
|
||||
//Debug.Log("Inventory Drag End");
|
||||
IgnoreOccupancy = null;
|
||||
GameManager.EndDrag();
|
||||
foreach(var dragObject in _dragCells)
|
||||
Destroy(dragObject.gameObject);
|
||||
_dragCells = null;
|
||||
});
|
||||
cell.PointerEnterTrigger.OnPointerEnterAsObservable()
|
||||
.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 =>
|
||||
{
|
||||
if (!(GameManager.DragObject is ItemDragObject)) return;
|
||||
FakeItem = null;
|
||||
FakeOccupancy = null;
|
||||
RefreshCells();
|
||||
GameManager.UnregisterDragTarget();
|
||||
});
|
||||
|
||||
CellInstances.Add(v, cell);
|
||||
}
|
||||
}
|
||||
RefreshCells();
|
||||
}
|
||||
|
||||
public void RefreshCells()
|
||||
{
|
||||
RefreshCells(CellInstances.Keys);
|
||||
}
|
||||
|
||||
public void RefreshCells(IEnumerable<int2> cells)
|
||||
{
|
||||
if (_displayedEntity != null)
|
||||
{
|
||||
foreach (var v in cells)
|
||||
{
|
||||
if(!CellInstances.ContainsKey(v)) continue;
|
||||
|
||||
var hullData = GameManager.ItemManager.GetData(_displayedEntity.Hull) as HullData;
|
||||
|
||||
var spriteIndex = 0;
|
||||
var interior = hullData.InteriorCells[v];
|
||||
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)
|
||||
{
|
||||
var v2 = v + offset * (Flip ? -1 : 1);
|
||||
return !(
|
||||
hullData.Shape[v2] &&
|
||||
_displayedEntity.Hardpoints[v2.x, v2.y] == hardpoint &&
|
||||
(FakeOccupancy?[v2]??false ? FakeItem : IgnoreOccupancy?[v2]??false ? null : _displayedEntity.GearOccupancy[v2.x, v2.y]?.EquippableItem) == item
|
||||
);
|
||||
}
|
||||
|
||||
bool NoHardpointMatch(int2 offset)
|
||||
{
|
||||
var v2 = v + offset * (Flip ? -1 : 1);
|
||||
return !(
|
||||
hullData.Shape[v2] && (
|
||||
!interior && !hullData.InteriorCells[v2] && _displayedEntity.Hardpoints[v2.x, v2.y] == null ||
|
||||
interior && item != null &&
|
||||
(FakeOccupancy?[v2]??false ? FakeItem : IgnoreOccupancy?[v2]??false ? null : _displayedEntity.GearOccupancy[v2.x, v2.y]?.EquippableItem) == item
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (hardpoint != null)
|
||||
{
|
||||
for(int i = 0; i < 8; i++)
|
||||
if (HardpointMatch(_offsets[i]))
|
||||
spriteIndex += 1 << i;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < 8; i++)
|
||||
if (NoHardpointMatch(_offsets[i]))
|
||||
spriteIndex += 1 << i;
|
||||
}
|
||||
|
||||
var bgSpriteIndex = spriteIndex;
|
||||
|
||||
if (item != null)
|
||||
spriteIndex += 1 << 8;
|
||||
|
||||
if (_thermal)
|
||||
{
|
||||
bool ThermalMatch(int2 offset)
|
||||
{
|
||||
if (!hullData.Shape[v + offset]) return false;
|
||||
var i = (offset.x, offset.y);
|
||||
return i switch
|
||||
{
|
||||
(1, 0) => _displayedEntity.HullConductivity[v.x, v.y].x,
|
||||
(-1, 0) => _displayedEntity.HullConductivity[v.x-1, v.y].x,
|
||||
(0, 1) => _displayedEntity.HullConductivity[v.x, v.y].y,
|
||||
(0, -1) => _displayedEntity.HullConductivity[v.x, v.y-1].y,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
spriteIndex = 0;
|
||||
for(int i = 0; i < 4; i++)
|
||||
if (ThermalMatch(_offsets[i]))
|
||||
spriteIndex += 1 << i;
|
||||
}
|
||||
|
||||
CellInstances[v].Background.sprite = NodeBackgroundTextures[bgSpriteIndex];
|
||||
CellInstances[v].Icon.sprite = _thermal ? ThermalTextures[spriteIndex] : NodeTextures[spriteIndex];
|
||||
CellInstances[v].Icon.color = GetColor(v);
|
||||
}
|
||||
}
|
||||
else if(_displayedCargo != null)
|
||||
{
|
||||
foreach (var v in cells)
|
||||
{
|
||||
if(!CellInstances.ContainsKey(v)) continue;
|
||||
|
||||
var spriteIndex = 0;
|
||||
var item = FakeOccupancy?[v]??false ? FakeItem : IgnoreOccupancy?[v]??false ? null : _displayedCargo.Occupancy[v.x, v.y];
|
||||
|
||||
bool ItemMatch(int2 offset)
|
||||
{
|
||||
var v2 = v + offset;
|
||||
return !_displayedCargo.Data.InteriorShape[v2] || item == null ||
|
||||
(FakeOccupancy?[v2]??false ? FakeItem : IgnoreOccupancy?[v2]??false ? null : _displayedCargo.Occupancy[v2.x, v2.y]) != item;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 8; i++)
|
||||
if (ItemMatch(_offsets[i]))
|
||||
spriteIndex += 1 << i;
|
||||
|
||||
var bgSpriteIndex = spriteIndex;
|
||||
|
||||
if (item != null)
|
||||
spriteIndex += 1 << 8;
|
||||
|
||||
CellInstances[v].Background.sprite = NodeBackgroundTextures[bgSpriteIndex];
|
||||
CellInstances[v].Icon.sprite = NodeTextures[spriteIndex];
|
||||
CellInstances[v].Icon.color = GetColor(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Color GetColor(int2 position, bool highlight = false)
|
||||
{
|
||||
if (_displayedEntity != null)
|
||||
{
|
||||
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 ? 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.Durability / _displayedEntity.ItemManager.GetData(item).Durability);
|
||||
return float3(.25f).ToColor();
|
||||
}
|
||||
|
||||
if (hardpoint == null)
|
||||
{
|
||||
if(!interior)
|
||||
return Color.white;
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
return float3(.25f).ToColor();
|
||||
}
|
||||
|
||||
if(highlight)
|
||||
return Color.white;
|
||||
|
||||
return float3(.5f).ToColor();
|
||||
}
|
||||
|
||||
var tint = hardpoint.TintColor;
|
||||
|
||||
if (!highlight || item == null)
|
||||
tint *= .7071f;
|
||||
|
||||
return tint.ToColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
var item = FakeOccupancy?[position] ?? false ? FakeItem : IgnoreOccupancy?[position] ?? false ? null : _displayedCargo.Occupancy[position.x, position.y];
|
||||
|
||||
if (item == null)
|
||||
return Color.white * .25f;
|
||||
|
||||
var c = float3(1);
|
||||
if (item.Data.Value is EquippableItemData equippable)
|
||||
c = HardpointData.GetColor(equippable.HardpointType);
|
||||
|
||||
if(!highlight)
|
||||
c *= .7071f;
|
||||
|
||||
return c.ToColor();
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanDropItem(ItemInstance item)
|
||||
{
|
||||
if (_displayedEntity != null && item is EquippableItem equippableItem)
|
||||
{
|
||||
return _displayedEntity.TryFindSpace(equippableItem, out _);
|
||||
}
|
||||
|
||||
if (_displayedCargo != null)
|
||||
{
|
||||
return _displayedCargo.TryFindSpace(item);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool DropItem(ItemInstance item)
|
||||
{
|
||||
if (_displayedEntity != null && item is EquippableItem equippableItem)
|
||||
{
|
||||
return _displayedEntity.TryEquip(equippableItem);
|
||||
}
|
||||
|
||||
if(_displayedCargo != null)
|
||||
{
|
||||
return _displayedCargo.TryStore(item);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Subject<PointerEventData> OnBackgroundClick = new Subject<PointerEventData>();
|
||||
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<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>());
|
||||
// public UniRx.IObservable<InventoryEventData> OnPointerEnterAsObservable() => _onPointerEnter ?? (_onPointerEnter = new Subject<InventoryEventData>());
|
||||
// public UniRx.IObservable<InventoryEventData> OnPointerExitAsObservable() => _onPointerExit ?? (_onPointerExit = new Subject<InventoryEventData>());
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
OnBackgroundClick.OnNext(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class InventoryEventData
|
||||
{
|
||||
protected InventoryEventData(PointerEventData pointerEventData, int2 position)
|
||||
{
|
||||
PointerEventData = pointerEventData;
|
||||
Position = position;
|
||||
}
|
||||
|
||||
public PointerEventData PointerEventData { get; }
|
||||
public int2 Position { get; }
|
||||
}
|
||||
|
||||
public class InventoryEntityEventData : InventoryEventData
|
||||
{
|
||||
public InventoryEntityEventData(PointerEventData pointerEventData, int2 position, Entity entity) :
|
||||
base(pointerEventData, position)
|
||||
{
|
||||
Entity = entity;
|
||||
}
|
||||
|
||||
public Entity Entity { get; }
|
||||
}
|
||||
|
||||
public class InventoryCargoEventData : InventoryEventData
|
||||
{
|
||||
public InventoryCargoEventData(PointerEventData pointerEventData, int2 position, EquippedCargoBay cargoBay) :
|
||||
base(pointerEventData, position)
|
||||
{
|
||||
CargoBay = cargoBay;
|
||||
}
|
||||
|
||||
public EquippedCargoBay CargoBay { get; }
|
||||
}
|
||||
|
||||
public enum InventoryPanelTarget
|
||||
{
|
||||
None,
|
||||
Cargo,
|
||||
Equipment
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/InventoryPanel.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/InventoryPanel.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 78aa0b8ec7594a7438f13757228e3500
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Scripts/UI/Menu/ItemFilter.cs
Normal file
24
Assets/Scripts/UI/Menu/ItemFilter.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ItemFilter : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public Button DisableButton;
|
||||
|
||||
public event Action OnDisable;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
DisableButton.onClick.AddListener(() =>
|
||||
{
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
OnDisable?.Invoke();
|
||||
OnDisable = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/ItemFilter.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/ItemFilter.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 84b08c807fa72e340b5b57841640ec13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/Scripts/UI/Menu/LegendElement.cs
Normal file
12
Assets/Scripts/UI/Menu/LegendElement.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LegendElement : MonoBehaviour
|
||||
{
|
||||
public Image Primary;
|
||||
public Image Secondary;
|
||||
public TextMeshProUGUI Label;
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/LegendElement.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/LegendElement.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d3cdb62043eacb24b87bab4e3584c17c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/Scripts/UI/Menu/LocalMenu.cs
Normal file
63
Assets/Scripts/UI/Menu/LocalMenu.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ink.Runtime;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UniRx.Triggers;
|
||||
using UnityEngine;
|
||||
|
||||
public class LocalMenu : MonoBehaviour
|
||||
{
|
||||
public ObservablePointerClickTrigger ContinueTrigger;
|
||||
public TextMeshProUGUI Output;
|
||||
public RectTransform ChoiceParent;
|
||||
public ChoicePrefab ChoicePrefab;
|
||||
|
||||
private Story _currentStory;
|
||||
private List<GameObject> _choiceInstances = new List<GameObject>();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_currentStory = ActionGameManager.Instance.GetStories.First();
|
||||
Continue();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
ContinueTrigger.OnPointerClickAsObservable().Subscribe(pointerEvent =>
|
||||
{
|
||||
if (_currentStory == null) return;
|
||||
|
||||
if(_currentStory.canContinue) Continue();
|
||||
});
|
||||
}
|
||||
|
||||
void Continue()
|
||||
{
|
||||
Output.text = _currentStory.Continue();
|
||||
|
||||
foreach(var instance in _choiceInstances)
|
||||
Destroy(instance);
|
||||
_choiceInstances.Clear();
|
||||
|
||||
foreach (var choice in _currentStory.currentChoices)
|
||||
{
|
||||
var choiceInstance = Instantiate(ChoicePrefab, ChoiceParent);
|
||||
choiceInstance.Label.text = choice.text;
|
||||
choiceInstance.Button.onClick.AddListener(() =>
|
||||
{
|
||||
_currentStory.ChoosePath(choice.targetPath);
|
||||
Continue();
|
||||
});
|
||||
_choiceInstances.Add(choiceInstance.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/LocalMenu.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/LocalMenu.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 94223b4e7b954df47a5400f0e7be80c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/Scripts/UI/Menu/MapMenuInput.cs
Normal file
47
Assets/Scripts/UI/Menu/MapMenuInput.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* 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 Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class MapMenuInput : MonoBehaviour, IBeginDragHandler, IDragHandler, IScrollHandler
|
||||
{
|
||||
public MapRenderer Map;
|
||||
public float ZoomSpeed;
|
||||
|
||||
private Vector2 _startMousePosition;
|
||||
|
||||
private Vector2 _startMapPosition;
|
||||
private RectTransform _mapRect;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_mapRect = Map.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
_startMousePosition = eventData.position;
|
||||
_startMapPosition = Map.Position;
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
Map.Position = _startMapPosition - (eventData.position - _startMousePosition) * Map.Scale;
|
||||
}
|
||||
|
||||
public void OnScroll(PointerEventData eventData)
|
||||
{
|
||||
Vector3[] mapCorners = new Vector3[4];
|
||||
_mapRect.GetWorldCorners(mapCorners);
|
||||
var mapCenter = ((float3)(mapCorners[2] + mapCorners[0]) / 2).xy;
|
||||
var oldPointerPosition = Map.Position + ((float2)eventData.position - mapCenter) * Map.Scale;
|
||||
Map.Scale *= 1 - eventData.scrollDelta.y * ZoomSpeed;
|
||||
var pointerPosition = Map.Position + ((float2)eventData.position - mapCenter) * Map.Scale;
|
||||
Map.Position += oldPointerPosition - pointerPosition;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/MapMenuInput.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/MapMenuInput.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d49dbb702a53a4e4196a99b448958958
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
121
Assets/Scripts/UI/Menu/MapRenderer.cs
Normal file
121
Assets/Scripts/UI/Menu/MapRenderer.cs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
/* 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 TMPro;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.UI;
|
||||
using static Unity.Mathematics.math;
|
||||
using int2 = Unity.Mathematics.int2;
|
||||
|
||||
public class MapRenderer : MonoBehaviour
|
||||
{
|
||||
public ActionGameManager GameManager;
|
||||
public TextMeshProUGUI Title;
|
||||
public Camera MapOverlayCamera;
|
||||
public Camera GravityCamera;
|
||||
public Camera TintCamera;
|
||||
public Camera InfluenceCamera;
|
||||
public Image OverlayDisplay;
|
||||
public Image GravityDisplay;
|
||||
public Image TintDisplay;
|
||||
public Image InfluenceDisplay;
|
||||
public float Scale;
|
||||
public float2 Position;
|
||||
|
||||
private RectTransform _rect;
|
||||
private RenderTexture _mapTexture;
|
||||
private RenderTexture _gravityTexture;
|
||||
private RenderTexture _tintTexture;
|
||||
private RenderTexture _influenceTexture;
|
||||
private int2 _size;
|
||||
private bool _init;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_rect = GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_init = true;
|
||||
MapOverlayCamera.gameObject.SetActive(true);
|
||||
GravityCamera.gameObject.SetActive(true);
|
||||
TintCamera.gameObject.SetActive(true);
|
||||
InfluenceCamera.gameObject.SetActive(true);
|
||||
Title.text = $"Zone: {GameManager.Zone.SectorZone.Name}";
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_mapTexture != null)
|
||||
{
|
||||
ReleaseTextures();
|
||||
}
|
||||
MapOverlayCamera.gameObject.SetActive(false);
|
||||
GravityCamera.gameObject.SetActive(false);
|
||||
TintCamera.gameObject.SetActive(false);
|
||||
InfluenceCamera.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void ReleaseTextures()
|
||||
{
|
||||
_mapTexture.Release();
|
||||
_mapTexture = null;
|
||||
_gravityTexture.Release();
|
||||
_gravityTexture = null;
|
||||
_tintTexture.Release();
|
||||
_tintTexture = null;
|
||||
_influenceTexture.Release();
|
||||
_influenceTexture = null;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
var size = int2(Screen.width, Screen.height);
|
||||
if (_init || size.x != _size.x || size.y != _size.y)
|
||||
{
|
||||
_init = false;
|
||||
_size = size;
|
||||
if (_mapTexture != null)
|
||||
{
|
||||
ReleaseTextures();
|
||||
}
|
||||
|
||||
_mapTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.Default);
|
||||
MapOverlayCamera.targetTexture = _mapTexture;
|
||||
OverlayDisplay.material.SetTexture("_DetailTex", _mapTexture);
|
||||
|
||||
_gravityTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.RFloat);
|
||||
GravityCamera.targetTexture = _gravityTexture;
|
||||
GravityDisplay.material.SetTexture("_DetailTex", _gravityTexture);
|
||||
|
||||
_tintTexture = new RenderTexture(_size.x / 2, _size.y / 2, 0, RenderTextureFormat.RGB111110Float);
|
||||
TintCamera.targetTexture = _tintTexture;
|
||||
TintDisplay.material.SetTexture("_DetailTex", _tintTexture);
|
||||
|
||||
_influenceTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.RFloat);
|
||||
InfluenceCamera.targetTexture = _influenceTexture;
|
||||
InfluenceDisplay.material.SetTexture("_DetailTex", _influenceTexture);
|
||||
}
|
||||
|
||||
var pos = ((Vector2) Position).Flatland(1);
|
||||
|
||||
MapOverlayCamera.transform.position = pos;
|
||||
MapOverlayCamera.orthographicSize = _size.y * Scale * .5f;
|
||||
|
||||
GravityCamera.transform.position = pos;
|
||||
GravityCamera.orthographicSize = _size.y * Scale * .5f;
|
||||
GravityDisplay.material.SetFloat("_Scale", Scale / 2);
|
||||
|
||||
TintCamera.transform.position = pos;
|
||||
TintCamera.orthographicSize = _size.y * Scale * .5f;
|
||||
|
||||
InfluenceCamera.transform.position = pos;
|
||||
InfluenceCamera.orthographicSize = _size.y * Scale * .5f;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/MapRenderer.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/MapRenderer.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 95307b613a054bc4a9bb1f9db0a2e3d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
42
Assets/Scripts/UI/Menu/MapViewDragHandler.cs
Normal file
42
Assets/Scripts/UI/Menu/MapViewDragHandler.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;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class MapViewDragHandler : MonoBehaviour
|
||||
{
|
||||
public Camera Camera;
|
||||
public float Scaling;
|
||||
public ClickCatcher Background;
|
||||
private Vector2 _previousPosition;
|
||||
private bool _isDragging;
|
||||
|
||||
void Update()
|
||||
{
|
||||
var newPosition = Camera.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
||||
if (!Input.GetMouseButton(0)) _isDragging = false;
|
||||
|
||||
if (_isDragging) Camera.transform.position -= (Vector3) ((Vector2) newPosition - _previousPosition);
|
||||
|
||||
if (Background.PointerIsInside)
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
_previousPosition = newPosition;
|
||||
_isDragging = true;
|
||||
}
|
||||
|
||||
if (abs(Input.mouseScrollDelta.y) > .01f)
|
||||
{
|
||||
var previousPosition = Camera.ScreenToWorldPoint(Input.mousePosition);
|
||||
Camera.orthographicSize *= 1 + Input.mouseScrollDelta.y * Scaling;
|
||||
Camera.transform.position -= Camera.ScreenToWorldPoint(Input.mousePosition) - previousPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/MapViewDragHandler.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/MapViewDragHandler.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d172604daaa352b4784c662883d40ec9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
78
Assets/Scripts/UI/Menu/MenuPanel.cs
Normal file
78
Assets/Scripts/UI/Menu/MenuPanel.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/* 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 UniRx.Triggers;
|
||||
using UnityEngine;
|
||||
|
||||
public class MenuPanel : MonoBehaviour
|
||||
{
|
||||
public ActionGameManager GameManager;
|
||||
public RectTransform TabButtons;
|
||||
public Color ActiveTabColor;
|
||||
public Color InactiveTabColor;
|
||||
|
||||
public event Action<MenuTab> TabChanged;
|
||||
|
||||
private Dictionary<MenuTab, MenuTabButton> _tabs = new Dictionary<MenuTab, MenuTabButton>();
|
||||
private MenuTabButton _current;
|
||||
|
||||
public MenuTab CurrentTab { get; private set; }
|
||||
|
||||
public void ShowTab(MenuTab tab)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
|
||||
if (_current == _tabs[tab]) return;
|
||||
|
||||
if(_current != null)
|
||||
{
|
||||
_current.TabContents.SetActive(false);
|
||||
_current.Text.color = InactiveTabColor;
|
||||
}
|
||||
|
||||
CurrentTab = tab;
|
||||
_current = _tabs[tab];
|
||||
|
||||
_current.TabContents.SetActive(true);
|
||||
_current.Text.color = ActiveTabColor;
|
||||
|
||||
TabChanged?.Invoke(tab);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
foreach (var tabButton in _tabs.Values)
|
||||
{
|
||||
tabButton.gameObject.SetActive(!tabButton.RequireDock || GameManager.DockedEntity != null);
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
foreach (var tabButton in TabButtons.GetComponentsInChildren<MenuTabButton>())
|
||||
{
|
||||
tabButton.TabContents.SetActive(false);
|
||||
tabButton.Text.color = InactiveTabColor;
|
||||
_tabs.Add(tabButton.Tab, tabButton);
|
||||
tabButton.Button.onClick.AddListener(() => ShowTab(tabButton.Tab));
|
||||
}
|
||||
}
|
||||
|
||||
// void Start()
|
||||
// {
|
||||
// ShowTab(MenuTab.Inventory);
|
||||
// }
|
||||
}
|
||||
|
||||
public enum MenuTab
|
||||
{
|
||||
Map,
|
||||
Inventory,
|
||||
Trade,
|
||||
Galaxy,
|
||||
Local
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/MenuPanel.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/MenuPanel.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ebae71ac39c2d9a42b3cfbaa0d1ae7a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/UI/Menu/MenuTabButton.cs
Normal file
19
Assets/Scripts/UI/Menu/MenuTabButton.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* 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 TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MenuTabButton : MonoBehaviour
|
||||
{
|
||||
public GameObject TabContents;
|
||||
public Button Button;
|
||||
public MenuTab Tab;
|
||||
public TextMeshProUGUI Text;
|
||||
public bool RequireDock;
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/MenuTabButton.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/MenuTabButton.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d90317f6ecd38754fad9aee92f46b126
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/Scripts/UI/Menu/MouseHover.cs
Normal file
31
Assets/Scripts/UI/Menu/MouseHover.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* 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 UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class MouseHover : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public event Action<PointerEventData> OnEnter;
|
||||
public event Action<PointerEventData> OnExit;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
OnEnter?.Invoke(eventData);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
OnExit?.Invoke(eventData);
|
||||
}
|
||||
|
||||
public void ClearListeners()
|
||||
{
|
||||
OnEnter = null;
|
||||
OnExit = null;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/MouseHover.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/MouseHover.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6435d6126b6f8694292cb94466cf1df4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
340
Assets/Scripts/UI/Menu/SectorMap.cs
Normal file
340
Assets/Scripts/UI/Menu/SectorMap.cs
Normal file
|
|
@ -0,0 +1,340 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using static Unity.Mathematics.noise;
|
||||
using Random = UnityEngine.Random;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
|
||||
public class SectorMap : MonoBehaviour
|
||||
{
|
||||
public Camera InfluenceCamera;
|
||||
public Prototype InfluenceRendererPrototype;
|
||||
public MeshRenderer SectorRenderer;
|
||||
public Prototype ZonePrototype;
|
||||
public Prototype LinkPrototype;
|
||||
public Prototype IconPrototype;
|
||||
public Prototype IconBackgroundPrototype;
|
||||
public Material ZonePrimaryMaterial;
|
||||
public Material ZoneSecondaryMaterial;
|
||||
public Material ZoneLinkMaterial;
|
||||
public float MegaPrimaryBoost = .75f;
|
||||
public float MegaSecondaryBoost = 2f;
|
||||
public float MegaLinkBoost = 2f;
|
||||
public Texture2D EntranceIcon;
|
||||
public Texture2D ExitIcon;
|
||||
public Texture2D BossIcon;
|
||||
public Texture2D HomeIcon;
|
||||
public Prototype LegendPrototype;
|
||||
public float IconDistance = 1;
|
||||
public float IconBackgroundSize = 3;
|
||||
public float LabelDistance = .4f;
|
||||
public float LinkWidth;
|
||||
public float CriticalLinkWidth;
|
||||
public AnimationCurve IconScaleAnimation;
|
||||
public Color PlayerLocationLabelColor;
|
||||
public float PlayerLocationIconSize = 1.25f;
|
||||
|
||||
private SectorZone _currentPlayerLocation;
|
||||
private HashSet<SectorZone> _revealedZones = new HashSet<SectorZone>();
|
||||
private HashSet<(SectorZone, SectorZone)> _revealedLinks = new HashSet<(SectorZone, SectorZone)>();
|
||||
|
||||
private Dictionary<Faction, (MeshRenderer influenceRenderer, RenderTexture influence, Material primaryMaterial, Material secondaryMaterial, Material linkMaterial)> _factionMaterials =
|
||||
new Dictionary<Faction, (MeshRenderer influenceRenderer, RenderTexture influence, Material primaryMaterial, Material secondaryMaterial, Material linkMaterial)>();
|
||||
|
||||
private Dictionary<SectorZone, SectorZoneUI> _zoneInstances = new Dictionary<SectorZone, SectorZoneUI>();
|
||||
private Queue<IEnumerable<SectorZone>> _queuedZoneReveals = new Queue<IEnumerable<SectorZone>>();
|
||||
|
||||
public void MarkPlayerLocation(SectorZone zone)
|
||||
{
|
||||
if (_currentPlayerLocation != null)
|
||||
{
|
||||
_zoneInstances[_currentPlayerLocation].Label.color = Color.white;
|
||||
_zoneInstances[_currentPlayerLocation].Label.fontStyle = FontStyles.Normal;
|
||||
_zoneInstances[_currentPlayerLocation].IconContainer.localScale = Vector3.one;
|
||||
}
|
||||
|
||||
_currentPlayerLocation = zone;
|
||||
if(_zoneInstances.ContainsKey(_currentPlayerLocation))
|
||||
{
|
||||
MarkPlayerLocation(_zoneInstances[_currentPlayerLocation]);
|
||||
}
|
||||
}
|
||||
|
||||
private void MarkPlayerLocation(SectorZoneUI zoneUI)
|
||||
{
|
||||
zoneUI.Label.color = PlayerLocationLabelColor;
|
||||
zoneUI.Label.fontStyle = FontStyles.Bold;
|
||||
zoneUI.IconContainer.localScale = new Vector3(PlayerLocationIconSize, PlayerLocationIconSize, 1);
|
||||
}
|
||||
|
||||
public void QueueZoneReveal(IEnumerable<SectorZone> zones)
|
||||
{
|
||||
_queuedZoneReveals.Enqueue(zones);
|
||||
}
|
||||
|
||||
public void StartReveal(float linkDuration, float iconDuration)
|
||||
{
|
||||
if (_queuedZoneReveals.Count > 0)
|
||||
{
|
||||
StartCoroutine(RevealZone(_queuedZoneReveals.Dequeue(), linkDuration, iconDuration));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator RevealZone(IEnumerable<SectorZone> zones, float linkDuration, float iconDuration)
|
||||
{
|
||||
var linksToReveal = new List<(float2 start, float2 end, Transform linkInstance, bool critical)>();
|
||||
var zoneTransforms = new List<Transform>();
|
||||
var zoneInstanceScale = ZonePrototype.transform.localScale;
|
||||
|
||||
foreach (var zone in zones)
|
||||
{
|
||||
if (!_revealedZones.Contains(zone))
|
||||
{
|
||||
var zoneInstance = ZonePrototype.Instantiate<SectorZoneUI>();
|
||||
if(zone == _currentPlayerLocation)
|
||||
MarkPlayerLocation(zoneInstance);
|
||||
_zoneInstances[zone] = zoneInstance;
|
||||
var zoneInstanceTransform = zoneInstance.transform;
|
||||
zoneTransforms.Add(zoneInstanceTransform);
|
||||
zoneInstanceTransform.localPosition = new Vector3(zone.Position.x, zone.Position.y);
|
||||
if(zone.Owner != null)
|
||||
{
|
||||
zoneInstance.Primary.sharedMaterial = _factionMaterials[zone.Owner].primaryMaterial;
|
||||
zoneInstance.Secondary.sharedMaterial = _factionMaterials[zone.Owner].secondaryMaterial;
|
||||
if(zone == ActionGameManager.CurrentSector.HomeZones[zone.Owner])
|
||||
zoneInstance.Secondary.transform.localScale = Vector3.one * 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoneInstance.Secondary.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
var isOnCriticalPath = ActionGameManager.CurrentSector.ExitPath?.Contains(zone) ?? false;
|
||||
foreach (var adjacentZone in zone.AdjacentZones)
|
||||
{
|
||||
// If the adjacent zone is in the set already revealed, then show the link
|
||||
if (_revealedZones.Contains(adjacentZone) &&
|
||||
!(_revealedLinks.Contains((zone, adjacentZone)) ||
|
||||
_revealedLinks.Contains((adjacentZone, zone))))
|
||||
{
|
||||
var link = LinkPrototype.Instantiate<Transform>();
|
||||
var critical = isOnCriticalPath && (ActionGameManager.CurrentSector.ExitPath?.Contains(adjacentZone) ?? false);
|
||||
linksToReveal.Add((zone.Position, adjacentZone.Position, link, critical));
|
||||
if (zone.Owner != null && zone.Owner == adjacentZone.Owner)
|
||||
link.GetComponent<MeshRenderer>().sharedMaterial = _factionMaterials[zone.Owner].linkMaterial;
|
||||
|
||||
var dir = normalize(zone.Position - adjacentZone.Position);
|
||||
link.rotation = Quaternion.Euler(0,0,atan2(dir.y,dir.x) * Mathf.Rad2Deg);
|
||||
|
||||
placeLink(zone.Position, adjacentZone.Position, link, 0, critical);
|
||||
}
|
||||
}
|
||||
_revealedZones.Add(zone);
|
||||
|
||||
// Determine center of mass for adjacent zone links, used for placement of label and icons
|
||||
var linkDirection = normalize(zone.AdjacentZones
|
||||
.Aggregate(float2.zero, (v, adjacentZone) => v + normalize(adjacentZone.Position - zone.Position)));
|
||||
|
||||
var zoneText = zoneInstance.Label;
|
||||
zoneText.text = zone.Name;
|
||||
var zoneTextTransform = zoneText.GetComponent<RectTransform>();
|
||||
zoneTextTransform.pivot = new Vector2(sign(linkDirection.x)/2+.5f,sign(linkDirection.y)/2+.5f);
|
||||
zoneTextTransform.localPosition = new Vector3(-linkDirection.x * LabelDistance, -linkDirection.y * LabelDistance, -1);
|
||||
|
||||
if (zone == ActionGameManager.CurrentSector.Entrance)
|
||||
{
|
||||
var iconInstance = IconPrototype.Instantiate<MeshRenderer>();
|
||||
iconInstance.material.mainTexture = EntranceIcon;
|
||||
var iconTransform = iconInstance.transform;
|
||||
iconTransform.SetParent(zoneInstanceTransform);
|
||||
iconTransform.localScale = Vector3.one;
|
||||
iconTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance);
|
||||
}
|
||||
|
||||
if (zone == ActionGameManager.CurrentSector.Exit)
|
||||
{
|
||||
var iconInstance = IconPrototype.Instantiate<MeshRenderer>();
|
||||
iconInstance.material.mainTexture = ExitIcon;
|
||||
var iconTransform = iconInstance.transform;
|
||||
iconTransform.SetParent(zoneInstanceTransform);
|
||||
iconTransform.localScale = Vector3.one;
|
||||
iconTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance);
|
||||
}
|
||||
|
||||
var homeMega = ActionGameManager.CurrentSector.HomeZones.Keys
|
||||
.FirstOrDefault(m => ActionGameManager.CurrentSector.HomeZones[m] == zone);
|
||||
if (homeMega != null)
|
||||
{
|
||||
var backgroundInstance = IconBackgroundPrototype.Instantiate<MeshRenderer>();
|
||||
var iconInstance = IconPrototype.Instantiate<MeshRenderer>();
|
||||
|
||||
backgroundInstance.material.SetColor("_Color", homeMega.SecondaryColor.ToColor());
|
||||
iconInstance.material.mainTexture = HomeIcon;
|
||||
iconInstance.material.SetColor("_Color", homeMega.PrimaryColor.ToColor());
|
||||
|
||||
var backgroundTransform = backgroundInstance.transform;
|
||||
var iconTransform = iconInstance.transform;
|
||||
|
||||
backgroundTransform.SetParent(zoneInstanceTransform);
|
||||
iconTransform.SetParent(zoneInstanceTransform);
|
||||
|
||||
backgroundTransform.localScale = Vector3.one * IconBackgroundSize;
|
||||
iconTransform.localScale = Vector3.one;
|
||||
|
||||
backgroundTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance, .5f);
|
||||
iconTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance);
|
||||
}
|
||||
|
||||
var bossMega = ActionGameManager.CurrentSector.BossZones.Keys
|
||||
.FirstOrDefault(m => ActionGameManager.CurrentSector.BossZones[m] == zone);
|
||||
if (bossMega != null)
|
||||
{
|
||||
var backgroundInstance = IconBackgroundPrototype.Instantiate<MeshRenderer>();
|
||||
var iconInstance = IconPrototype.Instantiate<MeshRenderer>();
|
||||
|
||||
backgroundInstance.material.SetColor("_Color", bossMega.SecondaryColor.ToColor());
|
||||
iconInstance.material.mainTexture = BossIcon;
|
||||
iconInstance.material.SetColor("_Color", bossMega.PrimaryColor.ToColor());
|
||||
|
||||
var backgroundTransform = backgroundInstance.transform;
|
||||
var iconTransform = iconInstance.transform;
|
||||
|
||||
backgroundTransform.SetParent(zoneInstanceTransform);
|
||||
iconTransform.SetParent(zoneInstanceTransform);
|
||||
|
||||
backgroundTransform.localScale = Vector3.one * IconBackgroundSize;
|
||||
iconTransform.localScale = Vector3.one;
|
||||
|
||||
if (homeMega != null)
|
||||
{
|
||||
backgroundTransform.localPosition = new Vector3(linkDirection.x * IconDistance, linkDirection.y * IconDistance, .5f);
|
||||
iconTransform.localPosition = new Vector3(linkDirection.x * IconDistance, linkDirection.y * IconDistance);
|
||||
}
|
||||
else
|
||||
{
|
||||
backgroundTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance, .5f);
|
||||
iconTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var tr in zoneTransforms) tr.gameObject.SetActive(false);
|
||||
|
||||
// Local function for animating the placement of a link
|
||||
void placeLink(float2 start, float2 end, Transform link, float t, bool critical)
|
||||
{
|
||||
var pos = lerp(start, end, t / 2);
|
||||
link.localPosition = new Vector3(pos.x, pos.y);
|
||||
|
||||
var localScale = link.localScale;
|
||||
localScale = new Vector3(length(start - end)*t, critical ? CriticalLinkWidth : LinkWidth, 1);
|
||||
link.localScale = localScale;
|
||||
}
|
||||
|
||||
var startTime = Time.time;
|
||||
while (Time.time - startTime < linkDuration)
|
||||
{
|
||||
var t = (Time.time - startTime) / linkDuration;
|
||||
foreach (var (start, end, link, critical) in linksToReveal) placeLink(end, start, link, t, critical);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
foreach (var (start, end, link, critical) in linksToReveal) placeLink(start, end, link, 1, critical);
|
||||
|
||||
foreach (var tr in zoneTransforms) tr.gameObject.SetActive(true);
|
||||
startTime = Time.time;
|
||||
while (Time.time - startTime < iconDuration)
|
||||
{
|
||||
var t = (Time.time - startTime) / iconDuration;
|
||||
foreach (var tr in zoneTransforms) tr.localScale = zoneInstanceScale * IconScaleAnimation.Evaluate(t);
|
||||
RenderInfluence();
|
||||
|
||||
yield return null;
|
||||
}
|
||||
foreach (var tr in zoneTransforms) tr.localScale = zoneInstanceScale;
|
||||
|
||||
StartReveal(linkDuration, iconDuration);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (ActionGameManager.CurrentSector == null)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
foreach (var mega in ActionGameManager.CurrentSector.Factions)
|
||||
{
|
||||
var influenceTexture = new RenderTexture(1024, 1024, 0, RenderTextureFormat.RHalf);
|
||||
var influenceRenderer = InfluenceRendererPrototype.Instantiate<MeshRenderer>();
|
||||
|
||||
influenceRenderer.material.mainTexture = influenceTexture;
|
||||
influenceRenderer.material.SetColor("_Color1", mega.PrimaryColor.ToColor());
|
||||
influenceRenderer.material.SetColor("_Color2", mega.SecondaryColor.ToColor());
|
||||
influenceRenderer.material.SetFloat("_FillTilt", Random.value * PI);
|
||||
|
||||
var primary = Instantiate(ZonePrimaryMaterial);
|
||||
primary.SetColor("_Color", (mega.PrimaryColor * MegaPrimaryBoost).ToColor());
|
||||
|
||||
var secondary = Instantiate(ZoneSecondaryMaterial);
|
||||
secondary.SetColor("_Color", (mega.SecondaryColor * MegaSecondaryBoost).ToColor());
|
||||
|
||||
var link = Instantiate(ZoneLinkMaterial);
|
||||
link.SetColor("_Color", (mega.PrimaryColor * MegaLinkBoost).ToColor());
|
||||
|
||||
_factionMaterials.Add(mega, (influenceRenderer, influenceTexture, primary, secondary, link));
|
||||
|
||||
var legendElement = LegendPrototype.Instantiate<LegendElement>();
|
||||
legendElement.Primary.color = mega.PrimaryColor.ToColor();
|
||||
legendElement.Secondary.color = mega.SecondaryColor.ToColor();
|
||||
legendElement.Label.text = mega.ShortName;
|
||||
}
|
||||
|
||||
SectorRenderer.material.SetFloat("CloudAmplitude", ActionGameManager.CurrentSector.Background.CloudAmplitude);
|
||||
SectorRenderer.material.SetFloat("CloudExponent", ActionGameManager.CurrentSector.Background.CloudExponent);
|
||||
SectorRenderer.material.SetFloat("NoisePosition", ActionGameManager.CurrentSector.Background.NoisePosition);
|
||||
SectorRenderer.material.SetFloat("NoiseAmplitude", ActionGameManager.CurrentSector.Background.NoiseAmplitude);
|
||||
SectorRenderer.material.SetFloat("NoiseOffset", ActionGameManager.CurrentSector.Background.NoiseOffset);
|
||||
SectorRenderer.material.SetFloat("NoiseGain", ActionGameManager.CurrentSector.Background.NoiseGain);
|
||||
SectorRenderer.material.SetFloat("NoiseLacunarity", ActionGameManager.CurrentSector.Background.NoiseLacunarity);
|
||||
SectorRenderer.material.SetFloat("NoiseFrequency", ActionGameManager.CurrentSector.Background.NoiseFrequency);
|
||||
}
|
||||
|
||||
private void RenderInfluence()
|
||||
{
|
||||
// Render Influence Textures
|
||||
foreach (var mega in ActionGameManager.CurrentSector.Factions)
|
||||
{
|
||||
foreach (var zone in ActionGameManager.CurrentSector.Zones)
|
||||
{
|
||||
if(_zoneInstances.ContainsKey(zone))
|
||||
{
|
||||
var instance = _zoneInstances[zone];
|
||||
var influence = 0f;
|
||||
if (zone.Factions.Length > 0)
|
||||
{
|
||||
if (zone.Factions.Contains(mega))
|
||||
{
|
||||
influence = 10;
|
||||
if (zone.Owner != mega)
|
||||
influence *= .5f;
|
||||
}
|
||||
else influence = -10;
|
||||
}
|
||||
|
||||
instance.Influence.material.SetFloat("_Depth", influence);
|
||||
}
|
||||
}
|
||||
|
||||
InfluenceCamera.targetTexture = _factionMaterials[mega].influence;
|
||||
InfluenceCamera.Render();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/SectorMap.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/SectorMap.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5369ea8554e422a45a9f949bdd3bee3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
161
Assets/Scripts/UI/Menu/SectorRenderer.cs
Normal file
161
Assets/Scripts/UI/Menu/SectorRenderer.cs
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
|
||||
public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IScrollHandler
|
||||
{
|
||||
public Canvas Canvas;
|
||||
public SectorMap Map;
|
||||
public ActionGameManager GameManager;
|
||||
public Camera MainCamera;
|
||||
public Camera SectorCamera;
|
||||
public MeshRenderer SectorBackgroundRenderer;
|
||||
public float ZoomSpeed;
|
||||
public float MinViewSize = .1f;
|
||||
public float MaxViewSize = 2;
|
||||
// public float PathAnimationDamping = .01f;
|
||||
// public float PathAnimationDuration = 30;
|
||||
// public float PathAnimationDurationPadding = 1.1f;
|
||||
public GameObject LegendPanel;
|
||||
public float LinkAnimationDuration;
|
||||
public float IconAnimationDuration;
|
||||
|
||||
private float2 _startMousePosition;
|
||||
private float2 _startMapPosition;
|
||||
|
||||
private Transform _sectorBackgroundTransform;
|
||||
private Transform _sectorCameraTransform;
|
||||
private Image _outputImage;
|
||||
private RenderTexture _outputTexture;
|
||||
private int2 _size;
|
||||
private bool _init;
|
||||
private float _aspectRatio;
|
||||
private float _sectorBackgroundDepth;
|
||||
private float _sectorCameraDepth;
|
||||
|
||||
private float2 _position = float2(0.5f);
|
||||
private float _viewSize = .5f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_outputImage = GetComponent<Image>();
|
||||
_sectorBackgroundTransform = SectorBackgroundRenderer.transform;
|
||||
_sectorBackgroundDepth = _sectorBackgroundTransform.position.z;
|
||||
_sectorCameraTransform = SectorCamera.transform;
|
||||
_sectorCameraDepth = _sectorCameraTransform.position.z;
|
||||
// PathAnimationButton.onClick.AddListener(() =>
|
||||
// {
|
||||
// Map.StartCoroutine(AnimatePath());
|
||||
// });
|
||||
}
|
||||
|
||||
// private IEnumerator AnimatePath()
|
||||
// {
|
||||
// var pathZones = ActionGameManager.CurrentSector.ExitPath;
|
||||
// LegendPanel.SetActive(false);
|
||||
// PathAnimationButton.gameObject.SetActive(false);
|
||||
//
|
||||
// var revealCount = ActionGameManager.CurrentSector.Entrance.Distance[ActionGameManager.CurrentSector.Exit];
|
||||
// Map.StartReveal(
|
||||
// PathAnimationDuration / revealCount * (LinkAnimationDuration / (IconAnimationDuration + LinkAnimationDuration)),
|
||||
// PathAnimationDuration / revealCount * (IconAnimationDuration / (IconAnimationDuration + LinkAnimationDuration)));
|
||||
// MainCamera.enabled = false;
|
||||
// SectorCamera.targetTexture = null;
|
||||
// Canvas.gameObject.SetActive(false);
|
||||
// SectorCamera.gameObject.SetActive(true);
|
||||
//
|
||||
// var pathAnimationLerp = 0f;
|
||||
// while (pathAnimationLerp < 1)
|
||||
// {
|
||||
// var currentTargetZone = pathZones[(int) (pathZones.Length * pathAnimationLerp)];
|
||||
// _position = lerp(_position, currentTargetZone.Position, PathAnimationDamping);
|
||||
// pathAnimationLerp += Time.deltaTime / (PathAnimationDuration * PathAnimationDurationPadding);
|
||||
// UpdateCamera();
|
||||
// yield return null;
|
||||
// }
|
||||
//
|
||||
// LegendPanel.SetActive(true);
|
||||
// PathAnimationButton.gameObject.SetActive(true);
|
||||
// }
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_init = true;
|
||||
SectorCamera.gameObject.SetActive(true);
|
||||
_position = GameManager.Zone.SectorZone.Position;
|
||||
_viewSize = .25f;
|
||||
|
||||
Map.StartReveal(LinkAnimationDuration, IconAnimationDuration);
|
||||
Map.MarkPlayerLocation(GameManager.CurrentEntity.Zone.SectorZone);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_outputTexture != null)
|
||||
{
|
||||
_outputTexture.Release();
|
||||
_outputTexture = null;
|
||||
}
|
||||
SectorCamera.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
var size = int2(Screen.width, Screen.height);
|
||||
if (_init || size.x != _size.x || size.y != _size.y)
|
||||
{
|
||||
_aspectRatio = (float) size.x / size.y;
|
||||
_size = size;
|
||||
if (_outputTexture != null)
|
||||
{
|
||||
_outputTexture.Release();
|
||||
}
|
||||
_outputTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.Default);
|
||||
SectorCamera.targetTexture = _outputTexture;
|
||||
_outputImage.material.SetTexture("_DetailTex", _outputTexture);
|
||||
}
|
||||
|
||||
UpdateCamera();
|
||||
}
|
||||
|
||||
void UpdateCamera()
|
||||
{
|
||||
var halfSize = _viewSize / 2;
|
||||
var bounds = float4(
|
||||
_position.x - _aspectRatio * halfSize,
|
||||
_position.y - halfSize,
|
||||
_position.x + _aspectRatio * halfSize,
|
||||
_position.y + halfSize);
|
||||
_sectorBackgroundTransform.position = new Vector3(_position.x, _position.y, _sectorBackgroundDepth);
|
||||
_sectorBackgroundTransform.localScale = new Vector3(_aspectRatio * _viewSize, _viewSize);
|
||||
_sectorCameraTransform.position = new Vector3(_position.x, _position.y, _sectorCameraDepth);
|
||||
SectorCamera.orthographicSize = halfSize;
|
||||
SectorBackgroundRenderer.material.SetVector("Extents", bounds);
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
_startMousePosition = eventData.position;
|
||||
_startMapPosition = _position;
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
_position = _startMapPosition - ((float2)eventData.position - _startMousePosition) / _size.y * _viewSize;
|
||||
}
|
||||
|
||||
public void OnScroll(PointerEventData eventData)
|
||||
{
|
||||
var mapCenter = float2((float)Screen.width / 2, (float)Screen.height / 2);
|
||||
var oldPointerPosition = _position + ((float2)eventData.position - mapCenter) / Screen.height * _viewSize;
|
||||
_viewSize = clamp(_viewSize * (1 - eventData.scrollDelta.y * ZoomSpeed), MinViewSize, MaxViewSize);
|
||||
var pointerPosition = _position + ((float2)eventData.position - mapCenter) / Screen.height * _viewSize;
|
||||
_position += oldPointerPosition - pointerPosition;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/SectorRenderer.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/SectorRenderer.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 59b26802254e34b4bb26f48d0d8b51bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/UI/Menu/SectorZoneUI.cs
Normal file
14
Assets/Scripts/UI/Menu/SectorZoneUI.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SectorZoneUI : MonoBehaviour
|
||||
{
|
||||
public MeshRenderer Primary;
|
||||
public MeshRenderer Secondary;
|
||||
public MeshRenderer Influence;
|
||||
public TextMeshPro Label;
|
||||
public Transform IconContainer;
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/SectorZoneUI.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/SectorZoneUI.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c8b54233e980c94096777e19a4e070a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
26
Assets/Scripts/UI/Menu/SizeFilter.cs
Normal file
26
Assets/Scripts/UI/Menu/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/Menu/SizeFilter.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/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/Menu/Spreadsheet.cs
Normal file
199
Assets/Scripts/UI/Menu/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/Menu/Spreadsheet.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/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/Menu/SpreadsheetColumnHeader.cs
Normal file
30
Assets/Scripts/UI/Menu/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/Menu/SpreadsheetColumnHeader.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/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/Menu/SpreadsheetRow.cs
Normal file
40
Assets/Scripts/UI/Menu/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/Menu/SpreadsheetRow.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/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:
|
||||
468
Assets/Scripts/UI/Menu/TradeMenu.cs
Normal file
468
Assets/Scripts/UI/Menu/TradeMenu.cs
Normal file
|
|
@ -0,0 +1,468 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class TradeMenu : MonoBehaviour
|
||||
{
|
||||
public ActionGameManager GameManager;
|
||||
public ContextMenu ContextMenu;
|
||||
public ConfirmationDialog Dialog;
|
||||
public Button NewFilterButton;
|
||||
public Prototype FilterPrototype;
|
||||
public SizeFilter MinimumSizeFilter;
|
||||
public SizeFilter MaximumSizeFilter;
|
||||
public PropertiesPanel Properties;
|
||||
public Spreadsheet Spreadsheet;
|
||||
public TextMeshProUGUI TargetCargoLabel;
|
||||
public Button FoldoutButton;
|
||||
|
||||
private EquippedCargoBay _targetCargo;
|
||||
private (ItemFilter filter, HardpointType type) _hardpointFilter;
|
||||
private (ItemFilter filter, SimpleCommodityCategory type) _commodityFilter;
|
||||
private (ItemFilter filter, CompoundCommodityCategory type) _compoundCommodityFilter;
|
||||
private List<(ItemFilter filter, Type type)> _behaviorFilters = new List<(ItemFilter filter, Type type)>();
|
||||
|
||||
public EquippedCargoBay Inventory { get; set; }
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (GameManager.DockedEntity == null) return;
|
||||
_targetCargo = GameManager.DockingBay;
|
||||
TargetCargoLabel.text = "Docking Bay";
|
||||
Properties.GameManager = GameManager;
|
||||
|
||||
MinimumSizeFilter.Width.onEndEdit.RemoveAllListeners();
|
||||
MinimumSizeFilter.Width.onEndEdit.AddListener(_ => Populate());
|
||||
|
||||
MinimumSizeFilter.Height.onEndEdit.RemoveAllListeners();
|
||||
MinimumSizeFilter.Height.onEndEdit.AddListener(_ => Populate());
|
||||
|
||||
MaximumSizeFilter.Width.onEndEdit.RemoveAllListeners();
|
||||
MaximumSizeFilter.Width.onEndEdit.AddListener(_ => Populate());
|
||||
|
||||
MaximumSizeFilter.Height.onEndEdit.RemoveAllListeners();
|
||||
MaximumSizeFilter.Height.onEndEdit.AddListener(_ => Populate());
|
||||
|
||||
NewFilterButton.onClick.AddListener(() =>
|
||||
{
|
||||
ContextMenu.Clear();
|
||||
IEnumerable<HardpointType> hardpointTypes = (HardpointType[]) Enum.GetValues(typeof(HardpointType));
|
||||
if (_hardpointFilter.filter != null)
|
||||
hardpointTypes = hardpointTypes.Where(x => x != _hardpointFilter.type);
|
||||
|
||||
IEnumerable<SimpleCommodityCategory> commodityTypes = (SimpleCommodityCategory[]) Enum.GetValues(typeof(SimpleCommodityCategory));
|
||||
if (_commodityFilter.filter != null)
|
||||
commodityTypes = commodityTypes.Where(x => x != _commodityFilter.type);
|
||||
|
||||
IEnumerable<CompoundCommodityCategory> compoundCommodityTypes = (CompoundCommodityCategory[]) Enum.GetValues(typeof(CompoundCommodityCategory));
|
||||
if (_compoundCommodityFilter.filter != null)
|
||||
compoundCommodityTypes = compoundCommodityTypes.Where(x => x != _compoundCommodityFilter.type);
|
||||
|
||||
ContextMenu.AddDropdown("Gear Type", hardpointTypes
|
||||
.Select<HardpointType, (string, Action, bool)>(x => (Enum.GetName(typeof(HardpointType), x), () =>
|
||||
{
|
||||
if (!_hardpointFilter.filter)
|
||||
{
|
||||
_hardpointFilter.filter = FilterPrototype.Instantiate<ItemFilter>();
|
||||
_hardpointFilter.filter.OnDisable += () =>
|
||||
{
|
||||
_hardpointFilter.filter = null;
|
||||
Populate();
|
||||
};
|
||||
}
|
||||
if(_commodityFilter.filter)
|
||||
{
|
||||
_commodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_commodityFilter.filter = null;
|
||||
}
|
||||
if(_compoundCommodityFilter.filter)
|
||||
{
|
||||
_compoundCommodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_compoundCommodityFilter.filter = null;
|
||||
}
|
||||
|
||||
_hardpointFilter.filter.Label.text = $"Hardpoint: {Enum.GetName(typeof(HardpointType), x)}";
|
||||
_hardpointFilter.type = x;
|
||||
Populate();
|
||||
}, true)));
|
||||
ContextMenu.AddDropdown("Simple Commodity", commodityTypes
|
||||
.Select<SimpleCommodityCategory, (string, Action, bool)>(x => (Enum.GetName(typeof(SimpleCommodityCategory), x), () =>
|
||||
{
|
||||
if (!_commodityFilter.filter)
|
||||
{
|
||||
_commodityFilter.filter = FilterPrototype.Instantiate<ItemFilter>();
|
||||
_commodityFilter.filter.OnDisable += () =>
|
||||
{
|
||||
_commodityFilter.filter = null;
|
||||
Populate();
|
||||
};
|
||||
}
|
||||
if(_hardpointFilter.filter)
|
||||
{
|
||||
_hardpointFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_hardpointFilter.filter = null;
|
||||
}
|
||||
if(_compoundCommodityFilter.filter)
|
||||
{
|
||||
_compoundCommodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_compoundCommodityFilter.filter = null;
|
||||
}
|
||||
|
||||
_commodityFilter.filter.Label.text = $"Hardpoint: {Enum.GetName(typeof(SimpleCommodityCategory), x)}";
|
||||
_commodityFilter.type = x;
|
||||
Populate();
|
||||
}, true)));
|
||||
ContextMenu.AddDropdown("Compound Commodity", compoundCommodityTypes
|
||||
.Select<CompoundCommodityCategory, (string, Action, bool)>(x => (Enum.GetName(typeof(CompoundCommodityCategory), x), () =>
|
||||
{
|
||||
if (!_compoundCommodityFilter.filter)
|
||||
{
|
||||
_compoundCommodityFilter.filter = FilterPrototype.Instantiate<ItemFilter>();
|
||||
_compoundCommodityFilter.filter.OnDisable += () =>
|
||||
{
|
||||
_compoundCommodityFilter.filter = null;
|
||||
Populate();
|
||||
};
|
||||
}
|
||||
if(_hardpointFilter.filter)
|
||||
{
|
||||
_hardpointFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_hardpointFilter.filter = null;
|
||||
}
|
||||
if(_commodityFilter.filter)
|
||||
{
|
||||
_commodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_commodityFilter.filter = null;
|
||||
}
|
||||
|
||||
_compoundCommodityFilter.filter.Label.text = $"Hardpoint: {Enum.GetName(typeof(CompoundCommodityCategory), x)}";
|
||||
_compoundCommodityFilter.type = x;
|
||||
Populate();
|
||||
}, true)));
|
||||
ContextMenu.AddDropdown("Item Behavior", typeof(BehaviorData).GetAllChildClasses()
|
||||
.Where(x=> x.GetCustomAttribute<RuntimeInspectable>() != null && _behaviorFilters.All(f => f.type != x))
|
||||
.Select<Type, (string, Action, bool)>(x=> (x.Name.FormatTypeName(), () =>
|
||||
{
|
||||
var matchingType = _behaviorFilters.FirstOrDefault(y => y.type.IsAssignableFrom(x) || x.IsAssignableFrom(y.type));
|
||||
if (matchingType.filter != null) matchingType.filter.DisableButton.onClick.Invoke();
|
||||
var filter = FilterPrototype.Instantiate<ItemFilter>();
|
||||
filter.Label.text = x.Name.FormatTypeName();
|
||||
filter.OnDisable += () =>
|
||||
{
|
||||
_behaviorFilters.Remove((filter, x));
|
||||
Populate();
|
||||
};
|
||||
_behaviorFilters.Add((filter, x));
|
||||
Populate();
|
||||
}, true)));
|
||||
if(!MinimumSizeFilter.gameObject.activeSelf)
|
||||
ContextMenu.AddOption("Minimum Size",
|
||||
() =>
|
||||
{
|
||||
MinimumSizeFilter.gameObject.SetActive(true);
|
||||
MinimumSizeFilter.OnDisable += () => Populate();
|
||||
});
|
||||
if(!MaximumSizeFilter.gameObject.activeSelf)
|
||||
ContextMenu.AddOption("Maximum Size",
|
||||
() =>
|
||||
{
|
||||
MaximumSizeFilter.gameObject.SetActive(true);
|
||||
MaximumSizeFilter.OnDisable += () => Populate();
|
||||
});
|
||||
ContextMenu.Show();
|
||||
});
|
||||
Populate();
|
||||
}
|
||||
|
||||
void Populate()
|
||||
{
|
||||
var columns = new List<(string name, int size, Func<(ItemInstance item, ItemData data), Func<string>> output, Func<ItemData, IComparable> sortKey)>();
|
||||
|
||||
columns.Add(("Name", 3,
|
||||
x => () => x.item is CraftedItemInstance craftedItemInstance ?
|
||||
$"<color=#{ColorUtility.ToHtmlStringRGB(GameManager.ItemManager.GetTier(craftedItemInstance).tier.Color.ToColor())}>{x.data.Name}" :
|
||||
x.data.Name,
|
||||
data => data.Name));
|
||||
if(_hardpointFilter.filter==null)
|
||||
columns.Add(("Type", 2,
|
||||
x => () =>
|
||||
{
|
||||
if (x.data is SimpleCommodityData s) return Enum.GetName(typeof(SimpleCommodityCategory), s.Category);
|
||||
if(x.data is CompoundCommodityData c) return Enum.GetName(typeof(CompoundCommodityCategory), c.Category);
|
||||
if(x.data is EquippableItemData e) return Enum.GetName(typeof(HardpointType), e.HardpointType);
|
||||
return "None";
|
||||
},
|
||||
data =>
|
||||
{
|
||||
if (data is SimpleCommodityData s) return (int) s.Category;
|
||||
var offset = Enum.GetValues(typeof(SimpleCommodityCategory)).Length;
|
||||
if(data is CompoundCommodityData c) return (int) c.Category + offset;
|
||||
offset += Enum.GetValues(typeof(CompoundCommodityCategory)).Length;
|
||||
if(data is EquippableItemData e) return (int) e.HardpointType + offset;
|
||||
return 0;
|
||||
}));
|
||||
columns.Add(("Mass", 1,
|
||||
x => () => ActionGameManager.PlayerSettings.Format(x.data.Mass),
|
||||
data => data.Mass));
|
||||
columns.Add(("Price", 1,
|
||||
x => () => (x.item is CraftedItemInstance craftedItemInstance ? GameManager.ItemManager.GetPrice(craftedItemInstance) : x.data.Price).ToString("N0"),
|
||||
data => data.Price));
|
||||
columns.Add(("Size", 1,
|
||||
x => () => $"{x.data.Shape.Width}x{x.data.Shape.Height}",
|
||||
data => data.Shape.Width*data.Shape.Height));
|
||||
|
||||
var items = Inventory.Cargo.Keys
|
||||
.Select<ItemInstance, (ItemInstance item, ItemData data)>(ii=>(ii, ii.Data.Value));
|
||||
|
||||
if (MinimumSizeFilter.gameObject.activeSelf)
|
||||
items = items.Where(i =>
|
||||
!(MinimumSizeFilter.Width.text.Length > 0 && i.data.Shape.Width < int.Parse(MinimumSizeFilter.Width.text) ||
|
||||
MinimumSizeFilter.Height.text.Length > 0 && i.data.Shape.Height < int.Parse(MinimumSizeFilter.Height.text)));
|
||||
|
||||
if (MaximumSizeFilter.gameObject.activeSelf)
|
||||
items = items.Where(i =>
|
||||
!(MaximumSizeFilter.Width.text.Length > 0 && i.data.Shape.Width > int.Parse(MaximumSizeFilter.Width.text) ||
|
||||
MaximumSizeFilter.Height.text.Length > 0 && i.data.Shape.Height > int.Parse(MaximumSizeFilter.Height.text)));
|
||||
|
||||
if(_commodityFilter.filter != null)
|
||||
items = items.Where(i => i.data is SimpleCommodityData s && s.Category == _commodityFilter.type);
|
||||
|
||||
if(_compoundCommodityFilter.filter != null)
|
||||
items = items.Where(i => i.data is CompoundCommodityData c && c.Category == _compoundCommodityFilter.type);
|
||||
|
||||
if (_hardpointFilter.filter != null)
|
||||
items = items.Where(i => i.data is EquippableItemData e && e.HardpointType == _hardpointFilter.type);
|
||||
|
||||
foreach (var (_, type) in _behaviorFilters)
|
||||
{
|
||||
items = items.Where(i => i.data is EquippableItemData e && e.Behaviors.Any(b => type.IsInstanceOfType(b)));
|
||||
|
||||
foreach (var field in type.GetFields().Where(f => f.GetCustomAttribute<RuntimeInspectable>() != null))
|
||||
{
|
||||
var fieldType = field.FieldType;
|
||||
if (fieldType == typeof(float))
|
||||
columns.Add((field.Name, 1, x =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) x.data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return () => ActionGameManager.PlayerSettings.Format((float) field.GetValue(behavior));
|
||||
}, data =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return (float) field.GetValue(behavior);
|
||||
}));
|
||||
else if (fieldType == typeof(int))
|
||||
columns.Add((field.Name, 1, x =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) x.data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return () => ((int) field.GetValue(behavior)).ToString();
|
||||
}, data =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return (int) field.GetValue(behavior);
|
||||
}));
|
||||
else if (fieldType == typeof(PerformanceStat))
|
||||
{
|
||||
columns.Add((field.Name, 1, x =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) x.data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return () => ActionGameManager.PlayerSettings.Format(((PerformanceStat) field.GetValue(behavior)).Max);
|
||||
}, data =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return ((PerformanceStat) field.GetValue(behavior)).Max;
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
columns.Add(("Owned", 1,
|
||||
x => () =>
|
||||
{
|
||||
if (x.data is HullData)
|
||||
return GameManager.DockedEntity.Children.Count(s => s.Hull.Data.LinkID == x.data.ID && s is Ship {IsPlayerShip: true}).ToString();
|
||||
if(x.data is SimpleCommodityData)
|
||||
return (_targetCargo.ItemsOfType.ContainsKey(x.data.ID) ? _targetCargo.ItemsOfType[x.data.ID].Cast<SimpleCommodity>().Sum(s=>s.Quantity) : 0).ToString();
|
||||
return (_targetCargo.ItemsOfType.ContainsKey(x.data.ID) ? _targetCargo.ItemsOfType[x.data.ID].Count : 0).ToString();
|
||||
},
|
||||
data =>
|
||||
{
|
||||
if (data is HullData)
|
||||
return GameManager.DockedEntity.Children.Count(s => s.Hull.Data.LinkID == data.ID && s is Ship {IsPlayerShip: true});
|
||||
if(data is SimpleCommodityData)
|
||||
return _targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Cast<SimpleCommodity>().Sum(s=>s.Quantity) : 0;
|
||||
return _targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Count : 0;
|
||||
}));
|
||||
|
||||
Spreadsheet.ShowData(
|
||||
columns.Select(x => x.name).ToArray(),
|
||||
columns.Select(x => x.size).ToArray(),
|
||||
items.Select(i => new SpreadsheetEntryRow
|
||||
{
|
||||
Columns = columns.Select(x => new SpreadsheetEntryColumn
|
||||
{
|
||||
Output = x.output(i),
|
||||
SortKey = x.sortKey(i.data)
|
||||
}).ToArray(),
|
||||
OnClick = () => Properties.Inspect(i.item),
|
||||
OnDoubleClick = () =>
|
||||
{
|
||||
switch (i.item)
|
||||
{
|
||||
case CraftedItemInstance c:
|
||||
Buy(c);
|
||||
break;
|
||||
case SimpleCommodity s:
|
||||
Buy(s, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
Populate();
|
||||
},
|
||||
OnRightClick = () =>
|
||||
{
|
||||
if (i.item is SimpleCommodity s)
|
||||
{
|
||||
ContextMenu.Clear();
|
||||
ContextMenu.AddOption("Buy Quantity",
|
||||
() =>
|
||||
{
|
||||
int quantity = 1;
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = $"Buying {i.data.Name}";
|
||||
Dialog.AddField("Quantity",
|
||||
() => quantity,
|
||||
q => quantity = min(min(q, GameManager.Credits / i.data.Price), s.Quantity));
|
||||
Dialog.Show(() =>
|
||||
{
|
||||
Buy(s,quantity);
|
||||
|
||||
Populate();
|
||||
});
|
||||
Dialog.MoveToCursor();
|
||||
});
|
||||
ContextMenu.Show();
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void Buy(CraftedItemInstance item)
|
||||
{
|
||||
var data = GameManager.ItemManager.GetData(item);
|
||||
var price = GameManager.ItemManager.GetPrice(item);
|
||||
if (price < GameManager.Credits)
|
||||
{
|
||||
if (data is HullData hullData)
|
||||
{
|
||||
if (hullData.HullType != HullType.Ship) throw new ArgumentException("Attempted to buy non-ship hull from station, WTF are you doing?!");
|
||||
|
||||
var ship = new Ship(GameManager.ItemManager, GameManager.Zone, item as EquippableItem, GameManager.NewEntitySettings) {IsPlayerShip = true};
|
||||
ship.SetParent(GameManager.DockedEntity);
|
||||
|
||||
GameManager.Credits -= data.Price;
|
||||
}
|
||||
else if (Inventory.TryTransferItem(_targetCargo, item))
|
||||
{
|
||||
GameManager.Credits -= price;
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to buy: Insufficient Cargo Space!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to buy: Insufficient Credits!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void Buy(SimpleCommodity simpleCommodity, int quantity)
|
||||
{
|
||||
var data = GameManager.ItemManager.GetData(simpleCommodity);
|
||||
// Up-rounded integer division from https://stackoverflow.com/a/503201
|
||||
int lots = (quantity - 1) / data.MaxStack + 1;
|
||||
int remaining = quantity;
|
||||
for (int i = 0; i < lots; i++)
|
||||
{
|
||||
int q = min(remaining, data.MaxStack);
|
||||
if (q * data.Price < GameManager.Credits)
|
||||
{
|
||||
if (Inventory.TryTransferItem(_targetCargo, simpleCommodity, quantity))
|
||||
{
|
||||
GameManager.Credits -= q * data.Price;
|
||||
remaining -= q;
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to buy: Insufficient Cargo Space!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to buy: Insufficient Credits!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
FoldoutButton.onClick.AddListener(() =>
|
||||
{
|
||||
ContextMenu.Clear();
|
||||
if(_targetCargo != GameManager.DockingBay)
|
||||
ContextMenu.AddOption("Docking Bay",
|
||||
() =>
|
||||
{
|
||||
_targetCargo = GameManager.DockingBay;
|
||||
TargetCargoLabel.text = "Docking Bay";
|
||||
});
|
||||
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)))
|
||||
{
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/TradeMenu.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/TradeMenu.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 674196ee85a8a424ab8d3f4d0101ada7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
472
Assets/Scripts/UI/Menu/TradeMenuDebug.cs
Normal file
472
Assets/Scripts/UI/Menu/TradeMenuDebug.cs
Normal file
|
|
@ -0,0 +1,472 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class TradeMenuDebug : MonoBehaviour
|
||||
{
|
||||
public ActionGameManager GameManager;
|
||||
public ContextMenu ContextMenu;
|
||||
public ConfirmationDialog Dialog;
|
||||
public Button NewFilterButton;
|
||||
public Prototype FilterPrototype;
|
||||
public SizeFilter MinimumSizeFilter;
|
||||
public SizeFilter MaximumSizeFilter;
|
||||
public PropertiesPanel Properties;
|
||||
public Spreadsheet Spreadsheet;
|
||||
public TextMeshProUGUI TargetCargoLabel;
|
||||
public Button FoldoutButton;
|
||||
|
||||
private EquippedCargoBay _targetCargo;
|
||||
private (ItemFilter filter, HardpointType type) _hardpointFilter;
|
||||
private (ItemFilter filter, SimpleCommodityCategory type) _commodityFilter;
|
||||
private (ItemFilter filter, CompoundCommodityCategory type) _compoundCommodityFilter;
|
||||
private List<(ItemFilter filter, Type type)> _behaviorFilters = new List<(ItemFilter filter, Type type)>();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_targetCargo = GameManager.DockingBay;
|
||||
TargetCargoLabel.text = "Docking Bay";
|
||||
Properties.GameManager = GameManager;
|
||||
MinimumSizeFilter.Width.onEndEdit.AddListener(_ => Populate());
|
||||
MinimumSizeFilter.Height.onEndEdit.AddListener(_ => Populate());
|
||||
MaximumSizeFilter.Width.onEndEdit.AddListener(_ => Populate());
|
||||
MaximumSizeFilter.Height.onEndEdit.AddListener(_ => Populate());
|
||||
NewFilterButton.onClick.AddListener(() =>
|
||||
{
|
||||
ContextMenu.Clear();
|
||||
IEnumerable<HardpointType> hardpointTypes = (HardpointType[]) Enum.GetValues(typeof(HardpointType));
|
||||
if (_hardpointFilter.filter != null)
|
||||
hardpointTypes = hardpointTypes.Where(x => x != _hardpointFilter.type);
|
||||
|
||||
IEnumerable<SimpleCommodityCategory> commodityTypes = (SimpleCommodityCategory[]) Enum.GetValues(typeof(SimpleCommodityCategory));
|
||||
if (_commodityFilter.filter != null)
|
||||
commodityTypes = commodityTypes.Where(x => x != _commodityFilter.type);
|
||||
|
||||
IEnumerable<CompoundCommodityCategory> compoundCommodityTypes = (CompoundCommodityCategory[]) Enum.GetValues(typeof(CompoundCommodityCategory));
|
||||
if (_compoundCommodityFilter.filter != null)
|
||||
compoundCommodityTypes = compoundCommodityTypes.Where(x => x != _compoundCommodityFilter.type);
|
||||
|
||||
ContextMenu.AddDropdown("Gear Type", hardpointTypes
|
||||
.Select<HardpointType, (string, Action, bool)>(x => (Enum.GetName(typeof(HardpointType), x), () =>
|
||||
{
|
||||
if (_hardpointFilter.filter == null)
|
||||
{
|
||||
_hardpointFilter.filter = FilterPrototype.Instantiate<ItemFilter>();
|
||||
_hardpointFilter.filter.OnDisable += () =>
|
||||
{
|
||||
_hardpointFilter.filter = null;
|
||||
Populate();
|
||||
};
|
||||
}
|
||||
if(_commodityFilter.filter != null)
|
||||
{
|
||||
_commodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_commodityFilter.filter = null;
|
||||
}
|
||||
if(_compoundCommodityFilter.filter != null)
|
||||
{
|
||||
_compoundCommodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_compoundCommodityFilter.filter = null;
|
||||
}
|
||||
|
||||
_hardpointFilter.filter.Label.text = $"Hardpoint: {Enum.GetName(typeof(HardpointType), x)}";
|
||||
_hardpointFilter.type = x;
|
||||
Populate();
|
||||
}, true)));
|
||||
ContextMenu.AddDropdown("Simple Commodity", commodityTypes
|
||||
.Select<SimpleCommodityCategory, (string, Action, bool)>(x => (Enum.GetName(typeof(SimpleCommodityCategory), x), () =>
|
||||
{
|
||||
if (_commodityFilter.filter == null)
|
||||
{
|
||||
_commodityFilter.filter = FilterPrototype.Instantiate<ItemFilter>();
|
||||
_commodityFilter.filter.OnDisable += () =>
|
||||
{
|
||||
_commodityFilter.filter = null;
|
||||
Populate();
|
||||
};
|
||||
}
|
||||
if(_hardpointFilter.filter != null)
|
||||
{
|
||||
_hardpointFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_hardpointFilter.filter = null;
|
||||
}
|
||||
if(_compoundCommodityFilter.filter != null)
|
||||
{
|
||||
_compoundCommodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_compoundCommodityFilter.filter = null;
|
||||
}
|
||||
|
||||
_commodityFilter.filter.Label.text = $"Hardpoint: {Enum.GetName(typeof(SimpleCommodityCategory), x)}";
|
||||
_commodityFilter.type = x;
|
||||
Populate();
|
||||
}, true)));
|
||||
ContextMenu.AddDropdown("Compound Commodity", compoundCommodityTypes
|
||||
.Select<CompoundCommodityCategory, (string, Action, bool)>(x => (Enum.GetName(typeof(CompoundCommodityCategory), x), () =>
|
||||
{
|
||||
if (_compoundCommodityFilter.filter == null)
|
||||
{
|
||||
_compoundCommodityFilter.filter = FilterPrototype.Instantiate<ItemFilter>();
|
||||
_compoundCommodityFilter.filter.OnDisable += () =>
|
||||
{
|
||||
_compoundCommodityFilter.filter = null;
|
||||
Populate();
|
||||
};
|
||||
}
|
||||
if(_hardpointFilter.filter != null)
|
||||
{
|
||||
_hardpointFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_hardpointFilter.filter = null;
|
||||
}
|
||||
if(_commodityFilter.filter != null)
|
||||
{
|
||||
_commodityFilter.filter.GetComponent<Prototype>().ReturnToPool();
|
||||
_commodityFilter.filter = null;
|
||||
}
|
||||
|
||||
_compoundCommodityFilter.filter.Label.text = $"Hardpoint: {Enum.GetName(typeof(CompoundCommodityCategory), x)}";
|
||||
_compoundCommodityFilter.type = x;
|
||||
Populate();
|
||||
}, true)));
|
||||
ContextMenu.AddDropdown("Item Behavior", typeof(BehaviorData).GetAllChildClasses()
|
||||
.Where(x=> x.GetCustomAttribute<RuntimeInspectable>() != null && _behaviorFilters.All(f => f.type != x))
|
||||
.Select<Type, (string, Action, bool)>(x=> (x.Name.FormatTypeName(), () =>
|
||||
{
|
||||
var matchingType = _behaviorFilters.FirstOrDefault(y => y.type.IsAssignableFrom(x) || x.IsAssignableFrom(y.type));
|
||||
if (matchingType.filter != null) matchingType.filter.DisableButton.onClick.Invoke();
|
||||
var filter = FilterPrototype.Instantiate<ItemFilter>();
|
||||
filter.Label.text = x.Name.FormatTypeName();
|
||||
filter.OnDisable += () =>
|
||||
{
|
||||
_behaviorFilters.Remove((filter, x));
|
||||
Populate();
|
||||
};
|
||||
_behaviorFilters.Add((filter, x));
|
||||
Populate();
|
||||
}, true)));
|
||||
if(!MinimumSizeFilter.gameObject.activeSelf)
|
||||
ContextMenu.AddOption("Minimum Size",
|
||||
() =>
|
||||
{
|
||||
MinimumSizeFilter.gameObject.SetActive(true);
|
||||
MinimumSizeFilter.OnDisable += () => Populate();
|
||||
});
|
||||
if(!MaximumSizeFilter.gameObject.activeSelf)
|
||||
ContextMenu.AddOption("Maximum Size",
|
||||
() =>
|
||||
{
|
||||
MaximumSizeFilter.gameObject.SetActive(true);
|
||||
MaximumSizeFilter.OnDisable += () => Populate();
|
||||
});
|
||||
ContextMenu.Show();
|
||||
});
|
||||
Populate();
|
||||
}
|
||||
|
||||
void Populate()
|
||||
{
|
||||
var columns = new List<(string name, int size, Func<ItemData, Func<string>> output, Func<ItemData, IComparable> sortKey)>();
|
||||
|
||||
columns.Add(("Name", 3,
|
||||
data => () => data.Name,
|
||||
data => data.Name));
|
||||
if(_hardpointFilter.filter==null)
|
||||
columns.Add(("Type", 2,
|
||||
data => () =>
|
||||
{
|
||||
if (data is SimpleCommodityData s) return Enum.GetName(typeof(SimpleCommodityCategory), s.Category);
|
||||
if(data is CompoundCommodityData c) return Enum.GetName(typeof(CompoundCommodityCategory), c.Category);
|
||||
if(data is EquippableItemData e) return Enum.GetName(typeof(HardpointType), e.HardpointType);
|
||||
return "None";
|
||||
},
|
||||
data =>
|
||||
{
|
||||
if (data is SimpleCommodityData s) return (int) s.Category;
|
||||
var offset = Enum.GetValues(typeof(SimpleCommodityCategory)).Length;
|
||||
if(data is CompoundCommodityData c) return (int) c.Category + offset;
|
||||
offset += Enum.GetValues(typeof(CompoundCommodityCategory)).Length;
|
||||
if(data is EquippableItemData e) return (int) e.HardpointType + offset;
|
||||
return 0;
|
||||
}));
|
||||
columns.Add(("Mass", 1,
|
||||
data => () => ActionGameManager.PlayerSettings.Format(data.Mass),
|
||||
data => data.Mass));
|
||||
columns.Add(("Price", 1,
|
||||
data => () => data.Price.ToString("N0"),
|
||||
data => data.Price));
|
||||
columns.Add(("Size", 1,
|
||||
data => () => $"{data.Shape.Width}x{data.Shape.Height}",
|
||||
data => data.Shape.Width*data.Shape.Height));
|
||||
|
||||
var items = GameManager.ItemManager.ItemData.GetAll<ItemData>().Where(i=>i.Price!=0);
|
||||
|
||||
if (MinimumSizeFilter.gameObject.activeSelf)
|
||||
items = items.Where(i =>
|
||||
!(MinimumSizeFilter.Width.text.Length > 0 && i.Shape.Width < int.Parse(MinimumSizeFilter.Width.text) ||
|
||||
MinimumSizeFilter.Height.text.Length > 0 && i.Shape.Height < int.Parse(MinimumSizeFilter.Height.text)));
|
||||
|
||||
if (MaximumSizeFilter.gameObject.activeSelf)
|
||||
items = items.Where(i =>
|
||||
!(MaximumSizeFilter.Width.text.Length > 0 && i.Shape.Width > int.Parse(MaximumSizeFilter.Width.text) ||
|
||||
MaximumSizeFilter.Height.text.Length > 0 && i.Shape.Height > int.Parse(MaximumSizeFilter.Height.text)));
|
||||
|
||||
if(_commodityFilter.filter != null)
|
||||
items = items.Where(i => i is SimpleCommodityData s && s.Category == _commodityFilter.type);
|
||||
|
||||
if(_compoundCommodityFilter.filter != null)
|
||||
items = items.Where(i => i is CompoundCommodityData c && c.Category == _compoundCommodityFilter.type);
|
||||
|
||||
if (_hardpointFilter.filter != null)
|
||||
items = items.Where(i => i is EquippableItemData e && e.HardpointType == _hardpointFilter.type);
|
||||
|
||||
foreach (var (_, type) in _behaviorFilters)
|
||||
{
|
||||
items = items.Where(i => i is EquippableItemData e && e.Behaviors.Any(b => type.IsInstanceOfType(b)));
|
||||
|
||||
foreach (var field in type.GetFields().Where(f => f.GetCustomAttribute<RuntimeInspectable>() != null))
|
||||
{
|
||||
var fieldType = field.FieldType;
|
||||
if (fieldType == typeof(float))
|
||||
columns.Add((field.Name, 1, data =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return () => ActionGameManager.PlayerSettings.Format((float) field.GetValue(behavior));
|
||||
}, data =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return (float) field.GetValue(behavior);
|
||||
}));
|
||||
else if (fieldType == typeof(int))
|
||||
columns.Add((field.Name, 1, data =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return () => ((int) field.GetValue(behavior)).ToString();
|
||||
}, data =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return (int) field.GetValue(behavior);
|
||||
}));
|
||||
else if (fieldType == typeof(PerformanceStat))
|
||||
{
|
||||
columns.Add((field.Name, 1, data =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return () => ActionGameManager.PlayerSettings.Format(((PerformanceStat) field.GetValue(behavior)).Max);
|
||||
}, data =>
|
||||
{
|
||||
var behavior = ((EquippableItemData) data).Behaviors.FirstOrDefault(b => type.IsInstanceOfType(b));
|
||||
return ((PerformanceStat) field.GetValue(behavior)).Max;
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
columns.Add(("Owned", 1,
|
||||
data => () =>
|
||||
{
|
||||
if (data is HullData)
|
||||
return GameManager.DockedEntity.Children.Count(s => s.Hull.Data.LinkID == data.ID && s is Ship {IsPlayerShip: true}).ToString();
|
||||
if(data is SimpleCommodityData)
|
||||
return (_targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Cast<SimpleCommodity>().Sum(s=>s.Quantity) : 0).ToString();
|
||||
return (_targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Count : 0).ToString();
|
||||
},
|
||||
data =>
|
||||
{
|
||||
if (data is HullData)
|
||||
return GameManager.DockedEntity.Children.Count(s => s.Hull.Data.LinkID == data.ID && s is Ship {IsPlayerShip: true});
|
||||
if(data is SimpleCommodityData)
|
||||
return _targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Cast<SimpleCommodity>().Sum(s=>s.Quantity) : 0;
|
||||
return _targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Count : 0;
|
||||
}));
|
||||
|
||||
Spreadsheet.ShowData(
|
||||
columns.Select(x => x.name).ToArray(),
|
||||
columns.Select(x => x.size).ToArray(),
|
||||
items.Select(i => new SpreadsheetEntryRow
|
||||
{
|
||||
Columns = columns.Select(x => new SpreadsheetEntryColumn
|
||||
{
|
||||
Output = x.output(i),
|
||||
SortKey = x.sortKey(i)
|
||||
}).ToArray(),
|
||||
OnClick = () =>
|
||||
{
|
||||
Properties.Inspect(i);
|
||||
},
|
||||
OnDoubleClick = () =>
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case HullData h:
|
||||
Buy(h);
|
||||
break;
|
||||
case CraftedItemData c:
|
||||
Buy(c,1);
|
||||
break;
|
||||
case SimpleCommodityData s:
|
||||
Buy(s, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
Populate();
|
||||
},
|
||||
OnRightClick = () =>
|
||||
{
|
||||
if (!(i is HullData))
|
||||
{
|
||||
ContextMenu.Clear();
|
||||
ContextMenu.AddOption("Buy Quantity",
|
||||
() =>
|
||||
{
|
||||
int quantity = 1;
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = $"Buying {i.Name}";
|
||||
Dialog.AddField("Quantity", () => quantity, q => quantity = min(q, GameManager.Credits/i.Price));
|
||||
Dialog.Show(() =>
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case CraftedItemData c:
|
||||
Buy(c,quantity);
|
||||
break;
|
||||
case SimpleCommodityData s:
|
||||
Buy(s, quantity);
|
||||
break;
|
||||
}
|
||||
|
||||
Populate();
|
||||
});
|
||||
Dialog.MoveToCursor();
|
||||
});
|
||||
ContextMenu.Show();
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void Buy(HullData data)
|
||||
{
|
||||
if (data.Price < GameManager.Credits)
|
||||
{
|
||||
var hull = GameManager.ItemManager.CreateInstance(data) as EquippableItem;
|
||||
Entity entity;
|
||||
if(data.HullType==HullType.Ship)
|
||||
entity = new Ship(GameManager.ItemManager, GameManager.Zone, hull, GameManager.Settings.GameplaySettings.DefaultEntitySettings) {IsPlayerShip = true};
|
||||
else entity = new OrbitalEntity(GameManager.ItemManager, GameManager.Zone, hull, Guid.Empty, GameManager.Settings.GameplaySettings.DefaultEntitySettings);
|
||||
entity.SetParent(GameManager.DockedEntity);
|
||||
|
||||
GameManager.Credits -= data.Price;
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to buy: Insufficient Credits!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
}
|
||||
}
|
||||
|
||||
private void Buy(CraftedItemData data, int quantity)
|
||||
{
|
||||
for (int i = 0; i < quantity; i++)
|
||||
{
|
||||
if (data.Price < GameManager.Credits)
|
||||
{
|
||||
if (_targetCargo.TryStore(GameManager.ItemManager.CreateInstance(data)))
|
||||
{
|
||||
GameManager.Credits -= data.Price;
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to buy: Insufficient Cargo Space!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to buy: Insufficient Credits!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Buy(SimpleCommodityData data, int quantity)
|
||||
{
|
||||
// Up-rounded integer division from https://stackoverflow.com/a/503201
|
||||
int lots = (quantity - 1) / data.MaxStack + 1;
|
||||
int remaining = quantity;
|
||||
for (int i = 0; i < lots; i++)
|
||||
{
|
||||
int q = min(remaining, data.MaxStack);
|
||||
if (q * data.Price < GameManager.Credits)
|
||||
{
|
||||
if (_targetCargo.TryStore(GameManager.ItemManager.CreateInstance(data, q)))
|
||||
{
|
||||
GameManager.Credits -= q * data.Price;
|
||||
remaining -= q;
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to buy: Insufficient Cargo Space!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Unable to buy: Insufficient Credits!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
FoldoutButton.onClick.AddListener(() =>
|
||||
{
|
||||
ContextMenu.Clear();
|
||||
if(_targetCargo != GameManager.DockingBay)
|
||||
ContextMenu.AddOption("Docking Bay",
|
||||
() =>
|
||||
{
|
||||
_targetCargo = GameManager.DockingBay;
|
||||
TargetCargoLabel.text = "Docking Bay";
|
||||
});
|
||||
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}";
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/UI/Menu/TradeMenuDebug.cs.meta
Normal file
3
Assets/Scripts/UI/Menu/TradeMenuDebug.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6eed32eb39c04a31b81e8a55685b222c
|
||||
timeCreated: 1616191013
|
||||
65
Assets/Scripts/UI/Menu/WeaponGroupAssignment.cs
Normal file
65
Assets/Scripts/UI/Menu/WeaponGroupAssignment.cs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class WeaponGroupAssignment : MonoBehaviour
|
||||
{
|
||||
public RectTransform Container;
|
||||
public WeaponGroupElement GroupPrefab;
|
||||
public Color ActiveColor;
|
||||
public Color InactiveColor;
|
||||
|
||||
Subject<(PointerEventData pointerEventData, int group)> _onBeginDrag;
|
||||
Subject<(PointerEventData pointerEventData, int group)> _onDrag;
|
||||
Subject<(PointerEventData pointerEventData, int group)> _onEndDrag;
|
||||
|
||||
public List<WeaponGroupElement> Groups { get; } = new List<WeaponGroupElement>();
|
||||
|
||||
public void Inspect(EquippedItem item)
|
||||
{
|
||||
var weapon = item.GetBehavior<Weapon>();
|
||||
if (weapon == null) throw new ArgumentException($"Attempted to inspect weapon groups on item \"{item.Data.Name}\" but no weapon is present!");
|
||||
var groupCount = ActionGameManager.Instance.Settings.GameplaySettings.WeaponGroupCount;
|
||||
for (int i = 0; i < groupCount; i++)
|
||||
{
|
||||
var i1 = i;
|
||||
bool groupContainsItem() => item.Entity.WeaponGroups[i1].items.Contains(item);
|
||||
var group = Instantiate(GroupPrefab, Container);
|
||||
Groups.Add(group);
|
||||
group.Label.text = $"G{i+1}";
|
||||
group.Label.color = groupContainsItem() ? ActiveColor : InactiveColor;
|
||||
group.Button.onClick.AddListener(() =>
|
||||
{
|
||||
if (groupContainsItem())
|
||||
{
|
||||
item.Entity.WeaponGroups[i1].items.Remove(item);
|
||||
item.Entity.WeaponGroups[i1].weapons.Remove(weapon);
|
||||
group.Label.color = InactiveColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Entity.WeaponGroups[i1].items.Add(item);
|
||||
item.Entity.WeaponGroups[i1].weapons.Add(weapon);
|
||||
group.Label.color = ActiveColor;
|
||||
}
|
||||
});
|
||||
|
||||
group.BeginDragTrigger.OnBeginDragAsObservable()
|
||||
.Subscribe(data => _onBeginDrag?.OnNext((data, i1)));
|
||||
group.DragTrigger.OnDragAsObservable()
|
||||
.Subscribe(data => _onDrag?.OnNext((data, i1)));
|
||||
group.EndDragTrigger.OnEndDragAsObservable()
|
||||
.Subscribe(data => _onEndDrag?.OnNext((data, i1)));
|
||||
}
|
||||
}
|
||||
|
||||
public UniRx.IObservable<(PointerEventData pointerEventData, int group)> OnBeginDragAsObservable() =>
|
||||
_onBeginDrag ?? (_onBeginDrag = new Subject<(PointerEventData pointerEventData, int group)>());
|
||||
public UniRx.IObservable<(PointerEventData pointerEventData, int group)> OnDragAsObservable() =>
|
||||
_onDrag ?? (_onDrag = new Subject<(PointerEventData pointerEventData, int group)>());
|
||||
public UniRx.IObservable<(PointerEventData pointerEventData, int group)> OnEndDragAsObservable() =>
|
||||
_onEndDrag ?? (_onEndDrag = new Subject<(PointerEventData pointerEventData, int group)>());
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/WeaponGroupAssignment.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/WeaponGroupAssignment.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b9b213fc96d20d848819b8159412680c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/UI/Menu/WeaponGroupElement.cs
Normal file
15
Assets/Scripts/UI/Menu/WeaponGroupElement.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UniRx.Triggers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class WeaponGroupElement : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public Button Button;
|
||||
public ObservableBeginDragTrigger BeginDragTrigger;
|
||||
public ObservableDragTrigger DragTrigger;
|
||||
public ObservableEndDragTrigger EndDragTrigger;
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu/WeaponGroupElement.cs.meta
Normal file
11
Assets/Scripts/UI/Menu/WeaponGroupElement.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 27f5673ad060b834489cad765159cb84
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue