GANG: Show equipments when there is not enough money (#1417)

This commit is contained in:
catloversg 2024-06-21 17:14:48 +07:00 committed by GitHub
parent a62bdcafef
commit 847d45f4f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -21,31 +21,6 @@ import { Settings } from "../../Settings/Settings";
import { StatsRow } from "../../ui/React/StatsRow"; import { StatsRow } from "../../ui/React/StatsRow";
import { useRerender } from "../../ui/React/hooks"; import { useRerender } from "../../ui/React/hooks";
interface INextRevealProps {
upgrades: string[];
type: UpgradeType;
}
function NextReveal(props: INextRevealProps): React.ReactElement {
const gang = useGang();
const upgrades = Object.keys(GangMemberUpgrades)
.filter((upgName: string) => {
const upg = GangMemberUpgrades[upgName];
if (Player.money > gang.getUpgradeCost(upg)) return false;
if (upg.type !== props.type) return false;
if (props.upgrades.includes(upgName)) return false;
return true;
})
.map((upgName: string) => GangMemberUpgrades[upgName]);
if (upgrades.length === 0) return <></>;
return (
<Typography>
Next at <Money money={gang.getUpgradeCost(upgrades[0])} />
</Typography>
);
}
function PurchasedUpgrade({ upgName }: { upgName: string }): React.ReactElement { function PurchasedUpgrade({ upgName }: { upgName: string }): React.ReactElement {
const upg = GangMemberUpgrades[upgName]; const upg = GangMemberUpgrades[upgName];
return ( return (
@ -65,6 +40,8 @@ interface IUpgradeButtonProps {
function UpgradeButton(props: IUpgradeButtonProps): React.ReactElement { function UpgradeButton(props: IUpgradeButtonProps): React.ReactElement {
const gang = useGang(); const gang = useGang();
const upgradeCost = gang.getUpgradeCost(props.upg);
const isUpgradable = Player.money >= upgradeCost;
function onClick(): void { function onClick(): void {
props.member.buyUpgrade(props.upg); props.member.buyUpgrade(props.upg);
props.rerender(); props.rerender();
@ -72,9 +49,13 @@ function UpgradeButton(props: IUpgradeButtonProps): React.ReactElement {
return ( return (
<Tooltip title={<Typography dangerouslySetInnerHTML={{ __html: props.upg.desc }} />}> <Tooltip title={<Typography dangerouslySetInnerHTML={{ __html: props.upg.desc }} />}>
<span> <span>
<Button onClick={onClick} sx={{ display: "flex", flexDirection: "column", width: "100%", height: "100%" }}> <Button
disabled={!isUpgradable}
onClick={onClick}
sx={{ display: "flex", flexDirection: "column", width: "100%", height: "100%" }}
>
<Typography sx={{ display: "block" }}>{props.upg.name}</Typography> <Typography sx={{ display: "block" }}>{props.upg.name}</Typography>
<Money money={gang.getUpgradeCost(props.upg)} /> <Money money={upgradeCost} forPurchase />
</Button> </Button>
</span> </span>
</Tooltip> </Tooltip>
@ -86,7 +67,6 @@ interface IPanelProps {
} }
function GangMemberUpgradePanel(props: IPanelProps): React.ReactElement { function GangMemberUpgradePanel(props: IPanelProps): React.ReactElement {
const gang = useGang();
const rerender = useRerender(); const rerender = useRerender();
const [currentCategory, setCurrentCategory] = useState("Weapons"); const [currentCategory, setCurrentCategory] = useState("Weapons");
@ -94,7 +74,6 @@ function GangMemberUpgradePanel(props: IPanelProps): React.ReactElement {
return Object.keys(GangMemberUpgrades) return Object.keys(GangMemberUpgrades)
.filter((upgName: string) => { .filter((upgName: string) => {
const upg = GangMemberUpgrades[upgName]; const upg = GangMemberUpgrades[upgName];
if (Player.money < gang.getUpgradeCost(upg)) return false;
if (upg.type !== type) return false; if (upg.type !== type) return false;
if (list.includes(upgName)) return false; if (list.includes(upgName)) return false;
return true; return true;
@ -214,7 +193,6 @@ function GangMemberUpgradePanel(props: IPanelProps): React.ReactElement {
<UpgradeButton key={upg.name} rerender={rerender} member={props.member} upg={upg} /> <UpgradeButton key={upg.name} rerender={rerender} member={props.member} upg={upg} />
))} ))}
</Box> </Box>
<NextReveal type={categories[currentCategory][1] as UpgradeType} upgrades={props.member.upgrades} />
</Box> </Box>
</span> </span>
</Box> </Box>