コード例 #1
0
        public override void OnFileDropped(DirectoryItemViewModel file)
        {
            if (file != null && !AllItems.Contains(file))
            {
                //Move the asset file into this folder
                var fileParent = file.Parent;

                string newFilePath = $"{FullPath}{Path.DirectorySeparatorChar}{file.Name}";

                if (file is FileViewModel fileVm)
                {
                    File.Move(file.FullPath, newFilePath);

                    fileParent.RemoveItem(fileVm);
                    AddItem(fileVm);
                }
                else if (file is FolderViewModel folderVm)
                {
                    Directory.Move(file.FullPath, newFilePath);

                    fileParent.RemoveItem(folderVm);
                    AddItem(folderVm);
                }
                else
                {
                    Debug.Assert(false, "Unknown directory item");
                }

                file.Parent = this;
            }
        }
コード例 #2
0
        public MenuItem AppendSubMenuItem(MenuItem parent, string label, EventHandler selectedHandler)
        {
            if (menuContainer != null)
            {
                throw new Exception("HUDRadialMenu cannot call AppendSubMenuItem after Create");
            }
            if (AllItems.Contains(parent) == false)
            {
                throw new Exception("HUDRadialMenu does not contain this MenuItem with label " + parent.Label);
            }

            MenuItem i = new MenuItem()
            {
                Label = label
            };

            i.OnSelected += selectedHandler;
            if (parent.SubItems == null)
            {
                parent.SubItems = new List <MenuItem>();
            }
            parent.SubItems.Add(i);
            i.ParentItem = parent;
            AllItems.Add(i);
            return(i);
        }
コード例 #3
0
 public void AddItem()
 {
     if (!string.IsNullOrEmpty(ItemToAdd) && !AllItems.Contains(ItemToAdd))
     {
         AllItems.Add(ItemToAdd);
     }
     ItemToAdd = "";
 }
コード例 #4
0
        /// <summary>
        /// Updates the selection bounds on the designer
        /// </summary>
        internal void UpdateDesignerSelectedBounds()
        {
            designerSelectedBounds = Rectangle.Empty;

            if (RibbonInDesignMode)
            {
                RibbonItem item = RibbonDesigner.Current.SelectedElement as RibbonItem;

                if (item != null && AllItems.Contains(item))
                {
                    designerSelectedBounds = item.Bounds;
                }
            }
        }
コード例 #5
0
 public bool Contains(TEntity item) => AllItems.Contains(item);
コード例 #6
0
ファイル: KmlNode.cs プロジェクト: tophyr/KML
        /// <summary>
        /// Adds (inserts before) a child KmlItem to this nodes lists of children.
        /// If item to insert before is null or not contained, it will be added at the end.
        /// This is the basic add method, derived classes can override but should
        /// always call base.Add(beforeItem, newItem) within.
        /// Public Add, AddRange, InsertBefore and InsertAfter all use this protected
        /// method to access the lists.
        /// <see cref="KML.KmlNode.Add(KML.KmlItem)"/>
        /// </summary>
        /// <param name="beforeItem">The KmlItem where the new item should be inserted before</param>
        /// <param name="newItem">The KmlItem to add</param>
        protected virtual void Add(KmlItem beforeItem, KmlItem newItem)
        {
            // ensure that item.Parent is this node
            if (newItem.Parent != this)
            {
                RemapParent(newItem, this);
            }

            // Not add always to end of AllItems, add well ordered: attribs first, then nodes.
            // Like Add(attrib), Add(Node), Add(attrib) should result in attrib, attrib, node
            if (newItem is KmlAttrib && !(beforeItem is KmlAttrib) && Children.Count > 0)
            {
                Syntax.Warning(newItem, "KML attribute should not come after nodes, will be fixed when saved");
                beforeItem = Children[0];
            }

            if (beforeItem != null && AllItems.Contains(beforeItem))
            {
                AllItems.Insert(AllItems.IndexOf(beforeItem), newItem);
            }
            else
            {
                AllItems.Add(newItem);
            }

            if (newItem is KmlNode)
            {
                if (beforeItem is KmlNode && Children.Contains((KmlNode)beforeItem))
                {
                    Children.Insert(Children.IndexOf((KmlNode)beforeItem), (KmlNode)newItem);
                }
                else
                {
                    Children.Add((KmlNode)newItem);
                }
                InvokeChildrenChanged();
            }
            else if (newItem is KmlAttrib)
            {
                KmlAttrib attrib = (KmlAttrib)newItem;
                if (attrib.Name.ToLower() == "name")
                {
                    if (Name.Length == 0)
                    {
                        Name = attrib.Value;

                        // Get notified when Name changes
                        attrib.AttribValueChanged += Name_Changed;
                        attrib.CanBeDeleted        = false;

                        // And notify that the name changed
                        InvokeToStringChanged();
                    }
                }

                if (beforeItem is KmlAttrib && Attribs.Contains((KmlAttrib)beforeItem))
                {
                    Attribs.Insert(Attribs.IndexOf((KmlAttrib)beforeItem), attrib);
                }
                else
                {
                    Attribs.Add(attrib);
                }
                InvokeAttribChanged();
            }
            else
            {
                if (beforeItem != null && Unknown.Contains(newItem))
                {
                    Unknown.Insert(Unknown.IndexOf(beforeItem), newItem);
                }
                else
                {
                    Unknown.Add(newItem);
                }
                Syntax.Warning(this, "Unknown line in persistence file: " + newItem.ToString());
            }
        }
コード例 #7
0
        public void ServerRead(ClientNetObject type, IReadMessage msg, Client c)
        {
            List <Item> prevItems = new List <Item>(AllItems.Distinct());

            byte slotCount = msg.ReadByte();

            List <ushort>[] newItemIDs = new List <ushort> [slotCount];
            for (int i = 0; i < slotCount; i++)
            {
                newItemIDs[i] = new List <ushort>();
                int itemCount = msg.ReadRangedInteger(0, MaxStackSize);
                for (int j = 0; j < itemCount; j++)
                {
                    newItemIDs[i].Add(msg.ReadUInt16());
                }
            }

            if (c == null || c.Character == null)
            {
                return;
            }

            bool accessible = c.Character.CanAccessInventory(this);

            if (this is CharacterInventory characterInventory && accessible)
            {
                if (Owner == null || !(Owner is Character ownerCharacter))
                {
                    accessible = false;
                }
                else if (!characterInventory.AccessibleWhenAlive && !ownerCharacter.IsDead)
                {
                    accessible = false;
                }
            }

            if (!accessible)
            {
                //create a network event to correct the client's inventory state
                //otherwise they may have an item in their inventory they shouldn't have been able to pick up,
                //and receiving an event for that inventory later will cause the item to be dropped
                CreateNetworkEvent();
                for (int i = 0; i < capacity; i++)
                {
                    foreach (ushort id in newItemIDs[i])
                    {
                        if (!(Entity.FindEntityByID(id) is Item item))
                        {
                            continue;
                        }
                        item.PositionUpdateInterval = 0.0f;
                        if (item.ParentInventory != null && item.ParentInventory != this)
                        {
                            item.ParentInventory.CreateNetworkEvent();
                        }
                    }
                }
                return;
            }

            List <Inventory> prevItemInventories = new List <Inventory>()
            {
                this
            };

            for (int i = 0; i < capacity; i++)
            {
                foreach (Item item in slots[i].Items.ToList())
                {
                    if (!newItemIDs[i].Contains(item.ID))
                    {
                        Item   droppedItem = item;
                        Entity prevOwner   = Owner;
                        droppedItem.Drop(null);

                        var previousInventory = prevOwner switch
                        {
                            Item itemInventory => (itemInventory.FindParentInventory(inventory => inventory is CharacterInventory) as CharacterInventory),
                            Character character => character.Inventory,
                            _ => null
                        };

                        if (previousInventory != null && previousInventory != c.Character?.Inventory)
                        {
                            GameMain.Server?.KarmaManager.OnItemTakenFromPlayer(previousInventory, c, droppedItem);
                        }

                        if (droppedItem.body != null && prevOwner != null)
                        {
                            droppedItem.body.SetTransform(prevOwner.SimPosition, 0.0f);
                        }
                    }
                }

                foreach (ushort id in newItemIDs[i])
                {
                    Item newItem = id == 0 ? null : Entity.FindEntityByID(id) as Item;
                    prevItemInventories.Add(newItem?.ParentInventory);
                }
            }

            for (int i = 0; i < capacity; i++)
            {
                foreach (ushort id in newItemIDs[i])
                {
                    if (!(Entity.FindEntityByID(id) is Item item) || slots[i].Contains(item))
                    {
                        continue;
                    }

                    if (GameMain.Server != null)
                    {
                        var holdable = item.GetComponent <Holdable>();
                        if (holdable != null && !holdable.CanBeDeattached())
                        {
                            continue;
                        }

                        if (!prevItems.Contains(item) && !item.CanClientAccess(c))
                        {
    #if DEBUG || UNSTABLE
                            DebugConsole.NewMessage($"Client {c.Name} failed to pick up item \"{item}\" (parent inventory: {(item.ParentInventory?.Owner.ToString() ?? "null")}). No access.", Color.Yellow);
    #endif
                            if (item.body != null && !c.PendingPositionUpdates.Contains(item))
                            {
                                c.PendingPositionUpdates.Enqueue(item);
                            }
                            item.PositionUpdateInterval = 0.0f;
                            continue;
                        }
                    }
                    TryPutItem(item, i, true, true, c.Character, false);
                    for (int j = 0; j < capacity; j++)
                    {
                        if (slots[j].Contains(item) && !newItemIDs[j].Contains(item.ID))
                        {
                            slots[j].RemoveItem(item);
                        }
                    }
                }
            }

            CreateNetworkEvent();
            foreach (Inventory prevInventory in prevItemInventories.Distinct())
            {
                if (prevInventory != this)
                {
                    prevInventory?.CreateNetworkEvent();
                }
            }

            foreach (Item item in AllItems.Distinct())
            {
                if (item == null)
                {
                    continue;
                }
                if (!prevItems.Contains(item))
                {
                    if (Owner == c.Character)
                    {
                        HumanAIController.ItemTaken(item, c.Character);
                        GameServer.Log(GameServer.CharacterLogName(c.Character) + " picked up " + item.Name, ServerLog.MessageType.Inventory);
                    }
                    else
                    {
                        GameServer.Log(GameServer.CharacterLogName(c.Character) + " placed " + item.Name + " in " + Owner, ServerLog.MessageType.Inventory);
                    }
                }
            }
            foreach (Item item in prevItems.Distinct())
            {
                if (item == null)
                {
                    continue;
                }
                if (!AllItems.Contains(item))
                {
                    if (Owner == c.Character)
                    {
                        GameServer.Log(GameServer.CharacterLogName(c.Character) + " dropped " + item.Name, ServerLog.MessageType.Inventory);
                    }
                    else
                    {
                        GameServer.Log(GameServer.CharacterLogName(c.Character) + " removed " + item.Name + " from " + Owner, ServerLog.MessageType.Inventory);
                    }
                }
            }
        }