Exemplo n.º 1
0
        public CustomStep ShowOptionAsStep(string optionKey, bool required, string title)
        {
            GameOption option = Options.First(c => c.Key == optionKey);

            option.Hidden = true;

            CustomStep step = new CustomStep();

            step.Option   = option;
            step.Required = required;
            step.Title    = title;

            CustomSteps.Add(step);
            return(step);
        }
        public override void Initialize(UserGameInfo game, GameProfile profile)
        {
            base.Initialize(game, profile);

            this.Controls.Clear();

            int wid = 200;

            list = new ControlListBox();
            GameOption[] options             = game.Game.Options;
            Dictionary <string, object> vals = profile.Options;

            for (int j = 0; j < options.Length; j++)
            {
                GameOption opt = options[j];

                object val;
                if (!vals.TryGetValue(opt.Key, out val))
                {
                    continue;
                }

                CoolListControl cool = new CoolListControl();
                cool.Text        = opt.Name;
                cool.Description = opt.Description;
                cool.Width       = this.Width;

                list.Controls.Add(cool);

                // Check the value type and add a control for it
                if (opt.Value is bool)
                {
                    SizeableCheckbox box = new SizeableCheckbox();
                    int border           = 10;

                    box.Checked = (bool)val;
                    box.Width   = 40;
                    box.Height  = 40;
                    box.Left    = cool.Width - box.Width - border;
                    box.Top     = (cool.Height / 2) - (box.Height / 2);
                    box.Anchor  = AnchorStyles.Right;
                    cool.AddControl(box, false);

                    box.Tag             = opt;
                    box.CheckedChanged += box_CheckedChanged;
                }
                else if (opt.Value is int || opt.Value is double)
                {
                    NumericUpDown num    = new NumericUpDown();
                    int           border = 10;

                    int value = (int)(double)val;
                    if (value < num.Minimum)
                    {
                        num.Minimum = value;
                    }

                    num.Value = value;

                    num.Width  = wid;
                    num.Height = 40;
                    num.Left   = cool.Width - num.Width - border;
                    num.Top    = (cool.Height / 2) - (num.Height / 2);
                    num.Anchor = AnchorStyles.Right;
                    cool.AddControl(num, false);

                    num.Tag           = opt;
                    num.ValueChanged += num_ValueChanged;
                }
                else if (opt.Value is Enum)
                {
                    ComboBox box    = new ComboBox();
                    int      border = 10;

                    Enum  value  = (Enum)val;
                    Array values = Enum.GetValues(value.GetType());
                    for (int i = 0; i < values.Length; i++)
                    {
                        box.Items.Add(((IList)values)[i]);
                    }
                    box.SelectedIndex = box.Items.IndexOf(value);

                    box.Width  = wid;
                    box.Height = 40;
                    box.Left   = cool.Width - box.Width - border;
                    box.Top    = (cool.Height / 2) - (box.Height / 2);
                    box.Anchor = AnchorStyles.Right;
                    cool.AddControl(box, false);

                    box.Tag = opt;
                    box.SelectedValueChanged += box_SelectedValueChanged;
                }
                else if (opt.Value is GameOptionValue)
                {
                    ComboBox box    = new ComboBox();
                    int      border = 10;

                    GameOptionValue value = (GameOptionValue)val;
                    PropertyInfo[]  props = value.GetType().GetProperties(BindingFlags.Public | BindingFlags.Static);

                    for (int i = 0; i < props.Length; i++)
                    {
                        PropertyInfo prop = props[i];
                        box.Items.Add(prop.GetValue(null, null));
                    }
                    box.SelectedIndex = box.Items.IndexOf(value);

                    box.Width  = wid;
                    box.Height = 40;
                    box.Left   = cool.Width - box.Width - border;
                    box.Top    = (cool.Height / 2) - (box.Height / 2);
                    box.Anchor = AnchorStyles.Right;
                    cool.AddControl(box, false);

                    box.Tag = opt;
                    box.SelectedValueChanged += box_SelectedValueChanged;
                }
            }

            list.Size = this.Size;
            this.Controls.Add(list);

            list.UpdateSizes();
            OnCanPlayTrue(false);
        }
Exemplo n.º 3
0
        public override void Initialize(HandlerData handlerData, UserGameInfo game, GameProfile profile)
        {
            base.Initialize(handlerData, game, profile);

            Controls.Clear();

            // grab the CustomStep and extract what we have to show from it
            GameOption option = CustomStep.Option;

            if (option.IsCollection())
            {
                ControlListBox list = new ControlListBox();
                list.Size       = this.Size;
                list.AutoScroll = true;

                Controls.Add(list);

                collection = option.GetCollection();
                for (int i = 0; i < collection.Count; i++)
                {
                    object val = collection[i];

                    // TODO: make image options
                    if (!(val is IDictionary <string, JToken>))
                    {
                        continue;
                    }

                    CoolListControl control = new CoolListControl(true);
                    control.Anchor      = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                    control.BackColor   = Color.FromArgb(30, 30, 30);
                    control.Size        = new Size(list.Width, 120);
                    control.Data        = val;
                    control.OnSelected += Control_OnSelected;

                    IDictionary <string, JToken> value = (IDictionary <string, JToken>)val;
                    string name = value["Name"].ToString();

                    control.Title       = name;
                    control.TitleFont   = nameFont;
                    control.DetailsFont = detailsFont;

                    string details = "";
                    JToken detailsObj;
                    if (value.TryGetValue("Details", out detailsObj))
                    {
                        details = detailsObj.ToString();

                        control.Details = details;
                    }

                    JToken imageUrlObj;
                    value.TryGetValue("ImageUrl", out imageUrlObj);
                    if (imageUrlObj != null)
                    {
                        string imageUrl = imageUrlObj.ToString();
                        if (!string.IsNullOrEmpty(imageUrl))
                        {
                            Image img = DataManager.Content.LoadImage(imageUrl);

                            PictureBox box = new PictureBox();
                            box.Anchor   = AnchorStyles.Top | AnchorStyles.Right;
                            box.Size     = new Size(140, 80);
                            box.Location = new Point(list.Width - box.Width - 10, 20);
                            box.SizeMode = PictureBoxSizeMode.Zoom;
                            box.Image    = img;
                            control.Controls.Add(box);
                        }
                    }

                    list.Controls.Add(control);
                }
            }
            else
            {
            }
        }