mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 08:17:38 +02:00
Buggy timeline object resizing
This commit is contained in:
@ -20,7 +20,7 @@ namespace RhythmHeavenMania.Editor
|
||||
private RectTransform eventsParent;
|
||||
|
||||
[Header("Properties")]
|
||||
private EventCaller.MiniGame mg;
|
||||
private Minigames.Minigame mg;
|
||||
private bool gameOpen;
|
||||
[SerializeField] private int currentEventIndex;
|
||||
private int dragTimes;
|
||||
|
@ -21,6 +21,7 @@ namespace RhythmHeavenMania.Editor
|
||||
private bool lastFrameDrag;
|
||||
public int LayerCount = 4;
|
||||
public bool metronomeEnabled;
|
||||
public bool resizable;
|
||||
|
||||
[Header("Timeline Components")]
|
||||
[SerializeField] private RectTransform TimelineSlider;
|
||||
@ -305,13 +306,28 @@ namespace RhythmHeavenMania.Editor
|
||||
else
|
||||
eventObj.Icon.sprite = Editor.GameIcon(eventName.Split(0));
|
||||
|
||||
EventCaller.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(eventName.Split(0)), eventName.Split(1));
|
||||
Minigames.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(eventName.Split(0)), eventName.Split(1));
|
||||
|
||||
if (gameAction != null)
|
||||
{
|
||||
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, LayerHeight());
|
||||
float length = gameAction.defaultLength;
|
||||
eventObj.length = length;
|
||||
if (gameAction.resizable == false)
|
||||
{
|
||||
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, LayerHeight());
|
||||
float length = gameAction.defaultLength;
|
||||
eventObj.length = length;
|
||||
}
|
||||
else
|
||||
{
|
||||
eventObj.resizable = true;
|
||||
if (gameAction.defaultLength != GameManager.instance.Beatmap.entities[entityId].length)
|
||||
{
|
||||
g.GetComponent<RectTransform>().sizeDelta = new Vector2(GameManager.instance.Beatmap.entities[entityId].length, LayerHeight());
|
||||
}
|
||||
else
|
||||
{
|
||||
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, LayerHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.SetActive(true);
|
||||
@ -335,7 +351,6 @@ namespace RhythmHeavenMania.Editor
|
||||
else
|
||||
{
|
||||
var entity = GameManager.instance.Beatmap.entities[entityId];
|
||||
var e = GameManager.instance.Beatmap.entities[entityId];
|
||||
|
||||
entity.eventObj = g.GetComponent<TimelineEventObj>();
|
||||
entity.track = (int)(g.transform.localPosition.y / LayerHeight() * -1);
|
||||
@ -361,7 +376,7 @@ namespace RhythmHeavenMania.Editor
|
||||
|
||||
public bool IsEventsDragging()
|
||||
{
|
||||
return Timeline.instance.eventObjs.FindAll(c => c.isDragging == true).Count > 0;
|
||||
return eventObjs.FindAll(c => c.isDragging == true).Count > 0 || eventObjs.FindAll(c => c.resizing == true).Count > 0;
|
||||
}
|
||||
|
||||
public float SnapToLayer(float y)
|
||||
|
@ -15,6 +15,7 @@ namespace RhythmHeavenMania.Editor
|
||||
public bool isDragging;
|
||||
|
||||
private Vector3 lastPos;
|
||||
private RectTransform rectTransform;
|
||||
|
||||
[Header("Components")]
|
||||
[SerializeField] private RectTransform PosPreview;
|
||||
@ -28,15 +29,28 @@ namespace RhythmHeavenMania.Editor
|
||||
private bool lastVisible;
|
||||
public bool selected;
|
||||
public bool mouseHovering;
|
||||
public bool resizable;
|
||||
public bool resizing;
|
||||
|
||||
[Header("Colors")]
|
||||
public Color NormalCol;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
|
||||
if (!resizable)
|
||||
{
|
||||
Destroy(transform.GetChild(5).gameObject);
|
||||
Destroy(transform.GetChild(6).gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
entity = GameManager.instance.Beatmap.entities.Find(a => a.eventObj == this);
|
||||
|
||||
mouseHovering = RectTransformUtility.RectangleContainsScreenPoint(GetComponent<RectTransform>(), Input.mousePosition, Camera.main);
|
||||
mouseHovering = RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Camera.main);
|
||||
|
||||
#region Optimizations
|
||||
|
||||
@ -67,7 +81,25 @@ namespace RhythmHeavenMania.Editor
|
||||
transform.GetChild(3).gameObject.SetActive(true);
|
||||
|
||||
for (int i = 0; i < transform.GetChild(4).childCount; i++)
|
||||
{
|
||||
transform.GetChild(4).GetChild(i).GetComponent<Image>().color = Color.cyan;
|
||||
}
|
||||
|
||||
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
||||
Vector3[] v = new Vector3[4];
|
||||
rectTransform.GetWorldCorners(v);
|
||||
|
||||
if (mouseHovering)
|
||||
{
|
||||
if (mousePos.x > transform.position.x && mousePos.x < transform.position.x + 0.1f)
|
||||
{
|
||||
}
|
||||
else if (mousePos.x > v[3].x - 0.1f && mousePos.x < v[3].x)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -83,50 +115,143 @@ namespace RhythmHeavenMania.Editor
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (Input.GetMouseButtonDown(0) && Timeline.instance.IsMouseAboveEvents())
|
||||
if (!resizing)
|
||||
{
|
||||
if (selected)
|
||||
if (Input.GetMouseButtonDown(0) && Timeline.instance.IsMouseAboveEvents())
|
||||
{
|
||||
if (selected)
|
||||
{
|
||||
Vector3 mousePos;
|
||||
mousePos = Input.mousePosition;
|
||||
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
|
||||
startPosX = mousePos.x - this.transform.position.x;
|
||||
startPosY = mousePos.y - this.transform.position.y;
|
||||
|
||||
isDragging = true;
|
||||
}
|
||||
}
|
||||
else if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
if (!mouseHovering && !isDragging && !BoxSelection.instance.selecting)
|
||||
{
|
||||
if (!Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
Selections.instance.Deselect(this);
|
||||
}
|
||||
}
|
||||
|
||||
OnUp();
|
||||
}
|
||||
if (isDragging && selected)
|
||||
{
|
||||
Vector3 mousePos;
|
||||
mousePos = Input.mousePosition;
|
||||
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
|
||||
startPosX = mousePos.x - this.transform.position.x;
|
||||
startPosY = mousePos.y - this.transform.position.y;
|
||||
|
||||
isDragging = true;
|
||||
this.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
|
||||
this.transform.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(this.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(this.transform.localPosition.y));
|
||||
|
||||
if (lastPos != transform.localPosition)
|
||||
OnMove();
|
||||
|
||||
lastPos = this.transform.localPosition;
|
||||
}
|
||||
}
|
||||
else if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
if (!mouseHovering && !isDragging && !BoxSelection.instance.selecting)
|
||||
{
|
||||
if (!Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
Selections.instance.Deselect(this);
|
||||
}
|
||||
}
|
||||
|
||||
OnUp();
|
||||
}
|
||||
|
||||
if (isDragging && selected)
|
||||
{
|
||||
Vector3 mousePos;
|
||||
mousePos = Input.mousePosition;
|
||||
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
|
||||
|
||||
this.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
|
||||
this.transform.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(this.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(this.transform.localPosition.y));
|
||||
|
||||
if (lastPos != transform.localPosition)
|
||||
OnMove();
|
||||
|
||||
lastPos = this.transform.localPosition;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region ResizeEvents
|
||||
|
||||
public void DragEnter()
|
||||
{
|
||||
if (selected)
|
||||
Cursor.SetCursor(Resources.Load<Texture2D>("Cursors/horizontal_resize"), new Vector2(8, 8), CursorMode.Auto);
|
||||
}
|
||||
|
||||
public void DragExit()
|
||||
{
|
||||
if (!resizing)
|
||||
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
||||
}
|
||||
|
||||
public void OnLeftDown()
|
||||
{
|
||||
if (selected)
|
||||
{
|
||||
SetPivot(new Vector2(1, rectTransform.pivot.y));
|
||||
resizing = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void DragLeft()
|
||||
{
|
||||
if (!resizing) return;
|
||||
|
||||
Vector2 sizeDelta = rectTransform.sizeDelta;
|
||||
|
||||
Vector2 mousePos;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Camera.main, out mousePos);
|
||||
|
||||
sizeDelta = new Vector2(-mousePos.x + 0.1f, sizeDelta.y);
|
||||
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, 0.25f, rectTransform.localPosition.x), sizeDelta.y);
|
||||
|
||||
rectTransform.sizeDelta = new Vector2(Mathp.Round2Nearest(sizeDelta.x, 0.25f), sizeDelta.y);
|
||||
}
|
||||
|
||||
public void OnLeftUp()
|
||||
{
|
||||
SetPivot(new Vector2(0, rectTransform.pivot.y));
|
||||
resizing = false;
|
||||
OnComplete();
|
||||
}
|
||||
|
||||
public void OnRightDown()
|
||||
{
|
||||
if (selected)
|
||||
{
|
||||
SetPivot(new Vector2(0, rectTransform.pivot.y));
|
||||
resizing = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void DragRight()
|
||||
{
|
||||
if (!resizing) return;
|
||||
// if (!mouseHovering) return;
|
||||
|
||||
Vector2 sizeDelta = rectTransform.sizeDelta;
|
||||
|
||||
Vector2 mousePos;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Camera.main, out mousePos);
|
||||
|
||||
sizeDelta = new Vector2(mousePos.x, sizeDelta.y);
|
||||
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, 0.25f, Mathf.Infinity), sizeDelta.y);
|
||||
|
||||
rectTransform.sizeDelta = new Vector2(Mathp.Round2Nearest(sizeDelta.x, 0.25f), sizeDelta.y);
|
||||
}
|
||||
|
||||
public void OnRightUp()
|
||||
{
|
||||
resizing = false;
|
||||
|
||||
OnComplete();
|
||||
}
|
||||
|
||||
private void SetPivot(Vector2 pivot)
|
||||
{
|
||||
if (rectTransform == null) return;
|
||||
|
||||
Vector2 size = rectTransform.rect.size;
|
||||
Vector2 deltaPivot = rectTransform.pivot - pivot;
|
||||
Vector3 deltaPosition = new Vector3(deltaPivot.x * size.x, deltaPivot.y * size.y);
|
||||
rectTransform.pivot = pivot;
|
||||
rectTransform.localPosition -= deltaPosition;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnEvents
|
||||
|
||||
private void OnMove()
|
||||
{
|
||||
if (GameManager.instance.Beatmap.entities.FindAll(c => c.beat == this.transform.localPosition.x && c.track == GetTrack()).Count > 0)
|
||||
@ -141,11 +266,14 @@ namespace RhythmHeavenMania.Editor
|
||||
|
||||
private void OnComplete()
|
||||
{
|
||||
entity.length = rectTransform.sizeDelta.x;
|
||||
entity.beat = this.transform.localPosition.x;
|
||||
GameManager.instance.SortEventsList();
|
||||
entity.track = GetTrack();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ClickEvents
|
||||
|
||||
public void OnDown()
|
||||
|
Reference in New Issue
Block a user