HumanBreak/src/ui/book.vue

244 lines
5.8 KiB
Vue
Raw Normal View History

2022-11-14 17:11:23 +08:00
<!-- 怪物手册ui -->
<template>
2022-11-16 23:01:23 +08:00
<div id="book">
2022-11-19 13:07:42 +08:00
<div id="tools">
2022-11-30 16:42:44 +08:00
<span id="back" class="button-text tools" @click="exit"
2022-11-19 13:07:42 +08:00
><left-outlined />返回游戏</span
>
</div>
2022-11-16 23:01:23 +08:00
<div v-if="enemy.length === 0" id="none">
<div>本层无怪物</div>
</div>
2022-11-19 11:30:14 +08:00
<Scroll
v-else
2022-11-30 16:42:44 +08:00
style="width: 100%; height: 94%; font-family: normal"
2022-11-19 11:30:14 +08:00
v-model:now="scroll"
v-model:drag="drag"
>
2023-07-31 16:49:04 +08:00
<div v-for="(e, i) of toShow" class="enemy">
2022-11-19 18:15:42 +08:00
<EnemyOne
:selected="i === selected"
:enemy="e"
:key="i"
@select="select(e, i)"
@hover="selected = i"
></EnemyOne>
2022-11-16 23:01:23 +08:00
<a-divider
dashed
style="width: 100%; border-color: #ddd4"
></a-divider>
</div>
</Scroll>
</div>
2023-01-06 22:18:33 +08:00
<BookDetail
v-if="detail"
:from-book="true"
@close="closeDetail()"
></BookDetail>
2022-11-14 17:11:23 +08:00
</template>
<script setup lang="tsx">
2022-11-19 11:30:14 +08:00
import { sleep } from 'mutate-animate';
2022-11-19 18:15:42 +08:00
import { onMounted, onUnmounted, ref } from 'vue';
2022-11-16 23:01:23 +08:00
import EnemyOne from '../components/enemyOne.vue';
2022-11-14 17:11:23 +08:00
import Scroll from '../components/scroll.vue';
2022-12-28 12:13:52 +08:00
import { getDamageColor, has, keycode } from '../plugin/utils';
2022-11-19 11:30:14 +08:00
import BookDetail from './bookDetail.vue';
2022-11-19 13:07:42 +08:00
import { LeftOutlined } from '@ant-design/icons-vue';
2023-08-01 11:09:23 +08:00
import { ToShowEnemy, detailInfo } from '../plugin/ui/book';
2023-08-06 17:46:29 +08:00
import { getDetailedEnemy } from '../plugin/ui/fixed';
2023-11-05 10:54:26 +08:00
import { GameUi } from '@/core/main/custom/ui';
2023-11-18 22:24:07 +08:00
import { gameKey } from '@/core/main/init/hotkey';
2024-01-24 21:32:49 +08:00
import { mainUi } from '@/core/main/init/ui';
2024-04-20 12:27:38 +08:00
import { mainSetting } from '@/core/main/setting';
import { isMobile } from '@/plugin/use';
2023-11-05 10:54:26 +08:00
const props = defineProps<{
num: number;
ui: GameUi;
}>();
2022-11-14 17:11:23 +08:00
const floorId =
2022-12-28 12:13:52 +08:00
// @ts-ignore
core.floorIds[core.status.event?.ui?.index] ?? core.status.floorId;
2022-11-14 17:11:23 +08:00
const enemy = core.getCurrentEnemys(floorId);
2023-08-06 17:46:29 +08:00
const toShow: ToShowEnemy[] = enemy.map(v =>
getDetailedEnemy(v.enemy, floorId)
);
2022-11-16 23:01:23 +08:00
2022-11-19 11:30:14 +08:00
const scroll = ref(0);
const drag = ref(false);
const detail = ref(false);
2022-11-19 18:15:42 +08:00
const selected = ref(0);
2024-04-26 22:13:44 +08:00
let detailClosing = false;
2022-11-19 11:30:14 +08:00
2024-04-20 12:27:38 +08:00
const settingScale = mainSetting.getValue('ui.bookScale', 100) / 100;
const scale = isMobile
? Math.max(settingScale * 15, 20)
: Math.max(
(window.innerWidth / window.innerHeight) * 15 * settingScale,
20
);
2022-11-19 11:30:14 +08:00
/**
* 选择怪物展示详细信息
* @param enemy 选择的怪物
* @param index 选择的怪物索引
*/
2023-07-31 16:49:04 +08:00
function select(enemy: ToShowEnemy, index: number) {
2022-11-19 11:30:14 +08:00
if (drag.value) return;
const h = window.innerHeight;
const y = index * h * 0.2 - scroll.value;
2023-07-31 16:49:04 +08:00
detailInfo.enemy = enemy;
detailInfo.pos = y;
2022-11-19 11:30:14 +08:00
detail.value = true;
hide();
}
2022-11-19 18:15:42 +08:00
/**
* 隐藏怪物手册
*/
2022-11-19 11:30:14 +08:00
async function hide() {
const div = document.getElementById('book') as HTMLDivElement;
div.style.display = 'none';
}
2022-11-19 18:15:42 +08:00
/**
* 关闭详细信息
*/
2022-11-19 11:30:14 +08:00
async function closeDetail() {
show();
detail.value = false;
}
2022-11-19 18:15:42 +08:00
/**
* 显示怪物手册
*/
2022-11-19 11:30:14 +08:00
async function show() {
const div = document.getElementById('book') as HTMLDivElement;
2022-11-19 13:07:42 +08:00
div.style.display = 'flex';
2022-11-19 11:30:14 +08:00
}
2022-11-19 13:07:42 +08:00
2022-11-19 18:15:42 +08:00
/**
* 退出怪物手册
*/
2022-12-28 12:13:52 +08:00
async function exit() {
2024-01-24 21:32:49 +08:00
const hold = mainUi.holdOn();
mainUi.close(props.num);
2022-12-28 12:13:52 +08:00
if (core.events.recoverEvents(core.status.event.interval)) {
2024-04-20 12:27:38 +08:00
hold.end(true);
2022-12-28 12:13:52 +08:00
return;
} else if (has(core.status.event.ui)) {
core.status.boxAnimateObjs = [];
// @ts-ignore
core.ui._drawViewMaps(core.status.event.ui);
2024-04-20 12:27:38 +08:00
hold.end(true);
2023-11-08 19:50:11 +08:00
} else hold.end();
2022-11-19 13:07:42 +08:00
}
2022-11-19 18:15:42 +08:00
function checkScroll() {
const h = window.innerHeight;
const y = selected.value * h * 0.2 - scroll.value;
if (y < 0) {
scroll.value += y - 20;
}
if (y > h * 0.655) {
scroll.value += y - h * 0.655 + 20;
}
}
2023-11-18 22:24:07 +08:00
// 按键控制
2024-04-20 12:27:38 +08:00
setTimeout(() => {
gameKey.use(props.ui.symbol);
gameKey
.realize('@book_up', () => {
if (selected.value > 0) {
selected.value--;
}
checkScroll();
})
.realize('@book_down', () => {
if (selected.value < enemy.length - 1) {
selected.value++;
}
checkScroll();
})
.realize('@book_pageDown', () => {
if (selected.value <= 4) {
selected.value = 0;
} else {
selected.value -= 5;
}
checkScroll();
})
.realize('@book_pageUp', () => {
if (selected.value >= enemy.length - 5) {
selected.value = enemy.length - 1;
} else {
selected.value += 5;
}
checkScroll();
})
.realize('exit', () => {
exit();
})
.realize('confirm', () => {
select(toShow[selected.value], selected.value);
});
}, 0);
2022-11-19 18:15:42 +08:00
2023-11-18 22:24:07 +08:00
onUnmounted(() => {
gameKey.dispose(props.ui.symbol);
2022-11-19 18:15:42 +08:00
});
2022-11-14 17:11:23 +08:00
</script>
<style lang="less" scoped>
2022-11-16 23:01:23 +08:00
#book {
user-select: none;
width: 80%;
height: 100%;
overflow: hidden;
2022-11-19 13:07:42 +08:00
display: flex;
flex-direction: column;
justify-content: space-between;
2022-11-16 23:01:23 +08:00
}
2022-11-19 13:07:42 +08:00
#tools {
2022-11-30 16:42:44 +08:00
height: 6%;
2022-12-29 19:57:31 +08:00
font-size: 3.2vh;
2022-11-19 13:07:42 +08:00
}
2022-11-16 23:01:23 +08:00
#none {
width: 100%;
height: 100%;
2022-12-28 20:34:23 +08:00
font-size: 6vw;
2022-11-16 23:01:23 +08:00
display: flex;
justify-content: center;
align-items: center;
}
.enemy {
display: flex;
flex-direction: column;
2024-04-20 12:27:38 +08:00
height: v-bind('scale + "vh"');
2022-11-16 23:01:23 +08:00
width: 100%;
padding: 0 1% 0 1%;
2022-11-14 17:11:23 +08:00
}
2022-11-19 13:07:42 +08:00
@media screen and (max-width: 600px) {
2024-04-20 12:27:38 +08:00
#tools {
transform: translateY(-50%);
}
2022-11-19 13:07:42 +08:00
#book {
width: 100%;
2022-12-31 19:49:43 +08:00
padding: 5%;
2022-11-19 13:07:42 +08:00
}
2023-08-06 17:46:29 +08:00
.enemy {
2024-04-20 12:27:38 +08:00
height: v-bind('scale * 2 / 3 + "vh"');
2023-08-06 17:46:29 +08:00
}
2022-11-19 13:07:42 +08:00
}
2022-11-14 17:11:23 +08:00
</style>