diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index aad908db..5e0d0a50 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -125,16 +125,30 @@ const guideMenu = [{ ] }, { - text: 'GUI Creation', + text: 'GUI', collapsed: false, items: [ { text: "Customizing Your Theme", link: "/gui/theme" }, { text: "Reusing GUI Components", link: "/gui/reuse-gui" }, { text: "Creating Notifications in Your GUI", link: "/gui/notification-gui" }, + ] +}, +{ + text: 'Create GUI with VueJS', + collapsed: false, + items: [ { text: "Creating Your Own GUI", link: "/guide/create-gui" }, { text: "Adding Tooltips to Your GUI", link: "/gui/tooltip" } ] }, +{ + text: 'Create GUI with React', + collapsed: false, + items: [ + { text: "Create Gui with React", link: "/gui/react" }, + { text: "Adding Tooltips to Your GUI", link: "/gui/react-tooltip" } + ] +}, { text: 'Technical', collapsed: false, @@ -145,6 +159,7 @@ const guideMenu = [{ { text: "Supporting Gamepad Input", link: "/guide/gamepad" }, { text: "Creating Responsive Game Design", link: "/guide/responsive-design" }, { text: "Create Progressive Web Apps (PWA)", link: "/guide/pwa" }, + { text: "Add TailwindCSS", link: "/guide/tailwindcss" }, { text: "Upgrade/Update RPGJS", link: "/guide/upgrade" } ] @@ -172,6 +187,13 @@ const pluginMenu = [{ { text: "Creating a Title Screen Plugin", link: "/plugins/title-screen" }, { text: "Displaying Emotion Bubbles for Characters", link: "/plugins/emotion-bubble" } ] +}, +{ + text: 'Unofficial Plugins', + collapsed: false, + items: [ + { text: "Character Select", link: "/plugins/character-select" }, + ] }] const GA_ID = 'G-VCPFWQS1BJ' diff --git a/docs/.vitepress/theme/components/PreferenceSwitch.vue b/docs/.vitepress/theme/components/PreferenceSwitch.vue index 365a3337..6937bfd8 100644 --- a/docs/.vitepress/theme/components/PreferenceSwitch.vue +++ b/docs/.vitepress/theme/components/PreferenceSwitch.vue @@ -9,7 +9,7 @@ import { const route = useRoute() const show = computed(() => - /^\/(guide|tutorial|examples|style-guide)\//.test(route.path) + /^\/(guide|tutorial|examples|style-guide|gui|advanced)\//.test(route.path) ) let isOpen = ref(true) diff --git a/docs/gui/_trigger-tooltip.md b/docs/gui/_trigger-tooltip.md new file mode 100644 index 00000000..6ba6d37a --- /dev/null +++ b/docs/gui/_trigger-tooltip.md @@ -0,0 +1,122 @@ +## Trigger the GUI + +You have either the client side solution or the server side solution. + +- Advantage on the client side: instantaneous, no communication with the server +- Disadvantage: the server does not have the authority and cannot trigger it for all players at once + +On the server side, it's the opposite :) + +### Client Side + +1. you must open the menu, as usual (here, named `my-tooltip`) + +```ts +RpgGui.display('my-tooltip') +``` + +You can open it whenever you want, for example, after loading a map + +
+ +```ts +import { RpgClient, RpgModule, RpgGui } from '@rpgjs/client' +import myTooltip from './gui/tooltip.vue' +import sprite from './sprite' + +@RpgModule({ + scenes: { + map: { + onAfterLoading() { + RpgGui.display('my-tooltip') + } + } + }, + sprite, + gui: [ + myTooltip + ] +}) +export default class RpgClientModuleEngine {} +``` + + + +```ts +import { RpgSprite, RpgSpriteHooks } from '@rpgjs/client' + +export const sprite: RpgSpriteHooks = { + onInit(sprite: RpgSprite) { + sprite.interactive = true + sprite.on('click', () => { + sprite.guiDisplay = !sprite.guiDisplay + }) + } +} +``` + +
+ +
+ + + +```ts +import {RpgGui } from '@rpgjs/client' + +export default { + onAfterLoading() { + RpgGui.display('my-tooltip') + } +} +``` + +2. Then you can trigger the opening on the sprite + + + +```ts +import { RpgSprite, RpgSpriteHooks } from '@rpgjs/client' + +export const sprite: RpgSpriteHooks = { + onInit(sprite: RpgSprite) { + sprite.interactive = true + sprite.on('click', () => { + sprite.guiDisplay = !sprite.guiDisplay + }) + } +} +``` + +Clicking on the sprite opens (or closes) the tooltip + +
+ + +## Server Side + +> Even if we are on the server side, remember to add the GUI in the client side module + + + +```ts +import { RpgPlayer, RpgPlayerHooks } from '@rpgjs/server' + +export const player: RpgPlayerHooks = { + onJoinMap(player: RpgPlayer) { + player.gui('my-tooltip').open() + player.showAttachedGui() + // you can hide with player.hideAttachedGui() + } +} +``` + +We open the `my-tooltip` GUI and display the player's tooltip + +:::tip Tip +You can indicate which tooltips you want to display by specifying the events (or players) in parameter: + +```ts +player.showAttachedGui([otherEvent, otherPlayer]) +``` +::: \ No newline at end of file diff --git a/docs/gui/react-tooltip.md b/docs/gui/react-tooltip.md new file mode 100644 index 00000000..ca5436e6 --- /dev/null +++ b/docs/gui/react-tooltip.md @@ -0,0 +1,35 @@ +# Create a GUI attached to a sprite + +## Prerequisites + +- Know how to create a GUI and add it in the module +- Be comfortable with React +- Since v4.1.0 + +::: warning +**Experimental Feature**: This feature is still in its experimental stage and may not be stable. +::: + +## Example + +This is very useful to make more advanced interactions on a sprite. For example, display a tooltip or additional interactive displays. + +