diff --git a/core/src/gdx/diablo/util/EventUtils.java b/core/src/gdx/diablo/util/EventUtils.java new file mode 100644 index 00000000..b9dc12d3 --- /dev/null +++ b/core/src/gdx/diablo/util/EventUtils.java @@ -0,0 +1,29 @@ +package gdx.diablo.util; + +import com.badlogic.gdx.Input; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.ui.Button; +import com.badlogic.gdx.utils.Pools; + +public class EventUtils { + + private EventUtils() {} + + public static boolean click(Button button) { + if (button.isDisabled()) return false; + InputEvent event = Pools.obtain(InputEvent.class); + event.setType(InputEvent.Type.touchDown); + event.setStage(button.getStage()); + event.setStageX(0); + event.setStageY(0); + event.setPointer(0); + event.setButton(Input.Buttons.LEFT); + event.setListenerActor(button); + button.fire(event); + + event.setType(InputEvent.Type.touchUp); + button.fire(event); + Pools.free(event); + return true; + } +}