/** * Sets the tile rendered by this layer to the asynchronous result of {@code tile}. When the * future completes, this layer's tile will be set. Until then, the current tile (if any) will * continue to be rendered. */ public ImageLayer setTile (RFuture<? extends Tile> tile) { tile.onSuccess(new Slot<Tile>() { public void onEmit (Tile tile) { setTile(tile); } }); return this; }
/** Configures the image used in our up state. */ public ImageButton setUp (TileSource up) { _up = up; _up.tileAsync().onSuccess(new UnitSlot() { public void onEmit () { invalidate(); } }); return this; }
/** Configures the image used in our down state. */ public ImageButton setDown (TileSource down) { _down = down; _down.tileAsync().onSuccess(new UnitSlot() { public void onEmit () { invalidate(); } }); return this; }
public PackedFrames (TileSource source, float width, float height, Frame[] frames) { if (source.isLoaded()) _tile = source.tile(); else source.tileAsync().onSuccess(new Slot<Tile>() { public void onEmit (Tile tile) { _tile = tile; } }); _width = width; _height = height; _frames = frames; }
Image atlas = imageLoader.load(baseDir + "/" + atlasData.file); atlasImages.add(atlas.state); atlas.state.onSuccess(new Slot<Image>() { public void onEmit (Image image) { for (LibraryData.TextureData textureData : atlasData.textures) { RFuture.sequence(atlasImages).onSuccess(new Slot<List<Image>>() { public void onEmit (List<Image> atlases) { result.succeed(new Library(frameRate, movies, textures));
/** * Creates an instance with the supplied tile source. The tile is assumed to contain {@code * count} frames, each {@code width x height} in size, in row major order (any missing frames * are on the right side of the bottom row). * @param width the width of each frame. * @param height the width of each frame. */ public SimpleFrames (TileSource source, float width, float height, int count) { if (source.isLoaded()) _tile = source.tile(); else source.tileAsync().onSuccess(new Slot<Tile>() { public void onEmit (Tile tile) { _tile = tile; } }); _width = width; _height = height; _count = count; }
protected void loadURL (String url) { displayText("Loading: " + url); try { game.net.req(url).execute().onSuccess(this::displayResult).onFailure(this::displayError); } catch (Exception e) { displayText(e.toString()); } }
/** * Sets the texture rendered by this layer to the texture provided by {@code source}. If {@code * source} is not yet ready, the texture will be set when it becomes ready. Until then any * previous texture will continue to be displayed. */ public ImageLayer setSource (TileSource source) { if (source.isLoaded()) setTile(source.tile()); else source.tileAsync().onSuccess(new Slot<Tile>() { public void onEmit (Tile tile) { setTile(tile); } }); return this; }
@Override public void onEmit () { String init = ""; if (tabs.tabCount() > 0) { Tabs.Tab tab = tabs.tabAt(_rnd.nextInt(tabs.tabCount())); init = "" + number(tab); } input().getText(Keyboard.TextType.NUMBER, "Enter tab number", init). onSuccess(new Slot<String>() { @Override public void onEmit (String result) { for (int ii = 0; ii < tabs.tabCount(); ii++) { if (result.equals("" + number(tabs.tabAt(ii)))) { handle(tabs.tabAt(ii)); break; } } } }); }
@Override public void onEmit (Icon icon) { if (icon == null) { clearLayoutData(); invalidate(); } else { icon.state().onSuccess(new Slot<Icon>() { public void onEmit (Icon resource) { // clear out the rendered icon in case we got laid out before the async // load finished _renderedIcon = null; clearLayoutData(); invalidate(); } }); } } };
@Override public void init() { final Image tile = game.assets.getImage("images/tile.png"); final Image orange = game.assets.getImage("images/orange.png"); Slot<Throwable> onError = new Slot<Throwable>() { float errY = 0; public void onEmit (Throwable err) { addDescrip("Error: " + err.getMessage(), 10, errY, game.graphics.viewSize.width()-20); errY += 30; } }; tile.state.onFailure(onError); orange.state.onFailure(onError); RFuture.collect(Arrays.asList(tile.state, orange.state)). onSuccess(imgs -> addTests(orange, tile)); }
/** Syncs the supplied database with this session's server. */ public void sync (final SyncDB db) { final Map<String,Integer> mods = db.getMods(); _server.sendSync(db.version(), db.getDelta()).onSuccess(new Slot<Response>() { public void onEmit (Response rsp) { onSyncSuccess(db, mods, rsp); } }).onFailure(new Slot<Throwable>() { public void onEmit (Throwable cause) { onSyncFailure(db, cause); } }); }
/** * Loads a binary encoded library via PlayN assets. * @param baseDir The base directory, containing library.bin and texture atlases. */ public static RFuture<Library> loadLibrary (final Platform plat, final String baseDir) { final RPromise<Library> result = RPromise.create(); plat.assets().getBytes(baseDir + "/library.bin").onSuccess(new Slot<ByteBuffer>() { public void onEmit (ByteBuffer buf) { try { LibraryData libData = new LibraryData(buf); decodeLibraryAsync(plat, libData, baseDir, result); } catch (Exception err) { result.fail(err); } } }); return result; }
@Override protected Group createIface (Root root) { final Group main = new Group(new AbsoluteLayout()); JsonLoader.loadLibrary(game().plat, "flump").onSuccess(new Slot<Library>() { public void onEmit (Library lib) { final Movie movie = lib.createMovie("walk"); movie.layer().setTranslation(size().width()/2, 300); main.layer.add(movie.layer()); closeOnHide(paint.connect(new Slot<Clock>() { public void onEmit (Clock clock) { movie.paint(clock); } })); } }); return main; } }
@Override public Image getRemoteImage(final String url, int width, int height) { final ImageImpl image = createImage(true, width, height, url); plat.net().req(url).execute(). onSuccess(new Slot<Net.Response>() { public void onEmit (Net.Response rsp) { try { image.succeed(toData(Scale.ONE, new UIImage(new NSData(rsp.payload())))); } catch (Throwable t) { plat.log().warn("Failed to decode remote image [url=" + url + "]", t); image.fail(t); } } }). onFailure(new Slot<Throwable>() { public void onEmit (Throwable cause) { image.fail(cause); } }); return image; }
private void addTestCanvas(String descrip, int width, int height, String imagePath, ImageDrawer drawer) { Canvas target = game.graphics.createCanvas(width, height); ImageLayer layer = new ImageLayer().setSize(width, height); game.assets.getImage(imagePath).state.onSuccess(image -> { drawer.draw(target, image); layer.setTile(target.toTexture()); }); addTestLayer(descrip, width, height, layer); }
protected void startEdit () { if (hasNative()) { updateMode(true); _nativeField.focus(); } else { // TODO: multi-line keyboard.getText root().iface.plat.input().getText(_textType, _popupLabel, text.get()). onSuccess(new Slot<String>() { @Override public void onEmit (String result) { // null result is a canceled entry dialog if (result != null) text.update(result); _finishedEditing.emit(result != null); } }); } }
onSuccess(new Slot<String>() { public void onEmit (String text) { if (text == null) return;
@Override public void init() { Image orange = game.assets.getImage("images/orange.png"); ImageLayer l1 = new ImageLayer(orange); game.rootLayer.addAt(l1.setScale(2).setRotation(FloatMath.PI/8), 50, 50); l1.events().connect(new Mover(l1).listener(game.input)); ImageLayer l2 = new ImageLayer(orange); game.rootLayer.addAt(l2.setScale(1.5f).setRotation(FloatMath.PI/4), 150, 50); l2.events().connect(new Mover(l2).listener(game.input)); Image mdb = game.assets.getRemoteImage("https://www.samskivert.com/images/headshot.jpg"); ImageLayer l3 = new ImageLayer(mdb); game.rootLayer.addAt(l3.setRotation(-FloatMath.PI/4), 50, 150); l3.events().connect(new Mover(l3).listener(game.input)); String l4url = "https://www.samskivert.com/images/2012/12/spellwood-app-icon.png"; game.net.req(l4url).execute().onSuccess(rsp -> { try { Image icon = rsp.payloadImage(new Scale(2)); ImageLayer l4 = new ImageLayer(icon); game.rootLayer.addAt(l4.setRotation(FloatMath.PI/4), 150, 150); l4.events().connect(new Mover(l4).listener(game.input)); } catch (Exception e) { game.log.warn("Failed to decode image: " + e); } }).onFailure(t -> game.log.warn("Failed to load image: " + l4url, t)); }
game.assets.getImage(imageSrc).state.onSuccess(image -> { Texture imtex = image.texture(); game.rootLayer.addAt(new ImageLayer(imtex), offset, offset);