PIXI Controls: Save custom button position
This commit is contained in:
parent
18e9ef4914
commit
ff890a2894
1 changed files with 48 additions and 21 deletions
|
@ -349,7 +349,10 @@ ONSControls.setupDragNDrop = function(element) {
|
|||
ONSControls._controlsCanvas.stage.on("pointermove", onMove);
|
||||
}
|
||||
var onMove = function(event) {
|
||||
if (element) {element.parent.toLocal(event.data.global, null, element.position);};
|
||||
if (element) {
|
||||
element.parent.toLocal(event.data.global, null, element.position);
|
||||
ConfigManager.ONSConfig.customPos = true;
|
||||
};
|
||||
}
|
||||
var onEnd = function(event) {
|
||||
if (element) {
|
||||
|
@ -377,6 +380,21 @@ ONSControls.replaceBackEvent = function() {
|
|||
});
|
||||
}
|
||||
//=============================================================================
|
||||
// * Save buttons position to config
|
||||
//=============================================================================
|
||||
ONSControls.saveButtonsPosition = function() {
|
||||
ConfigManager.ONSConfig.buttonsX = this._buttonsContainer.x;
|
||||
ConfigManager.ONSConfig.buttonsY = this._buttonsContainer.y;
|
||||
ConfigManager.ONSConfig.dPadX = this._dPadContainer.x;
|
||||
ConfigManager.ONSConfig.dPadY = this._dPadContainer.y;
|
||||
ConfigManager.ONSConfig.LBX = this._LBsprite.x;
|
||||
ConfigManager.ONSConfig.LBY = this._LBsprite.y;
|
||||
ConfigManager.ONSConfig.RBX = this._RBsprite.x;
|
||||
ConfigManager.ONSConfig.RBY = this._RBsprite.y;
|
||||
ConfigManager.ONSConfig.showX = this._showButton.x;
|
||||
ConfigManager.ONSConfig.showY = this._showButton.y;
|
||||
}
|
||||
//=============================================================================
|
||||
// * Open Edit Mode
|
||||
//=============================================================================
|
||||
ONSControls.openEditMode = function() {
|
||||
|
@ -401,6 +419,7 @@ ONSControls.closeEditMode = function() {
|
|||
Graphics._canvas.hidden = false;
|
||||
this.clearInteractive();
|
||||
this.setupInteractive();
|
||||
this.saveButtonsPosition();
|
||||
}
|
||||
|
||||
|
||||
|
@ -512,6 +531,7 @@ ONSControls.configManager = function() {
|
|||
// * Class Variables
|
||||
//=============================================================================
|
||||
ConfigManager.ONSConfig ||= {};
|
||||
ConfigManager.ONSConfig.customPos ||= false;
|
||||
ConfigManager.ONSConfig.buttonsScale ||= this.options.buttonsScale;
|
||||
ConfigManager.ONSConfig.buttonsOpacity ||= this.options.buttonsOpacity;
|
||||
ConfigManager.ONSConfig.safeArea ||= ONSControls._controlsCanvas.vh(0.032);
|
||||
|
@ -543,6 +563,7 @@ ConfigManager.restoreDefaultConfig = function () {
|
|||
var base = path.dirname(process.mainModule.filename);
|
||||
base = path.join(base, 'save/');
|
||||
if (fs.existsSync(base + "config.rpgsave")) { fs.unlinkSync(base + "config.rpgsave"); }
|
||||
this.ONSConfig.customPos = false;
|
||||
this.ONSConfig.buttonsScale = ONSControls.options.buttonsScale;
|
||||
this.ONSConfig.buttonsOpacity = ONSControls.options.buttonsOpacity;
|
||||
this.ONSConfig.safeArea = ONSControls._controlsCanvas.vh(0.032);
|
||||
|
@ -574,26 +595,30 @@ ConfigManager.restoreDefaultConfig = function () {
|
|||
// * Update all controls data
|
||||
//=============================================================================
|
||||
ConfigManager.ONSConfig.updateData = function() {
|
||||
ConfigManager.ONSConfig.buttonsScale = ConfigManager.ONSConfig.buttonsScale;
|
||||
ConfigManager.ONSConfig.buttonsOpacity = ConfigManager.ONSConfig.buttonsOpacity;
|
||||
ConfigManager.ONSConfig.safeArea = ConfigManager.ONSConfig.safeArea;
|
||||
ConfigManager.ONSConfig.buttonsSize = ONSControls._controlsCanvas.vh(0.18) * ConfigManager.ONSConfig.buttonsScale;
|
||||
ConfigManager.ONSConfig.buttonsX = ONSControls._controlsCanvas.screen.width - (ConfigManager.ONSConfig.buttonsSize + ConfigManager.ONSConfig.safeArea);;
|
||||
ConfigManager.ONSConfig.buttonsY = ONSControls._controlsCanvas.screen.height - (ConfigManager.ONSConfig.buttonsSize + ConfigManager.ONSConfig.safeArea);
|
||||
ConfigManager.ONSConfig.dPadSize = ONSControls._controlsCanvas.vh(0.36) * ConfigManager.ONSConfig.buttonsScale;
|
||||
ConfigManager.ONSConfig.dPadX = ConfigManager.ONSConfig.dPadSize / 2 + ConfigManager.ONSConfig.safeArea;
|
||||
ConfigManager.ONSConfig.dPadY = ONSControls._controlsCanvas.screen.height - (ConfigManager.ONSConfig.dPadSize / 2 + ConfigManager.ONSConfig.safeArea);
|
||||
ConfigManager.ONSConfig.bumpersOffsetX = ConfigManager.ONSConfig.bumpersOffsetX;
|
||||
ConfigManager.ONSConfig.bumpersOffsetY = ConfigManager.ONSConfig.bumpersOffsetY;
|
||||
ConfigManager.ONSConfig.bumpersWidth = ONSControls._controlsCanvas.vh(0.188) * ConfigManager.ONSConfig.buttonsScale;
|
||||
ConfigManager.ONSConfig.bumpersHeight = ONSControls._controlsCanvas.vh(0.12) * ConfigManager.ONSConfig.buttonsScale;
|
||||
ConfigManager.ONSConfig.LBX = ConfigManager.ONSConfig.bumpersOffsetX + ConfigManager.ONSConfig.safeArea + ConfigManager.ONSConfig.bumpersWidth / 2;
|
||||
ConfigManager.ONSConfig.LBY = (ConfigManager.ONSConfig.bumpersOffsetY + ConfigManager.ONSConfig.safeArea + ConfigManager.ONSConfig.bumpersHeight / 2);
|
||||
ConfigManager.ONSConfig.RBX = ONSControls._controlsCanvas.screen.width - (ConfigManager.ONSConfig.safeArea + ConfigManager.ONSConfig.bumpersOffsetX + ConfigManager.ONSConfig.bumpersWidth / 2);
|
||||
ConfigManager.ONSConfig.RBY = (ConfigManager.ONSConfig.bumpersOffsetY + ConfigManager.ONSConfig.safeArea + ConfigManager.ONSConfig.bumpersHeight / 2);ConfigManager.ONSConfig.additionalOffset = ConfigManager.ONSConfig.additionalOffset;
|
||||
ConfigManager.ONSConfig.additonalSize = ONSControls._controlsCanvas.vh(0.06) * ConfigManager.ONSConfig.buttonsScale;
|
||||
ConfigManager.ONSConfig.showX = ONSControls._controlsCanvas.screen.width - (ConfigManager.ONSConfig.additonalSize / 2 + ConfigManager.ONSConfig.safeArea);
|
||||
ConfigManager.ONSConfig.showY = ONSControls._controlsCanvas.screen.height - (ConfigManager.ONSConfig.additonalSize / 2 + ConfigManager.ONSConfig.safeArea);
|
||||
this.customPos = this.customPos;
|
||||
this.buttonsScale = this.buttonsScale;
|
||||
this.buttonsOpacity = this.buttonsOpacity;
|
||||
this.safeArea = this.safeArea;
|
||||
this.buttonsSize = ONSControls._controlsCanvas.vh(0.18) * this.buttonsScale;
|
||||
this.dPadSize = ONSControls._controlsCanvas.vh(0.36) * this.buttonsScale;
|
||||
this.bumpersOffsetX = this.bumpersOffsetX;
|
||||
this.bumpersOffsetY = this.bumpersOffsetY;
|
||||
this.bumpersWidth = ONSControls._controlsCanvas.vh(0.188) * this.buttonsScale;
|
||||
this.bumpersHeight = ONSControls._controlsCanvas.vh(0.12) * this.buttonsScale;
|
||||
this.additonalSize = ONSControls._controlsCanvas.vh(0.06) * this.buttonsScale;
|
||||
if (this.customPos === false) {
|
||||
this.buttonsX = ONSControls._controlsCanvas.screen.width - (this.buttonsSize + this.safeArea);
|
||||
this.buttonsY = ONSControls._controlsCanvas.screen.height - (this.buttonsSize + this.safeArea);
|
||||
this.dPadX = this.dPadSize / 2 + this.safeArea;
|
||||
this.dPadY = ONSControls._controlsCanvas.screen.height - (this.dPadSize / 2 + this.safeArea);
|
||||
this.LBX = this.bumpersOffsetX + this.safeArea + this.bumpersWidth / 2;
|
||||
this.LBY = (this.bumpersOffsetY + this.safeArea + this.bumpersHeight / 2);
|
||||
this.RBX = ONSControls._controlsCanvas.screen.width - (this.safeArea + this.bumpersOffsetX + this.bumpersWidth / 2);
|
||||
this.RBY = (this.bumpersOffsetY + this.safeArea + this.bumpersHeight / 2);
|
||||
this.additionalOffset = this.additionalOffset;
|
||||
this.showX = ONSControls._controlsCanvas.screen.width - (this.additonalSize / 2 + this.safeArea);
|
||||
this.showY = ONSControls._controlsCanvas.screen.height - (this.additonalSize / 2 + this.safeArea);
|
||||
}
|
||||
ONSControls.updateButtons();
|
||||
}
|
||||
}
|
||||
|
@ -609,6 +634,7 @@ var _ConfigManager_makeData = ConfigManager.makeData;
|
|||
ConfigManager.makeData = function () {
|
||||
var config = _ConfigManager_makeData.apply(this, arguments);
|
||||
config.ONSConfig = {};
|
||||
config.ONSConfig.customPos = this.ONSConfig.customPos;
|
||||
config.ONSConfig.buttonsScale = this.ONSConfig.buttonsScale;
|
||||
config.ONSConfig.buttonsOpacity = this.ONSConfig.buttonsOpacity;
|
||||
config.ONSConfig.safeArea = this.ONSConfig.safeArea;
|
||||
|
@ -639,6 +665,7 @@ ConfigManager.applyData = function (config) {
|
|||
_ConfigManager_applyData.apply(this, arguments);
|
||||
try {
|
||||
this.ONSConfig = config.ONSConfig;
|
||||
this.ONSConfig.customPos = config.ONSConfig.customPos;
|
||||
this.ONSConfig.buttonsScale = config.ONSConfig.buttonsScale;
|
||||
this.ONSConfig.buttonsOpacity = config.ONSConfig.buttonsOpacity;
|
||||
this.ONSConfig.safeArea = config.ONSConfig.safeArea;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue