/*:
* @target MZ
* @plugindesc 变量排行榜系统 v2.1(纯色版)
* @help 显示指定变量范围的排行榜(变量401-410),按数值从高到低排列
* 可在参数界面设置显示坐标和颜色
* @param posX
* @text 排行榜X坐标
* @desc 排行榜显示位置的X坐标(默认20)
* @type number
* @default 20
*
* @param posY
* @text 排行榜Y坐标
* @desc 排行榜显示位置的Y坐标(默认20)
* @type number
* @default 20
*
* @param bgColor
* @text 背景颜色
* @desc 排行榜背景颜色(默认#00000080)
* @type string
* @default #00000080
*
* @param titleColor
* @text 标题颜色
* @desc 标题文字颜色(默认#FFFFFF)
* @type string
* @default #FFFFFF
*
* @param rank1Color
* @text 第一名颜色
* @desc 第一名文字颜色(默认#FF0000)
* @type string
* @default #FF0000
*
* @param rank2Color
* @text 第二名颜色
* @desc 第二名文字颜色(默认#FFFF00)
* @type string
* @default #FFFF00
*
* @param rank3Color
* @text 第三名颜色
* @desc 第三名文字颜色(默认#FFFF00)
* @type string
* @default #FFFF00
*
* @param rank4Color
* @text 第四名颜色
* @desc 第四名文字颜色(默认#FFFFFF)
* @type string
* @default #FFFFFF
*
* @param rank5Color
* @text 第五名颜色
* @desc 第五名文字颜色(默认#FFFFFF)
* @type string
* @default #FFFFFF
*
* @param rank6Color
* @text 第六名颜色
* @desc 第六名文字颜色(默认#FFFFFF)
* @type string
* @default #FFFFFF
*
* @param rank7Color
* @text 第七名颜色
* @desc 第七名文字颜色(默认#FFFFFF)
* @type string
* @default #FFFFFF
*
* @param rank8Color
* @text 第八名颜色
* @desc 第八名文字颜色(默认#FFFFFF)
* @type string
* @default #FFFFFF
*
* @param rank9Color
* @text 第九名颜色
* @desc 第九名文字颜色(默认#FFFFFF)
* @type string
* @default #FFFFFF
*
* @param rank10Color
* @text 第十名颜色
* @desc 第十名文字颜色(默认#FFFFFF)
* @type string
* @default #FFFFFF
*
* @param switchId
* @text 排行榜开关ID
* @desc 控制排行榜显示的开关ID(默认0表示始终显示)
* @type switch
* @default 0
*
* @author AI助手
*/
(() => {
const parameters = PluginManager.parameters('VariableRanking');
const config = {
posX: parseInt(parameters['posX'] || 20),
posY: parseInt(parameters['posY'] || 20),
bgColor: parameters['bgColor'] || '#00000080',
titleColor: parameters['titleColor'] || '#FFFFFF',
rankColors: [
parameters['rank1Color'] || '#FF0000',
parameters['rank2Color'] || '#FFFF00',
parameters['rank3Color'] || '#FFFF00',
parameters['rank4Color'] || '#FFFFFF',
parameters['rank5Color'] || '#FFFFFF',
parameters['rank6Color'] || '#FFFFFF',
parameters['rank7Color'] || '#FFFFFF',
parameters['rank8Color'] || '#FFFFFF',
parameters['rank9Color'] || '#FFFFFF',
parameters['rank10Color'] || '#FFFFFF'
],
switchId: parseInt(parameters['switchId'] || 0)
};
const _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
_Scene_Map_update.call(this);
// 检查开关状态(如果设置了开关ID)
if (config.switchId > 0 && !$gameSwitches.value(config.switchId)) {
if (this._rankingSprite) {
this._rankingSprite.removeChildren();
}
return;
}
if (!this._rankingSprite) {
this._rankingSprite = new Sprite();
this._rankingSprite.z = 999;
this.addChild(this._rankingSprite);
}
// 收集变量数据(范围401-410)
const data = [];
for (let i = 401; i <= 410; i++) {
data.push({
value: $gameVariables.value(i),
id: i,
name: $dataSystem.variables[i] || `变量${i}` // 获取变量名(含默认值)
});
}
// 按数值降序排序
data.sort((a, b) => b.value - a.value);
// 更新排行榜显示
this._rankingSprite.removeChildren();
const bgWidth = 240;
const bgHeight = 400;
// 绘制纯色背景
const bg = new Sprite(new Bitmap(bgWidth, bgHeight));
bg.bitmap.fillAll(config.bgColor);
bg.x = config.posX;
bg.y = config.posY;
this._rankingSprite.addChild(bg);
// 绘制标题
const title = new Sprite(new Bitmap(bgWidth - 20, 40));
title.bitmap.fontSize = 24;
title.bitmap.textColor = config.titleColor;
title.bitmap.drawText('变量排行榜', 0, 0, bgWidth - 20, 40, 'center');
title.x = config.posX + 10;
title.y = config.posY + 10;
this._rankingSprite.addChild(title);
// 绘制排名条目
data.forEach((entry, rank) => {
const text = new Sprite(new Bitmap(bgWidth - 20, 32));
text.bitmap.fontSize = 20;
text.bitmap.textColor = config.rankColors[rank] || '#FFFFFF';
text.bitmap.drawText(
`${rank+1}. ${entry.name}: ${entry.value}`,
0, 0, bgWidth - 20, 32
);
text.x = config.posX + 10;
text.y = config.posY + 60 + rank * 32;
this._rankingSprite.addChild(text);
});
};
})();