private bool TryHandleDisconectOnSubsystem(ComponentEntityTuple <Subsystem, ItemStorage> subsystemTuple,
                                                   ComponentEntityTuple <Player, ItemStorage, CurrentLocation> playerTuple,
                                                   InventoryItemContainer inventoryItemContainer)
        {
            if (subsystemTuple.Component2.TryGetEmptyContainer(out var emptyContainer, out var containerIndex))
            {
                #region copied from DropItemCommandHandler
                // TODO: this should be replaced with an intent based approach, the command handler should abstract through the intent as well

                if (_itemMatcherGroup.TryGetMatchingEntity(inventoryItemContainer.Item.Value, out var itemTuple) &&
                    playerTuple.Component3.Value.HasValue &&
                    itemTuple.Component2.Value == playerTuple.Entity.Id)
                {
                    var inventory = playerTuple.Component2.Items[0] as InventoryItemContainer;
                    var target    = subsystemTuple.Component2.Items[containerIndex];
                    if (inventory != null &&
                        inventory.Item == itemTuple.Entity.Id &&
                        target != null &&
                        target.CanCapture(itemTuple.Entity.Id))
                    {
                        target.Item = itemTuple.Entity.Id;
                        itemTuple.Component3.Value = subsystemTuple.Entity.Id;
                        inventory.Item             = null;
                        itemTuple.Component2.Value = null;
                        return(true);
                    }
                }
                #endregion
            }
            return(false);
        }
Esempio n. 2
0
    /// <summary>
    /// Populates the data with a lot of records
    /// </summary>
    private void LoadData()
    {
        int RowCount = COLUMN;

        _data = new List <InventoryItemContainer>();

        int j = 0;
        int m = itemDatas.Count % RowCount;
        int n = itemDatas.Count / RowCount;

        if (m > 0)
        {
            n += 1;
        }

        for (var i = 0; i < n + 1; i++)
        {
            var masterData = new InventoryItemContainer()
            {
                normalizedScrollPosition = 0,
                childData = new List <ItemResource>()
            };
            _data.Add(masterData);

            for (; j < (RowCount * (i + 1)) && j < itemDatas.Count; j++)
            {
                masterData.childData.Add(itemDatas[j]);
            }
        }
        // tell the scroller to reload now that we have the data
        masterScroller.GetComponent <ScrollRect>().verticalNormalizedPosition = 0;
        ReloadData();
    }
Esempio n. 3
0
    private void UpdateData()
    {
        _data.Clear();

        int RowCount = COLUMN;
        int m        = itemDatas.Count % RowCount;
        int n        = itemDatas.Count / RowCount;

        if (m > 0)
        {
            n += 1;
        }

        int j = 0;

        for (var i = 0; i < n + 1; i++)
        {
            var masterData = new InventoryItemContainer()
            {
                normalizedScrollPosition = 0,
                childData = new List <ItemResource>()
            };
            _data.Add(masterData);

            for (; j < (RowCount * (i + 1)) && j < itemDatas.Count; j++)
            {
                masterData.childData.Add(itemDatas[j]);
            }
        }
    }
Esempio n. 4
0
    public void SetData(InventoryItemContainer data, Action <ItemResource> OnRightClickEvent)
    {
        // set up delegates and callbacks
        this.OnRightClickEvent          = OnRightClickEvent;
        detailScroller.Delegate         = this;
        detailScroller.scrollerScrolled = ScrollerScrolled;

        // assign data and flag that the detail scroller needs to be reloaded.
        // we have to reload on the next frame through the update so that the
        // main scroller has time to set up the master cell views first.
        _data = data;
        reloadDataNextFrame = true;
    }