1+ package de .zocker160 .adk .analyzer .binanalyzer ;
2+
3+ import de .zocker160 .adk .analyzer .binanalyzer .parser .BinFile ;
4+ import de .zocker160 .adk .analyzer .binanalyzer .parser .FogZone ;
5+ import javafx .application .Application ;
6+ import javafx .fxml .FXMLLoader ;
7+ import javafx .scene .Scene ;
8+ import javafx .scene .control .Button ;
9+ import javafx .scene .paint .Color ;
10+ import javafx .stage .FileChooser ;
11+ import javafx .stage .Stage ;
12+
13+ import java .awt .*;
14+ import java .io .File ;
15+ import java .io .IOException ;
16+
17+ public class MainWindow extends Application {
18+ private static Stage stage ;
19+ private static MainWindowController controller ;
20+
21+ private static BinFile data ;
22+
23+ @ Override
24+ public void start (Stage stage ) throws IOException {
25+ FXMLLoader fxmlLoader = new FXMLLoader (MainWindow .class .getResource ("mainWindow.fxml" ));
26+ Scene scene = new Scene (fxmlLoader .load ());
27+
28+ MainWindow .stage = stage ;
29+ MainWindow .controller = fxmlLoader .getController ();
30+
31+ stage .setTitle ("AdK BIN Editor" );
32+ stage .setScene (scene );
33+ stage .show ();
34+ }
35+
36+ public static void start () {
37+ launch ();
38+ }
39+
40+ public static Stage getStage () {
41+ return stage ;
42+ }
43+
44+ public static MainWindowController getController () {
45+ return controller ;
46+ }
47+
48+ protected static String openFile () {
49+ var fileChooser = new FileChooser ();
50+ fileChooser .setTitle ("Select BIN file" );
51+ fileChooser .getExtensionFilters ().addAll (
52+ new FileChooser .ExtensionFilter ("AdK BIN File" , "*.bin" )
53+ );
54+
55+ File file = fileChooser .showOpenDialog (stage );
56+
57+ BinFile binFile = BinFile .loadFile (file );
58+ data = binFile ;
59+
60+ controller .value1 .setText (binFile .getValue1 ());
61+ controller .value2 .setText (binFile .getValue2 ());
62+ controller .value3 .setText (binFile .getValue3 ());
63+ controller .value4 .setText (binFile .getValue4 ());
64+
65+ controller .fogStart .setText (binFile .getFogStart ());
66+ controller .fogEnd .setText (binFile .getFogEnd ());
67+
68+ controller .fogColor .setValue (binFile .fogColor );
69+ controller .ambientColor .setValue (binFile .ambientColor );
70+ controller .lightColor .setValue (binFile .lightColor );
71+
72+ controller .maxZone = binFile .getNumberOfZones ()-1 ;
73+ controller .setZone (0 );
74+
75+ return file .getName ();
76+ }
77+
78+ protected static void saveToFile () {
79+ if (data == null ) return ;
80+
81+ var fileChooser = new FileChooser ();
82+ fileChooser .setTitle ("Save file..." );
83+ fileChooser .getExtensionFilters ().addAll (
84+ new FileChooser .ExtensionFilter ("AdK BIN file" , "*.bin" ),
85+ new FileChooser .ExtensionFilter ("All files" , "*.*" )
86+ );
87+
88+ File file = fileChooser .showSaveDialog (stage );
89+
90+ // global settings
91+ BinFile binFile = data ;
92+
93+ binFile .setValue1 (controller .value1 .getText ());
94+ binFile .setValue2 (controller .value2 .getText ());
95+ binFile .setValue3 (controller .value3 .getText ());
96+ binFile .setValue4 (controller .value4 .getText ());
97+
98+ binFile .setFogStart (controller .fogStart .getText ());
99+ binFile .setFogEnd (controller .fogEnd .getText ());
100+
101+ binFile .fogColor = controller .fogColor .getValue ();
102+ binFile .ambientColor = controller .ambientColor .getValue ();
103+ binFile .lightColor = controller .lightColor .getValue ();
104+
105+ // current zone
106+ saveZone (controller .getCurrentZone ());
107+
108+ data .save (file );
109+ }
110+
111+ protected static void loadZone (int zone ) {
112+ if (data == null ) return ;
113+
114+ FogZone fogZone = data .getZone (zone );
115+
116+ controller .fogColorZone .setValue (fogZone .getFogColor ());
117+ controller .ambientColorZone .setValue (fogZone .getAmbientColor ());
118+ controller .lightColorZone .setValue (fogZone .getLightColor ());
119+
120+ controller .shadowDensityZone .setText (fogZone .getShadowDensity ());
121+
122+ controller .fogStartZone .setText (fogZone .getFogStart ());
123+ controller .fogEndZone .setText (fogZone .getFogEnd ());
124+
125+ controller .posXZone .setText (fogZone .getPostition ().xStr ());
126+ controller .posYZone .setText (fogZone .getPostition ().yStr ());
127+
128+ controller .radiusStartZone .setText (fogZone .getRadiusStart ());
129+ controller .radiusEndZone .setText (fogZone .getRadiusEnd ());
130+ }
131+
132+ protected static void saveZone (int zone ) {
133+ if (data == null ) return ;
134+
135+ FogZone fogZone = data .getZone (zone );
136+
137+ fogZone .setFogColor (controller .fogColorZone .getValue ());
138+ fogZone .setAmbientColor (controller .ambientColor .getValue ());
139+ fogZone .setLightColor (controller .lightColor .getValue ());
140+
141+ fogZone .setShadowDensity (controller .shadowDensityZone .getText ());
142+
143+ fogZone .setFogStart (controller .fogStartZone .getText ());
144+ fogZone .setFogEnd (controller .fogEndZone .getText ());
145+
146+ fogZone .getPostition ().setX (controller .posXZone .getText ());
147+ fogZone .getPostition ().setY (controller .posYZone .getText ());
148+
149+ fogZone .setRadiusStart (controller .radiusStartZone .getText ());
150+ fogZone .setRadiusEnd (controller .radiusEndZone .getText ());
151+ }
152+ }
0 commit comments