HumanBreak/src/ui/toolbar.vue

139 lines
2.8 KiB
Vue
Raw Normal View History

2023-12-17 18:11:58 +08:00
<template>
<Box
2023-12-18 17:10:28 +08:00
class="toolbar-container"
2023-12-17 18:11:58 +08:00
:dragable="true"
:resizable="true"
v-model:left="box.x"
v-model:top="box.y"
v-model:height="box.height"
v-model:width="box.width"
:key="num"
2023-12-17 18:11:58 +08:00
>
<div class="toolbar">
2023-12-18 17:10:28 +08:00
<div
class="toolbar-item"
v-for="item of bar.items"
@click.stop="click"
:noaction="!!item.noDefaultAction"
2023-12-18 17:10:28 +08:00
>
2023-12-17 18:11:58 +08:00
<component
2024-01-19 22:09:48 +08:00
:is="(CustomToolbar.info[item.type].show as any)"
2023-12-17 18:11:58 +08:00
:item="item"
:toolbar="bar"
></component>
</div>
</div>
</Box>
</template>
<script lang="ts" setup>
import Box from '@/components/box.vue';
import { CustomToolbar } from '@/core/main/custom/toolbar';
import { GameUi } from '@/core/main/custom/ui';
2024-04-20 12:27:38 +08:00
import { mainSetting } from '@/core/main/setting';
2024-02-02 21:01:13 +08:00
import { onUnmounted, reactive, watch } from 'vue';
2023-12-17 18:11:58 +08:00
interface BoxData {
x: number;
y: number;
width: number;
height: number;
}
const props = defineProps<{
num: number;
ui: GameUi;
bar: CustomToolbar;
}>();
const bar = props.bar;
2024-04-20 12:27:38 +08:00
const scale = mainSetting.getValue('ui.toolbarScale', 100) / 100;
2024-02-02 21:01:13 +08:00
2023-12-17 18:11:58 +08:00
const box = reactive<BoxData>({
x: bar.x,
y: bar.y,
width: bar.width,
height: bar.height
});
watch(box, ({ x, y, width, height }) => {
bar.x = x;
bar.y = y;
bar.width = width;
bar.height = height;
});
2023-12-18 17:10:28 +08:00
function click() {
// pass
}
2024-02-02 21:01:13 +08:00
function posChange() {
box.x = bar.x;
box.y = bar.y;
box.width = bar.width;
box.height = bar.height;
}
bar.on('posChange', posChange);
onUnmounted(() => {
bar.off('posChange', posChange);
});
2023-12-17 18:11:58 +08:00
</script>
<style lang="less" scoped>
2023-12-18 17:10:28 +08:00
.toolbar-container {
background-color: #0009;
2024-04-20 12:27:38 +08:00
padding: v-bind('scale * 5 + "px"');
2023-12-18 17:10:28 +08:00
}
2023-12-17 18:11:58 +08:00
.toolbar {
display: flex;
flex-direction: row;
2023-12-18 17:10:28 +08:00
flex-wrap: wrap;
align-items: center;
font-size: 150%;
}
.toolbar-item {
display: flex;
2024-04-20 12:27:38 +08:00
margin: v-bind('scale * 5 + "px"');
min-width: v-bind('scale * 50 + "px"');
min-height: v-bind('scale * 50 + "px"');
2023-12-18 17:10:28 +08:00
background-color: #222;
2023-12-18 17:47:00 +08:00
border: 1.5px solid #ddd8;
2023-12-18 17:10:28 +08:00
justify-content: center;
align-items: center;
transition: all 0.1s linear;
}
.toolbar-item[noaction='false'] {
cursor: pointer;
}
2023-12-18 17:10:28 +08:00
.toolbar-item::v-deep(> *) {
2023-12-18 17:47:00 +08:00
height: 100%;
2024-04-20 12:27:38 +08:00
min-width: v-bind('scale * 50 + "px"');
2023-12-18 17:10:28 +08:00
display: flex;
justify-content: center;
align-items: center;
text-align: center;
text-overflow: clip;
text-wrap: nowrap;
2023-12-18 17:47:00 +08:00
overflow: hidden;
}
.toolbar-item::v-deep(.button-text)[active='true'] {
color: gold;
background-color: #555;
2023-12-18 17:10:28 +08:00
}
.toolbar-item:hover[noaction='false'] {
2023-12-18 17:10:28 +08:00
background-color: #444;
}
.toolbar-item:active[noaction='false'] {
2023-12-18 17:10:28 +08:00
background-color: #333;
2023-12-17 18:11:58 +08:00
}
</style>