import { NFCAccountCard, NFCCard, NFCCardType, NFCPropertyCard, NFCPropertyCardSpecialProperties, PropertyColor, TaskType, WiFiNetwork } from "../RawConstants"; import React, {Component} from "react"; import { Backdrop, Box, Button, Fade, FormControl, FormControlLabel, FormGroup, FormLabel, Grid, InputLabel, MenuItem, Modal, Radio, RadioGroup, Select, SelectChangeEvent, Switch, TextField, Typography } from "@mui/material"; import WifiPasswordIcon from "@mui/icons-material/WifiPassword"; import WifiIcon from "@mui/icons-material/Wifi"; type AccountValues = keyof NFCAccountCard; type PropertyValues = keyof NFCPropertyCard; type TaskValues = "TYPE" | "AMOUNT1" | "AMOUNT2"; interface CardSetupState { validNFCCard: boolean, NFCCardType: NFCCardType, accountValues: { [key in AccountValues]?: string }, propertyValues: { [key in PropertyValues]?: string | number | boolean }, taskValues: { [key in TaskValues]?: TaskType | number } } interface CardSetupProps { closeCallback: () => void; card?: NFCCard; } export default class CardSetup extends Component { constructor(props: CardSetupProps) { super(props); let defaultType = NFCCardType.ACCOUNT; let accountValues: { [key in AccountValues]?: string } = {}; let propertyValues: { [key in PropertyValues]?: string } = {}; let taskValues: { [key in TaskValues]?: string } = {}; if (props.card) { defaultType = props.card.cardType; switch (defaultType) { case NFCCardType.ACCOUNT: let card = props.card as NFCAccountCard; accountValues = { symbol: card.symbol, nickname: card.nickname, pin: card.pin, } } } this.state = { validNFCCard: false, NFCCardType: NFCCardType.ACCOUNT, accountValues: accountValues, propertyValues: {}, taskValues: {}, } } componentDidMount() { } componentWillUnmount() { } modalStyle = { position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', width: 700, maxHeight: '80%', overflowY: 'scroll', height: 'auto', display: 'block', bgcolor: 'background.paper', border: '2px solid #0000', boxShadow: 24, p: 4, }; changeAccountState(prop: AccountValues, ev: React.ChangeEvent, useUpperCase = false) { this.setState(prevState => ({ ...prevState, accountValues: { ...prevState.accountValues, [prop]: useUpperCase ? ev.target.value.toUpperCase() : ev.target.value } })) } changePropertyState(prop: PropertyValues, ev: any) { if(prop == "fullSetAmount") { if (ev.target.value > 4) ev.target.value = 4; if(ev.target.value < 1) ev.target.value = 1; } if(prop == "buyValue" || prop == "mortgageValue" || prop.includes("rent")) { if(ev.target.value < 0) ev.target.value = 0; } this.setState(prevState => ({ ...prevState, propertyValues: { ...prevState.propertyValues, [prop]: ev.target.value } })) } changeTaskState(prop: TaskValues, ev: React.ChangeEvent) { this.setState(prevState => ({ ...prevState, taskValues: { ...prevState.taskValues, prop: ev.target.value } })) } insertInputsPerType = () => { if (this.state.NFCCardType == NFCCardType.ACCOUNT) { return ( this.changeAccountState("symbol", ev)} /> this.changeAccountState("nickname", ev)} /> this.changeAccountState("pin", ev)} /> ) } if (this.state.NFCCardType == NFCCardType.PROPERTY) { return ( Name this.changePropertyState("name", ev)} fullWidth /> Farbcode / Typ Voller Satz Anzahl this.changePropertyState("fullSetAmount", ev)} fullWidth aria-valuemin={0} aria-valuemax={4} /> Kauf-Wert this.changePropertyState("buyValue", ev)} fullWidth /> Hypothek-Wert this.changePropertyState("mortgageValue", ev)} fullWidth /> this.changePropertyState("rent", ev)} helperText={"Grundmiete ohne Haus und Set"} /> this.changePropertyState("rent1", ev)} helperText={"Miete bei einem Haus"} /> this.changePropertyState("rent2", ev)} helperText={"Miete bei 2 Häusern"} /> this.changePropertyState("rent3", ev)} helperText={"Miete bei 3 Häusern"} /> this.changePropertyState("rent4", ev)} helperText={"Miete bei 4 Häusern"} /> this.changePropertyState("rentHotel", ev)} helperText={"Miete bei einem Hotel"} /> Besondere Eigenschaften this.changePropertyState("specialProperties", ev)} > } label="Keine" /> } label="Bahnhof" /> } label="Versorgungswerk" /> } label="Gefängnis" /> ) } if (this.state.NFCCardType == NFCCardType.TASK) { return ( this.changeAccountState("symbol", ev)} /> this.changeAccountState("nickname", ev)} /> this.changeAccountState("pin", ev)} /> ) } return (
Typ selektieren um fortzufahren.
) } render() { return ( { this.props.closeCallback() }} closeAfterTransition slots={{backdrop: Backdrop}} slotProps={{ backdrop: { timeout: 500, }, }} > NFC-Karte konfigurieren {this.state.validNFCCard ? "Es wurde eine gültige Spielkarte erkannt." : "Es wurde eine ungültige NFC-Karte erkannt."}

Karten-Typ
{this.insertInputsPerType()}
); } }