public frmArea(Battle battle, Area area) { InitializeComponent(); this.battle = battle; this.area = area; displayArea(area); }
public frmArea(Battle battle) { InitializeComponent(); this.battle = battle; area = new Area(); cboAreaID.Text = "1"; cboAreaCountry.Text = "de"; rdbNoConstruction.Checked = true; rdbNoInstallation.Checked = true; }
private void btnAddArea_Click(object sender, EventArgs e) { saveArea(); if (!battle.areaList.Exists(i => i.id == area.id)) { battle.areaList.Add(area); } battle.areaList = battle.areaList.OrderBy(x => x.id).ToList(); area = new Area(); MessageBox.Show("儲存地塊成功。", "歐三戰役編輯器", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); }
private void cboAreaID_Validating(object sender, CancelEventArgs e) { int tempAreaID; if (!int.TryParse(cboAreaID.Text, out tempAreaID)) { MessageBox.Show("地塊ID不能為空。", "歐三戰役編輯器", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); e.Cancel = true; } else if (battle.areaList.Exists(i => i.id.Equals(tempAreaID))) { area = battle.areaList.Find(i => i.id.Equals(tempAreaID)); displayArea(area); } }
private void displayArea(Area area) { cboAreaID.Text = area.id.ToString(); cboAreaCountry.Text = area.country; if (area.construction == Construction.none) { rdbNoConstruction.Checked = true; pnlConstructionLevel.Visible = false; } if (area.construction == Construction.city) { rdbCity.Checked = true; pnlConstructionLevel.Visible = true; cboAreaLevel.Items.Clear(); for (int i = 1; i <= (int)Construction.city; i++) { cboAreaLevel.Items.Add(i.ToString()); } cboAreaLevel.SelectedItem = area.level.ToString(); } if (area.construction == Construction.industry) { rdbIndustry.Checked = true; pnlConstructionLevel.Visible = true; cboAreaLevel.Items.Clear(); for (int i = 1; i <= (int)Construction.industry; i++) { cboAreaLevel.Items.Add(i.ToString()); } cboAreaLevel.SelectedItem = area.level.ToString(); } if (area.construction == Construction.airport) { rdbAirport.Checked = true; pnlConstructionLevel.Visible = false; } if (area.installation == Installation.none) { rdbNoInstallation.Checked = true; } if (area.installation == Installation.entrenchment) { rdbEntrenchment.Checked = true; } if (area.installation == Installation.fort) { rdbFort.Checked = true; } if (area.installation == Installation.antiaircraft) { rdbAntiaircraft.Checked = true; } }
public string ReadFile(string filePath) { XDocument battleXml = new XDocument(); battleXml = XDocument.Load(filePath, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo | LoadOptions.SetBaseUri); XmlSchemaSet schemas = new XmlSchemaSet(); schemas.Add("", "Battle.xsd"); schemas.Compile(); String errorMessage = ""; Console.WriteLine("Attempting to validate"); bool errors = false; battleXml.Validate(schemas, (o, e) => { errorMessage += "XML " + e.Severity + ": " + e.Message + "(Line " + e.Exception.LineNumber + ")" + "\n"; errors = true; }); Console.WriteLine("Reading Xml {0}", errors ? "did not validate" : "validated"); Console.WriteLine(); if (errors) { return errorMessage; } IEnumerable<XElement> countryNode; IEnumerable<XElement> areaNode; if (battleXml.Element("battle").Attribute("areasenable") != null) { battleName = battleXml.Element("battle").Attribute("areasenable").Value; battleName = battleName.Substring(0, battleName.IndexOf(".")); } else { battleName = ""; } map = int.Parse(battleXml.Element("battle").Attribute("map").Value); countryNode = battleXml.Element("battle").Elements("list").Where(x => x.Attribute("name").Value.Equals("country")).SingleOrDefault().Elements("country"); areaNode = battleXml.Element("battle").Elements("list").Where(x => x.Attribute("name").Value.Equals("area")).SingleOrDefault().Elements("area"); foreach (XElement country in countryNode) { Country tempCountry = new Country(country); if (!countryList.Exists(i => i.name.Equals(tempCountry.name))) { countryList.Add(tempCountry); } else { errors = true; errorMessage += "國家名稱: \"" + tempCountry.name + "\" 重複出現!\n"; } } foreach (XElement area in areaNode) { Area tempArea = new Area(area); if (!areaList.Exists(i => i.id == tempArea.id)) { areaList.Add(tempArea); } else { errors = true; errorMessage += "地塊ID: \"" + tempArea.id + "\" 重複出現!\n"; } } return errorMessage; }
public string ReadFile(string filePath) { XDocument battleXml = new XDocument(); battleXml = XDocument.Load(filePath, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo | LoadOptions.SetBaseUri); XmlSchemaSet schemas = new XmlSchemaSet(); schemas.Add("", "Battle.xsd"); schemas.Compile(); String errorMessage = ""; Console.WriteLine("Attempting to validate"); bool errors = false; battleXml.Validate(schemas, (o, e) => { errorMessage += "XML " + e.Severity + ": " + e.Message + "(Line " + e.Exception.LineNumber + ")" + "\n"; errors = true; }); Console.WriteLine("Reading Xml {0}", errors ? "did not validate" : "validated"); Console.WriteLine(); if (errors) { return(errorMessage); } IEnumerable <XElement> countryNode; IEnumerable <XElement> areaNode; if (battleXml.Element("battle").Attribute("areasenable") != null) { battleName = battleXml.Element("battle").Attribute("areasenable").Value; battleName = battleName.Substring(0, battleName.IndexOf(".")); } else { battleName = ""; } map = int.Parse(battleXml.Element("battle").Attribute("map").Value); countryNode = battleXml.Element("battle").Elements("list").Where(x => x.Attribute("name").Value.Equals("country")).SingleOrDefault().Elements("country"); areaNode = battleXml.Element("battle").Elements("list").Where(x => x.Attribute("name").Value.Equals("area")).SingleOrDefault().Elements("area"); foreach (XElement country in countryNode) { Country tempCountry = new Country(country); if (!countryList.Exists(i => i.name.Equals(tempCountry.name))) { countryList.Add(tempCountry); } else { errors = true; errorMessage += "國家名稱: \"" + tempCountry.name + "\" 重複出現!\n"; } } foreach (XElement area in areaNode) { Area tempArea = new Area(area); if (!areaList.Exists(i => i.id == tempArea.id)) { areaList.Add(tempArea); } else { errors = true; errorMessage += "地塊ID: \"" + tempArea.id + "\" 重複出現!\n"; } } return(errorMessage); }