@@ -78,6 +78,7 @@ private void reload () {
7878 replace .replaceField = new ArrayList <>();
7979 replace .withField = new ArrayList <>();
8080 replace .removeButton = new ArrayList <>();
81+ replace .confirmButton = new ArrayList <>();
8182
8283 List <String > keys = new ArrayList <>(replace .replacements .keySet ());
8384 keys .sort (String ::compareTo );
@@ -90,43 +91,29 @@ private void reload () {
9091 }
9192 }
9293
94+ //874/2=437
9395 public void addElements (ReplaceStuff replace , String key , String value , boolean clubsPage ) {
94- TextInputField replaceField = new TextInputField (460 , 32 , false , "String to replace" );
96+ TextInputField replaceField = new TextInputField (390 , 32 , false , "String to replace" );
9597 replaceField .setInput (key );
9698 if (clubsPage && replace .clubReplacements .contains (key )) {
9799 replaceField .disable (true );
98100 }
99101 replace .replaceField .add (replaceField );
100102
101- TextInputField withField = new TextInputField (460 , 32 , false , "String to replace with" );
103+ TextInputField withField = new TextInputField (390 , 32 , false , "String to replace with" );
102104 withField .setInput (value );
103105 replace .withField .add (withField );
104106
105107 replace .removeButton .add (new DeleteElement (32 , 32 ));
106- }
107108
108- public void updateElements (ReplaceStuff replace , String key , String value , boolean clubsPage ) {
109- List <String > keys = new ArrayList <>(replace .replacements .keySet ());
110- keys .sort (String ::compareTo );
111- int index = keys .indexOf (key );
112- replace .replaceField .get (index ).setInput (key );
113- replace .withField .get (index ).setInput (value );
109+ replace .confirmButton .add (new BasicButton (96 , 32 , "Confirm" , BasicButton .ALIGNMENT_CENTER , ColorPalette .PRIMARY ));
114110 }
115111
116112 public static ReplaceOption create (Field field , Object parent ) {
117113 ReplaceAnnotation color = field .getAnnotation (ReplaceAnnotation .class );
118114 return new ReplaceOption (field , parent , color .name (), color .description (), color .category (), color .subcategory ());
119115 }
120116
121- public void removeElements (ReplaceStuff replaceStuff , String key ) {
122- List <String > keys = new ArrayList <>(replaceStuff .replacements .keySet ());
123- keys .sort (String ::compareTo );
124- int index = keys .indexOf (key );
125- replaceStuff .replaceField .remove (index );
126- replaceStuff .withField .remove (index );
127- replaceStuff .removeButton .remove (index );
128- }
129-
130117 @ Override
131118 public void draw (long vg , int x , int y , InputHandler inputHandler ) {
132119 final NanoVGHelper nanoVGHelper = NanoVGHelper .INSTANCE ;
@@ -148,15 +135,23 @@ public void draw(long vg, int x, int y, InputHandler inputHandler) {
148135 TextInputField replaceField = replace .replaceField .get (i );
149136 TextInputField withField = replace .withField .get (i );
150137 DeleteElement deleteElement = replace .removeButton .get (i );
138+ BasicButton confirmButton = replace .confirmButton .get (i );
151139
152140 replaceField .draw (vg , x , y , inputHandler );
153- withField .draw (vg , x + 475 , y , inputHandler );
141+ withField .draw (vg , x + 400 , y , inputHandler );
154142
143+ confirmButton .draw (vg , x + 800 , y , inputHandler );
144+ if (confirmButton .isClicked ()) {
145+ update (replace , i );
146+ }
155147
156- deleteElement .draw (vg , x + 950 , y , inputHandler );
148+ deleteElement .draw (vg , x + 900 , y , inputHandler );
157149 if (deleteElement .isClicked ()) {
158150 replace .replacements .remove (replaceField .getInput ());
159151 replace .replaceField .remove (i );
152+ replace .withField .remove (i );
153+ replace .removeButton .remove (i );
154+ replace .confirmButton .remove (i );
160155
161156 if (clubsPage && replace .clubReplacements .contains (replaceField .getInput ())) {
162157 replace .deleted .add (replaceField .getInput ());
@@ -195,29 +190,22 @@ public void keyTyped(char key, int keyCode) {
195190 if (currentTextInputField != null ) {
196191 currentTextInputField .keyTyped (key , keyCode );
197192 }
193+ }
194+
195+ public void update (ReplaceStuff replaceStuff , int index ) {
196+ TextInputField replaceField = replaceStuff .replaceField .get (index );
197+ TextInputField withField = replaceStuff .withField .get (index );
198+ String editKey = replaceStuff .replacements .keySet ().toArray (new String [0 ])[index ];
199+ if (editKey .equals (replaceField .getInput ())) {
200+ replaceStuff .replacements .put (replaceField .getInput (), withField .getInput ());
201+ } else {
202+ replaceStuff .replacements .put (replaceField .getInput (), withField .getInput ());
203+ replaceStuff .replacements .remove (editKey );
204+ }
198205 try {
199- ReplaceStuff icon = replacements .stream ().filter (i -> i .isWithField (currentTextInputField ) != null ).findFirst ().orElse (null );
200- if (icon != null ) {
201- System .out .println (icon .replacements + " " + icon .isWithField (currentTextInputField ) + " " + currentTextInputField .getInput ());
202- List <String > keys = new ArrayList <>(icon .replacements .keySet ());
203- keys .sort (String ::compareTo );
204- if (icon .isWithField (currentTextInputField ) == null ) return ;
205- int index = icon .isWithField (currentTextInputField ) ? icon .withField .indexOf (currentTextInputField ) : icon .replaceField .indexOf (currentTextInputField );
206- if (index == -1 ) return ;
207- System .out .println (index + " " + keys .get (index ) + " " + currentTextInputField .getInput () + " " + icon .replacements .get (keys .get (index )));
208- if (icon .isWithField (currentTextInputField )) {
209- icon .replacements .put (keys .get (index ), currentTextInputField .getInput ());
210- } else {
211- if (icon .replacements .containsKey (currentTextInputField .getInput ()) || currentTextInputField .getInput ().isEmpty ()) {
212- return ;
213- }
214- icon .replacements .put (currentTextInputField .getInput (), icon .replacements .get (keys .get (index )));
215- icon .replacements .remove (keys .get (index ));
216- }
217- System .out .println (icon .replacements );
218- }
219206 set (replacements );
220- } catch (IllegalAccessException ignored ) {
207+ } catch (IllegalAccessException e ) {
208+ e .printStackTrace ();
221209 }
222210 }
223211
0 commit comments