From bab0c7b4475298e00a4cec9fd2db64c8a8582c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 6 Nov 2024 19:04:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=87=E6=8D=A2=E5=9C=B0?= =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 5 ++++ src/env.ts | 2 +- src/mainMenu/mainMenu.ts | 2 ++ src/mainMenu/pages/mapManager.ts | 41 ++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/mainMenu/pages/mapManager.ts diff --git a/package.json b/package.json index d1159a1..05ddbb7 100644 --- a/package.json +++ b/package.json @@ -384,6 +384,11 @@ "title": "打开插件", "enablement": "viewItem == 插件", "category": "Y3开发助手" + }, + { + "command": "y3-helper.changeMap", + "title": "切换地图", + "category": "Y3开发助手" } ], "configuration": { diff --git a/src/env.ts b/src/env.ts index 0f7b28c..2164196 100644 --- a/src/env.ts +++ b/src/env.ts @@ -387,7 +387,7 @@ class Env { await this.updateEditor(askUser); } - private updateCurrentMap(map: Map) { + public updateCurrentMap(map: Map) { if (this.currentMap === map) { return; } diff --git a/src/mainMenu/mainMenu.ts b/src/mainMenu/mainMenu.ts index 67897ed..a22d0eb 100644 --- a/src/mainMenu/mainMenu.ts +++ b/src/mainMenu/mainMenu.ts @@ -9,6 +9,7 @@ import { 自定义事件 } from './pages/events'; import { 界面 } from './pages/ui'; import { 时间轴动画 } from './pages/uiAnim'; import { 插件 } from './pages/plugin'; +import { 地图管理 } from './pages/mapManager'; import { 跳字 } from './pages/jumpword'; import { 字体 } from './pages/font'; @@ -31,6 +32,7 @@ let mainNode = new TreeNode('主菜单', { ] }), new 插件, + new 地图管理, new 环境, new TreeNode('重新选择Y3地图路径', { command: { diff --git a/src/mainMenu/pages/mapManager.ts b/src/mainMenu/pages/mapManager.ts new file mode 100644 index 0000000..762866c --- /dev/null +++ b/src/mainMenu/pages/mapManager.ts @@ -0,0 +1,41 @@ +import { TreeNode } from "../treeNode"; +import * as vscode from 'vscode'; +import { env } from "../../env"; + +export class 地图管理 extends TreeNode { + constructor() { + super('地图管理', { + iconPath: new vscode.ThemeIcon('repo-clone'), + + update: async (node) => { + await env.mapReady(); + let entryMap = env.project?.entryMap; + let currentMap = env.currentMap; + node.childs = env.project?.maps.map(map => { + return new TreeNode(map.name, { + iconPath: map === entryMap ? new vscode.ThemeIcon('star-full') : new vscode.ThemeIcon('star-empty'), + description: map === currentMap ? '当前地图' : undefined, + tooltip: `id: ${String(map.id)}\n\n点击切换至此地图`, + command: { + command: "y3-helper.changeMap", + title: "切换地图", + arguments: [map.name], + } + }); + }); + }, + }); + + env.onDidChange(() => { + this.refresh(); + }); + } +}; + +vscode.commands.registerCommand('y3-helper.changeMap', async (name: string) => { + let map = env.project?.maps.find(map => map.name === name); + if (!map) { + return; + } + env.updateCurrentMap(map); +});