Example #1
0
        public void Initialize()
        {
            for (int i = 0; i < 7; i++)
            {
                HeightMap.RowDefinitions.Add(new RowDefinition());
            }
            for (int i = 0; i < 9; i++)
            {
                HeightMap.ColumnDefinitions.Add(new ColumnDefinition());
            }

            for (int i = 0; i < 9; i++)
            {
                float       height            = i == 0 ? TileUtils.VoidDefault : -1.25f + i * 0.25f;
                RadioButton heightRadioButton = height == TileUtils.VoidDefault
                                        ? new RadioButton {
                    Margin = new Thickness(), Background = new SolidColorBrush(Color.FromRgb(0, 0, 0)), ToolTip = new TextBlock {
                        Text = "Void", FontWeight = FontWeights.Bold
                    }, Tag = height, IsChecked = true
                }
                                        : new RadioButton {
                    Margin = new Thickness(), Background = new SolidColorBrush(TileUtils.GetColorFromHeight(height)), ToolTip = height.ToString("0.##"), Tag = height
                };
                heightRadioButton.Checked += (sender, e) =>
                {
                    RadioButton r = sender as RadioButton;
                    foreach (RadioButton rb in tileActionRadioButtons)
                    {
                        if (rb != r)
                        {
                            rb.IsChecked = false;
                        }
                    }
                    tileAction          = TileAction.Height;
                    heightSelectorValue = float.Parse(r.Tag.ToString());
                };

                Grid.SetRow(heightRadioButton, 0);
                Grid.SetColumn(heightRadioButton, i);
                HeightMap.Children.Add(heightRadioButton);

                tileActionRadioButtons.Add(heightRadioButton);
            }

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    float       height            = i * 9 + j + 1;
                    RadioButton heightRadioButton = new RadioButton {
                        Margin = new Thickness(), Background = new SolidColorBrush(TileUtils.GetColorFromHeight(height)), ToolTip = height.ToString(), Tag = height
                    };
                    heightRadioButton.Checked += (sender, e) =>
                    {
                        RadioButton r = sender as RadioButton;
                        foreach (RadioButton rb in tileActionRadioButtons)
                        {
                            if (rb != r)
                            {
                                rb.IsChecked = false;
                            }
                        }
                        tileAction          = TileAction.Height;
                        heightSelectorValue = float.Parse(r.Tag.ToString());
                    };

                    Grid.SetRow(heightRadioButton, i + 1);
                    Grid.SetColumn(heightRadioButton, j);
                    HeightMap.Children.Add(heightRadioButton);

                    tileActionRadioButtons.Add(heightRadioButton);
                }
            }

            foreach (TileAction tileAction in (TileAction[])Enum.GetValues(typeof(TileAction)))
            {
                if (tileAction == TileAction.Height)
                {
                    continue;
                }

                RadioButton radioButton = new RadioButton
                {
                    Content = new Image {
                        Source = new BitmapImage(ContentUtils.MakeUri(System.IO.Path.Combine("Content", "Images", "Buttons", $"ArenaTilesAction{tileAction}.png")))
                    },
                    ToolTip   = tileAction.ToUserFriendlyString(),
                    IsChecked = tileAction == 0
                };
                radioButton.Checked += (sender, e) =>
                {
                    RadioButton r = sender as RadioButton;
                    foreach (RadioButton rb in tileActionRadioButtons)
                    {
                        if (rb != r)
                        {
                            rb.IsChecked = false;
                        }
                    }
                    this.tileAction = tileAction;
                };

                tileActionRadioButtons.Add(radioButton);
                TileActionsStackPanel.Children.Add(radioButton);
            }

            foreach (TileSelection tileSelection in (TileSelection[])Enum.GetValues(typeof(TileSelection)))
            {
                RadioButton radioButton = new RadioButton
                {
                    Content = new Image {
                        Source = new BitmapImage(ContentUtils.MakeUri(System.IO.Path.Combine("Content", "Images", "Buttons", $"ArenaTilesSelection{tileSelection}.png")))
                    },
                    ToolTip   = tileSelection.ToUserFriendlyString(),
                    IsChecked = tileSelection == 0
                };
                radioButton.Checked += (sender, e) =>
                {
                    this.tileSelection = tileSelection;
                };

                tileSelectionRadioButtons.Add(radioButton);
                TileSelectionsStackPanel.Children.Add(radioButton);
            }

            foreach (Type type in ArenaPresetHandler.Instance.PresetTypes)
            {
                string typeName = type.Name.ToString();

                ComboBoxItem item = new ComboBoxItem()
                {
                    Content = typeName.ToUserFriendlyString(),
                    Tag     = typeName
                };
                if (typeName == "Default")
                {
                    ComboBoxArenaPreset.SelectedItem = item;
                }

                ComboBoxArenaPreset.Items.Add(item);
            }

            for (int i = 0; i < Spawnset.ArenaWidth; i++)
            {
                for (int j = 0; j < Spawnset.ArenaHeight; j++)
                {
                    Rectangle tileRectangle = new Rectangle
                    {
                        Width  = TileUtils.TileSize,
                        Height = TileUtils.TileSize
                    };
                    Canvas.SetLeft(tileRectangle, i * TileUtils.TileSize);
                    Canvas.SetTop(tileRectangle, j * TileUtils.TileSize);
                    ArenaTiles.Children.Add(tileRectangle);
                    tileElements[i, j] = tileRectangle;

                    UpdateTile(new ArenaCoord(i, j));
                }
            }

            CursorRectangle.Width  = TileUtils.TileSize;
            CursorRectangle.Height = TileUtils.TileSize;
            CursorRectangle.Stroke = new SolidColorBrush(Color.FromArgb(128, 255, 255, 255));

            SetSettingTextBoxes();
        }