/// <summary> /// Reads a portion of a binary stream to populate this building config. /// </summary> /// <param name="binaryReader">The <see cref="BinaryReader"/> encapsulating the binary information to read</param> /// <returns>True if the read succeeded, false otherwise</returns> public bool ReadBinary(BinaryReader binaryReader) { try { Offset = new Vector2I(binaryReader.ReadInt32(), binaryReader.ReadInt32()); BuildingDef = Assets.GetBuildingDef(binaryReader.ReadString()); int selectedElementCount = binaryReader.ReadInt32(); for (int i = 0; i < selectedElementCount; ++i) { Tag elementTag; //Only add the tag to the list if it describes a valid element in game. if (ElementLoader.GetElement(elementTag = new Tag(binaryReader.ReadInt32())) != null) { SelectedElements.Add(elementTag); } } Orientation = (Orientation)binaryReader.ReadInt32(); Flags = binaryReader.ReadInt32(); return(true); } catch (System.Exception) { return(false); } }
private void SelectedElement(T item) { if (!SelectedElements.Any(e => e.Equals(item))) { SelectedElements.Add(item); } }
/// <summary> /// 添加选中元素 /// </summary> /// <param name="element"></param> private void SelectedElementAdd(UIElement element) { if (!SelectedElements.Contains(element)) { SelectedElements.Add(element); this.ReorderZindex(); ((IControlBase)element).SetFocus(); } }
public void SelectElement(BaseElement el) { SelectedElements.Add(el); if (el is NodeElement) { SelectedNodes.Add(el); } if (_canFireEvents) OnElementSelection(this, new ElementSelectionEventArgs(SelectedElements)); }
public void SelectElements(Rectangle selectionRectangle) { SelectedElements.EnabledCalc = false; SelectedNodes.EnabledCalc = false; // Add all "hitable" elements foreach (BaseElement element in Elements) { if (!(element is IControllable)) { continue; } var ctrl = ((IControllable)element).GetController(); if (!ctrl.HitTest(selectionRectangle)) { continue; } if (!(element is ConnectorElement)) { SelectedElements.Add(element); } if (element is NodeElement) { SelectedNodes.Add(element); } } //if the seleciont isn't a expecific link, remove links // without 2 elements in selection if (SelectedElements.Count > 1) { foreach (BaseElement el in Elements) { var lnk = el as BaseLinkElement; if (lnk == null) { continue; } if ((!SelectedElements.Contains(lnk.Connector1.ParentElement)) || (!SelectedElements.Contains(lnk.Connector2.ParentElement))) { SelectedElements.Remove(lnk); } } } SelectedElements.EnabledCalc = true; SelectedNodes.EnabledCalc = true; OnElementSelection(this, new ElementSelectionEventArgs(SelectedElements)); }
/// <summary> /// Reads a JSON object to populate this building config. /// </summary> /// <param name="rootObject">The <see cref="JObject"/> to use to read from</param> public void ReadJSON(JObject rootObject) { JToken offsetToken = rootObject.SelectToken("offset"); JToken buildingDefToken = rootObject.SelectToken("buildingdef"); JToken selectedElementsToken = rootObject.SelectToken("selected_elements"); JToken orientationToken = rootObject.SelectToken("orientation"); JToken flagsToken = rootObject.SelectToken("flags"); if (offsetToken != null && offsetToken.Type == JTokenType.Object) { JToken xToken = offsetToken.SelectToken("x"); JToken yToken = offsetToken.SelectToken("y"); if (xToken != null && xToken.Type == JTokenType.Integer || yToken != null && yToken.Type == JTokenType.Integer) { Offset = new Vector2I(xToken == null ? 0 : xToken.Value <int>(), yToken == null ? 0 : yToken.Value <int>()); } } if (buildingDefToken != null && buildingDefToken.Type == JTokenType.String) { BuildingDef = Assets.GetBuildingDef(buildingDefToken.Value <string>()); } if (selectedElementsToken != null && selectedElementsToken.Type == JTokenType.Array) { JArray selectedElementTokens = selectedElementsToken.Value <JArray>(); if (selectedElementTokens != null) { foreach (JToken selectedElement in selectedElementTokens) { Tag elementTag; if (selectedElement.Type == JTokenType.Integer && ElementLoader.GetElement(elementTag = new Tag(selectedElement.Value <int>())) != null) { SelectedElements.Add(elementTag); } } } } if (orientationToken != null && orientationToken.Type == JTokenType.Integer) { Orientation = (Orientation)orientationToken.Value <int>(); } if (flagsToken != null && flagsToken.Type == JTokenType.Integer) { Flags = flagsToken.Value <int>(); } }
private void DoSelection(UIElement source) { var fElement = source as FrameworkElement; if (fElement != null) { // Save a reference to the adorned UIElement for removing later SelectedUiElement.Add(source); SelectedElements.Add(fElement.DataContext as ShapeViewModel); SelectedElement = fElement.DataContext as ShapeViewModel; AddAdorner(source); setRibbonSelection(true); } }
private void InternalSelectedElements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (SuppressNotificationsCounter > 0) { return; } try { SuppressNotifications(); switch (e.Action) { case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Replace: if (e.OldItems != null) { foreach (var item in e.OldItems.Cast <FieldExposer <T_Item> >()) { if (SelectedElements.Contains(item.InnerItem)) { SelectedElements.Remove(item.InnerItem); } } } if (e.NewItems != null) { foreach (var item in e.NewItems.Cast <FieldExposer <T_Item> >()) { if (!SelectedElements.Contains(item.InnerItem)) { SelectedElements.Add(item.InnerItem); } } } break; case NotifyCollectionChangedAction.Reset: SelectedElements.Clear(); break; } } finally { AllowNotifications(); } }
private void Button_OnClick(UIElement sender) { ISelectable element = (sender as ISelectable); if (element.GetStatus()) { SelectedElements.Add(element); } else { SelectedElements.Remove(element); } if (SelectedCountChanded != null) { SelectedCountChanded(SelectedElements.Count); } }
public void SelectAllElements() { SelectedElements.EnabledCalc = false; SelectedNodes.EnabledCalc = false; foreach(BaseElement element in Elements) { if (!(element is ConnectorElement)) SelectedElements.Add(element); if (element is NodeElement) SelectedNodes.Add(element); } SelectedElements.EnabledCalc = true; SelectedNodes.EnabledCalc = true; }
public bool ReadJSONLegacy(JObject rootObject) { JToken offsetToken = rootObject.SelectToken("offset"); JToken buildingDefToken = rootObject.SelectToken("buildingdef"); JToken elementToken = rootObject.SelectToken("element"); JToken orientationToken = rootObject.SelectToken("orientation"); JToken flagsToken = rootObject.SelectToken("flags"); if (offsetToken != null && offsetToken.Type == JTokenType.Object) { JToken xToken = offsetToken.SelectToken("x"); JToken yToken = offsetToken.SelectToken("y"); if (xToken != null && xToken.Type == JTokenType.Integer && yToken != null & yToken.Type == JTokenType.Integer) { Offset = new Vector2I(xToken.Value <int>(), yToken.Value <int>()); } else { return(false); } } else { return(false); } if (buildingDefToken != null && buildingDefToken.Type == JTokenType.String) { if ((BuildingDef = Assets.GetBuildingDef(buildingDefToken.Value <string>())) == null) { return(false); } } else { return(false); } if (elementToken != null && elementToken.Type == JTokenType.Integer) { Tag elementTag; if (ElementLoader.GetElement(elementTag = new Tag(elementToken.Value <int>())) == null) { return(false); } else { SelectedElements.Add(elementTag); } } else { return(false); } if (orientationToken != null && orientationToken.Type == JTokenType.Integer) { Orientation = (Orientation)orientationToken.Value <int>(); } else { return(false); } if (flagsToken != null && flagsToken.Type == JTokenType.Integer) { Flags = flagsToken.Value <int>(); } else { return(false); } return(true); }