HumanBreak/src/ui/desc.vue

80 lines
1.8 KiB
Vue
Raw Normal View History

2022-12-29 00:26:12 +08:00
<template>
2022-12-30 15:25:58 +08:00
<Colomn @close="exit" :width="80" :height="80" :left="30" :right="70"
><template #left
><div id="desc-list">
2022-12-31 18:24:21 +08:00
<div
2022-12-30 15:25:58 +08:00
v-for="(data, k) in desc"
2023-01-06 16:21:17 +08:00
class="selectable desc-item"
2022-12-30 15:25:58 +08:00
:selected="selected === k"
2023-01-06 16:21:17 +08:00
:show="show(data.condition)"
2022-12-31 18:24:21 +08:00
@click="click(k)"
2022-12-30 15:25:58 +08:00
>
2022-12-31 18:24:21 +08:00
<span v-if="show(data.condition)">{{ data.text }}</span>
</div>
2022-12-30 15:25:58 +08:00
</div></template
>
<template #right><span v-html="content"></span></template
></Colomn>
2022-12-29 00:26:12 +08:00
</template>
<script lang="ts" setup>
2023-11-20 20:05:54 +08:00
import { computed, onUnmounted, ref } from 'vue';
2022-12-30 00:55:03 +08:00
import desc from '../data/desc.json';
import { splitText } from '../plugin/utils';
2022-12-30 15:25:58 +08:00
import Colomn from '../components/colomn.vue';
import { GameUi } from '@/core/main/custom/ui';
import { gameKey } from '@/core/main/init/hotkey';
2024-01-24 21:32:49 +08:00
import { mainUi } from '@/core/main/init/ui';
2022-12-30 00:55:03 +08:00
2023-11-05 10:54:26 +08:00
const props = defineProps<{
num: number;
ui: GameUi;
2023-11-05 10:54:26 +08:00
}>();
2022-12-30 00:55:03 +08:00
type DescKey = keyof typeof desc;
const selected = ref(Object.keys(desc)[0] as DescKey);
function exit() {
2024-01-24 21:32:49 +08:00
mainUi.close(props.num);
2022-12-30 00:55:03 +08:00
}
const content = computed(() => {
2023-01-06 16:21:17 +08:00
return eval('`' + splitText(desc[selected.value].desc) + '`');
2022-12-30 00:55:03 +08:00
});
2022-12-31 18:24:21 +08:00
function click(key: DescKey) {
if (!eval(desc[key].condition)) return;
selected.value = key;
}
function show(condition: string) {
return eval(condition);
}
gameKey.use(props.ui.symbol);
gameKey
.realize('exit', () => {
exit();
})
.realize('desc', () => {
exit();
});
2023-11-20 20:05:54 +08:00
onUnmounted(() => {
gameKey.dispose(props.ui.symbol);
});
2022-12-29 00:26:12 +08:00
</script>
<style lang="less" scoped>
2022-12-30 00:55:03 +08:00
#desc-list {
display: flex;
flex-direction: column;
}
2023-01-06 16:21:17 +08:00
.desc-item[show='false'] {
margin: 0;
padding: 0;
}
2022-12-29 00:26:12 +08:00
</style>