Exemple #1
0
        private void Init()
        {
            // load all fists from Game State
            m_AllFists = new List <Fist>(Systems.GameState.Instance.AllFists);

            // get coins count from Game State
            m_CurrentCoins = Systems.GameState.Instance.CoinsCount;

            // load purchased fists and use them to set right values in m_AllFists
            m_PurchasedFists = new List <string>(Systems.GameState.Instance.PurchasedFists);

            // load selected fist
            m_SelectedFistName = Systems.GameState.Instance.SelectedFistName;

            foreach (Fist fist in m_AllFists)
            {
                // create fist item view by model
                Windows.FistItemView item = CreateFistItem(fist);
                m_Items.Add(item);

                // select current fist
                if (m_SelectedFistName == fist.m_Id)
                {
                    item.Select();
                }
            }

            // move More Content text to the end
            m_MoreContent.transform.SetAsLastSibling();

            UpdateCoinsCounter();
        }
Exemple #2
0
        private void OnBuyItemClick(Windows.FistItemView fistView)
        {
            if (m_CurrentCoins > fistView.m_Model.m_Price)
            {
                // spend coins
                m_CurrentCoins -= fistView.m_Model.m_Price;
                Systems.GameState.Instance.CoinsCount = m_CurrentCoins;
                UpdateCoinsCounter();

                // open new fist and save to Player Prefs
                fistView.m_Model.m_IsInInventory = true;
                m_PurchasedFists.Add(fistView.m_Model.m_Id);
                Systems.GameState.Instance.PurchasedFists = m_PurchasedFists.ToArray();
                PlayerPrefs.Save();

                fistView.Unlock();
            }
        }
Exemple #3
0
        private Windows.FistItemView CreateFistItem(Fist fistModel)
        {
            bool isPurchased = false;

            if (m_PurchasedFists.Contains(fistModel.m_Id))
            {
                isPurchased = true;
            }

            Windows.FistItemView fistItem = Instantiate <Windows.FistItemView>(m_ItemPrefab, m_Content);
            fistItem.Init(fistModel, isPurchased, OnBuyItemClick, OnSelectItemClick);

            // select if needed
            if (fistModel.m_Id == m_SelectedFistName)
            {
                OnSelectItemClick(fistItem);
            }

            return(fistItem);
        }
Exemple #4
0
        private void OnSelectItemClick(Windows.FistItemView fistView)
        {
            fistView.Select();

            // unselect others
            foreach (var item in m_Items)
            {
                if (item != fistView)
                {
                    item.Unselect();
                }
            }

            // save selected fist to Player Prefs
            m_SelectedFistName = fistView.m_Model.m_Id;
            Systems.GameState.Instance.SelectedFistName = m_SelectedFistName;

            // notify player
            GameEventsController.Instance.SetFist(fistView.m_Model.m_Sprite.sprite);
        }