Exemple #1
0
        private void SbPolicyTrees_SelectedChanged(object sender, ListItemEventArgs e)
        {
            // save the selected index
            PolicyTreeListItem ptli = (PolicyTreeListItem)e.ListItem;

            selectedIndex = ptli.Index;
            // draw the policy tree

            // show the form
            Show();
        }
Exemple #2
0
        /// <summary>
        /// Opens the gui element
        /// </summary>
        public void Show()
        {
            lock (SceneGame._lock_guiDrawCall)
            {
                // setup the form
                sceneGame.HideForms();
                canvas.RemoveChild(form);
                form           = new Form(formConfig, canvas);
                form.Draggable = false;
                form.Drawn    += Form_Drawn;
                form.CentreControl();
                form.Location = new Point(form.Location.X, 35);

                // get and setup the form elements
                ScrollBox sbSocialPolicyTrees = (ScrollBox)form.GetChildByName("sbSocialPolicyTrees");
                sbSocialPolicyTrees.SelectedIndex    = selectedIndex;
                sbSocialPolicyTrees.Items            = GetPolicyTreeListItems();
                sbSocialPolicyTrees.SelectedChanged += SbPolicyTrees_SelectedChanged;
                PolicyTreeListItem selectedItem = (PolicyTreeListItem)sbSocialPolicyTrees.Selected;

                lines = new List <Line>();

                int offsetX    = sbSocialPolicyTrees.AbsoluteBounds.Width + 10;
                int offsetY    = 50;
                int itemWidth  = 200;
                int itemHeight = 70;
                int sepX       = 70;
                int sepY       = 50;

                // build a button for every node in the social policy tree
                foreach (SocialPolicy policy in client.Player.SocialPolicyInstance.GetAllSocialPoliciesInTree(selectedItem.SocialPolicyTree.ID))
                {
                    Rectangle dest = new Rectangle(offsetX + policy.GridX * (itemWidth + sepX), offsetY + policy.GridY * (itemHeight + sepY), itemWidth, itemHeight);
                    Button    b    = new Button(dest, form);
                    string    text = policy.Name;
                    // format the button text
                    b.Text = text.ToRichText();
                    // pick an appropriate sprite
                    bool unlockable = true;
                    foreach (string prereqID in policy.Prerequisites)
                    {
                        SocialPolicy prereq = client.Player.SocialPolicyInstance.GetSocialPolicy(prereqID);
                        if (prereq != null && !prereq.Unlocked)
                        {
                            unlockable = false;
                        }
                    }
                    if (policy.Unlocked)
                    {
                        b.Sprite = policyUnlockedSprite;
                    }
                    else if (unlockable)
                    {
                        b.Sprite = policyAdoptable;
                    }
                    else
                    {
                        b.Sprite = policyLockedSprite;
                    }

                    string policyID = policy.ID; // cache id because of closure
                    b.MouseClick += (s, a) =>
                    {
                        // only tell the server to select a new tech if all the prereqs are unlocked
                        SocialPolicy clicked = client.DataManager.SocialPolicy.GetSocialPolicy(policyID);
                        foreach (string prereqID in clicked.Prerequisites)
                        {
                            SocialPolicy prereq = client.Player.SocialPolicyInstance.GetSocialPolicy(prereqID);
                            if (prereq != null && !prereq.Unlocked)
                            {
                                return;
                            }
                        }

                        client.CommandPlayer(new PlayerCommand(PlayerCommandID.UnlockPolicy, policyID));
                    };
                    // add a tool tip with more info about the policy
                    b.ToolTip = new ToolTip(policy.Description.ToRichText(), 500);
                    b.ToolTip.FollowCurosr = true;

                    // add a line from the current policy to all its prereqs
                    foreach (string prereqID in policy.Prerequisites)
                    {
                        SocialPolicy prereq = client.DataManager.SocialPolicy.GetSocialPolicy(prereqID);
                        if (prereq == null)
                        {
                            continue;
                        }
                        Rectangle prereqRect = new Rectangle(offsetX + prereq.GridX * (itemWidth + sepX), offsetY + prereq.GridY * (itemHeight + sepY), itemWidth, itemHeight);
                        lines.Add(new Line(new Vector2(form.AbsoluteLocation.X + dest.X, dest.Y + itemHeight / 2 + offsetY), new Vector2(form.AbsoluteLocation.X + prereqRect.X + itemWidth, prereqRect.Y + itemHeight / 2 + offsetY)));
                    }
                }
            }
        }