PIXI Controls: Debug enable button

This commit is contained in:
OleSTEEP 2024-02-01 14:35:38 +03:00
parent 03775afea1
commit b5d5cc6c89
3 changed files with 42 additions and 0 deletions

View file

@ -25,6 +25,7 @@ ONSControls.createCanvas = function() {
transparent: true
});
document.body.appendChild(canvas.view);
canvas.view.id = "ControlsCanvas";
canvas.view.style.zIndex = this.options.zIndex;
canvas.view.style.position = "absolute";
canvas.view.style.left = 0;
@ -150,6 +151,19 @@ ONSControls.sendEvent = function(event, button) {
const key = VirtualGamepad.keys.find((element) => element.name == button);
VirtualGamepad.gamepad.buttons[key.code].pressed = event.type == "pointerdown" ? true : false
}
//=============================================================================
// * Fix controls size on empty screen
//=============================================================================
document.addEventListener("deviceready", onCordovaDeviceReady, false);
ONSControls.onCordovaDeviceReady = function () {
console.log("ONSControls - SETUP!!!"); //Remove in release
document.addEventListener("resume", onCordovaResume, false);
};
ONSControls.onCordovaResume = function () {
// TODO: HERE CONTROLS WILL BE UPDATED OR RECREATED
};

View file

@ -51,6 +51,15 @@
z-index: 1489;
}
.new-button {
position: absolute;
right: 5px;
top: 5px;
width: 90px;
height: 40px;
z-index: 1489;
}
.gamepad-buttons {
opacity: 0.6;
z-index: 1488;

View file

@ -66,6 +66,24 @@ function create_fps_button() {
}
}
function create_new_controls() {
// Remove in release
const NewBtn = document.createElement("div");
NewBtn.className = "new-button";
document.body.appendChild(NewBtn);
NewBtn.addEventListener("pointerdown", () => {
var controls_canvas = document.getElementById("ControlsCanvas");
if (controls_canvas === null) {
document.getElementById("show-gamepad").remove();
ONSControls.initialize();
} else {
controls_canvas.remove();
create_show_button();
}
});
}
function create_dpad_buttons() {
// Скуфting elements
const DivDMain = document.createElement("div");
@ -283,6 +301,7 @@ function setupKey(id, key, keyCode) {
window.addEventListener('load', () => {
create_fps_button(); // Remove in release
create_new_controls(); // Remove in release
if (navigator.getGamepads().length == 0) {
create_control_buttons();
create_dpad_buttons();