/// <summary> /// Opens to sub category. Special function used to open the store UI straight /// up to a certain category /// </summary> /// <param name="category">Category.</param> /// <param name="isShortCut">If set to <c>true</c> is short cut.</param> public void OpenToSubCategory(string category, bool isShortCut = false, StoreShortcutType shortcutType = StoreShortcutType.None) { // this is a bit of a hack, but basically there are multiple ways to open the shop. One way is a shortcut in that it // bypasses the normal means of opening a shop, so we need to do some special things in this case isShortcutMode = isShortCut; if (isShortcutMode) { // Check to make sure we have a shortcut type and cache it if (shortcutType != StoreShortcutType.None) { this.shortcutType = shortcutType; } else { Debug.LogError("No shortcut type supplied with store shortcut call"); } // If we are shortcutting, we have to tween the bg in now storeBgPanel.GetComponent <TweenToggleDemux>().Show(); HUDUIManager.Instance.ShowPanel(); NavigationUIManager.Instance.HidePanel(); RoomArrowsUIManager.Instance.HidePanel(); } CreateSubCategoryItemsWithString(category, shortcutType); }
//------------------------------------------ // HideStoreSubPanel() // Return to the StoreBasePanel //------------------------------------------ public void HideStoreSubPanel() { DestroyGrid(); storeSubPanel.GetComponent <TweenToggleDemux>().Hide(); if (isShortcutMode) { switch (shortcutType) { // Exit back to decoration UI case StoreShortcutType.DecorationUIStoreButton: case StoreShortcutType.MinipetUIStoreButton: storeBgPanel.GetComponent <TweenToggleDemux>().Hide(); NavigationUIManager.Instance.HidePanel(); break; // Exit back to default UI case StoreShortcutType.NeedFoodTutorial: case StoreShortcutType.NeedFoodPetSpeech: case StoreShortcutType.NeedEmergencyInhalerPetSpeech: case StoreShortcutType.SickNotification: _CloseUI(); break; // Default cases which should never happen5 case StoreShortcutType.None: default: Debug.LogWarning("Invalid shortcut type detected"); _CloseUI(); break; } // if(ClickManager.Instance.CheckStack(UIModeTypes.EditDecos)){ // If we are shortcuting from edit deco // storeBgPanel.GetComponent<TweenToggleDemux>().Hide(); // Only hide certain things // DecoInventoryUIManager.Instance.ShowDecoInventory(); // InventoryUIManager.Instance.HidePanel(); // HUDUIManager.Instance.HidePanel(); // } // else if(ClickManager.Instance.CheckStack(UIModeTypes.GatingSystem)){ // If we are shortcuting from flame crystal notif // storeBgPanel.GetComponent<TweenToggleDemux>().Hide(); // Only hide certain things // InventoryUIManager.Instance.ShowPanel(); // RoomArrowsUIManager.Instance.ShowPanel(); // DecoInventoryUIManager.Instance.HideDecoInventory(); // } // else if(ClickManager.Instance.CheckStack(UIModeTypes.MiniPet)){ // storeBgPanel.GetComponent<TweenToggleDemux>().Hide(); // InventoryUIManager.Instance.ShowPanel(); // DecoInventoryUIManager.Instance.HideDecoInventory(); // } // else{ // _CloseUI(); // } if (OnShortcutModeEnd != null) { // This will unlock click manager when shortcutted OnShortcutModeEnd(this, EventArgs.Empty); } isShortcutMode = false; shortcutType = StoreShortcutType.None; } else { storeBasePanel.GetComponent <TweenToggleDemux>().Show(); DecoInventoryUIManager.Instance.HidePanel(); InventoryUIManager.Instance.HidePanel(); } }
//---------------------------------------------------- // CreateSubCategoryItemsTab() // Create items for sub category //---------------------------------------------------- public void CreateSubCategoryItemsTab(string tabName, StoreShortcutType shortcutType = StoreShortcutType.None) { // Debug.Log("OPENING STORE MODE " + shortcutType.ToString()); //Destroy existing items first DestroyGrid(); //Reset clip range so scrolling will start from beginning again ResetUIPanelClipRange(); AudioManager.Instance.PlayClip("shopChangeTab"); int itemCount = 0; //base on the tab name and the page name, create proper set of item in the store if (currentPage == "Food") { //No sub category so retrieve a list of all food List <Item> foodList = ItemManager.Instance.FoodList; foreach (Item itemData in foodList) { if (!itemData.IsSecretItem) { CreateStoreItem(grid.gameObject, itemStorePrefabStats, itemData); itemCount++; } } } else if (currentPage == "Items") { //No sub category so retrieve a list of all item List <Item> usableList = ItemManager.Instance.UsableList; foreach (Item itemData in usableList) { if (!itemData.IsSecretItem) { // Need emergency inhaler shortcut, only show emergency inhaler if (shortcutType == StoreShortcutType.SickNotification || shortcutType == StoreShortcutType.NeedEmergencyInhalerPetSpeech) { if (itemData.ID == "Usable0") { itemCount++; CreateStoreItem(grid.gameObject, itemStorePrefabStats, itemData); break; } continue; } // Default case, show everything else { CreateStoreItem(grid.gameObject, itemStorePrefabStats, itemData); itemCount++; } } } } else if (currentPage == "Decorations") { //Retrieve decoration items base on the tab name (sub category) Dictionary <DecorationTypes, List <DecorationItem> > decoDict = ItemManager.Instance.DecorationSubCatList; DecorationTypes decoType = (DecorationTypes)Enum.Parse(typeof(DecorationTypes), tabName); if (decoDict.ContainsKey(decoType)) { List <DecorationItem> decoList = decoDict[decoType]; foreach (DecorationItem decoItemData in decoList) { if (!decoItemData.IsSecretItem) { CreateStoreItem(grid.gameObject, itemStorePrefab, (Item)decoItemData); itemCount++; } } } } // Adjust the grid width based on the width of the cell and spacing itemCount = (itemCount % 2 == 1) ? itemCount + 1 : itemCount; // Dividing by 2 later, so make sure even float gridWidth = itemCount * 0.5f * (grid.cellSize.x + grid.spacing.x); grid.GetComponent <RectTransform>().sizeDelta = new Vector2(gridWidth, grid.GetComponent <RectTransform>().sizeDelta.y); }
/// <summary> /// Creates the sub category items with string. /// </summary> /// <param name="page">Page.</param> private void CreateSubCategoryItemsWithString(string page, StoreShortcutType shortcutType = StoreShortcutType.None) { if (page != "Items" && page != "Food" && page != "Decorations") { Debug.LogError("Illegal store sub category: " + page); return; } currentPage = page; // Reset the grid and scrolling scrollRect.StopMovement(); Vector2 auxPosition = grid.GetComponent <RectTransform>().anchoredPosition; grid.GetComponent <RectTransform>().anchoredPosition = new Vector2(0f, auxPosition.y); //create the tabs for those sub category if (currentPage == "Food") { InventoryUIManager.Instance.ShowPanel(true); DecoInventoryUIManager.Instance.HidePanel(); foreach (Transform tab in tabArea.transform) { ToggleTab(tab, false); } CreateSubCategoryItemsTab("foodDefaultTab", shortcutType); } else if (currentPage == "Items") { InventoryUIManager.Instance.ShowPanel(true); DecoInventoryUIManager.Instance.HidePanel(); foreach (Transform tab in tabArea.transform) { ToggleTab(tab, false); } CreateSubCategoryItemsTab("itemsDefaultTab", shortcutType); } else if (currentPage == "Decorations") { InventoryUIManager.Instance.HidePanel(); DecoInventoryUIManager.Instance.ShowPanel(); //Get a list of decoration types from Enum string[] decorationEnums = Enum.GetNames(typeof(DecorationTypes)); int counter = 0; // Set the default category string defaultTabName = "Carpet"; if (SceneUtils.CurrentScene == SceneUtils.YARD) { defaultTabName = "SmallPlant"; } List <string> unlockedDecoList = PartitionManager.Instance.GetAllowedDecoTypeFromLatestPartition(); //Rename the tab to reflect the sub category name foreach (Transform tab in tabArea.transform) // TODO-s CHANGE THIS TO FIT TABS { if (counter < decorationEnums.Length) { tab.name = decorationEnums[counter]; if (tab.name == defaultTabName) { tab.GetComponent <Image>().sprite = SpriteCacheManager.GetSprite("buttonCategoryActive"); } Image imageSprite = tab.FindChild("TabImage").gameObject.GetComponent <Image>(); imageSprite.sprite = SpriteCacheManager.GetDecoIconSprite((DecorationTypes)Enum.Parse(typeof(DecorationTypes), tab.name)); //Debug.Log(tabParent.name); // If the gate xml has the deco type allowed, enable button if (unlockedDecoList.Contains(tab.name)) { ToggleTab(tab, true); } // Else disable button else { ToggleTab(tab, false); } } else { tab.name = ""; ToggleTab(tab, false); } counter++; } //After tabs have been set up create items for the first/default tab CreateSubCategoryItemsTab(defaultTabName, shortcutType); } ShowStoreSubPanel(); }