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); } }
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; }); if (errors) { return errorMessage; } IEnumerable<XElement> countryNode; IEnumerable<XElement> areaNode; IEnumerable<XElement> dialogueNode; if (battleXml.Element("battle") != null) { battleType = BattleType.battle; battleName = battleXml.Element("battle").Attribute("areasenable").Value; battleName = battleName.Substring(0, battleName.IndexOf(".")); 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"); dialogueNode = battleXml.Element("battle").Elements("list").Where(x => x.Attribute("name").Value.Equals("dialogue")).SingleOrDefault().Elements("dialogue"); } else { battleType = BattleType.conquest; battleName = battleXml.Element("conquest").Attribute("areasenable").Value; battleName = battleName.Substring(0, battleName.IndexOf(".")); countryNode = battleXml.Element("conquest").Elements("list").Where(x => x.Attribute("name").Value.Equals("country")).SingleOrDefault().Elements("country"); areaNode = battleXml.Element("conquest").Elements("list").Where(x => x.Attribute("name").Value.Equals("area")).SingleOrDefault().Elements("area"); dialogueNode = battleXml.Element("conquest").Elements("list").Where(x => x.Attribute("name").Value.Equals("dialogue")).SingleOrDefault().Elements("dialogue"); } foreach (XElement country in countryNode) { Country tempCountry = new Country(country); if(!countryList.Exists(i=>i.id.Equals(tempCountry.id))) { countryList.Add(tempCountry); } else { errors = true; errorMessage += "國家ID \"" + tempCountry.id + "\" 重複出現!\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"; } } if (dialogueNode != null) { foreach (XElement dialogue in dialogueNode) { dialogueList.Add(new Dialogue(dialogue)); } } return errorMessage; }
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.constructionLevel.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.constructionLevel.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; } if (area.installation == Installation.radar) { rdbRadar.Checked = true; } }