1
1
// -------------------------------------------------------------------------------------------------
2
- // notes.cs 0.10.1
2
+ // notes.cs 0.11
3
3
//
4
4
// Simple KSP plugin to take notes ingame.
5
- // Copyright (C) 2014 Iván Atienza
5
+ // Copyright (C) 2015 Iván Atienza
6
6
//
7
7
// This program is free software: you can redistribute it and/or modify
8
8
// it under the terms of the GNU General Public License as published by
@@ -110,7 +110,7 @@ public class Notes : MonoBehaviour
110
110
private int _selectDirGridInt ;
111
111
112
112
// The text of the note.
113
- private string _text ;
113
+ public static string _text ;
114
114
115
115
// true to show delete button, false to hide.
116
116
private bool _toggleDel ;
@@ -131,10 +131,10 @@ public class Notes : MonoBehaviour
131
131
private string _versionLastRun ;
132
132
133
133
// The vessel info.
134
- private string _vesselInfo ;
134
+ public static string _vesselInfo ;
135
135
136
136
// The vessel name.
137
- private string _vesselName ;
137
+ private static string _vesselName ;
138
138
139
139
// true to show the plugin window, false to hide.
140
140
private bool _visible ;
@@ -145,14 +145,26 @@ public class Notes : MonoBehaviour
145
145
// The rectangle for list windows.
146
146
private Rect _windowRect2 ;
147
147
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
+
148
157
//true use ksp skin, false use unity stock.
149
158
private bool _useKspSkin ;
150
159
151
160
private List < string > _dirs ;
152
161
153
162
private string _newdir = "newdir" ;
154
163
155
- private string _deldir = String . Empty ;
164
+ private bool _showdeldial ;
165
+ private bool _showdeldirdial ;
166
+ private bool _showreloaddial ;
167
+ private bool _shownewnotedial ;
156
168
157
169
158
170
// Awakes the plugin.
@@ -175,9 +187,74 @@ private void Delete()
175
187
ScreenMessages . PostScreenMessage ( _fileNames [ _selectFileGridInt ] + ".txt DELETED!" , 3f ) ;
176
188
}
177
189
}
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
+ }
178
255
179
256
// Get vessel log information.
180
- private void GetLogInfo ( )
257
+ public static void GetLogInfo ( )
181
258
{
182
259
if ( ! HighLogic . LoadedSceneIsFlight || ! HighLogic . LoadedSceneHasPlanetarium ) return ;
183
260
double _seconds = Planetarium . GetUniversalTime ( ) ;
@@ -250,14 +327,14 @@ private void ListWindow(int windowId)
250
327
GUILayout . BeginHorizontal ( ) ;
251
328
GUILayout . BeginVertical ( ) ;
252
329
// Loads selected note in the list.
253
- if ( GUILayout . Button ( "Load selected " ) )
330
+ if ( GUILayout . Button ( "Load Selected File " ) )
254
331
{
255
332
_file = _fileNames [ _selectFileGridInt ] ;
256
333
Load ( ) ;
257
334
_fileNames = null ;
258
335
_showList = false ;
259
336
}
260
- if ( GUILayout . Button ( "Change Dir " ) )
337
+ if ( GUILayout . Button ( "Change to Selected Directory " ) )
261
338
{
262
339
if ( _dirs . Count == 0 )
263
340
{
@@ -278,7 +355,7 @@ private void ListWindow(int windowId)
278
355
}
279
356
}
280
357
GUILayout . BeginHorizontal ( ) ;
281
- if ( GUILayout . Button ( "Create Dir " ) )
358
+ if ( GUILayout . Button ( "Create Directory " ) )
282
359
{
283
360
Directory . CreateDirectory ( _notesDir + _newdir ) ;
284
361
_fileNames = null ;
@@ -289,22 +366,23 @@ private void ListWindow(int windowId)
289
366
_newdir = GUILayout . TextField ( _newdir ) ;
290
367
GUILayout . EndHorizontal ( ) ;
291
368
GUILayout . BeginHorizontal ( ) ;
292
- if ( GUILayout . Button ( "Delete Dir" ) )
369
+ GUI . contentColor = Color . red ;
370
+ if ( _dirs . Count > 0 )
293
371
{
294
- try
372
+ if ( GUILayout . Button ( "Delete Directory" ) )
295
373
{
296
- Directory . Delete ( _notesDir + _deldir ) ;
374
+ _showdeldirdial = true ;
297
375
}
298
- catch ( Exception )
376
+ }
377
+ // Delete the selected note.
378
+ if ( _fileNames . Count > 0 )
379
+ {
380
+ if ( GUILayout . Button ( "Delete File" ) )
299
381
{
300
- ScreenMessages . PostScreenMessage ( "You need to write the name of the folder or empty it before try to delete." , 3f ) ;
382
+ _showdeldial = true ;
301
383
}
302
- _fileNames = null ;
303
- _showList = false ;
304
- GetNotes ( ) ;
305
- _showList = true ;
306
384
}
307
- _deldir = GUILayout . TextField ( _deldir ) ;
385
+ GUI . contentColor = Color . white ;
308
386
GUILayout . EndHorizontal ( ) ;
309
387
GUILayout . EndVertical ( ) ;
310
388
// Refresh the notes list.
@@ -316,23 +394,6 @@ private void ListWindow(int windowId)
316
394
GetNotes ( ) ;
317
395
_showList = true ;
318
396
}
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 ( ) ;
336
397
GUILayout . EndHorizontal ( ) ;
337
398
GUILayout . BeginHorizontal ( ) ;
338
399
_scrollViewVector2 = GUILayout . BeginScrollView ( _scrollViewVector2 ) ;
@@ -395,8 +456,13 @@ private void LoadSettings()
395
456
_configFile . load ( ) ;
396
457
397
458
_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 ;
400
466
_keybind = _configFile . GetValue ( "keybind" , "n" ) ;
401
467
_keybind2 = _configFile . GetValue ( "keybind2" , "l" ) ;
402
468
_versionLastRun = _configFile . GetValue < string > ( "version" ) ;
@@ -437,9 +503,9 @@ private void NotesWindow(int windowId)
437
503
// Show the actual note file name.
438
504
_file = GUI . TextField ( new Rect ( 5f , 410f , 150f , 20f ) , _file ) ;
439
505
// 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 " ) )
441
507
{
442
- Load ( ) ;
508
+ _showreloaddial = true ;
443
509
}
444
510
// Save note file button.
445
511
if ( GUI . Button ( new Rect ( 235f , 410f , 80f , 30f ) , "Save" ) )
@@ -459,6 +525,11 @@ private void NotesWindow(int windowId)
459
525
_showList = true ;
460
526
}
461
527
}
528
+ //New file
529
+ if ( GUI . Button ( new Rect ( 155f , 445f , 80f , 30f ) , "New Note" ) )
530
+ {
531
+ _shownewnotedial = true ;
532
+ }
462
533
// Close the notes window.
463
534
if ( GUI . Button ( new Rect ( 2f , 2f , 13f , 13f ) , "X" ) )
464
535
{
@@ -501,6 +572,7 @@ private void NotesWindow(int windowId)
501
572
_file = _fileNames [ _selectFileGridInt ] ;
502
573
Load ( ) ;
503
574
}
575
+ GUI . Label ( new Rect ( 340f , 0f , 60 , 20f ) , _version ) ;
504
576
// If we are on flight show the vessel logs buttons
505
577
if ( HighLogic . LoadedSceneIsFlight && HighLogic . LoadedSceneHasPlanetarium )
506
578
{
@@ -532,6 +604,57 @@ private void NotesWindow(int windowId)
532
604
// Make this window dragable
533
605
GUI . DragWindow ( ) ;
534
606
}
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
+ }
535
658
536
659
// Executes the destroy action.
537
660
private void OnDestroy ( )
@@ -560,6 +683,26 @@ private void OnGUI()
560
683
"Notes list" ) ;
561
684
UpdateDelButtonText ( ) ;
562
685
}
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
+ }
563
706
//Restore the skin
564
707
GUI . skin = _defGuiSkin ;
565
708
}
@@ -601,6 +744,7 @@ private void SaveSettings()
601
744
602
745
_configFile . SetValue ( "main window position" , _windowRect ) ;
603
746
_configFile . SetValue ( "list window position" , _windowRect2 ) ;
747
+ _configFile . SetValue ( "del dialog position" , _windowRect3 ) ;
604
748
_configFile . SetValue ( "keybind" , _keybind ) ;
605
749
_configFile . SetValue ( "keybind2" , _keybind2 ) ;
606
750
_configFile . SetValue ( "version" , _version ) ;
0 commit comments