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
|
export class WiredSelectionVisualizer
|
||||||
{
|
{
|
||||||
private static _selectionShader: NitroFilter = new WiredSelectionFilter([ 1, 1, 1 ], [ 0.6, 0.6, 0.6 ]);
|
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
|
public static show(furniId: number): void
|
||||||
{
|
{
|
||||||
|
@ -4,90 +4,73 @@ import { Button, Column, Flex, NitroCardContentView, NitroCardHeaderView, NitroC
|
|||||||
import { useWired } from '../../../hooks';
|
import { useWired } from '../../../hooks';
|
||||||
import { WiredFurniSelectorView } from './WiredFurniSelectorView';
|
import { WiredFurniSelectorView } from './WiredFurniSelectorView';
|
||||||
|
|
||||||
export interface WiredBaseViewProps
|
export interface WiredBaseViewProps {
|
||||||
{
|
|
||||||
wiredType: string;
|
wiredType: string;
|
||||||
requiresFurni: number;
|
requiresFurni: number;
|
||||||
hasSpecialInput: boolean;
|
hasSpecialInput: boolean;
|
||||||
save: () => void;
|
save: () => void;
|
||||||
validate?: () => boolean;
|
validate?: () => boolean;
|
||||||
maxItemSelectionCount?: number;
|
maxItemSelectionCount?: number; // Optional parameter
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WiredBaseView: FC<PropsWithChildren<WiredBaseViewProps>> = props =>
|
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 { wiredType = '', requiresFurni = WiredFurniType.STUFF_SELECTION_OPTION_NONE, save = null, validate = null, children = null, hasSpecialInput = false, maxItemSelectionCount = 5 } = props; // Default to 5
|
|
||||||
const [wiredName, setWiredName] = useState<string>(null);
|
const [wiredName, setWiredName] = useState<string>(null);
|
||||||
const [wiredDescription, setWiredDescription] = useState<string>(null);
|
const [wiredDescription, setWiredDescription] = useState<string>(null);
|
||||||
const [needsSave, setNeedsSave] = useState<boolean>(false);
|
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 onClose = () => setTrigger(null);
|
||||||
|
|
||||||
const onSave = () =>
|
const onSave = () => {
|
||||||
{
|
|
||||||
if (validate && !validate()) return;
|
if (validate && !validate()) return;
|
||||||
|
|
||||||
if (save) save();
|
if (save) save();
|
||||||
|
|
||||||
setNeedsSave(true);
|
setNeedsSave(true);
|
||||||
}
|
};
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() => {
|
||||||
{
|
|
||||||
if (!needsSave) return;
|
if (!needsSave) return;
|
||||||
|
|
||||||
saveWired();
|
saveWired();
|
||||||
|
|
||||||
setNeedsSave(false);
|
setNeedsSave(false);
|
||||||
}, [needsSave, saveWired]);
|
}, [needsSave, saveWired]);
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() => {
|
||||||
{
|
|
||||||
if (!trigger) return;
|
if (!trigger) return;
|
||||||
|
const spriteId = trigger.spriteId || -1;
|
||||||
const spriteId = (trigger.spriteId || -1);
|
|
||||||
const furniData = GetSessionDataManager().getFloorItemData(spriteId);
|
const furniData = GetSessionDataManager().getFloorItemData(spriteId);
|
||||||
|
|
||||||
if(!furniData)
|
if (!furniData) {
|
||||||
{
|
setWiredName('NAME: ' + spriteId);
|
||||||
setWiredName(('NAME: ' + spriteId));
|
setWiredDescription('NAME: ' + spriteId);
|
||||||
setWiredDescription(('NAME: ' + spriteId));
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setWiredName(furniData.name);
|
setWiredName(furniData.name);
|
||||||
setWiredDescription(furniData.description);
|
setWiredDescription(furniData.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasSpecialInput)
|
if (hasSpecialInput) {
|
||||||
{
|
|
||||||
setIntParams(trigger.intData);
|
setIntParams(trigger.intData);
|
||||||
setStringParam(trigger.stringData);
|
setStringParam(trigger.stringData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(requiresFurni > WiredFurniType.STUFF_SELECTION_OPTION_NONE)
|
if (requiresFurni > WiredFurniType.STUFF_SELECTION_OPTION_NONE) {
|
||||||
{
|
setFurniIds(prevValue => {
|
||||||
setFurniIds(prevValue =>
|
|
||||||
{
|
|
||||||
if (prevValue && prevValue.length) WiredSelectionVisualizer.clearSelectionShaderFromFurni(prevValue);
|
if (prevValue && prevValue.length) WiredSelectionVisualizer.clearSelectionShaderFromFurni(prevValue);
|
||||||
|
if (trigger.selectedItems && trigger.selectedItems.length) {
|
||||||
if(trigger.selectedItems && trigger.selectedItems.length)
|
|
||||||
{
|
|
||||||
WiredSelectionVisualizer.applySelectionShaderToFurni(trigger.selectedItems);
|
WiredSelectionVisualizer.applySelectionShaderToFurni(trigger.selectedItems);
|
||||||
|
|
||||||
return trigger.selectedItems;
|
return trigger.selectedItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setAllowsFurni(requiresFurni);
|
setAllowsFurni(requiresFurni);
|
||||||
|
if (WiredSelectionVisualizer.setMaxItemSelectionCount) {
|
||||||
// Set max item selection count
|
WiredSelectionVisualizer.setMaxItemSelectionCount(maxItemSelectionCount);
|
||||||
WiredSelectionVisualizer.setMaxItemSelectionCount(maxItemSelectionCount); // Use the passed value
|
}
|
||||||
|
|
||||||
}, [trigger, hasSpecialInput, requiresFurni, setIntParams, setStringParam, setFurniIds, setAllowsFurni, maxItemSelectionCount]);
|
}, [trigger, hasSpecialInput, requiresFurni, setIntParams, setStringParam, setFurniIds, setAllowsFurni, maxItemSelectionCount]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -103,11 +86,12 @@ export const WiredBaseView: FC<PropsWithChildren<WiredBaseViewProps>> = props =>
|
|||||||
</Column>
|
</Column>
|
||||||
{!!children && <hr className="m-0 bg-dark" />}
|
{!!children && <hr className="m-0 bg-dark" />}
|
||||||
{children}
|
{children}
|
||||||
{ (requiresFurni > WiredFurniType.STUFF_SELECTION_OPTION_NONE) &&
|
{requiresFurni > WiredFurniType.STUFF_SELECTION_OPTION_NONE && (
|
||||||
<>
|
<>
|
||||||
<hr className="m-0 bg-dark" />
|
<hr className="m-0 bg-dark" />
|
||||||
<WiredFurniSelectorView maxItemSelectionCount={ maxItemSelectionCount } /> {/* Pass the count */}
|
<WiredFurniSelectorView maxItemSelectionCount={maxItemSelectionCount} />
|
||||||
</> }
|
</>
|
||||||
|
)}
|
||||||
<Flex alignItems="center" gap={1}>
|
<Flex alignItems="center" gap={1}>
|
||||||
<Button fullWidth variant="success" onClick={onSave}>{LocalizeText('wiredfurni.ready')}</Button>
|
<Button fullWidth variant="success" onClick={onSave}>{LocalizeText('wiredfurni.ready')}</Button>
|
||||||
<Button fullWidth variant="secondary" onClick={onClose}>{LocalizeText('cancel')}</Button>
|
<Button fullWidth variant="secondary" onClick={onClose}>{LocalizeText('cancel')}</Button>
|
||||||
@ -115,4 +99,4 @@ export const WiredBaseView: FC<PropsWithChildren<WiredBaseViewProps>> = props =>
|
|||||||
</NitroCardContentView>
|
</NitroCardContentView>
|
||||||
</NitroCardView>
|
</NitroCardView>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
@ -3,23 +3,25 @@ import { LocalizeText } from '../../../api';
|
|||||||
import { Column, Text } from '../../../common';
|
import { Column, Text } from '../../../common';
|
||||||
import { useWired } from '../../../hooks';
|
import { useWired } from '../../../hooks';
|
||||||
|
|
||||||
export interface WiredFurniSelectorViewProps
|
export interface WiredFurniSelectorViewProps {
|
||||||
{
|
|
||||||
maxItemSelectionCount: number;
|
maxItemSelectionCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WiredFurniSelectorView: FC<WiredFurniSelectorViewProps> = props =>
|
export const WiredFurniSelectorView: FC<WiredFurniSelectorViewProps> = props => {
|
||||||
{
|
|
||||||
const { maxItemSelectionCount } = props;
|
const { maxItemSelectionCount } = props;
|
||||||
const { trigger = null, furniIds = [] } = useWired();
|
const { furniIds, selectObjectForWired } = useWired();
|
||||||
|
|
||||||
// Enforce the selection limit
|
// Enforce the selection limit
|
||||||
const selectionText = LocalizeText('wiredfurni.pickfurnis.caption', ['count', 'limit'], [furniIds.length.toString(), maxItemSelectionCount.toString()]);
|
const selectionText = LocalizeText('wiredfurni.pickfurnis.caption', ['count', 'limit'], [furniIds.length.toString(), maxItemSelectionCount.toString()]);
|
||||||
|
|
||||||
|
const onSelectFurni = (furniId: number) => {
|
||||||
|
selectObjectForWired(furniId, 0);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column gap={1}>
|
<Column gap={1}>
|
||||||
<Text bold>{selectionText}</Text>
|
<Text bold>{selectionText}</Text>
|
||||||
<Text small>{LocalizeText('wiredfurni.pickfurnis.desc')}</Text>
|
<Text small>{LocalizeText('wiredfurni.pickfurnis.desc')}</Text>
|
||||||
</Column>
|
</Column>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
@ -2,22 +2,25 @@ import { FC, PropsWithChildren } from 'react';
|
|||||||
import { WiredFurniType } from '../../../../api';
|
import { WiredFurniType } from '../../../../api';
|
||||||
import { WiredBaseView } from '../WiredBaseView';
|
import { WiredBaseView } from '../WiredBaseView';
|
||||||
|
|
||||||
export interface WiredConditionBaseViewProps
|
export interface WiredConditionBaseViewProps {
|
||||||
{
|
|
||||||
hasSpecialInput: boolean;
|
hasSpecialInput: boolean;
|
||||||
requiresFurni: number;
|
requiresFurni: number;
|
||||||
save: () => void;
|
save: () => void;
|
||||||
maxItemSelectionCount?: number; // Optional parameter
|
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 { requiresFurni = WiredFurniType.STUFF_SELECTION_OPTION_NONE, save = null, hasSpecialInput = false, children = null, maxItemSelectionCount = 5 } = props;
|
||||||
|
|
||||||
const onSave = () => (save && save());
|
const onSave = () => (save && save());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WiredBaseView wiredType="condition" requiresFurni={ requiresFurni } hasSpecialInput={ hasSpecialInput } save={ onSave } maxItemSelectionCount={ maxItemSelectionCount }>
|
<WiredBaseView
|
||||||
|
wiredType="condition"
|
||||||
|
requiresFurni={requiresFurni}
|
||||||
|
hasSpecialInput={hasSpecialInput}
|
||||||
|
save={onSave}
|
||||||
|
maxItemSelectionCount={maxItemSelectionCount}>
|
||||||
{children}
|
{children}
|
||||||
</WiredBaseView>
|
</WiredBaseView>
|
||||||
);
|
);
|
||||||
|
@ -1,8 +1,42 @@
|
|||||||
import { FC } from 'react';
|
import { FC, useState } from 'react';
|
||||||
import { WiredFurniType } from '../../../../api';
|
import { LocalizeText, WiredFurniType } from '../../../../api';
|
||||||
|
import { Column, Flex, Text } from '../../../../common';
|
||||||
import { WiredConditionBaseView } from './WiredConditionBaseView';
|
import { WiredConditionBaseView } from './WiredConditionBaseView';
|
||||||
|
|
||||||
export const WiredConditionFurniHasAvatarOnView: FC<{}> = props =>
|
export const WiredConditionFurniHasAvatarOnView: FC<{}> = props => {
|
||||||
{
|
const [requireAll, setRequireAll] = useState<number>(5); // Default to 5
|
||||||
return <WiredConditionBaseView requiresFurni={ WiredFurniType.STUFF_SELECTION_OPTION_BY_ID } hasSpecialInput={ false } save={ null } maxItemSelectionCount={ 1 } />;
|
|
||||||
}
|
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 [ furniIds, setFurniIds ] = useState<number[]>([]);
|
||||||
const [ actionDelay, setActionDelay ] = useState<number>(0);
|
const [ actionDelay, setActionDelay ] = useState<number>(0);
|
||||||
const [ allowsFurni, setAllowsFurni ] = useState<number>(WiredFurniType.STUFF_SELECTION_OPTION_NONE);
|
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 = () =>
|
const saveWired = () =>
|
||||||
{
|
{
|
||||||
@ -69,7 +70,7 @@ const useWiredState = () =>
|
|||||||
WiredSelectionVisualizer.hide(objectId);
|
WiredSelectionVisualizer.hide(objectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(newFurniIds.length < trigger.maximumItemSelectionCount)
|
else if(newFurniIds.length < maxItemSelectionCount)
|
||||||
{
|
{
|
||||||
newFurniIds.push(objectId);
|
newFurniIds.push(objectId);
|
||||||
|
|
||||||
@ -127,7 +128,7 @@ const useWiredState = () =>
|
|||||||
}
|
}
|
||||||
}, [ trigger ]);
|
}, [ 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);
|
export const useWired = () => useBetween(useWiredState);
|
Loading…
x
Reference in New Issue
Block a user