/// <summary> /// Gets the currently selected object. /// </summary> /// <param name="selected">The currently selected object.</param> public void SetSelected(T selected) { // Check if to clear instead if (selected == null) { Clear(); return; } // Ignore if we already have this exact set as the current selection if (_selectedObjs.Count == 1 && _selectedObjs[0] == selected) { return; } // Set the new selected objects and update Clear(); _selectedObjs.Add(selected); OnObjectAdded(selected); if (ObjectAdded != null) { ObjectAdded.Raise(this, EventArgsHelper.Create(selected)); } UpdateSelection(); }
/// <summary> /// Gets the currently selected objects. /// </summary> /// <param name="selectedObjs">The currently selected objects.</param> public void SetManySelected(IEnumerable <T> selectedObjs) { // Check if to clear instead if (selectedObjs == null || selectedObjs.IsEmpty()) { Clear(); return; } selectedObjs = selectedObjs.Distinct().ToImmutable(); // Ignore if we already have this exact set as the current selection if (selectedObjs.ContainSameElements(_selectedObjs)) { return; } // Set the new selected objects and update Clear(); foreach (var obj in selectedObjs) { _selectedObjs.Add(obj); OnObjectAdded(obj); if (ObjectAdded != null) { ObjectAdded.Raise(this, EventArgsHelper.Create(obj)); } } UpdateSelection(); }
/// <summary> /// Sets the focused object. /// </summary> /// <param name="obj">The object to set as focused.</param> /// <param name="addIfMissing">If true, <paramref name="obj"/> will be added to the collection /// if it is not already in it.</param> /// <returns>True if the <paramref name="obj"/> was successfully set as the focused object; otherwise /// false.</returns> public bool SetFocused(T obj, bool addIfMissing = false) { if (obj == null) { return(false); } if (!_selectedObjs.Contains(obj)) { if (!addIfMissing) { return(false); } _selectedObjs.Add(obj); OnObjectAdded(obj); if (ObjectAdded != null) { ObjectAdded.Raise(this, EventArgsHelper.Create(obj)); } } Focused = obj; return(true); }
/// <summary> /// Adds a new object to the collection of selected objects. /// </summary> /// <param name="obj">The object to add.</param> public void Add(T obj) { if (obj == null) { return; } if (_selectedObjs.Contains(obj)) { return; } _selectedObjs.Add(obj); OnObjectAdded(obj); if (ObjectAdded != null) { ObjectAdded.Raise(this, EventArgsHelper.Create(obj)); } UpdateSelection(); }
public bool Add(ISimpleGameObject obj) { if (!AddToPrimaryRegionAndTiles(obj)) { return(false); } // Keeps track of objects that exist in the map obj.InWorld = true; RegisterObjectEventListeners(obj); // Add appropriate objects to the minimap IMiniMapRegionObject miniMapRegionObject = obj as IMiniMapRegionObject; if (miniMapRegionObject != null) { MiniMapRegions.Add(miniMapRegionObject); } // Post to channel ushort regionId = regionLocator.GetRegionIndex(obj); channel.Post("/WORLD/" + regionId, () => { var packet = new Packet(Command.ObjectAdd); packet.AddUInt16(regionId); PacketHelper.AddToPacket(obj, packet); return(packet); }); // Raise event ObjectAdded.Raise(this, new ObjectEvent(obj)); return(true); }