-
Notifications
You must be signed in to change notification settings - Fork 57
feat(spx-gui): separate generation entry #2963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3e89e74
add separate ai generation entry
e072e5f
show asset library suggestions in AssetGenModal
edc9cbe
details
30d630e
more details
c5c4b58
refactor: split AssetGenModal into dedicated SpriteGenModal and Backd…
2b62c97
fix: add ongoing asset generation repeatedly when collapse
5cf0ceb
revert removed TODO comment
d44641a
optimize tip
db72894
fix: backdrop gen modal close flow
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
spx-gui/src/components/asset/gen/backdrop/BackdropGenModal.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| <script setup lang="ts"> | ||
| import { computed } from 'vue' | ||
| import { UIModal, UIModalClose, useConfirmDialog } from '@/components/ui' | ||
| import { useI18n } from '@/utils/i18n' | ||
| import { useMessageHandle } from '@/utils/exception' | ||
| import { AssetType } from '@/apis/asset' | ||
| import type { Backdrop } from '@/models/spx/backdrop' | ||
| import type { BackdropGen as BackdropGenModel } from '@/models/spx/gen/backdrop-gen' | ||
| import type { SpxProject } from '@/models/spx/project' | ||
| import { useAssetGen } from '../use-asset-gen' | ||
| import BackdropGenComp from './BackdropGen.vue' | ||
|
|
||
| const props = withDefaults( | ||
| defineProps<{ | ||
| visible: boolean | ||
| project: SpxProject | ||
| // Currently no use case for providing an external gen, but we keep this prop | ||
| // for consistency with SpriteGenModal and potential future use cases. | ||
| gen?: BackdropGenModel | ||
| }>(), | ||
| { | ||
| gen: undefined | ||
| } | ||
| ) | ||
|
|
||
| const emit = defineEmits<{ | ||
| resolved: [Backdrop] | ||
| cancelled: [] | ||
| }>() | ||
|
|
||
| const i18n = useI18n() | ||
| const confirm = useConfirmDialog() | ||
|
|
||
| const typeRef = computed(() => (props.gen != null ? null : AssetType.Backdrop)) | ||
| const { assetGen: internalGen } = useAssetGen(props.project, typeRef) | ||
| const activeGen = computed(() => props.gen ?? internalGen.value) | ||
|
|
||
| const handleModalClose = useMessageHandle( | ||
| async () => { | ||
| if (props.gen == null) { | ||
| await confirm({ | ||
| title: i18n.t({ zh: '退出背景生成?', en: 'Exit backdrop generation?' }), | ||
| content: i18n.t({ | ||
| zh: '当前内容不会被保存,确定要退出吗?', | ||
| en: 'Current progress will not be saved. Are you sure to exit?' | ||
| }), | ||
| confirmText: i18n.t({ en: 'Exit', zh: '退出' }) | ||
| }) | ||
| } | ||
| emit('cancelled') | ||
| }, | ||
| { en: 'Failed to exit modal', zh: '退出失败' } | ||
| ).fn | ||
| </script> | ||
|
|
||
| <template> | ||
| <UIModal | ||
| :radar="{ name: 'Backdrop generation modal', desc: 'Modal for backdrop generation' }" | ||
| style="width: 1076px; height: 800px" | ||
| :visible="visible" | ||
| mask-closable | ||
| @update:visible="handleModalClose" | ||
| > | ||
| <header class="header"> | ||
| <h2 class="title">{{ $t({ zh: '生成背景', en: 'Backdrop Generator' }) }}</h2> | ||
| <UIModalClose class="close" @click="handleModalClose" /> | ||
| </header> | ||
|
|
||
| <BackdropGenComp | ||
| v-if="activeGen != null" | ||
| class="backdrop-gen" | ||
| :gen="activeGen" | ||
| library-search-enabled | ||
| @resolved="emit('resolved', $event)" | ||
| /> | ||
| </UIModal> | ||
| </template> | ||
|
|
||
| <style lang="scss" scoped> | ||
| .header { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| padding: 0 24px; | ||
| height: 56px; | ||
| border-bottom: 1px solid var(--ui-color-grey-400); | ||
|
|
||
| .title { | ||
| font-size: 16px; | ||
| color: var(--ui-color-title); | ||
| } | ||
| } | ||
|
|
||
| .backdrop-gen { | ||
| flex: 1 1 0; | ||
| min-height: 0; | ||
| } | ||
| </style> |
83 changes: 83 additions & 0 deletions
83
spx-gui/src/components/asset/gen/common/AssetSuggestions.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <script setup lang="ts"> | ||
| import { computed } from 'vue' | ||
| import { AssetType, type AssetData } from '@/apis/asset' | ||
| import { UILoading } from '@/components/ui' | ||
|
|
||
| const props = defineProps<{ | ||
| type: AssetType | ||
| loading: boolean | ||
| keyword: string | ||
| suggestions: AssetData[] | ||
| selected: AssetData | null | ||
| }>() | ||
|
|
||
| const emit = defineEmits<{ | ||
| toggle: [AssetData] | ||
| }>() | ||
|
|
||
| function isSelected(asset: AssetData) { | ||
| return props.selected?.id === asset.id | ||
| } | ||
|
|
||
| const entityMessages = { | ||
| [AssetType.Backdrop]: { en: 'backdrop', zh: '背景' }, | ||
| [AssetType.Sprite]: { en: 'sprite', zh: '精灵' }, | ||
| [AssetType.Sound]: { en: 'sound', zh: '声音' } | ||
| } | ||
| const entityMessage = computed(() => entityMessages[props.type]) | ||
| </script> | ||
|
|
||
| <template> | ||
| <UILoading v-if="loading" /> | ||
| <div v-else class="asset-suggestions"> | ||
| <template v-if="suggestions.length > 0"> | ||
| <ul class="list"> | ||
| <template v-for="asset in suggestions" :key="asset.id"> | ||
| <slot name="item" :asset="asset" :selected="isSelected(asset)" :on-click="() => emit('toggle', asset)"></slot> | ||
| </template> | ||
| </ul> | ||
| <p class="tip"> | ||
| {{ | ||
| $t({ | ||
| en: `There are related ${entityMessage.en}s in the asset library. You can choose the one you like or continue generating.`, | ||
| zh: `素材库中已有相关的${entityMessage.zh},可以选择你喜欢的${entityMessage.zh}直接使用,或者继续生成。` | ||
| }) | ||
| }} | ||
| </p> | ||
| </template> | ||
| <p v-else-if="keyword.length > 0" class="tip" style="margin-top: 56px"> | ||
| {{ | ||
| $t({ | ||
| en: `No matching ${entityMessage.en}s found in the asset library. You can continue generating.`, | ||
| zh: `素材库中未找到匹配的${entityMessage.zh},你可以继续生成。` | ||
| }) | ||
| }} | ||
| </p> | ||
| </div> | ||
| </template> | ||
|
|
||
| <style lang="scss" scoped> | ||
| .asset-suggestions { | ||
|
cn0809 marked this conversation as resolved.
|
||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| gap: 12px; | ||
| } | ||
|
|
||
| .list { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 8px; | ||
| flex-wrap: nowrap; | ||
| justify-content: center; | ||
| list-style: none; | ||
| padding: 0; | ||
| margin: 0; | ||
| } | ||
|
|
||
| .tip { | ||
| text-align: center; | ||
| font-size: 12px; | ||
| color: var(--ui-color-hint-2); | ||
| } | ||
| </style> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.