예제 #1
0
        void OnGUI()
        {
            if (HighLogic.LoadedSceneIsFlight && vessel && vessel.isActiveVessel && !vessel.packed)
            {
                if (BDArmorySettings.GAME_UI_ENABLED)
                {
                    if (showGUI)
                    {
                        if (!rectInit)
                        {
                            guiWindowRect                        = new Rect(45, 75, 240, 800);
                            buttonWidth                          = guiWindowRect.width - (2 * margin);
                            buttonEndY                           = buttonStartY;
                            wingmanButtonStyle                   = new GUIStyle(HighLogic.Skin.button);
                            wingmanButtonStyle.alignment         = TextAnchor.MiddleLeft;
                            wingmanButtonStyle.wordWrap          = false;
                            wingmanButtonStyle.fontSize          = 11;
                            wingmanButtonSelectedStyle           = new GUIStyle(HighLogic.Skin.box);
                            wingmanButtonSelectedStyle.alignment = TextAnchor.MiddleLeft;
                            wingmanButtonSelectedStyle.wordWrap  = false;
                            wingmanButtonSelectedStyle.fontSize  = 11;
                            rectInit = true;
                        }
                        guiWindowRect = GUI.Window(1293293, guiWindowRect, WingmenWindow, "WingCommander",
                                                   HighLogic.Skin.window);

                        if (showAGWindow)
                        {
                            AGWindow();
                        }
                    }

                    //command position diamonds
                    float diamondSize = 24;
                    foreach (var comPos in commandedPositions)
                    {
                        BDGUIUtils.DrawTextureOnWorldPos(comPos.worldPos, BDArmorySettings.Instance.greenDiamondTexture,
                                                         new Vector2(diamondSize, diamondSize), 0);
                        Vector2 labelPos;
                        if (BDGUIUtils.WorldToGUIPos(comPos.worldPos, out labelPos))
                        {
                            labelPos.x += diamondSize / 2;
                            labelPos.y -= 10;
                            GUI.Label(new Rect(labelPos.x, labelPos.y, 300, 20), comPos.name);
                        }
                    }

                    if (drawMouseDiamond)
                    {
                        Vector2 mouseDiamondPos  = Input.mousePosition;
                        Rect    mouseDiamondRect = new Rect(mouseDiamondPos.x - (diamondSize / 2),
                                                            Screen.height - mouseDiamondPos.y - (diamondSize / 2), diamondSize, diamondSize);
                        GUI.DrawTexture(mouseDiamondRect, BDArmorySettings.Instance.greenDiamondTexture,
                                        ScaleMode.StretchToFill, true);
                    }
                }
            }
        }
예제 #2
0
		void DrawAlignmentIndicator()
		{
			if(fireTransforms == null || fireTransforms[0] == null) return;

			Transform refTransform = EditorLogic.RootPart.GetReferenceTransform();

			Vector3 fwdPos = fireTransforms[0].position + (5 * fireTransforms[0].forward);
			BDGUIUtils.DrawLineBetweenWorldPositions(fireTransforms[0].position, fwdPos, 4, Color.green);

			Vector3 referenceDirection = refTransform.up;
			Vector3 refUp = -refTransform.forward;
			Vector3 refRight = refTransform.right;

			Vector3 refFwdPos = fireTransforms[0].position + (5 * referenceDirection);
			BDGUIUtils.DrawLineBetweenWorldPositions(fireTransforms[0].position, refFwdPos, 2, Color.white);

			BDGUIUtils.DrawLineBetweenWorldPositions(fwdPos, refFwdPos, 2, XKCDColors.Orange);

			Vector2 guiPos;
			if(BDGUIUtils.WorldToGUIPos(fwdPos, out guiPos))
			{
				Rect angleRect = new Rect(guiPos.x, guiPos.y, 100, 200);

				Vector3 pitchVector = (5 *Vector3.ProjectOnPlane(fireTransforms[0].forward, refRight));
				Vector3 yawVector = (5 * Vector3.ProjectOnPlane(fireTransforms[0].forward, refUp));

				BDGUIUtils.DrawLineBetweenWorldPositions(fireTransforms[0].position + pitchVector, fwdPos, 3, Color.white);
				BDGUIUtils.DrawLineBetweenWorldPositions(fireTransforms[0].position + yawVector, fwdPos, 3, Color.white);

				float pitch = Vector3.Angle(pitchVector, referenceDirection);
				float yaw = Vector3.Angle(yawVector, referenceDirection); 

				string convergeDistance;

				Vector3 projAxis = Vector3.Project(refTransform.position - fireTransforms[0].transform.position, refRight);
				float xDist = projAxis.magnitude;
				float convergeAngle = 90 - Vector3.Angle(yawVector, refTransform.up);
				if(Vector3.Dot(fireTransforms[0].forward, projAxis) > 0)
				{
					convergeDistance = "Converge: "+Mathf.Round((xDist * Mathf.Tan(convergeAngle*Mathf.Deg2Rad))).ToString()+"m";
				}
				else
				{
					convergeDistance = "Diverging";
				}

				string xAngle = "X: " + Vector3.Angle(fireTransforms[0].forward, pitchVector).ToString("0.00");
				string yAngle = "Y: " + Vector3.Angle(fireTransforms[0].forward, yawVector).ToString("0.00");

				GUI.Label(angleRect, xAngle+"\n"+ yAngle + "\n"+convergeDistance);
			}
		}