Save-Point
AddEnemyBookToMenu - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+--- Thread: AddEnemyBookToMenu (/thread-5606.html)



AddEnemyBookToMenu - kyonides - 10-29-2015

Window_Menu Add On
to include Yoji Ojima's EnemyBook js script in the main menu screen

This basic plugin author: Kyonides-Arkanthos

EnemyBook script author: Yoji Ojima

Introduction

This plugin or javascript file with a bunch of lines of code adds the Enemy Book option to the main menu.

I just had a reason to work on this, Yoji Ojima expected people to call his script by means of a Plugin Command call. It seems he never thought some gamers would prefer to check the Bestiary by opening the main menu and hitting the Bestiary or Enemy Book option instead of calling it from any event on the map.

Instructions

Just go to your project's js and then the plugins folder and place the script in any TXT file and change the file extension to js. Perhaps you wanna name it AddEnemyBookToMenu.js as I did.

Code:
//========================================================================================
// AddEnemyBookToMenu : Window_MenuCommand now includes an option to open EnemyBook scene
//========================================================================================

/*:
 * @plugindesc Displays the Bestiary menu option.
 * @author Kyonides-Arkanthos
 *
 * @param None
 */

/*
 * Enemy Book Description: Displays detailed statuses of enemies.
 * Enemy Book Author: Yoji Ojima
 */
 
function Scene_EnemyBook() {
    this.initialize.apply(this, arguments);
}

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

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

Scene_EnemyBook.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this._indexWindow = new Window_EnemyBookIndex(0, 0);
    this._indexWindow.setHandler('cancel', this.popScene.bind(this));
    var wy = this._indexWindow.height;
    var ww = Graphics.boxWidth;
    var wh = Graphics.boxHeight - wy;
    var parameters = PluginManager.parameters('EnemyBook');
    this.unknownData = String(parameters['Unknown Data'] || '??????');
    this._statusWindow = new Window_EnemyBookStatus(0, wy, ww, wh);
    this.addWindow(this._indexWindow);
    this.addWindow(this._statusWindow);
    this._indexWindow.setStatusWindow(this._statusWindow);
};

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

Window_EnemyBookIndex.prototype = Object.create(Window_Selectable.prototype);
Window_EnemyBookIndex.prototype.constructor = Window_EnemyBookIndex;

Window_EnemyBookIndex.lastTopRow = 0;
Window_EnemyBookIndex.lastIndex  = 0;

Window_EnemyBookIndex.prototype.initialize = function(x, y) {
    var width = Graphics.boxWidth;
    var height = this.fittingHeight(6);
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
    this.setTopRow(Window_EnemyBookIndex.lastTopRow);
    this.select(Window_EnemyBookIndex.lastIndex);
    this.activate();
}

Window_EnemyBookIndex.prototype.maxCols = function() { return 3; }

 Window_EnemyBookIndex.prototype.maxItems = function() {
    return this._list ? this._list.length : 0;
}

Window_EnemyBookIndex.prototype.setStatusWindow = function(statusWindow) {
    this._statusWindow = statusWindow;
    this.updateStatus();
}

Window_EnemyBookIndex.prototype.update = function() {
    Window_Selectable.prototype.update.call(this);
    this.updateStatus();
}

Window_EnemyBookIndex.prototype.updateStatus = function() {
    if (this._statusWindow) {
        var enemy = this._list[this.index()];
        this._statusWindow.setEnemy(enemy);
    }
}

Window_EnemyBookIndex.prototype.refresh = function() {
    this._list = [];
    for (var i = 1; i < $dataEnemies.length; i++) {
        var enemy = $dataEnemies[i];
        if (enemy.name && enemy.meta.book !== 'no') {
            this._list.push(enemy);
        }
    }
    this.createContents();
    this.drawAllItems();
}

Window_EnemyBookIndex.prototype.drawItem = function(index) {
    var enemy = this._list[index];
    var rect = this.itemRectForText(index);
    var name;
    if ($gameSystem.isInEnemyBook(enemy)) {
        name = enemy.name;
    } else {
        name = this.unknownData;
    }
    this.drawText(name, rect.x, rect.y, rect.width);
}

Window_EnemyBookIndex.prototype.processCancel = function() {
    Window_Selectable.prototype.processCancel.call(this);
    Window_EnemyBookIndex.lastTopRow = this.topRow();
    Window_EnemyBookIndex.lastIndex = this.index();
}

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

Window_EnemyBookStatus.prototype = Object.create(Window_Base.prototype)
Window_EnemyBookStatus.prototype.constructor = Window_EnemyBookStatus;

Window_EnemyBookStatus.prototype.initialize = function(x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this._enemy = null;
    this._enemySprite = new Sprite();
    this._enemySprite.anchor.x = 0.5;
    this._enemySprite.anchor.y = 0.5;
    this._enemySprite.x = width / 2 - 20;
    this._enemySprite.y = height / 2;
    this.addChildToBack(this._enemySprite);
    this.refresh();
}

 Window_EnemyBookStatus.prototype.setEnemy = function(enemy) {
    if (this._enemy !== enemy) {
        this._enemy = enemy;
        this.refresh();
    }
}

Window_EnemyBookStatus.prototype.update = function() {
    Window_Base.prototype.update.call(this);
    if (this._enemySprite.bitmap) {
        var bitmapHeight = this._enemySprite.bitmap.height;
        var contentsHeight = this.contents.height;
        var scale = 1;
        if (bitmapHeight > contentsHeight) {
            scale = contentsHeight / bitmapHeight;
        }
        this._enemySprite.scale.x = scale;
        this._enemySprite.scale.y = scale;
    }
}

Window_EnemyBookStatus.prototype.refresh = function() {
    var enemy = this._enemy;
    var x = 0;
    var y = 0;
    var lineHeight = this.lineHeight();

    this.contents.clear();

    if (!enemy || !$gameSystem.isInEnemyBook(enemy)) {
        this._enemySprite.bitmap = null;
        return;
    }

    var name = enemy.battlerName;
    var hue = enemy.battlerHue;
    var bitmap;
    if ($gameSystem.isSideView()) {
        bitmap = ImageManager.loadSvEnemy(name, hue);
    } else {
        bitmap = ImageManager.loadEnemy(name, hue);
    }
    this._enemySprite.bitmap = bitmap;

    this.resetTextColor();
    this.drawText(enemy.name, x, y);

    x = this.textPadding();
    y = lineHeight + this.textPadding();

    for (var i = 0; i < 8; i++) {
        this.changeTextColor(this.systemColor());
        this.drawText(TextManager.param(i), x, y, 160);
        this.resetTextColor();
        this.drawText(enemy.params[i], x + 160, y, 60, 'right');
        y += lineHeight;
    }

    var rewardsWidth = 280;
    x = this.contents.width - rewardsWidth;
    y = lineHeight + this.textPadding();

    this.resetTextColor();
    this.drawText(enemy.exp, x, y);
    x += this.textWidth(enemy.exp) + 6;
    this.changeTextColor(this.systemColor());
    this.drawText(TextManager.expA, x, y);
    x += this.textWidth(TextManager.expA + '  ');

    this.resetTextColor();
    this.drawText(enemy.gold, x, y);
    x += this.textWidth(enemy.gold) + 6;
    this.changeTextColor(this.systemColor());
    this.drawText(TextManager.currencyUnit, x, y);

    x = this.contents.width - rewardsWidth;
    y += lineHeight;

    for (var j = 0; j < enemy.dropItems.length; j++) {
        var di = enemy.dropItems[j];
        if (di.kind > 0) {
            var item = Game_Enemy.prototype.itemObject(di.kind, di.dataId);
            this.drawItemName(item, x, y, rewardsWidth);
            y += lineHeight;
        }
    }

    var descWidth = 480;
    x = this.contents.width - descWidth;
    y = this.textPadding() + lineHeight * 7;
    this.drawTextEx(enemy.meta.desc1, x, y + lineHeight * 0, descWidth);
    this.drawTextEx(enemy.meta.desc2, x, y + lineHeight * 1, descWidth);
};

Window_MenuCommand.prototype.addOriginalCommands = function() {
    this.addCommand('Bestiary', 'bestiary', true);
}

Scene_Menu.prototype.createCommandWindow = function() {
    this._commandWindow = new Window_MenuCommand(0, 0);
    this._commandWindow.setHandler('item',      this.commandItem.bind(this));
    this._commandWindow.setHandler('skill',     this.commandPersonal.bind(this));
    this._commandWindow.setHandler('equip',     this.commandPersonal.bind(this));
    this._commandWindow.setHandler('status',    this.commandPersonal.bind(this));
    this._commandWindow.setHandler('formation', this.commandFormation.bind(this));
    this._commandWindow.setHandler('bestiary',  this.commandBestiary.bind(this));
    this._commandWindow.setHandler('options',   this.commandOptions.bind(this));
    this._commandWindow.setHandler('save',      this.commandSave.bind(this));
    this._commandWindow.setHandler('gameEnd',   this.commandGameEnd.bind(this));
    this._commandWindow.setHandler('cancel',    this.popScene.bind(this));
    this.addWindow(this._commandWindow);
}

Scene_Menu.prototype.commandBestiary = function() {
    SceneManager.push(Scene_EnemyBook);
}

Credits

To Yoji Ojima for the Enemy Book script (that I actually dislike because of the way it looks).

And to me, Kyonides-Arkanthos, if you like. The truth is I just did some minor changes to the original RMMV and Ojima's scripts.