drawToolbox

This commit is contained in:
oc 2019-03-29 00:43:26 +08:00
parent 5e978fa2d4
commit 90407e94a0
2 changed files with 124 additions and 143 deletions

View File

@ -1234,49 +1234,47 @@ actions.prototype._keyUpQuickShop = function (keycode) {
////// 工具栏界面时的点击操作 //////
actions.prototype._clickToolbox = function (x, y) {
// 装备栏
if (x >= 10 && x <= 12 && y == 0) {
if (x >= this.LAST - 2 && y == 0) {
core.ui.closePanel();
core.openEquipbox();
return;
}
// 返回
if (x >= 10 && x <= 12 && y == 12) {
if (x >= this.LAST - 2 && y == this.LAST) {
core.ui.closePanel();
return;
}
var toolsPage = core.status.event.data.toolsPage;
var constantsPage = core.status.event.data.constantsPage;
// 上一页
if (x == 3 || x == 4) {
if (y == 7 && toolsPage > 1) {
if (x == this.HSIZE-2 || x == this.HSIZE-3) {
if (y == this.LAST - 5 && toolsPage > 1) {
core.status.event.data.toolsPage--;
core.ui.drawToolbox(core.status.event.selection);
}
if (y == 12 && constantsPage > 1) {
if (y == this.LAST && constantsPage > 1) {
core.status.event.data.toolsPage--;
core.ui.drawToolbox(core.status.event.selection);
}
}
// 下一页
if (x == 8 || x == 9) {
if (y == 7 && toolsPage < Math.ceil(Object.keys(core.status.hero.items.tools).length / 12)) {
if (x == this.HSIZE+2 || x == this.HSIZE+3) {
if (y == this.LAST - 5 && toolsPage < Math.ceil(Object.keys(core.status.hero.items.tools).length / this.LAST)) {
core.status.event.data.toolsPage++;
core.ui.drawToolbox(core.status.event.selection);
}
if (y == 12 && constantsPage < Math.ceil(Object.keys(core.status.hero.items.constants).length / 12)) {
if (y == this.LAST && constantsPage < Math.ceil(Object.keys(core.status.hero.items.constants).length / this.LAST)) {
core.status.event.data.constantsPage++;
core.ui.drawToolbox(core.status.event.selection);
}
}
var index = parseInt(x / 2);
;
if (y == 4) index += 0;
else if (y == 6) index += 6;
else if (y == 9) index += 12;
else if (y == 11) index += 18;
if (y == this.LAST - 8) index += 0;
else if (y == this.LAST - 6) index += this.HSIZE;
else if (y == this.LAST - 3) index += this.LAST;
else if (y == this.LAST - 1) index += this.LAST + this.HSIZE;
else index = -1;
if (index >= 0)
this._clickToolboxIndex(index);
}
@ -1285,12 +1283,12 @@ actions.prototype._clickToolbox = function (x, y) {
actions.prototype._clickToolboxIndex = function (index) {
var items = null;
var select;
if (index < 12) {
select = index + 12 * (core.status.event.data.toolsPage - 1);
if (index < this.LAST) {
select = index + this.LAST * (core.status.event.data.toolsPage - 1);
items = Object.keys(core.status.hero.items.tools).sort();
}
else {
select = index % 12 + 12 * (core.status.event.data.constantsPage - 1);
select = index % this.LAST + this.LAST * (core.status.event.data.constantsPage - 1);
items = Object.keys(core.status.hero.items.constants).sort();
}
if (items == null) return;
@ -1308,33 +1306,35 @@ actions.prototype._clickToolboxIndex = function (index) {
actions.prototype._keyDownToolbox = function (keycode) {
if (core.status.event.data == null) return;
var last_index = this.LAST - 1;
var tools = Object.keys(core.status.hero.items.tools).sort();
var constants = Object.keys(core.status.hero.items.constants).sort();
var index = core.status.event.selection;
var toolsPage = core.status.event.data.toolsPage;
var constantsPage = core.status.event.data.constantsPage;
var toolsTotalPage = Math.ceil(tools.length / 12);
var constantsTotalPage = Math.ceil(constants.length / 12);
var toolsLastIndex = toolsPage < toolsTotalPage ? 11 : (tools.length + 11) % 12;
var constantsLastIndex = 12 + (constantsPage < constantsTotalPage ? 11 : (constants.length + 11) % 12);
var toolsTotalPage = Math.ceil(tools.length / this.LAST);
var constantsTotalPage = Math.ceil(constants.length / this.LAST);
var toolsLastIndex = toolsPage < toolsTotalPage ? last_index : (tools.length + last_index) % this.LAST;
var constantsLastIndex = this.LAST + (constantsPage < constantsTotalPage ? last_index : (constants.length + last_index) % this.LAST);
if (keycode == 37) { // left
if (index == 0) { // 处理向前翻页
if (toolsPage > 1) {
core.status.event.data.toolsPage--;
index = 11;
index = last_index;
}
else return; // 第一页不向前翻
}
else if (index == 12) {
else if (index == this.LAST) {
if (constantsPage == 1) {
if (toolsTotalPage == 0) return;
core.status.event.data.toolsPage = toolsTotalPage;
index = (tools.length + 11) % 12;
index = (tools.length + last_index) % this.LAST;
}
else {
core.status.event.data.constantsPage--;
index = 23;
index = 2 * this.LAST - 1;
}
}
else index -= 1;
@ -1342,29 +1342,29 @@ actions.prototype._keyDownToolbox = function (keycode) {
return;
}
if (keycode == 38) { // up
if (index >= 12 && index <= 17) { // 进入tools
if (index >= this.LAST && index < this.LAST + this.HSIZE) { // 进入tools
if (toolsTotalPage == 0) return;
if (toolsLastIndex >= 6) index = Math.min(toolsLastIndex, index - 6);
else index = Math.min(toolsLastIndex, index - 12);
if (toolsLastIndex >= this.HSIZE) index = Math.min(toolsLastIndex, index - this.HSIZE);
else index = Math.min(toolsLastIndex, index - this.LAST);
}
else if (index < 6) return; // 第一行没有向上
else index -= 6;
else if (index < this.HSIZE) return; // 第一行没有向上
else index -= this.HSIZE;
this._clickToolboxIndex(index);
return;
}
if (keycode == 39) { // right
if (toolsPage < toolsTotalPage && index == 11) {
if (toolsPage < toolsTotalPage && index == last_index) {
core.status.event.data.toolsPage++;
index = 0;
}
else if (constantsPage < constantsTotalPage && index == 23) {
else if (constantsPage < constantsTotalPage && index == 2 * this.LAST - 1) {
core.status.event.data.constantsPage++;
index = 12;
index = this.LAST;
}
else if (index == toolsLastIndex) {
if (constantsTotalPage == 0) return;
core.status.event.data.constantsPage = 1;
index = 12;
index = this.LAST;
}
else if (index == constantsLastIndex) // 一个物品无操作
return;
@ -1374,16 +1374,17 @@ actions.prototype._keyDownToolbox = function (keycode) {
}
if (keycode == 40) { // down
var nextIndex = null;
if (index <= 5) {
if (toolsLastIndex > 5) nextIndex = Math.min(toolsLastIndex, index + 6);
else index += 6;
if (index < this.HSIZE) {
if (toolsLastIndex >= this.HSIZE) nextIndex = Math.min(toolsLastIndex, index + this.HSIZE);
else index += this.HSIZE;
}
if (nextIndex == null && index <= 11) {
if (nextIndex == null && index < this.LAST) {
if (constantsTotalPage == 0) return;
nextIndex = Math.min(index + 6, constantsLastIndex);
nextIndex = Math.min(index + this.HSIZE, constantsLastIndex);
}
if (nextIndex == null && index <= 17) {
if (constantsLastIndex > 17) nextIndex = Math.min(constantsLastIndex, index + 6);
if (nextIndex == null && index < this.LAST + this.HSIZE) {
if (constantsLastIndex >= this.LAST + this.HSIZE)
nextIndex = Math.min(constantsLastIndex, index + this.HSIZE);
}
if (nextIndex != null) {
this._clickToolboxIndex(nextIndex);

View File

@ -1710,149 +1710,129 @@ ui.prototype._drawMaps_buildData = function (index, x, y) {
////// 绘制道具栏 //////
ui.prototype.drawToolbox = function(index) {
// 设定eventdata
if (!core.isset(core.status.event.data) || !core.isset(core.status.event.data.toolsPage) || !core.isset(core.status.event.data.constantsPage))
core.status.event.data = {"toolsPage":1, "constantsPage":1, "selectId":null}
var info = this._drawToolbox_getInfo(index);
this._drawToolbox_drawBackground();
// 绘制线
core.setAlpha('ui', 1);
core.setStrokeStyle('ui', '#DDDDDD');
core.canvas.ui.lineWidth = 2;
core.canvas.ui.strokeWidth = 2;
core.setTextAlign('ui', 'right');
var line1 = this.PIXEL - 306;
this._drawToolbox_drawLine(line1, "消耗道具");
var line2 = this.PIXEL - 146;
this._drawToolbox_drawLine(line2, "永久道具");
this._drawToolbox_drawDescription(info, line1);
this._drawToolbox_drawContent(info, line1, info.tools, info.toolsPage, true);
this.drawPagination(info.toolsPage, info.toolsTotalPage, this.LAST - 5);
this._drawToolbox_drawContent(info, line2, info.constants, info.constantsPage);
this.drawPagination(info.constantsPage, info.constantsTotalPage);
core.setTextAlign('ui', 'center');
core.fillText('ui', '[装备栏]', this.PIXEL - 46, 25, '#DDDDDD', this._buildFont(15, true));
core.fillText('ui', '返回游戏', this.PIXEL - 46, this.PIXEL - 13,'#DDDDDD');
}
ui.prototype._drawToolbox_getInfo = function (index) {
// 设定eventdata
if (!core.status.event.data || core.status.event.data.toolsPage == null)
core.status.event.data = {"toolsPage":1, "constantsPage":1, "selectId":null}
// 获取物品列表
var tools = Object.keys(core.status.hero.items.tools).sort();
var constants = Object.keys(core.status.hero.items.constants).sort();
// 处理页数
var toolsPage = core.status.event.data.toolsPage;
var constantsPage = core.status.event.data.constantsPage;
var toolsTotalPage = Math.ceil(tools.length/12);
var constantsTotalPage = Math.ceil(constants.length/12);
var toolsTotalPage = Math.ceil(tools.length/this.LAST);
var constantsTotalPage = Math.ceil(constants.length/this.LAST);
// 处理index
if (!core.isset(index)) {
if (tools.length>0) index=0;
else if (constants.length>0) index=12;
else index=0;
}
if (index == null)
index = tools.length == 0 && constants.length > 0 ? this.LAST : 0;
core.status.event.selection=index;
// 确认选择对象
var select;
var selectId;
if (index<12) {
select = index + (toolsPage-1)*12;
var select, selectId;
if (index<this.LAST) {
select = index + (toolsPage-1)*this.LAST;
if (select>=tools.length) select=Math.max(0, tools.length-1);
selectId = tools[select];
}
else {
select = index%12 + (constantsPage-1)*12;
select = index%this.LAST + (constantsPage-1)*this.LAST;
if (select>=constants.length) select=Math.max(0, constants.length-1);
selectId = constants[select];
}
if (!core.hasItem(selectId)) selectId=null;
core.status.event.data.selectId=selectId;
return {
index: index, tools: tools, constants: constants, toolsPage: toolsPage, constantsPage: constantsPage,
toolsTotalPage: toolsTotalPage, constantsTotalPage: constantsTotalPage, selectId: selectId
};
}
ui.prototype._drawToolbox_drawBackground = function () {
// 绘制
core.clearMap('ui');
core.setAlpha('ui', 0.85);
core.fillRect('ui', 0, 0, 416, 416, '#000000');
core.setAlpha('ui', 1);
core.fillRect('ui', 0, 0, this.PIXEL, this.PIXEL, '#000000');
}
ui.prototype._drawToolbox_drawLine = function (yoffset, text) {
core.setFillStyle('ui', '#DDDDDD');
core.setStrokeStyle('ui', '#DDDDDD');
core.canvas.ui.lineWidth = 2;
core.canvas.ui.strokeWidth = 2;
var ydelta = 20;
// 画线
core.canvas.ui.beginPath();
core.canvas.ui.moveTo(0, 130-ydelta);
core.canvas.ui.lineTo(416, 130-ydelta);
core.canvas.ui.moveTo(0, yoffset);
core.canvas.ui.lineTo(this.PIXEL, yoffset);
core.canvas.ui.stroke();
core.canvas.ui.beginPath();
core.canvas.ui.moveTo(416,129-ydelta);
core.canvas.ui.lineTo(416,105-ydelta);
core.canvas.ui.lineTo(416-72,105-ydelta);
core.canvas.ui.lineTo(416-102,129-ydelta);
core.canvas.ui.moveTo(this.PIXEL, yoffset-1);
core.canvas.ui.lineTo(this.PIXEL, yoffset-25);
core.canvas.ui.lineTo(this.PIXEL-72, yoffset-25);
core.canvas.ui.lineTo(this.PIXEL-102, yoffset-1);
core.canvas.ui.fill();
core.fillText('ui', text, this.PIXEL - 5, yoffset-6, '#333333', this._buildFont(16, true));
}
core.canvas.ui.beginPath();
core.canvas.ui.moveTo(0, 290-ydelta);
core.canvas.ui.lineTo(416, 290-ydelta);
core.canvas.ui.stroke();
core.canvas.ui.beginPath();
core.canvas.ui.moveTo(416,289-ydelta);
core.canvas.ui.lineTo(416,265-ydelta);
core.canvas.ui.lineTo(416-72,265-ydelta);
core.canvas.ui.lineTo(416-102,289-ydelta);
core.canvas.ui.fill();
// 文字
core.setTextAlign('ui', 'right');
var globalFont = core.status.globalAttribute.font;
core.fillText('ui', "消耗道具", 411, 124-ydelta, '#333333', "bold 16px "+globalFont);
core.fillText('ui', "永久道具", 411, 284-ydelta);
ui.prototype._drawToolbox_drawDescription = function (info, max_height) {
core.setTextAlign('ui', 'left');
// 描述
if (core.isset(selectId)) {
var item=core.material.items[selectId];
core.fillText('ui', item.name, 10, 32, '#FFD700', "bold 20px "+globalFont)
if (info.selectId) {
var item=core.material.items[info.selectId];
core.fillText('ui', item.name, 10, 32, '#FFD700', this._buildFont(20, true))
var text = item.text||"该道具暂无描述。";
try {
// 检查能否eval
text = core.replaceText(text);
} catch (e) {}
var lines = core.splitLines('ui', text, 406, '17px '+globalFont);
core.fillText('ui', lines[0], 10, 62, '#FFFFFF', '17px '+globalFont);
if (lines.length==1) {
core.fillText('ui', '<继续点击该道具即可进行使用>', 10, 89, '#CCCCCC', '14px '+globalFont);
var lines = core.splitLines('ui', text, this.PIXEL - 15, this._buildFont(17, false));
// --- 开始逐行绘制
var curr = 62, line_height = 25;
core.setFillStyle('ui', '#FFFFFF');
for (var i=0;i<lines.length;++i) {
core.fillText('ui', lines[i], 10, curr);
curr += line_height;
if (curr>=max_height) break;
}
else {
var leftText = text.substring(lines[0].length);
core.fillText('ui', leftText, 10, 89, '#FFFFFF', '17px '+globalFont);
if (curr < max_height) {
core.fillText('ui', '<继续点击该道具即可进行使用>', 10, curr, '#CCCCCC', this._buildFont(14, false));
}
}
}
ui.prototype._drawToolbox_drawContent = function (info, line, items, page, drawCount) {
core.setTextAlign('ui', 'right');
var images = core.material.images.items;
// 消耗道具
for (var i=0;i<12;i++) {
var tool=tools[12*(toolsPage-1)+i];
if (!core.isset(tool)) break;
var yoffset = 144 + Math.floor(i/6)*54 + 5 - ydelta;
var icon=core.material.icons.items[tool];
core.drawImage('ui', images, 0, icon*32, 32, 32, 16*(4*(i%6)+1)+5, yoffset, 32, 32)
// 个数
core.fillText('ui', core.itemCount(tool), 16*(4*(i%6)+1)+40, yoffset+33, '#FFFFFF', "bold 14px "+globalFont);
if (selectId == tool)
core.strokeRect('ui', 16*(4*(i%6)+1)+1, yoffset-4, 40, 40, '#FFD700');
for (var i = 0; i < this.LAST; i++) {
var item = items[this.LAST * (page - 1) + i];
if (!item) continue;
var yoffset = line + 54 * Math.floor(i / this.HSIZE) + 19;
var icon = core.material.icons.items[item], image = core.material.images.items;
core.drawImage('ui', image, 0, 32 * icon, 32, 32, 64 * (i % this.HSIZE) + 21, yoffset, 32, 32);
if (drawCount)
core.fillText('ui', core.itemCount(item), 64 * (i % this.HSIZE) + 56, yoffset + 33, '#FFFFFF', this._buildFont(14, true));
if (info.selectId == item)
core.strokeRect('ui', 64 * (i % this.HSIZE) + 17, yoffset - 4, 40, 40, '#FFD700');
}
// 永久道具
for (var i=0;i<12;i++) {
var constant=constants[12*(constantsPage-1)+i];
if (!core.isset(constant)) break;
var yoffset = 304+Math.floor(i/6)*54+5-ydelta;
var icon=core.material.icons.items[constant];
core.drawImage('ui', images, 0, icon*32, 32, 32, 16*(4*(i%6)+1)+5, yoffset, 32, 32)
if (selectId == constant)
core.strokeRect('ui', 16*(4*(i%6)+1)+1, yoffset-4, 40, 40, '#FFD700');
}
// 分页
this.drawPagination(toolsPage, toolsTotalPage, 7);
this.drawPagination(constantsPage, constantsTotalPage, 12);
core.setTextAlign('ui', 'center');
// 装备栏
// if (core.flags.equipment)
core.fillText('ui', '[装备栏]', 370, 25,'#DDDDDD', 'bold 15px '+globalFont);
// core.fillText('ui', '删除道具', 370, 32,'#DDDDDD', 'bold 15px '+globalFont);
// 退出
core.fillText('ui', '返回游戏', 370, 403,'#DDDDDD', 'bold 15px '+globalFont);
}
////// 绘制装备界面 //////