mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08: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
c41a2df3ac
commit
2caa5cbf37
1 changed files with 28 additions and 11 deletions
|
|
@ -12,6 +12,7 @@ import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -22,7 +23,9 @@ public class ThemePluginImpl implements ThemePlugin {
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger(ThemePluginImpl.class);
|
private static final Logger log = Logger.getLogger(ThemePluginImpl.class);
|
||||||
private static BufferedImage background;
|
private static BufferedImage background;
|
||||||
|
private List flist = new List();
|
||||||
|
private String BackgroundDir = "plugins" + File.separator + "plugin.data" + File.separator
|
||||||
|
+ "background" + File.separator;
|
||||||
@Init
|
@Init
|
||||||
public void init() {
|
public void init() {
|
||||||
}
|
}
|
||||||
|
|
@ -36,17 +39,31 @@ public class ThemePluginImpl implements ThemePlugin {
|
||||||
return "[Theme plugin, version 0.5]";
|
return "[Theme plugin, version 0.5]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyInGame(Map<String, JComponent> ui) {
|
public boolean loadimages(){
|
||||||
String filename = "/dragon.png";
|
File filedir = new File(BackgroundDir);
|
||||||
try {
|
File[] filelist = filedir.listFiles();
|
||||||
InputStream is = this.getClass().getResourceAsStream(filename);
|
if(filelist.length == 0) return false;
|
||||||
|
for(File f:filelist){
|
||||||
if (is == null) {
|
String filename = f.getName().toLowerCase();
|
||||||
throw new FileNotFoundException("Couldn't find " + filename + " in resources.");
|
if(filename != null && (filename.endsWith(".png") || filename.endsWith(".jpg")
|
||||||
|
|| filename.endsWith(".bmp"))){
|
||||||
|
flist.add(filename);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
BufferedImage background = ImageIO.read(is);
|
if(flist.getItemCount() == 0) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public void applyInGame(Map<String, JComponent> ui) {
|
||||||
|
String filename;
|
||||||
|
if(loadimages()){
|
||||||
|
int it = (int)Math.abs(Math.random()*(flist.getItemCount()));
|
||||||
|
filename = BackgroundDir + flist.getItem(it);
|
||||||
|
}else{
|
||||||
|
filename = "/dragon.png";
|
||||||
|
}
|
||||||
|
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…
Add table
Add a link
Reference in a new issue