public void Game_PurchasedItemsTabSelected(ItemsStoreTab tab)
        {
            ClearPurchasedItemsScrollView();

            var tabIndex = tab.tabIndex;
            var selectedTabIndex = selectedTab != null ? selectedTab.tabIndex : 0;

            // De-highlight the currently selected tab
            purchasedItemsHighlightedTabs[selectedTabIndex].SetActive(false);
            purchasedItemsTabs[selectedTabIndex].SetActive(true);

            // Anchor the tab next to the previously highlighted to the regular version of the tab
            if (selectedTabIndex < purchasedItemsTabs.Length - 1)
            {
                // TODO: Use generic UIRect for anchoring
                var tabOnRight = purchasedItemsTabs[selectedTabIndex + 1];
                var tabOnRightTexture = tabOnRight.GetComponentOrThrow<UITexture>();

                var anchorTexture = purchasedItemsTabs[selectedTabIndex].GetComponentOrThrow<UITexture>();
                var anchorTransform = purchasedItemsTabs[selectedTabIndex].transform;

                tabOnRightTexture.leftAnchor.target = anchorTransform;
                tabOnRightTexture.leftAnchor.rect = anchorTexture;
            }

            // Highlight the new tab
            purchasedItemsHighlightedTabs[tabIndex].SetActive(true);
            purchasedItemsTabs[tabIndex].SetActive(false);

            // Anchor the next tab to the highlighted version of the tab
            if (tabIndex < purchasedItemsTabs.Length - 1)
            {
                // TODO: Use generic UIRect for anchoring
                var tabOnRight = purchasedItemsTabs[tabIndex + 1];
                var tabOnRightTexture = tabOnRight.GetComponentOrThrow<UITexture>();

                var anchorTexture = purchasedItemsHighlightedTabs[tabIndex].GetComponentOrThrow<UITexture>();
                var anchorTransform = purchasedItemsHighlightedTabs[tabIndex].transform;

                tabOnRightTexture.leftAnchor.target = anchorTransform;
                tabOnRightTexture.leftAnchor.rect = anchorTexture;
            }

            selectedTab = tab;

            Log.Debug("Selected tab {0}", selectedTab.tabIndex);

            PopulatePurchasedItems(selectedTab);
        }
Exemple #2
0
        private void PopulateItemsForTab(ItemsStoreTab tab)
        {
            var selectedCateogry = tab != null ? tab.category : DefaultCategory;

            GameObject previousStoreItem = null;

            foreach (var item in availableItems.Where(x => x.Category == selectedCateogry))
            {
                var storeItem = NGUITools.AddChild(storeItemsScrollView, storeItemTemplate);
                storeItem.SingleChild().GetComponentOrThrow <UISprite>().spriteName = item.ThumbnailName;

                // Capture index for the anonimous delegate closure
                var capturedId = item.Id;
                UIEventListener.Get(storeItem.GetComponentOrThrow <UIButton>().gameObject).onClick += (obj) =>
                {
                    SelectItem(capturedId);
                };

                var storeItemSprite = storeItem.GetComponentOrThrow <UISprite>();

                storeItemSprite.topAnchor.target   = storeItemsScrollView.transform;
                storeItemSprite.topAnchor.absolute = 0;

                storeItemSprite.bottomAnchor.target = storeItemsScrollView.transform;
                storeItemSprite.topAnchor.absolute  = 0;

                if (previousStoreItem == null)
                {
                    SelectItem(item.Id);
                }
                else
                {
                    storeItemSprite.leftAnchor.target   = previousStoreItem.transform;
                    storeItemSprite.leftAnchor.absolute = 0;
                    storeItemSprite.leftAnchor.relative = 1f;
                }

                storeItemSprite.updateAnchors = UIRect.AnchorUpdate.OnUpdate;

                storeItemSprite.ResetAndUpdateAnchors();

                previousStoreItem = storeItem;
            }

            storeItemsScrollView.GetComponentOrThrow <UIScrollView>().ResetPosition();
        }
Exemple #3
0
        public void SelectTab(ItemsStoreTab tab)
        {
            ClearItemsScrollView();

            var tabIndex         = tab.tabIndex;
            var selectedTabIndex = selectedTab != null ? selectedTab.tabIndex : 0;

            // De-highlight the currently selected tab
            highlightedTabs[selectedTabIndex].SetActive(false);
            tabs[selectedTabIndex].SetActive(true);

            // Anchor the tab next to the previously highlighted to the regular version of the tab
            if (selectedTabIndex < tabs.Length - 1)
            {
                var tabOnRight       = tabs[selectedTabIndex + 1];
                var tabOnRightSprite = tabOnRight.GetComponentOrThrow <UISprite>();

                var anchorSprite    = tabs[selectedTabIndex].GetComponentOrThrow <UISprite>();
                var anchorTransform = tabs[selectedTabIndex].transform;

                tabOnRightSprite.leftAnchor.target = anchorTransform;
                tabOnRightSprite.leftAnchor.rect   = anchorSprite;
            }

            // Highlight the new tab
            highlightedTabs[tabIndex].SetActive(true);
            tabs[tabIndex].SetActive(false);

            // Anchor the next tab to the highlighted version of the tab
            if (tabIndex < tabs.Length - 1)
            {
                var tabOnRight       = tabs[tabIndex + 1];
                var tabOnRightSprite = tabOnRight.GetComponentOrThrow <UISprite>();

                var anchorSprite    = highlightedTabs[tabIndex].GetComponentOrThrow <UISprite>();
                var anchorTransform = highlightedTabs[tabIndex].transform;

                tabOnRightSprite.leftAnchor.target = anchorTransform;
                tabOnRightSprite.leftAnchor.rect   = anchorSprite;
            }

            selectedTab = tab;

            PopulateItemsForTab(selectedTab);
        }
 private void PopulatePurchasedItems(ItemsStoreTab tab)
 {
     var selectedCategory = tab != null ? tab.category : DefaultInventoryCategory;
     PopulatePurchasedItems(selectedCategory);
 }