protected Dialog(string windowTitle, float defaultWidth, float defaultHeight) { WindowTitle = windowTitle; windowId = windowTitle.GetHashCode() + new System.Random().Next(65536) + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.GetHashCode(); configNodeName = windowTitle.Replace(" ", ""); windowPos = new Rect((Screen.width - defaultWidth) / 2, (Screen.height - defaultHeight) / 2, defaultWidth, defaultHeight); mouseDown = false; visible = false; var texture = DialogUtils.LoadImage <T>(IOUtils.GetFilePathFor(typeof(T), "resize.png")); resizeContent = (texture != null) ? new GUIContent(texture, "Drag to resize the window.") : new GUIContent("R", "Drag to resize the window."); Resizable = true; HideCloseButton = false; }
public virtual ConfigNode Load(ConfigNode config) { if (config.HasNode(configNodeName)) { ConfigNode windowConfig = config.GetNode(configNodeName); windowPos.x = DialogUtils.GetValue(windowConfig, "x", windowPos.x); windowPos.y = DialogUtils.GetValue(windowConfig, "y", windowPos.y); windowPos.width = DialogUtils.GetValue(windowConfig, "width", windowPos.width); windowPos.height = DialogUtils.GetValue(windowConfig, "height", windowPos.height); bool newValue = DialogUtils.GetValue(windowConfig, "visible", visible); SetVisible(newValue); return(windowConfig); } else { return(null); } }
//Note: parent object needs to call DrawWindow in its OnGUI method. public virtual void DrawWindow() { if (visible) { bool paused = false; if (HighLogic.LoadedSceneIsFlight) { try { paused = PauseMenu.isOpen || FlightResultsDialog.isDisplaying; } catch (Exception) { // ignore the error and assume the pause menu is not open } } if (!paused) { GUI.skin = HighLogic.Skin; ConfigureStyles(); windowPos = DialogUtils.EnsureVisible(windowPos); windowPos = GUILayout.Window(windowId, windowPos, PreDrawWindowContents, WindowTitle, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MinWidth(64), GUILayout.MinHeight(64)); } Vector3 mousePosition = Input.mousePosition; if (windowPos.Contains(mousePosition)) { InputLockManager.SetControlLock(ControlTypes.ALLBUTCAMERAS, "WindowLock" + windowId); } else { InputLockManager.RemoveControlLock("WindowLock" + windowId); } } }