Пример #1
0
        public static bool IsConditionTrue(string displayCondition, ini ini)
        {
            var parsed = new DisplayConditionParse(displayCondition);
            var opt    = ini.FindIniOption(parsed.category, parsed.name);

            if (opt != null)
            {
                if (parsed.op == ">" && int.Parse(opt.inidata) <= int.Parse(parsed.val))
                {
                    return(false);
                }
                if (parsed.op == "<" && int.Parse(opt.inidata) >= int.Parse(parsed.val))
                {
                    return(false);
                }
                if (parsed.op == "==" && int.Parse(opt.inidata) != int.Parse(parsed.val))
                {
                    return(false);
                }
                if (parsed.op == "!=" && int.Parse(opt.inidata) == int.Parse(parsed.val))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        public int Render(Control parent, int y)
        {
            if (dontRender)
            {
                return(y);
            }

            if (!string.IsNullOrEmpty(displayCondition))
            {
                if (!DisplayConditionParse.IsConditionTrue(displayCondition, ini))
                {
                    return(y);
                }
            }

            var x = 10;

            if (type == optionType.boolean)
            {
                var chk = new CheckBox();
                chk.AutoSize        = true;
                chk.Location        = new Point(x, y);
                chk.Checked         = inidata == "1";
                chk.Parent          = parent;
                chk.CheckedChanged += (object sender, EventArgs e) => inidata = chk.Checked ? "1" : "0";
                x += 15;
                var lbl2 = new Label();
                lbl2.Text        = label;
                lbl2.Parent      = parent;
                lbl2.Location    = new Point(x, y);
                lbl2.AutoSize    = true;
                lbl2.MouseClick += (_, __) =>
                {
                    chk.Checked = !chk.Checked;
                    inidata     = chk.Checked ? "1" : "0";
                    ini.redrawCallback();
                };

                if (!string.IsNullOrEmpty(description))
                {
                    y += 18;
                    var label = new Label();
                    label.AutoSize = true;
                    label.Text     = description;
                    label.Location = new Point(x, y);
                    label.Parent   = parent;
                    y += label.Height;
                }

                y += 20;
            }
            if (type == optionType.integer)
            {
                // Draw everything on one line
                if (style == RenderStyle.Inline)
                {
                    var lbl = CreateLabel(parent, label, x, y + 3);
                    CreateNumericUpDown(parent, lbl.PreferredWidth + x, y);
                    y += 30;
                }
                else
                {
                    var grp  = CreateGroupBox(parent, x, y);
                    int grpY = 25;
                    var num  = CreateNumericUpDown(grp, x, grpY);
                    x = 10;

                    if (min.HasValue)
                    {
                        num.Minimum = min.Value;
                    }
                    if (max.HasValue)
                    {
                        num.Maximum = max.Value;
                    }

                    if (!string.IsNullOrEmpty(description))
                    {
                        grpY += 25;
                        var label = new Label();
                        label.AutoSize = true;
                        label.Text     = description;
                        label.Location = new Point(x, grpY);
                        label.Parent   = grp;
                    }

                    grp.Height = grpY;
                    y         += grp.Height + 10;
                }
            }

            if (type == optionType.intEnum)
            {
                var grp = new GroupBox();
                grp.Text     = label;
                grp.Parent   = parent;
                grp.Location = new Point(x, y);
                grp.AutoSize = true;

                int grpY = 25;

                var cmb = new ComboBox();
                cmb.Location      = new Point(x, grpY - 2);
                cmb.Parent        = grp;
                cmb.DropDownStyle = ComboBoxStyle.DropDownList;

                int i           = 0;
                int selectedIdx = 0;
                int maxWidth    = 0;
                foreach (var e in enums)
                {
                    cmb.Items.Add(e.Key);
                    var temp = TextRenderer.MeasureText(e.Key, cmb.Font).Width + 20;
                    if (temp > maxWidth)
                    {
                        maxWidth = temp;
                    }

                    if (e.Value.ToString() == inidata)
                    {
                        selectedIdx = i;
                    }

                    i++;
                }
                cmb.SelectedIndex         = selectedIdx;
                cmb.Width                 = maxWidth;
                cmb.SelectedIndexChanged += (object sender, EventArgs ee) =>
                {
                    if (cmb.SelectedIndex == -1)
                    {
                        return;
                    }
                    inidata = enums[cmb.Text].ToString();
                    // TODO: Be more clever about when to redraw or not
                    // we can check if some displayCondition is depending on this.
                    ini.redrawCallback();
                };

                x = 10;

                string renderDescription = "";
                int    val = int.Parse(inidata);

                if (!string.IsNullOrEmpty(valueDescription))
                {
                    int idxValueDesc = valueDescription.IndexOf(val + ":");
                    if (idxValueDesc != -1)
                    {
                        idxValueDesc += 2;
                        int stopIdx = valueDescription.IndexOf(':', idxValueDesc);
                        int len     = stopIdx - idxValueDesc;
                        renderDescription += valueDescription.Substring(idxValueDesc, len) + "\n\n";
                    }
                }

                if (!string.IsNullOrEmpty(description))
                {
                    renderDescription += description;
                }

                if (!string.IsNullOrEmpty(renderDescription))
                {
                    grpY += 25;
                    var label = new Label();
                    label.AutoSize = true;
                    label.Text     = renderDescription;
                    label.Location = new Point(x, grpY);
                    label.Parent   = grp;
                }

                grp.Height = grpY;

                y += grp.Height + 10;
            }

            if (type == optionType.str)
            {
                var grp  = this.CreateGroupBox(parent, x, y);
                int grpY = 20;

                /* var lbl = CreateLabel(parent, label, x, grpY + 3);
                 * x += lbl.Width;*/
                var txt = new TextBox();
                txt.Location     = new Point(x, grpY);
                txt.Parent       = grp;
                txt.Text         = inidata;
                txt.TextChanged += (object sender, EventArgs e) =>
                {
                    this.inidata = txt.Text;
                };
                if (!string.IsNullOrEmpty(description))
                {
                    x     = 10;
                    grpY += 25;
                    var label = new Label();
                    label.AutoSize = true;
                    label.Text     = description;
                    label.Location = new Point(x, grpY);
                    label.Parent   = grp;
                }

                y += grp.Height + 10;
            }



            return(y);
        }
Пример #3
0
        public int Render(Control parent, int y)
        {
            if (!string.IsNullOrEmpty(displayCondition))
            {
                if (!DisplayConditionParse.IsConditionTrue(displayCondition, ini))
                {
                    return(y);
                }
            }

            var spl  = iniOptions.Split(',');
            var wOpt = ini.FindIniOption(category, spl[0]);
            var hOpt = ini.FindIniOption(category, spl[1]);

            var width  = int.Parse(wOpt.inidata);
            var height = int.Parse(hOpt.inidata);

            var grp = new GroupBox();

            grp.Text     = name;
            grp.Parent   = parent;
            grp.Location = new Point(10, y);
            grp.AutoSize = true;

            int grpY = 25;
            int x    = 10;

            var lblw = new Label();

            lblw.Text     = "W:";
            lblw.Parent   = grp;
            lblw.Location = new Point(x, grpY + 3);
            lblw.AutoSize = true;

            x += 23;

            var num1 = new NumericUpDown();

            num1.Width         = 50;
            num1.Location      = new Point(x, grpY);
            num1.Maximum       = 10000;
            num1.Value         = width;
            num1.Parent        = grp;
            num1.ValueChanged += (object sender, EventArgs e) => wOpt.inidata = num1.Value.ToString();

            x += 55;

            var lblh = new Label();

            lblh.Text     = "H:";
            lblh.Parent   = grp;
            lblh.Location = new Point(x, grpY + 3);
            lblh.AutoSize = true;

            x += 23;

            var num2 = new NumericUpDown();

            num2.Width         = 50;
            num2.Location      = new Point(x, grpY);
            num2.Maximum       = 10000;
            num2.Value         = height;
            num2.Parent        = grp;
            num2.ValueChanged += (object sender, EventArgs e) => wOpt.inidata = num1.Value.ToString();

            if (!string.IsNullOrEmpty(description))
            {
                x     = 10;
                grpY += 25;
                var dsc = new Label();
                dsc.AutoSize = true;
                dsc.Text     = description;
                dsc.Location = new Point(x, grpY);
                dsc.Parent   = grp;
            }

            grp.Height = grpY;

            y += grp.Height + 20;

            return(y);
        }