getNumberById
This commit is contained in:
parent
dae1ace3ff
commit
272d40315c
@ -1616,9 +1616,10 @@ core.clearMap(name)
|
||||
该函数的name也可以是'all',若为'all'则为清空所有系统画布。
|
||||
|
||||
|
||||
core.fillText(name, text, x, y, style, font)
|
||||
core.fillText(name, text, x, y, style, font, maxWidth)
|
||||
在某个画布上绘制一段文字。
|
||||
text为要绘制的文本,x,y为要绘制的坐标,style可选为绘制的样式,font可选为绘制的字体。(下同)
|
||||
如果maxWidth不为null,则视为文字最大宽度,如果超过此宽度则会自动放缩文字直到自适应为止。
|
||||
请注意textAlign和textBaseline将决定绘制的左右对齐和上下对齐方式。
|
||||
具体可详见core.setTextAlign()和core.setTextBaseline()函数。
|
||||
|
||||
|
||||
@ -62,6 +62,12 @@ maps.prototype._mapIntoBlocks = function (map, floor, floorId) {
|
||||
|
||||
////// 从ID获得数字 //////
|
||||
maps.prototype.getNumberById = function (id) {
|
||||
core.status.id2number = core.status.id2number || {};
|
||||
if (core.status.id2number[id] != null) return core.status.id2number[id];
|
||||
return core.status.id2number[id] = this._getNumberById(id);
|
||||
}
|
||||
|
||||
maps.prototype._getNumberById = function (id) {
|
||||
for (var number in this.blocksInfo) {
|
||||
if ((this.blocksInfo[number] || {}).id == id)
|
||||
return parseInt(number) || 0;
|
||||
|
||||
25
libs/ui.js
25
libs/ui.js
@ -53,11 +53,30 @@ ui.prototype.clearMap = function (name, x, y, width, height) {
|
||||
}
|
||||
|
||||
////// 在某个canvas上绘制一段文字 //////
|
||||
ui.prototype.fillText = function (name, text, x, y, style, font) {
|
||||
ui.prototype.fillText = function (name, text, x, y, style, font, maxWidth) {
|
||||
if (style) core.setFillStyle(name, style);
|
||||
if (font) core.setFont(name, font);
|
||||
var ctx = this.getContextByName(name);
|
||||
if (ctx) ctx.fillText(text, x, y);
|
||||
if (ctx) {
|
||||
// 如果存在最大宽度
|
||||
if (maxWidth != null)
|
||||
this._fillTextWithMaxWidth(ctx, text, x, y, maxWidth);
|
||||
else
|
||||
ctx.fillText(text, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
////// 自适配字体大小
|
||||
ui.prototype._fillTextWithMaxWidth = function (ctx, text, x, y, maxWidth) {
|
||||
// 获得当前字体
|
||||
var font = ctx.font, u = /(\d+)px/.exec(font);
|
||||
if (u == null) return ctx.fillText(text, x, y);
|
||||
for (var font_size = parseInt(u[1]); font_size >= 8; font_size--) {
|
||||
ctx.font = font.replace(/(\d+)px/, font_size+"px");
|
||||
if (ctx.measureText(text).width <= maxWidth) break;
|
||||
}
|
||||
ctx.fillText(text, x, y);
|
||||
ctx.font = font;
|
||||
}
|
||||
|
||||
////// 在某个canvas上绘制粗体 //////
|
||||
@ -875,7 +894,7 @@ ui.prototype._drawTextBox_getHorizontalPosition = function (content, titleInfo,
|
||||
|
||||
ui.prototype._drawTextBox_getVerticalPosition = function (content, titleInfo, posInfo, validWidth) {
|
||||
var textAttribute = core.status.textAttribute || core.initStatus.textAttribute;
|
||||
var lineHeight = textAttribute.textfont + 5;
|
||||
var lineHeight = textAttribute.textfont + 6;
|
||||
var realContent = this._getRealContent(content);
|
||||
var height = 30 + lineHeight * core.splitLines("ui", realContent, validWidth, this._buildFont()).length;
|
||||
if (titleInfo.title) height += textAttribute.titlefont + 5;
|
||||
|
||||
@ -913,9 +913,6 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
||||
"saveData": function () {
|
||||
// 存档操作,此函数应该返回“具体要存档的内容”
|
||||
|
||||
// 勇士和hash值(防改存档文件来作弊)
|
||||
var hero = core.clone(core.status.hero),
|
||||
hashCode = core.utils.hashCode(hero);
|
||||
// 差异化存储values
|
||||
var values = {};
|
||||
for (var key in core.values) {
|
||||
@ -926,7 +923,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
||||
// 要存档的内容
|
||||
var data = {
|
||||
'floorId': core.status.floorId,
|
||||
'hero': hero,
|
||||
'hero': core.clone(core.status.hero),
|
||||
'hard': core.status.hard,
|
||||
'maps': core.maps.saveMap(),
|
||||
'route': core.encodeRoute(core.status.route),
|
||||
@ -936,6 +933,9 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
||||
"time": new Date().getTime(),
|
||||
"hashCode": hashCode
|
||||
};
|
||||
if (core.flags.checkConsole) {
|
||||
data.hashCode = core.utils.hashCode(data.hero);
|
||||
}
|
||||
// 设置商店次数
|
||||
for (var shopId in core.status.shops) {
|
||||
data.shops[shopId] = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user