mirror of
https://github.com/duckietm/Nitro-Cool-UI.git
synced 2025-06-21 22:36:58 +00:00
🆙 WiredConditionFurniHasAvatarOnView
This commit is contained in:
parent
381617c3bd
commit
6a89143759
@ -5,6 +5,12 @@ import { GetRoomEngine } from '..';
|
||||
export class WiredSelectionVisualizer
|
||||
{
|
||||
private static _selectionShader: NitroFilter = new WiredSelectionFilter([ 1, 1, 1 ], [ 0.6, 0.6, 0.6 ]);
|
||||
private static _maxItemSelectionCount: number = 0;
|
||||
|
||||
public static setMaxItemSelectionCount(count: number): void
|
||||
{
|
||||
WiredSelectionVisualizer._maxItemSelectionCount = count;
|
||||
}
|
||||
|
||||
public static show(furniId: number): void
|
||||
{
|
||||
|
@ -4,90 +4,73 @@ import { Button, Column, Flex, NitroCardContentView, NitroCardHeaderView, NitroC
|
||||
import { useWired } from '../../../hooks';
|
||||
import { WiredFurniSelectorView } from './WiredFurniSelectorView';
|
||||
|
||||
export interface WiredBaseViewProps
|
||||
{
|
||||
export interface WiredBaseViewProps {
|
||||
wiredType: string;
|
||||
requiresFurni: number;
|
||||
hasSpecialInput: boolean;
|
||||
save: () => void;
|
||||
validate?: () => boolean;
|
||||
maxItemSelectionCount?: number;
|
||||
maxItemSelectionCount?: number; // Optional parameter
|
||||
}
|
||||
|
||||
export const WiredBaseView: FC<PropsWithChildren<WiredBaseViewProps>> = props =>
|
||||
{
|
||||
const { wiredType = '', requiresFurni = WiredFurniType.STUFF_SELECTION_OPTION_NONE, save = null, validate = null, children = null, hasSpecialInput = false, maxItemSelectionCount = 5 } = props; // Default to 5
|
||||
export const WiredBaseView: FC<PropsWithChildren<WiredBaseViewProps>> = props => {
|
||||
const { wiredType = '', requiresFurni = WiredFurniType.STUFF_SELECTION_OPTION_NONE, save = null, validate = null, children = null, hasSpecialInput = false, maxItemSelectionCount = 5 } = props;
|
||||
const [wiredName, setWiredName] = useState<string>(null);
|
||||
const [wiredDescription, setWiredDescription] = useState<string>(null);
|
||||
const [needsSave, setNeedsSave] = useState<boolean>(false);
|
||||
const { trigger = null, setTrigger = null, setIntParams = null, setStringParam = null, setFurniIds = null, setAllowsFurni = null, saveWired = null } = useWired();
|
||||
const { trigger, setTrigger, setIntParams, setStringParam, setFurniIds, setAllowsFurni, saveWired, setMaxItemSelectionCount: setMaxCount } = useWired();
|
||||
|
||||
useEffect(() => {
|
||||
setMaxCount(maxItemSelectionCount);
|
||||
}, [maxItemSelectionCount, setMaxCount]);
|
||||
|
||||
const onClose = () => setTrigger(null);
|
||||
|
||||
const onSave = () =>
|
||||
{
|
||||
const onSave = () => {
|
||||
if (validate && !validate()) return;
|
||||
|
||||
if (save) save();
|
||||
|
||||
setNeedsSave(true);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
useEffect(() => {
|
||||
if (!needsSave) return;
|
||||
|
||||
saveWired();
|
||||
|
||||
setNeedsSave(false);
|
||||
}, [needsSave, saveWired]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
useEffect(() => {
|
||||
if (!trigger) return;
|
||||
|
||||
const spriteId = (trigger.spriteId || -1);
|
||||
const spriteId = trigger.spriteId || -1;
|
||||
const furniData = GetSessionDataManager().getFloorItemData(spriteId);
|
||||
|
||||
if(!furniData)
|
||||
{
|
||||
setWiredName(('NAME: ' + spriteId));
|
||||
setWiredDescription(('NAME: ' + spriteId));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!furniData) {
|
||||
setWiredName('NAME: ' + spriteId);
|
||||
setWiredDescription('NAME: ' + spriteId);
|
||||
} else {
|
||||
setWiredName(furniData.name);
|
||||
setWiredDescription(furniData.description);
|
||||
}
|
||||
|
||||
if(hasSpecialInput)
|
||||
{
|
||||
if (hasSpecialInput) {
|
||||
setIntParams(trigger.intData);
|
||||
setStringParam(trigger.stringData);
|
||||
}
|
||||
|
||||
if(requiresFurni > WiredFurniType.STUFF_SELECTION_OPTION_NONE)
|
||||
{
|
||||
setFurniIds(prevValue =>
|
||||
{
|
||||
if (requiresFurni > WiredFurniType.STUFF_SELECTION_OPTION_NONE) {
|
||||
setFurniIds(prevValue => {
|
||||
if (prevValue && prevValue.length) WiredSelectionVisualizer.clearSelectionShaderFromFurni(prevValue);
|
||||
|
||||
if(trigger.selectedItems && trigger.selectedItems.length)
|
||||
{
|
||||
if (trigger.selectedItems && trigger.selectedItems.length) {
|
||||
WiredSelectionVisualizer.applySelectionShaderToFurni(trigger.selectedItems);
|
||||
|
||||
return trigger.selectedItems;
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
setAllowsFurni(requiresFurni);
|
||||
|
||||
// Set max item selection count
|
||||
WiredSelectionVisualizer.setMaxItemSelectionCount(maxItemSelectionCount); // Use the passed value
|
||||
|
||||
if (WiredSelectionVisualizer.setMaxItemSelectionCount) {
|
||||
WiredSelectionVisualizer.setMaxItemSelectionCount(maxItemSelectionCount);
|
||||
}
|
||||
}, [trigger, hasSpecialInput, requiresFurni, setIntParams, setStringParam, setFurniIds, setAllowsFurni, maxItemSelectionCount]);
|
||||
|
||||
return (
|
||||
@ -103,11 +86,12 @@ export const WiredBaseView: FC<PropsWithChildren<WiredBaseViewProps>> = props =>
|
||||
</Column>
|
||||
{!!children && <hr className="m-0 bg-dark" />}
|
||||
{children}
|
||||
{ (requiresFurni > WiredFurniType.STUFF_SELECTION_OPTION_NONE) &&
|
||||
{requiresFurni > WiredFurniType.STUFF_SELECTION_OPTION_NONE && (
|
||||
<>
|
||||
<hr className="m-0 bg-dark" />
|
||||
<WiredFurniSelectorView maxItemSelectionCount={ maxItemSelectionCount } /> {/* Pass the count */}
|
||||
</> }
|
||||
<WiredFurniSelectorView maxItemSelectionCount={maxItemSelectionCount} />
|
||||
</>
|
||||
)}
|
||||
<Flex alignItems="center" gap={1}>
|
||||
<Button fullWidth variant="success" onClick={onSave}>{LocalizeText('wiredfurni.ready')}</Button>
|
||||
<Button fullWidth variant="secondary" onClick={onClose}>{LocalizeText('cancel')}</Button>
|
||||
@ -115,4 +99,4 @@ export const WiredBaseView: FC<PropsWithChildren<WiredBaseViewProps>> = props =>
|
||||
</NitroCardContentView>
|
||||
</NitroCardView>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -3,23 +3,25 @@ import { LocalizeText } from '../../../api';
|
||||
import { Column, Text } from '../../../common';
|
||||
import { useWired } from '../../../hooks';
|
||||
|
||||
export interface WiredFurniSelectorViewProps
|
||||
{
|
||||
export interface WiredFurniSelectorViewProps {
|
||||
maxItemSelectionCount: number;
|
||||
}
|
||||
|
||||
export const WiredFurniSelectorView: FC<WiredFurniSelectorViewProps> = props =>
|
||||
{
|
||||
export const WiredFurniSelectorView: FC<WiredFurniSelectorViewProps> = props => {
|
||||
const { maxItemSelectionCount } = props;
|
||||
const { trigger = null, furniIds = [] } = useWired();
|
||||
const { furniIds, selectObjectForWired } = useWired();
|
||||
|
||||
// Enforce the selection limit
|
||||
const selectionText = LocalizeText('wiredfurni.pickfurnis.caption', ['count', 'limit'], [furniIds.length.toString(), maxItemSelectionCount.toString()]);
|
||||
|
||||
const onSelectFurni = (furniId: number) => {
|
||||
selectObjectForWired(furniId, 0);
|
||||
};
|
||||
|
||||
return (
|
||||
<Column gap={1}>
|
||||
<Text bold>{selectionText}</Text>
|
||||
<Text small>{LocalizeText('wiredfurni.pickfurnis.desc')}</Text>
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -2,22 +2,25 @@ import { FC, PropsWithChildren } from 'react';
|
||||
import { WiredFurniType } from '../../../../api';
|
||||
import { WiredBaseView } from '../WiredBaseView';
|
||||
|
||||
export interface WiredConditionBaseViewProps
|
||||
{
|
||||
export interface WiredConditionBaseViewProps {
|
||||
hasSpecialInput: boolean;
|
||||
requiresFurni: number;
|
||||
save: () => void;
|
||||
maxItemSelectionCount?: number; // Optional parameter
|
||||
}
|
||||
|
||||
export const WiredConditionBaseView: FC<PropsWithChildren<WiredConditionBaseViewProps>> = props =>
|
||||
{
|
||||
export const WiredConditionBaseView: FC<PropsWithChildren<WiredConditionBaseViewProps>> = props => {
|
||||
const { requiresFurni = WiredFurniType.STUFF_SELECTION_OPTION_NONE, save = null, hasSpecialInput = false, children = null, maxItemSelectionCount = 5 } = props;
|
||||
|
||||
const onSave = () => (save && save());
|
||||
|
||||
return (
|
||||
<WiredBaseView wiredType="condition" requiresFurni={ requiresFurni } hasSpecialInput={ hasSpecialInput } save={ onSave } maxItemSelectionCount={ maxItemSelectionCount }>
|
||||
<WiredBaseView
|
||||
wiredType="condition"
|
||||
requiresFurni={requiresFurni}
|
||||
hasSpecialInput={hasSpecialInput}
|
||||
save={onSave}
|
||||
maxItemSelectionCount={maxItemSelectionCount}>
|
||||
{children}
|
||||
</WiredBaseView>
|
||||
);
|
||||
|
@ -1,8 +1,42 @@
|
||||
import { FC } from 'react';
|
||||
import { WiredFurniType } from '../../../../api';
|
||||
import { FC, useState } from 'react';
|
||||
import { LocalizeText, WiredFurniType } from '../../../../api';
|
||||
import { Column, Flex, Text } from '../../../../common';
|
||||
import { WiredConditionBaseView } from './WiredConditionBaseView';
|
||||
|
||||
export const WiredConditionFurniHasAvatarOnView: FC<{}> = props =>
|
||||
{
|
||||
return <WiredConditionBaseView requiresFurni={ WiredFurniType.STUFF_SELECTION_OPTION_BY_ID } hasSpecialInput={ false } save={ null } maxItemSelectionCount={ 1 } />;
|
||||
}
|
||||
export const WiredConditionFurniHasAvatarOnView: FC<{}> = props => {
|
||||
const [requireAll, setRequireAll] = useState<number>(5); // Default to 5
|
||||
|
||||
const handleRadioChange = (value: number) => {
|
||||
setRequireAll(value);
|
||||
};
|
||||
|
||||
return (
|
||||
<WiredConditionBaseView
|
||||
requiresFurni={WiredFurniType.STUFF_SELECTION_OPTION_BY_ID}
|
||||
hasSpecialInput={false}
|
||||
save={null}
|
||||
maxItemSelectionCount={requireAll}
|
||||
>
|
||||
<Column gap={1}>
|
||||
<Text bold>{LocalizeText('wiredfurni.params.requireall.caption')}</Text>
|
||||
{[1, 5].map(value => (
|
||||
<Flex key={value} gap={1} alignItems="center">
|
||||
<input
|
||||
className="form-check-input"
|
||||
type="radio"
|
||||
name="requireAll"
|
||||
id={`requireAll${value}`}
|
||||
checked={requireAll === value}
|
||||
onChange={() => handleRadioChange(value)}
|
||||
/>
|
||||
<label className="text-black form-check-label" htmlFor={`requireAll${value}`}>
|
||||
{value === 1
|
||||
? LocalizeText('wiredfurni.params.requireall.2')
|
||||
: LocalizeText('wiredfurni.params.requireall.3')}
|
||||
</label>
|
||||
</Flex>
|
||||
))}
|
||||
</Column>
|
||||
</WiredConditionBaseView>
|
||||
);
|
||||
};
|
||||
|
@ -13,7 +13,8 @@ const useWiredState = () =>
|
||||
const [ furniIds, setFurniIds ] = useState<number[]>([]);
|
||||
const [ actionDelay, setActionDelay ] = useState<number>(0);
|
||||
const [ allowsFurni, setAllowsFurni ] = useState<number>(WiredFurniType.STUFF_SELECTION_OPTION_NONE);
|
||||
const { showConfirm = null } = useNotification();
|
||||
const [ maxItemSelectionCount, setMaxItemSelectionCount ] = useState<number>(5);
|
||||
const { showConfirm } = useNotification();
|
||||
|
||||
const saveWired = () =>
|
||||
{
|
||||
@ -69,7 +70,7 @@ const useWiredState = () =>
|
||||
WiredSelectionVisualizer.hide(objectId);
|
||||
}
|
||||
|
||||
else if(newFurniIds.length < trigger.maximumItemSelectionCount)
|
||||
else if(newFurniIds.length < maxItemSelectionCount)
|
||||
{
|
||||
newFurniIds.push(objectId);
|
||||
|
||||
@ -127,7 +128,7 @@ const useWiredState = () =>
|
||||
}
|
||||
}, [ trigger ]);
|
||||
|
||||
return { trigger, setTrigger, intParams, setIntParams, stringParam, setStringParam, furniIds, setFurniIds, actionDelay, setActionDelay, setAllowsFurni, saveWired, selectObjectForWired };
|
||||
return { trigger, setTrigger, intParams, setIntParams, stringParam, setStringParam, furniIds, setFurniIds, actionDelay, setActionDelay, setAllowsFurni, saveWired, selectObjectForWired, maxItemSelectionCount, setMaxItemSelectionCount };
|
||||
}
|
||||
|
||||
export const useWired = () => useBetween(useWiredState);
|
Loading…
x
Reference in New Issue
Block a user