Stephen,
Would you be willing for me to submit a change to ToneGodGui for support of cursors that is a PNG file and not just cur files. It is a simple change to StyleManager.parseCursors() fuction.
It is a simple change in code to support PNG files for cursors. Would you be okay with this. I coded it so that old XML style sheets that do not have the new attribute, works like before. Assumes they are “cur” format for JMECursor to load.
Or should this be added to JMECursor to support PNG files. I’m okay with either. I altered the ToneGodGui to support my PNG cursors, also allows me to have larger and colorful cursors in the game.
Also, I do not know if this is by design or not. If the first Cursor fails to load, it will not attempt to load the rest. I would put the try/catch around the one line that throws that, so it keeps looping to get the others cursors. I could make this change.
private void parseCursors(List<String> docPaths) {
for (String docPath : docPaths) {
try {
Document doc = app.getAssetManager().loadAsset(new AssetKey<Document>(docPath));
if (doc == null) {
throw new AssetNotFoundException(String.format("Could not find style %s", docPath));
}
NodeList nLst = doc.getElementsByTagName("cursor");
for (int s = 0; s < nLst.getLength(); s++) {
Node fstNode = nLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
String key = XMLHelper.getNodeAttributeValue(fstNode, "type");
String curPath = XMLHelper.getNodeAttributeValue(fstNode, "path");
String imgType = XMLHelper.getNodeAttributeValue(fstNode, "imgType");
JmeCursor jmeCursor = null;
if (!imgType.equals("cur") && imgType.length() > 0)
{
Texture cursorTexture = app.getAssetManager().loadTexture(curPath);
Image image = cursorTexture.getImage();
imgByteBuff = (ByteBuffer) image.getData(0).rewind();
IntBuffer curIntBuff = BufferUtils.createIntBuffer(image.getHeight() * image.getWidth());
while (imgByteBuff.hasRemaining()) {
int rgba = imgByteBuff.getInt();
int argb = ((rgba & 255) << 24) | (rgba >> 8);
curIntBuff.put(argb);
}
jmeCursor = new JmeCursor();
jmeCursor.setHeight(image.getHeight());
jmeCursor.setWidth(image.getWidth());
jmeCursor.setNumImages(1);
jmeCursor.setImagesData((IntBuffer) curIntBuff.rewind());
} else {
jmeCursor = (JmeCursor)app.getAssetManager().loadAsset(curPath);//new JmeCursor();
}
try {
int hsX = Integer.valueOf(XMLHelper.getNodeAttributeValue(fstNode, "x"));
int hsY = Integer.valueOf(XMLHelper.getNodeAttributeValue(fstNode, "y"));
jmeCursor.setxHotSpot(hsX);
jmeCursor.setyHotSpot(hsY);
} catch (Exception npe) { }
cursors.put(CursorType.valueOf(key), jmeCursor);
}
}
} catch (Exception ex) {
System.err.println("Problem loading cursor definition: " + ex);
}
}
}