查看: 4221|回复: 1

[原创发布] Nwjs Window 控制器

[复制链接]
梦石
0
星屑
4628
在线时间
1208 小时
注册时间
2016-4-7
回帖
944

开拓者

发表于 2016-9-10 15:59:03 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 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版并无关系。
脚本
  1. //=============================================================================
  2. // NwjsWindowController.js
  3. //=============================================================================

  4. /*:
  5. * @plugindesc  Nwjs Window 控制器
  6. * @author shitake
  7. *
  8. * @param title
  9. * @desc 窗口标题。
  10. * @default null
  11. *
  12. * @param x
  13. * @desc 窗口的x坐标。
  14. * @default null
  15. *
  16. * @param y
  17. * @desc 窗口的y坐标。
  18. * @default null
  19. *
  20. * @param width
  21. * @desc 窗口的宽度.
  22. * @default 816
  23. *
  24. * @param height
  25. * @desc 窗口的高度.
  26. * @default 624
  27. *
  28. * @param minWidth
  29. * @desc 窗口的最小宽度.
  30. * @default 816
  31. *
  32. * @param minHeight
  33. * @desc 窗口的最小高度.
  34. * @default 624
  35. *
  36. * @param maxWidth
  37. * @desc 窗口的最大宽度.
  38. * @default 816
  39. *
  40. * @param maxHeight
  41. * @desc 窗口的最大高度.
  42. * @default 624
  43. *
  44. * @param position
  45. * @desc 窗口位置。
  46. * @default center
  47. *
  48. * @param isFullscreen
  49. * @desc 窗口是否全屏。
  50. * @default false
  51. *
  52. * @param resizable
  53. * @desc 窗口是否可以被重置大小。
  54. * @default true
  55. *
  56. * @param alwaysOnTop
  57. * @desc 窗口是否总在最前端。
  58. * @default false
  59. *
  60. * @param showInTaskbar
  61. * @desc 是否允许在任务栏显示图标。
  62. * @default false
  63. *
  64. * @help
  65. * Commands:
  66. *         setTitle([String]title) 设置窗口标题。
  67. *         setAlwaysOnTop([Boolean]value) 设置窗口是否置顶。
  68. *         setShowInTaskbar([Boolean]value) 设置是否允许在任务栏显示图标。
  69. *         moveTo([Int]x, [Int]y) 将窗口移动到指定值。
  70. *         moveBy([Int]x, [Int]y) 将窗口移动指定值。
  71. *         resizeTo([Int]width, [Int]height) 将窗口大小变更到指定值。
  72. *         resizeBy([Int]width, [Int]height) 将窗口大小变更指定值。
  73. *         focus() 窗口获得焦点。
  74. *         blur() 窗口失去焦点。
  75. *         show() 显示窗口。
  76. *         hide() 隐藏窗口。
  77. *         close([Boolean]force) 关闭窗口。force为真时将忽略close事件的监听。
  78. *         reload() 重新加载窗口。
  79. *         reloadIgnoringCache() 重新加载窗体,强制刷新缓存。
  80. *         maximize() 窗口最大化。
  81. *         minimize() 窗口最小化。
  82. *         restore() 窗口返回上一个状态。
  83. *         enterFullscreen() 进入全屏模式。
  84. *         leaveFullscreen() 退出全屏模式。
  85. *         toggleFullscreen() 切换全屏模式。
  86. *         capturePage([String]filename) 对窗口内的内容作截图,然后保存为png。文件名及路径由filename指定(不需要带后缀名)。
  87. */

  88. (function() {
  89.         $plugins.NwControl = {
  90.                 init: function () {
  91.                         this.parameters = PluginManager.parameters('nwjsWindowController');
  92.                         this.winParams = {
  93.                                 title: String(this.parameters['title']) || null,
  94.                                 x: parseInt(this.parameters['x']) || null,
  95.                                 y: parseInt(this.parameters['y']) || null,
  96.                                 width: parseInt(this.parameters['width']) || 816,
  97.                                 height: parseInt(this.parameters['height']) || 624,
  98.                                 minWidth: parseInt(this.parameters['minWidth']) || 816,
  99.                                 minHeight: parseInt(this.parameters['minHeight']) || 624,
  100.                                 maxWidth: parseInt(this.parameters['maxWidth']) || 816,
  101.                                 maxHeight: parseInt(this.parameters['maxHeight'] || 624),
  102.                                 position: String(this.parameters['position']) || 'center',
  103.                                 isFullscreen: Boolean(this.parameters['isFullscreen']) || false,
  104.                                 resizable: Boolean(this.parameters['resizable']) || false,
  105.                                 alwaysOnTop: Boolean(this.parameters['alwaysOnTop']) || false,
  106.                                 showInTaskbar: Boolean(this.parameters['showInTaskbar']) || false
  107.                         };
  108.                         if (Utils.isNwjs()) { this.createSettings();}
  109.                         this.createCommands();
  110.                 },
  111.                 createSettings: function () {
  112.                         this.win = require('nw.gui').Window.get();
  113.                         if(this.winParams.title != 'null'){ this.win.title = this.winParams.title; }
  114.                         if(!isNaN(this.winParams.x) && !isNaN(this.winParams.y)){ this.win.moveTo(this.winParams.x, this.winParams.y); }
  115.                         this.win.width = this.winParams.width;
  116.                         this.win.height = this.winParams.height;
  117.                         this.win.setMinimumSize(this.winParams.minWidth, this.winParams.minHeight);
  118.                         this.win.setMaximumSize(this.winParams.maxWidth, this.winParams.maxHeight);
  119.                         this.win.isFullscreen = this.winParams.isFullscreen;
  120.                         this.win.setPosition(this.winParams.position);
  121.                         this.win.setResizable(this.winParams.resizable);
  122.                         this.win.setAlwaysOnTop(this.winParams.alwaysOnTop);
  123.                         this.win.setShowInTaskbar(this.winParams.showInTaskbar);
  124.                 },
  125.                 createCommands: function () {
  126.                         var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  127.                         Game_Interpreter.prototype.pluginCommand = function(command, args) {
  128.                                 _Game_Interpreter_pluginCommand.call(this, command, args);
  129.                                 if (Utils.isNwjs()) {
  130.                                         var module = command.split('.')[0];
  131.                                         var methods = command.split('.')[1];
  132.                                         if(module != 'NwControl'){ return null; }
  133.                                         var win = $plugins.NwControl.win;
  134.                                         switch(methods) {
  135.                                                 case 'setTitle':
  136.                                                         win.title = String(args[0]);
  137.                                                         break;
  138.                                                 case 'setAlwaysOnTop':
  139.                                                         win.setAlwaysOnTop(Boolean(args[0]));
  140.                                                         break;
  141.                                                 case 'setShowInTaskbar':
  142.                                                         win.setShowInTaskbar(Boolean(args[0]));
  143.                                                         break;
  144.                                                 case 'moveTo':
  145.                                                         win.moveTo(parseInt(args[0]), parseInt(args[1]));
  146.                                                         break;
  147.                                                 case 'moveBy':
  148.                                                         win.moveBy(parseInt(args[0]), parseInt(args[1]));
  149.                                                         break;
  150.                                                 case 'resizeTo':
  151.                                                         win.resizeTo(parseInt(args[0]), parseInt(args[1]));
  152.                                                         break;
  153.                                                 case 'resizeBy':
  154.                                                         win.resizeBy(parseInt(args[0]), parseInt(args[1]));
  155.                                                         break;
  156.                                                 case 'focus':
  157.                                                         win.focus();
  158.                                                         break;
  159.                                                 case 'blur':
  160.                                                         win.blur();
  161.                                                         break;
  162.                                                 case 'show':
  163.                                                         win.show();
  164.                                                         break;
  165.                                                 case 'hide':
  166.                                                         win.hide();
  167.                                                         break;
  168.                                                 case 'close':
  169.                                                         win.close(Boolean(args[0]));
  170.                                                         break;
  171.                                                 case 'reload':
  172.                                                         win.reload();
  173.                                                         break;
  174.                                                 case 'reloadIgnoringCache':
  175.                                                         win.reloadIgnoringCache();
  176.                                                         break;
  177.                                                 case 'maximize':
  178.                                                         win.maximize();
  179.                                                         break;
  180.                                                 case 'minimize':
  181.                                                         win.minimize();
  182.                                                         break;
  183.                                                 case 'restore':
  184.                                                         win.restore();
  185.                                                         break;
  186.                                                 case 'enterFullscreen':
  187.                                                         win.enterFullscreen();
  188.                                                         break;
  189.                                                 case 'leaveFullscreen':
  190.                                                         win.leaveFullscreen();
  191.                                                         break;
  192.                                                 case 'toggleFullscreen':
  193.                                                         win.toggleFullscreen();
  194.                                                         break;
  195.                                                 case 'capturePage':
  196.                                                         var filename = args[0];
  197.                                                         win.capturePage(function (image) {
  198.                                                                 var base64Data = image.replace(/^data:image\/(png|jpg|jpeg);base64,/, "");
  199.                                                                 require("fs").writeFile(filename + ".png", base64Data, 'base64', function (err) {
  200.                                                                         console.log(err);
  201.                                                                 });
  202.                                                         }, 'png');
  203.                                                         break
  204.                                         }
  205.                                 } else {
  206.                                         console.log('Not NW.js!')
  207.                                 }
  208.                         };
  209.                 }
  210.         };
  211.         $plugins.NwControl.init()
  212. })();
复制代码
附庸的附庸不是我的附庸,女儿的女儿还是我的女儿。CK2沉迷ing
梦石
0
星屑
50
在线时间
92 小时
注册时间
2012-1-30
回帖
23
发表于 2016-9-11 10:44:48 | 显示全部楼层
感谢LZ,想请问下这个可以解决最小化会停止的问题么~!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部