public frmCountry(Battle battle) { InitializeComponent(); this.battle = battle; country = new Country(); if (battle.countryList != null) { foreach (Country tempcountry in battle.countryList) { cboCountryID.Items.Add(tempcountry.id); } } cboCountryID.Text = "de"; txtCountryName.Text = "de"; rdbAiYes.Checked = true; rdbDefeatedLand.Checked = true; txtTaxFactor.Text = "1.000000"; txtMoney.Text = "100"; txtIndustry.Text = "100"; txtTechLevel.Text = "3"; rdbAllianceA.Checked = true; txtColorR.Text = "0"; txtColorG.Text = "0"; txtColorB.Text = "0"; txtColorA.Text = "0"; }
private void btnSaveCountry_Click(object sender, EventArgs e) { setCountry(); if (!battle.countryList.Exists(i => i.id.Equals(country.id))) { battle.countryList.Add(country); } country = new Country(); MessageBox.Show("儲存國家成功。", "世二戰役編輯器", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); }
public frmCountry(Battle battle, Country country) { InitializeComponent(); this.battle = battle; this.country = country; if (battle.countryList != null) { foreach (Country tempcountry in battle.countryList) { cboCountryID.Items.Add(tempcountry.id); } } displayCountry(country); }
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 cboCountryID_Validating(object sender, CancelEventArgs e) { if (cboCountryID.Text.Equals("")) { MessageBox.Show("請設定國家ID。", "世二戰役編輯器", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); e.Cancel = true; } else if (battle.countryList.Exists(i => i.id.Equals(cboCountryID.Text))) { country = battle.countryList.Find(i => i.id.Equals(cboCountryID.Text)); displayCountry(country); } }
private void displayCountry(Country country) { cboCountryID.Text = country.id; txtCountryName.Text = country.name; if (country.ai == 0) { rdbAiNo.Checked = true; } else { rdbAiYes.Checked = true; } txtTaxFactor.Text = country.taxfactor.ToString("0.000000"); if (country.defeated == Defeated.army) { rdbDefeatedArmy.Checked = true; } else { rdbDefeatedLand.Checked = true; } txtMoney.Text = country.money.ToString(); txtIndustry.Text = country.industry.ToString(); txtTechLevel.Text = country.techlevel.ToString(); cboCommander.Text = country.commander; if (country.alliance == Alliance.a) { rdbAllianceA.Checked = true; } if (country.alliance == Alliance.b) { rdbAllianceB.Checked = true; } if (country.alliance == Alliance.c) { rdbAllianceC.Checked = true; } if (country.alliance == Alliance.n) { rdbAllianceN.Checked = true; } txtColorR.Text = country.color.r.ToString(); txtColorG.Text = country.color.g.ToString(); txtColorB.Text = country.color.b.ToString(); txtColorA.Text = country.color.a.ToString(); }