diff --git a/src/Settings.hx b/src/Settings.hx index 396ae897..572fcff1 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -1,5 +1,6 @@ package src; +import h3d.Vector; import haxe.ds.Option; import gui.Canvas; import src.AudioManager; @@ -49,6 +50,16 @@ typedef ControlsSettings = { 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 { public static var highScores:Map> = []; @@ -85,6 +96,15 @@ class Settings { 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 highscoreName = ""; diff --git a/src/gui/GuiControl.hx b/src/gui/GuiControl.hx index d1b42f29..c8404370 100644 --- a/src/gui/GuiControl.hx +++ b/src/gui/GuiControl.hx @@ -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) { this.children.push(ctrl); ctrl.parent = this; diff --git a/src/gui/OptionsDlg.hx b/src/gui/OptionsDlg.hx index 3c199660..ffd8b45c 100644 --- a/src/gui/OptionsDlg.hx +++ b/src/gui/OptionsDlg.hx @@ -70,7 +70,7 @@ class OptionsDlg extends GuiImage { var mainPane = new GuiControl(); mainPane.position = new Vector(60, 15); - mainPane.extent = new Vector(520, 450); + mainPane.extent = new Vector(520, 480); mainPane.horizSizing = Center; mainPane.vertSizing = Center; this.addChild(mainPane); @@ -483,6 +483,11 @@ Extensions: EAX 2.0, EAX 3.0, EAX Unified, and EAX-AC3"; } 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); transparentbmp.setPixel(0, 0, 0); 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"); 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) { tabs.removeChild(audioTab); tabs.removeChild(controlsTab); diff --git a/src/gui/TouchCtrlsEditGui.hx b/src/gui/TouchCtrlsEditGui.hx new file mode 100644 index 00000000..0ab4aeed --- /dev/null +++ b/src/gui/TouchCtrlsEditGui.hx @@ -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); + } +} diff --git a/src/touch/CameraInput.hx b/src/touch/CameraInput.hx index da72129d..b8ee940e 100644 --- a/src/touch/CameraInput.hx +++ b/src/touch/CameraInput.hx @@ -74,7 +74,7 @@ class CameraInput { #end var jumpcam = MarbleGame.instance.touchInput.jumpButton.pressed || MarbleGame.instance.touchInput.powerupButton.pressed; if (jumpcam) { - scaleFactor /= 2.5; + scaleFactor /= Settings.touchSettings.buttonJoystickMultiplier; } MarbleGame.instance.world.marble.camera.orbit(delta.x / scaleFactor, delta.y / scaleFactor, true); prevMouse.x = e.relX; diff --git a/src/touch/JumpButton.hx b/src/touch/JumpButton.hx index 5586fba7..bd1c362c 100644 --- a/src/touch/JumpButton.hx +++ b/src/touch/JumpButton.hx @@ -8,6 +8,6 @@ import src.Settings; class JumpButton extends TouchButton { 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); } } diff --git a/src/touch/MovementInput.hx b/src/touch/MovementInput.hx index 6583868a..450ac408 100644 --- a/src/touch/MovementInput.hx +++ b/src/touch/MovementInput.hx @@ -24,26 +24,28 @@ class MovementInput { var touchId = -1; public function new() { + var size = Settings.touchSettings.joystickSize; + var g = new h2d.Graphics(); g.beginFill(0xffffff, 0.4); - g.drawRoundedRect(0, 0, 300, 300, 50); + g.drawRoundedRect(0, 0, size * 6, size * 6, size); g.endFill(); this.area = new GuiGraphics(g); - this.area.position = new Vector(100, 40); - this.area.extent = new Vector(300, 300); + this.area.position = Settings.touchSettings.joystickPos; + this.area.extent = new Vector(size * 6, size * 6); 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(); g2.beginFill(0xffffff, 0.7); - g2.drawCircle(0, 0, 50); + g2.drawCircle(0, 0, size); g2.endFill(); this.joystick = new GuiGraphics(g2); - this.joystick.position = new Vector(150, 150); - this.joystick.extent = new Vector(50, 50); + this.joystick.position = new Vector(size * 3, size * 3); + this.joystick.extent = new Vector(size, size); this.area.addChild(this.joystick); @@ -72,11 +74,11 @@ class MovementInput { return; } if (emove.kind == EMove) { - var xPos = Util.clamp(emove.relX, 50, 250); - var yPos = Util.clamp(emove.relY, 50, 250); + var xPos = Util.clamp(emove.relX, size, size * 5); + var yPos = Util.clamp(emove.relY, size, size * 5); - this.value.x = (xPos - 150) / 100; - this.value.y = (yPos - 150) / 100; + this.value.x = (xPos - (size * 3)) / (size * 2); + this.value.y = (yPos - (size * 3)) / (size * 2); this.joystick.graphics.setPosition(this.area.graphics.x + xPos, this.area.graphics.y + yPos); } diff --git a/src/touch/MovementInputEdit.hx b/src/touch/MovementInputEdit.hx new file mode 100644 index 00000000..6336b670 --- /dev/null +++ b/src/touch/MovementInputEdit.hx @@ -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); + } +} diff --git a/src/touch/PowerupButton.hx b/src/touch/PowerupButton.hx index 4ec6c08b..f08ac011 100644 --- a/src/touch/PowerupButton.hx +++ b/src/touch/PowerupButton.hx @@ -8,7 +8,7 @@ import src.Settings; class PowerupButton extends TouchButton { 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); } } diff --git a/src/touch/TouchButton.hx b/src/touch/TouchButton.hx index 2c59ac62..a9b3af5d 100644 --- a/src/touch/TouchButton.hx +++ b/src/touch/TouchButton.hx @@ -10,16 +10,10 @@ import hxd.res.Image; import src.MarbleGame; class TouchButton { - public var img:Image; - public var guiElement:GuiGraphics; - public var position:Vector; - public var radius:Float; - var doing = false; - var added = false; public var pressed = false; diff --git a/src/touch/TouchEditButton.hx b/src/touch/TouchEditButton.hx new file mode 100644 index 00000000..080ce057 --- /dev/null +++ b/src/touch/TouchEditButton.hx @@ -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(); + } + } +}