Skip to content

Commit 131d33a

Browse files
author
hashashin
committed
0.11
Interface changes to improve usability, fixed issue with refresh button texture size being not power of 2.
1 parent 15aed9b commit 131d33a

File tree

1 file changed

+185
-41
lines changed

1 file changed

+185
-41
lines changed

notes.cs

Lines changed: 185 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// -------------------------------------------------------------------------------------------------
2-
// notes.cs 0.10.1
2+
// notes.cs 0.11
33
//
44
// Simple KSP plugin to take notes ingame.
5-
// Copyright (C) 2014 Iván Atienza
5+
// Copyright (C) 2015 Iván Atienza
66
//
77
// This program is free software: you can redistribute it and/or modify
88
// it under the terms of the GNU General Public License as published by
@@ -110,7 +110,7 @@ public class Notes : MonoBehaviour
110110
private int _selectDirGridInt;
111111

112112
// The text of the note.
113-
private string _text;
113+
public static string _text;
114114

115115
// true to show delete button, false to hide.
116116
private bool _toggleDel;
@@ -131,10 +131,10 @@ public class Notes : MonoBehaviour
131131
private string _versionLastRun;
132132

133133
// The vessel info.
134-
private string _vesselInfo;
134+
public static string _vesselInfo;
135135

136136
// The vessel name.
137-
private string _vesselName;
137+
private static string _vesselName;
138138

139139
// true to show the plugin window, false to hide.
140140
private bool _visible;
@@ -145,14 +145,26 @@ public class Notes : MonoBehaviour
145145
// The rectangle for list windows.
146146
private Rect _windowRect2;
147147

148+
// rectangles for the dialogs windows
149+
private Rect _windowRect3; //delete
150+
151+
private Rect _windowRect4; //delete directory
152+
153+
private Rect _windowRect5; //reload note
154+
155+
private Rect _windowRect6; //new note
156+
148157
//true use ksp skin, false use unity stock.
149158
private bool _useKspSkin;
150159

151160
private List<string> _dirs;
152161

153162
private string _newdir = "newdir";
154163

155-
private string _deldir = String.Empty;
164+
private bool _showdeldial;
165+
private bool _showdeldirdial;
166+
private bool _showreloaddial;
167+
private bool _shownewnotedial;
156168

157169

158170
// Awakes the plugin.
@@ -175,9 +187,74 @@ private void Delete()
175187
ScreenMessages.PostScreenMessage(_fileNames[_selectFileGridInt] + ".txt DELETED!", 3f);
176188
}
177189
}
190+
// Delete note dialog
191+
private void DelWindow(int windowId)
192+
{
193+
GUILayout.BeginVertical();
194+
GUILayout.BeginHorizontal();
195+
GUI.contentColor = Color.red;
196+
GUILayout.Label("Are you sure want to delete: " + _fileNames[_selectFileGridInt] + "?");
197+
GUI.contentColor = Color.white;
198+
GUILayout.BeginVertical();
199+
if (GUILayout.Button("Yes"))
200+
{
201+
Delete();
202+
_fileNames = null;
203+
_showList = false;
204+
GetNotes();
205+
_showList = true;
206+
_showdeldial = false;
207+
}
208+
GUILayout.EndVertical();
209+
GUILayout.BeginVertical();
210+
if (GUILayout.Button("No"))
211+
{
212+
_showdeldial = false;
213+
}
214+
GUILayout.EndVertical();
215+
GUILayout.EndHorizontal();
216+
GUILayout.EndVertical();
217+
GUI.DragWindow();
218+
}
219+
//delete directory dialog
220+
private void DelDirWindow(int windowId)
221+
{
222+
GUILayout.BeginVertical();
223+
GUILayout.BeginHorizontal();
224+
GUI.contentColor = Color.red;
225+
GUILayout.Label("Are you sure want to delete: " + _dirs[_selectDirGridInt] + "?");
226+
GUI.contentColor = Color.white;
227+
GUILayout.BeginVertical();
228+
if (GUILayout.Button("Yes"))
229+
{
230+
try
231+
{
232+
Directory.Delete(_notesDir + _dirs[_selectDirGridInt]);
233+
}
234+
catch (Exception)
235+
{
236+
ScreenMessages.PostScreenMessage("You need empty the folder before try to delete it.", 3f);
237+
}
238+
_fileNames = null;
239+
_showList = false;
240+
GetNotes();
241+
_showList = true;
242+
_showdeldirdial = false;
243+
}
244+
GUILayout.EndVertical();
245+
GUILayout.BeginVertical();
246+
if (GUILayout.Button("No"))
247+
{
248+
_showdeldirdial = false;
249+
}
250+
GUILayout.EndVertical();
251+
GUILayout.EndHorizontal();
252+
GUILayout.EndVertical();
253+
GUI.DragWindow();
254+
}
178255

179256
// Get vessel log information.
180-
private void GetLogInfo()
257+
public static void GetLogInfo()
181258
{
182259
if (!HighLogic.LoadedSceneIsFlight || !HighLogic.LoadedSceneHasPlanetarium) return;
183260
double _seconds = Planetarium.GetUniversalTime();
@@ -250,14 +327,14 @@ private void ListWindow(int windowId)
250327
GUILayout.BeginHorizontal();
251328
GUILayout.BeginVertical();
252329
// Loads selected note in the list.
253-
if (GUILayout.Button("Load selected"))
330+
if (GUILayout.Button("Load Selected File"))
254331
{
255332
_file = _fileNames[_selectFileGridInt];
256333
Load();
257334
_fileNames = null;
258335
_showList = false;
259336
}
260-
if (GUILayout.Button("Change Dir"))
337+
if (GUILayout.Button("Change to Selected Directory"))
261338
{
262339
if (_dirs.Count == 0)
263340
{
@@ -278,7 +355,7 @@ private void ListWindow(int windowId)
278355
}
279356
}
280357
GUILayout.BeginHorizontal();
281-
if (GUILayout.Button("Create Dir"))
358+
if (GUILayout.Button("Create Directory"))
282359
{
283360
Directory.CreateDirectory(_notesDir + _newdir);
284361
_fileNames = null;
@@ -289,22 +366,23 @@ private void ListWindow(int windowId)
289366
_newdir = GUILayout.TextField(_newdir);
290367
GUILayout.EndHorizontal();
291368
GUILayout.BeginHorizontal();
292-
if (GUILayout.Button("Delete Dir"))
369+
GUI.contentColor = Color.red;
370+
if (_dirs.Count > 0)
293371
{
294-
try
372+
if (GUILayout.Button("Delete Directory"))
295373
{
296-
Directory.Delete(_notesDir + _deldir);
374+
_showdeldirdial = true;
297375
}
298-
catch (Exception)
376+
}
377+
// Delete the selected note.
378+
if (_fileNames.Count > 0)
379+
{
380+
if (GUILayout.Button("Delete File"))
299381
{
300-
ScreenMessages.PostScreenMessage("You need to write the name of the folder or empty it before try to delete.", 3f);
382+
_showdeldial = true;
301383
}
302-
_fileNames = null;
303-
_showList = false;
304-
GetNotes();
305-
_showList = true;
306384
}
307-
_deldir = GUILayout.TextField(_deldir);
385+
GUI.contentColor = Color.white;
308386
GUILayout.EndHorizontal();
309387
GUILayout.EndVertical();
310388
// Refresh the notes list.
@@ -316,23 +394,6 @@ private void ListWindow(int windowId)
316394
GetNotes();
317395
_showList = true;
318396
}
319-
GUILayout.BeginVertical();
320-
// Toggle the delete button visibility to avoid missclicks.
321-
if (_toggleDel = GUILayout.Toggle(_toggleDel, _currentDelText))
322-
{
323-
GUI.contentColor = Color.red;
324-
// Delete the selected note.
325-
if (GUILayout.Button("Delete"))
326-
{
327-
Delete();
328-
_fileNames = null;
329-
_showList = false;
330-
GetNotes();
331-
_showList = true;
332-
}
333-
GUI.contentColor = Color.white;
334-
}
335-
GUILayout.EndVertical();
336397
GUILayout.EndHorizontal();
337398
GUILayout.BeginHorizontal();
338399
_scrollViewVector2 = GUILayout.BeginScrollView(_scrollViewVector2);
@@ -395,8 +456,13 @@ private void LoadSettings()
395456
_configFile.load();
396457

397458
_windowRect = _configFile.GetValue("main window position", new Rect(50f, 25f, 425f, 487f));
398-
_windowRect2 = _configFile.GetValue("list window position", new Rect(Screen.width / 2 - 150f,
399-
Screen.height / 2 - 75f, 520f, 390f));
459+
_windowRect2 = _configFile.GetValue("list window position", new Rect(Screen.width / 2f - 150f,
460+
Screen.height / 2f - 75f, 520f, 390f));
461+
_windowRect3 = _configFile.GetValue("del dialog position", new Rect(Screen.width / 2f - 150f,
462+
Screen.height / 2f - 75f, 220f, 100f));
463+
_windowRect4 = _windowRect3;
464+
_windowRect5 = _windowRect3;
465+
_windowRect6 = _windowRect3;
400466
_keybind = _configFile.GetValue("keybind", "n");
401467
_keybind2 = _configFile.GetValue("keybind2", "l");
402468
_versionLastRun = _configFile.GetValue<string>("version");
@@ -437,9 +503,9 @@ private void NotesWindow(int windowId)
437503
// Show the actual note file name.
438504
_file = GUI.TextField(new Rect(5f, 410f, 150f, 20f), _file);
439505
// Load note file button.
440-
if (GUI.Button(new Rect(155f, 410f, 80f, 30f), "Load"))
506+
if (GUI.Button(new Rect(155f, 410f, 80f, 30f), "Reload"))
441507
{
442-
Load();
508+
_showreloaddial = true;
443509
}
444510
// Save note file button.
445511
if (GUI.Button(new Rect(235f, 410f, 80f, 30f), "Save"))
@@ -459,6 +525,11 @@ private void NotesWindow(int windowId)
459525
_showList = true;
460526
}
461527
}
528+
//New file
529+
if (GUI.Button(new Rect(155f, 445f, 80f, 30f), "New Note"))
530+
{
531+
_shownewnotedial = true;
532+
}
462533
// Close the notes window.
463534
if (GUI.Button(new Rect(2f, 2f, 13f, 13f), "X"))
464535
{
@@ -501,6 +572,7 @@ private void NotesWindow(int windowId)
501572
_file = _fileNames[_selectFileGridInt];
502573
Load();
503574
}
575+
GUI.Label(new Rect(340f, 0f, 60, 20f), _version);
504576
// If we are on flight show the vessel logs buttons
505577
if (HighLogic.LoadedSceneIsFlight && HighLogic.LoadedSceneHasPlanetarium)
506578
{
@@ -532,6 +604,57 @@ private void NotesWindow(int windowId)
532604
// Make this window dragable
533605
GUI.DragWindow();
534606
}
607+
//reload dialog
608+
private void Reloaddial(int windowId)
609+
{
610+
GUILayout.BeginVertical();
611+
GUILayout.BeginHorizontal();
612+
GUI.contentColor = Color.red;
613+
GUILayout.Label("Are you sure want to load/reload: " + _file + "? Unsaved changes will be lost!");
614+
GUI.contentColor = Color.white;
615+
GUILayout.BeginVertical();
616+
if (GUILayout.Button("Yes"))
617+
{
618+
Load();
619+
_showreloaddial = false;
620+
}
621+
GUILayout.EndVertical();
622+
GUILayout.BeginVertical();
623+
if (GUILayout.Button("No"))
624+
{
625+
_showreloaddial = false;
626+
}
627+
GUILayout.EndVertical();
628+
GUILayout.EndHorizontal();
629+
GUILayout.EndVertical();
630+
GUI.DragWindow();
631+
}
632+
//new note dialog
633+
private void NewFiledial(int windowId)
634+
{
635+
GUILayout.BeginVertical();
636+
GUILayout.BeginHorizontal();
637+
GUI.contentColor = Color.red;
638+
GUILayout.Label("Are you sure want to create new file? Unsaved changes will be lost!");
639+
GUI.contentColor = Color.white;
640+
GUILayout.BeginVertical();
641+
if (GUILayout.Button("Yes"))
642+
{
643+
_file = "newnote";
644+
_text = String.Empty;
645+
_shownewnotedial = false;
646+
}
647+
GUILayout.EndVertical();
648+
GUILayout.BeginVertical();
649+
if (GUILayout.Button("No"))
650+
{
651+
_shownewnotedial = false;
652+
}
653+
GUILayout.EndVertical();
654+
GUILayout.EndHorizontal();
655+
GUILayout.EndVertical();
656+
GUI.DragWindow();
657+
}
535658

536659
// Executes the destroy action.
537660
private void OnDestroy()
@@ -560,6 +683,26 @@ private void OnGUI()
560683
"Notes list");
561684
UpdateDelButtonText();
562685
}
686+
if (_showdeldial)
687+
{
688+
_windowRect3 = GUI.Window(GUIUtility.GetControlID(FocusType.Passive), _windowRect3, DelWindow,
689+
"File Deletion Dialog");
690+
}
691+
if (_showdeldirdial)
692+
{
693+
_windowRect4 = GUI.Window(GUIUtility.GetControlID(FocusType.Passive), _windowRect4, DelDirWindow,
694+
"Directory Deletion Dialog");
695+
}
696+
if (_showreloaddial)
697+
{
698+
_windowRect5 = GUI.Window(GUIUtility.GetControlID(FocusType.Passive), _windowRect5, Reloaddial,
699+
"File Reload Dialog");
700+
}
701+
if (_shownewnotedial)
702+
{
703+
_windowRect6 = GUI.Window(GUIUtility.GetControlID(FocusType.Passive), _windowRect6, NewFiledial,
704+
"New File Dialog");
705+
}
563706
//Restore the skin
564707
GUI.skin = _defGuiSkin;
565708
}
@@ -601,6 +744,7 @@ private void SaveSettings()
601744

602745
_configFile.SetValue("main window position", _windowRect);
603746
_configFile.SetValue("list window position", _windowRect2);
747+
_configFile.SetValue("del dialog position", _windowRect3);
604748
_configFile.SetValue("keybind", _keybind);
605749
_configFile.SetValue("keybind2", _keybind2);
606750
_configFile.SetValue("version", _version);

0 commit comments

Comments
 (0)