feat:绘制存档界面缩略图

This commit is contained in:
ShakeFlower 2025-06-23 15:55:38 +08:00
parent b026287a71
commit 462f0d5b7e
3 changed files with 83 additions and 12 deletions

View File

@ -7,10 +7,12 @@ import {
SetupComponentOptions, SetupComponentOptions,
UIComponentProps UIComponentProps
} from '@motajs/system-ui'; } from '@motajs/system-ui';
import { defineComponent, ref, computed } from 'vue'; import { defineComponent, ref, computed, watch } from 'vue';
import { Page, PageExpose } from '../components'; import { Page, PageExpose } from '../components';
import { useKey } from '../use'; import { useKey } from '../use';
import { MAP_WIDTH, MAP_HEIGHT } from '../shared'; import { MAP_WIDTH, MAP_HEIGHT } from '../shared';
import { getSave, SaveData } from '../utils';
import { Thumbnail } from '../components/thumbnail';
export interface SaveProps extends UIComponentProps, DefaultProps { export interface SaveProps extends UIComponentProps, DefaultProps {
loc: ElementLocator; loc: ElementLocator;
@ -32,6 +34,11 @@ export type SaveEmits = {
exit: () => void; exit: () => void;
}; };
export type SaveBtnEmits = {
/** 读取数据 */
updateData: (isValid: boolean) => void;
};
const saveProps = { const saveProps = {
props: ['loc', 'controller', 'instance'], props: ['loc', 'controller', 'instance'],
emits: ['delete', 'emit', 'exit'] emits: ['delete', 'emit', 'exit']
@ -41,10 +48,24 @@ const saveBtnProps = {
props: ['loc', 'index', 'isSelected', 'isDelete'] props: ['loc', 'index', 'isSelected', 'isDelete']
} satisfies SetupComponentOptions<SaveBtnProps>; } satisfies SetupComponentOptions<SaveBtnProps>;
export const SaveBtn = defineComponent<SaveBtnProps>(props => { export const SaveBtn = defineComponent<
SaveBtnProps,
SaveBtnEmits,
keyof SaveBtnEmits
>((props, { emit }) => {
const w = props.loc[2] ?? 200; const w = props.loc[2] ?? 200;
const font = new Font('normal', 18); const font = new Font('normal', 18);
const statusFont = new Font('normal', 14); const statusFont = new Font('normal', 14);
const data = ref<SaveData | null>(null);
const mapBlocks = computed(() => {
if (data.value == null) return void 0;
else {
const currData = data.value?.data;
const map = core.maps.loadMap(currData.maps, currData.floorId);
core.extractBlocksForUI(map, currData.hero.flags); // 这一步会向map写入blocks
return map.blocks;
}
});
const text = computed(() => const text = computed(() =>
props.index === -1 ? '自动存档' : `存档${props.index + 1}` props.index === -1 ? '自动存档' : `存档${props.index + 1}`
); );
@ -53,6 +74,18 @@ export const SaveBtn = defineComponent<SaveBtnProps>(props => {
else return 'white'; else return 'white';
}); });
const lineWidth = computed(() => (props.isSelected ? 2 : 1)); const lineWidth = computed(() => (props.isSelected ? 2 : 1));
watch(
() => props.index,
newIndex => {
getSave(newIndex + 1).then(value => {
data.value = value;
emit('updateData', value != null);
});
},
{ immediate: true }
);
return () => ( return () => (
<container loc={props.loc}> <container loc={props.loc}>
<text <text
@ -69,6 +102,16 @@ export const SaveBtn = defineComponent<SaveBtnProps>(props => {
lineWidth={lineWidth.value} lineWidth={lineWidth.value}
lineJoin="miter" lineJoin="miter"
/> />
<Thumbnail
hidden={data.value == null}
loc={[3, 26, w - 6, w - 4]}
size={w / MAP_WIDTH}
floorId={data.value?.data.floorId || 'MT0'}
map={mapBlocks.value}
hero={data.value?.data.hero as HeroStatus}
all={true}
noHD={true}
/>
<text <text
text="placeholder" text="placeholder"
fillStyle="yellow" fillStyle="yellow"
@ -88,14 +131,26 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
const font = new Font('normal', 18); const font = new Font('normal', 18);
const pageFont = new Font('normal', 14); const pageFont = new Font('normal', 14);
/** 各个存档是否有数据 */
const saveValidArr = Array(pageCap).fill(false);
/** 这里参数是存档在当前页的索引posIndex */
const updateValid = (index: number) => (isValid: boolean) => {
saveValidArr[index] = isValid;
};
const isDelete = ref(false); const isDelete = ref(false);
const pageRef = ref<PageExpose>(); const pageRef = ref<PageExpose>();
/** 当前页上被选中的存档的序号 只会是0到5 */ /** 当前页上被选中的存档的序号 只会是0到5 */
const pickIndex = ref(1); const pickIndex = ref(1);
const getPosIndex = (index: number) => {
if (index === -1) return 0;
return index - pageCap * (pageRef.value?.now() || 0) + 1;
};
const emitSave = (index: number) => { const emitSave = (index: number) => {
if (isDelete.value) emit('delete', index); const posIndex = getPosIndex(index);
else emit('emit', index); if (isDelete.value) emit('delete', index, saveValidArr[posIndex]);
else emit('emit', index, saveValidArr[posIndex]);
pickIndex.value = (index % pageCap) + 1; pickIndex.value = (index % pageCap) + 1;
}; };
@ -117,6 +172,7 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
props.controller.close(props.instance); props.controller.close(props.instance);
}; };
// #region 按键实现
const [key] = useKey(); const [key] = useKey();
key.realize('confirm', () => { key.realize('confirm', () => {
const currPage = pageRef.value?.now(); const currPage = pageRef.value?.now();
@ -160,9 +216,9 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
.realize( .realize(
'@save_down', '@save_down',
() => { () => {
if (pickIndex.value <= pageCap - row) if (pickIndex.value <= pageCap - row) {
pickIndex.value += column; pickIndex.value += column;
else { } else {
pickIndex.value += column - pageCap - 1; pickIndex.value += column - pageCap - 1;
pageRef.value?.movePage(1); pageRef.value?.movePage(1);
} }
@ -188,14 +244,16 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
.realize( .realize(
'@save_right', '@save_right',
() => { () => {
if (pickIndex.value < pageCap) pickIndex.value++; if (pickIndex.value < pageCap) {
else { pickIndex.value++;
} else {
pickIndex.value = 0; pickIndex.value = 0;
pageRef.value?.movePage(1); pageRef.value?.movePage(1);
} }
}, },
{ type: 'down-repeat' } { type: 'down-repeat' }
); );
// #endregion
return () => ( return () => (
<container loc={props.loc} zIndex={10}> <container loc={props.loc} zIndex={10}>
@ -214,6 +272,7 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
isSelected={pickIndex.value === 0} isSelected={pickIndex.value === 0}
isDelete={isDelete.value} isDelete={isDelete.value}
onClick={() => emitSave(-1)} onClick={() => emitSave(-1)}
onUpdateData={updateValid(0)}
cursor="pointer" cursor="pointer"
/> />
<SaveBtn <SaveBtn
@ -222,6 +281,7 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
isSelected={pickIndex.value === 1} isSelected={pickIndex.value === 1}
isDelete={isDelete.value} isDelete={isDelete.value}
onClick={() => emitSave(page * pageCap)} onClick={() => emitSave(page * pageCap)}
onUpdateData={updateValid(1)}
cursor="pointer" cursor="pointer"
/> />
<SaveBtn <SaveBtn
@ -230,6 +290,7 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
isSelected={pickIndex.value === 2} isSelected={pickIndex.value === 2}
isDelete={isDelete.value} isDelete={isDelete.value}
onClick={() => emitSave(page * pageCap + 1)} onClick={() => emitSave(page * pageCap + 1)}
onUpdateData={updateValid(2)}
cursor="pointer" cursor="pointer"
/> />
<SaveBtn <SaveBtn
@ -238,6 +299,7 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
isSelected={pickIndex.value === 3} isSelected={pickIndex.value === 3}
isDelete={isDelete.value} isDelete={isDelete.value}
onClick={() => emitSave(page * pageCap + 2)} onClick={() => emitSave(page * pageCap + 2)}
onUpdateData={updateValid(3)}
cursor="pointer" cursor="pointer"
/> />
<SaveBtn <SaveBtn
@ -246,6 +308,7 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
isSelected={pickIndex.value === 4} isSelected={pickIndex.value === 4}
isDelete={isDelete.value} isDelete={isDelete.value}
onClick={() => emitSave(page * pageCap + 3)} onClick={() => emitSave(page * pageCap + 3)}
onUpdateData={updateValid(4)}
cursor="pointer" cursor="pointer"
/> />
<SaveBtn <SaveBtn
@ -254,6 +317,7 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
isSelected={pickIndex.value === 5} isSelected={pickIndex.value === 5}
isDelete={isDelete.value} isDelete={isDelete.value}
onClick={() => emitSave(page * pageCap + 4)} onClick={() => emitSave(page * pageCap + 4)}
onUpdateData={updateValid(5)}
cursor="pointer" cursor="pointer"
/> />
</container> </container>
@ -359,7 +423,7 @@ export async function saveSave(
}; };
const index = await selectSave(controller, loc, validate, props); const index = await selectSave(controller, loc, validate, props);
if (index === -2) return; if (index === -2) return;
core.doSL(index, 'save'); core.doSL(index + 1, 'save');
} }
export async function saveLoad( export async function saveLoad(
@ -375,6 +439,6 @@ export async function saveLoad(
if (index === -1) { if (index === -1) {
core.doSL('autosave', 'load'); core.doSL('autosave', 'load');
} else { } else {
core.doSL(index, 'load'); core.doSL(index + 1, 'load');
} }
} }

View File

@ -21,7 +21,7 @@ import { KeyCode } from '@motajs/client-base';
import { Progress } from '../components/misc'; import { Progress } from '../components/misc';
import { generateBinary } from '@motajs/legacy-common'; import { generateBinary } from '@motajs/legacy-common';
import { SetupComponentOptions } from '@motajs/system-ui'; import { SetupComponentOptions } from '@motajs/system-ui';
import { saveSave } from './save'; import { saveSave, saveLoad } from './save';
import { mainUIController } from './controller'; import { mainUIController } from './controller';
import { MAIN_WIDTH, MAIN_HEIGHT } from '../shared'; import { MAIN_WIDTH, MAIN_HEIGHT } from '../shared';
@ -90,7 +90,9 @@ export const PlayingToolbar = defineComponent<
const save = () => { const save = () => {
saveSave(mainUIController, [0, 0, MAIN_WIDTH, MAIN_HEIGHT]); saveSave(mainUIController, [0, 0, MAIN_WIDTH, MAIN_HEIGHT]);
}; };
const load = () => core.load(true); const load = () => {
saveLoad(mainUIController, [0, 0, MAIN_WIDTH, MAIN_HEIGHT]);
};
const equip = () => core.openEquipbox(true); const equip = () => core.openEquipbox(true);
const shop = () => core.openQuickShop(true); const shop = () => core.openQuickShop(true);
const key = () => { const key = () => {

View File

@ -280,6 +280,11 @@ interface ResolvedFloor<T extends FloorIds = FloorIds> extends FloorBase<T> {
* *
*/ */
eachArrive?: MotaEvent; eachArrive?: MotaEvent;
/**
*
*/
blocks?: Block[];
} }
interface BlockInfo<T extends keyof NumberToId = keyof NumberToId> { interface BlockInfo<T extends keyof NumberToId = keyof NumberToId> {