/// <summary> /// Tries to set new content to this socket. /// If <paramref name="content"/>'s key matches one of keys in this socket, /// returns true and set content. If not, returns false. /// If <paramref name="force"/> is true, set this content no matter what key it has. /// </summary> /// <returns><c>true</c>, if content was set, <c>false</c> otherwise.</returns> /// <param name="content">Content.</param> /// <param name="force">If set to <c>true</c> force.</param> public bool SetContent(IDragable content, bool force = false) { bool passed = MatchKey(content); if (passed || force) { DragSocket otherSocket = content.GetSocket(); if (otherSocket != null) { otherSocket.ResetContent(); // If this socket already have content, exchange content with given content's socket. if (this.content != null) { if (!otherSocket.SetContent((IDragable)this.content)) { otherSocket.SetContent(content, true); return(false); // If setting socket is failed, return false. } components.Clear(); } } if (components.Count > 0) { return(false); } components.Add((GUIComponent)content); content.ChangeSocket(this); return(true); } return(false); }
private void SetItems() { for (int row = 0; row < Player.ITEM_HEIGHT; row++) { for (int col = 0; col < Player.ITEM_WIDTH; col++) { Item item = player.items[row, col]; DragSocket socket = itemGroup.GetSocket(col + row * Player.ITEM_WIDTH); if (item != null && socket.content == null) { socket.SetContent(new ItemIcon(item.name, socket, 0, 0, item)); } if (item == null && socket.content != null) { socket.ResetContent(); } } } }