23
23
import java .nio .file .Files ;
24
24
import java .nio .file .Path ;
25
25
import java .nio .file .Paths ;
26
+ import java .util .*;
26
27
import java .util .AbstractMap .SimpleEntry ;
27
- import java .util .ArrayList ;
28
- import java .util .Comparator ;
29
28
import java .util .List ;
30
- import java .util .Map ;
31
29
import java .util .stream .Collectors ;
32
30
import java .util .stream .Stream ;
33
31
import javax .swing .*;
@@ -87,6 +85,8 @@ public class Main {
87
85
interlaceCheckbox ,
88
86
autoscrollLogsCheckbox ,
89
87
sidebarCheckbox ,
88
+ customUiMode ,
89
+ keepInvOpen ,
90
90
gfxCheckbox ; // all the checkboxes on the sidepanel.
91
91
private static JButton loadScriptButton ,
92
92
pathwalkerButton ,
@@ -386,26 +386,26 @@ public static void main(String[] args)
386
386
rscFrame .setSize (new Dimension (rscFrame .getWidth () + 122 , rscFrame .getHeight ()));
387
387
388
388
// Set checkboxes on side panel using "get" methods
389
+ autoLoginCheckbox .setSelected (config .isAutoLogin ());
390
+ graphicsCheckbox .setSelected (config .isGraphicsEnabled ());
391
+ render3DCheckbox .setSelected (config .isRender3DEnabled ());
392
+ gfxCheckbox .setSelected (config .isGraphicsEnabled ());
393
+ controller .setDrawing (config .isGraphicsEnabled (), 0 );
394
+ controller .setRender3D (config .isRender3DEnabled ());
389
395
logWindowCheckbox .setSelected (config .isLogWindowVisible ());
390
396
sidebarCheckbox .setSelected (config .isSidebarVisible ());
391
397
debugCheckbox .setSelected (config .isDebug ());
392
398
interlaceCheckbox .setSelected (config .isGraphicsInterlacingEnabled ());
393
399
botPaintCheckbox .setSelected (config .isBotPaintVisible ());
400
+ customUiMode .setSelected (config .getNewUi ());
401
+ keepInvOpen .setSelected (config .getKeepOpen ());
394
402
395
- if (config .isGraphicsInterlacingEnabled ()) {
403
+ // Set client properties from checkboxes
404
+ if (config .getKeepOpen ()) controller .setKeepInventoryOpenMode (keepInvOpen .isSelected ());
405
+ if (config .isGraphicsInterlacingEnabled ())
396
406
controller .setInterlacer (config .isGraphicsInterlacingEnabled ());
397
- }
398
- if (config .isScriptSelectorOpen ()) {
399
- showLoadScript ();
400
- }
401
-
407
+ if (config .isScriptSelectorOpen ()) showLoadScript ();
402
408
if (config .isDebug ()) debugger .open ();
403
- autoLoginCheckbox .setSelected (config .isAutoLogin ());
404
- graphicsCheckbox .setSelected (config .isGraphicsEnabled ());
405
- render3DCheckbox .setSelected (config .isRender3DEnabled ());
406
- gfxCheckbox .setSelected (config .isGraphicsEnabled ());
407
- controller .setDrawing (config .isGraphicsEnabled (), 0 );
408
- controller .setRender3D (config .isRender3DEnabled ());
409
409
410
410
log ("Initializing WindowListener..." );
411
411
windowListener =
@@ -607,14 +607,6 @@ private static void initializeMenuBar() {
607
607
menuBar .add (logWindowCheckbox );
608
608
menuBar .add (sidebarCheckbox );
609
609
610
- // prevent tab/etc "focusing" an element
611
- menuBar .setFocusable (false );
612
- settingsMenu .setFocusable (false );
613
- themeMenu .setFocusable (false );
614
- gfxCheckbox .setFocusable (false );
615
- logWindowCheckbox .setFocusable (false );
616
- sidebarCheckbox .setFocusable (false );
617
-
618
610
// style our elements
619
611
settingsMenu .setBackground (themeBackColor );
620
612
settingsMenu .setBorder (BorderFactory .createLineBorder (themeBackColor ));
@@ -650,11 +642,10 @@ private static void initializeMenuBar() {
650
642
themeMenu .add (menuItem );
651
643
}
652
644
JMenuItem _accOpp ;
653
- JCheckBox customUiMode , keepInvOpen ;
654
645
// Define settings menu drop down
655
646
Component [] _settingsMenu = {
656
647
_accOpp = new JMenuItem ("Account Startup Settings" , KeyEvent .VK_F4 ), // S key
657
- customUiMode = new JCheckBox ("Custom in -game UI" ),
648
+ customUiMode = new JCheckBox ("Custom In -game UI" ),
658
649
keepInvOpen = new JCheckBox ("Keep Inventory Open" ),
659
650
};
660
651
@@ -663,6 +654,16 @@ private static void initializeMenuBar() {
663
654
settingsMenu .add (_menuItem );
664
655
}
665
656
657
+ // prevent tab/etc "focusing" an element
658
+ menuBar .setFocusable (false );
659
+ settingsMenu .setFocusable (false );
660
+ themeMenu .setFocusable (false );
661
+ gfxCheckbox .setFocusable (false );
662
+ logWindowCheckbox .setFocusable (false );
663
+ sidebarCheckbox .setFocusable (false );
664
+ customUiMode .setFocusable (false );
665
+ keepInvOpen .setFocusable (false );
666
+
666
667
// menuItem.setAccelerator(KeyStroke.getKeyStroke((char) KeyEvent.VK_F4));
667
668
// //opens 2 authframes
668
669
_accOpp .addActionListener (
@@ -677,14 +678,20 @@ private static void initializeMenuBar() {
677
678
authFrame .storeAuthData (authFrame );
678
679
authFrame .setVisible (false );
679
680
});
681
+ settingsMenu .setPopupMenuVisible (false );
682
+ settingsMenu .setSelected (false );
680
683
authFrame .setVisible (true );
681
684
});
682
685
customUiMode .addActionListener (
683
686
e -> {
687
+ settingsMenu .setPopupMenuVisible (false );
688
+ settingsMenu .setSelected (false );
684
689
controller .setCustomUiMode (customUiMode .isSelected ());
685
690
});
686
691
keepInvOpen .addActionListener (
687
692
e -> {
693
+ settingsMenu .setPopupMenuVisible (false );
694
+ settingsMenu .setSelected (false );
688
695
controller .setKeepInventoryOpenMode (keepInvOpen .isSelected ());
689
696
});
690
697
}
@@ -790,8 +797,8 @@ private static void initializeBotFrame(JComponent botFrame) {
790
797
botFrame .add (debugCheckbox );
791
798
botFrame .add (interlaceCheckbox );
792
799
botFrame .add (botPaintCheckbox );
793
- botFrame .add (graphicsCheckbox );
794
800
botFrame .add (render3DCheckbox );
801
+ botFrame .add (graphicsCheckbox );
795
802
botFrame .add (takeScreenshotButton );
796
803
botFrame .add (showIdButton );
797
804
botFrame .add (openDebuggerButton );
@@ -1063,7 +1070,7 @@ private static void handleCache(Config config) {
1063
1070
}
1064
1071
1065
1072
// set new or old UI bar design
1066
- setUiStyle (config .getNewUi ());
1073
+ setIconStyle (config .getNewIcons ());
1067
1074
1068
1075
// Generate our port file
1069
1076
if (config .getInitCache ().equalsIgnoreCase ("custom" )) {
@@ -1088,65 +1095,59 @@ private static boolean checkCacheFiles() {
1088
1095
new File ("cache" + File .separator + "video" + File .separator + "spritepacks" );
1089
1096
File videoDirectory = new File ("cache" + File .separator + "video/" );
1090
1097
File [] spriteFilelist = spriteDirectory .listFiles ();
1091
- File [] videoFilelist = videoDirectory .listFiles ();
1098
+ String [] videoFilelist = videoDirectory .list ();
1092
1099
String [] fileNames = {
1093
1100
"authentic_landscape.orsc" ,
1094
1101
"authentic_sprites.orsc" ,
1095
1102
"custom_landscape.orsc" ,
1096
1103
"custom_sprites.osar" ,
1097
1104
"library.orsc" ,
1098
- "models.orsc"
1105
+ "models.orsc" ,
1106
+ "spritepacks"
1099
1107
};
1100
1108
1101
- if (spriteFilelist != null ) {
1102
- if (!spriteFilelist [0 ].getName ().equalsIgnoreCase ("Menus.osar" )) return false ;
1109
+ // check sprite files
1110
+ if (spriteFilelist != null && spriteFilelist .length > 0 ) {
1111
+ if (!spriteFilelist [0 ].getName ().equalsIgnoreCase ("menus.osar" )) return false ;
1103
1112
} else return false ;
1104
- if (videoFilelist != null ) {
1105
- if (videoFilelist .length < 6 ) return false ;
1106
- String [] videoNames = new String [videoFilelist .length ];
1107
- for (int i = 0 ; i < videoFilelist .length ; i ++) {
1108
- videoNames [i ] = videoFilelist [i ].getName ();
1109
- }
1110
- // compare the file names we read to the names we need
1111
- for (String videoName : videoNames ) {
1112
- boolean callReturn = true ;
1113
- for (String fileName : fileNames ) {
1114
- if (videoName .equalsIgnoreCase (fileName )) {
1115
- callReturn = false ;
1116
- break ;
1117
- }
1118
- }
1113
+
1114
+ // check video files
1115
+ if (videoFilelist != null && videoFilelist .length >= 6 ) {
1116
+ for (String fileName : fileNames ) {
1117
+ boolean callReturn = Arrays .stream (videoFilelist ).noneMatch (fileName ::equalsIgnoreCase );
1119
1118
// we are missing a file so regen cache
1120
1119
if (callReturn ) return false ;
1121
1120
}
1122
1121
} else return false ;
1122
+
1123
1123
return true ;
1124
1124
}
1125
1125
1126
- private static void setUiStyle (boolean newStyle ) {
1126
+ private static void createCache () {
1127
+ log ("Cache Missing, Generating the Cache." );
1127
1128
// Create Cache directory
1128
1129
File dir = new File ("." + File .separator + "Cache" );
1129
1130
dir .mkdirs ();
1130
1131
1131
- // Add config.txt to client cache (1 gives new UI icons, 0 gives old Icons)
1132
+ // Copy embedded cache to cache directory
1132
1133
try {
1133
- FileWriter portFile = new FileWriter ("Cache/config.txt" );
1134
- portFile .write ("Menus:" + (newStyle ? 1 : 0 ));
1135
- portFile .close ();
1134
+ Extractor .extractZipResource ("/cache/ZipCache.zip" , dir .toPath ());
1136
1135
} catch (IOException e ) {
1137
1136
e .printStackTrace ();
1138
1137
System .out .println (e .getMessage ());
1139
1138
}
1140
1139
}
1141
1140
1142
- private static void createCache ( ) {
1141
+ private static void setIconStyle ( boolean newIcons ) {
1143
1142
// Create Cache directory
1144
1143
File dir = new File ("." + File .separator + "Cache" );
1145
1144
dir .mkdirs ();
1146
1145
1147
- // Copy embedded cache to cache directory
1146
+ // Add config.txt to client cache (1 gives new UI icons, 0 gives old Icons)
1148
1147
try {
1149
- Extractor .extractZipResource ("/cache/ZipCache.zip" , dir .toPath ());
1148
+ FileWriter portFile = new FileWriter ("Cache/config.txt" );
1149
+ portFile .write ("Menus:" + (newIcons ? 1 : 0 ));
1150
+ portFile .close ();
1150
1151
} catch (IOException e ) {
1151
1152
e .printStackTrace ();
1152
1153
System .out .println (e .getMessage ());
@@ -1292,6 +1293,15 @@ public static String getThemeName() {
1292
1293
return themeName ;
1293
1294
}
1294
1295
1296
+ /**
1297
+ * Used by login listener to set
1298
+ *
1299
+ * @return
1300
+ */
1301
+ public static boolean isCustomUiSelected () {
1302
+ return customUiMode .isSelected ();
1303
+ }
1304
+
1295
1305
/**
1296
1306
* Used by the WindowListener for tracking the log window.
1297
1307
*
0 commit comments