Java源码示例:de.lessvoid.nifty.Nifty

示例1
private NiftyJmeDisplay(
    final AssetManager assetManager,
    final InputManager inputManager,
    final AudioRenderer audioRenderer,
    final ViewPort viewport,
    final BatchRenderConfiguration batchRenderConfiguration) {
  initialize(assetManager, inputManager, audioRenderer, viewport);

  this.renderDev = null;
  this.batchRendererBackend = new JmeBatchRenderBackend(this);

  nifty = new Nifty(
      new BatchRenderDevice(batchRendererBackend, batchRenderConfiguration),
      soundDev,
      inputSys,
      new AccurateTimeProvider());
  inputSys.setNifty(nifty);

  resourceLocation = new ResourceLocationJme();
  nifty.getResourceLoader().removeAllResourceLocations();
  nifty.getResourceLoader().addResourceLocation(resourceLocation);
}
 
示例2
/**
 * Create a standard NiftyJmeDisplay. This uses the old Nifty renderer. It's probably slower then the batched
 * renderer and is mainly here for backwards compatibility.
 *
 * @param assetManager jME AssetManager
 * @param inputManager jME InputManager
 * @param audioRenderer jME AudioRenderer
 * @param vp Viewport to use
 */
public NiftyJmeDisplay(AssetManager assetManager,
                       InputManager inputManager,
                       AudioRenderer audioRenderer,
                       ViewPort vp){
    initialize(assetManager, inputManager, audioRenderer, vp);

    this.renderDev = new RenderDeviceJme(this);
    this.batchRendererBackend = null;

    nifty = new Nifty(renderDev, soundDev, inputSys, new AccurateTimeProvider());
    inputSys.setNifty(nifty);

    resourceLocation = new ResourceLocationJme();
    nifty.getResourceLoader().removeAllResourceLocations();
    nifty.getResourceLoader().addResourceLocation(resourceLocation);
}
 
示例3
@Override
public void simpleInitApp() {
    /*
     * GUI requires a cursor; prevent flyCam from hiding it.
     */
    flyCam.setDragToRotate(true);
    /*
     * Start NiftyGUI without the batched renderer.
     */
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
            assetManager, inputManager, audioRenderer, guiViewPort);
    guiViewPort.addProcessor(niftyDisplay);
    /*
     * Load GUI controls, styles, and layout from XML assets.
     */
    Nifty nifty = niftyDisplay.getNifty();
    nifty.loadControlFile("nifty-default-controls.xml");
    nifty.loadStyleFile("nifty-default-styles.xml");
    nifty.fromXml("Interface/Nifty/test-issue-99.xml",
            "test-issue-99", this);
}
 
示例4
@Override
@SuppressWarnings("unchecked")
public void bind(Nifty nifty, Screen screen) {
    applyButton = screen.findNiftyControl("ApplyButton", Button.class);
    platformListBox = screen.findNiftyControl("PlatformListBox", ListBox.class);
    deviceListBox = screen.findNiftyControl("DeviceListBox", ListBox.class);
    infoLabel = screen.findNiftyControl("InfoLabel", Label.class);
    
    updateInfos();
    
    platformListBox.clear();
    for (Platform p : availabePlatforms) {
        platformListBox.addItem(p.getName());
    }
    platformListBox.selectItem(selectedPlatform);
    changePlatform(selectedPlatform);
}
 
示例5
/**
 * Create a new empty gui with one screen and set as the current gui.
 * @param nifty a valid Nifty instace @see Nifty
 * @throws ParserConfigurationException if controller failed to create
 * a valid document instance
 */
public void createNewGui(Nifty nifty) throws ParserConfigurationException, JAXBException, ClassNotFoundException, IOException, NoProductException{
    gui= GUIFactory.getInstance().createGUI(nifty);
    GScreen screen = (GScreen) GUIFactory.getInstance().newGElement(GScreen.class);
    GLayer layer1 = (GLayer) GUIFactory.getInstance().newGElement(GLayer.class);
    screen.addChild(layer1, true);
    getGui().addScreen(screen);
    this.currentS = screen;
    this.currentL = layer1;
    this.currentlayers.clear();
    this.currentlayers.add(layer1);
    GUseControls standardControls = new GUseControls();
    GUseStyle standardStyle = new GUseStyle();
    standardControls.setFilename("nifty-default-controls.xml");
    standardStyle.setFilename("nifty-default-styles.xml");
    this.gui.addUseControls(standardControls);
    this.gui.addUseStyles(standardStyle);
    this.model.setCurentGUI(gui);
    this.setChanged();
    this.notifyObservers(new ReloadGuiEvent(gui));
    this.clearChanged();
    writer = new GUIWriter(gui);
    dragDropManager = new NiftyDDManager(nifty);
    System.gc();
}
 
示例6
public void refresh() {
    Nifty temp = nElement.getNifty();
    Attributes att = this.nElement.getElementType().getAttributes();
    String newStyle = att.get("style");
    Attributes attcopy = new Attributes(att);
    // Add the old style if there was one
    if (oldStyle != null && !oldStyle.equals(newStyle)) {

        att.set("style", oldStyle);
        nElement.setStyle(newStyle);
        attcopy = att;
        oldStyle = newStyle;
    }
    if (att.isSet("renderOrder")) {
        int renderorder = att.get("renderOrder").isEmpty() ? this.parent.children.indexOf(this) : att.getAsInteger("renderOrder");
        nElement.setRenderOrder(renderorder);
    }
    nElement.setId(id);
    this.internalRefresh(temp, attcopy);
    this.processRemoved();
    fireUpdate();
}
 
示例7
public void init() {
       InputSystemAwtImpl inputSystem = new InputSystemAwtImpl();
       FontProviderJava2dImpl fontProvider = new FontProviderJava2dImpl();
registerFonts(fontProvider);
       RenderDeviceJava2dImpl renderDevice = new RenderDeviceJava2dImpl(graphWrap);
renderDevice.setFontProvider(fontProvider);
nifty = new Nifty(renderDevice,  new SoudDevicenull(), inputSystem,new TimeProvider());
      
       java.net.URL empty = getClass().getResource("/jada/ngeditor/resources/empty.xml");
       try {
           nifty.fromXml(empty.getFile(),empty.openStream(), "screen1");
       } catch (IOException ex) {
           Logger.getLogger(J2DNiftyView.class.getName()).log(Level.SEVERE, null, ex);
       }
       this.dragDropManager = new NiftyDDManager(nifty);
       timer = new Timer(30,this); 
       timer.start();
       this.setIgnoreRepaint(true);
       nifty.resolutionChanged();
   }
 
示例8
public NiftyJmeDisplay(AssetManager assetManager, 
                       InputManager inputManager,
                       AudioRenderer audioRenderer,
                       ViewPort vp){
    this.assetManager = assetManager;

    w = vp.getCamera().getWidth();
    h = vp.getCamera().getHeight();

    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, new FastTimeProvider());
    inputSys.setNifty(nifty);

    resourceLocation = new ResourceLocationJme();
    nifty.getResourceLoader().removeAllResourceLocations();
    nifty.getResourceLoader().addResourceLocation(resourceLocation);
}
 
示例9
/**
 * Create a new NiftyJmeDisplay for use with the Batched Nifty Renderer (improved Nifty rendering performance).
 *
 * Nifty will use a single texture of the given dimensions (see atlasWidth and atlasHeight parameters). Every
 * graphical asset you're rendering through Nifty will be placed into this big texture. The goal is to render
 * all Nifty components in a single (or at least very few) draw calls. This should speed up rendering quite a
 * bit.
 *
 * Currently you have to make sure to not use more image space than this single texture provides. However, Nifty
 * tries to be smart about this and internally will make sure that only the images are uploaded that your GUI
 * really needs. So in general this shouldn't be an issue.
 *
 * A complete re-organisation of the texture atlas happens when a Nifty screen ends and another begins. Dynamically
 * adding images while a screen is running is supported as well.
 *
 * @param assetManager jME AssetManager
 * @param inputManager jME InputManager
 * @param audioRenderer jME AudioRenderer
 * @param viewport Viewport to use
 * @param atlasWidth the width of the texture atlas Nifty uses to speed up rendering (2048 is a good value)
 * @param atlasHeight the height of the texture atlas Nifty uses to speed up rendering (2048 is a good value)
 *
 * @deprecated use the static factory methods {@link #newNiftyJmeDisplay(com.jme3.asset.AssetManager, com.jme3.input.InputManager, com.jme3.audio.AudioRenderer, com.jme3.renderer.ViewPort) }
 * or {@link #newNiftyJmeDisplay(com.jme3.asset.AssetManager, com.jme3.input.InputManager, com.jme3.audio.AudioRenderer, com.jme3.renderer.ViewPort, de.lessvoid.nifty.render.batch.BatchRenderConfiguration) }
 * instead of this constructor.
 */
public NiftyJmeDisplay(
    final AssetManager assetManager,
    final InputManager inputManager,
    final AudioRenderer audioRenderer,
    final ViewPort viewport,
    final int atlasWidth,
    final int atlasHeight) {
  // The code duplication in here really sucks - it's a copy of the
  // private constructor below that takes a BatchRenderConfiguration as an
  // additional parameter. This method should really be removed soon and
  // users should simply call the new factory methods.
  //
  // For now I keep this constructor as-is but have marked it as deprecated
  // to allow migration to the new way to instantiate this class.
  initialize(assetManager, inputManager, audioRenderer, viewport);

  this.renderDev = null;
  this.batchRendererBackend = new JmeBatchRenderBackend(this);

  BatchRenderConfiguration batchRenderConfiguration = new BatchRenderConfiguration();
  batchRenderConfiguration.atlasWidth = atlasWidth;
  batchRenderConfiguration.atlasHeight = atlasHeight;

  nifty = new Nifty(
      new BatchRenderDevice(batchRendererBackend, batchRenderConfiguration),
      soundDev,
      inputSys,
      new AccurateTimeProvider());
  inputSys.setNifty(nifty);

  resourceLocation = new ResourceLocationJme();
  nifty.getResourceLoader().removeAllResourceLocations();
  nifty.getResourceLoader().addResourceLocation(resourceLocation);
}
 
示例10
public BattlefieldController(MapView view, Nifty nifty, InputManager inputManager, Camera cam) {
	super(view, inputManager, cam);
	this.view = view;
	inputInterpreter = new BattlefieldInputInterpreter(this);
	guiController = new BattlefieldGUIController(nifty, this);

	EventManager.register(this);

	cameraManager = new IsometricCameraManager(cam, 10);
}
 
示例11
public EditorController(EditorView view, Nifty nifty, InputManager inputManager, Camera cam) {
	super(view, inputManager, cam);
	this.view = view;
	inputInterpreter = new EditorInputInterpreter(this);
	guiController = new EditorGUIController(nifty, this);
	cameraManager = new IsometricCameraManager(cam, 10);

	EventManager.register(this);
}
 
示例12
public GroundController(EditorView view, Nifty nifty, InputManager inputManager, Camera cam) {
	super(view, inputManager, cam);

	inputInterpreter = new GroundInputInterpreter(this);
	cameraManager = new GroundCameraManager(cam);
	guiController = new GroundGUIController(nifty, this);
}
 
示例13
/**
 * Create a new gui from a file and current assetFolder as assets
 * @param nifty a valid Nifty instace @see Nifty
 * @throws ParserConfigurationException if controller failed to create
 * a valid document instance
 * @throws IOException
 * @throws  SAXException
 * @throws Exception if nifty can't create the gui
 * @return A string with the elements that weren't loaded
 * 
 */
public String createNewGui(Nifty nifty ,File filename) throws ParserConfigurationException, IOException, SAXException, NoProductException, Exception{
   String assets= ".";
   if(this.gui != null){
      assets = this.gui.getAssetFolder().getPath(); 
   }
   GUIReader reader = new GUIReader(nifty);
   String res = "";
   this.gui = reader.readGUI(filename);
   this.gui.setAssetFolder(new File(assets));
   res = reader.getTagNotLoaded();
   final GScreen screen =this.getGui().gettopScreen();
   for(String sel : nifty.getAllScreensName()){
                nifty.removeScreen(sel);
   }
   writer = new GUIWriter(gui);
  nifty.scheduleEndOfFrameElementAction(new Reload(nifty, screen.getID()), new EndNotify() {

        @Override
        public void perform() {
           setChanged();
           notifyObservers(new ReloadGuiEvent(gui));
           clearChanged();
        }
    });
   currentL=gui.getTopLayer();
   currentS=gui.gettopScreen();
   currentlayers.addAll(gui.getLayers());
   dragDropManager = new NiftyDDManager(nifty);
   this.model.setCurentGUI(gui);
   return res;
        
}
 
示例14
/**
 * Create a new gui from a file with given assetsFolder
 * @param nifty a valid Nifty instace @see Nifty
 * @throws ParserConfigurationException if controller failed to create
 * a valid document instance
 * @throws IOException
 * @throws  SAXException
 * @throws Exception if nifty can't create the gui
 * @return A string with the elements that weren't loaded
  */
 public String createNewGui(Nifty nifty ,File filename,File assetsFolder) throws ParserConfigurationException, IOException, SAXException, NoProductException, Exception{
   GUIReader reader = new GUIReader(nifty);
   String res = "";
   this.gui = reader.readGUI(filename);
   this.gui.setAssetFolder(assetsFolder);
   res = reader.getTagNotLoaded();
   final GScreen screen =this.getGui().gettopScreen();
   for(String sel : nifty.getAllScreensName()){
                nifty.removeScreen(sel);
   }
   writer = new GUIWriter(gui);
  nifty.scheduleEndOfFrameElementAction(new Reload(nifty, screen.getID()), new EndNotify() {

        @Override
        public void perform() {
           setChanged();
           notifyObservers(new ReloadGuiEvent(gui));
           clearChanged();
        }
    });
   currentL=gui.getTopLayer();
   currentS=gui.gettopScreen();
   currentlayers.addAll(gui.getLayers());
   dragDropManager = new NiftyDDManager(nifty);
   this.model.setCurentGUI(gui);
   return res;
        
}
 
示例15
/**
 * Create a new gui from a file with given assetsFolder
 * @param nifty a valid Nifty instace @see Nifty
 * @throws ParserConfigurationException if controller failed to create
 * a valid document instance
 * @throws IOException
 * @throws  SAXException
 * @throws Exception if nifty can't create the gui
 * @return A string with the elements that weren't loaded
  */
 public String createNewGui(Nifty nifty , InputStream stream,File assetsFolder) throws ParserConfigurationException, IOException, SAXException, NoProductException, Exception{
   GUIReader reader = new GUIReader(nifty);
   String res = "";
   this.gui = reader.readGUI(stream);
   this.gui.setAssetFolder(assetsFolder);
   res = reader.getTagNotLoaded();
   final GScreen screen =this.getGui().gettopScreen();
   for(String sel : nifty.getAllScreensName()){
                nifty.removeScreen(sel);
   }
   writer = new GUIWriter(gui);
  nifty.scheduleEndOfFrameElementAction(new Reload(nifty, screen.getID()), new EndNotify() {

        @Override
        public void perform() {
           setChanged();
           notifyObservers(new ReloadGuiEvent(gui));
           clearChanged();
        }
    });
   currentL=gui.getTopLayer();
   currentS=gui.gettopScreen();
   currentlayers.addAll(gui.getLayers());
   dragDropManager = new NiftyDDManager(nifty);
   this.model.setCurentGUI(gui);
   return res;
        
}
 
示例16
/**
 * Refresh the current gui . It causes a call to nifty.fromXml method. 
 * @param nifty
 * @throws Exception if nifty can't load the old gui
 */
public void refresh(Nifty nifty) throws Exception{
    if(getGui() != null){
        String screenID =this.currentS.getID();
            nifty.scheduleEndOfFrameElementAction(new Reload(nifty, screenID), null);
            
            
    }
}
 
示例17
public void lightRefresh() {
    Nifty temp = nElement.getNifty();
    Screen currentScreen = temp.getCurrentScreen();
    Attributes att = this.nElement.getElementType().getAttributes();
    nElement.initializeFromAttributes(currentScreen, att, temp.getRenderEngine());
    currentScreen.layoutLayers();
}
 
示例18
public void reloadElement(Nifty manager) {
    Nifty nif = manager;
    if (nElement != null) {
        nif = nElement.getNifty();
    }
    nElement = parent.nElement.findElementById(id);
}
 
示例19
public void createNiftyElement(Nifty nifty) {
    for (String sel : attributes.keySet()) {
        builder.set(sel, attributes.get(sel));
    }
    nElement = builder.build(nifty, nifty.getCurrentScreen(), this.parent.getDropContext());

}
 
示例20
@Override
protected void internalRefresh(Nifty nifty, Attributes att) {
    int index = parent.getNiftyElement().getChildren().indexOf(nElement);
    final GElement telement = this;

    nElement.markForRemoval(new EndNotify() {
        @Override
        public void perform() {
            this.buildChild(telement);
        }

        private void buildChild(GElement ele) {
            for (GElement e : ele.getElements()) {
                ele.getDropContext().addChild(e.getNiftyElement());
                e.refresh();
                this.buildChild(e);
            }
        }
    });
    for (String sel : attributes.keySet()) {
        builder.set(sel, attributes.get(sel));
    }

    nElement = builder.build(nifty, nifty.getCurrentScreen(), this.parent.getDropContext(), index);
    nifty.getCurrentScreen().layoutLayers();
    String keyWord = "style-refresh:"+attributes.get("style");
    nifty.getEventService().unsubscribe(keyWord, specialRerefresher);
    nifty.getEventService().subscribe(keyWord, specialRerefresher);
}
 
示例21
@Override
public void createNiftyElement(Nifty nifty) {
    Screen screen = new ScreenBuilder(id){{
         
    }}.build(nifty);
    nElement = screen.getRootElement();
     for(String sel : attributes.keySet()){
           nElement.getElementType().getAttributes().set(sel, attributes.get(sel));
     }
    
}
 
示例22
@Override
public void reloadElement(Nifty manger) {
     Nifty nif = manger;
    if(nElement != null)
        nif = nElement.getNifty();
    Collection<String> pe = nif.getAllScreensName();
    
    nElement = nif.getScreen(id).getRootElement();
     for(String sel : attributes.keySet()){
           nElement.getElementType().getAttributes().set(sel, attributes.get(sel));
     }
}
 
示例23
public NiftyDDManager(Nifty nifty){
    Element temp = nifty.findPopupByName(NIFTY_EDITOR_POPUP_SUPPORT);
    if(temp == null){
        PopupBuilder builder = new PopupBuilder(NIFTY_EDITOR_POPUP_SUPPORT);
        builder.childLayoutAbsolute();
        builder.registerPopup(nifty);
        temp = nifty.createPopup(NIFTY_EDITOR_POPUP_SUPPORT);
    }
    popUp = temp;
    this.nifty = nifty;
    dragged = null;
}
 
示例24
/**
 * Creates a new gui
 *
 * @param nifty
 */
protected GUI(Nifty nifty) {
    this.manager = nifty;
    this.screens = new LinkedList<GScreen>();
    this.currentS = null;
    ID = GUI.GUIID++;
    this.assetsFile = new File(".");
    this.selection = new Selection();
}
 
示例25
public NiftyJmeDisplay(AssetManager assetManager, 
                       InputSystem inputManager,
                       AudioRenderer audioRenderer,
                       ViewPort vp){
    this.assetManager = assetManager;
    //TODO: move
    ((DesktopAssetManager)assetManager).clearCache();
    w = vp.getCamera().getWidth();
    h = vp.getCamera().getHeight();

    soundDev = new SoundDeviceJme(assetManager, audioRenderer);
    renderDev = new RenderDeviceJme(this);
    nifty = new Nifty(renderDev, soundDev, inputManager, new TimeProvider());
}
 
示例26
public GuiTrack(Nifty nifty, String screen) {
    this.screen = screen;
    this.nifty = nifty;
}
 
示例27
public GuiTrack(Nifty nifty, String screen, float initialDuration) {
    super(initialDuration);
    this.screen = screen;
    this.nifty = nifty;
}
 
示例28
public GuiTrack(Nifty nifty, String screen, LoopMode loopMode) {
    super(loopMode);
    this.screen = screen;
    this.nifty = nifty;
}
 
示例29
public GuiTrack(Nifty nifty, String screen, float initialDuration, LoopMode loopMode) {
    super(initialDuration, loopMode);
    this.screen = screen;
    this.nifty = nifty;
}
 
示例30
public void setNifty(Nifty nifty) {
    this.nifty = nifty;
}