From 4f1e8c6f19a7144ff6232ab4d64637503e028e66 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Fri, 20 Nov 2026 17:06:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=B1=20icon=20=E5=BC=95=E5=8F=91?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client-base/src/components/icon.tsx | 65 ++++++ .../client-base/src/components/index.ts | 2 + .../client-base/src/components/textbox.tsx | 6 +- .../client-base/src/components/tip.tsx | 8 +- .../client-base/src/elements/cache.ts | 16 -- .../client-base/src/elements/misc.ts | 165 +-------------- .../client-base/src/elements/props.ts | 12 -- .../client-base/src/elements/types.ts | 37 ---- packages-user/client-base/src/map/element.ts | 6 + .../client-base/src/map/extension/hero.ts | 3 +- .../client-base/src/map/extension/manager.ts | 22 -- packages-user/client-base/src/map/index.ts | 1 - packages-user/client-modules/src/client.ts | 41 ++-- packages-user/client-modules/src/index.ts | 6 - .../client-modules/src/render/index.tsx | 7 - .../client-modules/src/render/utils/index.ts | 2 - .../client-modules/src/render/utils/saves.ts | 198 ------------------ .../client-modules/src/render/utils/use.ts | 13 -- .../src/render/weather/presets/cloudLike.ts | 2 +- .../src/render/weather/presets/sun.ts | 2 +- src/client/initialize.ts | 8 +- src/client/plugin/shop/shop.tsx | 5 +- .../ui/__test__/legacyUiParityGate.test.ts | 2 +- src/client/ui/background.tsx | 52 +---- src/client/ui/book.tsx | 1 + src/client/ui/bookDetail.tsx | 1 + src/client/ui/choices.tsx | 10 +- src/client/ui/enemyOne.tsx | 15 +- src/client/ui/equipbox.tsx | 11 +- src/client/ui/index.ts | 2 +- src/client/ui/inputBox.tsx | 6 +- src/client/ui/load.tsx | 3 +- src/client/ui/main.tsx | 12 +- src/client/ui/save.tsx | 3 +- src/client/ui/scene.tsx | 14 ++ src/client/ui/title.tsx | 12 +- src/client/ui/toolbar.tsx | 4 +- src/client/ui/toolbox.tsx | 10 +- src/client/ui/waitBox.tsx | 5 +- 39 files changed, 188 insertions(+), 602 deletions(-) create mode 100644 packages-user/client-base/src/components/icon.tsx delete mode 100644 packages-user/client-modules/src/render/utils/index.ts delete mode 100644 packages-user/client-modules/src/render/utils/saves.ts delete mode 100644 packages-user/client-modules/src/render/utils/use.ts create mode 100644 src/client/ui/scene.tsx diff --git a/packages-user/client-base/src/components/icon.tsx b/packages-user/client-base/src/components/icon.tsx new file mode 100644 index 0000000..1a4553b --- /dev/null +++ b/packages-user/client-base/src/components/icon.tsx @@ -0,0 +1,65 @@ +import { DefaultProps } from '@motajs/render-vue'; +import { SetupComponentOptions } from '@motajs/system'; +import { computed, defineComponent, markRaw } from 'vue'; +import { IMaterialFramedData, ITextureManager } from '../material'; +import { isNil } from 'lodash-es'; +import { ITexture, TextureRowAnimater } from '@motajs/render'; + +export interface IIconProps extends DefaultProps { + /** 当前显示的图标 */ + icon?: number | string; + /** 贴图管理器 */ + manager?: ITextureManager; + /** 是否播放图块动画 */ + animate?: boolean; + /** 展示图块指定帧数的动画,传入时会忽略 `animate` 的动画 */ + frame?: number; +} + +const iconProps = { + props: ['icon', 'manager', 'animate', 'frame'], + emits: ['change', 'input', 'update:value'] +} satisfies SetupComponentOptions; + +export const Icon = defineComponent(props => { + const animater = markRaw(new TextureRowAnimater()); + + /** 图块的渲染数据 */ + const data = computed(() => { + if (!props.manager) return null; + const icon = props.icon ?? 0; + if (typeof icon === 'number') { + return props.manager.getTile(icon); + } else { + return props.manager.getTileByAlias(icon); + } + }); + /** 图块的完整贴图 */ + const texture = computed( + () => data.value?.texture ?? null + ); + /** 是否播放图块动画 */ + const animate = computed(() => { + const frames = data.value?.frames ?? 1; + return isNil(props.frame) && !!props.animate && frames > 1; + }); + /** 当不播放图块动画时,静态使用的贴图 */ + const staticImage = computed(() => { + if (!animate.value || !data.value) return null; + const frame = props.frame ?? data.value.defaultFrame; + const o = data.value.offset * frame; + const tex = data.value.texture; + return tex.clip({ x: o, y: 0, w: o, h: tex.height }); + }); + + return () => + animate.value ? ( + + ) : ( + + ); +}, iconProps); diff --git a/packages-user/client-base/src/components/index.ts b/packages-user/client-base/src/components/index.ts index 5970bd8..d9916fe 100644 --- a/packages-user/client-base/src/components/index.ts +++ b/packages-user/client-base/src/components/index.ts @@ -1,4 +1,6 @@ +export * from './background'; export * from './floorSelect'; +export * from './icon'; export * from './icons'; export * from './input'; export * from './list'; diff --git a/packages-user/client-base/src/components/textbox.tsx b/packages-user/client-base/src/components/textbox.tsx index d70c1e9..1705cc3 100644 --- a/packages-user/client-base/src/components/textbox.tsx +++ b/packages-user/client-base/src/components/textbox.tsx @@ -2,13 +2,11 @@ import { ElementLocator, Font, CustomRenderItem, - Text, MotaOffscreenCanvas2D } from '@motajs/render'; import { computed, defineComponent, - nextTick, onMounted, onUnmounted, ref, @@ -32,6 +30,7 @@ import { import { SetupComponentOptions } from '@motajs/system'; import { texture } from '../elements'; import { DefaultProps, onExcited } from '@motajs/render-vue'; +import { Icon } from './icon'; // todo: TextContent 应该改成渲染元素? @@ -526,7 +525,8 @@ export const Textbox = defineComponent< > )} {hasIcon.value && ( - + // TODO: manager + )} {hasIcon.value && ( ((props, { expose }) => { hide(); }; - const onSetText = (width: number) => { + const onSetText = (_: unknown, width: number) => { textWidth.value = width; }; @@ -128,9 +129,10 @@ export const Tip = defineComponent((props, { expose }) => { fill fillStyle="rgba(0,0,0,0.8)" /> -