Beispiel #1
0
        /// <summary>
        /// Brings up the Criteria Editor for an Award
        /// </summary>
        public void EditCriteria()
        {
            // Grab the selected treenode
            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 its a child node, and not the topmost
            if (SelectedNode.Parent == null) // && SelectedNode.Nodes.Count != 0)
            {
                return;
            }

            // Open correct condition editor form
            if (SelectedNode.Tag is ObjectStat)
            {
                Child = new ObjectStatForm(SelectedNode);
            }
            else if (SelectedNode.Tag is PlayerStat)
            {
                Child = new ScoreStatForm(SelectedNode);
            }
            else if (SelectedNode.Tag is MedalOrRankCondition)
            {
                Child = new MedalConditionForm(SelectedNode);
            }
            else if (SelectedNode.Tag is GlobalStatMultTimes)
            {
                Child = new GlobalStatMultTimesForm(SelectedNode);
            }
            else if (SelectedNode.Tag is ConditionList)
            {
                Child = new ConditionListForm(SelectedNode);
            }
            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.ToTree());
                ConditionTree.Refresh();
                ConditionTree.ExpandAll();
            }
        }
Beispiel #2
0
        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;
        }
        /// <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>
        /// Removes a criteria from the selected awards condition tree
        /// </summary>
        public void DeleteCriteria()
        {
            // Make sure we have a node selected
            if (ConditionNode == null)
            {
                MessageBox.Show("Please select a criteria to remove.");
                return;
            }

            // Dont update tree till we are finished adding/removing
            AwardConditionsTree.BeginUpdate();

            if (ConditionNode.Parent == null)
            {
                AwardConditionsTree.Nodes.Remove(ConditionNode);
                ValidateConditions(SelectedAwardNode, SelectedAward.GetCondition());
            }

            // Dont delete on Plus / Div Trees
            else if (!(ConditionNode.Tag is ConditionList))
            {
                TreeNode      Parent = ConditionNode.Parent;
                ConditionList C      = (ConditionList)Parent.Tag;

                // Remove Not Conditions, as they only hold 1 criteria anyways
                if (C.Type == ConditionType.Not)
                {
                    AwardConditionsTree.Nodes.Remove(Parent);
                }

                // Dont remove Plus or Div elements as they need 2 or 3 to work!
                else if (C.Type == ConditionType.Plus || C.Type == ConditionType.Div)
                {
                    ConditionNode = Parent;
                    AwardConditionsTree.SelectedNode = Parent;
                    EditCriteria();
                }
                else
                {
                    // Remove Node
                    AwardConditionsTree.Nodes.Remove(ConditionNode);

                    // remove empty parent nodes
                    if (Parent.Nodes.Count == 0)
                    {
                        AwardConditionsTree.Nodes.Remove(Parent);
                    }
                }
            }
            else
            {
                AwardConditionsTree.Nodes.Remove(ConditionNode);
            }

            // Get our selected medal condition
            Condition Cond = null;

            // Set awards new conditions
            if (AwardConditionsTree.Nodes.Count > 0)
            {
                Cond = MedalDataParser.ParseNodeConditions(AwardConditionsTree.Nodes[0]);
                SelectedAward.SetCondition(Cond);
            }
            else
            {
                SelectedAward.SetCondition(null);
            }

            // Reparse conditions
            AwardConditionsTree.Nodes.Clear();
            TreeNode NN = SelectedAward.ToTree();

            if (NN != null)
            {
                AwardConditionsTree.Nodes.Add(NN);
            }

            ValidateConditions(SelectedAwardNode, Cond);
            AwardConditionsTree.EndUpdate();
            AwardConditionsTree.ExpandAll();
        }
        /// <summary>
        /// Brings up the Criteria Editor for the selected Award Condition Node
        /// </summary>
        public void EditCriteria()
        {
            // Make sure we have a node selected
            if (ConditionNode == null)
            {
                MessageBox.Show("Please select a criteria to edit.");
                return;
            }

            // Make sure its a child node
            if (ConditionNode.Parent == null && ConditionNode.Nodes.Count != 0)
            {
                return;
            }

            // Open correct condition editor form
            if (ConditionNode.Tag is ObjectStat)
            {
                Child = new ObjectStatForm(ConditionNode);
            }
            else if (ConditionNode.Tag is PlayerStat)
            {
                Child = new ScoreStatForm(ConditionNode);
            }
            else if (ConditionNode.Tag is MedalOrRankCondition)
            {
                Child = new MedalConditionForm(ConditionNode);
            }
            else if (ConditionNode.Tag is GlobalStatMultTimes)
            {
                Child = new GlobalStatMultTimesForm(ConditionNode);
            }
            else if (ConditionNode.Tag is ConditionList)
            {
                Child = new ConditionListForm(ConditionNode);
            }
            else
            {
                return;
            }

            if (Child.ShowDialog() == DialogResult.OK)
            {
                // Delay tree redraw
                AwardConditionsTree.BeginUpdate();

                // Set awards new conditions from the tree node tagged conditions
                SelectedAward.SetCondition(MedalDataParser.ParseNodeConditions(AwardConditionsTree.Nodes[0]));

                // Clear all current Nodes
                AwardConditionsTree.Nodes.Clear();

                // Reparse conditions
                AwardConditionsTree.Nodes.Add(SelectedAward.ToTree());

                // Validation highlighting
                ValidateConditions(SelectedAwardNode, SelectedAward.GetCondition());

                // Conditions tree's are to be expanded at all times
                AwardConditionsTree.ExpandAll();
                AwardConditionsTree.EndUpdate();
            }
        }