// TODO: Transfer to unit tests private static void Check(CustomElement[] elements) { // 1. Проверка за наредба във възходящ ред for (int i = 0; i < elements.Length - 1; i++) { Debug.Assert(elements[i].Key <= elements[i + 1].Key, "Wrong order"); } // 2. Проверка за пермутация на изходните елементи bool[] found = new bool[elements.Length]; for (int i = 0; i < elements.Length; i++) { for (int j = 0; j < elements.Length; j++) { if (!found[j] && elements[i].Key == elements[j].Key) { found[j] = true; break; } // Пропада, ако не е намерен съответен Debug.Assert(j < elements.Length, "No element found"); } } }
static void Swap(CustomElement e1, CustomElement e2) { CustomElement old = e1; e1 = e2; e2 = old; }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { var grid = layout.CustomContainer <GridPanel>(); var gridControl = grid.CustomControl; gridControl.ClipChildren = false; gridControl.Height = TextBox.DefaultHeight; gridControl.RowFill = new[] { 1.0f, }; gridControl.ColumnFill = new[] { 0.9f, 0.1f }; _element = grid.Custom <InputBindingBox>(); SetText(); _element.CustomControl.WatermarkText = "Type a binding"; _element.CustomControl.EditEnd += OnValueChanged; var button = grid.Button("X"); button.Button.TooltipText = "Remove binding"; button.Button.Clicked += OnXButtonClicked; }
void AddLogicalElement(object sender, RoutedEventArgs e) { Button myButton = new Button(); myButton.Content = "Happy birthday! " + System.DateTime.Now.TimeOfDay.ToString(); CustomElement.SetSingleChild(myButton); }
/// <summary> /// Read from the XmlReader instance. /// </summary> /// <returns>A CustomElement or null if nothing left to read.</returns> private CustomElement ReadFromReader() { bool ok = reader.Read(); if (!ok) { return(null); } CustomElement newElement = new CustomElement(); newElement.Name = reader.Name; newElement.Value = reader.Value; newElement.NodeType = reader.NodeType; newElement.IsEmptyElement = reader.IsEmptyElement; while (reader.MoveToNextAttribute()) { if (newElement.attributes == null) { newElement.attributes = new List <KeyValuePair <string, string> >(); } newElement.attributes.Add(new KeyValuePair <string, string>(reader.Name, reader.Value)); } reader.MoveToElement(); return(newElement); }
public bool GetItemElement(int nID, out CustomElement itemElement) { itemElement = null; if(!_mItemElementList.TryGetValue(nID, out itemElement)) return false; return true; }
public Error MergeEDL(string _edl) { Error err = Error.OK; try { JSONArray aryEDL = JSON.Parse(_edl).AsArray; foreach (JSONNode nEDL in aryEDL) { JSONClass cEDL = nEDL.AsObject; CustomElement element = new CustomElement(); element.name = cEDL["name"].Value; element.type = cEDL["type"].Value; foreach (JSONNode nValue in cEDL["values"].AsArray) { element.values.Add(nValue.Value); } status.elements.Add(element); } } catch (System.Exception e) { err = Error.NewException(e); } return(err); }
/// <summary> /// Adds new custom element. /// </summary> /// <typeparam name="T">The custom control.</typeparam> /// <returns>The created element.</returns> public CustomElement <T> Custom <T>() where T : Control, new() { var element = new CustomElement <T>(); OnAddElement(element); return(element); }
// Извежда ключовете на масива на екрана static void Print(CustomElement[] elements) { for (int i = 0; i < elements.Length; i++) { Console.Write("{0} ", elements[i].Key); } Console.WriteLine(); }
private void AddLogicalElement(object sender, RoutedEventArgs e) { var mybutton = new Button { Content = "Happy birthday! " + DateTime.Now.TimeOfDay }; CustomElement.SetSingleChild(mybutton); }
// Запълва масива със случайни цели числа static void Init(CustomElement[] elements) { for (int i = 0; i < elements.Length; i++) { int key = random.Next() % elements.Length; elements[i] = new CustomElement() { Key = key }; } }
/// <summary> /// Initializes this editor. /// </summary> /// <param name="layout">The layout builder.</param> public override void Initialize(LayoutElementsContainer layout) { Style style = (Style)this.Values[0]; _element = layout.Custom <StyleValueEditor>(); _element.CustomControl.Value = style; _element.CustomControl.ValueChanged += OnValueChanged; }
public void LabelContentIsCreatedWithDefaults() { var sut = new CustomElement(); Assert.Equal(ZPLForgeDefaults.Elements.FieldOrigin, sut.FieldOrigin); Assert.Equal(ZPLForgeDefaults.Elements.FieldReversePrint, sut.FieldReversePrint); Assert.Equal(ZPLForgeDefaults.Elements.PositionX, sut.PositionX); Assert.Equal(ZPLForgeDefaults.Elements.PositionY, sut.PositionY); }
/// <summary> /// Adds new label element. /// </summary> /// <param name="text">The label text.</param> /// <param name="horizontalAlignment">The label text horizontal alignment.</param> /// <returns>The created element.</returns> public CustomElement <ClickableLabel> ClickableLabel(string text, TextAlignment horizontalAlignment = TextAlignment.Near) { var element = new CustomElement <ClickableLabel>(); element.CustomControl.Height = 18.0f; element.CustomControl.Text = text; element.CustomControl.HorizontalAlignment = horizontalAlignment; OnAddElement(element); return(element); }
private void AddCustomControl(CustomElement element) { var filename = Path.GetFileName(element.FileName); CCSprite tmp = new CCSprite(filename); tmp.Position = new CCPoint((float)element.X + tmp.ContentSize.Width * .5f, (Window.WindowSizeInPixels.Height - (float)element.Y)); AddChild(tmp); }
/// <summary>Reads the next node from the stream.</summary> /// <returns>True if node was read.</returns> public override bool Read() { if (incrementDepthNextCall) { incrementDepthNextCall = false; depth++; } if (elements.Count > 0) { elements.RemoveAt(0); // Done with this one. } if (elements.Count == 0) { AddElements(elements); if (elements.Count == 0) { depth = 0; endOfFile = true; return(false); // All finished. } } CustomElement element = elements[0]; if (element.NodeType == XmlNodeType.CDATA) { nodeType = XmlNodeType.CDATA; } else if (element.NodeType == XmlNodeType.EndElement) { nodeType = XmlNodeType.EndElement; depth--; } else if (element.Name == string.Empty) { nodeType = XmlNodeType.Text; popElementOffStackOnNextRead = true; } else { if (!element.IsEmptyElement) { incrementDepthNextCall = true; } nodeType = XmlNodeType.Element; } if (emptyElement) { popElementOffStackOnNextRead = true; } return(elements.Count > 0); }
public GameObject SpawnCustomElement(CustomElement element) { switch (element) { case CustomElement.Placeholder: return(SpawnPlaceHolder()); default: throw new NotImplementedException("Not implemented yet!"); } }
static CustomElement[] SortRadix(CustomElement[] elements) { // Допълнителен помощен масив CustomElement[] helper = new CustomElement[elements.Length]; // Масив брояч и масив с префикси int[] count = new int[1 << Pow2]; int[] prefixes = new int[1 << Pow2]; // Брой групи int groups = (int)Math.Ceiling((double)BitsCount / (double)Pow2); // Битова маска за идентифициране на групи int mask = (1 << Pow2) - 1; // Алгоритъмът for (int c = 0, shiftRight = 0; c < groups; c++, shiftRight += Pow2) { // Нулиране на масива брояч for (int j = 0; j < count.Length; j++) { count[j] = 0; } // Изброяване на елементите в C-тата група for (int i = 0; i < elements.Length; i++) { count[(elements[i].Key >> shiftRight) & mask]++; } // Изчисляване на префиксите prefixes[0] = 0; for (int i = 1; i < count.Length; i++) { prefixes[i] = prefixes[i - 1] + count[i - 1]; } // Прехвърляне на елементите от основния в //спомагателния масив подредени по C-тата група for (int i = 0; i < elements.Length; i++) { helper[prefixes[(elements[i].Key >> shiftRight) & mask]++] = elements[i]; } // Копиране на спомагателния масив в основния //и започване отначало до последната група helper.CopyTo(elements, 0); } // Масивът е сортиран return elements; }
static CustomElement[] SortRadix(CustomElement[] elements) { // Допълнителен помощен масив CustomElement[] helper = new CustomElement[elements.Length]; // Масив брояч и масив с префикси int[] count = new int[1 << Pow2]; int[] prefixes = new int[1 << Pow2]; // Брой групи int groups = (int)Math.Ceiling((double)BitsCount / (double)Pow2); // Битова маска за идентифициране на групи int mask = (1 << Pow2) - 1; // Алгоритъмът for (int c = 0, shiftRight = 0; c < groups; c++, shiftRight += Pow2) { // Нулиране на масива брояч for (int j = 0; j < count.Length; j++) { count[j] = 0; } // Изброяване на елементите в C-тата група for (int i = 0; i < elements.Length; i++) { count[(elements[i].Key >> shiftRight) & mask]++; } // Изчисляване на префиксите prefixes[0] = 0; for (int i = 1; i < count.Length; i++) { prefixes[i] = prefixes[i - 1] + count[i - 1]; } // Прехвърляне на елементите от основния в //спомагателния масив подредени по C-тата група for (int i = 0; i < elements.Length; i++) { helper[prefixes[(elements[i].Key >> shiftRight) & mask]++] = elements[i]; } // Копиране на спомагателния масив в основния //и започване отначало до последната група helper.CopyTo(elements, 0); } // Масивът е сортиран return(elements); }
/// <summary>Read in a name parameter e.g. <Name>xxx</Name></summary> /// <param name="elements"></param> private void ReadInName(List <CustomElement> elements) { // Expecting a <Name> element. CustomElement element = reader.Read(); if (element == null || element.Name != "Name") { throw new Exception("Invalid .apsimx format. Cannot find name element."); } elements.Add(element); // name elements.Add(reader.Read()); // value elements.Add(reader.Read()); // end element }
static CustomElement[] Init(int n) { CustomElement[] elements = new CustomElement[n]; for (int i = 0; i < n; i++) { CustomElement currentElement = new CustomElement(); currentElement.Key = random.Next(); elements[i] = currentElement; } return(elements); }
static CustomElement[] Init(int n) { CustomElement[] elements = new CustomElement[n]; for (int i = 0; i < n; i++) { CustomElement currentElement = new CustomElement(); currentElement.Key = random.Next(); elements[i] = currentElement; } return elements; }
static void StraightSelection(CustomElement[] elements) { for (int i = 0; i < elements.Length - 1; i++) { for (int j = i + 1; j < elements.Length; j++) { if (elements[i].Key > elements[j].Key) { CustomElement old = elements[i]; elements[i] = elements[j]; elements[j] = old; } } } }
private static CustomElement[] Init(int n) { CustomElement[] elements = new CustomElement[n]; for (int i = 0; i < n; i++) { CustomElement currentElement = new CustomElement { Key = Random.Next() }; elements[i] = currentElement; } return elements; }
public override bool Load (SecurityElement element) { if(element.Tag != "Items") return false; if(element.Children!=null) { foreach(SecurityElement ChildrenElement in element.Children) { if(ChildrenElement.Tag=="Item") { CustomElement itemElement = new CustomElement(); itemElement.nCustomID = StrParser.ParseDecInt(ChildrenElement.Attribute("CustomID"),-1); itemElement.nCustomContent = ChildrenElement.Attribute("CustomContet"); itemElement.nBoneCount = StrParser.ParseDecInt(ChildrenElement.Attribute("BoneCount"),0); itemElement.ValueBegin = StrParser.ParseDecInt(ChildrenElement.Attribute("ValueBegin"),0); itemElement.nBoneList = new List<BoneItemInfo>(); for (int i=0; i<itemElement.nBoneCount; i++) { BoneItemInfo boneItemInfo = new BoneItemInfo(); string strIter = "BoneName" + (i+1).ToString(); boneItemInfo.boneName = ChildrenElement.Attribute(strIter); strIter = "Axis" + (i+1).ToString(); boneItemInfo.nAxis = StrParser.ParseDecInt(ChildrenElement.Attribute(strIter),0); strIter = "PRS" + (i+1).ToString(); boneItemInfo.nPRS = StrParser.ParseDecInt(ChildrenElement.Attribute(strIter),0); strIter = "IsWorld" + (i+1).ToString(); if (ChildrenElement.Attribute(strIter) != "") boneItemInfo.nIsWorld = StrParser.ParseDecInt(ChildrenElement.Attribute(strIter),0); else boneItemInfo.nIsWorld = 0; strIter = "ValueRange" + (i+1).ToString(); boneItemInfo.nValueRange = StrParser.ParseFloat(ChildrenElement.Attribute(strIter),0); strIter = "BigValueRange" + (i+1).ToString(); boneItemInfo.nBigValueRange = StrParser.ParseFloat(ChildrenElement.Attribute(strIter),0); itemElement.nBoneList.Add(boneItemInfo); } _mItemElementList[itemElement.nCustomID] = itemElement; } } return true; } return false; }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { float trackBallSize = 80.0f; float margin = 4.0f; // Panel var masterPanel = layout.CustomContainer <GridPanel>(); var masterPanelControl = masterPanel.CustomControl; masterPanelControl.ClipChildren = false; masterPanelControl.SlotPadding = new Margin(0, 0, margin, margin); masterPanelControl.Height = trackBallSize + margin + margin; masterPanelControl.ColumnFill = new[] { -trackBallSize, 1.0f }; masterPanelControl.RowFill = new[] { 1.0f }; // Trackball _trackball = masterPanel.Custom <ColorSelector>(); _trackball.CustomControl.ColorChanged += OnColorWheelChanged; _trackball.CustomControl.SlidingEnd += ClearToken; // Scale editor { var grid = masterPanel.CustomContainer <UniformGridPanel>(); var gridControl = grid.CustomControl; gridControl.SlotPadding = new Margin(4, 2, 2, 2); gridControl.ClipChildren = false; gridControl.SlotsHorizontally = 1; gridControl.SlotsVertically = 4; LimitAttribute limit = null; var attributes = Values.GetAttributes(); if (attributes != null) { limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute); } _xElement = CreateFloatEditor(grid, limit, Color.Red); _yElement = CreateFloatEditor(grid, limit, Color.Green); _zElement = CreateFloatEditor(grid, limit, Color.Blue); _wElement = CreateFloatEditor(grid, limit, Color.White); } }
public override void Draw(bool highlight) { DrawNode(viewPage.name, highlight); var btnRect = new Rect(drawRect.x, drawRect.y + drawRect.height - 40, drawRect.width, 18); bool btnInteractiable = IsInactivable; if (Application.isPlaying) { btnInteractiable = ViewSystemVisualEditor.allowPreviewWhenPlaying && IsInactivable; } if (CustomElement.Button(id, btnRect, new GUIContent("Preview"), new GUIStyle("ObjectPickerResultsEven"), btnInteractiable)) { OnPreviewBtnClick?.Invoke(viewPage); isSelect = false; } }
/// <summary>Read the next element.</summary> /// <returns>A CustomElement or null if nothing left to read.</returns> public CustomElement Read() { CustomElement element; currentLookAheadIndex = 0; if (lookAheadReads.Count > 0) { element = lookAheadReads[0]; lookAheadReads.RemoveAt(0); } else { element = ReadFromReader(); } lastRead = element; return(element); }
static void Main() { CustomElement[] elements = new CustomElement[Max]; for (int i = 1; i <= TestLoopCount; i++) { Console.WriteLine("{0}<<<<< Тест {1} >>>>>", Environment.NewLine, i); Init(elements); Console.WriteLine("Масивът преди сортирането:"); Print(elements); StraightSelection(elements); Console.WriteLine("Масивът след сортирането:"); Print(elements); Check(elements); } }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { if (!HasDifferentTypes) { _type = Values.Type != typeof(object) || Values[0] == null ? Values.Type : Values[0].GetType(); float height = 48; var attributes = Values.GetAttributes(); if (attributes != null) { var assetReference = (AssetReferenceAttribute)attributes.FirstOrDefault(x => x is AssetReferenceAttribute); if (assetReference != null) { if (assetReference.UseSmallPicker) { height = 32; } if (!string.IsNullOrEmpty(assetReference.TypeName)) { var customType = Utilities.Utils.GetType(assetReference.TypeName); if (customType != null) { _type = customType; } else { Debug.LogWarning(string.Format("Unknown asset type '{0}' to use for asset picker filter.", assetReference.TypeName)); } } } } _element = layout.Custom <AssetPicker>(); _element.CustomControl.AssetType = _type; _element.CustomControl.Height = height; _element.CustomControl.SelectedItemChanged += OnSelectedItemChanged; } }
/// <summary> /// Read from the XmlReader instance. /// </summary> /// <returns>A CustomElement or null if nothing left to read.</returns> private CustomElement ReadFromReader() { bool ok = reader.Read(); if (!ok) return null; CustomElement newElement = new CustomElement(); newElement.Name = reader.Name; newElement.Value = reader.Value; newElement.NodeType = reader.NodeType; newElement.IsEmptyElement = reader.IsEmptyElement; while (reader.MoveToNextAttribute()) { if (newElement.attributes == null) newElement.attributes = new List<KeyValuePair<string, string>>(); newElement.attributes.Add(new KeyValuePair<string, string>(reader.Name, reader.Value)); } reader.MoveToElement(); return newElement; }
public CustomControl() { InitializeComponent(); Element = new CustomElement(); }
/// <summary>Is the specified element a known model?</summary> /// <param name="element">The element to inspect.</param> private bool ElementIsModel(CustomElement element) { return validModelTypes.Find(t => t.Name == element.Name) != null; }
/// <summary>Read the next element.</summary> /// <returns>A CustomElement or null if nothing left to read.</returns> public CustomElement Read() { CustomElement element; currentLookAheadIndex = 0; if (lookAheadReads.Count > 0) { element = lookAheadReads[0]; lookAheadReads.RemoveAt(0); } else element = ReadFromReader(); lastRead = element; return element; }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { element = layout.Custom <ColorValueBox>(); element.CustomControl.ValueChanged += OnValueChanged; }
/// <summary> /// Add elements to the specified list. If no elements are added, it is assumed that /// there are no more elements left and parsing is finished. /// </summary> /// <param name="elements">A list of elements to add to.</param> protected override void AddElements(List<CustomElement> elements) { // Iterate one or more times through elements on the reader. bool continueProcessing; do { continueProcessing = false; switch (currentState) { case States.Initial: { // This is the very first state and will create the root <ModelWrapper> element. CustomElement element = reader.Read(); if (element != null) { //prefix = "xsi"; // namespaceURI = "http://www.w3.org/2001/XMLSchema-instance"; element.Name = "ModelWrapper"; element.attributes = new List<KeyValuePair<string, string>>(); element.attributes.Add(new KeyValuePair<string, string>("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")); elements.Add(element); ReadInName(elements); modelTypesFound.Push("Simulations"); openElements.Push("ModelWrapper"); currentState = States.ExpectingChildOrModel; } break; } case States.ExpectingChildOrModel: { prefix = ""; //namespaceURI = ""; // In this state we look for: // 1. the end of all reading, OR // 2. an end element associated with closing a model node e.g. </Clock>, OR // 3. a new model e.g. <Clock>, OR // 4. the first property of a model e.g. <StartDate> CustomElement element = reader.Read(); if (element == null) { // 1. the end of all reading elements.Add(new CustomElement() { Name = "ModelWrapper", NodeType = XmlNodeType.EndElement }); openElements.Pop(); currentState = States.End; } else if (element.NodeType == XmlNodeType.EndElement) { // 2. an end element associated with closing a model node e.g. </ Clock > modelTypesFound.Pop(); if (openElements.Peek() == "Model") { elements.Add(new CustomElement() { Name = "Model", NodeType = XmlNodeType.EndElement }); openElements.Pop(); } if (openElements.Peek() == "Child") { elements.Add(new CustomElement() { Name = "Child", NodeType = XmlNodeType.EndElement }); openElements.Pop(); } } else if (ElementIsModel(element)) { // 3. a new model e.g. <Clock>, OR CustomElement childElement = new CustomElement(); childElement.Name = "Child"; childElement.NodeType = XmlNodeType.Element; childElement.attributes = new List<KeyValuePair<string, string>>(); childElement.attributes.Add(new KeyValuePair<string, string>("xsi:type", "ModelWrapper")); elements.Add(childElement); if (element.IsEmptyElement) { // Create a model element. CustomElement modelElement = new CustomElement(); modelElement.Name = "Model"; modelElement.attributes = new List<KeyValuePair<string, string>>(); modelElement.attributes.Add(new KeyValuePair<string, string>("xsi:type", element.Name)); modelElement.IsEmptyElement = true; modelElement.NodeType = XmlNodeType.Element; elements.Add(modelElement); elements.Add(new CustomElement() { Name = "Child", NodeType = XmlNodeType.EndElement }); } else { modelTypesFound.Push(element.Name); openElements.Push("Child"); ReadInName(elements); } } else { // 4. the first property of a model e.g. <StartDate> CustomElement modelElement = new CustomElement(); modelElement.Name = "Model"; modelElement.NodeType = XmlNodeType.Element; modelElement.attributes = new List<KeyValuePair<string, string>>(); modelElement.attributes.Add(new KeyValuePair<string, string>("xsi:type", modelTypesFound.Peek())); elements.Add(modelElement); openElements.Push("Model"); currentState = States.ExpectingModelProperties; reader.UndoRead(); } break; } case States.ExpectingModelProperties: { // In this state we look for model parameters and structures. // e.g. simple parameter: <StartDate>xxxx</StartDate> // e.g. array parameter: // <LL> // <double>0.29</double> // <double>0.29</double> // </LL> // e.g. structure // <ResidueTypes> // </ResidueTypes> // This state will detect the end of a model parameter and pass control back to // States.ExpectingChildOrModel. CustomElement element = reader.Read(); if (element == null) throw new Exception("Unexpected end of .apsimx format reached while reading model parameters."); if (element.NodeType == XmlNodeType.Element) { if (element.IsEmptyElement) { // 1. If it is an empty element e.g. <eo_source/> then simply pass it through to caller. elements.Add(element); } else { CustomElement nextElement = reader.LookAhead(); if (nextElement.Value != string.Empty) { // 2. Simple parameter elements.Add(element); elements.Add(reader.Read()); elements.Add(reader.Read()); } else if (ElementIsModel(element)) { // 3. New child model found. Need to close the model element and pass control back // to States.ExpectingChildOrModel elements.Add(new CustomElement() { Name = "Model", NodeType = XmlNodeType.EndElement }); openElements.Pop(); reader.UndoRead(); currentState = States.ExpectingChildOrModel; } else { if (nextElement.Value == string.Empty) { //4. Structure - stay in this state and increment counter. structureCounter++; } else { // 5. Array parameter found. Need to pass control to States.ParsingArrayParameter currentState = States.ParsingArrayParameter; } elements.Add(element); } } } else if (element.NodeType == XmlNodeType.EndElement) { if (structureCounter > 0) { // 6. End of structure. structureCounter--; elements.Add(element); // pass element to caller. } else { // 7. End of our model element. Undo the read of the model element so that // States.ExpectingChildOrModel can read it in. reader.UndoRead(); continueProcessing = true; currentState = States.ExpectingChildOrModel; } } else elements.Add(element); break; } case States.ParsingArrayParameter: { // In this state we parse array parameters // e.g. array parameter: // <LL> // <double>0.29</double> // <double>0.29</double> // </LL> // This state will detect the end of an array parameter and pass control back to // States.ExpectingModelProperties. CustomElement element = reader.Read(); if (element == null) throw new Exception("Unexpected end of .apsimx format reached while reading an array."); if (element.IsEmptyElement) elements.Add(element); else if (element.NodeType == XmlNodeType.Element) { elements.Add(element); elements.Add(reader.Read()); elements.Add(reader.Read()); } else if (element.NodeType == XmlNodeType.EndElement) { elements.Add(element); currentState = States.ExpectingModelProperties; } break; } case States.End: { // All finished. break; } } } while (continueProcessing); }
/// <inheritdoc /> public override void Initialize(LayoutElementsContainer layout) { if (!HasDiffrentTypes) { // TODO: find better way to get content domain from the asset type (mayb util function?) var domain = ContentDomain.Other; type = Values.Type != typeof(object) || Values[0] == null ? Values.Type : Values[0].GetType(); if (type == typeof(Texture) || type == typeof(SpriteAtlas)) { domain = ContentDomain.Texture; } else if (type == typeof(CubeTexture)) { domain = ContentDomain.CubeTexture; } else if (type == typeof(Material) || type == typeof(MaterialInstance) || type == typeof(MaterialBase)) { domain = ContentDomain.Material; } else if (type == typeof(Model)) { domain = ContentDomain.Model; } //else if (type == typeof(PrefabAsset)) // domain = ContentDomain.Prefab; else if (type == typeof(Shader)) { domain = ContentDomain.Shader; } else if (type == typeof(FontAsset)) { domain = ContentDomain.Font; } else if (type == typeof(IESProfile)) { domain = ContentDomain.IESProfile; } else if (type == typeof(AudioClip)) { domain = ContentDomain.Audio; } //else if (type == typeof(SceneAsset)) // domain = ContentDomain.Scene; else if (type == typeof(JsonAsset)) { domain = JsonAsset.Domain; } typeName = null; float height = 48; if (Values.Info != null) { var attributes = Values.Info.GetCustomAttributes(true); var assetReference = (AssetReferenceAttribute)attributes.FirstOrDefault(x => x is AssetReferenceAttribute); if (assetReference != null) { typeName = assetReference.TypeName; if (assetReference.UseSmallPicker) { height = 24; } if (typeName == SceneItem.SceneAssetTypename) { domain = ContentDomain.Scene; } } } element = layout.Custom <AssetPicker>(); element.CustomControl.Domain = domain; element.CustomControl.Height = height; element.CustomControl.SelectedItemChanged += OnSelectedItemChanged; element.CustomControl.ValidateValue += ValidateValue; } }
public OwnerDrawnCell(CustomElement element, UITableViewCellStyle style, string cellReuseIdentifier) : base(style, cellReuseIdentifier) { Element = element; }
public OwnerDrawnCellView(CustomElement element) { _element = element; BackgroundColor = UIColor.Clear; }
public void SetData(CustomElement item) { X = item.X; Y = item.Y; ID = item.ID; IsDocket = item.IsDocked; IsLocked = item.IsLocked; ControlType = (CustomControlType)item.TypeId; Width = item.Width; Height = item.Height; FileName = item.FileName; if (!string.IsNullOrEmpty(FileName)) LoadImageFile(FileName); }
public static IReadOnlyList <string> Create(MavenGeneratorViewModel model) { MavenBuilder builder = new MavenBuilder { GroupId = model.GroupId, ArtifactId = model.ArtifactId, Version = model.Version, Packaging = "jar" }; builder.AddDefaults(); MavenProperties properties = new MavenProperties(); properties.AddProperty(new MavenProperty("java.version", model.JavaVersion)); if (model.MainClass != null) { properties.AddProperty(new MavenProperty("main.class", model.MainClass)); } if (model.DeployUrl != null) { MavenDistributionManagement distributionManagement = new MavenDistributionManagement(); MavenRepository repository = new MavenRepository { Id = "deploy-id", Url = model.DeployUrl }; distributionManagement.AddRepository(repository); builder.PushElement(distributionManagement); } properties.AddProperty(new MavenProperty("project.build.sourceEncoding", "UTF-8")); MavenBuild build = new MavenBuild(); MavenRepositories repositories = new MavenRepositories(); MavenDependencies dependencies = new MavenDependencies(); MavenPlugins plugins = new MavenPlugins(); if (model.Language == Language.Kotlin) { build.AddElement(new MavenProperty("sourceDirectory", "src/main/kotlin")); properties.AddProperty(new MavenProperty("kotlin.version", "1.2.41")); // Enables experimental kotlin compiler properties.AddProperty(new MavenProperty("kotlin.compiler.incremental", "true")); MavenDependency kotlinDependency = new MavenDependency { GroupId = "org.jetbrains.kotlin", ArtifactId = "kotlin-stdlib", Version = "${kotlin.version}", Scope = Maven.Data.Scope.Compile }; dependencies.AddDependency(kotlinDependency); MavenPlugin kotlinPlugin = new MavenPlugin { GroupId = "org.jetbrains.kotlin", ArtifactId = "kotlin-maven-plugin", Version = "${kotlin.version}" }; CustomElement configuration = new CustomElement(3); configuration.AddLine("<executions>"); configuration.AddLine(2, "<execution>"); configuration.AddLine(3, "<id>compile</id>"); configuration.AddLine(3, "<goals><goal>compile</goal></goals>"); configuration.AddLine(3, "<configuration>"); configuration.AddLine(4, "<sourceDirs>"); configuration.AddLine(5, "<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>"); configuration.AddLine(5, "<sourceDir>${project.basedir}/src/main/java</sourceDir>"); configuration.AddLine(4, "</sourceDirs>"); configuration.AddLine(3, "</configuration>"); configuration.AddLine(2, "</execution>"); configuration.AddLine("</executions>"); kotlinPlugin.AddCustomElement(configuration); plugins.AddPlugin(kotlinPlugin); } if (model.IsBukkitPlugin) { properties.AddProperty(new MavenProperty("bukkit.version", "1.12.2-R0.1-SNAPSHOT")); MavenRepository bukkitRepository = new MavenRepository() { Id = "bukkit-repo", Url = "https://hub.spigotmc.org/nexus/content/groups/public/" }; repositories.AddRepository(bukkitRepository); MavenDependency bukkitDependency = new MavenDependency { GroupId = "org.bukkit", ArtifactId = "bukkit", Version = "${bukkit.version}", Scope = Maven.Data.Scope.Provided }; dependencies.AddDependency(bukkitDependency); } builder.PushElement(properties); builder.PushElement(repositories); if (model.IsBukkitPlugin) { builder.PushElement(dependencies); } foreach (Plugin plugin in model.Plugins) { switch (plugin) { case Plugin.Compiler: { MavenPlugin compilerPlugin = new MavenPlugin { GroupId = "org.apache.maven.plugins", ArtifactId = "maven-compiler-plugin", Version = "3.7.0" }; CustomElement configuration = new CustomElement(3); configuration.AddLine("<configuration>"); configuration.AddLine(2, "<source>${java.version}</source>"); configuration.AddLine(2, "<target>${java.version}</target>"); configuration.AddLine("</configuration>"); compilerPlugin.AddCustomElement(configuration); if (model.Language == Language.Kotlin) { CustomElement executions = new CustomElement(3); executions.AddLine("<executions>"); executions.AddLine(2, "<execution>"); executions.AddLine(3, "<id>default-compile</id>"); executions.AddLine(3, "<phase>none</phase>"); executions.AddLine(2, "</execution>"); executions.AddLine("</executions>"); executions.AddLine("<executions>"); executions.AddLine(2, "<execution>"); executions.AddLine(3, "<id>java-compile</id>"); executions.AddLine(3, "<phase>compile</phase>"); executions.AddLine(3, "<goals>"); executions.AddLine(4, "<goal>compile</goal>"); executions.AddLine(3, "</goals>"); executions.AddLine(2, "</execution>"); executions.AddLine("</executions>"); compilerPlugin.AddCustomElement(executions); } plugins.AddPlugin(compilerPlugin); break; } case Plugin.Shade: { MavenPlugin shadePlugin = new MavenPlugin { GroupId = "org.apache.maven.plugins", ArtifactId = "maven-shade-plugin", Version = "3.1.1" }; CustomElement executions = new CustomElement(3); executions.AddLine("<executions>"); executions.AddLine(2, "<execution>"); executions.AddLine(3, "<phase>package</phase>"); executions.AddLine(3, "<goals>"); executions.AddLine(4, "<goal>shade</goal>"); executions.AddLine(3, "</goals>"); executions.AddLine(2, "</execution>"); executions.AddLine("</executions>"); shadePlugin.AddCustomElement(executions); plugins.AddPlugin(shadePlugin); break; } case Plugin.Jar: { MavenPlugin jarPlugin = new MavenPlugin { GroupId = "org.apache.maven.plugins", ArtifactId = "maven-jar-plugin", Version = "3.1.0" }; if (model.MainClass != null) { CustomElement configuration = new CustomElement(3); configuration.AddLine("<configuration>"); configuration.AddLine(2, "<archive>"); configuration.AddLine(3, "<manifest>"); configuration.AddLine(4, "<addClasspath>true</addClasspath>"); configuration.AddLine(4, "<mainClass>${main.class}</mainClass>"); configuration.AddLine(3, "</manifest>"); configuration.AddLine(2, "</archive>"); configuration.AddLine("</configuration>"); jarPlugin.AddCustomElement(configuration); } plugins.AddPlugin(jarPlugin); break; } case Plugin.Assembly: { MavenPlugin jarPlugin = new MavenPlugin { GroupId = "org.apache.maven.plugins", ArtifactId = "maven-assembly-plugin", Version = "3.1.0" }; CustomElement configuration = new CustomElement(3); configuration.AddLine("<configuration>"); if (model.MainClass != null) { configuration.AddLine(2, "<archive>"); configuration.AddLine(3, "<manifest>"); configuration.AddLine(4, "<addClasspath>true</addClasspath>"); configuration.AddLine(4, "<mainClass>${main.class}</mainClass>"); configuration.AddLine(3, "</manifest>"); configuration.AddLine(2, "</archive>"); } configuration.AddLine(2, "<descriptorRefs>"); configuration.AddLine(3, "<descriptorRef>jar-with-dependencies</descriptorRef>"); configuration.AddLine(2, "</descriptorRefs>"); configuration.AddLine("</configuration>"); jarPlugin.AddCustomElement(configuration); plugins.AddPlugin(jarPlugin); break; } } } build.AddElement(plugins); MavenResources resources = new MavenResources(); MavenResource resource = new MavenResource(); // Default: src/main/resources resources.AddResource(resource); build.AddElement(resources); builder.PushElement(build); return(builder.GetGeneratedLines()); }
public IntroGameState(IAnarkanoidGame anarkanoidGame, IKeysConfiguration keys) : base(anarkanoidGame, keys) { KeyDelay = KEY_DELAY; TOTAL_OPTIONS = OPTIONS_TEXTS.Length; AnarkanoidGame.CurrentStage = 0; var backgroundSize = new Size( AnarkanoidGame.ComponentManager.Configuration.ScreenSize.Width, AnarkanoidGame.ComponentManager.Configuration.ScreenSize.Height ); _background = new CustomElement(AnarkanoidGame.ComponentManager.Configuration, backgroundSize) { Scale = new Vector2(BACKGROUND_SCALE, BACKGROUND_SCALE) }; AnarkanoidGame.ComponentManager.AddComponentByAssetName(_background, "Title"); var spaceInvaderSize = new Size( AnarkanoidGame.ComponentManager.Configuration.ScreenSize.Width / SPACE_INVADER_PERCENT_SCALE, AnarkanoidGame.ComponentManager.Configuration.ScreenSize.Height / SPACE_INVADER_PERCENT_SCALE ); _spaceInvader = new CustomElement(AnarkanoidGame.ComponentManager.Configuration, spaceInvaderSize) { Position = SPACE_INVADER_POSITION }; AnarkanoidGame.ComponentManager.AddComponentByAssetName(_spaceInvader, "SpaceInvader"); var subtitle = new ShowText(AnarkanoidGame.ComponentManager.Configuration, OPTION_TEXT_SIZE) { Position = SUBTITLE_POSITION, SpriteColor = Color.Red, Scale = new Vector2(1.5f, 1.5f) }; AnarkanoidGame.ComponentManager.AddText(subtitle, SUBTITLE_TEXT); //SUBTITLE_TEXT var textTopPosition = FIRST_OPTION_TEXT_POSITION.Y; _optionsText = new List <ShowText>(); foreach (string optionText in OPTIONS_TEXTS) { var text = new ShowText(AnarkanoidGame.ComponentManager.Configuration, OPTION_TEXT_SIZE) { Position = new Vector2(FIRST_OPTION_TEXT_POSITION.X, textTopPosition), SpriteColor = Color.Black }; AnarkanoidGame.ComponentManager.AddText(text, optionText); _optionsText.Add(text); textTopPosition += text.Size.Height; } ACTIONS = new System.Action[] { NewGameSelected, ConfigureControlsSelected, ToggleFullScreenSelected, ExitGameSelected }; AnarkanoidGame.ComponentManager.SpaceShip.Scale = new Vector2(.8f, .8f); AnarkanoidGame.ComponentManager.SpaceShip.Position = new Vector2( _optionsText[0].Position.X - AnarkanoidGame.ComponentManager.SpaceShip.Size.Width, _optionsText[0].Position.Y + 10 ); AnarkanoidGame.ComponentManager.AddSpaceShip(AnarkanoidGame.ComponentManager.SpaceShip); CommandsFactory.GetDelayedActionCommand(ToggleSpceInvaderPosition, 1000).Execute(); CommandPerKey.Add(Keys.Up, CommandsFactory.GetActionCommand(MoveUpOption)); CommandPerKey.Add(Keys.Down, CommandsFactory.GetActionCommand(MoveDownOption)); CommandPerKey.Add(Microsoft.Xna.Framework.Input.Keys.Enter, CommandsFactory.GetActionCommand(EnterPressed)); _returnState = this; AnarkanoidGame.ComponentManager.PlaySound("Anarky"); }
/// <summary> /// Add elements to the specified list. If no elements are added, it is assumed that /// there are no more elements left and parsing is finished. /// </summary> /// <param name="elements">A list of elements to add to.</param> protected override void AddElements(List <CustomElement> elements) { // Iterate one or more times through elements on the reader. bool continueProcessing; do { continueProcessing = false; switch (currentState) { case States.Initial: { // This is the very first state and will create the root <ModelWrapper> element. CustomElement element = reader.Read(); if (element != null) { //prefix = "xsi"; // namespaceURI = "http://www.w3.org/2001/XMLSchema-instance"; element.Name = "ModelWrapper"; element.attributes = new List <KeyValuePair <string, string> >(); element.attributes.Add(new KeyValuePair <string, string>("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")); elements.Add(element); ReadInName(elements); modelTypesFound.Push("Simulations"); openElements.Push("ModelWrapper"); currentState = States.ExpectingChildOrModel; } break; } case States.ExpectingChildOrModel: { prefix = ""; //namespaceURI = ""; // In this state we look for: // 1. the end of all reading, OR // 2. an end element associated with closing a model node e.g. </Clock>, OR // 3. a new model e.g. <Clock>, OR // 4. the first property of a model e.g. <StartDate> CustomElement element = reader.Read(); if (element == null) { // 1. the end of all reading elements.Add(new CustomElement() { Name = "ModelWrapper", NodeType = XmlNodeType.EndElement }); openElements.Pop(); currentState = States.End; } else if (element.NodeType == XmlNodeType.EndElement) { // 2. an end element associated with closing a model node e.g. </ Clock > modelTypesFound.Pop(); if (openElements.Peek() == "Model") { elements.Add(new CustomElement() { Name = "Model", NodeType = XmlNodeType.EndElement }); openElements.Pop(); } if (openElements.Peek() == "Child") { elements.Add(new CustomElement() { Name = "Child", NodeType = XmlNodeType.EndElement }); openElements.Pop(); } } else if (ElementIsModel(element)) { // 3. a new model e.g. <Clock>, OR CustomElement childElement = new CustomElement(); childElement.Name = "Child"; childElement.NodeType = XmlNodeType.Element; childElement.attributes = new List <KeyValuePair <string, string> >(); childElement.attributes.Add(new KeyValuePair <string, string>("xsi:type", "ModelWrapper")); elements.Add(childElement); if (element.IsEmptyElement) { // Create a model element. CustomElement modelElement = new CustomElement(); modelElement.Name = "Model"; modelElement.attributes = new List <KeyValuePair <string, string> >(); modelElement.attributes.Add(new KeyValuePair <string, string>("xsi:type", element.Name)); modelElement.IsEmptyElement = true; modelElement.NodeType = XmlNodeType.Element; elements.Add(modelElement); elements.Add(new CustomElement() { Name = "Child", NodeType = XmlNodeType.EndElement }); } else { modelTypesFound.Push(element.Name); openElements.Push("Child"); ReadInName(elements); } } else { // 4. the first property of a model e.g. <StartDate> CustomElement modelElement = new CustomElement(); modelElement.Name = "Model"; modelElement.NodeType = XmlNodeType.Element; modelElement.attributes = new List <KeyValuePair <string, string> >(); modelElement.attributes.Add(new KeyValuePair <string, string>("xsi:type", modelTypesFound.Peek())); elements.Add(modelElement); openElements.Push("Model"); currentState = States.ExpectingModelProperties; reader.UndoRead(); } break; } case States.ExpectingModelProperties: { // In this state we look for model parameters and structures. // e.g. simple parameter: <StartDate>xxxx</StartDate> // e.g. array parameter: // <LL> // <double>0.29</double> // <double>0.29</double> // </LL> // e.g. structure // <ResidueTypes> // </ResidueTypes> // This state will detect the end of a model parameter and pass control back to // States.ExpectingChildOrModel. CustomElement element = reader.Read(); if (element == null) { throw new Exception("Unexpected end of .apsimx format reached while reading model parameters."); } if (element.NodeType == XmlNodeType.Element) { if (element.IsEmptyElement) { // 1. If it is an empty element e.g. <eo_source/> then simply pass it through to caller. elements.Add(element); } else { CustomElement nextElement = reader.LookAhead(); if (nextElement.Value != string.Empty) { // 2. Simple parameter elements.Add(element); elements.Add(reader.Read()); elements.Add(reader.Read()); } else if (ElementIsModel(element)) { // 3. New child model found. Need to close the model element and pass control back // to States.ExpectingChildOrModel elements.Add(new CustomElement() { Name = "Model", NodeType = XmlNodeType.EndElement }); openElements.Pop(); reader.UndoRead(); currentState = States.ExpectingChildOrModel; } else { if (nextElement.Value == string.Empty) { //4. Structure - stay in this state and increment counter. structureCounter++; } else { // 5. Array parameter found. Need to pass control to States.ParsingArrayParameter currentState = States.ParsingArrayParameter; } elements.Add(element); } } } else if (element.NodeType == XmlNodeType.EndElement) { if (structureCounter > 0) { // 6. End of structure. structureCounter--; elements.Add(element); // pass element to caller. } else { // 7. End of our model element. Undo the read of the model element so that // States.ExpectingChildOrModel can read it in. reader.UndoRead(); continueProcessing = true; currentState = States.ExpectingChildOrModel; } } else { elements.Add(element); } break; } case States.ParsingArrayParameter: { // In this state we parse array parameters // e.g. array parameter: // <LL> // <double>0.29</double> // <double>0.29</double> // </LL> // This state will detect the end of an array parameter and pass control back to // States.ExpectingModelProperties. CustomElement element = reader.Read(); if (element == null) { throw new Exception("Unexpected end of .apsimx format reached while reading an array."); } if (element.IsEmptyElement) { elements.Add(element); } else if (element.NodeType == XmlNodeType.Element) { elements.Add(element); elements.Add(reader.Read()); elements.Add(reader.Read()); } else if (element.NodeType == XmlNodeType.EndElement) { elements.Add(element); currentState = States.ExpectingModelProperties; } break; } case States.End: { // All finished. break; } } }while (continueProcessing); }
/// <summary>Is the specified element a known model?</summary> /// <param name="element">The element to inspect.</param> private bool ElementIsModel(CustomElement element) { return(validModelTypes.Find(t => t.Name == element.Name) != null); }