1
1
package com .github .rafael09ed .nMMModProfileExporter ;
2
2
3
3
import javafx .application .Application ;
4
+ import javafx .application .Platform ;
5
+ import javafx .geometry .Side ;
4
6
import javafx .scene .Scene ;
7
+ import javafx .scene .control .*;
5
8
import javafx .scene .control .Button ;
9
+ import javafx .scene .control .Dialog ;
6
10
import javafx .scene .control .Label ;
11
+ import javafx .scene .control .MenuItem ;
7
12
import javafx .scene .control .ScrollPane ;
8
13
import javafx .scene .control .TextArea ;
9
14
import javafx .scene .control .TextField ;
15
+ import javafx .scene .input .MouseButton ;
16
+ import javafx .scene .layout .GridPane ;
10
17
import javafx .scene .layout .HBox ;
11
18
import javafx .scene .layout .Priority ;
12
19
import javafx .scene .layout .VBox ;
13
20
import javafx .stage .Stage ;
21
+ import javafx .util .Pair ;
14
22
15
23
import java .awt .*;
16
24
import java .awt .datatransfer .Clipboard ;
17
25
import java .awt .datatransfer .StringSelection ;
26
+ import java .io .File ;
27
+ import java .io .IOException ;
18
28
import java .util .List ;
29
+ import java .util .Optional ;
19
30
20
31
21
32
/**
22
- * EGR 283 B01
23
- * UserInterface.java
24
- * Purpose:
25
- *
26
33
* @author Rafael
27
34
* @version 1.0 2/16/2017
28
35
*/
@@ -33,6 +40,7 @@ public class UserInterface extends Application {
33
40
private final Button autoFindButton = new Button ("Auto" ), demoButton = new Button ("Demo" ),
34
41
markdownButton = new Button ("Markdown" ), copyButton = new Button ("Copy Mod List" );
35
42
private ModProfile activeModProfile ;
43
+ private final PreferencesIO preferences = new PreferencesIO ();
36
44
37
45
public static void main (String [] args ) {
38
46
launch (args );
@@ -94,7 +102,8 @@ public void start(Stage primaryStage) throws Exception {
94
102
primaryStage .setScene (new Scene (main , 900 , 800 ));
95
103
primaryStage .getScene ().getStylesheets ().add ("style.css" );
96
104
97
- primaryStage .setTitle ("Nexus Mod Manager Mod Profile Extractor" );
105
+ primaryStage .setTitle ("Nexus Mod Manager Mod Profile Extractor By Rafael09ED" );
106
+ primaryStage .setOnCloseRequest (event -> preferences .saveToFile ());
98
107
primaryStage .show ();
99
108
}
100
109
@@ -106,7 +115,8 @@ private void updateList() {
106
115
modListArea .setText (TextOutputFormater
107
116
.makeTextOutput (
108
117
layoutArea .getText (),
109
- activeModProfile
118
+ activeModProfile ,
119
+ preferences
110
120
));
111
121
}
112
122
@@ -115,32 +125,87 @@ private void loadProfiles(List<ModProfile> profiles) {
115
125
if (profiles .size () > 0 )
116
126
activeModProfile = profiles .get (0 );
117
127
for (ModProfile profile : profiles ) {
118
- VBox vBox = new VBox ();
119
- vBox .setOnMouseClicked (event -> {
120
- activeModProfile = profile ;
121
- updateList ();
128
+ VBox modProfileVBox = new VBox ();
129
+ modProfileVBox .setOnMouseClicked (event -> {
130
+ if (event .getButton () == MouseButton .PRIMARY ) {
131
+ activeModProfile = profile ;
132
+ updateList ();
133
+ } else {
134
+ ContextMenu modProfileContextMenu = new ContextMenu ();
135
+ MenuItem modProfileMenuItem = new MenuItem ("Set URL Subpath for Game" );
136
+ modProfileMenuItem .setOnAction (e -> {
137
+ Dialog <Pair <String , String >> dialog = new Dialog <>();
138
+ dialog .setTitle ("Set URL Subpath for Game" );
139
+ dialog .getDialogPane ().getButtonTypes ().addAll (ButtonType .APPLY , ButtonType .CANCEL );
140
+
141
+ GridPane grid = new GridPane ();
142
+
143
+ TextField gameField = new TextField ();
144
+ gameField .setPromptText ("Game Path" );
145
+ gameField .setText (profile .getGameName ().toLowerCase ());
146
+ TextField urlField = new TextField ();
147
+ urlField .setPromptText ("Nexus Mod URL SubPath" );
148
+ grid .add (new Label ("Game Path:" ), 0 , 0 );
149
+ grid .add (gameField , 0 , 1 );
150
+ grid .add (new Label ("URL Path:" ), 1 , 0 );
151
+ grid .add (urlField , 1 , 1 );
152
+
153
+ dialog .getDialogPane ().setContent (grid );
154
+ Platform .runLater (urlField ::requestFocus );
155
+ dialog .setResultConverter (dialogButton -> {
156
+ if (dialogButton == ButtonType .APPLY ) {
157
+ return new Pair <>(gameField .getText (), urlField .getText ());
158
+ }
159
+ return null ;
160
+ });
161
+
162
+ Optional <Pair <String , String >> result = dialog .showAndWait ();
163
+ result .ifPresent (values -> {
164
+ preferences .setUrlForGamePath (values .getKey (), values .getValue ());
165
+ updateList ();
166
+ });
167
+ });
168
+ modProfileContextMenu .getItems ().add (modProfileMenuItem );
169
+
170
+ modProfileMenuItem = new MenuItem ("Open Profile Path" );
171
+ modProfileMenuItem .setOnAction (e -> {
172
+ try {
173
+ Desktop .getDesktop ().open (new File (profile .getProfilePath ()));
174
+ } catch (IOException e1 ) {
175
+ Alert alert = new Alert (Alert .AlertType .ERROR );
176
+ alert .setTitle ("Error" );
177
+ alert .setHeaderText (null );
178
+ alert .setContentText ("Could Not Open Path" );
179
+ alert .show ();
180
+ }
181
+ });
182
+ modProfileContextMenu .getItems ().add (modProfileMenuItem );
183
+
184
+ modProfileContextMenu .show (modProfileVBox , Side .BOTTOM , 0 , 0 );
185
+ }
122
186
});
187
+
123
188
Label label ;
124
189
125
190
String profileName = profile .getProfileName ();
126
191
if (profileName == null || profileName .trim ().length () <= 0 )
127
192
profileName = "Untitled Profile" ;
128
193
label = new Label (profileName );
129
194
label .getStyleClass ().add ("profileTitle" );
130
- vBox .getChildren ().add (label );
195
+ modProfileVBox .getChildren ().add (label );
131
196
132
197
label = new Label (profile .getGameName ());
133
- vBox .getChildren ().add (label );
198
+ modProfileVBox .getChildren ().add (label );
134
199
135
200
label = new Label (profile .getProfilePath ());
136
- vBox .getChildren ().add (label );
201
+ modProfileVBox .getChildren ().add (label );
137
202
138
203
label = new Label (profile .getMods ().size () + " Mods" );
139
- vBox .getChildren ().add (label );
204
+ modProfileVBox .getChildren ().add (label );
140
205
141
- vBox .getStyleClass ().add ("profileListItem" );
142
- vBox .setMaxWidth (Double .MAX_VALUE );
143
- modProfilesList .getChildren ().add (vBox );
206
+ modProfileVBox .getStyleClass ().add ("profileListItem" );
207
+ modProfileVBox .setMaxWidth (Double .MAX_VALUE );
208
+ modProfilesList .getChildren ().add (modProfileVBox );
144
209
}
145
210
updateList ();
146
211
}
0 commit comments