Exemplo n.º 1
0
 public static RawImage getStageTexture(StageIcon stageIcon)
 {
     if (stageIcon.GetType().GetField("iconImage", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) == null)
     {
         PluginLogger.logDebug("field null!");
     }
     return((RawImage)stageIcon.GetType().GetField("iconImage", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(stageIcon));
 }
Exemplo n.º 2
0
        public void Start()
        {
            PluginCommons.init(new PlanItinearyForRoversProperties());

            GameEvents.onPlanetariumTargetChanged.Add(new EventData <MapObject> .OnEvent(onPlanetariumTargetChanged));

            PluginLogger.logDebug("Start " + DateTime.Now);
        }
Exemplo n.º 3
0
        private void CleanUp()
        {
            PluginLogger.logDebug("CleanUp in " + EditorDriver.editorFacility);

            foreach (ApplicationLauncherButton button in appLauncherButtons)
            {
                ApplicationLauncher.Instance.RemoveModApplication(button);
            }

            foreach (BaseWindow window in windows)
            {
                window.hideWindow();
            }
        }
Exemplo n.º 4
0
        public void Start()
        {
            PluginCommons.init(new KspEasyEditorStagingProperties());

            PluginLogger.logDebug("plugin start");


            StagingWindow stagingWindow = addWindow(new StagingWindow());

            ApplicationLauncherButton button = null;

            Texture2D texture;

            texture = Texture2D.whiteTexture;


            button = ApplicationLauncher.Instance.AddModApplication(
                delegate() {
                onTrue();
                //button.SetFalse(false);
                //foreach (Part p in EditorLogic.SortedShipList) {
                //	PluginLogger.logDebug("DEBUG1: " + p.partInfo.name + ":" + p.GetInstanceID() + ", " + p.inStageIndex + "," + p.inverseStage + "," + p.stagingOn);

                //	//p.highlight(new Color(1, 0, 0));
                //	p.SetHighlight(false, false);

                //}
                //EditorLogic.RootPart.highlight(new Color(0, 0, 1));
                //EditorLogic.RootPart.SetHighlight(false, false);
                //PluginLogger.logDebug("DEBUG: " + EditorLogic.RootPart.partName);
                stagingWindow.displayWindow();
            }, delegate() {
                stagingWindow.hideWindow();
                onFalse();
            }, null, null, null, null,
                ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH, texture);
            appLauncherButtons.Add(button);
        }
Exemplo n.º 5
0
        private void highlight(EntryInEasyStage entry)
        {
            foreach (Part p in EditorLogic.SortedShipList)
            {
                p.SetHighlight(false, false);
            }
            destroyHighlightObjects();
            foreach (Part p in entry.parts)
            {
                p.highlight(new Color(0, 1, 0));
                highlightObjects.Add(createLineObject(p));
                Vector2 partScreenPosition = Camera.main.WorldToScreenPoint(p.transform.position);
                float   percent            = 0.2f;

                PluginLogger.logDebug(Screen.height + ", " + partScreenPosition);
                if (partScreenPosition.y < Screen.height * percent || partScreenPosition.y > Screen.height * (1 - 2 * percent))
                {
                    EditorDriver.fetch.vabCamera.scrollHeight = p.transform.position.y;
                }


                highlightParts.Add(p);
            }
        }
Exemplo n.º 6
0
        protected override void windowGUI(int WindowID)
        {
            using (var scrollViewScope = new GUILayout.ScrollViewScope(scrollPos)) {
                scrollPos = scrollViewScope.scrollPosition;
                using (new GUILayout.VerticalScope()) {
                    foreach (EasyStage stage in easyStages.stages)
                    {
                        GUILayout.Label(stage.index + ":");
                        foreach (var stageEntry in stage.entries)
                        {
                            //RUI.Icons.Simple.IconLoader

                            //GameObject icon = GameObject.Instantiate(stageEntry.parts[0].partInfo.iconPrefab);

                            if (stageEntry.parts.Count > 0)
                            {
                                using (new GUILayout.HorizontalScope()) {
                                    RawImage texture = StageIconHelper.getStageTexture(stageEntry.parts[0].stackIcon.StageIcon);
                                    //GUI.DrawTextureWithTexCoords(new Rect(10, 50 * stageEntry.indexInStage, 50, 50), texture.texture, texture.uvRect);
                                    GUILayout.Space(40);
                                    if (Event.current.type == EventType.Repaint)
                                    {
                                        stageEntry.rect        = GUILayoutUtility.GetLastRect();
                                        stageEntry.rect.height = stageEntry.rect.width = 40;
                                    }
                                    GUI.DrawTextureWithTexCoords(stageEntry.rect, texture.texture, texture.uvRect);
                                    if (GUILayout.Button(stageEntry.parts[0].partInfo.name + "(" + stageEntry.parts.Count + ") " + stageEntry.parts[0].craftID))
                                    {
                                        highlight(stageEntry);
                                    }
                                    if (GUILayout.Button("Move to 0"))
                                    {
                                        //EditorLogic.fetch.SetBackup();

                                        stageEntry.parts[0].inverseStage = 0;

                                        for (int j = StageManager.Instance.Stages.Count - 1; j >= 0; j--)
                                        {
                                            UnityEngine.Object.Destroy(StageManager.Instance.Stages[j].gameObject);
                                        }
                                        StageManager.Instance.Stages.Clear();

                                        //The only sane way to restet staging manager is to create two ship backups one after another and then simulate "undo" action.
                                        //The other options would be to save ship to disc and load it immediately, but this completely wipes out undo history
                                        //EditorLogic.fetch.SetBackup();
                                        //EditorLogic.fetch.SetBackup();
                                        //EditorLogic.fetch.GetType().GetMethod("RestoreState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(EditorLogic.fetch, new object[] { -1 });

                                        //EditorLogic.fetch.SetBackup();
                                        //if (this.selectedPart != null) {
                                        //	this.displayAttachNodeIcons(false, false, false);
                                        //}
                                        //if (this.ship.Any<Part>()) {
                                        //	Object.Destroy(this.rootPart.gameObject);
                                        //}
                                        //this.undoLevel = num;
                                        //this.ship = ShipConstruction.RestoreBackup(EditorLogic.fetch.undoLevel - 1);
                                        ////this.rootPart = this.ship.parts[0].localRoot;
                                        ////ShipConstruction.SanitizeCraftIDs(this.ship.parts, false);
                                        ////ShipConstruction.ShipConfig = this.ship.SaveShip();
                                        //GameEvents.onEditorRestoreState.Fire();
                                        ////this.RefreshCrewAssignment(ShipConstruction.ShipConfig, this.GetPartExistsFilter());
                                        //GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
                                        //GameEvents.onEditorUndo.Fire(EditorLogic.fetch.ship);
                                        //this.fsm.RunEvent(this.on_undoRedo);


                                        //StageManager.CurrentStage = 0;
                                        //StageManager.Instance.SortIcons(true);
                                        //StageManager.SetSeparationIndices(EditorLogic.RootPart, 0);

                                        //stageEntry.parts[0].stackIcon.StageIcon.group
                                        //StageManager.SetSeparationIndices(EditorLogic.RootPart, 0);
                                        //StageManager.Instance.UpdateStageGroups(false);
                                        //StageManager.Instance.Stages.Clear();
                                        //StageManager.GenerateStagingSequence(EditorLogic.RootPart);
                                        //StageManager.Instance.SortIcons(false);

                                        //EditorLogic editor = EditorLogic.fetch;
                                        //ConfigNode shipCfg = editor.ship.SaveShip();

                                        //string filename = "saves/" + HighLogic.SaveFolder + "/Ships/VAB/StagingEditor.craft.hidden";
                                        //shipCfg.Save(filename);
                                        //EditorLogic.LoadShipFromFile(filename);
                                        //EditorLogic.fetch.SetBackup();

                                        //ProtoStageIcon i;

                                        //stageEntry.parts[0].stackIcon.Highlight(true);

                                        //KSP.UI.Screens.StageIcon stageIcon = UnityEngine.Object.Instantiate<KSP.UI.Screens.StageIcon>(KSP.UI.Screens.StageManager.Instance.stageIconPrefab);
                                        //stageIcon.Setup(stageEntry.parts[0].stackIcon);
                                        //stageIcon.transform.localPosition = new Vector3(100, 100, 0);
                                        //stageIcon.transform.setPa

                                        //PluginLogger.logDebug(Globals.join( new RUI.Icons.Selectable.IconLoader().iconDictionary.Keys, ","));
                                        //stageEntry.parts[0].stackIcon.StageIcon.ProtoIcon.Stage

                                        //stageEntry.parts[0].stagingIcon;
                                        //PluginLogger.logDebug("debug:" + stageEntry.parts[0].stackIcon.);
                                    }
                                }
                            }
                        }


                        //if (GUILayout.Button(p.partInfo.name + (p.symmetryCounterparts.Count > 0 ? "--" + p.symmetryCounterparts.Count : ""))) {
                        //	p.highlight(new Color(1, 0, 0));
                        //	drawLine(p.transform.position);
                        //	foreach (Part p2 in p.symmetryCounterparts) {
                        //		p2.highlight(new Color(0, 1, 0));
                        //	}
                        //}
                    }
                    //foreach (Part p in EditorLogic.SortedShipList) {
                    //	if (p.hasStagingIcon && p.stagingOn) {
                    //		if (GUILayout.Button(p.partInfo.name + (p.symmetryCounterparts.Count > 0 ? "--" + p.symmetryCounterparts.Count : ""))) {
                    //			p.highlight(new Color(1, 0, 0));
                    //			drawLine(p.transform.position);
                    //			foreach (Part p2 in p.symmetryCounterparts) {
                    //				p2.highlight(new Color(0, 1, 0));
                    //			}
                    //		}
                    //	}
                    //}
                }
            }
            stagingCamera = GUILayout.Toggle(stagingCamera, "Staging camera");
            if (GUILayout.Button("Debug"))
            {
                PluginLogger.logDebug(EditorLogic.fetch.editorCamera.transform.position);
                PluginLogger.logDebug(EditorLogic.fetch.editorCamera.transform.forward);
                destroyHighlightObjects();
            }
            if (GUILayout.Button("apply"))
            {
                EditorLogic.fetch.SetBackup();
                EditorLogic.fetch.SetBackup();
                EditorLogic.fetch.GetType().GetMethod("RestoreState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(EditorLogic.fetch, new object[] { -1 });
                destroyHighlightObjects();
            }

            GUI.DragWindow();
        }
Exemplo n.º 7
0
        public void OnGUI()
        {
            if (Event.current.type == EventType.MouseDown)
            {
                PluginLogger.logDebug("OnGUI");

                PluginLogger.logDebug("removing old");
                removeGameObject("MouseRayLine");

                Camera  camera = Camera.main;
                Ray     mouseRay;
                Vector3 worldStart;
                Vector3 worldDirection;
                if (MapView.MapIsEnabled)
                {
                    body   = Planetarium.fetch.CurrentMainBody;
                    camera = PlanetariumCamera.Camera;

                    mouseRay        = camera.ScreenPointToRay(Input.mousePosition);
                    mouseRay.origin = mouseRay.origin;

                    PluginLogger.logDebug(mouseRay);

                    Vector3 toDrawStart = mouseRay.origin;
                    Vector3 toDrawEnd   = mouseRay.origin + mouseRay.direction * (float)body.Radius;

                    PluginLogger.logDebug(toDrawStart + "->" + toDrawEnd);
                    PluginLogger.logDebug(ScaledSpace.LocalToScaledSpace(body.position));


                    GameObject lineObj = addGameObject(new GameObject("MouseRayLine"));
                    lineObj.layer = 9;
                    LineRenderer line = lineObj.AddComponent <LineRenderer>();
                    line.useWorldSpace              = true;
                    line.transform.localPosition    = Vector3.zero;
                    line.transform.localEulerAngles = Vector3.zero;

                    // Make it render a red to yellow triangle, 1 meter wide and 2 meters long
                    line.material = new Material(Shader.Find("Particles/Additive"));
                    line.SetColors(Color.green, Color.red);
                    line.SetWidth((float)10 / 1000 * PlanetariumCamera.fetch.Distance, (float)10 / 1000 * PlanetariumCamera.fetch.Distance);

                    line.SetVertexCount(2);
                    //line.SetPosition(0, ScaledSpace.LocalToScaledSpace(body.position + new Vector3(1, 0, 0) * (float)body.Radius *5));
                    //line.SetPosition(1, ScaledSpace.LocalToScaledSpace(body.position));

                    //line.SetPosition(0, toDrawStart);
                    line.SetPosition(0, toDrawStart + new Vector3(0, -1, 0));
                    line.SetPosition(1, toDrawEnd);

                    worldStart     = ScaledSpace.ScaledToLocalSpace(mouseRay.origin);
                    worldDirection = mouseRay.direction;
                }
                else
                {
                    //Input.mousePosition = new Vector2(Event.current.mousePosition.x, Screen.height - Event.current.mousePosition.y)
                    mouseRay = camera.ScreenPointToRay(Input.mousePosition);

                    PluginLogger.logDebug(Input.mousePosition);
                    PluginLogger.logDebug(camera.ScreenToWorldPoint(Event.current.mousePosition));
                    PluginLogger.logDebug(mouseRay);

                    PluginLogger.logDebug(camera.transform.position);



                    //mouseRay.origin = ScaledSpace.ScaledToLocalSpace(mouseRay.origin);

                    GameObject   lineObj = addGameObject(new GameObject("MouseRayLine"));
                    LineRenderer line    = lineObj.AddComponent <LineRenderer>();
                    line.useWorldSpace              = true;
                    line.transform.localPosition    = Vector3.zero;
                    line.transform.localEulerAngles = Vector3.zero;

                    // Make it render a red to yellow triangle, 1 meter wide and 2 meters long
                    line.material = new Material(Shader.Find("Particles/Additive"));
                    line.SetColors(Color.red, Color.red);
                    line.SetWidth(1, 1);

                    line.SetVertexCount(2);
                    line.SetPosition(0, mouseRay.origin);
                    line.SetPosition(1, mouseRay.origin + mouseRay.direction * 1000);

                    worldStart     = mouseRay.origin;
                    worldDirection = mouseRay.direction;
                }



                Vector3d intersectionPoint = new Vector3d();
                Vector3d bodyToMouse       = worldStart - body.position;
                float    radius            = (float)body.pqsController.radiusMax;
                //if (body.pqsController.RayIntersection(worldStart, worldDirection, out intersectionPoint)) {
                if (PQS.LineSphereIntersection(bodyToMouse, mouseRay.direction, radius, out intersectionPoint))
                {
                    PluginLogger.logDebug("intersect!");
                }
                else
                {
                    PluginLogger.logDebug("No hit!");
                }

                //mouseRay.origin = ScaledSpace.ScaledToLocalSpace(mouseRay.origin);
            }
        }
Exemplo n.º 8
0
        public void onPlanetariumTargetChanged(MapObject map)
        {
            PluginLogger.logDebug("onPlanetariumTargetChanged");

            //map.celestialBody.pqsController.RayIntersection(worldStart, worldDirection, intersectionDistance);
        }
Exemplo n.º 9
0
 public void OnDisable()
 {
     PluginLogger.logDebug("OnDisable in " + EditorDriver.editorFacility);
 }
Exemplo n.º 10
0
 public void OnDestroy()
 {
     PluginLogger.logDebug("OnDestroy in " + EditorDriver.editorFacility);
     CleanUp();
 }