Drag n drop begun

This commit is contained in:
Braedon
2022-01-10 19:17:29 -05:00
parent 00e3791e6d
commit f8a8180061
12 changed files with 823 additions and 47 deletions

View File

@ -6,10 +6,12 @@ namespace RhythmHeavenMania.Common
{
public class FollowMouse : MonoBehaviour
{
public Vector2 offset;
private void Update()
{
var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = new Vector3(pos.x, pos.y, 0);
transform.position = new Vector3(pos.x - offset.x, pos.y - offset.y, 0);
}
}
}

View File

@ -150,5 +150,10 @@ namespace RhythmHeavenMania
else
return false;
}
public bool NotStopped()
{
return Conductor.instance.isPlaying == true || Conductor.instance.isPaused;
}
}
}

View File

@ -34,13 +34,15 @@ namespace RhythmHeavenMania
public class MiniGame
{
public string name;
public string displayName;
public string color;
public GameObject holder;
public List<GameAction> actions = new List<GameAction>();
public MiniGame(string name, string color, List<GameAction> actions)
public MiniGame(string name, string displayName, string color, List<GameAction> actions)
{
this.name = name;
this.displayName = displayName;
this.color = color;
this.actions = actions;
}
@ -79,12 +81,12 @@ namespace RhythmHeavenMania
instance = this;
minigames = new List<MiniGame>()
{
new MiniGame("gameManager", "", new List<GameAction>()
new MiniGame("gameManager", "Game Manager", "", new List<GameAction>()
{
new GameAction("end", delegate { Debug.Log("end"); }),
new GameAction("switchGame", delegate { GameManager.instance.SwitchGame(currentSwitchGame); })
}),
new MiniGame("forkLifter", "FFFFFF", new List<GameAction>()
new MiniGame("forkLifter", "Fork Lifter", "FFFFFF", new List<GameAction>()
{
new GameAction("pea", delegate { ForkLifter.instance.Flick(currentBeat, 0); }, 3, true),
new GameAction("topbun", delegate { ForkLifter.instance.Flick(currentBeat, 1); }, 3, true),
@ -94,14 +96,14 @@ namespace RhythmHeavenMania
new GameAction("gulp", delegate { ForkLifterPlayer.instance.Eat(); }),
new GameAction("sigh", delegate { Jukebox.PlayOneShot("sigh"); })
}),
new MiniGame("clappyTrio", "29E7FF", new List<GameAction>()
new MiniGame("clappyTrio", "The Clappy Trio", "29E7FF", new List<GameAction>()
{
new GameAction("clap", delegate { ClappyTrio.instance.Clap(currentBeat, currentLength); }, 3, true),
new GameAction("bop", delegate { ClappyTrio.instance.Bop(currentBeat); } ),
new GameAction("prepare", delegate { ClappyTrio.instance.Prepare(0); } ),
new GameAction("prepare_alt", delegate { ClappyTrio.instance.Prepare(3); } ),
}),
new MiniGame("spaceball", "00A518", new List<GameAction>()
new MiniGame("spaceball", "Spaceball", "00A518", new List<GameAction>()
{
new GameAction("shoot", delegate { Spaceball.instance.Shoot(currentBeat, false, currentType); }, 2, true),
new GameAction("shootHigh", delegate { Spaceball.instance.Shoot(currentBeat, true, currentType); }, 3, true),
@ -109,7 +111,7 @@ namespace RhythmHeavenMania
new GameAction("alien", delegate { Spaceball.instance.alien.Show(currentBeat); } ),
new GameAction("cameraZoom", delegate { } ),
}),
new MiniGame("karateman", "70A8D8", new List<GameAction>()
new MiniGame("karateman", "Karate Man", "70A8D8", new List<GameAction>()
{
new GameAction("bop", delegate { KarateMan.instance.Bop(currentBeat, currentLength); }, 0.5f, true, true),
new GameAction("pot", delegate { KarateMan.instance.Shoot(currentBeat, 0); }, 2, true),

View File

@ -43,7 +43,7 @@ namespace RhythmHeavenMania.Editor
GameObject GameIcon_ = Instantiate(GridGameSelector.GetChild(0).gameObject, GridGameSelector);
GameIcon_.GetComponent<Image>().sprite = GameIcon(EventCaller.instance.minigames[i].name);
GameIcon_.gameObject.SetActive(true);
GameIcon_.name = "GameIcon";
GameIcon_.name = EventCaller.instance.minigames[i].displayName;
}
}

View File

@ -1,20 +1,117 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace RhythmHeavenMania.Editor
{
public class GridGameSelector : MonoBehaviour
{
public GameObject GameTitlePreview;
public string SelectedMinigame;
public void OnEnter()
[Header("Components")]
public GameObject GameEventSelector;
public GameObject EventRef;
[Header("Properties")]
private EventCaller.MiniGame mg;
private bool gameOpen;
[SerializeField] private int currentEventIndex;
private int dragTimes;
private void Update()
{
GameTitlePreview.GetComponent<Image>().enabled = true;
if (gameOpen)
{
if (Input.GetKeyDown(KeyCode.DownArrow))
{
UpdateIndex(1);
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
{
UpdateIndex(-1);
}
}
}
public void OnExit()
#region Events
public void Drag()
{
GameTitlePreview.GetComponent<Image>().enabled = false;
if (Conductor.instance.NotStopped()) return;
if (Timeline.instance.CheckIfMouseInTimeline() && dragTimes < 1)
{
dragTimes++;
Timeline.instance.AddEventObject(mg.name + "/" + mg.actions[currentEventIndex].actionName, true);
}
}
public void Drop()
{
if (Conductor.instance.NotStopped()) return;
dragTimes = 0;
}
#endregion
#region Functions
public void UpdateIndex(int amount)
{
currentEventIndex += amount;
if (currentEventIndex < 0)
{
currentEventIndex = mg.actions.Count - 1;
}
else if (currentEventIndex > mg.actions.Count - 1)
{
currentEventIndex = 0;
}
SetColor(currentEventIndex);
}
public void SelectGame(string gameName)
{
DestroyEvents();
SelectedMinigame = gameName;
mg = EventCaller.instance.minigames.Find(c => c.displayName == gameName);
for (int i = 0; i < mg.actions.Count; i++)
{
GameObject e = Instantiate(EventRef, EventRef.transform.parent);
e.GetComponent<TMP_Text>().text = mg.actions[i].actionName;
e.SetActive(true);
}
gameOpen = true;
currentEventIndex = 0;
SetColor(0);
}
private void SetColor(int ind)
{
for (int i = 0; i < EventRef.transform.parent.childCount; i++) EventRef.transform.parent.GetChild(i).GetComponent<TMP_Text>().color = Color.white;
EventRef.transform.parent.GetChild(ind + 1).GetComponent<TMP_Text>().color = Color.cyan;
}
private void DestroyEvents()
{
for (int i = 1; i < EventRef.transform.parent.childCount; i++)
{
Destroy(EventRef.transform.parent.GetChild(i).gameObject);
}
gameOpen = false;
}
#endregion
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 0baf64619d1dc0749bfc3f9a4b8f7b47
guid: d9d826be8d1e71d4c971f5ed377ee873
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,30 @@
using UnityEngine;
using UnityEngine.UI;
namespace RhythmHeavenMania.Editor
{
public class GridGameSelectorGame : MonoBehaviour
{
public GameObject GameTitlePreview;
public GridGameSelector GridGameSelector;
public void OnClick()
{
GridGameSelector.SelectGame(this.gameObject.name);
}
public void OnEnter()
{
GameTitlePreview.GetComponent<Image>().enabled = true;
GameTitlePreview.transform.GetChild(0).GetComponent<TMPro.TMP_Text>().text = this.gameObject.name;
GameTitlePreview.transform.GetChild(0).gameObject.SetActive(true);
}
public void OnExit()
{
GameTitlePreview.GetComponent<Image>().enabled = false;
GameTitlePreview.transform.GetChild(0).gameObject.SetActive(false);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0baf64619d1dc0749bfc3f9a4b8f7b47
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -26,11 +26,14 @@ namespace RhythmHeavenMania.Editor
[SerializeField] private RectTransform TimelineEventObjRef;
private RectTransform TimelineSongPosLine;
public static Timeline instance { get; private set; }
#region Initializers
public void Init()
{
instance = this;
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
{
var entity = GameManager.instance.Beatmap.entities[i];
@ -178,6 +181,52 @@ namespace RhythmHeavenMania.Editor
int milliseconds = (int)(1000 * (time - minutes * 60 - seconds));
return string.Format("{0:00}:{1:00}:{2:000}", minutes, seconds, milliseconds);
}
public bool CheckIfMouseInTimeline()
{
return (this.gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(TimelineContent.transform.parent.gameObject.GetComponent<RectTransform>(), Input.mousePosition, Camera.main));
}
#endregion
#region Functions
public void AddEventObject(string eventName, bool dragNDrop = false)
{
GameObject g = Instantiate(TimelineEventObjRef.gameObject, TimelineEventObjRef.parent);
g.transform.localPosition = new Vector3(0, 0);
g.transform.GetChild(1).GetComponent<TMP_Text>().text = eventName.Split('/')[1];
TimelineEventObj eventObj = g.GetComponent<TimelineEventObj>();
eventObj.Icon.sprite = Editor.GameIcon(eventName.Split(0));
EventCaller.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, g.GetComponent<RectTransform>().sizeDelta.y);
float length = gameAction.defaultLength;
eventObj.length = length;
}
g.SetActive(true);
Beatmap.Entity entity = new Beatmap.Entity();
entity.datamodel = eventName;
entity.eventObj = eventObj;
GameManager.instance.Beatmap.entities.Add(entity);
GameManager.instance.SortEventsList();
g.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (dragNDrop)
{
eventObj.OnDown();
}
// entity.eventObj = g.GetComponent<TimelineEventObj>();
// entity.track = (int)(g.transform.localPosition.y / 51.34f * -1);
}
#endregion
}
}

View File

@ -12,7 +12,7 @@ namespace RhythmHeavenMania.Editor
{
private float startPosX;
private float startPosY;
private bool isDragging;
public bool isDragging;
private Vector3 lastPos;
@ -28,7 +28,7 @@ namespace RhythmHeavenMania.Editor
private void Update()
{
if (Conductor.instance.isPlaying == true || Conductor.instance.isPaused)
if (Conductor.instance.NotStopped())
{
Cancel();
return;
@ -42,26 +42,29 @@ namespace RhythmHeavenMania.Editor
mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
PosPreview.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
PosPreview.transform.localPosition = new Vector3(Mathp.Round2Nearest(PosPreview.transform.localPosition.x, 0.25f), Mathp.Round2Nearest(PosPreview.transform.localPosition.y, 51.34f));
this.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
this.transform.localPosition = new Vector3(Mathp.Round2Nearest(this.transform.localPosition.x, 0.25f), Mathp.Round2Nearest(this.transform.localPosition.y, 51.34f));
if (lastPos != transform.localPosition)
OnMove();
lastPos = PosPreview.transform.localPosition;
lastPos = this.transform.localPosition;
}
if (Input.GetMouseButtonUp(0))
OnUp();
}
private void OnMove()
{
if (GameManager.instance.Beatmap.entities.FindAll(c => c.beat == PosPreview.transform.localPosition.x && c.track == (int)(PosPreview.transform.localPosition.y / 51.34f * -1)).Count > 0)
if (GameManager.instance.Beatmap.entities.FindAll(c => c.beat == this.transform.localPosition.x && c.track == (int)(this.transform.localPosition.y / 51.34f * -1)).Count > 0)
{
PosPreview.GetComponent<Image>().color = Color.red;
// PosPreview.GetComponent<Image>().color = Color.red;
eligibleToMove = false;
}
else
{
PosPreview.GetComponent<Image>().color = Color.yellow;
// PosPreview.GetComponent<Image>().color = Color.yellow;
eligibleToMove = true;
}
}
@ -69,11 +72,11 @@ namespace RhythmHeavenMania.Editor
private void OnComplete()
{
var entity = GameManager.instance.Beatmap.entities[enemyIndex];
entity.beat = PosPreview.transform.localPosition.x;
entity.beat = this.transform.localPosition.x;
GameManager.instance.SortEventsList();
entity.track = (int)(PosPreview.transform.localPosition.y / 51.34f) * -1;
entity.track = (int)(this.transform.localPosition.y / 51.34f) * -1;
this.transform.localPosition = PosPreview.transform.localPosition;
// this.transform.localPosition = this.transform.localPosition;
// transform.DOLocalMove(PosPreview.transform.localPosition, 0.15f).SetEase(Ease.OutExpo);
}
@ -87,18 +90,17 @@ namespace RhythmHeavenMania.Editor
{
Vector3 mousePos;
PosPreview = Instantiate(PosPreviewRef, PosPreviewRef.transform.parent);
/*PosPreview = Instantiate(PosPreviewRef, PosPreviewRef.transform.parent);
PosPreview.sizeDelta = new Vector2(100 * transform.GetComponent<RectTransform>().sizeDelta.x, transform.GetComponent<RectTransform>().sizeDelta.y);
PosPreview.transform.localPosition = this.transform.localPosition;
PosPreview.GetComponent<Image>().enabled = true;
PosPreview.GetComponent<Image>().color = Color.yellow;
PosPreview.GetComponent<Image>().color = Color.yellow;*/
mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
startPosX = mousePos.x - PosPreview.transform.position.x;
startPosY = mousePos.y - PosPreview.transform.position.y;
startPosX = mousePos.x - this.transform.position.x;
startPosY = mousePos.y - this.transform.position.y;
isDragging = true;
}
public void OnUp()