Ejemplo n.º 1
0
        public override IntRange SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            RangeBorderAttribute rangeAtt = ReflectionExt.FindAttribute <RangeBorderAttribute>(attributes);
            int addMin = 0;
            int addMax = 0;

            if (rangeAtt != null)
            {
                rangeAtt.GetAddVals(out addMin, out addMax);
            }

            int controlIndex = 0;

            controlIndex++;
            Avalonia.Controls.Grid innerControl = (Avalonia.Controls.Grid)control.Children[controlIndex];
            int innerControlIndex = 0;

            innerControlIndex++;
            NumericUpDown nudValueX = (NumericUpDown)innerControl.Children[innerControlIndex];

            innerControlIndex++;
            innerControlIndex++;
            NumericUpDown nudValueY = (NumericUpDown)innerControl.Children[innerControlIndex];

            return(new IntRange((int)nudValueX.Value - addMin, (int)nudValueY.Value - addMax));
        }
Ejemplo n.º 2
0
        public override Color SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            int controlIndex = 0;

            controlIndex++;
            Avalonia.Controls.Grid innerControl = (Avalonia.Controls.Grid)control.Children[controlIndex];
            int innerControlIndex = 0;

            innerControlIndex++;
            NumericUpDown nudValueR = (NumericUpDown)innerControl.Children[innerControlIndex];

            innerControlIndex++;
            innerControlIndex++;
            NumericUpDown nudValueG = (NumericUpDown)innerControl.Children[innerControlIndex];

            innerControlIndex++;
            innerControlIndex++;
            NumericUpDown nudValueB = (NumericUpDown)innerControl.Children[innerControlIndex];

            innerControlIndex++;
            innerControlIndex++;
            NumericUpDown nudValueA = (NumericUpDown)innerControl.Children[innerControlIndex];

            return(new Color((int)nudValueR.Value, (int)nudValueG.Value, (int)nudValueB.Value, (int)nudValueA.Value));
        }
Ejemplo n.º 3
0
        public override MonsterID SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            MonsterID          result  = new MonsterID();
            MonsterIDAttribute dataAtt = ReflectionExt.FindAttribute <MonsterIDAttribute>(attributes);

            int controlIndex = 0;

            controlIndex++;
            Avalonia.Controls.Grid innerControl1 = (Avalonia.Controls.Grid)control.Children[controlIndex];

            int innerControlIndex = 0;

            innerControlIndex++;
            ComboBox cbSpecies = (ComboBox)innerControl1.Children[innerControlIndex];

            result.Species = cbSpecies.SelectedIndex;
            if (dataAtt.InvalidSpecies)
            {
                result.Species--;
            }

            controlIndex++;
            Avalonia.Controls.Grid innerControl2 = (Avalonia.Controls.Grid)control.Children[controlIndex];
            innerControlIndex = 0;
            innerControlIndex++;
            ComboBox cbForm = (ComboBox)innerControl2.Children[innerControlIndex];

            result.Form = cbForm.SelectedIndex;
            if (dataAtt.InvalidForm)
            {
                result.Form--;
            }

            controlIndex++;
            Avalonia.Controls.Grid innerControl3 = (Avalonia.Controls.Grid)control.Children[controlIndex];

            innerControlIndex = 0;
            innerControlIndex++;
            ComboBox cbSkin = (ComboBox)innerControl3.Children[innerControlIndex];

            result.Skin = cbSkin.SelectedIndex;
            if (dataAtt.InvalidSkin)
            {
                result.Skin--;
            }

            innerControlIndex++;
            innerControlIndex++;
            ComboBox cbGender = (ComboBox)innerControl3.Children[innerControlIndex];

            result.Gender = (Gender)cbGender.SelectedIndex;
            if (dataAtt.InvalidGender)
            {
                result.Gender--;
            }

            return(result);
        }
Ejemplo n.º 4
0
        public void Calculates_Colspan_Correctly()
        {
            var target = new Grid
            {
                ColumnDefinitions = new ColumnDefinitions
                {
                    new ColumnDefinition(GridLength.Auto),
                    new ColumnDefinition(new GridLength(4, GridUnitType.Pixel)),
                    new ColumnDefinition(GridLength.Auto),
                },
                RowDefinitions = new RowDefinitions
                {
                    new RowDefinition(GridLength.Auto),
                    new RowDefinition(GridLength.Auto),
                },
                Children = new Controls
                {
                    new Border
                    {
                        Width = 100,
                        Height = 25,
                        [Grid.ColumnSpanProperty] = 3,
                    },
                    new Border
                    {
                        Width = 150,
                        Height = 25,
                        [Grid.RowProperty] = 1,
                    },
                    new Border
                    {
                        Width = 50,
                        Height = 25,
                        [Grid.RowProperty] = 1,
                        [Grid.ColumnProperty] = 2,
                    }
                },
            };

            target.Measure(Size.Infinity);

            // Issue #25 only appears after a second measure
            target.InvalidateMeasure();
            target.Measure(Size.Infinity);

            target.Arrange(new Rect(target.DesiredSize));

            Assert.Equal(new Size(204, 50), target.Bounds.Size);
            Assert.Equal(150d, target.ColumnDefinitions[0].ActualWidth);
            Assert.Equal(4d, target.ColumnDefinitions[1].ActualWidth);
            Assert.Equal(50d, target.ColumnDefinitions[2].ActualWidth);
            Assert.Equal(new Rect(52, 0, 100, 25), target.Children[0].Bounds);
            Assert.Equal(new Rect(0, 25, 150, 25), target.Children[1].Bounds);
            Assert.Equal(new Rect(154, 25, 50, 25), target.Children[2].Bounds);
        }
Ejemplo n.º 5
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IntRange member)
        {
            LoadLabelControl(control, name);

            RangeBorderAttribute rangeAtt = ReflectionExt.FindAttribute <RangeBorderAttribute>(attributes);
            int addMin = 0;
            int addMax = 0;

            if (rangeAtt != null)
            {
                rangeAtt.GetAddVals(out addMin, out addMax);
            }

            Avalonia.Controls.Grid innerPanel = getSharedRowPanel(4);
            innerPanel.ColumnDefinitions[0].Width = new GridLength(30);
            innerPanel.ColumnDefinitions[2].Width = new GridLength(30);

            TextBlock lblX = new TextBlock();

            lblX.Text = "Min:";
            lblX.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
            lblX.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
            innerPanel.Children.Add(lblX);
            lblX.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0);

            NumericUpDown nudValueX = new NumericUpDown();

            nudValueX.Margin  = new Thickness(4, 0, 0, 0);
            nudValueX.Minimum = Int32.MinValue;
            nudValueX.Maximum = Int32.MaxValue;
            nudValueX.Value   = member.Min + addMin;
            innerPanel.Children.Add(nudValueX);
            nudValueX.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1);

            TextBlock lblY = new TextBlock();

            lblY.Margin              = new Thickness(8, 0, 0, 0);
            lblY.Text                = "Max:";
            lblY.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
            lblY.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
            innerPanel.Children.Add(lblY);
            lblY.SetValue(Avalonia.Controls.Grid.ColumnProperty, 2);

            NumericUpDown nudValueY = new NumericUpDown();

            nudValueY.Margin  = new Thickness(4, 0, 0, 0);
            nudValueY.Minimum = Int32.MinValue;
            nudValueY.Maximum = Int32.MaxValue;
            nudValueY.Value   = member.Max + addMax;
            innerPanel.Children.Add(nudValueY);
            nudValueY.SetValue(Avalonia.Controls.Grid.ColumnProperty, 3);

            control.Children.Add(innerPanel);
        }
Ejemplo n.º 6
0
        public override Type SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            int controlIndex = 0;
            TypeConstraintAttribute dataAtt = ReflectionExt.FindAttribute <TypeConstraintAttribute>(attributes);
            Type baseType = dataAtt.BaseClass;

            Type[] children = baseType.GetAssignableTypes();

            Avalonia.Controls.Grid subGrid = (Avalonia.Controls.Grid)control.Children[controlIndex];
            ComboBox cbValue = (ComboBox)subGrid.Children[1];

            return(children[cbValue.SelectedIndex]);
        }
Ejemplo n.º 7
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, FlagType member)
        {
            StringTypeConstraintAttribute dataAtt = ReflectionExt.FindAttribute <StringTypeConstraintAttribute>(attributes);

            if (dataAtt != null)
            {
                Type baseType = dataAtt.BaseClass;

                Type[] children = baseType.GetAssignableTypes();

                Avalonia.Controls.Grid sharedRowPanel = getSharedRowPanel(2);

                TextBlock lblType = new TextBlock();
                lblType.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center;
                lblType.Text = name + ":";
                sharedRowPanel.Children.Add(lblType);
                sharedRowPanel.ColumnDefinitions[0].Width = new GridLength(30);
                lblType.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0);

                ComboBox cbValue = new ComboBox();
                cbValue.Margin = new Thickness(4, 0, 0, 0);
                sharedRowPanel.Children.Add(cbValue);
                cbValue.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1);

                List <string> items     = new List <string>();
                int           selection = 0;
                for (int ii = 0; ii < children.Length; ii++)
                {
                    Type childType = children[ii];
                    items.Add(childType.GetDisplayName());

                    if (childType == ((FlagType)member).FullType)
                    {
                        selection = ii;
                    }
                }

                var subject = new Subject <List <string> >();
                cbValue.Bind(ComboBox.ItemsProperty, subject);
                subject.OnNext(items);
                cbValue.SelectedIndex = selection;

                control.Children.Add(sharedRowPanel);
            }
            else
            {
                throw new InvalidOperationException("No constraints set for member!");
            }
        }
Ejemplo n.º 8
0
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            //Bind to keydown event
            this.KeyDown += MainWindow_KeyDown;

            // Store grid reference in global var
            _grid = this.FindControl <Avalonia.Controls.Grid>("cgolGrid");

            // Add columns and rows. Add Button controls to each cell.
            InitializeGrid(_cols, _rows);

            NewGame();
        }
Ejemplo n.º 9
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, Loc member)
        {
            LoadLabelControl(control, name);

            Avalonia.Controls.Grid innerPanel = getSharedRowPanel(4);

            TextBlock lblX = new TextBlock();

            lblX.Text = "X:";
            lblX.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
            lblX.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
            innerPanel.Children.Add(lblX);
            innerPanel.ColumnDefinitions[0].Width = new GridLength(30);
            lblX.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0);

            NumericUpDown nudValueX = new NumericUpDown();

            nudValueX.Margin  = new Thickness(4, 0, 0, 0);
            nudValueX.Minimum = Int32.MinValue;
            nudValueX.Maximum = Int32.MaxValue;
            nudValueX.Value   = member.X;
            innerPanel.Children.Add(nudValueX);
            nudValueX.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1);

            TextBlock lblY = new TextBlock();

            lblY.Margin              = new Thickness(8, 0, 0, 0);
            lblY.Text                = "Y:";
            lblY.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
            lblY.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
            innerPanel.Children.Add(lblY);
            innerPanel.ColumnDefinitions[2].Width = new GridLength(30);
            lblY.SetValue(Avalonia.Controls.Grid.ColumnProperty, 2);


            NumericUpDown nudValueY = new NumericUpDown();

            nudValueY.Margin  = new Thickness(4, 0, 0, 0);
            nudValueY.Minimum = Int32.MinValue;
            nudValueY.Maximum = Int32.MaxValue;
            nudValueY.Value   = member.Y;
            innerPanel.Children.Add(nudValueY);
            nudValueY.SetValue(Avalonia.Controls.Grid.ColumnProperty, 3);

            control.Children.Add(innerPanel);
        }
Ejemplo n.º 10
0
        public override SegLoc SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            int controlIndex = 0;

            controlIndex++;
            Avalonia.Controls.Grid innerControl = (Avalonia.Controls.Grid)control.Children[controlIndex];
            int innerControlIndex = 0;

            innerControlIndex++;
            NumericUpDown nudValueX = (NumericUpDown)innerControl.Children[innerControlIndex];

            innerControlIndex++;
            innerControlIndex++;
            NumericUpDown nudValueY = (NumericUpDown)innerControl.Children[innerControlIndex];

            return(new SegLoc((int)nudValueX.Value, (int)nudValueY.Value));
        }
Ejemplo n.º 11
0
        public override FlagType SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            int controlIndex = 0;
            StringTypeConstraintAttribute dataAtt = ReflectionExt.FindAttribute <StringTypeConstraintAttribute>(attributes);

            if (dataAtt != null)
            {
                Type baseType = dataAtt.BaseClass;

                Type[] children = baseType.GetAssignableTypes();

                Avalonia.Controls.Grid subGrid = (Avalonia.Controls.Grid)control.Children[controlIndex];
                ComboBox cbValue = (ComboBox)subGrid.Children[1];
                return(new FlagType(children[cbValue.SelectedIndex]));
            }
            else
            {
                throw new InvalidOperationException("No constraints set for member!");
            }
        }
Ejemplo n.º 12
0
        public override Enum SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            int controlIndex = 0;

            controlIndex++;

            Array enums = type.GetEnumValues();

            if (type.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0)
            {
                Avalonia.Controls.Grid innerControl = (Avalonia.Controls.Grid)control.Children[controlIndex];
                int innerControlIndex = 0;

                int pending = 0;
                for (int ii = 0; ii < enums.Length; ii++)
                {
                    int numeric = (int)enums.GetValue(ii);
                    int num1s   = 0;
                    for (int jj = 0; jj < 32; jj++)
                    {
                        if ((numeric & 0x1) == 1)
                        {
                            num1s++;
                        }
                        numeric = numeric >> 1;
                    }
                    if (num1s == 1)
                    {
                        CheckBox chkValue = (CheckBox)innerControl.Children[innerControlIndex];
                        pending |= ((chkValue.IsChecked.HasValue && chkValue.IsChecked.Value) ? 1 : 0) * (int)enums.GetValue(ii);
                        innerControlIndex++;
                    }
                }
                return((Enum)Enum.ToObject(type, pending));
            }
            else
            {
                ComboBox cbValue = (ComboBox)control.Children[controlIndex];
                return((Enum)Enum.ToObject(type, cbValue.SelectedIndex));
            }
        }
Ejemplo n.º 13
0
            public GridWalker(Grid grid, Segment[,] rowMatrix, Segment[,] colMatrix)
            {
                foreach (UIElement child in VisualTreeHelper.GetChildren(grid))
                {
                    bool starCol = false;
                    bool starRow = false;
                    bool autoCol = false;
                    bool autoRow = false;

                    int col = Math.Min(Grid.GetColumn(child), colMatrix.GetUpperBound(0));
                    int row = Math.Min(Grid.GetRow(child), rowMatrix.GetUpperBound(0));
                    int colspan = Math.Min(Grid.GetColumnSpan(child), colMatrix.GetUpperBound(0));
                    int rowspan = Math.Min(Grid.GetRowSpan(child), rowMatrix.GetUpperBound(0));

                    for (int r = row; r < row + rowspan; r++) 
                    {
                        starRow |= rowMatrix[r, r].Type == GridUnitType.Star;
                        autoRow |= rowMatrix[r, r].Type == GridUnitType.Auto;
                    }

                    for (int c = col; c < col + colspan; c++) 
                    {
                        starCol |= colMatrix[c, c].Type == GridUnitType.Star;
                        autoCol |= colMatrix[c, c].Type == GridUnitType.Auto;
                    }

                    this.HasAutoAuto |= autoRow && autoCol && !starRow && !starCol;
                    this.HasStarAuto |= starRow && autoCol;
                    this.HasAutoStar |= autoRow && starCol;
                }
            }
Ejemplo n.º 14
0
		protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
		{
			titleBar = e.NameScope.Find<Grid>("titlebar");
			minimiseButton = e.NameScope.Find<Button>("minimiseButton");
			restoreButton = e.NameScope.Find<Button>("restoreButton");
			closeButton = e.NameScope.Find<Button>("closeButton");
			icon = e.NameScope.Find<Image>("icon");

			topHorizontalGrip = e.NameScope.Find<Grid>("topHorizontalGrip");
			bottomHorizontalGrip = e.NameScope.Find<Grid>("bottomHorizontalGrip");
			leftVerticalGrip = e.NameScope.Find<Grid>("leftVerticalGrip");
			rightVerticalGrip = e.NameScope.Find<Grid>("rightVerticalGrip");

			topLeftGrip = e.NameScope.Find<Grid>("topLeftGrip");
			bottomLeftGrip = e.NameScope.Find<Grid>("bottomLeftGrip");
			topRightGrip = e.NameScope.Find<Grid>("topRightGrip");
			bottomRightGrip = e.NameScope.Find<Grid>("bottomRightGrip");

			minimiseButton.Click += (sender, ee) => { WindowState = WindowState.Minimized; };

			restoreButton.Click += (sender, ee) => { ToggleWindowState(); };

			titleBar.DoubleTapped += (sender, ee) => { ToggleWindowState(); };

			closeButton.Click += (sender, ee) => { Application.Current.Exit(); };

			icon.DoubleTapped += (sender, ee) => { Close(); };
		}
Ejemplo n.º 15
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, Color member)
        {
            LoadLabelControl(control, name);

            Avalonia.Controls.Grid innerPanel = getSharedRowPanel(8);

            TextBlock lblR = new TextBlock();

            lblR.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center;
            lblR.Text = "R:";
            lblR.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
            lblR.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
            innerPanel.Children.Add(lblR);
            innerPanel.ColumnDefinitions[0].Width = new GridLength(18);
            lblR.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0);

            NumericUpDown nudValueR = new NumericUpDown();

            nudValueR.Margin  = new Thickness(4, 0, 0, 0);
            nudValueR.Minimum = byte.MinValue;
            nudValueR.Maximum = byte.MaxValue;
            nudValueR.Value   = member.R;
            innerPanel.Children.Add(nudValueR);
            nudValueR.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1);

            TextBlock lblG = new TextBlock();

            lblG.Margin            = new Thickness(8, 0, 0, 0);
            lblG.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center;
            lblG.Text = "G:";
            lblG.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
            lblG.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
            innerPanel.Children.Add(lblG);
            innerPanel.ColumnDefinitions[2].Width = new GridLength(18);
            lblG.SetValue(Avalonia.Controls.Grid.ColumnProperty, 2);

            NumericUpDown nudValueG = new NumericUpDown();

            nudValueG.Margin  = new Thickness(4, 0, 0, 0);
            nudValueG.Minimum = byte.MinValue;
            nudValueG.Maximum = byte.MaxValue;
            nudValueG.Value   = member.G;
            innerPanel.Children.Add(nudValueG);
            nudValueG.SetValue(Avalonia.Controls.Grid.ColumnProperty, 3);

            TextBlock lblB = new TextBlock();

            lblB.Margin            = new Thickness(8, 0, 0, 0);
            lblB.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center;
            lblB.Text = "B:";
            lblB.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
            lblB.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
            innerPanel.Children.Add(lblB);
            innerPanel.ColumnDefinitions[4].Width = new GridLength(18);
            lblB.SetValue(Avalonia.Controls.Grid.ColumnProperty, 4);

            NumericUpDown nudValueB = new NumericUpDown();

            nudValueB.Margin  = new Thickness(4, 0, 0, 0);
            nudValueB.Minimum = byte.MinValue;
            nudValueB.Maximum = byte.MaxValue;
            nudValueB.Value   = member.B;
            innerPanel.Children.Add(nudValueB);
            nudValueB.SetValue(Avalonia.Controls.Grid.ColumnProperty, 5);

            TextBlock lblA = new TextBlock();

            lblA.Margin            = new Thickness(8, 0, 0, 0);
            lblA.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center;
            lblA.Text = "A:";
            lblA.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
            lblA.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
            innerPanel.Children.Add(lblA);
            innerPanel.ColumnDefinitions[6].Width = new GridLength(18);
            lblA.SetValue(Avalonia.Controls.Grid.ColumnProperty, 6);

            NumericUpDown nudValueA = new NumericUpDown();

            nudValueA.Margin  = new Thickness(4, 0, 0, 0);
            nudValueA.Minimum = byte.MinValue;
            nudValueA.Maximum = byte.MaxValue;
            nudValueA.Value   = member.A;
            innerPanel.Children.Add(nudValueA);
            nudValueA.SetValue(Avalonia.Controls.Grid.ColumnProperty, 7);

            control.Children.Add(innerPanel);
        }
Ejemplo n.º 16
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, MonsterID member)
        {
            LoadLabelControl(control, name);

            MonsterIDAttribute dataAtt = ReflectionExt.FindAttribute <MonsterIDAttribute>(attributes);

            {
                Avalonia.Controls.Grid innerPanel1 = getSharedRowPanel(2);

                TextBlock lblSpecies = new TextBlock();
                lblSpecies.Text = "Species:";
                lblSpecies.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
                lblSpecies.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
                innerPanel1.Children.Add(lblSpecies);
                innerPanel1.ColumnDefinitions[0].Width = new GridLength(46);
                lblSpecies.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0);

                ComboBox cbSpecies = new ComboBox();
                ComboBox cbForms   = new ComboBox();

                cbSpecies.VirtualizationMode = ItemVirtualizationMode.Simple;
                int            chosenSpecies = member.Species;
                EntryDataIndex nameIndex     = DataManager.Instance.DataIndices[DataManager.DataType.Monster];

                List <string> species = new List <string>();
                List <string> forms   = new List <string>();

                if (dataAtt.InvalidSpecies)
                {
                    species.Add("---");
                    chosenSpecies++;
                }

                for (int ii = 0; ii < nameIndex.Count; ii++)
                {
                    species.Add(ii.ToString() + ": " + nameIndex.Entries[ii].GetLocalString(false));
                }

                var speciesSubject = new Subject <List <string> >();
                var formSubject    = new Subject <List <string> >();

                cbSpecies.Bind(ComboBox.ItemsProperty, speciesSubject);
                speciesSubject.OnNext(species);
                cbSpecies.SelectedIndex     = Math.Min(Math.Max(0, chosenSpecies), species.Count - 1);
                cbSpecies.SelectionChanged += (object sender, SelectionChangedEventArgs e) =>
                {
                    loadForms(dataAtt, cbSpecies.SelectedIndex, forms);
                    cbForms.SelectedIndex = -1;
                    cbForms.SelectedIndex = Math.Min(Math.Max(0, cbForms.SelectedIndex), forms.Count - 1);
                    formSubject.OnNext(forms);
                };

                innerPanel1.Children.Add(cbSpecies);
                cbSpecies.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1);
                control.Children.Add(innerPanel1);


                Avalonia.Controls.Grid innerPanel2 = getSharedRowPanel(2);

                TextBlock lblForm = new TextBlock();
                lblForm.Margin              = new Thickness(8, 0, 0, 0);
                lblForm.Text                = "Form:";
                lblForm.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
                lblForm.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
                innerPanel2.Children.Add(lblForm);
                innerPanel2.ColumnDefinitions[0].Width = new GridLength(46);
                lblForm.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0);


                cbForms.VirtualizationMode = ItemVirtualizationMode.Simple;
                int chosenForm = member.Form;

                loadForms(dataAtt, member.Species, forms);

                if (dataAtt.InvalidForm)
                {
                    chosenForm++;
                }

                cbForms.Bind(ComboBox.ItemsProperty, formSubject);
                formSubject.OnNext(forms);
                cbForms.SelectedIndex = Math.Min(Math.Max(0, chosenForm), forms.Count - 1);
                innerPanel2.Children.Add(cbForms);
                cbForms.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1);
                control.Children.Add(innerPanel2);
            }

            Avalonia.Controls.Grid innerPanel3 = getSharedRowPanel(4);

            {
                TextBlock lblSkin = new TextBlock();
                lblSkin.Margin              = new Thickness(8, 0, 0, 0);
                lblSkin.Text                = "Skin:";
                lblSkin.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
                lblSkin.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
                innerPanel3.Children.Add(lblSkin);
                innerPanel3.ColumnDefinitions[0].Width = new GridLength(46);
                lblSkin.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0);

                ComboBox cbSkin = new ComboBox();
                cbSkin.VirtualizationMode = ItemVirtualizationMode.Simple;
                int            chosenIndex = member.Skin;
                EntryDataIndex nameIndex   = DataManager.Instance.DataIndices[DataManager.DataType.Skin];

                List <string> items = new List <string>();
                if (dataAtt.InvalidSkin)
                {
                    items.Add("---");
                    chosenIndex++;
                }

                for (int ii = 0; ii < nameIndex.Count; ii++)
                {
                    items.Add(ii.ToString() + ": " + nameIndex.Entries[ii].GetLocalString(false));
                }

                var subject = new Subject <List <string> >();
                cbSkin.Bind(ComboBox.ItemsProperty, subject);
                subject.OnNext(items);
                cbSkin.SelectedIndex = Math.Min(Math.Max(0, chosenIndex), items.Count - 1);
                innerPanel3.Children.Add(cbSkin);
                cbSkin.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1);
            }

            {
                TextBlock lblGender = new TextBlock();
                lblGender.Margin              = new Thickness(8, 0, 0, 0);
                lblGender.Text                = "Gender:";
                lblGender.VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center;
                lblGender.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right;
                innerPanel3.Children.Add(lblGender);
                innerPanel3.ColumnDefinitions[2].Width = new GridLength(46);
                lblGender.SetValue(Avalonia.Controls.Grid.ColumnProperty, 2);

                ComboBox cbGender = new ComboBox();
                cbGender.VirtualizationMode = ItemVirtualizationMode.Simple;
                int chosenIndex = (int)member.Gender;

                List <string> items = new List <string>();
                if (dataAtt.InvalidGender)
                {
                    items.Add("---");
                    chosenIndex++;
                }

                for (int ii = 0; ii <= (int)Gender.Female; ii++)
                {
                    items.Add(((Gender)ii).ToLocal());
                }

                var subject = new Subject <List <string> >();
                cbGender.Bind(ComboBox.ItemsProperty, subject);
                subject.OnNext(items);
                cbGender.SelectedIndex = Math.Min(Math.Max(0, chosenIndex), items.Count - 1);
                innerPanel3.Children.Add(cbGender);
                cbGender.SetValue(Avalonia.Controls.Grid.ColumnProperty, 3);
            }

            control.Children.Add(innerPanel3);
        }
Ejemplo n.º 17
0
 protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
 {
     base.OnAttachedToVisualTree(e);
     _grid = this.GetVisualParent<Grid>();
     
     if (Orientation == Orientation.Vertical)
     {
         Cursor = new Cursor(StandardCursorType.SizeWestEast);
         var col = GetValue(Grid.ColumnProperty);
         _definitions = _grid.ColumnDefinitions.Cast<DefinitionBase>().ToList();
         _prevDefinition = _definitions[col - 1];
         _nextDefinition = _definitions[col + 1];
     }
     else
     {
         Cursor = new Cursor(StandardCursorType.SizeNorthSouth);
         var row = GetValue(Grid.RowProperty);
         _definitions = _grid.RowDefinitions.Cast<DefinitionBase>().ToList();
         _prevDefinition = _definitions[row - 1];
         _nextDefinition = _definitions[row + 1];
     }
 }
Ejemplo n.º 18
0
            public GridWalker(Grid grid, Segment[,] rowMatrix, Segment[,] colMatrix)
            {
                int rowMatrixDim = rowMatrix.GetLength(0);
                int colMatrixDim = colMatrix.GetLength(0);

                foreach (Control child in grid.Children)
                {
                    bool starCol = false;
                    bool starRow = false;
                    bool autoCol = false;
                    bool autoRow = false;

                    int col = Math.Min(GetColumn(child), colMatrixDim - 1);
                    int row = Math.Min(GetRow(child), rowMatrixDim - 1);
                    int colspan = Math.Min(GetColumnSpan(child), colMatrixDim - 1);
                    int rowspan = Math.Min(GetRowSpan(child), rowMatrixDim - 1);

                    for (int r = row; r < row + rowspan; r++)
                    {
                        starRow |= rowMatrix[r, r].Type == GridUnitType.Star;
                        autoRow |= rowMatrix[r, r].Type == GridUnitType.Auto;
                    }

                    for (int c = col; c < col + colspan; c++)
                    {
                        starCol |= colMatrix[c, c].Type == GridUnitType.Star;
                        autoCol |= colMatrix[c, c].Type == GridUnitType.Auto;
                    }

                    HasAutoAuto |= autoRow && autoCol && !starRow && !starCol;
                    HasStarAuto |= starRow && autoCol;
                    HasAutoStar |= autoRow && starCol;
                }
            }
Ejemplo n.º 19
0
        protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
        {
            base.OnAttachedToVisualTree(e);
            _grid = this.GetVisualParent<Grid>();

            _orientation = DetectOrientation();

            int defenitionIndex; //row or col
            if (_orientation == Orientation.Vertical)
            {
                Cursor = new Cursor(StandardCursorType.SizeWestEast);
                _definitions = _grid.ColumnDefinitions.Cast<DefinitionBase>().ToList();
                defenitionIndex = GetValue(Grid.ColumnProperty);
                PseudoClasses.Add(":vertical");
            }
            else
            {
                Cursor = new Cursor(StandardCursorType.SizeNorthSouth);
                defenitionIndex = GetValue(Grid.RowProperty);
                _definitions = _grid.RowDefinitions.Cast<DefinitionBase>().ToList();
                PseudoClasses.Add(":horizontal");
            }

            if (defenitionIndex > 0)
                _prevDefinition = _definitions[defenitionIndex - 1];

            if (defenitionIndex < _definitions.Count - 1)
                _nextDefinition = _definitions[defenitionIndex + 1];
        }
Ejemplo n.º 20
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, Enum member)
        {
            LoadLabelControl(control, name);

            Array enums = type.GetEnumValues();

            if (type.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0)
            {
                List <CheckBox> checkboxes = new List <CheckBox>();
                for (int ii = 0; ii < enums.Length; ii++)
                {
                    int numeric = (int)enums.GetValue(ii);
                    int num1s   = 0;
                    for (int jj = 0; jj < 32; jj++)
                    {
                        if ((numeric & 0x1) == 1)
                        {
                            num1s++;
                        }
                        numeric = numeric >> 1;
                    }
                    if (num1s == 1)
                    {
                        CheckBox chkValue = new CheckBox();
                        if (checkboxes.Count > 0)
                        {
                            chkValue.Margin = new Thickness(4, 0, 0, 0);
                        }
                        chkValue.Content   = enums.GetValue(ii).ToString();
                        chkValue.IsChecked = member.HasFlag((Enum)enums.GetValue(ii));
                        checkboxes.Add(chkValue);
                    }
                }

                Avalonia.Controls.Grid innerPanel = getSharedRowPanel(checkboxes.Count);
                for (int ii = 0; ii < checkboxes.Count; ii++)
                {
                    innerPanel.Children.Add(checkboxes[ii]);
                    checkboxes[ii].SetValue(Avalonia.Controls.Grid.ColumnProperty, ii);
                }

                control.Children.Add(innerPanel);
            }
            else
            {
                //for enums, use a combobox
                ComboBox cbValue = new ComboBox();
                cbValue.VirtualizationMode = ItemVirtualizationMode.Simple;

                List <string> items     = new List <string>();
                int           selection = 0;
                for (int ii = 0; ii < enums.Length; ii++)
                {
                    items.Add(enums.GetValue(ii).ToString());
                    if (Enum.Equals(enums.GetValue(ii), member))
                    {
                        selection = ii;
                    }
                }

                var subject = new Subject <List <string> >();
                cbValue.Bind(ComboBox.ItemsProperty, subject);
                subject.OnNext(items);
                cbValue.SelectedIndex = selection;
                control.Children.Add(cbValue);
            }
        }