查看: 1799|回复: 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


[pre lang="javascript"]//=============================================================================
// NonCombatMenu.js
//=============================================================================

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

var NCMenu = NCMenu || {};

/*:
* @plugindesc Fully customizable menu geared toward less battle-oriented games.
* @author mjshi
*
* @param ---Main Menu---
* @desc  
* @default
*
* @param Menu Order
* @desc Format is "Name: keyword". Keywords: item equip status formation save load options toTitle cancel quest
* @default Item: item, Status: status, Save: save, Quit: toTitle
*
* @param Background Image
* @desc Background image of the main menu. If undefined, is black. PNG file must be in /img/pictures.
* @default
*
* @param Persistent Background
* @desc yes/no: Background image persists throughout all the sub-menus.
* @default no
*
* @param Menu Background Opacity
* @desc Ranges from 0 to 255. 0 for opaque, 255 for transparent.
* @default 128
*
* @param ---Item Menu---
* @desc
* @default
*
* @param Number of Tabs
* @desc How many tabs are you showing? (minimum # of tabs is the # of "yes"es in this section)
* @default 2
*
* @param Show Consumables
* @desc yes/no: Show a tab for consumable items?
* @default yes
*
* @param Show Key Items
* @desc yes/no: Show a tab for key items?
* @default yes
*
* @param Show Weapons
* @desc yes/no: Show a tab for weapons?
* @default no
*
* @param Show Armors
* @desc yes/no: Show a tab for armors?
* @default no
*
* @param Description Placement
* @desc Where should the description window be placed? 0 = top, 1 = middle, 2 = bottom.
* @default 0
*
* @param ---Gold Window---
* @desc  
* @default
*
* @param Show Gold Window
* @desc yes/no: Should the gold window be shown in the item menu?
* @default yes
*
* @param Gold Window Position
* @desc left/right: Where should it be shown?
* @default left
*
* @param Gold Window Width
* @desc How wide should the gold window be? (in pixels- 240 is default.)
* @default 240
*
* @param ---Backgrounds---
* @desc
* @default
*
* @param Item Screen BG
* @desc Background of the items screen. If undefined, is black. PNG file must be in /img/pictures.
* @default
*
* @param Equip Screen BG
* @desc Background of the equip screen. If undefined, is black. PNG file must be in /img/pictures.
* @default
*
* @param Status Screen BG
* @desc Background of the equip screen. If undefined, is black. PNG file must be in /img/pictures.
* @default
*
* @param Save Screen BG
* @desc Background of the save screen. If undefined, is black. PNG file must be in /img/pictures.
* @default
*
* @param Load Screen BG
* @desc Background of the load screen. If undefined, is black. PNG file must be in /img/pictures.
* @default
*
* @param Options Screen BG
* @desc Background of the options screen. If undefined, is black. PNG file must be in /img/pictures.
* @default
*
* @help
* ----------------------------------------------------------------------------
*   Non-Combat Menu v1.01 by mjshi
*   Free for both commercial and non-commercial use, with credit.
* ----------------------------------------------------------------------------
*
* > Update v1.0b
* - Added support for Yanfly Item Core (place the NonCombatMenu below it)
*
* > Update v1.01
* - Added support for backgrounds.
*
* > Update v1.01a
* - Made it so backgrounds actually work and didn't error xD
*
* > Is something broken? Go to http://mjshi.weebly.com/contact.html and I'll
*   try my best to help you!
*
*/

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

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

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

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

//=============================================================================
// Scene_NCMenu
//=============================================================================

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

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

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

Scene_NCMenu.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this.createCommandWindow();
    this.createInvisibleFormationWindow();
};

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

Scene_NCMenu.prototype.createBackground = function() {
    Scene_MenuBase.prototype.createBackground.call(this);
    if (NCMenu.backgroundImage) {
        this._background = new Sprite(ImageManager.loadPicture(NCMenu.backgroundImage));
        this._background.opacity = NCMenu.menuDim;
        this.addChild(this._background);
    }
    else {
        this.setBackgroundOpacity(NCMenu.menuDim)
    }
};

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

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

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

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


Scene_NCMenu.prototype.commandItem = function() {
    SceneManager.push(Scene_Item);
};
if (NCMenu.persistentBG) {
    Scene_Item.prototype.createBackground = Scene_NCMenu.prototype.createBackground
}
else {
    Scene_Item.prototype.createBackground = function() {
            Scene_MenuBase.prototype.createBackground.call(this);
            if (NCMenu.itemBG) {
                    console.log("has run");
                this._background = new Sprite(ImageManager.loadPicture(NCMenu.itemBG));
                this._background.opacity = NCMenu.menuDim;
                this.addChild(this._background);
            }
            else {
                    console.log("hasn't run");
                this.setBackgroundOpacity(NCMenu.menuDim)
            }
    }
}

Scene_NCMenu.prototype.commandEquip = function() {
    SceneManager.push(Scene_Equip);
};
if (NCMenu.persistentBG) {
    Scene_Equip.prototype.createBackground = Scene_NCMenu.prototype.createBackground
}
else {
    Scene_Equip.prototype.createBackground = function() {
            Scene_MenuBase.prototype.createBackground.call(this);
            if (NCMenu.equipBG) {
                this._background = new Sprite(ImageManager.loadPicture(NCMenu.equipBG));
                this._background.opacity = NCMenu.menuDim;
                this.addChild(this._background);
            }
            else {
                this.setBackgroundOpacity(NCMenu.menuDim)
            }
    }
}

Scene_NCMenu.prototype.commandStatus = function() {
    SceneManager.push(Scene_Status);
};
if (NCMenu.persistentBG) {
    Scene_Status.prototype.createBackground = Scene_NCMenu.prototype.createBackground
}
else {
    Scene_Status.prototype.createBackground = function() {
            Scene_MenuBase.prototype.createBackground.call(this);
            if (NCMenu.statusBG) {
                this._background = new Sprite(ImageManager.loadPicture(NCMenu.statusBG));
                this._background.opacity = NCMenu.menuDim;
                this.addChild(this._background);
            }
            else {
                this.setBackgroundOpacity(NCMenu.menuDim)
            }
    }
}


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

Scene_NCMenu.prototype.commandSave = function() {
    SceneManager.push(Scene_Save);
};
if (NCMenu.persistentBG) {
    Scene_Save.prototype.createBackground = Scene_NCMenu.prototype.createBackground
}
else {
    Scene_Save.prototype.createBackground = function() {
            Scene_MenuBase.prototype.createBackground.call(this);
            if (NCMenu.saveBG) {
                this._background = new Sprite(ImageManager.loadPicture(NCMenu.saveBG));
                this._background.opacity = NCMenu.menuDim;
                this.addChild(this._background);
            }
            else {
                this.setBackgroundOpacity(NCMenu.menuDim)
            }
    }
}


Scene_NCMenu.prototype.commandOptions = function() {
    SceneManager.push(Scene_Options);
};
if (NCMenu.persistentBG) {
    Scene_Options.prototype.createBackground = Scene_NCMenu.prototype.createBackground
}
else {
    Scene_Options.prototype.createBackground = function() {
            Scene_MenuBase.prototype.createBackground.call(this);
            if (NCMenu.optionsBG) {
                this._background = new Sprite(ImageManager.loadPicture(NCMenu.optionsBG));
                this._background.opacity = NCMenu.menuDim;
                this.addChild(this._background);
            }
            else {
                this.setBackgroundOpacity(NCMenu.menuDim)
            }
    }
}

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


Scene_NCMenu.prototype.commandLoad = function() {
    SceneManager.push(Scene_Load);
};
if (NCMenu.persistentBG) {
    Scene_Load.prototype.createBackground = Scene_NCMenu.prototype.createBackground
}
else {
    Scene_Load.prototype.createBackground = function() {
            Scene_MenuBase.prototype.createBackground.call(this);
            if (NCMenu.loadBG) {
                this._background = new Sprite(ImageManager.loadPicture(NCMenu.loadBG));
                this._background.opacity = NCMenu.menuDim;
                this.addChild(this._background);
            }
            else {
                this.setBackgroundOpacity(NCMenu.menuDim)
            }
    }
}

Scene_NCMenu.prototype.commandFormation = function() {
    this._commandWindow.hide();
    this._commandWindow.deactivate();
    this._statusWindow.setFormationMode(true);
    this._statusWindow.selectLast();
    this._statusWindow.show();
    this._statusWindow.activate();
    this._statusWindow.setHandler('ok',     this.onFormationOk.bind(this));
    this._statusWindow.setHandler('cancel', this.onFormationCancel.bind(this));
};

Scene_NCMenu.prototype.onFormationOk = function() {
    var index = this._statusWindow.index();
    var actor = $gameParty.members()[index];
    var pendingIndex = this._statusWindow.pendingIndex();
    if (pendingIndex >= 0) {
        $gameParty.swapOrder(index, pendingIndex);
        this._statusWindow.setPendingIndex(-1);
        this._statusWindow.redrawItem(index);
    } else {
        this._statusWindow.setPendingIndex(index);
    }
    this._statusWindow.activate();
};

Scene_NCMenu.prototype.onFormationCancel = function() {
    if (this._statusWindow.pendingIndex() >= 0) {
        this._statusWindow.setPendingIndex(-1);
        this._statusWindow.activate();
    } else {
        this._statusWindow.deselect();
        this._statusWindow.hide();
        this._commandWindow.show();
        this._commandWindow.activate();
    }
};

//=============================================================================
// Window_NCMenu
//=============================================================================

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

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

Window_NCMenu.prototype.initialize = function() {
    Window_Command.prototype.initialize.call(this, 0, 0);
    this.updatePlacement();
    this.openness = 0;
    this.open();
};

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

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

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

//=============================================================================
// Scene_Map - changed to call NCMenu rather than original menu screen
//=============================================================================

Scene_Map.prototype.callMenu = function() {
    SoundManager.playOk();
    SceneManager.push(Scene_NCMenu);
    Window_MenuCommand.initCommandPosition();
    $gameTemp.clearDestination();
    this._mapNameWindow.hide();
    this._waitCount = 2;
};


if (!Imported.YEP_ItemCore) {

//=============================================================================
// Window_ItemCategory - changed to accept NCMenu parameters
//=============================================================================

Window_ItemCategory.prototype.windowWidth = function() {
    if (NCMenu.showGoldWindow) {
      return Graphics.boxWidth - NCMenu.goldWindowWidth;
    } else {
      return Graphics.boxWidth;
    }
};

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

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

//=============================================================================
// Window_Gold - changed to accept NCMenu parameters
//=============================================================================

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

//=============================================================================
// Scene_Item - changed to accept NCMenu parameters
//=============================================================================

Scene_Item.prototype.create = function() {
    Scene_ItemBase.prototype.create.call(this);
    this.createHelpWindow();
    if (NCMenu.showGoldWindow) {this.createGoldWindow()}
    this.createCategoryWindow();
    this.createItemWindow();
    this.createActorWindow();
};

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

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

    if (NCMenu.descrPlacement == 1) {
      this._helpWindow.y = this._categoryWindow.height;
    }
      else if (NCMenu.descrPlacement == 2) {
        this._helpWindow.y = Graphics.boxHeight - this._helpWindow.height;
      }
        else {
          if (NCMenu.showGoldWindow) {this._goldWindow.y = this._helpWindow.height}
          this._categoryWindow.y = this._helpWindow.height;
        }

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

Scene_Item.prototype.createItemWindow = function() {
    if (NCMenu.descrPlacement == 1) {
      wy = this._categoryWindow.y + this._categoryWindow.height + this._helpWindow.height;
    }
      else if (NCMenu.descrPlacement == 2) {
        wy = this._categoryWindow.height + this._helpWindow.height;
      } else {
          wy = this._categoryWindow.y + this._categoryWindow.height;
        }

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

    if (NCMenu.descrPlacement == 2) {this._itemWindow.y = this._categoryWindow.height};
   
    this._itemWindow.setHelpWindow(this._helpWindow);
    this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
    this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
    this.addWindow(this._itemWindow);
    this._categoryWindow.setItemWindow(this._itemWindow);
};

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

};

//=============================================================================
// Window_Status - Streamlined
//=============================================================================

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

Window_Status.prototype.refresh = function() {
    this.contents.clear();
    if (this._actor) {
        var lineHeight = this.lineHeight();
        this.drawBlock2(0);
    }
};

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

Window_Status.prototype.drawBasicInfo = function(x, y) {
    var lineHeight = this.lineHeight();
    this.drawActorName(this._actor, x, y + lineHeight * 0.5);
    this.drawActorHp(this._actor, x, y + lineHeight * 1.5);
    this.drawActorMp(this._actor, x, y + lineHeight * 2.5);
};
[/pre]
梦石
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.

在本版发帖返回顶部