You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.7 KiB
141 lines
4.7 KiB
using System.Collections;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class Card : MonoBehaviour {//, IPointerEnterHandler, IPointerExitHandler{
|
|
public GameObject cardCanvas;
|
|
private GameObject cardPreview;
|
|
public static bool preparingCard = false;
|
|
public static GameObject cardBeingPrepared;
|
|
public bool preparedCard = false;
|
|
public static Vector3 preparingOffset = new Vector3(0f,40f);
|
|
public bool thrown = false;
|
|
private GameObject actionMenu;
|
|
private static GameObject thrownCards;
|
|
private static float yOffsetTable = 0.51f/2;
|
|
private MainMenuController mmc;
|
|
|
|
public string inPileName;
|
|
public bool isInCommonPile;
|
|
public int idx;
|
|
void Start() {
|
|
mmc = GameLoader.mmc;
|
|
cardPreview = GameObject.FindGameObjectsWithTag("CardPreview")[0];
|
|
thrownCards = GameObject.Find("ThrownCards");
|
|
actionMenu = transform.Find("ActionMenu").gameObject;
|
|
actionMenu.SetActive(false);
|
|
GetComponent<Button>().onClick.AddListener(OnClickCard);
|
|
}
|
|
|
|
public void InitData(string pileName, bool isCommonPile, int index) {
|
|
inPileName = pileName;
|
|
isInCommonPile = isCommonPile;
|
|
idx = index;
|
|
}
|
|
|
|
// Card Previewing Code
|
|
// public void OnPointerEnter(PointerEventData edata) {
|
|
// if(cardPreview && !cardBeingPrepared) {
|
|
// SetPreview();
|
|
// }
|
|
// }
|
|
|
|
//public void OnPointerExit(PointerEventData edata) {
|
|
// if(cardPreview && !cardBeingPrepared) {
|
|
// HidePreview();
|
|
// }
|
|
// }
|
|
public void OnClickCard() {
|
|
// var conn = Client.GetConnection();
|
|
// if (conn != null) {
|
|
// Debug.Log(conn.GetLobby());
|
|
// Debug.Log(conn.CreateLobby());
|
|
// }
|
|
if ((!preparingCard || cardBeingPrepared != gameObject) && !thrown) {
|
|
|
|
cardBeingPrepared = gameObject;
|
|
//SetPreview();
|
|
preparingCard = true;
|
|
} else {
|
|
var conn = Client.GetConnection();
|
|
if (conn != null) {
|
|
// conn.OnClickCard(inPileName, isInCommonPile, idx, mmc.currentUsername);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Update() {
|
|
if(cardBeingPrepared == gameObject && !thrown) {
|
|
if (!preparedCard) {
|
|
transform.position += preparingOffset;
|
|
preparedCard = true;
|
|
}
|
|
} else {
|
|
if (preparedCard) {
|
|
transform.position -= preparingOffset;
|
|
preparedCard = false;
|
|
}
|
|
}
|
|
actionMenu.SetActive(preparedCard);
|
|
}
|
|
|
|
private void SetPreview() {
|
|
cardPreview.GetComponentsInChildren<RawImage>()[0].enabled = true;
|
|
cardPreview.GetComponentsInChildren<RawImage>()[0].texture = gameObject.GetComponentsInChildren<RawImage>()[0].texture;
|
|
}
|
|
|
|
private void HidePreview() {
|
|
cardPreview.GetComponentsInChildren<RawImage>()[0].enabled = false;
|
|
}
|
|
|
|
public void ThrowCard() {
|
|
var canvas = Instantiate(cardCanvas, thrownCards.transform.position + new Vector3(0, yOffsetTable + thrownCards.transform.childCount*0.01f, -2.79f), transform.rotation);
|
|
canvas.GetComponent<Canvas>().worldCamera = Camera.main;
|
|
var newCard = Instantiate(gameObject, Vector3.zero, Quaternion.identity, canvas.transform);
|
|
newCard.transform.localScale = Vector3.one;
|
|
newCard.GetComponent<Card>().thrown = true;
|
|
newCard.GetComponent<Card>().inPileName = "placed";
|
|
newCard.GetComponent<Card>().idx = thrownCards.transform.childCount;
|
|
newCard.GetComponent<Card>().isInCommonPile = true;
|
|
canvas.transform.SetParent(thrownCards.transform);
|
|
canvas.transform.localScale = new Vector3(0.01f, 0.01f);
|
|
canvas.transform.Rotate(new Vector3(90f, 0f, 0f));
|
|
canvas.transform.Rotate(new Vector3(0f, 0f, Random.Range(-20, 20)));
|
|
Destroy(gameObject);
|
|
}
|
|
public void ThrowCard(GameObject pos) {
|
|
var canvas = Instantiate(cardCanvas, pos.transform.position+new Vector3(0, yOffsetTable + pos.transform.childCount * 0.01f, 0), transform.rotation);
|
|
canvas.GetComponent<Canvas>().worldCamera = Camera.main;
|
|
var newCard = Instantiate(gameObject, Vector3.zero, Quaternion.identity, canvas.transform);
|
|
newCard.transform.localScale = Vector3.one;
|
|
newCard.GetComponent<Card>().thrown = true;
|
|
newCard.GetComponent<Card>().inPileName = "placed";
|
|
newCard.GetComponent<Card>().idx = pos.transform.childCount;
|
|
newCard.GetComponent<Card>().isInCommonPile = true;
|
|
canvas.transform.SetParent(pos.transform);
|
|
canvas.tag = "ThrownCard";
|
|
canvas.transform.localScale = new Vector3(0.01f, 0.01f);
|
|
canvas.transform.Rotate(new Vector3(90f, 0f, 0f));
|
|
canvas.transform.Rotate(new Vector3(0f, 0f, Random.Range(-20, 20)));
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public void DoContextualAction() {
|
|
if (preparedCard) {
|
|
var conn = Client.GetConnection();
|
|
if (conn != null) {
|
|
// GameLoader.ReloadPiles(conn.OnClickCard(inPileName, isInCommonPile, idx, mmc.currentUsername));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CancelContextualAction() {
|
|
if (preparedCard) {
|
|
cardBeingPrepared = null;
|
|
}
|
|
}
|
|
}
|
|
|