@@ -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