private void cmdOK_Click(object sender, EventArgs e) { //TODO: THIS IS UGLY AS SHIT, FIX BETTER string strSelectedMount = cboSize.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedMount)) { return; } string strSelectedControl = cboControl.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedControl)) { return; } string strSelectedFlexibility = cboFlexibility.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedFlexibility)) { return; } string strSelectedVisibility = cboVisibility.SelectedValue?.ToString(); if (string.IsNullOrEmpty(strSelectedVisibility)) { return; } XmlNode xmlSelectedMount = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedMount + "\"]"); if (xmlSelectedMount == null) { return; } XmlNode xmlSelectedControl = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedControl + "\"]"); if (xmlSelectedControl == null) { return; } XmlNode xmlSelectedFlexibility = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedFlexibility + "\"]"); if (xmlSelectedFlexibility == null) { return; } XmlNode xmlSelectedVisibility = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + strSelectedVisibility + "\"]"); if (xmlSelectedVisibility == null) { return; } XmlNode xmlForbiddenNode = xmlSelectedMount["forbidden"]; if (xmlForbiddenNode != null) { string strStringToCheck = xmlSelectedControl["name"]?.InnerText; if (!string.IsNullOrEmpty(strStringToCheck)) { using (XmlNodeList xmlControlNodeList = xmlForbiddenNode.SelectNodes("control")) if (xmlControlNodeList?.Count > 0) { foreach (XmlNode xmlLoopNode in xmlControlNodeList) { if (xmlLoopNode.InnerText == strStringToCheck) { return; } } } } strStringToCheck = xmlSelectedFlexibility["name"]?.InnerText; if (!string.IsNullOrEmpty(strStringToCheck)) { using (XmlNodeList xmlFlexibilityNodeList = xmlForbiddenNode.SelectNodes("flexibility")) if (xmlFlexibilityNodeList?.Count > 0) { foreach (XmlNode xmlLoopNode in xmlFlexibilityNodeList) { if (xmlLoopNode.InnerText == strStringToCheck) { return; } } } } strStringToCheck = xmlSelectedVisibility["name"]?.InnerText; if (!string.IsNullOrEmpty(strStringToCheck)) { using (XmlNodeList xmlVisibilityNodeList = xmlForbiddenNode.SelectNodes("visibility")) if (xmlVisibilityNodeList?.Count > 0) { foreach (XmlNode xmlLoopNode in xmlVisibilityNodeList) { if (xmlLoopNode.InnerText == strStringToCheck) { return; } } } } } XmlNode xmlRequiredNode = xmlSelectedMount["required"]; if (xmlRequiredNode != null) { bool blnRequirementsMet = true; string strStringToCheck = xmlSelectedControl["name"]?.InnerText; if (!string.IsNullOrEmpty(strStringToCheck)) { using (XmlNodeList xmlControlNodeList = xmlRequiredNode.SelectNodes("control")) if (xmlControlNodeList?.Count > 0) { foreach (XmlNode xmlLoopNode in xmlControlNodeList) { blnRequirementsMet = false; if (xmlLoopNode.InnerText == strStringToCheck) { blnRequirementsMet = true; break; } } } } if (!blnRequirementsMet) { return; } strStringToCheck = xmlSelectedFlexibility["name"]?.InnerText; if (!string.IsNullOrEmpty(strStringToCheck)) { using (XmlNodeList xmlFlexibilityNodeList = xmlRequiredNode.SelectNodes("flexibility")) if (xmlFlexibilityNodeList?.Count > 0) { foreach (XmlNode xmlLoopNode in xmlFlexibilityNodeList) { blnRequirementsMet = false; if (xmlLoopNode.InnerText == strStringToCheck) { blnRequirementsMet = true; break; } } } } if (!blnRequirementsMet) { return; } strStringToCheck = xmlSelectedVisibility["name"]?.InnerText; if (!string.IsNullOrEmpty(strStringToCheck)) { using (XmlNodeList xmlVisibilityNodeList = xmlRequiredNode.SelectNodes("visibility")) if (xmlVisibilityNodeList?.Count > 0) { foreach (XmlNode xmlLoopNode in xmlVisibilityNodeList) { blnRequirementsMet = false; if (xmlLoopNode.InnerText == strStringToCheck) { blnRequirementsMet = true; break; } } } } if (!blnRequirementsMet) { return; } } if (_objMount == null) { _objMount = new WeaponMount(_objCharacter, _objVehicle); _objMount.Create(xmlSelectedMount); } else if (_objMount.SourceId != strSelectedMount) { _objMount.Create(xmlSelectedMount); } WeaponMountOption objControlOption = new WeaponMountOption(_objCharacter); WeaponMountOption objFlexibilityOption = new WeaponMountOption(_objCharacter); WeaponMountOption objVisibilityOption = new WeaponMountOption(_objCharacter); if (objControlOption.Create(xmlSelectedControl) && objFlexibilityOption.Create(xmlSelectedFlexibility) && objVisibilityOption.Create(xmlSelectedVisibility)) { _objMount.WeaponMountOptions.Clear(); _objMount.WeaponMountOptions.Add(objControlOption); _objMount.WeaponMountOptions.Add(objFlexibilityOption); _objMount.WeaponMountOptions.Add(objVisibilityOption); } _objMount.Mods.Clear(); foreach (VehicleMod objMod in _lstMods) { objMod.WeaponMountParent = _objMount; _objMount.Mods.Add(objMod); } DialogResult = DialogResult.OK; }
private void cmdOK_Click(object sender, EventArgs e) { TreeNode tree = new TreeNode(); //TODO: THIS IS UGLY AS SHIT, FIX BETTER XmlNode node = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + cboSize.SelectedValue + "\"]"); if (node["forbidden"] != null) { XmlNodeList list = node.SelectNodes("/forbidden/control"); XmlNode check = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + cboControl.SelectedValue + "\"]"); if (list.Cast <XmlNode>().Any(n => n.InnerText == check["name"].InnerText)) { return; } list = node.SelectNodes("/forbidden/flexibility"); check = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + cboFlexibility.SelectedValue + "\"]"); if (list.Cast <XmlNode>().Any(n => n.InnerText == check["name"].InnerText)) { return; } list = node.SelectNodes("/forbidden/visibility"); check = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + cboVisibility.SelectedValue + "\"]"); if (list.Cast <XmlNode>().Any(n => n.InnerText == check["name"].InnerText)) { return; } } if (node["required"] != null) { bool requirementsMet = true; XmlNodeList list = node.SelectNodes("/required/control"); XmlNode check = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + cboControl.SelectedValue + "\"]"); if (list.Count > 0) { requirementsMet = requirementsMet && list.Cast <XmlNode>().Any(n => n.InnerText == check["name"].InnerText); if (!requirementsMet) { return; } } list = node.SelectNodes("/required/flexibility"); if (list.Count > 0) { check = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + cboFlexibility.SelectedValue + "\"]"); requirementsMet = requirementsMet && list.Cast <XmlNode>().Any(n => n.InnerText == check["name"].InnerText); if (!requirementsMet) { return; } } list = node.SelectNodes("/required/visibility"); if (list.Count > 0) { check = _xmlDoc.SelectSingleNode("/chummer/weaponmounts/weaponmount[id = \"" + cboVisibility.SelectedValue + "\"]"); requirementsMet = requirementsMet && list.Cast <XmlNode>().Any(n => n.InnerText == check["name"].InnerText); if (!requirementsMet) { return; } } } WeaponMount mount = new WeaponMount(_objCharacter, _vehicle); mount.Create(node, tree, _vehicle); WeaponMountOption option = new WeaponMountOption(_objCharacter); option.Create(cboControl.SelectedValue.ToString(), mount.WeaponMountOptions); option = new WeaponMountOption(_objCharacter); option.Create(cboFlexibility.SelectedValue.ToString(), mount.WeaponMountOptions); option = new WeaponMountOption(_objCharacter); option.Create(cboVisibility.SelectedValue.ToString(), mount.WeaponMountOptions); WeaponMount = mount; tree.Text = mount.DisplayName(GlobalOptions.Language); DialogResult = DialogResult.OK; }