Exemplo n.º 1
0
        public override void Update()
        {
            if (m_inventory == null || DragHostWidget == null)
            {
                return;
            }
            WidgetInput     input      = base.Input;
            ComponentPlayer viewPlayer = GetViewPlayer();
            int             slotValue  = m_inventory.GetSlotValue(m_slotIndex);
            int             num        = Terrain.ExtractContents(slotValue);
            Block           block      = BlocksManager.Blocks[num];

            if (m_componentPlayer != null)
            {
                m_blockIconWidget.DrawBlockEnvironmentData.InWorldMatrix = m_componentPlayer.ComponentBody.Matrix;
            }
            if (m_focus && !input.Press.HasValue)
            {
                m_focus = false;
            }
            else if (input.Tap.HasValue && HitTestGlobal(input.Tap.Value) == this)
            {
                m_focus = true;
            }
            if (input.SpecialClick.HasValue && HitTestGlobal(input.SpecialClick.Value.Start) == this && HitTestGlobal(input.SpecialClick.Value.End) == this)
            {
                IInventory inventory = null;
                foreach (InventorySlotWidget item in ((ContainerWidget)base.RootWidget).AllChildren.OfType <InventorySlotWidget>())
                {
                    if (item.m_inventory != null && item.m_inventory != m_inventory && item.Input == base.Input && item.IsEnabledGlobal && item.IsVisibleGlobal)
                    {
                        inventory = item.m_inventory;
                        break;
                    }
                }
                if (inventory != null)
                {
                    int num2 = ComponentInventoryBase.FindAcquireSlotForItem(inventory, slotValue);
                    if (num2 >= 0)
                    {
                        HandleMoveItem(m_inventory, m_slotIndex, inventory, num2, m_inventory.GetSlotCount(m_slotIndex));
                    }
                }
            }
            if (input.Click.HasValue && HitTestGlobal(input.Click.Value.Start) == this && HitTestGlobal(input.Click.Value.End) == this)
            {
                bool flag = false;
                if (viewPlayer != null)
                {
                    if (viewPlayer.ComponentInput.SplitSourceInventory == m_inventory && viewPlayer.ComponentInput.SplitSourceSlotIndex == m_slotIndex)
                    {
                        viewPlayer.ComponentInput.SetSplitSourceInventoryAndSlot(null, -1);
                        flag = true;
                    }
                    else if (viewPlayer.ComponentInput.SplitSourceInventory != null)
                    {
                        flag = HandleMoveItem(viewPlayer.ComponentInput.SplitSourceInventory, viewPlayer.ComponentInput.SplitSourceSlotIndex, m_inventory, m_slotIndex, 1);
                        AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
                    }
                }
                if (!flag && m_inventory.ActiveSlotIndex != m_slotIndex && m_slotIndex < 10)
                {
                    m_inventory.ActiveSlotIndex = m_slotIndex;
                    if (m_inventory.ActiveSlotIndex == m_slotIndex)
                    {
                        AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
                    }
                }
            }
            if (!m_focus || ProcessingOnly || viewPlayer == null)
            {
                return;
            }
            Vector2?hold = input.Hold;

            if (hold.HasValue && HitTestGlobal(hold.Value) == this && !DragHostWidget.IsDragInProgress && m_inventory.GetSlotCount(m_slotIndex) > 0 && (viewPlayer.ComponentInput.SplitSourceInventory != m_inventory || viewPlayer.ComponentInput.SplitSourceSlotIndex != m_slotIndex))
            {
                input.Clear();
                viewPlayer.ComponentInput.SetSplitSourceInventoryAndSlot(m_inventory, m_slotIndex);
                AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
            }
            Vector2?drag = input.Drag;

            if (!drag.HasValue || HitTestGlobal(drag.Value) != this || DragHostWidget.IsDragInProgress)
            {
                return;
            }
            int slotCount = m_inventory.GetSlotCount(m_slotIndex);

            if (slotCount > 0)
            {
                DragMode dragMode = input.DragMode;
                if (viewPlayer.ComponentInput.SplitSourceInventory == m_inventory && viewPlayer.ComponentInput.SplitSourceSlotIndex == m_slotIndex)
                {
                    dragMode = DragMode.SingleItem;
                }
                int num3 = (dragMode != 0) ? 1 : slotCount;
                SubsystemTerrain subsystemTerrain = m_inventory.Project.FindSubsystem <SubsystemTerrain>();
                ContainerWidget  containerWidget  = (ContainerWidget)Widget.LoadWidget(null, ContentManager.Get <XElement>("Widgets/InventoryDragWidget"), null);
                containerWidget.Children.Find <BlockIconWidget>("InventoryDragWidget.Icon").Value = Terrain.ReplaceLight(slotValue, 15);
                containerWidget.Children.Find <BlockIconWidget>("InventoryDragWidget.Icon").DrawBlockEnvironmentData.SubsystemTerrain = subsystemTerrain;
                containerWidget.Children.Find <LabelWidget>("InventoryDragWidget.Name").Text       = block.GetDisplayName(subsystemTerrain, slotValue);
                containerWidget.Children.Find <LabelWidget>("InventoryDragWidget.Count").Text      = num3.ToString();
                containerWidget.Children.Find <LabelWidget>("InventoryDragWidget.Count").IsVisible = (!(m_inventory is ComponentCreativeInventory) && !(m_inventory is ComponentFurnitureInventory));
                DragHostWidget.BeginDrag(containerWidget, new InventoryDragData
                {
                    Inventory = m_inventory,
                    SlotIndex = m_slotIndex,
                    DragMode  = dragMode
                }, delegate
                {
                    m_dragMode = null;
                });
                m_dragMode = dragMode;
            }
        }