查看: 1829|回复: 3

[有事请教] [已解决]如何在菜单背景中添加开关/变数操控的图片

[复制链接]
梦石
0
星屑
188
在线时间
39 小时
注册时间
2020-5-24
回帖
15
发表于 2020-6-11 17:15:43 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 emshupisim 于 2020-6-14 06:03 编辑

已善用搜索功能,不过没找到想要的效果(((

这里用了mjshi 的 non combat menu来简化MV自带的菜单,代码如下

想做出的效果是: 菜单背景图片可以通过开关或者变数操纵,比如开关A打开时背景白色,开关A关闭时背景黑色。

还请前辈们指教一下要如何达成,十分感谢OTTZ


  1. //=============================================================================
  2. // NonCombatMenu.js
  3. //=============================================================================

  4. var Imported = Imported || {};
  5. Imported.NonCombatMenu = true;

  6. var NCMenu = NCMenu || {};

  7. /*:
  8. * @plugindesc Fully customizable menu geared toward less battle-oriented games.
  9. * @author mjshi
  10. *
  11. * @param ---Main Menu---
  12. * @desc  
  13. * @default
  14. *
  15. * @param Menu Order
  16. * @desc Format is "Name: keyword". Keywords: item equip status formation save load options toTitle cancel quest
  17. * @default Item: item, Status: status, Save: save, Quit: toTitle
  18. *
  19. * @param Background Image
  20. * @desc Background image of the main menu. If undefined, is black. PNG file must be in /img/pictures.
  21. * @default
  22. *
  23. * @param Persistent Background
  24. * @desc yes/no: Background image persists throughout all the sub-menus.
  25. * @default no
  26. *
  27. * @param Menu Background Opacity
  28. * @desc Ranges from 0 to 255. 0 for opaque, 255 for transparent.
  29. * @default 128
  30. *
  31. * @param ---Item Menu---
  32. * @desc
  33. * @default
  34. *
  35. * @param Number of Tabs
  36. * @desc How many tabs are you showing? (minimum # of tabs is the # of "yes"es in this section)
  37. * @default 2
  38. *
  39. * @param Show Consumables
  40. * @desc yes/no: Show a tab for consumable items?
  41. * @default yes
  42. *
  43. * @param Show Key Items
  44. * @desc yes/no: Show a tab for key items?
  45. * @default yes
  46. *
  47. * @param Show Weapons
  48. * @desc yes/no: Show a tab for weapons?
  49. * @default no
  50. *
  51. * @param Show Armors
  52. * @desc yes/no: Show a tab for armors?
  53. * @default no
  54. *
  55. * @param Description Placement
  56. * @desc Where should the description window be placed? 0 = top, 1 = middle, 2 = bottom.
  57. * @default 0
  58. *
  59. * @param ---Gold Window---
  60. * @desc  
  61. * @default
  62. *
  63. * @param Show Gold Window
  64. * @desc yes/no: Should the gold window be shown in the item menu?
  65. * @default yes
  66. *
  67. * @param Gold Window Position
  68. * @desc left/right: Where should it be shown?
  69. * @default left
  70. *
  71. * @param Gold Window Width
  72. * @desc How wide should the gold window be? (in pixels- 240 is default.)
  73. * @default 240
  74. *
  75. * @param ---Backgrounds---
  76. * @desc
  77. * @default
  78. *
  79. * @param Item Screen BG
  80. * @desc Background of the items screen. If undefined, is black. PNG file must be in /img/pictures.
  81. * @default
  82. *
  83. * @param Equip Screen BG
  84. * @desc Background of the equip screen. If undefined, is black. PNG file must be in /img/pictures.
  85. * @default
  86. *
  87. * @param Status Screen BG
  88. * @desc Background of the equip screen. If undefined, is black. PNG file must be in /img/pictures.
  89. * @default
  90. *
  91. * @param Save Screen BG
  92. * @desc Background of the save screen. If undefined, is black. PNG file must be in /img/pictures.
  93. * @default
  94. *
  95. * @param Load Screen BG
  96. * @desc Background of the load screen. If undefined, is black. PNG file must be in /img/pictures.
  97. * @default
  98. *
  99. * @param Options Screen BG
  100. * @desc Background of the options screen. If undefined, is black. PNG file must be in /img/pictures.
  101. * @default
  102. *
  103. * @help
  104. * ----------------------------------------------------------------------------
  105. *   Non-Combat Menu v1.01 by mjshi
  106. *   Free for both commercial and non-commercial use, with credit.
  107. * ----------------------------------------------------------------------------
  108. *
  109. * > Update v1.0b
  110. * - Added support for Yanfly Item Core (place the NonCombatMenu below it)
  111. *
  112. * > Update v1.01
  113. * - Added support for backgrounds.
  114. *
  115. * > Update v1.01a
  116. * - Made it so backgrounds actually work and didn't error xD
  117. *
  118. * > Is something broken? Go to http://mjshi.weebly.com/contact.html and I'll
  119. *   try my best to help you!
  120. *
  121. */

  122. NCMenu.Parameters = PluginManager.parameters('NonCombatMenu');
  123. NCMenu.menuList = (String(NCMenu.Parameters['Menu Order'])).split(", ");
  124. for (var i = 0; i < NCMenu.menuList.length; i++) {
  125.   NCMenu.menuList[i] = NCMenu.menuList[i].split(": ");
  126. }
  127. NCMenu.backgroundImage = (String(NCMenu.Parameters['Background Image'])).replace(".png", "");
  128. NCMenu.persistentBG = (String(NCMenu.Parameters['Persistent Background']) == "yes");
  129. NCMenu.menuDim = Number(NCMenu.Parameters['Menu Background Opacity']);

  130. NCMenu.tabsShown = Number(NCMenu.Parameters['Number of Tabs']);
  131. NCMenu.showConsumables = (String(NCMenu.Parameters['Show Consumables']) == "yes");
  132. NCMenu.showKeyItems = (String(NCMenu.Parameters['Show Key Items']) == "yes");
  133. NCMenu.showWeapons = (String(NCMenu.Parameters['Show Weapons']) == "yes");
  134. NCMenu.showArmors = (String(NCMenu.Parameters['Show Armors']) == "yes");
  135. NCMenu.descrPlacement = Number(NCMenu.Parameters['Description Placement']);

  136. NCMenu.showGoldWindow = (String(NCMenu.Parameters['Show Gold Window']) == "yes");
  137. NCMenu.goldWindowAlignRight = (String(NCMenu.Parameters['Gold Window Position']) == "right");
  138. NCMenu.goldWindowWidth = Number(NCMenu.Parameters['Gold Window Width']);

  139. NCMenu.itemBG = (String(NCMenu.Parameters['Item Screen BG'])).replace(".png", "");
  140. NCMenu.equipBG = (String(NCMenu.Parameters['Equip Screen BG'])).replace(".png", "");
  141. NCMenu.statusBG = (String(NCMenu.Parameters['Status Screen BG'])).replace(".png", "");
  142. NCMenu.saveBG = (String(NCMenu.Parameters['Save Screen BG'])).replace(".png", "");
  143. NCMenu.loadBG = (String(NCMenu.Parameters['Load Screen BG'])).replace(".png", "");
  144. NCMenu.optionsBG = (String(NCMenu.Parameters['Options Screen BG'])).replace(".png", "");

  145. //=============================================================================
  146. // Scene_NCMenu
  147. //=============================================================================

  148. function Scene_NCMenu() {
  149.     this.initialize.apply(this, arguments);
  150. }

  151. Scene_NCMenu.prototype = Object.create(Scene_MenuBase.prototype);
  152. Scene_NCMenu.prototype.constructor = Scene_NCMenu;

  153. Scene_NCMenu.prototype.initialize = function() {
  154.     Scene_MenuBase.prototype.initialize.call(this);
  155. };

  156. Scene_NCMenu.prototype.create = function() {
  157.     Scene_MenuBase.prototype.create.call(this);
  158.     this.createCommandWindow();
  159.     this.createInvisibleFormationWindow();
  160. };

  161. Scene_NCMenu.prototype.stop = function() {
  162.     Scene_MenuBase.prototype.stop.call(this);
  163.     this._commandWindow.close();
  164. };

  165. Scene_NCMenu.prototype.createBackground = function() {
  166.     Scene_MenuBase.prototype.createBackground.call(this);
  167.     if (NCMenu.backgroundImage) {
  168.         this._background = new Sprite(ImageManager.loadPicture(NCMenu.backgroundImage));
  169.         this._background.opacity = NCMenu.menuDim;
  170.         this.addChild(this._background);
  171.     }
  172.     else {
  173.         this.setBackgroundOpacity(NCMenu.menuDim)
  174.     }
  175. };

  176. Scene_NCMenu.prototype.createCommandWindow = function() {
  177.     this._commandWindow = new Window_NCMenu();
  178.     var method;

  179.     for (var i = 0; i < NCMenu.menuList.length; i++) {
  180.       method = NCMenu.menuList[i][1];
  181.       if (method == 'cancel') {continue}
  182.       this._commandWindow.setHandler(method, eval(String("this.command" + method.charAt(0).toUpperCase() + method.slice(1) + ".bind(this)")));
  183.     }

  184.     this._commandWindow.setHandler('cancel', this.popScene.bind(this));
  185.     this.addWindow(this._commandWindow);
  186. };

  187. Scene_NCMenu.prototype.createInvisibleFormationWindow = function() {
  188.     this._statusWindow = new Window_MenuStatus((Graphics.boxWidth - Window_MenuStatus.prototype.windowWidth()) / 2, 0);
  189.     this._statusWindow.hide();
  190.     this._statusWindow.deactivate();
  191.     this.addWindow(this._statusWindow);
  192. };


  193. Scene_NCMenu.prototype.commandItem = function() {
  194.     SceneManager.push(Scene_Item);
  195. };
  196. if (NCMenu.persistentBG) {
  197.     Scene_Item.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  198. }
  199. else {
  200.     Scene_Item.prototype.createBackground = function() {
  201.             Scene_MenuBase.prototype.createBackground.call(this);
  202.             if (NCMenu.itemBG) {
  203.                     console.log("has run");
  204.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.itemBG));
  205.                 this._background.opacity = NCMenu.menuDim;
  206.                 this.addChild(this._background);
  207.             }
  208.             else {
  209.                     console.log("hasn't run");
  210.                 this.setBackgroundOpacity(NCMenu.menuDim)
  211.             }
  212.     }
  213. }

  214. Scene_NCMenu.prototype.commandEquip = function() {
  215.     SceneManager.push(Scene_Equip);
  216. };
  217. if (NCMenu.persistentBG) {
  218.     Scene_Equip.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  219. }
  220. else {
  221.     Scene_Equip.prototype.createBackground = function() {
  222.             Scene_MenuBase.prototype.createBackground.call(this);
  223.             if (NCMenu.equipBG) {
  224.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.equipBG));
  225.                 this._background.opacity = NCMenu.menuDim;
  226.                 this.addChild(this._background);
  227.             }
  228.             else {
  229.                 this.setBackgroundOpacity(NCMenu.menuDim)
  230.             }
  231.     }
  232. }

  233. Scene_NCMenu.prototype.commandStatus = function() {
  234.     SceneManager.push(Scene_Status);
  235. };
  236. if (NCMenu.persistentBG) {
  237.     Scene_Status.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  238. }
  239. else {
  240.     Scene_Status.prototype.createBackground = function() {
  241.             Scene_MenuBase.prototype.createBackground.call(this);
  242.             if (NCMenu.statusBG) {
  243.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.statusBG));
  244.                 this._background.opacity = NCMenu.menuDim;
  245.                 this.addChild(this._background);
  246.             }
  247.             else {
  248.                 this.setBackgroundOpacity(NCMenu.menuDim)
  249.             }
  250.     }
  251. }


  252. Scene_NCMenu.prototype.commandQuest = function() {
  253.     SceneManager.push(Scene_Quest);
  254. };

  255. Scene_NCMenu.prototype.commandSave = function() {
  256.     SceneManager.push(Scene_Save);
  257. };
  258. if (NCMenu.persistentBG) {
  259.     Scene_Save.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  260. }
  261. else {
  262.     Scene_Save.prototype.createBackground = function() {
  263.             Scene_MenuBase.prototype.createBackground.call(this);
  264.             if (NCMenu.saveBG) {
  265.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.saveBG));
  266.                 this._background.opacity = NCMenu.menuDim;
  267.                 this.addChild(this._background);
  268.             }
  269.             else {
  270.                 this.setBackgroundOpacity(NCMenu.menuDim)
  271.             }
  272.     }
  273. }


  274. Scene_NCMenu.prototype.commandOptions = function() {
  275.     SceneManager.push(Scene_Options);
  276. };
  277. if (NCMenu.persistentBG) {
  278.     Scene_Options.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  279. }
  280. else {
  281.     Scene_Options.prototype.createBackground = function() {
  282.             Scene_MenuBase.prototype.createBackground.call(this);
  283.             if (NCMenu.optionsBG) {
  284.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.optionsBG));
  285.                 this._background.opacity = NCMenu.menuDim;
  286.                 this.addChild(this._background);
  287.             }
  288.             else {
  289.                 this.setBackgroundOpacity(NCMenu.menuDim)
  290.             }
  291.     }
  292. }

  293. Scene_NCMenu.prototype.commandToTitle = function() {
  294.     this.fadeOutAll();
  295.     SceneManager.goto(Scene_Title);
  296. };


  297. Scene_NCMenu.prototype.commandLoad = function() {
  298.     SceneManager.push(Scene_Load);
  299. };
  300. if (NCMenu.persistentBG) {
  301.     Scene_Load.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  302. }
  303. else {
  304.     Scene_Load.prototype.createBackground = function() {
  305.             Scene_MenuBase.prototype.createBackground.call(this);
  306.             if (NCMenu.loadBG) {
  307.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.loadBG));
  308.                 this._background.opacity = NCMenu.menuDim;
  309.                 this.addChild(this._background);
  310.             }
  311.             else {
  312.                 this.setBackgroundOpacity(NCMenu.menuDim)
  313.             }
  314.     }
  315. }

  316. Scene_NCMenu.prototype.commandFormation = function() {
  317.     this._commandWindow.hide();
  318.     this._commandWindow.deactivate();
  319.     this._statusWindow.setFormationMode(true);
  320.     this._statusWindow.selectLast();
  321.     this._statusWindow.show();
  322.     this._statusWindow.activate();
  323.     this._statusWindow.setHandler('ok',     this.onFormationOk.bind(this));
  324.     this._statusWindow.setHandler('cancel', this.onFormationCancel.bind(this));
  325. };

  326. Scene_NCMenu.prototype.onFormationOk = function() {
  327.     var index = this._statusWindow.index();
  328.     var actor = $gameParty.members()[index];
  329.     var pendingIndex = this._statusWindow.pendingIndex();
  330.     if (pendingIndex >= 0) {
  331.         $gameParty.swapOrder(index, pendingIndex);
  332.         this._statusWindow.setPendingIndex(-1);
  333.         this._statusWindow.redrawItem(index);
  334.     } else {
  335.         this._statusWindow.setPendingIndex(index);
  336.     }
  337.     this._statusWindow.activate();
  338. };

  339. Scene_NCMenu.prototype.onFormationCancel = function() {
  340.     if (this._statusWindow.pendingIndex() >= 0) {
  341.         this._statusWindow.setPendingIndex(-1);
  342.         this._statusWindow.activate();
  343.     } else {
  344.         this._statusWindow.deselect();
  345.         this._statusWindow.hide();
  346.         this._commandWindow.show();
  347.         this._commandWindow.activate();
  348.     }
  349. };

  350. //=============================================================================
  351. // Window_NCMenu
  352. //=============================================================================

  353. function Window_NCMenu() {
  354.     this.initialize.apply(this, arguments);
  355. }

  356. Window_NCMenu.prototype = Object.create(Window_Command.prototype);
  357. Window_NCMenu.prototype.constructor = Window_NCMenu;

  358. Window_NCMenu.prototype.initialize = function() {
  359.     Window_Command.prototype.initialize.call(this, 0, 0);
  360.     this.updatePlacement();
  361.     this.openness = 0;
  362.     this.open();
  363. };

  364. Window_NCMenu.prototype.windowWidth = function() {
  365.     return 240;
  366. };

  367. Window_NCMenu.prototype.updatePlacement = function() {
  368.     this.x = (Graphics.boxWidth - this.width) / 2;
  369.     this.y = (Graphics.boxHeight - this.height) / 2;
  370. };

  371. Window_NCMenu.prototype.makeCommandList = function() {
  372.     for (var i = 0; i < NCMenu.menuList.length; i++) {
  373.       this.addCommand(NCMenu.menuList[i][0], NCMenu.menuList[i][1]);
  374.     }
  375. };

  376. //=============================================================================
  377. // Scene_Map - changed to call NCMenu rather than original menu screen
  378. //=============================================================================

  379. Scene_Map.prototype.callMenu = function() {
  380.     SoundManager.playOk();
  381.     SceneManager.push(Scene_NCMenu);
  382.     Window_MenuCommand.initCommandPosition();
  383.     $gameTemp.clearDestination();
  384.     this._mapNameWindow.hide();
  385.     this._waitCount = 2;
  386. };


  387. if (!Imported.YEP_ItemCore) {

  388. //=============================================================================
  389. // Window_ItemCategory - changed to accept NCMenu parameters
  390. //=============================================================================

  391. Window_ItemCategory.prototype.windowWidth = function() {
  392.     if (NCMenu.showGoldWindow) {
  393.       return Graphics.boxWidth - NCMenu.goldWindowWidth;
  394.     } else {
  395.       return Graphics.boxWidth;
  396.     }
  397. };

  398. Window_ItemCategory.prototype.maxCols = function() {
  399.     return NCMenu.tabsShown;
  400. };

  401. Window_ItemCategory.prototype.makeCommandList = function() {
  402.     if (NCMenu.showConsumables) {this.addCommand(TextManager.item, 'item')}
  403.     if (NCMenu.showWeapons) {this.addCommand(TextManager.weapon,   'weapon')}
  404.     if (NCMenu.showArmors) {this.addCommand(TextManager.armor,     'armor')}
  405.     if (NCMenu.showKeyItems) {this.addCommand(TextManager.keyItem, 'keyItem')}
  406. };

  407. //=============================================================================
  408. // Window_Gold - changed to accept NCMenu parameters
  409. //=============================================================================

  410. Window_Gold.prototype.windowWidth = function() {
  411.     return NCMenu.goldWindowWidth;
  412. };

  413. //=============================================================================
  414. // Scene_Item - changed to accept NCMenu parameters
  415. //=============================================================================

  416. Scene_Item.prototype.create = function() {
  417.     Scene_ItemBase.prototype.create.call(this);
  418.     this.createHelpWindow();
  419.     if (NCMenu.showGoldWindow) {this.createGoldWindow()}
  420.     this.createCategoryWindow();
  421.     this.createItemWindow();
  422.     this.createActorWindow();
  423. };

  424. Scene_Item.prototype.createCategoryWindow = function() {
  425.     this._categoryWindow = new Window_ItemCategory();
  426.     this._categoryWindow.setHelpWindow(this._helpWindow);

  427.     if (NCMenu.showGoldWindow && !NCMenu.goldWindowAlignRight) {this._categoryWindow.x = NCMenu.goldWindowWidth}

  428.     if (NCMenu.descrPlacement == 1) {
  429.       this._helpWindow.y = this._categoryWindow.height;
  430.     }
  431.       else if (NCMenu.descrPlacement == 2) {
  432.         this._helpWindow.y = Graphics.boxHeight - this._helpWindow.height;
  433.       }
  434.         else {
  435.           if (NCMenu.showGoldWindow) {this._goldWindow.y = this._helpWindow.height}
  436.           this._categoryWindow.y = this._helpWindow.height;
  437.         }

  438.     this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
  439.     this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
  440.     this.addWindow(this._categoryWindow);
  441. };

  442. Scene_Item.prototype.createItemWindow = function() {
  443.     if (NCMenu.descrPlacement == 1) {
  444.       wy = this._categoryWindow.y + this._categoryWindow.height + this._helpWindow.height;
  445.     }
  446.       else if (NCMenu.descrPlacement == 2) {
  447.         wy = this._categoryWindow.height + this._helpWindow.height;
  448.       } else {
  449.           wy = this._categoryWindow.y + this._categoryWindow.height;
  450.         }

  451.     var wh = Graphics.boxHeight - wy;
  452.     this._itemWindow = new Window_ItemList(0, wy, Graphics.boxWidth, wh);

  453.     if (NCMenu.descrPlacement == 2) {this._itemWindow.y = this._categoryWindow.height};
  454.    
  455.     this._itemWindow.setHelpWindow(this._helpWindow);
  456.     this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
  457.     this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
  458.     this.addWindow(this._itemWindow);
  459.     this._categoryWindow.setItemWindow(this._itemWindow);
  460. };

  461. Scene_Item.prototype.createGoldWindow = function() {
  462.     this._goldWindow = new Window_Gold(0, 0);
  463.     if (NCMenu.goldWindowAlignRight) {this._goldWindow.x = Graphics.boxWidth - NCMenu.goldWindowWidth}
  464.     this.addWindow(this._goldWindow);
  465. };

  466. };

  467. //=============================================================================
  468. // Window_Status - Streamlined
  469. //=============================================================================

  470. Window_Status.prototype.initialize = function() {
  471.     var width = 440;
  472.     var height = 180;
  473.     Window_Selectable.prototype.initialize.call(this, (Graphics.boxWidth - width) / 2, (Graphics.boxHeight - height) / 2, width, height);
  474.     this.refresh();
  475.     this.activate();
  476. };

  477. Window_Status.prototype.refresh = function() {
  478.     this.contents.clear();
  479.     if (this._actor) {
  480.         var lineHeight = this.lineHeight();
  481.         this.drawBlock2(0);
  482.     }
  483. };

  484. Window_Status.prototype.drawBlock2 = function(y) {
  485.     this.drawActorFace(this._actor, 12, y);
  486.     this.drawBasicInfo(204, y);
  487.     this.drawExpInfo(456, y);
  488. };

  489. Window_Status.prototype.drawBasicInfo = function(x, y) {
  490.     var lineHeight = this.lineHeight();
  491.     this.drawActorName(this._actor, x, y + lineHeight * 0.5);
  492.     this.drawActorHp(this._actor, x, y + lineHeight * 1.5);
  493.     this.drawActorMp(this._actor, x, y + lineHeight * 2.5);
  494. };
复制代码
梦石
0
星屑
188
在线时间
39 小时
注册时间
2020-5-24
回帖
15
 楼主| 发表于 2020-6-13 14:21:43 | 显示全部楼层
捞一下_(:з)∠)_
回复

使用道具 举报

梦石
0
星屑
1343
在线时间
153 小时
注册时间
2020-4-26
回帖
146
发表于 2020-6-13 19:04:31 | 显示全部楼层
  1. NCMenu.backgroundImage = "背景圖片名字";
复制代码

点评

成功了,十分感谢!  发表于 2020-6-14 06:02
回复 1 0

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部