@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; }
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); }
@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()); } }
@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()); } }
@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; }
@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(); }*/ }
@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; // } }
@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); } } }
@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; } }
@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; }
@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; // } }
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()); } }); }
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; }
@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; }
@Override public void drop(Source source, Payload payload, float x, float y, int pointer) { }
@Override public void reset(Source source, Payload payload) { getActor().setColor(Color.LIGHT_GRAY); }
@Override public boolean drag(Source source, Payload payload, float x, float y, int pointer) { return true; }
@Override public void reset(Source source, Payload payload) { }
@Override public void dragStop (InputEvent event, float x, float y, int pointer, Payload payload, Target target) { if( target == null ){ sourceSlot.add(payload.getDragActor()); } }
@Override public void drop(Source source, Payload payload, float x, float y, int pointer) {}
@Override public void reset(Source source, Payload payload) {}