Search in sources :

Example 1 with Selection

use of com.badlogic.gdx.scenes.scene2d.utils.Selection in project talos by rockbite.

the class DynamicItemListWidget method getSubWidget.

@Override
public Actor getSubWidget() {
    Table table = new Table();
    Skin skin = TalosMain.Instance().getSkin();
    Table topBar = new Table();
    topBar.setBackground(ColorLibrary.obtainBackground(getSkin(), ColorLibrary.BackgroundColor.DARK_GRAY));
    SquareButton newBtn = new SquareButton(skin, skin.getDrawable("timeline-btn-icon-new"));
    SquareButton deleteBtn = new SquareButton(skin, skin.getDrawable("timeline-btn-icon-delete"));
    topBar.add().expandX();
    topBar.add(newBtn).padRight(2);
    topBar.add(deleteBtn).padRight(2);
    list = new FilteredTree<>(skin, "modern");
    list.draggable = true;
    list.setItemListener(new FilteredTree.ItemListener() {

        @Override
        public void onNodeMove(FilteredTree.Node parentToMoveTo, FilteredTree.Node childThatHasMoved, int indexInParent, int indexOfPayloadInPayloadBefore) {
            callValueChanged(makeDataArray());
        }

        @Override
        public void delete(Array<FilteredTree.Node> nodes) {
            deleteSelection();
        }
    });
    table.add(list).growX();
    table.row();
    table.add(topBar).growX().padLeft(-10).padRight(-10);
    newBtn.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            ItemData newItemData = new ItemData(defaultItemName, defaultItemName);
            Selection<FilteredTree.Node<Object>> selection = list.getSelection();
            FilteredTree.Node node;
            if (selection.size() > 0) {
                int index = 0;
                Array<FilteredTree.Node<Object>> rootNodes = list.getRootNodes();
                for (index = 0; index < rootNodes.size; index++) {
                    if (rootNodes.get(index) == selection.first()) {
                        break;
                    }
                }
                node = addNode(newItemData, index + 1);
            } else {
                node = addNode(newItemData);
            }
            callValueChanged(makeDataArray());
            EditableLabel label = (EditableLabel) node.getActor();
            label.setEditMode();
        }
    });
    deleteBtn.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            deleteSelection();
        }
    });
    return table;
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SquareButton(com.talosvfx.talos.editor.widgets.ui.common.SquareButton) Selection(com.badlogic.gdx.scenes.scene2d.utils.Selection) FilteredTree(com.talosvfx.talos.editor.widgets.ui.FilteredTree) Array(com.badlogic.gdx.utils.Array) EditableLabel(com.talosvfx.talos.editor.widgets.ui.EditableLabel) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1 Selection (com.badlogic.gdx.scenes.scene2d.utils.Selection)1 Array (com.badlogic.gdx.utils.Array)1 EditableLabel (com.talosvfx.talos.editor.widgets.ui.EditableLabel)1 FilteredTree (com.talosvfx.talos.editor.widgets.ui.FilteredTree)1 SquareButton (com.talosvfx.talos.editor.widgets.ui.common.SquareButton)1