protected void FileSelectedCallback (string path) { m_fileBrowser = null; fileBrowserEnabled = false; m_textPath = path; if (m_textPath != "" && m_textPath != null) { if (selectionType == ".craft") { #if EXPORT if (downloadState == downloadStateType.UPLOAD_FILESELECTION) downloadState = downloadStateType.UPLOAD; else #endif downloadState = downloadStateType.GUI; craftURL = "file://" + m_textPath; thisCI.configuration.lastImportDir = System.IO.Path.GetDirectoryName (m_textPath); return; } } if (m_textPath != "" && m_textPath != null) { if (selectionType == ".png|.jpg") { #if EXPORT downloadState = downloadStateType.UPLOAD; pictureUrl = "file://" + m_textPath; #endif //CI.configuration.lastImportDir = System.IO.Path.GetDirectoryName (m_textPath); return; } } //Log.Info ("downloadState: " + downloadState.ToString ()); downloadState = downloadStateType.GUI; }
///////////////////////////////////// public void OnGUI () { GUI.skin = HighLogic.Skin; if (Event.current.type == EventType.Repaint || Event.current.isMouse) { DrawCall(); // Your current on preDrawQueue code } #if EXPORT Awake (); #endif // InputLockManager.SetControlLock((ControlTypes.EDITOR_LOCK | ControlTypes.EDITOR_GIZMO_TOOLS), "CraftImportLock"); if (m_fileBrowser != null) { if (!fileBrowserEnabled) { m_fileBrowser = null; downloadState = downloadStateType.GUI; //this one closes the dropdown if you click outside the window elsewhere // styleItems.CloseOnOutsideClick(); } else { // GUI.skin = HighLogic.Skin; #if true GUIStyle s = new GUIStyle (HighLogic.Skin.textField); s.onNormal = HighLogic.Skin.textField.onNormal; // s.fontSize = 15; s.name = "listitem"; s.alignment = TextAnchor.MiddleLeft; //s.fontStyle = FontStyle.Bold; //s.fixedHeight = 50; s.imagePosition = ImagePosition.ImageLeft; GUI.skin.customStyles [0] = s; #endif m_fileBrowser.Window (GetInstanceID ()); return; } } try { if (this.Visible ()) { // Rect bounds2 = GUILayout.Window (GetInstanceID (), bounds, Window, CI.TITLE, HighLogic.Skin.window); if (resetWinPos) { bounds = new Rect (Screen.width - WIDTH, Screen.height / 2 - HEIGHT / 2, WIDTH, HEIGHT); resetWinPos = false; } bounds = GUILayout.Window (GetInstanceID (), bounds, Window, CI.TITLE, HighLogic.Skin.window); #if EXPORT if (_image != null) { imgbounds = new Rect (imgbounds.xMin, imgbounds.yMin, displayres, displayres + 30); imgbounds = GUILayout.Window (GetInstanceID () + 1, imgbounds, imgWindow, CI.TITLE + " Upload Image Preview", HighLogic.Skin.window); } #endif } } catch (Exception e) { Log.Error ("exception: " + e.Message); } }
void getFile (string title, string suffix, string dir = "") { fileBrowserEnabled = true; selectionType = suffix; #if false GUILayout.BeginHorizontal (); GUILayout.Label ("Select Craft File: ", GUILayout.Width (100)); //GUILayout.FlexibleSpace (); GUILayout.Label (m_textPath ?? "none selected"); GUILayout.FlexibleSpace (); //if (!m_directoryImage) Log.Info ("getFile 1 m_directoryImage is null"); if (GUILayout.Button (" ... ", GUILayout.ExpandWidth (false))) { Log.Info ("creating m_fileBrowser"); #endif m_fileBrowser = new FileBrowser ( new Rect (Screen.width / 2 - BR_WIDTH / 2, Screen.height / 2 - BR_HEIGHT / 2, BR_WIDTH, BR_HEIGHT), title, FileSelectedCallback ); if (!m_directoryImage) { m_directoryImage = new Texture2D (38, 38, TextureFormat.ARGB32, false); if (GameDatabase.Instance.ExistsTexture (CI.TEXTURE_DIR + "CI-folder")) m_directoryImage = GameDatabase.Instance.GetTexture (CI.TEXTURE_DIR + "CI-folder", false); } if (!m_fileImage) { m_fileImage = new Texture2D (38, 38, TextureFormat.ARGB32, false); if (GameDatabase.Instance.ExistsTexture (CI.TEXTURE_DIR + "CI-file")) m_fileImage = GameDatabase.Instance.GetTexture (CI.TEXTURE_DIR + "CI-file", false); } // Linux change may needed here m_fileBrowser.SelectionPattern = "*" + suffix; m_fileBrowser.DirectoryImage = m_directoryImage; m_fileBrowser.FileImage = m_fileImage; m_fileBrowser.showDrives = thisCI.configuration.showDrives; m_fileBrowser.ShowNonmatchingFiles = false; if (dir != "") { m_fileBrowser.SetNewDirectory (dir); } else { if (m_textPath != "") m_fileBrowser.SetNewDirectory (m_textPath); } #if false } if (m_fileBrowser != null) Log.Info("3 m_fileBrowser not null"); GUILayout.FlexibleSpace (); GUILayout.EndHorizontal (); GUILayout.BeginHorizontal (); GUILayout.Label (" "); GUILayout.EndHorizontal (); GUILayout.BeginHorizontal (); if (GUILayout.Button ("OK", GUILayout.Width (125.0f))) {; fileBrowserEnabled = false; downloadState = downloadStateType.GUI; if (m_textPath != "") craftURL = "file://" + m_textPath; //m_fileBrowser = null; } if (GUILayout.Button ("Cancel", GUILayout.Width (125.0f))) { // Log.Info ("Cancel2"); fileBrowserEnabled = false; downloadState = downloadStateType.GUI; //m_fileBrowser = null; } GUILayout.EndHorizontal (); GUI.DragWindow (); if (m_fileBrowser != null) Log.Info("m_fileBrowser not null"); #endif }