-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add senator mouseover summary (#442)
* Add senator summary Add a senator summary. This is a MUI Popover that appears when hovering over a senator portrait. It shows their faction, titles and some attributes. * Make Popover render conditional Make the senator summary Popover render conditional. This will potentially improve performance.
- Loading branch information
Showing
11 changed files
with
184 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import Faction from "@/classes/Faction" | ||
import { useGameContext } from "@/contexts/GameContext" | ||
import FactionLink from "@/components/FactionLink" | ||
import Senator from "@/classes/Senator" | ||
import SenatorFactList from "@/components/SenatorFactList" | ||
import FactionIcon from "./FactionIcon" | ||
|
||
interface SenatorFactionAndFactsProps { | ||
senator: Senator | ||
selectable?: boolean | ||
} | ||
|
||
const SenatorFactionAndFacts = ({ | ||
senator, | ||
selectable, | ||
}: SenatorFactionAndFactsProps) => { | ||
const { allFactions, allTitles } = useGameContext() | ||
|
||
// Get senator-specific data | ||
const faction: Faction | null = senator?.faction | ||
? allFactions.byId[senator.faction] ?? null | ||
: null | ||
const isFactionLeader: boolean = senator | ||
? allTitles.asArray.some( | ||
(t) => t.senator === senator.id && t.name == "Faction Leader" | ||
) | ||
: false | ||
|
||
// Get JSX for the faction description | ||
const getFactionDescription = () => { | ||
if (!faction) return null | ||
return ( | ||
<span className="ml-px"> | ||
{selectable ? ( | ||
<FactionLink faction={faction} includeIcon={true} /> | ||
) : ( | ||
<span> | ||
<span style={{ marginRight: 4 }}> | ||
<FactionIcon faction={faction} size={17} /> | ||
</span> | ||
{faction.getName()} Faction | ||
</span> | ||
)} | ||
{isFactionLeader ? " Leader" : " Member"} | ||
</span> | ||
) | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<p> | ||
{faction && senator.alive ? ( | ||
<span>{getFactionDescription()}</span> | ||
) : senator.alive ? ( | ||
"Unaligned" | ||
) : ( | ||
<span> | ||
{faction ? ( | ||
<span>Died as {getFactionDescription()}</span> | ||
) : ( | ||
"Was always Unaligned" | ||
)} | ||
</span> | ||
)} | ||
</p> | ||
<SenatorFactList senator={senator} selectable={selectable} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default SenatorFactionAndFacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { MouseEvent, ReactNode, useState } from "react" | ||
import Senator from "@/classes/Senator" | ||
import { Popover } from "@mui/material" | ||
import AttributeFlex, { Attribute } from "@/components/AttributeFlex" | ||
import InfluenceIcon from "@/images/icons/influence.svg" | ||
import TalentsIcon from "@/images/icons/talents.svg" | ||
import VotesIcon from "@/images/icons/votes.svg" | ||
import SenatorFactionAndFacts from "@/components/SenatorFactionAndFacts" | ||
|
||
interface SenatorSummaryProps { | ||
senator: Senator | ||
children: ReactNode | ||
} | ||
|
||
const SenatorSummary = ({ senator, children }: SenatorSummaryProps) => { | ||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null) | ||
const handleOpen = (event: MouseEvent<HTMLElement>) => { | ||
setAnchorEl(event.currentTarget) | ||
} | ||
const handleClose = () => { | ||
setAnchorEl(null) | ||
} | ||
const open = Boolean(anchorEl) | ||
|
||
// Attribute data | ||
const attributeItems: Attribute[] = [ | ||
{ | ||
name: "influence", | ||
value: senator.influence, | ||
icon: InfluenceIcon, | ||
}, | ||
{ name: "talents", value: senator.talents, icon: TalentsIcon }, | ||
{ name: "votes", value: senator.votes, icon: VotesIcon }, | ||
] | ||
|
||
return ( | ||
<> | ||
<div | ||
onMouseEnter={handleOpen} | ||
onMouseLeave={handleClose} | ||
className="inline" | ||
> | ||
{children} | ||
</div> | ||
{open && ( | ||
<Popover | ||
sx={{ | ||
pointerEvents: "none", | ||
marginTop: "4px", | ||
}} | ||
open={open} | ||
anchorEl={anchorEl} | ||
anchorOrigin={{ | ||
vertical: "bottom", | ||
horizontal: "center", | ||
}} | ||
transformOrigin={{ | ||
vertical: "top", | ||
horizontal: "center", | ||
}} | ||
onClose={handleClose} | ||
disableRestoreFocus | ||
> | ||
<div className="py-3 px-4 max-w-[260px] flex flex-col gap-4"> | ||
<p className="font-semibold w-full text-center"> | ||
{senator.displayName} | ||
</p> | ||
<SenatorFactionAndFacts senator={senator} /> | ||
<div className="flex justify-center"> | ||
<AttributeFlex attributes={attributeItems}></AttributeFlex> | ||
</div> | ||
</div> | ||
</Popover> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default SenatorSummary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.