com.badlogic.gdx.scenes.scene2d.Actor Java Examples
The following examples show how to use
com.badlogic.gdx.scenes.scene2d.Actor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PagedScrollPane.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
private void scrollToPage () { final float width = getWidth(); final float scrollX = getScrollX(); final float maxX = getMaxX(); if (scrollX >= maxX || scrollX <= 0) return; Array<Actor> pages = content.getChildren(); float pageX = 0; float pageWidth = 0; if (pages.size > 0) { for (Actor a : pages) { pageX = a.getX(); pageWidth = a.getWidth(); if (scrollX < (pageX + pageWidth * 0.5)) { break; } } setScrollX(MathUtils.clamp(pageX - (width - pageWidth) / 2, 0, maxX)); } }
Example #2
Source File: Vector2UI.java From gdx-gltf with Apache License 2.0 | 6 votes |
public Vector2UI(Skin skin, final Vector2 value) { super(skin); this.value = value; for(int i=0 ; i<2 ; i++){ final Slider slider = new Slider(0, 1, .01f, false, skin); add(name(i)); add(slider).row(); slider.setValue(get(i)); final int index = i; slider.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { set(index, slider.getValue()); } }); } }
Example #3
Source File: InfoTable.java From skin-composer with MIT License | 6 votes |
public InfoTable(final Skin skin, final Stage stage) { pad(10.0f); var label = new Label(Core.readAndReplace("about.txt"), skin, "small"); label.setWrap(true); label.setTouchable(Touchable.disabled); add(label).growX().expandY().top(); row(); var textButton = new TextButton("OK", skin); add(textButton).growX().height(30.0f); textButton.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { Core.transition(InfoTable.this, new MenuTable(skin, stage)); } }); }
Example #4
Source File: Scene2dUtils.java From gdx-vfx with Apache License 2.0 | 6 votes |
public static void simulateClickGlobal(Actor actor, int button, int pointer, float stageX, float stageY) { InputEvent event = Pools.obtain(InputEvent.class); event.setStage(actor.getStage()); event.setRelatedActor(actor); event.setTarget(actor); event.setStageX(stageX); event.setStageY(stageY); event.setButton(button); event.setPointer(pointer); event.setType(InputEvent.Type.touchDown); actor.notify(event, false); event.setType(InputEvent.Type.touchUp); actor.notify(event, false); Pools.free(event); }
Example #5
Source File: MultiSplitPane.java From vis-ui with Apache License 2.0 | 6 votes |
/** Changes widgets of this split pane. You can pass any number of actors even 1 or 0. Actors can't be null. */ public void setWidgets (Iterable<Actor> actors) { clearChildren(); widgetBounds.clear(); scissors.clear(); handleBounds.clear(); splits.clear(); for (Actor actor : actors) { super.addActor(actor); widgetBounds.add(new Rectangle()); scissors.add(new Rectangle()); } float currentSplit = 0; float splitAdvance = 1f / getChildren().size; for (int i = 0; i < getChildren().size - 1; i++) { handleBounds.add(new Rectangle()); currentSplit += splitAdvance; splits.add(currentSplit); } invalidate(); }
Example #6
Source File: TestIssue326.java From vis-ui with Apache License 2.0 | 6 votes |
public TestIssue326 () { super("issue #326"); final VisTextField passwordTextField = new VisTextField("password"); final IntSpinnerModel intModel = new IntSpinnerModel(10, -5, 20, 2); Spinner intSpinner = new Spinner("int", intModel); intSpinner.addListener(new ChangeListener() { @Override public void changed (ChangeEvent event, Actor actor) { passwordTextField.setDisabled(true); } }); add(new LinkLabel("issue #326 - FocusManager crash", "https://github.com/kotcrab/vis-ui/issues/326")).colspan(2).row(); add(passwordTextField); row(); add(intSpinner); setResizable(false); setModal(false); addCloseButton(); closeOnEscape(); pack(); centerWindow(); }
Example #7
Source File: TabbedPane.java From gdx-ai with Apache License 2.0 | 6 votes |
public void addTab (String title, Actor actor) { int index = tabTitleTable.getCells().size; TabTitleButton button = new TabTitleButton(index, title, style); button.addListener(new ClickListener() { @Override public void clicked (InputEvent event, float x, float y) { TabTitleButton tabTitleButton = (TabTitleButton)event.getListenerActor(); // if (tabTitleButton.isChecked()) setSelectedIndex(tabTitleButton.index); } }); tabTitleTable.add(button); // .uniform().fill(); // uniform gives tabs the same size tabBodyStack.add(actor); // Make sure the 1st tab is selected even after adding the tab // TODO // CAUTION: if you've added a ChangeListener before adding the tab // the following lines will fire 2 ChangeEvents. setSelectedIndex(index); setSelectedIndex(0); }
Example #8
Source File: PropertyTable.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public void setProperty(String name, String value) { SnapshotArray<Actor> actors = table.getChildren(); for (Actor a : actors) { if (name.equals(a.getName())) { if (a instanceof SelectBox<?>) { ((SelectBox<String>) a).setSelected(value == null ? "" : value); } else { ((TextField) a).setText(value == null ? "" : value); } return; } } }
Example #9
Source File: DeckBuilderScreen.java From Cardshifter with Apache License 2.0 | 6 votes |
public void removeCardFromDeck(int id) { for (Actor actor : cardsInDeckList.getChildren()) { if (actor instanceof DeckCardView) { if (actor instanceof DeckCardView) { if (((DeckCardView)actor).getId() == id) { int newCount = ((DeckCardView)actor).getCount() - 1; if (newCount > 0) { ((DeckCardView) actor).setCount(newCount); } else { actor.remove(); } config.setChosen(id, newCount); } } } } this.updateLabels(); this.displayPage(this.page); }
Example #10
Source File: EditableSelectBox.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
public void hide() { if (!list.isTouchable() || !hasParent()) return; list.setTouchable(Touchable.disabled); Stage stage = getStage(); if (stage != null) { stage.removeCaptureListener(hideListener); if (previousScrollFocus != null && previousScrollFocus.getStage() == null) previousScrollFocus = null; Actor actor = stage.getScrollFocus(); if (actor == null || isAscendantOf(actor)) stage.setScrollFocus(previousScrollFocus); } clearActions(); getColor().a = 1; addAction(sequence(fadeOut(0.15f, Interpolation.fade), Actions.removeActor())); }
Example #11
Source File: AdvancedColorLmlAttribute.java From gdx-vfx with Apache License 2.0 | 6 votes |
@Override public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) { if (rawAttributeData.startsWith("#")) { String hexCode = rawAttributeData.substring(1); Color color; try { color = CommonUtils.parseHexColor(hexCode); } catch (Exception e) { parser.throwError("Error parsing HEX code value \"" + hexCode + "\"", e); return; } actor.setColor(color); } else { super.process(parser, tag, actor, rawAttributeData); } }
Example #12
Source File: DirsSuggestionPopup.java From vis-ui with Apache License 2.0 | 6 votes |
private int createRecentDirSuggestions (Array<FileHandle> files, float width) { clearChildren(); int suggestions = 0; for (final FileHandle file : files) { if (file.exists() == false) continue; MenuItem item = createMenuItem(file.path()); item.getLabel().setEllipsis(true); item.getLabelCell().width(width - 20); addItem(item); item.addListener(new ChangeListener() { @Override public void changed (ChangeEvent event, Actor actor) { chooser.setDirectory(file, FileChooser.HistoryPolicy.ADD); } }); suggestions++; if (suggestions == MAX_SUGGESTIONS) { break; } } return suggestions; }
Example #13
Source File: ControllerMenuStage.java From gdx-controllerutils with Apache License 2.0 | 6 votes |
/** * checks if the given actor is focusable: in the list of focusable actors, visible, touchable, and on the stage * * @param actor * @return true if focusable */ protected boolean isActorFocusable(Actor actor) { if (!focusableActors.contains(actor, true)) return false; if (!actor.isVisible()) return false; if (!actor.isTouchable() && !(actor instanceof IControllerActable)) return false; if (actor.getStage() != this) return false; return true; }
Example #14
Source File: DropDownSetting.java From Cubes with MIT License | 6 votes |
@Override public Actor getActor(final String settingName, VisualSettingManager visualSettingManager) { final SelectBox<String> selectBox = new SelectBox<String>(visualSettingManager.getSkin()) { @Override protected String toString(String s) { return Settings.getLocalisedSettingName(settingName + "." + s); } }; selectBox.setItems(options); selectBox.setSelected(selected); selectBox.addListener(new EventListener() { @Override public boolean handle(Event event) { if (!(event instanceof SettingsMenu.SaveEvent)) return false; set(selectBox.getSelected()); return true; } }); return selectBox; }
Example #15
Source File: PatchedOnClickLmlAttribute.java From gdx-vfx with Apache License 2.0 | 5 votes |
@Override public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) { final ActorConsumer<?, Actor> action = parser.parseAction(rawAttributeData, actor); if (action == null) { parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor); } actor.addListener(new ClickListener() { @Override public void clicked(final InputEvent event, final float x, final float y) { if (event.isHandled()) return; action.consume(actor); } }); }
Example #16
Source File: OriginLmlAttribute.java From gdx-vfx with Apache License 2.0 | 5 votes |
@Override public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) { final int origin = LmlUtilities.parseAlignment(parser, actor, rawAttributeData); // Simple trick to make this attribute applied after actor is laid out (likely) actor.addAction(ActionsExt.post(Actions.run(new Runnable() { @Override public void run() { actor.setOrigin(origin); } }))); }
Example #17
Source File: PackDialogController.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
private void showReopenLastDialogNotification() { final LmlParser parser = interfaceService.getParser(); final ToastTable toastTable = new ToastTable(); final String actionName = "showLastDialog"; if (prevReopenDialogToast != null) { eventDispatcher.postEvent(new RemoveToastEvent().toast(prevReopenDialogToast)); prevReopenDialogToast = null; } parser.getData().addActorConsumer(actionName, new ActorConsumer<Void, Object>() { @Override public Void consume(Object actor) { if (window != null) { window.show(stage); } toastTable.fadeOut(); return null; } }); Actor content = parser.parseTemplate(Gdx.files.internal("lml/toastReopenLastPackingDialog.lml")).first(); parser.getData().removeActorConsumer(actionName); toastTable.add(content).grow(); eventDispatcher.postEvent(new ShowToastEvent() .content(toastTable) .duration(10f)); prevReopenDialogToast = toastTable.getToast(); }
Example #18
Source File: MundusMultiSplitPane.java From Mundus with Apache License 2.0 | 5 votes |
@Override public float getPrefHeight() { float height = 0; for (Actor actor : getChildren()) { height = actor instanceof Layout ? ((Layout) actor).getPrefHeight() : actor.getHeight(); } if (vertical) height += handleBounds.size * style.handle.getMinHeight(); return height; }
Example #19
Source File: Scene2dUtils.java From gdx-vfx with Apache License 2.0 | 5 votes |
public static Rectangle stageToLocalBounds(Actor actor, Rectangle stageBounds) { return localToStageBounds(actor, stageBounds.x, stageBounds.y, stageBounds.x + stageBounds.width, stageBounds.y + stageBounds.height); }
Example #20
Source File: VerticalFlowGroup.java From vis-ui with Apache License 2.0 | 5 votes |
private void computeSize () { prefWidth = 0; prefHeight = getHeight(); sizeInvalid = false; SnapshotArray<Actor> children = getChildren(); float y = 0; float columnWidth = 0; for (int i = 0; i < children.size; i++) { Actor child = children.get(i); float width = child.getWidth(); float height = child.getHeight(); if (child instanceof Layout) { Layout layout = (Layout) child; width = layout.getPrefWidth(); height = layout.getPrefHeight(); } if (y + height > getHeight()) { y = 0; prefWidth += columnWidth + spacing; columnWidth = width; } else { columnWidth = Math.max(width, columnWidth); } y += height + spacing; } //handle last column width prefWidth += columnWidth + spacing; }
Example #21
Source File: DialogSceneComposerJavaBuilder.java From skin-composer with MIT License | 5 votes |
private static TypeSpec basicNodeType() { return TypeSpec.classBuilder("BasicNode") .superclass(Node.class) .addModifiers(Modifier.PUBLIC, Modifier.STATIC) .addMethod(MethodSpec.constructorBuilder() .addModifiers(Modifier.PUBLIC) .addParameter(Actor.class, "actor") .addStatement("super(actor)") .build()) .build(); }
Example #22
Source File: LmlUtils.java From gdx-vfx with Apache License 2.0 | 5 votes |
public static <T extends Actor> T parseLmlTemplate(LmlParser lmlParser, LmlView viewController, FileHandle fileHandle) { // Check if the view controller was added as an action container already. final ActionContainerWrapper acw = lmlParser.getData().getActionContainer(viewController.getViewId()); final ActionContainer actionContainer; if (acw != null) { actionContainer = acw.getActionContainer(); } else { actionContainer = null; } Array<Actor> actors = lmlParser.createView(viewController, fileHandle); if (actionContainer != null) { // LmlParser removes action container after layout parsing. Let's add it back. lmlParser.getData().addActionContainer(viewController.getViewId(), actionContainer); } if (viewController.getStage() != null) { // LmlParser adds created actors directly to the stage after layout parsing. // Now we should remove them manually... for (Actor actor : actors) { actor.remove(); } } return (T) actors.first(); }
Example #23
Source File: LabelManager.java From riiablo with Apache License 2.0 | 5 votes |
@Override protected void process(int entityId) { tmpVec2.set(mPosition.get(entityId).position); iso.toScreen(tmpVec2); Label label = mLabel.get(entityId); tmpVec2.add(label.offset); Actor actor = label.actor; actor.setPosition(tmpVec2.x, tmpVec2.y, Align.center | Align.bottom); labels.add(actor); }
Example #24
Source File: DefaultSceneScreen.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
public void setTextManagerUI(Actor a) { if (a instanceof ITextManagerUI) { textManagerUI.remove(); textManagerUI = a; stage.addActor(textManagerUI); } else { EngineLogger.error("ERROR setTextManagerUI: actor is not a ITextManagerUI"); dispose(); Gdx.app.exit(); } }
Example #25
Source File: ResurrectVisualizer.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@Override public IFuture<Void> visualize(final ResurrectResult result) { final Future<Void> future = new Future<Void>(); final ParticleActor particle = new ParticleActor(Config.particles.get("ability-resurrection-" + result.resurrected.profession.name).obtain()); particle.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { particle.remove(); particle.effect.free(); } }); particle.setPosition( ViewController.CELL_SIZE * result.coordinate.x() + ViewController.CELL_SIZE / 2f, ViewController.CELL_SIZE * result.coordinate.y() + PARTICLE_OFFSET ); particle.addAction(Actions.moveBy(0, -PARTICLE_OFFSET + 5, 1f)); visualizer.viewController.effectLayer.addActor(particle); result.resurrected.setPosition(result.coordinate.x(), result.coordinate.y()); WorldObjectView view = visualizer.viewController.addView(result.resurrected); view.getColor().a = 0; SoundManager.instance.playSound("ability-resurrect"); view.addAction(Actions.sequence( Actions.alpha(1f, 1f), Actions.run(new Runnable() { @Override public void run() { particle.effect.allowCompletion(); visualizer.viewController.removeView(result.resurrected); future.happen(); } }) )); return future; }
Example #26
Source File: GUIManagerGDX.java From Entitas-Java with MIT License | 5 votes |
@Override public Actor createGUIElement(String name) { GUIFactory<Actor,GUIManagerGDX> factory = guiFactories.get(name); Actor element = null; if (factory != null) { element = factory.create(this); } return element; }
Example #27
Source File: MenuTools.java From Cubes with MIT License | 5 votes |
public static void arrangeY(float x, boolean centerX, Actor... actors) { float w = (GUI_HEIGHT / (actors.length + 1)); for (int i = 0; i < actors.length; i++) { Actor a = actors[i]; a.setPosition(x - (centerX ? (a.getWidth() / 2f) : 0), ((i + 0.5f) * w) - (a.getHeight() / 2f)); } }
Example #28
Source File: ResizeArrowListener.java From skin-composer with MIT License | 5 votes |
@Override public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) { if (!draggingCursor && event.getListenerActor().equals(event.getTarget())) { Gdx.graphics.setSystemCursor(Cursor.SystemCursor.Arrow); } }
Example #29
Source File: LabelWidget.java From talos with Apache License 2.0 | 5 votes |
@Override public Actor getSubWidget() { propertyValue = new Label("", TalosMain.Instance().getSkin()); propertyValue.setWidth(170); propertyValue.setEllipsis(true); propertyValue.setAlignment(Align.right); return propertyValue; }
Example #30
Source File: VisSplitPane.java From vis-ui with Apache License 2.0 | 5 votes |
/** * @param firstWidget May be null. * @param secondWidget May be null. */ public VisSplitPane (Actor firstWidget, Actor secondWidget, boolean vertical, VisSplitPaneStyle style) { this.firstWidget = firstWidget; this.secondWidget = secondWidget; this.vertical = vertical; setStyle(style); setFirstWidget(firstWidget); setSecondWidget(secondWidget); setSize(getPrefWidth(), getPrefHeight()); initialize(); }