Project1

标题: [已解决]如何在菜单背景中添加开关/变数操控的图片 [打印本页]

作者: emshupisim    时间: 2020-6-11 17:15
标题: [已解决]如何在菜单背景中添加开关/变数操控的图片
本帖最后由 emshupisim 于 2020-6-14 06:03 编辑

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

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

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

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


JAVASCRIPT 代码复制
  1. //=============================================================================
  2. // NonCombatMenu.js
  3. //=============================================================================
  4.  
  5. var Imported = Imported || {};
  6. Imported.NonCombatMenu = true;
  7.  
  8. var NCMenu = NCMenu || {};
  9.  
  10. /*:
  11.  * @plugindesc Fully customizable menu geared toward less battle-oriented games.
  12.  * @author mjshi
  13.  *
  14.  * @param ---Main Menu---
  15.  * @desc  
  16.  * @default
  17.  *
  18.  * @param Menu Order
  19.  * @desc Format is "Name: keyword". Keywords: item equip status formation save load options toTitle cancel quest
  20.  * @default Item: item, Status: status, Save: save, Quit: toTitle
  21.  *
  22.  * @param Background Image
  23.  * @desc Background image of the main menu. If undefined, is black. PNG file must be in /img/pictures.
  24.  * @default
  25.  *
  26.  * @param Persistent Background
  27.  * @desc yes/no: Background image persists throughout all the sub-menus.
  28.  * @default no
  29.  *
  30.  * @param Menu Background Opacity
  31.  * @desc Ranges from 0 to 255. 0 for opaque, 255 for transparent.
  32.  * @default 128
  33.  *
  34.  * @param ---Item Menu---
  35.  * @desc
  36.  * @default
  37.  *
  38.  * @param Number of Tabs
  39.  * @desc How many tabs are you showing? (minimum # of tabs is the # of "yes"es in this section)
  40.  * @default 2
  41.  *
  42.  * @param Show Consumables
  43.  * @desc yes/no: Show a tab for consumable items?
  44.  * @default yes
  45.  *
  46.  * @param Show Key Items
  47.  * @desc yes/no: Show a tab for key items?
  48.  * @default yes
  49.  *
  50.  * @param Show Weapons
  51.  * @desc yes/no: Show a tab for weapons?
  52.  * @default no
  53.  *
  54.  * @param Show Armors
  55.  * @desc yes/no: Show a tab for armors?
  56.  * @default no
  57.  *
  58.  * @param Description Placement
  59.  * @desc Where should the description window be placed? 0 = top, 1 = middle, 2 = bottom.
  60.  * @default 0
  61.  *
  62.  * @param ---Gold Window---
  63.  * @desc  
  64.  * @default
  65.  *
  66.  * @param Show Gold Window
  67.  * @desc yes/no: Should the gold window be shown in the item menu?
  68.  * @default yes
  69.  *
  70.  * @param Gold Window Position
  71.  * @desc left/right: Where should it be shown?
  72.  * @default left
  73.  *
  74.  * @param Gold Window Width
  75.  * @desc How wide should the gold window be? (in pixels- 240 is default.)
  76.  * @default 240
  77.  *
  78.  * @param ---Backgrounds---
  79.  * @desc
  80.  * @default
  81.  *
  82.  * @param Item Screen BG
  83.  * @desc Background of the items screen. If undefined, is black. PNG file must be in /img/pictures.
  84.  * @default
  85.  *
  86.  * @param Equip Screen BG
  87.  * @desc Background of the equip screen. If undefined, is black. PNG file must be in /img/pictures.
  88.  * @default
  89.  *
  90.  * @param Status Screen BG
  91.  * @desc Background of the equip screen. If undefined, is black. PNG file must be in /img/pictures.
  92.  * @default
  93.  *
  94.  * @param Save Screen BG
  95.  * @desc Background of the save screen. If undefined, is black. PNG file must be in /img/pictures.
  96.  * @default
  97.  *
  98.  * @param Load Screen BG
  99.  * @desc Background of the load screen. If undefined, is black. PNG file must be in /img/pictures.
  100.  * @default
  101.  *
  102.  * @param Options Screen BG
  103.  * @desc Background of the options screen. If undefined, is black. PNG file must be in /img/pictures.
  104.  * @default
  105.  *
  106.  * @help
  107.  * ----------------------------------------------------------------------------
  108.  *   Non-Combat Menu v1.01 by mjshi
  109.  *   Free for both commercial and non-commercial use, with credit.
  110.  * ----------------------------------------------------------------------------
  111.  *
  112.  * > Update v1.0b
  113.  * - Added support for Yanfly Item Core (place the NonCombatMenu below it)
  114.  *
  115.  * > Update v1.01
  116.  * - Added support for backgrounds.
  117.  *
  118.  * > Update v1.01a
  119.  * - Made it so backgrounds actually work and didn't error xD
  120.  *
  121.  * > Is something broken? Go to http://mjshi.weebly.com/contact.html and I'll
  122.  *   try my best to help you!
  123.  *
  124.  */
  125.  
  126. NCMenu.Parameters = PluginManager.parameters('NonCombatMenu');
  127. NCMenu.menuList = (String(NCMenu.Parameters['Menu Order'])).split(", ");
  128. for (var i = 0; i < NCMenu.menuList.length; i++) {
  129.   NCMenu.menuList[i] = NCMenu.menuList[i].split(": ");
  130. }
  131. NCMenu.backgroundImage = (String(NCMenu.Parameters['Background Image'])).replace(".png", "");
  132. NCMenu.persistentBG = (String(NCMenu.Parameters['Persistent Background']) == "yes");
  133. NCMenu.menuDim = Number(NCMenu.Parameters['Menu Background Opacity']);
  134.  
  135. NCMenu.tabsShown = Number(NCMenu.Parameters['Number of Tabs']);
  136. NCMenu.showConsumables = (String(NCMenu.Parameters['Show Consumables']) == "yes");
  137. NCMenu.showKeyItems = (String(NCMenu.Parameters['Show Key Items']) == "yes");
  138. NCMenu.showWeapons = (String(NCMenu.Parameters['Show Weapons']) == "yes");
  139. NCMenu.showArmors = (String(NCMenu.Parameters['Show Armors']) == "yes");
  140. NCMenu.descrPlacement = Number(NCMenu.Parameters['Description Placement']);
  141.  
  142. NCMenu.showGoldWindow = (String(NCMenu.Parameters['Show Gold Window']) == "yes");
  143. NCMenu.goldWindowAlignRight = (String(NCMenu.Parameters['Gold Window Position']) == "right");
  144. NCMenu.goldWindowWidth = Number(NCMenu.Parameters['Gold Window Width']);
  145.  
  146. NCMenu.itemBG = (String(NCMenu.Parameters['Item Screen BG'])).replace(".png", "");
  147. NCMenu.equipBG = (String(NCMenu.Parameters['Equip Screen BG'])).replace(".png", "");
  148. NCMenu.statusBG = (String(NCMenu.Parameters['Status Screen BG'])).replace(".png", "");
  149. NCMenu.saveBG = (String(NCMenu.Parameters['Save Screen BG'])).replace(".png", "");
  150. NCMenu.loadBG = (String(NCMenu.Parameters['Load Screen BG'])).replace(".png", "");
  151. NCMenu.optionsBG = (String(NCMenu.Parameters['Options Screen BG'])).replace(".png", "");
  152.  
  153. //=============================================================================
  154. // Scene_NCMenu
  155. //=============================================================================
  156.  
  157. function Scene_NCMenu() {
  158.     this.initialize.apply(this, arguments);
  159. }
  160.  
  161. Scene_NCMenu.prototype = Object.create(Scene_MenuBase.prototype);
  162. Scene_NCMenu.prototype.constructor = Scene_NCMenu;
  163.  
  164. Scene_NCMenu.prototype.initialize = function() {
  165.     Scene_MenuBase.prototype.initialize.call(this);
  166. };
  167.  
  168. Scene_NCMenu.prototype.create = function() {
  169.     Scene_MenuBase.prototype.create.call(this);
  170.     this.createCommandWindow();
  171.     this.createInvisibleFormationWindow();
  172. };
  173.  
  174. Scene_NCMenu.prototype.stop = function() {
  175.     Scene_MenuBase.prototype.stop.call(this);
  176.     this._commandWindow.close();
  177. };
  178.  
  179. Scene_NCMenu.prototype.createBackground = function() {
  180.     Scene_MenuBase.prototype.createBackground.call(this);
  181.     if (NCMenu.backgroundImage) {
  182.         this._background = new Sprite(ImageManager.loadPicture(NCMenu.backgroundImage));
  183.         this._background.opacity = NCMenu.menuDim;
  184.         this.addChild(this._background);
  185.     }
  186.     else {
  187.         this.setBackgroundOpacity(NCMenu.menuDim)
  188.     }
  189. };
  190.  
  191. Scene_NCMenu.prototype.createCommandWindow = function() {
  192.     this._commandWindow = new Window_NCMenu();
  193.     var method;
  194.  
  195.     for (var i = 0; i < NCMenu.menuList.length; i++) {
  196.       method = NCMenu.menuList[i][1];
  197.       if (method == 'cancel') {continue}
  198.       this._commandWindow.setHandler(method, eval(String("this.command" + method.charAt(0).toUpperCase() + method.slice(1) + ".bind(this)")));
  199.     }
  200.  
  201.     this._commandWindow.setHandler('cancel', this.popScene.bind(this));
  202.     this.addWindow(this._commandWindow);
  203. };
  204.  
  205. Scene_NCMenu.prototype.createInvisibleFormationWindow = function() {
  206.     this._statusWindow = new Window_MenuStatus((Graphics.boxWidth - Window_MenuStatus.prototype.windowWidth()) / 2, 0);
  207.     this._statusWindow.hide();
  208.     this._statusWindow.deactivate();
  209.     this.addWindow(this._statusWindow);
  210. };
  211.  
  212.  
  213. Scene_NCMenu.prototype.commandItem = function() {
  214.     SceneManager.push(Scene_Item);
  215. };
  216. if (NCMenu.persistentBG) {
  217.     Scene_Item.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  218. }
  219. else {
  220.     Scene_Item.prototype.createBackground = function() {
  221.             Scene_MenuBase.prototype.createBackground.call(this);
  222.             if (NCMenu.itemBG) {
  223.                     console.log("has run");
  224.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.itemBG));
  225.                 this._background.opacity = NCMenu.menuDim;
  226.                 this.addChild(this._background);
  227.             }
  228.             else {
  229.                     console.log("hasn't run");
  230.                 this.setBackgroundOpacity(NCMenu.menuDim)
  231.             }
  232.     }
  233. }
  234.  
  235. Scene_NCMenu.prototype.commandEquip = function() {
  236.     SceneManager.push(Scene_Equip);
  237. };
  238. if (NCMenu.persistentBG) {
  239.     Scene_Equip.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  240. }
  241. else {
  242.     Scene_Equip.prototype.createBackground = function() {
  243.             Scene_MenuBase.prototype.createBackground.call(this);
  244.             if (NCMenu.equipBG) {
  245.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.equipBG));
  246.                 this._background.opacity = NCMenu.menuDim;
  247.                 this.addChild(this._background);
  248.             }
  249.             else {
  250.                 this.setBackgroundOpacity(NCMenu.menuDim)
  251.             }
  252.     }
  253. }
  254.  
  255. Scene_NCMenu.prototype.commandStatus = function() {
  256.     SceneManager.push(Scene_Status);
  257. };
  258. if (NCMenu.persistentBG) {
  259.     Scene_Status.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  260. }
  261. else {
  262.     Scene_Status.prototype.createBackground = function() {
  263.             Scene_MenuBase.prototype.createBackground.call(this);
  264.             if (NCMenu.statusBG) {
  265.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.statusBG));
  266.                 this._background.opacity = NCMenu.menuDim;
  267.                 this.addChild(this._background);
  268.             }
  269.             else {
  270.                 this.setBackgroundOpacity(NCMenu.menuDim)
  271.             }
  272.     }
  273. }
  274.  
  275.  
  276. Scene_NCMenu.prototype.commandQuest = function() {
  277.     SceneManager.push(Scene_Quest);
  278. };
  279.  
  280. Scene_NCMenu.prototype.commandSave = function() {
  281.     SceneManager.push(Scene_Save);
  282. };
  283. if (NCMenu.persistentBG) {
  284.     Scene_Save.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  285. }
  286. else {
  287.     Scene_Save.prototype.createBackground = function() {
  288.             Scene_MenuBase.prototype.createBackground.call(this);
  289.             if (NCMenu.saveBG) {
  290.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.saveBG));
  291.                 this._background.opacity = NCMenu.menuDim;
  292.                 this.addChild(this._background);
  293.             }
  294.             else {
  295.                 this.setBackgroundOpacity(NCMenu.menuDim)
  296.             }
  297.     }
  298. }
  299.  
  300.  
  301. Scene_NCMenu.prototype.commandOptions = function() {
  302.     SceneManager.push(Scene_Options);
  303. };
  304. if (NCMenu.persistentBG) {
  305.     Scene_Options.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  306. }
  307. else {
  308.     Scene_Options.prototype.createBackground = function() {
  309.             Scene_MenuBase.prototype.createBackground.call(this);
  310.             if (NCMenu.optionsBG) {
  311.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.optionsBG));
  312.                 this._background.opacity = NCMenu.menuDim;
  313.                 this.addChild(this._background);
  314.             }
  315.             else {
  316.                 this.setBackgroundOpacity(NCMenu.menuDim)
  317.             }
  318.     }
  319. }
  320.  
  321. Scene_NCMenu.prototype.commandToTitle = function() {
  322.     this.fadeOutAll();
  323.     SceneManager.goto(Scene_Title);
  324. };
  325.  
  326.  
  327. Scene_NCMenu.prototype.commandLoad = function() {
  328.     SceneManager.push(Scene_Load);
  329. };
  330. if (NCMenu.persistentBG) {
  331.     Scene_Load.prototype.createBackground = Scene_NCMenu.prototype.createBackground
  332. }
  333. else {
  334.     Scene_Load.prototype.createBackground = function() {
  335.             Scene_MenuBase.prototype.createBackground.call(this);
  336.             if (NCMenu.loadBG) {
  337.                 this._background = new Sprite(ImageManager.loadPicture(NCMenu.loadBG));
  338.                 this._background.opacity = NCMenu.menuDim;
  339.                 this.addChild(this._background);
  340.             }
  341.             else {
  342.                 this.setBackgroundOpacity(NCMenu.menuDim)
  343.             }
  344.     }
  345. }
  346.  
  347. Scene_NCMenu.prototype.commandFormation = function() {
  348.     this._commandWindow.hide();
  349.     this._commandWindow.deactivate();
  350.     this._statusWindow.setFormationMode(true);
  351.     this._statusWindow.selectLast();
  352.     this._statusWindow.show();
  353.     this._statusWindow.activate();
  354.     this._statusWindow.setHandler('ok',     this.onFormationOk.bind(this));
  355.     this._statusWindow.setHandler('cancel', this.onFormationCancel.bind(this));
  356. };
  357.  
  358. Scene_NCMenu.prototype.onFormationOk = function() {
  359.     var index = this._statusWindow.index();
  360.     var actor = $gameParty.members()[index];
  361.     var pendingIndex = this._statusWindow.pendingIndex();
  362.     if (pendingIndex >= 0) {
  363.         $gameParty.swapOrder(index, pendingIndex);
  364.         this._statusWindow.setPendingIndex(-1);
  365.         this._statusWindow.redrawItem(index);
  366.     } else {
  367.         this._statusWindow.setPendingIndex(index);
  368.     }
  369.     this._statusWindow.activate();
  370. };
  371.  
  372. Scene_NCMenu.prototype.onFormationCancel = function() {
  373.     if (this._statusWindow.pendingIndex() >= 0) {
  374.         this._statusWindow.setPendingIndex(-1);
  375.         this._statusWindow.activate();
  376.     } else {
  377.         this._statusWindow.deselect();
  378.         this._statusWindow.hide();
  379.         this._commandWindow.show();
  380.         this._commandWindow.activate();
  381.     }
  382. };
  383.  
  384. //=============================================================================
  385. // Window_NCMenu
  386. //=============================================================================
  387.  
  388. function Window_NCMenu() {
  389.     this.initialize.apply(this, arguments);
  390. }
  391.  
  392. Window_NCMenu.prototype = Object.create(Window_Command.prototype);
  393. Window_NCMenu.prototype.constructor = Window_NCMenu;
  394.  
  395. Window_NCMenu.prototype.initialize = function() {
  396.     Window_Command.prototype.initialize.call(this, 0, 0);
  397.     this.updatePlacement();
  398.     this.openness = 0;
  399.     this.open();
  400. };
  401.  
  402. Window_NCMenu.prototype.windowWidth = function() {
  403.     return 240;
  404. };
  405.  
  406. Window_NCMenu.prototype.updatePlacement = function() {
  407.     this.x = (Graphics.boxWidth - this.width) / 2;
  408.     this.y = (Graphics.boxHeight - this.height) / 2;
  409. };
  410.  
  411. Window_NCMenu.prototype.makeCommandList = function() {
  412.     for (var i = 0; i < NCMenu.menuList.length; i++) {
  413.       this.addCommand(NCMenu.menuList[i][0], NCMenu.menuList[i][1]);
  414.     }
  415. };
  416.  
  417. //=============================================================================
  418. // Scene_Map - changed to call NCMenu rather than original menu screen
  419. //=============================================================================
  420.  
  421. Scene_Map.prototype.callMenu = function() {
  422.     SoundManager.playOk();
  423.     SceneManager.push(Scene_NCMenu);
  424.     Window_MenuCommand.initCommandPosition();
  425.     $gameTemp.clearDestination();
  426.     this._mapNameWindow.hide();
  427.     this._waitCount = 2;
  428. };
  429.  
  430.  
  431. if (!Imported.YEP_ItemCore) {
  432.  
  433. //=============================================================================
  434. // Window_ItemCategory - changed to accept NCMenu parameters
  435. //=============================================================================
  436.  
  437. Window_ItemCategory.prototype.windowWidth = function() {
  438.     if (NCMenu.showGoldWindow) {
  439.       return Graphics.boxWidth - NCMenu.goldWindowWidth;
  440.     } else {
  441.       return Graphics.boxWidth;
  442.     }
  443. };
  444.  
  445. Window_ItemCategory.prototype.maxCols = function() {
  446.     return NCMenu.tabsShown;
  447. };
  448.  
  449. Window_ItemCategory.prototype.makeCommandList = function() {
  450.     if (NCMenu.showConsumables) {this.addCommand(TextManager.item, 'item')}
  451.     if (NCMenu.showWeapons) {this.addCommand(TextManager.weapon,   'weapon')}
  452.     if (NCMenu.showArmors) {this.addCommand(TextManager.armor,     'armor')}
  453.     if (NCMenu.showKeyItems) {this.addCommand(TextManager.keyItem, 'keyItem')}
  454. };
  455.  
  456. //=============================================================================
  457. // Window_Gold - changed to accept NCMenu parameters
  458. //=============================================================================
  459.  
  460. Window_Gold.prototype.windowWidth = function() {
  461.     return NCMenu.goldWindowWidth;
  462. };
  463.  
  464. //=============================================================================
  465. // Scene_Item - changed to accept NCMenu parameters
  466. //=============================================================================
  467.  
  468. Scene_Item.prototype.create = function() {
  469.     Scene_ItemBase.prototype.create.call(this);
  470.     this.createHelpWindow();
  471.     if (NCMenu.showGoldWindow) {this.createGoldWindow()}
  472.     this.createCategoryWindow();
  473.     this.createItemWindow();
  474.     this.createActorWindow();
  475. };
  476.  
  477. Scene_Item.prototype.createCategoryWindow = function() {
  478.     this._categoryWindow = new Window_ItemCategory();
  479.     this._categoryWindow.setHelpWindow(this._helpWindow);
  480.  
  481.     if (NCMenu.showGoldWindow && !NCMenu.goldWindowAlignRight) {this._categoryWindow.x = NCMenu.goldWindowWidth}
  482.  
  483.     if (NCMenu.descrPlacement == 1) {
  484.       this._helpWindow.y = this._categoryWindow.height;
  485.     }
  486.       else if (NCMenu.descrPlacement == 2) {
  487.         this._helpWindow.y = Graphics.boxHeight - this._helpWindow.height;
  488.       }
  489.         else {
  490.           if (NCMenu.showGoldWindow) {this._goldWindow.y = this._helpWindow.height}
  491.           this._categoryWindow.y = this._helpWindow.height;
  492.         }
  493.  
  494.     this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
  495.     this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
  496.     this.addWindow(this._categoryWindow);
  497. };
  498.  
  499. Scene_Item.prototype.createItemWindow = function() {
  500.     if (NCMenu.descrPlacement == 1) {
  501.       wy = this._categoryWindow.y + this._categoryWindow.height + this._helpWindow.height;
  502.     }
  503.       else if (NCMenu.descrPlacement == 2) {
  504.         wy = this._categoryWindow.height + this._helpWindow.height;
  505.       } else {
  506.           wy = this._categoryWindow.y + this._categoryWindow.height;
  507.         }
  508.  
  509.     var wh = Graphics.boxHeight - wy;
  510.     this._itemWindow = new Window_ItemList(0, wy, Graphics.boxWidth, wh);
  511.  
  512.     if (NCMenu.descrPlacement == 2) {this._itemWindow.y = this._categoryWindow.height};
  513.  
  514.     this._itemWindow.setHelpWindow(this._helpWindow);
  515.     this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
  516.     this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
  517.     this.addWindow(this._itemWindow);
  518.     this._categoryWindow.setItemWindow(this._itemWindow);
  519. };
  520.  
  521. Scene_Item.prototype.createGoldWindow = function() {
  522.     this._goldWindow = new Window_Gold(0, 0);
  523.     if (NCMenu.goldWindowAlignRight) {this._goldWindow.x = Graphics.boxWidth - NCMenu.goldWindowWidth}
  524.     this.addWindow(this._goldWindow);
  525. };
  526.  
  527. };
  528.  
  529. //=============================================================================
  530. // Window_Status - Streamlined
  531. //=============================================================================
  532.  
  533. Window_Status.prototype.initialize = function() {
  534.     var width = 440;
  535.     var height = 180;
  536.     Window_Selectable.prototype.initialize.call(this, (Graphics.boxWidth - width) / 2, (Graphics.boxHeight - height) / 2, width, height);
  537.     this.refresh();
  538.     this.activate();
  539. };
  540.  
  541. Window_Status.prototype.refresh = function() {
  542.     this.contents.clear();
  543.     if (this._actor) {
  544.         var lineHeight = this.lineHeight();
  545.         this.drawBlock2(0);
  546.     }
  547. };
  548.  
  549. Window_Status.prototype.drawBlock2 = function(y) {
  550.     this.drawActorFace(this._actor, 12, y);
  551.     this.drawBasicInfo(204, y);
  552.     this.drawExpInfo(456, y);
  553. };
  554.  
  555. Window_Status.prototype.drawBasicInfo = function(x, y) {
  556.     var lineHeight = this.lineHeight();
  557.     this.drawActorName(this._actor, x, y + lineHeight * 0.5);
  558.     this.drawActorHp(this._actor, x, y + lineHeight * 1.5);
  559.     this.drawActorMp(this._actor, x, y + lineHeight * 2.5);
  560. };

作者: emshupisim    时间: 2020-6-13 14:21
捞一下_(:з)∠)_
作者: moonyoulove    时间: 2020-6-13 19:04
  1. NCMenu.backgroundImage = "背景圖片名字";
复制代码





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1