mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 21:21:41 +00:00
Merge pull request #10 from thearst3rd/mbg-gamepad
MBG - Add gamepad support
This commit is contained in:
commit
f5c44a3e00
16 changed files with 207 additions and 28 deletions
|
|
@ -26,6 +26,7 @@ import h3d.Camera;
|
||||||
import h3d.Vector;
|
import h3d.Vector;
|
||||||
import hxsl.Types.Matrix;
|
import hxsl.Types.Matrix;
|
||||||
import h3d.scene.Scene;
|
import h3d.scene.Scene;
|
||||||
|
import src.Gamepad;
|
||||||
|
|
||||||
enum CameraMode {
|
enum CameraMode {
|
||||||
FreeOrbit;
|
FreeOrbit;
|
||||||
|
|
@ -160,18 +161,18 @@ class CameraController extends Object {
|
||||||
|
|
||||||
var lerpt = hxd.Math.min(1, 1 - Math.pow(0.6, dt * 600));
|
var lerpt = hxd.Math.min(1, 1 - Math.pow(0.6, dt * 600));
|
||||||
|
|
||||||
if (Key.isDown(Settings.controlsSettings.camForward)) {
|
var cameraPitchDelta = (Key.isDown(Settings.controlsSettings.camBackward) ? 1 : 0)
|
||||||
nextCameraPitch += 0.75 * 5 * dt;
|
- (Key.isDown(Settings.controlsSettings.camForward) ? 1 : 0)
|
||||||
}
|
+ Gamepad.getAxis(Settings.gamepadSettings.cameraYAxis);
|
||||||
if (Key.isDown(Settings.controlsSettings.camBackward)) {
|
if (Settings.gamepadSettings.invertYAxis)
|
||||||
nextCameraPitch -= 0.75 * 5 * dt;
|
cameraPitchDelta = -cameraPitchDelta;
|
||||||
}
|
nextCameraPitch += 0.75 * 5 * cameraPitchDelta * dt * Settings.gamepadSettings.cameraSensitivity;
|
||||||
if (Key.isDown(Settings.controlsSettings.camLeft)) {
|
var cameraYawDelta = (Key.isDown(Settings.controlsSettings.camRight) ? 1 : 0)
|
||||||
nextCameraYaw -= 0.75 * 5 * dt;
|
- (Key.isDown(Settings.controlsSettings.camLeft) ? 1 : 0)
|
||||||
}
|
+ Gamepad.getAxis(Settings.gamepadSettings.cameraXAxis);
|
||||||
if (Key.isDown(Settings.controlsSettings.camRight)) {
|
if (Settings.gamepadSettings.invertXAxis)
|
||||||
nextCameraYaw += 0.75 * 5 * dt;
|
cameraYawDelta = -cameraYawDelta;
|
||||||
}
|
nextCameraYaw += 0.75 * 5 * cameraYawDelta * dt * Settings.gamepadSettings.cameraSensitivity;
|
||||||
|
|
||||||
nextCameraPitch = Math.max(-Math.PI / 2 + Math.PI / 4, Math.min(Math.PI / 2 - 0.0001, nextCameraPitch));
|
nextCameraPitch = Math.max(-Math.PI / 2 + Math.PI / 4, Math.min(Math.PI / 2 - 0.0001, nextCameraPitch));
|
||||||
|
|
||||||
|
|
|
||||||
113
src/Gamepad.hx
Normal file
113
src/Gamepad.hx
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
package src;
|
||||||
|
|
||||||
|
import hxd.Pad;
|
||||||
|
import src.Settings;
|
||||||
|
|
||||||
|
class Gamepad {
|
||||||
|
public static var gamepad:Pad = Pad.createDummy();
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
Pad.wait(onPad);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function onPad(pad:Pad) {
|
||||||
|
pad.axisDeadZone = Settings.gamepadSettings.axisDeadzone;
|
||||||
|
pad.onDisconnect = function() {
|
||||||
|
gamepad = Pad.createDummy();
|
||||||
|
}
|
||||||
|
gamepad = pad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getId(name:String) {
|
||||||
|
switch (name) {
|
||||||
|
case "start":
|
||||||
|
return gamepad.config.start;
|
||||||
|
case "ranalogY":
|
||||||
|
return gamepad.config.ranalogY;
|
||||||
|
case "ranalogX":
|
||||||
|
return gamepad.config.ranalogX;
|
||||||
|
case "ranalogClick":
|
||||||
|
return gamepad.config.ranalogClick;
|
||||||
|
case "dpadUp":
|
||||||
|
return gamepad.config.dpadUp;
|
||||||
|
case "dpadRight":
|
||||||
|
return gamepad.config.dpadRight;
|
||||||
|
case "dpadLeft":
|
||||||
|
return gamepad.config.dpadLeft;
|
||||||
|
case "dpadDown":
|
||||||
|
return gamepad.config.dpadDown;
|
||||||
|
case "back":
|
||||||
|
return gamepad.config.back;
|
||||||
|
case "analogY":
|
||||||
|
return gamepad.config.analogY;
|
||||||
|
case "analogX":
|
||||||
|
return gamepad.config.analogX;
|
||||||
|
case "analogClick":
|
||||||
|
return gamepad.config.analogClick;
|
||||||
|
case "Y":
|
||||||
|
return gamepad.config.Y;
|
||||||
|
case "X":
|
||||||
|
return gamepad.config.X;
|
||||||
|
case "RT":
|
||||||
|
return gamepad.config.RT;
|
||||||
|
case "RB":
|
||||||
|
return gamepad.config.RB;
|
||||||
|
case "LT":
|
||||||
|
return gamepad.config.LT;
|
||||||
|
case "LB":
|
||||||
|
return gamepad.config.LB;
|
||||||
|
case "B":
|
||||||
|
return gamepad.config.B;
|
||||||
|
case "A":
|
||||||
|
return gamepad.config.A;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isDown(buttons:Array<String>) {
|
||||||
|
for (button in buttons) {
|
||||||
|
var buttonId = getId(button);
|
||||||
|
if (buttonId < 0 || buttonId > gamepad.buttons.length)
|
||||||
|
continue;
|
||||||
|
if (gamepad.isDown(buttonId))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isPressed(buttons:Array<String>) {
|
||||||
|
for (button in buttons) {
|
||||||
|
var buttonId = getId(button);
|
||||||
|
if (buttonId < 0 || buttonId > gamepad.buttons.length)
|
||||||
|
continue;
|
||||||
|
if (gamepad.isPressed(buttonId))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isReleased(buttons:Array<String>) {
|
||||||
|
for (button in buttons) {
|
||||||
|
var buttonId = getId(button);
|
||||||
|
if (buttonId < 0 || buttonId > gamepad.buttons.length)
|
||||||
|
continue;
|
||||||
|
if (gamepad.isReleased(buttonId))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAxis(axis:String) {
|
||||||
|
switch (axis) {
|
||||||
|
case "analogX":
|
||||||
|
return gamepad.xAxis;
|
||||||
|
case "analogY":
|
||||||
|
return gamepad.yAxis;
|
||||||
|
case "ranalogX":
|
||||||
|
return gamepad.rxAxis;
|
||||||
|
case "ranalogY":
|
||||||
|
return gamepad.ryAxis;
|
||||||
|
}
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,6 +17,7 @@ import hxd.res.DefaultFont;
|
||||||
import h2d.Text;
|
import h2d.Text;
|
||||||
import h3d.Vector;
|
import h3d.Vector;
|
||||||
import src.ProfilerUI;
|
import src.ProfilerUI;
|
||||||
|
import src.Gamepad;
|
||||||
|
|
||||||
class Main extends hxd.App {
|
class Main extends hxd.App {
|
||||||
var marbleGame:MarbleGame;
|
var marbleGame:MarbleGame;
|
||||||
|
|
@ -58,6 +59,7 @@ class Main extends hxd.App {
|
||||||
|
|
||||||
ResourceLoader.init(s2d, () -> {
|
ResourceLoader.init(s2d, () -> {
|
||||||
Settings.init();
|
Settings.init();
|
||||||
|
Gamepad.init();
|
||||||
AudioManager.init();
|
AudioManager.init();
|
||||||
AudioManager.playShell();
|
AudioManager.playShell();
|
||||||
marbleGame = new MarbleGame(s2d, s3d);
|
marbleGame = new MarbleGame(s2d, s3d);
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ import h3d.mat.Texture;
|
||||||
import collision.CCDCollision.TraceInfo;
|
import collision.CCDCollision.TraceInfo;
|
||||||
import src.ResourceLoaderWorker;
|
import src.ResourceLoaderWorker;
|
||||||
import src.InteriorObject;
|
import src.InteriorObject;
|
||||||
|
import src.Gamepad;
|
||||||
|
|
||||||
class Move {
|
class Move {
|
||||||
public var d:Vector;
|
public var d:Vector;
|
||||||
|
|
@ -136,6 +137,7 @@ class Marble extends GameObject {
|
||||||
var _airAccel:Float = 5;
|
var _airAccel:Float = 5;
|
||||||
var _maxDotSlide = 0.5;
|
var _maxDotSlide = 0.5;
|
||||||
var _minBounceVel:Float = 0.1;
|
var _minBounceVel:Float = 0.1;
|
||||||
|
var _minBounceSpeed:Float = 3;
|
||||||
var _minTrailVel:Float = 10;
|
var _minTrailVel:Float = 10;
|
||||||
var _bounceKineticFriction = 0.2;
|
var _bounceKineticFriction = 0.2;
|
||||||
var minVelocityBounceSoft = 2.5;
|
var minVelocityBounceSoft = 2.5;
|
||||||
|
|
@ -635,7 +637,7 @@ class Marble extends GameObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
function bounceEmitter(speed:Float, normal:Vector) {
|
function bounceEmitter(speed:Float, normal:Vector) {
|
||||||
if (this.bounceEmitDelay == 0 && this._minBounceVel <= speed) {
|
if (this.bounceEmitDelay == 0 && this._minBounceSpeed <= speed) {
|
||||||
this.level.particleManager.createEmitter(bounceParticleOptions, this.bounceEmitterData, this.getAbsPos().getPosition());
|
this.level.particleManager.createEmitter(bounceParticleOptions, this.bounceEmitterData, this.getAbsPos().getPosition());
|
||||||
this.bounceEmitDelay = 0.3;
|
this.bounceEmitDelay = 0.3;
|
||||||
}
|
}
|
||||||
|
|
@ -1428,6 +1430,8 @@ class Marble extends GameObject {
|
||||||
var move = new Move();
|
var move = new Move();
|
||||||
move.d = new Vector();
|
move.d = new Vector();
|
||||||
if (this.controllable && this.mode != Finish && !MarbleGame.instance.paused && !this.level.isWatching) {
|
if (this.controllable && this.mode != Finish && !MarbleGame.instance.paused && !this.level.isWatching) {
|
||||||
|
move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis);
|
||||||
|
move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis);
|
||||||
if (Key.isDown(Settings.controlsSettings.forward)) {
|
if (Key.isDown(Settings.controlsSettings.forward)) {
|
||||||
move.d.x -= 1;
|
move.d.x -= 1;
|
||||||
}
|
}
|
||||||
|
|
@ -1440,10 +1444,14 @@ class Marble extends GameObject {
|
||||||
if (Key.isDown(Settings.controlsSettings.right)) {
|
if (Key.isDown(Settings.controlsSettings.right)) {
|
||||||
move.d.y -= 1;
|
move.d.y -= 1;
|
||||||
}
|
}
|
||||||
if (Key.isDown(Settings.controlsSettings.jump) || MarbleGame.instance.touchInput.jumpButton.pressed) {
|
if (Key.isDown(Settings.controlsSettings.jump)
|
||||||
|
|| MarbleGame.instance.touchInput.jumpButton.pressed
|
||||||
|
|| Gamepad.isDown(Settings.gamepadSettings.jump)) {
|
||||||
move.jump = true;
|
move.jump = true;
|
||||||
}
|
}
|
||||||
if (Util.isTouchDevice() ? MarbleGame.instance.touchInput.powerupButton.pressed : Key.isDown(Settings.controlsSettings.powerup)) {
|
if (Key.isDown(Settings.controlsSettings.powerup)
|
||||||
|
|| (Util.isTouchDevice() && MarbleGame.instance.touchInput.powerupButton.pressed)
|
||||||
|
|| Gamepad.isDown(Settings.gamepadSettings.powerup)) {
|
||||||
move.powerup = true;
|
move.powerup = true;
|
||||||
}
|
}
|
||||||
if (MarbleGame.instance.touchInput.movementInput.pressed) {
|
if (MarbleGame.instance.touchInput.movementInput.pressed) {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import src.JSPlatform;
|
||||||
import gui.Canvas;
|
import gui.Canvas;
|
||||||
import src.Util;
|
import src.Util;
|
||||||
import src.ProfilerUI;
|
import src.ProfilerUI;
|
||||||
|
import src.Gamepad;
|
||||||
|
|
||||||
@:publicFields
|
@:publicFields
|
||||||
class MarbleGame {
|
class MarbleGame {
|
||||||
|
|
@ -161,17 +162,10 @@ class MarbleGame {
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
world.update(dt);
|
world.update(dt);
|
||||||
}
|
}
|
||||||
if (Key.isPressed(Key.ESCAPE) && world.finishTime == null && world._ready) {
|
if (((Key.isPressed(Key.ESCAPE) #if js && paused #end) || Gamepad.isPressed(["start"]))
|
||||||
#if hl
|
&& world.finishTime == null && world._ready) {
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
handlePauseGame();
|
handlePauseGame();
|
||||||
#end
|
|
||||||
#if js
|
|
||||||
if (paused) {
|
|
||||||
paused = false;
|
|
||||||
}
|
|
||||||
handlePauseGame();
|
|
||||||
#end
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (canvas != null) {
|
if (canvas != null) {
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ import src.Marble;
|
||||||
import src.Resource;
|
import src.Resource;
|
||||||
import src.ProfilerUI;
|
import src.ProfilerUI;
|
||||||
import src.ResourceLoaderWorker;
|
import src.ResourceLoaderWorker;
|
||||||
|
import src.Gamepad;
|
||||||
|
|
||||||
class MarbleWorld extends Scheduler {
|
class MarbleWorld extends Scheduler {
|
||||||
public var collisionWorld:CollisionWorld;
|
public var collisionWorld:CollisionWorld;
|
||||||
|
|
@ -910,7 +911,9 @@ class MarbleWorld extends Scheduler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.outOfBounds && this.finishTime == null && Key.isDown(Settings.controlsSettings.powerup)) {
|
if (this.outOfBounds
|
||||||
|
&& this.finishTime == null
|
||||||
|
&& (Key.isDown(Settings.controlsSettings.powerup) || Gamepad.isDown(Settings.gamepadSettings.powerup))) {
|
||||||
this.clearSchedule();
|
this.clearSchedule();
|
||||||
this.restart();
|
this.restart();
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,19 @@ typedef TouchSettings = {
|
||||||
var buttonJoystickMultiplier:Float;
|
var buttonJoystickMultiplier:Float;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef GamepadSettings = {
|
||||||
|
var moveXAxis:String;
|
||||||
|
var moveYAxis:String;
|
||||||
|
var cameraXAxis:String;
|
||||||
|
var cameraYAxis:String;
|
||||||
|
var jump:Array<String>;
|
||||||
|
var powerup:Array<String>;
|
||||||
|
var cameraSensitivity:Float;
|
||||||
|
var invertXAxis:Bool;
|
||||||
|
var invertYAxis:Bool;
|
||||||
|
var axisDeadzone:Float;
|
||||||
|
}
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
public static var highScores:Map<String, Array<Score>> = [];
|
public static var highScores:Map<String, Array<Score>> = [];
|
||||||
|
|
||||||
|
|
@ -107,6 +120,20 @@ class Settings {
|
||||||
powerupButtonSize: 60,
|
powerupButtonSize: 60,
|
||||||
buttonJoystickMultiplier: 2.5
|
buttonJoystickMultiplier: 2.5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static var gamepadSettings:GamepadSettings = {
|
||||||
|
moveXAxis: "analogX",
|
||||||
|
moveYAxis: "analogY",
|
||||||
|
cameraXAxis: "ranalogX",
|
||||||
|
cameraYAxis: "ranalogY",
|
||||||
|
jump: ["A", "LT"],
|
||||||
|
powerup: ["B", "RT"],
|
||||||
|
cameraSensitivity: 1.0,
|
||||||
|
invertXAxis: false,
|
||||||
|
invertYAxis: false,
|
||||||
|
axisDeadzone: 0.15
|
||||||
|
}
|
||||||
|
|
||||||
public static var progression = [24, 24, 52];
|
public static var progression = [24, 24, 52];
|
||||||
public static var highscoreName = "";
|
public static var highscoreName = "";
|
||||||
|
|
||||||
|
|
@ -158,6 +185,7 @@ class Settings {
|
||||||
options: optionsSettings,
|
options: optionsSettings,
|
||||||
controls: controlsSettings,
|
controls: controlsSettings,
|
||||||
touch: touchSettings,
|
touch: touchSettings,
|
||||||
|
gamepad: gamepadSettings,
|
||||||
progression: progression,
|
progression: progression,
|
||||||
highscoreName: highscoreName
|
highscoreName: highscoreName
|
||||||
};
|
};
|
||||||
|
|
@ -223,6 +251,9 @@ class Settings {
|
||||||
if (json.touch != null) {
|
if (json.touch != null) {
|
||||||
touchSettings = json.touch;
|
touchSettings = json.touch;
|
||||||
}
|
}
|
||||||
|
if (json.gamepad != null) {
|
||||||
|
gamepadSettings = json.gamepad;
|
||||||
|
}
|
||||||
progression = json.progression;
|
progression = json.progression;
|
||||||
highscoreName = json.highscoreName;
|
highscoreName = json.highscoreName;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ class EndGameGui extends GuiControl {
|
||||||
continueButton.position = new Vector(333, 386);
|
continueButton.position = new Vector(333, 386);
|
||||||
continueButton.extent = new Vector(113, 47);
|
continueButton.extent = new Vector(113, 47);
|
||||||
continueButton.accelerator = hxd.Key.ENTER;
|
continueButton.accelerator = hxd.Key.ENTER;
|
||||||
|
continueButton.gamepadAccelerator = ["A"];
|
||||||
continueButton.pressedAction = continueFunc;
|
continueButton.pressedAction = continueFunc;
|
||||||
|
|
||||||
var restartButton = new GuiButton(loadButtonImages("data/ui/endgame/replay"));
|
var restartButton = new GuiButton(loadButtonImages("data/ui/endgame/replay"));
|
||||||
|
|
@ -50,6 +51,7 @@ class EndGameGui extends GuiControl {
|
||||||
restartButton.vertSizing = Bottom;
|
restartButton.vertSizing = Bottom;
|
||||||
restartButton.position = new Vector(51, 388);
|
restartButton.position = new Vector(51, 388);
|
||||||
restartButton.extent = new Vector(104, 48);
|
restartButton.extent = new Vector(104, 48);
|
||||||
|
restartButton.gamepadAccelerator = ["B"];
|
||||||
restartButton.pressedAction = restartFunc;
|
restartButton.pressedAction = restartFunc;
|
||||||
|
|
||||||
function setButtonStates(enabled:Bool) {
|
function setButtonStates(enabled:Bool) {
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ class EnterNameDlg extends GuiControl {
|
||||||
okbutton.position = new Vector(163, 182);
|
okbutton.position = new Vector(163, 182);
|
||||||
okbutton.extent = new Vector(78, 59);
|
okbutton.extent = new Vector(78, 59);
|
||||||
okbutton.accelerator = hxd.Key.ENTER;
|
okbutton.accelerator = hxd.Key.ENTER;
|
||||||
|
okbutton.gamepadAccelerator = ["A"];
|
||||||
okbutton.pressedAction = (sender) -> {
|
okbutton.pressedAction = (sender) -> {
|
||||||
MarbleGame.canvas.popDialog(this);
|
MarbleGame.canvas.popDialog(this);
|
||||||
Settings.highscoreName = enterNameEdit.text.text;
|
Settings.highscoreName = enterNameEdit.text.text;
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ class ExitGameDlg extends GuiControl {
|
||||||
yesButton.horizSizing = Right;
|
yesButton.horizSizing = Right;
|
||||||
yesButton.pressedAction = yesFunc;
|
yesButton.pressedAction = yesFunc;
|
||||||
yesButton.accelerator = hxd.Key.ENTER;
|
yesButton.accelerator = hxd.Key.ENTER;
|
||||||
|
yesButton.gamepadAccelerator = ["A"];
|
||||||
|
|
||||||
var noButton = new GuiButton(loadButtonImages("data/ui/common/no"));
|
var noButton = new GuiButton(loadButtonImages("data/ui/common/no"));
|
||||||
noButton.position = new Vector(151, 107);
|
noButton.position = new Vector(151, 107);
|
||||||
|
|
@ -55,6 +56,7 @@ class ExitGameDlg extends GuiControl {
|
||||||
noButton.vertSizing = Bottom;
|
noButton.vertSizing = Bottom;
|
||||||
noButton.horizSizing = Right;
|
noButton.horizSizing = Right;
|
||||||
noButton.pressedAction = noFunc;
|
noButton.pressedAction = noFunc;
|
||||||
|
noButton.gamepadAccelerator = ["B"];
|
||||||
|
|
||||||
var restartButton = new GuiButton(loadButtonImages("data/ui/common/restart"));
|
var restartButton = new GuiButton(loadButtonImages("data/ui/common/restart"));
|
||||||
restartButton.position = new Vector(249, 107);
|
restartButton.position = new Vector(249, 107);
|
||||||
|
|
@ -62,6 +64,7 @@ class ExitGameDlg extends GuiControl {
|
||||||
restartButton.vertSizing = Bottom;
|
restartButton.vertSizing = Bottom;
|
||||||
restartButton.horizSizing = Right;
|
restartButton.horizSizing = Right;
|
||||||
restartButton.pressedAction = restartFunc;
|
restartButton.pressedAction = restartFunc;
|
||||||
|
restartButton.gamepadAccelerator = ["X"];
|
||||||
|
|
||||||
dialogImg.addChild(exitGameText);
|
dialogImg.addChild(exitGameText);
|
||||||
dialogImg.addChild(yesButton);
|
dialogImg.addChild(yesButton);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import gui.GuiControl.MouseState;
|
||||||
import hxd.Window;
|
import hxd.Window;
|
||||||
import h2d.Tile;
|
import h2d.Tile;
|
||||||
import src.ResourceLoader;
|
import src.ResourceLoader;
|
||||||
|
import src.Gamepad;
|
||||||
|
|
||||||
enum ButtonType {
|
enum ButtonType {
|
||||||
Normal;
|
Normal;
|
||||||
|
|
@ -28,6 +29,8 @@ class GuiButton extends GuiAnim {
|
||||||
public var buttonSounds:Bool = true;
|
public var buttonSounds:Bool = true;
|
||||||
|
|
||||||
public var accelerator:Int = 0;
|
public var accelerator:Int = 0;
|
||||||
|
public var gamepadAccelerator:Array<String> = [];
|
||||||
|
public var acceleratorWasPressed = false;
|
||||||
|
|
||||||
public function new(anim:Array<Tile>) {
|
public function new(anim:Array<Tile>) {
|
||||||
super(anim);
|
super(anim);
|
||||||
|
|
@ -69,11 +72,20 @@ class GuiButton extends GuiAnim {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!disabled && accelerator != 0 && hxd.Key.isReleased(accelerator)) {
|
if (!disabled) {
|
||||||
if (this.pressedAction != null) {
|
if (acceleratorWasPressed &&
|
||||||
this.pressedAction(this);
|
(accelerator != 0 && hxd.Key.isReleased(accelerator)) || Gamepad.isReleased(gamepadAccelerator)) {
|
||||||
|
if (this.pressedAction != null) {
|
||||||
|
this.pressedAction(this);
|
||||||
|
}
|
||||||
|
} else if ((accelerator != 0 && hxd.Key.isPressed(accelerator)) || Gamepad.isPressed(gamepadAccelerator)) {
|
||||||
|
acceleratorWasPressed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (acceleratorWasPressed) {
|
||||||
|
if ((accelerator != 0 && hxd.Key.isReleased(accelerator)) || Gamepad.isReleased(gamepadAccelerator))
|
||||||
|
acceleratorWasPressed = false;
|
||||||
|
}
|
||||||
super.update(dt, mouseState);
|
super.update(dt, mouseState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ class HelpCreditsGui extends GuiImage {
|
||||||
homeButton.position = new Vector(278, 378);
|
homeButton.position = new Vector(278, 378);
|
||||||
homeButton.extent = new Vector(79, 61);
|
homeButton.extent = new Vector(79, 61);
|
||||||
homeButton.accelerator = hxd.Key.ESCAPE;
|
homeButton.accelerator = hxd.Key.ESCAPE;
|
||||||
|
homeButton.gamepadAccelerator = ["B"];
|
||||||
homeButton.pressedAction = (sender) -> {
|
homeButton.pressedAction = (sender) -> {
|
||||||
MarbleGame.canvas.setContent(new MainMenuGui());
|
MarbleGame.canvas.setContent(new MainMenuGui());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ class MainMenuGui extends GuiImage {
|
||||||
var playButton = new GuiButton(loadButtonImages("data/ui/home/play"));
|
var playButton = new GuiButton(loadButtonImages("data/ui/home/play"));
|
||||||
playButton.position = new Vector(50, 113);
|
playButton.position = new Vector(50, 113);
|
||||||
playButton.extent = new Vector(270, 95);
|
playButton.extent = new Vector(270, 95);
|
||||||
|
playButton.gamepadAccelerator = ["A"];
|
||||||
playButton.pressedAction = (sender) -> {
|
playButton.pressedAction = (sender) -> {
|
||||||
cast(this.parent, Canvas).setContent(new PlayMissionGui());
|
cast(this.parent, Canvas).setContent(new PlayMissionGui());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ class MessageBoxOkDlg extends GuiControl {
|
||||||
okButton.extent = new Vector(78, 59);
|
okButton.extent = new Vector(78, 59);
|
||||||
okButton.vertSizing = Top;
|
okButton.vertSizing = Top;
|
||||||
okButton.accelerator = hxd.Key.ENTER;
|
okButton.accelerator = hxd.Key.ENTER;
|
||||||
|
okButton.gamepadAccelerator = ["A"];
|
||||||
okButton.pressedAction = (sender) -> {
|
okButton.pressedAction = (sender) -> {
|
||||||
MarbleGame.canvas.popDialog(this);
|
MarbleGame.canvas.popDialog(this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ class MessageBoxYesNoDlg extends GuiControl {
|
||||||
yesButton.extent = new Vector(82, 47);
|
yesButton.extent = new Vector(82, 47);
|
||||||
yesButton.vertSizing = Top;
|
yesButton.vertSizing = Top;
|
||||||
yesButton.accelerator = hxd.Key.ENTER;
|
yesButton.accelerator = hxd.Key.ENTER;
|
||||||
|
yesButton.gamepadAccelerator = ["A"];
|
||||||
yesButton.pressedAction = (sender) -> {
|
yesButton.pressedAction = (sender) -> {
|
||||||
MarbleGame.canvas.popDialog(this);
|
MarbleGame.canvas.popDialog(this);
|
||||||
yesFunc();
|
yesFunc();
|
||||||
|
|
@ -58,6 +59,7 @@ class MessageBoxYesNoDlg extends GuiControl {
|
||||||
noButton.extent = new Vector(75, 47);
|
noButton.extent = new Vector(75, 47);
|
||||||
noButton.vertSizing = Top;
|
noButton.vertSizing = Top;
|
||||||
noButton.accelerator = hxd.Key.ESCAPE;
|
noButton.accelerator = hxd.Key.ESCAPE;
|
||||||
|
noButton.gamepadAccelerator = ["B"];
|
||||||
noButton.pressedAction = (sender) -> {
|
noButton.pressedAction = (sender) -> {
|
||||||
MarbleGame.canvas.popDialog(this);
|
MarbleGame.canvas.popDialog(this);
|
||||||
noFunc();
|
noFunc();
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,7 @@ class PlayMissionGui extends GuiImage {
|
||||||
var pmPlay = new GuiButton(loadButtonImages("data/ui/play/play"));
|
var pmPlay = new GuiButton(loadButtonImages("data/ui/play/play"));
|
||||||
pmPlay.position = new Vector(391, 257);
|
pmPlay.position = new Vector(391, 257);
|
||||||
pmPlay.extent = new Vector(121, 62);
|
pmPlay.extent = new Vector(121, 62);
|
||||||
|
pmPlay.gamepadAccelerator = ["A"];
|
||||||
pmPlay.pressedAction = (sender) -> {
|
pmPlay.pressedAction = (sender) -> {
|
||||||
// Wacky hacks
|
// Wacky hacks
|
||||||
currentList[currentSelection].index = currentSelection;
|
currentList[currentSelection].index = currentSelection;
|
||||||
|
|
@ -235,6 +236,7 @@ class PlayMissionGui extends GuiImage {
|
||||||
var pmPrev = new GuiButton(loadButtonImages("data/ui/play/prev"));
|
var pmPrev = new GuiButton(loadButtonImages("data/ui/play/prev"));
|
||||||
pmPrev.position = new Vector(321, 260);
|
pmPrev.position = new Vector(321, 260);
|
||||||
pmPrev.extent = new Vector(77, 58);
|
pmPrev.extent = new Vector(77, 58);
|
||||||
|
pmPrev.gamepadAccelerator = ["dpadLeft"];
|
||||||
pmPrev.pressedAction = (sender) -> {
|
pmPrev.pressedAction = (sender) -> {
|
||||||
setSelectedFunc(currentSelection - 1);
|
setSelectedFunc(currentSelection - 1);
|
||||||
}
|
}
|
||||||
|
|
@ -243,6 +245,7 @@ class PlayMissionGui extends GuiImage {
|
||||||
var pmNext = new GuiButton(loadButtonImages("data/ui/play/next"));
|
var pmNext = new GuiButton(loadButtonImages("data/ui/play/next"));
|
||||||
pmNext.position = new Vector(507, 262);
|
pmNext.position = new Vector(507, 262);
|
||||||
pmNext.extent = new Vector(75, 60);
|
pmNext.extent = new Vector(75, 60);
|
||||||
|
pmNext.gamepadAccelerator = ["dpadRight"];
|
||||||
pmNext.pressedAction = (sender) -> {
|
pmNext.pressedAction = (sender) -> {
|
||||||
setSelectedFunc(currentSelection + 1);
|
setSelectedFunc(currentSelection + 1);
|
||||||
}
|
}
|
||||||
|
|
@ -280,6 +283,7 @@ class PlayMissionGui extends GuiImage {
|
||||||
var pmBack = new GuiButton(loadButtonImages("data/ui/play/back"));
|
var pmBack = new GuiButton(loadButtonImages("data/ui/play/back"));
|
||||||
pmBack.position = new Vector(102, 260);
|
pmBack.position = new Vector(102, 260);
|
||||||
pmBack.extent = new Vector(79, 61);
|
pmBack.extent = new Vector(79, 61);
|
||||||
|
pmBack.gamepadAccelerator = ["B"];
|
||||||
pmBack.pressedAction = (sender) -> {
|
pmBack.pressedAction = (sender) -> {
|
||||||
cast(this.parent, Canvas).setContent(new MainMenuGui());
|
cast(this.parent, Canvas).setContent(new MainMenuGui());
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue