PIXI Controls: Safe area in persentage

This commit is contained in:
OleSTEEP 2024-02-19 23:51:59 +03:00
parent c1625397fc
commit d70c09e713

View file

@ -285,8 +285,11 @@ ONSControls.updateButtons = function() {
// * Clamp to safe area
//=============================================================================
ONSControls.toSafeArea = function(position, element) {
let safeAreaX = ConfigManager.ONSConfig.safeArea + element.width / 2;
let safeAreaY = ConfigManager.ONSConfig.safeArea + element.height / 2;
let sx = ONSControls._controlsCanvas.vh(0.032);
let sy = ONSControls._controlsCanvas.vh(0.024);
let n = ConfigManager.ONSConfig.safeArea;
let safeAreaX = 10 * sx * Math.abs(n - 1) + sx + element.width / 2;
let safeAreaY = 10 * sy * Math.abs(n - 1) + sy + element.height / 2;
position.x = position.x.clamp(safeAreaX, this._controlsCanvas.screen.width - safeAreaX);
position.y = position.y.clamp(safeAreaY, this._controlsCanvas.screen.height - safeAreaY);
return position;
@ -569,22 +572,22 @@ 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);
ConfigManager.ONSConfig.buttonsSize ||= ONSControls._controlsCanvas.vh(0.18) * ConfigManager.ONSConfig.buttonsScale;
ConfigManager.ONSConfig.safeArea ||= 1;
ConfigManager.ONSConfig.buttonsSize ||= ONSControls._controlsCanvas.vh(0.18) * this.ONSConfig.buttonsScale;
ConfigManager.ONSConfig.buttonsX ||= ONSControls._controlsCanvas.screen.width - this.ONSConfig.buttonsSize;
ConfigManager.ONSConfig.buttonsY ||= ONSControls._controlsCanvas.screen.height - this.ONSConfig.buttonsSize;
ConfigManager.ONSConfig.dPadSize ||= ONSControls._controlsCanvas.vh(0.36) * ConfigManager.ONSConfig.buttonsScale;
ConfigManager.ONSConfig.dPadSize ||= ONSControls._controlsCanvas.vh(0.36) * this.ONSConfig.buttonsScale;
ConfigManager.ONSConfig.dPadX ||= this.ONSConfig.dPadSize / 2;
ConfigManager.ONSConfig.dPadY ||= ONSControls._controlsCanvas.screen.height - this.ONSConfig.dPadSize / 2;
ConfigManager.ONSConfig.bumpersOffsetX ||= 16;
ConfigManager.ONSConfig.bumpersOffsetY ||= ONSControls._controlsCanvas.vh(0.30);
ConfigManager.ONSConfig.bumpersWidth ||= ONSControls._controlsCanvas.vh(0.188) * ConfigManager.ONSConfig.buttonsScale;
ConfigManager.ONSConfig.bumpersHeight ||= ONSControls._controlsCanvas.vh(0.12) * ConfigManager.ONSConfig.buttonsScale;
ConfigManager.ONSConfig.bumpersWidth ||= ONSControls._controlsCanvas.vh(0.188) * this.ONSConfig.buttonsScale;
ConfigManager.ONSConfig.bumpersHeight ||= ONSControls._controlsCanvas.vh(0.12) * this.ONSConfig.buttonsScale;
ConfigManager.ONSConfig.LBX ||= this.ONSConfig.bumpersOffsetX + this.ONSConfig.bumpersWidth / 2;
ConfigManager.ONSConfig.LBY ||= this.ONSConfig.bumpersOffsetY + this.ONSConfig.bumpersHeight / 2;
ConfigManager.ONSConfig.RBX ||= this.ONSConfig.bumpersOffsetX + this.ONSConfig.bumpersWidth / 2;
ConfigManager.ONSConfig.RBY ||= this.ONSConfig.bumpersOffsetY + this.ONSConfig.bumpersHeight / 2;
ConfigManager.ONSConfig.additonalSize ||= ONSControls._controlsCanvas.vh(0.06) * ConfigManager.ONSConfig.buttonsScale;
ConfigManager.ONSConfig.additonalSize ||= ONSControls._controlsCanvas.vh(0.06) * this.ONSConfig.buttonsScale;
ConfigManager.ONSConfig.showX ||= ONSControls._controlsCanvas.screen.width - this.ONSConfig.additonalSize / 2;
ConfigManager.ONSConfig.showY ||= ONSControls._controlsCanvas.screen.height - this.ONSConfig.additonalSize / 2;
//=============================================================================
@ -601,7 +604,7 @@ ConfigManager.restoreDefaultConfig = function () {
this.ONSConfig.customPos = false;
this.ONSConfig.buttonsScale = ONSControls.options.buttonsScale;
this.ONSConfig.buttonsOpacity = ONSControls.options.buttonsOpacity;
this.ONSConfig.safeArea = ONSControls._controlsCanvas.vh(0.032);
this.ONSConfig.safeArea = 1;
this.ONSConfig.buttonsSize = ONSControls._controlsCanvas.vh(0.18) * this.ONSConfig.buttonsScale;
this.ONSConfig.buttonsX = ONSControls._controlsCanvas.screen.width - this.ONSConfig.buttonsSize;
this.ONSConfig.buttonsY = ONSControls._controlsCanvas.screen.height - this.ONSConfig.buttonsSize;
@ -833,9 +836,9 @@ Window_OmoMenuOptionsONSControls.prototype.makeOptionsList = function () {
// Get Text
//var text = LanguageManager.getPluginText('optionsMenu', 'audio');
var text = {
buttonsScale: {help: "Изменить размер наэкранных кнопок управления.", text: "РАЗМЕР УПРАВЛЕНИЯ", isBar: true, persent: true, maxValue: 500},
buttonsOpacity: {help: "Изменить прозрачность наэкранных кнопок управления.", text: "ПРОЗРАЧНОСТЬ УПРАВЛЕНИЯ", isBar: true, persent: true, maxValue: 100},
safeArea: {help: "Изменить размер безопасной области для управления.", text: "БЕЗОПАСНАЯ ОБЛАСТЬ", isBar: true, persent: false, maxValue: 500},
buttonsScale: {help: "Изменить размер наэкранных кнопок управления.", text: "РАЗМЕР УПРАВЛЕНИЯ", isBar: true, persent: true, minValue: 0, maxValue: 500},
buttonsOpacity: {help: "Изменить прозрачность наэкранных кнопок управления.", text: "ПРОЗРАЧНОСТЬ УПРАВЛЕНИЯ", isBar: true, persent: true, minValue: 0, maxValue: 100},
safeArea: {help: "Изменить размер безопасной области для управления.", text: "БЕЗОПАСНАЯ ОБЛАСТЬ", isBar: true, persent: true, minValue: 10, maxValue: 100},
editMenu: {help: "Нажмите кнопку влево или вправо, чтобы открыть меню.", text: "ОТКРЫТЬ МЕНЮ НАСТРОЕК", isBar: false}
}
// Get Config
@ -853,9 +856,9 @@ Window_OmoMenuOptionsONSControls.prototype.makeOptionsList = function () {
// Add Option
if (data.isBar) {
if (data.persent) {
this._optionsList.push({ header: data.text + ':', config: name, option: ConfigManager.ONSConfig[name] * 100, helpText: data.help, isBar: data.isBar, persent: data.persent, maxValue: data.maxValue });
this._optionsList.push({ header: data.text + ':', config: name, option: ConfigManager.ONSConfig[name] * 100, helpText: data.help, isBar: data.isBar, persent: data.persent, minValue: data.minValue, maxValue: data.maxValue });
} else {
this._optionsList.push({ header: data.text + ':', config: name, option: ConfigManager.ONSConfig[name], helpText: data.help, isBar: data.isBar, persent: data.persent, maxValue: data.maxValue });
this._optionsList.push({ header: data.text + ':', config: name, option: ConfigManager.ONSConfig[name], helpText: data.help, isBar: data.isBar, persent: data.persent, minValue: data.minValue, maxValue: data.maxValue });
}
} else {
this._optionsList.push({ header: data.text, config: name, helpText: data.help, isBar: data.isBar});
@ -921,7 +924,7 @@ Window_OmoMenuOptionsONSControls.prototype.cursorLeft = function (wrap) {
// Get Data
if (data) {
var rate = Input.isLongPressed('left') ? 5 : 5
data.option = Math.max(data.option - rate, 0);
data.option = Math.max(data.option - rate, data.minValue);
if (data.isBar) {
this.updateOptionBar(this.index(), data.option, data.persent);
} else {