Java 类com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Payload 实例源码

项目:Inspiration    文件:InventorySlotSource.java   
@Override
    public Payload dragStart(InputEvent event, float x, float y, int pointer) {
        Payload payload = new Payload();

        Actor actor = getActor();
        if( actor == null ){
            return null;
        }

        InventorySlot source = (InventorySlot)actor.getParent();
        if( source == null ){
            return null;
        }else{
            sourceSlot = source;
        }

    sourceSlot.decrementItemCount(true);

    payload.setDragActor(getActor());
    dragAndDrop.setDragActorPosition(-x, -y + getActor().getHeight());

    return payload;
}
项目:GDXJam    文件:CommandCardContainer.java   
public void addSquad (final Entity squad, final int index) {
        final SquadCommandCard squadCard = new SquadCommandCard(squad, index, skin);
        Source source = new Source(squadCard) {

            @Override
            public Payload dragStart (InputEvent event, float x, float y, int pointer) {
                Payload payload = new Payload();

// payload.setDragActor(new Label("Test", skin));
                SquadCommandCard card = new SquadCommandCard(squad, index, skin);
                payload.setDragActor(card);
// payload.setDragActor(squadTable);
                return payload;
            }
        };

        dragAndDrop.addSource(source);

        cardSlots.get(index).setCard(squadCard);
    }
项目:Terminkalender    文件:SlotSource.java   
@Override
public void dragStop(InputEvent event, float x, float y, int pointer, Payload payload, Target target) {
    Slot payloadSlot = (Slot) payload.getObject();
    if (target != null) {
        Slot targetSlot = ((SlotActor) target.getActor()).getSlot();
        sourceSlot.copy(targetSlot.isEmpty(), targetSlot.getTask());
        targetSlot.copy(payloadSlot.isEmpty(), payloadSlot.getTask());

        if(targetSlot.hasPosition()) {
            dialog.setTask(targetSlot.getTask());
            dialog.show(AppMain.calendarScreen.getStage());
        }
    } else {
        sourceSlot.copy(payloadSlot.isEmpty(), payloadSlot.getTask());
    }
}
项目:libgdx-utils    文件:SlotSource.java   
@Override
public void dragStop(InputEvent event, float x, float y, int pointer, Payload payload, Target target) {
    Slot payloadSlot = (Slot) payload.getObject();
    if (target != null) {
        Slot targetSlot = ((SlotActor) target.getActor()).getSlot();
        if (targetSlot.getItem() == payloadSlot.getItem() || targetSlot.getItem() == null) {
            targetSlot.add(payloadSlot.getItem(), payloadSlot.getAmount());
        } else {
            Item targetType = targetSlot.getItem();
            int targetAmount = targetSlot.getAmount();
            targetSlot.take(targetAmount);
            targetSlot.add(payloadSlot.getItem(), payloadSlot.getAmount());
            sourceSlot.add(targetType, targetAmount);
        }
    } else {
        sourceSlot.add(payloadSlot.getItem(), payloadSlot.getAmount());
    }
}
项目:GDefence    文件:SlotSource.java   
@Override
    public Payload dragStart(InputEvent event, float x, float y, int pointer) {
        if (sourceSlot.getAmount() == 0) {
            return null;
        }

        Payload payload = new Payload();
//      Slot payloadSlot = new Slot(sourceSlot.getPrototype(), sourceSlot.getAmount());
        payloadSlot = new Slot(sourceSlot.getType()/*, sourceSlot.getPrototype(), 0*/);
        if(!takeSlot()) return null;
        payload.setObject(payloadSlot);

        //TextureAtlas icons = LibgdxUtils.assets.get("icons/icons.atlas", TextureAtlas.class);
        TextureAtlas icons = /*new TextureAtlas(*//*Gdx.files.internal("icons/icons.atlas")*/GDefence.getInstance().assetLoader.get("icons/icons.atlas", TextureAtlas.class)/*)*/;
        TextureRegion icon = icons.findRegion(payloadSlot.getPrototype().getTextureRegion());

        Actor dragActor = new Image(icon);
//        dragActor.setSize(35, 35);
        payload.setDragActor(dragActor);

        Actor validDragActor = new Image(icon);
//        validDragActor.setSize(35, 35);
        // validDragActor.setColor(0, 1, 0, 1);
        payload.setValidDragActor(validDragActor);

        Actor invalidDragActor = new Image(icon);
//        invalidDragActor.setSize(35, 35);
        // invalidDragActor.setColor(1, 0, 0, 1);
        payload.setInvalidDragActor(invalidDragActor);

        return payload;
    }
项目:GDefence    文件:SlotSource.java   
@Override
public void dragStop(InputEvent event, float x, float y, int pointer, Payload payload, Target target) {
    //Slot payloadSlot = (Slot) payload.getObject();
    if (target == null) {
        ifNullTarget();
    } else if(target instanceof SlotTarget){
        ifSlotTarget(target);
    } /*else {// other targets
        System.out.println("else");
        ifNullTarget();
    }*/
}
项目:GDefence    文件:SlotTarget.java   
@Override
public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
    Slot payloadSlot = (Slot) payload.getObject();
    // if (targetSlot.getPrototype() == payloadSlot.getPrototype() ||
    // targetSlot.getPrototype() == null) {
    getActor().setColor(Color.WHITE);
    return true;
    // } else {
    // getActor().setColor(Color.DARK_GRAY);
    // return false;
    // }
}
项目:Inspiration    文件:InventorySlotTarget.java   
@Override
public void drop(Source source, Payload payload, float x, float y, int pointer) {
    InventoryItem sourceActor = (InventoryItem) payload.getDragActor();
    InventoryItem targetActor = _targetSlot.getTopInventoryItem();
    InventorySlot sourceSlot = ((InventorySlotSource)source).getSourceSlot();

    if( sourceActor == null ) {
        return;
    }

    //First, does the slot accept the source item type?
    if( !_targetSlot.doesAcceptItemUseType(sourceActor.getItemUseType()))  {
        //Put item back where it came from, slot doesn't accept item
        sourceSlot.add(sourceActor);
        return;
    }

    if( !_targetSlot.hasItem() ){
        _targetSlot.add(sourceActor);
    }else{
        //If the same item and stackable, add
        if( sourceActor.isSameItemType(targetActor) && sourceActor.isStackable()){
            _targetSlot.add(sourceActor);
        }else{
            //If they aren't the same items or the items aren't stackable, then swap
            InventorySlot.swapSlots(sourceSlot, _targetSlot, sourceActor);
        }
    }

}
项目:Terminkalender    文件:SlotSource.java   
@Override
public Payload dragStart(InputEvent event, float x, float y, int pointer) {
    if (sourceSlot.isEmpty()) {
        return null;
    }
    else {
        Payload payload = new Payload();
        Slot payloadSlot = new Slot();
        payloadSlot.copy(sourceSlot.isEmpty(), sourceSlot.getTask());
        sourceSlot.setEmpty();
        payload.setObject(payloadSlot);

        TextButton button = new TextButton(payloadSlot.getTask().getShortDescription(), Resources.skin, "fullTextButtonDescription");
        button.setWidth(CalendarScreen.WIDTHTASK);
        button.setHeight(CalendarScreen.HEIGHTTASK);

        Actor dragActor = button;
        payload.setDragActor(dragActor);

        Actor validDragActor = button;
        payload.setValidDragActor(validDragActor);

        Actor invalidDragActor = button;
        payload.setInvalidDragActor(invalidDragActor);

        return payload;
    }
}
项目:libgdx-utils    文件:SlotSource.java   
@Override
public Payload dragStart(InputEvent event, float x, float y, int pointer) {
    if (sourceSlot.getAmount() == 0) {
        return null;
    }

    Payload payload = new Payload();
    Slot payloadSlot = new Slot(sourceSlot.getItem(), sourceSlot.getAmount());
    sourceSlot.take(sourceSlot.getAmount());
    payload.setObject(payloadSlot);

    TextureAtlas icons = LibgdxUtils.assets.get("icons/icons.atlas", TextureAtlas.class);
    TextureRegion icon = icons.findRegion(payloadSlot.getItem().getTextureRegion());

    Actor dragActor = new Image(icon);
    payload.setDragActor(dragActor);

    Actor validDragActor = new Image(icon);
    // validDragActor.setColor(0, 1, 0, 1);
    payload.setValidDragActor(validDragActor);

    Actor invalidDragActor = new Image(icon);
    // invalidDragActor.setColor(1, 0, 0, 1);
    payload.setInvalidDragActor(invalidDragActor);

    return payload;
}
项目:libgdx-utils    文件:SlotTarget.java   
@Override
public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
    Slot payloadSlot = (Slot) payload.getObject();
    // if (targetSlot.getItem() == payloadSlot.getItem() ||
    // targetSlot.getItem() == null) {
    getActor().setColor(Color.WHITE);
    return true;
    // } else {
    // getActor().setColor(Color.DARK_GRAY);
    // return false;
    // }
}
项目:vis-editor    文件:AssetDragAndDrop.java   
private void addAtlasSource (AtlasItem item) {
    dragAndDrop.addSource(new Source(item) {
        @Override
        public Payload dragStart (InputEvent event, float x, float y, int pointer) {
            return createTexturePayload(item.getRegion(), item.getAtlasAsset());
        }
    });
}
项目:vis-editor    文件:AssetDragAndDrop.java   
private Payload createTexturePayload (TextureRegion region, TextureAssetDescriptor asset) {
    Payload payload = new Payload();

    payload.setObject(asset);

    //image creation
    Image img = new Image(region);
    payload.setDragActor(img);

    float invZoom = 1.0f / dropTarget.getCameraZoom();
    img.setScale(invZoom);
    dragAndDrop.setDragActorPosition(-img.getWidth() * invZoom / 2, img.getHeight() - img.getHeight() * invZoom / 2);

    return payload;
}
项目:vis-editor    文件:VisDropSource.java   
@Override
public Payload dragStart (InputEvent event, float x, float y, int pointer) {
    Payload payload = new Payload();

    payload.setObject(payloadObject);

    Label label = new VisLabel(viewText);
    label.setAlignment(Align.center);
    payload.setDragActor(label);

    dragAndDrop.setDragActorPosition(-label.getWidth() / 2, label.getHeight() / 2);

    return payload;
}
项目:GDefence    文件:SlotTarget.java   
@Override
public void drop(Source source, Payload payload, float x, float y, int pointer) {
}
项目:GDefence    文件:SlotTarget.java   
@Override
public void reset(Source source, Payload payload) {
    getActor().setColor(Color.LIGHT_GRAY);
}
项目:Inspiration    文件:InventorySlotTarget.java   
@Override
public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
    return true;
}
项目:Inspiration    文件:InventorySlotTarget.java   
@Override
public void reset(Source source, Payload payload) {
}
项目:Inspiration    文件:InventorySlotSource.java   
@Override
public void dragStop (InputEvent event, float x, float y, int pointer, Payload payload, Target target) {
    if( target == null ){
        sourceSlot.add(payload.getDragActor());
    }
}
项目:Terminkalender    文件:SlotTarget.java   
@Override
public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
    return true;
}
项目:Terminkalender    文件:SlotTarget.java   
@Override
public void drop(Source source, Payload payload, float x, float y, int pointer) {}
项目:Terminkalender    文件:SlotTarget.java   
@Override
public void reset(Source source, Payload payload) {}
项目:libgdx-utils    文件:SlotTarget.java   
@Override
public void drop(Source source, Payload payload, float x, float y, int pointer) {
}
项目:libgdx-utils    文件:SlotTarget.java   
@Override
public void reset(Source source, Payload payload) {
    getActor().setColor(Color.LIGHT_GRAY);
}