/// <summary> /// Constructor /// </summary> /// <param name="Node"></param> public ConditionListForm(TreeNode Node) { InitializeComponent(); // Set internal vars this.Node = Node; this.List = (ConditionList) Node.Tag; this.OrigList = (ConditionList)this.List.Clone(); Initialize(); }
/// <summary> /// Constructor /// </summary> /// <param name="Type"></param> public ConditionListForm(ConditionType Type) { InitializeComponent(); // Set internal vars this.List = new ConditionList(Type); this.OrigList = new ConditionList(Type); this.Node = new TreeNode(); Initialize(); }
/// <summary> /// Adds a new criteria to an award from the Add Critera Dialog /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddNewCriteria(object sender, FormClosingEventArgs e) { TreeNode Node = AwardConditionsTree.SelectedNode; TreeNode AwardNode = AwardTree.SelectedNode; IAward Award = AwardCache.GetAward(AwardNode.Name); // If there is a node referenced. if (Node != null && Node.Tag is ConditionList) { //Condition C = (Condition)Node.Tag; Condition Add = Child.GetCondition(); ConditionList List = (ConditionList)Node.Tag; List.Add(Add); } else { // No Node referenced... Use top most ConditionList A = new ConditionList(ConditionType.And); Condition B = Award.GetCondition(); if (B is ConditionList) { ConditionList C = (ConditionList)B; if (C.Type == ConditionType.And) A = C; else A.Add(B); } else { // Add existing conditions into the condition list A.Add(B); } // Add the new condition A.Add(Child.GetCondition()); // Parse award conditions into tree view Award.SetCondition(A); } // Update the tree view AwardConditionsTree.BeginUpdate(); AwardConditionsTree.Nodes.Clear(); AwardConditionsTree.Nodes.Add(Award.ToTree()); AwardConditionsTree.ExpandAll(); AwardConditionsTree.EndUpdate(); }
/// <summary> /// Returns a copy (clone) of this object /// </summary> public override object Clone() { ConditionList Clone = new ConditionList(this.Type); foreach (Condition Cond in SubConditions) Clone.Add(Cond.Clone() as Condition); return Clone as object; }
private void UpdateRoot() { ConditionList NList = new ConditionList(List.Type); // Add existing nodes to the new list foreach (TreeNode E in ConditionTree.Nodes[0].Nodes) NList.Add((Condition)E.Tag); // Add condition value if enabled if (ValueBox.Enabled) NList.Add(new ConditionValue(ValueBox.Value.ToString())); // update tree ConditionTree.BeginUpdate(); ConditionTree.Nodes.Clear(); ConditionTree.Nodes.Add(NList.ToTreeNoCollapse()); ConditionTree.ExpandAll(); ConditionTree.EndUpdate(); }
/// <summary> /// Undo Changes menu item click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UndoChanges_Click(object sender, EventArgs e) { List = (ConditionList)OrigList.Clone(); Initialize(); }
private void SaveBtn_Click(object sender, EventArgs e) { if (List.Type == ConditionType.Not) { if (ConditionTree.Nodes[0].Nodes.Count == 0) { MessageBox.Show("You must define a criteria."); return; } } else { if (ConditionTree.Nodes[0].Nodes.Count < 2) { MessageBox.Show("You must define 2 criteria's."); return; } } List = (ConditionList)MedalDataParser.ParseNodeConditions(ConditionTree.Nodes[0]); Node.Tag = List; MedalDataEditor.ChangesMade = true; this.DialogResult = DialogResult.OK; }
/// <summary> /// Brings up the Criteria Editor for an Award /// </summary> public void EditCriteria() { TreeNode SelectedNode = ConditionTree.SelectedNode; // Make sure we have a node selected if (Node == null) { MessageBox.Show("Please select a criteria to edit."); return; } // Make sure its a child node if (SelectedNode.Parent == null && SelectedNode.Nodes.Count != 0) return; this.Node = SelectedNode; // Open correct condition editor form if (Node.Tag is ObjectStat) Child = new ObjectStatForm(Node); else if (Node.Tag is PlayerStat) Child = new ScoreStatForm(Node); else if (Node.Tag is MedalOrRankCondition) Child = new MedalConditionForm(Node); else if (Node.Tag is GlobalStatMultTimes) Child = new GlobalStatMultTimesForm(Node); else if (Node.Tag is ConditionList) Child = new ConditionListForm(Node); else return; if (Child.ShowDialog() == DialogResult.OK) { ConditionList NN = new ConditionList(List.Type); NN = (ConditionList) MedalDataParser.ParseNodeConditions(ConditionTree.Nodes[0]); ConditionTree.Nodes.Clear(); ConditionTree.Nodes.Add(NN.ToTreeNoCollapse()); ConditionTree.Refresh(); ConditionTree.ExpandAll(); } }
/// <summary> /// Parses a string condition into condition objects /// </summary> /// <param name="parts"></param> /// <param name="i"></param> /// <returns></returns> private static Condition ParseCondition(List<Token> parts, ref int i) { ParseFunctions(ref parts); ConditionList List; for(; i < parts.Count; i++) { if (parts[i].Kind == TokenType.ConditionFunction) { // Default ConditionType Type = ConditionType.And; switch (parts[i].Value) { case "f_and": Type = ConditionType.And; break; case "f_or": Type = ConditionType.Or; break; case "f_not": Type = ConditionType.Not; break; case "f_plus": Type = ConditionType.Plus; break; case "f_div": Type = ConditionType.Div; break; } // Create the new condition list List = new ConditionList(Type); // Parse sub conditions i++; while(i < parts.Count && parts[i].Kind != TokenType.CloseParen) List.Add(ParseCondition(parts, ref i)); i++; // Return condition list return List; } else if (parts[i].Kind == TokenType.StatFunction) { List<string> Params = new List<string>(); string Name = parts[i].Value; for (; i < parts.Count; i++) { if (parts[i].Kind == TokenType.CloseParen) break; if (parts[i].Kind == TokenType.OpenParen) continue; Params.Add(parts[i].Value); } i++; // Create the condition switch (Name) { case "object_stat": return new ObjectStat(Params); case "global_stat": case "player_stat": return new PlayerStat(Params); case "has_medal": case "has_rank": return new MedalOrRankCondition(Params); case "global_stat_multiple_times": return new GlobalStatMultTimes(Params); } } else if (parts[i].Kind == TokenType.Literal) { ConditionValue V = new ConditionValue(parts[i].Value); i++; return V; } } return new ConditionList( ConditionType.And ); }
/// <summary> /// Deletes the selected criteria node /// </summary> public void DeleteCriteria() { TreeNode SelectedNode = ConditionTree.SelectedNode; // Make sure we have a node selected if (SelectedNode == null) { MessageBox.Show("Please select a criteria to edit."); return; } // Make sure we can't delete the parent node // Mostly because we need to keep references intact if (SelectedNode.Parent == null) { return; } // Dont delete on Plus / Div Trees if (!(SelectedNode.Tag is ConditionList)) { TreeNode Parent = SelectedNode.Parent; if (Parent == null) { return; } // If we are in the root condition list if (Parent.Parent == null || Parent.Parent.Tag == null) { ConditionTree.Nodes.Remove(SelectedNode); return; } // Get the parents condition list ConditionList C = (ConditionList)Parent.Tag; // Remove the whole tree if its a not statement if (C.Type == ConditionType.Not) { ConditionTree.Nodes.Remove(Parent); } // We donot handle nested condition lists in this form else if (C.Type == ConditionType.Plus || C.Type == ConditionType.Div) { ConditionTree.SelectedNode = Parent; EditCriteria(); } else { ConditionTree.Nodes.Remove(SelectedNode); } } else { ConditionTree.Nodes.Remove(SelectedNode); } ConditionTree.Refresh(); }
private void SaveBtn_Click(object sender, EventArgs e) { if (List.Type == ConditionType.Not) { if (ConditionTree.Nodes[0].Nodes.Count == 0) { MessageBox.Show("You must define a criteria."); return; } } else { if (ConditionTree.Nodes[0].Nodes.Count < 2) { MessageBox.Show("You must define 2 criteria's."); return; } } // Generate a new list, and store it in the Node.Tag List = (ConditionList)MedalDataParser.ParseNodeConditions(ConditionTree.Nodes[0]); Node.Tag = List; // For AND (and) OR lists, since we can add and remove elements (thus losing references), // we must clear the condition nodes, and rebuild them from scratch if (List.Type == ConditionType.And || List.Type == ConditionType.Or) { Node.Nodes.Clear(); foreach (var something in List.GetConditions()) Node.Nodes.Add(something.ToTree()); } // Signal to the DataEditor that we made changes MedalDataEditor.ChangesMade = true; this.DialogResult = DialogResult.OK; }