示例#1
0
        protected override void OnSlotAdd(ItemSlotManager manager)
        {
            manager.onMainAction += () =>
            {
                ReturnSlot(manager.slot);
                manager.Hovered = false;
            };

            manager.onHovered += () =>
            {
                HoveredSlot(manager.slot);
            };

            manager.onUnfocus += () =>
            {
                UnhoveredSlot(manager.slot);
            };
        }
示例#2
0
        public void Unhover()
        {
            if (!Hovered)
            {
                return;
            }

            Hovered = false;

            if (CurrentlyHovered == this)
            {
                CurrentlyHovered = null;
            }

            if (onUnfocus != null)
            {
                onUnfocus();
            }
        }
        private void SlotRemoveCallback(ItemSlot slot)
        {
            for (int i = 0; i < managers.Count; i++)
            {
                ItemSlotManager manager = managers[i];

                if (manager.slot == slot)
                {
                    manager.Detatch();
                    Destroy(manager.gameObject);
                    managers.RemoveAt(i);

                    OnSlotRemove(manager);

                    return;
                }
            }

            filterDirty = true;
        }
示例#4
0
        public override void Setup(Inventory inventory)
        {
            if (current != null)
            {
                return;
            }

            current = inventory;

            managers = new List <ItemSlotManager> (current.Size);

            for (int i = 0; i < current.Items.Count; i++)
            {
                ItemSlot        slot    = current.Items[i];
                ItemSlotManager manager = Slots[i];

                manager.Setup(slot);
                OnSlotAdd(manager);
            }
        }
示例#5
0
        private void Update()
        {
            transform.position = mouse.ScreenToCanvas(Input.mousePosition);

            if (dragState == DragState.None)
            {
                if (Input.GetMouseButtonDown(0) && ItemSlotManager.CurrentlyHovered != null &&
                    ItemSlotManager.CurrentlyHovered.slot != null &&
                    ItemSlotManager.CurrentlyHovered.slot.Item != null)
                {
                    dragState         = DragState.Potential;
                    dragStartPosition = transform.position;

                    startSlot = ItemSlotManager.CurrentlyHovered;
                    startSlot.slotRenderer.Faded = true;
                }
            }

            if (dragState == DragState.Potential)
            {
                if (!EnableClickDrag && Input.GetMouseButtonUp(0))
                {
                    dragState = DragState.None;
                    ghost.gameObject.SetActive(false);
                    ghost.RenderSlot(null);
                    startSlot.slotRenderer.Faded = false;
                    startSlot = null;
                }
                else if (Vector3.Distance(dragStartPosition, Input.mousePosition) > dragThreshhold)
                {
                    dragState = DragState.Dragging;

                    if (startSlot.slot.Item.template.StartDrag != null)
                    {
                        AudioManager.Play(startSlot.slot.Item.template.StartDrag);
                    }

                    if (positioner == DragPositioner.Offset)
                    {
                        var originalPosition = transform.position;
                        transform.position = dragStartPosition;

                        ghost.RenderSlot(startSlot.slot);
                        ghost.transform.position = startSlot.transform.position;

                        transform.position = originalPosition;
                    }
                    else if (positioner == DragPositioner.Fixed)
                    {
                        ghost.RenderSlot(startSlot.slot);
                        ghost.transform.localPosition = Vector3.zero;
                    }

                    ghost.gameObject.SetActive(true);

                    // TODO: Tell Item Slot to fade out
                }
                else
                {
                    return;
                }
            }

            if (dragState == DragState.Dragging)
            {
                if (lastHoveringSlot != ItemSlotManager.CurrentlyHovered)
                {
                    if (lastHoveringSlot != null)
                    {
                        lastHoveringSlot.slotRenderer.Faded = false;
                    }

                    lastHoveringSlot = ItemSlotManager.CurrentlyHovered;

                    if (lastHoveringSlot != null)
                    {
                        if (lastHoveringSlot.slot.IsValid(startSlot.slot.Item))
                        {
                            lastHoveringSlot.slotRenderer.Faded = true;
                        }
                    }
                }

                if (Input.GetMouseButtonUp(0))
                {
                    dragState = DragState.None;
                    ghost.gameObject.SetActive(false);
                    ghost.RenderSlot(null);

                    if (startSlot.slot.Item.template.EndDrag != null)
                    {
                        AudioManager.Play(startSlot.slot.Item.template.EndDrag);
                    }

                    if (ItemSlotManager.CurrentlyHovered == null)
                    {
                    }
                    else if (ItemSlotManager.CurrentlyHovered != null)
                    {
                        var endSlot = ItemSlotManager.CurrentlyHovered;

                        endSlot.slot.Swap(startSlot.slot);
                    }

                    startSlot.slotRenderer.Faded = false;
                    startSlot = null;
                }
            }
        }
示例#6
0
 protected override void OnSlotRemove(ItemSlotManager slot)
 {
 }
示例#7
0
 protected virtual void OnSlotRemove(ItemSlotManager slot)
 {
 }
示例#8
0
 protected virtual void OnSlotAdd(ItemSlotManager slot)
 {
 }
        public void Filter(SortingMode mode, ItemCondition[] Filters)
        {
            lastSorting = mode;
            LastFilters = Filters;

            sorted = new List <ItemSlot> ();

            for (int i = 0; i < current.Items.Count; i++)
            {
                ItemSlot slot = current.Items[i];

                if (HideEmpty && slot.Item == null)
                {
                    continue;
                }

                if (Filters == null)
                {
                    sorted.Add(slot);
                    continue;
                }

                if (Filters.IsValid(slot.Item))
                {
                    sorted.Add(slot);
                }
            }

            if (mode == SortingMode.Name)
            {
                sorted.Sort(NameComparison);
            }
            else if (mode == SortingMode.Type)
            {
                sorted.Sort(TypeComparison);
            }

            for (int i = 0; i < managers.Count; i++)
            {
                ItemSlotManager manager = managers[i];

                if (EventSystem.current.currentSelectedGameObject == manager.gameObject)
                {
                    EventSystem.current.SetSelectedGameObject(null);
                }
                manager.Detatch();
                manager.gameObject.SetActive(false);
            }

            for (int i = 0; i < sorted.Count; i++)
            {
                ItemSlotManager manager = managers[i];

                manager.gameObject.SetActive(true);

                manager.Setup(sorted[i]);

                /*if (i == 0)
                 * {
                 * EventSystem.current.SetSelectedGameObject(manager.gameObject);
                 * var pointer = new PointerEventData(EventSystem.current);
                 * //ExecuteEvents.Execute(manager.gameObject, pointer, ExecuteEvents.pointerEnterHandler);
                 * //ExecuteEvents.Execute(manager.gameObject, pointer, ExecuteEvents.selectHandler);
                 * }*/
            }

            filterDirty = false;
        }