public void SetupUI(CraftUI craftUI, Machine machine)
 {
     this.machine = machine;
     craftId      = craftUI.name;
     name         = craftUI.name;
     transform.Find("Selected").gameObject.SetActive(false);
     foreach (Transform child in inputs)
     {
         Destroy(child.gameObject);
     }
     foreach (CraftItem item in craftUI.inputs)
     {
         GameObject itemGo = Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/SingleCraftItem"), inputs);
         itemGo.GetComponent <Image>().sprite        = Resources.Load <ItemUI>("UIs/Items/" + item.itemId).sprite;
         itemGo.GetComponentInChildren <Text>().text = item.number.ToString();
     }
     foreach (Transform child in outputs)
     {
         Destroy(child.gameObject);
     }
     foreach (CraftItem item in craftUI.outputs)
     {
         GameObject itemGo = Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/SingleCraftItem"), outputs);
         itemGo.GetComponent <Image>().sprite        = Resources.Load <ItemUI>("UIs/Items/" + item.itemId).sprite;
         itemGo.GetComponentInChildren <Text>().text = item.number.ToString();
     }
     if (!craftUI.AreRequirementsMet())
     {
         transform.Find("Locked").gameObject.SetActive(true);
     }
 }
Example #2
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.I))
     {
         if (!InventoryCaneva.panel.gameObject.activeInHierarchy)
         {
             InventoryCaneva.OpenInventory(Items);
         }
         else
         {
             if (CraftUI.isActive)
             {
                 CraftUI.StaticExit();
             }
             InventoryCaneva.Exit();
         }
     }
     if (Input.GetKeyDown(KeyCode.C) && InventoryCaneva.panel.gameObject.activeInHierarchy)
     {
         if (!CraftUI.isActive)
         {
             CraftUI.OpenCraftingUI();
         }
         else
         {
             CraftUI.StaticExit();
         }
     }
 }
Example #3
0
 public void Exit()
 {
     if (CraftUI.isActive)
     {
         CraftUI.StaticExit();
     }
     panel.SetActive(false);
     panelPlayer.SetActive(false);
     _lastSelectedItem = -1;
 }
Example #4
0
 void  Awake()
 {
     InvUI          = FindObjectOfType(typeof(InventoryUI)) as InventoryUI;
     VendorPanel    = FindObjectOfType(typeof(VendorUI)) as VendorUI;
     SkillBarPanel  = FindObjectOfType(typeof(SkillBarUI)) as SkillBarUI;
     EquipmentPanel = FindObjectOfType(typeof(EquipmentUI)) as EquipmentUI;
     InvContainer   = FindObjectOfType(typeof(ContainerUI)) as ContainerUI;
     InvCraft       = FindObjectOfType(typeof(CraftUI)) as CraftUI;
     InvItemGroup   = FindObjectOfType(typeof(ItemGroupUI)) as ItemGroupUI;
     HoverScript    = FindObjectOfType(typeof(HoverItem)) as HoverItem;
 }
Example #5
0
    public IEnumerator TryCraft()
    {
        CraftUI craft = GetCraft();

        if (craft != null)
        {
            yield return(new WaitForSeconds(craft.speed));

            BuildManager.instance.StartCoroutine(Craft(craft));
        }
    }
Example #6
0
 public CraftUI GetCraft()
 {
     if (craftChosen != null)
     {
         CraftUI craft = Resources.Load <CraftUI>($"UIs/Crafts/{blockId}/{craftChosen}");
         if (CheckIfCraftable(craft))
         {
             return(craft);
         }
     }
     return(null);
 }
Example #7
0
 public static IEnumerator Load(
     CraftUI craftUI,
     Transform viewerParent,
     Action <RecipeViewer> onComplete)
 {
     // ISSUE: object of a compiler-generated type is created
     return((IEnumerator) new RecipeViewer.\u003CLoad\u003Ec__Iterator0()
     {
         viewerParent = viewerParent,
         craftUI = craftUI,
         onComplete = onComplete
     });
 }
Example #8
0
        protected override void OnAwake(PlayerActor player)
        {
            CraftPoint currentCraftPoint = player.CurrentCraftPoint;

            if (Object.op_Equality((Object)currentCraftPoint, (Object)null) || !Singleton <MapUIContainer> .IsInstance())
            {
                player.PlayerController.ChangeState("Normal");
            }
            else
            {
                MapUIContainer.SetCommandLabelAcception(CommandLabel.AcceptionState.None);
                player.SetScheduledInteractionState(false);
                player.ReleaseInteraction();
                CraftUI     craftUi     = (CraftUI)null;
                RecyclingUI recyclingUi = (RecyclingUI)null;
                switch (currentCraftPoint.Kind)
                {
                case CraftPoint.CraftKind.Medicine:
                    craftUi = MapUIContainer.MedicineCraftUI;
                    break;

                case CraftPoint.CraftKind.Pet:
                    craftUi = MapUIContainer.PetCraftUI;
                    break;

                case CraftPoint.CraftKind.Recycling:
                    recyclingUi = MapUIContainer.RecyclingUI;
                    break;

                default:
                    this.OnClosed(player);
                    break;
                }
                if (Object.op_Inequality((Object)craftUi, (Object)null))
                {
                    craftUi.OnClosedEvent   = (Action)(() => this.OnClosed(player));
                    craftUi.IsActiveControl = true;
                }
                else if (Object.op_Inequality((Object)recyclingUi, (Object)null))
                {
                    recyclingUi.OnClosedEvent   = (Action)(() => this.OnClosed(player));
                    recyclingUi.IsActiveControl = true;
                }
                else
                {
                    this.OnClosed(player);
                }
            }
        }
Example #9
0
        public void Refresh(CraftUI craftUI)
        {
            this.itemListUI.ClearItems();
            this.ResetScroll();
            craftUI.SetID(this._id);
            // ISSUE: object of a compiler-generated type is created
            foreach (\u003C\u003E__AnonType18 <KeyValuePair <int, RecipeDataInfo[]>, int> anonType18 in ((IEnumerable <KeyValuePair <int, RecipeDataInfo[]> >) this._info).Select <KeyValuePair <int, RecipeDataInfo[]>, \u003C\u003E__AnonType18 <KeyValuePair <int, RecipeDataInfo[]>, int> >((Func <KeyValuePair <int, RecipeDataInfo[]>, int, \u003C\u003E__AnonType18 <KeyValuePair <int, RecipeDataInfo[]>, int> >)((p, i) => new \u003C\u003E__AnonType18 <KeyValuePair <int, RecipeDataInfo[]>, int>(p, i))))
            {
                int hash = anonType18.p.Key;
                RecipeDataInfo[] recipeInfo = anonType18.p.Value;
                StuffItemInfo    itemInfo   = Singleton <Resources> .Instance.GameInfo.FindItemInfo(hash);

                this.itemListUI.AddItemNode(anonType18.i, new CraftItemNodeUI.StuffItemInfoPack(itemInfo, (Func <CraftItemNodeUI.Possible>)(() => CraftViewer.Possible(craftUI.checkStorages, hash, recipeInfo))), recipeInfo);
            }
        }
Example #10
0
        private bool CalcTargetRecipe()
        {
            AgentActor       agent    = this.Agent;
            List <StuffItem> itemList = agent.AgentData.ItemList;

            this._createItem = CraftUI.CreateCheck(Singleton <Resources> .Instance.GameInfo.recipe.cookTable, (IReadOnlyCollection <IReadOnlyCollection <StuffItem> >) new List <StuffItem>[2]
            {
                itemList,
                Singleton <Game> .Instance.Environment.ItemListInPantry
            });
            int  num  = agent.ChaControl.fileGameInfo.flavorState[0];
            bool chef = agent.ChaControl.fileGameInfo.normalSkill.ContainsValue(0);

            return(CraftUI.CreateCooking(this._createItem, itemList, (float)num, chef));
        }
Example #11
0
    public static GameObject CreateRecipeInventoryButton(int index, int recipeID)
    {
        GameObject obj = new GameObject();

        if (index < 10)
        {
            obj.name = string.Format("0{0}", index);
        }
        else
        {
            obj.name = index.ToString();
        }
        //Set the image component:
        Image img = obj.AddComponent <Image>();

        img.type   = Image.Type.Sliced;
        img.sprite = ResourcesManager.instance.EmptySprite;
        img.color  = new Color32(0, 0, 0, 255);
        //Add events:
        EventTrigger eventTrigger = obj.AddComponent <EventTrigger>();

        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerEnter;
        entry.callback.AddListener((eventData) => { CraftUI.OnRecipePointerEnter(recipeID); });
        eventTrigger.triggers.Add(entry);

        entry         = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerExit;
        entry.callback.AddListener((eventData) => { CraftUI.OnRecipePointerExit(); });
        eventTrigger.triggers.Add(entry);

        entry         = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerDown;
        entry.callback.AddListener((eventData) => { CraftUI.OnRecipeClick(recipeID); });
        eventTrigger.triggers.Add(entry);

        //Create first child:
        GameObject child1 = new GameObject("inventorySlot");

        child1.transform.SetParent(obj.transform);
        img = child1.AddComponent <Image>();
        child1.GetComponent <RectTransform>().SetSize(new Vector2(35, 35));
        img.type   = Image.Type.Sliced;
        img.sprite = Craft.Recipes[recipeID].InventorySprite;
        img.color  = new Color32(255, 255, 255, 255);

        return(obj);
    }
Example #12
0
 public bool CheckIfCraftable(CraftUI craft)
 {
     foreach (CraftItem inputItem in craft.inputs)
     {
         bool itemPresent = false;
         foreach (CraftItem inventoryItem in inventory)
         {
             if (inventoryItem.itemId == inputItem.itemId && inventoryItem.number >= inputItem.number)
             {
                 itemPresent = true;
                 break;
             }
         }
         if (!itemPresent)
         {
             return(false);
         }
     }
     return(true);
 }
Example #13
0
 public IEnumerator Craft(CraftUI craft)
 {
     foreach (CraftItem inputItem in craft.inputs)
     {
         foreach (CraftItem inventoryItem in inventory)
         {
             if (inventoryItem.itemId == inputItem.itemId)
             {
                 for (int i = 0; i < inputItem.number; i++)
                 {
                     inventoryItem.number--;
                 }
                 if (inventoryItem.number == 0)
                 {
                     inventory.Remove(inventoryItem);
                 }
                 break;
             }
         }
     }
     SaveManager.instance.save.ModifyBlock(this);
     foreach (CraftItem item in craft.outputs)
     {
         for (int i = 0; i < item.number; i++)
         {
             Item spawnedItem = new Item(item.itemId);
             SaveManager.instance.save.stats.AddItemToCrafted(spawnedItem);
             GameObject go = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/ItemOnConveyor"), GameObject.Find("ItemsOnConveyor").transform);
             go.GetComponent <ItemBehaviour>().Setup(this);
             go.GetComponent <SpriteRenderer>().sprite = spawnedItem.itemUI.sprite;
             go.GetComponent <ItemBehaviour>().item    = spawnedItem;
             go.name = spawnedItem.itemId + " " + spawnedItem.id.ToString();
             yield return(new WaitForSeconds(0.5f));
         }
     }
 }
    public void OnDrop(PointerEventData eventData)
    {
        if (DragHandeler.itemBeginDragged == null)
        {
            return;
        }
        if (DragHandeler.itemBeginDragged.GetComponent <DragHandeler>() == null)
        {
            return;
        }
        int ID = 0;

        if (item == null)
        {
            DragHandeler.itemBeginDragged.transform.SetParent(transform);
        }
        else
        {
            //Switching the objects
            #region Same type
            if (Type == DragHandeler.staticType)
            {
                #region Crafting table
                //Swithing items in the grid:
                if (Type == SlotType.Craft)
                {
                    #region Splitting
                    if (DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().isSplitting)
                    {
                        if (DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem.Count > 1)
                        {
                            item.SetActive(true);
                            //Check if the target tile is empty or the same:
                            if (CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)] != null)
                            {
                                if (CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)].Name == DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem.Name)
                                {
                                    CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)].Count += (DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem.Count / 2);

                                    //Old one
                                    if (DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem.Count % 2 == 0)
                                    {
                                        CraftUI.ItemsInCraftTable[DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().ID].Count /= 2;
                                    }
                                    else
                                    {
                                        CraftUI.ItemsInCraftTable[DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().ID].Count /= 2;
                                        CraftUI.ItemsInCraftTable[DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().ID].Count++;
                                    }
                                    //Update the count texts:
                                    CraftUI.RefreshUI();
                                }
                                else
                                {
                                    return;
                                }
                            }
                            else //The target item is null
                            {
                                CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)] = (Item)DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem.Clone();
                                //Splitting the stack in 2:
                                //New one
                                CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)].Count /= 2;

                                //Old one
                                if (DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem.Count % 2 == 0)
                                {
                                    CraftUI.ItemsInCraftTable[DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().ID].Count /= 2;
                                }
                                else
                                {
                                    CraftUI.ItemsInCraftTable[DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().ID].Count /= 2;
                                    CraftUI.ItemsInCraftTable[DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().ID].Count++;
                                }

                                //item.GetComponent<DragHandeler>().image.sprite = CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)].InventorySprite;

                                CraftUI.RefreshUI();
                            }
                        }
                        return;
                    }
                    #endregion
                    #region Normal
                    else
                    {
                        Item tmp = CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)];
                        Debug.Log(tmp + "  " + DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem);
                        if (tmp != null && tmp.Name == DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem.Name) //Different items
                        {
                            if (item.transform.parent == DragHandeler.itemBeginDragged.transform.parent)
                            {
                                return;
                            }
                            Debug.Log("Merge");
                            //Same item => merging counts
                            CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)].Count += DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem.Count;
                            CraftUI.ItemsInCraftTable[int.Parse(DragHandeler.itemBeginDragged.transform.parent.name)] = null;
                            DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().image.sprite = ResourcesManager.instance.EmptySprite;
                            DragHandeler.itemBeginDragged.SetActive(false);
                            CraftUI.RefreshUI();
                            return;
                        }
                        else
                        {
                            Debug.Log("Normal");
                            CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)] = DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem;
                            CraftUI.ItemsInCraftTable[int.Parse(DragHandeler.itemBeginDragged.transform.parent.name)] = tmp;

                            //Switching parents:
                            item.transform.SetParent(DragHandeler.itemBeginDragged.transform.parent);
                            DragHandeler.itemBeginDragged.transform.SetParent(transform);
                            DragHandeler.itemBeginDragged.GetComponent <CanvasGroup>().blocksRaycasts = true;
                            return;
                        }
                    }
                    #endregion
                }
                #endregion

                Inventory.SwitchItems(DragHandeler.itemBeginDragged, item);
                DragHandeler.itemBeginDragged.GetComponent <CanvasGroup>().blocksRaycasts = true;
            }
            #endregion

            #region Inventory to Crafting table
            //If inventory to craft table :
            if (Type == SlotType.Craft && DragHandeler.staticType == SlotType.Inventory)
            {
                Item draggedItem = DragHandeler.itemBeginDragged.GetComponent <DragHandeler>().currentItem;
                //Check if the item is not already in the list
                if (!CraftUI.CheckIfItemAlreadyPresent(draggedItem) && !Input.GetKey(KeyCode.LeftShift))
                {
                    item.SetActive(true);
                    Debug.Log("Inventory to CraftUI => ID: " + int.Parse(item.transform.parent.name));
                    CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)] = (Item)draggedItem.Clone();
                    item.GetComponent <DragHandeler>().UpdateCountText(CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)].Count);
                    item.GetComponent <DragHandeler>().currentItem  = CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)];
                    item.GetComponent <DragHandeler>().image.sprite = CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)].InventorySprite;
                    return;
                }
                #region Single drop
                //If there's a drag'n drop with left shift => drop + 1 item
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    item.SetActive(true);
                    ID = int.Parse(item.transform.parent.name);
                    Debug.Log("SINGLE Inventory to CraftUI => ID: " + ID);
                    //1- Check if the target is an empty item or not
                    if (CraftUI.ItemsInCraftTable[ID] == null)
                    {
                        //2- Check of we can add one more item
                        if (draggedItem.Count > CraftUI.GetCountOfItem(draggedItem.Name))
                        {
                            CraftUI.ItemsInCraftTable[ID]       = (Item)draggedItem.Clone();
                            CraftUI.ItemsInCraftTable[ID].Count = 1;
                            //item.GetComponent<DragHandeler>().UpdateCountText(CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)].Count);
                            //item.GetComponent<DragHandeler>().currentItem = CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)];
                            //item.GetComponent<DragHandeler>().image.sprite = CraftUI.ItemsInCraftTable[int.Parse(item.transform.parent.name)].InventorySprite;
                            CraftUI.RefreshUI();
                        }
                        else
                        {
                            item.SetActive(false);
                        }
                    }
                    else
                    {
                        //2- Check if the target item is the same item:
                        if (CraftUI.ItemsInCraftTable[ID].Name == draggedItem.Name)
                        {
                            if (draggedItem.Count > CraftUI.GetCountOfItem(draggedItem.Name))
                            {
                                CraftUI.ItemsInCraftTable[ID].Count++;
                                CraftUI.RefreshUI();
                            }
                        }
                    }
                    return;
                }
                #endregion
            }
            #endregion
        }
    }
Example #15
0
 void Awake()
 {
     InvCraft = FindObjectOfType(typeof(CraftUI)) as CraftUI;
 }