コード例 #1
0
        public void Select(StandardLine line, Vector2d position)
        {
            if (selectionwindow != null)
            {
                if (selectionwindow.UserData != line)
                {
                    selectionwindow.Close();
                    selectionwindow = null;
                }
            }
            if (selectionwindow == null)
            {
                selectionwindow = new WindowControl(game.Canvas, "Line Settings", false);
                selectionwindow.MakeModal(true);
                selectionwindow.UserData      = line;
                selectionwindow.DeleteOnClose = true;
                selectionwindow.DisableResizing();
                selectionwindow.Height = 170;
                selectionwindow.Width  = 150;

                ControlBase container1 = new ControlBase(selectionwindow);
                container1.Dock = Gwen.Pos.Fill;
                if (line.GetLineType() != LineType.Scenery)
                {
                    LabeledCheckBox btn = new LabeledCheckBox(container1);
                    btn.Dock          = Gwen.Pos.Top;
                    btn.Text          = "Inverse";
                    btn.IsChecked     = line.inv;
                    btn.CheckChanged += (o, e) =>
                    {
                        var caller = (LabeledCheckBox)o;
                        line.inv = caller.IsChecked;
                        line.CalculateConstants();
                        game.Track.TrackUpdated();
                        game.Invalidate();
                    };
                    LineTrigger tr = (LineTrigger)line.Trigger ?? new LineTrigger();

                    var gb = new PropertyTree(container1);
                    gb.Height = 110;
                    gb.Dock   = Gwen.Pos.Top;

                    PropertyTree table = new PropertyTree(gb);

                    table.Name   = "triggers";
                    table.Dock   = Gwen.Pos.Fill;
                    table.Height = 100;

                    var row     = table.Add("Zoom Trigger");
                    var enabled = row.Add("Enabled", new Gwen.Controls.Property.Check(table));
                    enabled.Value         = tr.Zoomtrigger ? "1" : "0";
                    enabled.ValueChanged += (o, e) =>
                    {
                        if (enabled.Value == "1")
                        {
                            tr.Zoomtrigger = true;
                            tr.ZoomTarget  = float.Parse(((PropertyRow)container1.FindChildByName("Zoom", true)).Value);
                            tr.ZoomFrames  = int.Parse(((PropertyRow)container1.FindChildByName("ZoomFrames", true)).Value);
                            line.Trigger   = tr;
                        }
                        else
                        {
                            tr.Zoomtrigger = false;
                            if (!tr.Enabled)
                            {
                                line.Trigger = null;
                            }
                        }
                        game.Track.LineChanged(line);
                    };
                    var prop = row.Add("Zoom");
                    prop.Name          = "Zoom";
                    prop.Value         = (enabled.Value == "1" ? tr.ZoomTarget : 1).ToString();
                    prop.ValueChanged += (o, e) =>
                    {
                        var   caller = (PropertyRow)o;
                        float val    = 0;
                        if (float.TryParse(caller.Value, out val) && val >= 0.1 && val <= 24)
                        {
                            caller.LabelColor = System.Drawing.Color.Black;
                            tr.ZoomTarget     = val;
                        }
                        else
                        {
                            caller.LabelColor = System.Drawing.Color.Red;
                        }
                    };
                    prop               = row.Add("Frames");
                    prop.Name          = "ZoomFrames";
                    prop.Value         = (enabled.Value == "1" ? tr.ZoomFrames : 40).ToString();
                    prop.ValueChanged += (o, e) =>
                    {
                        var caller = (PropertyRow)o;
                        int val    = 0;
                        if (int.TryParse(caller.Value, out val) && val >= 1 && val < 10000)
                        {
                            caller.LabelColor = System.Drawing.Color.Black;
                            tr.ZoomFrames     = val;
                        }
                        else
                        {
                            caller.LabelColor = System.Drawing.Color.Red;
                        }
                    };
                }

                if (line.GetLineType() == LineType.Red)
                {
                    selectionwindow.Height += 30;
                    NoDecimalNUD nud  = new NoDecimalNUD(container1);
                    var          marg = nud.Margin;
                    marg.Top          = 5;
                    marg.Left         = marg.Right = 1;
                    marg.Left         = 70;
                    marg.Bottom       = 10;
                    nud.Margin        = marg;
                    nud.Dock          = Gwen.Pos.Top;
                    nud.Min           = 1;
                    nud.Max           = 3;
                    nud.Value         = (line as RedLine).Multiplier;
                    nud.ValueChanged += nud_redlinemultiplier_ValueChanged;
                    nud.UserData      = line;
                    Label l = new Label(container1);
                    l.Y    = 137;
                    l.Text = "Multiplier";
                    selectionwindow.Height += 25;


                    nud         = new NoDecimalNUD(container1);
                    marg        = nud.Margin;
                    marg.Top    = 5;
                    marg.Left   = marg.Right = 1;
                    marg.Left   = 70;
                    marg.Bottom = 10;
                    nud.Margin  = marg;
                    nud.Dock    = Gwen.Pos.Top;
                    var         lines    = game.Track.GetLinesInRect(new FloatRect((Vector2)line.Position, new Vector2(1, 1)), false);
                    List <Line> redlines = new List <Line>();
                    foreach (var red in lines)
                    {
                        if (red.Position == line.Position && red.Position2 == line.Position2)
                        {
                            redlines.Add(red);
                        }
                    }
                    nud.Min = 1;
                    nud.Max = 50;
                    redlines.Sort(new Track.Linecomparer());
                    nud.Value         = redlines.Count;
                    nud.ValueChanged += (o, e) =>
                    {
                        var diff = nud.Value - redlines.Count;
                        if (diff < 0)
                        {
                            for (int i = 0; i > diff; i--)
                            {
                                game.Track.RemoveLine(redlines[(int)((redlines.Count - 1))]);
                                redlines.RemoveAt(redlines.Count - 1);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < diff; i++)
                            {
                                var red = new RedLine(line.Position, line.Position2, line.inv)
                                {
                                    Multiplier = ((RedLine)line).Multiplier
                                };
                                game.Track.AddLine(red);
                                redlines.Add(red);
                            }
                        }
                        game.Track.TrackUpdated();
                    };
                    nud.UserData = line;
                    l            = new Label(container1);
                    l.Y          = 137 + 35;
                    l.Text       = "Multilines";
                }
                selectionwindow.IsHiddenChanged += Selectionwindow_IsHiddenChanged;
                selectionwindow.Show();
                selectionwindow.X = (int)position.X;
                selectionwindow.Y = (int)position.Y;
                game.Cursor       = MouseCursor.Default;
            }
        }
コード例 #2
0
        public SelectedLineWindow(Gwen.Controls.ControlBase parent, MainWindow glgame, GameLine line) : base(parent, DefaultTitle)
        {
            game       = glgame;
            _ownerline = line;
            this.MakeModal(true);
            this.Height = 190;
            this.Width  = 150;
            ControlBase container1 = new ControlBase(this);

            container1.Dock = Gwen.Pos.Fill;
            if (line.Type != LineType.Scenery)
            {
                var             stl = (StandardLine)line;
                LabeledCheckBox btn = new LabeledCheckBox(container1);
                btn.Dock          = Gwen.Pos.Top;
                btn.Text          = "Inverse";
                btn.IsChecked     = stl.inv;
                btn.CheckChanged += (o, e) =>
                {
                    using (var trk = game.Track.CreateTrackWriter())
                    {
                        LineChanging();
                        var copy   = (StandardLine)stl.Clone();
                        var caller = (LabeledCheckBox)o;
                        copy.inv = caller.IsChecked;
                        copy.CalculateConstants();
                        trk.ReplaceLine(stl, copy);
                        game.Track.NotifyTrackChanged();
                        game.Invalidate();
                    }
                };
                LineTrigger tr = (LineTrigger)stl.Trigger ?? new LineTrigger();

                var gb = new PropertyTree(container1);
                gb.Height = 110;
                gb.Dock   = Gwen.Pos.Top;

                PropertyTree table = new PropertyTree(gb);

                table.Name   = "triggers";
                table.Dock   = Gwen.Pos.Fill;
                table.Height = 100;

                var row     = table.Add("Zoom Trigger");
                var enabled = row.Add("Enabled", new Gwen.Controls.Property.Check(table));
                enabled.Value         = tr.Zoomtrigger ? "1" : "0";
                enabled.ValueChanged += (o, e) =>
                {
                    using (var trk = game.Track.CreateTrackWriter())
                    {
                        LineChanging();
                        trk.DisableExtensionUpdating();
                        var copy = (StandardLine)stl.Clone();
                        if (enabled.Value == "1")
                        {
                            tr.Zoomtrigger = true;
                            tr.ZoomTarget  = float.Parse(((PropertyRow)container1.FindChildByName("Zoom", true)).Value);
                            tr.ZoomFrames  = int.Parse(((PropertyRow)container1.FindChildByName("ZoomFrames", true)).Value);
                            copy.Trigger   = tr;
                        }
                        else
                        {
                            tr.Zoomtrigger = false;
                            if (!tr.Enabled)
                            {
                                copy.Trigger = null;
                            }
                        }
                        trk.ReplaceLine(stl, copy);
                        game.Track.NotifyTrackChanged();
                    }
                };
                var prop = row.Add("Zoom");
                prop.Name          = "Zoom";
                prop.Value         = (enabled.Value == "1" ? tr.ZoomTarget : 1).ToString();
                prop.ValueChanged += (o, e) =>
                {
                    var   caller = (PropertyRow)o;
                    float val    = 0;
                    if (float.TryParse(caller.Value, out val) && val >= 0.1 && val <= 24)
                    {
                        caller.LabelColor = System.Drawing.Color.Black;
                        tr.ZoomTarget     = val;
                    }
                    else
                    {
                        caller.LabelColor = System.Drawing.Color.Red;
                    }
                };
                prop               = row.Add("Frames");
                prop.Name          = "ZoomFrames";
                prop.Value         = (enabled.Value == "1" ? tr.ZoomFrames : 40).ToString();
                prop.ValueChanged += (o, e) =>
                {
                    var caller = (PropertyRow)o;
                    int val    = 0;
                    if (int.TryParse(caller.Value, out val) && val >= 1 && val < 10000)
                    {
                        caller.LabelColor = System.Drawing.Color.Black;
                        tr.ZoomFrames     = val;
                    }
                    else
                    {
                        caller.LabelColor = System.Drawing.Color.Red;
                    }
                };
            }

            if (line.Type == LineType.Red)
            {
                ControlBase optioncontainer = new ControlBase(container1);
                optioncontainer.Dock   = Pos.Top;
                optioncontainer.Height = 30;
                var redstl = (RedLine)line;
                Height += 30;
                NoDecimalNUD nud  = new NoDecimalNUD(optioncontainer);
                var          marg = nud.Margin;
                marg.Top          = 5;
                marg.Left         = marg.Right = 1;
                marg.Left         = 70;
                marg.Bottom       = 10;
                nud.Margin        = marg;
                nud.Dock          = Gwen.Pos.Top;
                nud.Min           = 1;
                nud.Max           = 3;
                nud.Value         = (line as RedLine).Multiplier;
                nud.ValueChanged += nud_redlinemultiplier_ValueChanged;
                nud.UserData      = line;
                Label l = new Label(optioncontainer);
                l.Y     = 5;
                l.Text  = "Multiplier";
                Height += 25;

                optioncontainer        = new ControlBase(container1);
                optioncontainer.Dock   = Pos.Top;
                optioncontainer.Height = 30;
                nud               = new NoDecimalNUD(optioncontainer);
                marg              = nud.Margin;
                marg.Top          = 5;
                marg.Left         = marg.Right = 1;
                marg.Left         = 70;
                marg.Bottom       = 10;
                nud.Margin        = marg;
                nud.Dock          = Gwen.Pos.Top;
                nud.Min           = 1;
                nud.Max           = 9999;
                nud.Value         = GetMultiLines(true).Count;
                nud.ValueChanged += (o, e) =>
                {
                    var val = (int)nud.Value;
                    if (val > 0)
                    {
                        Multiline(val);
                    }
                };
                nud.UserData = line;
                l            = new Label(optioncontainer);
                l.Y          = 5;
                l.Text       = "Multilines";
            }
            Button saveandquit = new Button(container1);

            saveandquit.Name = "saveandquit";
            saveandquit.Disable();
            saveandquit.Dock     = Pos.Bottom;
            saveandquit.Text     = "Save changes";
            saveandquit.Clicked += (o, e) =>
            {
                if (!saveandquit.IsDisabled)
                {
                    if (!_closing)
                    {
                        _closing = true;
                        if (_linechanged)
                        {
                            game.Track.UndoManager.EndAction();
                        }
                        if (!this.IsHidden)
                        {
                            Close();
                        }
                    }
                }
            };
            RecurseLayout(Skin);
            this.MinimumSize = new System.Drawing.Point(Width, Height);
            game.Cursor      = OpenTK.MouseCursor.Default;
        }