mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-25 09:22:52 +00:00
finish touch controls or something
This commit is contained in:
parent
9b3a2b11ec
commit
0e2e18a3ac
6 changed files with 232 additions and 16 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -6,4 +6,5 @@ native
|
|||
*.exe
|
||||
*.obj
|
||||
settings.json
|
||||
release
|
||||
release
|
||||
Export
|
||||
|
|
@ -146,6 +146,7 @@ class Settings {
|
|||
var outputData:Dynamic = {
|
||||
options: optionsSettings,
|
||||
controls: controlsSettings,
|
||||
touch: touchSettings,
|
||||
progression: progression,
|
||||
highscoreName: highscoreName
|
||||
};
|
||||
|
|
@ -205,6 +206,8 @@ class Settings {
|
|||
if (optionsSettings.fov == 0 #if js || optionsSettings.fov == null #end)
|
||||
optionsSettings.fov = 60;
|
||||
controlsSettings = json.controls;
|
||||
if (json.touch != null)
|
||||
touchSettings = json.touch;
|
||||
progression = json.progression;
|
||||
highscoreName = json.highscoreName;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -661,23 +661,25 @@ Extensions: EAX 2.0, EAX 3.0, EAX Unified, and EAX-AC3";
|
|||
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);
|
||||
if (Util.isTouchDevice()) {
|
||||
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());
|
||||
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);
|
||||
}
|
||||
|
||||
mainPane.addChild(touchControlsTxt);
|
||||
mainPane.addChild(touchControlsEdit);
|
||||
|
||||
setTab = function(tab:String) {
|
||||
tabs.removeChild(audioTab);
|
||||
tabs.removeChild(controlsTab);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package gui;
|
||||
|
||||
import hxd.res.BitmapFont;
|
||||
import h3d.prim.Quads;
|
||||
import touch.TouchEditButton;
|
||||
import touch.MovementInputEdit;
|
||||
|
|
@ -24,6 +25,11 @@ class TouchCtrlsEditGui extends GuiImage {
|
|||
return [normal, hover, pressed];
|
||||
}
|
||||
|
||||
var domcasual32fontdata = ResourceLoader.getFileEntry("data/font/DomCasualD.fnt");
|
||||
var domcasual32b = new BitmapFont(domcasual32fontdata.entry);
|
||||
@:privateAccess domcasual32b.loader = ResourceLoader.loader;
|
||||
var domcasual32 = domcasual32b.toSdfFont(cast 26 * Settings.uiScale, MultiChannel);
|
||||
|
||||
var mainMenuButton = new GuiButton(loadButtonImages("data/ui/options/mainm"));
|
||||
mainMenuButton.position = new Vector(500, 400);
|
||||
mainMenuButton.extent = new Vector(121, 53);
|
||||
|
|
@ -33,6 +39,14 @@ class TouchCtrlsEditGui extends GuiImage {
|
|||
MarbleGame.canvas.setContent(new OptionsDlg());
|
||||
}
|
||||
|
||||
var touchControlsTxt = new GuiText(domcasual32);
|
||||
touchControlsTxt.position = new Vector(350, 415);
|
||||
touchControlsTxt.extent = new Vector(121, 53);
|
||||
touchControlsTxt.text.text = "Edit Touch Controls";
|
||||
touchControlsTxt.horizSizing = Center;
|
||||
touchControlsTxt.vertSizing = Top;
|
||||
touchControlsTxt.text.textColor = 0;
|
||||
|
||||
var joystick = new MovementInputEdit();
|
||||
|
||||
var jumpBtn = new TouchEditButton(ResourceLoader.getImage("data/ui/touch/up-arrow.png").resource, Settings.touchSettings.jumpButtonPos,
|
||||
|
|
@ -44,14 +58,38 @@ class TouchCtrlsEditGui extends GuiImage {
|
|||
jumpBtn.onClick = (sender, mousePos) -> {
|
||||
sender.setSelected(true);
|
||||
powerupBtn.setSelected(false);
|
||||
joystick.setSelected(false);
|
||||
}
|
||||
|
||||
jumpBtn.onChangeCb = (sender, value, rvalue) -> {
|
||||
Settings.touchSettings.jumpButtonPos = value;
|
||||
Settings.touchSettings.jumpButtonSize = rvalue;
|
||||
}
|
||||
|
||||
powerupBtn.onClick = (sender, mousePos) -> {
|
||||
sender.setSelected(true);
|
||||
jumpBtn.setSelected(false);
|
||||
joystick.setSelected(false);
|
||||
}
|
||||
|
||||
powerupBtn.onChangeCb = (sender, value, rvalue) -> {
|
||||
Settings.touchSettings.powerupButtonPos = value;
|
||||
Settings.touchSettings.powerupButtonSize = rvalue;
|
||||
}
|
||||
|
||||
joystick.onClick = (mousePos) -> {
|
||||
joystick.setSelected(true);
|
||||
jumpBtn.setSelected(false);
|
||||
powerupBtn.setSelected(false);
|
||||
}
|
||||
|
||||
joystick.onChangeCb = (value, rvalue) -> {
|
||||
Settings.touchSettings.joystickPos = value;
|
||||
Settings.touchSettings.joystickSize = rvalue;
|
||||
}
|
||||
|
||||
this.addChild(mainMenuButton);
|
||||
this.addChild(touchControlsTxt);
|
||||
this.addChild(joystick);
|
||||
this.addChild(jumpBtn);
|
||||
this.addChild(powerupBtn);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,29 @@
|
|||
package touch;
|
||||
|
||||
import src.Util;
|
||||
import gui.GuiControl.MouseState;
|
||||
import h3d.Vector;
|
||||
import src.Settings;
|
||||
import gui.GuiGraphics;
|
||||
|
||||
class MovementInputEdit extends GuiGraphics {
|
||||
public var selected = false;
|
||||
|
||||
public var onClick:(MouseState) -> Void;
|
||||
|
||||
public var onChangeCb:(Vector, Float) -> Void;
|
||||
|
||||
var mousePos:Vector;
|
||||
|
||||
var size:Float;
|
||||
|
||||
var state = 0;
|
||||
|
||||
public function new() {
|
||||
var size = Settings.touchSettings.joystickSize;
|
||||
|
||||
this.size = size;
|
||||
|
||||
var g = new h2d.Graphics();
|
||||
g.beginFill(0xffffff, 0.4);
|
||||
g.drawRoundedRect(0, 0, size * 6, size * 6, size);
|
||||
|
|
@ -32,4 +48,107 @@ class MovementInputEdit extends GuiGraphics {
|
|||
|
||||
this.addChild(joystick);
|
||||
}
|
||||
|
||||
public override function onMousePress(mouseState:MouseState) {
|
||||
onClick(mouseState);
|
||||
this.mousePos = mouseState.position;
|
||||
|
||||
var renderRect = getHitTestRect();
|
||||
var knobPos = new Vector(renderRect.position.x + renderRect.extent.x / 2, renderRect.position.y + 15);
|
||||
if (mouseState.position.sub(knobPos).length() < 15) {
|
||||
state = 2;
|
||||
} else {
|
||||
state = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public override function onMouseDown(mouseState:MouseState) {
|
||||
if (selected) {
|
||||
var deltaPos = mouseState.position.sub(this.mousePos);
|
||||
this.mousePos = mouseState.position;
|
||||
|
||||
if (state == 1) {
|
||||
this.graphics.setPosition(this.graphics.x + deltaPos.x, this.graphics.y + deltaPos.y);
|
||||
this.position = this.position.add(deltaPos);
|
||||
|
||||
var joy:GuiGraphics = cast this.children[0];
|
||||
joy.graphics.setPosition(joy.graphics.x + deltaPos.x, joy.graphics.y + deltaPos.y);
|
||||
|
||||
onChangeCb(this.position, this.size);
|
||||
}
|
||||
if (state == 2) {
|
||||
var renderRect = getHitTestRect();
|
||||
|
||||
var knobPos = new Vector(renderRect.position.x + renderRect.extent.x / 2, renderRect.position.y + 15);
|
||||
|
||||
var newSize = Util.clamp(Math.abs(mouseState.position.y - (renderRect.position.y + renderRect.extent.y / 2)) / 3, 30,
|
||||
70); // Full size is size * 6
|
||||
var newPos = new Vector(knobPos.x - newSize * 3, mouseState.position.y);
|
||||
|
||||
var deltaPos = new Vector(renderRect.position.x + 15 + 6.5 - newPos.x, renderRect.position.y + 15 + 6.5 - newPos.y);
|
||||
|
||||
this.size = newSize;
|
||||
this.extent = new Vector(size * 6, size * 6);
|
||||
this.position = this.position.sub(deltaPos);
|
||||
this.graphics.setPosition(this.graphics.x - deltaPos.x, this.graphics.y - deltaPos.y);
|
||||
|
||||
var joystick:GuiGraphics = cast this.children[0];
|
||||
joystick.position = new Vector(size * 3, size * 3);
|
||||
joystick.extent = new Vector(size, size);
|
||||
joystick.graphics.setPosition(this.graphics.x + size * 3, this.graphics.y + size * 3);
|
||||
|
||||
// Redraw lmao
|
||||
this.setSelected(false);
|
||||
this.setSelected(true);
|
||||
// Redraw the joystick
|
||||
joystick.graphics.clear();
|
||||
joystick.graphics.beginFill(0xffffff, 0.7);
|
||||
joystick.graphics.drawCircle(0, 0, size);
|
||||
joystick.graphics.endFill();
|
||||
|
||||
onChangeCb(this.position, this.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override function onMouseRelease(mouseState:MouseState) {
|
||||
state = 0;
|
||||
}
|
||||
|
||||
public override function getHitTestRect() {
|
||||
var thisRect = this.getRenderRectangle();
|
||||
|
||||
if (selected) {
|
||||
thisRect.position = thisRect.position.add(new Vector(-15 - 6.5, -15 - 6.5));
|
||||
thisRect.extent = thisRect.extent.add(new Vector(30 + 13, 30 + 13));
|
||||
}
|
||||
|
||||
if (this.parent == null)
|
||||
return thisRect;
|
||||
else {
|
||||
return thisRect.intersect(this.parent.getRenderRectangle());
|
||||
}
|
||||
}
|
||||
|
||||
public function setSelected(selected:Bool) {
|
||||
this.selected = selected;
|
||||
if (selected) {
|
||||
this.graphics.lineStyle(3, 0xFFFFFF);
|
||||
this.graphics.moveTo(-6.5, -6.5);
|
||||
this.graphics.lineTo(size * 6 + 6.5, -6.5);
|
||||
this.graphics.lineTo(size * 6 + 6.5, size * 6 + 6.5);
|
||||
this.graphics.lineTo(-6.5, size * 6 + 6.5);
|
||||
this.graphics.lineTo(-6.5, -6.5);
|
||||
|
||||
this.graphics.beginFill(0x8B8B8B);
|
||||
this.graphics.lineStyle(0, 0xFFFFFF);
|
||||
this.graphics.drawCircle(size * 3, -6.5, 15);
|
||||
this.graphics.endFill();
|
||||
} else {
|
||||
this.graphics.clear();
|
||||
this.graphics.beginFill(0xffffff, 0.4);
|
||||
this.graphics.drawRoundedRect(0, 0, size * 6, size * 6, size);
|
||||
this.graphics.endFill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package touch;
|
||||
|
||||
import src.Util;
|
||||
import gui.GuiControl.MouseState;
|
||||
import gui.GuiGraphics;
|
||||
import h3d.Vector;
|
||||
|
|
@ -12,8 +13,14 @@ class TouchEditButton extends GuiGraphics {
|
|||
|
||||
public var onClick:(TouchEditButton, MouseState) -> Void;
|
||||
|
||||
public var onChangeCb:(TouchEditButton, Vector, Float) -> Void;
|
||||
|
||||
var imgTile:h2d.Tile;
|
||||
|
||||
var mousePos:Vector;
|
||||
|
||||
var state = 0;
|
||||
|
||||
public function new(img:Image, position:Vector, radius:Float) {
|
||||
this.imgTile = img.toTile();
|
||||
|
||||
|
|
@ -40,6 +47,12 @@ class TouchEditButton extends GuiGraphics {
|
|||
public override function getHitTestRect() {
|
||||
var thisRect = this.getRenderRectangle();
|
||||
thisRect.position = thisRect.position.sub(new Vector(radius, radius));
|
||||
|
||||
if (selected) {
|
||||
thisRect.position = thisRect.position.add(new Vector(-15 - 6.5, -15 - 6.5));
|
||||
thisRect.extent = thisRect.extent.add(new Vector(30 + 13, 30 + 13));
|
||||
}
|
||||
|
||||
if (this.parent == null)
|
||||
return thisRect;
|
||||
else {
|
||||
|
|
@ -48,15 +61,55 @@ class TouchEditButton extends GuiGraphics {
|
|||
}
|
||||
|
||||
public override function onMousePress(mouseState:MouseState) {
|
||||
super.onMousePress(mouseState);
|
||||
onClick(this, mouseState);
|
||||
this.mousePos = mouseState.position;
|
||||
|
||||
var renderRect = getHitTestRect();
|
||||
var knobPos = new Vector(renderRect.position.x + renderRect.extent.x / 2, renderRect.position.y + 15);
|
||||
if (mouseState.position.sub(knobPos).length() < 15) {
|
||||
state = 1;
|
||||
} else {
|
||||
state = 2;
|
||||
}
|
||||
}
|
||||
|
||||
public override function onMouseDown(mouseState:MouseState) {
|
||||
if (selected) {
|
||||
var deltaPos = mouseState.position.sub(this.mousePos);
|
||||
this.mousePos = mouseState.position;
|
||||
|
||||
if (state == 1) {
|
||||
var renderRect = getHitTestRect();
|
||||
var newRadius = Util.clamp(mouseState.position.sub(renderRect.position.add(renderRect.extent.multiply(0.5))).length(), 30, 80);
|
||||
this.radius = newRadius;
|
||||
this.extent = new Vector(2 * newRadius, 2 * newRadius);
|
||||
|
||||
// Redraw lmao
|
||||
this.setSelected(false);
|
||||
this.setSelected(true);
|
||||
onChangeCb(this, this.position, this.radius);
|
||||
}
|
||||
if (state == 2) {
|
||||
this.graphics.setPosition(this.graphics.x + deltaPos.x, this.graphics.y + deltaPos.y);
|
||||
this.position = this.position.add(deltaPos);
|
||||
onChangeCb(this, this.position, this.radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override function onMouseRelease(mouseState:MouseState) {
|
||||
state = 0;
|
||||
}
|
||||
|
||||
public function setSelected(selected:Bool) {
|
||||
this.selected = selected;
|
||||
if (selected) {
|
||||
this.graphics.beginFill(0xffffff);
|
||||
this.graphics.drawPieInner(0, 0, radius + 8, radius + 5, 0, 2 * Math.PI);
|
||||
this.graphics.endFill();
|
||||
this.graphics.beginFill(0x8B8B8B);
|
||||
this.graphics.drawCircle(0, -radius - 6.5, 15);
|
||||
this.graphics.endFill();
|
||||
} else {
|
||||
this.graphics.clear();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue