PIXI Controls: Fix DPad stopping after two events

This commit is contained in:
OleSTEEP 2024-02-03 14:27:28 +03:00
parent 0510c9c694
commit 94da0e41fc

View file

@ -93,6 +93,9 @@ ONSControls.createDPad = function() {
button = "DPAD_RIGHT"; button = "DPAD_RIGHT";
} }
if (button !== container.pressed_button && button !== undefined) { if (button !== container.pressed_button && button !== undefined) {
if (container.pressed_button !== null) {
ONSControls.sendEvent({type: "pointerup"}, container.pressed_button);
}
container.pressed = true; container.pressed = true;
container.pressed_button = button; container.pressed_button = button;
ONSControls.sendEvent({type: "pointerdown"}, button); ONSControls.sendEvent({type: "pointerdown"}, button);
@ -550,6 +553,295 @@ ConfigManager.ONSConfig.updateData = function() {
//=============================================================================
// ** Window_OmoMenuOptionsONSControls
//-----------------------------------------------------------------------------
// The window for showing ONSControls options in the OMORI options menu
//=============================================================================
function Window_OmoMenuOptionsONSControls() { this.initialize.apply(this, arguments); }
Window_OmoMenuOptionsONSControls.prototype = Object.create(Window_Selectable.prototype);
Window_OmoMenuOptionsONSControls.prototype.constructor = Window_OmoMenuOptionsONSControls;
//=============================================================================
// * Object Initialization
//=============================================================================
Window_OmoMenuOptionsONSControls.prototype.initialize = function () {
// Make Options List
this.makeOptionsList();
// Super Call
Window_Selectable.prototype.initialize.call(this, 0, 0, this.windowWidth(), this.windowHeight());
// Create Option Bars
this.createOptionBars();
this.select(0);
// Refresh
this.refresh();
};
//=============================================================================
// * Settings
//=============================================================================
Window_OmoMenuOptionsONSControls.prototype.isUsingCustomCursorRectSprite = function () { return true; };
Window_OmoMenuOptionsONSControls.prototype.standardPadding = function () { return 8; }
Window_OmoMenuOptionsONSControls.prototype.windowWidth = function () { return Graphics.width - 20; };
Window_OmoMenuOptionsONSControls.prototype.windowHeight = function () { return 318; }
Window_OmoMenuOptionsONSControls.prototype.maxItems = function () { return this._optionsList.length; };
Window_OmoMenuOptionsONSControls.prototype.maxCols = function () { return 1; };
Window_OmoMenuOptionsONSControls.prototype.itemHeight = function () { return 75; };
Window_OmoMenuOptionsONSControls.prototype.spacing = function () { return 5; };
Window_OmoMenuOptionsONSControls.prototype.customCursorRectXOffset = function () { return 15; }
Window_OmoMenuOptionsONSControls.prototype.customCursorRectYOffset = function () { return -18; }
//=============================================================================
// * Height
//=============================================================================
Object.defineProperty(Window_OmoMenuOptionsONSControls.prototype, 'height', {
get: function () { return this._height; },
set: function (value) {
this._height = value;
this._refreshAllParts();
// If Option Sprites Exist
if (this._optionSprites) {
for (var i = 0; i < this._optionSprites.length; i++) {
var sprite = this._optionSprites[i];
sprite.visible = value >= (sprite.y + sprite.height)
};
}
},
configurable: true
});
//=============================================================================
// * Create Option Bars
//=============================================================================
Window_OmoMenuOptionsONSControls.prototype.createOptionBars = function () {
// Initialize Option Sprites
this._optionSprites = [];
// Create Bitmap
var bitmap = new Bitmap(400, 40);
// Iterate from 0 to 100
for (var i = 0; i < 100; i++) {
var x = (i + 4) + (i % 2);;
var x = (i * 4);
bitmap.fillRect(x, 0, 2, 20, 'rgba(100, 100, 100, 1)');
bitmap.fillRect(x, 20, 2, 20, 'rgba(255, 255, 255, 1)');
};
// Create Sprites
for (var i = 0; i < 8; i++) {
var sprite = new Sprite(bitmap);
var index = Math.floor(i / 2);
var rect = this.itemRect(index);
sprite.x = rect.x + 60;
sprite.y = rect.y + 50;
// sprite.y += (i % 2) * 20;
sprite.setFrame(0, (i % 2) * 20, bitmap.width, 20);
this._optionSprites.push(sprite);
this.addChild(sprite);
};
};
//=============================================================================
// * Make Options List
//=============================================================================
Window_OmoMenuOptionsONSControls.prototype.makeOptionsList = function () {
// Get Text
//var text = LanguageManager.getPluginText('optionsMenu', 'audio');
var text = {
buttonsScale: {help: "Change scale of A/B/X/Y buttons.", text: "BUTTONS SCALE", persent: true},
bumpersOffsetX: {help: "Change x coordinate offset of LB/RB.", text: "LB/RB X OFFSET", persent: false},
bumpersOffsetY: {help: "Change y coordinate offset of LB/RB.", text: "LB/RB Y OFFSET", persent: false}
}
// Get Config
var config = ConfigManager;
// Get Options
var options = Object.keys(text);
// Initialize Options List
this._optionsList = [];
// Go Through Options
for (var i = 0; i < options.length; i++) {
// Get Name
var name = options[i];
// Get Data
var data = text[name];
// Add Option
if (data.persent) {
this._optionsList.push({ header: data.text + ':', config: name, option: ConfigManager.ONSConfig[name] * 100, helpText: data.help, persent: data.persent });
} else {
this._optionsList.push({ header: data.text + ':', config: name, option: ConfigManager.ONSConfig[name], helpText: data.help, persent: data.persent });
}
};
}
//=============================================================================
// * Draw Item
//=============================================================================
Window_OmoMenuOptionsONSControls.prototype.drawItem = function (index) {
// Get Item Rect
var rect = this.itemRect(index);
// Get Data
var data = this._optionsList[index];
// If Data Exists
if (data) {
// Draw Header
this.contents.drawText(data.header, rect.x + 50, rect.y, rect.width, 24);
// Update option bar
this.updateOptionBar(index, data.option, data.persent);
};
};
//=============================================================================
// * Call Update Help
//=============================================================================
Window_OmoMenuOptionsONSControls.prototype.callUpdateHelp = function () {
// Run Original Function
Window_Selectable.prototype.callUpdateHelp.call(this);
// If Help Window Exist
if (this._helpWindow) {
this._helpWindow.setText(this._optionsList[this.index()].helpText);
};
};
//=============================================================================
// * Cursor Right
//=============================================================================
Window_OmoMenuOptionsONSControls.prototype.cursorRight = function (wrap) {
// Super Call
Window_Selectable.prototype.cursorRight.call(this, wrap);
// Get Data
var data = this._optionsList[this.index()];
// Get Data
if (data) {
var rate = Input.isLongPressed('right') ? 5 : 5
data.option = Math.min(data.option + rate, 500);
this.updateOptionBar(this.index(), data.option, data.persent);
};
};
//=============================================================================
// * Cursor Left
//=============================================================================
Window_OmoMenuOptionsONSControls.prototype.cursorLeft = function (wrap) {
// Super Call
Window_Selectable.prototype.cursorLeft.call(this, wrap);
// Get Data
var data = this._optionsList[this.index()];
// Get Data
if (data) {
var rate = Input.isLongPressed('left') ? 5 : 5
data.option = Math.max(data.option - rate, 0);
this.updateOptionBar(this.index(), data.option, data.persent);
};
};
//=============================================================================
// * Cursor Left
//=============================================================================
Window_OmoMenuOptionsONSControls.prototype.updateOptionBar = function (index, option, persent) {
// Get Data
var data = this._optionsList[index];
// Get Back and Front Sprite
var front = this._optionSprites[(index * 2) + 1];
front._frame.width = option / 5 * 4;
front._refresh();
// Get Itm Rect
var rect = this.itemRect(index);
rect.x += 415; rect.y += 27; rect.width = 100; rect.height = 40;
this.contents.clearRect(rect.x, rect.y, rect.width, rect.height);
if (persent) {
this.contents.drawText(option + '%', rect.x, rect.y, rect.width, rect.height, 'right');
// Set Option
ConfigManager.ONSConfig[data.config] = option / 100;
} else {
this.contents.drawText(Math.round(option) + 'px', rect.x, rect.y, rect.width, rect.height, 'right');
// Set Option
ConfigManager.ONSConfig[data.config] = option;
}
ConfigManager.ONSConfig.updateData();
};
//=============================================================================
// * Add to options menus
//=============================================================================
Window_OmoMenuOptionsONSControls.prototype.add = function () {
Scene_OmoMenuOptions.prototype.createONSControlsOptionsWindow = function () {
// Create ONSControls Options Window
this._onscontrolsOptionsWindow = new Window_OmoMenuOptionsONSControls();
this._onscontrolsOptionsWindow.x = 10;
this._onscontrolsOptionsWindow.y = 10;
this._onscontrolsOptionsWindow.setHandler('cancel', this.onOptionWindowCancel.bind(this));
this._onscontrolsOptionsWindow.height = 0;
this._onscontrolsOptionsWindow.visible = false;
this.addChild(this._onscontrolsOptionsWindow);
};
Scene_OmoMenuOptions.prototype.optionWindows = function () {
return [this._generalOptionsWindow, this._audioOptionsWindow, this._controlOptionsWindow, this._onscontrolsOptionsWindow, this._systemOptionsWindow]
}
Scene_OmoriTitleScreen.prototype.createONSControlsOptionsWindow = function () {
// Create Audio Options Window
this._onscontrolsOptionsWindow = new Window_OmoMenuOptionsONSControls();
this._onscontrolsOptionsWindow.setHandler('cancel', this.onOptionWindowCancel.bind(this));
this._onscontrolsOptionsWindow.visible = false;
this._optionsWindowsContainer.addChild(this._onscontrolsOptionsWindow);
};
Scene_OmoriTitleScreen.prototype.optionWindows = function () {
return [this._generalOptionsWindow, this._audioOptionsWindow, this._controlOptionsWindow, this._onscontrolsOptionsWindow, this._systemOptionsWindow]
}
Scene_OmoriTitleScreen.prototype.create = function () {
// Super Call
Scene_BaseEX.prototype.create.call(this);
this.createFilters();
// Create Background
this.createBackground();
// Create Omori Sprite
this.createOmoriSprite();
// Create Title Sprites
this.createTitleSprites();
// Create Title Commands
this.createTitleCommands();
// Create Command Hints
this.createCommandHints();
// Create Version Text
this.createVersionText();
// Create Options Windows
this.createOptionWindowsContainer();
this.createHelpWindow();
this.createGeneralOptionsWindow();
this.createAudioOptionsWindow();
this.createControllerOptionsWindow();
this.createONSControlsOptionsWindow();
this.createSystemOptionsWindow();
this.createExitPromptWindow();
this.createOptionCategoriesWindow();
// Update world bitmaps
this.updateWorldBitmaps();
this.playBgm();
this.playBgs();
// this._backgroundSprite.filters = [this._glitchFilter]
};
Scene_OmoMenuOptions.prototype.create = function () {
// Super Call
Scene_OmoMenuBase.prototype.create.call(this);
this.createHelpWindow();
this.createStatusWindows();
this.createGoldWindow();
this.createGeneralOptionsWindow();
this.createAudioOptionsWindow();
this.createControllerOptionsWindow();
this.createONSControlsOptionsWindow();
this.createSystemOptionsWindow();
this.createOptionCategoriesWindow();
// this.createHelpWindow();
this.createCommandWindow();
this.createExitPromptWindow();
};
Window_OmoMenuOptionsCategory.prototype.standardPadding = function () { return 7; }
Window_OmoMenuOptionsCategory.prototype.maxCols = function () { return 5; };
Window_OmoMenuOptionsCategory.prototype.makeCommandList = function () {
const localization = LanguageManager.getMessageData("XX_BLUE.Omori_Mainmenu_Sceneoptions").commands
this.addCommand(localization[0], 'ok');
this.addCommand(localization[1], 'ok');
// this.addCommand('GAMEPLAY', 'ok');
this.addCommand(localization[2], 'ok');
this.addCommand("ONSControls", 'ok');
this.addCommand(localization[3], 'ok');
};
}
//============================================================================= //=============================================================================
// * Plugin init // * Plugin init
//============================================================================= //=============================================================================
@ -563,4 +855,5 @@ ONSControls.initialize = function() {
this.createAdditionalButtons(); this.createAdditionalButtons();
this.updateButtons(); this.updateButtons();
VirtualGamepad.connect(); VirtualGamepad.connect();
Window_OmoMenuOptionsONSControls.prototype.add();
} }