private void DrawPart(Part part) { // Someday we may work on making this into something that // actually draws out the part image like in the editor icons, however // there appears to be no KSP API to do this for us, and it's a bit messy // and there's more important other stuff to do first. // // In the meantime, this is as far as my research has taken me: // Step 1: get a Unity GameObject from the part prototype, like so: // GameObject prototypeGO = part.partInfo.iconPrefab; // Also, it seems to be using some proprietary extension to Unity's GUI // called EZGui to render some sort of camera view of the gameobject inside the // button, and EZGui is even worse for online documentation than Unity itself, // so whatever the technique is, it's hidden behind a wall of impenetrable // documentation with zero examples. // So for the meantime let's use our own text label and leave it at that. KOSNameTag partTag = part.Modules.OfType <KOSNameTag>().FirstOrDefault(); string labelText = String.Format("{0}\n({1})", part.partInfo.title.Split(' ')[0], // just the first word of the name, i.e "CX-4181" ((partTag == null) ? "" : partTag.nameTag) ); GUILayout.Box(new GUIContent(labelText, "This is the currently highlighted part on the vessel"), partNameStyle); }
private int numberOfRepaints = 0; // "explicit", not "redundant". // ReSharper enable RedundantDefaultFieldInitializer public void Invoke(KOSNameTag module, string oldValue) { attachedModule = module; tagValue = oldValue; 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 = 200; // windowRect = new Rect(xPixelWindow, yPixelPoint, windowWidth, 130); windowRect = new Rect(xPixelPoint, yPixelPoint, WINDOW_WIDTH, 130); // Please don't delete these. They're not being used, but that's because we haven't // finished prettying up the interface with the tag line and so the coords aren't // being made use of yet. But keep this in the code so I can remember how I did the math: // -------------------------------------------------------------------------------------- // bool drawOnLeft = (screenPos.x > 0.5f); // float xPixelWindow = (drawOnLeft ? screenPos.x - 0.3f : screenPos.x + 0.2f) * UnityEngine.Screen.width; // float tagLineWidth = (drawOnLeft) ? (xPixelPoint - xPixelWindow) : (xPixelWindow - xPixelPoint - windowWidth); // tagLineRect = new Rect(xPixelPoint, yPixelPoint, tagLineWidth, 3); // SafeHouse.Logger.Log("tagLineRect = " + tagLineRect ); SetEnabled(true); if (HighLogic.LoadedSceneIsEditor) { attachedModule.part.SetHighlight(false, false); } }
private void SetTagName(string value) { KOSNameTag tagModule = Part.Modules.OfType <KOSNameTag>().FirstOrDefault(); if (tagModule != null) { tagModule.nameTag = value; } }
private void SetTagName(StringValue value) { ThrowIfNotCPUVessel(); KOSNameTag tagModule = Part.Modules.OfType <KOSNameTag>().FirstOrDefault(); if (tagModule != null) { tagModule.nameTag = value; } }
internal string CalcualteTitle() { KOSNameTag partTag = shared.KSPPart.Modules.OfType <KOSNameTag>().FirstOrDefault(); return(String.Format("{0} CPU: {1} ({2})", shared.Vessel.vesselName, shared.KSPPart.partInfo.title.Split(' ')[0], // just the first word of the name, i.e "CX-4181" ((partTag == null) ? "" : partTag.nameTag) )); }
void OnGUI() { if (!IsOpen()) { return; } if (isLocked) { ProcessKeyStrokes(); } try { if (PauseMenu.isOpen || FlightResultsDialog.isDisplaying) { return; } } catch (NullReferenceException) { } GUI.skin = HighLogic.Skin; GUI.color = isLocked ? color : colorAlpha; // Should probably make "gui screen name for my CPU part" into some sort of utility method: KOSNameTag partTag = shared.KSPPart.Modules.OfType <KOSNameTag>().FirstOrDefault(); string labelText = String.Format("{0} CPU: {1} ({2})", shared.Vessel.vesselName, shared.KSPPart.partInfo.title.Split(' ')[0], // just the first word of the name, i.e "CX-4181" ((partTag == null) ? "" : partTag.nameTag) ); windowRect = GUI.Window(uniqueId, windowRect, TerminalGui, labelText); if (consumeEvent) { consumeEvent = false; Event.current.Use(); } }
private void PrintCPUMenu() { localMenuBuffer.Remove(0, localMenuBuffer.Length); // Any time the menu is reprinted, clear out any previous buffer text. telnetServer.ReadAll(); // Consume and throw away any readahead typing that preceeded the printing of this menu. forceMenuReprint = false; telnetServer.Write("Terminal: type = " + telnetServer.ClientTerminalType + ", size = " + telnetServer.ClientWidth + "x" + telnetServer.ClientHeight + (char)UnicodeCommand.STARTNEXTLINE); telnetServer.Write(CenterPadded("", '_') /*line of '-' chars*/ + (char)UnicodeCommand.STARTNEXTLINE); const string FORMATTER = "{0,4} {1,4} {2,4} {3} {4} {5}"; int userPickNum = 1; int longestLength = 0; List <string> displayChoices = new List <string> { String.Format(FORMATTER, "Menu", "GUI ", " Other ", "", "", ""), String.Format(FORMATTER, "Pick", "Open", "Telnets", "", "Vessel Name", "(CPU tagname)"), String.Format(FORMATTER, "----", "----", "-------", "", "--------------------------------", "") }; longestLength = displayChoices[2].Length; foreach (kOSProcessor kModule in availableCPUs) { Part thisPart = kModule.part; KOSNameTag partTag = thisPart.Modules.OfType <KOSNameTag>().FirstOrDefault(); string partLabel = String.Format("{0}({1})", thisPart.partInfo.title.Split(' ')[0], // just the first word of the name, i.e "CX-4181" ((partTag == null) ? "" : partTag.nameTag) ); Vessel vessel = (thisPart == null) ? null /*can this even happen?*/ : thisPart.vessel; string vesselLabel = (vessel == null) ? "<no vessel>" /*can this even happen?*/ : vessel.GetName(); bool guiOpen = kModule.GetWindow().IsOpen; int numTelnets = kModule.GetWindow().NumTelnets(); string choice = String.Format(FORMATTER, "[" + userPickNum + "]", (guiOpen ? "yes": "no"), numTelnets, " ", vesselLabel, "(" + partLabel + ")"); displayChoices.Add(choice); longestLength = Math.Max(choice.Length, longestLength); ++userPickNum; } foreach (string choice in displayChoices) { string choicePaddedToLongest = choice + new String(' ', (longestLength - choice.Length)); telnetServer.Write(CenterPadded(choicePaddedToLongest, ' ') + (char)UnicodeCommand.STARTNEXTLINE); } if (availableCPUs.Count > 0) { telnetServer.Write(CenterPadded("", '-') /*line of '-' chars*/ + (char)UnicodeCommand.STARTNEXTLINE + WordBreak("Choose a CPU to attach to by typing a " + "selection number and pressing return/enter. " + "Or enter [Q] to quit terminal server.") + (char)UnicodeCommand.STARTNEXTLINE + (char)UnicodeCommand.STARTNEXTLINE + WordBreak("(After attaching, you can (D)etach and return " + "to this menu by pressing Control-D as the first " + "character on a new command line.)") + (char)UnicodeCommand.STARTNEXTLINE + CenterPadded("", '-') /*line of '-' chars*/ + (char)UnicodeCommand.STARTNEXTLINE + "> "); } else { telnetServer.Write(CenterPadded(String.Format(FORMATTER, "", "", "", "", "<NONE>", ""), ' ') + (char)UnicodeCommand.STARTNEXTLINE); } }
public StringValue GetTagName() // public because I picture this being a useful API method later { KOSNameTag tagModule = Part.Modules.OfType <KOSNameTag>().FirstOrDefault(); return(tagModule == null ? string.Empty : tagModule.nameTag); }