mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
Update ThemePluginImpl, know the client can randomly choose images in plugins/plugin.data/background/, nothing will be effect if there is no image files.
This commit is contained in:
parent
2caa5cbf37
commit
37530f97ae
1 changed files with 9 additions and 3 deletions
|
@ -42,6 +42,7 @@ public class ThemePluginImpl implements ThemePlugin {
|
|||
public boolean loadimages(){
|
||||
File filedir = new File(BackgroundDir);
|
||||
File[] filelist = filedir.listFiles();
|
||||
if(filelist == null) return false;
|
||||
if(filelist.length == 0) return false;
|
||||
for(File f:filelist){
|
||||
String filename = f.getName().toLowerCase();
|
||||
|
@ -55,14 +56,19 @@ public class ThemePluginImpl implements ThemePlugin {
|
|||
}
|
||||
public void applyInGame(Map<String, JComponent> ui) {
|
||||
String filename;
|
||||
BufferedImage background;
|
||||
try {
|
||||
if(loadimages()){
|
||||
int it = (int)Math.abs(Math.random()*(flist.getItemCount()));
|
||||
filename = BackgroundDir + flist.getItem(it);
|
||||
filename = BackgroundDir + flist.getItem(it);
|
||||
background = ImageIO.read(new File(filename));
|
||||
}else{
|
||||
filename = "/dragon.png";
|
||||
InputStream is = this.getClass().getResourceAsStream(filename);
|
||||
if (is == null)
|
||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||
background = ImageIO.read(is);
|
||||
}
|
||||
try {
|
||||
BufferedImage background = ImageIO.read(new File(filename));
|
||||
|
||||
if (background == null) {
|
||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||
|
|
Loading…
Reference in a new issue