(() => {
const pluginName = "Spotlight";
PluginManager.registerCommand(pluginName, "show", args => {
let scene = SceneManager._scene;
if (scene.objName() && scene.objName() === 'Scene_Map') {
scene.createSpotLightWindow();
}
});
Scene_Map.prototype.objName = function() {
return 'Scene_Map';
};
Scene_Map.prototype.createSpotLightWindow = function () {
this._spotLightWindow = new Window_SpotLight();
// 本window放在最下层
this.addWindowAt(this._spotLightWindow, 0);
};
Scene_Base.prototype.addWindowAt = function(window, index) {
this._windowLayer.addChildAt(window, index);
};
// windowNameMap 隐藏
Window_MapName.prototype.updateFadeOut = function() {
this.contentsOpacity -= 16;
if (this.contentsOpacity === 0) {
this.hide();
}
};
function Window_SpotLight() {
this.initialize(...arguments);
}
Window_SpotLight.prototype = Object.create(Window.prototype);
Window_SpotLight.prototype.constructor = Window_SpotLight;
Window_SpotLight.prototype.initialize = function () {
Window.prototype.initialize.call(this);
let x = -this._margin / 2;
let y = -this._margin / 2;
let w = $dataSystem.advanced.screenWidth;
let h = $dataSystem.advanced.screenHeight;
this._sceenCenterX = w / 2;
this._sceenCenterY = h / 2;
// console.log(this._sceenCenterX, this._sceenCenterY);
this.move(x, y, w, h);
this._spotLightSprite = new Sprite(ImageManager.loadSystem('_spot_light2'));
this._spotLightSprite.x = this._sceenCenterX;
this._spotLightSprite.y = this._sceenCenterY;
this._spotLightSprite.anchor.x = 0.5;
this._spotLightSprite.anchor.y = 0.5;
this.addChild(this._spotLightSprite);
this._lastPlayerX = this._sceenCenterX;
this._lastPlayerY = this._sceenCenterY + 18; // TODO 不知道这18是怎么来的
this._canZoomOut = true;
};
Window_SpotLight.prototype.update = function () {
if (this._lastPlayerX !== $gamePlayer.screenX()) {
this._spotLightSprite.x -= this._lastPlayerX - $gamePlayer.screenX();
this._lastPlayerX = $gamePlayer.screenX();
}
if (this._lastPlayerY !== $gamePlayer.screenY()) {
this._spotLightSprite.y -= this._lastPlayerY - $gamePlayer.screenY();
this._lastPlayerY = $gamePlayer.screenY();
}
if (this._canZoomOut) {
this._spotLightSprite.scale.x += 0.01;
this._spotLightSprite.scale.y += 0.01;
if (this._spotLightSprite.scale.x >= 1.5) {
this._canZoomOut = false;
}
} else {
this._spotLightSprite.scale.x -= 0.01;
this._spotLightSprite.scale.y -= 0.01;
if (this._spotLightSprite.scale.x <= 1) {
this._canZoomOut = true;
}
}
};
})();