Skip to content

Commit d6a32f1

Browse files
Upgraded settings menu
Signed-off-by: JayFromProgramming <[email protected]>
1 parent c3629e7 commit d6a32f1

File tree

3 files changed

+66
-32
lines changed

3 files changed

+66
-32
lines changed

resources/settingsTemplates/settings.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
"group": "Encoding"
3636
},
3737
"preferredCompatibilityEncoder": {
38-
"name": "preferredCompatibilityEncoder",
38+
"name": "Preferred HWAccel Encoder",
3939
"type": "encoderEnum",
4040
"value": "libx264",
41-
"description": "The preferred encoder to select for when converting to a compatible format.",
41+
"description": "\nThe preferred encoder to select for when converting to a compatible format.",
4242
"group": "Encoding"
4343
},
4444
"defaultAllow100MB": {
@@ -52,7 +52,7 @@
5252
"name": "Use Full CPU",
5353
"type": "toggle",
5454
"value": "true",
55-
"description": "Whether or not to use full CPU in vp9 encoding.",
55+
"description": "Whether or not to use full CPU in vp9 encoding. \n(Reduces compression, but allows for higher speed)",
5656
"group": "Encoding"
5757
},
5858
"preferredVideoSize": {
@@ -63,7 +63,7 @@
6363
"group": "Encoding"
6464
},
6565
"defaultAudioVolume": {
66-
"name": "defaultAudioVolume",
66+
"name": "Default audio volume",
6767
"type": "text",
6868
"value": "1",
6969
"description": "The default audio volume to use.",
@@ -103,5 +103,19 @@
103103
"value": "Left",
104104
"description": "The key to use to skip backward one second.",
105105
"group": "Keybinds"
106+
},
107+
"previewClip": {
108+
"name": "Preview Clip",
109+
"type": "keyBind",
110+
"value": "P",
111+
"description": "The key to use to preview the current clip.",
112+
"group": "Keybinds"
113+
},
114+
"clipIt": {
115+
"name": "Clip It",
116+
"type": "keyBind",
117+
"value": "Enter",
118+
"description": "Launches the clipIt window.",
119+
"group": "Keybinds"
106120
}
107121
}

src/main/java/HelperMethods/SettingsWrapper.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ public class SettingsWrapper {
2020

2121

2222
public static class setting{
23+
public String key;
2324
public String name;
2425
public String value;
2526
public String type;
2627
public String description;
2728
public String group;
2829

29-
setting(JSONObject jsonObject){
30+
setting(String key, JSONObject jsonObject){
3031
try {
32+
this.key = key;
3133
this.name = jsonObject.getString("name");
3234
this.value = jsonObject.getString("value");
3335
this.type = jsonObject.getString("type");
@@ -97,7 +99,7 @@ public static ArrayList<setting> getAllSettings() {
9799
ArrayList<setting> settings = new ArrayList<>();
98100
for (String key : templateJSON.keySet()) {
99101
try {
100-
settings.add(new setting(settingsJSON.getJSONObject(key)));
102+
settings.add(new setting(key, settingsJSON.getJSONObject(key)));
101103
} catch (JSONException e) {
102104
settings.add(repairSetting(key));
103105
}
@@ -107,12 +109,12 @@ public static ArrayList<setting> getAllSettings() {
107109

108110
private static setting repairSetting(String badKey){
109111
settingsJSON.put(badKey, templateJSON.getJSONObject(badKey));
110-
return new setting(templateJSON.getJSONObject(badKey));
112+
return new setting(badKey, templateJSON.getJSONObject(badKey));
111113
}
112114

113115
public static setting getSetting(String key) {
114116
try {
115-
return new setting(settingsJSON.getJSONObject(key));
117+
return new setting(key, settingsJSON.getJSONObject(key));
116118
} catch (JSONException e) {
117119
return repairSetting(key);
118120
}

src/main/java/com/example/clippyfx/SettingsView.java

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class SettingsView implements PopOut {
3030
public Button cancelButton;
3131
public AnchorPane pain;
3232
public TabPane settingsTabs;
33-
public Tab focusedTab;
33+
public tabWrapper focusedTab;
3434
public Text noticeText;
3535

3636
private boolean isAlive = true;
@@ -48,20 +48,25 @@ public void keyPressed(KeyEvent keyEvent) {
4848
}
4949

5050
public void mouseScroll(ScrollEvent scrollEvent) {
51-
// for (Node node : focusedTab.gry.getChildren()) {
52-
// node.setTranslateY(node.getTranslateY() + scrollEvent.getDeltaY());
53-
// // Get if the node is out of bounds and if so, make it hidden
54-
// node.setVisible(!(node.getLayoutY() + node.getTranslateY() > 320));
55-
// }
51+
if (focusedTab == null) {
52+
focusedTab = tabs.get(settingsTabs.getSelectionModel().getSelectedItem().getText());
53+
}
54+
for (Node node : focusedTab.pane.getChildren()) {
55+
node.setTranslateY(node.getTranslateY() + scrollEvent.getDeltaY());
56+
// Get if the node is out of bounds and if so, make it hidden
57+
node.setVisible(!(node.getLayoutY() + node.getTranslateY() > 280));
58+
}
5659
scrollEvent.consume();
5760
}
5861

5962
public void changeTab(MouseEvent mouseEvent) {
63+
focusedTab = tabs.get(settingsTabs.getSelectionModel().getSelectedItem().getText());
6064
noticeText.setVisible(settingsTabs.getSelectionModel().getSelectedItem().getText().equals("Keybinds"));
6165
}
6266

6367

6468
static class OptionWrapper {
69+
String key;
6570
String name;
6671
String startValue;
6772
String type;
@@ -84,12 +89,14 @@ public void hookHooks(){
8489
public void build() {
8590
System.out.println("Initializing SettingsView");
8691
ArrayList<SettingsWrapper.setting> settings = SettingsWrapper.getAllSettings();
92+
settingsTabs.getTabs().clear();
93+
tabs.clear();
8794
for (SettingsWrapper.setting setting : settings) {
8895
if (tabs.containsKey(setting.group)) {
89-
tabs.get(setting.group).yOffset += 44;
96+
// tabs.get(setting.group).yOffset += 44;
9097
Pane tab = tabs.get(setting.group).pane;
9198
int yOffset = tabs.get(setting.group).yOffset;
92-
settingOptionBuilder(setting, yOffset, tab);
99+
tabs.get(setting.group).yOffset = settingOptionBuilder(setting, yOffset, tab);
93100
} else {
94101
tabWrapper tabWrapper = new tabWrapper();
95102
tabWrapper.name = setting.group;
@@ -98,7 +105,7 @@ public void build() {
98105
tabWrapper.tab.setContent(tabWrapper.pane);
99106
tabWrapper.yOffset = 24;
100107
tabs.put(setting.group, tabWrapper);
101-
settingOptionBuilder(setting, tabWrapper.yOffset, tabWrapper.pane);
108+
tabWrapper.yOffset = settingOptionBuilder(setting, tabWrapper.yOffset, tabWrapper.pane);
102109
}
103110

104111
}
@@ -107,23 +114,26 @@ public void build() {
107114
}
108115
}
109116

110-
public void settingOptionBuilder(SettingsWrapper.setting setting, int yOffset, Pane parent) {
117+
public int settingOptionBuilder(SettingsWrapper.setting setting, int yOffset, Pane parent) {
111118
Text fieldName = new Text(setting.name);
112119
fieldName.setText(setting.name + ": " + setting.description);
113120
fieldName.setLayoutY(yOffset);
114121
OptionWrapper option = new OptionWrapper();
122+
option.key = setting.key;
115123
option.name = setting.name;
116124
option.startValue = setting.value;
125+
yOffset += fieldName.getLayoutBounds().getHeight() - 10;
117126
switch (setting.type) {
118127
case "filePath" -> {
119128
TextField textField = new TextField();
120129
Button button = new Button("Choose");
121130
button.setOnMouseClicked(mouseEvent -> makeDirectorySelector(textField, setting.value));
122131
textField.setText(setting.value);
123-
textField.setLayoutY(yOffset + 6);
132+
textField.setLayoutY(yOffset);
124133
textField.setPrefWidth(350);
134+
button.setLayoutY(yOffset);
125135
button.setLayoutX(textField.getLayoutX() + textField.getPrefWidth() + 5);
126-
button.setLayoutY(yOffset + 6);
136+
yOffset += textField.getLayoutBounds().getHeight() + 6;
127137
textField.setDisable(false);
128138
option.textField = textField;
129139
option.type = "textField";
@@ -132,26 +142,30 @@ public void settingOptionBuilder(SettingsWrapper.setting setting, int yOffset, P
132142
case "keyBind" -> {
133143
TextField textField = new TextField();
134144
textField.setText(setting.value);
135-
textField.setLayoutY(yOffset + 6);
145+
textField.setLayoutY(yOffset);
136146
textField.setPrefWidth(175);
137147
textField.setOnKeyReleased(keyEvent -> keyPressDetector(textField, keyEvent));
148+
yOffset += textField.getLayoutBounds().getHeight() + 6;
138149
option.textField = textField;
139150
option.type = "keyBind";
140151
parent.getChildren().addAll(fieldName, textField);
141152
}
142153
case "toggle" -> {
143154
CheckBox checkBox = new CheckBox();
144155
checkBox.setSelected(setting.bool());
145-
checkBox.setLayoutY(yOffset + 6);
156+
// yOffset -= 5;
157+
checkBox.setLayoutY(yOffset);
146158
parent.getChildren().addAll(fieldName, checkBox);
159+
yOffset += checkBox.getLayoutBounds().getHeight() + 6;
147160
option.checkBox = checkBox;
148161
option.type = "checkBox";
149162
}
150163
case "sizeEnum" -> {
151164
ChoiceBox<String> choiceBox = new ChoiceBox<>();
152165
choiceBox.getItems().addAll(VideoChecks.getSizesString());
153166
choiceBox.setValue(setting.value);
154-
choiceBox.setLayoutY(yOffset + 6);
167+
choiceBox.setLayoutY(yOffset);
168+
yOffset += choiceBox.getLayoutBounds().getHeight() + 6;
155169
parent.getChildren().addAll(fieldName, choiceBox);
156170
option.choiceBox = choiceBox;
157171
option.type = "choiceBox";
@@ -160,22 +174,26 @@ public void settingOptionBuilder(SettingsWrapper.setting setting, int yOffset, P
160174
ChoiceBox<String> choiceBox = new ChoiceBox<>();
161175
choiceBox.getItems().addAll(VideoChecks.getEncodersString());
162176
choiceBox.setValue(setting.value);
163-
choiceBox.setLayoutY(yOffset + 6);
177+
choiceBox.setLayoutY(yOffset);
178+
yOffset += choiceBox.getLayoutBounds().getHeight() + 6;
164179
parent.getChildren().addAll(fieldName, choiceBox);
165180
option.choiceBox = choiceBox;
166181
option.type = "choiceBox";
167182
}
168183
case "text" -> {
169184
TextField textField = new TextField();
170185
textField.setText(setting.value);
171-
textField.setLayoutY(yOffset + 5);
186+
yOffset += 6;
187+
textField.setLayoutY(yOffset);
172188
textField.setPrefWidth(350);
173189
option.textField = textField;
174190
option.type = "text";
175191
parent.getChildren().addAll(fieldName, textField);
176192
}
177-
}
193+
};
194+
System.out.println("End " + yOffset);
178195
options.add(option);
196+
return yOffset + 32;
179197
}
180198

181199
private void makeDirectorySelector(TextField textField, String directory) {
@@ -197,24 +215,24 @@ public void onSavePressed(MouseEvent mouseEvent) {
197215
System.out.println("Saving");
198216
for (OptionWrapper option : options) {
199217
switch (option.type) {
200-
case "textField" -> {
201-
JSONObject object = SettingsWrapper.getRawObject(option.name).put("value", option.textField.getText());
218+
case "textField", "keyBind" -> {
219+
JSONObject object = SettingsWrapper.getRawObject(option.key).put("value", option.textField.getText());
202220
SettingsWrapper.updateSetting(option.name, object);
203221
}
204222
case "checkBox" -> {
205223
String value = option.checkBox.isSelected() ? "true" : "false";
206-
JSONObject object = SettingsWrapper.getRawObject(option.name).put("value", value);
224+
JSONObject object = SettingsWrapper.getRawObject(option.key).put("value", value);
207225
SettingsWrapper.updateSetting(option.name, object);
208226
}
209227
case "choiceBox" -> {
210-
JSONObject object = SettingsWrapper.getRawObject(option.name).put("value", option.choiceBox.getValue());
228+
JSONObject object = SettingsWrapper.getRawObject(option.key).put("value", option.choiceBox.getValue());
211229
SettingsWrapper.updateSetting(option.name, object);
212230
}
213231
}
214232
}
215233
SettingsWrapper.saveSettings();
216-
options.clear();
217-
build();
234+
// options.clear();
235+
// build();
218236
}
219237

220238
public void onResetPressed(MouseEvent mouseEvent) throws IOException {

0 commit comments

Comments
 (0)