Java Code Examples for com.badlogic.gdx.scenes.scene2d.Actor

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Actor. These examples are extracted from open source projects. 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 Project: gdx-controllerutils   Source File: ControllerMenuStage.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 2
Source Project: gdx-vfx   Source File: AdvancedColorLmlAttribute.java    License: Apache License 2.0 6 votes vote down vote up
@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 3
Source Project: gdx-ai   Source File: TabbedPane.java    License: Apache License 2.0 6 votes vote down vote up
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 4
Source Project: vis-ui   Source File: TestIssue326.java    License: Apache License 2.0 6 votes vote down vote up
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 5
Source Project: vis-ui   Source File: MultiSplitPane.java    License: Apache License 2.0 6 votes vote down vote up
/** 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 Project: skin-composer   Source File: InfoTable.java    License: MIT License 6 votes vote down vote up
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 7
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 8
Source Project: gdx-vfx   Source File: Scene2dUtils.java    License: Apache License 2.0 6 votes vote down vote up
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 9
Source Project: bladecoder-adventure-engine   Source File: PropertyTable.java    License: Apache License 2.0 6 votes vote down vote up
@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 10
Source Project: Cubes   Source File: DropDownSetting.java    License: MIT License 6 votes vote down vote up
@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 11
Source Project: vis-ui   Source File: DirsSuggestionPopup.java    License: Apache License 2.0 6 votes vote down vote up
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 12
Source Project: gdx-gltf   Source File: Vector2UI.java    License: Apache License 2.0 6 votes vote down vote up
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 13
Source Project: Cardshifter   Source File: DeckBuilderScreen.java    License: Apache License 2.0 6 votes vote down vote up
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 14
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 15
Source Project: Cardshifter   Source File: ResViewFactory.java    License: Apache License 2.0 5 votes vote down vote up
public ResView str(String s) {
    final Label label = new Label(s, skin);
    return new ResView() {
        @Override
        public Actor getActor() {
            return label;
        }

        @Override
        public void update(Map<String, ? extends Object> properties) {

        }
    };
}
 
Example 16
Source Project: cocos-ui-libgdx   Source File: BaseWidgetParser.java    License: Apache License 2.0 5 votes vote down vote up
private Touchable deduceTouchable(Actor actor, ObjectData widget) {
    if (widget.isTouchEnable()) {
        return Touchable.enabled;
    } else if (Touchable.childrenOnly.equals(actor.getTouchable())) {
        return Touchable.childrenOnly;
    } else {
        return Touchable.disabled;
    }
}
 
Example 17
Source Project: gdx-vfx   Source File: PatchedOnClickLmlAttribute.java    License: Apache License 2.0 5 votes vote down vote up
@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 18
Source Project: gdx-vfx   Source File: OriginLmlAttribute.java    License: Apache License 2.0 5 votes vote down vote up
@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 19
Source Project: bladecoder-adventure-engine   Source File: TabPanel.java    License: Apache License 2.0 5 votes vote down vote up
public void setTab(int i) {		
	Actor panel = tabs.get(i).content;
	tabs.get(i).button.setChecked(true);
	body.setActor(null);
	body.clear();
	body.setActor(panel);
}
 
Example 20
Source Project: gdx-vfx   Source File: LmlUtils.java    License: Apache License 2.0 5 votes vote down vote up
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 21
Source Project: dice-heroes   Source File: CraftingPane.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void clean() {
    Array<Actor> keys = inputs.keys().toArray();
    for (ItemIcon icon : inputs.values()) {
        if (icon != null) {
            icon.remove();
        }
    }
    for (Actor actor : keys) {
        inputs.put(actor, null);
    }
    updateResult();
}
 
Example 22
Source Project: riiablo   Source File: LabelManager.java    License: Apache License 2.0 5 votes vote down vote up
@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 23
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 24
Source Project: skin-composer   Source File: ResizeArrowListener.java    License: MIT License 5 votes vote down vote up
@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 25
Source Project: vis-ui   Source File: VisSplitPane.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @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();
}
 
Example 26
Source Project: skin-composer   Source File: DialogSceneComposerJavaBuilder.java    License: MIT License 5 votes vote down vote up
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 27
private void assignShortcut(Actor actor, String rawAttributeData) {
    if (actor instanceof MenuItem) {
        MenuItem menuItem = (MenuItem) actor;

        String shortcut = App.inst().getShortcuts().resolveShortcutString(rawAttributeData);
        menuItem.setShortcut(shortcut);
    }
}
 
Example 28
Source Project: vis-ui   Source File: VerticalFlowGroup.java    License: Apache License 2.0 5 votes vote down vote up
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 29
Source Project: gdx-vfx   Source File: Scene2dUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Rectangle localToStageBounds(Actor actor, float x0, float y0, float x1, float y1) {
    Rectangle stageRect = Scene2dUtils.tmpRect;
    actor.localToStageCoordinates(tmpVec2.set(x0, y0));
    stageRect.setX(tmpVec2.x);
    stageRect.setY(tmpVec2.y);
    actor.localToStageCoordinates(tmpVec2.set(x1, y1));
    stageRect.setWidth(tmpVec2.x - stageRect.x);
    stageRect.setHeight(tmpVec2.y - stageRect.y);
    return stageRect;
}
 
Example 30
Source Project: gdx-vfx   Source File: Scene2dUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Rectangle stageToLocalBounds(Actor actor, Rectangle stageBounds) {
    return localToStageBounds(actor,
            stageBounds.x,
            stageBounds.y,
            stageBounds.x + stageBounds.width,
            stageBounds.y + stageBounds.height);
}