Ver Fonte

* Nifty Gui now uses jME3 AssetManager to find XML files

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7378 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
sha..rd há 14 anos atrás
pai
commit
f72d5c20fd
1 ficheiros alterados com 25 adições e 3 exclusões
  1. 25 3
      engine/src/niftygui/com/jme3/niftygui/NiftyJmeDisplay.java

+ 25 - 3
engine/src/niftygui/com/jme3/niftygui/NiftyJmeDisplay.java

@@ -32,6 +32,8 @@
 
 package com.jme3.niftygui;
 
+import com.jme3.asset.AssetInfo;
+import com.jme3.asset.AssetKey;
 import com.jme3.asset.AssetManager;
 import com.jme3.audio.AudioRenderer;
 import com.jme3.input.InputManager;
@@ -43,8 +45,12 @@ import com.jme3.renderer.queue.RenderQueue;
 import com.jme3.texture.FrameBuffer;
 import de.lessvoid.nifty.Nifty;
 import de.lessvoid.nifty.tools.TimeProvider;
+import de.lessvoid.nifty.tools.resourceloader.ResourceLoader;
+import de.lessvoid.nifty.tools.resourceloader.ResourceLocation;
+import java.io.InputStream;
+import java.net.URL;
 
-public class NiftyJmeDisplay extends TimeProvider implements SceneProcessor {
+public class NiftyJmeDisplay implements SceneProcessor {
 
     protected boolean inited = false;
     protected Nifty nifty;
@@ -55,10 +61,22 @@ public class NiftyJmeDisplay extends TimeProvider implements SceneProcessor {
     protected SoundDeviceJme soundDev;
     protected Renderer renderer;
     protected ViewPort vp;
+    
+    protected ResourceLocationJme resourceLocation;
 
     protected int w, h;
 
-    public NiftyJmeDisplay() {
+    protected class ResourceLocationJme implements ResourceLocation {
+
+        public InputStream getResourceAsStream(String path) {
+            AssetKey<Object> key = new AssetKey<Object>(path);
+            AssetInfo info = assetManager.locateAsset(key);
+            return info.openStream();
+        }
+
+        public URL getResource(String path) {
+            throw new UnsupportedOperationException();
+        }
     }
 
     public NiftyJmeDisplay(AssetManager assetManager, 
@@ -70,13 +88,17 @@ public class NiftyJmeDisplay extends TimeProvider implements SceneProcessor {
         w = vp.getCamera().getWidth();
         h = vp.getCamera().getHeight();
 
+        resourceLocation = new ResourceLocationJme();
+        ResourceLoader.removeAllResourceLocations();
+        ResourceLoader.addResourceLocation(resourceLocation);
+
         soundDev = new SoundDeviceJme(assetManager, audioRenderer);
         renderDev = new RenderDeviceJme(this);
         inputSys = new InputSystemJme(inputManager);
         if (inputManager != null)
             inputManager.addRawInputListener(inputSys);
         
-        nifty = new Nifty(renderDev, soundDev, inputSys, this);
+        nifty = new Nifty(renderDev, soundDev, inputSys, new TimeProvider());
         inputSys.setNifty(nifty);
     }