private void AddItem(ShipDNA dna, string filename) { Grid grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1d, GridUnitType.Auto) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(4d) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1d, GridUnitType.Star) }); Icon3D icon = new Icon3D(dna.ShipName, dna, _world); icon.ShowName = false; Grid.SetColumn(icon, 0); grid.Children.Add(icon); icon.Width = 60d; // this has logic to keep itself square StackPanel panel = new StackPanel(); panel.HorizontalAlignment = HorizontalAlignment.Left; panel.VerticalAlignment = VerticalAlignment.Center; Label label = new Label(); label.Content = dna.ShipName; label.FontSize = 14; label.FontWeight = FontWeights.DemiBold; label.HorizontalAlignment = HorizontalAlignment.Left; label.VerticalAlignment = VerticalAlignment.Center; panel.Children.Add(label); if (!string.IsNullOrEmpty(filename)) { label = new Label(); label.Content = filename; label.FontSize = 10; label.Foreground = new SolidColorBrush(Color.FromRgb(96, 96, 96)); label.HorizontalAlignment = HorizontalAlignment.Left; label.VerticalAlignment = VerticalAlignment.Center; panel.Children.Add(label); } Grid.SetColumn(panel, 2); grid.Children.Add(panel); lstItems.Items.Add(grid); _currentDNA.Add(dna); }
private static Icon3D BuildIcon(Inventory inventory, World world, EditorOptions options, FrameworkElement parent) { Icon3D retVal = null; if (inventory.Ship != null) { retVal = new Icon3D("", inventory.Ship, world); // don't want to autorotate the ship icons. This is a 2D game, and the ships will always be viewed from the top } else if (inventory.Part != null) { retVal = new Icon3D(inventory.Part, options) { AutoRotateOnMouseHover = true, AutoRotateParent = parent, }; } else if (inventory.Mineral != null) { retVal = new Icon3D(inventory.Mineral.MineralType) { AutoRotateOnMouseHover = true, AutoRotateParent = parent, }; } if (retVal != null) { retVal.ShowName = false; retVal.ShowBorder = false; } return retVal; }
protected static UIElement GetVisual2D(string text, string description, EditorOptions options, PartToolItemBase partBase) { Brush standardBack = new SolidColorBrush(options.EditorColors.PartVisual_BackgroundColor); Brush hoverBack = new SolidColorBrush(options.EditorColors.PartVisual_BackgroundColor_Hover); // Border Border retVal = new Border() { Background = standardBack, // this at least needs to be transparent for drag/drop to work BorderBrush = new SolidColorBrush(options.EditorColors.PartVisual_BorderColor), BorderThickness = new Thickness(1d), CornerRadius = new CornerRadius(7d), Margin = new Thickness(3d), }; retVal.MouseEnter += (s, e) => { retVal.Background = hoverBack; }; retVal.MouseLeave += (s, e) => { retVal.Background = standardBack; }; // Grid Grid grid = new Grid() { Margin = new Thickness(2, 1, 6, 1), }; grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(4, GridUnitType.Pixel) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); retVal.Child = grid; // Icon Icon3D icon = new Icon3D(partBase.GetNewDesignPart().GetDNA(), options) { ShowName = false, ShowBorder = false, Width = 50, Height = 50, Margin = new Thickness(4), AutoRotateOnMouseHover = true, AutoRotateParent = retVal, }; Grid.SetColumn(icon, 0); grid.Children.Add(icon); // Text TextBlock textblock = new TextBlock() { Text = text, ToolTip = description, Foreground = new SolidColorBrush(options.EditorColors.PartVisual_TextColor), FontSize = 11d, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, TextWrapping = TextWrapping.Wrap, }; Grid.SetColumn(textblock, 2); grid.Children.Add(textblock); return retVal; }
private void Player_ShipChanged(object sender, ShipChangedArgs e) { try { if (_player.Ship == null) { pnlPlayerIcon.Content = null; } else { Icon3D icon = new Icon3D("", _player.Ship.GetNewDNA(), _world); icon.ShowName = false; icon.ShowBorder = false; pnlPlayerIcon.Content = icon; } GenerateRefillButtons(); ShowShipCargo(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), TITLE, MessageBoxButton.OK, MessageBoxImage.Error); } }
private void RemoveIconVisual(Icon3D icon) { icon.MouseDown -= new MouseButtonEventHandler(Icon_MouseDown); grdIcons.Children.Remove(icon); _icons.Remove(icon); }
private void AddIconVisual(string name, ShipDNA dna, World world) { Icon3D icon = new Icon3D(name, dna, world); icon.VerticalAlignment = VerticalAlignment.Top; icon.MouseDown += new MouseButtonEventHandler(Icon_MouseDown); _icons.Add(icon); grdIcons.Children.Add(icon); }