/// <summary> /// Saves the medal data to a file /// </summary> private void SaveButton_Click(object sender, EventArgs e) { // ============ Check For Condition Errors and Alert User of Any string Profile = ProfileSelector.SelectedItem.ToString(); int CondErrors = 0; // Check for condition errors on badges TreeNode BadgeNode = AwardTree.Nodes[0]; for (int i = 0; i < BadgeNode.Nodes.Count; i++) { foreach (TreeNode N in BadgeNode.Nodes[i].Nodes) { IAward t = AwardCache.GetAward(N.Name); Condition Cond = t.GetCondition(); if (Cond is ConditionList) { ConditionList Clist = Cond as ConditionList; if (Clist.HasConditionErrors) { CondErrors++; } } else if (Cond.Returns() != ReturnType.Bool) { CondErrors++; } } } // Check for condition errors on the rest of the awards for (int i = 1; i < 4; i++) { foreach (TreeNode N in AwardTree.Nodes[i].Nodes) { IAward t = AwardCache.GetAward(N.Name); Condition Cond = t.GetCondition(); if (Cond is ConditionList) { ConditionList Clist = Cond as ConditionList; if (Clist.HasConditionErrors) { CondErrors++; } } else if (Cond.Returns() != ReturnType.Bool) { CondErrors++; } } } // Warn the user of any condition errors, and verify if we wanna save anyways if (CondErrors > 0) { DialogResult Res = MessageBox.Show( "A total of " + CondErrors + " award condition errors were found." + Environment.NewLine + Environment.NewLine + "Are you sure you want to save these changes without fixing these issues?", "Condition Errors Found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning ); if (Res != DialogResult.Yes) { return; } } // ============ Begin applying Medal Data Update // Add base medal data functions StringBuilder MedalData = new StringBuilder(); MedalData.AppendLine(Program.GetResourceAsString("BF2Statistics.MedalData.PyFiles.functions.py")); MedalData.AppendLine("medal_data = ("); // Add Each Award (except ranks) to the MedalData Array foreach (Award A in AwardCache.GetBadges()) { MedalData.AppendLine("\t" + A.ToPython()); } foreach (Award A in AwardCache.GetMedals()) { MedalData.AppendLine("\t" + A.ToPython()); } foreach (Award A in AwardCache.GetRibbons()) { MedalData.AppendLine("\t" + A.ToPython()); } // Append Rank Data MedalData.AppendLine(")"); MedalData.AppendLine("rank_data = ("); foreach (Rank R in AwardCache.GetRanks()) { MedalData.AppendLine("\t" + R.ToPython()); } // Close off the Rank Data Array MedalData.AppendLine(")#end"); // ============ Save Medal Data try { // Write to file File.WriteAllText( Path.Combine(PythonPath, "medal_data_" + Profile + ".py"), MedalData.ToString().TrimEnd() ); // Update variables, and display success ChangesMade = false; Notify.Show("Medal Data Saved Successfully!", "Operation Successful", AlertType.Success); } catch (Exception ex) { MessageBox.Show( "An exception was thrown while trying to save medal data. Medal data has NOT saved." + Environment.NewLine + Environment.NewLine + "Message: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); } }
/// <summary> /// This method is used to highlight the invalid condition nodes /// of the current selected AwardNode, to let the user know that the /// conditions selected wont work properly when loaded by the server /// </summary> /// <remarks>Applies highlighting from the Award Node => to => The Root Node</remarks> protected void ValidateConditions(TreeNode AwardNode, Condition Con) { // Color the Conditions texts to show invalid condition returns if (Con != null) { // Condition lists if (Con is ConditionList) { if ((Con as ConditionList).HasConditionErrors) { AwardNode.ForeColor = Color.Red; } else { AwardNode.ForeColor = Color.Black; } // Double check that our condition list returns a bool if (Con.Returns() != ReturnType.Bool) { // The root must always return a bool AwardNode.ForeColor = Color.Red; if (AwardConditionsTree.Nodes.Count > 0) { AwardConditionsTree.Nodes[0].ForeColor = Color.Red; } } } // Any kind of condition, Root must always else if (Con.Returns() != ReturnType.Bool) { // The root must always return a bool AwardNode.ForeColor = Color.Red; if (AwardConditionsTree.Nodes.Count > 0) { AwardConditionsTree.Nodes[0].ForeColor = Color.Red; } } else { // All is well AwardNode.ForeColor = Color.Black; if (AwardConditionsTree.Nodes.Count > 0) { AwardConditionsTree.Nodes[0].ForeColor = Color.Black; } } } else { // A null award is bad AwardNode.ForeColor = Color.Red; } // Now we also highlight all the parent nodes highlight as well TreeNode qq = AwardNode; while (qq.Parent != null) { qq = qq.Parent; qq.ForeColor = AwardNode.ForeColor; } }
/// <summary> /// This method is used to highlight the invalid condition nodes /// in the conditions treeview, as to let the user know that the /// conditions selected wont work properly when loaded by the server /// </summary> /// <remarks>Applies highlighting from the Root Nodes => to => The Award Nodes</remarks> private void ValidateConditions() { // Apply highlighting of badges TreeNode BadgeNode = AwardTree.Nodes[0]; for (int i = 0; i < BadgeNode.Nodes.Count; i++) { int j = 0; foreach (TreeNode N in BadgeNode.Nodes[i].Nodes) { // Fetch the award and its condition Condition Cond = AwardCache.GetAward(N.Name).GetCondition(); if (Cond is ConditionList) { ConditionList Clist = Cond as ConditionList; if (Clist.HasConditionErrors) { // Top level node BadgeNode.ForeColor = Color.Red; // Badge Node BadgeNode.Nodes[i].ForeColor = Color.Red; // Badege Level Node BadgeNode.Nodes[i].Nodes[j].ForeColor = Color.Red; } } // Make sure that this condition returns a bool else if (Cond.Returns() != ReturnType.Bool) { // Top level node BadgeNode.ForeColor = Color.Red; // Badge Node BadgeNode.Nodes[i].ForeColor = Color.Red; // Badege Level Node BadgeNode.Nodes[i].Nodes[j].ForeColor = Color.Red; } j++; } } // Apply highlighting for the rest of the awards for (int i = 1; i < 4; i++) { int j = 0; foreach (TreeNode N in AwardTree.Nodes[i].Nodes) { // Fetch the award and its condition Condition Cond = AwardCache.GetAward(N.Name).GetCondition(); if (Cond is ConditionList) { ConditionList Clist = Cond as ConditionList; if (Clist.HasConditionErrors) { // Top level Node AwardTree.Nodes[i].ForeColor = Color.Red; // Award Node AwardTree.Nodes[i].Nodes[j].ForeColor = Color.Red; } } // Make sure that this condition returns a bool else if (Cond.Returns() != ReturnType.Bool) { // Top level Node AwardTree.Nodes[i].ForeColor = Color.Red; // Award Node AwardTree.Nodes[i].Nodes[j].ForeColor = Color.Red; } j++; } } }
/// <summary> /// This method is used to highlight the invalid condition nodes /// of the current selected AwardNode, to let the user know that the /// conditions selected wont work properly when loaded by the server /// </summary> /// <remarks>Applies highlighting from the Award Node => to => The Root Node</remarks> protected void ValidateConditions(TreeNode AwardNode, Condition Con) { // Color the Conditions texts to show invalid condition returns if (Con != null) { // Condition lists if (Con is ConditionList) { if ((Con as ConditionList).HasConditionErrors) AwardNode.ForeColor = Color.Red; else AwardNode.ForeColor = Color.Black; // Double check that our condition list returns a bool if (Con.Returns() != ReturnType.Bool) { // The root must always return a bool AwardNode.ForeColor = Color.Red; if (AwardConditionsTree.Nodes.Count > 0) AwardConditionsTree.Nodes[0].ForeColor = Color.Red; } } // Any kind of condition, Root must always else if (Con.Returns() != ReturnType.Bool) { // The root must always return a bool AwardNode.ForeColor = Color.Red; if (AwardConditionsTree.Nodes.Count > 0) AwardConditionsTree.Nodes[0].ForeColor = Color.Red; } else { // All is well AwardNode.ForeColor = Color.Black; if(AwardConditionsTree.Nodes.Count > 0) AwardConditionsTree.Nodes[0].ForeColor = Color.Black; } } else { // A null award is bad AwardNode.ForeColor = Color.Red; } // Now we also highlight all the parent nodes highlight as well TreeNode qq = AwardNode; while (qq.Parent != null) { qq = qq.Parent; qq.ForeColor = AwardNode.ForeColor; } }