InteractiveNodes can now also be pressed against their will !
This commit is contained in:
parent
87d78195d4
commit
adf75ef7a1
@ -6,6 +6,7 @@ import com.badlogic.ashley.core.EntityListener;
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.saltosion.gladiator.components.CAI;
|
||||
@ -187,8 +188,15 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
||||
System.out.println(img1.getRegionHeight() + " - " + img1.getRegionWidth());
|
||||
ButtonNode button = new ButtonNode("test-button", img1, img2) {
|
||||
@Override
|
||||
public void click(float x, float y, Input.Buttons mouseButton) {
|
||||
Log.info("I should never be pressed!");
|
||||
public void pressed(int x, int y, int mouseButton) {
|
||||
Log.info("I should never be pressed against my will!");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void released(int x, int y, int mouseButton) {
|
||||
Log.info("And now I was even released! Blasphemy!");
|
||||
|
||||
}
|
||||
};
|
||||
button.setPosition(0.12f, 0.5f);
|
||||
|
@ -16,12 +16,20 @@ public interface InteractiveNode {
|
||||
* @param y position of the mouse.
|
||||
*/
|
||||
public void mouseLeave(float x, float y);
|
||||
|
||||
|
||||
/**
|
||||
* Called when someone presses a mouse button on the node's elements.
|
||||
* @param x position of the mouse.
|
||||
* @param y position of the mouse.
|
||||
* @param mouseButton button pressed.
|
||||
*/
|
||||
public void click(float x, float y, Buttons mouseButton);
|
||||
public void pressed(int x, int y, int mouseButton);
|
||||
/**
|
||||
*
|
||||
* Called when someone releases a mouse button on the node's elements.
|
||||
* @param x position of the mouse.
|
||||
* @param y position of the mouse.
|
||||
* @param mouseButton button pressed.
|
||||
*/
|
||||
public void released(int x, int y, int mouseButton);
|
||||
}
|
||||
|
@ -56,12 +56,30 @@ public class InputHandler implements InputProcessor {
|
||||
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||
return false;
|
||||
for (String id : hoveredUIElements) {
|
||||
for (GUINode node : AppUtil.guiManager.getAllRecursiveChildren(AppUtil.guiManager.getRootNode())) {
|
||||
if (node.getID().equals(id)) {
|
||||
if (node instanceof InteractiveNode) {
|
||||
((InteractiveNode) node).pressed(screenX, screenY, button);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||
return false;
|
||||
for (String id : hoveredUIElements) {
|
||||
for (GUINode node : AppUtil.guiManager.getAllRecursiveChildren(AppUtil.guiManager.getRootNode())) {
|
||||
if (node.getID().equals(id)) {
|
||||
if (node instanceof InteractiveNode) {
|
||||
((InteractiveNode) node).released(screenX, screenY, button);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -92,18 +110,18 @@ public class InputHandler implements InputProcessor {
|
||||
continue;
|
||||
}
|
||||
hoveredUIElements.add(node.getID());
|
||||
interactiveNode.mouseEnter(x, y);
|
||||
interactiveNode.mouseEnter(screenX, screenY);
|
||||
} else {
|
||||
if (!hoveredUIElements.contains(node.getID(), false)) {
|
||||
continue;
|
||||
}
|
||||
hoveredUIElements.removeValue(node.getID(), false);
|
||||
interactiveNode.mouseLeave(x, y);
|
||||
interactiveNode.mouseLeave(screenX, screenY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user