| 赞 | 54 |
| VIP | |
| 好人卡 | |
| 积分 | 46 |
| 经验 | |
| 最后登录 | 2026-10-12 |
| 在线时间 | 1208 小时 |
- 梦石
- 0
- 星屑
- 4628
- 在线时间
- 1208 小时
- 注册时间
- 2016-4-7
- 回帖
- 944

|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 shitake 于 2016-9-10 16:01 编辑
Nwjs Window 控制器
正如其名,用来对Nwjs Window做一些操作用。虽然这些属性等大多数都可以通过配置文件来设置。不过鉴于有不少人并不懂如何配置。就有了这个脚本。
具体的可参考一下网站:
http://www.cnblogs.com/xuanhun/p/3664635.html
http://docs.nwjs.io/en/latest/References/Window/
p.s.此脚本只对桌面版有效(准确来说是nwjs平台),和移动平台和web版并无关系。
脚本- //=============================================================================
- // NwjsWindowController.js
- //=============================================================================
- /*:
- * @plugindesc Nwjs Window 控制器
- * @author shitake
- *
- * @param title
- * @desc 窗口标题。
- * @default null
- *
- * @param x
- * @desc 窗口的x坐标。
- * @default null
- *
- * @param y
- * @desc 窗口的y坐标。
- * @default null
- *
- * @param width
- * @desc 窗口的宽度.
- * @default 816
- *
- * @param height
- * @desc 窗口的高度.
- * @default 624
- *
- * @param minWidth
- * @desc 窗口的最小宽度.
- * @default 816
- *
- * @param minHeight
- * @desc 窗口的最小高度.
- * @default 624
- *
- * @param maxWidth
- * @desc 窗口的最大宽度.
- * @default 816
- *
- * @param maxHeight
- * @desc 窗口的最大高度.
- * @default 624
- *
- * @param position
- * @desc 窗口位置。
- * @default center
- *
- * @param isFullscreen
- * @desc 窗口是否全屏。
- * @default false
- *
- * @param resizable
- * @desc 窗口是否可以被重置大小。
- * @default true
- *
- * @param alwaysOnTop
- * @desc 窗口是否总在最前端。
- * @default false
- *
- * @param showInTaskbar
- * @desc 是否允许在任务栏显示图标。
- * @default false
- *
- * @help
- * Commands:
- * setTitle([String]title) 设置窗口标题。
- * setAlwaysOnTop([Boolean]value) 设置窗口是否置顶。
- * setShowInTaskbar([Boolean]value) 设置是否允许在任务栏显示图标。
- * moveTo([Int]x, [Int]y) 将窗口移动到指定值。
- * moveBy([Int]x, [Int]y) 将窗口移动指定值。
- * resizeTo([Int]width, [Int]height) 将窗口大小变更到指定值。
- * resizeBy([Int]width, [Int]height) 将窗口大小变更指定值。
- * focus() 窗口获得焦点。
- * blur() 窗口失去焦点。
- * show() 显示窗口。
- * hide() 隐藏窗口。
- * close([Boolean]force) 关闭窗口。force为真时将忽略close事件的监听。
- * reload() 重新加载窗口。
- * reloadIgnoringCache() 重新加载窗体,强制刷新缓存。
- * maximize() 窗口最大化。
- * minimize() 窗口最小化。
- * restore() 窗口返回上一个状态。
- * enterFullscreen() 进入全屏模式。
- * leaveFullscreen() 退出全屏模式。
- * toggleFullscreen() 切换全屏模式。
- * capturePage([String]filename) 对窗口内的内容作截图,然后保存为png。文件名及路径由filename指定(不需要带后缀名)。
- */
- (function() {
- $plugins.NwControl = {
- init: function () {
- this.parameters = PluginManager.parameters('nwjsWindowController');
- this.winParams = {
- title: String(this.parameters['title']) || null,
- x: parseInt(this.parameters['x']) || null,
- y: parseInt(this.parameters['y']) || null,
- width: parseInt(this.parameters['width']) || 816,
- height: parseInt(this.parameters['height']) || 624,
- minWidth: parseInt(this.parameters['minWidth']) || 816,
- minHeight: parseInt(this.parameters['minHeight']) || 624,
- maxWidth: parseInt(this.parameters['maxWidth']) || 816,
- maxHeight: parseInt(this.parameters['maxHeight'] || 624),
- position: String(this.parameters['position']) || 'center',
- isFullscreen: Boolean(this.parameters['isFullscreen']) || false,
- resizable: Boolean(this.parameters['resizable']) || false,
- alwaysOnTop: Boolean(this.parameters['alwaysOnTop']) || false,
- showInTaskbar: Boolean(this.parameters['showInTaskbar']) || false
- };
- if (Utils.isNwjs()) { this.createSettings();}
- this.createCommands();
- },
- createSettings: function () {
- this.win = require('nw.gui').Window.get();
- if(this.winParams.title != 'null'){ this.win.title = this.winParams.title; }
- if(!isNaN(this.winParams.x) && !isNaN(this.winParams.y)){ this.win.moveTo(this.winParams.x, this.winParams.y); }
- this.win.width = this.winParams.width;
- this.win.height = this.winParams.height;
- this.win.setMinimumSize(this.winParams.minWidth, this.winParams.minHeight);
- this.win.setMaximumSize(this.winParams.maxWidth, this.winParams.maxHeight);
- this.win.isFullscreen = this.winParams.isFullscreen;
- this.win.setPosition(this.winParams.position);
- this.win.setResizable(this.winParams.resizable);
- this.win.setAlwaysOnTop(this.winParams.alwaysOnTop);
- this.win.setShowInTaskbar(this.winParams.showInTaskbar);
- },
- createCommands: function () {
- var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function(command, args) {
- _Game_Interpreter_pluginCommand.call(this, command, args);
- if (Utils.isNwjs()) {
- var module = command.split('.')[0];
- var methods = command.split('.')[1];
- if(module != 'NwControl'){ return null; }
- var win = $plugins.NwControl.win;
- switch(methods) {
- case 'setTitle':
- win.title = String(args[0]);
- break;
- case 'setAlwaysOnTop':
- win.setAlwaysOnTop(Boolean(args[0]));
- break;
- case 'setShowInTaskbar':
- win.setShowInTaskbar(Boolean(args[0]));
- break;
- case 'moveTo':
- win.moveTo(parseInt(args[0]), parseInt(args[1]));
- break;
- case 'moveBy':
- win.moveBy(parseInt(args[0]), parseInt(args[1]));
- break;
- case 'resizeTo':
- win.resizeTo(parseInt(args[0]), parseInt(args[1]));
- break;
- case 'resizeBy':
- win.resizeBy(parseInt(args[0]), parseInt(args[1]));
- break;
- case 'focus':
- win.focus();
- break;
- case 'blur':
- win.blur();
- break;
- case 'show':
- win.show();
- break;
- case 'hide':
- win.hide();
- break;
- case 'close':
- win.close(Boolean(args[0]));
- break;
- case 'reload':
- win.reload();
- break;
- case 'reloadIgnoringCache':
- win.reloadIgnoringCache();
- break;
- case 'maximize':
- win.maximize();
- break;
- case 'minimize':
- win.minimize();
- break;
- case 'restore':
- win.restore();
- break;
- case 'enterFullscreen':
- win.enterFullscreen();
- break;
- case 'leaveFullscreen':
- win.leaveFullscreen();
- break;
- case 'toggleFullscreen':
- win.toggleFullscreen();
- break;
- case 'capturePage':
- var filename = args[0];
- win.capturePage(function (image) {
- var base64Data = image.replace(/^data:image\/(png|jpg|jpeg);base64,/, "");
- require("fs").writeFile(filename + ".png", base64Data, 'base64', function (err) {
- console.log(err);
- });
- }, 'png');
- break
- }
- } else {
- console.log('Not NW.js!')
- }
- };
- }
- };
- $plugins.NwControl.init()
- })();
复制代码 |
|