Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add confirmation step to destroy building #2433

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions client/src/ui/modules/entity-details/BuildingEntityDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BUILDINGS_CENTER } from "@/three/scenes/constants";
import { ResourceMiningTypes } from "@/types";
import { BuildingInfo, ResourceInfo } from "@/ui/components/construction/SelectPreviewBuilding";
import Button from "@/ui/elements/Button";
import { getEntityIdFromKeys, ResourceIdToMiningType } from "@/ui/utils/utils";
import { ResourceIdToMiningType, getEntityIdFromKeys } from "@/ui/utils/utils";
import { BuildingType, ID, ResourcesIds, StructureType } from "@bibliothecadao/eternum";
import { useComponentValue } from "@dojoengine/react";
import { getComponentValue } from "@dojoengine/recs";
Expand All @@ -31,6 +31,7 @@ export const BuildingEntityDetails = () => {
});
const [isPaused, setIsPaused] = useState<boolean>(false);
const [isOwnedByPlayer, setIsOwnedByPlayer] = useState<boolean>(false);
const [showDestroyConfirm, setShowDestroyConfirm] = useState(false);

const { getEntityInfo } = useEntitiesUtils();

Expand Down Expand Up @@ -92,6 +93,11 @@ export const BuildingEntityDetails = () => {
}, [selectedBuildingHex, isPaused]);

const handleDestroyBuilding = useCallback(() => {
if (!showDestroyConfirm) {
setShowDestroyConfirm(true);
return;
}

const tileManager = new TileManager(dojo.setup, {
col: selectedBuildingHex.outerCol,
row: selectedBuildingHex.outerRow,
Expand All @@ -106,8 +112,9 @@ export const BuildingEntityDetails = () => {
} else {
playDestroyWooden();
}
setShowDestroyConfirm(false);
setLeftNavigationView(LeftView.None);
}, [selectedBuildingHex, buildingState]);
}, [selectedBuildingHex, buildingState, showDestroyConfirm]);

const canDestroyBuilding = useMemo(() => {
if (buildingState.buildingType !== BuildingType.WorkersHut) return true;
Expand Down Expand Up @@ -170,7 +177,7 @@ export const BuildingEntityDetails = () => {
variant="danger"
withoutSound
>
Destroy
{showDestroyConfirm ? "Confirm Destroy" : "Destroy"}
</Button>
</div>
)}
Expand Down
Loading