示例#1
0
        private void StartDraggingItem(SlotButton button)
        {
            myDraggingItem        = true;
            myDragOriginButton    = button;
            myDraggedItem         = button.Slot.Item;
            myDragCount           = button.Slot.Count;
            myDragSprite          = new UISprite(myDraggedItem.ItemSprite);
            myDragSprite.Position = MousePosition - myDragSprite.Size * 0.5f - new Vector2(PaddingLeft, PaddingTop);
            AddChild(myDragSprite);

            button.Slot.Clear();

            foreach (SlotButton btn in myPlayerView.Slots)
            {
                btn.Enable();
            }

            if (myEntityView != null)
            {
                foreach (SlotButton btn in myEntityView.Slots)
                {
                    btn.Enable();
                }
            }
        }
示例#2
0
 /// <summary>
 /// 加载背包中物品中的信息
 /// </summary>
 private void LoadSlot()
 {
     for (int i = 0; i < slotsList.Count; i++)
     {
         SlotButton sb = (SlotButton)UIPackage.CreateObject("BagMenu", "SlotButton");
         sb.SlotInfo  = slotsList[i];
         sb.Item      = ItemManager.Instance.GetItemByID(sb.SlotInfo.ItemID);
         sb.draggable = true;
         sb.data      = i;
         sb.onClick.Add(OnMouseButtonDown);
         sb.onDragStart.Add(OnDragStart);
         sb.onDrop.Add(OnDrop);
         if (sb.Item != null)
         {
             sb.icon = sb.Item.Sprite;
             if (sb.Item.Capacity != 1)
             {
                 sb.title = sb.SlotInfo.ItemCount.ToString();
             }
             sb.tooltips = sb.Item.GetToolTipText();
         }
         else
         {
             sb.tooltips = dToolTips;
         }
         buttonList.Add(sb);
     }
 }
示例#3
0
 private void closeSlotIfNot(SlotButton sb, int slot)
 {
     if (sb.slot != slot)
     {
         sb.close();
     }
 }
示例#4
0
    public void OnSlotsEnter(SlotButton button)
    {
        //Change alpha
        var tempColor = button.background.color;

        tempColor.a             = 0.5f;
        button.background.color = tempColor;
    }
示例#5
0
 public void Subscribe(SlotButton button)
 {
     if (slotButtons == null)
     {
         slotButtons = new List <SlotButton>();
     }
     slotButtons.Add(button);
 }
示例#6
0
    /// <summary>
    /// 开始拖拽
    /// </summary>
    /// <param name="context"></param>
    private void OnDragStart(EventContext context)
    {
        SlotButton sb = (SlotButton)context.sender;

        startSlotId = sb.SlotInfo.SlotID;
        context.PreventDefault();
        //DragDropManager.inst.StartDrag(sb, sb.icon, sb.icon, (int)context.data);
        DragDropManager.inst.StartDrag(sb, sb.icon, sb, (int)context.data);
    }
示例#7
0
	void DisableOtherButtons ( SlotButton slotButton ) {
		for (int i = 0; i < slotButtons.Count; i++) {
			if ( slotButtons[i] != slotButton ) {
				//Debug.Log (slotButtons[i].unit.name);
				slotButtons[i].IsSelected = false;
			}
			
		}
	}
示例#8
0
 /// <summary>
 /// 拖拽释放
 /// </summary>
 /// <param name="context"></param>
 private void OnDrop(EventContext context)
 {
     try
     {
         SlotButton sb = (SlotButton)context.sender;
         if (sb.Item == null)
         {
             //对当前格子进行赋值
             sb.Item               = buttonList[startSlotId].Item;
             sb.SlotInfo.ItemID    = buttonList[startSlotId].SlotInfo.ItemID;
             sb.SlotInfo.ItemCount = buttonList[startSlotId].SlotInfo.ItemCount;
             //对格子的显示属性赋值
             sb.title    = buttonList[startSlotId].title;
             sb.icon     = (string)context.data;
             sb.tooltips = buttonList[startSlotId].tooltips;
             //置空原始格子
             buttonList[startSlotId].Item               = null;
             buttonList[startSlotId].SlotInfo.ItemID    = -1;
             buttonList[startSlotId].SlotInfo.ItemCount = 0;
             //清除原始格子的显示属性
             buttonList[startSlotId].icon     = null;
             buttonList[startSlotId].title    = "";
             buttonList[startSlotId].tooltips = dToolTips;
         }
         else
         {
             //创建临时格子
             SlotButton temp = new SlotButton();
             temp.SlotInfo = new SlotInfo();
             //将要当前的格子信息赋值到临时格子
             temp.Item               = sb.Item;
             temp.SlotInfo.ItemID    = sb.SlotInfo.ItemID;
             temp.SlotInfo.ItemCount = sb.SlotInfo.ItemCount;
             temp.title              = sb.title;
             temp.icon               = sb.icon;
             temp.tooltips           = sb.tooltips;
             //将拖拽格子复制到当前格子
             sb.Item               = buttonList[startSlotId].Item;
             sb.SlotInfo.ItemID    = buttonList[startSlotId].SlotInfo.ItemID;
             sb.SlotInfo.ItemCount = buttonList[startSlotId].SlotInfo.ItemCount;
             sb.title              = buttonList[startSlotId].title;
             sb.icon               = buttonList[startSlotId].icon;
             sb.tooltips           = buttonList[startSlotId].tooltips;
             //将临时格子中的信息赋值到拖拽格子
             buttonList[startSlotId].Item               = temp.Item;
             buttonList[startSlotId].SlotInfo.ItemID    = temp.SlotInfo.ItemID;
             buttonList[startSlotId].SlotInfo.ItemCount = temp.SlotInfo.ItemCount;
             buttonList[startSlotId].title              = temp.title;
             buttonList[startSlotId].icon               = temp.icon;
             buttonList[startSlotId].tooltips           = temp.tooltips;
         }
     }
     catch (Exception)
     {
     }
 }
示例#9
0
 void DisableOtherButtons(SlotButton slotButton)
 {
     for (int i = 0; i < slotButtons.Count; i++)
     {
         if (slotButtons[i] != slotButton)
         {
             //Debug.Log (slotButtons[i].unit.name);
             slotButtons[i].IsSelected = false;
         }
     }
 }
示例#10
0
    public void OnSlotsSelected(SlotButton button)
    {
        // Check if selection is the same that actual selected object
        if (selectedSlot == button)
        {
            return;
        }

        selectedSlot = button;
        ResetSlots();
        button.background.sprite = slotActive;
        //Add Observer event
        if (OnSlotSelectedTrigger != null)
        {
            OnSlotSelectedTrigger(button.carEquipmentData);
        }
    }
示例#11
0
    public void ResetSlotsVBox()
    {
        foreach (Node Child in SlotsVBox.GetChildren())
        {
            Child.QueueFree();
        }

        Directory     SaveDir = new Directory();
        List <string> Names   = new List <string>();

        if (SaveDir.DirExists("user://Saves"))
        {
            SaveDir.Open("user://Saves");
            SaveDir.ListDirBegin(skipNavigational: true, skipHidden: true);
            while (true)
            {
                string SaveName = SaveDir.GetNext();
                if (SaveName == "")
                {
                    break;
                }
                Names.Add(SaveName);
            }
            Names.Sort();

            foreach (string Name in Names)
            {
                SlotButton Instanced = SlotButtonScene.Instance() as SlotButton;
                Instanced.HostMenuInstance = this;
                Instanced.Text             = Name;
                SlotsVBox.AddChild(Instanced);
            }
        }

        if (Names.Count <= 0)
        {
            Label Message = LabelPieceScene.Instance() as Label;
            Message.Text = "No saves to load";
            SlotsVBox.AddChild(Message);
        }
    }
示例#12
0
            public ItemInfoView(SlotButton btn)
                : base(new Vector2(192.0f, 128.0f))
            {
                Button = btn;
                Item   = btn.Slot.Item;
                Colour = new Color4(0, 0, 0, 223);

                UILabel name = new UILabel(Font.Large, 1.5f)
                {
                    Colour    = Color4.White,
                    Text      = Item.ItemName,
                    Position  = new Vector2(4.0f, 4.0f),
                    WrapWidth = 184.0f
                };

                AddChild(name);

                UILabel value = new UILabel(Font.Large, 1.0f)
                {
                    Colour   = new Color4(191, 191, 191, 255),
                    Text     = "Value: " + Item.ItemValue.ToString(),
                    Position = new Vector2(4.0f, name.Position.Y + name.Height + 4.0f)
                };

                AddChild(value);

                UILabel desc = new UILabel(Font.Large, 1.0f)
                {
                    Colour    = new Color4(191, 191, 191, 255),
                    Text      = Item.ItemDescription,
                    Position  = new Vector2(4.0f, value.Position.Y + value.Height + 4.0f),
                    WrapWidth = 184.0f
                };

                AddChild(desc);

                Height = name.Height + value.Height + desc.Height + 16.0f;

                Disable();
            }
示例#13
0
        private void StopDraggingItem(SlotButton button)
        {
            myDragOriginButton.Slot.Item  = myDraggedItem;
            myDragOriginButton.Slot.Count = myDragCount;

            RemoveChild(myDragSprite);
            myDragSprite = null;

            if (myDragOriginButton != button)
            {
                myDraggingItem = false;

                button.Slot.Swap(myDragOriginButton.Slot);

                InventorySingleView invViewA = myDragOriginButton.Parent as InventorySingleView;
                InventorySingleView invViewB = button.Parent as InventorySingleView;

                GameClient.SendTransferItem(invViewA.Inventory.Owner, invViewB.Inventory.Owner, myDragOriginButton.Slot, button.Slot);
            }

            foreach (SlotButton btn in myPlayerView.Slots)
            {
                if (!btn.Slot.HasItem)
                {
                    btn.Disable();
                }
            }

            if (myEntityView != null)
            {
                foreach (SlotButton btn in myEntityView.Slots)
                {
                    if (!btn.Slot.HasItem)
                    {
                        btn.Disable();
                    }
                }
            }
        }
示例#14
0
            public InventorySingleView(InventoryView parent, Inventory inventory, Vector2 size)
                : base(size)
            {
                myInventoryView = parent;

                Inventory = inventory;

                mySlots = new SlotButton[Inventory.Capacity];

                InventorySlot[] slots = Inventory.Slots;

                int x = 0, y = 0;
                int cols = (int)((size.X - 4.0f) / 44.0f);

                for (int i = 0; i < mySlots.Length; ++i)
                {
                    SlotButton btn = new SlotButton(slots[i])
                    {
                        Position = new Vector2(x * 44.0f + 4.0f, y * 44.0f + 4.0f)
                    };
                    mySlots[i] = btn;

                    btn.Click += delegate(object sender, MouseButtonEventArgs e)
                    {
                        if (SlotButtonClicked != null)
                        {
                            SlotButtonClicked(sender, new SlotButtonClickedEventArgs(Inventory, (sender as SlotButton).Slot));
                        }
                    };

                    btn.MouseUp += delegate(object sender, MouseButtonEventArgs e)
                    {
                        if (myInventoryView.IsDraggingItem)
                        {
                            myInventoryView.StopDraggingItem(btn);
                        }
                    };

                    btn.MouseEnter += delegate(object sender, MouseMoveEventArgs e)
                    {
                        if (btn.Slot.HasItem && !myInventoryView.IsDraggingItem && (ItemView == null || ItemView.Item != btn.Slot.Item))
                        {
                            if (ItemView != null)
                            {
                                Parent.RemoveChild(ItemView);
                            }

                            ItemView          = new ItemInfoView(btn);
                            ItemView.Flipped  = Parent.Parent.MousePosition.X + 224.0f > Parent.Parent.InnerWidth;
                            ItemView.Position = Parent.MousePosition + new Vector2(ItemView.Flipped ? -208.0f : 16.0f, 0.0f);
                            Parent.AddChild(ItemView);
                        }
                    };

                    btn.MouseMove += delegate(object sender, MouseMoveEventArgs e)
                    {
                        if (btn.Slot.HasItem && ItemView != null && ItemView.Item == btn.Slot.Item)
                        {
                            ItemView.Flipped  = Parent.Parent.MousePosition.X + 224.0f > Parent.Parent.InnerWidth;
                            ItemView.Position = Parent.MousePosition + new Vector2(ItemView.Flipped ? -208.0f : 16.0f, 0.0f);
                        }
                    };

                    btn.MouseLeave += delegate(object sender, MouseMoveEventArgs e)
                    {
                        if (btn.Slot.HasItem && ItemView != null && ItemView.Item == btn.Slot.Item)
                        {
                            Parent.RemoveChild(ItemView);
                            ItemView = null;
                        }

                        if (btn.MouseButtonPressed && btn.Slot.HasItem)
                        {
                            myInventoryView.StartDraggingItem(btn);
                        }
                    };

                    btn.Slot.SlotContentsChanged += delegate(object sender, EventArgs e)
                    {
                        if (ItemView != null && ItemView.Button == btn && btn.Slot.Item != ItemView.Item)
                        {
                            Parent.RemoveChild(ItemView);
                            ItemView = null;

                            if (btn.IsEnabled && btn.Slot.HasItem)
                            {
                                ItemView          = new ItemInfoView(btn);
                                ItemView.Flipped  = Parent.Parent.MousePosition.X + 224.0f > Parent.Parent.InnerWidth;
                                ItemView.Position = Parent.MousePosition + new Vector2(ItemView.Flipped ? -208.0f : 16.0f, 0.0f);
                                Parent.AddChild(ItemView);
                            }
                        }
                    };

                    AddChild(btn);

                    ++x;
                    if (x >= cols)
                    {
                        x = 0;
                        ++y;
                    }
                }
            }
示例#15
0
 public void Display(SlotButton slotButton)
 {
     slotButton.SetItemImage(Sprite);
 }
示例#16
0
 void ISlotButtonHandler.Handle(SlotButton button)
 {
 }
示例#17
0
 public void OnSlotsExit(SlotButton button)
 {
     ResetSlots();
 }
示例#18
0
 void ISlotButtonHandler.Handle(SlotButton button)
 {
     Interact(Structs.IndexOf(slots, button));
 }