mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +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(){
|
public boolean loadimages(){
|
||||||
File filedir = new File(BackgroundDir);
|
File filedir = new File(BackgroundDir);
|
||||||
File[] filelist = filedir.listFiles();
|
File[] filelist = filedir.listFiles();
|
||||||
|
if(filelist == null) return false;
|
||||||
if(filelist.length == 0) return false;
|
if(filelist.length == 0) return false;
|
||||||
for(File f:filelist){
|
for(File f:filelist){
|
||||||
String filename = f.getName().toLowerCase();
|
String filename = f.getName().toLowerCase();
|
||||||
|
@ -55,14 +56,19 @@ public class ThemePluginImpl implements ThemePlugin {
|
||||||
}
|
}
|
||||||
public void applyInGame(Map<String, JComponent> ui) {
|
public void applyInGame(Map<String, JComponent> ui) {
|
||||||
String filename;
|
String filename;
|
||||||
|
BufferedImage background;
|
||||||
|
try {
|
||||||
if(loadimages()){
|
if(loadimages()){
|
||||||
int it = (int)Math.abs(Math.random()*(flist.getItemCount()));
|
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{
|
}else{
|
||||||
filename = "/dragon.png";
|
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) {
|
if (background == null) {
|
||||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
||||||
|
|
Loading…
Reference in a new issue