Ejemplo n.º 1
0
        public void drawPoints(List <AeroPair> listToDraw, int x_max, int y_max, bool lastIsGreen)
        {
            Clear();
            for (int i = 0; i < listToDraw.Count; i++)
            {
                AeroPair l    = listToDraw[i];
                int      xLoc = (int)Mathf.Clamp(l.Q * displayTex.width / x_max, 2, displayTex.width - 3);
                int      yLoc = (int)Mathf.Clamp(l.deflection * displayTex.height / y_max, 2, displayTex.height - 3);

                for (int j = -2; j <= 2; j++)
                {
                    for (int k = -2; k <= 2; k++)
                    {
                        if (lastIsGreen && i == listToDraw.Count - 1)
                        {
                            displayTex.SetPixel(xLoc + j, yLoc + k, XKCDColors.Green);
                        }
                        else
                        {
                            displayTex.SetPixel(xLoc + j, yLoc + k, XKCDColors.Red);
                        }
                    }
                }
            }
            displayTex.Apply();
        }
Ejemplo n.º 2
0
        private void DrawWindow(int id)
        {
            if (moduleToDraw.deflectionAtPressure == null)
            {
                moduleToDraw.deflectionAtPressure = new List <AeroPair>();
            }

            GUILayout.Label("100% deflection: " + Math.Abs(moduleToDraw.aeroModule.GetDefaultMaxDeflect()).ToString("0.0") + " degrees");
            if (HighLogic.LoadedSceneIsFlight)
            {
                GUILayout.Label("Deflect @ Q(" + moduleToDraw.vessel.dynamicPressurekPa.ToString("0") + ") = "
                                + Math.Abs(moduleToDraw.currentDeflection).ToString("0.0") + "(" + (moduleToDraw.currentDeflection * 100 / moduleToDraw.aeroModule.GetDefaultMaxDeflect()).ToString("0") + "%)");
            }
            GUILayout.Box("", GUILayout.Height(10));
            GUILayout.BeginHorizontal();
            GUILayout.Space(77);
            GUILayout.Label("Q (kPa)", GUILayout.Width(53));
            GUILayout.Label("% Deflect", GUILayout.Width(57));
            GUILayout.EndHorizontal();

            for (int i = 0; i < moduleToDraw.deflectionAtPressure.Count; i++)
            {
                AeroPair list = moduleToDraw.deflectionAtPressure[i];

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Remove", GUILayout.Width(65)))
                {
                    list.deflection   = -1;
                    windowRect.height = 0;
                    RemoveFocus();
                }
                list.Q = float.Parse(GUILayout.TextField(list.Q.ToString("0.0#"), GUILayout.Width(60)));
                if (moduleToDraw.deflectionAtPressure.Count - 1 == i)
                {
                    GUI.SetNextControlName("deflection");
                }
                string tmp = GUILayout.TextField(list.deflection == 0 ? "" : list.deflection.ToString("0.0"), GUILayout.Width(60));
                if (tmp != "")
                {
                    list.deflection = float.Parse(tmp);
                }
                GUILayout.EndHorizontal();
            }

            // ==================== The new entry fields
            GUILayout.BeginHorizontal();
            GUILayout.Space(70);
            GUI.SetNextControlName("dynPress");
            dynPressure = GUILayout.TextField(dynPressure, GUILayout.Width(60));

            deflection = GUILayout.TextField(deflection, GUILayout.Width(60));
            GUILayout.EndHorizontal();
            if (focus == 0)
            {
                GUI.FocusControl("deflection");
                focus = -1;
            }
            else if (focus > 0)
            {
                focus--;
            }
            if (dynPressure != "" && GUI.GetNameOfFocusedControl() != "dynPress")
            {
                AeroPair newEntry = new AeroPair(Mathf.Abs(float.Parse(dynPressure)), Mathf.Abs(deflection != "" ? float.Parse(deflection) : 0));
                moduleToDraw.deflectionAtPressure = moduleToDraw.deflectionAtPressure.OrderBy(x => x.Q).ToList(); // sort exisint entries
                moduleToDraw.deflectionAtPressure.Add(newEntry);                                                  // add new entry to end
                dynPressure = deflection = "";
                focus       = 5;
            }
            // ===================== End new entry fields

            if (GUILayout.Button("Copy to all"))
            {
                CopyToAll();
                RemoveFocus();
            }
            GUILayout.Box("", GUILayout.Height(10));
            GUILayout.BeginHorizontal();
            GUILayout.Label("Defaults: ");
            if (GUILayout.Button("Update"))
            {
                ConfigNode node = new ConfigNode(nodeName);
                ModuleDynamicDeflection.defaults = ToConfigNode(moduleToDraw.deflectionAtPressure, node, true);
                WriteDefaultsToFile();
            }
            if (GUILayout.Button("Restore"))
            {
                moduleToDraw.LoadConfig(ModuleDynamicDeflection.defaults, true);
                windowRect.height = 0;
            }
            GUILayout.EndHorizontal();
            if (GUILayout.Button("", GUILayout.Height(10)))
            {
                showDisplay       = !showDisplay;
                windowRect.height = 0;
            }

            // ======================== draw graph thing
            if (showDisplay)
            {
                GUILayout.BeginHorizontal();
                GUILayout.BeginVertical();
                GUILayout.Label(maxY.ToString());
                GUILayout.Space(67);
                GUILayout.Label(" %");
                GUILayout.Space(67);
                GUILayout.Label("0");
                GUILayout.EndVertical();
                GUILayout.Label(display.Image);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Space(30);
                GUILayout.Label("0");
                GUILayout.Space(47);
                GUILayout.Label("Q");
                GUILayout.Space(47);
                GUILayout.Label(maxX.ToString());
                GUILayout.EndHorizontal();
            }

            GUI.DragWindow();
        }