Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

DeckBuilder

a guest Mar 28th, 2016 2 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. //using UnityEditor;
  6. using System.Text;
  7. using System.Xml;
  8. using UnityEngine.UI;
  9. using System.IO;
  10.  
  11. public class DeckBuilder : MonoBehaviour {
  12.     public GameObject DeckGrid; //hold images that represent Decks
  13.     public GameObject DeckPrefab;
  14.     public CardInformationScreen cardInfo;
  15.     public InventoryScript inventory;
  16.     public InputField txtDeckName;
  17.     public DebugManager debugManager;
  18.  
  19.     private List<GameObject> DeckObjects = new List<GameObject>();
  20.     private static OnUIDeckClick _selectedDeck = null;
  21.     private DeckManager _deckManager;
  22.     public Button btnRemove;
  23.     public Toggle tgglBattleDeck;
  24.     // Use this for initialization
  25.     void Start ()
  26.     {
  27.         _deckManager = DeckManager.GetInstance();
  28.         RefreshDeckList();
  29.         btnRemove.gameObject.SetActive(false);
  30.         tgglBattleDeck.gameObject.SetActive(false);
  31.     }
  32.  
  33.     public bool HasDeckSelected
  34.     {
  35.         get
  36.         {
  37.             if (_selectedDeck == null)
  38.                 return false;
  39.             return true;
  40.         }
  41.     }
  42.  
  43.     public static OnUIDeckClick SelectedDeck
  44.     {
  45.         get { return _selectedDeck; }
  46.         private set { _selectedDeck = value; }
  47.     }
  48.  
  49.     // Update is called once per frame
  50.     public void RemoveDeck()
  51.     {
  52.         if (_deckManager.Decks.Count <= 1)
  53.             debugManager.Show("You need atleast one deck!");
  54.         if (SelectedDeck != null && _deckManager.Decks.Count > 1)
  55.         {
  56.            
  57.             if (SelectedDeck.Deck != _deckManager.BattleDeck)
  58.             {
  59.                 _deckManager.Decks.Remove(SelectedDeck.Deck);
  60.                 inventory.ResetFilteredList();
  61.                 RefreshDeckList();
  62.                 btnRemove.gameObject.SetActive(false);
  63.                 tgglBattleDeck.gameObject.SetActive(false);
  64.                 txtDeckName.text = "";
  65.             }
  66.             else
  67.             {
  68.                 debugManager.Show("You can't remove the battle deck!");
  69.             }
  70.         }
  71.     }
  72.  
  73.     public void RefreshDeckList()
  74.     {
  75.  
  76.         DeckObjects.Clear();
  77.         foreach (Transform child in DeckGrid.transform)
  78.         {
  79.             Destroy(child.gameObject);
  80.         }
  81.  
  82.         //use the filteredList to create new children in elementGrid
  83.         for (int i = 0; i < _deckManager.Decks.Count; ++i)
  84.         {
  85.             var spawn = Instantiate(DeckPrefab);
  86.             spawn.transform.SetParent(DeckGrid.transform);
  87.             spawn.GetComponent<OnUIDeckClick>().Init(_deckManager.Decks[i]);
  88.             DeckObjects.Add(spawn);
  89.         }
  90.     }
  91.  
  92.     private PlayerDeck NewDeck(string name)
  93.     {
  94.         PlayerDeck d = new PlayerDeck(name);
  95.         _deckManager.Decks.Add(d);
  96.  
  97.         //refresh DeckList;
  98.         RefreshDeckList();
  99.         return d;
  100.     }
  101.     public void NewEmptyDeck()
  102.     {
  103.         PlayerDeck d = new PlayerDeck("a new deck");
  104.         _deckManager.Decks.Add(d);
  105.  
  106.         //refresh DeckList;
  107.         RefreshDeckList();
  108.     }
  109.  
  110.     public void EnableAllDecks()
  111.     {
  112.         //loop through all decks and check is the card can be added
  113.         foreach (var d in DeckObjects)
  114.         {
  115.             //deck halen uit
  116.             PlayerDeck deck = d.GetComponent<OnUIDeckClick>().Deck;
  117.             //terug licht maken
  118.             d.GetComponentInChildren<Image>().color = new Color(1.0f, 1.0f, 1.0f);
  119.             //d.GetComponent<Image>().color = new Color(1.0f, 1.0f, 1.0f);
  120.             d.GetComponent<CanvasGroup>().blocksRaycasts = true;
  121.         }
  122.     }
  123.  
  124.     public void CheckAllDecksIfCanAdd(Card c)
  125.     {
  126.         //loop through all decks and check is the card can be added
  127.         foreach (var d in DeckObjects)
  128.         {
  129.             //deck halen uit
  130.             PlayerDeck deck = d.GetComponent<OnUIDeckClick>().Deck;
  131.             //Debug.Log(!_deckManager.CanAdd(c, deck) + ", " + _deckManager.IsDeckFull(deck) + ", " + _deckManager.AlreadyInDeck(c, deck));
  132.             if (!_deckManager.CanAdd(c, deck) || _deckManager.IsDeckFull(deck) || _deckManager.AlreadyInDeck(c, deck))
  133.             {
  134.                 //donker maken
  135.                 d.GetComponentInChildren<Image>().color = new Color(0.2f, 0.2f, 0.2f);
  136.                 //d.GetComponent<Image>().color = new Color(0.2f, 0.2f, 0.2f);
  137.                 d.GetComponent<CanvasGroup>().blocksRaycasts = false;
  138.             }
  139.         }
  140.     }
  141.  
  142.     public void SaveDecks()
  143.     {
  144.         //save decks
  145.         if (!Application.isWebPlayer && !Application.isEditor && !Application.isMobilePlatform)
  146.         {
  147.             _deckManager.SaveDecks();
  148.             //save invetory
  149.             inventory.SaveInventory();
  150.         }
  151.  
  152.     }
  153.  
  154.     public void SelectDeck(OnUIDeckClick d)
  155.     {
  156.         if(SelectedDeck != null)
  157.         {
  158.             btnRemove.gameObject.SetActive(false);
  159.             tgglBattleDeck.gameObject.SetActive(false);
  160.             SelectedDeck.selected.SetActive(false);
  161.         }
  162.         SelectedDeck = d;
  163.         if (SelectedDeck != null)
  164.         {
  165.             btnRemove.gameObject.SetActive(true);
  166.             SelectedDeck.selected.SetActive(true);
  167.             tgglBattleDeck.gameObject.SetActive(true);
  168.             if (SelectedDeck.Deck == _deckManager.BattleDeck)
  169.             {
  170.                 //toggle true
  171.                 tgglBattleDeck.isOn = true;
  172.             }
  173.             else
  174.             {
  175.                 //toggle false
  176.                 tgglBattleDeck.isOn = false;
  177.             }
  178.         }
  179.         else
  180.         {
  181.            tgglBattleDeck.isOn = false;
  182.         }
  183.  
  184.        
  185.  
  186.         //set the text
  187.         if (d != null)
  188.             txtDeckName.text = d.Deck.Name;
  189.         else
  190.             txtDeckName.text = "";
  191.        
  192.        
  193.     }
  194.  
  195.     public void ChangeName()
  196.     {
  197.         if(SelectedDeck == null)
  198.         {
  199.             txtDeckName.text = "";
  200.         }
  201.         else
  202.         {
  203.             SelectedDeck.Deck.Name = txtDeckName.text;
  204.         }
  205.     }
  206.  
  207.     public void SetBattleDeck()
  208.     {
  209.         if (SelectedDeck != null)
  210.         {
  211.             tgglBattleDeck.isOn = true;
  212.             _deckManager.BattleDeck = SelectedDeck.Deck;
  213.         }
  214.     }
  215. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top