Action Bar Weapon Group Binding
Selecting a weapon now displays weapon group toggles Added global drag and drop handling in game manager Weapon group toggles can be dragged to action bar to bind them
This commit is contained in:
parent
4489b18452
commit
9779afb1bb
24 changed files with 1213 additions and 27 deletions
|
|
@ -36,7 +36,10 @@ public class PropertiesPanel : MonoBehaviour
|
|||
public IncrementField IncrementField;
|
||||
public StatSheet StatSheet;
|
||||
public CurveField CurveField;
|
||||
public WeaponGroupAssignment WeaponGroupAssignment;
|
||||
public RectTransform Content;
|
||||
public RectTransform DragParent;
|
||||
|
||||
[HideInInspector] public FlatFlatButton SelectedChild;
|
||||
[HideInInspector] public ActionGameManager GameManager;
|
||||
|
||||
|
|
@ -45,6 +48,9 @@ public class PropertiesPanel : MonoBehaviour
|
|||
protected event Action RefreshPropertyValues;
|
||||
protected bool RadioSelection = false;
|
||||
|
||||
private RectTransform _dragObject;
|
||||
|
||||
|
||||
protected event Action<GameObject> OnPropertyAdded;
|
||||
protected Action OnPropertiesChanged;
|
||||
|
||||
|
|
@ -462,6 +468,33 @@ public class PropertiesPanel : MonoBehaviour
|
|||
|
||||
AddItemProperties(item.EquippableItem);
|
||||
AddSpacer();
|
||||
|
||||
if (item.GetBehavior<Weapon>() != null)
|
||||
{
|
||||
var weaponGroups = Instantiate(WeaponGroupAssignment, Content ?? transform);
|
||||
weaponGroups.Inspect(item);
|
||||
var dragOffset = Vector2.zero;
|
||||
Transform dragObject = null;
|
||||
weaponGroups.OnBeginDragAsObservable().Subscribe(x =>
|
||||
{
|
||||
//Debug.Log($"Began dragging weapon group {x.group}");
|
||||
GameManager.BeginDrag(new WeaponGroupDragAction(x.group));
|
||||
dragObject = Instantiate(weaponGroups.Groups[x.group], DragParent, true).transform;
|
||||
dragOffset = (Vector2)dragObject.position - x.pointerEventData.position;
|
||||
});
|
||||
weaponGroups.OnDragAsObservable().Subscribe(x =>
|
||||
{
|
||||
dragObject.position = x.pointerEventData.position + dragOffset;
|
||||
});
|
||||
weaponGroups.OnEndDragAsObservable().Subscribe(x =>
|
||||
{
|
||||
//Debug.Log($"Ended dragging weapon group {x.group}");
|
||||
GameManager.EndDrag();
|
||||
Destroy(dragObject.gameObject);
|
||||
});
|
||||
Properties.Add(weaponGroups.gameObject);
|
||||
OnPropertyAdded?.Invoke(weaponGroups.gameObject);
|
||||
}
|
||||
|
||||
var gearData = GameManager.ItemManager.GetData(item.EquippableItem);
|
||||
var statusSheet = AddStatSheet();
|
||||
|
|
|
|||
65
Assets/Scripts/UI/WeaponGroupAssignment.cs
Normal file
65
Assets/Scripts/UI/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.TriggerGroupCount;
|
||||
for (int i = 0; i < groupCount; i++)
|
||||
{
|
||||
var i1 = i;
|
||||
bool groupContainsItem() => item.Entity.TriggerGroups[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.TriggerGroups[i1].items.Remove(item);
|
||||
item.Entity.TriggerGroups[i1].weapons.Remove(weapon);
|
||||
group.Label.color = InactiveColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Entity.TriggerGroups[i1].items.Add(item);
|
||||
item.Entity.TriggerGroups[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/WeaponGroupAssignment.cs.meta
Normal file
11
Assets/Scripts/UI/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/WeaponGroupElement.cs
Normal file
15
Assets/Scripts/UI/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/WeaponGroupElement.cs.meta
Normal file
11
Assets/Scripts/UI/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