Java Code Examples for com.badlogic.gdx.utils.SnapshotArray

The following examples show how to use com.badlogic.gdx.utils.SnapshotArray. 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: cocos-ui-libgdx   Source File: PageView.java    License: Apache License 2.0 6 votes vote down vote up
public void nextView() {
    Gdx.app.debug("PageView", "Change to next view");
    SnapshotArray<Actor> children = this.getChildren();
    if (children.get(children.size - 1).getX() <= 0) {
        Gdx.app.debug("PageView", "Already last one, can't move to next.");
        return;
    }
    Actor[] actors = children.begin();
    float width = this.getWidth();
    for (Actor actor : actors) {
        if (actor != null) {
            actor.addAction(Actions.moveTo(actor.getX() - width, 0, 0.5f));
        }
    }
    children.end();
}
 
Example 2
Source Project: cocos-ui-libgdx   Source File: PageView.java    License: Apache License 2.0 6 votes vote down vote up
public void previousView() {
    Gdx.app.debug("PageView", "Change to previous view");
    SnapshotArray<Actor> children = this.getChildren();
    if (children.get(0).getX() >= 0) {
        Gdx.app.debug("PageView", "Already first one, can't move to previous.");
        return;
    }
    float width = this.getWidth();
    Actor[] actors = children.begin();
    for (Actor actor : actors) {
        if (actor != null) {
            actor.addAction(Actions.moveTo(actor.getX() + width, 0, 0.5f));
        }
    }
    children.end();
}
 
Example 3
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 4
Source Project: Klooni1010   Source File: CustomizeScreen.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void render(float delta) {
    Klooni.theme.glClearBackground();
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    stage.act(Math.min(Gdx.graphics.getDeltaTime(), MIN_DELTA));
    stage.draw();

    // After everything is drawn, showcase the current shop item
    SnapshotArray<Actor> children = shopGroup.getChildren();
    if (children.size > 0) {
        final ShopCard card = (ShopCard) children.get(showcaseIndex);

        final Batch batch = stage.getBatch();
        batch.begin();
        // For some really strange reason, we need to displace the particle effect
        // by "buyBand.height", or it will render exactly that height below where
        // it should.
        // TODO Fix this - maybe use the same project matrix as stage.draw()?
        // batch.setProjectionMatrix(stage.getViewport().getCamera().combined)
        if (!card.showcase(batch, buyBand.getHeight())) {
            showcaseIndex = (showcaseIndex + 1) % children.size;
        }
        batch.end();
    }

    if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {
        goBack();
    }
}
 
Example 5
Source Project: dice-heroes   Source File: EventDispatcher.java    License: GNU General Public License v3.0 5 votes vote down vote up
public <T> void dispatch(EventType<T> type, T t) {
    SnapshotArray<EventListener<T>> list = getList(type, false);
    if (list == null)
        return;
    EventListener<T>[] items = list.begin();
    for (int i = 0, n = list.size; i < n; i++) {
        items[i].handle(type, t);
    }
    list.end();
}
 
Example 6
Source Project: dice-heroes   Source File: EventDispatcher.java    License: GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> SnapshotArray<EventListener<T>> getList(EventType<T> type, boolean createIfNotExist) {
    Object list = data.get(type);
    if (list == null) {
        if (!createIfNotExist)
            return null;
        SnapshotArray<EventListener<T>> result = new SnapshotArray<EventListener<T>>(EventListener.class);
        data.put(type, result);
        return result;
    }
    return (SnapshotArray<EventListener<T>>) list;
}
 
Example 7
Source Project: riiablo   Source File: BeltGrid.java    License: Apache License 2.0 5 votes vote down vote up
private void updateItems(boolean hidden) {
  Touchable touchable = hidden ? Touchable.disabled : Touchable.enabled;
  SnapshotArray<Actor> snapshot = getChildren();
  Actor[] children = snapshot.begin();
  for (Actor child : children) {
    StoredItem item = (StoredItem) child;
    if (item == null) continue;
    if (item.getY() >= boxHeight) item.setTouchable(touchable);
  }
  snapshot.end();
}
 
Example 8
Source Project: libgdx-inGameConsole   Source File: GUIConsole.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Compares the given processor to the console's stage. If given a multiplexer, it is iterated through recursively to check all
 * of the multiplexer's processors for comparison.
 *
 * @param processor
 * @return processor == this.stage
 */
private boolean hasStage (InputProcessor processor) {
	if (!(processor instanceof InputMultiplexer)) {
		return processor == stage;
	}
	InputMultiplexer im = (InputMultiplexer)processor;
	SnapshotArray<InputProcessor> ips = im.getProcessors();
	for (InputProcessor ip : ips) {
		if (hasStage(ip)) {
			return true;
		}
	}
	return false;
}
 
Example 9
Source Project: Mundus   Source File: MundusMultiSplitPane.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void layout() {
    if (!vertical)
        calculateHorizBoundsAndPositions();
    else
        calculateVertBoundsAndPositions();

    SnapshotArray<Actor> actors = getChildren();
    for (int i = 0; i < actors.size; i++) {
        Actor actor = actors.get(i);
        Rectangle bounds = widgetBounds.get(i);
        actor.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
        if (actor instanceof Layout) ((Layout) actor).validate();
    }
}
 
Example 10
Source Project: Mundus   Source File: MundusMultiSplitPane.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    validate();

    Color color = getColor();

    applyTransform(batch, computeTransform());

    SnapshotArray<Actor> actors = getChildren();
    for (int i = 0; i < actors.size; i++) {
        Actor actor = actors.get(i);
        Rectangle bounds = widgetBounds.get(i);
        Rectangle scissor = scissors.get(i);
        getStage().calculateScissors(bounds, scissor);
        if (ScissorStack.pushScissors(scissor)) {
            if (actor.isVisible()) actor.draw(batch, parentAlpha * color.a);
            batch.flush();
            ScissorStack.popScissors();
        }
    }

    batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);

    Drawable handle = style.handle;
    Drawable handleOver = style.handle;
    if (isTouchable() && style.handleOver != null) handleOver = style.handleOver;
    for (Rectangle rect : handleBounds) {
        if (this.handleOver == rect) {
            handleOver.draw(batch, rect.x, rect.y, rect.width, rect.height);
        } else {
            handle.draw(batch, rect.x, rect.y, rect.width, rect.height);
        }
    }
    resetTransform(batch);
}
 
Example 11
Source Project: vis-ui   Source File: PopupMenu.java    License: Apache License 2.0 5 votes vote down vote up
private void selectNextItem () {
	SnapshotArray<Actor> children = getChildren();
	if (!hasSelectableMenuItems()) return;
	int startIndex = activeItem == null ? 0 : children.indexOf(activeItem, true) + 1;
	for (int i = startIndex; ; i++) {
		if (i >= children.size) i = 0;
		Actor actor = children.get(i);
		if (actor instanceof MenuItem && ((MenuItem) actor).isDisabled() == false) {
			setActiveItem((MenuItem) actor, true);
			break;
		}
	}
}
 
Example 12
Source Project: vis-ui   Source File: PopupMenu.java    License: Apache License 2.0 5 votes vote down vote up
private void selectPreviousItem () {
	SnapshotArray<Actor> children = getChildren();
	if (!hasSelectableMenuItems()) return;
	int startIndex = activeItem == null ? children.size - 1 : children.indexOf(activeItem, true) - 1;
	for (int i = startIndex; ; i--) {
		if (i <= -1) i = children.size - 1;
		Actor actor = children.get(i);
		if (actor instanceof MenuItem && ((MenuItem) actor).isDisabled() == false) {
			setActiveItem((MenuItem) actor, true);
			break;
		}
	}
}
 
Example 13
Source Project: vis-ui   Source File: PopupMenu.java    License: Apache License 2.0 5 votes vote down vote up
private boolean hasSelectableMenuItems () {
	SnapshotArray<Actor> children = getChildren();
	for (Actor actor : children) {
		if (actor instanceof MenuItem && ((MenuItem) actor).isDisabled() == false) return true;
	}
	return false;
}
 
Example 14
Source Project: vis-ui   Source File: MultiSplitPane.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void layout () {
	if (!vertical)
		calculateHorizBoundsAndPositions();
	else
		calculateVertBoundsAndPositions();

	SnapshotArray<Actor> actors = getChildren();
	for (int i = 0; i < actors.size; i++) {
		Actor actor = actors.get(i);
		Rectangle bounds = widgetBounds.get(i);
		actor.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
		if (actor instanceof Layout) ((Layout) actor).validate();
	}
}
 
Example 15
Source Project: vis-ui   Source File: MultiSplitPane.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	validate();

	Color color = getColor();

	applyTransform(batch, computeTransform());

	SnapshotArray<Actor> actors = getChildren();
	for (int i = 0; i < actors.size; i++) {
		Actor actor = actors.get(i);
		Rectangle bounds = widgetBounds.get(i);
		Rectangle scissor = scissors.get(i);
		getStage().calculateScissors(bounds, scissor);
		if (ScissorStack.pushScissors(scissor)) {
			if (actor.isVisible()) actor.draw(batch, parentAlpha * color.a);
			batch.flush();
			ScissorStack.popScissors();
		}
	}

	batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);

	Drawable handle = style.handle;
	Drawable handleOver = style.handle;
	if (isTouchable() && style.handleOver != null) handleOver = style.handleOver;
	for (Rectangle rect : handleBounds) {
		if (this.handleOver == rect) {
			handleOver.draw(batch, rect.x, rect.y, rect.width, rect.height);
		} else {
			handle.draw(batch, rect.x, rect.y, rect.width, rect.height);
		}
	}
	resetTransform(batch);
}
 
Example 16
Source Project: vis-ui   Source File: IconStack.java    License: Apache License 2.0 5 votes vote down vote up
private void computeSize () {
	sizeInvalid = false;
	prefWidth = 0;
	prefHeight = 0;
	minWidth = 0;
	minHeight = 0;
	maxWidth = 0;
	maxHeight = 0;
	SnapshotArray<Actor> children = getChildren();
	for (int i = 0, n = children.size; i < n; i++) {
		Actor child = children.get(i);
		float childMaxWidth, childMaxHeight;
		if (child instanceof Layout) {
			Layout layout = (Layout) child;
			prefWidth = Math.max(prefWidth, layout.getPrefWidth());
			prefHeight = Math.max(prefHeight, layout.getPrefHeight());
			minWidth = Math.max(minWidth, layout.getMinWidth());
			minHeight = Math.max(minHeight, layout.getMinHeight());
			childMaxWidth = layout.getMaxWidth();
			childMaxHeight = layout.getMaxHeight();
		} else {
			prefWidth = Math.max(prefWidth, child.getWidth());
			prefHeight = Math.max(prefHeight, child.getHeight());
			minWidth = Math.max(minWidth, child.getWidth());
			minHeight = Math.max(minHeight, child.getHeight());
			childMaxWidth = 0;
			childMaxHeight = 0;
		}
		if (childMaxWidth > 0) maxWidth = maxWidth == 0 ? childMaxWidth : Math.min(maxWidth, childMaxWidth);
		if (childMaxHeight > 0) maxHeight = maxHeight == 0 ? childMaxHeight : Math.min(maxHeight, childMaxHeight);
	}
}
 
Example 17
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 18
Source Project: vis-ui   Source File: HorizontalFlowGroup.java    License: Apache License 2.0 5 votes vote down vote up
private void computeSize () {
	prefWidth = getWidth();
	prefHeight = 0;
	sizeInvalid = false;

	SnapshotArray<Actor> children = getChildren();

	float x = 0;
	float rowHeight = 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 (x + width > getWidth()) {
			x = 0;
			prefHeight += rowHeight + spacing;
			rowHeight = height;
		} else {
			rowHeight = Math.max(height, rowHeight);
		}

		x += width + spacing;
	}

	//handle last row height
	prefHeight += rowHeight + spacing;
}
 
Example 19
Source Project: vis-ui   Source File: GridGroup.java    License: Apache License 2.0 5 votes vote down vote up
private void computeSize () {
	prefWidth = getWidth();
	prefHeight = 0;
	sizeInvalid = false;

	SnapshotArray<Actor> children = getChildren();

	if (children.size == 0) {
		prefWidth = 0;
		prefHeight = 0;
		return;
	}

	float width = getWidth();

	float maxHeight = 0;
	float tempX = spacing;

	for (int i = 0; i < children.size; i++) {
		if (tempX + itemWidth + spacing > width) {
			tempX = spacing;
			maxHeight += itemHeight + spacing;
		}

		tempX += itemWidth + spacing;
	}

	if (itemWidth + spacing * 2 > prefWidth)
		maxHeight += spacing;
	else
		maxHeight += itemHeight + spacing * 2;

	prefHeight = maxHeight;
}
 
Example 20
Source Project: vis-ui   Source File: GridGroup.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void layout () {
	if (sizeInvalid) {
		computeSize();
		if (lastPrefHeight != prefHeight) {
			lastPrefHeight = prefHeight;
			invalidateHierarchy();
		}
	}

	SnapshotArray<Actor> children = getChildren();

	float width = getWidth();
	boolean notEnoughSpace = itemWidth + spacing * 2 > width;

	float x = spacing;
	float y = notEnoughSpace ? (getHeight()) : (getHeight() - itemHeight - spacing);

	for (int i = 0; i < children.size; i++) {
		Actor child = children.get(i);

		if (x + itemWidth + spacing > width) {
			x = spacing;
			y -= itemHeight + spacing;
		}

		child.setBounds(x, y, itemWidth, itemHeight);
		x += itemWidth + spacing;
	}
}
 
Example 21
Source Project: Scene3d   Source File: Stage3d.java    License: Apache License 2.0 5 votes vote down vote up
public Actor3d getObject(int screenX, int screenY) {
	 Actor3d temp = null;
	 SnapshotArray<Actor3d> children = root.getChildren();
	 Actor3d[] actors = children.begin();
     for(int i = 0, n = children.size; i < n; i++){
    	 temp = hit3d(screenX, screenY, actors[i]);
    	 if(actors[i] instanceof Group3d)
    		 temp = hit3d(screenX, screenY, (Group3d)actors[i]);
     }
     children.end();
     return temp;
}
 
Example 22
Source Project: Scene3d   Source File: Stage3d.java    License: Apache License 2.0 5 votes vote down vote up
public Actor3d hit3d(int screenX, int screenY, Group3d group3d) {
	 Actor3d temp = null;
	 SnapshotArray<Actor3d> children = group3d.getChildren();
	 Actor3d[] actors = children.begin();
     for(int i = 0, n = children.size; i < n; i++){
    	 temp = hit3d(screenX, screenY, actors[i]);
    	 if(actors[i] instanceof Group3d)
    		 temp = hit3d(screenX, screenY, (Group3d)actors[i]);
     }
     children.end();
     return temp;
}
 
Example 23
Source Project: thunderboard-android   Source File: GdxDemoActivity.java    License: Apache License 2.0 4 votes vote down vote up
public SnapshotArray<LifecycleListener> getLifecycleListeners() {
    return this.lifecycleListeners;
}
 
Example 24
Source Project: dice-heroes   Source File: EventDispatcher.java    License: GNU General Public License v3.0 4 votes vote down vote up
public <T> void add(EventType<T> type, EventListener<T> listener) {
    SnapshotArray<EventListener<T>> list = getList(type, true);
    list.add(listener);
}
 
Example 25
Source Project: dice-heroes   Source File: EventDispatcher.java    License: GNU General Public License v3.0 4 votes vote down vote up
public <T> void remove(EventType<T> type, EventListener<T> listener) {
    SnapshotArray<EventListener<T>> list = getList(type, false);
    if (list == null)
        return;
    list.removeValue(listener, true);
}
 
Example 26
Source Project: vis-ui   Source File: PopupMenu.java    License: Apache License 2.0 4 votes vote down vote up
private void createListeners () {
	stageListener = new InputListener() {
		@Override
		public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
			if (getRootMenu().subMenuStructureContains(x, y) == false) {
				remove();
			}
			return true;
		}

		@Override
		public boolean keyDown (InputEvent event, int keycode) {
			SnapshotArray<Actor> children = getChildren();
			if (children.size == 0 || activeSubMenu != null) return false;
			if (keycode == Input.Keys.DOWN) {
				selectNextItem();
				return true;
			}
			if (keycode == Input.Keys.UP) {
				selectPreviousItem();
				return true;
			}
			if (activeItem == null) return false;
			if (keycode == Input.Keys.LEFT && activeItem.containerMenu.parentSubMenu != null) {
				activeItem.containerMenu.parentSubMenu.setActiveSubMenu(null);
				return true;
			}
			if (keycode == Input.Keys.RIGHT && activeItem.getSubMenu() != null) {
				activeItem.showSubMenu();
				activeSubMenu.selectNextItem();
				return true;
			}
			if (keycode == Input.Keys.ENTER) {
				activeItem.fireChangeEvent();
				return true;
			}
			return false;
		}
	};

	sharedMenuItemInputListener = new InputListener() {
		@Override
		public void enter (InputEvent event, float x, float y, int pointer, Actor fromActor) {
			if (pointer == -1 && event.getListenerActor() instanceof MenuItem) {
				MenuItem item = (MenuItem) event.getListenerActor();
				if (item.isDisabled() == false) {
					setActiveItem(item, false);
				}
			}
		}

		@Override
		public void exit (InputEvent event, float x, float y, int pointer, Actor toActor) {
			if (pointer == -1 && event.getListenerActor() instanceof MenuItem) {
				if (activeSubMenu != null) return;

				MenuItem item = (MenuItem) event.getListenerActor();
				if (item == activeItem) {
					setActiveItem(null, false);
				}
			}
		}
	};

	sharedMenuItemChangeListener = new ChangeListener() {
		@Override
		public void changed (ChangeEvent event, Actor actor) {
			if (event.isStopped() == false) removeHierarchy();
		}
	};
}
 
Example 27
Source Project: vis-ui   Source File: DragPane.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SnapshotArray<Actor> getChildren () {
	return getActor().getChildren();
}
 
Example 28
Source Project: Scene3d   Source File: Group3d.java    License: Apache License 2.0 4 votes vote down vote up
public void drawChildren(ModelBatch modelBatch, Environment environment){
     //modelBatch.render(children, environment); maybe faster 
     SnapshotArray<Actor3d> children = this.children;
	 Actor3d[] actors = children.begin();
	 visibleCount = 0;
	 for (int i = 0, n = children.size; i < n; i++){
		 if(actors[i] instanceof Group3d){
    		 ((Group3d) actors[i]).drawChildren(modelBatch, environment);
    	 }
		 else{
				float offsetX = x, offsetY = y, offsetZ = z;
				float offsetScaleX = scaleX, offsetScaleY = scaleY, offsetScaleZ = scaleZ;
				float offsetYaw = yaw, offsetPitch = pitch, offsetRoll = roll;
				x = 0;
				y = 0;
				z = 0;
				scaleX = 0;
				scaleY = 0;
				scaleZ = 0;
				yaw = 0;
				pitch = 0;
				roll = 0;
				Actor3d child = actors[i];
				if (!child.isVisible()) continue;
				/*Matrix4 diff = sub(child.getTransform(), getTransform());
				Matrix4 childMatrix = child.getTransform().cpy();
				child.getTransform().set(add(diff, childMatrix));
				child.draw(modelBatch, environment);*/
				float cx = child.x, cy = child.y, cz = child.z;
				float sx = child.scaleX, sy = child.scaleY, sz = child.scaleZ;
				float ry = child.yaw, rp = child.pitch, rr = child.roll;
				//child.x = cx + offsetX;
				//child.y = cy + offsetY;
				//child.z = cz + offsetZ;
				child.setPosition(cx + offsetX, cy + offsetY, cz + offsetZ);
				child.setScale(sx + offsetScaleX, sy + offsetScaleY, sz + offsetScaleZ);
				child.setRotation(ry + offsetYaw, rp + offsetPitch, rr +offsetRoll);
		        if (child.isCullable(getStage3d().getCamera())) {
		        	child.draw(modelBatch, environment);
		            visibleCount++;
		        }
				child.x = cx;
				child.y = cy;
				child.z = cz;
				x = offsetX;
				y = offsetY;
				z = offsetZ;
				child.scaleX = sx;
				child.scaleY = sy;
				child.scaleZ = sz;
				scaleX = offsetScaleX;
				scaleY = offsetScaleY;
				scaleZ = offsetScaleZ;
				child.yaw = ry;
				child.pitch = rp;
				child.roll = rr;
				yaw = offsetYaw;
				pitch = offsetPitch;
				roll = offsetRoll;
		 }
	 }
	 children.end();
}
 
Example 29
Source Project: Scene3d   Source File: Group3d.java    License: Apache License 2.0 4 votes vote down vote up
/** Returns an ordered list of child actors in this group. */
public SnapshotArray<Actor3d> getChildren () {
	return children;
}
 
Example 30
Source Project: ashley   Source File: Signal.java    License: Apache License 2.0 4 votes vote down vote up
public Signal () {
	listeners = new SnapshotArray<Listener<T>>();
}