private void SaveCustomSerializationValues(TextBlock textBlock) { if (customSerializationValues.Count == 0) { return; } TextBlock customValuesBlock = textBlock.AddChild("customSerializationValues"); foreach (KeyValuePair <string, object> current in customSerializationValues) { string key = current.Key; object value = current.Value; if (value == null) { continue; } Type type = value.GetType(); string errorString = string.Format("World: Custom serialization value \"{0}\"", key); string saveValueString = EntityHelper.ConvertToString(type, value, errorString); TextBlock customValueBlock = customValuesBlock.AddChild(key); customValueBlock.SetAttribute("type", type.FullName); customValueBlock.SetAttribute("value", saveValueString); } ClearAllCustomSerializationValues(); }
internal void OnSave(TextBlock textBlock) { if (this.waitintThreads.Count != 0) { TextBlock textBlock2 = textBlock.AddChild("waitItems"); foreach (WaitingThreadItem current in this.waitintThreads) { TextBlock textBlock3 = textBlock2.AddChild("item"); if (!string.IsNullOrEmpty(current.ThreadName)) { textBlock3.SetAttribute("threadName", current.ThreadName); } textBlock3.SetAttribute("remainingTime", current.RemainingTime.ToString()); if (current.currentExecutingMethodInformations != null) { TextBlock textBlock4 = textBlock3.AddChild("executeMethodInformations"); foreach (LogicExecuteMethodInformation current2 in current.currentExecutingMethodInformations) { TextBlock textBlock5 = textBlock4.AddChild("item"); current2.a(textBlock5); } } } } }
public bool SaveTypeToFile(EntityType type) { TextBlock textBlock = new TextBlock(); TextBlock typeBlock = textBlock.AddChild("type", type.Name); typeBlock.SetAttribute("class", type.ClassInfo.EntityClassType.Name); if (!type.Save(typeBlock)) { return(false); } if (!type._OnSave(typeBlock)) { return(false); } try { using (FileStream fileStream = new FileStream(VirtualFileSystem.GetRealPathByVirtual(type.FilePath), FileMode.Create)) { using (StreamWriter streamWriter = new StreamWriter(fileStream)) { streamWriter.Write(textBlock.DumpToString()); } } } catch (Exception ex) { Log.Warning("Save type to file failed: {0}", ex.ToString()); return(false); } return(true); }
internal void OnSave(TextBlock block) { if (block == null) { return; } block.SetAttribute("name", this.Name); if (!Visible) { block.SetAttribute("visible", Visible.ToString()); } if (!AllowSelect) { block.SetAttribute("allowSelect", AllowSelect.ToString()); } if (!AllowEdit) { block.SetAttribute("allowEdit", AllowEdit.ToString()); } foreach (EditorLayer child in children) { TextBlock childBlock = block.AddChild("layer"); child.OnSave(childBlock); } }
protected override void OnSave(TextBlock block) { base.OnSave(block); TextBlock editorLayersBlock = block.AddChild("editorLayers"); rootEditorLayer.OnSave(editorLayersBlock); }
public void WriteEntitiesToSceneFileBlock(TextBlock block, IList <Entity> entities) { foreach (Entity current in entities) { TextBlock block2 = block.AddChild("entity"); this.WriteEntityTreeToTextBlock(current, block2); } }
public void SaveGame(String filename) { TextBlock block = new TextBlock(); TextBlock b1 = block.AddChild("EnemiesKill", EnemiesKill.ToString()); TextBlock b2 = block.AddChild("Level", Level.ToString()); TextBlock b3 = block.AddChild("CheckPoint", CheckPoint); var sc = Component_Scene.First; var chr = (Component_Character)sc?.GetComponentByPath("Character"); if (chr.ItemGetEnabledFirst() != null) { hasWeapon = true; } TextBlock b4 = block.AddChild("hasWeapon", hasWeapon.ToString()); TextBlockUtility.SaveToVirtualFile(block, "Store\\AndreyKorolev\\5MinGame\\Saves\\" + filename + ".lvldata"); }
internal void Save(TextBlock textBlock) { this.OnSave(textBlock); foreach (Entity current in this.Children) { if (current.AllowSave) { TextBlock entityBlock = textBlock.AddChild("entity"); current.Save(entityBlock); } } }
protected override void OnSave(TextBlock block) { base.OnSave(block); if (!(currentTask is IdleTask)) { TextBlock taskBlock = block.AddChild("currentTask"); taskBlock.SetAttribute("class", GetTaskClassName(currentTask)); currentTask._Save(taskBlock); } if (tasks.Count != 0) { TextBlock tasksBlock = block.AddChild("tasks"); foreach (Task task in tasks) { TextBlock taskBlock = tasksBlock.AddChild("item"); taskBlock.SetAttribute("class", GetTaskClassName(task)); task._Save(taskBlock); } } }
public bool Save(TextBlock block) { //fireObjects if (fireObjects.Count != 0) { TextBlock fireObjectsBlock = block.AddChild("fireObjects"); if (!fireObjects.Save(fireObjectsBlock)) { return(false); } } return(true); }
private void btnAddWeapon_Click(Button sender) { if (cbxWeaponSlots.SelectedItem == null || lstWeaponList.SelectedItem == null) { return; } AKunit u = spawner.Spawned as AKunit; AKunitType.WeaponItem wi = cbxWeaponSlots.SelectedItem as AKunitType.WeaponItem; AKunitType.AlternateWeaponItem awi = lstWeaponList.SelectedItem as AKunitType.AlternateWeaponItem; string selectedBodyPartName = GetBodyPartNameFromActiveButton(); int selectedBodyPartIndex = GetBodyPartIndex(selectedBodyPartName); int weaponFireGroup = u.Bp[selectedBodyPartIndex].Weapons[cbxWeaponSlots.SelectedIndex].FireGroup; u.Bp[selectedBodyPartIndex].Weapons[cbxWeaponSlots.SelectedIndex].Ammo = awi.Ammo; u.Bp[selectedBodyPartIndex].Weapons[cbxWeaponSlots.SelectedIndex].MagazineCapacity = awi.MagazineCapacity; u.Bp[selectedBodyPartIndex].Weapons[cbxWeaponSlots.SelectedIndex].WeaponType = awi.WeaponType; TextBlock bodyPartBlock = variant.FindChild(selectedBodyPartName); if (bodyPartBlock == null) { bodyPartBlock = variant.AddChild(selectedBodyPartName); } if (bodyPartBlock != null) { TextBlock wBlock = bodyPartBlock.FindChild(wi.MapObjectAlias); if (wBlock == null) { wBlock = bodyPartBlock.AddChild(wi.MapObjectAlias); } if (wBlock != null) { wBlock.SetAttribute("i", lstWeaponList.SelectedIndex.ToString()); wBlock.SetAttribute("g", weaponFireGroup.ToString()); } } UpdateVariantCost(awi.Price); PopulateWeaponSlotsDropDown(selectedBodyPartName); }
protected override void OnNewResource(string directory) { base.OnNewResource(directory); EntityTypeNewResourceDialog cd = new EntityTypeNewResourceDialog(directory); if (cd.ShowDialog(MainForm.Instance) != DialogResult.OK) { return; } string text = ""; if (directory != "") { text = text + directory + "\\"; } text = text + cd.TypeName + ".type"; TextBlock textBlock = new TextBlock(); TextBlock typeBlock = textBlock.AddChild("type", cd.TypeName); typeBlock.SetAttribute("class", cd.TypeClass.EntityClassType.Name); try { using (Stream stream = new FileStream(VirtualFileSystem.GetRealPathByVirtual(text), FileMode.Create)) { using (StreamWriter streamWriter = new StreamWriter(stream)) { streamWriter.Write(textBlock.DumpToString()); } } } catch (Exception ex) { Log.Warning(ex.Message); return; } if (EntityTypes.Instance.LoadTypeFromFile(text) != null) { MainForm.Instance.ResourcesForm.UpdateAddResource(text); MainForm.Instance.ResourcesForm.SelectNodeByPath(text); return; } Log.Fatal("OnNewResource: EntityTypes.Instance.LoadType: Internal error."); }
protected override bool OnSave(TextBlock block) { if (!base.OnSave(block)) { return(false); } //hitObjects if (hitObjects.Count != 0) { TextBlock hitObjectsBlock = block.AddChild("hitObjects"); if (!hitObjects.Save(hitObjectsBlock)) { return(false); } } return(true); }
internal void a(TextBlock textBlock) { if (this.aAO != null) { textBlock.SetAttribute("method", this.aAO.UIN.ToString()); } if (this.aAo != null) { textBlock.SetAttribute("logicClassType", this.aAo.FullName); } if (this.aAp != null) { textBlock.SetAttribute("logicEntityObjectOwnerEntity", this.aAp.OwnerEntity().UIN.ToString()); } textBlock.SetAttribute("needReturn", this.aAQ.ToString()); textBlock.SetAttribute("needReturnForWait", this.aAq.ToString()); if (this.aAR.Count != 0) { TextBlock textBlock2 = textBlock.AddChild("localVariablesBlock"); foreach (LogicLocalVariable current in this.aAR.Values) { TextBlock textBlock3 = textBlock2.AddChild("item"); current.a(textBlock3); } } textBlock.SetAttribute("currentClassActionsLevelIndex", this.aAr.ToString()); if (this.aAS.Count != 0) { string text = ""; foreach (int current2 in this.aAS) { if (text != "") { text += " "; } text += current2.ToString(); } textBlock.SetAttribute("callActionsLevelIndexes", text); } }
public static void Save() { if (!ToolsLocalization.IsInitialized) { return; } string realPathByVirtual = VirtualFileSystem.GetRealPathByVirtual(ToolsLocalization.EL); TextBlock textBlock = new TextBlock(); TextBlock textBlock2 = textBlock.AddChild("groups"); foreach (ToolsLocalization.GroupItem current in ToolsLocalization.EM.Values) { TextBlock textBlock3 = textBlock2.AddChild("group", current.eM); foreach (KeyValuePair <string, string> current2 in current.em) { textBlock3.SetAttribute(current2.Key, current2.Value); } } using (StreamWriter streamWriter = new StreamWriter(realPathByVirtual)) { streamWriter.Write(textBlock.DumpToString()); } }
public void Save( TextBlock block ) { if( scroll != Vec2.Zero ) block.SetAttribute( "scroll", scroll.ToString() ); if( scale != new Vec2( 1, 1 ) ) block.SetAttribute( "scale", scale.ToString() ); if( rotate != 0 ) block.SetAttribute( "rotate", rotate.ToString() ); if( dynamicParameters ) block.SetAttribute( "dynamicParameters", dynamicParameters.ToString() ); if( animation.IsDataExists() ) { TextBlock animationBlock = block.AddChild( "animation" ); animation.Save( animationBlock ); } }
public virtual void Save( TextBlock block ) { if( !string.IsNullOrEmpty( texture ) ) block.SetAttribute( "texture", texture ); if( texCoord != TexCoordIndexes.TexCoord0 ) block.SetAttribute( "texCoord", texCoord.ToString() ); if( clamp ) block.SetAttribute( "clamp", clamp.ToString() ); if( transform.IsDataExists() ) { TextBlock transformBlock = block.AddChild( "transform" ); transform.Save( transformBlock ); } }
protected override void OnSave( TextBlock block ) { base.OnSave( block ); //General { if( blending != MaterialBlendingTypes.Opaque ) block.SetAttribute( "blending", blending.ToString() ); if( !lighting ) block.SetAttribute( "lighting", lighting.ToString() ); if( !ambientLighting ) block.SetAttribute( "ambientLighting", ambientLighting.ToString() ); if( doubleSided ) block.SetAttribute( "doubleSided", doubleSided.ToString() ); if( !useNormals ) block.SetAttribute( "useNormals", useNormals.ToString() ); if( !receiveShadows ) block.SetAttribute( "receiveShadows", receiveShadows.ToString() ); if( receiveSimpleShadows ) block.SetAttribute( "receiveSimpleShadows", receiveSimpleShadows.ToString() ); if( alphaRejectFunction != CompareFunction.AlwaysPass ) block.SetAttribute( "alphaRejectFunction", alphaRejectFunction.ToString() ); if( alphaRejectValue != 127 ) block.SetAttribute( "alphaRejectValue", alphaRejectValue.ToString() ); if( alphaToCoverage ) block.SetAttribute( "alphaToCoverage", alphaToCoverage.ToString() ); if( fadingByDistanceRange != new Range( 0, 0 ) ) block.SetAttribute( "fadingByDistanceRange", fadingByDistanceRange.ToString() ); if( !allowFog ) block.SetAttribute( "allowFog", allowFog.ToString() ); if( !depthWrite ) block.SetAttribute( "depthWrite", depthWrite.ToString() ); if( !depthTest ) block.SetAttribute( "depthTest", depthTest.ToString() ); if( softParticles ) block.SetAttribute( "softParticles", softParticles.ToString() ); if( softParticlesFadingLength != 1 ) block.SetAttribute( "softParticlesFadingLength", softParticlesFadingLength.ToString() ); if( depthOffset != 0 ) block.SetAttribute( "depthOffset", depthOffset.ToString() ); if( halfLambert ) block.SetAttribute( "halfLambert", halfLambert.ToString() ); } //Diffuse { if( diffuseColor != new ColorValue( 1, 1, 1 ) ) block.SetAttribute( "diffuseColor", diffuseColor.ToString() ); if( diffusePower != 1 ) block.SetAttribute( "diffusePower", diffusePower.ToString() ); if( diffuseScaleDynamic ) block.SetAttribute( "diffuseScaleDynamic", diffuseScaleDynamic.ToString() ); if( diffuseVertexColor ) block.SetAttribute( "diffuseVertexColor", diffuseVertexColor.ToString() ); if( diffuse1Map.IsDataExists() ) { TextBlock diffuse1MapBlock = block.AddChild( "diffuse1Map" ); diffuse1Map.Save( diffuse1MapBlock ); } if( diffuse2Map.IsDataExists() ) { TextBlock diffuse2MapBlock = block.AddChild( "diffuse2Map" ); diffuse2Map.Save( diffuse2MapBlock ); } if( diffuse3Map.IsDataExists() ) { TextBlock diffuse3MapBlock = block.AddChild( "diffuse3Map" ); diffuse3Map.Save( diffuse3MapBlock ); } if( diffuse4Map.IsDataExists() ) { TextBlock diffuse4MapBlock = block.AddChild( "diffuse4Map" ); diffuse4Map.Save( diffuse4MapBlock ); } } //Reflection { if( reflectionColor != new ColorValue( 0, 0, 0 ) ) block.SetAttribute( "reflectionColor", reflectionColor.ToString() ); if( reflectionPower != 1 ) block.SetAttribute( "reflectionPower", reflectionPower.ToString() ); if( reflectionScaleDynamic ) block.SetAttribute( "reflectionScaleDynamic", reflectionScaleDynamic.ToString() ); if( reflectionMap.IsDataExists() ) { TextBlock reflectionMapBlock = block.AddChild( "reflectionMap" ); reflectionMap.Save( reflectionMapBlock ); } if( !string.IsNullOrEmpty( reflectionSpecificCubemap ) ) block.SetAttribute( "reflectionSpecificCubemap", reflectionSpecificCubemap ); if( reflectionBoxParallaxCorrectedCubemaps ) block.SetAttribute( "reflectionBoxParallaxCorrectedCubemaps", reflectionBoxParallaxCorrectedCubemaps.ToString() ); } //Emission { if( emissionColor != new ColorValue( 0, 0, 0 ) ) block.SetAttribute( "emissionColor", emissionColor.ToString() ); if( emissionPower != 1 ) block.SetAttribute( "emissionPower", emissionPower.ToString() ); if( emissionScaleDynamic ) block.SetAttribute( "emissionScaleDynamic", emissionScaleDynamic.ToString() ); if( emissionMap.IsDataExists() ) { TextBlock emissionMapBlock = block.AddChild( "emissionMap" ); emissionMap.Save( emissionMapBlock ); } } //Specular { if( specularColor != new ColorValue( 0, 0, 0 ) ) block.SetAttribute( "specularColor", specularColor.ToString() ); if( specularPower != 1 ) block.SetAttribute( "specularPower", specularPower.ToString() ); if( specularScaleDynamic ) block.SetAttribute( "specularScaleDynamic", specularScaleDynamic.ToString() ); if( specularMap.IsDataExists() ) { TextBlock specularMapBlock = block.AddChild( "specularMap" ); specularMap.Save( specularMapBlock ); } if( specularShininess != 20 ) block.SetAttribute( "specularShininess", specularShininess.ToString() ); } //Translucency { if( translucencyColor != new ColorValue( 0, 0, 0 ) ) block.SetAttribute( "translucencyColor", translucencyColor.ToString() ); if( translucencyPower != 1 ) block.SetAttribute( "translucencyPower", translucencyPower.ToString() ); if( translucencyDynamic ) block.SetAttribute( "translucencyDynamic", translucencyDynamic.ToString() ); if( translucencyMap.IsDataExists() ) { TextBlock translucencyMapBlock = block.AddChild( "translucencyMap" ); translucencyMap.Save( translucencyMapBlock ); } if( translucencyClearness != 4f ) block.SetAttribute( "translucencyClearness", translucencyClearness.ToString() ); } //Height { if( normalMap.IsDataExists() ) { TextBlock normalMapBlock = block.AddChild( "normalMap" ); normalMap.Save( normalMapBlock ); } if( heightFromNormalMapAlpha ) block.SetAttribute( "heightFromNormalMapAlpha", heightFromNormalMapAlpha.ToString() ); if( heightMap.IsDataExists() ) { TextBlock heightMapBlock = block.AddChild( "heightMap" ); heightMap.Save( heightMapBlock ); } if( displacementTechnique != DisplacementTechniques.ParallaxOcclusionMapping ) block.SetAttribute( "displacementTechnique", displacementTechnique.ToString() ); if( heightScale != .04f ) block.SetAttribute( "heightScale", heightScale.ToString() ); } }
protected override bool OnSave(TextBlock block) { if (!base.OnSave(block)) return false; //hitObjects if (hitObjects.Count != 0) { TextBlock hitObjectsBlock = block.AddChild("hitObjects"); if (!hitObjects.Save(hitObjectsBlock)) return false; } return true; }
public void SaveCustomConfig() { var block = new TextBlock(); var controlBloc = block.AddChild("Controls"); //var deadzone = controlBloc.AddChild("DeadZone"); var keyBlockDz = DeadZone.ToString(); block.SetAttribute("DeadZone", keyBlockDz); foreach (GameControlItem item in Items) { var currentKeyBlock = controlBloc.AddChild(item.ControlKey.ToString()); //keybord Setting if (item.BindedKeyboardMouseValues.Count > 0) { var keyboardBlock = currentKeyBlock.AddChild("Keyboard"); foreach (var keyboardvalue in item.BindedKeyboardMouseValues) { var keyBlock = keyboardBlock.AddChild("Item"); SystemKeyboardMouseValue.Save(keyboardvalue, keyBlock); } } //Joystick setting if (item.BindedJoystickValues.Count > 0) { var joystickBlock = currentKeyBlock.AddChild("Joystick"); foreach (var joystickvalue in item.BindedJoystickValues) { var keyBlock = joystickBlock.AddChild("Item"); SystemJoystickValue.Save(joystickvalue, keyBlock); } } } string fileName = VirtualFileSystem.GetRealPathByVirtual(keyconfig); try { string directoryName = Path.GetDirectoryName(fileName); if (directoryName != "" && !Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName); using (StreamWriter writer = new StreamWriter(fileName)) { writer.Write(block.DumpToString()); } } catch { Log.Fatal(string.Format("Saving file failed \"{0}\".", fileName)); return; } }
protected override void OnSave( TextBlock block ) { base.OnSave( block ); //General { if( blending != MaterialBlendingTypes.Opaque ) block.SetAttribute( "blending", blending.ToString() ); if( !lighting ) block.SetAttribute( "lighting", lighting.ToString() ); if( !culling ) block.SetAttribute( "culling", culling.ToString() ); if( !useNormals ) block.SetAttribute( "useNormals", useNormals.ToString() ); if( !receiveShadows ) block.SetAttribute( "receiveShadows", receiveShadows.ToString() ); if( alphaRejectFunction != CompareFunction.AlwaysPass ) block.SetAttribute( "alphaRejectFunction", alphaRejectFunction.ToString() ); if( alphaRejectValue != 127 ) block.SetAttribute( "alphaRejectValue", alphaRejectValue.ToString() ); if( alphaToCoverage ) block.SetAttribute( "alphaToCoverage", alphaToCoverage.ToString() ); if( fadingByDistanceRange != new Range( 0, 0 ) ) block.SetAttribute( "fadingByDistanceRange", fadingByDistanceRange.ToString() ); if( !allowFog ) block.SetAttribute( "allowFog", allowFog.ToString() ); if( !depthWrite ) block.SetAttribute( "depthWrite", depthWrite.ToString() ); if( !depthTest ) block.SetAttribute( "depthTest", depthTest.ToString() ); } //Diffuse { if( diffuseColor != new ColorValue( 1, 1, 1 ) ) block.SetAttribute( "diffuseColor", diffuseColor.ToString() ); if( diffusePower != 1 ) block.SetAttribute( "diffusePower", diffusePower.ToString() ); if( diffuseScaleDynamic ) block.SetAttribute( "diffuseScaleDynamic", diffuseScaleDynamic.ToString() ); if( diffuseVertexColor ) block.SetAttribute( "diffuseVertexColor", diffuseVertexColor.ToString() ); if( diffuse1Map.IsDataExists() ) { TextBlock diffuse1MapBlock = block.AddChild( "diffuse1Map" ); diffuse1Map.Save( diffuse1MapBlock ); } if( diffuse2Map.IsDataExists() ) { TextBlock diffuse2MapBlock = block.AddChild( "diffuse2Map" ); diffuse2Map.Save( diffuse2MapBlock ); } if( diffuse3Map.IsDataExists() ) { TextBlock diffuse3MapBlock = block.AddChild( "diffuse3Map" ); diffuse3Map.Save( diffuse3MapBlock ); } if( diffuse4Map.IsDataExists() ) { TextBlock diffuse4MapBlock = block.AddChild( "diffuse4Map" ); diffuse4Map.Save( diffuse4MapBlock ); } } //Reflection { if( reflectionColor != new ColorValue( 0, 0, 0 ) ) block.SetAttribute( "reflectionColor", reflectionColor.ToString() ); if( reflectionPower != 1 ) block.SetAttribute( "reflectionPower", reflectionPower.ToString() ); if( reflectionScaleDynamic ) block.SetAttribute( "reflectionScaleDynamic", reflectionScaleDynamic.ToString() ); if( reflectionMap.IsDataExists() ) { TextBlock reflectionMapBlock = block.AddChild( "reflectionMap" ); reflectionMap.Save( reflectionMapBlock ); } if( !string.IsNullOrEmpty( reflectionSpecificCubemap ) ) block.SetAttribute( "reflectionSpecificCubemap", reflectionSpecificCubemap ); } //Emission { if( emissionColor != new ColorValue( 0, 0, 0 ) ) block.SetAttribute( "emissionColor", emissionColor.ToString() ); if( emissionPower != 1 ) block.SetAttribute( "emissionPower", emissionPower.ToString() ); if( emissionScaleDynamic ) block.SetAttribute( "emissionScaleDynamic", emissionScaleDynamic.ToString() ); if( emissionMap.IsDataExists() ) { TextBlock emissionMapBlock = block.AddChild( "emissionMap" ); emissionMap.Save( emissionMapBlock ); } } //Specular { if( specularColor != new ColorValue( 0, 0, 0 ) ) block.SetAttribute( "specularColor", specularColor.ToString() ); if( specularPower != 1 ) block.SetAttribute( "specularPower", specularPower.ToString() ); if( specularScaleDynamic ) block.SetAttribute( "specularScaleDynamic", specularScaleDynamic.ToString() ); if( specularMap.IsDataExists() ) { TextBlock specularMapBlock = block.AddChild( "specularMap" ); specularMap.Save( specularMapBlock ); } if( specularShininess != 20 ) block.SetAttribute( "specularShininess", specularShininess.ToString() ); } //Height { if( normalMap.IsDataExists() ) { TextBlock normalMapBlock = block.AddChild( "normalMap" ); normalMap.Save( normalMapBlock ); } if( heightFromNormalMapAlpha ) block.SetAttribute( "heightFromNormalMapAlpha", heightFromNormalMapAlpha.ToString() ); if( heightMap.IsDataExists() ) { TextBlock heightMapBlock = block.AddChild( "heightMap" ); heightMap.Save( heightMapBlock ); } if( heightScale != .04f ) block.SetAttribute( "heightScale", heightScale.ToString() ); } }
public void TestLoadAndSave() { TextBlock textBlock = new TextBlock(); string id = "09234"; string name = "你的名字"; textBlock.SetAttribute("id", id); textBlock.SetAttribute("name", name); string section = "管理器"; TextBlock ctb = textBlock.AddChild(section); string section_id = "sec_928023874"; string section_name = "中文系统简要设计"; ctb.SetAttribute("id", section_id); ctb.SetAttribute("name", section_name); string rowsName = "rows"; TextBlock rowsBlock = ctb.AddChild(rowsName); int rowCount = 8; rowsBlock.SetAttribute("cnt", Convert.ToString(rowCount)); for (int i = 0; i < rowCount; i++) { string row_name = string.Format("row_{0}", i); string row_value = string.Format("值_{0}", i); rowsBlock.SetAttribute(row_name, row_value); } string textResult = textBlock.DumpToString(); string errorMessage = ""; TextBlock block = TextBlock.Parse(textResult, out errorMessage); Assert.IsNotNull(block); // Level 0 string _id = block.GetAttribute("id"); Assert.IsTrue(id == _id); string _name = block.GetAttribute("name"); Assert.IsTrue(name == _name); TextBlock _tbRnd = block.FindChild(Guid.NewGuid().ToString()); Assert.IsNull(_tbRnd); TextBlock _ctb = block.FindChild(section); Assert.IsNotNull(_ctb); string _section_id = _ctb.GetAttribute("id"); Assert.IsTrue(section_id == _section_id); string _section_name = _ctb.GetAttribute("name"); Assert.IsTrue(section_name == _section_name); TextBlock _rowsBlock = _ctb.FindChild(rowsName); Assert.IsNotNull(_rowsBlock); string _cnt = _rowsBlock.GetAttribute("cnt"); int nCnt = -1; int.TryParse(_cnt, out nCnt); Assert.IsTrue(nCnt == rowCount); for (int i = 0; i < nCnt; i++) { string _row_name = string.Format("row_{0}", i); string _row_value = string.Format("值_{0}", i); Assert.IsTrue(_rowsBlock.IsAttributeExist(_row_name)); string __row_value = _rowsBlock.GetAttribute(_row_name); Assert.IsTrue(__row_value == _row_value); } }
private bool SaveEngineConfig() { TextBlock block = new TextBlock(); //Renderer { EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType( EngineComponentManager.ComponentTypeFlags.RenderingSystem); EngineComponentManager.ComponentInfo component = null; if (comboBoxRenderSystems.SelectedIndex != -1) component = components[comboBoxRenderSystems.SelectedIndex]; TextBlock rendererBlock = block.AddChild("Renderer"); if (component != null) rendererBlock.SetAttribute("implementationComponent", component.Name); //rendering device if (component != null && component.Name.Contains("Direct3D")) { rendererBlock.SetAttribute("renderingDeviceName", (string)comboBoxRenderingDevices.SelectedItem); rendererBlock.SetAttribute("renderingDeviceIndex", (comboBoxRenderingDevices.SelectedIndex - 1).ToString()); } if (!checkBoxAllowShaders.Checked) rendererBlock.SetAttribute("allowShaders", checkBoxAllowShaders.Checked.ToString()); //depthBufferAccess if (comboBoxDepthBufferAccess.SelectedIndex != -1) { rendererBlock.SetAttribute("depthBufferAccess", (comboBoxDepthBufferAccess.SelectedIndex == 1).ToString()); } //fullSceneAntialiasing if (comboBoxAntialiasing.SelectedIndex != -1) { ComboBoxItem item = (ComboBoxItem)comboBoxAntialiasing.SelectedItem; rendererBlock.SetAttribute("fullSceneAntialiasing", item.Identifier); } //filtering if (comboBoxFiltering.SelectedIndex != -1) { RendererWorld.FilteringModes filtering = (RendererWorld.FilteringModes) comboBoxFiltering.SelectedIndex; rendererBlock.SetAttribute("filtering", filtering.ToString()); } //renderTechnique if (comboBoxRenderTechnique.SelectedIndex != -1) { ComboBoxItem item = (ComboBoxItem)comboBoxRenderTechnique.SelectedItem; rendererBlock.SetAttribute("renderTechnique", item.Identifier); } //multiMonitorMode if (comboBoxVideoMode.SelectedIndex == 1) rendererBlock.SetAttribute("multiMonitorMode", true.ToString()); //videoMode if (comboBoxVideoMode.SelectedIndex >= 2) { string[] strings = ((string)comboBoxVideoMode.SelectedItem). Split(new char[] { 'x' }); Vec2I videoMode = new Vec2I(int.Parse(strings[0]), int.Parse(strings[1])); rendererBlock.SetAttribute("videoMode", videoMode.ToString()); } //fullScreen rendererBlock.SetAttribute("fullScreen", checkBoxFullScreen.Checked.ToString()); //vertical sync rendererBlock.SetAttribute("verticalSync", checkBoxVerticalSync.Checked.ToString()); } //Physics system { EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType( EngineComponentManager.ComponentTypeFlags.PhysicsSystem); EngineComponentManager.ComponentInfo component = null; if (comboBoxPhysicsSystems.SelectedIndex != -1) component = components[comboBoxPhysicsSystems.SelectedIndex]; if (component != null) { TextBlock physicsSystemBlock = block.AddChild("PhysicsSystem"); physicsSystemBlock.SetAttribute("implementationComponent", component.Name); //physicsSystemBlock.SetAttribute( "allowHardwareAcceleration", // checkBoxPhysicsAllowHardwareAcceleration.Checked.ToString() ); } } //Sound system { EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType( EngineComponentManager.ComponentTypeFlags.SoundSystem); EngineComponentManager.ComponentInfo component = null; if (comboBoxSoundSystems.SelectedIndex != -1) component = components[comboBoxSoundSystems.SelectedIndex]; if (component != null) { TextBlock soundSystemBlock = block.AddChild("SoundSystem"); soundSystemBlock.SetAttribute("implementationComponent", component.Name); } } //Localization { string language = "Autodetect"; if (comboBoxLanguages.SelectedIndex > 0) language = (string)comboBoxLanguages.SelectedItem; TextBlock localizationBlock = block.AddChild("Localization"); localizationBlock.SetAttribute("language", language); if (!checkBoxLocalizeEngine.Checked) localizationBlock.SetAttribute("localizeEngine", checkBoxLocalizeEngine.Checked.ToString()); if (!checkBoxLocalizeToolset.Checked) localizationBlock.SetAttribute("localizeToolset", checkBoxLocalizeToolset.Checked.ToString()); } //save file { string fileName = VirtualFileSystem.GetRealPathByVirtual( "user:Configs/Engine.config"); try { string directoryName = Path.GetDirectoryName(fileName); if (directoryName != "" && !Directory.Exists(directoryName)) Directory.CreateDirectory(directoryName); using (StreamWriter writer = new StreamWriter(fileName)) { writer.Write(block.DumpToString()); } } catch { string text = string.Format("Saving file failed \"{0}\".", fileName); MessageBox.Show(text, "Configurator", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } } return true; }
public bool Save( TextBlock block ) { //fireObjects if( fireObjects.Count != 0 ) { TextBlock fireObjectsBlock = block.AddChild( "fireObjects" ); if( !fireObjects.Save( fireObjectsBlock ) ) return false; } return true; }
public static bool SaveFieldValue(bool entitySerialize, object owner, FieldInfo field, TextBlock block, object defaultValue, string errorString) { if (field == null) { return(false); } object value = field.GetValue(owner); if (value == null) { return(true); } string serializeName = GetFieldSerializeName(entitySerialize, field); errorString += string.Format(", property: \"{0}\"", serializeName); bool IsList = field.FieldType.IsGenericType && field.FieldType.Name == typeof(List <>).Name; bool isArray = field.FieldType.IsArray; bool FieldIsCollection = IsList | isArray; if (FieldIsCollection) { if (isArray && field.FieldType.GetArrayRank() != 1) { Log.Fatal("Entity System: Serialization of arrays are supported only for one dimensions arrays ({0}).", errorString); return(false); } bool saveResult = SaveCollectionFieldValue(entitySerialize, owner, field, block, defaultValue, errorString); return(saveResult); } bool isEntityType = typeof(EntityType).IsAssignableFrom(field.FieldType); bool isEntity = typeof(Entity).IsAssignableFrom(field.FieldType); bool simpleSerialization = (SimpleTypesUtils.IsSimpleType(field.FieldType) | isEntityType | isEntity) || typeof(Type) == field.FieldType; if (simpleSerialization) { if (!entitySerialize & isEntity) { Log.Fatal("Entity System: Serialization Entity classes in entity types is forbidden ({0}).", errorString); return(false); } if (isEntity) { Entity entity = (Entity)value; if (!entity.AllowSaveHerit()) { Log.Fatal("Entity System: Serialization error. The reference to entity which does not allow serialization ({0}). Field to serialize: \"{1}\".", entity.ToString(), errorString); return(false); } } string saveValueString = ConvertToString(field.FieldType, value, errorString); string defaultSaveValueString = null; if (defaultValue != null) { bool isEnum = field.FieldType.IsEnum; if (isEnum) { defaultSaveValueString = Enum.GetName(field.FieldType, defaultValue); } else { defaultSaveValueString = defaultValue.ToString(); } } bool shouldSave = (defaultSaveValueString != null && defaultSaveValueString != saveValueString) || (defaultValue == null && saveValueString != ""); if (shouldSave) { block.SetAttribute(serializeName, saveValueString); } return(true); } TextBlock blockSerialize = block.AddChild(serializeName); Type type = field.FieldType; if (field.FieldType == typeof(LogicEntityObject)) { type = field.GetValue(owner).GetType(); } while (type != null) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); for (int m = 0; m < fields.Length; m++) { FieldInfo fieldInfo = fields[m]; if (!IsFieldSerializable(fieldInfo, entitySerialize)) { continue; } bool saveResult = SaveFieldValue(entitySerialize, value, fieldInfo, blockSerialize, errorString); if (!saveResult) { return(false); } } type = type.BaseType; } return(true); }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnSave(TextBlock)"/>.</summary> protected override void OnSave( TextBlock block ) { base.OnSave( block ); //World serialization: save animation tree. if( EntitySystemWorld.Instance.SerializationMode == SerializationModes.World ) { AnimationTree tree = GetFirstAnimationTree(); if( tree != null ) { TextBlock treeBlock = block.AddChild( "animationTree" ); tree.WorldSave( treeBlock ); } } }
private static bool SaveCollectionFieldValue( bool entitySerialize, object obj, FieldInfo fieldInfo, TextBlock textBlock, object defaultObj, string errorMessage) { object value = fieldInfo.GetValue(obj); bool isArray = fieldInfo.FieldType.IsArray; List <object> items = new List <object>(); #region 获得Collection中的元素 -> items if (isArray) { PropertyInfo propertyLength = fieldInfo.FieldType.GetProperty("Length"); MethodInfo methodGetValue = fieldInfo.FieldType.GetMethod("GetValue", new Type[] { typeof(int) }); int arrayLength = (int)propertyLength.GetValue(value, null); for (int i = 0; i < arrayLength; i++) { object o = methodGetValue.Invoke(value, new object[] { i }); items.Add(o); } } else { PropertyInfo propertyCount = fieldInfo.FieldType.GetProperty("Count"); PropertyInfo propertyItem = fieldInfo.FieldType.GetProperty("Item"); int listCount = (int)propertyCount.GetValue(value, null); for (int j = 0; j < listCount; j++) { object o1 = propertyItem.GetValue(value, new object[] { j }); items.Add(o1); } } #endregion bool entityTypeDefaultSerialize = !entitySerialize && obj is EntityType && defaultObj != null; #region EntityType 如果是缺省值,就不保存 if (entityTypeDefaultSerialize) { int itemsCount = 0; if (isArray) { PropertyInfo propertyLength = fieldInfo.FieldType.GetProperty("Length"); itemsCount = (int)propertyLength.GetValue(defaultObj, null); } else { PropertyInfo propertyCount = fieldInfo.FieldType.GetProperty("Count"); itemsCount = (int)propertyCount.GetValue(defaultObj, null); } if (items.Count == 0 & itemsCount == 0) { return(true); } } #endregion Type typeElement = typeof(object); if (isArray) { typeElement = fieldInfo.FieldType.GetElementType(); } else { typeElement = fieldInfo.FieldType.GetGenericArguments()[0]; } string fieldSerializeName = GetFieldSerializeName(entitySerialize, fieldInfo); if (typeElement == typeof(string)) { TextBlock stringsBlock = textBlock.AddChild(fieldSerializeName); for (int k = 0; k < items.Count; k++) { object item = items[k]; TextBlock textBlock3 = stringsBlock.AddChild("item"); if (item != null) { textBlock3.SetAttribute("value", (string)item); } else { textBlock3.SetAttribute(NULL_ITEM, true.ToString()); } } return(true); } bool isEntityType = typeof(EntityType).IsAssignableFrom(typeElement); bool isEntity = typeof(Entity).IsAssignableFrom(typeElement); bool simpleTypeSerializing = (SimpleTypesUtils.IsSimpleType(typeElement) | isEntityType | isEntity) || typeof(Type) == typeElement; if (simpleTypeSerializing) { if (!entitySerialize & isEntity) { Log.Fatal("Entity System: Serialization Entity classes in entity types is forbidden ({0}).", errorMessage); return(false); } char itemSeperator = typeElement.IsPrimitive | isEntity? ' ' : ';'; StringBuilder stringBuilder = new StringBuilder(); for (int l = 0; l < items.Count; l++) { object item = items[l]; if (isEntity && item != null) { Entity entity = (Entity)item; if (!entity.AllowSaveHerit()) { Log.Fatal("Entity System: Serialization error. The reference to entity which does not allow serialization ({0}). Field to serialize: \"{1}\".", entity.ToString(), errorMessage); return(false); } } if (l != 0) { stringBuilder.Append(itemSeperator); } if (item != null) { stringBuilder.Append(ConvertToString(typeElement, item, errorMessage + ": " + fieldSerializeName)); } else { stringBuilder.Append("null"); } } textBlock.SetAttribute(fieldSerializeName, stringBuilder.ToString()); return(true); } TextBlock textBlockField = textBlock.AddChild(fieldSerializeName); List <FieldInfo> list = GetTypeSerializableFields(entitySerialize, typeElement); for (int m = 0; m < items.Count; m++) { object item = items[m]; TextBlock textBlockItem = textBlockField.AddChild("item"); if (item == null) { textBlockItem.SetAttribute(NULL_ITEM, true.ToString()); continue; } for (int k = 0; k < list.Count; k++) { FieldInfo elementField = list[k]; bool _saveResult = SaveFieldValue(entitySerialize, item, elementField, textBlockItem, errorMessage); if (!_saveResult) { return(false); } } } return(true); }
protected virtual void OnSave(TextBlock block) { block.SetAttribute("type", Type.Name); block.SetAttribute("uin", uin.ToString()); if (!(this is LogicComponent)) { block.SetAttribute("classPrompt", Type.ClassInfo.entityClassType.Name); } if (subscriptionsToDeletionEvent != null && subscriptionsToDeletionEvent.Count != 0) { string _subscriptionsToDeletionEvent = string.Join(" ", subscriptionsToDeletionEvent.Select(_x => _x.UIN)); block.SetAttribute("subscriptionsToDeletionEvent", _subscriptionsToDeletionEvent); } string text = Type.Name; if (this.name != "") { text += string.Format(" ({0})", this.name); } text = string.Format("Entity: \"{0}\"", text); for (EntityTypes.ClassInfo classInfo = Type.ClassInfo; classInfo != null; classInfo = classInfo.BaseClassInfo) { foreach (EntityTypes.ClassInfo.EntitySerializableFieldItem current2 in classInfo.EntitySerializableFields) { //if (EntitySystemWorld.Instance.IsEntityFieldSerializable(current2.SupportedSerializationTypes)) { if (!EntityHelper.SaveFieldValue(true, this, current2.Field, block, text)) { return; } } } } if (logicClass != null) { block.SetAttribute("logicClass", logicClass.UIN.ToString()); } if (extendedProperties != null) { TextBlock textBlock = block.AddChild("extendedProperties"); textBlock.SetAttribute("class", this.extendedProperties.GetType().Name); extendedProperties.OnSave(textBlock); } if (logicObject != null) { TextBlock logicObjectBlock = block.FindChild("logicObject"); if (logicObjectBlock == null) { logicObjectBlock = block.AddChild("logicObject"); } logicObject.OnSave(logicObjectBlock); return; } }
bool SaveEngineConfig() { TextBlock block = new TextBlock(); //Renderer { EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType( EngineComponentManager.ComponentTypeFlags.RenderingSystem); EngineComponentManager.ComponentInfo component = null; if (comboBoxRenderSystems.SelectedIndex != -1) { component = components[comboBoxRenderSystems.SelectedIndex]; } TextBlock rendererBlock = block.AddChild("Renderer"); if (component != null) { rendererBlock.SetAttribute("implementationComponent", component.Name); } //rendering device if (component != null && component.Name.Contains("Direct3D")) { rendererBlock.SetAttribute("renderingDeviceName", (string)comboBoxRenderingDevices.SelectedItem); rendererBlock.SetAttribute("renderingDeviceIndex", (comboBoxRenderingDevices.SelectedIndex - 1).ToString()); } if (!checkBoxAllowShaders.Checked) { rendererBlock.SetAttribute("allowShaders", checkBoxAllowShaders.Checked.ToString()); } //depthBufferAccess if (comboBoxDepthBufferAccess.SelectedIndex != -1) { rendererBlock.SetAttribute("depthBufferAccess", (comboBoxDepthBufferAccess.SelectedIndex == 1).ToString()); } //fullSceneAntialiasing if (comboBoxAntialiasing.SelectedIndex != -1) { ComboBoxItem item = (ComboBoxItem)comboBoxAntialiasing.SelectedItem; rendererBlock.SetAttribute("fullSceneAntialiasing", item.Identifier); } //filtering if (comboBoxFiltering.SelectedIndex != -1) { RendererWorld.FilteringModes filtering = (RendererWorld.FilteringModes) comboBoxFiltering.SelectedIndex; rendererBlock.SetAttribute("filtering", filtering.ToString()); } //renderTechnique if (comboBoxRenderTechnique.SelectedIndex != -1) { ComboBoxItem item = (ComboBoxItem)comboBoxRenderTechnique.SelectedItem; rendererBlock.SetAttribute("renderTechnique", item.Identifier); } //multiMonitorMode if (comboBoxVideoMode.SelectedIndex == 1) { rendererBlock.SetAttribute("multiMonitorMode", true.ToString()); } //videoMode if (comboBoxVideoMode.SelectedIndex >= 2) { string[] strings = ((string)comboBoxVideoMode.SelectedItem). Split(new char[] { 'x' }); Vec2I videoMode = new Vec2I(int.Parse(strings[0]), int.Parse(strings[1])); rendererBlock.SetAttribute("videoMode", videoMode.ToString()); } //fullScreen rendererBlock.SetAttribute("fullScreen", checkBoxFullScreen.Checked.ToString()); //vertical sync rendererBlock.SetAttribute("verticalSync", checkBoxVerticalSync.Checked.ToString()); } //Physics system { EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType( EngineComponentManager.ComponentTypeFlags.PhysicsSystem); EngineComponentManager.ComponentInfo component = null; if (comboBoxPhysicsSystems.SelectedIndex != -1) { component = components[comboBoxPhysicsSystems.SelectedIndex]; } if (component != null) { TextBlock physicsSystemBlock = block.AddChild("PhysicsSystem"); physicsSystemBlock.SetAttribute("implementationComponent", component.Name); //physicsSystemBlock.SetAttribute( "allowHardwareAcceleration", // checkBoxPhysicsAllowHardwareAcceleration.Checked.ToString() ); } } //Sound system { EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType( EngineComponentManager.ComponentTypeFlags.SoundSystem); EngineComponentManager.ComponentInfo component = null; if (comboBoxSoundSystems.SelectedIndex != -1) { component = components[comboBoxSoundSystems.SelectedIndex]; } if (component != null) { TextBlock soundSystemBlock = block.AddChild("SoundSystem"); soundSystemBlock.SetAttribute("implementationComponent", component.Name); } } //Localization { string language = "Autodetect"; if (comboBoxLanguages.SelectedIndex > 0) { language = (string)comboBoxLanguages.SelectedItem; } TextBlock localizationBlock = block.AddChild("Localization"); localizationBlock.SetAttribute("language", language); if (!checkBoxLocalizeEngine.Checked) { localizationBlock.SetAttribute("localizeEngine", checkBoxLocalizeEngine.Checked.ToString()); } if (!checkBoxLocalizeToolset.Checked) { localizationBlock.SetAttribute("localizeToolset", checkBoxLocalizeToolset.Checked.ToString()); } } //save file { string fileName = VirtualFileSystem.GetRealPathByVirtual( "user:Configs/Engine.config"); try { string directoryName = Path.GetDirectoryName(fileName); if (directoryName != "" && !Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } using (StreamWriter writer = new StreamWriter(fileName)) { writer.Write(block.DumpToString()); } } catch { string text = string.Format("Saving file failed \"{0}\".", fileName); MessageBox.Show(text, "Configurator", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } return(true); }
protected override void OnFormClosing( FormClosingEventArgs e ) { if( DialogResult == DialogResult.OK ) { //save Engine.config TextBlock block = new TextBlock(); //Renderer { TextBlock rendererBlock = block.AddChild( "Renderer" ); string renderSystemName = ""; if( comboBoxRenderSystems.SelectedIndex != -1 ) renderSystemName = (string)comboBoxRenderSystems.SelectedItem; if( renderSystemName != "" ) rendererBlock.SetAttribute( "renderSystemName", renderSystemName ); //maxPixelShaders { EnumTypeConverter enumConverter = new EnumTypeConverter( typeof( RendererWorld.MaxPixelShadersVersions ) ); string text = comboBoxMaxPixelShaders.SelectedItem.ToString(); RendererWorld.MaxPixelShadersVersions maxPixelShaders = (RendererWorld.MaxPixelShadersVersions)enumConverter.ConvertFromString( text ); rendererBlock.SetAttribute( "maxPixelShaders", maxPixelShaders.ToString() ); } //maxVertexShaders { EnumTypeConverter enumConverter = new EnumTypeConverter( typeof( RendererWorld.MaxVertexShadersVersions ) ); string text = comboBoxMaxVertexShaders.SelectedItem.ToString(); RendererWorld.MaxVertexShadersVersions maxVertexShaders = (RendererWorld.MaxVertexShadersVersions)enumConverter.ConvertFromString( text ); rendererBlock.SetAttribute( "maxVertexShaders", maxVertexShaders.ToString() ); } //fullSceneAntialiasing { int fullSceneAntialiasing = 0; if( comboBoxAntialiasing.SelectedIndex > 0 ) fullSceneAntialiasing = int.Parse( (string)comboBoxAntialiasing.SelectedItem ); rendererBlock.SetAttribute( "fullSceneAntialiasing", fullSceneAntialiasing.ToString() ); } //filtering { EnumTypeConverter enumConverter = new EnumTypeConverter( typeof( RendererWorld.FilteringModes ) ); string text = comboBoxFiltering.SelectedItem.ToString(); RendererWorld.FilteringModes filtering = (RendererWorld.FilteringModes)enumConverter.ConvertFromString( text ); rendererBlock.SetAttribute( "filtering", filtering.ToString() ); } //renderTechnique if( comboBoxRenderTechnique.SelectedIndex != -1 ) { string renderTechnique = ""; if( comboBoxRenderTechnique.SelectedIndex != 0 ) { renderTechnique = ( (RenderTechniqueItem)comboBoxRenderTechnique.SelectedItem ).Name; } rendererBlock.SetAttribute( "renderTechnique", renderTechnique ); } //videoMode if( comboBoxVideoMode.SelectedIndex > 0 ) { string[] strings = ( (string)comboBoxVideoMode.SelectedItem ). Split( new char[] { 'x' } ); Vec2i videoMode = new Vec2i( int.Parse( strings[ 0 ] ), int.Parse( strings[ 1 ] ) ); rendererBlock.SetAttribute( "videoMode", videoMode.ToString() ); } //fullScreen rendererBlock.SetAttribute( "fullScreen", checkBoxFullScreen.Checked.ToString() ); //vertical sync rendererBlock.SetAttribute( "verticalSync", checkBoxVerticalSync.Checked.ToString() ); //allowChangeDisplayFrequency rendererBlock.SetAttribute( "allowChangeDisplayFrequency", checkBoxAllowChangeDisplayFrequency.Checked.ToString() ); } //Physics system { string physicsSystemName = ""; if( comboBoxPhysicsSystems.SelectedIndex != -1 ) physicsSystemName = (string)comboBoxPhysicsSystems.SelectedItem; //physics system name TextBlock physicsSystemBlock = block.AddChild( "PhysicsSystem" ); if( physicsSystemName != "" ) physicsSystemBlock.SetAttribute( "physicsSystemName", physicsSystemName ); } //Sound system { string soundSystemName = ""; if( comboBoxSoundSystems.SelectedIndex != -1 ) soundSystemName = (string)comboBoxSoundSystems.SelectedItem; TextBlock soundSystemBlock = block.AddChild( "SoundSystem" ); if( soundSystemName != "" ) soundSystemBlock.SetAttribute( "soundSystemName", soundSystemName ); } //Localization { string language = "English"; if( comboBoxLanguages.SelectedIndex != -1 ) language = (string)comboBoxLanguages.SelectedItem; TextBlock localizationBlock = block.AddChild( "Localization" ); localizationBlock.SetAttribute( "language", language ); } //save file { string fileName = VirtualFileSystem.GetRealPathByVirtual( "user:Configs/Engine.config" ); try { string directoryName = Path.GetDirectoryName( fileName ); if( directoryName != "" && !Directory.Exists( directoryName ) ) Directory.CreateDirectory( directoryName ); using( StreamWriter writer = new StreamWriter( fileName ) ) { writer.Write( block.DumpToString() ); } } catch { string text = string.Format( "Saving file failed \"{0}\".", fileName ); MessageBox.Show( text, "Configurator", MessageBoxButtons.OK, MessageBoxIcon.Warning ); e.Cancel = true; return; } } } base.OnFormClosing( e ); }
void SaveAnimationState( TextBlock block ) { if( currentAnimationItem != null && !currentAnimationItem.Removed ) { TextBlock itemBlock = block.AddChild( "currentAnimationItem" ); MeshObjectAnimationController.AnimationItem item = currentAnimationItem; itemBlock.SetAttribute( "animationBaseName", item.AnimationBaseName ); itemBlock.SetAttribute( "allowRandomAnimationNumber", item.AllowRandomAnimationNumber.ToString() ); itemBlock.SetAttribute( "loop", item.Loop.ToString() ); itemBlock.SetAttribute( "velocity", item.Velocity.ToString() ); itemBlock.SetAttribute( "weight", item.Weight.ToString() ); itemBlock.SetAttribute( "timePosition", item.TimePosition.ToString() ); } if( forceAnimationRemainingTime != 0 ) { block.SetAttribute( "forceAnimationRemainingTime", forceAnimationRemainingTime.ToString() ); } }