mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
New paste functions plus keyframe drag select
This commit is contained in:
parent
3d2c11f469
commit
f449a9b4e2
117 changed files with 399 additions and 81 deletions
|
@ -4,18 +4,24 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class InputManager : Singleton<InputManager>
|
||||
{
|
||||
public Transform dialogBoxes;
|
||||
public GameObject keyframeSelector;
|
||||
|
||||
private float lastUpdate = -1f;
|
||||
private float timeBetweenUpdates = 0.15f;
|
||||
private float largeStep = 0.1f;
|
||||
private float smallStep = 0.03f;
|
||||
|
||||
private bool isDragging;
|
||||
private Vector2 v0;
|
||||
|
||||
public bool CanRepeatThisUpdate()
|
||||
{
|
||||
if (Time.unscaledTime > lastUpdate + timeBetweenUpdates)
|
||||
|
@ -55,6 +61,7 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
bool canRepeatThisUpdate = CanRepeatThisUpdate();
|
||||
|
||||
// Check keybinds
|
||||
foreach (Keybind keybind in KeybindConfig.Instance.GetAllKeybinds())
|
||||
{
|
||||
if (IsModifierKeyHeld() && keybind.keyModifiers.NullOrEmpty()) goto nextKeybind;
|
||||
|
@ -73,6 +80,89 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
nextKeybind:;
|
||||
}
|
||||
|
||||
// Drag selection
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{ StartKeyframeSelectionDrag(); }
|
||||
|
||||
else if (Input.GetMouseButtonUp(0))
|
||||
{ EndKeyframeSelectionDrag(); }
|
||||
|
||||
else if (isDragging)
|
||||
{ UpdateKeyframeSelector(); }
|
||||
|
||||
else
|
||||
{ HideKeyframeSelector(); }
|
||||
}
|
||||
|
||||
public void StartKeyframeSelectionDrag()
|
||||
{
|
||||
PointerEventData pointer = new PointerEventData(EventSystem.current);
|
||||
pointer.position = Input.mousePosition;
|
||||
|
||||
List<RaycastResult> raycastResults = new List<RaycastResult>();
|
||||
EventSystem.current.RaycastAll(pointer, raycastResults);
|
||||
|
||||
if (raycastResults.Count > 0)
|
||||
{
|
||||
foreach (var go in raycastResults)
|
||||
{
|
||||
//Debug.Log(go.gameObject);
|
||||
if (go.gameObject?.GetComponent<Button>() != null) return;
|
||||
if (go.gameObject?.GetComponent<IDragHandler>() != null) return;
|
||||
if (go.gameObject?.GetComponentInParent<IDragHandler>() != null) return;
|
||||
}
|
||||
}
|
||||
|
||||
v0 = (Vector2)Input.mousePosition;
|
||||
isDragging = true;
|
||||
}
|
||||
|
||||
public void EndKeyframeSelectionDrag()
|
||||
{
|
||||
if (isDragging == false) return;
|
||||
isDragging = false;
|
||||
|
||||
Vector2 v1 = (Vector2)Input.mousePosition;
|
||||
List<int> keyframeIDs = new List<int>();
|
||||
IEnumerable<KeyframeSlider> sliders = Selectable.allSelectablesArray.Select(x => x.GetComponent<KeyframeSlider>());
|
||||
|
||||
foreach (KeyframeSlider slider in sliders)
|
||||
{
|
||||
Transform handle = slider?.transform?.FindDeepChild("Handle");
|
||||
if (handle == null) continue;
|
||||
|
||||
Vector2 vi = (Vector2)handle.GetComponent<RectTransform>().position;
|
||||
|
||||
if (vi.x < Mathf.Min(v0.x, v1.x)) continue;
|
||||
if (vi.x > Mathf.Max(v0.x, v1.x)) continue;
|
||||
if (vi.y < Mathf.Min(v0.y, v1.y)) continue;
|
||||
if (vi.y > Mathf.Max(v0.y, v1.y)) continue;
|
||||
|
||||
keyframeIDs.Add(slider.keyframeID);
|
||||
}
|
||||
|
||||
if (keyframeIDs.NotNullOrEmpty())
|
||||
{ Workspace.keyframeID = keyframeIDs; }
|
||||
}
|
||||
|
||||
public void UpdateKeyframeSelector()
|
||||
{
|
||||
Vector2 v1 = (Vector2)Input.mousePosition;
|
||||
Vector2 pos = new Vector2(Mathf.Min(v0.x, v1.x), Mathf.Min(v0.y, v1.y));
|
||||
Vector2 dim = new Vector2(Mathf.Abs(v1.x - v0.x), Mathf.Abs(v1.y - v0.y));
|
||||
|
||||
keyframeSelector.GetComponent<RectTransform>().anchoredPosition = pos;
|
||||
keyframeSelector.GetComponent<RectTransform>().sizeDelta = dim;
|
||||
|
||||
if (keyframeSelector.activeSelf == false)
|
||||
{ keyframeSelector.SetActive(true); }
|
||||
}
|
||||
|
||||
public void HideKeyframeSelector()
|
||||
{
|
||||
if (keyframeSelector.activeSelf)
|
||||
{ keyframeSelector.SetActive(false); }
|
||||
}
|
||||
|
||||
public void QuitApplication()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue