mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-10 15:20:25 +07:00
Create EventUtils to assist with repetitive macros
Added EventUtils.click(Button) to click button programmically and call its click listeners
This commit is contained in:
parent
cbaba5c40b
commit
8f4d8aaab6
29
core/src/gdx/diablo/util/EventUtils.java
Normal file
29
core/src/gdx/diablo/util/EventUtils.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user