|
| 1 | +import { computed, defineComponent, PropType } from 'vue'; |
| 2 | +import { IEntryState, ISectionState, Section } from "@/client/apiGen"; |
| 3 | +import { WhateverNaviBar } from '@munet/ui'; |
| 4 | + |
| 5 | +const WINDOW_PREFIX = 'GameSystem.Window.'; |
| 6 | + |
| 7 | +interface Preset { |
| 8 | + name: string; |
| 9 | + width: number; |
| 10 | + height: number; |
| 11 | +} |
| 12 | + |
| 13 | +const presets: Preset[] = [ |
| 14 | + { name: '720P 1P', width: 720, height: 1280 }, |
| 15 | + { name: '720P 2P', width: 1440, height: 1280 }, |
| 16 | + { name: '1080P 1P', width: 1080, height: 1920 }, |
| 17 | + { name: '1080P 2P', width: 2160, height: 1920 }, |
| 18 | + { name: '2K 1P', width: 1440, height: 2560 }, |
| 19 | + { name: '2K 2P', width: 2880, height: 2560 }, |
| 20 | + { name: '4K 1P', width: 2160, height: 3840 }, |
| 21 | + { name: '4K 2P', width: 4320, height: 3840 }, |
| 22 | +]; |
| 23 | + |
| 24 | +export default defineComponent({ |
| 25 | + props: { |
| 26 | + section: { type: Object as PropType<Section>, required: true }, |
| 27 | + entryStates: { type: Object as PropType<Record<string, IEntryState>>, required: true }, |
| 28 | + sectionState: { type: Object as PropType<ISectionState>, required: true }, |
| 29 | + allSectionStates: { type: Object as PropType<Record<string, ISectionState>> }, |
| 30 | + }, |
| 31 | + setup(props) { |
| 32 | + const activePreset = computed(() => { |
| 33 | + for (const preset of presets) { |
| 34 | + const widthEntry = props.entryStates[WINDOW_PREFIX + 'Width']; |
| 35 | + const heightEntry = props.entryStates[WINDOW_PREFIX + 'Height']; |
| 36 | + if (widthEntry && heightEntry && |
| 37 | + Number(widthEntry.value) === preset.width && |
| 38 | + Number(heightEntry.value) === preset.height) { |
| 39 | + return preset.name; |
| 40 | + } |
| 41 | + } |
| 42 | + return null; |
| 43 | + }); |
| 44 | + |
| 45 | + const applyPreset = (preset: Preset) => { |
| 46 | + const widthEntry = props.entryStates[WINDOW_PREFIX + 'Width']; |
| 47 | + const heightEntry = props.entryStates[WINDOW_PREFIX + 'Height']; |
| 48 | + if (widthEntry) widthEntry.value = preset.width; |
| 49 | + if (heightEntry) heightEntry.value = preset.height; |
| 50 | + props.sectionState.enabled = true; |
| 51 | + }; |
| 52 | + |
| 53 | + const naviItems = computed(() => presets.map(preset => ({ |
| 54 | + name: preset.name, |
| 55 | + selected: activePreset.value === preset.name, |
| 56 | + onClick: () => applyPreset(preset), |
| 57 | + }))); |
| 58 | + |
| 59 | + return () => <div class="flex flex-col gap-2"> |
| 60 | + <div class="pl-40 flex items-center gap-2"> |
| 61 | + 预设: |
| 62 | + <WhateverNaviBar items={naviItems.value}/> |
| 63 | + </div> |
| 64 | + </div>; |
| 65 | + }, |
| 66 | +}); |
0 commit comments