Example usage for com.badlogic.gdx.scenes.scene2d Actor getUserObject

List of usage examples for com.badlogic.gdx.scenes.scene2d Actor getUserObject

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d Actor getUserObject.

Prototype

public Object getUserObject() 

Source Link

Document

Returns an application specific object for convenience, or null.

Usage

From source file:es.eucm.ead.editor.control.actions.editor.ShowInfoPanel.java

License:Open Source License

@Override
public void initialize(final Controller controller) {
    super.initialize(controller);
    skin = controller.getApplicationAssets().getSkin();
    i18n = controller.getApplicationAssets().getI18N();
    preferences = controller.getPreferences();

    skipListener = new ClickListener() {
        @Override// w  w  w  .ja v  a2  s . co  m
        public void clicked(InputEvent event, float x, float y) {
            Actor actor = event.getListenerActor();
            final Actor root = (Actor) actor.getUserObject();
            hide(root);
        }
    };
}

From source file:es.eucm.ead.editor.ui.scenes.ribbon.interaction.BehaviorsSelector.java

License:Open Source License

private void removeBehavior(Behavior behavior) {
    for (Actor actor : getChildren()) {
        if (actor.getUserObject() == behavior) {
            actor.remove();// ww  w .j ava 2  s .  c o  m
            break;
        }
    }
}

From source file:es.eucm.ead.editor.view.widgets.galleries.ScenesGallery.java

License:Open Source License

private void removeScene(String id) {
    Actor tile = findActor(id);
    ModelEntity scene = null;/*from   w  w w . j  av  a  2s  . c o m*/
    if (tile instanceof Tile) {
        scene = (ModelEntity) tile.getParent().getUserObject();
        tile.getParent().remove();
    } else if (tile instanceof Cell) {
        tile.remove();
        scene = (ModelEntity) tile.getUserObject();
    }
    controller.getModel().removeListenersFrom(Q.getComponent(scene, Documentation.class));
    sortScenes();
}

From source file:es.eucm.ead.editor.view.widgets.galleries.ScenesGallery.java

License:Open Source License

@Override
public int compare(Actor actor, Actor actor2) {
    String scene1 = Q.getDate((ModelEntity) actor.getUserObject());
    String scene2 = Q.getDate((ModelEntity) actor2.getUserObject());
    if (scene1 != null && scene2 != null) {
        return scene1.compareTo(scene2);
    } else {//from  w  w w.j  a va 2  s. com
        return scene1 != null ? 1 : scene2 != null ? -1 : 0;
    }
}

From source file:es.eucm.ead.engine.collision.BoundingAreaBuilder.java

License:Open Source License

/**
 * Creates a minimum rectangle that contains the given entity. The algorithm
 * takes into account renderers' colliders (if available), and children. The
 * algorithm is simple: search for min and max x and y coordinates to build
 * the rectangle./* www  . j  a  va  2 s.co  m*/
 * 
 * @param entity
 *            The entity to build a bounding rectangle for.
 * @return The bounding rectangle, in coordinates of the
 *         {@link Layer#SCENE_CONTENT} layer. May return {@code null} if
 *         this entity is not a descendant of {@link Layer#SCENE_CONTENT}.
 */
public static RectangleWrapper getBoundingRectangle(EngineEntity entity) {
    RectangleWrapper rectangleWrapper = Pools.obtain(RectangleWrapper.class);
    Rectangle rectangle = Pools.obtain(Rectangle.class);
    rectangleWrapper.set(rectangle);
    /*
     * Vectors x and y will hold min and max coordinates: x.x = minX, x.y =
     * maxX y.x = minY, y.y = maxY
     */
    Vector2 x = Pools.obtain(Vector2.class);
    Vector2 y = Pools.obtain(Vector2.class);
    x.set(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY);
    y.set(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY);
    Group sceneContentGroup = getSceneContentAncestor(entity).getGroup();
    if (sceneContentGroup == null) {
        return null;
    }

    processRenderer(entity, sceneContentGroup, entity.getGroup(), x, y);

    for (Actor actor : entity.getGroup().getChildren()) {
        if (actor.getUserObject() != null && actor.getUserObject() instanceof EngineEntity) {
            EngineEntity child = (EngineEntity) actor.getUserObject();
            RectangleWrapper childWrapper = getBoundingRectangle(child);
            Rectangle childRect = childWrapper.rectangle;
            Vector2 bottomLeft = Pools.obtain(Vector2.class);
            Vector2 topRight = Pools.obtain(Vector2.class);
            bottomLeft.set(childRect.getX(), childRect.getY());
            topRight.set(childRect.getX() + childRect.getWidth(), childRect.getY() + childRect.getHeight());
            entity.getGroup().localToAscendantCoordinates(sceneContentGroup, bottomLeft);
            entity.getGroup().localToAscendantCoordinates(sceneContentGroup, topRight);
            x.set(Math.min(bottomLeft.x, x.x), Math.max(topRight.x, x.y));
            y.set(Math.min(bottomLeft.y, y.x), Math.max(topRight.y, y.y));
            Pools.free(bottomLeft);
            Pools.free(topRight);
            Pools.free(childWrapper);
        }
    }

    rectangle.x = x.x;
    rectangle.y = y.x;
    rectangle.width = x.y - x.x;
    rectangle.height = y.y - y.x;
    Pools.free(x);
    Pools.free(y);
    return rectangleWrapper;
}

From source file:es.eucm.ead.engine.collision.BoundingAreaBuilder.java

License:Open Source License

/**
 * Creates a minimum convex polygon that contains the given entity. The
 * algorithm takes into account renderers' colliders (if available), and
 * children. The algorithm gets different polygons coming from renderers,
 * children, etc. and uses {@link ConvexHull} to determine the minimum
 * convex polygon that contains all of them.
 * // ww w .j  a  v a 2 s .c  o  m
 * @param entity
 *            The entity to build a bounding polygon for.
 * @return The bounding convex polygon, in coordinates of the
 *         {@link Layer#SCENE_CONTENT} layer. May return {@code null} if
 *         this entity is not a descendant of {@link Layer#SCENE_CONTENT}.
 */
static Polygon getBoundingPolygon(EngineEntity entity) {
    Array<Vector2> points = new Array<Vector2>();
    int count = 0;
    Group sceneContentGroup = getSceneContentAncestor(entity).getGroup();
    if (sceneContentGroup == null) {
        return null;
    }

    Polygon polygon = getBoundingPolygon(entity, sceneContentGroup, entity.getGroup());
    if (polygon != null) {
        toVector2Array(polygon.getVertices(), points);
        count++;
    }

    for (Actor actor : entity.getGroup().getChildren()) {
        if (actor.getUserObject() != null && actor.getUserObject() instanceof EngineEntity) {
            EngineEntity child = (EngineEntity) actor.getUserObject();
            Polygon childPolygon = getBoundingPolygon(child);
            toVector2Array(childPolygon.getVertices(), points);
            count++;
        }
    }

    polygon = new Polygon();
    if (count > 1) {
        FloatArray polygonPoints = convexHull.computePolygon(toSimpleArray(points), false);
        // Remove last point (duplicate)
        polygonPoints.removeRange(polygonPoints.size - 2, polygonPoints.size - 1);
        polygon.setVertices(polygonPoints.toArray());
    } else {
        polygon.setVertices(toSimpleArray(points));
    }
    for (Vector2 point : points) {
        Pools.free(point);
    }
    return polygon;
}

From source file:es.eucm.ead.engine.DefaultGameView.java

License:Open Source License

@Override
public void clearLayer(Layer layer, boolean clearChildrenLayers) {
    EngineEntity layerEntity = layers.get(layer);
    SnapshotArray<Actor> childrenArray = layerEntity.getGroup().getChildren();
    Actor[] children = childrenArray.begin();
    for (int i = 0, n = childrenArray.size; i < n; i++) {
        Actor actor = children[i];
        if (actor.getUserObject() instanceof EngineLayer) {
            if (clearChildrenLayers) {
                EngineLayer childrenLayer = (EngineLayer) actor.getUserObject();
                clearLayer(getLayerForEntity(childrenLayer), true);
            }//from   w  w  w.j  a v  a 2  s  . c  o  m
        } else if (actor.getUserObject() instanceof EngineEntity) {
            EngineEntity childEntityToRemove = (EngineEntity) actor.getUserObject();
            gameLoop.removeEntity(childEntityToRemove);
        } else {
            Gdx.app.error("GameView",
                    "GameView has a child that does not belong to an EngineEntity or its user object is not set.");
        }
    }
    childrenArray.end();

}

From source file:es.eucm.ead.engine.entities.EngineEntity.java

License:Open Source License

@Override
public void reset() {
    removeAll();//from ww  w  .  j  a  v  a2s. c  o  m
    flags = 0;
    if (group != null) {
        group.remove();
        Actor[] children = group.getChildren().begin();
        for (int i = 0, n = group.getChildren().size; i < n; i++) {
            Actor child = children[i];
            Object o = child.getUserObject();
            if (o instanceof EngineEntity) {
                gameLoop.removeEntity((EngineEntity) o);
            }
        }
        group = null;
    }
    modelEntity = null;
}

From source file:es.eucm.ead.engine.utils.EngineUtils.java

License:Open Source License

/**
 * @return the nearest entity associated to the given actor
 *//*from   w w  w .j  a v a  2s  .c o m*/
public static EngineEntity getActorEntity(Actor actor) {
    if (actor == null) {
        return null;
    }
    Object o = actor.getUserObject();
    return o instanceof EngineEntity ? (EngineEntity) o : getActorEntity(actor.getParent());
}

From source file:es.eucm.ead.mockup.core.control.screens.gallery.ElementGallery.java

License:Open Source License

@Override
public void create() {
    setPreviousScreen(Screens.PROJECT_MENU);
    navigationGroup = UIAssets.getNavigationGroup();

    super.root = new Group();
    root.setVisible(false);//from   w  w w.j av  a2 s .  co  m

    topToolbar = new ToolBar(skin);
    ToolBar bottomToolbar = new ToolBar(skin);
    topToolbar.right();

    String search = "Buscar por ...";// TODO use i18n!
    TextField searchtf = new TextField("", skin);
    searchtf.setMessageText(search);
    searchtf.setMaxLength(search.length());
    String[] orders = new String[] { "Ordenar por ...", "nombre A-Z", "nombre Z-A", "ms recientes",
            "menos recientes" };// TODO use
    // i18n!
    SelectBox order = new SelectBox(orders, skin);

    /* filter panel */
    Button applyFilter = new TextButton("Filtrar", skin);

    CheckBox[] tags = new CheckBox[] { new CheckBox("Almohada", skin), new CheckBox("Camilla", skin),
            new CheckBox("Doctor", skin), new CheckBox("Enfermera", skin), new CheckBox("Guantes", skin),
            new CheckBox("Habitacin", skin), new CheckBox("Hospital", skin), new CheckBox("Quirfano", skin),
            new CheckBox("Medicamentos", skin), new CheckBox("Mdico", skin), new CheckBox("Paciente", skin),
            new CheckBox("Vehculo", skin) };
    Table tagList = new Table(skin);
    tagList.left();
    tagList.defaults().left();
    for (int i = 0; i < tags.length; ++i) {
        tagList.add(tags[i]);
        if (i < tags.length - 1)
            tagList.row();
    }
    ScrollPane tagScroll = new ScrollPane(tagList, skin, "opaque");

    final Panel filterPanel = new Panel(skin);
    filterPanel.setVisible(false);
    final float panelw = stagew * .26f, panelx = stagew - panelw;
    filterPanel.add(tagScroll).fill().colspan(3).left();
    filterPanel.row();
    filterPanel.add(applyFilter).colspan(3).expandX();
    filterPanel.setBounds(panelx, topToolbar.getHeight(), panelw, stageh - topToolbar.getHeight() * 2f);

    Button filterButton = new TextButton("Filtrar por tags", skin);
    ClickListener closeFilterListenerTmp = new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (filterPanel.isVisible()) {
                mockupController.hide(filterPanel);
            } else {
                mockupController.show(filterPanel);
            }
        }
    };
    applyFilter.addListener(closeFilterListenerTmp);
    filterButton.addListener(closeFilterListenerTmp);

    Label nombre = new Label("Galera de elementos", skin);

    topToolbar.add(nombre).expandX().left().padLeft(UIAssets.NAVIGATION_BUTTON_WIDTH_HEIGHT * 1.1f);
    topToolbar.add(order);
    topToolbar.add(filterButton);
    topToolbar.add(searchtf).width(skin.getFont("default-font").getBounds(search).width + 50); // FIXME
    // hardcoded
    // fixed
    // value
    /***/

    final int COLS = 4, ROWS = 6;
    gridPanel = new GalleryGrid<Actor>(skin, ROWS, COLS, root, new ToolBar[] { topToolbar, bottomToolbar }) {
        @Override
        protected void entityClicked(InputEvent event) {
            Actor target = event.getTarget();
            if (target instanceof Image) {
                ElementEdition.setELEMENT_INDEX((Integer) target.getUserObject());
                exitAnimation(Screens.ELEMENT_EDITION);
            } else if (target instanceof Label) {
                ElementEdition.setELEMENT_INDEX(null);
                exitAnimation(Screens.ELEMENT_EDITION);
            }
        }
    };
    boolean first = true;
    for (int i = 0; i < ROWS; ++i) {
        for (int j = 0; j < COLS; ++j) {
            if (first) {
                first = false;
                gridPanel.addItem(new TextButton("Imagen en blanco", skin), 0, 0).fill();
            } else {
                int rand = MathUtils.random(Loading.demoElementsThumbnail.length - 1);
                GalleryEntity auxImg = new GalleryEntity(Loading.demoElementsThumbnail[rand]);
                auxImg.setUserObject(Integer.valueOf(rand));
                gridPanel.addItem(auxImg, i, j);// .size(auxWidth,
                // auxHeight);
            }
        }
    }

    ScrollPane scrollPane = new ScrollPane(gridPanel);
    scrollPane.setScrollingDisabled(true, false);
    scrollPane.setBounds(0, topToolbar.getHeight(), stagew, stageh - 2 * topToolbar.getHeight());
    final float DEFAULT_ICON_LABEL_SPACE = 10f;
    final Button picButton = new Button(skin);
    picButton.defaults().space(DEFAULT_ICON_LABEL_SPACE);
    Label picLabel = new Label("Nuevo desde cmara", skin);
    Image picImage = new Image(skin.getDrawable("ic_photocamera"));
    picButton.add(picImage);
    picButton.add(picLabel);

    ClickListener mTransitionLIstener = new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            final Screens next = getNextScreen(event.getListenerActor());
            if (next == null) {
                return;
            }
            exitAnimation(next);
        }

        private Screens getNextScreen(Actor target) {
            Screens next = null;
            if (target == picButton) {
                next = Screens.PICTURE;
            }
            return next;
        }
    };
    picButton.addListener(mTransitionLIstener);

    bottomToolbar.setY(0);
    bottomToolbar.add(picButton).expandX().left();

    root.addActor(topToolbar);
    root.addActor(bottomToolbar);
    root.addActor(scrollPane);
    root.addActor(filterPanel);

    stage.addActor(root);
}