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

The following examples show how to use com.badlogic.gdx.utils.Array#insert() . 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: GLTFDemoUI.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
public void setEntry(ModelEntry entry, FileHandle rootFolder) 
{
	variantSelector.setSelected(null);
	Array<String> variants = entry.variants.keys().toArray(new Array<String>());
	variants.insert(0, "");
	variantSelector.setItems(variants);
	
	if(entry.variants.size == 1){
		variantSelector.setSelectedIndex(1);
	}else{
		variantSelector.setSelectedIndex(0);
	}
	
	
	if(screenshotsTable.getChildren().size > 0){
		Image imgScreenshot = (Image)screenshotsTable.getChildren().first();
		((TextureRegionDrawable)imgScreenshot.getDrawable()).getRegion().getTexture().dispose();
	}
	screenshotsTable.clear();
}
 
Example 2
Source File: LayerList.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<SceneLayer> items = list.getItems();
	SceneLayer e = items.get(pos);
	SceneLayer e2 = items.get(pos - 1);

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

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

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

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

	SceneLayer e = items.get(pos);
	SceneLayer e2 = pos + 1 < items.size ? items.get(pos + 1) : null;

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

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

	Ctx.project.setModified();
}
 
Example 4
Source File: CCTouchDispatcher.java    From cocos2d-java with MIT License 6 votes vote down vote up
protected void forceAddHandler(CCTouchHandler pHandler, Array<CCTouchHandler> pArray)
{
    int u = 0;
    for (int i = 0; i < pArray.size; i++)
    {
        CCTouchHandler h = pArray.get(i);

        if (h != null)
        {
            if (h.getPriority() < pHandler.getPriority())
            {
                ++u;
            }

            if (h.getDelegate() == pHandler.getDelegate())
            {
                return;
            }
        }
    }

    pArray.insert(u, pHandler);
}
 
Example 5
Source File: FileChooser.java    From gdx-soundboard with MIT License 6 votes vote down vote up
private void changeDirectory(FileHandle directory) {

        currentDir = directory;
        fileListLabel.setText(currentDir.path());

        final Array<FileListItem> items = new Array<FileListItem>();

        final FileHandle[] list = directory.list(filter);
        for (final FileHandle handle : list) {
            items.add(new FileListItem(handle));
        }

        items.sort(dirListComparator);

        if (directory.file().getParentFile() != null) {
            items.insert(0, new FileListItem("..", directory.parent()));
        }

        fileList.setSelected(null);
        fileList.setItems(items);
    }
 
Example 6
Source File: GLTFDemoUI.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public void setNodes(Array<Node> nodes) {
	nodeMap.clear();
	
	Array<String> names = new Array<String>();
	for(Node e : nodes){
		names.add(e.id);
		nodeMap.put(e.id, e);
	}
	names.sort();
	names.insert(0, "");
	nodeSelector.setItems();
	nodeSelector.setItems(names);
}
 
Example 7
Source File: ModelUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void movePackTop(PackModel pack) {
    ensurePackExists(pack);

    Array<PackModel> packs = getProject().getPacks();
    // Check if pack is already at the top
    if (packs.indexOf(pack, true) == 0) return;

    packs.removeValue(pack, true);
    packs.insert(0, pack);
    eventDispatcher.postEvent(new PackListOrderChangedEvent());
}
 
Example 8
Source File: ModelUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void movePackBottom(PackModel pack) {
    ensurePackExists(pack);

    Array<PackModel> packs = getProject().getPacks();
    int idx = packs.indexOf(pack, true);
    // Check if pack is already at the bottom
    if (idx == packs.size-1) return;

    packs.removeValue(pack, true);
    packs.insert(packs.size-1, pack);
    eventDispatcher.postEvent(new PackListOrderChangedEvent());
}
 
Example 9
Source File: ModelUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void movePackNextTo(PackModel anchor, PackModel pack) {
       ensurePackExists(anchor);
       ensurePackExists(pack);

       Array<PackModel> packs = getProject().getPacks();
       int idxAnchor = packs.indexOf(anchor, true);
       int idxPack = packs.indexOf(pack, true);
       // Check if pack is already next to anchor
       if (idxAnchor-idxPack == -1) return;

       packs.removeValue(pack, true);
       packs.insert(idxAnchor+1, pack);
	eventDispatcher.postEvent(new PackListOrderChangedEvent());
}
 
Example 10
Source File: ModelUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void movePackPrevTo(PackModel anchor, PackModel pack) {
       ensurePackExists(anchor);
       ensurePackExists(pack);

       Array<PackModel> packs = getProject().getPacks();
       int idxAnchor = packs.indexOf(anchor, true);
       int idxPack = packs.indexOf(pack, true);
       // Check if pack is already previous to anchor
       if (idxAnchor-idxPack == 1) return;

       packs.removeValue(pack, true);
       packs.insert(idxAnchor, pack);
	eventDispatcher.postEvent(new PackListOrderChangedEvent());
}
 
Example 11
Source File: Box2DMapObjectParser.java    From Entitas-Java with MIT License 5 votes vote down vote up
/**
 * creates {@link Fixture Fixtures} from a {@link MapObject}
 *
 * @param mapObject the {@link MapObject} to parse
 * @return an array of parsed {@link Fixture Fixtures}
 */
public Fixture[] createFixtures(MapObject mapObject) {
    Polygon polygon;

    if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()))
        return new Fixture[]{createFixture(mapObject)};

    Polygon[] convexPolygons;
    if (triangulate) {
        if (areVerticesClockwise(polygon)) { // ensure the vertices are in counterclockwise order (not really necessary according to EarClippingTriangulator's javadoc, but sometimes better)
            Array<Vector2> vertices = new Array<Vector2>(toVector2Array(polygon.getVertices()));
            Vector2 first = vertices.removeIndex(0);
            vertices.reverse();
            vertices.insert(0, first);
            polygon.setVertices(toFloatArray(vertices.items));
        }
        convexPolygons = toPolygonArray(toVector2Array(new EarClippingTriangulator().computeTriangles(polygon.getTransformedVertices()).toArray()), 3);
    } else {
        Array<Array<Vector2>> convexPolys = BayazitDecomposer.convexPartition(new Array<Vector2>(toVector2Array(polygon.getTransformedVertices())));
        convexPolygons = new Polygon[convexPolys.size];
        for (int i = 0; i < convexPolygons.length; i++)
            convexPolygons[i] = new Polygon(toFloatArray((Vector2[]) convexPolys.get(i).toArray(Vector2.class)));
    }

    // create the fixtures using the convex polygons
    Fixture[] fixtures = new Fixture[convexPolygons.length];
    for (int i = 0; i < fixtures.length; i++) {
        PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
        convexObject.setColor(mapObject.getColor());
        convexObject.setName(mapObject.getName());
        convexObject.setOpacity(mapObject.getOpacity());
        convexObject.setVisible(mapObject.isVisible());
        convexObject.getProperties().putAll(mapObject.getProperties());
        fixtures[i] = createFixture(convexObject);
    }

    return fixtures;
}
 
Example 12
Source File: Box2DMapObjectParser.java    From Entitas-Java with MIT License 5 votes vote down vote up
/**
 * creates {@link Fixture Fixtures} from a {@link MapObject}
 *
 * @param mapObject the {@link MapObject} to parse
 * @return an array of parsed {@link Fixture Fixtures}
 */
public Fixture[] createFixtures(MapObject mapObject) {
    Polygon polygon;

    if (!(mapObject instanceof PolygonMapObject) || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()))
        return new Fixture[]{createFixture(mapObject)};

    Polygon[] convexPolygons;
    if (triangulate) {
        if (areVerticesClockwise(polygon)) { // ensure the vertices are in counterclockwise order (not really necessary according to EarClippingTriangulator's javadoc, but sometimes better)
            Array<Vector2> vertices = new Array<Vector2>(toVector2Array(polygon.getVertices()));
            Vector2 first = vertices.removeIndex(0);
            vertices.reverse();
            vertices.insert(0, first);
            polygon.setVertices(toFloatArray(vertices.items));
        }
        convexPolygons = toPolygonArray(toVector2Array(new EarClippingTriangulator().computeTriangles(polygon.getTransformedVertices()).toArray()), 3);
    } else {
        Array<Array<Vector2>> convexPolys = BayazitDecomposer.convexPartition(new Array<Vector2>(toVector2Array(polygon.getTransformedVertices())));
        convexPolygons = new Polygon[convexPolys.size];
        for (int i = 0; i < convexPolygons.length; i++)
            convexPolygons[i] = new Polygon(toFloatArray((Vector2[]) convexPolys.get(i).toArray(Vector2.class)));
    }

    // create the fixtures using the convex polygons
    Fixture[] fixtures = new Fixture[convexPolygons.length];
    for (int i = 0; i < fixtures.length; i++) {
        PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
        convexObject.setColor(mapObject.getColor());
        convexObject.setName(mapObject.getName());
        convexObject.setOpacity(mapObject.getOpacity());
        convexObject.setVisible(mapObject.isVisible());
        convexObject.getProperties().putAll(mapObject.getProperties());
        fixtures[i] = createFixture(convexObject);
    }

    return fixtures;
}
 
Example 13
Source File: CCScheduler.java    From cocos2d-java with MIT License 4 votes vote down vote up
private void priorityIn(Array<ListEntry> list, ICCSelectorProtocol target, int priority, Boolean paused)
  {
ListEntry listElement = new ListEntry();
        
listElement.Target = target;
listElement.Priority = priority;
listElement.Paused = paused;
listElement.MarkedForDeletion = false;
          

      if (list.size == 0)
      {
          list.insert(0,listElement);
      }
      else
      {
          boolean added = false;           
          for (int i=0, n=list.size; i<n; i++)
          {
          	if (priority < list.get(i).Priority)
          	{
          		list.insert(i, listElement);
          		added = true;
          		break;
          	}
          }

          if (!added)
          {
              list.add(listElement);
          }
      }

      // update hash entry for quick access
      HashUpdateEntry hashElement = new HashUpdateEntry();
      
      hashElement.Target = target;
      hashElement.List = list;
      hashElement.Entry = listElement;
      

      m_pHashForUpdates.put(target, hashElement);
  }