Example #1
0
    private void UpdateInventory(Inventory inventory)
    {
        Debug.Log("InventoryExample UpdateInventory ");

        for (int x = 0; x < MAX_COLS; x++)
        {
            for (int y = 0; y < MAX_ROWS; y++)
            {
                cellArray[x, y].GetComponent <CellLogic>().isOccupied = false;
            }
        }

        for (int i = 0; i < interfaceItems.Count; i++)
        {
            Destroy(interfaceItems[i]);
        }

        interfaceItems = new List <GameObject>();

        for (int i = 0; i < inventory.items.Count; i++)
        {
            GameObject         interfaceItem = (GameObject)Instantiate(Resources.Load("ColorPrefab"));
            ColorInventoryItem inventoryItem = inventory.items[i];
            interfaceItem.transform.SetParent(anchor.transform);
            interfaceItem.transform.position = cellArray[inventoryItem.x, inventoryItem.y].transform.position;
            cellArray[inventoryItem.x, inventoryItem.y].GetComponent <CellLogic>().isOccupied = true;
            interfaceItem.GetComponent <CanvasRenderer>().SetColor(inventoryItem.color);
            interfaceItem.GetComponent <UserInterfaceItem>().cell = cellArray[inventoryItem.x, inventoryItem.y].GetComponent <CellLogic>();
            interfaceItems.Add(interfaceItem);
        }
    }
Example #2
0
    //work both for single change of position and for swipe between 2 items
    internal static void ChangePosition(int x1, int y1, int x2, int y2, Callback callback)
    {
        ColorInventoryItem item1 = null;
        ColorInventoryItem item2 = null;

        foreach (var item in inventory.items)
        {
            if (item.x == x1 && item.y == y1)
            {
                item1 = item;
                continue;
            }
            if (item.x == x2 && item.y == y2)
            {
                item2 = item;
                continue;
            }
        }
        if (item1 != null)
        {
            item1.x = x2;
            item1.y = y2;
        }
        if (item2 != null)
        {
            item2.x = x1;
            item2.y = y1;
        }
        SaveToFile();
        callback(inventory);
    }
Example #3
0
    /// <summary>
    /// Add new element into data collection
    /// </summary>
    public void Add(IColorInventoryItem inventoryItem)
    {
        if (inventoryItem is ColorInventoryItem == false)
        {
            Debug.LogError("wrong type, Need 'ColorInventoryItem'");
            return;
        }

        ColorInventoryItem colorInventoryItem = (inventoryItem as ColorInventoryItem);

        colorInventorySystemData.items.Add(colorInventoryItem);
    }
Example #4
0
    /// <summary>
    /// use through button
    /// </summary>
    public void OnRemove()
    {
        if (!Initialized)
        {
            Debug.LogError("Need Init");
            return;
        }

        if (SelectedColorInventoryItem == null)
        {
            return;
        }

        colorInventorySystem.Remove(SelectedColorInventoryItem);
        SelectedColorInventoryItem = null;
    }
Example #5
0
    /// <summary>
    /// use through action, when user opens pickColorPanel and choose color, create new item and add into data collection
    /// </summary>
    private void OnSetColorAndCreate(Color color)
    {
        if (!Initialized)
        {
            Debug.LogError("Need Init");
            return;
        }

        var colorSystemItem = new ColorInventoryItem(color);

        colorSystemItem.Init(colorSystemItemPrefab, inventoryPanel);

        colorInventorySystem.Add(colorSystemItem);

        SelectedColorInventoryItem = colorSystemItem;
        SelectedColorInventoryItem.colorInventoryItemComponent.Select(true);
    }
Example #6
0
    /// <summary>
    /// remove element from data collection
    /// </summary>
    public void Remove(IColorInventoryItem inventoryItem)
    {
        if (inventoryItem is ColorInventoryItem == false)
        {
            Debug.LogError("wrong type, Need 'ColorInventoryItem'");
            return;
        }

        ColorInventoryItem colorInventoryItem = (inventoryItem as ColorInventoryItem);

        if (colorInventorySystemData.items.Contains(colorInventoryItem) == false)
        {
            Debug.LogWarning("system doen't contains this item");
            return;
        }

        colorInventorySystemData.items.Remove(colorInventoryItem);
        colorInventoryItem.SelfDestroy();
    }
Example #7
0
    private static void DropToCellLogic()
    {
        Debug.Log("DropToCellLogic");
        Debug.Log("draggingItem.isNew " + draggingItem.isNew);
        Debug.Log("dropCell.isDeleteCell " + dropCell.isDeleteCell);

        if (draggingItem.isNew)
        {
            if (dropCell.isDeleteCell)
            {
                MoveItemBack();
            }
            else if (dropCell.isOccupied)
            {
                Debug.Log("Can't exchange position with new ");
            }
            else
            {
                ColorInventoryItem item = new ColorInventoryItem();
                item.color = GetColorFromSliders();
                item.x     = dropCell.x;
                item.y     = dropCell.y;
                APIInventory.AddElement(item, callback);
                Destroy(draggingItem.gameObject);
                GenerateNewColorItem();
            }
        }
        else
        {
            if (dropCell.isDeleteCell)
            {
                APIInventory.DeleteElement(draggingItem.cell.x, draggingItem.cell.y, callback);
                Destroy(draggingItem.gameObject);
            }
            else
            {
                APIInventory.ChangePosition(draggingItem.cell.x, draggingItem.cell.y, dropCell.x, dropCell.y, callback);
                Destroy(draggingItem.gameObject);
            }
        }
    }
Example #8
0
 /// <summary>
 /// set item color
 /// </summary>
 public void Modify(ColorInventoryItem colorInventoryItem, Color color)
 {
     colorInventoryItem.SetColor(color);
 }
Example #9
0
 private void OnColorInventoryItemComponentSelect(ColorInventoryItemComponent colorInventoryItemComponent)
 {
     SelectedColorInventoryItem = colorInventoryItemComponent.colorInventoryItem;
 }
Example #10
0
 public static void AddElement(ColorInventoryItem item, Callback callback)
 {
     inventory.items.Add(item);
     SaveToFile();
     callback(inventory);
 }
 public void Init(ColorInventoryItem colorInventoryItem)
 {
     this.colorInventoryItem = colorInventoryItem;
 }