Example #1
0
        private void VesselFlagExchange_Click(object sender, RoutedEventArgs e)
        {
            KmlVessel vessel = ((sender as MenuItem).DataContext as KmlVessel);

            if (vessel.Flags.Count > 0)
            {
                string oldFlag    = vessel.Flags[0];
                string otherFlags = "";
                foreach (string flag in vessel.Flags)
                {
                    if (flag.ToLower() != oldFlag.ToLower())
                    {
                        otherFlags += "\n - " + flag;
                    }
                }
                if (otherFlags.Length > 0)
                {
                    otherFlags = "\nThese other flags will not be changed" + otherFlags;
                }
                string newFlag;
                if (DlgInput.Show("All parts with flag '" + oldFlag + "' will be changed." + otherFlags + "\n\nEnter the new flag:", "Change vessel flag", Icons.VesselFlag, oldFlag, out newFlag))
                {
                    vessel.FlagExchange(oldFlag, newFlag);
                }
            }
        }
Example #2
0
        private Image GenerateImage(KmlVessel vessel)
        {
            Image image = new Image();

            image.Height = 48;
            if (vessel.Type.ToLower() == "base")
            {
                image.Source = Icons.VesselBase.Source;
            }
            else if (vessel.Type.ToLower() == "debris")
            {
                image.Source = Icons.VesselDebris.Source;
            }
            else if (vessel.Type.ToLower() == "eva")
            {
                image.Source = Icons.VesselEVA.Source;
            }
            else if (vessel.Type.ToLower() == "flag")
            {
                image.Source = Icons.VesselFlag.Source;
            }
            else if (vessel.Type.ToLower() == "lander")
            {
                image.Source = Icons.VesselLander.Source;
            }
            else if (vessel.Type.ToLower() == "plane")
            {
                image.Source = Icons.VesselPlane.Source;
            }
            else if (vessel.Type.ToLower() == "probe")
            {
                image.Source = Icons.VesselProbe.Source;
            }
            else if (vessel.Type.ToLower() == "relay")
            {
                image.Source = Icons.VesselRelay.Source;
            }
            else if (vessel.Type.ToLower() == "rover")
            {
                image.Source = Icons.VesselRover.Source;
            }
            else if (vessel.Type.ToLower() == "spaceobject")
            {
                image.Source = Icons.VesselSpaceObject.Source;
            }
            else if (vessel.Type.ToLower() == "station")
            {
                image.Source = Icons.VesselStation.Source;
            }
            else
            {
                image.Source = Icons.Vessel.Source;
            }
            image.Margin = new Thickness(0, 0, 3, 0);

            return(image);
        }
Example #3
0
        private TextBlock GenerateText(KmlVessel vessel)
        {
            TextBlock text = new TextBlock();

            text.Inlines.Add(new Bold(new Run(vessel.Name)));
            text.Inlines.Add(new Run("\n" + vessel.Type + "\n" + vessel.Situation));
            text.Margin = new Thickness(3, 0, 0, 0);
            return(text);
        }
Example #4
0
        private static List <KmlItem> ParseFile(System.IO.StreamReader file, KmlNode parent)
        {
            List <KmlItem> list = new List <KmlItem>();

            string line;

            while ((line = file.ReadLine()) != null)
            {
                KmlItem newItem = ParseLine(line);
                if (newItem is KmlBegin)
                {
                    KmlItem lastItem;
                    int     l = list.Count - 1;
                    if (l < 0)
                    {
                        lastItem = new KmlItem("");
                    }
                    else
                    {
                        lastItem = list[l];
                        list.RemoveAt(l);
                    }
                    KmlNode newNode = new KmlNode(lastItem, parent);
                    if (newNode.Tag.ToLower() == "vessel")
                    {
                        newNode = new KmlVessel(newNode);
                    }
                    else if (newNode.Tag.ToLower() == "kerbal")
                    {
                        newNode = new KmlKerbal(newNode);
                    }
                    else if (newNode.Tag.ToLower() == "part")
                    {
                        newNode = new KmlPart(newNode);
                    }
                    else if (newNode.Tag.ToLower() == "resource")
                    {
                        newNode = new KmlResource(newNode);
                    }
                    list.Add(newNode);
                    newNode.AddRange(ParseFile(file, newNode));
                }
                else if (newItem is KmlEnd)
                {
                    Identify(list);
                    return(list);
                }
                else
                {
                    list.Add(newItem);
                }
            }

            Identify(list);
            return(list);
        }
Example #5
0
        /// <summary>
        /// Creates a GuiVesselsNode containing the given DataVessel.
        /// To have nice icons in the tree, a GuiIcons can be
        /// provided.
        /// </summary>
        /// <param name="dataVessel">The KmlVessel to contain</param>
        public GuiVesselsNode(KmlVessel dataVessel)
        {
            DataVessel = dataVessel;

            AssignTemplate();
            BuildContextMenu();

            // Get notified when KmlNode ToString() changes
            DataVessel.ToStringChanged += DataVessel_ToStringChanged;
        }
Example #6
0
        private void VesselToLKO_Click(object sender, RoutedEventArgs e)
        {
            KmlVessel vessel = (sender as MenuItem).DataContext as KmlVessel;

            if (DlgConfirmation.Show("Do you really want to send " + vessel.Name + " to low kerbin orbit?\n\n" +
                                     "- The vessel situation and orbit data will be changed\n" +
                                     "- Orbit height will be 80km\n" +
                                     "- Do not use when your kerbin is scaled bigger (RSS)",
                                     "Send vessel to LKO", (sender as MenuItem).Icon as Image))
            {
                vessel.SendToKerbinOrbit(80000.0);
            }
        }
Example #7
0
 /// <summary>
 /// After all items are loaded, each items Finalize is called.
 /// The roots list will contain all loaded items in KML tree structure.
 /// Each item can then check for other items to get further properties.
 /// </summary>
 /// <param name="roots">The loaded root items list</param>
 protected override void Finalize(List <KmlItem> roots)
 {
     base.Finalize(roots);
     if (Origin == KerbalOrigin.Roster)
     {
         string[] tags            = { "game", "flightstate" };
         KmlNode  flightStateNode = GetNodeFromDeep(roots, tags);
         if (flightStateNode != null)
         {
             foreach (KmlNode vesselNode in flightStateNode.Children)
             {
                 if (vesselNode is KmlVessel)
                 {
                     KmlVessel vessel = (KmlVessel)vesselNode;
                     foreach (KmlPart part in vessel.Parts)
                     {
                         foreach (KmlAttrib attrib in part.Attribs)
                         {
                             if (attrib.Name.ToLower() == "crew" && attrib.Value.ToLower() == Name.ToLower())
                             {
                                 if (AssignedCrewAttrib == null)
                                 {
                                     AssignedVessel      = vessel;
                                     AssignedPart        = part;
                                     AssignedCrewAttrib  = attrib;
                                     attrib.CanBeDeleted = false;
                                 }
                                 else
                                 {
                                     Syntax.Warning(attrib, "Kerbal is listed in multiple vessel part's crew. Kerbal: " + Name +
                                                    "Assigned vessel: " + AssignedVessel.Name + ", Assigned part: " + AssignedPart +
                                                    ", Unused Vessel: " + vessel.Name + ", Unused part: " + part);
                                 }
                                 if (State.ToLower() != "assigned")
                                 {
                                     Syntax.Warning(this, "Kerbal is listed in a vessels crew list, but state is not 'Assigned'. Vessel: " + vessel.Name + ", Part: " + part);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (AssignedCrewAttrib == null && State.ToLower() == "assigned" && Type.ToLower() != "unowned")
         {
             Syntax.Warning(this, "Kerbal state is 'Assigned' but not listed in any vessels crew list");
         }
     }
 }
Example #8
0
        private void VesselsChanged(object sender, RoutedEventArgs e)
        {
            // Vessel was added or deleted
            KmlVessel oldSelected = null;

            if (VesselsList.SelectedItem is GuiVesselsNode)
            {
                oldSelected = (VesselsList.SelectedItem as GuiVesselsNode).DataVessel;
            }
            Load(Master.TreeManager);
            if (oldSelected != null)
            {
                Select(oldSelected);
            }
        }
Example #9
0
        private Image GenerateFlag(KmlVessel vessel)
        {
            Image image = new Image();

            image.Source = new BitmapImage(new Uri("pack://application:,,,/KML;component/Images/DummyFlag.png"));
            image.Height = 40;
            image.Width  = image.Height * 1.6;
            image.Margin = new Thickness(0, 0, 3, 0);
            if (vessel.RootPart != null && vessel.RootPart.Flag.Length > 0)
            {
                string flag = vessel.RootPart.Flag;
                flag = flag.Replace('/', '\\');
                flag = Path.Combine(GuiTabsManager.GetCurrent().FileGamedataDirectory, flag);

                flag = Path.ChangeExtension(flag, ".png");
                if (!File.Exists(flag))
                {
                    flag = Path.ChangeExtension(flag, ".dds");
                    if (!File.Exists(flag))
                    {
                        // keep dummy image
                        return(image);
                    }
                    else
                    {
                        // *.dds files are drawn vertically flipped
                        image.RenderTransform = new ScaleTransform(1.0, -1.0, 0.0, image.Height / 2.0);
                    }
                }
                // flag points to existing file here
                try
                {
                    image.Source = (new ImageSourceConverter()).ConvertFromString(flag) as ImageSource;
                }
                catch
                {
                    // there could be any problem loading the flag, ignore it and stay with dummy
                    // one problem so far: Win 10 can load *.dds, Win 7 can't
                }
            }

            return(image);
        }
Example #10
0
        /// <summary>
        /// Generates a nice informative string to be used in display for this part.
        /// It will contain the tag, the index in parent's part-list, a root marker and the name.
        /// </summary>
        /// <returns>A string to display this node</returns>
        public override string ToString()
        {
            string s = "";

            if (Parent is KmlVessel)
            {
                KmlVessel p = (KmlVessel)Parent;
                s += " [" + p.Parts.IndexOf(this).ToString();
                if (p.RootPart == this)
                {
                    s += ", root";
                }
                s += "]";
            }
            if (Name.Length > 0)
            {
                s += " (" + Name + ")";
            }
            return(Tag + s);
        }
Example #11
0
        /// <summary>
        /// Creates a GuiVesselsNode containing the given DataVessel.
        /// To have nice icons in the tree, a GuiIcons can be
        /// provided.
        /// </summary>
        /// <param name="dataVessel">The KmlVessel to contain</param>
        public GuiVesselsNode(KmlVessel dataVessel)
        {
            DataVessel = dataVessel;

            AssignTemplate();
            BuildContextMenu();

            // Get notified when KmlNode ToString() changes
            DataVessel.ToStringChanged += DataVessel_ToStringChanged;

            // Get notified when flag changes
            if (DataVessel.RootPart != null)
            {
                KmlAttrib flag = DataVessel.RootPart.GetAttrib("flag");
                if (flag != null)
                {
                    flag.AttribValueChanged += DataVessel_FlagChanged;
                }
            }
        }
Example #12
0
        private static KmlNode ParseNode(KmlItem item)
        {
            KmlNode newNode = new KmlNode(item);

            if (newNode.Tag.ToLower() == "vessel")
            {
                newNode = new KmlVessel(newNode);
            }
            else if (newNode.Tag.ToLower() == "kerbal")
            {
                newNode = new KmlKerbal(newNode);
            }
            else if (newNode.Tag.ToLower() == "part")
            {
                newNode = new KmlPart(newNode);
            }
            else if (newNode.Tag.ToLower() == "resource")
            {
                newNode = new KmlResource(newNode);
            }
            return(newNode);
        }
Example #13
0
        /// <summary>
        /// Draws all parts of the given KmlVessel.
        /// </summary>
        /// <param name="vessel">The KmlVessel to read all parts from</param>
        public void DrawPartStructure(KmlVessel vessel)
        {
            VesselsDetails.Children.Clear();
            InitGrid();
            if (vessel != null)
            {
                foreach (KmlPart part in vessel.Parts)
                {
                    part.Visited = false;
                }

                IntPair rootKoords = CalcKoords(new IntPair(0, 0), 0, 0);
                GuiVesselsPartGraphNode rootNode = DrawPart(vessel.RootPart, rootKoords);
                DrawConnectedParts(rootNode, rootKoords);

                // Draw all parts, that are not drawn yet
                foreach (KmlPart part in vessel.Parts)
                {
                    if (!part.Visited)
                    {
                        IntPair koords = CalcKoords(new IntPair(0, PartGridMaxY), 0, PartGridMaxY + CountTop(part, vessel.RootPart));
                        GuiVesselsPartGraphNode partNode = DrawPart(part, koords);
                        DrawConnectedParts(partNode, koords);
                    }
                }

                double minX = 0;
                double minY = 0;
                double maxX = 0;
                double maxY = 0;
                CalcMinMax(out minX, out minY, out maxX, out maxY);

                VesselsDetails.Width           = maxX - minX + ElementWidth * 2;
                VesselsDetails.Height          = maxY - minY + ElementHeight;
                VesselsDetails.RenderTransform = new TranslateTransform(-minX, -minY);
            }
        }
Example #14
0
        private void VesselsChanged(object sender, RoutedEventArgs e)
        {
            // Vessel was added or deleted
            KmlVessel oldSelected       = null;
            KmlVessel alternateSelected = null;

            if (VesselsList.SelectedItem is GuiVesselsNode)
            {
                oldSelected = (VesselsList.SelectedItem as GuiVesselsNode).DataVessel;
                int i = VesselsList.SelectedIndex + 1;
                while (i < VesselsList.Items.Count && !(VesselsList.Items[i] as GuiVesselsNode).IsVisible)
                {
                    i++;
                }
                if (i >= VesselsList.Items.Count)
                {
                    i = VesselsList.SelectedIndex - 1;
                    while (i >= 0 && !(VesselsList.Items[i] as GuiVesselsNode).IsVisible)
                    {
                        i--;
                    }
                }
                if (i >= 0)
                {
                    alternateSelected = (VesselsList.Items[i] as GuiVesselsNode).DataVessel;
                }
            }
            Load(Master.TreeManager);
            if (oldSelected != null)
            {
                if (!Select(oldSelected) && alternateSelected != null)
                {
                    Select(alternateSelected);
                }
            }
        }
Example #15
0
 /// <summary>
 /// Selects the given item in the tree view or in the list, the item fits into.
 /// If called when tree is active it will switch to the list when possible.
 /// Otherwise when list is active it will switch to the tree view.
 /// </summary>
 /// <param name="item">The KmlItem to select</param>
 /// <returns>Whether item was found or not</returns>
 public bool Select(KmlItem item)
 {
     if (item is KmlVessel)
     {
         KmlVessel vessel = (KmlVessel)item;
         if (Tabs.SelectedItem == TreeTab && vessel.Origin == KmlVessel.VesselOrigin.Flightstate)
         {
             Tabs.SelectedItem = VesselsTab;
             return(VesselsManager.Select(vessel));
         }
         else
         {
             Tabs.SelectedItem = TreeTab;
             return(TreeManager.Select(vessel));
         }
     }
     else if (item is KmlKerbal)
     {
         KmlKerbal kerbal = (KmlKerbal)item;
         if (Tabs.SelectedItem == TreeTab && kerbal.Origin == KmlKerbal.KerbalOrigin.Roster)
         {
             Tabs.SelectedItem = KerbalsTab;
             return(KerbalsManager.Select(kerbal));
         }
         else
         {
             Tabs.SelectedItem = TreeTab;
             return(TreeManager.Select(kerbal));
         }
     }
     else
     {
         Tabs.SelectedItem = TreeTab;
         return(TreeManager.Select(item));
     }
 }
Example #16
0
        private void BuildContextMenu(bool withAddMenu, bool withDeleteMenu)
        {
            ContextMenu menu  = new ContextMenu();
            MenuItem    title = new MenuItem();
            Image       img   = GenerateImage(DataNode);

            img.Margin            = new Thickness(0);
            title.Icon            = img;
            title.Header          = DataNode.ToString();
            title.IsEnabled       = false;
            title.Background      = new SolidColorBrush(Colors.Black);
            title.BorderThickness = new Thickness(1);
            title.BorderBrush     = new SolidColorBrush(Colors.Gray);
            menu.Items.Add(title);
            menu.Items.Add(new Separator());

            // So far it's the default Menu, wich should not be shown if no items follow
            int defaultMenuCount = menu.Items.Count;

            // Give menu item a more descriptive name
            string nodeName = "node";

            if (DataNode is KmlResource)
            {
                nodeName = "resource";
                MenuItem m = new MenuItem();
                m.DataContext = DataNode;
                m.Icon        = Icons.CreateImage(Icons.Resource);
                m.Header      = "_Refill this resource";
                m.Click      += ResourceRefill_Click;
                menu.Items.Add(m);
            }
            else if (DataNode is KmlPart)
            {
                nodeName = "part";
                KmlPart node = (KmlPart)DataNode;
                if (node.HasResources)
                {
                    MenuItem m = new MenuItem();
                    m.DataContext = DataNode;
                    m.Icon        = Icons.CreateImage(Icons.Resource);
                    m.Header      = "_Refill all resources in this part";
                    m.Click      += PartRefill_Click;
                    menu.Items.Add(m);
                    foreach (string resType in node.ResourceTypes)
                    {
                        m             = new MenuItem();
                        m.DataContext = DataNode;
                        m.Icon        = Icons.CreateImage(Icons.Resource);
                        m.Header      = "_Refill '" + resType + "' resource in this part";
                        m.Tag         = resType;
                        m.Click      += PartRefill_Click;
                        menu.Items.Add(m);
                    }
                }
                if (node is KmlPartDock)
                {
                    KmlPartDock dock = (KmlPartDock)node;
                    if (dock.NeedsRepair)
                    {
                        if (menu.Items.Count > defaultMenuCount)
                        {
                            menu.Items.Add(new Separator());
                        }
                        MenuItem m = new MenuItem();
                        m.DataContext = DataNode;
                        m.Icon        = Icons.CreateImage(Icons.PartDock);
                        m.Header      = "Re_pair docking connection of this and connected part";
                        m.Click      += DockRepair_Click;
                        menu.Items.Add(m);
                    }
                }
            }
            else if (DataNode is KmlVessel)
            {
                nodeName = "vessel";
                KmlVessel node = (KmlVessel)DataNode;

                MenuItem m = new MenuItem();
                m.DataContext = DataNode;
                img           = GenerateImage(DataNode);
                img.Margin    = new Thickness(0);
                m.Icon        = img;
                m.Header      = "S_witch view";
                m.Click      += SwitchView_Click;
                menu.Items.Add(m);

                menu.Items.Add(new Separator());
                m             = new MenuItem();
                m.DataContext = DataNode;
                m.Icon        = Icons.CreateImage(Icons.VesselSpaceObject);
                m.Header      = "Send to _low kerbin orbit";
                m.Click      += VesselToLKO_Click;
                menu.Items.Add(m);

                if (node.HasResources)
                {
                    menu.Items.Add(new Separator());
                    m             = new MenuItem();
                    m.DataContext = DataNode;
                    m.Icon        = Icons.CreateImage(Icons.Resource);
                    m.Header      = "_Refill all resources in all parts of this vessel";
                    m.Click      += VesselRefill_Click;
                    menu.Items.Add(m);
                    foreach (string resType in node.ResourceTypes)
                    {
                        m             = new MenuItem();
                        m.DataContext = DataNode;
                        m.Icon        = Icons.CreateImage(Icons.Resource);
                        m.Header      = "_Refill all '" + resType + "' resources in all parts of this vessel";
                        m.Tag         = resType;
                        m.Click      += VesselRefill_Click;
                        menu.Items.Add(m);
                    }
                }
                if (node.Flags.Count > 0)
                {
                    menu.Items.Add(new Separator());
                    m             = new MenuItem();
                    m.DataContext = DataNode;
                    m.Icon        = Icons.CreateImage(Icons.VesselFlag);
                    m.Header      = "Change _flag in all parts of this vessel...";
                    m.Click      += VesselFlagExchange_Click;
                    menu.Items.Add(m);
                }
            }
            else if (DataNode is KmlKerbal)
            {
                nodeName = "kerbal";
                KmlKerbal node = (KmlKerbal)DataNode;

                MenuItem m = new MenuItem();
                m.DataContext = DataNode;
                img           = GenerateImage(DataNode);
                img.Margin    = new Thickness(0);
                m.Icon        = img;
                m.Header      = "S_witch view";
                m.Click      += SwitchView_Click;
                menu.Items.Add(m);

                if (node.AssignedVessel != null || node.AssignedPart != null)
                {
                    if (menu.Items.Count > defaultMenuCount)
                    {
                        menu.Items.Add(new Separator());
                    }
                    if (node.AssignedVessel != null)
                    {
                        m             = new MenuItem();
                        m.DataContext = DataNode;
                        img           = GenerateImage(node.AssignedVessel);
                        img.Margin    = new Thickness(0);
                        m.Icon        = img;
                        m.Header      = "Select assigned _vessel: " + node.AssignedVessel.Name;
                        m.Click      += KerbalSelectAssignedVessel_Click;
                        menu.Items.Add(m);
                    }
                    if (node.AssignedPart != null)
                    {
                        m             = new MenuItem();
                        m.DataContext = DataNode;
                        img           = GenerateImage(node.AssignedPart);
                        img.Margin    = new Thickness(0);
                        m.Icon        = img;
                        m.Header      = "Select assigned _part: " + node.AssignedPart.Name;
                        m.Click      += KerbalSelectAssignedPart_Click;
                        menu.Items.Add(m);
                    }
                }

                if (node.AssignedVessel != null || node.AssignedPart != null || node.State.ToLower() == "missing")
                {
                    if (menu.Items.Count > defaultMenuCount)
                    {
                        menu.Items.Add(new Separator());
                    }
                    m             = new MenuItem();
                    m.DataContext = DataNode;
                    img           = Icons.CreateImage(Icons.VesselSpaceObject);
                    m.Icon        = img;
                    m.Header      = "Send _home to astronaut complex";
                    m.Click      += KerbalSendHome_Click;
                    menu.Items.Add(m);
                }
            }

            // Adding / deleting
            if (withAddMenu)
            {
                if (menu.Items.Count > defaultMenuCount)
                {
                    menu.Items.Add(new Separator());
                }
                MenuItem m = new MenuItem();
                m.DataContext = DataNode;
                m.Icon        = Icons.CreateImage(Icons.Add);
                m.Header      = "Add _attribute...";
                m.Click      += NodeAddAttrib_Click;
                menu.Items.Add(m);

                m             = new MenuItem();
                m.DataContext = DataNode;
                m.Icon        = Icons.CreateImage(Icons.Add);
                m.Header      = "Add _child node...";
                m.Click      += NodeAddChild_Click;
                menu.Items.Add(m);

                m             = new MenuItem();
                m.DataContext = DataNode;
                m.Icon        = Icons.CreateImage(Icons.Add);
                m.Header      = "_Insert node...";
                m.Click      += NodeInsertBefore_Click;
                m.IsEnabled   = DataNode.Parent != null;
                menu.Items.Add(m);
            }
            if (withDeleteMenu)
            {
                if (menu.Items.Count > defaultMenuCount)
                {
                    menu.Items.Add(new Separator());
                }
                MenuItem m = new MenuItem();
                m.DataContext = DataNode;
                m.Icon        = Icons.CreateImage(Icons.Delete);
                m.Header      = "_Delete this " + nodeName + "...";
                m.Click      += NodeDelete_Click;
                m.IsEnabled   = DataNode.CanBeDeleted;
                menu.Items.Add(m);
            }

            // Need to have a seperate menu for each item, even if it is empty.
            // If ContextMenu is null, the parent's contextmenu will be used (WTF).
            // Item[0] is the menu title, Item[1] a Seperator, both always created.
            ContextMenu = menu;
            if (menu.Items.Count <= defaultMenuCount)
            {
                ContextMenu.Visibility = System.Windows.Visibility.Hidden;
            }
            else
            {
                // Apply look and feel
                foreach (object o in menu.Items)
                {
                    if (o is MenuItem)
                    {
                        MenuItem m = (MenuItem)o;
                        if (!m.IsEnabled && m.Icon != null)
                        {
                            (m.Icon as Image).Opacity = 0.3;
                        }
                    }
                }
            }
        }
Example #17
0
        private Image GenerateImage(KmlNode node)
        {
            Image image = new Image();

            image.Height = 16;
            if (node is KmlVessel)
            {
                KmlVessel vessel = (KmlVessel)node;
                if (vessel.Type.ToLower() == "base")
                {
                    image.Source = Icons.VesselBase.Source;
                }
                else if (vessel.Type.ToLower() == "debris")
                {
                    image.Source = Icons.VesselDebris.Source;
                }
                else if (vessel.Type.ToLower() == "eva")
                {
                    image.Source = Icons.VesselEVA.Source;
                }
                else if (vessel.Type.ToLower() == "flag")
                {
                    image.Source = Icons.VesselFlag.Source;
                }
                else if (vessel.Type.ToLower() == "lander")
                {
                    image.Source = Icons.VesselLander.Source;
                }
                else if (vessel.Type.ToLower() == "probe")
                {
                    image.Source = Icons.VesselProbe.Source;
                }
                else if (vessel.Type.ToLower() == "spaceobject")
                {
                    image.Source = Icons.VesselSpaceObject.Source;
                }
                else if (vessel.Type.ToLower() == "station")
                {
                    image.Source = Icons.VesselStation.Source;
                }
                else if (vessel.Type.ToLower() == "rover")
                {
                    image.Source = Icons.VesselRover.Source;
                }
                else
                {
                    image.Source = Icons.Vessel.Source;
                }
            }
            else if (node is KmlPartDock)
            {
                KmlPartDock dock = (KmlPartDock)node;
                if (dock.DockType == KmlPartDock.DockTypes.Grapple)
                {
                    image.Source = Icons.PartGrapple.Source;
                }
                else
                {
                    image.Source = Icons.PartDock.Source;
                }
            }
            else if (node is KmlPart)
            {
                image.Source = Icons.Part.Source;
            }
            else if (node is KmlResource)
            {
                image.Source = Icons.Resource.Source;
            }
            else if (node is KmlKerbal)
            {
                KmlKerbal kerbal = (KmlKerbal)node;
                if (kerbal.Type.ToLower() == "applicant")
                {
                    image.Source = Icons.KerbalApplicant.Source;
                }
                else if (kerbal.Type.ToLower() == "tourist")
                {
                    image.Source = Icons.KerbalTorist.Source;
                }
                else
                {
                    image.Source = Icons.Kerbal.Source;
                }
            }
            else if (node is KmlGhostNode)
            {
                image.Source = Icons.Ghost.Source;
            }
            else
            {
                image.Source = Icons.Node.Source;
            }
            image.Margin = new Thickness(0, 0, 3, 0);

            return(image);
        }
Example #18
0
        private void BuildContextMenu()
        {
            ContextMenu menu  = new ContextMenu();
            MenuItem    title = new MenuItem();

            title.Icon            = GenerateImage(DataNode);
            title.Header          = DataNode.ToString();
            title.IsEnabled       = false;
            title.Background      = new SolidColorBrush(Colors.Black);
            title.BorderThickness = new Thickness(1);
            title.BorderBrush     = new SolidColorBrush(Colors.Gray);
            menu.Items.Add(title);
            menu.Items.Add(new Separator());

            if (DataNode is KmlResource)
            {
                MenuItem m = new MenuItem();
                m.DataContext = DataNode;
                m.Icon        = Icons.CreateImage(Icons.Resource);
                m.Header      = "Refill this resource";
                m.Click      += ResourceRefill_Click;
                menu.Items.Add(m);
            }
            else if (DataNode is KmlPart)
            {
                KmlPart node = (KmlPart)DataNode;
                if (node.HasResources)
                {
                    MenuItem m = new MenuItem();
                    m.DataContext = DataNode;
                    m.Icon        = Icons.CreateImage(Icons.Resource);
                    m.Header      = "Refill all resources in this part";
                    m.Click      += PartRefill_Click;
                    menu.Items.Add(m);
                    foreach (string resType in node.ResourceTypes)
                    {
                        m             = new MenuItem();
                        m.DataContext = DataNode;
                        m.Icon        = Icons.CreateImage(Icons.Resource);
                        m.Header      = "Refill '" + resType + "' resource in this part";
                        m.Tag         = resType;
                        m.Click      += PartRefill_Click;
                        menu.Items.Add(m);
                    }
                }
                if (node is KmlPartDock)
                {
                    KmlPartDock dock = (KmlPartDock)node;
                    if (dock.NeedsRepair)
                    {
                        if (menu.Items.Count > 2)
                        {
                            menu.Items.Add(new Separator());
                        }
                        MenuItem m = new MenuItem();
                        m.DataContext = DataNode;
                        m.Icon        = Icons.CreateImage(Icons.PartDock);
                        m.Header      = "Repair docking connection of this and connected part";
                        m.Click      += DockRepair_Click;
                        menu.Items.Add(m);
                    }
                }
            }
            else if (DataNode is KmlVessel)
            {
                KmlVessel node = (KmlVessel)DataNode;
                if (node.HasResources)
                {
                    MenuItem m = new MenuItem();
                    m.DataContext = DataNode;
                    m.Icon        = Icons.CreateImage(Icons.Resource);
                    m.Header      = "Refill all resources in all parts of this vessel";
                    m.Click      += VesselRefill_Click;
                    menu.Items.Add(m);
                    foreach (string resType in node.ResourceTypes)
                    {
                        m             = new MenuItem();
                        m.DataContext = DataNode;
                        m.Icon        = Icons.CreateImage(Icons.Resource);
                        m.Header      = "Refill all '" + resType + "' resources in all parts of this vessel";
                        m.Tag         = resType;
                        m.Click      += VesselRefill_Click;
                        menu.Items.Add(m);
                    }
                }
            }

            // Need to have a seperate menu for each item, even if it is empty.
            // If ContextMenu is null, the parent's contextmenu will be used (WTF).
            // Item[0] is the menu title, Item[1] a Seperator, both always created.
            ContextMenu = menu;
            if (menu.Items.Count < 3)
            {
                ContextMenu.Visibility = System.Windows.Visibility.Hidden;
            }
        }
Example #19
0
 private string GenerateText(KmlVessel vessel)
 {
     return(vessel.Name + "\n " + vessel.Type + "\n " + vessel.Situation);
 }
Example #20
0
        private static void RepairGrappling(KmlPartDock grapple, KmlPart part)
        {
            int grappleIndex = -1;
            int partIndex    = -1;

            if (grapple.Parent is KmlVessel)
            {
                bool      dockedVesselOk = true;
                KmlVessel vessel         = (KmlVessel)grapple.Parent;
                grappleIndex = vessel.Parts.IndexOf(grapple);
                partIndex    = vessel.Parts.IndexOf(part);
                try
                {
                    KmlNode module = grapple.GetOrCreateChildNode("MODULE", "ModuleGrappleNode");
                    module.GetOrCreateAttrib("isEnabled", "True");
                    //module.GetOrCreateAttrib("stagingEnabled").Value = "False"; // True?!?
                    module.GetOrCreateAttrib("state").Value   = "Grappled";
                    module.GetOrCreateAttrib("dockUId").Value = part.Uid;
                    KmlNode events = module.GetOrCreateChildNode("EVENTS");
                    events.GetOrCreateChildNode("Release").GetOrCreateAttrib("active").Value           = "True";
                    events.GetOrCreateChildNode("ReleaseSameVessel").GetOrCreateAttrib("active").Value = "False";
                    events.GetOrCreateChildNode("Decouple").GetOrCreateAttrib("active").Value          = "False";
                    module.GetOrCreateChildNode("ACTIONS");

                    KmlNode dockedVessel      = module.GetOrCreateChildNode("DOCKEDVESSEL");
                    KmlNode dockedVesselOther = module.GetOrCreateChildNode("DOCKEDVESSEL_Other");

                    string vesselName;
                    string vesselRootUId;
                    string defaultName;
                    if (grapple.Parent is KmlVessel)
                    {
                        vesselName    = (grapple.Parent as KmlVessel).Name;
                        vesselRootUId = (grapple.Parent as KmlVessel).RootPart.Uid;
                        defaultName   = vesselName + " Grappled - repaired by KML";
                    }
                    else
                    {
                        vesselName = "Unknown Vessel - repaired by KML";
                        if (part.ParentPart == grapple)
                        {
                            vesselRootUId = grapple.Uid;
                        }
                        else
                        {
                            vesselRootUId = part.Uid;
                        }
                        defaultName = "Unknown Grappled - repaired by KML";
                    }

                    string thisName;
                    string otherName;
                    string thisUid;
                    string otherUid;
                    if (part.ParentPart == grapple)
                    {
                        thisName  = vesselName;
                        thisUid   = vesselRootUId;
                        otherName = defaultName;
                        otherUid  = part.Uid;
                    }
                    else
                    {
                        thisName  = defaultName;
                        thisUid   = grapple.Uid;
                        otherName = vesselName;
                        otherUid  = vesselRootUId;
                    }
                    if (dockedVessel.GetAttrib("vesselName") == null)
                    {
                        KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselName", thisName);
                        attrib.AttribValueChanged += grapple.DockedVesselName_Changed;
                        grapple.DockedVesselName_Changed(attrib, new System.Windows.RoutedEventArgs());
                    }
                    if (dockedVessel.GetAttrib("vesselType") == null)
                    {
                        KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselType", "6");
                        attrib.AttribValueChanged += grapple.DockedVesselType_Changed;
                        grapple.DockedVesselType_Changed(attrib, new System.Windows.RoutedEventArgs());
                    }
                    dockedVessel.GetOrCreateAttrib("rootUId", thisUid);
                    if (dockedVesselOther.GetAttrib("vesselName") == null)
                    {
                        KmlAttrib attrib = dockedVesselOther.GetOrCreateAttrib("vesselName", otherName);
                        attrib.AttribValueChanged += grapple.DockedVesselOtherName_Changed;
                        grapple.DockedVesselOtherName_Changed(attrib, new System.Windows.RoutedEventArgs());
                    }
                    if (dockedVesselOther.GetAttrib("vesselType") == null)
                    {
                        KmlAttrib attrib = dockedVesselOther.GetOrCreateAttrib("vesselType", "6");
                        attrib.AttribValueChanged += grapple.DockedVesselOtherType_Changed;
                        grapple.DockedVesselOtherType_Changed(attrib, new System.Windows.RoutedEventArgs());
                    }
                    dockedVesselOther.GetOrCreateAttrib("rootUId", otherUid);

                    module = grapple.GetOrCreateChildNode("MODULE", "ModuleAnimateGeneric");
                    module.GetOrCreateAttrib("animSwitch").Value = "False";
                    module.GetOrCreateAttrib("animTime").Value   = "1";
                    events = module.GetOrCreateChildNode("EVENTS");
                    KmlNode toggle = events.GetOrCreateChildNode("Toggle");
                    toggle.GetOrCreateAttrib("active").Value  = "False";
                    toggle.GetOrCreateAttrib("guiName").Value = "Disarm";
                    if (part.ParentPart == grapple)
                    {
                        RepairGrappleAttachment(part, grappleIndex);
                    }
                    else if (grapple.ParentPart == part)
                    {
                        RepairGrappleAttachment(grapple, partIndex);
                    }
                    else
                    {
                        // TODO KmlPartDock:RepairGrappling(): Is there a 'Grappled (same vessel)'?
                    }
                    if (dockedVesselOk)
                    {
                        Syntax.Info(grapple, "Successfully repaired grappling");
                        BuildAttachmentStructure(vessel.Parts);
                    }
                }
                catch (NullReferenceException)
                {
                    Syntax.Warning(grapple, "Couldn't fix grappling node, there are sub-nodes missing.\n" +
                                   "You should copy a MODULE node from a functional state 'Grappled' part\n" +
                                   "grappled part should be: " + part);
                }
            }
            else
            {
                Syntax.Warning(grapple, "Could not search for connected parts, parent vessel is not valid");
            }
        }
Example #21
0
        /// <summary>
        /// Repair the docking connection of this port.
        /// </summary>
        public void Repair()
        {
            // Two docks
            if (DockType == DockTypes.Dock)
            {
                if (DockedPart == null)
                {
                    if (Parent is KmlVessel)
                    {
                        KmlVessel vessel  = (KmlVessel)Parent;
                        int       myIndex = vessel.Parts.IndexOf(this);
                        for (int i = 0; i < vessel.Parts.Count; i++)
                        {
                            KmlPart part = vessel.Parts[i];
                            if (part is KmlPartDock)
                            {
                                KmlPartDock otherDock = (KmlPartDock)part;
                                if (otherDock.DockedPart == this)
                                {
                                    // This will choose the right docker / dockee or switch to same vessel if none is parent
                                    RepairDockerChoose(this, otherDock);
                                    return;
                                }
                                else if (otherDock.ParentPart == this || ParentPart == otherDock)
                                {
                                    if (AttachedToSurfaceIndex == i || AttachedToNodeIndices.Contains(i) ||
                                        otherDock.AttachedToSurfaceIndex == myIndex || otherDock.AttachedToNodeIndices.Contains(myIndex))
                                    {
                                        // It's attached and not docked
                                        continue;
                                    }
                                    else
                                    {
                                        RepairDockerChoose(this, otherDock);
                                        return;
                                    }
                                }
                            }
                        }
                        // To avoid getting to here there are returns spread above
                        // Syntax.Warning(this, "Didn't find another part in all parts of the vessel to fix this dock with");
                        RepairClearDocking(this);
                    }
                    else
                    {
                        Syntax.Warning(this, "Could not search for connected parts, parent vessel is not valid");
                    }
                }
                else if (!(DockedPart is KmlPartDock))
                {
                    Syntax.Warning(this, "Don't know how to repair this docking connection, this one is no dock: " + DockedPart);
                }
                else
                {
                    KmlPartDock otherDock = (KmlPartDock)DockedPart;
                    if (otherDock.DockedPart == this || otherDock.ParentPart == this || ParentPart == otherDock)
                    {
                        // They are already linked but there's something to fix unless context menu to this wouldn't be enabled
                        // This will choose the right docker / dockee or switch to same vessel if none is parent
                        RepairDockerChoose(this, otherDock);
                    }
                    else
                    {
                        // Semi-functional same vessel docking would be fixed above, this is no docking
                        RepairClearDocking(this);
                    }
                }
            }

            // One dock and another part
            else if (DockType == DockTypes.Grapple)
            {
                if (DockedPart == null)
                {
                    if (Parent is KmlVessel)
                    {
                        KmlVessel vessel  = (KmlVessel)Parent;
                        int       myIndex = vessel.Parts.IndexOf(this);
                        for (int i = 0; i < vessel.Parts.Count; i++)
                        {
                            KmlPart part = vessel.Parts[i];
                            if (part.ParentPart == this || this.ParentPart == part)
                            {
                                if (AttachedToSurfaceIndex == i || AttachedToNodeIndices.Contains(i) ||
                                    part.AttachedToSurfaceIndex == myIndex || part.AttachedToNodeIndices.Contains(myIndex))
                                {
                                    // It's attached and not grappled
                                    continue;
                                }
                                else
                                {
                                    RepairGrappling(this, part);
                                    return;
                                }
                            }
                        }
                        // To avoid getting to here there are returns spread above
                        // Syntax.Warning(this, "Didn't find another part in all parts of the vessel to fix this grappling device with");
                        RepairClearDocking(this);
                    }
                    else
                    {
                        Syntax.Warning(this, "Could not search for connected parts, parent vessel is not valid");
                    }
                }
                else
                {
                    if (DockedPart.ParentPart == this || ParentPart == DockedPart)
                    {
                        RepairGrappling(this, DockedPart);
                    }
                    else
                    {
                        RepairClearDocking(this);
                    }
                }
            }
        }
Example #22
0
        private static void RepairGrappling(KmlPartDock grapple, KmlPart part)
        {
            int grappleIndex = -1;
            int partIndex    = -1;

            if (grapple.Parent == null || !(grapple.Parent is KmlVessel))
            {
                System.Windows.MessageBox.Show("Could not search for connected parts, parent vessel is not valid");
            }
            else
            {
                bool      dockedVesselOk = true;
                KmlVessel vessel         = (KmlVessel)grapple.Parent;
                grappleIndex = vessel.Parts.IndexOf(grapple);
                partIndex    = vessel.Parts.IndexOf(part);
                try
                {
                    KmlNode module = grapple.GetChildNode("MODULE", "ModuleGrappleNode");
                    module.GetAttrib("state").Value   = "Grappled";
                    module.GetAttrib("dockUId").Value = part.Uid;
                    KmlNode events = module.GetChildNode("EVENTS");
                    events.GetChildNode("Release").GetAttrib("active").Value           = "True";
                    events.GetChildNode("ReleaseSameVessel").GetAttrib("active").Value = "False";
                    if (module.GetChildNode("DOCKEDVESSEL") == null)
                    {
                        System.Windows.MessageBox.Show("Couldn't find sub-node DOCKEDVESSEL, you should try to copy it from older save file.");
                        dockedVesselOk = false;
                    }
                    if (module.GetChildNode("DOCKEDVESSEL_other") == null)
                    {
                        System.Windows.MessageBox.Show("Couldn't find sub-node DOCKEDVESSEL_other, you should try to copy it from older save file.");
                        dockedVesselOk = false;
                    }
                    module = grapple.GetChildNode("MODULE", "ModuleAnimateGeneric");
                    module.GetAttrib("animSwitch").Value = "False";
                    module.GetAttrib("animTime").Value   = "1";
                    events = module.GetChildNode("EVENTS");
                    KmlNode toggle = events.GetChildNode("Toggle");
                    toggle.GetAttrib("active").Value  = "False";
                    toggle.GetAttrib("guiName").Value = "Disarm";
                    if (part.ParentPart == grapple)
                    {
                        RepairGrappleAttachment(part, grappleIndex);
                    }
                    else if (grapple.ParentPart == part)
                    {
                        RepairGrappleAttachment(grapple, partIndex);
                    }
                    else
                    {
                        // TODO KmlPartDock:RepairGrappling(): Is there a 'Grappled (same vessel)'?
                    }
                    if (dockedVesselOk)
                    {
                        // Maybe RepairGrappleAttachment()  will cause a message to save and reload
                        System.Windows.MessageBox.Show("Successfully repaired grappling. Please save and reload to see the rebuilt part structure.");
                        // TODO KmlPartDock:RepairGrappling(): Refresh structure without save / reload
                    }
                }
                catch (NullReferenceException)
                {
                    System.Windows.MessageBox.Show("Couldn't fix grappling node, there are sub-nodes missing.\n" +
                                                   "You should copy a MODULE node from a functional state 'Grappled' part.\n" +
                                                   "grappled part should be: " + part);
                }
            }
        }