diff --git a/_server/table/plugins.comment.js b/_server/table/plugins.comment.js index 0ea6e33..a9cb7a1 100644 --- a/_server/table/plugins.comment.js +++ b/_server/table/plugins.comment.js @@ -128,6 +128,12 @@ var plugins_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_type": "textarea", "_range": "typeof(thiseval)=='string' || thiseval==null", "_data": "背景音乐拼接" + }, + "scrollingText": { + "_leaf": true, + "_type": "textarea", + "_range": "typeof(thiseval)=='string' || thiseval==null", + "_data": "接收&发送在线留言" } } if (obj[key]) return obj[key]; diff --git a/project/data.js b/project/data.js index 9047933..c8c6aef 100644 --- a/project/data.js +++ b/project/data.js @@ -1520,7 +1520,7 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = }, "firstData": { "title": "秽翼的尤斯蒂娅", - "name": "Eustia", + "name": "Eustia_text", "version": "鸽子窝造塔小队", "floorId": "jiaocheng01", "hero": { @@ -1935,7 +1935,7 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = }, { "type": "function", - "function": "function(){\ncore.getItem('book', 1);\ncore.getItem('fly', 1);\n}" + "function": "function(){\ncore.getItem('book', 1);\ncore.getItem('fly', 1);\ncore.getItem('postman', 1);\ncore.getItem('I369', 1);\n}" }, { "type": "insert", diff --git a/project/floors/jiaocheng01.js b/project/floors/jiaocheng01.js index ee12147..1c5cd0f 100644 --- a/project/floors/jiaocheng01.js +++ b/project/floors/jiaocheng01.js @@ -1,7 +1,7 @@ main.floors.jiaocheng01= { "floorId": "jiaocheng01", - "title": "广场", + "title": "教程1", "name": "1", "width": 13, "height": 13, @@ -70,7 +70,7 @@ main.floors.jiaocheng01= [129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,129], [ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1] ], - "areas": "牢狱", + "areas": "教程", "bgmap": [ ], diff --git a/project/floors/jiaocheng02.js b/project/floors/jiaocheng02.js index 78b800f..e36624e 100644 --- a/project/floors/jiaocheng02.js +++ b/project/floors/jiaocheng02.js @@ -1,7 +1,7 @@ main.floors.jiaocheng02= { "floorId": "jiaocheng02", - "title": "广场", + "title": "教程2", "name": "1", "width": 13, "height": 13, @@ -82,7 +82,7 @@ main.floors.jiaocheng02= [ 28, 1, 30, 1, 27,129, 0,204, 0, 33, 0, 23, 0], [ 1, 1, 1, 1, 1, 1, 93, 1, 1, 1, 1, 1, 1] ], - "areas": "牢狱", + "areas": "教程", "bgmap": [ ], diff --git a/project/functions.js b/project/functions.js index 459927d..9727b82 100644 --- a/project/functions.js +++ b/project/functions.js @@ -192,6 +192,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = core.plugin.bfs(); } } + if (!core.isReplaying()) core.plugin.drawCommentSign() }, "flyTo": function (toId, callback) { // 楼层传送器的使用,从当前楼层飞往toId @@ -2022,6 +2023,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = nowy = core.getHeroLoc("y"); var block = core.getBlock(nowx, nowy); var hasTrigger = false; + core.showComment(nowx, nowy) if ( block != null && block.event.trigger == "getItem" && @@ -2061,7 +2063,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = core.status.hero.statistics.poisonDamage += damage; core.status.hero.hp -= damage; } - + core.showComment(nowx, nowy) core.clearMap("hero"); if ( core.bigmap.width * 32 === core.bigmap.height * 32 && diff --git a/project/icons.js b/project/icons.js index 73914d5..36641a7 100644 --- a/project/icons.js +++ b/project/icons.js @@ -326,7 +326,8 @@ var icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1 = "I373": 36, "I374": 37, "I375": 38, - "I396": 39 + "I396": 39, + "postman": 62 }, "autotile": { "autotile": 0, diff --git a/project/items.js b/project/items.js index aa455cd..b437a50 100644 --- a/project/items.js +++ b/project/items.js @@ -529,9 +529,31 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "canUseItemEffect": "true" }, "I369": { - "cls": "items", - "name": "新物品", - "canUseItemEffect": "true" + "cls": "constants", + "name": "动画开关", + "canUseItemEffect": "true", + "hideInToolbox": true, + "hideInReplay": true, + "useItemEvent": [ + { + "type": "confirm", + "text": "是否开启战斗动画", + "yes": [ + { + "type": "setValue", + "name": "flag:noAnimate", + "value": "false" + } + ], + "no": [ + { + "type": "setValue", + "name": "flag:noAnimate", + "value": "true" + } + ] + } + ] }, "I370": { "cls": "items", @@ -576,5 +598,13 @@ var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = "cls": "items", "name": "新物品", "canUseItemEffect": "true" + }, + "postman": { + "cls": "constants", + "name": "言灵", + "canUseItemEffect": "true", + "text": "可以发送和接收在线留言。", + "hideInToolbox": true, + "hideInReplay": true } } \ No newline at end of file diff --git a/project/maps.js b/project/maps.js index d1b42f0..dddf478 100644 --- a/project/maps.js +++ b/project/maps.js @@ -295,6 +295,7 @@ var maps_90f36752_8815_4be8_b32b_d7fad1d0542e = "394": {"cls":"terrains","id":"T394"}, "395": {"cls":"terrains","id":"T395"}, "396": {"cls":"items","id":"I396"}, + "397": {"cls":"items","id":"postman"}, "20034": {"cls":"tileset","id":"X20034","canPass":true}, "20154": {"cls":"tileset","id":"X20154","canPass":true}, "20216": {"cls":"tileset","id":"X20216","canPass":true}, diff --git a/project/materials/items.png b/project/materials/items.png index 04dc29b..2445872 100644 Binary files a/project/materials/items.png and b/project/materials/items.png differ diff --git a/project/plugins.js b/project/plugins.js index df24c93..5f97d09 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -2912,7 +2912,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = //道具栏列表 this.itemMx = [ //空位用‘none’填充,当前ui至多4列6行 - ["book", "wand", "none", "fly"], + ["book", "postman", "I369", "fly"], ["cross", "superPotion", "pickaxe"], ["bomb", "centerFly", "upFly"], ["none", "none", "none"], @@ -2929,7 +2929,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.openToolbox, core.doSL, ], - [main.core.openSettings, main.core.save, main.core.load, core.doSL], + [main.core.save, main.core.load, main.core.openSettings, core.doSL], ]; this.replayAction = [ [core.triggerReplay, core.stopReplay, core.rewindReplay], @@ -3561,7 +3561,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = ["speedDown", "speedUp", "save"], ] : [ ["keyboard", "shop", "pack", "T332"], - ["settings", "save", "load", "T331"], + ["save", "load", "settings", "T331"], ]; if (core.domStyle.isVertical) { core.clearMap( @@ -3630,15 +3630,6 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = case "book": core.openBook(true); break; - case "wand": - core.insertAction({ - type: "useItem", - id: itemId, - }); - break; - case "fly": - core.useItem(itemId); - break; default: core.useItem(itemId); } @@ -5605,1683 +5596,1680 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = }; }, "新道具栏/装备栏": function () { - // 这个插件有点离谱 个人觉得参数过多只会降低可读性,还不如硬编码 + // 这个插件有点离谱 个人觉得参数过多只会降低可读性,还不如硬编码 - // 注:///// *** 裹起来的区域: 该区域内参数可以随意更改调整ui绘制 不会影响总体布局 - // 请尽量修改该区域而不是其他区域 修改的时候最好可以对照现有ui修改 + // 注:///// *** 裹起来的区域: 该区域内参数可以随意更改调整ui绘制 不会影响总体布局 + // 请尽量修改该区域而不是其他区域 修改的时候最好可以对照现有ui修改 - ///// *** 道具类型 - // cls对应name - var itemClsName = { - constants: "永久道具", - tools: "消耗道具", - }; - // 一页最大放的道具数量 将把整个道具左栏分成num份 每份是一个道具项 - var itemNum = 12; - ///// *** + ///// *** 道具类型 + // cls对应name + var itemClsName = { + constants: "永久道具", + tools: "消耗道具", + }; + // 一页最大放的道具数量 将把整个道具左栏分成num份 每份是一个道具项 + var itemNum = 12; + ///// *** - // 背景设置 - function drawBoxBackground(ctx) { - core.setTextAlign(ctx, "left"); - core.clearMap(ctx); - core.deleteCanvas("_selector"); - var info = core.status.thisUIEventInfo || {}; + // 背景设置 + function drawBoxBackground(ctx) { + core.setTextAlign(ctx, "left"); + core.clearMap(ctx); + core.deleteCanvas("_selector"); + var info = core.status.thisUIEventInfo || {}; - ///// *** 背景设置 - var max = core.__PIXELS__; - var x = 2, - y = x, - w = max - x * 2, - h = w; - var borderWidth = 2, - borderRadius = 5, // radius:圆角矩形的圆角半径 - borderStyle = "#fff"; - var backgroundColor = "gray"; - // 设置背景不透明度(0.85) - var backgroundAlpha = 0.85; - ///// *** + ///// *** 背景设置 + var max = core.__PIXELS__; + var x = 2, + y = x, + w = max - x * 2, + h = w; + var borderWidth = 2, + borderRadius = 5, // radius:圆角矩形的圆角半径 + borderStyle = "#fff"; + var backgroundColor = "gray"; + // 设置背景不透明度(0.85) + var backgroundAlpha = 0.85; + ///// *** - var start_x = x + borderWidth / 2, - start_y = y + borderWidth / 2, - width = max - start_x * 2, - height = max - start_y * 2; + var start_x = x + borderWidth / 2, + start_y = y + borderWidth / 2, + width = max - start_x * 2, + height = max - start_y * 2; - // 渐变色背景的一个例子(黑色渐变白色): - // 有关渐变色的具体知识请网上搜索canvas createGradient了解 - /* + // 渐变色背景的一个例子(黑色渐变白色): + // 有关渐变色的具体知识请网上搜索canvas createGradient了解 + /* var grd = ctx.createLinearGradient(x, y, x + w, y); grd.addColorStop(0, "black"); grd.addColorStop(1, "white"); backgroundColor = grd; */ - // 使用图片背景要注释掉下面的strokeRect和fillRoundRect - // 图片背景的一个例子: - /* + // 使用图片背景要注释掉下面的strokeRect和fillRoundRect + // 图片背景的一个例子: + /* core.drawImage(ctx, "xxx.png", x, y, w, h); core.strokeRect(ctx, x, y, w, h, borderStyle, borderWidth); */ - core.setAlpha(ctx, backgroundAlpha); - core.strokeRoundRect( - ctx, - x, - y, - w, - h, - borderRadius, - borderStyle, - borderWidth - ); - core.fillRoundRect( - ctx, - start_x, - start_y, - width, - height, - borderRadius, - backgroundColor - ); - core.setAlpha(ctx, 1); - - ///// *** 左栏配置 - var leftbar_height = height; - // 左边栏宽度(width*0.6) 本身仅为坐标使用 需要与底下的rightbar_width(width*0.4)同时更改 - var leftbar_width = width * 0.6; - ///// *** - - // xxx_right参数 代表最右侧坐标 - var leftbar_right = start_x + leftbar_width - borderWidth / 2; - var leftbar_bottom = start_y + leftbar_height; - var leftbar_x = start_x; - var leftbar_y = start_y; - - ///// *** 道具栏配置 - var boxName_color = "#fff"; - var boxName_fontSize = 15; - var boxName_font = core.ui._buildFont(boxName_fontSize, true); - var arrow_x = 10 + start_x; - var arrow_y = 10 + start_y; - var arrow_width = 20; - var arrow_style = "white"; - // 暂时只能是1 否则不太行 等待新样板(2.7.3)之后对drawArrow做优化 - var arrow_lineWidth = 2; - // 右箭头 - var rightArrow_right = leftbar_right - 10; - // 道具内栏顶部坐标 本质是通过该项 控制(道具栏顶部文字和箭头)与道具内栏顶部的间隔 - var itembar_top = arrow_y + 15; - ///// *** - - var itembar_right = rightArrow_right; - var boxName = - core.status.event.id == "toolbox" - ? "\r[yellow]道具栏\r | 装备栏" - : "道具栏 | \r[yellow]装备栏\r"; - core.drawArrow( - ctx, - arrow_x + arrow_width, - arrow_y, - arrow_x, - arrow_y, - arrow_style, - arrow_lineWidth - ); - core.drawArrow( - ctx, - rightArrow_right - arrow_width, - arrow_y, - rightArrow_right, - arrow_y, - arrow_style, - arrow_lineWidth - ); - core.setTextAlign(ctx, "center"); - core.setTextBaseline(ctx, "middle"); - var changeBox = function () { - var id = core.status.event.id; - core.closePanel(); - if (id == "toolbox") core.openEquipbox(); - else core.openToolbox(); - }; - core.fillText( - ctx, - boxName, - (leftbar_right + leftbar_x) / 2, - arrow_y + 2, - boxName_color, - boxName_font - ); - - ///// *** 底栏按钮 - var pageBtn_radius = 8; - // xxx_left 最左侧坐标 - var pageBtn_left = leftbar_x + 3; - var pageBtn_right = leftbar_right - 3; - // xxx_bottom 最底部坐标 - var pageBtn_bottom = leftbar_bottom - 2; - var pageBtn_borderStyle = "#fff"; - var pageBtn_borderWidth = 2; - var pageText_color = "#fff"; - // 底部按钮与上面的道具内栏的间隔大小 - var bottomSpace = 8; - ///// *** - - drawItemListbox_setPageBtn( - ctx, - pageBtn_left, - pageBtn_right, - pageBtn_bottom, - pageBtn_radius, - pageBtn_borderStyle, - pageBtn_borderWidth - ); - var page = info.page || 1; - var pageFontSize = pageBtn_radius * 2 - 4; - var pageFont = core.ui._buildFont(pageFontSize); - setPageItems(page); - var num = itemNum; - if (core.status.event.id == "equipbox") num -= 5; - var maxPage = info.maxPage; - var pageText = page + " / " + maxPage; - core.setTextAlign(ctx, "center"); - core.setTextBaseline(ctx, "bottom"); - core.fillText( - ctx, - pageText, - (leftbar_x + leftbar_right) / 2, - pageBtn_bottom, - pageText_color, - pageFont - ); - addUIEventListener( - start_x, - start_y, - leftbar_right - start_x, - arrow_y - start_y + 13, - changeBox - ); - var itembar_height = Math.ceil( - pageBtn_bottom - - pageBtn_radius * 2 - - pageBtn_borderWidth / 2 - - bottomSpace - - itembar_top - ); - var oneItemHeight = (itembar_height - 4) / itemNum; - return { - x: start_x, - y: start_y, - width: width, - height: height, - leftbar_right: leftbar_right, - obj: { - x: arrow_x, - y: itembar_top, - width: itembar_right - arrow_x, - height: itembar_height, - oneItemHeight: oneItemHeight, - }, - }; - } - - function drawItemListbox(ctx, obj) { - ctx = ctx || core.canvas.ui; - var itembar_x = obj.x, - itembar_y = obj.y, - itembar_width = obj.width, - itembar_height = obj.height, - itemNum = obj.itemNum, - oneItemHeight = obj.oneItemHeight; - var itembar_right = itembar_x + itembar_width; - var info = core.status.thisUIEventInfo || {}; - var obj = {}; - var page = info.page || 1, - index = info.index, - select = info.select || {}; - - ///// *** 道具栏内栏配置 - var itembar_style = "black"; - var itembar_alpha = 0.7; - // 一个竖屏下减少道具显示的例子: - // if (core.domStyle.isVertical) itemNum = 10; - // 每个道具项的上下空隙占总高度的比例 - var itembar_marginHeightRatio = 0.2; - // 左右间隔空隙 - var item_marginLeft = 2; - var item_x = itembar_x + 2, - item_y = itembar_y + 2, - item_right = itembar_right - 2, - itemName_color = "#fff"; - // 修改此项以更换闪烁光标 - var item_selector = "winskin.webp"; - ///// *** - - core.setAlpha(ctx, itembar_alpha); - core.fillRect( - ctx, - itembar_x, - itembar_y, - itembar_width, - itembar_height, - itembar_style - ); - core.setAlpha(ctx, 1); - var pageItems = setPageItems(page); - var marginHeight = itembar_marginHeightRatio * oneItemHeight; - core.setTextBaseline(ctx, "middle"); - var originColor = itemName_color; - for (var i = 0; i < pageItems.length; i++) { - itemName_color = originColor; - var item = pageItems[i]; - // 设置某个的字体颜色的一个例子 - // if (item.id == "xxx") itemName_color = "green"; - drawItemListbox_drawItem( - ctx, - item_x, - item_right, - item_y, - oneItemHeight, - item_marginLeft, - marginHeight, - itemName_color, - pageItems[i] - ); - if (index == i + 1) - core.ui._drawWindowSelector( - item_selector, - item_x + 1, - item_y - 1, - item_right - item_x - 2, - oneItemHeight - 2 - ); - item_y += oneItemHeight; - } - } - - function drawToolboxRightbar(ctx, obj) { - ctx = ctx || core.canvas.ui; - var info = core.status.thisUIEventInfo || {}; - var page = info.page || 1, - index = info.index || 1, - select = info.select || {}; - var start_x = obj.x, - start_y = obj.y, - width = obj.width, - height = obj.height; - var toolboxRight = start_x + width, - toolboxBottom = start_y + height; - - ///// *** 侧边栏(rightbar)背景设置(物品介绍) - var rightbar_width = width * 0.4; - var rightbar_height = height; - var rightbar_lineWidth = 2; - var rightbar_lineStyle = "#fff"; - ///// *** - - var rightbar_x = toolboxRight - rightbar_width - rightbar_lineWidth / 2; - var rightbar_y = start_y; - core.drawLine( - ctx, - rightbar_x, - rightbar_y, - rightbar_x, - rightbar_y + rightbar_height, - rightbar_lineStyle, - rightbar_lineWidth - ); - - // 获取道具id(有可能为null) - var itemId = select.id; - var item = core.material.items[itemId]; - - ///// *** 侧边栏物品Icon信息 - var iconRect_y = rightbar_y + 10; - // space:间距 - // 这里布局设定iconRect与侧边栏左边框 itemName与工具栏右边框 itemRect与itemName的间距均为space - var space = 15; - var iconRect_x = rightbar_x + space; - var iconRect_radius = 2, - iconRect_width = 32, - iconRect_height = 32, - iconRect_style = "#fff", - iconRect_lineWidth = 2; - ///// *** - - var iconRect_bottom = iconRect_y + iconRect_height, - iconRect_right = iconRect_x + iconRect_width; - - ///// *** 侧边栏各项信息 - var itemTextFontSize = 15, - itemText_x = iconRect_x - 4, - itemText_y = Math.floor(start_y + rightbar_height * 0.25), // 坐标取整防止模糊 - itemClsFontSize = 15, - itemClsFont = core.ui._buildFont(itemClsFontSize), - itemClsColor = "#fff", - itemCls_x = itemText_x - itemClsFontSize / 2, - itemCls_middle = (iconRect_bottom + itemText_y) / 2, //_middle代表文字的中心y坐标 - itemNameFontSize = 18, - itemNameColor = "#fff", - itemNameFont = core.ui._buildFont(itemNameFontSize, true); - var itemName_x = iconRect_right + space; - var itemName_middle = - iconRect_y + iconRect_height / 2 + iconRect_lineWidth; - // 修改这里可以编辑未选中道具时的默认值 - var defaultItem = { - cls: "constants", - name: "未知道具", - text: "没有道具最永久", - }; - var defaultEquip = { - cls: "equips", - name: "未知装备", - text: "一无所有,又何尝不是一种装备", - equip: { - type: "装备", - }, - }; - ///// *** - - var originItem = item; - if (core.status.event.id == "equipbox") item = item || defaultEquip; - item = item || defaultItem; - var itemCls = item.cls, - itemName = item.name, - itemText = item.text; - itemText = core.replaceText(itemText); - if (!itemText) itemText = "该道具无描述。"; - /* 一个根据道具id修改道具名字(右栏)的例子 - * if (item.id == "xxx") itemNameColor = "red"; - */ - var itemClsName = core.getItemClsName(item); - var itemNameMaxWidth = - rightbar_width - iconRect_width - iconRect_lineWidth * 2 - space * 2; - core.strokeRoundRect( - ctx, - iconRect_x, - iconRect_y, - iconRect_width, - iconRect_height, - iconRect_radius, - iconRect_style, - iconRect_lineWidth - ); - if (item.id) - core.drawIcon( - ctx, - item.id, - iconRect_x + iconRect_lineWidth / 2, - iconRect_y + iconRect_lineWidth / 2, - iconRect_width - iconRect_lineWidth, - iconRect_height - iconRect_lineWidth - ); - core.setTextAlign(ctx, "left"); - core.setTextBaseline(ctx, "middle"); - if (itemCls === "equips" && item.id) { - itemName = "【" + item.equipCls + "】" + itemName; - } - core.fillText( - ctx, - itemName, - itemName_x, - itemName_middle, - itemNameColor, - itemNameFont, - itemNameMaxWidth - ); - if (!item.equip) - core.fillText( - ctx, - "【" + itemClsName + "】", - itemCls_x, - itemCls_middle, - itemClsColor, - itemClsFont - ); - - var statusText = ""; - if (core.status.event.id == "equipbox") { - var type = item.equip.type; - if (typeof type == "string") type = core.getEquipTypeByName(type); - var compare = core.compareEquipment(item.id, core.getEquip(type)); - var compare2; - if (item.equipCls === "双手剑") - compare2 = core.compareEquipment(null, core.getEquip(1)); - if ( - item.equipCls === "盾牌" && - core.material.items[core.getEquip(0)]?.equipCls === "双手剑" - ) - compare2 = core.compareEquipment(null, core.getEquip(0)); - if (info.select.action == "unload") - compare = core.compareEquipment(null, item.id); - // --- 变化值... - for (var name in core.status.hero) { - if (typeof core.status.hero[name] != "number") continue; - var nowValue = core.getRealStatus(name); - // 查询新值 - var newValue = Math.floor( - ((core.getStatus(name) + - (compare.value[name] || 0) + - (compare2?.value[name] || 0)) * - (core.getBuff(name) * 100 + - (compare.percentage[name] || 0) + - (compare2?.percentage[name] || 0))) / - 100 - ); - if (name === "mdef") { - var nowValue = core.getRealStatus(name); - var newValue = Math.round( - (core.getStatus(name) - - (compare.value[name] || 0) - - (compare2?.value[name] || 0)) * - (1 - - (1 - core.getBuff(name)) * - (compare.percentage[name] || 1) * - (compare2?.percentage[name] || 1)) - ); - } - if (nowValue == newValue) continue; - var color = newValue > nowValue ? "#00FF00" : "#FF0000"; - nowValue = core.formatBigNumber(nowValue); - newValue = core.formatBigNumber(newValue); - - if (name === "mdef") { - nowValue += "%"; - newValue += "%"; - } - statusText += - core.getStatusLabel(name) + - " " + - nowValue + - "->\r[" + - color + - "]" + - newValue + - "\r\n"; - } - } - itemText = statusText + itemText; - if (item.equip) { - core.drawTextContent(ctx, itemText, { - left: itemText_x, - top: itemCls_middle, - bold: false, - color: "white", - align: "left", - fontSize: itemTextFontSize, - maxWidth: - rightbar_width - - (itemText_x - rightbar_x) * 2 + - itemTextFontSize / 2, - }); - } else { - core.drawTextContent(ctx, itemText, { - left: itemText_x, - top: itemText_y, - bold: false, - color: "white", - align: "left", - fontSize: itemTextFontSize, - maxWidth: - rightbar_width - - (itemText_x - rightbar_x) * 2 + - itemTextFontSize / 2, - }); - } - - ///// *** 退出按钮设置 - var btnRadius = 10; - var btnBorderWidth = 2; - var btnRight = toolboxRight - 2; - var btnBottom = toolboxBottom - 2; - var btnBorderStyle = "#fff"; - ///// *** - - // 获取圆心位置 - var btn_x = btnRight - btnRadius - btnBorderWidth / 2; - btn_y = btnBottom - btnRadius - btnBorderWidth / 2; - drawToolbox_setExitBtn( - ctx, - btn_x, - btn_y, - btnRadius, - btnBorderStyle, - btnBorderWidth - ); - - ///// *** 使用按钮设置 - var useBtnHeight = btnRadius * 2; - // 这里不设置useBtnWidth而是根据各项数据自动得出width - var useBtnRadius = useBtnHeight / 4; - var useBtn_x = rightbar_x + 4, - useBtn_y = btnBottom - useBtnHeight; - var useBtnBorderStyle = "#fff"; - var useBtnBorderWidth = btnBorderWidth; - const batchUseBtn_x = useBtn_x + 50; // 个人觉得,搞这么多参数还不如硬编码 - const hideBtn_y = useBtn_y - useBtnHeight - 8; - ///// *** - - drawToolbox_setUseBtn( - ctx, - useBtn_x, - useBtn_y, - useBtnRadius, - useBtnHeight, - useBtnBorderStyle, - useBtnBorderWidth - ); - if (core.status.event.id === "toolbox") { - drawToolbox_setBatchUseBtn( - ctx, - batchUseBtn_x, - useBtn_y, - useBtnRadius, - useBtnHeight, - useBtnBorderStyle, - useBtnBorderWidth - ); - } - drawToolbox_setHideBtn( - ctx, - useBtn_x, - hideBtn_y, - useBtnRadius, - useBtnHeight, - useBtnBorderStyle, - useBtnBorderWidth - ); - drawToolbox_setShowHideBtn( - ctx, - rightbar_x, - useBtn_y, - useBtnHeight, - useBtnBorderStyle - ); - } - - function drawEquipbox_drawOthers(ctx, obj) { - var info = core.status.thisUIEventInfo; - - ///// *** 装备格设置 - var equipList_lineWidth = 2; - var equipList_boxSize = 32; - var equipList_borderWidth = 2; - var equipList_borderStyle = "#fff"; - var equipList_nameColor = "#fff"; - ///// *** - - var equipList_x = obj.x + 4, - equipList_bottom = obj.obj.y - equipList_lineWidth, - equipList_y = equipList_bottom - obj.obj.oneItemHeight * reduceItem - 2, - equipList_height = equipList_bottom - equipList_y; - var equipList_right = obj.leftbar_right, - equipList_width = equipList_right - equipList_x; - core.drawLine( - ctx, - obj.x, - equipList_bottom + equipList_lineWidth / 2, - equipList_right, - equipList_bottom + equipList_lineWidth / 2, - equipList_borderStyle, - equipList_lineWidth - ); - var toDrawList = core.status.globalAttribute.equipName, - len = toDrawList.length; - - ///// *** 装备格设置 - var maxItem = 2; - var box_width = 32, - box_height = 32, - box_borderStyle = "#fff", - box_selectBorderStyle = "gold", // 选中的装备格的颜色 - box_borderWidth = 2; - var boxName_fontSize = 14, - boxName_space = 2, - boxName_color = "#fff"; // 装备格名称与上面的装备格框的距离 - var maxLine = Math.ceil(len / maxItem); - ///// *** - var l = Math.sqrt(len); - if (Math.pow(l) == len && len != 4) { - if (l <= maxItem) maxItem = l; - } - maxItem = Math.min(toDrawList.length, maxItem); - info.equips = maxItem; - - var boxName_font = core.ui._buildFont(boxName_fontSize); - // 总宽高减去所有装备格宽高得到空隙大小 - var oneBoxWidth = box_width + box_borderWidth * 2; - var oneBoxHeight = - box_height + boxName_fontSize + boxName_space + 2 * box_borderWidth; - var space_y = (equipList_height - maxLine * oneBoxHeight) / (1 + maxLine), - space_x = (equipList_width - maxItem * oneBoxWidth) / (1 + maxItem); - var box_x = equipList_x + space_x, - box_y = equipList_y + space_y + 12; - for (var i = 0; i < 2; i++) { - var id = core.getEquip(i), - name = toDrawList[i]; - if (i === 0) name = "主手"; - if (i === 1) name = "副手"; - var selectBorder = false; - if (core.status.thisUIEventInfo.select.type == i) selectBorder = true; - var borderStyle = selectBorder - ? box_selectBorderStyle - : box_borderStyle; - drawEquipbox_drawOne( - ctx, - name, - id, - box_x, - box_y, - box_width, - box_height, - boxName_space, - boxName_font, - boxName_color, - borderStyle, - box_borderWidth - ); - var todo = new Function( - "core.clickOneEquipbox('" + id + "'," + i + ")" - ); - addUIEventListener( - box_x - box_borderWidth / 2, - box_y - box_borderWidth / 2, - oneBoxWidth, - oneBoxHeight, - todo - ); - box_x += space_x + oneBoxWidth; - if ((i + 1) % maxItem == 0) { - box_x = equipList_x + space_x; - box_y += space_y + oneBoxHeight; - } - } - if (core.material.items[core.getEquip(0)]?.equipCls === "双手剑") { - core.drawLine( - ctx, - equipList_x + space_x + space_x + oneBoxWidth, - equipList_y + space_y + 12, - equipList_x + - space_x + - space_x + - oneBoxWidth + - box_width + - box_borderWidth, - equipList_y + space_y + box_height + 12 - ); - core.drawLine( - ctx, - equipList_x + space_x + space_x + oneBoxWidth, - equipList_y + space_y + box_height + 12, - equipList_x + - space_x + - space_x + - oneBoxWidth + - box_width + - box_borderWidth, - equipList_y + space_y + 12 - ); - } - ///// *** 装备格设置 - var maxItem = 3; - var box_width = 32, - box_height = 32, - box_borderStyle = "#fff", - box_selectBorderStyle = "gold", // 选中的装备格的颜色 - box_borderWidth = 2; - var boxName_fontSize = 14, - boxName_space = 2, - boxName_color = "#fff"; // 装备格名称与上面的装备格框的距离 - var maxLine = Math.ceil(len / maxItem); - ///// *** - var l = Math.sqrt(len); - if (Math.pow(l) == len && len != 4) { - if (l <= maxItem) maxItem = l; - } - maxItem = Math.min(toDrawList.length, maxItem); - info.equips = maxItem; - - var boxName_font = core.ui._buildFont(boxName_fontSize); - // 总宽高减去所有装备格宽高得到空隙大小 - var oneBoxWidth = box_width + box_borderWidth * 2; - var oneBoxHeight = - box_height + boxName_fontSize + boxName_space + 2 * box_borderWidth; - var space_y = (equipList_height - maxLine * oneBoxHeight) / (1 + maxLine), - space_x = (equipList_width - maxItem * oneBoxWidth) / (1 + maxItem); - var box_x = equipList_x + space_x, - box_y = equipList_y + space_y + space_y + oneBoxHeight; - for (var i = 2; i < len; i++) { - var id = core.getEquip(i), - name = toDrawList[i]; - var selectBorder = false; - if (core.status.thisUIEventInfo.select.type == i) selectBorder = true; - var borderStyle = selectBorder - ? box_selectBorderStyle - : box_borderStyle; - drawEquipbox_drawOne( - ctx, - name, - id, - box_x, - box_y, - box_width, - box_height, - boxName_space, - boxName_font, - boxName_color, - borderStyle, - box_borderWidth - ); - var todo = new Function( - "core.clickOneEquipbox('" + id + "'," + i + ")" - ); - addUIEventListener( - box_x - box_borderWidth / 2, - box_y - box_borderWidth / 2, - oneBoxWidth, - oneBoxHeight, - todo - ); - box_x += space_x + oneBoxWidth; - } - } - - this.drawToolbox = function (ctx) { - ctx = ctx || core.canvas.ui; - core.status.thisEventClickArea = []; - - var info = drawBoxBackground(ctx); - info.itemNum = itemNum; - drawItemListbox(ctx, info.obj); - drawToolboxRightbar(ctx, info); - core.setTextBaseline(ctx, "alphabetic"); - core.setTextAlign("left"); - }; - - var reduceItem = 4; - this.drawEquipbox = function (ctx) { - ctx = ctx || core.canvas.ui; - core.status.thisEventClickArea = []; - var info = drawBoxBackground(ctx); - info.itemNum = itemNum - reduceItem; - info.obj.y += info.obj.oneItemHeight * reduceItem; - info.obj.height -= info.obj.oneItemHeight * reduceItem; - drawItemListbox(ctx, info.obj); - drawEquipbox_drawOthers(ctx, info); - drawToolboxRightbar(ctx, info); - core.setTextBaseline(ctx, "alphabetic"); - core.setTextAlign("left"); - }; - - function drawEquipbox_drawOne( - ctx, - name, - id, - x, - y, - width, - height, - space, - font, - color, - style, - lineWidth - ) { - if (id) - core.drawIcon( - ctx, - id, - x + lineWidth / 2, - y + lineWidth / 2, - width, - height - ); - core.strokeRect( - ctx, - x, - y, - width + lineWidth, - height + lineWidth, - style, - lineWidth - ); - core.setTextAlign(ctx, "center"); - core.setTextBaseline(ctx, "top"); - var tx = (x + x + lineWidth / 2 + width) / 2, - ty = y + height + (lineWidth / 2) * 3 + space; - core.fillText(ctx, name, tx, ty, color, font); - - core.setAlpha(ctx, 1); - - core.setTextBaseline(ctx, "alphabetic"); - core.setTextAlign("left"); - } - - function drawItemListbox_drawItem( - ctx, - left, - right, - top, - height, - marginLeft, - marginHeight, - style, - id - ) { - var info = core.status.thisUIEventInfo; - var nowClick = info.index; - var item = core.material.items[id] || {}; - var name = item.name || "???"; - var num = core.itemCount(id) || 0; - var fontSize = Math.floor(height - marginHeight * 2); - core.setTextAlign(ctx, "right"); - var numText = "x" + num; - core.fillText( - ctx, - numText, - right - marginLeft, - top + height / 2, - style, - core.ui._buildFont(fontSize) - ); - - const hideInfo = core.getFlag("hideInfo", {}); - if ( - item && - (hideInfo.hasOwnProperty(id) ? hideInfo[id] : item.hideInToolbox) - ) - core.setAlpha(ctx, 0.5); - - if (name != "???") - core.drawIcon( - ctx, - id, - left + marginLeft, - top + marginHeight, - fontSize, - fontSize - ); - var text_x = left + marginLeft + fontSize + 2; - var maxWidth = right - core.calWidth(ctx, numText) - text_x; - core.setTextAlign(ctx, "left"); - core.fillText( - ctx, - name, - text_x, - top + height / 2, - style, - core.ui._buildFont(fontSize), - maxWidth - ); - core.setAlpha(ctx, 1); - - var todo = new Function("core.clickItemFunc('" + id + "');"); - addUIEventListener(left, top, right - left, height, todo); - } - - function setPageItems(page) { - var num = itemNum; - if (core.status.event.id == "equipbox") num -= reduceItem; - var info = core.status.thisUIEventInfo; - if (!info) return; - page = page || info.page; - var items = core.getToolboxItems( - core.status.event.id == "toolbox" ? "all" : "equips", - core.getFlag("showHideItem", false) - ); - info.allItems = items; - var maxPage = Math.ceil(items.length / num); - info.maxPage = maxPage; - var pageItems = items.slice((page - 1) * num, page * num); - info.pageItems = pageItems; - info.maxItem = pageItems.length; - if (items.length == 0 && pageItems.length == 0) info.index = null; - if (pageItems.length == 0 && info.page > 1) { - info.page = Math.max(1, info.page - 1); - return setPageItems(info.page); - } - return pageItems; - } - - function drawToolbox_setExitBtn(ctx, x, y, r, style, lineWidth) { - core.strokeCircle(ctx, x, y, r, style, lineWidth); - ctx.textAlign = "center"; - ctx.textBaseline = "middle"; - var textSize = Math.sqrt(2) * r; - core.fillText( - ctx, - "x", - x, - y, - style, - core.ui._buildFont(textSize), - textSize - ); - core.setTextAlign(ctx, "start"); - core.setTextBaseline(ctx, "top"); - - var todo = function () { - core.closePanel(); - }; - addUIEventListener(x - r, y - r, r * 2, r * 2, todo); - } - - function drawToolbox_setUseBtn(ctx, x, y, r, h, style, lineWidth) { - core.setTextAlign(ctx, "left"); - core.setTextBaseline(ctx, "top"); - var fontSize = h - 4; - var font = core.ui._buildFont(fontSize); - var text = core.status.event.id == "toolbox" ? "使用" : "装备"; - if (core.status.thisUIEventInfo.select.action == "unload") text = "卸下"; - var w = core.calWidth(ctx, text, font) + 2 * r + lineWidth / 2; - - core.strokeRoundRect(ctx, x, y, w, h, r, style, lineWidth); - core.fillText(ctx, text, x + r, y + lineWidth / 2 + 2, style, font); - - var todo = function () { - core.useSelectItemInBox(); - }; - addUIEventListener(x, y, w, h, todo); - } - - function getSelectedItem() { - var info = core.status.thisUIEventInfo; - if ( - !( - info && - info.select.id && - ["toolbox", "equipbox"].includes(core.status.event.id) - ) - ) { - core.drawFailTip("发生了未知错误!"); - return; - } - return info.select.id; - } - - function batchUse(item, count) { - try { - const itemCount = core.itemCount(item); - if (count > itemCount) count = itemCount; - core.closePanel(); - for (let i = 0; i < count; i++) { - if (core.canUseItem(item)) core.useItem(item); - else return; - } - } catch (e) { - console.error(e); - core.drawFailTip("批量使用时出现未知错误!"); - } - } - - function drawToolbox_setBatchUseBtn(ctx, x, y, r, h, style, lineWidth) { - try { - const selectedItem = getSelectedItem(); - let canBatchUse = eval(core.material.items[selectedItem]?.canBatchUse); - if (!canBatchUse) return; - } catch (error) { - console.error(error); - return; - } - core.setTextAlign(ctx, "left"); - core.setTextBaseline(ctx, "top"); - var fontSize = h - 4; - var font = core.ui._buildFont(fontSize); - var text = "批量使用"; - var w = core.calWidth(ctx, text, font) + 2 * r + lineWidth / 2; - - core.strokeRoundRect(ctx, x, y, w, h, r, style, lineWidth); - core.fillText(ctx, text, x + r, y + lineWidth / 2 + 2, style, font); - - var todo = function () { - core.utils.myprompt("输入要使用该物品的次数(0~99)。", null, (value) => { - value = parseInt(value); - const id = getSelectedItem(); - - if (Number.isNaN(value) || value < 0 || value > 99) { - core.drawFailTip("输入不合法!"); - return; - } - if (!core.canUseItem(id)) { - core.drawFailTip("当前无法使用该道具!"); - return; - } - core.closePanel(); - batchUse(id, value); - }); - }; - addUIEventListener(x, y, w, h, todo); - } - - function drawToolbox_setHideBtn(ctx, x, y, r, h, style, lineWidth) { - core.setTextAlign(ctx, "left"); - core.setTextBaseline(ctx, "top"); - var fontSize = h - 4; - var font = core.ui._buildFont(fontSize); - var text = "显示/隐藏"; - var w = core.calWidth(ctx, text, font) + 2 * r + lineWidth / 2; - - core.strokeRoundRect(ctx, x, y, w, h, r, style, lineWidth); - core.fillText(ctx, text, x + r, y + lineWidth / 2 + 2, style, font); - - var todo = function () { - //debugger; - var id = getSelectedItem(); - let hideInfo = core.getFlag("hideInfo", {}); - console.log(id); - if (hideInfo.hasOwnProperty(id)) { - hideInfo[id] = !hideInfo[id]; - core.setFlag("hideInfo", hideInfo); - } else { - hideInfo[id] = !core.material.items[id].hideInToolbox; - core.setFlag("hideInfo", hideInfo); - } - if (core.status.event.id === "toolbox") core.plugin.drawToolbox(); - else if (core.status.event.id === "equipbox") - core.plugin.drawEquipbox(); - }; - addUIEventListener(x, y, w, h, todo); - } - - ui.prototype.getToolboxItems = function (cls, showHide) { - let list = Object.keys(core.status.hero.items[cls] || {}); - if (cls === "all") { - for (let name in core.status.hero.items) { - if (name == "equips") continue; - list = list.concat(Object.keys(core.status.hero.items[name])); - } - if (!showHide) - list = list.filter(function (id2) { - const hideInfo = core.getFlag("hideInfo", {}); - if (hideInfo.hasOwnProperty(id2)) return !hideInfo[id2]; - else return !core.material.items[id2].hideInToolbox; - }); - list = list.sort(); - return list; - } - if (cls === "equips") { - if (!showHide) - list = list.filter(function (id2) { - const hideInfo = core.getFlag("hideInfo", {}); - if (hideInfo.hasOwnProperty(id2)) return !hideInfo[id2]; - else return !core.material.items[id2].hideInToolbox; - }); - - list = list.sort(); - return list; - } - if (this.uidata.getToolboxItems) { - return this.uidata.getToolboxItems(cls, showHide); - } - if (!showHide) - list = list.filter(function (id2) { - return !core.material.items[id2].hideInToolbox; - }); - list = list.sort(); - return list; - }; - - function drawToolbox_setShowHideBtn(ctx, x, y, h, style) { - core.setTextAlign(ctx, "left"); - core.setTextBaseline(ctx, "top"); - var fontSize = h - 6; - var font = core.ui._buildFont(fontSize); - var text = "显示隐藏"; - var w = core.calWidth(ctx, text, font); - h += 4; - const squareSize = h - 6; - - x -= w + squareSize + 26; - - const border = 2; - core.fillRect(ctx, x, y, squareSize, squareSize, " #F5F5F5"); - if (core.hasFlag("showHideItem")) { - core.fillRect( - ctx, - x + border, - y + border, - squareSize - 2 * border, - squareSize - 2 * border, - "lime" - ); - } - core.fillText(ctx, text, x + squareSize + 2, y + 4, style, font); - - var todo = function () { - core.setFlag("showHideItem", !core.getFlag("showHideItem", false)); - if (core.status.event.id === "toolbox") core.plugin.drawToolbox(); - else if (core.status.event.id === "equipbox") - core.plugin.drawEquipbox(); - }; - addUIEventListener(x, y, w, h, todo); - } - - function drawItemListbox_setPageBtn( - ctx, - left, - right, - bottom, - r, - style, - lineWidth - ) { - var offset = lineWidth / 2 + r; - - var x = left + offset; - var y = bottom - offset; - var pos = (Math.sqrt(2) / 2) * (r - lineWidth / 2); - core.fillPolygon( - ctx, - [ - [x - pos, y], - [x + pos - 2, y - pos], - [x + pos - 2, y + pos], - ], - style - ); - core.strokeCircle(ctx, x, y, r, style, lineWidth); - var todo = function () { - core.addItemListboxPage(-1); - }; - addUIEventListener(x - r - 2, y - r - 2, r * 2 + 4, r * 2 + 4, todo); - - x = right - offset; - core.fillPolygon( - ctx, - [ - [x + pos, y], - [x - pos + 2, y - pos], - [x - pos + 2, y + pos], - ], - style - ); - core.strokeCircle(ctx, x, y, r, style, lineWidth); - var todo = function () { - core.addItemListboxPage(1); - }; - addUIEventListener(x - r - 2, y - r - 2, r * 2 + 4, r * 2 + 4, todo); - } - - this.clickItemFunc = function (id) { - var info = core.status.thisUIEventInfo; - if (!info) return; - if (info.select.id == id) return core.useSelectItemInBox(); - info.select = {}; - info.select.id = id; - core.setIndexAndSelect("index"); - refreshBox(); - }; - - this.clickOneEquipbox = function (id, type) { - var info = core.status.thisUIEventInfo; - if (!info) return; - if (info.select.id == id && info.select.type == type) - core.useSelectItemInBox(); - else - core.status.thisUIEventInfo.select = { - id: id, - type: type, - action: "unload", - }; - return refreshBox(); - }; - - this.useSelectItemInBox = function () { - var info = core.status.thisUIEventInfo; - if (!info) return; - if (!info.select.id) return; - var id = info.select.id; - if (core.status.event.id == "toolbox") { - core.events.tryUseItem(id); - // core.closePanel(); - } else if (core.status.event.id == "equipbox") { - var action = info.select.action || "load"; - info.index = 1; - if (action == "load") { - var type = core.getEquipTypeById(id); - let equipClsid = core.material.items[id]?.equipCls; - let equipCls0 = core.material.items[core.getEquip(0)]?.equipCls; - let equipCls1 = core.material.items[core.getEquip(1)]?.equipCls; - if (equipClsid === "双手剑") { - core.unloadEquip(0, function () { - core.status.route.push("unEquip:" + 0); - }); - core.unloadEquip(1, function () { - core.status.route.push("unEquip:" + 1); - }); - } - if ( - equipCls0 === "双手剑" && - !(equipClsid === "饰品" || equipClsid === "护具") - ) { - core.unloadEquip(0, function () { - core.status.route.push("unEquip:" + 0); - }); - } - core.loadEquip(id, function () { - core.status.route.push("equip:" + id); - info.select.type = type; - core.setIndexAndSelect("select"); - core.drawEquipbox(); - }); - } else { - var type = info.select.type; - core.unloadEquip(type, function () { - core.status.route.push("unEquip:" + type); - info.select.type = type; - info.select.action = "load"; - core.setIndexAndSelect("select"); - core.drawEquipbox(); - }); - } - } - core.updateStatusBar(); - }; - - this.setIndexAndSelect = function (toChange) { - var info = core.status.thisUIEventInfo; - if (!info) return; - setPageItems(info.page); - var index = info.index || 1; - var items = info.pageItems; - - info.select.action = null; - info.select.type = null; - if (toChange == "index") info.index = items.indexOf(info.select.id) + 1; - info.select.id = items[info.index - 1]; - }; - - this.addItemListboxPage = function (num) { - var info = core.status.thisUIEventInfo; - if (!info) return; - var maxPage = info.maxPage || 1; - info.page = info.page || 1; - info.page += num; - if (info.page <= 0) info.page = maxPage; - if (info.page > maxPage) info.page = 1; - info.index = 1; - setPageItems(info.page); - core.setIndexAndSelect("select"); - refreshBox(); - }; - - this.addItemListboxIndex = function (num) { - var info = core.status.thisUIEventInfo; - if (!info) return; - var maxItem = info.maxItem || 0; - info.index = info.index || 0; - info.index += num; - if (info.index <= 0) info.index = 1; - if (info.index > maxItem) info.index = maxItem; - core.setIndexAndSelect("select"); - refreshBox(); - }; - - this.addEquipboxType = function (num) { - var info = core.status.thisUIEventInfo; - var type = info.select.type; - if (type == null && num > 0) info.select.type = 0; - else info.select.type = type + num; - var max = core.status.globalAttribute.equipName.length; - if (info.select.type >= max) { - info.select = {}; - core.setIndexAndSelect("select"); - return core.addItemListboxPage(0); - } else { - var m = Math.abs(info.select.type); - if (info.select.type < 0) info.select.type = max - m; - core.setIndexAndSelect("select"); - refreshBox(); - return; - } - }; - - core.actions._keyDownToolbox = function (keycode) { - if (!core.status.thisEventClickArea) return; - if (keycode == 37) { - // left - core.addItemListboxPage(-1); - return; - } - if (keycode == 38) { - // up - core.addItemListboxIndex(-1); - return; - } - if (keycode == 39) { - // right - core.addItemListboxPage(1); - return; - } - if (keycode == 40) { - // down - core.addItemListboxIndex(1); - return; - } - }; - - ////// 工具栏界面时,放开某个键的操作 ////// - core.actions._keyUpToolbox = function (keycode) { - if (keycode == 81) { - core.ui.closePanel(); - if (core.isReplaying()) core.control._replay_equipbox(); - else core.openEquipbox(); - return; - } - if (keycode == 84 || keycode == 27 || keycode == 88) { - core.closePanel(); - return; - } - if (keycode == 13 || keycode == 32 || keycode == 67) { - var info = core.status.thisUIEventInfo; - if (info.select) { - core.useSelectItemInBox(); - } - return; - } - }; - - core.actions._keyDownEquipbox = function (keycode) { - if (!core.status.thisEventClickArea) return; - if (keycode == 37) { - // left - var info = core.status.thisUIEventInfo; - if (info.index != null) return core.addItemListboxPage(-1); - return core.addEquipboxType(-1); - } - if (keycode == 38) { - // up - var info = core.status.thisUIEventInfo; - if (info.index == 1) { - info.select.type = core.status.globalAttribute.equipName.length - 1; - core.setIndexAndSelect(); - return refreshBox(); - } - if (info.index) return core.addItemListboxIndex(-1); - return core.addEquipboxType(-1 * info.equips); - } - if (keycode == 39) { - // right - var info = core.status.thisUIEventInfo; - if (info.index != null) return core.addItemListboxPage(1); - return core.addEquipboxType(1); - } - if (keycode == 40) { - // down - var info = core.status.thisUIEventInfo; - if (info.index) return core.addItemListboxIndex(1); - return core.addEquipboxType(info.equips); - } - }; - - core.actions._keyUpEquipbox = function (keycode, altKey) { - if (altKey && keycode >= 48 && keycode <= 57) { - core.items.quickSaveEquip(keycode - 48); - return; - } - if (keycode == 84) { - core.ui.closePanel(); - if (core.isReplaying()) core.control._replay_toolbox(); - else core.openToolbox(); - return; - } - if (keycode == 81 || keycode == 27 || keycode == 88) { - core.closePanel(); - return; - } - if (keycode == 13 || keycode == 32 || keycode == 67) { - var info = core.status.thisUIEventInfo; - if (info.select) core.useSelectItemInBox(); - return; - } - }; - - core.registerAction( - "ondown", - "inEventClickAction", - function (x, y, px, py) { - if (!core.status.thisEventClickArea) return false; - var info = core.status.thisEventClickArea; - for (var i = 0; i < info.length; i++) { - var obj = info[i]; - if ( - px >= obj.x && - px <= obj.x + obj.width && - py > obj.y && - py < obj.y + obj.height - ) { - if (obj.todo) obj.todo(); - break; - } - } - return true; - }, - 51 - ); - core.registerAction( - "onclick", - "stopClick", - function () { - if (core.status.thisEventClickArea) return true; - }, - 51 - ); - - function addUIEventListener(x, y, width, height, todo) { - if (!core.status.thisEventClickArea) return; - var obj = { - x: x, - y: y, - width: width, - height: height, - todo: todo, - }; - core.status.thisEventClickArea.push(obj); - } - - this.initThisEventInfo = function () { - core.status.thisUIEventInfo = { - page: 1, - select: {}, - }; - core.status.thisEventClickArea = []; - }; - - function refreshBox() { - if (!core.status.event.id) return; - if (core.status.event.id == "toolbox") core.drawToolbox(); - else core.drawEquipbox(); - } - - core.ui.closePanel = function () { - if (core.status.hero && core.status.hero.flags) { - // 清除全部临时变量 - Object.keys(core.status.hero.flags).forEach(function (name) { - if (name.startsWith("@temp@") || /^arg\d+$/.test(name)) { - delete core.status.hero.flags[name]; - } - }); - } - this.clearUI(); - core.maps.generateGroundPattern(); - core.updateStatusBar(true); - core.unlockControl(); - core.status.event.data = null; - core.status.event.id = null; - core.status.event.selection = null; - core.status.event.ui = null; - core.status.event.interval = null; - core.status.thisUIEventInfo = null; - core.status.thisEventClickArea = null; - }; - - this.getItemClsName = function (item) { - if (item == null) return itemClsName; - if (item.cls == "equips") { - if (typeof item.equip.type == "string") return item.equip.type; - var type = core.getEquipTypeById(item.id); - return core.status.globalAttribute.equipName[type]; - } else return itemClsName[item.cls] || item.cls; - }; - - core.events.openToolbox = function (fromUserAction) { - if (core.isReplaying()) return; - if (!this._checkStatus("toolbox", fromUserAction)) return; - core.initThisEventInfo(); - let info = core.status.thisUIEventInfo; - info.index = 1; - core.setIndexAndSelect("select"); - core.drawToolbox(); - }; - - core.events.openEquipbox = function (fromUserAction) { - if (core.isReplaying()) return; - if (!this._checkStatus("equipbox", fromUserAction)) return; - core.initThisEventInfo(); - let info = core.status.thisUIEventInfo; - info.select.type = 0; - core.setIndexAndSelect("select"); - core.drawEquipbox(); - }; - - core.control._replay_toolbox = function () { - if (!core.isPlaying() || !core.isReplaying()) return; - if (!core.status.replay.pausing) return core.drawTip("请先暂停录像"); - if (core.isMoving() || core.status.replay.animate || core.status.event.id) - return core.drawTip("请等待当前事件的处理结束"); - - core.lockControl(); - core.status.event.id = "toolbox"; - core.drawToolbox(); - }; - - core.control._replay_equipbox = function () { - if (!core.isPlaying() || !core.isReplaying()) return; - if (!core.status.replay.pausing) return core.drawTip("请先暂停录像"); - if (core.isMoving() || core.status.replay.animate || core.status.event.id) - return core.drawTip("请等待当前事件的处理结束"); - - core.lockControl(); - core.status.event.id = "equipbox"; - core.drawEquipbox(); - }; - - core.control._replayAction_item = function (action) { - if (action.indexOf("item:") != 0) return false; - var itemId = action.substring(5); - if (!core.canUseItem(itemId)) return false; - if ( - core.material.items[itemId].hideInReplay || - core.status.replay.speed == 24 - ) { - core.useItem(itemId, false, core.replay); - return true; - } - core.status.event.id = "toolbox"; - core.initThisEventInfo(); - var info = core.status.thisUIEventInfo; - var items = core.getToolboxItems( - "all", - core.getFlag("showHideItem", false) - ); - setPageItems(1); - var index = items.indexOf(itemId) + 1; - info.page = Math.ceil(index / info.maxItem); - info.index = index % info.maxItem || info.maxItem; - core.setIndexAndSelect("select"); - setPageItems(info.page); - core.drawToolbox(); - setTimeout(function () { - core.ui.closePanel(); - core.useItem(itemId, false, core.replay); - }, core.control.__replay_getTimeout()); - return true; - }; - - core.control._replayAction_equip = function (action) { - if (action.indexOf("equip:") != 0) return false; - var itemId = action.substring(6); - var items = core.getToolboxItems( - "equips", - core.getFlag("showHideItem", false) - ); - var index = items.indexOf(itemId) + 1; - if (index < 1) { - core.removeFlag("__doNotCheckAutoEvents__"); - return false; - } - - var cb = function () { - var next = core.status.replay.toReplay[0] || ""; - if (!next.startsWith("equip:") && !next.startsWith("unEquip:")) { - core.removeFlag("__doNotCheckAutoEvents__"); - core.checkAutoEvents(); - } - core.replay(); - }; - core.setFlag("__doNotCheckAutoEvents__", true); - - core.status.route.push(action); - if ( - core.material.items[itemId].hideInReplay || - core.status.replay.speed == 24 - ) { - core.loadEquip(itemId, cb); - return true; - } - core.status.event.id = "equipbox"; - core.initThisEventInfo(); - var info = core.status.thisUIEventInfo; - setPageItems(1); - info.page = Math.ceil(index / info.maxItem); - info.index = index % info.maxItem || info.maxItem; - core.setIndexAndSelect("select"); - setPageItems(info.page); - core.drawEquipbox(); - setTimeout(function () { - core.ui.closePanel(); - core.loadEquip(itemId, cb); - }, core.control.__replay_getTimeout()); - return true; - }; - - core.control._replayAction_unEquip = function (action) { - if (action.indexOf("unEquip:") != 0) return false; - var equipType = parseInt(action.substring(8)); - if (!core.isset(equipType)) { - core.removeFlag("__doNotCheckAutoEvents__"); - return false; - } - - var cb = function () { - var next = core.status.replay.toReplay[0] || ""; - if (!next.startsWith("equip:") && !next.startsWith("unEquip:")) { - core.removeFlag("__doNotCheckAutoEvents__"); - core.checkAutoEvents(); - } - core.replay(); - }; - core.setFlag("__doNotCheckAutoEvents__", true); - - core.status.route.push(action); - if (core.status.replay.speed == 24) { - core.unloadEquip(equipType, cb); - return true; - } - core.status.event.id = "equipbox"; - core.initThisEventInfo(); - var info = core.status.thisUIEventInfo; - setPageItems(1); - info.select.type = equipType; - core.setIndexAndSelect(); - core.drawEquipbox(); - setTimeout(function () { - core.ui.closePanel(); - core.unloadEquip(equipType, cb); - }, core.control.__replay_getTimeout()); - return true; - }; - core.registerReplayAction("item", core.control._replayAction_item); - core.registerReplayAction("equip", core.control._replayAction_equip); - core.registerReplayAction("unEquip", core.control._replayAction_unEquip); - }, + core.setAlpha(ctx, backgroundAlpha); + core.strokeRoundRect( + ctx, + x, + y, + w, + h, + borderRadius, + borderStyle, + borderWidth + ); + core.fillRoundRect( + ctx, + start_x, + start_y, + width, + height, + borderRadius, + backgroundColor + ); + core.setAlpha(ctx, 1); + + ///// *** 左栏配置 + var leftbar_height = height; + // 左边栏宽度(width*0.6) 本身仅为坐标使用 需要与底下的rightbar_width(width*0.4)同时更改 + var leftbar_width = width * 0.6; + ///// *** + + // xxx_right参数 代表最右侧坐标 + var leftbar_right = start_x + leftbar_width - borderWidth / 2; + var leftbar_bottom = start_y + leftbar_height; + var leftbar_x = start_x; + var leftbar_y = start_y; + + ///// *** 道具栏配置 + var boxName_color = "#fff"; + var boxName_fontSize = 15; + var boxName_font = core.ui._buildFont(boxName_fontSize, true); + var arrow_x = 10 + start_x; + var arrow_y = 10 + start_y; + var arrow_width = 20; + var arrow_style = "white"; + // 暂时只能是1 否则不太行 等待新样板(2.7.3)之后对drawArrow做优化 + var arrow_lineWidth = 2; + // 右箭头 + var rightArrow_right = leftbar_right - 10; + // 道具内栏顶部坐标 本质是通过该项 控制(道具栏顶部文字和箭头)与道具内栏顶部的间隔 + var itembar_top = arrow_y + 15; + ///// *** + + var itembar_right = rightArrow_right; + var boxName = + core.status.event.id == "toolbox" ? + "\r[yellow]道具栏\r | 装备栏" : + "道具栏 | \r[yellow]装备栏\r"; + core.drawArrow( + ctx, + arrow_x + arrow_width, + arrow_y, + arrow_x, + arrow_y, + arrow_style, + arrow_lineWidth + ); + core.drawArrow( + ctx, + rightArrow_right - arrow_width, + arrow_y, + rightArrow_right, + arrow_y, + arrow_style, + arrow_lineWidth + ); + core.setTextAlign(ctx, "center"); + core.setTextBaseline(ctx, "middle"); + var changeBox = function () { + var id = core.status.event.id; + core.closePanel(); + if (id == "toolbox") core.openEquipbox(); + else core.openToolbox(); + }; + core.fillText( + ctx, + boxName, + (leftbar_right + leftbar_x) / 2, + arrow_y + 2, + boxName_color, + boxName_font + ); + + ///// *** 底栏按钮 + var pageBtn_radius = 8; + // xxx_left 最左侧坐标 + var pageBtn_left = leftbar_x + 3; + var pageBtn_right = leftbar_right - 3; + // xxx_bottom 最底部坐标 + var pageBtn_bottom = leftbar_bottom - 2; + var pageBtn_borderStyle = "#fff"; + var pageBtn_borderWidth = 2; + var pageText_color = "#fff"; + // 底部按钮与上面的道具内栏的间隔大小 + var bottomSpace = 8; + ///// *** + + drawItemListbox_setPageBtn( + ctx, + pageBtn_left, + pageBtn_right, + pageBtn_bottom, + pageBtn_radius, + pageBtn_borderStyle, + pageBtn_borderWidth + ); + var page = info.page || 1; + var pageFontSize = pageBtn_radius * 2 - 4; + var pageFont = core.ui._buildFont(pageFontSize); + setPageItems(page); + var num = itemNum; + if (core.status.event.id == "equipbox") num -= 5; + var maxPage = info.maxPage; + var pageText = page + " / " + maxPage; + core.setTextAlign(ctx, "center"); + core.setTextBaseline(ctx, "bottom"); + core.fillText( + ctx, + pageText, + (leftbar_x + leftbar_right) / 2, + pageBtn_bottom, + pageText_color, + pageFont + ); + addUIEventListener( + start_x, + start_y, + leftbar_right - start_x, + arrow_y - start_y + 13, + changeBox + ); + var itembar_height = Math.ceil( + pageBtn_bottom - + pageBtn_radius * 2 - + pageBtn_borderWidth / 2 - + bottomSpace - + itembar_top + ); + var oneItemHeight = (itembar_height - 4) / itemNum; + return { + x: start_x, + y: start_y, + width: width, + height: height, + leftbar_right: leftbar_right, + obj: { + x: arrow_x, + y: itembar_top, + width: itembar_right - arrow_x, + height: itembar_height, + oneItemHeight: oneItemHeight, + }, + }; + } + + function drawItemListbox(ctx, obj) { + ctx = ctx || core.canvas.ui; + var itembar_x = obj.x, + itembar_y = obj.y, + itembar_width = obj.width, + itembar_height = obj.height, + itemNum = obj.itemNum, + oneItemHeight = obj.oneItemHeight; + var itembar_right = itembar_x + itembar_width; + var info = core.status.thisUIEventInfo || {}; + var obj = {}; + var page = info.page || 1, + index = info.index, + select = info.select || {}; + + ///// *** 道具栏内栏配置 + var itembar_style = "black"; + var itembar_alpha = 0.7; + // 一个竖屏下减少道具显示的例子: + // if (core.domStyle.isVertical) itemNum = 10; + // 每个道具项的上下空隙占总高度的比例 + var itembar_marginHeightRatio = 0.2; + // 左右间隔空隙 + var item_marginLeft = 2; + var item_x = itembar_x + 2, + item_y = itembar_y + 2, + item_right = itembar_right - 2, + itemName_color = "#fff"; + // 修改此项以更换闪烁光标 + var item_selector = "winskin.webp"; + ///// *** + + core.setAlpha(ctx, itembar_alpha); + core.fillRect( + ctx, + itembar_x, + itembar_y, + itembar_width, + itembar_height, + itembar_style + ); + core.setAlpha(ctx, 1); + var pageItems = setPageItems(page); + var marginHeight = itembar_marginHeightRatio * oneItemHeight; + core.setTextBaseline(ctx, "middle"); + var originColor = itemName_color; + for (var i = 0; i < pageItems.length; i++) { + itemName_color = originColor; + var item = pageItems[i]; + // 设置某个的字体颜色的一个例子 + // if (item.id == "xxx") itemName_color = "green"; + drawItemListbox_drawItem( + ctx, + item_x, + item_right, + item_y, + oneItemHeight, + item_marginLeft, + marginHeight, + itemName_color, + pageItems[i] + ); + if (index == i + 1) + core.ui._drawWindowSelector( + item_selector, + item_x + 1, + item_y - 1, + item_right - item_x - 2, + oneItemHeight - 2 + ); + item_y += oneItemHeight; + } + } + + function drawToolboxRightbar(ctx, obj) { + ctx = ctx || core.canvas.ui; + var info = core.status.thisUIEventInfo || {}; + var page = info.page || 1, + index = info.index || 1, + select = info.select || {}; + var start_x = obj.x, + start_y = obj.y, + width = obj.width, + height = obj.height; + var toolboxRight = start_x + width, + toolboxBottom = start_y + height; + + ///// *** 侧边栏(rightbar)背景设置(物品介绍) + var rightbar_width = width * 0.4; + var rightbar_height = height; + var rightbar_lineWidth = 2; + var rightbar_lineStyle = "#fff"; + ///// *** + + var rightbar_x = toolboxRight - rightbar_width - rightbar_lineWidth / 2; + var rightbar_y = start_y; + core.drawLine( + ctx, + rightbar_x, + rightbar_y, + rightbar_x, + rightbar_y + rightbar_height, + rightbar_lineStyle, + rightbar_lineWidth + ); + + // 获取道具id(有可能为null) + var itemId = select.id; + var item = core.material.items[itemId]; + + ///// *** 侧边栏物品Icon信息 + var iconRect_y = rightbar_y + 10; + // space:间距 + // 这里布局设定iconRect与侧边栏左边框 itemName与工具栏右边框 itemRect与itemName的间距均为space + var space = 15; + var iconRect_x = rightbar_x + space; + var iconRect_radius = 2, + iconRect_width = 32, + iconRect_height = 32, + iconRect_style = "#fff", + iconRect_lineWidth = 2; + ///// *** + + var iconRect_bottom = iconRect_y + iconRect_height, + iconRect_right = iconRect_x + iconRect_width; + + ///// *** 侧边栏各项信息 + var itemTextFontSize = 15, + itemText_x = iconRect_x - 4, + itemText_y = Math.floor(start_y + rightbar_height * 0.25), // 坐标取整防止模糊 + itemClsFontSize = 15, + itemClsFont = core.ui._buildFont(itemClsFontSize), + itemClsColor = "#fff", + itemCls_x = itemText_x - itemClsFontSize / 2, + itemCls_middle = (iconRect_bottom + itemText_y) / 2, //_middle代表文字的中心y坐标 + itemNameFontSize = 18, + itemNameColor = "#fff", + itemNameFont = core.ui._buildFont(itemNameFontSize, true); + var itemName_x = iconRect_right + space; + var itemName_middle = + iconRect_y + iconRect_height / 2 + iconRect_lineWidth; + // 修改这里可以编辑未选中道具时的默认值 + var defaultItem = { + cls: "constants", + name: "未知道具", + text: "没有道具最永久", + }; + var defaultEquip = { + cls: "equips", + name: "未知装备", + text: "一无所有,又何尝不是一种装备", + equip: { + type: "装备", + }, + }; + ///// *** + + var originItem = item; + if (core.status.event.id == "equipbox") item = item || defaultEquip; + item = item || defaultItem; + var itemCls = item.cls, + itemName = item.name, + itemText = item.text; + itemText = core.replaceText(itemText); + if (!itemText) itemText = "该道具无描述。"; + /* 一个根据道具id修改道具名字(右栏)的例子 + * if (item.id == "xxx") itemNameColor = "red"; + */ + var itemClsName = core.getItemClsName(item); + var itemNameMaxWidth = + rightbar_width - iconRect_width - iconRect_lineWidth * 2 - space * 2; + core.strokeRoundRect( + ctx, + iconRect_x, + iconRect_y, + iconRect_width, + iconRect_height, + iconRect_radius, + iconRect_style, + iconRect_lineWidth + ); + if (item.id) + core.drawIcon( + ctx, + item.id, + iconRect_x + iconRect_lineWidth / 2, + iconRect_y + iconRect_lineWidth / 2, + iconRect_width - iconRect_lineWidth, + iconRect_height - iconRect_lineWidth + ); + core.setTextAlign(ctx, "left"); + core.setTextBaseline(ctx, "middle"); + if (itemCls === "equips" && item.id) { + itemName = "【" + item.equipCls + "】" + itemName; + } + core.fillText( + ctx, + itemName, + itemName_x, + itemName_middle, + itemNameColor, + itemNameFont, + itemNameMaxWidth + ); + if (!item.equip) + core.fillText( + ctx, + "【" + itemClsName + "】", + itemCls_x, + itemCls_middle, + itemClsColor, + itemClsFont + ); + + var statusText = ""; + if (core.status.event.id == "equipbox") { + var type = item.equip.type; + if (typeof type == "string") type = core.getEquipTypeByName(type); + var compare = core.compareEquipment(item.id, core.getEquip(type)); + var compare2; + if (item.equipCls === "双手剑") + compare2 = core.compareEquipment(null, core.getEquip(1)); + if ( + item.equipCls === "盾牌" && + core.material.items[core.getEquip(0)]?.equipCls === "双手剑" + ) + compare2 = core.compareEquipment(null, core.getEquip(0)); + if (info.select.action == "unload") + compare = core.compareEquipment(null, item.id); + // --- 变化值... + for (var name in core.status.hero) { + if (typeof core.status.hero[name] != "number") continue; + var nowValue = core.getRealStatus(name); + // 查询新值 + var newValue = Math.floor( + ((core.getStatus(name) + + (compare.value[name] || 0) + + (compare2?.value[name] || 0)) * + (core.getBuff(name) * 100 + + (compare.percentage[name] || 0) + + (compare2?.percentage[name] || 0))) / + 100 + ); + if (name === "mdef") { + var nowValue = core.getRealStatus(name); + var newValue = Math.round( + (core.getStatus(name) - + (compare.value[name] || 0) - + (compare2?.value[name] || 0)) * + (1 - + (1 - core.getBuff(name)) * + (compare.percentage[name] || 1) * + (compare2?.percentage[name] || 1)) + ); + } + if (nowValue == newValue) continue; + var color = newValue > nowValue ? "#00FF00" : "#FF0000"; + nowValue = core.formatBigNumber(nowValue); + newValue = core.formatBigNumber(newValue); + + if (name === "mdef") { + nowValue += "%"; + newValue += "%"; + } + statusText += + core.getStatusLabel(name) + + " " + + nowValue + + "->\r[" + + color + + "]" + + newValue + + "\r\n"; + } + } + itemText = statusText + itemText; + if (item.equip) { + core.drawTextContent(ctx, itemText, { + left: itemText_x, + top: itemCls_middle, + bold: false, + color: "white", + align: "left", + fontSize: itemTextFontSize, + maxWidth: rightbar_width - + (itemText_x - rightbar_x) * 2 + + itemTextFontSize / 2, + }); + } else { + core.drawTextContent(ctx, itemText, { + left: itemText_x, + top: itemText_y, + bold: false, + color: "white", + align: "left", + fontSize: itemTextFontSize, + maxWidth: rightbar_width - + (itemText_x - rightbar_x) * 2 + + itemTextFontSize / 2, + }); + } + + ///// *** 退出按钮设置 + var btnRadius = 10; + var btnBorderWidth = 2; + var btnRight = toolboxRight - 2; + var btnBottom = toolboxBottom - 2; + var btnBorderStyle = "#fff"; + ///// *** + + // 获取圆心位置 + var btn_x = btnRight - btnRadius - btnBorderWidth / 2; + btn_y = btnBottom - btnRadius - btnBorderWidth / 2; + drawToolbox_setExitBtn( + ctx, + btn_x, + btn_y, + btnRadius, + btnBorderStyle, + btnBorderWidth + ); + + ///// *** 使用按钮设置 + var useBtnHeight = btnRadius * 2; + // 这里不设置useBtnWidth而是根据各项数据自动得出width + var useBtnRadius = useBtnHeight / 4; + var useBtn_x = rightbar_x + 4, + useBtn_y = btnBottom - useBtnHeight; + var useBtnBorderStyle = "#fff"; + var useBtnBorderWidth = btnBorderWidth; + const batchUseBtn_x = useBtn_x + 50; // 个人觉得,搞这么多参数还不如硬编码 + const hideBtn_y = useBtn_y - useBtnHeight - 8; + ///// *** + + drawToolbox_setUseBtn( + ctx, + useBtn_x, + useBtn_y, + useBtnRadius, + useBtnHeight, + useBtnBorderStyle, + useBtnBorderWidth + ); + if (core.status.event.id === "toolbox") { + drawToolbox_setBatchUseBtn( + ctx, + batchUseBtn_x, + useBtn_y, + useBtnRadius, + useBtnHeight, + useBtnBorderStyle, + useBtnBorderWidth + ); + } + drawToolbox_setHideBtn( + ctx, + useBtn_x, + hideBtn_y, + useBtnRadius, + useBtnHeight, + useBtnBorderStyle, + useBtnBorderWidth + ); + drawToolbox_setShowHideBtn( + ctx, + rightbar_x, + useBtn_y, + useBtnHeight, + useBtnBorderStyle + ); + } + + function drawEquipbox_drawOthers(ctx, obj) { + var info = core.status.thisUIEventInfo; + + ///// *** 装备格设置 + var equipList_lineWidth = 2; + var equipList_boxSize = 32; + var equipList_borderWidth = 2; + var equipList_borderStyle = "#fff"; + var equipList_nameColor = "#fff"; + ///// *** + + var equipList_x = obj.x + 4, + equipList_bottom = obj.obj.y - equipList_lineWidth, + equipList_y = equipList_bottom - obj.obj.oneItemHeight * reduceItem - 2, + equipList_height = equipList_bottom - equipList_y; + var equipList_right = obj.leftbar_right, + equipList_width = equipList_right - equipList_x; + core.drawLine( + ctx, + obj.x, + equipList_bottom + equipList_lineWidth / 2, + equipList_right, + equipList_bottom + equipList_lineWidth / 2, + equipList_borderStyle, + equipList_lineWidth + ); + var toDrawList = core.status.globalAttribute.equipName, + len = toDrawList.length; + + ///// *** 装备格设置 + var maxItem = 2; + var box_width = 32, + box_height = 32, + box_borderStyle = "#fff", + box_selectBorderStyle = "gold", // 选中的装备格的颜色 + box_borderWidth = 2; + var boxName_fontSize = 14, + boxName_space = 2, + boxName_color = "#fff"; // 装备格名称与上面的装备格框的距离 + var maxLine = Math.ceil(len / maxItem); + ///// *** + var l = Math.sqrt(len); + if (Math.pow(l) == len && len != 4) { + if (l <= maxItem) maxItem = l; + } + maxItem = Math.min(toDrawList.length, maxItem); + info.equips = maxItem; + + var boxName_font = core.ui._buildFont(boxName_fontSize); + // 总宽高减去所有装备格宽高得到空隙大小 + var oneBoxWidth = box_width + box_borderWidth * 2; + var oneBoxHeight = + box_height + boxName_fontSize + boxName_space + 2 * box_borderWidth; + var space_y = (equipList_height - maxLine * oneBoxHeight) / (1 + maxLine), + space_x = (equipList_width - maxItem * oneBoxWidth) / (1 + maxItem); + var box_x = equipList_x + space_x, + box_y = equipList_y + space_y + 12; + for (var i = 0; i < 2; i++) { + var id = core.getEquip(i), + name = toDrawList[i]; + if (i === 0) name = "主手"; + if (i === 1) name = "副手"; + var selectBorder = false; + if (core.status.thisUIEventInfo.select.type == i) selectBorder = true; + var borderStyle = selectBorder ? + box_selectBorderStyle : + box_borderStyle; + drawEquipbox_drawOne( + ctx, + name, + id, + box_x, + box_y, + box_width, + box_height, + boxName_space, + boxName_font, + boxName_color, + borderStyle, + box_borderWidth + ); + var todo = new Function( + "core.clickOneEquipbox('" + id + "'," + i + ")" + ); + addUIEventListener( + box_x - box_borderWidth / 2, + box_y - box_borderWidth / 2, + oneBoxWidth, + oneBoxHeight, + todo + ); + box_x += space_x + oneBoxWidth; + if ((i + 1) % maxItem == 0) { + box_x = equipList_x + space_x; + box_y += space_y + oneBoxHeight; + } + } + if (core.material.items[core.getEquip(0)]?.equipCls === "双手剑") { + core.drawLine( + ctx, + equipList_x + space_x + space_x + oneBoxWidth, + equipList_y + space_y + 12, + equipList_x + + space_x + + space_x + + oneBoxWidth + + box_width + + box_borderWidth, + equipList_y + space_y + box_height + 12 + ); + core.drawLine( + ctx, + equipList_x + space_x + space_x + oneBoxWidth, + equipList_y + space_y + box_height + 12, + equipList_x + + space_x + + space_x + + oneBoxWidth + + box_width + + box_borderWidth, + equipList_y + space_y + 12 + ); + } + ///// *** 装备格设置 + var maxItem = 3; + var box_width = 32, + box_height = 32, + box_borderStyle = "#fff", + box_selectBorderStyle = "gold", // 选中的装备格的颜色 + box_borderWidth = 2; + var boxName_fontSize = 14, + boxName_space = 2, + boxName_color = "#fff"; // 装备格名称与上面的装备格框的距离 + var maxLine = Math.ceil(len / maxItem); + ///// *** + var l = Math.sqrt(len); + if (Math.pow(l) == len && len != 4) { + if (l <= maxItem) maxItem = l; + } + maxItem = Math.min(toDrawList.length, maxItem); + info.equips = maxItem; + + var boxName_font = core.ui._buildFont(boxName_fontSize); + // 总宽高减去所有装备格宽高得到空隙大小 + var oneBoxWidth = box_width + box_borderWidth * 2; + var oneBoxHeight = + box_height + boxName_fontSize + boxName_space + 2 * box_borderWidth; + var space_y = (equipList_height - maxLine * oneBoxHeight) / (1 + maxLine), + space_x = (equipList_width - maxItem * oneBoxWidth) / (1 + maxItem); + var box_x = equipList_x + space_x, + box_y = equipList_y + space_y + space_y + oneBoxHeight; + for (var i = 2; i < len; i++) { + var id = core.getEquip(i), + name = toDrawList[i]; + var selectBorder = false; + if (core.status.thisUIEventInfo.select.type == i) selectBorder = true; + var borderStyle = selectBorder ? + box_selectBorderStyle : + box_borderStyle; + drawEquipbox_drawOne( + ctx, + name, + id, + box_x, + box_y, + box_width, + box_height, + boxName_space, + boxName_font, + boxName_color, + borderStyle, + box_borderWidth + ); + var todo = new Function( + "core.clickOneEquipbox('" + id + "'," + i + ")" + ); + addUIEventListener( + box_x - box_borderWidth / 2, + box_y - box_borderWidth / 2, + oneBoxWidth, + oneBoxHeight, + todo + ); + box_x += space_x + oneBoxWidth; + } + } + + this.drawToolbox = function (ctx) { + ctx = ctx || core.canvas.ui; + core.status.thisEventClickArea = []; + + var info = drawBoxBackground(ctx); + info.itemNum = itemNum; + drawItemListbox(ctx, info.obj); + drawToolboxRightbar(ctx, info); + core.setTextBaseline(ctx, "alphabetic"); + core.setTextAlign("left"); + }; + + var reduceItem = 4; + this.drawEquipbox = function (ctx) { + ctx = ctx || core.canvas.ui; + core.status.thisEventClickArea = []; + var info = drawBoxBackground(ctx); + info.itemNum = itemNum - reduceItem; + info.obj.y += info.obj.oneItemHeight * reduceItem; + info.obj.height -= info.obj.oneItemHeight * reduceItem; + drawItemListbox(ctx, info.obj); + drawEquipbox_drawOthers(ctx, info); + drawToolboxRightbar(ctx, info); + core.setTextBaseline(ctx, "alphabetic"); + core.setTextAlign("left"); + }; + + function drawEquipbox_drawOne( + ctx, + name, + id, + x, + y, + width, + height, + space, + font, + color, + style, + lineWidth + ) { + if (id) + core.drawIcon( + ctx, + id, + x + lineWidth / 2, + y + lineWidth / 2, + width, + height + ); + core.strokeRect( + ctx, + x, + y, + width + lineWidth, + height + lineWidth, + style, + lineWidth + ); + core.setTextAlign(ctx, "center"); + core.setTextBaseline(ctx, "top"); + var tx = (x + x + lineWidth / 2 + width) / 2, + ty = y + height + (lineWidth / 2) * 3 + space; + core.fillText(ctx, name, tx, ty, color, font); + + core.setAlpha(ctx, 1); + + core.setTextBaseline(ctx, "alphabetic"); + core.setTextAlign("left"); + } + + function drawItemListbox_drawItem( + ctx, + left, + right, + top, + height, + marginLeft, + marginHeight, + style, + id + ) { + var info = core.status.thisUIEventInfo; + var nowClick = info.index; + var item = core.material.items[id] || {}; + var name = item.name || "???"; + var num = core.itemCount(id) || 0; + var fontSize = Math.floor(height - marginHeight * 2); + core.setTextAlign(ctx, "right"); + var numText = "x" + num; + core.fillText( + ctx, + numText, + right - marginLeft, + top + height / 2, + style, + core.ui._buildFont(fontSize) + ); + + const hideInfo = core.getFlag("hideInfo", {}); + if ( + item && + (hideInfo.hasOwnProperty(id) ? hideInfo[id] : item.hideInToolbox) + ) + core.setAlpha(ctx, 0.5); + + if (name != "???") + core.drawIcon( + ctx, + id, + left + marginLeft, + top + marginHeight, + fontSize, + fontSize + ); + var text_x = left + marginLeft + fontSize + 2; + var maxWidth = right - core.calWidth(ctx, numText) - text_x; + core.setTextAlign(ctx, "left"); + core.fillText( + ctx, + name, + text_x, + top + height / 2, + style, + core.ui._buildFont(fontSize), + maxWidth + ); + core.setAlpha(ctx, 1); + + var todo = new Function("core.clickItemFunc('" + id + "');"); + addUIEventListener(left, top, right - left, height, todo); + } + + function setPageItems(page) { + var num = itemNum; + if (core.status.event.id == "equipbox") num -= reduceItem; + var info = core.status.thisUIEventInfo; + if (!info) return; + page = page || info.page; + var items = core.getToolboxItems( + core.status.event.id == "toolbox" ? "all" : "equips", + core.getFlag("showHideItem", false) + ); + info.allItems = items; + var maxPage = Math.ceil(items.length / num); + info.maxPage = maxPage; + var pageItems = items.slice((page - 1) * num, page * num); + info.pageItems = pageItems; + info.maxItem = pageItems.length; + if (items.length == 0 && pageItems.length == 0) info.index = null; + if (pageItems.length == 0 && info.page > 1) { + info.page = Math.max(1, info.page - 1); + return setPageItems(info.page); + } + return pageItems; + } + + function drawToolbox_setExitBtn(ctx, x, y, r, style, lineWidth) { + core.strokeCircle(ctx, x, y, r, style, lineWidth); + ctx.textAlign = "center"; + ctx.textBaseline = "middle"; + var textSize = Math.sqrt(2) * r; + core.fillText( + ctx, + "x", + x, + y, + style, + core.ui._buildFont(textSize), + textSize + ); + core.setTextAlign(ctx, "start"); + core.setTextBaseline(ctx, "top"); + + var todo = function () { + core.closePanel(); + }; + addUIEventListener(x - r, y - r, r * 2, r * 2, todo); + } + + function drawToolbox_setUseBtn(ctx, x, y, r, h, style, lineWidth) { + core.setTextAlign(ctx, "left"); + core.setTextBaseline(ctx, "top"); + var fontSize = h - 4; + var font = core.ui._buildFont(fontSize); + var text = core.status.event.id == "toolbox" ? "使用" : "装备"; + if (core.status.thisUIEventInfo.select.action == "unload") text = "卸下"; + var w = core.calWidth(ctx, text, font) + 2 * r + lineWidth / 2; + + core.strokeRoundRect(ctx, x, y, w, h, r, style, lineWidth); + core.fillText(ctx, text, x + r, y + lineWidth / 2 + 2, style, font); + + var todo = function () { + core.useSelectItemInBox(); + }; + addUIEventListener(x, y, w, h, todo); + } + + function getSelectedItem() { + var info = core.status.thisUIEventInfo; + if ( + !( + info && + info.select.id && ["toolbox", "equipbox"].includes(core.status.event.id) + ) + ) { + core.drawFailTip("发生了未知错误!"); + return; + } + return info.select.id; + } + + function batchUse(item, count) { + try { + const itemCount = core.itemCount(item); + if (count > itemCount) count = itemCount; + core.closePanel(); + for (let i = 0; i < count; i++) { + if (core.canUseItem(item)) core.useItem(item); + else return; + } + } catch (e) { + console.error(e); + core.drawFailTip("批量使用时出现未知错误!"); + } + } + + function drawToolbox_setBatchUseBtn(ctx, x, y, r, h, style, lineWidth) { + try { + const selectedItem = getSelectedItem(); + let canBatchUse = eval(core.material.items[selectedItem]?.canBatchUse); + if (!canBatchUse) return; + } catch (error) { + console.error(error); + return; + } + core.setTextAlign(ctx, "left"); + core.setTextBaseline(ctx, "top"); + var fontSize = h - 4; + var font = core.ui._buildFont(fontSize); + var text = "批量使用"; + var w = core.calWidth(ctx, text, font) + 2 * r + lineWidth / 2; + + core.strokeRoundRect(ctx, x, y, w, h, r, style, lineWidth); + core.fillText(ctx, text, x + r, y + lineWidth / 2 + 2, style, font); + + var todo = function () { + core.utils.myprompt("输入要使用该物品的次数(0~99)。", null, (value) => { + value = parseInt(value); + const id = getSelectedItem(); + + if (Number.isNaN(value) || value < 0 || value > 99) { + core.drawFailTip("输入不合法!"); + return; + } + if (!core.canUseItem(id)) { + core.drawFailTip("当前无法使用该道具!"); + return; + } + core.closePanel(); + batchUse(id, value); + }); + }; + addUIEventListener(x, y, w, h, todo); + } + + function drawToolbox_setHideBtn(ctx, x, y, r, h, style, lineWidth) { + core.setTextAlign(ctx, "left"); + core.setTextBaseline(ctx, "top"); + var fontSize = h - 4; + var font = core.ui._buildFont(fontSize); + var text = "显示/隐藏"; + var w = core.calWidth(ctx, text, font) + 2 * r + lineWidth / 2; + + core.strokeRoundRect(ctx, x, y, w, h, r, style, lineWidth); + core.fillText(ctx, text, x + r, y + lineWidth / 2 + 2, style, font); + + var todo = function () { + //debugger; + var id = getSelectedItem(); + let hideInfo = core.getFlag("hideInfo", {}); + console.log(id); + if (hideInfo.hasOwnProperty(id)) { + hideInfo[id] = !hideInfo[id]; + core.setFlag("hideInfo", hideInfo); + } else { + hideInfo[id] = !core.material.items[id].hideInToolbox; + core.setFlag("hideInfo", hideInfo); + } + if (core.status.event.id === "toolbox") core.plugin.drawToolbox(); + else if (core.status.event.id === "equipbox") + core.plugin.drawEquipbox(); + }; + addUIEventListener(x, y, w, h, todo); + } + + ui.prototype.getToolboxItems = function (cls, showHide) { + let list = Object.keys(core.status.hero.items[cls] || {}); + if (cls === "all") { + for (let name in core.status.hero.items) { + if (name == "equips") continue; + list = list.concat(Object.keys(core.status.hero.items[name])); + } + if (!showHide) + list = list.filter(function (id2) { + const hideInfo = core.getFlag("hideInfo", {}); + if (hideInfo.hasOwnProperty(id2)) return !hideInfo[id2]; + else return !core.material.items[id2].hideInToolbox; + }); + list = list.sort(); + return list; + } + if (cls === "equips") { + if (!showHide) + list = list.filter(function (id2) { + const hideInfo = core.getFlag("hideInfo", {}); + if (hideInfo.hasOwnProperty(id2)) return !hideInfo[id2]; + else return !core.material.items[id2].hideInToolbox; + }); + + list = list.sort(); + return list; + } + if (this.uidata.getToolboxItems) { + return this.uidata.getToolboxItems(cls, showHide); + } + if (!showHide) + list = list.filter(function (id2) { + return !core.material.items[id2].hideInToolbox; + }); + list = list.sort(); + return list; + }; + + function drawToolbox_setShowHideBtn(ctx, x, y, h, style) { + core.setTextAlign(ctx, "left"); + core.setTextBaseline(ctx, "top"); + var fontSize = h - 6; + var font = core.ui._buildFont(fontSize); + var text = "显示隐藏"; + var w = core.calWidth(ctx, text, font); + h += 4; + const squareSize = h - 6; + + x -= w + squareSize + 26; + + const border = 2; + core.fillRect(ctx, x, y, squareSize, squareSize, " #F5F5F5"); + if (core.hasFlag("showHideItem")) { + core.fillRect( + ctx, + x + border, + y + border, + squareSize - 2 * border, + squareSize - 2 * border, + "lime" + ); + } + core.fillText(ctx, text, x + squareSize + 2, y + 4, style, font); + + var todo = function () { + core.setFlag("showHideItem", !core.getFlag("showHideItem", false)); + if (core.status.event.id === "toolbox") core.plugin.drawToolbox(); + else if (core.status.event.id === "equipbox") + core.plugin.drawEquipbox(); + }; + addUIEventListener(x, y, w, h, todo); + } + + function drawItemListbox_setPageBtn( + ctx, + left, + right, + bottom, + r, + style, + lineWidth + ) { + var offset = lineWidth / 2 + r; + + var x = left + offset; + var y = bottom - offset; + var pos = (Math.sqrt(2) / 2) * (r - lineWidth / 2); + core.fillPolygon( + ctx, + [ + [x - pos, y], + [x + pos - 2, y - pos], + [x + pos - 2, y + pos], + ], + style + ); + core.strokeCircle(ctx, x, y, r, style, lineWidth); + var todo = function () { + core.addItemListboxPage(-1); + }; + addUIEventListener(x - r - 2, y - r - 2, r * 2 + 4, r * 2 + 4, todo); + + x = right - offset; + core.fillPolygon( + ctx, + [ + [x + pos, y], + [x - pos + 2, y - pos], + [x - pos + 2, y + pos], + ], + style + ); + core.strokeCircle(ctx, x, y, r, style, lineWidth); + var todo = function () { + core.addItemListboxPage(1); + }; + addUIEventListener(x - r - 2, y - r - 2, r * 2 + 4, r * 2 + 4, todo); + } + + this.clickItemFunc = function (id) { + var info = core.status.thisUIEventInfo; + if (!info) return; + if (info.select.id == id) return core.useSelectItemInBox(); + info.select = {}; + info.select.id = id; + core.setIndexAndSelect("index"); + refreshBox(); + }; + + this.clickOneEquipbox = function (id, type) { + var info = core.status.thisUIEventInfo; + if (!info) return; + if (info.select.id == id && info.select.type == type) + core.useSelectItemInBox(); + else + core.status.thisUIEventInfo.select = { + id: id, + type: type, + action: "unload", + }; + return refreshBox(); + }; + + this.useSelectItemInBox = function () { + var info = core.status.thisUIEventInfo; + if (!info) return; + if (!info.select.id) return; + var id = info.select.id; + if (core.status.event.id == "toolbox") { + core.events.tryUseItem(id); + // core.closePanel(); + } else if (core.status.event.id == "equipbox") { + var action = info.select.action || "load"; + info.index = 1; + if (action == "load") { + var type = core.getEquipTypeById(id); + let equipClsid = core.material.items[id]?.equipCls; + let equipCls0 = core.material.items[core.getEquip(0)]?.equipCls; + let equipCls1 = core.material.items[core.getEquip(1)]?.equipCls; + if (equipClsid === "双手剑") { + core.unloadEquip(0, function () { + core.status.route.push("unEquip:" + 0); + }); + core.unloadEquip(1, function () { + core.status.route.push("unEquip:" + 1); + }); + } + if ( + equipCls0 === "双手剑" && + !(equipClsid === "饰品" || equipClsid === "护具") + ) { + core.unloadEquip(0, function () { + core.status.route.push("unEquip:" + 0); + }); + } + core.loadEquip(id, function () { + core.status.route.push("equip:" + id); + info.select.type = type; + core.setIndexAndSelect("select"); + core.drawEquipbox(); + }); + } else { + var type = info.select.type; + core.unloadEquip(type, function () { + core.status.route.push("unEquip:" + type); + info.select.type = type; + info.select.action = "load"; + core.setIndexAndSelect("select"); + core.drawEquipbox(); + }); + } + } + core.updateStatusBar(); + }; + + this.setIndexAndSelect = function (toChange) { + var info = core.status.thisUIEventInfo; + if (!info) return; + setPageItems(info.page); + var index = info.index || 1; + var items = info.pageItems; + + info.select.action = null; + info.select.type = null; + if (toChange == "index") info.index = items.indexOf(info.select.id) + 1; + info.select.id = items[info.index - 1]; + }; + + this.addItemListboxPage = function (num) { + var info = core.status.thisUIEventInfo; + if (!info) return; + var maxPage = info.maxPage || 1; + info.page = info.page || 1; + info.page += num; + if (info.page <= 0) info.page = maxPage; + if (info.page > maxPage) info.page = 1; + info.index = 1; + setPageItems(info.page); + core.setIndexAndSelect("select"); + refreshBox(); + }; + + this.addItemListboxIndex = function (num) { + var info = core.status.thisUIEventInfo; + if (!info) return; + var maxItem = info.maxItem || 0; + info.index = info.index || 0; + info.index += num; + if (info.index <= 0) info.index = 1; + if (info.index > maxItem) info.index = maxItem; + core.setIndexAndSelect("select"); + refreshBox(); + }; + + this.addEquipboxType = function (num) { + var info = core.status.thisUIEventInfo; + var type = info.select.type; + if (type == null && num > 0) info.select.type = 0; + else info.select.type = type + num; + var max = core.status.globalAttribute.equipName.length; + if (info.select.type >= max) { + info.select = {}; + core.setIndexAndSelect("select"); + return core.addItemListboxPage(0); + } else { + var m = Math.abs(info.select.type); + if (info.select.type < 0) info.select.type = max - m; + core.setIndexAndSelect("select"); + refreshBox(); + return; + } + }; + + core.actions._keyDownToolbox = function (keycode) { + if (!core.status.thisEventClickArea) return; + if (keycode == 37) { + // left + core.addItemListboxPage(-1); + return; + } + if (keycode == 38) { + // up + core.addItemListboxIndex(-1); + return; + } + if (keycode == 39) { + // right + core.addItemListboxPage(1); + return; + } + if (keycode == 40) { + // down + core.addItemListboxIndex(1); + return; + } + }; + + ////// 工具栏界面时,放开某个键的操作 ////// + core.actions._keyUpToolbox = function (keycode) { + if (keycode == 81) { + core.ui.closePanel(); + if (core.isReplaying()) core.control._replay_equipbox(); + else core.openEquipbox(); + return; + } + if (keycode == 84 || keycode == 27 || keycode == 88) { + core.closePanel(); + return; + } + if (keycode == 13 || keycode == 32 || keycode == 67) { + var info = core.status.thisUIEventInfo; + if (info.select) { + core.useSelectItemInBox(); + } + return; + } + }; + + core.actions._keyDownEquipbox = function (keycode) { + if (!core.status.thisEventClickArea) return; + if (keycode == 37) { + // left + var info = core.status.thisUIEventInfo; + if (info.index != null) return core.addItemListboxPage(-1); + return core.addEquipboxType(-1); + } + if (keycode == 38) { + // up + var info = core.status.thisUIEventInfo; + if (info.index == 1) { + info.select.type = core.status.globalAttribute.equipName.length - 1; + core.setIndexAndSelect(); + return refreshBox(); + } + if (info.index) return core.addItemListboxIndex(-1); + return core.addEquipboxType(-1 * info.equips); + } + if (keycode == 39) { + // right + var info = core.status.thisUIEventInfo; + if (info.index != null) return core.addItemListboxPage(1); + return core.addEquipboxType(1); + } + if (keycode == 40) { + // down + var info = core.status.thisUIEventInfo; + if (info.index) return core.addItemListboxIndex(1); + return core.addEquipboxType(info.equips); + } + }; + + core.actions._keyUpEquipbox = function (keycode, altKey) { + if (altKey && keycode >= 48 && keycode <= 57) { + core.items.quickSaveEquip(keycode - 48); + return; + } + if (keycode == 84) { + core.ui.closePanel(); + if (core.isReplaying()) core.control._replay_toolbox(); + else core.openToolbox(); + return; + } + if (keycode == 81 || keycode == 27 || keycode == 88) { + core.closePanel(); + return; + } + if (keycode == 13 || keycode == 32 || keycode == 67) { + var info = core.status.thisUIEventInfo; + if (info.select) core.useSelectItemInBox(); + return; + } + }; + + core.registerAction( + "ondown", + "inEventClickAction", + function (x, y, px, py) { + if (!core.status.thisEventClickArea) return false; + var info = core.status.thisEventClickArea; + for (var i = 0; i < info.length; i++) { + var obj = info[i]; + if ( + px >= obj.x && + px <= obj.x + obj.width && + py > obj.y && + py < obj.y + obj.height + ) { + if (obj.todo) obj.todo(); + break; + } + } + return true; + }, + 51 + ); + core.registerAction( + "onclick", + "stopClick", + function () { + if (core.status.thisEventClickArea) return true; + }, + 51 + ); + + function addUIEventListener(x, y, width, height, todo) { + if (!core.status.thisEventClickArea) return; + var obj = { + x: x, + y: y, + width: width, + height: height, + todo: todo, + }; + core.status.thisEventClickArea.push(obj); + } + + this.initThisEventInfo = function () { + core.status.thisUIEventInfo = { + page: 1, + select: {}, + }; + core.status.thisEventClickArea = []; + }; + + function refreshBox() { + if (!core.status.event.id) return; + if (core.status.event.id == "toolbox") core.drawToolbox(); + else core.drawEquipbox(); + } + + core.ui.closePanel = function () { + if (core.status.hero && core.status.hero.flags) { + // 清除全部临时变量 + Object.keys(core.status.hero.flags).forEach(function (name) { + if (name.startsWith("@temp@") || /^arg\d+$/.test(name)) { + delete core.status.hero.flags[name]; + } + }); + } + this.clearUI(); + core.maps.generateGroundPattern(); + core.updateStatusBar(true); + core.unlockControl(); + core.status.event.data = null; + core.status.event.id = null; + core.status.event.selection = null; + core.status.event.ui = null; + core.status.event.interval = null; + core.status.thisUIEventInfo = null; + core.status.thisEventClickArea = null; + }; + + this.getItemClsName = function (item) { + if (item == null) return itemClsName; + if (item.cls == "equips") { + if (typeof item.equip.type == "string") return item.equip.type; + var type = core.getEquipTypeById(item.id); + return core.status.globalAttribute.equipName[type]; + } else return itemClsName[item.cls] || item.cls; + }; + + core.events.openToolbox = function (fromUserAction) { + if (core.isReplaying()) return; + if (!this._checkStatus("toolbox", fromUserAction)) return; + core.initThisEventInfo(); + let info = core.status.thisUIEventInfo; + info.index = 1; + core.setIndexAndSelect("select"); + core.drawToolbox(); + }; + + core.events.openEquipbox = function (fromUserAction) { + if (core.isReplaying()) return; + if (!this._checkStatus("equipbox", fromUserAction)) return; + core.initThisEventInfo(); + let info = core.status.thisUIEventInfo; + info.select.type = 0; + core.setIndexAndSelect("select"); + core.drawEquipbox(); + }; + + core.control._replay_toolbox = function () { + if (!core.isPlaying() || !core.isReplaying()) return; + if (!core.status.replay.pausing) return core.drawTip("请先暂停录像"); + if (core.isMoving() || core.status.replay.animate || core.status.event.id) + return core.drawTip("请等待当前事件的处理结束"); + + core.lockControl(); + core.status.event.id = "toolbox"; + core.drawToolbox(); + }; + + core.control._replay_equipbox = function () { + if (!core.isPlaying() || !core.isReplaying()) return; + if (!core.status.replay.pausing) return core.drawTip("请先暂停录像"); + if (core.isMoving() || core.status.replay.animate || core.status.event.id) + return core.drawTip("请等待当前事件的处理结束"); + + core.lockControl(); + core.status.event.id = "equipbox"; + core.drawEquipbox(); + }; + + core.control._replayAction_item = function (action) { + if (action.indexOf("item:") != 0) return false; + var itemId = action.substring(5); + if (!core.canUseItem(itemId)) return false; + if ( + core.material.items[itemId].hideInReplay || + core.status.replay.speed == 24 + ) { + core.useItem(itemId, false, core.replay); + return true; + } + core.status.event.id = "toolbox"; + core.initThisEventInfo(); + var info = core.status.thisUIEventInfo; + var items = core.getToolboxItems( + "all", + core.getFlag("showHideItem", false) + ); + setPageItems(1); + var index = items.indexOf(itemId) + 1; + info.page = Math.ceil(index / info.maxItem); + info.index = index % info.maxItem || info.maxItem; + core.setIndexAndSelect("select"); + setPageItems(info.page); + core.drawToolbox(); + setTimeout(function () { + core.ui.closePanel(); + core.useItem(itemId, false, core.replay); + }, core.control.__replay_getTimeout()); + return true; + }; + + core.control._replayAction_equip = function (action) { + if (action.indexOf("equip:") != 0) return false; + var itemId = action.substring(6); + var items = core.getToolboxItems( + "equips", + core.getFlag("showHideItem", false) + ); + var index = items.indexOf(itemId) + 1; + if (index < 1) { + core.removeFlag("__doNotCheckAutoEvents__"); + return false; + } + + var cb = function () { + var next = core.status.replay.toReplay[0] || ""; + if (!next.startsWith("equip:") && !next.startsWith("unEquip:")) { + core.removeFlag("__doNotCheckAutoEvents__"); + core.checkAutoEvents(); + } + core.replay(); + }; + core.setFlag("__doNotCheckAutoEvents__", true); + + core.status.route.push(action); + if ( + core.material.items[itemId].hideInReplay || + core.status.replay.speed == 24 + ) { + core.loadEquip(itemId, cb); + return true; + } + core.status.event.id = "equipbox"; + core.initThisEventInfo(); + var info = core.status.thisUIEventInfo; + setPageItems(1); + info.page = Math.ceil(index / info.maxItem); + info.index = index % info.maxItem || info.maxItem; + core.setIndexAndSelect("select"); + setPageItems(info.page); + core.drawEquipbox(); + setTimeout(function () { + core.ui.closePanel(); + core.loadEquip(itemId, cb); + }, core.control.__replay_getTimeout()); + return true; + }; + + core.control._replayAction_unEquip = function (action) { + if (action.indexOf("unEquip:") != 0) return false; + var equipType = parseInt(action.substring(8)); + if (!core.isset(equipType)) { + core.removeFlag("__doNotCheckAutoEvents__"); + return false; + } + + var cb = function () { + var next = core.status.replay.toReplay[0] || ""; + if (!next.startsWith("equip:") && !next.startsWith("unEquip:")) { + core.removeFlag("__doNotCheckAutoEvents__"); + core.checkAutoEvents(); + } + core.replay(); + }; + core.setFlag("__doNotCheckAutoEvents__", true); + + core.status.route.push(action); + if (core.status.replay.speed == 24) { + core.unloadEquip(equipType, cb); + return true; + } + core.status.event.id = "equipbox"; + core.initThisEventInfo(); + var info = core.status.thisUIEventInfo; + setPageItems(1); + info.select.type = equipType; + core.setIndexAndSelect(); + core.drawEquipbox(); + setTimeout(function () { + core.ui.closePanel(); + core.unloadEquip(equipType, cb); + }, core.control.__replay_getTimeout()); + return true; + }; + core.registerReplayAction("item", core.control._replayAction_item); + core.registerReplayAction("equip", core.control._replayAction_equip); + core.registerReplayAction("unEquip", core.control._replayAction_unEquip); +}, "技能树": function () { // 在此增加新插件 // @@ -23679,5 +23667,242 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = ctx.restore(); //恢复变换前的坐标,否则将连续转置 } +}, + "scrollingText": function () { + // 本插件用于绘制在线留言 + // 说明:https://h5mota.com/bbs/thread/?tid=1017 + // 目前使用core.http代替帖子中提到的axios + ////// 绘制提示同时播放成功音效 ////// + ui.prototype.drawSuccessTip = function (text, id, frame) { + this.drawTip(text, id, frame); + core.playSound('gem.mp3'); + } + core.plugin.aniMap = new Map() + ////// 绘制提示同时播放错误音效 ////// + ui.prototype.drawFailTip = function (text, id, frame) { + this.drawTip(text, id, frame); + core.playSound('error.mp3'); + } + /** 塔的英文名 */ + const towerName = core.firstData.name; + + let [W, H] = [core.__SIZE__, core.__SIZE__]; + let [WIDTH, HEIGHT] = [core.__PIXELS__, core.__PIXELS__]; + + //#region 弹幕的收发 + this.getComment = function () { + if (core.isReplaying()) return; + let form = new FormData(); + form.append('type', 1); + form.append('towername', towerName); + utils.prototype.http( + 'POST', + 'https://h5mota.com/backend/tower/barrage.php', + form, + function (res) { + try { + res = JSON.parse(res); + console.log(res); + core.drawTip('接收成功!') + core.playSound('item.mp3'); + let commentCollection = {}; + const commentList = res?.list; + const isEmpty = /^\s*$/; + for (let i = 0, l = commentList.length; i <= l - 1; i++) { + if (isEmpty.test(commentList[i]?.comment)) continue; + const commentTagsList = commentList[i].tags.split(','); + const [cFloorId, cX, cY] = commentTagsList; + if (0 <= cX && cX <= W - 1 && 0 <= cY && cY <= H - 1 && core.floorIds.includes(cFloorId)) { + if (!commentCollection.hasOwnProperty(cFloorId)) { commentCollection[cFloorId] = {}; } + const str = cX + ',' + cY; + if (!commentCollection[cFloorId].hasOwnProperty(str)) { commentCollection[cFloorId][str] = []; } + commentCollection[cFloorId][str].push(commentList[i]?.comment); + } + } + core.setFlag('commentCollection', commentCollection); + } catch (err) { + core.drawFailTip('接收失败!' + err.message); + } + }, + function (err) { + err = JSON.parse(err); + console.error(err); + core.drawFailTip('接收失败' + err?.message); + }, + null, null, null, 1000 + ); + } + + this.postComment = function (comment, tags) { + if (core.isReplaying()) return; + const isEmpty = /^\s*$/; + if (isEmpty.test(comment)) { + core.drawFailTip('您输入的消息为空,请重发!'); + return; + } + let form = new FormData(); + form.append('type', 2); + form.append('towername', towerName); + form.append('comment', comment); + form.append('tags', tags); + form.append('userid', 2324); + form.append('password', '77c8fd5ff49c370342e4472ebdda5903'); + utils.prototype.http( + 'POST', + 'https://h5mota.com/backend/tower/barrage.php', + form, + function (res) { + try { + res = JSON.parse(res); + console.log(res); + if (res?.code === 0) { + core.drawTip('提交成功!') + } else { + core.drawTip('提交失败!' + res?.message); + } + } catch (err) { + core.drawFailTip('提交失败!' + err.message); + } + }, + function (err) { + err = JSON.parse(err); + console.error(err); + core.drawFailTip('提交失败!' + err?.message); + }, + null, null, null, 1000 + ); + } + //#endregion + + /** 若变量comment为真,在每层切换时在地上有弹幕的地方显示相应图标。 */ + this.drawCommentSign = function () { + if (!core.hasFlag('comment') || core.isReplaying()) return; + let commentCollection = core.getFlag('commentCollection', {}), + floorId = core.status.floorId; + core.createCanvas('sign', 0, 0, WIDTH, HEIGHT, 61); + core.setOpacity('sign', 0.6); + if (commentCollection.hasOwnProperty(floorId)) { + for (let pos in commentCollection[floorId]) { + const l = commentCollection[floorId][pos].length; + for (let i = 0; i <= l - 1; i++) { + const [x, y] = pos.split(','); + core.drawIcon('sign', 'postman', 32 * x, 32 * y); + break; + } + } + } + } + + /** 立即清除楼层的弹幕图标。关闭弹幕相关设置时调用。 */ + this.clearCommentSign = function () { + core.deleteCanvas('sign'); + } + + /** 默认一次显示的弹幕数 */ + const showNum = 5; + + // 每走一步或瞬移,调用该函数,若目标点有弹幕,显示之 + this.showComment = function (x, y) { + if (!core.getFlag('comment') || core.isReplaying()) return; + const commentCollection = core.getFlag('commentCollection', {}); + const floorId = core.status.floorId, + str = x + ',' + y; + if (commentCollection.hasOwnProperty(floorId) && + commentCollection[floorId].hasOwnProperty(str)) { + let commentArr = commentCollection[floorId][str].concat(); + const commentArrPicked = pickComment(commentArr, showNum); + drawComment(commentArrPicked); + } + } + + /** 返回从commentArr中挑选showNum个comment组成的数组*/ + function pickComment(commentArr, showNum) { + let showList = []; + if (commentArr.length <= showNum) { + showList = commentArr; + } else { + for (let i = 0; i <= showNum - 1; i++) { + const l = commentArr.length, + n = core.plugin.dice(l - 1); + showList.push(commentArr[n]); + commentArr.splice(n, 1); + } + } + return showList; + } + + function drawComment(commentArr) { + const l = commentArr.length; + let yList = generateCommentYList(20, HEIGHT - 20, showNum); + if (l < showNum) yList = getRandomElements(yList, l); + for (let i = 0; i <= l - 1; i++) { + drawCommentStr(commentArr[i], WIDTH + 20 * Math.random(), + yList[i], Math.random() * 0.1 + 0.1); + } + } + + /** 生成count个随机数,范围从min到max,作为弹幕的y坐标*/ + function generateCommentYList(min, max, count) { + let yList = Array(count).fill(0); + const distance = (max - min) / (count + 1); + for (let i = 0; i < count; i++) { + yList[i] = min + distance * (i + 1) + (Math.random() - 0.5) * (distance / 2); + } + return yList; + } + + function getRandomElements(arr, count) { + let result = [...arr]; + let len = result.length; + count = Math.min(len, count); + + for (let i = len - 1; i > len - 1 - count; i--) { + let j = Math.floor(Math.random() * (i + 1)); + [result[i], result[j]] = [result[j], result[i]]; + } + + return result.slice(len - count); + } + + //#region 弹幕绘制部分 + const { Animation, linear, Ticker } = core.plugin.animate ?? {}; + const ctxName = 'scrollingText'; + + if (Ticker) { + const ticker = new Ticker(); + ticker.add(() => { + if (core.isReplaying()) return; + core.createCanvas(ctxName, 0, 0, core.__PIXELS__, core.__PIXELS__, 136); //每帧重绘该画布 + }); + } + + /** + * 绘制弹幕 + * @example + * drawCommentStr('OK', 450, 200, 0.1); + * @param {string} content 弹幕的内容 + * @param {number} x 弹幕的初始x坐标 + * @param {number} y 弹幕的初始y坐标 + * @param {number} vx 弹幕的横向滚动速度 + */ + function drawCommentStr(content, x, y, vx) { + if (core.isReplaying() || !Animation) return; + const ani = new Animation(); + core.plugin.aniMap.set(ani, (ani) => ani.ticker.destroy()); + ani.ticker.add(() => { + core.fillText(ctxName, content, x + ani.x, y, 'white', '16px Verdana'); + }) + // 弹幕的最大长度5600,再长属于异常数据 + const aim = 600 + Math.min(core.calWidth(ctxName, content, '16px Verdana'), 5000); + ani.mode(linear()) + .time(aim / vx) + .absolute() + .move(-aim, 0) + ani.all().then(() => { + ani.ticker.destroy(); + }); + } + //#endregion + } } \ No newline at end of file