コード例 #1
0
    public void RefreshShopWindow() // Called whenever the player visits their shop
    {
        foreach (Transform child in shopWindowContent)
        {
            Destroy(child.gameObject);
        }

        foreach (ShopItem itemSelling in itemsForSale)
        {
            GameObject     saleItemPrefab = Instantiate(saleItemButtonPrefab, shopWindowContent);
            ShopItemButton shopButton     = saleItemPrefab.GetComponent <ShopItemButton>();

            shopButton.myShopItem = itemSelling;
            shopButton.buyOrSell  = ShopItemButton.saleType.sell;

            shopButton.UpdateShopItemInfo();

            if (itemSelling.sold)
            {
                saleItemButtonPrefab.transform.Find("Text_Sold").gameObject.SetActive(true);
            }
            else
            {
                saleItemButtonPrefab.transform.Find("Text_Sold").gameObject.SetActive(false);
            }
        }
    }
コード例 #2
0
ファイル: Shop.cs プロジェクト: NemotoYoshiyuki/Unity2DRPG
    public void SellWindow()
    {
        List <Item> items       = InventorySystem.GetItems();
        int         buttonIndex = -1;

        foreach (var item in items)
        {
            ShopItemButton sellButton = Instantiate(productButton, listViewContent.gameObject.transform);
            buttonIndex++;
            sellButton.button.index     = buttonIndex;
            sellButton.productName.text = item.itemName;
            sellButton.monyText.text    = (item.price / 2).ToString() + "G";

            sellButton.button.onClick.AddListener(() =>
            {
                Sell(item);
                DestroyButton(sellButton.button);
            });
            sellButton.button.onHover = (() =>
            {
                int possessionsNumber = 0;
                ViewPossessionsNumber(possessionsNumber);
                ProductDescription(item);
            });
            productButtons.Add(sellButton);
            //sellButton.transform.SetParent(listViewContent.transform);
        }
        productButtons[0].button.Select();
    }
コード例 #3
0
    public void InspectShopItem(ShopItemButton shopButton, ShopItem item) // Called by ShopItemButton. Delegate Applied on ShopItemButton Start
    {
        if (shopButton.buyOrSell == ShopItemButton.saleType.buy)
        {
            OpenBuyWindow(item);
        }

        // TODO - Ability to cancel sale and put item back in world
    }
コード例 #4
0
 public bool Buy(ShopItemButton item)
 {
     if (cachedGold > dh.possibleItemsDict[item.name].GetComponent <Item>().price)
     {
         cachedGold -= dh.possibleItemsDict[item.name].GetComponent <Item>().price;
         QueueItem(dh.possibleItemsDict[item.name]);
         return(true);
     }
     return(false);
 }
コード例 #5
0
 void RemoveShoptemUI(InventoryItem item)
 {
     foreach (Transform child in ShopInventoryContent)
     {
         ShopItemButton shopItemButton = child.GetComponent <ShopItemButton>();
         if (item == shopItemButton.Item)
         {
             Destroy(child.gameObject);
             _eventSystem.SetSelectedGameObject(ShopInventoryContent.transform.GetChild(0).gameObject);
         }
     }
     PartyGoldText.text = "Party Gold " + _partyInventory.Gold;
 }
コード例 #6
0
 void UpdateShopItemUI(InventoryItem inventoryItem, int amount)
 {
     foreach (Transform child in ShopInventoryContent.transform)
     {
         //get child with the item
         ShopItemButton shopItemButton = child.GetComponent <ShopItemButton>();
         if (shopItemButton.Item == inventoryItem)
         {
             //get item panel
             child.transform.GetChild(0).GetChild(0).GetComponent <Text>().text = "x" + (shopItemButton.Item.Amount + amount);
         }
     }
     PartyGoldText.text = "Party Gold " + _partyInventory.Gold;
 }
コード例 #7
0
 void Update()
 {
     if (inputControl)
     {
         if (generalMenuPanel.activeInHierarchy && Input.GetButtonDown("CancelMenu") && !shopPanel.activeInHierarchy)
         {
             CloseGeneralPlayerMenu();
         }
         else if (shopPanel.activeInHierarchy && !quantityActive && Input.GetButtonDown("CancelMenu"))
         {
             CloseShopPanel();
         }
         else if (shopPanel.activeInHierarchy && quantityActive && Input.GetButtonDown("CancelMenu"))
         {
             shopItemButtonRef.item.quantityHeld = 1;
             quantityActive = false;
             shopItemButtonRef.quantityPanel.SetActive(false);
             shopItemButtonRef.mySelf.Select();
             EnableOtherShopButtons();
             shopItemButtonRef = null;
         }
         else if (playerStatusPanel.activeInHierarchy && Input.GetButtonDown("CancelMenu"))
         {
             ClosePlayerStatusWindow();
         }
         else if (playerStatusPanel.activeInHierarchy && Input.GetButtonDown("CancelMenu"))
         {
             ClosePlayerStatusWindow();
         }
         else if (equipmentPanel.activeInHierarchy && Input.GetButtonDown("CancelMenu"))
         {
             CloseEquipmentMenu();
         }
         else if (questLogPanel.activeInHierarchy && Input.GetButtonDown("CancelMenu"))
         {
             //close quest log panel
         }
         else if (settingsPanel.activeInHierarchy && Input.GetButtonDown("CancelMenu"))
         {
             //close settings panel
         }
         else if (useItemPanel.activeInHierarchy && Input.GetButtonDown("CancelMenu"))
         {
             CloseApplyConsumableToCharacter();
         }
     }
 }
コード例 #8
0
ファイル: ShopManager.cs プロジェクト: sedatyavuz/Scripts
    private void PopulateItemContainer(GameObject content, ItemRuntimeSet items)
    {
        RectTransform contentRect = content.GetComponent <RectTransform>();
        float         yItemSize   = shopItemButtonPrefab.GetComponent <RectTransform>().sizeDelta.y;

        contentRect.sizeDelta = new Vector2(contentRect.sizeDelta.x, items.Count * yItemSize);

        foreach (BaseItem item in items)
        {
            if (item.itemGender == Gender.Unisex || item.itemGender == playerData.gender)
            {
                GameObject     newShopItem  = Instantiate(shopItemButtonPrefab, content.transform);
                ShopItemButton buttonScript = newShopItem.GetComponent <ShopItemButton>();
                buttonScript.InitilizeShopListing(item);
            }
        }
    }
コード例 #9
0
ファイル: ShopView.cs プロジェクト: AlmostMatt/LD48
    public void PurchaseItem(ShopItemButton shopItemButton)
    {
        int      itemIndex = shopItemButton.transform.GetSiblingIndex();
        ShopItem item      = shopItemList[itemIndex];

        SaveData.Get().DecreaseCash(item.priceInDollars);
        shopItemList[itemIndex] = new ShopItem(item.name, item.description, item.imageName, item.priceInDollars, item.effectType, item.effectValue, true);
        // The effect of the item
        switch (item.effectType)
        {
        case "DigSkill":
            SaveData.Get().digSkill = Mathf.Max(SaveData.Get().digSkill, item.effectValue);
            break;

        default:
            Debug.LogError("Purchase an item with unknown effect type: " + item.effectType);
            break;
        }
    }
コード例 #10
0
ファイル: Shop.cs プロジェクト: NemotoYoshiyuki/Unity2DRPG
    //商品陳列
    public void ProductsDisplay()
    {
        foreach (var item in product)
        {
            ShopItemButton BuyButton = Instantiate(productButton, listViewContent.gameObject.transform);
            BuyButton.productName.text = item.itemName;
            BuyButton.monyText.text    = item.price.ToString() + "G";

            BuyButton.button.onClick.AddListener(() => { Buy(item); });
            BuyButton.button.onHover = (() =>
            {
                int possessionsNumber = 0;
                ViewPossessionsNumber(possessionsNumber);
                ProductDescription(item);
            });
            productButtons.Add(BuyButton);
            //BuyButton.transform.SetParent(listViewContent.transform);
        }
    }
コード例 #11
0
    void OnEnable()
    {
        foreach (GameItem thisItem in PlayerStatus.VisitingIsland.GetShop().inventoryList)
        {
            if (thisItem.quantity != 0)
            {
                GameObject button = (GameObject)GameObject.Instantiate(invItemButton); //Make a copy of the base dialogue button
                button.SetActive(true);                                                //As the base button is not active, new button must be set active
                button.transform.SetParent(invLayoutPanel.transform);                  //Set its parent to the dialogue panel
                button.tag = "ToDestroy";

                ShopItemButton inventoryItemButton = button.GetComponent <ShopItemButton>(); //Get a reference to its script
                if (inventoryItemButton == null)
                {
                    Debug.Log("script null");
                }
                if (thisItem == null)
                {
                    Debug.Log("item null");
                }
                inventoryItemButton.SetVars(thisItem);
            }
        }
    }
コード例 #12
0
    public void Initialize(Shop shop)
    {
        Reset();

        CrystalWhenEnter = StoryManager.Instance.GetStory().Crystal;
        Cur_Shop         = (Shop)shop.Clone();

        ShopNameText.text = Cur_Shop.LevelNames[LanguageManager.Instance.GetCurrentLanguage()];

        List <ShopItem_Card> si_cards  = new List <ShopItem_Card>();
        List <ShopItem>      si_others = new List <ShopItem>();

        foreach (ShopItem si in Cur_Shop.ShopItems)
        {
            if (si is ShopItem_Card sic)
            {
                si_cards.Add(sic);
            }
            else
            {
                si_others.Add(si);
            }
        }

        int shopItemCardCount   = shop.ShopItemCardCount;
        int shopItemOthersCount = shop.ShopItemOthersCount;

        if (si_cards.Count > 0)
        {
            List <ShopItem_Card> si_cards_random = Utils.GetRandomWithProbabilityFromList(si_cards, shopItemCardCount); // 卡片按概率随机
            HashSet <int>        cardIdHashSet   = new HashSet <int>();
            foreach (ShopItem_Card sic in si_cards_random)
            {
                CardInfo_Base ci = AllCards.GetRandomCardInfoByLevelNum(sic.CardRareLevel, cardIdHashSet);
                if (ci != null)
                {
                    sic.GenerateCardID = ci.CardID;
                    sic.Price          = Mathf.CeilToInt(Random.Range(ci.BaseInfo.ShopPrice * 0.8f, ci.BaseInfo.ShopPrice * 1.2f));
                    cardIdHashSet.Add(sic.GenerateCardID);
                    ShopItemButton btn = ShopItemButton.GenerateShopItemButton(sic, ShopItemSmallContainers, ShopItemContainer);
                    ShopItemButtons.Add(sic.ShopItemID, btn);
                }
                else
                {
                    shopItemCardCount--;
                    shopItemOthersCount++;
                }
            }
        }

        if (si_others.Count > 0)
        {
            List <ShopItem> si_others_random = Utils.GetRandomWithProbabilityFromList(si_others, shopItemOthersCount * SHOP_ITEM_OTHERS_GROUP_CAPACITY); // 其他物品按概率随机

            foreach (ShopItem si in si_others_random)
            {
                if (si is ShopItem_Budget)
                {
                    ShopItemButton btn = ShopItemButton.GenerateShopItemButton(si, ShopItemSmallContainers, ShopItemContainer);
                    ShopItemButtons.Add(si.ShopItemID, btn);
                }
            }

            foreach (ShopItem si in si_others_random)
            {
                if (si is ShopItem_LifeUpperLimit)
                {
                    ShopItemButton btn = ShopItemButton.GenerateShopItemButton(si, ShopItemSmallContainers, ShopItemContainer);
                    ShopItemButtons.Add(si.ShopItemID, btn);
                }
            }

            foreach (ShopItem si in si_others_random)
            {
                if (si is ShopItem_EnergyUpperLimit)
                {
                    ShopItemButton btn = ShopItemButton.GenerateShopItemButton(si, ShopItemSmallContainers, ShopItemContainer);
                    ShopItemButtons.Add(si.ShopItemID, btn);
                }
            }
        }

        RefreshAllShopItemAffordable();
    }