mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-05-10 11:31:39 +00:00
start work on touch controls settings
This commit is contained in:
parent
a1dd6f3b55
commit
9b3a2b11ec
11 changed files with 233 additions and 21 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import h3d.Vector;
|
||||||
import haxe.ds.Option;
|
import haxe.ds.Option;
|
||||||
import gui.Canvas;
|
import gui.Canvas;
|
||||||
import src.AudioManager;
|
import src.AudioManager;
|
||||||
|
|
@ -49,6 +50,16 @@ typedef ControlsSettings = {
|
||||||
var invertYAxis:Bool;
|
var invertYAxis:Bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef TouchSettings = {
|
||||||
|
var joystickPos:Vector;
|
||||||
|
var joystickSize:Float;
|
||||||
|
var jumpButtonPos:Vector;
|
||||||
|
var jumpButtonSize:Float;
|
||||||
|
var powerupButtonPos:Vector;
|
||||||
|
var powerupButtonSize:Float;
|
||||||
|
var buttonJoystickMultiplier:Float;
|
||||||
|
}
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
public static var highScores:Map<String, Array<Score>> = [];
|
public static var highScores:Map<String, Array<Score>> = [];
|
||||||
|
|
||||||
|
|
@ -85,6 +96,15 @@ class Settings {
|
||||||
invertYAxis: false
|
invertYAxis: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static var touchSettings:TouchSettings = {
|
||||||
|
joystickPos: new Vector(100, 40),
|
||||||
|
joystickSize: 50,
|
||||||
|
jumpButtonPos: new Vector(440, 320),
|
||||||
|
jumpButtonSize: 60,
|
||||||
|
powerupButtonPos: new Vector(440, 180),
|
||||||
|
powerupButtonSize: 60,
|
||||||
|
buttonJoystickMultiplier: 2.5
|
||||||
|
}
|
||||||
public static var progression = [0, 0, 0];
|
public static var progression = [0, 0, 0];
|
||||||
public static var highscoreName = "";
|
public static var highscoreName = "";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,11 @@ class GuiControl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function guiToScreen(point:Vector) {
|
||||||
|
var rect = this.getRenderRectangle();
|
||||||
|
return rect.position.add(point);
|
||||||
|
}
|
||||||
|
|
||||||
public function addChild(ctrl:GuiControl) {
|
public function addChild(ctrl:GuiControl) {
|
||||||
this.children.push(ctrl);
|
this.children.push(ctrl);
|
||||||
ctrl.parent = this;
|
ctrl.parent = this;
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ class OptionsDlg extends GuiImage {
|
||||||
|
|
||||||
var mainPane = new GuiControl();
|
var mainPane = new GuiControl();
|
||||||
mainPane.position = new Vector(60, 15);
|
mainPane.position = new Vector(60, 15);
|
||||||
mainPane.extent = new Vector(520, 450);
|
mainPane.extent = new Vector(520, 480);
|
||||||
mainPane.horizSizing = Center;
|
mainPane.horizSizing = Center;
|
||||||
mainPane.vertSizing = Center;
|
mainPane.vertSizing = Center;
|
||||||
this.addChild(mainPane);
|
this.addChild(mainPane);
|
||||||
|
|
@ -483,6 +483,11 @@ Extensions: EAX 2.0, EAX 3.0, EAX Unified, and EAX-AC3";
|
||||||
}
|
}
|
||||||
marbleControlsPane.addChild(moveJmp);
|
marbleControlsPane.addChild(moveJmp);
|
||||||
|
|
||||||
|
var domcasual24fontdata = ResourceLoader.getFileEntry("data/font/DomCasualD.fnt");
|
||||||
|
var domcasual24b = new BitmapFont(domcasual24fontdata.entry);
|
||||||
|
@:privateAccess domcasual24b.loader = ResourceLoader.loader;
|
||||||
|
var domcasual24 = domcasual24b.toSdfFont(cast 20 * Settings.uiScale, MultiChannel);
|
||||||
|
|
||||||
var transparentbmp = new hxd.BitmapData(1, 1);
|
var transparentbmp = new hxd.BitmapData(1, 1);
|
||||||
transparentbmp.setPixel(0, 0, 0);
|
transparentbmp.setPixel(0, 0, 0);
|
||||||
var transparentTile = Tile.fromBitmap(transparentbmp);
|
var transparentTile = Tile.fromBitmap(transparentbmp);
|
||||||
|
|
@ -655,6 +660,24 @@ Extensions: EAX 2.0, EAX 3.0, EAX Unified, and EAX-AC3";
|
||||||
graphicsTabBtn.pressedAction = (sender) -> setTab("Graphics");
|
graphicsTabBtn.pressedAction = (sender) -> setTab("Graphics");
|
||||||
mainPane.addChild(graphicsTabBtn);
|
mainPane.addChild(graphicsTabBtn);
|
||||||
|
|
||||||
|
// Touch Controls buttons???
|
||||||
|
var touchControlsTxt = new GuiText(domcasual24);
|
||||||
|
touchControlsTxt.text.text = "Touch Controls:";
|
||||||
|
touchControlsTxt.text.color = new Vector(0, 0, 0);
|
||||||
|
touchControlsTxt.position = new Vector(200, 465);
|
||||||
|
touchControlsTxt.extent = new Vector(200, 40);
|
||||||
|
|
||||||
|
var touchControlsEdit = new GuiButtonText(loadButtonImages("data/ui/options/cntr_cam_dwn"), domcasual24);
|
||||||
|
touchControlsEdit.position = new Vector(300, 455);
|
||||||
|
touchControlsEdit.txtCtrl.text.text = "Edit";
|
||||||
|
touchControlsEdit.setExtent(new Vector(109, 39));
|
||||||
|
touchControlsEdit.pressedAction = (sender) -> {
|
||||||
|
MarbleGame.canvas.setContent(new TouchCtrlsEditGui());
|
||||||
|
}
|
||||||
|
|
||||||
|
mainPane.addChild(touchControlsTxt);
|
||||||
|
mainPane.addChild(touchControlsEdit);
|
||||||
|
|
||||||
setTab = function(tab:String) {
|
setTab = function(tab:String) {
|
||||||
tabs.removeChild(audioTab);
|
tabs.removeChild(audioTab);
|
||||||
tabs.removeChild(controlsTab);
|
tabs.removeChild(controlsTab);
|
||||||
|
|
|
||||||
59
src/gui/TouchCtrlsEditGui.hx
Normal file
59
src/gui/TouchCtrlsEditGui.hx
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
package gui;
|
||||||
|
|
||||||
|
import h3d.prim.Quads;
|
||||||
|
import touch.TouchEditButton;
|
||||||
|
import touch.MovementInputEdit;
|
||||||
|
import h3d.Vector;
|
||||||
|
import src.ResourceLoader;
|
||||||
|
import src.MarbleGame;
|
||||||
|
import src.Settings;
|
||||||
|
|
||||||
|
class TouchCtrlsEditGui extends GuiImage {
|
||||||
|
public function new() {
|
||||||
|
var img = ResourceLoader.getImage("data/ui/background.jpg");
|
||||||
|
super(img.resource.toTile());
|
||||||
|
this.horizSizing = Width;
|
||||||
|
this.vertSizing = Height;
|
||||||
|
this.position = new Vector();
|
||||||
|
this.extent = new Vector(640, 480);
|
||||||
|
|
||||||
|
function loadButtonImages(path:String) {
|
||||||
|
var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile();
|
||||||
|
var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile();
|
||||||
|
var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile();
|
||||||
|
return [normal, hover, pressed];
|
||||||
|
}
|
||||||
|
|
||||||
|
var mainMenuButton = new GuiButton(loadButtonImages("data/ui/options/mainm"));
|
||||||
|
mainMenuButton.position = new Vector(500, 400);
|
||||||
|
mainMenuButton.extent = new Vector(121, 53);
|
||||||
|
mainMenuButton.horizSizing = Left;
|
||||||
|
mainMenuButton.vertSizing = Top;
|
||||||
|
mainMenuButton.pressedAction = (sender) -> {
|
||||||
|
MarbleGame.canvas.setContent(new OptionsDlg());
|
||||||
|
}
|
||||||
|
|
||||||
|
var joystick = new MovementInputEdit();
|
||||||
|
|
||||||
|
var jumpBtn = new TouchEditButton(ResourceLoader.getImage("data/ui/touch/up-arrow.png").resource, Settings.touchSettings.jumpButtonPos,
|
||||||
|
Settings.touchSettings.jumpButtonSize);
|
||||||
|
|
||||||
|
var powerupBtn = new TouchEditButton(ResourceLoader.getImage("data/ui/touch/energy.png").resource, Settings.touchSettings.powerupButtonPos,
|
||||||
|
Settings.touchSettings.powerupButtonSize);
|
||||||
|
|
||||||
|
jumpBtn.onClick = (sender, mousePos) -> {
|
||||||
|
sender.setSelected(true);
|
||||||
|
powerupBtn.setSelected(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
powerupBtn.onClick = (sender, mousePos) -> {
|
||||||
|
sender.setSelected(true);
|
||||||
|
jumpBtn.setSelected(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addChild(mainMenuButton);
|
||||||
|
this.addChild(joystick);
|
||||||
|
this.addChild(jumpBtn);
|
||||||
|
this.addChild(powerupBtn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -74,7 +74,7 @@ class CameraInput {
|
||||||
#end
|
#end
|
||||||
var jumpcam = MarbleGame.instance.touchInput.jumpButton.pressed || MarbleGame.instance.touchInput.powerupButton.pressed;
|
var jumpcam = MarbleGame.instance.touchInput.jumpButton.pressed || MarbleGame.instance.touchInput.powerupButton.pressed;
|
||||||
if (jumpcam) {
|
if (jumpcam) {
|
||||||
scaleFactor /= 2.5;
|
scaleFactor /= Settings.touchSettings.buttonJoystickMultiplier;
|
||||||
}
|
}
|
||||||
MarbleGame.instance.world.marble.camera.orbit(delta.x / scaleFactor, delta.y / scaleFactor, true);
|
MarbleGame.instance.world.marble.camera.orbit(delta.x / scaleFactor, delta.y / scaleFactor, true);
|
||||||
prevMouse.x = e.relX;
|
prevMouse.x = e.relX;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,6 @@ import src.Settings;
|
||||||
|
|
||||||
class JumpButton extends TouchButton {
|
class JumpButton extends TouchButton {
|
||||||
public function new() {
|
public function new() {
|
||||||
super(ResourceLoader.getImage("data/ui/touch/up-arrow.png").resource, new Vector(440, 320), 60);
|
super(ResourceLoader.getImage("data/ui/touch/up-arrow.png").resource, Settings.touchSettings.jumpButtonPos, Settings.touchSettings.jumpButtonSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,26 +24,28 @@ class MovementInput {
|
||||||
var touchId = -1;
|
var touchId = -1;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
|
var size = Settings.touchSettings.joystickSize;
|
||||||
|
|
||||||
var g = new h2d.Graphics();
|
var g = new h2d.Graphics();
|
||||||
g.beginFill(0xffffff, 0.4);
|
g.beginFill(0xffffff, 0.4);
|
||||||
g.drawRoundedRect(0, 0, 300, 300, 50);
|
g.drawRoundedRect(0, 0, size * 6, size * 6, size);
|
||||||
g.endFill();
|
g.endFill();
|
||||||
|
|
||||||
this.area = new GuiGraphics(g);
|
this.area = new GuiGraphics(g);
|
||||||
this.area.position = new Vector(100, 40);
|
this.area.position = Settings.touchSettings.joystickPos;
|
||||||
this.area.extent = new Vector(300, 300);
|
this.area.extent = new Vector(size * 6, size * 6);
|
||||||
this.area.vertSizing = Top;
|
this.area.vertSizing = Top;
|
||||||
|
|
||||||
this.collider = new h2d.Interactive(300, 300, g, h2d.col.Bounds.fromValues(0, 0, 300, 300));
|
this.collider = new h2d.Interactive(size * 6, size * 6, g, h2d.col.Bounds.fromValues(0, 0, size * 6, size * 6));
|
||||||
|
|
||||||
var g2 = new h2d.Graphics();
|
var g2 = new h2d.Graphics();
|
||||||
g2.beginFill(0xffffff, 0.7);
|
g2.beginFill(0xffffff, 0.7);
|
||||||
g2.drawCircle(0, 0, 50);
|
g2.drawCircle(0, 0, size);
|
||||||
g2.endFill();
|
g2.endFill();
|
||||||
|
|
||||||
this.joystick = new GuiGraphics(g2);
|
this.joystick = new GuiGraphics(g2);
|
||||||
this.joystick.position = new Vector(150, 150);
|
this.joystick.position = new Vector(size * 3, size * 3);
|
||||||
this.joystick.extent = new Vector(50, 50);
|
this.joystick.extent = new Vector(size, size);
|
||||||
|
|
||||||
this.area.addChild(this.joystick);
|
this.area.addChild(this.joystick);
|
||||||
|
|
||||||
|
|
@ -72,11 +74,11 @@ class MovementInput {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (emove.kind == EMove) {
|
if (emove.kind == EMove) {
|
||||||
var xPos = Util.clamp(emove.relX, 50, 250);
|
var xPos = Util.clamp(emove.relX, size, size * 5);
|
||||||
var yPos = Util.clamp(emove.relY, 50, 250);
|
var yPos = Util.clamp(emove.relY, size, size * 5);
|
||||||
|
|
||||||
this.value.x = (xPos - 150) / 100;
|
this.value.x = (xPos - (size * 3)) / (size * 2);
|
||||||
this.value.y = (yPos - 150) / 100;
|
this.value.y = (yPos - (size * 3)) / (size * 2);
|
||||||
|
|
||||||
this.joystick.graphics.setPosition(this.area.graphics.x + xPos, this.area.graphics.y + yPos);
|
this.joystick.graphics.setPosition(this.area.graphics.x + xPos, this.area.graphics.y + yPos);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
src/touch/MovementInputEdit.hx
Normal file
35
src/touch/MovementInputEdit.hx
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
package touch;
|
||||||
|
|
||||||
|
import h3d.Vector;
|
||||||
|
import src.Settings;
|
||||||
|
import gui.GuiGraphics;
|
||||||
|
|
||||||
|
class MovementInputEdit extends GuiGraphics {
|
||||||
|
public function new() {
|
||||||
|
var size = Settings.touchSettings.joystickSize;
|
||||||
|
|
||||||
|
var g = new h2d.Graphics();
|
||||||
|
g.beginFill(0xffffff, 0.4);
|
||||||
|
g.drawRoundedRect(0, 0, size * 6, size * 6, size);
|
||||||
|
g.endFill();
|
||||||
|
|
||||||
|
super(g);
|
||||||
|
|
||||||
|
this.position = Settings.touchSettings.joystickPos;
|
||||||
|
this.extent = new Vector(size * 6, size * 6);
|
||||||
|
this.vertSizing = Top;
|
||||||
|
|
||||||
|
var collider = new h2d.Interactive(size * 6, size * 6, g, h2d.col.Bounds.fromValues(0, 0, size * 6, size * 6));
|
||||||
|
|
||||||
|
var g2 = new h2d.Graphics();
|
||||||
|
g2.beginFill(0xffffff, 0.7);
|
||||||
|
g2.drawCircle(0, 0, size);
|
||||||
|
g2.endFill();
|
||||||
|
|
||||||
|
var joystick = new GuiGraphics(g2);
|
||||||
|
joystick.position = new Vector(size * 3, size * 3);
|
||||||
|
joystick.extent = new Vector(size, size);
|
||||||
|
|
||||||
|
this.addChild(joystick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ import src.Settings;
|
||||||
|
|
||||||
class PowerupButton extends TouchButton {
|
class PowerupButton extends TouchButton {
|
||||||
public function new() {
|
public function new() {
|
||||||
super(ResourceLoader.getImage("data/ui/touch/energy.png").resource, new Vector(440, 180), 60);
|
super(ResourceLoader.getImage("data/ui/touch/energy.png").resource, Settings.touchSettings.powerupButtonPos, Settings.touchSettings.powerupButtonSize);
|
||||||
this.setEnabled(false);
|
this.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,10 @@ import hxd.res.Image;
|
||||||
import src.MarbleGame;
|
import src.MarbleGame;
|
||||||
|
|
||||||
class TouchButton {
|
class TouchButton {
|
||||||
public var img:Image;
|
|
||||||
|
|
||||||
public var guiElement:GuiGraphics;
|
public var guiElement:GuiGraphics;
|
||||||
|
|
||||||
public var position:Vector;
|
|
||||||
|
|
||||||
public var radius:Float;
|
public var radius:Float;
|
||||||
|
|
||||||
var doing = false;
|
|
||||||
|
|
||||||
var added = false;
|
var added = false;
|
||||||
|
|
||||||
public var pressed = false;
|
public var pressed = false;
|
||||||
|
|
|
||||||
74
src/touch/TouchEditButton.hx
Normal file
74
src/touch/TouchEditButton.hx
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
package touch;
|
||||||
|
|
||||||
|
import gui.GuiControl.MouseState;
|
||||||
|
import gui.GuiGraphics;
|
||||||
|
import h3d.Vector;
|
||||||
|
import hxd.res.Image;
|
||||||
|
|
||||||
|
class TouchEditButton extends GuiGraphics {
|
||||||
|
public var radius:Float;
|
||||||
|
|
||||||
|
public var selected = false;
|
||||||
|
|
||||||
|
public var onClick:(TouchEditButton, MouseState) -> Void;
|
||||||
|
|
||||||
|
var imgTile:h2d.Tile;
|
||||||
|
|
||||||
|
public function new(img:Image, position:Vector, radius:Float) {
|
||||||
|
this.imgTile = img.toTile();
|
||||||
|
|
||||||
|
var iconScale = 1.5;
|
||||||
|
|
||||||
|
var g = new h2d.Graphics();
|
||||||
|
g.beginFill(0xffffff);
|
||||||
|
g.drawCircle(0, 0, radius);
|
||||||
|
g.beginTileFill(-(imgTile.width * iconScale * radius / imgTile.width) / 2, -(imgTile.height * iconScale * radius / imgTile.width) / 2,
|
||||||
|
iconScale * radius / imgTile.width, iconScale * radius / imgTile.height, imgTile);
|
||||||
|
g.drawRect(-(imgTile.width * iconScale * radius / imgTile.width) / 2, -(imgTile.height * iconScale * radius / imgTile.width / 2),
|
||||||
|
(imgTile.width * iconScale * radius / imgTile.width), (imgTile.height * iconScale * radius / imgTile.width));
|
||||||
|
g.endFill();
|
||||||
|
|
||||||
|
super(g);
|
||||||
|
|
||||||
|
this.position = position;
|
||||||
|
this.extent = new Vector(2 * radius, 2 * radius);
|
||||||
|
this.horizSizing = Left;
|
||||||
|
this.vertSizing = Top;
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override function getHitTestRect() {
|
||||||
|
var thisRect = this.getRenderRectangle();
|
||||||
|
thisRect.position = thisRect.position.sub(new Vector(radius, radius));
|
||||||
|
if (this.parent == null)
|
||||||
|
return thisRect;
|
||||||
|
else {
|
||||||
|
return thisRect.intersect(this.parent.getRenderRectangle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override function onMousePress(mouseState:MouseState) {
|
||||||
|
super.onMousePress(mouseState);
|
||||||
|
onClick(this, mouseState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSelected(selected:Bool) {
|
||||||
|
if (selected) {
|
||||||
|
this.graphics.beginFill(0xffffff);
|
||||||
|
this.graphics.drawPieInner(0, 0, radius + 8, radius + 5, 0, 2 * Math.PI);
|
||||||
|
this.graphics.endFill();
|
||||||
|
} else {
|
||||||
|
this.graphics.clear();
|
||||||
|
|
||||||
|
var iconScale = 1.5;
|
||||||
|
|
||||||
|
this.graphics.beginFill(0xffffff);
|
||||||
|
this.graphics.drawCircle(0, 0, radius);
|
||||||
|
this.graphics.beginTileFill(-(imgTile.width * iconScale * radius / imgTile.width) / 2, -(imgTile.height * iconScale * radius / imgTile.width) / 2,
|
||||||
|
iconScale * radius / imgTile.width, iconScale * radius / imgTile.height, imgTile);
|
||||||
|
this.graphics.drawRect(-(imgTile.width * iconScale * radius / imgTile.width) / 2, -(imgTile.height * iconScale * radius / imgTile.width / 2),
|
||||||
|
(imgTile.width * iconScale * radius / imgTile.width), (imgTile.height * iconScale * radius / imgTile.width));
|
||||||
|
this.graphics.endFill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue