mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-26 11:34:30 +08:00
道具栏
This commit is contained in:
1 parent
c29a958689
commit
9b2c56f829
25 files changed
+3088
-3265
No files matched your search
@@ -1,56 +1,78 @@
|
||||
<template>
|
||||
<canvas
|
||||
ref="canvas"
|
||||
:width="width ?? 32"
|
||||
:height="height ?? 32"
|
||||
id="canvas"
|
||||
:id="`box-animate-${id}`"
|
||||
></canvas>
|
||||
</template>
|
||||
|
||||
<script lang="tsx" setup>
|
||||
import { onMounted, onUnmounted, ref } from 'vue';
|
||||
import { onMounted, onUnmounted, onUpdated, ref } from 'vue';
|
||||
import { addAnimate, removeAnimate } from '../plugin/animateController';
|
||||
import { has } from '../plugin/utils';
|
||||
|
||||
const id = (Math.random() * 1e8).toFixed(0);
|
||||
|
||||
const props = defineProps<{
|
||||
id: string;
|
||||
noborder?: boolean;
|
||||
width?: number;
|
||||
height?: number;
|
||||
}>();
|
||||
|
||||
const canvas = ref<HTMLCanvasElement>();
|
||||
let c: HTMLCanvasElement;
|
||||
let ctx: CanvasRenderingContext2D;
|
||||
|
||||
let drawFn: () => void;
|
||||
|
||||
function draw() {
|
||||
if (has(drawFn)) removeAnimate(drawFn);
|
||||
|
||||
onMounted(() => {
|
||||
const c = canvas.value!;
|
||||
const ctx = c.getContext('2d')!;
|
||||
const cls = core.getClsFromId(props.id);
|
||||
const frames = core.getAnimateFrames(cls);
|
||||
const w = props.width ?? 32;
|
||||
const h = props.height ?? 32;
|
||||
|
||||
if (!props.noborder) {
|
||||
c.style.border = '1.5px solid #ddd';
|
||||
c.style.backgroundColor = '#222';
|
||||
}
|
||||
|
||||
const scale = window.devicePixelRatio;
|
||||
|
||||
c.style.width = `${c.width}px`;
|
||||
c.style.height = `${c.height}px`;
|
||||
c.width *= scale;
|
||||
c.height *= scale;
|
||||
c.style.width = `${w}px`;
|
||||
c.style.height = `${h}px`;
|
||||
c.width = scale * w;
|
||||
c.height = scale * h;
|
||||
ctx.scale(scale, scale);
|
||||
|
||||
const fn = () => {
|
||||
core.clearMap(ctx);
|
||||
const frame = core.status.globalAnimateStatus % frames;
|
||||
core.drawIcon(ctx, props.id, 0, 0, props.width, props.height, frame);
|
||||
};
|
||||
if (frames === 1) {
|
||||
core.drawIcon(ctx, props.id, 0, 0, props.width, props.height);
|
||||
} else {
|
||||
drawFn = () => {
|
||||
core.clearMap(ctx);
|
||||
const frame = core.status.globalAnimateStatus % frames;
|
||||
core.drawIcon(ctx, props.id, 0, 0, w, h, frame);
|
||||
};
|
||||
|
||||
fn();
|
||||
addAnimate(fn);
|
||||
drawFn();
|
||||
addAnimate(drawFn);
|
||||
|
||||
onUnmounted(() => {
|
||||
removeAnimate(fn);
|
||||
});
|
||||
onUnmounted(() => {
|
||||
removeAnimate(drawFn);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
c = document.getElementById(`box-animate-${id}`) as HTMLCanvasElement;
|
||||
ctx = c.getContext('2d')!;
|
||||
draw();
|
||||
});
|
||||
|
||||
onUpdated(() => {
|
||||
draw();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
#canvas {
|
||||
border: 1.5px solid #ddd;
|
||||
background-color: #222;
|
||||
}
|
||||
</style>
|
||||
<style lang="less" scoped></style>
|
||||
+13
-12
@@ -11,12 +11,13 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, onUnmounted, onUpdated } from 'vue';
|
||||
import { cancelGlobalDrag, isMobile, useDrag, useWheel } from '../plugin/use';
|
||||
import { cancelGlobalDrag, useDrag, useWheel } from '../plugin/use';
|
||||
|
||||
const props = defineProps<{
|
||||
now?: number;
|
||||
type?: 'vertical' | 'horizontal';
|
||||
drag?: boolean;
|
||||
width?: number;
|
||||
}>();
|
||||
|
||||
const emits = defineEmits<{
|
||||
@@ -29,6 +30,7 @@ let total = 0;
|
||||
|
||||
const id = (1e8 * Math.random()).toFixed(0);
|
||||
const scale = window.devicePixelRatio;
|
||||
const width = props.width ?? 20;
|
||||
|
||||
const cssTarget = props.type === 'horizontal' ? 'left' : 'top';
|
||||
const canvasAttr = props.type === 'horizontal' ? 'width' : 'height';
|
||||
@@ -52,6 +54,8 @@ function draw() {
|
||||
} else if (now < 0) {
|
||||
now = 0;
|
||||
}
|
||||
const w = ctx.canvas.width;
|
||||
const h = ctx.canvas.height;
|
||||
emits('update:now', now);
|
||||
const length =
|
||||
Math.min(ctx.canvas[canvasAttr] / total / scale, 1) *
|
||||
@@ -61,14 +65,11 @@ function draw() {
|
||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
ctx.beginPath();
|
||||
if (props.type === 'horizontal') {
|
||||
ctx.moveTo(Math.max(py + 5, 5), 10 * scale);
|
||||
ctx.lineTo(Math.min(py + length - 5, ctx.canvas.width - 5), 10 * scale);
|
||||
ctx.moveTo(Math.max(py + 5, 5), h / 2);
|
||||
ctx.lineTo(Math.min(py + length - 5, ctx.canvas.width - 5), h / 2);
|
||||
} else {
|
||||
ctx.moveTo(10 * scale, Math.max(py + 5, 5));
|
||||
ctx.lineTo(
|
||||
10 * scale,
|
||||
Math.min(py + length - 5, ctx.canvas.height - 5)
|
||||
);
|
||||
ctx.moveTo(w / 2, Math.max(py + 5, 5));
|
||||
ctx.lineTo(w / 2, Math.min(py + length - 5, ctx.canvas.height - 5));
|
||||
}
|
||||
ctx.lineCap = 'round';
|
||||
ctx.lineWidth = 6;
|
||||
@@ -130,16 +131,17 @@ onMounted(() => {
|
||||
content.addEventListener('resize', resize);
|
||||
|
||||
const style = getComputedStyle(canvas);
|
||||
canvas.width = 20 * scale;
|
||||
canvas.style.width = `${width}px`;
|
||||
canvas.width = width * scale;
|
||||
canvas.height = parseFloat(style.height) * scale;
|
||||
|
||||
if (props.type === 'horizontal') {
|
||||
div.style.flexDirection = 'column';
|
||||
canvas.style.height = '40px';
|
||||
canvas.style.height = `${width}px`;
|
||||
canvas.style.width = '98%';
|
||||
canvas.style.margin = '0 1% 0 1%';
|
||||
canvas.width = parseFloat(style.width) * scale;
|
||||
canvas.height = 20 * scale;
|
||||
canvas.height = width * scale;
|
||||
}
|
||||
|
||||
draw();
|
||||
@@ -200,7 +202,6 @@ onUnmounted(() => {
|
||||
<style lang="less" scoped>
|
||||
.scroll {
|
||||
opacity: 0.2;
|
||||
width: 20px;
|
||||
transition: opacity 0.2s linear;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { getCriticalDamage, getDefDamage } from '../plugin/book';
|
||||
import { getCriticalDamage, getDefDamage } from '../plugin/ui/book';
|
||||
import Chart, { ChartConfiguration } from 'chart.js/auto';
|
||||
import { has, setCanvasSize } from '../plugin/utils';
|
||||
import { debounce } from 'lodash';
|
||||
@@ -147,11 +147,12 @@ function generateChart(ele: HTMLCanvasElement, data: [number, number][]) {
|
||||
* 生成图表数据
|
||||
* @param data 数据
|
||||
*/
|
||||
function generateData(data: [number, number][]) {
|
||||
function generateData(data: [number, number][]): ChartConfiguration['data'] {
|
||||
return {
|
||||
datasets: [
|
||||
{
|
||||
data: data.map(v => v[1])
|
||||
data: data.map(v => v[1]),
|
||||
label: '怪物伤害'
|
||||
}
|
||||
],
|
||||
labels: data.map(v => Math.round(v[0] / ratio))
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { isMobile } from '../plugin/use';
|
||||
import { getSpecialHint } from '../plugin/book';
|
||||
import { getSpecialHint } from '../plugin/ui/book';
|
||||
|
||||
const enemy = core.plugin.bookDetailEnemy;
|
||||
|
||||
|
||||
@@ -27,6 +27,6 @@ export function addAnimate(fn: (time: number) => void) {
|
||||
*/
|
||||
export function removeAnimate(fn: (time: number) => void) {
|
||||
const index = animation.findIndex(v => v === fn);
|
||||
if (index === -1)
|
||||
throw new ReferenceError('No such function in animation.');
|
||||
if (index === -1) return;
|
||||
animation.splice(index, 1);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { has } from './utils';
|
||||
import { has } from '../utils';
|
||||
|
||||
/**
|
||||
* 获取怪物的特殊技能描述
|
||||
@@ -64,10 +64,10 @@ export function getDefDamage(
|
||||
atk: core.status.hero.atk + addAtk
|
||||
});
|
||||
|
||||
if (i === 0) {
|
||||
if (res.length === 0) {
|
||||
origin = dam?.damage;
|
||||
if (has(origin)) {
|
||||
res.push([addDef, origin]);
|
||||
res.push([addDef + i * ratio, origin]);
|
||||
last = origin;
|
||||
}
|
||||
continue;
|
||||
@@ -0,0 +1,45 @@
|
||||
import { has } from '../utils';
|
||||
|
||||
interface ClsMap {
|
||||
tools: '消耗道具';
|
||||
constants: '永久道具';
|
||||
all: '全部道具';
|
||||
}
|
||||
|
||||
interface AllItem {
|
||||
tools: [string, number][];
|
||||
constants: [string, number][];
|
||||
}
|
||||
|
||||
const clsMap: ClsMap = {
|
||||
tools: '消耗道具',
|
||||
constants: '永久道具',
|
||||
all: '全部道具'
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据道具的cls获取中文类型
|
||||
* @param cls 道具的cls
|
||||
*/
|
||||
export function getClsName<T extends keyof ClsMap | 'all'>(cls: T): ClsMap[T] {
|
||||
return clsMap[cls];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个类型的所有道具
|
||||
* @param cls 道具类型
|
||||
*/
|
||||
export function getItems(cls: 'all'): AllItem;
|
||||
export function getItems(cls: keyof ClsMap): [string, number][];
|
||||
export function getItems(cls: keyof ClsMap | 'all') {
|
||||
const i = core.status.hero.items;
|
||||
if (cls === 'all') {
|
||||
return {
|
||||
tools: Object.entries(i.tools),
|
||||
constants: Object.entries(i.constants)
|
||||
};
|
||||
}
|
||||
const items = i[cls];
|
||||
const data = Object.entries(items);
|
||||
return data;
|
||||
}
|
||||
@@ -1,13 +1,20 @@
|
||||
import { sleep } from 'mutate-animate';
|
||||
import { Component, markRaw, ref, Ref, watch } from 'vue';
|
||||
import Book from '../ui/book.vue';
|
||||
import Toolbox from '../ui/toolbox.vue';
|
||||
|
||||
export const bookOpened = ref(false);
|
||||
export const toolOpened = ref(false);
|
||||
|
||||
export const transition = ref(true);
|
||||
|
||||
let app: HTMLDivElement;
|
||||
|
||||
/** ui声明列表 */
|
||||
const UI_LIST: [Ref<boolean>, Component][] = [[bookOpened, Book]];
|
||||
const UI_LIST: [Ref<boolean>, Component][] = [
|
||||
[bookOpened, Book],
|
||||
[toolOpened, Toolbox]
|
||||
];
|
||||
|
||||
/** ui栈 */
|
||||
export const uiStack = ref<Component[]>([]);
|
||||
@@ -23,24 +30,40 @@ export default function init() {
|
||||
const index = uiStack.value.findIndex(v => v === com);
|
||||
if (uiStack.value.length === 1) {
|
||||
hideApp(index);
|
||||
} else {
|
||||
uiStack.value.splice(index, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return { uiStack, bookOpened };
|
||||
return { uiStack, bookOpened, toolOpened, transition };
|
||||
}
|
||||
|
||||
async function showApp() {
|
||||
core.lockControl();
|
||||
if (transition.value) {
|
||||
app.style.transition = 'all 0.6s linear';
|
||||
} else {
|
||||
app.style.transition = '';
|
||||
}
|
||||
app.style.display = 'flex';
|
||||
await sleep(50);
|
||||
app.style.opacity = '1';
|
||||
core.lockControl();
|
||||
}
|
||||
|
||||
async function hideApp(index: number) {
|
||||
app.style.opacity = '0';
|
||||
await sleep(600);
|
||||
uiStack.value.splice(index, 1);
|
||||
app.style.display = 'none';
|
||||
core.unlockControl();
|
||||
if (transition.value) {
|
||||
app.style.transition = 'all 0.6s linear';
|
||||
app.style.opacity = '0';
|
||||
await sleep(600);
|
||||
uiStack.value.splice(index, 1);
|
||||
app.style.display = 'none';
|
||||
core.closePanel();
|
||||
} else {
|
||||
app.style.transition = '';
|
||||
app.style.opacity = '0';
|
||||
uiStack.value.splice(index, 1);
|
||||
app.style.display = 'none';
|
||||
core.closePanel();
|
||||
}
|
||||
}
|
||||
+63
-1
@@ -1,8 +1,18 @@
|
||||
import { isNil } from 'lodash';
|
||||
import { Animation, TimingFn } from 'mutate-animate';
|
||||
import { ComputedRef, ref } from 'vue';
|
||||
import { EVENT_KEY_CODE_MAP } from './keyCodes';
|
||||
|
||||
type CanParseCss = keyof {
|
||||
[P in keyof CSSStyleDeclaration as CSSStyleDeclaration[P] extends string
|
||||
? P extends string
|
||||
? P
|
||||
: never
|
||||
: never]: CSSStyleDeclaration[P];
|
||||
};
|
||||
|
||||
export default function init() {
|
||||
return { has, getDamageColor };
|
||||
return { has, getDamageColor, parseCss };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,3 +61,55 @@ export function setCanvasSize(
|
||||
export function keycode(key: number) {
|
||||
return EVENT_KEY_CODE_MAP[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析css字符串为CSSStyleDeclaration对象
|
||||
* @param css 要解析的css字符串
|
||||
*/
|
||||
export function parseCss(css: string): Partial<Record<CanParseCss, string>> {
|
||||
const str = css.replace(/[\n\s\t]*/g, '').replace(/[;,]*/g, ';');
|
||||
const styles = str.split(';');
|
||||
const res: Partial<Record<CanParseCss, string>> = {};
|
||||
|
||||
for (const one of styles) {
|
||||
const [key, data] = one.split(':');
|
||||
const cssKey = key.replace(/\-([a-z])/g, $1 =>
|
||||
$1.toUpperCase()
|
||||
) as CanParseCss;
|
||||
res[cssKey] = data;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用打字机效果显示一段文字
|
||||
* @param str 要打出的字符串
|
||||
* @param time 打出总用时,默认1秒
|
||||
* @param timing 打出时的速率曲线,默认为线性变化
|
||||
* @returns 文字的响应式变量
|
||||
*/
|
||||
export function type(
|
||||
str: string,
|
||||
time: number = 1000,
|
||||
timing: TimingFn = n => n
|
||||
): Ref<string> {
|
||||
const toShow = eval('`' + str + '`') as string;
|
||||
const ani = new Animation();
|
||||
const content = ref('');
|
||||
const all = toShow.length;
|
||||
|
||||
const fn = (time: number) => {
|
||||
if (!has(time)) return;
|
||||
const now = ani.x;
|
||||
content.value = toShow.slice(0, Math.floor(now));
|
||||
if (Math.floor(now) === all) {
|
||||
ani.ticker.destroy();
|
||||
}
|
||||
};
|
||||
|
||||
ani.ticker.add(fn);
|
||||
|
||||
ani.mode(timing).time(time).move(all, 0);
|
||||
|
||||
return content;
|
||||
}
|
||||
+6
-1
@@ -3,7 +3,7 @@
|
||||
display: none;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 9999;
|
||||
z-index: 1000;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
@@ -11,3 +11,8 @@
|
||||
opacity: 0;
|
||||
background-color: #000d;
|
||||
}
|
||||
|
||||
.antdv-message {
|
||||
font-family: 'normal';
|
||||
font-size: 1.6em;
|
||||
}
|
||||
Vendored
+1
-1
@@ -330,7 +330,7 @@ declare class Sprite {
|
||||
removeEventListenr: HTMLCanvasElement['addEventListener'];
|
||||
}
|
||||
|
||||
declare const main: main;
|
||||
declare const main: Main;
|
||||
declare const core: Core;
|
||||
declare const flags: { [x: string]: any };
|
||||
declare const hero: HeroStatus;
|
||||
|
||||
Vendored
+4
-1
@@ -479,7 +479,10 @@ declare class maps {
|
||||
resizeMap(floorId?: string): void;
|
||||
|
||||
/** 以x,y的形式返回每个点的事件 */
|
||||
getMapBlocksObj(floorId?: string, noCache?: boolean): object;
|
||||
getMapBlocksObj(
|
||||
floorId?: string,
|
||||
noCache?: boolean
|
||||
): Record<`${number},${number}`, Block>;
|
||||
|
||||
/** 获得某些点可否通行的信息 */
|
||||
canMoveDirectlyArray(locs?: any): object;
|
||||
|
||||
Vendored
+20
@@ -6,6 +6,14 @@ type Ref<T> = {
|
||||
|
||||
type DragFn = (x: number, y: number, e: MouseEvent | TouchEvent) => void;
|
||||
|
||||
type CanParseCss = keyof {
|
||||
[P in keyof CSSStyleDeclaration as CSSStyleDeclaration[P] extends string
|
||||
? P extends string
|
||||
? P
|
||||
: never
|
||||
: never]: CSSStyleDeclaration[P];
|
||||
};
|
||||
|
||||
interface PluginDeclaration extends PluginUtils {
|
||||
/**
|
||||
* 添加函数 例:添加弹出文字,像这个就可以使用core.addPop或core.plugin.addPop调用
|
||||
@@ -24,9 +32,15 @@ interface PluginDeclaration extends PluginUtils {
|
||||
/** 怪物手册详细信息展示的怪物 */
|
||||
bookDetailEnemy: Enemy & DetailedEnemy;
|
||||
|
||||
/** ui是否使用渐变 */
|
||||
readonly transition: Ref<boolean>;
|
||||
|
||||
/** 手册是否打开 */
|
||||
readonly bookOpened: Ref<boolean>;
|
||||
|
||||
/** 道具栏是否打开 */
|
||||
readonly toolOpened: Ref<boolean>;
|
||||
|
||||
/** ui栈 */
|
||||
readonly uiStack: Ref<Component[]>;
|
||||
|
||||
@@ -96,6 +110,12 @@ interface PluginUtils {
|
||||
* @param damage 伤害大小
|
||||
*/
|
||||
getDamageColor(damage: number): string;
|
||||
|
||||
/**
|
||||
* 解析css字符串为CSSStyleDeclaration对象
|
||||
* @param css 要解析的css字符串
|
||||
*/
|
||||
parseCss(css: string): Partial<Record<CanParseCss, string>>;
|
||||
}
|
||||
|
||||
type Forward<T> = {
|
||||
|
||||
Vendored
+6
-1
@@ -553,7 +553,12 @@ type DetailedEnemy = {
|
||||
};
|
||||
|
||||
type Item = {
|
||||
cls: string;
|
||||
name: string;
|
||||
cls: 'items' | 'constants' | 'tools' | 'equips';
|
||||
text: string;
|
||||
hideInToolbox?: boolean;
|
||||
color?: string;
|
||||
css?: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
|
||||
+1
-2
@@ -116,7 +116,6 @@ async function show() {
|
||||
* 退出怪物手册
|
||||
*/
|
||||
function exit() {
|
||||
core.closePanel();
|
||||
core.plugin.bookOpened.value = false;
|
||||
}
|
||||
|
||||
@@ -190,7 +189,7 @@ onMounted(async () => {
|
||||
document.addEventListener('keydown', keydown);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onUnmounted(async () => {
|
||||
document.removeEventListener('keyup', keyup);
|
||||
document.removeEventListener('keydown', keydown);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,405 @@
|
||||
<template>
|
||||
<span id="back" class="item-type-mobile" @click="exit"
|
||||
><left-outlined />返回游戏</span
|
||||
>
|
||||
<div id="toolbox">
|
||||
<div v-for="cls of toShow" class="item-main">
|
||||
<div class="item-info">
|
||||
<div class="item-type" v-if="!isMobile">
|
||||
{{ getClsName(cls) }}
|
||||
</div>
|
||||
<div v-else id="item-type-mobile">
|
||||
<span
|
||||
class="item-type-mobile"
|
||||
@click="mode = 'tools'"
|
||||
:selected="mode === 'tools'"
|
||||
>消耗道具</span
|
||||
>
|
||||
<a-divider
|
||||
dashed
|
||||
style="border-color: #ddd4; height: 100%"
|
||||
type="vertical"
|
||||
></a-divider>
|
||||
<span
|
||||
class="item-type-mobile"
|
||||
@click="mode = 'constants'"
|
||||
:selected="mode === 'constants'"
|
||||
>永久道具</span
|
||||
>
|
||||
</div>
|
||||
<a-divider
|
||||
dashed
|
||||
style="margin: 1vh 0 1vh 0; border-color: #ddd4"
|
||||
></a-divider>
|
||||
<Scroll class="item-list" :width="10">
|
||||
<div
|
||||
class="item"
|
||||
v-for="[id, num] of items[cls]"
|
||||
:selected="selected === id"
|
||||
@click="
|
||||
mode = cls;
|
||||
select(id);
|
||||
"
|
||||
>
|
||||
<div class="item-icon">
|
||||
<BoxAnimate
|
||||
:id="id"
|
||||
:width="32"
|
||||
:height="32"
|
||||
:noborder="true"
|
||||
></BoxAnimate>
|
||||
<span class="item-name">{{ all[id].name }}</span>
|
||||
</div>
|
||||
<span>× {{ num }}</span>
|
||||
</div>
|
||||
</Scroll>
|
||||
</div>
|
||||
<a-divider
|
||||
dashed
|
||||
:type="isMobile ? 'horizontal' : 'vertical'"
|
||||
class="divider"
|
||||
style="border-color: #ddd4; margin: 1%"
|
||||
></a-divider>
|
||||
</div>
|
||||
<div id="detail">
|
||||
<div id="info">
|
||||
<BoxAnimate
|
||||
:id="selected"
|
||||
:width="32"
|
||||
:height="32"
|
||||
></BoxAnimate>
|
||||
<div id="basic-info">
|
||||
<span style="border-bottom: 1px solid #ddd4">{{
|
||||
all[selected]?.name ?? '没有道具'
|
||||
}}</span>
|
||||
<span>{{
|
||||
getClsName(all[selected]?.cls as ItemMode) ?? '永久道具'
|
||||
}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span style="margin-top: 2vh">点击该物品以使用</span>
|
||||
<a-divider dashed style="border-color: #ddd4"></a-divider>
|
||||
<div id="desc">
|
||||
<span style="border-bottom: 1px solid #ddd4">道具描述</span>
|
||||
<Scroll id="desc-text">
|
||||
<div v-if="!descText.value.startsWith('!!html')">
|
||||
{{ descText.value }}
|
||||
</div>
|
||||
<div v-else v-html="descText.value.slice(6)"></div>
|
||||
</Scroll>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { LeftOutlined } from '@ant-design/icons-vue';
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import Scroll from '../components/scroll.vue';
|
||||
import BoxAnimate from '../components/boxAnimate.vue';
|
||||
import { getClsName, getItems } from '../plugin/ui/toolbox';
|
||||
import { isMobile } from '../plugin/use';
|
||||
import { type, keycode, has } from '../plugin/utils';
|
||||
import { hyper, sleep } from 'mutate-animate';
|
||||
import { message } from 'ant-design-vue';
|
||||
import { KeyCode } from '../plugin/keyCodes';
|
||||
|
||||
type ItemMode = 'tools' | 'constants';
|
||||
|
||||
const mode = ref<ItemMode>('tools');
|
||||
|
||||
const items = getItems('all');
|
||||
|
||||
const toShow = computed<ItemMode[]>(() => {
|
||||
return isMobile ? [mode.value] : ['tools', 'constants'];
|
||||
});
|
||||
|
||||
const all = core.material.items;
|
||||
|
||||
const selected = ref(items[toShow.value[0]][0]?.[0] ?? 'none');
|
||||
const index = ref(0);
|
||||
|
||||
watch(index, n => {
|
||||
select(items[mode.value][n][0], true);
|
||||
});
|
||||
|
||||
watch(mode, n => {
|
||||
if (!has(items[n][index.value])) {
|
||||
selected.value = 'none';
|
||||
return;
|
||||
}
|
||||
select(items[n][index.value][0], true);
|
||||
});
|
||||
|
||||
const descText = computed(() => {
|
||||
const s = selected.value;
|
||||
if (s === 'none') return ref('没有选择道具');
|
||||
if (all[s].text.startsWith('!!html')) return ref(all[s].text);
|
||||
return type(all[s].text, 600, hyper('sin', 'out'));
|
||||
});
|
||||
|
||||
/**
|
||||
* 选择一个道具时
|
||||
* @param id 道具id
|
||||
*/
|
||||
async function select(id: string, nouse: boolean = false) {
|
||||
if (selected.value === id && !nouse) {
|
||||
use(id);
|
||||
}
|
||||
index.value = items[mode.value].findIndex(v => v[0] === id);
|
||||
selected.value = id;
|
||||
}
|
||||
|
||||
function exit() {
|
||||
core.plugin.toolOpened.value = false;
|
||||
}
|
||||
|
||||
async function use(id: string) {
|
||||
if (core.canUseItem(id)) {
|
||||
// 应该暂时把动画去掉
|
||||
core.plugin.transition.value = false;
|
||||
exit();
|
||||
await sleep(50);
|
||||
core.useItem(id);
|
||||
core.plugin.transition.value = true;
|
||||
} else {
|
||||
message.warn({
|
||||
content: '当前无法使用该道具!',
|
||||
class: 'antdv-message'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function keyup(e: KeyboardEvent) {
|
||||
const c = keycode(e.keyCode);
|
||||
if (c === KeyCode.Escape || c === KeyCode.KeyX) {
|
||||
exit();
|
||||
}
|
||||
if (c === KeyCode.Enter || c === KeyCode.KeyC) {
|
||||
use(selected.value);
|
||||
}
|
||||
}
|
||||
|
||||
function keydown(e: KeyboardEvent) {
|
||||
const c = keycode(e.keyCode);
|
||||
const total = items[mode.value].length;
|
||||
if (c === KeyCode.DownArrow) {
|
||||
if (index.value < total - 1) {
|
||||
index.value++;
|
||||
}
|
||||
}
|
||||
if (c === KeyCode.UpArrow) {
|
||||
if (index.value > 0) {
|
||||
index.value--;
|
||||
}
|
||||
}
|
||||
if (c === KeyCode.RightArrow) {
|
||||
const constants = items.constants.length;
|
||||
if (mode.value === 'tools') {
|
||||
if (index.value >= constants) {
|
||||
index.value = constants - 1;
|
||||
}
|
||||
mode.value = 'constants';
|
||||
}
|
||||
}
|
||||
if (c === KeyCode.LeftArrow) {
|
||||
const constants = items.tools.length;
|
||||
if (mode.value === 'constants') {
|
||||
if (index.value >= constants) {
|
||||
index.value = constants - 1;
|
||||
}
|
||||
mode.value = 'tools';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await sleep(600);
|
||||
document.addEventListener('keyup', keyup);
|
||||
document.addEventListener('keydown', keydown);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('keyup', keyup);
|
||||
document.removeEventListener('keydown', keydown);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
#toolbox {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
font-family: 'normal';
|
||||
font-size: 2.5vh;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#back {
|
||||
position: absolute;
|
||||
left: 2%;
|
||||
font-size: 2em;
|
||||
font-family: 'normal';
|
||||
}
|
||||
|
||||
.item-main {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
.item-info {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.item-list {
|
||||
width: 100%;
|
||||
height: 88vh;
|
||||
}
|
||||
|
||||
.item-type {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#item-type-mobile {
|
||||
width: 80%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.item-type-mobile {
|
||||
cursor: pointer;
|
||||
transition: color 0.2s linear;
|
||||
}
|
||||
|
||||
.item-type-mobile:hover,
|
||||
.item-type-mobile[selected='true'] {
|
||||
color: aqua;
|
||||
}
|
||||
|
||||
.item-type-mobile:active {
|
||||
color: aquamarine;
|
||||
}
|
||||
|
||||
.item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin: 1vh 1vw 0 0.5vw;
|
||||
padding: 0.5vh 0.5vw 0.5vh 0.5vw;
|
||||
border: #0000 0.5px solid;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
|
||||
.item-icon {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
||||
.item-name {
|
||||
margin-left: 5%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.item[selected='true'] {
|
||||
animation: selected alternate 5s infinite ease-in-out;
|
||||
}
|
||||
|
||||
.divider {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
#info {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
#basic-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-left: 1px solid #ddd4;
|
||||
padding-left: 5%;
|
||||
margin-left: 10%;
|
||||
}
|
||||
}
|
||||
|
||||
#desc {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
#desc-text {
|
||||
margin-top: 2vh;
|
||||
margin-left: 0.5vw;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes selected {
|
||||
0% {
|
||||
border: #0ff7 0.5px solid;
|
||||
background-color: rgba(39, 251, 209, 0.143);
|
||||
}
|
||||
50% {
|
||||
border: #0ffa 0.5px solid;
|
||||
background-color: rgba(39, 251, 209, 0.284);
|
||||
}
|
||||
100% {
|
||||
border: #0ff7 0.5px solid;
|
||||
background-color: rgba(39, 251, 209, 0.143);
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 600px) {
|
||||
#toolbox {
|
||||
flex-direction: column-reverse;
|
||||
padding: 5%;
|
||||
}
|
||||
|
||||
.item-list {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.divider {
|
||||
height: auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.item-main {
|
||||
display: flex;
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
|
||||
#back {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user