Feature - Rentable Spaces

This commit is contained in:
oobjectt 2023-04-08 21:24:18 +02:00
parent aba4ddf2db
commit b390afc25c
4 changed files with 163 additions and 1 deletions

View File

@ -0,0 +1,43 @@
import { FriendlyTime } from '@nitrots/nitro-renderer';
import { FC } from 'react';
import { LocalizeText } from '../../../../api';
import { Button, Column, Flex, LayoutCurrencyIcon, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common';
import { useFurnitureRentableSpaceWidget } from '../../../../hooks';
export const FurnitureRentableSpaceView: FC<{}> = props =>
{
const { renter, isRoomOwner, onRent, onCancelRent, onClose } = useFurnitureRentableSpaceWidget();
if(!renter) return null;
return (
<NitroCardView className="nitro-guide-tool no-resize" theme="primary-slim">
<NitroCardHeaderView headerText={ LocalizeText('rentablespace.widget.title') } onCloseClick={ onClose } />
<NitroCardContentView className="text-black">
<Column>
{ (!renter.rented) &&
<>
<Text>{ LocalizeText('rentablespace.widget.instructions') }</Text>
<Flex pointer center className="p-2 bg-primary border border-dark rounded text-light h3" onClick={ onRent }>
{ renter.price + ' x' }&nbsp;
<LayoutCurrencyIcon type={ -1 } className="mt-1" />&nbsp;
{ LocalizeText('catalog.purchase_confirmation.rent') }
</Flex>
</>
}
{ (renter.rented) &&
<>
<Text bold>{ LocalizeText('rentablespace.widget.rented_to_label') }</Text>
<Text italics>{ renter.renterName }</Text>
<Text bold>{ LocalizeText('rentablespace.widget.expires_label') }</Text>
<Text italics>{ FriendlyTime.shortFormat(renter.timeRemaining) }</Text>
{ (isRoomOwner) &&
<Button variant="danger" className="mt-2" onClick={ onCancelRent }>{ LocalizeText('rentablespace.widget.cancel_rent') }</Button> }
</>
}
</Column>
</NitroCardContentView>
</NitroCardView>
);
}

View File

@ -1,6 +1,5 @@
import { FC } from 'react';
import { Base } from '../../../../common';
import { FurnitureContextMenuView } from './context-menu/FurnitureContextMenuView';
import { FurnitureBackgroundColorView } from './FurnitureBackgroundColorView';
import { FurnitureBadgeDisplayView } from './FurnitureBadgeDisplayView';
import { FurnitureCraftingView } from './FurnitureCraftingView';
@ -12,12 +11,14 @@ import { FurnitureGiftOpeningView } from './FurnitureGiftOpeningView';
import { FurnitureHighScoreView } from './FurnitureHighScoreView';
import { FurnitureInternalLinkView } from './FurnitureInternalLinkView';
import { FurnitureMannequinView } from './FurnitureMannequinView';
import { FurnitureRentableSpaceView } from './FurnitureRentableSpaceView';
import { FurnitureRoomLinkView } from './FurnitureRoomLinkView';
import { FurnitureSpamWallPostItView } from './FurnitureSpamWallPostItView';
import { FurnitureStackHeightView } from './FurnitureStackHeightView';
import { FurnitureStickieView } from './FurnitureStickieView';
import { FurnitureTrophyView } from './FurnitureTrophyView';
import { FurnitureYoutubeDisplayView } from './FurnitureYoutubeDisplayView';
import { FurnitureContextMenuView } from './context-menu/FurnitureContextMenuView';
import { FurniturePlaylistEditorWidgetView } from './playlist-editor/FurniturePlaylistEditorWidgetView';
export const FurnitureWidgetsView: FC<{}> = props =>
@ -43,6 +44,7 @@ export const FurnitureWidgetsView: FC<{}> = props =>
<FurnitureTrophyView />
<FurnitureContextMenuView />
<FurnitureYoutubeDisplayView />
<FurnitureRentableSpaceView />
</Base>
);
}

View File

@ -11,6 +11,7 @@ export * from './useFurnitureInternalLinkWidget';
export * from './useFurnitureMannequinWidget';
export * from './useFurniturePlaylistEditorWidget';
export * from './useFurniturePresentWidget';
export * from './useFurnitureRentableSpaceWidget';
export * from './useFurnitureRoomLinkWidget';
export * from './useFurnitureSpamWallPostItWidget';
export * from './useFurnitureStackHeightWidget';

View File

@ -0,0 +1,116 @@
import { RentableSpaceCancelRentMessageComposer, RentableSpaceRentMessageComposer, RentableSpaceStatusMessageEvent, RentableSpaceStatusMessageParser, RoomEngineTriggerWidgetEvent, RoomWidgetEnum } from '@nitrots/nitro-renderer';
import { useState } from 'react';
import { GetRoomEngine, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../../api';
import { useMessageEvent, useRoomEngineEvent } from '../../../events';
import { useNavigator } from '../../../navigator';
import { useNotification } from '../../../notification';
import { useFurniRemovedEvent } from '../../engine';
const useFurnitureRentableSpaceWidgetState = () =>
{
const [ renter, setRenter ] = useState<RentableSpaceStatusMessageParser>(null);
const [ itemId, setItemId ] = useState<number>(-1);
const [ category, setCategory ] = useState<number>(-1);
const { navigatorData = null } = useNavigator();
const { simpleAlert } = useNotification();
const isRoomOwner = GetSessionDataManager().userName === navigatorData.enteredGuestRoom.ownerName;
const onClose = () =>
{
setItemId(-1);
setCategory(-1);
setRenter(null);
}
const onRent = () =>
{
if (!itemId) return;
SendMessageComposer(new RentableSpaceRentMessageComposer(itemId));
}
const onCancelRent = () =>
{
if (!itemId) return;
SendMessageComposer(new RentableSpaceCancelRentMessageComposer(itemId));
onClose();
}
const getRentErrorCode = (code: number) =>
{
let errorAlert = '';
switch(code)
{
case RentableSpaceStatusMessageParser.SPACE_ALREADY_RENTED:
errorAlert = LocalizeText('rentablespace.widget.error_reason_already_rented');
break;
case RentableSpaceStatusMessageParser.SPACE_EXTEND_NOT_RENTED:
errorAlert = LocalizeText('rentablespace.widget.error_reason_not_rented');
break;
case RentableSpaceStatusMessageParser.SPACE_EXTEND_NOT_RENTED_BY_YOU:
errorAlert = LocalizeText('rentablespace.widget.error_reason_not_rented_by_you');
break;
case RentableSpaceStatusMessageParser.CAN_RENT_ONLY_ONE_SPACE:
errorAlert = LocalizeText('rentablespace.widget.error_reason_can_rent_only_one_space');
break;
case RentableSpaceStatusMessageParser.NOT_ENOUGH_CREDITS:
errorAlert = LocalizeText('rentablespace.widget.error_reason_not_enough_credits');
break;
case RentableSpaceStatusMessageParser.NOT_ENOUGH_PIXELS:
errorAlert = LocalizeText('rentablespace.widget.error_reason_not_enough_duckets');
break;
case RentableSpaceStatusMessageParser.CANT_RENT_NO_PERMISSION:
errorAlert = LocalizeText('rentablespace.widget.error_reason_no_permission');
break;
case RentableSpaceStatusMessageParser.CANT_RENT_NO_HABBO_CLUB:
errorAlert = LocalizeText('rentablespace.widget.error_reason_no_habboclub');
break;
case RentableSpaceStatusMessageParser.CANT_RENT:
errorAlert = LocalizeText('rentablespace.widget.error_reason_disabled');
break;
case RentableSpaceStatusMessageParser.CANT_RENT_GENERIC:
errorAlert = LocalizeText('rentablespace.widget.error_reason_generic');
break;
}
onClose();
return simpleAlert(errorAlert);
}
useRoomEngineEvent<RoomEngineTriggerWidgetEvent>(RoomEngineTriggerWidgetEvent.OPEN_WIDGET, event =>
{
if (event.widget !== RoomWidgetEnum.RENTABLESPACE) return;
const roomObject = GetRoomEngine().getRoomObject(event.roomId, event.objectId, event.category);
if(!roomObject) return;
setItemId(roomObject.id);
setCategory(event.category);
});
useFurniRemovedEvent(((itemId !== -1) && (category !== -1)), event =>
{
if((event.id !== itemId) || (event.category !== category)) return;
onCancelRent();
});
useMessageEvent<RentableSpaceStatusMessageEvent>(RentableSpaceStatusMessageEvent, event =>
{
const parser = event.getParser();
if (!parser) return;
if (parser.canRentErrorCode !== 0 && (!isRoomOwner || !GetSessionDataManager().isModerator) || (parser.renterName === '' && parser.canRentErrorCode !== 0)) return getRentErrorCode(parser.canRentErrorCode);
setRenter(parser);
});
return { renter, isRoomOwner, onRent, onCancelRent, onClose };
}
export const useFurnitureRentableSpaceWidget = useFurnitureRentableSpaceWidgetState;