Java Code Examples for com.badlogic.gdx.utils.Array#set()

The following examples show how to use com.badlogic.gdx.utils.Array#set() . 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: OptionList.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
private void up() {
	int pos = list.getSelectedIndex();

	if (pos == -1 || pos == 0)
		return;

	Array<DialogOption> items = list.getItems();
	DialogOption e = items.get(pos);
	DialogOption e2 = items.get(pos - 1);

	items.set(pos - 1, e);
	items.set(pos, e2);

	parent.getOptions().set(pos - 1, e);
	parent.getOptions().set(pos, e2);

	list.setSelectedIndex(pos - 1);
	upBtn.setDisabled(list.getSelectedIndex() == 0);
	downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1);

	Ctx.project.setModified();
}
 
Example 2
Source File: OptionList.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
private void down() {
	int pos = list.getSelectedIndex();
	Array<DialogOption> items = list.getItems();

	if (pos == -1 || pos == items.size - 1)
		return;

	DialogOption e = items.get(pos);
	DialogOption e2 = items.get(pos + 1);

	parent.getOptions().set(pos + 1, e);
	parent.getOptions().set(pos, e2);

	items.set(pos + 1, e);
	items.set(pos, e2);
	list.setSelectedIndex(pos + 1);
	upBtn.setDisabled(list.getSelectedIndex() == 0);
	downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1);

	Ctx.project.setModified();
}
 
Example 3
Source File: CommonUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Splits a string, and trims each segment.
 */
public static Array<String> splitAndTrim(String str, String regex) {
    Array<String> lines = new Array<>(str.split(regex));
    // Trim each line
    for (int i = 0; i < lines.size; i++) {
        lines.set(i, lines.get(i).trim());
    }
    // Remove empty lines
    for (Iterator<String> iter = lines.iterator(); iter.hasNext();) {
        if (iter.next().isEmpty()) {
            iter.remove();
        }
    }
    return lines;
}
 
Example 4
Source File: ActionList.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
private void up() {
	if (parent == null || list.getSelection().size() == 0)
		return;

	Array<Action> sel = new Array<Action>();

	for (Action a : getSortedSelection()) {
		
		int pos = list.getItems().indexOf(a, true);

		if (pos == -1 || pos == 0)
			return;

		Array<Action> items = list.getItems();
		Action e = items.get(pos);
		Action e2 = items.get(pos - 1);

		sel.add(e);

		if (isControlAction(e) && isControlAction(e2)) {
			continue;
		}

		parent.getActions().set(pos - 1, e);
		parent.getActions().set(pos, e2);

		items.set(pos - 1, e);
		items.set(pos, e2);
	}

	list.getSelection().clear();
	list.getSelection().addAll(sel);
	upBtn.setDisabled(list.getSelectedIndex() == 0);
	downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1);

	Ctx.project.setModified();
}
 
Example 5
Source File: BulletJumpTest.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
/** Creates a random path which is bound by rectangle described by the min/max values */
private static Array<Vector3> createRandomPath (int numWaypoints, float minX, float minY, float maxX, float maxY, float height) {
	Array<Vector3> wayPoints = new Array<Vector3>(numWaypoints);
	wayPoints.size = numWaypoints;

	float midX = (maxX + minX) / 2f;
	float midY = (maxY + minY) / 2f;

	float smaller = Math.min(midX, midY);

	float spacing = MathUtils.PI2 / (numWaypoints - 0);

	for (int i = 0; i < numWaypoints - 2; i++) {
		float radialDist = MathUtils.random(smaller * 0.2f, smaller);
		tmpVector2.set(radialDist, 0.0f);

		// rotates the specified vector angle rads around the origin
		// init and rotate the transformation matrix
		tmpMatrix3.idt().rotateRad(i * spacing);
		// now transform the object's vertices
		tmpVector2.mul(tmpMatrix3);

		wayPoints.set(i + 1, new Vector3(tmpVector2.x, height, tmpVector2.y));
		System.out.println((i + 1) + ": " + wayPoints.get(i + 1));
	}

	Vector3 midpoint = new Vector3(wayPoints.get(1)).add(wayPoints.get(numWaypoints - 2)).scl(0.5f);
	System.out.println("midpoint = " + midpoint);
	// Set the landing point
	wayPoints.set(0, new Vector3(wayPoints.get(1)).add(midpoint).scl(1f / 3f));
	wayPoints.get(0).y = height;
	// Set the takeoff point
	wayPoints.set(numWaypoints - 1, new Vector3(midpoint).add(wayPoints.get(numWaypoints - 2)).scl(1f / 3f));
	wayPoints.get(numWaypoints - 1).y = height;
	System.out.println("0: " + wayPoints.first());
	System.out.println((numWaypoints - 1) + ": " + wayPoints.peek());

	return wayPoints;
}
 
Example 6
Source File: ActionList.java    From bladecoder-adventure-engine with Apache License 2.0 3 votes vote down vote up
private void down() {
	if (parent == null || list.getSelection().size() == 0)
		return;

	Array<Action> sel = new Array<Action>();

	Array<Action> sortedSelection = getSortedSelection();

	for (int i = sortedSelection.size - 1; i >= 0; i--) {

		int pos = list.getItems().indexOf(sortedSelection.get(i), true);

		Array<Action> items = list.getItems();

		if (pos == -1 || pos == items.size - 1)
			return;

		Action e = items.get(pos);
		Action e2 = items.get(pos + 1);

		sel.add(e);

		if (isControlAction(e) && isControlAction(e2)) {
			continue;
		}

		parent.getActions().set(pos + 1, e);
		parent.getActions().set(pos, e2);

		items.set(pos + 1, e);
		items.set(pos, e2);
	}

	list.getSelection().clear();
	list.getSelection().addAll(sel);
	upBtn.setDisabled(list.getSelectedIndex() == 0);
	downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1);

	Ctx.project.setModified();
}