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

Inventory

a guest Mar 28th, 2016 3 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.UI;
  5. using System.Linq;
  6. using System.Xml;
  7.  
  8. public class InventoryScript : MonoBehaviour {
  9.     private CardManager _cardManager;
  10.     public CardInformationScreen cardInfo;
  11.     private List<Card> _filteredCardsList = new List<Card>();
  12.     public GameObject ElementGrid;
  13.     public GameObject cardUIPrefab;
  14.     private bool _dragEnbaled = false;
  15.     private DeckBuilder _deckBuilder;
  16.     public Image filterImage;
  17.  
  18.     PlayerDeck DeckFilter = null;
  19.  
  20.     public bool DragEnabled
  21.     {
  22.         get { return _dragEnbaled; }
  23.         set { _dragEnbaled = value; }
  24.     }
  25.  
  26.     public List<Card> FilteredCardsList
  27.     {
  28.         get { return _filteredCardsList; }
  29.         private set { _filteredCardsList = value; }
  30.     }
  31.  
  32.  
  33.     // Use this for initialization
  34.     void Start ()
  35.     {
  36.         _cardManager = CardManager.GetInstance();
  37.         //AllOwnedCardList
  38.         //FilteredCardList
  39.         ResetFilteredList();
  40.         cardInfo.Hide();
  41.  
  42.         if (_deckBuilder == null)
  43.         {
  44.             _deckBuilder = GameObject.FindGameObjectWithTag("manager").GetComponent<DeckBuilder>();
  45.         }
  46.     }
  47.  
  48.     int TempIntCreate()
  49.     {
  50.         return Random.Range(1, 21);
  51.     }
  52.     void LoadPlayerInventory(TextAsset asset)
  53.     {
  54.         XmlDocument xDoc = new XmlDocument();
  55.         xDoc.LoadXml(asset.text);
  56.         XmlNode root = xDoc.DocumentElement;
  57.         XmlNodeList nodeList = root.SelectNodes("card");
  58.         foreach (XmlNode node in nodeList)
  59.         {
  60.             _cardManager.OwnedIDList.Add(int.Parse(node.InnerText));
  61.         }
  62.     }
  63.  
  64.    public void RefreshInventory()
  65.     {
  66.         OnUICardDragDrop.DestroyDraggedItem();
  67.         //delete all the children of elementGrid
  68.         foreach(Transform child in ElementGrid.transform)
  69.         {
  70.             Destroy(child.gameObject);
  71.         }
  72.  
  73.         //use the filteredList to create new children in elementGrid
  74.         for (int i = 0; i < FilteredCardsList.Count; ++i)
  75.         {
  76.             var spawn = Instantiate(cardUIPrefab);
  77.             spawn.transform.SetParent(ElementGrid.transform);
  78.             //spawn.GetComponent<RawImage>().texture = (Texture)Resources.Load(FilteredCardsList[i].Image);
  79.             spawn.name = FilteredCardsList[i].Name;
  80.             spawn.GetComponent<OnUICardClick>().Init(FilteredCardsList[i]);
  81.             //spawn.GetComponent<OnUICardDragDrop>().enabled = DragEnabled;
  82.         }
  83.     }
  84.  
  85.     public void SaveInventory()
  86.     {
  87.         _cardManager.SaveInventory();
  88.     }
  89.  
  90.     public void ResetFilteredList()
  91.     {
  92.         FilteredCardsList.Clear();
  93.         var cardList = _cardManager.AllOwnedCardsList.OrderBy(c => c.ElementID).ThenBy(c => c.Rarity).ThenBy(c => c.Name).ThenBy(c => c.Tier);
  94.         foreach (var card in cardList)
  95.         {
  96.             FilteredCardsList.Add(card);
  97.         }
  98.         //if(_deckBuilder)
  99.             //_deckBuilder.SelectDeck(null);
  100.         RefreshInventory();
  101.         SetFilterImage("images/Icon_Inventory");
  102.         DeckFilter = null;
  103.     }
  104.  
  105.     public void FilterAll()
  106.     {
  107.         FilteredCardsList.Clear();
  108.         var cardList = _cardManager.AllOwnedCardsList.OrderBy(c => c.ElementID).ThenBy(c => c.Rarity).ThenBy(c => c.Name).ThenBy(c => c.Tier);
  109.         if (DeckFilter != null)
  110.             cardList = DeckFilter.CardList.OrderBy(c => c.ElementID).ThenBy(c => c.Rarity).ThenBy(c => c.Name).ThenBy(c => c.Tier);
  111.         foreach (var card in cardList)
  112.         {
  113.             FilteredCardsList.Add(card);
  114.         }
  115.         //if(_deckBuilder)
  116.         //_deckBuilder.SelectDeck(null);
  117.         RefreshInventory();
  118.         SetFilterImage("images/Icon_Inventory");
  119.     }
  120.  
  121.     public void FilterDeck(PlayerDeck deck)
  122.     {
  123.         FilteredCardsList.Clear();
  124.         var cardList = deck.CardList.OrderBy(c => c.ElementID).ThenBy(c => c.Rarity).ThenBy(c => c.Name).ThenBy(c => c.Tier);
  125.  
  126.         foreach(var card in cardList)
  127.         {
  128.             FilteredCardsList.Add(card);
  129.         }
  130.  
  131.         RefreshInventory();
  132.         DeckFilter = deck;
  133.         SetFilterImage("images/Icon_Inventory");
  134.     }
  135.  
  136.     private void FilterElement(int element)
  137.     {
  138.         var sortingList = from card in _cardManager.AllOwnedCardsList where card.ElementID == element orderby card.ElementID, card.Rarity, card.Name, card.Tier descending  select card;
  139.         if (DeckFilter != null)
  140.             sortingList = from card in DeckFilter.CardList where card.ElementID == element orderby card.ElementID, card.Rarity, card.Name, card.Tier descending select card;
  141.         FilteredCardsList.Clear();
  142.         foreach(var node in sortingList)
  143.         {
  144.             FilteredCardsList.Add(node);
  145.         }
  146.  
  147.         RefreshInventory();
  148.  
  149.     }
  150.  
  151.     private void FilterRarity(int rarity)
  152.     {
  153.         var sortingList = from card in _cardManager.AllOwnedCardsList where card.Rarity == rarity orderby card.ElementID, card.Rarity, card.Name, card.Tier descending select card;
  154.         if (DeckFilter != null)
  155.             sortingList = from card in DeckFilter.CardList where card.Rarity == rarity orderby card.ElementID, card.Rarity, card.Name, card.Tier descending select card;
  156.         FilteredCardsList.Clear();
  157.         foreach (var node in sortingList)
  158.         {
  159.             FilteredCardsList.Add(node);
  160.         }
  161.  
  162.         RefreshInventory();
  163.  
  164.     }
  165.  
  166.     private void FilterTiers(int tier)
  167.     {
  168.         var sortingList = from card in _cardManager.AllOwnedCardsList where card.Tier == tier orderby card.ElementID, card.Rarity, card.Name, card.Tier descending select card;
  169.         if (DeckFilter != null)
  170.             sortingList = from card in DeckFilter.CardList where card.Tier == tier orderby card.ElementID, card.Rarity, card.Name, card.Tier descending select card;
  171.         FilteredCardsList.Clear();
  172.         foreach (var node in sortingList)
  173.         {
  174.             FilteredCardsList.Add(node);
  175.         }
  176.  
  177.         RefreshInventory();
  178.  
  179.     }
  180.  
  181.     private void SetFilterImage(string path)
  182.     {
  183.         filterImage.overrideSprite = Resources.Load<Sprite>(path);
  184.     }
  185.     public void FilterAir()
  186.     {
  187.         FilterElement((int)Element.Air);
  188.         SetFilterImage("images/Icon_Element_Air");
  189.     }
  190.  
  191.     public void FilterEarth()
  192.     {
  193.         FilterElement((int)Element.Earth);
  194.         SetFilterImage("images/Icon_Element_Earth");
  195.     }
  196.  
  197.     public void FilterSpirit()
  198.     {
  199.         FilterElement((int)Element.Spirit);
  200.         SetFilterImage("images/Icon_Element_Spirit");
  201.     }
  202.  
  203.     public void FilterWater()
  204.     {
  205.         FilterElement((int)Element.Water);
  206.         SetFilterImage("images/Icon_Element_Water");
  207.     }
  208.  
  209.     public void FilterFire()
  210.     {
  211.         FilterElement((int)Element.Fire);
  212.         SetFilterImage("images/Icon_Element_Fire");
  213.     }
  214.  
  215.     public void FilterVoid()
  216.     {
  217.         FilterElement((int)Element.Void);
  218.         SetFilterImage("images/Icon_Element_Void");
  219.     }
  220.  
  221.     public void FilterCommon()
  222.     {
  223.         FilterRarity((int)Rarity.Common);
  224.         SetFilterImage("images/Icon_Rarity_1");
  225.     }
  226.  
  227.     public void FilterRare()
  228.     {
  229.         FilterRarity((int)Rarity.Rare);
  230.         SetFilterImage("images/Icon_Rarity_2");
  231.     }
  232.  
  233.     public void FilterLegend()
  234.     {
  235.         FilterRarity((int)Rarity.Legendary);
  236.         SetFilterImage("images/Icon_Rarity_3");
  237.     }
  238.  
  239.     public void FilterTier1()
  240.     {
  241.         FilterTiers(1);
  242.         SetFilterImage("images/Icon_Tier_1");
  243.     }
  244.  
  245.     public void FilterTier2()
  246.     {
  247.         FilterTiers(2);
  248.         SetFilterImage("images/Icon_Tier_2");
  249.     }
  250.  
  251.     public void FilterTier3()
  252.     {
  253.         FilterTiers(3);
  254.         SetFilterImage("images/Icon_Tier_3");
  255.     }
  256. }
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