Skip to content

Commit

Permalink
feat: new dropdown entries & refactor dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluefissure committed Jul 20, 2024
1 parent f7ef2be commit 3f2efd5
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 37 deletions.
28 changes: 21 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ReactCountryFlag from "react-country-flag";

// App Components
import { TextInput } from "./components/textInput";
import { DeathPenaltyDropDown } from "./components/deathPenaltyDropdown";
import { DropDown } from "./components/dropdown";
import { SliderInput } from "./components/sliderInput";
import { SwitchInput } from "./components/switchInput";
import { Input } from "./components/ui/input";
Expand All @@ -36,7 +36,7 @@ import { AdvancedSettings, InGameSettings, ServerSettings } from "./consts/setti

// Types
import { Gvas } from "./types/gvas";
import { DeathPenaltyLabel } from "./components/deathPenaltyDropdown";
import { LabelValue } from "./components/dropdown";

interface ChangeEvent<T> {
target: {
Expand Down Expand Up @@ -203,6 +203,20 @@ function App() {
enum_type: "EPalOptionWorldDifficulty",
},
};
} else if (entry.id === "AllowConnectPlatform") {
dictValue = {
Enum: {
value: `EPalOptionWorldAllowConnectPlatform::${entryValue}`,
enum_type: "EPalOptionWorldAllowConnectPlatform",
},
};
} else if (entry.id === "LogFormatType") {
dictValue = {
Enum: {
value: `EPalOptionWorldLogFormatType::${entryValue}`,
enum_type: "EPalOptionWorldLogFormatType",
},
};
}
} else if (entry.type === "boolean") {
dictValue = {
Expand Down Expand Up @@ -373,13 +387,13 @@ function App() {
}
const entryName = t(`entry.name.${entry.id}`);
const entryValue = entries[entry.id] ?? entry.defaultValue;
if (entry.id === "DeathPenalty") {
if (entry.type === "select") {
return (
<DeathPenaltyDropDown
key={id}
label={entryValue as DeathPenaltyLabel}
<DropDown
dKey={entry.id as "DeathPenalty" | "AllowConnectPlatform" | "LogFormatType"}
label={entryValue as LabelValue}
onLabelChange={(labelName: string) => {
onStateChanged("DeathPenalty")({
onStateChanged(entry.id)({
target: { value: labelName },
});
}}
Expand Down
10 changes: 10 additions & 0 deletions src/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
"PalEggDefaultHatchingTime": "Pal Egg Default Hatching Time",
"WorkSpeedRate": "Work Speed Rate",
"AutoSaveSpan": "Auto Save Span",
"AllowConnectPlatform": "Allow Connect Platform",
"LogFormatType": "Log Format Type",
"bIsMultiplay": "Is Multiplay",
"bIsPvP": "Is PvP",
"bCanPickupOtherGuildDeathPenaltyDrop": "Can Pickup Other Guild Death Penalty Drop",
Expand Down Expand Up @@ -121,6 +123,14 @@
"Item": "Lost item without equipment",
"ItemAndEquipment": "Lost item and equipment",
"All": "Lost All item, equipment, pal (in inventory)"
},
"AllowConnectPlatform": {
"Steam": "Only allow Steam to connect",
"Xbox": "Only allow Xbox to connect"
},
"LogFormatType": {
"Text": "Use Text format to log",
"Json": "Use Json format to log"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from "react"
import { useTranslation, Trans } from 'react-i18next';
import { ChevronDown } from "lucide-react"

import { DeathPenaltyLabels, AllowConnectPlatformLabels, LogFormatTypeLabels } from "@/consts/dropdownLabels"
import { Button } from "@/components/ui/button"
import { Label } from "@/components/ui/label"
import {
Expand All @@ -25,49 +26,43 @@ import {
} from "@/components/ui/tooltip"
import { I18nStr } from "@/i18n";

const labels = [
{
name: "None",
desc: "No lost",
},
{
name: "Item",
desc: "Lost item without equipment",
},
{
name: "ItemAndEquipment",
desc: "Lost item and equipment",
},
{
name: "All",
desc: "Lost All item, equipment, pal(in inventory)",
},
]
type Labels = typeof DeathPenaltyLabels | typeof AllowConnectPlatformLabels | typeof LogFormatTypeLabels;
export type LabelValue = Labels[number]['name'];
type Key = 'DeathPenalty' | 'AllowConnectPlatform' | 'LogFormatType';

export type DeathPenaltyLabel = "None" | "Item" | "ItemAndEquipment" | "All";
function get<T>(dict: Record<string, T>, key: string, defaultValue: T): T {
return Object.prototype.hasOwnProperty.call(dict, key) ? dict[key] : defaultValue;
}

export const DeathPenaltyDropDown = (props: {
label: DeathPenaltyLabel,
onLabelChange: (label: string) => void,
}) => {
export function DropDown(props: {
dKey: Key;
label: LabelValue;
onLabelChange: (label: string) => void;
}) {
const { dKey, label, onLabelChange } = props;
const labels = {
DeathPenalty: DeathPenaltyLabels,
AllowConnectPlatform: AllowConnectPlatformLabels,
LogFormatType: LogFormatTypeLabels
}[dKey] as Labels;
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const i18nLabelDesc = get(I18nStr.entry.description[dKey] as Record<string, string>, label, "");

const { label, onLabelChange } = props;
const [open, setOpen] = useState(false)

const labelDesc = t(I18nStr.entry.description.DeathPenalty[label], {
const labelDesc = t(i18nLabelDesc, {
defaultValue: labels.find((l) => l.name === label)?.desc ?? "",
});


return (
<div className="space-y-1">
<Label>
<TooltipProvider>
<Tooltip>
<TooltipTrigger className="cursor-default">
<Trans i18nKey={I18nStr.entry.name.DeathPenalty} />
<Trans i18nKey={get(I18nStr.entry.name, dKey, "")} />
<TooltipContent>
<p>DeathPenalty</p>
<p>{dKey}</p>
</TooltipContent>
</TooltipTrigger>
</Tooltip>
Expand Down
40 changes: 40 additions & 0 deletions src/consts/dropdownLabels.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const DeathPenaltyLabels = [
{
name: "None",
desc: "No lost",
},
{
name: "Item",
desc: "Lost item without equipment",
},
{
name: "ItemAndEquipment",
desc: "Lost item and equipment",
},
{
name: "All",
desc: "Lost All item, equipment, pal(in inventory)",
},
] as const;

export const AllowConnectPlatformLabels = [
{
name: "Steam",
desc: "Only allow Steam to connect",
},
{
name: "Xbox",
desc: "Only allow Xbox to connect",
},
] as const;

export const LogFormatTypeLabels = [
{
name: "Text",
desc: "Use Text format to log",
},
{
name: "Json",
desc: "Use Json format to log",
},
] as const;
16 changes: 16 additions & 0 deletions src/consts/entries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,22 @@ export const ENTRIES: Record<string, Entry> = {
range: [30, 3600],
desc: "Auto save span",
},
AllowConnectPlatform: {
name: "Allow Connect Platform",
id: "AllowConnectPlatform",
defaultValue: "Steam",
type: "select",
options: ["Steam", "Xbox"],
desc: "Allow connect platform",
},
LogFormatType: {
name: "Log Format Type",
id: "LogFormatType",
defaultValue: "Text",
type: "select",
options: ["Text", "Json"],
desc: "Log format type",
},
bIsMultiplay: {
name: "Is Multiplay",
id: "bIsMultiplay",
Expand Down
4 changes: 3 additions & 1 deletion src/consts/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export const ServerSettings = [
"PublicPort",
"ServerPlayerMaxNum",
"bIsUseBackupSaveData",
"AutoSaveSpan"
"AutoSaveSpan",
"AllowConnectPlatform",
"LogFormatType"
];

export const InGameSettings = [
Expand Down
12 changes: 12 additions & 0 deletions src/consts/worldoption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,18 @@ export const DEFAULT_WORLDOPTION = {
enum_type: "EPalOptionWorldDeathPenalty",
},
},
AllowConnectPlatform: {
Enum: {
value: "EPalOptionWorldAllowConnectPlatform::Steam",
enum_type: "EPalOptionWorldAllowConnectPlatform",
},
},
LogFormatType: {
Enum: {
value: "EPalOptionWorldLogFormatType::Text",
enum_type: "EPalOptionWorldLogFormatType",
},
},
bEnableInvaderEnemy: {
Bool: {
value: false,
Expand Down

0 comments on commit 3f2efd5

Please sign in to comment.