//=============================================================================
// STV_StageSelector.js
//=============================================================================
/*:
* @plugindesc v1.1 - STV_StageSelector
* || This will add a level selector to your Project
* @author SkottyTV || Special Thanks: Lantiz
*
* @param ----- Window -----
*
* @param Show Window
* @desc Show or Hide Window Skin
* TRUE = show window / FALSE = hide window
* @default TRUE
*
* @param Background Picture
* @desc The Background Picture in img/pictures/
* (leave empty for no Background Picture)
* @default
*
* @param Backbar Color
* @desc The default Backbar Color
* (default 15)
* @default 15
*
* @param ----- Text -----
*
* @param Chapter Text
* @desc Default Text for "Chapter"
* @default Chapter
*
* @param Transfer Text
* @desc Default Text for "Start"
* @default Transfer
*
* @param Back Text
* @desc Default Text for "Back"
* @default Back
*
* @param Info Text
* @desc Default Text for "Info"
* @default Info
*
* @param ----- Icons -----
*
* @param Completed Icon
* @desc Default Icon for completed levels
* @default 87
*
* @param --- Functions ---
*
* @param Show Level ID
* @desc Show Level ID in front of name
* TRUE = show, FALSE = hide
* @default TRUE
*
* @param Transfer Direction
* @desc Direction the Player looks after Transfer
* 2 = down, 4 = left, 6 = right, 8 = up, 0 = as before
* @default 0
*
* @param Transfer Type
* @desc The Type of the Transfer
* 0 = Fade Black, 1 = Fade White, 2 = none/instant
* @default 0
*
* @help
*
* ////////////////////////////////////////////////////////////////////////////
* ----------------------------- Terms of Usage: ------------------------------
* ////////////////////////////////////////////////////////////////////////////
* Feel free to use this Plugin in 1. Non-Commercial Games, 2. Commercial Games
* However it would be nice to give proper Credits to "SkottyTV"
* Also a free copy of your Game would be a nice move :)
*
* Many Thanks to the Forum User "Lantiz" !
*
* Have Fun And Enjoy! :)
*
*
*
* ////////////////////////////////////////////////////////////////////////////
* --------------------------------- Updates:----------------------------------
* ////////////////////////////////////////////////////////////////////////////
*
* Update v1.0
* - Basic Functionality
* - Bug fixes
* - upgrades
*
* Updated v1.1
* - Bug Fixes
*
*
* ////////////////////////////////////////////////////////////////////////////
* -------------------------------- Commands: ---------------------------------
* ////////////////////////////////////////////////////////////////////////////
* Plugin Command:
* StageSelector open # Opens the Stage Selector.
* StageSelector reveal 1 3 # Shows Stage 1 Level 3 inside StageSelector.
* StageSelector complete 2 5 # Completes Level 5 of Stage 2.
*
* Event Note:
* <STVSS start> # This Event will be the start position
* of the Player after the Transfer.
* Map Note:
* <STVSS Stage: 1,4> # This Map will be Stage 1, Level 4.
* <STVSS Info> # Start of all Infos.
* Some Info here # The Info Text.
* </STVSS Info> # End of all Infos.
*
*
* ////////////////////////////////////////////////////////////////////////////
* -------------------------- Examples / Tutorials: ---------------------------
* ////////////////////////////////////////////////////////////////////////////
*
* For a Map notebox it could look like this:
*
* <STVSS Stage: 1,3>
* <STVSS Info>
* This is Stage 1 Level 3.
* This is some colored \c[2]Info \c[0]Text.
* You can even put Variables \V[1] here!
* </STVSS Info>
*
*
*/
// ----------------------------------------------------------------------------------------------------------------------------
// STV_SkillSystem Parameters
// ----------------------------------------------------------------------------------------------------------------------------
var stv_StageSelector_parameters = PluginManager.parameters('STV_StageSelector');
// ----- Window -----
var stv_StageSelector_showWindow = String(stv_StageSelector_parameters['Show Window'] || 'TRUE');
var stv_StageSelector_bgPicture = String(stv_StageSelector_parameters['Background Picture'] || '');
var stv_StageSelector_backBarColor = Number(stv_StageSelector_parameters['Backbar Color'] || 15);
// ----- Text -----
var stv_StageSelector_chapterText = String(stv_StageSelector_parameters['Chapter Text'] || 'Chapter');
var stv_StageSelector_transferText = String(stv_StageSelector_parameters['Transfer Text'] || 'Transfer');
var stv_StageSelector_backText = String(stv_StageSelector_parameters['Back Text'] || 'Back');
var stv_StageSelector_descText = String(stv_StageSelector_parameters['Info Text'] || 'Info');
// --- Icons ---
var stv_StageSelector_completedIcon = Number(stv_StageSelector_parameters['Completed Icon'] || 87);
// --- Functions ---
var stv_StageSelector_showLevelId = String(stv_StageSelector_parameters['Show Level ID'] || 'TRUE');
var stv_StageSelector_transferDirection = Number(stv_StageSelector_parameters['Transfer Direction'] || 0);
var stv_StageSelector_transferType = Number(stv_StageSelector_parameters['Transfer Type'] || 0);
// ----------------------------------------------------------------------------------------------------------------------------
// Scene MonsterCardsManager create
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector = function() {
this.initialize.apply(this, arguments);
};
Scene_StageSelector.prototype = Object.create(Scene_MenuBase.prototype);
Scene_StageSelector.prototype.constructor = Scene_StageSelector;
Scene_StageSelector.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_StageSelector.prototype.createBackground = function() {
this._backgroundSprite = new Sprite();
this._backgroundSprite.move(0, 0, Graphics.width, Graphics.height);
this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
this.addChild(this._backgroundSprite);
if (stv_StageSelector_bgPicture){
this._foregroundSprite = new Sprite();
this._foregroundSprite.move(0, 0, Graphics.width, Graphics.height);
this._foregroundSprite.bitmap = ImageManager.loadPicture(stv_StageSelector_bgPicture);
this.addChild(this._foregroundSprite);
}
};
Scene_StageSelector.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createWindowPositions();
this.createChapterWindow();
this.createLevelWindow();
this.createInfoWindow();
this.createCommandWindow();
if(stv_StageSelector_showWindow != "TRUE"){
this._chapterWindow.opacity = 0;
this._levelWindow.opacity = 0;
this._infoWindow.opacity = 0;
this._commandWindow.opacity = 0;
}
};
// ----------------------------------------------------------------------------------------------------------------------------
// Create Window Positions
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.createWindowPositions = function() {
var maxWidth = Graphics.boxWidth,
maxHeight = Graphics.boxHeight;
var cX = 0,
cY = 0,
cW = maxWidth,
cH = (maxHeight/4);
this._chapterWindow = new Window_StageSelector_Chapter(cX, cY, cW, cH);
var lX = cX,
lY = cH,
lW = cW/3,
lH = maxHeight-cH;
this._levelWindow = new Window_StageSelector_Level(lX, lY, lW, lH);
var iX = lW,
iY = lY,
iW = cW-lW,
iH = lH;
this._infoWindow = new Window_StageSelector_Info(iX, iY, iW, iH);
var hX = iX,
hY = maxHeight - 75,
hW = iW,
hH = 75;
this._commandWindow = new Window_StageSelector_Command(hX, hY, hW, hH);
};
// ----------------------------------------------------------------------------------------------------------------------------
// Refresh Windows
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.refreshWindows = function() {
this._chapterWindow.refresh();
this._levelWindow.refresh();
this._infoWindow.refresh();
this._commandWindow.refresh();
};
// ----------------------------------------------------------------------------------------------------------------------------
// Setup Chapter Window
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.createChapterWindow = function() {
this._chapterWindow.setHandler('ok', this.selectChapter.bind(this));
this._chapterWindow.setHandler('cancel', this.popScene.bind(this));
this._chapterWindow.setLevelWindow(this._levelWindow);
this.addWindow(this._chapterWindow);
this._chapterWindow.activate();
};
// ----------------------------------------------------------------------------------------------------------------------------
// Setup Level Window
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.createLevelWindow = function() {
this._levelWindow.setHandler('ok', this.selectLevel.bind(this));
this._levelWindow.setHandler('cancel', this.cancelLevel.bind(this));
this._levelWindow.setInfoWindow(this._infoWindow);
this.addWindow(this._levelWindow);
};
// ----------------------------------------------------------------------------------------------------------------------------
// Setup Info Window
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.createInfoWindow = function() {
this.addWindow(this._infoWindow);
};
// ----------------------------------------------------------------------------------------------------------------------------
// Setup Command Window
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.createCommandWindow = function() {
this._commandWindow.setHandler('start', this.startLevel.bind(this));
this._commandWindow.setHandler('cancel', this.cancelCommand.bind(this));
this.addWindow(this._commandWindow);
this._commandWindow.deactivate();
this._commandWindow.hide();
};
// ----------------------------------------------------------------------------------------------------------------------------
// On Chapter Select
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.selectChapter = function() {
if (this._chapterWindow._list[0]) {
this._chapterWindow.deactivate();
this._levelWindow.activate();
} else {
this.popScene();
}
};
// ----------------------------------------------------------------------------------------------------------------------------
// On Level Select
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.selectLevel = function() {
this._levelWindow.deactivate();
this._commandWindow.show();
this._commandWindow.activate();
};
// ----------------------------------------------------------------------------------------------------------------------------
// On Start Select
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.startLevel = function() {
this.popScene();
$stv_stageselector.transfer($stv_stageselector.selectedLevel);
};
// ----------------------------------------------------------------------------------------------------------------------------
// On Command Cancel
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.cancelCommand = function() {
this._commandWindow.deactivate();
this._commandWindow.hide();
this._levelWindow.activate();
};
// ----------------------------------------------------------------------------------------------------------------------------
// On Level Cancel
// ----------------------------------------------------------------------------------------------------------------------------
Scene_StageSelector.prototype.cancelLevel = function() {
this._chapterWindow.activate();
this._levelWindow.deactivate();
this._levelWindow.select(0);
};
// ----------------------------------------------------------------------------------------------------------------------------
// Fill Chapter Window
// ----------------------------------------------------------------------------------------------------------------------------
function Window_StageSelector_Chapter() {
this.initialize.apply(this, arguments);
}
Window_StageSelector_Chapter.prototype = Object.create(Window_Selectable.prototype);
Window_StageSelector_Chapter.prototype.constructor = Window_StageSelector_Chapter;
Window_StageSelector_Chapter.lastTopRow = 0;
Window_StageSelector_Chapter.lastIndex = 0;
Window_StageSelector_Chapter.prototype.initialize = function(x, y, width, height) {
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
this.refresh();
this.setTopRow(Window_StageSelector_Chapter.lastTopRow);
this.select(Window_StageSelector_Chapter.lastIndex);
};
Window_StageSelector_Chapter.prototype.maxCols = function() {
return 4;
};
Window_StageSelector_Chapter.prototype.maxItems = function() {
return this._list ? this._list.length : 0;
};
Window_StageSelector_Chapter.prototype.update = function() {
Window_Selectable.prototype.update.call(this);
this.updateStatus();
};
Window_StageSelector_Chapter.prototype.refresh = function() {
this._list = [];
for (var i = 1; i < $stv_stageselector._stageList.length; i++) {
var stage = $stv_stageselector._stageList[i];
for (var j = 1; j < stage.length; j++) {
if (stage[j]._revealed) {
this._list.push(stage);
break;
}
}
}
this.contents.clear();
this.drawAllItems();
};
Window_StageSelector_Chapter.prototype.drawItem = function(index) {
var stage = this._list[index],
rect = this.itemRect(index);
this.drawText(stv_StageSelector_chapterText + " " + stage[0], rect.x, rect.y, rect.width, 'center');
};
Window_StageSelector_Chapter.prototype.setLevelWindow = function(window) {
this._levelWindow = window;
this.updateStatus();
};
Window_StageSelector_Chapter.prototype.updateStatus = function() {
var chapter = this._list[this.index()];
$stv_stageselector.selectedChapter = chapter;
if (this._levelWindow) this._levelWindow.setChapter(chapter);
};
// ----------------------------------------------------------------------------------------------------------------------------
// Fill Level Window
// ----------------------------------------------------------------------------------------------------------------------------
function Window_StageSelector_Level() {
this.initialize.apply(this, arguments);
}
Window_StageSelector_Level.prototype = Object.create(Window_Selectable.prototype);
Window_StageSelector_Level.prototype.constructor = Window_StageSelector_Level;
Window_StageSelector_Level.lastTopRow = 0;
Window_StageSelector_Level.lastIndex = 0;
Window_StageSelector_Level.prototype.initialize = function(x, y, width, height) {
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
this.setTopRow(Window_StageSelector_Level.lastTopRow);
this.select(Window_StageSelector_Level.lastIndex);
};
Window_StageSelector_Level.prototype.maxCols = function() {
return 1;
};
Window_StageSelector_Level.prototype.maxItems = function() {
return this._list ? this._list.length : 0;
};
Window_StageSelector_Level.prototype.update = function() {
Window_Selectable.prototype.update.call(this);
this.updateStatus();
};
Window_StageSelector_Level.prototype.refresh = function() {
this._list = [];
if (this._chapter) {
for (var i = 1; i < this._chapter.length; i++) {
var level = this._chapter[i];
if (level._revealed) this._list.push(level);
}
this.contents.clear();
this.drawAllItems();
}
};
Window_StageSelector_Level.prototype.drawItem = function(index) {
var level = this._list[index],
rect = this.itemRect(index),
levelNr = "";
if (stv_StageSelector_showLevelId == "TRUE") levelNr = "%1: ".format((level._levelId).padZero(3));
this.drawText(levelNr, rect.x, rect.y);
this.drawText(level.displayName, rect.x + this.textWidth(levelNr), rect.y, this.contents.width - 40 - this.textWidth(levelNr));
if (level._completed) this.drawIcon(stv_StageSelector_completedIcon, rect.x + rect.width - 32, rect.y + 2, "center");
};
Window_StageSelector_Level.prototype.setChapter = function(chapter) {
this._chapter = chapter;
this.refresh();
};
Window_StageSelector_Level.prototype.setInfoWindow = function(window) {
this._infoWindow = window;
this.updateStatus();
};
Window_StageSelector_Level.prototype.updateStatus = function() {
var level = this._list[this.index()];
$stv_stageselector.selectedLevel = level;
if (this._infoWindow) this._infoWindow.setLevel(level);
};
// ----------------------------------------------------------------------------------------------------------------------------
// Fill Info Window
// ----------------------------------------------------------------------------------------------------------------------------
function Window_StageSelector_Info() {
this.initialize.apply(this, arguments);
}
Window_StageSelector_Info.prototype = Object.create(Window_Base.prototype);
Window_StageSelector_Info.prototype.constructor = Window_StageSelector_Info;
Window_StageSelector_Info.prototype.initialize = function(x, y, width, height) {
Window_Base.prototype.initialize.call(this, x, y, width, height);
};
Window_StageSelector_Info.prototype.update = function() {
Window_Base.prototype.update.call(this);
};
Window_StageSelector_Info.prototype.setLevel = function(level) {
this._level = level;
this.refresh();
};
Window_StageSelector_Info.prototype.drawHead = function() {
this.contents.clear();
this.contents.paintOpacity = 180;
this.contents.fillRect(0, 0, this.contents.width, this.lineHeight(), this.textColor(stv_StageSelector_backBarColor));
this.contents.paintOpacity = 255;
if (this._level._completed) {
this.drawIcon(stv_StageSelector_completedIcon, 0, 2);
this.drawIcon(stv_StageSelector_completedIcon, this.contents.width - 32, 2);
}
this.drawText(this._level.displayName, (this.contents.width/2) - (this.textWidth(this._level.displayName)/2), 0);
};
Window_StageSelector_Info.prototype.drawDesc = function() {
this.drawText(stv_StageSelector_descText, (this.contents.width/2) - (this.textWidth(stv_StageSelector_descText)/2), this.lineHeight()*2);
this.contents.fillRect(0, this.lineHeight()*3, this.contents.width, 1, this.textColor(0));
this.drawTextEx(this._level._desc, 0, this.lineHeight()*2);
};
Window_StageSelector_Info.prototype.refresh = function() {
if (this._level) {
this.drawHead();
this.drawDesc();
}
};
// ----------------------------------------------------------------------------------------------------------------------------
// Fill Command Window 2
// ----------------------------------------------------------------------------------------------------------------------------
function Window_StageSelector_Command() {
this.initialize.apply(this, arguments);
}
Window_StageSelector_Command.prototype = Object.create(Window_HorzCommand.prototype);
Window_StageSelector_Command.prototype.constructor = Window_StageSelector_Command;
Window_StageSelector_Command.prototype.initialize = function(x, y, width, height) {
Window_HorzCommand.prototype.initialize.call(this, x, y, width, height);
};
Window_StageSelector_Command.prototype.maxCols = function() {
return 2;
};
Window_StageSelector_Command.prototype.windowWidth = function() {
return (Graphics.boxWidth/3)*2;
};
Window_StageSelector_Command.prototype.makeCommandList = function() {
this.addCommand(stv_StageSelector_transferText, 'start');
this.addCommand(stv_StageSelector_backText, 'cancel');
};
// ----------------------------------------------------------------------------------------------------------------------------
// Alias methods
// ----------------------------------------------------------------------------------------------------------------------------
STV_StageSelector_PluginCommand = Game_Interpreter.prototype.pluginCommand;
STV_StageSelector_Create = DataManager.createGameObjects;
STV_StageSelector_Save = DataManager.makeSaveContents;
STV_StageSelector_Load = DataManager.extractSaveContents;
// ----------------------------------------------------------------------------------------------------------------------------
// DataManager
// ----------------------------------------------------------------------------------------------------------------------------
var $stv_stageselector = null;
DataManager.makeSaveContents = function() {
contents = STV_StageSelector_Save.call(this);
contents.stvstageselector = $stv_stageselector;
return contents;
};
DataManager.extractSaveContents = function(contents) {
STV_StageSelector_Load.call(this, contents);
$stv_stageselector = contents.stvstageselector;
};
DataManager.createGameObjects = function() {
STV_StageSelector_Create.call(this);
$stv_stageselector = new STV_StageSelector();
};
// ----------------------------------------------------------------------------------------------------------------------------
// STV_StageSelector Functions
// ----------------------------------------------------------------------------------------------------------------------------
function STV_StageSelector() {
this.initialize.apply(this, arguments);
}
STV_StageSelector.prototype.initialize = function() {
this.selectedChapter = null;
this.selectedLevel = null;
this.setup();
};
// Setup
STV_StageSelector.prototype.setup = function() {
this.createMapList();
this.createStageList();
this._mapList = [null]; //delete Map List after needed for more Memory
};
// Get Maps
STV_StageSelector.prototype.getMaps = function(filename) {
var fs = require('fs');
var dir = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/');
if (dir.match(/^\/([A-Z]\:)/)) {
dir = dir.slice(1);
}
filename = decodeURIComponent(dir) + 'data/' + filename;
return JsonEx.parse(fs.readFileSync(filename, 'utf8'));
};
// Create Map List
STV_StageSelector.prototype.createMapList = function() {
this._mapList = [null];
for (var i = 1; i < $dataMapInfos.length; i++) {
var filename = 'Map%1.json'.format(i.padZero(3));
this._mapList.push(this.getMaps(filename));
}
};
// Create Stage List
STV_StageSelector.prototype.createStageList = function() {
this._stageList = [null];
for (var i = 1; i < $dataMapInfos.length; i++) {
var note = this._mapList[i].note,
desc = "";
if (note.match(/<STVSS Info>((.|\n)*?)<\/STVSS Info>/g)) {
desc = String(RegExp.$1);
}
if (note.match(/<(?:STVSS STAGE):[ ](.*)>/i)) {
var string = String(RegExp.$1).split(","),
stage = Number(string[0]),
level = Number(string[1]);
if (!this._stageList[stage]) this._stageList[stage] = [];
this._stageList[stage][0] = stage;
this._stageList[stage][level] = {};
this._stageList[stage][level].displayName = this._mapList[i].displayName;
this._stageList[stage][level].events = this._mapList[i].events;
this._stageList[stage][level].note = this._mapList[i].note;
this._stageList[stage][level].bgm = this._mapList[i].bgm;
this._stageList[stage][level].bgs = this._mapList[i].bgs;
this._stageList[stage][level]._desc = desc;
this._stageList[stage][level]._revealed = false;
this._stageList[stage][level]._completed = false;
this._stageList[stage][level]._mapId = i;
this._stageList[stage][level]._levelId = level;
this._stageList[stage][level]._stageId = stage;
}
}
};
// Transfer Player to Level
STV_StageSelector.prototype.transfer = function(level) {
for (var i = 1; i < level.events.length; i++) {
if (level.events[1]) {
var note = level.events[i].note;
if (note.match(/<STVSS START>/i)) {
var mapId = level._mapId,
x = level.events[i].x,
y = level.events[i].y,
dir = stv_StageSelector_transferDirection,
type = stv_StageSelector_transferType;
$gamePlayer.reserveTransfer(mapId, x, y, dir, type);
break;
}
}
}
};
// Complete Level
STV_StageSelector.prototype.completeLevel = function(stageId, levelId) {
if (this._stageList[stageId][levelId]) {
this._stageList[stageId][levelId]._completed = true;
}
};
// Reveal Level
STV_StageSelector.prototype.revealLevel = function(stageId, levelId) {
if (this._stageList[stageId][levelId]) {
this._stageList[stageId][levelId]._revealed = true;
}
};
// ----------------------------------------------------------------------------------------------------------------------------
// Plugin Commands
// ----------------------------------------------------------------------------------------------------------------------------
Game_Interpreter.prototype.pluginCommand = function(command, args) {
STV_StageSelector_PluginCommand.call(this, command, args);
if (command === 'StageSelector') {
switch (args[0]) {
case 'open':
SceneManager.push(Scene_StageSelector);
break;
case 'complete':
$stv_stageselector.completeLevel(args[1], args[2]);
break;
case 'reveal':
$stv_stageselector.revealLevel(args[1], args[2]);
break;
}
}
};