public VesselType GetVesselType()
        {
            Log.Info("PDPNVesselModule.GetVesselType");
            if (this.pdpnVessel == null)
            {
                return(VesselType.Unknown);
            }
            Log.Info("origVesselGuid: " + origVesselGuid.ToString() + "   this.vessel.id: " + this.pdpnVessel.id.ToString());

            PersistentDynamicPodNames acn = Utils.getActiveCommandPodModule(pdpnVessel.parts);

            if (acn == null)
            {
                return(pdpnVessel.vesselType);
            }

            Part p = Utils.getActiveCommandPodPart(pdpnVessel.parts);

            Log.Info("GetVesselType");
            Log.Info("vessel.vesselName: " + pdpnVessel.vesselName);
            Log.Info("storedVesselName: " + acn.storedVesselName);
            Log.Info("vesselType: " + acn.vesselType.ToString());
            Log.Info("priority: " + acn.priority.ToString());
            Log.Info("renamed: " + acn.needsManualInput.ToString());
            Log.Info("p.partName: " + p.name);

            return(acn.vesselType);
        }
Esempio n. 2
0
        // must be unique for Unity to not mash two nametag windows togehter.


        public void Invoke(PersistentDynamicPodNames module, string oldVesselName, VesselType oldVesselType, int oldPriority)
        {
            attachedModule        = module;
            workingvesselname     = oldVesselName;
            workingvesseltype     = oldVesselType;
            workingpriority       = oldPriority;
            workingprioritystring = workingpriority.ToString();


            myWindowId = GetInstanceID();              // Use the Id of this MonoBehaviour to guarantee unique window ID.

            Vector3 screenPos = GetViewportPosFor(attachedModule.part.transform.position);

            // screenPos is in coords from 0 to 1, 0 to 1, not screen pixel coords.
            // Transform it to pixel coords:
            float       xPixelPoint   = screenPos.x * UnityEngine.Screen.width;
            float       yPixelPoint   = (1 - screenPos.y) * UnityEngine.Screen.height;
            const float WINDOW_WIDTH  = 400;
            const float WINDOW_HEIGHT = 200;

            // windowRect = new Rect(xPixelWindow, yPixelPoint, windowWidth, 130);
            windowRect = new Rect(xPixelPoint - WINDOW_WIDTH / 2, yPixelPoint, WINDOW_WIDTH, WINDOW_HEIGHT);

            SetEnabled(true);

            if (HighLogic.LoadedSceneIsEditor)
            {
                attachedModule.part.SetHighlight(false, false);
            }
        }
        public static PersistentDynamicPodNames getActiveCommandPodModule(List <Part> pl)
        {
            var acn = new PersistentDynamicPodNames();

            if (pl == null)
            {
                return(null);
            }

            acn.priority = -1;

            // List<Part> pl = Utils.getPartList(pm2);
            //for (int i = pl.Count - 1; i >= 0; --i)
            //{
            // Part part = pl[i];

            foreach (Part p in pl)
            {
                Log.Info("getActiveCommandPodModule.getActiveCommandPodModule Part: " + p.name);
                foreach (PartModule m in p.Modules)
                {
                    if (m.moduleName == Constants.MODNAME)
                    {
                        if (((PersistentDynamicPodNames)m).priority > acn.priority /* && ((PersistentDynamicPodNames)m).storedVesselName != "" */)
                        {
                            acn = ((PersistentDynamicPodNames)m);
                        }
                    }
                }
            }
            return(acn);
        }
        void FillSelections(Vessel v)
        {
            Log.Info("FillSelections start v.vesselName: " + v.vesselName);

            PersistentDynamicPodNames pdpn = Utils.getActiveCommandPodModule(v.parts);

            v.vesselName = formatManualEntryName(pdpn, v.vesselName, true);
            Log.Info("FillSelections end v.vesselName: " + v.vesselName);
            pdpn.pdpnVesselModule.renamed = true;
        }
        public static Part getActiveCommandPodPart(List <Part> pm2)
        {
            var  acn      = new PersistentDynamicPodNames();
            Part lastPart = pm2.First();

            acn.priority = -1;
            for (int i = pm2.Count - 1; i >= 0; --i)
            {
                for (int i1 = pm2[i].Modules.Count - 1; i1 >= 0; --i1)
                {
                    PartModule m = pm2[i].Modules[i1];

                    if (m.moduleName == Constants.MODNAME)
                    {
                        if (((PersistentDynamicPodNames)m).priority > acn.priority && ((PersistentDynamicPodNames)m).storedVesselName != "")
                        {
                            acn      = ((PersistentDynamicPodNames)m);
                            lastPart = pm2[i];
                        }
                    }
                }
            }
            return(lastPart);
        }
        //
        // Following support the inheritance of: IVesselAutoRename
        //
        public string GetVesselName()
        {
            if (pdpnVessel == null || pdpnVessel.id == null)
            {
                return("");
            }
            Log.Info("PDPNVesselModule.GetVesselName, id: " + pdpnVessel.id.ToString());
            Log.Info("origVesselGuid: " + origVesselGuid.ToString());
            PersistentDynamicPodNames acn = Utils.getActiveCommandPodModule(pdpnVessel.parts);

            if (acn == null)
            {
                return(pdpnVessel.vesselName);
//                return "unknown Vessel";
            }
            string returnString = acn.vessel.vesselName;

            Log.Info("returnString: " + returnString);

            if (renamed && acn.used)
            {
                Log.Info("vessel already renamed & active pod used");
                if (acn.vessel.vesselName == "")
                {
                    acn.vessel.vesselName = acn.vessel.vesselType.ToString();
                }
                Log.Info("returning vessel name  vessel.id: " + pdpnVessel.id.ToString() + "   vesselName: " + acn.vessel.vesselName);
                return(acn.vessel.vesselName);
            }
            else
            {
                Part p = Utils.getActiveCommandPodPart(pdpnVessel.parts);

                Log.Info("vessel.vesselName: " + pdpnVessel.vesselName);
                Log.Info("acn.vessel.vesselName: " + acn.vessel.vesselName);
                // Log.Info("partOrigVesselGuid: " + acn.partOrigVesselGuid.ToString());
                Log.Info("storedVesselName: " + acn.storedVesselName);
                Log.Info("vesselType: " + acn.vesselType.ToString());
                Log.Info("priority: " + acn.priority.ToString());
                Log.Info("needsManualInput: " + acn.needsManualInput.ToString());
                Log.Info("p.partName: " + p.name);
                if (acn.storedVesselName != "")
                {
                    returnString = acn.storedVesselName;
                }
                acn.used = true;
                renamed  = true;

                if (returnString == "")
                {
                    Log.Info("No name specified in pod");
                    Log.Info("returning vessel name  vessel.id: " + pdpnVessel.id.ToString() + "   vesselName: " + pdpnVessel.vesselName);
                    return(acn.vessel.vesselName);
                }
            }

            if (returnString == "")
            {
                returnString = "debris";
            }
            Log.Info("Before formatName, returnString: " + returnString);
            returnString = Utils.formatName(acn, returnString);
            Log.Info("After formatName, returnString: " + returnString);
            //
            // Check for a manual-input field
            //
            string pattern = "\\(.*?\\)|\\#.*?\\#";
            Regex  r       = new Regex(pattern);

            Match m = r.Match(returnString);

            acn.needsManualInput = m.Success;



            if (acn.needsManualInput)
            {
                acn.originalStoredVesselName = acn.storedVesselName;
            }
            Log.Info("final acn.needsManualInput: " + acn.needsManualInput.ToString());
            Log.Info("final returnString: " + returnString + "  vessel.id: " + pdpnVessel.id.ToString() + "\n");
            return(returnString);
        }