Stuyk/altv-athena

Make UIs Toggleable with Key Used to Open Them

Stuyk opened this issue · 2 comments

Stuyk commented

When you open an inventory with i you should be able to close it with i.

Taken from Discord from KeRR.

please assign me this issue

Stuyk commented

This can be done with the new simplified page constructor.

import * as alt from 'alt-client';
import { AthenaClient } from '@AthenaClient/api/athena';

function onReady() {
    AthenaClient.webview.emit('do:something...', 'hi');
}

function onClose() {
    // Nothing actually needs to be done.
    // The internal controller handled it all.
}

const page = new AthenaClient.webview.page({
    name: 'Designs',
    callbacks: { onReady, onClose },
    options: {
        onOpen: {
            disableControls: true,
            blurBackground: true,
            focus: true,
            hideHud: true,
            hideOverlays: true,
            setIsMenuOpenToTrue: true,
            showCursor: true,
        },
        onClose: {
            enableControls: true,
            hideCursor: true,
            setIsMenuOpenToFalse: true,
            showHud: true,
            showOverlays: true,
            unblurBackground: true,
            unfocus: true,
        },
    },
    keybind: {
        key: 75, // k
        isLongPress: true,
        useSameKeyToClose: true, // <-----
    },
});

alt.onServer('openMyPage', page.open);
alt.onServer('forceCloseMyPage', () => {
    page.close(true);
});