Drag and Drop + Zoooooooom

Refactored inventory drag & drop to use new global drag & drop management
Enabled Drag & Drop from inventory panel to action bar
Enabled gear and consumable item binding
Fixed stat modifier behavior to allow it to be toggled
Fixed Switch behavior to make it bindable
Added lambda multiplier to aether drive so that stat mod can target it
This commit is contained in:
Reinier Vens 2021-04-21 01:49:07 +01:00
commit 7cfc5cd04f
21 changed files with 352 additions and 323 deletions

View file

@ -79,213 +79,6 @@ public class InventoryMenu : MonoBehaviour
PropertiesPanel.GameManager = GameManager;
foreach (var panel in InventoryPanels)
{
panel.OnBeginDragAsObservable().Subscribe(data =>
{
//Debug.Log($"Begin drag on panel {panel.name}");
if (data is InventoryCargoEventData cargoEvent)
{
var item = cargoEvent.CargoBay.Occupancy[cargoEvent.Position.x, cargoEvent.Position.y];
if (item != null)
{
var itemData = item.Data.Value;
var itemPosition = cargoEvent.CargoBay.Cargo[item];
_originalOccupancy = cargoEvent.CargoBay.Data.InteriorShape.Inset(itemData.Shape, itemPosition, item.Rotation);
_originalRotation = item.Rotation;
_originalPanel = panel;
_dragItem = item;
_dragCellOffset = itemPosition - cargoEvent.Position;
_dragCells = _originalOccupancy.Coordinates
.Select(v => Instantiate(panel.CellInstances[v], DragParent, true).transform).ToArray();
foreach(var cell in _dragCells)
{
foreach (var component in cell.GetComponentsInChildren<ObservableTriggerBase>())
component.enabled = false;
cell.GetComponentInChildren<Image>().raycastTarget = false;
}
_dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray();
panel.IgnoreOccupancy = _originalOccupancy;
panel.RefreshCells(_originalOccupancy.Expand().Coordinates);
AkSoundEngine.PostEvent("Pickup", gameObject);
}
}
else if (data is InventoryEntityEventData entityEvent)
{
if(!entityEvent.Entity.Active)
{
var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y];
if (item != null)
{
var itemData = GameManager.ItemManager.GetData(item.EquippableItem);
var hullData = GameManager.ItemManager.GetData(entityEvent.Entity.Hull);
_originalRotation = item.EquippableItem.Rotation;
_originalEquippedItem = entityEvent.Entity.GearOccupancy[data.Position.x, data.Position.y];
_originalOccupancy = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation);
_originalPanel = panel;
_dragItem = item.EquippableItem;
_dragCellOffset = item.Position - entityEvent.Position;
_dragCells = _originalOccupancy.Coordinates
.Select(v => Instantiate(panel.CellInstances[v], DragParent, true).transform).ToArray();
foreach (var cell in _dragCells)
{
foreach (var component in cell.GetComponentsInChildren<ObservableTriggerBase>())
component.enabled = false;
cell.GetComponentInChildren<Image>().raycastTarget = false;
}
_dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray();
panel.IgnoreOccupancy = _originalOccupancy;
panel.RefreshCells(_originalOccupancy.Expand().Coordinates);
AkSoundEngine.PostEvent("Pickup", gameObject);
}
}
}
});
panel.OnDragAsObservable().Subscribe(data =>
{
if (_dragItem == null) return;
for (var i = 0; i < _dragCells.Length; i++)
_dragCells[i].position = new Vector3(
data.PointerEventData.position.x + _dragOffsets[i].x,
data.PointerEventData.position.y + _dragOffsets[i].y,
_dragCells[i].position.z);
});
panel.OnEndDragAsObservable().Subscribe(data =>
{
if (_dragItem == null) return;
if (_dragTargetValid)
{
if (data is InventoryCargoEventData cargoEvent)
{
cargoEvent.CargoBay.Remove(_dragItem);
_dragTargetPanel.DropItem(_dragItem, _dragTargetPosition);
if(_dragTargetPanel.Target == InventoryPanelTarget.Cargo)
AkSoundEngine.PostEvent("Drop", gameObject);
else
AkSoundEngine.PostEvent("Equip", gameObject);
}
else if (data is InventoryEntityEventData entityEvent)
{
if (entityEvent.Entity.TryUnequip(_originalEquippedItem) != null)
{
_dragTargetPanel.DropItem(_dragItem, _dragTargetPosition);
AkSoundEngine.PostEvent("Unequip", gameObject);
}
else
{
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();
}
}
_dragTargetPanel.FakeOccupancy = null;
}
else
{
_dragItem.Rotation = _originalRotation;
}
if (_destroyItem)
{
if (data is InventoryCargoEventData cargoEvent)
{
cargoEvent.CargoBay.Remove(_dragItem);
}
else if (data is InventoryEntityEventData entityEvent)
{
if (entityEvent.Entity.TryUnequip(_originalEquippedItem) == null)
{
Dialog.Clear();
Dialog.Title.text = "Unable to destroy item!";
Dialog.AddProperty("Verify that cargo bays are empty before un-equipping them.");
Dialog.Show();
Dialog.MoveToCursor();
}
}
}
panel.IgnoreOccupancy = null;
panel.RefreshCells();
if(_dragTargetPanel!=panel && _dragTargetPanel != null)
_dragTargetPanel.RefreshCells();
_dragItem = null;
foreach (var cell in _dragCells) Destroy(cell.gameObject);
});
Action floatCells = () =>
{
foreach (var cell in _dragCells) cell.gameObject.SetActive(true);
_dragTargetValid = false;
};
panel.OnPointerEnterAsObservable().Subscribe(data =>
{
if (_dragItem == null) return;
// Debug.Log($"Pointer entered {data.Position}");
// if(panel != _originalPanel)
// _originalPanel.RefreshCells();
_dragTargetPanel = panel;
_lastDragPosition = data.Position;
_dragTargetPosition = data.Position + _dragCellOffset;
if (data is InventoryCargoEventData cargoEvent)
{
if (cargoEvent.CargoBay.ItemFits(_dragItem, _dragTargetPosition))
{
foreach (var cell in _dragCells) cell.gameObject.SetActive(false);
var itemData = _dragItem.Data.Value;
panel.FakeItem = _dragItem;
panel.FakeOccupancy = cargoEvent.CargoBay.Data.InteriorShape.Inset(itemData.Shape, _dragTargetPosition, _dragItem.Rotation);
_dragTargetValid = true;
panel.RefreshCells();
}
}
else if (data is InventoryEntityEventData entityEvent)
{
var eqItem = _dragItem as EquippableItem;
var hullData = GameManager.ItemManager.GetData(entityEvent.Entity.Hull);
if (eqItem != null && entityEvent.Entity.ItemFits(eqItem, _dragTargetPosition))
{
foreach (var cell in _dragCells) cell.gameObject.SetActive(false);
var itemData = _dragItem.Data.Value;
panel.FakeEquipment = _originalEquippedItem;
panel.FakeOccupancy = hullData.Shape.Inset(itemData.Shape, _dragTargetPosition, _dragItem.Rotation);
_dragTargetValid = true;
panel.RefreshCells();
}
}
});
panel.OnPointerExitAsObservable().Subscribe(data =>
{
if (_dragItem == null) return;
if (data.Position.Equals(_lastDragPosition) || !_dragTargetValid)
{
panel.FakeItem = null;
panel.FakeOccupancy = null;
panel.RefreshCells();
// if (_originalPanel != panel)
// {
// _originalPanel.FakeItem = null;
// _originalPanel.FakeOccupancy = null;
// _originalPanel.RefreshCells();
// }
floatCells();
}
});
panel.OnClickAsObservable().Subscribe(e =>
{
if (e.data is InventoryCargoEventData cargoEvent)