|
@@ -6,36 +6,71 @@ using UnityEngine.UI;
|
|
|
|
|
|
|
|
public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
|
|
public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
|
|
|
|
|
|
|
|
- public Vector3 startPosition;
|
|
|
|
|
public Transform parent = null;
|
|
public Transform parent = null;
|
|
|
public Transform placeholderParent = null;
|
|
public Transform placeholderParent = null;
|
|
|
- GameObject placeholder = null;
|
|
|
|
|
|
|
+ public GameObject placeholder = null;
|
|
|
|
|
|
|
|
public void OnDrag(PointerEventData eventData) {
|
|
public void OnDrag(PointerEventData eventData) {
|
|
|
|
|
+ if (!eventData.pointerDrag.gameObject.name.Contains("NewQuestion")) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
this.transform.position = eventData.position;
|
|
this.transform.position = eventData.position;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (placeholder.transform.parent != placeholderParent) {
|
|
if (placeholder.transform.parent != placeholderParent) {
|
|
|
placeholder.transform.SetParent(placeholderParent);
|
|
placeholder.transform.SetParent(placeholderParent);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int newSiblingIndex = placeholderParent.childCount;
|
|
int newSiblingIndex = placeholderParent.childCount;
|
|
|
-
|
|
|
|
|
for (int i = 0; i < placeholderParent.childCount; i++) {
|
|
for (int i = 0; i < placeholderParent.childCount; i++) {
|
|
|
- if (this.transform.position.x < placeholderParent.GetChild(i).transform.position.x) {
|
|
|
|
|
|
|
+ if (this.transform.position.x < placeholderParent.GetChild(i).position.x) {
|
|
|
newSiblingIndex = i;
|
|
newSiblingIndex = i;
|
|
|
- if (parent.transform.GetSiblingIndex() < newSiblingIndex) {
|
|
|
|
|
|
|
+ if (placeholder.transform.GetSiblingIndex() < newSiblingIndex) {
|
|
|
newSiblingIndex--;
|
|
newSiblingIndex--;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- placeholderParent.transform.SetSiblingIndex(newSiblingIndex);
|
|
|
|
|
|
|
+ if (placeholderParent.gameObject.name.Contains("AnswerLine")) {
|
|
|
|
|
+ int cardBefore = newSiblingIndex - 1;
|
|
|
|
|
+ int cardAfter = newSiblingIndex + 1;
|
|
|
|
|
+
|
|
|
|
|
+ if (placeholder.transform.GetSiblingIndex() == cardAfter) {
|
|
|
|
|
+ cardAfter++;
|
|
|
|
|
+ }
|
|
|
|
|
+ QuestionCard questionCardBefore = null;
|
|
|
|
|
+ QuestionCard questionCardAfter = null;
|
|
|
|
|
+ string answerTextBefore = "";
|
|
|
|
|
+ string answerTextAfter = "";
|
|
|
|
|
+ if (cardBefore < 0) {
|
|
|
|
|
+ answerTextBefore = "Before";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ questionCardBefore = placeholderParent.GetChild(cardBefore).GetComponent<QuestionCard>();
|
|
|
|
|
+ if (questionCardBefore == null) {
|
|
|
|
|
+ questionCardBefore = placeholderParent.GetChild(cardBefore - 1).GetComponent<QuestionCard>();
|
|
|
|
|
+ }
|
|
|
|
|
+ answerTextBefore = questionCardBefore.GetAnswerText().text;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (cardAfter >= placeholderParent.childCount) {
|
|
|
|
|
+ answerTextAfter = "After";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ questionCardAfter = placeholderParent.GetChild(cardAfter).GetComponent<QuestionCard>();
|
|
|
|
|
+ answerTextAfter += questionCardAfter.GetAnswerText().text;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (answerTextAfter.Equals("After")) {
|
|
|
|
|
+ this.GetComponent<NewQuestion>().GetAnswerText().text = answerTextAfter + " " + answerTextBefore;
|
|
|
|
|
+ } else if (answerTextBefore.Equals("Before")) {
|
|
|
|
|
+ this.GetComponent<NewQuestion>().GetAnswerText().text = answerTextBefore + " " + answerTextAfter;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.GetComponent<NewQuestion>().GetAnswerText().text = answerTextBefore + " - " + answerTextAfter;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ placeholder.transform.SetSiblingIndex(newSiblingIndex);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void OnBeginDrag(PointerEventData eventData) {
|
|
public void OnBeginDrag(PointerEventData eventData) {
|
|
|
- startPosition = this.transform.position;
|
|
|
|
|
-
|
|
|
|
|
placeholder = new GameObject();
|
|
placeholder = new GameObject();
|
|
|
placeholder.transform.SetParent(this.transform.parent);
|
|
placeholder.transform.SetParent(this.transform.parent);
|
|
|
LayoutElement le = placeholder.AddComponent<LayoutElement>();
|
|
LayoutElement le = placeholder.AddComponent<LayoutElement>();
|
|
@@ -50,18 +85,18 @@ public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDra
|
|
|
|
|
|
|
|
parent = this.transform.parent;
|
|
parent = this.transform.parent;
|
|
|
placeholderParent = parent;
|
|
placeholderParent = parent;
|
|
|
|
|
+ this.transform.SetParent(this.transform.parent);
|
|
|
|
|
+
|
|
|
GetComponent<CanvasGroup>().blocksRaycasts = false;
|
|
GetComponent<CanvasGroup>().blocksRaycasts = false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void OnEndDrag(PointerEventData eventData) {
|
|
public void OnEndDrag(PointerEventData eventData) {
|
|
|
- if (parent == null) {
|
|
|
|
|
- this.transform.position = startPosition;
|
|
|
|
|
- this.transform.SetSiblingIndex(placeholder.transform.GetSiblingIndex());
|
|
|
|
|
- } else {
|
|
|
|
|
- this.transform.SetParent(parent);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.transform.SetParent(parent);
|
|
|
|
|
+ this.transform.SetSiblingIndex(placeholder.transform.GetSiblingIndex());
|
|
|
GetComponent<CanvasGroup>().blocksRaycasts = true;
|
|
GetComponent<CanvasGroup>().blocksRaycasts = true;
|
|
|
|
|
|
|
|
Destroy(placeholder);
|
|
Destroy(placeholder);
|
|
|
|
|
+ //Destroy(this);
|
|
|
|
|
+ // Show Modal and get yes/no confirm on placement, create new QuestionCard at newSiblingIndex.
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|