public void PDPNActivateEvent()
        {
            if (pdpnEntryWindow != null)
            {
                pdpnEntryWindow.Close();
            }

            GameObject gObj = new GameObject("PDPNwindow", typeof(PDPN_EntryWindow));

            DontDestroyOnLoad(gObj);
            pdpnEntryWindow = (PDPN_EntryWindow)gObj.GetComponent(typeof(PDPN_EntryWindow));

            pdpnEntryWindow.Invoke(this, storedVesselName, Utils.getModulePartParent(this).vesselType, priority);
        }
 public void TypingCancel()
 {
     pdpnEntryWindow.Close();
     pdpnEntryWindow = null;
 }
예제 #3
0
        void CmdPodsWindow(int WindowID)
        {
            UnityEngine.GUI.skin = HighLogic.Skin;
            GUIStyle t = new GUIStyle("TextField");

            t.fontSize    = 12;
            sortedPodList = Utils.getSortedCommandPodList(EditorLogic.fetch.ship.parts);

            GUILayout.Label("Click field to select command pod for editing\nDouble-click to get selection arrows");
            GUILayout.BeginVertical();
            sitesScrollPosition = GUILayout.BeginScrollView(sitesScrollPosition, false, true, GUILayout.Height(HEIGHT - 3 * LINEHEIGHT));
            //int cnt = 0;
            Vector3 position = Input.mousePosition;
            Part    p;
            int     i                = -1;
            bool    mouseDown        = Input.GetMouseButtonDown(0);
            bool    mouseDoubleClick = false;

            if (mouseDown)
            {
                if (one_click && mouseup && Time.fixedTime - lastMouseDowntime < GameSettings.DOUBLECLICK_MOUSESPEED && lastMouseDowntime > 0)
                {
                    mouseDoubleClick = true;
                }
                else
                {
                    lastMouseDowntime = Time.fixedTime;
                    one_click         = true;
                    mouseup           = false;
                }
            }
            else
            {
                if (Time.fixedTime - lastMouseDowntime < GameSettings.DOUBLECLICK_MOUSESPEED)
                {
                    mouseup = true;
                }
                else
                {
                    one_click = false;
                }
            }

            foreach (Tuple <int, Part, PartModule> pt in sortedPodList)
            {
                p = pt.Second;
                i++;

                PartModule m = pt.Third;

                if (m.moduleName == Constants.MODNAME)
                {
                    GUILayout.BeginHorizontal();

                    GUILayout.Label(p.name, t, GUILayout.Width(100));
                    checkMouseLocation(p);

                    if (selectedLine == i && selectedField == Field.name)
                    {
                        if (GUILayout.Button("<", readoutButtonStyle, GUILayout.Width(15.0f), GUILayout.Height(25)))
                        {
                            getTmplList();
                            int x = 0;
                            //for (int i1 = tmplListdest.Length - 1; i1 >= 0; --i1) {
                            foreach (string s in tmplListdest)
                            {
                                if (((PersistentDynamicPodNames)m).storedVesselName == s)
                                {
                                    if (x == 0)
                                    {
                                        ((PersistentDynamicPodNames)m).storedVesselName = tmplListdest[tmplListdest.Count() - 1];
                                    }
                                    else
                                    {
                                        ((PersistentDynamicPodNames)m).storedVesselName = tmplListdest[x - 1];
                                    }
                                    break;
                                }
                                x++;
                            }
                            if (x == tmplListdest.Count())
                            {
                                ((PersistentDynamicPodNames)m).storedVesselName = tmplListdest[0];
                            }
                        }
                        checkMouseLocation(p);
                    }
                    //GUI.SetNextControlName(i.ToString());

                    ((PersistentDynamicPodNames)m).storedVesselName = GUILayout.TextField(((PersistentDynamicPodNames)m).storedVesselName, t, GUILayout.Width(225));
                    if (mouseDoubleClick && checkMouseLocation(p))
                    {
                        newSelectedLine  = i;
                        newSelectedField = Field.name;
                    }
                    checkMouseLocation(p);
                    if (selectedLine == i && selectedField == Field.name)
                    {
                        if (GUILayout.Button(">", readoutButtonStyle, GUILayout.Width(15.0f), GUILayout.Height(25)))
                        {
                            getTmplList();
                            int x = 0;
                            //for (int i1 = tmplListdest.Length - 1; i1 >= 0; --i1)
                            //{
                            foreach (string s in tmplListdest)
                            {
                                if (((PersistentDynamicPodNames)m).storedVesselName == s)
                                {
                                    if (x == tmplListdest.Count() - 1)
                                    {
                                        ((PersistentDynamicPodNames)m).storedVesselName = tmplListdest[0];
                                    }
                                    else
                                    {
                                        ((PersistentDynamicPodNames)m).storedVesselName = tmplListdest[x + 1];
                                    }
                                    break;
                                }
                                x++;
                            }
                            if (x == tmplListdest.Count())
                            {
                                ((PersistentDynamicPodNames)m).storedVesselName = tmplListdest[0];
                            }
                        }
                        checkMouseLocation(p);
                    }

                    if (selectedLine == i && selectedField == Field.vesseltype)
                    {
                        if (GUILayout.Button("<", readoutButtonStyle, GUILayout.Width(15.0f), GUILayout.Height(25)))
                        {
                            int        cnt = 0;
                            VesselType workingvesseltype = VesselType.Unknown;

                            //for (int cnt = PDPN_EntryWindow.vtypes.Length - 1; cnt >= 0; --cnt)
                            //{
                            foreach (string s in PDPN_EntryWindow.vtypes)
                            {
                                cnt++;
                                if (((PersistentDynamicPodNames)m).vesselType.ToString() == s)
                                {
                                    if (cnt == 1)
                                    {
                                        workingvesseltype = PDPN_EntryWindow.getVesselType(PDPN_EntryWindow.vtypes.Count() - 1);
                                    }
                                    else
                                    {
                                        workingvesseltype = PDPN_EntryWindow.getVesselType(cnt - 2);
                                    }
                                    break;
                                }
                            }
                            ((PersistentDynamicPodNames)m).vesselType = workingvesseltype;
                        }
                    }

                    checkMouseLocation(p);

                    GUILayout.Label(((PersistentDynamicPodNames)m).vesselType.ToString(), t, GUILayout.Width(50.0f));
                    if (mouseDoubleClick && checkMouseLocation(p))
                    {
                        newSelectedLine  = i;
                        newSelectedField = Field.vesseltype;
                    }
                    if (selectedLine == i && selectedField == Field.vesseltype)
                    {
                        if (GUILayout.Button(">", readoutButtonStyle, GUILayout.Width(15.0f), GUILayout.Height(25)))
                        {
                            int        cnt = 0;
                            VesselType workingvesseltype = VesselType.Unknown;

                            //for (int cnt = PDPN_EntryWindow.vtypes.Length - 1; cnt >= 0; --cnt)
                            //{
                            foreach (string s in PDPN_EntryWindow.vtypes)
                            {
                                cnt++;
                                if (((PersistentDynamicPodNames)m).vesselType.ToString() == s)
                                {
                                    if (cnt == PDPN_EntryWindow.vtypes.Count() - 1)
                                    {
                                        workingvesseltype = PDPN_EntryWindow.getVesselType(0);
                                    }
                                    else
                                    {
                                        workingvesseltype = PDPN_EntryWindow.getVesselType(cnt);
                                    }
                                    break;
                                }
                            }
                            ((PersistentDynamicPodNames)m).vesselType = workingvesseltype;
                        }
                    }

                    checkMouseLocation(p);

                    GUILayout.BeginVertical();
                    if (i == 0)
                    {
                        GUI.enabled = false;
                    }
                    if (GUILayout.Button("▲", readoutButtonStyle, GUILayout.Width(25.0f)))
                    {
                        Tuple <int, Part, PartModule> prev = sortedPodList[i - 1];
                        int x = ((PersistentDynamicPodNames)prev.Third).priority;
                        ((PersistentDynamicPodNames)prev.Third).priority = ((PersistentDynamicPodNames)m).priority;
                        ((PersistentDynamicPodNames)m).priority          = x;
                    }

                    checkMouseLocation(p);
                    if (i == sortedPodList.Count - 1)
                    {
                        GUI.enabled = false;
                    }
                    else
                    {
                        GUI.enabled = true;
                    }
                    if (GUILayout.Button("▼", readoutButtonStyle, GUILayout.Width(25.0f)))
                    {
                        Tuple <int, Part, PartModule> next = sortedPodList[i + 1];
                        int x = ((PersistentDynamicPodNames)next.Third).priority;
                        ((PersistentDynamicPodNames)next.Third).priority = ((PersistentDynamicPodNames)m).priority;
                        ((PersistentDynamicPodNames)m).priority          = x;
                    }

                    GUI.enabled = true;
                    checkMouseLocation(p);
                    GUILayout.EndVertical();

                    GUILayout.EndHorizontal();
                    GUILayout.Space(5);
                }
            }
            GUILayout.EndScrollView();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Hide Window"))
            {
                cmdPodwindowVisible = false;
                UnHighlightParts(EditorLogic.fetch.ship.parts);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            //Log.Info ("GUI.GetNameOfFocusedControl: " + GUI.GetNameOfFocusedControl ());

            selectedField = newSelectedField;
            selectedLine  = newSelectedLine;
            GUI.DragWindow();
        }