拆分ui.create和ui.click, 特别拆分ui.create.menu,修改武将和卡牌在菜单栏(包括联机)的加载逻辑

This commit is contained in:
nonameShijian 2024-02-14 01:49:37 +08:00
parent c2c18b2913
commit 601148aa55
12 changed files with 14530 additions and 14076 deletions

View File

@ -4379,7 +4379,16 @@ export class Game extends Uninstantable {
} }
} }
if (lib[i][j] == undefined) { if (lib[i][j] == undefined) {
lib[i][j] = pack[i][j]; // 判断扩展武将包是否开启
if (i == 'character') {
// if (!game.hasExtension(extname) || !game.hasExtensionLoaded(extname)) continue;
if (lib.config[`extension_${extname}_characters_enable`] === undefined) {
game.saveExtensionConfig(extname, 'characters_enable', true);
}
if (lib.config[`extension_${extname}_characters_enable`] === true) {
lib[i][j] = pack[i][j];
}
} else lib[i][j] = pack[i][j];
} }
} }
} }
@ -4482,7 +4491,18 @@ export class Game extends Uninstantable {
pack[i][j].audio = 'ext:' + extname + ':' + pack[i][j].audio; pack[i][j].audio = 'ext:' + extname + ':' + pack[i][j].audio;
} }
} }
if (lib[i][j] == undefined) lib[i][j] = pack[i][j]; if (lib[i][j] == undefined) {
// 判断扩展卡牌包是否开启
if (i == 'card') {
// if (!game.hasExtension(extname) || !game.hasExtensionLoaded(extname)) continue;
if (lib.config[`extension_${extname}_cards_enable`] === undefined) {
game.saveExtensionConfig(extname, 'cards_enable', true);
}
if (lib.config[`extension_${extname}_cards_enable`] === true) {
lib[i][j] = pack[i][j];
}
} else lib[i][j] = pack[i][j];
}
} }
} }
} }

View File

@ -47,14 +47,37 @@ export class Library extends Uninstantable {
static connectBanned = []; static connectBanned = [];
static characterIntro = {}; static characterIntro = {};
static characterTitle = {}; static characterTitle = {};
static characterPack = {}; static characterPack = new Proxy({}, {
set(target, prop, newValue) {
if (typeof prop == 'string') {
// 新增武将包,且不是“收藏”和“禁用”
if (!['mode_favourite', 'mode_banned'].includes(prop) && !Reflect.has(target, prop)) {
Promise.resolve().then(() => {
ui.updateCharacterPackMenu.forEach(fun => fun(prop));
});
}
}
return Reflect.set(target, prop, newValue);
}
});
static characterFilter = {}; static characterFilter = {};
static characterSort = {}; static characterSort = {};
static characterReplace = {}; static characterReplace = {};
static characterInitFilter = {}; static characterInitFilter = {};
static characterGuozhanFilter = ["mode_guozhan"]; static characterGuozhanFilter = ["mode_guozhan"];
static dynamicTranslate = {}; static dynamicTranslate = {};
static cardPack = {}; static cardPack = new Proxy({}, {
set(target, prop, newValue) {
if (typeof prop == 'string') {
if (!Reflect.has(target, prop)) {
Promise.resolve().then(() => {
ui.updateCardPackMenu.forEach(fun => fun(prop));
});
}
}
return Reflect.set(target, prop, newValue);
}
});
/** /**
* @type { SMap<number> } * @type { SMap<number> }
*/ */

3913
noname/ui/click/index.js Normal file

File diff suppressed because it is too large Load Diff

3092
noname/ui/create/index.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,528 @@
import { ui, game, get, lib, _status } from "../../../../noname.js";
export function openMenu(node, e, onclose) {
popupContainer.innerHTML = '';
var left = Math.round(e.clientX / game.documentZoom);
var zoom = get.is.phoneLayout() ? 1.3 : 1;
popupContainer.appendChild(node);
// var rect=node.getBoundingClientRect();
if (node.classList.contains('visual')) {
// var num=node.querySelectorAll('.menu.visual>div').length;
// node.style.top=(e.y-node.offsetHeight/2+30)+'px';
for (var i = 0; i < node.childElementCount; i++) {
if (node.childNodes[i].update) {
node.childNodes[i].update();
}
}
// if(node.offsetTop<10){
// node.style.top='10px';
// }
}
// else if(get.is.phoneLayout()&&rect.top*1.3+rect.height*1.3+20>ui.window.offsetHeight){
// node.style.top=(ui.winheightdow.offsetHeight-20-rect.height*1.3)/1.3+'px';
// }
// if(e){
var height = node.offsetHeight;
var idealtop = e.clientY / game.documentZoom;
if (idealtop < 10) {
idealtop = 10;
}
else if ((idealtop + height) * zoom + 10 > ui.window.offsetHeight) {
idealtop = (ui.window.offsetHeight - 10) / zoom - height;
}
node.style.top = idealtop + 'px';
node.style.left = left + 'px';
// }
popupContainer.classList.remove('hidden');
popupContainer.onclose = onclose;
};
export function clickToggle() {
if (this.classList.contains('disabled')) return;
this.classList.toggle('on');
var config = this._link.config;
if (config.onclick) {
if (config.onclick.call(this, this.classList.contains('on')) === false) {
this.classList.toggle('on');
}
}
if (config.update) {
config.update();
}
};
export function clickSwitcher() {
if (this.classList.contains('disabled')) return;
var node = this;
this.classList.add('on');
if (this._link.menu) {
var pos1 = this.lastChild.getBoundingClientRect();
var pos2 = ui.window.getBoundingClientRect();
if (this._link.menu.classList.contains('visual')) {
openMenu(this._link.menu, {
clientX: pos1.left + pos1.width + 5 - pos2.left,
clientY: pos1.top - pos2.top
}, function () {
node.classList.remove('on');
});
}
else if (this._link.menu.childElementCount > 10) {
openMenu(this._link.menu, {
clientX: pos1.left + pos1.width + 5 - pos2.left,
clientY: Math.min((ui.window.offsetHeight - 400) / 2, pos1.top - pos2.top)
}, function () {
node.classList.remove('on');
});
lib.setScroll(this._link.menu);
}
else {
openMenu(this._link.menu, {
clientX: pos1.left + pos1.width + 5 - pos2.left,
clientY: pos1.top - pos2.top
}, function () {
node.classList.remove('on');
});
}
}
};
/**
* @this { HTMLDivElement } menuContainer
*/
export function clickContainer(connectMenu) {
this.classList.add('hidden');
if (connectMenu) {
if (_status.enteringroom) {
_status.enteringroom = false;
}
if (_status.creatingroom) {
_status.creatingroom = false;
}
ui.window.classList.remove('shortcutpaused');
}
else {
game.resume2();
if (game.onresume2) {
game.onresume2();
}
ui.arena.classList.remove('menupaused');
ui.historybar.classList.remove('menupaused');
ui.window.classList.remove('touchinfohidden');
ui.config2.classList.remove('pressdown2');
}
};
export function clickMenuItem() {
var node = this.parentNode._link;
var config = node._link.config;
node._link.current = this.link;
var tmpName = node.lastChild.innerHTML;
node.lastChild.innerHTML = config.item[this._link];
if (config.onclick) {
if (config.onclick.call(node, this._link, this) === false) {
node.lastChild.innerHTML = tmpName;
}
}
if (config.update) {
config.update();
}
};
export function createMenu(connectMenu, tabs, config) {
var createPage = function (position) {
var node = ui.create.div(position);
lib.setScroll(ui.create.div('.left.pane', node));
lib.setScroll(ui.create.div('.right.pane', node));
return node;
};
var menu = ui.create.div('.main.menu.dialog.popped.static', config.position, function (e) {
e.stopPropagation();
});
if (connectMenu) {
menu.classList.add('center');
menuContainer.classList.add('centermenu');
}
var menuTab = ui.create.div('.menu-tab', menu);
var menuTabBar = ui.create.div('.menu-tab-bar', menu);
menuTabBar.style.left = (config.bar || 0) + 'px';
if (Math.round(2 * game.documentZoom) < 2) {
menuTabBar.style.height = '3px';
}
var menuContent = ui.create.div('.menu-content', menu);
var clickTab = function () {
if (this.classList.contains('disabled')) return;
var active = this.parentNode.querySelector('.active');
if (active) {
active.classList.remove('active');
active._link.remove();
}
this.classList.add('active');
menuTabBar.style.transform = 'translateX(' + (this.getBoundingClientRect().left - this.parentNode.firstChild.getBoundingClientRect().left) / game.documentZoom + 'px)';
menuContent.appendChild(this._link);
};
ui.click.menuTab = function (tab) {
for (var i = 0; i < menuTab.childNodes.length; i++) {
if (menuTab.childNodes[i].innerHTML == tab) {
clickTab.call(menuTab.childNodes[i]);
return;
}
}
};
var pages = [];
for (var i = 0; i < tabs.length; i++) {
var active = (i === (config.init || 0));
pages[i] = createPage(active ? menuContent : null);
ui.create.div(active ? '.active' : '', tabs[i], menuTab, clickTab)._link = pages[i];
}
return {
menu: menu,
pages: pages
};
};
export function createConfig(config, position) {
var node = ui.create.div('.config', config.name);
node._link = { config: config };
if (!config.clear) {
if (config.name != '开启') {
if (config.name == '屏蔽弱将') {
config.intro = '强度过低的武将孙策除外不会出现在选将框也不会被AI选择';
}
else if (config.name == '屏蔽强将') {
config.intro = '强度过高的武将不会出现在选将框也不会被AI选择';
}
else if (!config.intro) {
config.intro = '设置' + config.name;
}
lib.setIntro(node, function (uiintro) {
if (lib.config.touchscreen) _status.dragged = true;
uiintro.style.width = '170px';
var str = config.intro;
if (typeof str == 'function') {
str = str();
}
uiintro._place_text = uiintro.add('<div class="text" style="display:inline">' + str + '</div>');
});
}
}
else {
node.innerHTML = '<span>' + config.name + '</span>';
if (!config.nopointer) {
node.classList.add('pointerspan');
}
}
if (config.item) {
if (typeof config.item == 'function') {
config.item = config.item();
}
if (Array.isArray(config.init)) {
void 0;
}
else {
node.classList.add('switcher');
node.listen(clickSwitcher);
node._link.choosing = ui.create.div('', config.item[config.init], node);
node._link.menu = ui.create.div('.menu');
if (config.visualMenu) {
node._link.menu.classList.add('visual');
var updateVisual = function () {
config.visualMenu(this, this._link, config.item[this._link], config);
};
var createNode = function (i, before) {
var visualMenu = ui.create.div();
if (config.visualBar) {
if (before) {
node._link.menu.insertBefore(visualMenu, before);
}
else {
node._link.menu.insertBefore(visualMenu, node._link.menu.lastChild);
}
}
else {
node._link.menu.appendChild(visualMenu);
}
ui.create.div('.name', get.verticalStr(config.item[i]), visualMenu);
visualMenu._link = i;
if (config.visualMenu(visualMenu, i, config.item[i], config) !== false) {
visualMenu.listen(clickMenuItem);
}
visualMenu.update = updateVisual;
};
if (config.visualBar) {
var visualBar = ui.create.div(node._link.menu, function () {
this.parentNode.parentNode.noclose = true;
});
node._link.menu.classList.add('withbar');
config.visualBar(visualBar, config.item, createNode, node);
visualBar.update = function () {
config.visualBar(visualBar, config.item, createNode, node);
};
}
for (var i in config.item) {
createNode(i);
}
lib.setScroll(node._link.menu);
node._link.menu.updateBr = function () {
var br = Array.from(this.querySelectorAll('.menu.visual>br'));
while (br.length) {
br.shift().remove();
}
var split = [];
for (var i = 1; i < this.childElementCount; i++) {
if (i % 3 == 0) {
split.push(this.childNodes[i]);
}
}
for (var i = 0; i < split.length; i++) {
this.insertBefore(ui.create.node('br'), split[i]);
}
};
node._link.menu.updateBr();
}
else {
for (var i in config.item) {
var textMenu = ui.create.div('', config.item[i], node._link.menu, clickMenuItem);
textMenu._link = i;
if (config.textMenu) {
config.textMenu(textMenu, i, config.item[i], config);
}
lib.setScroll(node._link.menu);
}
}
node._link.menu._link = node;
node._link.current = config.init;
}
}
else if (config.range) {
void 0;
}
else if (config.clear) {
if (node.innerHTML.length >= 15) node.style.height = 'auto';
node.listen(clickToggle);
}
else if (config.input) {
node.classList.add('switcher');
var input = ui.create.div(node);
if (!config.fixed) {
input.contentEditable = true;
input.style.webkitUserSelect = 'text';
}
input.style.minWidth = '10px';
input.style.maxWidth = '60%';
input.style.overflow = 'hidden';
input.style.whiteSpace = 'nowrap';
input.onkeydown = function (e) {
if (e.keyCode == 13) {
e.preventDefault();
e.stopPropagation();
input.blur();
}
};
if (config.name == '联机昵称') {
input.innerHTML = config.init || '无名玩家';
input.onblur = function () {
input.innerHTML = input.innerHTML.replace(/<br>/g, '');
if (!input.innerHTML || get.is.banWords(input.innerHTML)) {
input.innerHTML = '无名玩家';
}
input.innerHTML = input.innerHTML.slice(0, 12);
game.saveConfig('connect_nickname', input.innerHTML);
game.saveConfig('connect_nickname', input.innerHTML, 'connect');
};
}
else if (config.name == '联机大厅') {
input.innerHTML = config.init || lib.hallURL;
input.onblur = function () {
if (!input.innerHTML) {
input.innerHTML = lib.hallURL;
}
input.innerHTML = input.innerHTML.replace(/<br>/g, '');
game.saveConfig('hall_ip', input.innerHTML, 'connect');
};
}
else {
input.innerHTML = config.init;
input.onblur = config.onblur;
}
}
else {
node.classList.add('toggle');
node.listen(clickToggle);
ui.create.div(ui.create.div(node));
if (config.init == true) {
node.classList.add('on');
}
}
if (position) {
position.appendChild(node);
}
return node;
};
/**
* @type { HTMLDivElement }
*
* 也是一个全屏div但它的子元素是菜单栏
*/
export let menuContainer;
/**
* @type { HTMLDivElement }
*
* 一个全屏div
*/
export let popupContainer;
/**
* @type { Function }
*/
export let updateActive;
/**
* @param { Function } fun
*/
export function setUpdateActive(fun) {
updateActive = fun;
}
/**
* @type { Function }
*/
export let updateActiveCard;
/**
* @param { Function } fun
*/
export function setUpdateActiveCard(fun) {
updateActiveCard = fun;
}
/**
* @type { { menu: HTMLDivElement; pages: HTMLDivElement[]; } }
*/
export let menux;
/**
* @type { HTMLDivElement[] }
*/
export let menuxpages;
/**
* @type { Function[] }
*/
export const menuUpdates = [];
/**
* @param { boolean } [connectMenu]
*/
export function menu(connectMenu) {
/** 提示重启的计时器 */
let menuTimeout = null;
if (!connectMenu && !game.syncMenu) {
menuTimeout = setTimeout(lib.init.reset, 1000);
}
/** menu是menux.menu目前只有赋值没有使用所以先注释掉 */
// let menu;
/**
* 由于联机模式会创建第二个菜单所以需要缓存一下可变的变量
*/
const cacheMenuContainer = menuContainer = ui.create.div('.menu-container.hidden', ui.window, () => {
clickContainer.call(cacheMenuContainer, connectMenu);
})
const cachePopupContainer = popupContainer = ui.create.div('.popup-container.hidden', ui.window, function closeMenu() {
// @ts-ignore
if (cachePopupContainer.noclose) {
// @ts-ignore
cachePopupContainer.noclose = false;
return;
}
cachePopupContainer.classList.add('hidden');
if (typeof cachePopupContainer.onclose == 'function') {
// @ts-ignore
cachePopupContainer.onclose();
}
});
if (!connectMenu) {
ui.menuContainer = cacheMenuContainer;
ui.click.configMenu = function () {
ui.click.shortcut(false);
if (cacheMenuContainer.classList.contains('hidden')) {
ui.config2.classList.add('pressdown2');
ui.arena.classList.add('menupaused');
ui.historybar.classList.add('menupaused');
ui.window.classList.add('touchinfohidden');
cacheMenuContainer.classList.remove('hidden');
for (var i = 0; i < menuUpdates.length; i++) {
menuUpdates[i]();
}
}
else {
clickContainer.call(cacheMenuContainer, connectMenu);
}
};
menux = createMenu(connectMenu, ['开始', '选项', '武将', '卡牌', '扩展', '其它'], {
position: cacheMenuContainer, bar: 40
});
}
else {
ui.connectMenuContainer = cacheMenuContainer;
ui.click.connectMenu = function () {
if (cacheMenuContainer.classList.contains('hidden')) {
if (_status.waitingForPlayer) {
startButton.innerHTML = '设';
var start = cacheMenux.pages[0].firstChild;
for (var i = 0; i < start.childNodes.length; i++) {
if (start.childNodes[i].mode != lib.configOL.mode) {
start.childNodes[i].classList.add('unselectable');
start.childNodes[i].classList.remove('active');
if (start.childNodes[i].link) start.childNodes[i].link.remove();
}
else {
start.childNodes[i].classList.add('active');
if (start.childNodes[i].link) start.nextSibling.appendChild(start.childNodes[i].link);
else console.log(start.nextSibling, start.childNodes[i]);
}
}
}
ui.window.classList.add('shortcutpaused');
cacheMenuContainer.classList.remove('hidden');
for (var i = 0; i < menuUpdates.length; i++) {
menuUpdates[i]();
}
}
else {
clickContainer.call(cacheMenuContainer, connectMenu);
}
};
menux = createMenu(connectMenu, ['模式', '武将', '卡牌'], {
position: cacheMenuContainer, bar: 123
});
// menu = menux.menu;
let cacheMenux = menux;
}
menuxpages = menux.pages.slice(0);
// 开始
let startButton = ui.create.startMenu(connectMenu);
// 选项
ui.create.optionsMenu(connectMenu);
// 武将
let updateCharacterPackMenu = ui.create.characterPackMenu(connectMenu);
ui.updateCharacterPackMenu.push(updateCharacterPackMenu);
// 卡牌
let updatecardPackMenu = ui.create.cardPackMenu(connectMenu);
ui.updateCardPackMenu.push(updatecardPackMenu);
// 扩展
ui.create.extensionMenu(connectMenu);
// 其他
ui.create.otherMenu(connectMenu);
if (menuTimeout) {
clearTimeout(menuTimeout);
delete window.resetExtension;
localStorage.removeItem(lib.configprefix + 'disable_extension', true);
}
}

View File

@ -0,0 +1,648 @@
import {
menuContainer,
popupContainer,
updateActive,
setUpdateActive,
updateActiveCard,
setUpdateActiveCard,
menux,
menuxpages,
menuUpdates,
openMenu,
clickToggle,
clickSwitcher,
clickContainer,
clickMenuItem,
createMenu,
createConfig
} from "../index.js";
import { ui, game, get, lib, _status } from "../../../../../noname.js";
export const cardPackMenu = function (connectMenu) {
/**
* 由于联机模式会创建第二个菜单所以需要缓存一下可变的变量
*/
// const cacheMenuContainer = menuContainer;
// const cachePopupContainer = popupContainer;
const cacheMenux = menux;
const cacheMenuxpages = menuxpages;
/** @type { HTMLDivElement } */
// @ts-ignore
var start = cacheMenuxpages.shift();
var rightPane = start.lastChild;
var pileCreated = false;
var recreatePile = function () {
lib.config.customcardpile['当前牌堆'] = [lib.config.bannedpile, lib.config.addedpile];
game.saveConfig('customcardpile', lib.config.customcardpile);
game.saveConfig('cardpilename', '当前牌堆', true);
pileCreated = false;
};
var clickMode = function () {
var active = this.parentNode.querySelector('.active');
if (active === this) {
return;
}
active.classList.remove('active');
active.link.remove();
active = this;
this.classList.add('active');
updateActiveCard(this);
if (this.mode == 'cardpile') {
this.create();
}
if (this.link) rightPane.appendChild(this.link);
else {
this._initLink();
rightPane.appendChild(this.link);
}
};
setUpdateActiveCard(function (node) {
if (!node) {
node = start.firstChild.querySelector('.active');
if (!node) {
return;
}
}
if (!node.link) node._initLink();
for (var i = 0; i < node.link.childElementCount; i++) {
if (node.link.childNodes[i].updateBanned) {
node.link.childNodes[i].updateBanned();
}
}
});
var updateNodes = function () {
for (var i = 0; i < start.firstChild.childNodes.length; i++) {
var node = start.firstChild.childNodes[i];
if (node.mode) {
if (node.mode.startsWith('mode_')) {
// 扩展卡牌包开启逻辑
if (node.mode.startsWith('mode_extension')) {
const extName = node.mode.slice(15);
if (!game.hasExtension(extName) || !game.hasExtensionLoaded(extName)) continue;
if (lib.config[`extension_${extName}_cards_enable`] == true) {
node.classList.remove('off');
if (node.link) node.link.firstChild.classList.add('on');
}
else {
node.classList.add('off');
if (node.link) node.link.firstChild.classList.remove('on');
}
}
continue;
}
if (node.mode == 'custom') continue;
if (node.mode == 'cardpile') continue;
if (connectMenu) {
if (!lib.config.connect_cards.includes(node.mode)) {
node.classList.remove('off');
if (node.link) node.link.firstChild.classList.add('on');
}
else {
node.classList.add('off');
if (node.link) node.link.firstChild.classList.remove('on');
}
}
else {
if (lib.config.cards.includes(node.mode)) {
node.classList.remove('off');
if (node.link) node.link.firstChild.classList.add('on');
}
else {
node.classList.add('off');
if (node.link) node.link.firstChild.classList.remove('on');
}
}
}
}
};
var togglePack = function (bool) {
var name = this._link.config._name;
// 扩展卡牌包开启逻辑
if (name.startsWith('mode_extension')) {
const extName = name.slice(15);
if (!game.hasExtension(extName) || !game.hasExtensionLoaded(extName)) return false;
game.saveExtensionConfig(extName, 'cards_enable', bool);
}
// 原逻辑
else {
if (connectMenu) {
if (!bool) {
lib.config.connect_cards.add(name);
}
else {
lib.config.connect_cards.remove(name);
}
game.saveConfig('connect_cards', lib.config.connect_cards);
}
else {
if (bool) {
lib.config.cards.add(name);
}
else {
lib.config.cards.remove(name);
}
game.saveConfig('cards', lib.config.cards);
}
}
updateNodes();
};
var toggleCardPile = function (bool) {
var name = this._link.config._name;
var number = this._link.config._number;
if (!lib.config.bannedpile[name]) {
lib.config.bannedpile[name] = [];
}
if (bool) {
lib.config.bannedpile[name].remove(number);
}
else {
lib.config.bannedpile[name].add(number);
}
recreatePile();
};
var createModeConfig = function (mode, position) {
var info = lib.cardPack[mode];
var page = ui.create.div('');
var node = ui.create.div('.menubutton.large', lib.translate[mode + '_card_config'], position, clickMode);
if (node.innerHTML.length >= 5) {
node.classList.add('smallfont');
}
node.mode = mode;
node._initLink = function () {
node.link = page;
var list = [];
for (var i = 0; i < info.length; i++) {
if (!lib.card[info[i]] || (lib.card[info[i]].derivation && mode != 'mode_derivation')) continue;
list.push([get.translation(get.type(info[i], 'trick')), '', info[i]]);
}
var sortCard = function (card) {
var type = lib.card[card[2]].type;
var subtype = lib.card[card[2]].subtype;
if (lib.cardType[subtype]) {
return lib.cardType[subtype];
}
if (lib.cardType[type]) {
return lib.cardType[type];
}
switch (type) {
case 'basic': return 0;
case 'chess': return 1.5;
case 'trick': return 2;
case 'delay': return 3;
case 'equip': {
switch (lib.card[card[2]].subtype) {
case 'equip1': return 4.1;
case 'equip2': return 4.2;
case 'equip3': return 4.3;
case 'equip4': return 4.4;
case 'equip5': return 4.5;
default: return 4;
}
}
case 'zhenfa': return 5;
default: return 6;
}
};
list.sort(function (a, b) {
var sort1 = sortCard(a);
var sort2 = sortCard(b);
if (sort1 == sort2) {
return (b[2] < a[2]) ? 1 : -1;
}
else if (sort1 > sort2) {
return 1;
}
else {
return -1;
}
});
var cfgnode = createConfig({
name: '开启',
_name: mode,
init: (() => {
// 扩展卡牌包开启逻辑
if (mode.startsWith('mode_extension')) {
const extName = mode.slice(15);
if (!game.hasExtension(extName) || !game.hasExtensionLoaded(extName)) return false;
// 这块或许应该在加载扩展时候写
if (lib.config[`extension_${extName}_cards_enable`] === undefined) {
game.saveExtensionConfig(extName, 'cards_enable', true);
}
return lib.config[`extension_${extName}_cards_enable`] === true;
}
// 原逻辑
else return lib.config.cards.includes(mode);
})(),
onclick: togglePack
});
if (!mode.startsWith('mode_')) {
page.appendChild(cfgnode);
}
else {
page.style.paddingTop = '8px';
}
var banCard = function (e) {
if (_status.clicked) {
_status.clicked = false;
return;
}
if (mode.startsWith('mode_') && !mode.startsWith('mode_extension_') && mode != 'mode_banned') {
return;
}
ui.click.touchpop();
this._banning = connectMenu ? 'online' : 'offline';
ui.click.intro.call(this, e);
_status.clicked = false;
delete this._banning;
};
var updateBanned = function () {
var list;
if (connectMenu) {
var mode = cacheMenux.pages[0].firstChild.querySelector('.active');
if (mode && mode.mode) {
list = lib.config['connect_' + mode.mode + '_bannedcards'];
}
}
else {
list = lib.config[get.mode() + '_bannedcards'];
}
if (list && list.includes(this.link[2])) {
this.classList.add('banned');
}
else {
this.classList.remove('banned');
}
};
var buttons = ui.create.buttons(list, 'vcard', page);
for (var i = 0; i < buttons.length; i++) {
buttons[i].classList.add('noclick');
buttons[i].listen(banCard);
if (mode != 'mode_banned') {
buttons[i].updateBanned = updateBanned;
}
}
page.classList.add('menu-buttons');
page.classList.add('leftbutton');
if (!connectMenu && !lib.config.all.sgscards.includes(mode) && !mode.startsWith('mode_')) {
ui.create.div('.config.pointerspan', '<span>隐藏卡牌包</span>', page, function () {
if (this.firstChild.innerHTML == '隐藏卡牌包') {
this.firstChild.innerHTML = '卡牌包将在重启后隐藏';
lib.config.hiddenCardPack.add(mode);
if (!lib.config.prompt_hidepack) {
alert('隐藏的扩展包可通过选项-其它-重置隐藏内容恢复');
game.saveConfig('prompt_hidepack', true);
}
}
else {
this.firstChild.innerHTML = '隐藏卡牌包';
lib.config.hiddenCardPack.remove(mode);
}
game.saveConfig('hiddenCardPack', lib.config.hiddenCardPack);
});
}
if (!mode.startsWith('mode_') && lib.cardPile[mode]) {
var cardpileNodes = [];
var cardpileexpanded = false;
if (!lib.config.bannedpile[mode]) {
lib.config.bannedpile[mode] = [];
}
if (!lib.config.addedpile[mode]) {
lib.config.addedpile[mode] = [];
}
ui.create.div('.config.more.pile', '编辑牌堆 <div>&gt;</div>', page, function () {
if (cardpileexpanded) {
this.classList.remove('on');
for (var k = 0; k < cardpileNodes.length; k++) {
cardpileNodes[k].style.display = 'none';
}
}
else {
this.classList.add('on');
for (var k = 0; k < cardpileNodes.length; k++) {
cardpileNodes[k].style.display = '';
}
}
cardpileexpanded = !cardpileexpanded;
});
var cfgnode = ui.create.div(page, '.config.pointerspan.cardpilecfg.toggle');
var cfgaddcard = ui.create.node('button', '', '添加卡牌', cfgnode, function () {
this.parentNode.nextSibling.classList.toggle('hidden');
});
var cfgbancard = ui.create.node('button', '', '全部关闭', cfgnode, function () {
for (var i = 0; i < cardpileNodes.length; i++) {
if (cardpileNodes[i].type == 'defaultcards' && cardpileNodes[i].classList.contains('on')) {
clickToggle.call(cardpileNodes[i]);
}
}
});
var cfgenablecard = ui.create.node('button', '', '全部开启', cfgnode, function () {
for (var i = 0; i < cardpileNodes.length; i++) {
if (cardpileNodes[i].type == 'defaultcards' && !cardpileNodes[i].classList.contains('on')) {
clickToggle.call(cardpileNodes[i]);
}
}
});
cfgbancard.style.marginLeft = '5px';
cfgenablecard.style.marginLeft = '5px';
cardpileNodes.push(cfgnode);
cfgnode.style.display = 'none';
cfgnode.classList.add('cardpilecfg');
cfgnode.classList.add('toggle');
cfgnode.style.marginTop = '5px';
page.appendChild(cfgnode);
var cardpileadd = ui.create.div('.config.toggle.hidden.cardpilecfg.cardpilecfgadd', page);
var pileaddlist = [];
for (var i = 0; i < lib.config.cards.length; i++) {
if (!lib.cardPack[lib.config.cards[i]]) continue;
for (var j = 0; j < lib.cardPack[lib.config.cards[i]].length; j++) {
var cname = lib.cardPack[lib.config.cards[i]][j];
pileaddlist.push([cname, get.translation(cname)]);
if (cname == 'sha') {
pileaddlist.push(['huosha', '火杀']);
pileaddlist.push(['leisha', '雷杀']);
pileaddlist.push(['icesha', '冰杀']);
pileaddlist.push(['cisha', '刺杀']);
}
}
}
var cardpileaddname = ui.create.selectlist(pileaddlist, null, cardpileadd);
cardpileaddname.style.width = '75px';
cardpileaddname.style.marginRight = '2px';
cardpileaddname.style.marginLeft = '-1px';
var cardpileaddsuit = ui.create.selectlist([
['heart', '红桃'],
['diamond', '方片'],
['club', '梅花'],
['spade', '黑桃'],
], null, cardpileadd);
cardpileaddsuit.style.width = '53px';
cardpileaddsuit.style.marginRight = '2px';
var cardpileaddnumber = ui.create.selectlist([
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
], null, cardpileadd);
cardpileaddnumber.style.width = '43px';
cardpileaddnumber.style.marginRight = '2px';
var button = document.createElement('button');
button.innerHTML = '确定';
button.style.width = '40px';
var deletecard = function () {
this.parentNode.remove();
var info = this.parentNode._info;
var list = lib.config.addedpile[mode];
for (var i = 0; i < list.length; i++) {
if (list[i][0] == info[0] && list[i][1] == info[1] && list[i][2] == info[2]) {
list.splice(i, 1); break;
}
}
recreatePile();
};
button.onclick = function () {
var card = [
cardpileaddsuit.value,
cardpileaddnumber.value,
cardpileaddname.value,
];
lib.config.addedpile[mode].push(card);
recreatePile();
var cfgnode = ui.create.div('.config.toggle.cardpilecfg');
cfgnode._info = card;
cfgnode.innerHTML = get.translation(card[2]) + ' ' + get.translation(card[0]) + get.strNumber(card[1]);
var cfgnodedelete = document.createElement('span');
cfgnodedelete.classList.add('cardpiledelete');
cfgnodedelete.innerHTML = '删除';
cfgnodedelete.onclick = deletecard;
cfgnode.appendChild(cfgnodedelete);
page.insertBefore(cfgnode, cardpileadd.nextSibling);
};
cardpileadd.appendChild(button);
cardpileadd.style.whiteSpace = 'nowrap';
cardpileNodes.push(cardpileadd);
for (var i = 0; i < lib.config.addedpile[mode].length; i++) {
var card = lib.config.addedpile[mode][i];
var cfgnode = ui.create.div('.config.toggle.cardpilecfg');
cfgnode._info = card;
cfgnode.innerHTML = get.translation(card[2]) + ' ' + get.translation(card[0]) + card[1];
var cfgnodedelete = document.createElement('span');
cfgnodedelete.classList.add('cardpiledelete');
cfgnodedelete.innerHTML = '删除';
cfgnodedelete.onclick = deletecard;
cfgnode.appendChild(cfgnodedelete);
cfgnode.style.display = 'none';
cardpileNodes.push(cfgnode);
page.appendChild(cfgnode);
}
for (var i = 0; i < lib.cardPile[mode].length; i++) {
var card = lib.cardPile[mode][i];
var cfgnode = createConfig({
name: ((card[2] == 'sha' && card[3]) ? (get.translation(card[3])) : '') + get.translation(card[2]) + ' ' + get.translation(card[0]) + get.strNumber(card[1]),
_number: i,
_name: mode,
init: !lib.config.bannedpile[mode].includes(i),
onclick: toggleCardPile
});
cfgnode.type = 'defaultcards';
cardpileNodes.push(cfgnode);
cfgnode.style.display = 'none';
cfgnode.classList.add('cardpilecfg');
page.appendChild(cfgnode);
}
ui.create.div('.menuplaceholder', page);
}
};
if (!get.config('menu_loadondemand')) node._initLink();
return node;
};
if (!connectMenu && lib.config.show_ban_menu) {
lib.cardPack.mode_banned = [];
for (var i = 0; i < lib.config.all.mode.length; i++) {
var banned = lib.config[lib.config.all.mode[i] + '_bannedcards'];
if (banned) {
for (var j = 0; j < banned.length; j++) {
lib.cardPack.mode_banned.add(banned[j]);
}
}
}
var bannednode = createModeConfig('mode_banned', start.firstChild);
if (lib.cardPack.mode_banned.length == 0) {
bannednode.style.display = 'none';
}
delete lib.cardPack.mode_banned;
}
for (var i = 0; i < lib.config.all.cards.length; i++) {
if (connectMenu && !lib.connectCardPack.includes(lib.config.all.cards[i])) continue;
createModeConfig(lib.config.all.cards[i], start.firstChild);
}
if (!connectMenu) Object.keys(lib.cardPack).forEach(key => {
if (!lib.config.all.cards.includes(key)) createModeConfig(key, start.firstChild);
if (connectMenu) lib.connectCardPack.add(key);
});
var active = start.firstChild.querySelector('.active');
if (!active) {
active = start.firstChild.firstChild;
if (active.style.display == 'none') {
active = active.nextSibling;
}
active.classList.add('active');
updateActiveCard(active);
}
if (!active.link) active._initLink();
rightPane.appendChild(active.link);
(function () {
if (connectMenu) return;
var page = ui.create.div('.menu-buttons');
var node = ui.create.div('.menubutton.large', '牌堆', clickMode);
start.firstChild.insertBefore(node, start.firstChild.querySelector('.lefttext'));
node.link = page;
node.mode = 'cardpile';
node.create = function () {
if (pileCreated) return;
pileCreated = true;
page.innerHTML = '';
var pileList = null;
var createList = function () {
if (pileList) {
pileList.remove();
}
var list = ['默认牌堆'];
if (lib.config.customcardpile['当前牌堆']) {
list.push('当前牌堆');
}
for (var i in lib.config.customcardpile) {
list.add(i);
}
var currentpile = get.config('cardpilename');
if (!currentpile) {
if (list.includes('当前牌堆')) {
currentpile = '当前牌堆';
}
else {
currentpile = '默认牌堆';
}
}
pileList = ui.create.selectlist(list, currentpile, pileChoose, function (e) {
game.saveConfig('cardpilename', this.value, true);
restart.style.display = '';
});
pileList.style.float = 'right';
};
var pileChoose = ui.create.div('.config.toggle.cardpilecfg.nomarginleft', '选择牌堆', page);
createList();
var pileDel = function () {
delete lib.config.customcardpile[this.parentNode.link];
this.parentNode.remove();
game.saveConfig('customcardpile', lib.config.customcardpile);
for (var i in lib.config.mode_config) {
if (i == 'global') continue;
if (lib.config.mode_config[i].cardpilename == this.parentNode.link) {
game.saveConfig('cardpilename', null, i);
}
}
createList();
};
var restart = ui.create.div('.config.more', '重新启动', game.reload, page);
restart.style.display = 'none';
var createPileNode = function (name) {
var node = ui.create.div('.config.toggle.cardpilecfg.nomarginleft', name);
node.link = name;
var del = document.createElement('span');
del.innerHTML = '删除';
del.classList.add('cardpiledelete');
del.onclick = pileDel;
node.appendChild(del);
if (name == '当前牌堆') {
page.insertBefore(node, pileChoose.nextSibling);
}
else {
page.insertBefore(node, restart);
}
};
for (var i in lib.config.customcardpile) {
createPileNode(i);
}
var exportCardPile;
ui.create.div('.config.more', '保存当前牌堆 <div>&gt;</div>', page, function () {
this.classList.toggle('on');
if (this.classList.contains('on')) {
exportCardPile.classList.remove('hidden');
}
else {
exportCardPile.classList.add('hidden');
}
});
exportCardPile = ui.create.div('.config.cardpileadd.indent', page);
exportCardPile.classList.add('hidden');
ui.create.div('', '名称:<input type="text"><button>确定</button>', exportCardPile);
var input = exportCardPile.firstChild.lastChild.previousSibling;
input.value = '自定义牌堆';
input.style.marginRight = '3px';
input.style.width = '120px';
exportCardPile.firstChild.lastChild.onclick = function () {
var name = input.value;
var ok = true;
if (lib.config.customcardpile[name] || name == '默认牌堆' || name == '当前牌堆') {
for (var i = 1; i <= 1000; i++) {
if (!lib.config.customcardpile[name + '(' + i + ')']) {
name = name + '(' + i + ')';
break;
}
}
}
lib.config.customcardpile[name] = [lib.config.bannedpile, lib.config.addedpile];
delete lib.config.customcardpile['当前牌堆'];
for (var i in lib.mode) {
if (lib.config.mode_config[i] &&
(lib.config.mode_config[i].cardpilename == '当前牌堆' || !lib.config.mode_config[i].cardpilename)) {
game.saveConfig('cardpilename', name, i);
}
}
for (var i = 0; i < page.childElementCount; i++) {
if (page.childNodes[i].link == '当前牌堆') {
page.childNodes[i].remove();
break;
}
}
game.saveConfig('customcardpile', lib.config.customcardpile);
createPileNode(name);
createList();
};
};
}());
if (!connectMenu) {
// 下面使用了var的特性请不要在这里直接改为let
var node1 = ui.create.div('.lefttext', '全部开启', start.firstChild, function () {
game.saveConfig('cards', lib.config.all.cards);
updateNodes();
});
var node2 = ui.create.div('.lefttext', '恢复默认', start.firstChild, function () {
game.saveConfig('cards', lib.config.defaultcards);
updateNodes();
});
node1.style.marginTop = '12px';
node2.style.marginTop = '7px';
}
updateNodes();
/**
* 在菜单栏初始化完成后如果又加载了武将包进行刷新
*
* @param { string } packName
*/
return function (packName) {
// 判断菜单栏有没有加载过这个卡牌包
if ([...start.firstChild.children].map(node => node.mode).includes(packName)) return;
// 单机模式下显示不在lib.config.all.cards里的卡牌包
if (!lib.config.all.cards.includes(packName)) createModeConfig(packName, start.firstChild);
if (connectMenu) lib.connectCardPack.add(packName);
}
};

View File

@ -0,0 +1,528 @@
import {
menuContainer,
popupContainer,
updateActive,
setUpdateActive,
updateActiveCard,
setUpdateActiveCard,
menux,
menuxpages,
menuUpdates,
openMenu,
clickToggle,
clickSwitcher,
clickContainer,
clickMenuItem,
createMenu,
createConfig
} from "../index.js";
import { ui, game, get, lib, _status } from "../../../../../noname.js";
export const characterPackMenu = function (connectMenu) {
/**
* 由于联机模式会创建第二个菜单所以需要缓存一下可变的变量
*/
// const cacheMenuContainer = menuContainer;
// const cachePopupContainer = popupContainer;
const cacheMenux = menux;
const cacheMenuxpages = menuxpages;
/** @type { HTMLDivElement } */
// @ts-ignore
var start = cacheMenuxpages.shift();
// 用于切换显示对应武将包所有武将的界面
var rightPane = start.lastChild;
var clickMode = function () {
var active = this.parentNode.querySelector('.active');
if (active) {
if (active === this) {
return;
}
active.classList.remove('active');
active.link.remove();
}
this.classList.add('active');
updateActive(this);
if (this.link) rightPane.appendChild(this.link);
else {
this._initLink();
rightPane.appendChild(this.link);
}
};
setUpdateActive(function (node) {
if (!node) {
node = start.firstChild.querySelector('.active');
if (!node) {
return;
}
}
if (!node.link) {
node._initLink();
}
for (var i = 0; i < node.link.childElementCount; i++) {
if (node.link.childNodes[i].updateBanned) {
node.link.childNodes[i].updateBanned();
}
}
});
var updateNodes = function () {
for (var i = 0; i < start.firstChild.childNodes.length; i++) {
var node = start.firstChild.childNodes[i];
if (node.mode) {
if (node.mode.startsWith('mode_')) {
// 扩展武将包开启逻辑
if (node.mode.startsWith('mode_extension')) {
const extName = node.mode.slice(15);
if (!game.hasExtension(extName) || !game.hasExtensionLoaded(extName)) continue;
if (lib.config[`extension_${extName}_characters_enable`] == true) {
node.classList.remove('off');
if (node.link) node.link.firstChild.classList.add('on');
}
else {
node.classList.add('off');
if (node.link) node.link.firstChild.classList.remove('on');
}
}
continue;
}
if (node.mode == 'custom') continue;
if (connectMenu) {
if (!lib.config.connect_characters.includes(node.mode)) {
node.classList.remove('off');
if (node.link) node.link.firstChild.classList.add('on');
}
else {
node.classList.add('off');
if (node.link) node.link.firstChild.classList.remove('on');
}
}
else {
if (lib.config.characters.includes(node.mode)) {
node.classList.remove('off');
if (node.link) node.link.firstChild.classList.add('on');
}
else {
node.classList.add('off');
if (node.link) node.link.firstChild.classList.remove('on');
}
}
}
}
};
var togglePack = function (bool) {
var name = this._link.config._name;
// 扩展武将包开启逻辑
if (name.startsWith('mode_extension')) {
const extName = name.slice(15);
if (!game.hasExtension(extName) || !game.hasExtensionLoaded(extName)) return false;
game.saveExtensionConfig(extName, 'characters_enable', bool);
}
// 原逻辑
else {
if (connectMenu) {
if (!bool) {
lib.config.connect_characters.add(name);
}
else {
lib.config.connect_characters.remove(name);
}
game.saveConfig('connect_characters', lib.config.connect_characters);
}
else {
if (bool) {
lib.config.characters.add(name);
}
else {
lib.config.characters.remove(name);
}
game.saveConfig('characters', lib.config.characters);
}
}
updateNodes();
};
var createModeConfig = function (mode, position, position2) {
var _info = lib.characterPack[mode];
var page = ui.create.div('');
var node = ui.create.div('.menubutton.large', lib.translate[mode + '_character_config'], position, clickMode);
if (node.innerHTML.length >= 5) {
node.classList.add('smallfont');
}
if (position2) {
position.insertBefore(node, position2);
}
node.mode = mode;
node._initLink = function () {
node.link = page;
page.node = node;
var list = [];
var boolAI = true;
var alterableSkills = [];
var alterableCharacters = [];
var charactersToAlter = [];
for (var i in _info) {
if (_info[i][4] && _info[i][4].includes('unseen')) continue;
if (connectMenu && lib.connectBanned.includes(i)) continue;
list.push(i);
if (boolAI && !lib.config.forbidai_user.includes(i)) boolAI = false;
for (var j = 0; j < _info[i][3].length; j++) {
if (!lib.skill[_info[i][3][j]]) {
continue;
}
if (lib.skill[_info[i][3][j]].alter) {
alterableSkills.add(_info[i][3][j]);
alterableCharacters.add(i);
if (lib.config.vintageSkills.includes(_info[i][3][j])) {
charactersToAlter.add(i);
}
}
}
}
alterableCharacters.sort();
list.sort(lib.sort.character);
var list2 = list.slice(0);
var cfgnode = createConfig({
name: '开启',
_name: mode,
init: (() => {
// 扩展武将包开启逻辑
if (mode.startsWith('mode_extension')) {
const extName = mode.slice(15);
if (!game.hasExtension(extName) || !game.hasExtensionLoaded(extName)) return false;
// 这块或许应该在加载扩展时候写
if (lib.config[`extension_${extName}_characters_enable`] === undefined) {
game.saveExtensionConfig(extName, 'characters_enable', true);
}
return lib.config[`extension_${extName}_characters_enable`] === true;
}
// 原逻辑
else {
return connectMenu ? (!lib.config.connect_characters.includes(mode)) : (lib.config.characters.includes(mode));
}
})(),
onclick: togglePack
});
var cfgnodeAI = createConfig({
name: '仅点将可用',
_name: mode,
init: boolAI,
intro: '将该武将包内的武将全部设置为仅点将可用',
onclick(bool) {
if (bool) {
for (var i = 0; i < list.length; i++) {
lib.config.forbidai_user.add(list[i]);
}
}
else {
for (var i = 0; i < list.length; i++) {
lib.config.forbidai_user.remove(list[i]);
}
}
game.saveConfig('forbidai_user', lib.config.forbidai_user);
},
});
if (!mode.startsWith('mode_')) {
cfgnodeAI.style.marginTop = '0px';
page.appendChild(cfgnode);
page.appendChild(cfgnodeAI);
if (alterableCharacters.length) {
var cfgnode2 = createConfig({
name: '新版替换',
_name: mode,
init: charactersToAlter.length == 0,
intro: '以下武将将被修改:' + get.translation(alterableCharacters),
onclick(bool) {
if (bool) {
for (var i = 0; i < alterableSkills.length; i++) {
lib.config.vintageSkills.remove(alterableSkills[i]);
lib.translate[alterableSkills[i] + '_info'] = lib.translate[alterableSkills[i] + '_info_alter'];
}
}
else {
for (var i = 0; i < alterableSkills.length; i++) {
lib.config.vintageSkills.add(alterableSkills[i]);
lib.translate[alterableSkills[i] + '_info'] = lib.translate[alterableSkills[i] + '_info_origin'];
}
}
game.saveConfig('vintageSkills', lib.config.vintageSkills);
}
});
cfgnode2.style.marginTop = '0px';
page.appendChild(cfgnode2);
}
}
else if (mode.startsWith('mode_extension')) {
// 排除4个基本扩展
// 再排除那个boss扩展的间隔包
// 给扩展的武将包加一个开启关闭的功能
if (!lib.config.all.stockextension.includes(mode.slice(15)) && mode != 'mode_extension_jiange') {
page.appendChild(cfgnode);
}
page.appendChild(cfgnodeAI);
}
else {
page.style.paddingTop = '8px';
}
var banCharacter = function (e) {
if (_status.clicked) {
_status.clicked = false;
return;
}
if (mode.startsWith('mode_') && !mode.startsWith('mode_extension_') &&
mode != 'mode_favourite' && mode != 'mode_banned') {
if (!connectMenu && lib.config.show_charactercard) {
ui.click.charactercard(this.link, this, mode == 'mode_guozhan' ? 'guozhan' : true);
}
return;
}
ui.click.touchpop();
this._banning = connectMenu ? 'online' : 'offline';
if (!connectMenu && lib.config.show_charactercard) {
ui.click.charactercard(this.link, this);
}
else {
ui.click.intro.call(this, e);
}
_status.clicked = false;
delete this._banning;
};
var updateBanned = function () {
var _list;
if (connectMenu) {
var mode = cacheMenux.pages[0].firstChild.querySelector('.active');
if (mode && mode.mode) {
_list = lib.config['connect_' + mode.mode + '_banned'];
}
}
else {
_list = lib.config[get.mode() + '_banned'];
}
if (_list && _list.includes(this.link)) {
this.classList.add('banned');
}
else {
this.classList.remove('banned');
}
};
if (lib.characterSort[mode]) {
var listb = [];
if (!connectMenu) {
listb = lib.config[get.mode() + '_banned'] || [];
}
else {
var modex = cacheMenux.pages[0].firstChild.querySelector('.active');
if (modex && modex.mode) {
listb = lib.config['connect_' + modex.mode + '_banned'];
}
}
for (var pak in lib.characterSort[mode]) {
var info = lib.characterSort[mode][pak];
var listx = [];
var boolx = false;
for (var ii = 0; ii < list2.length; ii++) {
if (info.includes(list2[ii])) {
listx.add(list2[ii]);
if (!listb.includes(list2[ii])) boolx = true;
list2.splice(ii--, 1);
}
}
if (listx.length) {
var cfgnodeY = {
name: lib.translate[pak],
_name: pak,
init: boolx,
onclick(bool) {
var banned = [];
if (connectMenu) {
var modex = cacheMenux.pages[0].firstChild.querySelector('.active');
if (modex && modex.mode) {
banned = lib.config['connect_' + modex.mode + '_banned'];
}
}
else if (_status.connectMode) return;
else banned = lib.config[get.mode() + '_banned'] || [];
var listx = lib.characterSort[mode][this._link.config._name];
if (bool) {
for (var i = 0; i < listx.length; i++) {
banned.remove(listx[i]);
}
}
else {
for (var i = 0; i < listx.length; i++) {
banned.add(listx[i]);
}
}
game.saveConfig(connectMenu ? ('connect_' + modex.mode + '_banned') : (get.mode() + '_banned'), banned);
updateActive();
},
};
if (mode.startsWith('mode_') && !mode.startsWith('mode_extension_') && !mode.startsWith('mode_guozhan')) {
cfgnodeY.clear = true;
delete cfgnodeY.onclick;
}
var cfgnodeX = createConfig(cfgnodeY);
page.appendChild(cfgnodeX);
var buttons = ui.create.buttons(listx, 'character', page);
for (var i = 0; i < buttons.length; i++) {
buttons[i].classList.add('noclick');
buttons[i].listen(banCharacter);
ui.create.rarity(buttons[i]);
buttons[i].node.hp.style.transition = 'all 0s';
buttons[i].node.hp._innerHTML = buttons[i].node.hp.innerHTML;
if (mode != 'mode_banned') {
buttons[i].updateBanned = updateBanned;
}
}
}
}
if (list2.length) {
var cfgnodeX = createConfig({
name: '其他',
_name: 'others',
clear: true,
});
page.appendChild(cfgnodeX);
var buttons = ui.create.buttons(list2, 'character', page);
for (var i = 0; i < buttons.length; i++) {
buttons[i].classList.add('noclick');
buttons[i].listen(banCharacter);
ui.create.rarity(buttons[i]);
buttons[i].node.hp.style.transition = 'all 0s';
buttons[i].node.hp._innerHTML = buttons[i].node.hp.innerHTML;
if (mode != 'mode_banned') {
buttons[i].updateBanned = updateBanned;
}
}
}
}
else {
var buttons = ui.create.buttons(list, 'character', page);
for (var i = 0; i < buttons.length; i++) {
buttons[i].classList.add('noclick');
ui.create.rarity(buttons[i]);
buttons[i].listen(banCharacter);
buttons[i].node.hp.style.transition = 'all 0s';
buttons[i].node.hp._innerHTML = buttons[i].node.hp.innerHTML;
if (mode != 'mode_banned') {
buttons[i].updateBanned = updateBanned;
}
}
}
page.classList.add('menu-buttons');
page.classList.add('leftbutton');
if (!connectMenu) {
if (lib.config.all.sgscharacters.includes(mode)) {
ui.create.div('.config.pointerspan', '<span style="opacity:0.5">该武将包不可被隐藏</span>', page);
}
else if (!mode.startsWith('mode_')) {
ui.create.div('.config.pointerspan', '<span>隐藏武将包</span>', page, function () {
if (this.firstChild.innerHTML == '隐藏武将包') {
if (confirm('真的要隐藏“' + get.translation(mode + '_character_config') + '”武将包吗?\n建议使用“关闭”而不是“隐藏”功能否则将会影响其他相关武将包的正常运行')) {
this.firstChild.innerHTML = '武将包将在重启后隐藏';
lib.config.hiddenCharacterPack.add(mode);
if (!lib.config.prompt_hidepack) {
alert('隐藏的扩展包可通过选项-其它-重置隐藏内容恢复');
game.saveConfig('prompt_hidepack', true);
}
}
}
else {
this.firstChild.innerHTML = '隐藏武将包';
lib.config.hiddenCharacterPack.remove(mode);
}
game.saveConfig('hiddenCharacterPack', lib.config.hiddenCharacterPack);
});
}
}
};
if (!get.config('menu_loadondemand')) node._initLink();
return node;
};
if (lib.config.show_favourite_menu && !connectMenu && Array.isArray(lib.config.favouriteCharacter)) {
lib.characterPack.mode_favourite = {};
for (var i = 0; i < lib.config.favouriteCharacter.length; i++) {
var favname = lib.config.favouriteCharacter[i];
if (lib.character[favname]) {
lib.characterPack.mode_favourite[favname] = lib.character[favname];
}
}
var favouriteCharacterNode = createModeConfig('mode_favourite', start.firstChild);
if (!favouriteCharacterNode.link) favouriteCharacterNode._initLink();
ui.favouriteCharacter = favouriteCharacterNode.link;
if (get.is.empty(lib.characterPack.mode_favourite)) {
ui.favouriteCharacter.node.style.display = 'none';
}
delete lib.characterPack.mode_favourite;
}
if (!connectMenu && lib.config.show_ban_menu) {
lib.characterPack.mode_banned = {};
for (var i = 0; i < lib.config.all.mode.length; i++) {
var banned = lib.config[lib.config.all.mode[i] + '_banned'];
if (banned) {
for (var j = 0; j < banned.length; j++) {
if (lib.character[banned[j]]) {
lib.characterPack.mode_banned[banned[j]] = lib.character[banned[j]];
}
}
}
}
var bannednode = createModeConfig('mode_banned', start.firstChild);
if (get.is.empty(lib.characterPack.mode_banned)) {
bannednode.style.display = 'none';
}
delete lib.characterPack.mode_banned;
}
var characterlist = connectMenu ? lib.connectCharacterPack : lib.config.all.characters;
for (var i = 0; i < characterlist.length; i++) {
createModeConfig(characterlist[i], start.firstChild);
}
if (!connectMenu) Object.keys(lib.characterPack).forEach(key => {
// 单机模式下显示不在lib.config.all.characters里的武将包
if (!characterlist.includes(key)) createModeConfig(key, start.firstChild);
if (connectMenu) lib.connectCharacterPack.add(key);
});
var active = start.firstChild.querySelector('.active');
if (!active) {
active = start.firstChild.firstChild;
if (active.style.display == 'none') {
active = active.nextSibling;
if (active.style.display == 'none') {
active = active.nextSibling;
}
}
active.classList.add('active');
updateActive(active);
}
if (!active.link) active._initLink();
rightPane.appendChild(active.link);
if (!connectMenu) {
// 下面使用了var的特性请不要在这里直接改为let
var node1 = ui.create.div('.lefttext', '全部开启', start.firstChild, function () {
game.saveConfig('characters', lib.config.all.characters);
updateNodes();
});
var node2 = ui.create.div('.lefttext', '恢复默认', start.firstChild, function () {
game.saveConfig('characters', lib.config.defaultcharacters);
updateNodes();
});
node1.style.marginTop = '12px';
node2.style.marginTop = '7px';
}
updateNodes();
/**
* 在菜单栏初始化完成后如果又加载了武将包进行刷新
*
* @param { string } packName
*/
return function (packName) {
// 判断菜单栏有没有加载过这个武将包
if ([...start.firstChild.children].map(node => node.mode).includes(packName)) return;
// 单机模式下显示不在lib.config.all.characters里的武将包
if (!characterlist.includes(packName)) createModeConfig(packName, start.firstChild, node1);
if (connectMenu) lib.connectCharacterPack.add(packName);
}
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,397 @@
import {
menuContainer,
popupContainer,
updateActive,
setUpdateActive,
updateActiveCard,
setUpdateActiveCard,
menux,
menuxpages,
menuUpdates,
openMenu,
clickToggle,
clickSwitcher,
clickContainer,
clickMenuItem,
createMenu,
createConfig
} from "../index.js";
import { ui, game, get, lib, _status } from "../../../../../noname.js";
export const startMenu = function (connectMenu) {
/**
* 由于联机模式会创建第二个菜单所以需要缓存一下可变的变量
*/
const cacheMenuContainer = menuContainer;
// const cachePopupContainer = popupContainer;
// const cacheMenux = menux;
const cacheMenuxpages = menuxpages;
/** @type { HTMLDivElement } */
// @ts-ignore
var start = cacheMenuxpages.shift();
var rightPane = start.lastChild;
/** 启动按钮 */
let startButton = ui.create.div('.menubutton.round.highlight', '启', start, function () {
if (this.animating || this.classList.contains('dim')) {
return;
}
var active = this.parentNode.querySelector('.active');
if (active) {
if (connectMenu) {
if (_status.waitingForPlayer) {
var config = {};
for (var i in lib.mode[lib.configOL.mode].connect) {
if (i == 'update') continue;
config[i.slice(8)] = get.config(i, lib.configOL.mode);
}
config.zhinang_tricks = lib.config.connect_zhinang_tricks;
if (game.online) {
if (game.onlinezhu) {
game.send('changeRoomConfig', config);
}
}
else {
game.broadcastAll(function (config) {
for (var i in config) {
lib.configOL[i] = config[i];
}
}, config);
if (lib.configOL.mode == 'identity' && lib.configOL.identity_mode == 'zhong' && game.connectPlayers) {
for (var i = 0; i < game.connectPlayers.length; i++) {
game.connectPlayers[i].classList.remove('unselectable2');
}
lib.configOL.number = 8;
game.updateWaiting();
}
if (game.onlineroom) {
game.send('server', 'config', lib.configOL);
}
game.connectPlayers[0].chat('房间设置已更改');
}
}
else if (_status.enteringroom || _status.creatingroom) {
lib.configOL.mode = active.mode;
if (_status.enteringroomserver) {
game.saveConfig('connect_mode', lib.configOL.mode);
var config = {};
for (var i in lib.mode[lib.configOL.mode].connect) {
if (i == 'update') continue;
config[i.slice(8)] = get.config(i, lib.configOL.mode);
}
config.zhinang_tricks = lib.config.connect_zhinang_tricks;
config.characterPack = lib.connectCharacterPack.slice(0);
config.cardPack = lib.connectCardPack.slice(0);
for (var i = 0; i < lib.config.connect_characters.length; i++) {
config.characterPack.remove(lib.config.connect_characters[i]);
}
for (var i = 0; i < lib.config.connect_cards.length; i++) {
config.cardPack.remove(lib.config.connect_cards[i]);
}
config.banned = lib.config['connect_' + active.mode + '_banned'];
config.bannedcards = lib.config['connect_' + active.mode + '_bannedcards'];
game.send('server', 'create', game.onlineKey, get.connectNickname(), lib.config.connect_avatar, config, active.mode);
}
else {
game.send('server', 'create', game.onlineKey, get.connectNickname(), lib.config.connect_avatar);
}
}
else {
localStorage.setItem(lib.configprefix + 'directstart', true);
game.saveConfig('directstartmode', active.mode);
game.saveConfig('mode', 'connect');
ui.exitroom = ui.create.system('退出房间', function () {
game.saveConfig('directstartmode');
game.reload();
}, true);
game.switchMode(active.mode);
}
clickContainer.call(cacheMenuContainer, connectMenu);
}
else {
game.saveConfig('mode', active.mode);
localStorage.setItem(lib.configprefix + 'directstart', true);
game.reload();
}
}
});
var clickMode = function () {
if (this.classList.contains('unselectable')) return;
var active = this.parentNode.querySelector('.active');
if (active === this) {
return;
}
active.classList.remove('active');
active.link.remove();
active = this;
this.classList.add('active');
if (this.link) rightPane.appendChild(this.link);
else {
this._initLink();
rightPane.appendChild(this.link);
}
if (connectMenu) {
if (updateActive) updateActive();
if (updateActiveCard) updateActiveCard();
}
};
var createModeConfig = function (mode, position) {
var info = lib.mode[mode];
var page = ui.create.div('');
var node = ui.create.div('.menubutton.large', info.name, position, clickMode);
node.mode = mode;
var connectDisplayMap = {
connect_player_number: null,
connect_versus_mode: null,
};
var updateConnectDisplayMap = function () {
if (_status.waitingForPlayer) {
if (connectDisplayMap.connect_player_number) {
connectDisplayMap.connect_player_number.style.display = 'none';
}
if (connectDisplayMap.connect_versus_mode) {
connectDisplayMap.connect_versus_mode.style.display = 'none';
}
}
};
if (connectMenu) {
menuUpdates.push(updateConnectDisplayMap);
if (mode == lib.config.connect_mode) {
node.classList.add('active');
}
}
else {
if (mode == lib.config.mode) {
node.classList.add('active');
}
}
node._initLink = function () {
node.link = page;
//“更多”下的内容
var map = {};
var infoconfig = connectMenu ? info.connect : info.config;
if (infoconfig) {
var hiddenNodes = [];
var config = lib.config.mode_config[mode] || {};
if (connectMenu) {
infoconfig.connect_choose_timeout = {
name: '出牌时限',
init: '30',
item: {
'10': '10秒',
'15': '15秒',
'30': '30秒',
'60': '60秒',
'90': '90秒',
},
connect: true,
frequent: true
};
infoconfig.connect_observe = {
name: '允许旁观',
init: true,
connect: true
};
infoconfig.connect_observe_handcard = {
name: '允许观看手牌',
init: false,
connect: true
};
infoconfig.connect_mount_combine = {
name: '合并坐骑栏',
init: false,
connect: true
};
}
for (var j in infoconfig) {
if (j === 'update') {
continue;
}
var cfg = get.copy(infoconfig[j]);
cfg._name = j;
cfg.mode = mode;
if (j in config) {
cfg.init = config[j];
}
else {
game.saveConfig(j, cfg.init, mode);
}
if (!cfg.onclick) {
cfg.onclick = function (result) {
var cfg = this._link.config;
game.saveConfig(cfg._name, result, mode);
if (cfg.onsave) {
cfg.onsave.call(this, result);
}
if (!_status.connectMode || game.online) {
if (typeof cfg.restart == 'function') {
if (cfg.restart()) {
startButton.classList.add('glowing');
}
}
else if (cfg.restart) {
startButton.classList.add('glowing');
}
}
};
}
if (infoconfig.update) {
cfg.update = function () {
infoconfig.update(config, map);
};
}
var cfgnode = createConfig(cfg);
map[j] = cfgnode;
if (cfg.frequent) {
page.appendChild(cfgnode);
}
else {
cfgnode.classList.add('auto-hide');
hiddenNodes.push(cfgnode);
}
}
if (!connectMenu) {
var move = ui.create.div('.auto-hide.config', '<div style="margin-right:10px" class="pointerdiv">上移↑</div><div class="pointerdiv">下移↓</div>');
move.firstChild.listen(function () {
if (node.previousSibling) {
node.parentNode.insertBefore(node, node.previousSibling);
var order = [];
for (var i = 0; i < node.parentNode.childNodes.length; i++) {
order.push(node.parentNode.childNodes[i].mode);
}
game.saveConfig('modeorder', order);
}
});
move.lastChild.listen(function () {
if (node.nextSibling) {
if (node.nextSibling.nextSibling) {
node.parentNode.insertBefore(node, node.nextSibling.nextSibling);
}
else {
node.parentNode.insertBefore(node.nextSibling, node);
}
var order = [];
for (var i = 0; i < node.parentNode.childNodes.length; i++) {
order.push(node.parentNode.childNodes[i].mode);
}
game.saveConfig('modeorder', order);
}
});
hiddenNodes.push(move);
}
var expanded = false;
var hasexpand = true;
if (hiddenNodes.length) {
if (lib.config.fold_mode) {
var clickmore = function (type) {
if (type === 'expand' && expanded) return;
if (type === 'unexpand' && !expanded) return;
if (expanded) {
this.classList.remove('on');
this.parentNode.classList.remove('expanded');
}
else {
this.classList.add('on');
this.parentNode.classList.add('expanded');
}
expanded = !expanded;
};
var morenodes = ui.create.div('.config.more', '更多 <div>&gt;</div>', page);
morenodes.listen(clickmore);
morenodes._onclick = clickmore;
page.morenodes = morenodes;
}
else {
page.classList.add('expanded');
if (!connectMenu) {
page.classList.add('expanded2');
}
}
for (var k = 0; k < hiddenNodes.length; k++) {
page.appendChild(hiddenNodes[k]);
}
}
else {
hasexpand = false;
}
if (!connectMenu) {
var hidemode = ui.create.div('.config.pointerspan', '<span>隐藏此模式</span>', page, function () {
if (this.firstChild.innerHTML == '隐藏此模式') {
this.firstChild.innerHTML = '此模式将在重启后隐藏';
lib.config.hiddenModePack.add(mode);
if (!lib.config.prompt_hidepack) {
alert('隐藏的扩展包可通过选项-其它-重置隐藏内容恢复');
game.saveConfig('prompt_hidepack', true);
}
}
else {
this.firstChild.innerHTML = '隐藏此模式';
lib.config.hiddenModePack.remove(mode);
}
game.saveConfig('hiddenModePack', lib.config.hiddenModePack);
});
if (hasexpand) {
hidemode.classList.add('auto-hide');
}
}
if (infoconfig.update) {
infoconfig.update(config, map);
node.update = function () {
infoconfig.update(config, map);
};
}
}
if (connectMenu) {
connectDisplayMap.connect_player_number = map.connect_player_number;
connectDisplayMap.connect_versus_mode = map.connect_versus_mode;
updateConnectDisplayMap();
}
};
if (!get.config('menu_loadondemand')) node._initLink();
return node;
};
var modeorder = lib.config.modeorder || [];
for (var i in lib.mode) {
modeorder.add(i);
}
for (var i = 0; i < modeorder.length; i++) {
if (connectMenu) {
if (!lib.mode[modeorder[i]].connect) continue;
if (!lib.config['connect_' + modeorder[i] + '_banned']) {
lib.config['connect_' + modeorder[i] + '_banned'] = [];
}
if (!lib.config['connect_' + modeorder[i] + '_bannedcards']) {
lib.config['connect_' + modeorder[i] + '_bannedcards'] = [];
}
}
if (lib.config.all.mode.includes(modeorder[i])) {
createModeConfig(modeorder[i], start.firstChild);
}
}
var active = start.firstChild.querySelector('.active');
if (!active) {
active = start.firstChild.firstChild;
active.classList.add('active');
}
if (!active.link) active._initLink();
rightPane.appendChild(active.link);
if (lib.config.fold_mode) {
rightPane.addEventListener('mousewheel', function (e) {
var morenodes = this.firstChild.morenodes;
if (morenodes) {
if (e.wheelDelta < 0) {
morenodes._onclick.call(morenodes, 'expand');
}
else if (this.scrollTop == 0) {
morenodes._onclick.call(morenodes, 'unexpand');
}
}
}, { passive: true });
}
return startButton;
};

File diff suppressed because it is too large Load Diff