-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from libondev/dev
feat: 道具系统
- Loading branch information
Showing
10 changed files
with
204 additions
and
104 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
- [x] i18n | ||
- [x] 积分系统 | ||
- [x] 道具兑换 | ||
- [ ] 道具系统 | ||
- [x] 道具系统 | ||
|
||
### 后续功能 | ||
一些想做但不确定会不会做的功能 | ||
|
This file contains 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 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 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,77 @@ | ||
<script setup lang="ts"> | ||
import { Popover, PopoverButton, PopoverPanel } from '@headlessui/vue' | ||
import type { GameGood } from '@/config/goods' | ||
import { getGameGoods, setGameGoods } from '@/composables/use-local-cache' | ||
defineProps<{ | ||
disabled?: boolean | ||
}>() | ||
const emits = defineEmits<{ | ||
(eventName: 'use-props', good: GameGood): void | ||
}>() | ||
const popoverTriggerRef = shallowRef<typeof PopoverButton>() | ||
const goods = ref<GameGood[]>([]) | ||
function onClickGood(good: GameGood) { | ||
if (good.count <= 0) { | ||
return | ||
} | ||
good.count -= 1 | ||
emits('use-props', good) | ||
setGameGoods(goods.value) | ||
popoverTriggerRef.value!.el.click() | ||
} | ||
onMounted(async () => { | ||
goods.value = await getGameGoods() || [] | ||
}) | ||
</script> | ||
|
||
<template> | ||
<Popover class="relative" :class="{ 'opacity-40 pointer-events-none': disabled }"> | ||
<PopoverButton | ||
ref="popoverTriggerRef" | ||
:disabled | ||
class="inline-block px-3 py-1.5 select-none rounded-lg text-sm shadow-sm dark:bg-gray-700 border-[rgba(0,0,0,.2)] border-x-[1.5px] border-t-[1.5px] border-b-4 active:border-b-[1.5px] active:translate-y-1 active:shadow-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-1" | ||
> | ||
道具栏 | ||
</PopoverButton> | ||
|
||
<Transition | ||
enter-active-class="transition duration-200 ease-out" | ||
enter-from-class="translate-y-1 opacity-0" | ||
enter-to-class="translate-y-0 opacity-100" | ||
leave-active-class="transition duration-150 ease-in" | ||
leave-from-class="translate-y-0 opacity-100" | ||
leave-to-class="translate-y-1 opacity-0" | ||
> | ||
<PopoverPanel class="absolute right-0 bottom-full mb-2 z-10 p-1 border rounded-md bg-[hsl(var(--background))] shadow-sm w-max select-none" as="ul"> | ||
<li | ||
v-for="good of goods" | ||
:key="good.id" | ||
class="relative flex items-center pl-2 pr-2 py-1 rounded hover:bg-secondary cursor-pointer" | ||
@click="onClickGood(good)" | ||
> | ||
<i :class="[good.icon, good.color]" /> | ||
|
||
{{ good.name }} | ||
|
||
<span class="text-white bg-red-500 rounded-e-full rounded-s-full text-xs px-1 absolute right-0 -top-0.5"> | ||
{{ good.count }} | ||
</span> | ||
</li> | ||
<li v-if="goods.length === 0" class="text-center text-sm px-1 text-gray-500"> | ||
暂无道具,<RouterLink to="/store" class="text-primary font-medium"> | ||
去购买 | ||
</RouterLink> | ||
</li> | ||
</PopoverPanel> | ||
</Transition> | ||
</Popover> | ||
</template> |
This file contains 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 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 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 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 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
Oops, something went wrong.