/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (ExpressionMemberValueDescriptions.PropertyF.Editor.XmlValueToDisplay.ContainsKey(container.GetAttribute("property", ExpressionMemberValueDescriptions.PropertyF.DefaultIfNull))) return Choices[0]; // ok else return Choices[1]; // not ok }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (container.GetAttribute("use_gm_position") == null) return Choices[0]; // point else return Choices[1]; // use_gm_pos }
/// <summary> /// Default context menu strip for checks /// </summary> internal static ContextMenuStrip PrepareContextMenuStrip_DefaultCheck(ExpressionMemberContainer container, ExpressionMemberValueEditor editor, ExpressionMemberValueEditorActivationMode mode) { string value = container.GetValue(); if (editor.ValueSelectorContextMenuStrip == null || editor.LastUser != container.Member.ValueDescription || editor.ForceRecreateMenu) { editor.ValueSelectorContextMenuStrip = new ContextMenuStrip(); editor.InitContextMenuStrip(); editor.LastUser = container.Member.ValueDescription; editor.ValueSelectorContextMenuStrip.Items.Clear(); editor.ValueSelectorContextMenuStrip.Tag = false; for (int i = 0; i < ((ExpressionMemberCheck)container.Member).Choices.Count(); i++) { string item = ((ExpressionMemberCheck)container.Member).Choices[i]; if (container.Member.ValueToDisplay(item) == null) continue; ToolStripItem tsi = editor.ValueSelectorContextMenuStrip.Items.Add((editor.XmlValueToMenu.ContainsKey(item)) ? editor.XmlValueToMenu[item] : container.Member.ValueToDisplay(item)); tsi.Tag = container; tsi.Click += ContextMenuClickChoose; if (container.Member.ValueDescription.AreEqual(container.Member.ValueToXml(item), value)) tsi.Select(); if (((ExpressionMemberCheck)container.Member).SeparatorAt(i)) editor.ValueSelectorContextMenuStrip.Items.Add(new ToolStripSeparator()); } editor.ShowHideContextMenuStrip(); } AssignContainerToContextMenuStrip(editor.ValueSelectorContextMenuStrip, container, value); return editor.ValueSelectorContextMenuStrip; }
/// <summary> /// Called after Decide has made its choice, or, as usual for ExpressionMembers, after user edited the value through a Dialog. /// For checks, SetValue must change the attributes/etc of the statement according to the newly chosen value /// <example>If you chose "Use GM ...", SetValue will set "use_gm_..." attribute to ""</example> /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { if (Mission.Current.Loading && value == "!ok") Log.Add("Warning! Unknown fleet property " + container.GetAttribute("property_f") + " detected in event: " + container.Statement.Parent.Name + "!"); base.SetValueInternal(container, value); }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (container.Statement.Name == "if_exists") return Choices[0]; // if object exists else return Choices[1]; // if object doesnt exist }
/// <summary> /// Default context menu strip for booleans (yes/no) /// </summary> internal static ContextMenuStrip PrepareContextMenuStrip_DefaultBool(ExpressionMemberContainer container, ExpressionMemberValueEditor editor, ExpressionMemberValueEditorActivationMode mode) { string value = container.GetValue(); if (editor.ValueSelectorContextMenuStrip == null || editor.LastUser != container.Member.ValueDescription || editor.ForceRecreateMenu) { editor.ValueSelectorContextMenuStrip = new ContextMenuStrip(); editor.InitContextMenuStrip(); editor.LastUser = container.Member.ValueDescription; editor.ValueSelectorContextMenuStrip.Items.Clear(); editor.ValueSelectorContextMenuStrip.Tag = false; foreach (string item in new string[2] { container.Member.ValueToDisplay("1"), container.Member.ValueToDisplay("0") }) { ToolStripItem tsi = editor.ValueSelectorContextMenuStrip.Items.Add(item); tsi.Tag = container; tsi.Click += ContextMenuClickChoose; } editor.ShowHideContextMenuStrip(); } AssignContainerToContextMenuStrip(editor.ValueSelectorContextMenuStrip, container, value); return editor.ValueSelectorContextMenuStrip; }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (container.Statement.Name == "if_outside_box" || container.Statement.Name == "if_inside_box") return Choices[0]; // box else return Choices[1]; // sphere }
/// <summary> /// Called after Decide has made its choice, or, as usual for ExpressionMembers, after user edited the value through a Dialog. /// For checks, SetValue must change the attributes/etc of the statement according to the newly chosen value /// <example>If you chose "Use GM ...", SetValue will set "use_gm_..." attribute to ""</example> /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { if (value == Choices[1]) //convert { string msg = "Direct statement (name: \"" + (container.GetAttribute("name") ?? "<null>") + "\" "; value = "add_ai"; container.Statement.Name = value; if (!String.IsNullOrEmpty(container.GetAttribute("targetName"))) { //ATTACK container.SetAttribute("type", "TARGET_THROTTLE"); container.SetAttribute("value1", container.GetAttribute("scriptThrottle")); msg += "targetName: \"" + container.GetAttribute("targetName") + "\" scriptThrottle \"" + container.GetAttribute("scriptThrottle") + ") was converted to add_ai \"TARGET_THROTTLE\" statement"; } else { //POINT_THROTTLE container.SetAttribute("type", "POINT_THROTTLE"); container.SetAttribute("value1", container.GetAttribute("pointX")); container.SetAttribute("value2", container.GetAttribute("pointY")); container.SetAttribute("value3", container.GetAttribute("pointZ")); container.SetAttribute("value4", container.GetAttribute("scriptThrottle")); msg += "target point: \"" + container.GetAttribute("pointX") + ", " + container.GetAttribute("pointY") + ", " + container.GetAttribute("pointZ") + "\" scriptThrottle: \"" + container.GetAttribute("scriptThrottle") + ") was converted to add_ai \"POINT_THROTTLE\" statement"; } Log.Add(msg); } base.SetValueInternal(container, value); }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (container.GetAttribute("fleetnumber") == null) return Choices[0]; // all ships else return Choices[1]; // fleetnumber }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (container.GetAttribute("sideValue") == null) return Choices[0]; // "... on default side" else return Choices[1]; // "... on side #" }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (!String.IsNullOrEmpty(container.GetAttribute("targetName"))) return Choices[1]; // name else return Choices[0]; // point }
/// <summary> /// Called after Decide has made its choice, or, as usual for ExpressionMembers, after user edited the value through a Dialog. /// For checks, SetValue must change the attributes/etc of the statement according to the newly chosen value /// <example>If you chose "Use GM ...", SetValue will set "use_gm_..." attribute to ""</example> /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { if (value == Choices[1]) //random int { container.SetAttributeIfNull("randomIntLow", "0"); container.SetAttributeIfNull("randomIntHigh", "0"); container.SetAttribute("randomFloatLow", null); container.SetAttribute("randomFloatHigh", null); container.SetAttribute("value", null); } if (value == Choices[2]) //random float { container.SetAttribute("randomIntLow", null); container.SetAttribute("randomIntHigh", null); container.SetAttributeIfNull("randomFloatLow", "0.0"); container.SetAttributeIfNull("randomFloatHigh", "0.0"); container.SetAttribute("value", null); } if (value == Choices[0]) // exact value { container.SetAttributeIfNull("value", "0.0"); } base.SetValueInternal(container, value); }
/// <summary> /// Called after Decide has made its choice, or, as usual for ExpressionMembers, after user edited the value through a Dialog. /// For checks, SetValue must change the attributes/etc of the statement according to the newly chosen value /// <example>If you chose "Use GM ...", SetValue will set "use_gm_..." attribute to ""</example> /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { if (value == Choices[0]) container.Statement.Name = container.Statement.Name.Replace("sphere","box"); else container.Statement.Name = container.Statement.Name.Replace("box", "sphere"); base.SetValueInternal(container, value); }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (!String.IsNullOrEmpty(container.GetAttribute("name"))) return Choices[2]; // name if (container.GetAttribute("use_gm_position") != null) return Choices[1]; // use_gm_pos else return Choices[0]; // point }
/// <summary> /// Called after Decide has made its choice, or, as usual for ExpressionMembers, after user edited the value through a Dialog. /// For checks, SetValue must change the attributes/etc of the statement according to the newly chosen value /// <example>If you chose "Use GM ...", SetValue will set "use_gm_..." attribute to ""</example> /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { if (value == Choices[0]) //point container.SetAttribute("fleetnumber", null); else container.SetAttributeIfNull("fleetnumber", "0.0"); base.SetValueInternal(container, value); }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (container.Statement.Kind == MissionStatementKind.Commentary) return "Commentary"; if (container.Statement.Kind == MissionStatementKind.Condition) return "Condition"; if (true) return "Action"; }
/// <summary> /// Called after Decide has made its choice, or, as usual for ExpressionMembers, after user edited the value through a Dialog. /// For checks, SetValue must change the attributes/etc of the statement according to the newly chosen value /// <example>If you chose "Use GM ...", SetValue will set "use_gm_..." attribute to ""</example> /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { if (value == Choices[0]) //point container.SetAttribute("use_gm_position", null); else container.SetAttribute("use_gm_position", ""); base.SetValueInternal(container, value); }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (container.GetAttribute("value") == null && (container.GetAttribute("randomIntLow") != null || container.GetAttribute("randomIntHigh") != null)) return Choices[1]; // random int if (container.GetAttribute("value") == null && (container.GetAttribute("randomFloatLow") != null || container.GetAttribute("randomFloatHigh") != null)) return Choices[2]; // random float else return Choices[0]; // exact value }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { //if ((container.GetAttribute("hullKeys") == null && container.GetAttribute("raceKeys") == null) || !string.IsNullOrEmpty(container.GetAttribute("hullID"))) //|| !string.IsNullOrEmpty(container.GetAttribute("hullID") if (container.GetAttribute("hullID") == null ) return Choices[HullRaceKey]; // hullKeys / raceKeys else return Choices[HullID]; // hullID }
/// <summary> /// Called after Decide has made its choice, or, as usual for ExpressionMembers, after user edited the value through a Dialog. /// For checks, SetValue must change the attributes/etc of the statement according to the newly chosen value /// <example>If you chose "Use GM ...", SetValue will set "use_gm_..." attribute to ""</example> /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { if (value == Choices[0]) container.Statement.Name = "if_exists"; else container.Statement.Name = "if_not_exists"; base.SetValueInternal(container, value); }
/// <summary> /// Assign ExpressionMemberContainer to each of Context Menu Strip's items. /// Item with value equal to current also gets selected. /// </summary> /// <param name="cms">Context Menu Strip to assign to.</param> /// <param name="container">Container to be assigned.</param> /// <param name="currentValue">Item with this value will be selected.</param> /// <param name="selectDialogItem">If true, "Edit in Dialog" option will be selected by default.</param> public static void AssignContainerToContextMenuStrip(ContextMenuStrip cms, ExpressionMemberContainer container, string currentValue, bool selectDialogItem = false) { bool itemSelected = false; foreach (ToolStripItem item in cms.Items) { AssignContainerToContextMenuStrip_RecursivelyAssign(item, container, currentValue); itemSelected = itemSelected || item.Selected; } if (selectDialogItem && !itemSelected) cms.Items[cms.Items.Count - 1].Select(); }
/// <summary> /// Called after Decide has made its choice, or, as usual for ExpressionMembers, after user edited the value through a Dialog. /// For checks, SetValue must change the attributes/etc of the statement according to the newly chosen value /// <example>If you chose "Use GM ...", SetValue will set "use_gm_..." attribute to ""</example> /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { if (value == Choices[0]) //point { container.SetAttribute("targetName", null); } if (value == Choices[1]) // name { container.SetAttributeIfNull("targetName", " "); } base.SetValueInternal(container, value); }
/// <summary> /// Appends expression members from the specified list of ExpressionMemebers to the specified list of ExpressionMemberContainers /// </summary> /// <param name="what"></param> /// <param name="where"></param> private static void Append(MissionStatement statement, List<ExpressionMember> what, List<ExpressionMemberContainer> where) { foreach (ExpressionMember item in what) { ExpressionMemberContainer nEMC = new ExpressionMemberContainer(item, statement); where.Add(nEMC); if (item as ExpressionMemberCheck == null) continue; Append(statement, ((ExpressionMemberCheck)item).PossibleExpressions[nEMC.Decide()], where); } }
/// <summary> /// Set value of the current member (whole Xml element is supplied) /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { XmlDocument xDoc = new XmlDocument(); try { xDoc.LoadXml(value); container.Statement.FromXml(xDoc.ChildNodes[0]); } catch (Exception ex) { MessageBox.Show(ex.Message + " " +ex.StackTrace); } }
/// <summary> /// Gets the Xml representing this unknown member (returns whole Xml element). /// </summary> public override string GetValue(ExpressionMemberContainer container) { XmlDocument xDoc = new XmlDocument(); XmlElement eResult = xDoc.CreateElement(container.Statement.Name); foreach (KeyValuePair<string, string> kvp in container.Statement.GetAttributes()) { XmlAttribute cAtt = xDoc.CreateAttribute(kvp.Key); cAtt.Value = kvp.Value; eResult.Attributes.Append(cAtt); } if (!String.IsNullOrEmpty(container.Statement.Body)) eResult.InnerText = container.Statement.Body; return eResult.OuterXml; }
/// <summary> /// Called after Decide has made its choice, or, as usual for ExpressionMembers, after user edited the value through a Dialog. /// For checks, SetValue must change the attributes/etc of the statement according to the newly chosen value /// <example>If you chose "Use GM ...", SetValue will set "use_gm_..." attribute to ""</example> /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { if (value == Choices[HullID]) //hullID { container.SetAttributeIfNull("hullID", ""); container.SetAttribute("hullKeys", null); container.SetAttribute("raceKeys", null); } if (value == Choices[HullRaceKey]) //hullKeys / raceKeys { container.SetAttribute("hullID", null); container.SetAttributeIfNull("hullKeys", ""); container.SetAttributeIfNull("raceKeys", ""); } base.SetValueInternal(container, value); }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { if (container.Statement.Name == "destroy") return Choices[0]; // destroy (named object) if (container.GetAttribute("type") == "asteroids") return Choices[1]; // destroy_near asteroids if (container.GetAttribute("type") == "mines") return Choices[2]; // destroy_near mines if (container.GetAttribute("type") == "nebulas") return Choices[3]; // destroy_near nebulas if (container.GetAttribute("type") == "whales") return Choices[4]; // destroy_near whales if (container.GetAttribute("type") == "drones") return Choices[5]; // destroy_near drones if (true) return Choices[6]; // destroy_near all }
/// <summary> /// Set value of the current member, including all checks (like, sets to null if this is a "store only if filled" value etc...) /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { string old = container.Statement.Body; if (value != null) container.Statement.Body = value; else container.Statement.Body = ""; if (old != container.Statement.Body) { try { // Miscrosoft.Preformance is so helpful! Yeah sure, if I could just call OuterXml without assigning it, I'd never do this! string justSoThatOuterXmlGetLogicIsCalled = container.Statement.ToXml(new XmlDocument()).OuterXml; } catch { container.Statement.Body = old; } } }
/// <summary> /// This function is called when check needs to decide which list of ExpressionMembers to output. /// After it is called, SetValue will be called, to allow for error correction. /// </summary> /// <example>If input is wrong, decide will choose something, and then the input will be corrected in the SetValue function</example> public override string Decide(ExpressionMemberContainer container) { string f = container.GetAttribute("fakeShieldsFront"); string r = container.GetAttribute("fakeShieldsRear"); int fi, ri; Helper.IntTryParse(f, out fi); Helper.IntTryParse(r, out ri); if ((f == null || fi == -1) && (r == null || ri == -1)) return Choices[0]; // no fake shields if (r == null || ri == -1) return Choices[1]; // fake front shields if (f == null || fi == -1) return Choices[2]; // fake rear shields if (true) return Choices[3]; // fake front/rear shields }
/// <summary> /// Called after Decide has made its choice, or, as usual for ExpressionMembers, after user edited the value through a Dialog. /// For checks, SetValue must change the attributes/etc of the statement according to the newly chosen value /// <example>If you chose "Use GM ...", SetValue will set "use_gm_..." attribute to ""</example> /// </summary> protected override void SetValueInternal(ExpressionMemberContainer container, string value) { if (value == Choices[0]) //destroy named object container.Statement.Name = "destroy"; else // destroy_near container.Statement.Name = "destroy_near"; if (value == Choices[1]) // destroy asteroids container.SetAttribute("type", "asteroids"); if (value == Choices[2]) // destroy mines container.SetAttribute("type", "mines"); if (value == Choices[3]) // destroy nebulas container.SetAttribute("type", "nebulas"); if (value == Choices[4]) // destroy whales container.SetAttribute("type", "whales"); if (value == Choices[5]) // destroy drones container.SetAttribute("type", "drones"); if (value == Choices[6]) // destroy all container.SetAttribute("type", "all"); base.SetValueInternal(container, value); }