package ethanjones.cubes.graphics.hud.inv;

import ethanjones.cubes.item.ItemStack;
import ethanjones.cubes.item.inv.Inventory;

import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

public class InventoryManagerTouchscreen {
  private static SlotActor selected;

  protected static void newSlot(final SlotActor slot) {
    final Inventory inventory = slot.getInventory();
    final int num = slot.getNum();

    slot.addListener(new ClickListener() {

      @Override
      public void clicked(InputEvent event, float x, float y) {
        if (selected == null) {
          if (inventory.itemStacks[num] != null && getTapCount() == 2) {
            selected = slot;
          }
        } else {
          Inventory selectedInv = selected.getInventory();
          int selectedNum = selected.getNum();

          ItemStack itemStack = inventory.itemStacks[num];
          inventory.itemStacks[num] = selectedInv.itemStacks[selectedNum];
          selectedInv.itemStacks[selectedNum] = itemStack;

          if (selectedInv == inventory) {
            inventory.sync();
          } else {
            inventory.sync();
            selectedInv.sync();
          }
          selected = null;
        }

      }
    });
  }

  protected static boolean isSelected(SlotActor slot) {
    return slot == selected;
  }
}

@@ -391,25 +391,25 @@
 ventory 
-inventory
+targetInv
  = slot.
@@ -438,17 +438,23 @@
 nal int 
-n
+targetN
 um = slo
@@ -636,25 +636,25 @@
     if (
-inventory
+targetInv
 .itemSta
@@ -653,25 +653,31 @@
 .itemStacks%5B
-n
+targetN
 um%5D != null 
@@ -902,54 +902,247 @@
 k = 
-inventory.itemStacks%5Bnum%5D;%0A          inventory
+targetInv.itemStacks%5BtargetNum%5D;%0A          if (targetInv.fixed) %7B%0A            if (targetInv.voidItems && !selectedInv.fixed) %7B%0A              selectedInv.itemStacks%5BselectedNum%5D = null;%0A            %7D%0A          %7D else %7B%0A            targetInv
 .ite
@@ -1149,17 +1149,23 @@
 mStacks%5B
-n
+targetN
 um%5D = se
@@ -1195,24 +1195,66 @@
 lectedNum%5D;%0A
+            if (!selectedInv.fixed) %7B%0A    
           se
@@ -1299,16 +1299,42 @@
 emStack;
+%0A            %7D%0A          %7D
 %0A%0A      
@@ -1356,25 +1356,25 @@
 dInv == 
-inventory
+targetInv
 ) %7B%0A    
@@ -1377,33 +1377,33 @@
             
-inventory
+targetInv
 .sync();%0A   
@@ -1434,17 +1434,17 @@
     
-inventory
+targetInv
 .syn

Fix InventoryManagerTouchscreen for Creative Inventory