/// <summary> /// Restores the condition / criteria back to default (vanilla) /// </summary> private void RestoreToDefaultMenuItem_Click(object sender, EventArgs e) { // Make sure we have an award selected if (SelectedAwardNode == null || SelectedAwardNode.Parent == null) { MessageBox.Show("Please select an award!"); return; } // Delay or tree redraw AwardConditionsTree.BeginUpdate(); // Clear all Nodes AwardConditionsTree.Nodes.Clear(); // Parse award conditions into tree view IAward SAward = AwardCache.GetAward(SelectedAwardNode.Name); SAward.RestoreDefaultConditions(); AwardConditionsTree.Nodes.Add(SAward.ToTree()); // Revalidate ValidateConditions(SelectedAwardNode, SAward.GetCondition()); // Conditions tree's are to be expanded at all times AwardConditionsTree.ExpandAll(); // Redraw the tree AwardConditionsTree.EndUpdate(); }
/// <summary> /// Loads the default medal data into the Award Cache /// </summary> static MedalDataParser() { // Fill the award cache with the original award conditions MatchCollection MedalsMatches, RankMatches; ParseMedalData(Program.GetResourceAsString("BF2Statistics.MedalData.PyFiles.medal_data_xpack.py"), out MedalsMatches, out RankMatches); // Convert each medal match into an object, and add it to the award cache foreach (Match ArrayMatch in MedalsMatches) { AwardCache.AddDefaultAwardCondition( ArrayMatch.Groups["MedalIntId"].Value, ParseCondition(ArrayMatch.Groups["Conditions"].Value) ); } // Convert ranks into objects, and also add them to the award cache foreach (Match ArrayMatch in RankMatches) { AwardCache.AddDefaultAwardCondition( ArrayMatch.Groups["RankId"].Value, ParseCondition(ArrayMatch.Groups["Conditions"].Value) ); } }
/// <summary> /// This method builds the award cache with the given data from the medal data file. /// This method WILL CLEAR the award cache from any existing medals /// </summary> /// <param name="MedalsMatches"></param> /// <param name="RanksMatches"></param> public static void BuildAwardCache(MatchCollection MedalsMatches, MatchCollection RanksMatches) { // Clear out the award cache! AwardCache.Clear(); // Convert each medal match into an object, and add it to the award cache foreach (Match ArrayMatch in MedalsMatches) { AwardCache.AddAward( new Award( ArrayMatch.Groups["MedalIntId"].Value, ArrayMatch.Groups["MedalStrId"].Value, ArrayMatch.Groups["RewardType"].Value, ParseCondition(ArrayMatch.Groups["Conditions"].Value) ) ); } // Convert ranks into objects, and also add them to the award cache foreach (Match ArrayMatch in RanksMatches) { AwardCache.AddRank( new Rank( Int32.Parse(ArrayMatch.Groups["RankId"].Value), ParseCondition(ArrayMatch.Groups["Conditions"].Value) ) ); } }
/// <summary> /// An event called everytime a new award is selected... /// It repaints the current award info /// </summary> private void AwardTree_AfterSelect(object sender, TreeViewEventArgs e) { // Set our award globally SelectedAwardNode = e.Node; // Only proccess child Nodes if (SelectedAwardNode.Nodes.Count == 0) { // Set Award Image SetAwardImage(SelectedAwardNode.Name); // Set award name and type switch (Award.GetType(SelectedAwardNode.Name)) { case AwardType.Badge: AwardTypeBox.Text = "Badge"; AwardNameBox.Text = Award.GetName(SelectedAwardNode.Name); break; case AwardType.Medal: AwardTypeBox.Text = "Medal"; AwardNameBox.Text = Award.GetName(SelectedAwardNode.Name); break; case AwardType.Ribbon: AwardTypeBox.Text = "Ribbon"; AwardNameBox.Text = Award.GetName(SelectedAwardNode.Name); break; case AwardType.Rank: AwardTypeBox.Text = "Rank"; AwardNameBox.Text = Rank.GetName(Int32.Parse(SelectedAwardNode.Name)); break; } // Delay or tree redraw AwardConditionsTree.BeginUpdate(); // Clear all Nodes AwardConditionsTree.Nodes.Clear(); // Parse award conditions into tree view SelectedAward = AwardCache.GetAward(SelectedAwardNode.Name); TreeNode Conds = SelectedAward.ToTree(); if (Conds != null) { AwardConditionsTree.Nodes.Add(Conds); } // Conditions tree's are to be expanded at all times AwardConditionsTree.ExpandAll(); // Redraw the tree AwardConditionsTree.EndUpdate(); } }
void TypeSelect_SelectedIndexChanged(object sender, EventArgs e) { AwardSelect.Items.Clear(); switch (TypeSelect.SelectedIndex) { case 0: foreach (Award A in AwardCache.GetBadges()) { AwardSelect.Items.Add(new KeyValuePair(A.Id, A.Name)); } break; case 1: foreach (Award A in AwardCache.GetMedals()) { AwardSelect.Items.Add(new KeyValuePair(A.Id, A.Name)); } break; case 2: foreach (Award A in AwardCache.GetRibbons()) { AwardSelect.Items.Add(new KeyValuePair(A.Id, A.Name)); } break; case 3: foreach (Rank A in AwardCache.GetRanks()) { AwardSelect.Items.Add(new KeyValuePair(A.Id.ToString(), A.Name)); } break; } AwardSelect.SelectedIndex = 0; }
/// <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 called upon selecting a new Medal Data Profile. /// It loads the new medal data, and calls the parser to parse it. /// </summary> private void ProfileSelector_SelectedIndexChanged(object sender, EventArgs e) { // Make sure we have an index! Also make sure we didnt select the same profile again if (ProfileSelector.SelectedIndex == -1 || ProfileSelector.SelectedItem.ToString() == LastSelectedProfile) { return; } // Get current profile string Profile = ProfileSelector.SelectedItem.ToString(); // Make sure the user wants to commit without saving changes if (ChangesMade && MessageBox.Show("Some changes have not been saved. Are you sure you want to continue?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes) { ProfileSelector.SelectedIndex = Profiles.IndexOf(LastSelectedProfile.ToLower()); return; } // Disable the form to prevent errors. Show loading screen this.Enabled = false; LoadingForm.ShowScreen(this); // Suppress repainting the TreeView until all the objects have been created. AwardConditionsTree.Nodes.Clear(); AwardTree.BeginUpdate(); // Remove old medal data if applicable for (int i = 0; i < 4; i++) { AwardTree.Nodes[i].Nodes.Clear(); AwardTree.Nodes[i].ForeColor = Color.Black; } // Get Medal Data try { MedalDataParser.LoadMedalDataFile(Path.Combine(PythonPath, "medal_data_" + Profile + ".py")); } catch (Exception ex) { AwardTree.EndUpdate(); MessageBox.Show(ex.Message, "Medal Data Parse Error"); ProfileSelector.SelectedIndex = -1; this.Enabled = true; LoadingForm.CloseForm(); return; } // Iterator for badges int itr = -1; // Add all awards to the corresponding Node foreach (Award A in AwardCache.GetBadges()) { if (Award.GetBadgeLevel(A.Id) == BadgeLevel.Bronze) { AwardTree.Nodes[0].Nodes.Add(A.Id, A.Name.Replace("Basic ", "")); ++itr; } AwardTree.Nodes[0].Nodes[itr].Nodes.Add(A.Id, A.Name.Split(' ')[0]); } foreach (Award A in AwardCache.GetMedals()) { AwardTree.Nodes[1].Nodes.Add(A.Id, A.Name); } foreach (Award A in AwardCache.GetRibbons()) { AwardTree.Nodes[2].Nodes.Add(A.Id, A.Name); } foreach (Rank R in AwardCache.GetRanks()) { AwardTree.Nodes[3].Nodes.Add(R.Id.ToString(), R.Name); } // Begin repainting the TreeView. AwardTree.CollapseAll(); AwardTree.EndUpdate(); // Reset current award data AwardNameBox.Text = null; AwardTypeBox.Text = null; AwardPictureBox.Image = null; // Process Active profile button if (Profile == ActiveProfile) { ActivateProfileBtn.Text = "Current Server Profile"; ActivateProfileBtn.BackgroundImage = Resources.check; } else { ActivateProfileBtn.Text = "Set as Server Profile"; ActivateProfileBtn.BackgroundImage = Resources.power; } // Apply inital highlighting of condition nodes ValidateConditions(); // Enable form controls AwardTree.Enabled = true; AwardConditionsTree.Enabled = true; DelProfileBtn.Enabled = true; ActivateProfileBtn.Enabled = true; SaveBtn.Enabled = true; this.Enabled = true; LoadingForm.CloseForm(); // Set this profile as the last selected profile LastSelectedProfile = Profile; ChangesMade = false; }
/// <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> /// Restores the condition of this award to the default (vanilla) state /// </summary> public void RestoreDefaultConditions() { Conditions = AwardCache.GetDefaultAwardCondition(this.Id.ToString()); }
public MedalConditionForm(TreeNode Node) { InitializeComponent(); this.Node = Node; this.Obj = (MedalOrRankCondition)Node.Tag; List <string> Params = Obj.GetParams(); int I = 0; int Index = 0; // Set default award requirement type if (Params[0] == "has_medal") { AwardType Type = Award.GetType(Params[1]); switch (Type) { case AwardType.Badge: TypeSelect.SelectedIndex = 0; foreach (Award A in AwardCache.GetBadges()) { AwardSelect.Items.Add(new KeyValuePair(A.Id, A.Name)); if (A.Id == Params[1]) { Index = I; } I++; } break; case AwardType.Medal: TypeSelect.SelectedIndex = 1; foreach (Award A in AwardCache.GetMedals()) { AwardSelect.Items.Add(new KeyValuePair(A.Id, A.Name)); if (A.Id == Params[1]) { Index = I; } I++; } break; case AwardType.Ribbon: TypeSelect.SelectedIndex = 2; foreach (Award A in AwardCache.GetRibbons()) { AwardSelect.Items.Add(new KeyValuePair(A.Id, A.Name)); if (A.Id == Params[1]) { Index = I; } I++; } break; } } else { TypeSelect.SelectedIndex = 3; foreach (Rank R in AwardCache.GetRanks()) { AwardSelect.Items.Add(new KeyValuePair(R.Id.ToString(), R.Name)); if (R.Id.ToString() == Params[1]) { Index = I; } I++; } } // Add index change event AwardSelect.SelectedIndex = Index; TypeSelect.SelectedIndexChanged += new EventHandler(TypeSelect_SelectedIndexChanged); }