public bool CloseShopWindow(bool sendCloseShopWindow = true) { //unreference callbacks int onBuy; int onSell; Npc npc = GetShopOwner(out onBuy, out onSell); if (npc == null) { ShopItemList.Clear(); return(false); } SetShopOwner(null, -1, -1); npc.FireOnPlayerEndTrade(this, onBuy, onSell); if (sendCloseShopWindow) { SendCloseShop(); } ShopItemList.Clear(); return(true); }
private void InitialDateFromConfig() { ConfigController configController = new ConfigController(); _resources = configController.GetListNaturalResourcesConfig(); _shopItemList = configController.GetShopListConfig(); farmItemList = configController.GetFarmtemsConfig(); }
public void CreateUI() { //Popula o grid foreach (string key in GlobalVars.shopCache.lists.Keys) { ShopItemList list = GlobalVars.shopCache.lists[key]; GameObject categoryLabel = Instantiate(itemCategoryPrefab); categoryLabel.transform.SetParent(grid.transform, false); categoryLabel.GetComponent <ItemCategoryUI>().Populate(list.listName); foreach (ShopItem item in list.items) { GameObject itemSlot = Instantiate(itemPrefab); itemSlot.transform.SetParent(grid.transform, false); Sprite itemSprite = null; if (!GlobalVars.GetShopImagesCache().ContainsKey(item.imageURL)) { GlobalVars.LoadImageFromStorage(item.imageURL, (byte[] data) => { //Já que eu não posso dar texture.LoadImage fora da Thread principal //do Unity, eu coloco ele numa lista de próximas coisas a serem //Executadas na main Thread (no metodo Update desse objeto) QueueToExecute(() => { Texture2D texture = new Texture2D(1, 1); texture.LoadImage(data); Sprite sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f); itemSlot.GetComponent <ItemSlotUI>().icon = sprite; }); }); } else { itemSprite = GlobalVars.GetShopImagesCache()[item.imageURL]; } itemSlot.GetComponent <ItemSlotUI>().Populate( item, GlobalVars.getPlayerProfile().GetValue(item.id), item.GetCurrentCost(), itemSprite ); itemSlot.GetComponent <ItemSlotUI>().manager = GetComponent <ShopManager>(); } } //Pega o 2o white space e joga pro final grid.transform.GetChild(1).transform.SetAsLastSibling(); }
void Start() { //Touch touch = Input.GetTouch(0); m_list = transform.Find("ScrollView/Viewport/ShopItemList").GetComponent <ShopItemList>(); m_weaponBtn = transform.Find("BuyList/Weapon").GetComponent <Button>(); m_armorBtn = transform.Find("BuyList/Armor").GetComponent <Button>(); m_consumptionBtn = transform.Find("BuyList/Consumption").GetComponent <Button>(); m_showItem = transform.Find("ShowItem").gameObject; m_weaponBtn.onClick.AddListener(Weapon); m_armorBtn.onClick.AddListener(Armor); m_consumptionBtn.onClick.AddListener(Consumption); m_scrollbar = transform.Find("ScrollView/Scrollbar Vertical").GetComponent <Scrollbar>(); }
static string[] OnWillSaveAssets(string[] paths) { ShopItemList specialItems = (ShopItemList)AssetDatabase.LoadAssetAtPath("Assets/Special Shop Items.asset", typeof(ShopItemList)); ShopItemList allItems = (ShopItemList)AssetDatabase.LoadAssetAtPath("Assets/All Shop Items.asset", typeof(ShopItemList)); allItems.shopItems = new List <ShopItem>(specialItems.shopItems); string prefabsFolder = Path.Combine(Application.dataPath, "Prefabs", "Balls"); string[] prefabPaths = Directory.GetFiles(prefabsFolder, "*.prefab", SearchOption.AllDirectories); foreach (string path in prefabPaths) { string assetPath = "Assets" + path.Replace(Application.dataPath, "").Replace("\\", "/"); GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)); allItems.shopItems.Add(ShopItemFor(prefab)); } Debug.Log("populated shop items"); return(paths); }
public ActionResult <ShopItemList> Items() { ShopItemList shopItems = new ShopItemList(); shopItems.Items.Add(new Models.ShopItem() { ItemId = "001", ItemName = "cloth" }); shopItems.Items.Add(new Models.ShopItem() { ItemId = "002", ItemName = "cloth1" }); shopItems.Items.Add(new Models.ShopItem() { ItemId = "003", ItemName = "cloth2" }); return(shopItems); }
//POPULA O SHOP JÁ CARREGADO NA INTERFACE public void PopulateInterface() { int i = 0; foreach (string key in GlobalVars.shopCache.lists.Keys) { ShopItemList list = GlobalVars.shopCache.lists[key]; GameObject go = Instantiate(listPrefab); go.transform.SetParent(content.transform, false); ShopItemListUI listUI = go.GetComponent <ShopItemListUI>(); listUI.listName = list.listName; RectTransform rect = go.GetComponent <RectTransform>(); rect.offsetMin = new Vector2(0, -initialListY - 200 - listPeriod * i); rect.offsetMax = new Vector2(0, -initialListY + 200 - listPeriod * i); int j = 0; float size = 300; foreach (ShopItem item in list.items) { GameObject go2 = Instantiate(itemPrefab); go2.transform.SetParent(listUI.content.transform, false); ShopItemUI itemUI = go2.GetComponent <ShopItemUI>(); itemUI.LoadShopItem(item); itemUI.canvas = canvas; RectTransform rect2 = go2.GetComponent <RectTransform>(); rect2.offsetMin = new Vector2(j * size, 100); rect2.offsetMax = new Vector2(size + j * size, -100); RectTransform listContentRect = listUI.content.GetComponent <RectTransform>(); listContentRect.offsetMax = new Vector2(listContentRect.offsetMax.x + size, 100); j++; } i++; } }
public void LoadFromRTD(Dictionary <string, object> data) { //Carrega os arquivos de mídia Dictionary <string, object> media = GetChildrenPath(data, "media/files"); //Carrega as listas de items da loja Dictionary <string, object> itemLists = GetChildrenPath(data, "environments/production/content/itemList/en-US"); foreach (string key in itemLists.Keys) { Dictionary <string, object> listDict = (Dictionary <string, object>)itemLists[key]; ShopItemList list = new ShopItemList((string)listDict["listName"]); string listID = ToLong(listDict["id"]) + ""; lists.Add(listID, list); } //Carrega os items da loja e popula nas respectivas listas de items Dictionary <string, object> items = GetChildrenPath(data, "environments/production/content/items/en-US"); foreach (string key in items.Keys) { Dictionary <string, object> itemDict = (Dictionary <string, object>)items[key]; //Pucha a URL da imagem baseado no ID salvo (o flamelink é ruim nisso) string imageID = ToLong(((List <object>)itemDict["imageURL"])[0]) + ""; string imageURL = "gs://pimba-ball.appspot.com/flamelink/media/" + (string)((Dictionary <string, object>)media[imageID])["file"]; string listID = ToLong(itemDict["item-list"]) + ""; ShopItem item = new ShopItem( (string)itemDict["displayName"], (string)itemDict["itemId"], ToInt(itemDict["precoInicial"]), (ShopItemUI.ItemProgression) int.Parse((string)itemDict["progression"]), ToFloat(itemDict["ratio"]), ToInt(itemDict["limite"]), imageURL, (string)itemDict["description"] ); lists[listID].addShopItem(item); } }
public void LegacyLoad(Dictionary <string, object> data) { List <object> ls = (List <object>)data["lists"]; for (int i = 0; i < ls.Count; i++) { Dictionary <string, object> list = (Dictionary <string, object>)ls[i]; ShopItemList sil = new ShopItemList((string)list["listName"]); List <object> items = (List <object>)list["items"]; for (int j = 0; j < items.Count; j++) { Dictionary <string, object> item = (Dictionary <string, object>)items[j]; string displayName = (string)item["displayName"]; string id = (string)item["id"]; int initialCost = ToInt(item["initialCost"]); ShopItemUI.ItemProgression progression = (ShopItemUI.ItemProgression)(ToInt(item["progression"])); float ratio = ToFloat(item["ratio"]); int limit = ToInt(item["limit"]); string imageURL = (string)item["imageURL"]; string description = (string)item["description"]; ShopItem si = new ShopItem( displayName, id, initialCost, progression, ratio, limit, imageURL, description ); sil.addShopItem(si); } lists.Add(sil.listName, sil); } }