круто

This commit is contained in:
aurinex
2025-12-17 13:16:59 +05:00
parent 24423173a6
commit fef89513c2
10 changed files with 555 additions and 105 deletions

View File

@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { Box, Typography, Grid, Button, Paper } from '@mui/material';
import { Box, Typography, Grid, Button, Paper, FormControl, Select, MenuItem, InputLabel } from '@mui/material';
import { FullScreenLoader } from '../components/FullScreenLoader';
import { translateServer } from '../utils/serverTranslator';
@ -18,6 +18,8 @@ const KNOWN_SERVER_IPS = [
'minecraft.minigames.popa-popa.ru',
];
const STORAGE_KEY = 'inventory_layout';
function stripMinecraftColors(text?: string | null): string {
if (!text) return '';
return text.replace(/§[0-9A-FK-ORa-fk-or]/g, '');
@ -34,30 +36,29 @@ const CardFacePaperSx = {
color: 'white',
} as const;
function readLauncherConfig(): any {
function readInventoryLayout(): any {
try {
const raw = localStorage.getItem('launcher_config');
const raw = localStorage.getItem(STORAGE_KEY);
return raw ? JSON.parse(raw) : {};
} catch {
return {};
}
}
function writeLauncherConfig(next: any) {
localStorage.setItem('launcher_config', JSON.stringify(next));
function writeInventoryLayout(next: any) {
localStorage.setItem(STORAGE_KEY, JSON.stringify(next));
}
function getLayout(username: string, serverIp: string): Record<string, number> {
const cfg = readLauncherConfig();
return cfg?.inventory_layout?.[username]?.[serverIp] ?? {};
const inv = readInventoryLayout();
return inv?.[username]?.[serverIp] ?? {};
}
function setLayout(username: string, serverIp: string, layout: Record<string, number>) {
const cfg = readLauncherConfig();
cfg.inventory_layout ??= {};
cfg.inventory_layout[username] ??= {};
cfg.inventory_layout[username][serverIp] = layout;
writeLauncherConfig(cfg);
const inv = readInventoryLayout();
inv[username] ??= {};
inv[username][serverIp] = layout;
writeInventoryLayout(inv);
}
function buildSlots(
@ -399,8 +400,6 @@ export default function Inventory() {
mt: '12vh',
}}
>
{loading && <FullScreenLoader fullScreen={false} message="Загрузка инвентаря..." />}
{/* ШАПКА + ПАГИНАЦИЯ */}
<Box
sx={{
@ -448,6 +447,73 @@ export default function Inventory() {
</Box>
)}
{availableServers.length > 0 && (
<FormControl size="small" sx={{ minWidth: 260 }}>
<InputLabel
id="inventory-server-label"
sx={{ fontFamily: 'Benzin-Bold', color: 'rgba(255,255,255,0.75)' }}
>
Сервер
</InputLabel>
<Select
labelId="inventory-server-label"
label="Сервер"
value={selectedServerIp}
onChange={(e) => setSelectedServerIp(String(e.target.value))}
MenuProps={{
PaperProps: {
sx: {
bgcolor: 'rgba(10,10,20,0.96)',
border: '1px solid rgba(255,255,255,0.10)',
borderRadius: '1vw',
backdropFilter: 'blur(14px)',
'& .MuiMenuItem-root': {
color: 'rgba(255,255,255,0.9)',
fontFamily: 'Benzin-Bold',
},
'& .MuiMenuItem-root.Mui-selected': {
backgroundColor: 'rgba(242,113,33,0.16)',
},
'& .MuiMenuItem-root:hover': {
backgroundColor: 'rgba(233,64,205,0.14)',
},
},
},
}}
sx={{
borderRadius: '999px',
bgcolor: 'rgba(255,255,255,0.04)',
color: 'rgba(255,255,255,0.92)',
fontFamily: 'Benzin-Bold',
'& .MuiSelect-select': {
py: '0.9vw',
px: '1.2vw',
},
'& .MuiOutlinedInput-notchedOutline': {
borderColor: 'rgba(255,255,255,0.14)',
},
'&:hover .MuiOutlinedInput-notchedOutline': {
borderColor: 'rgba(242,113,33,0.55)',
},
'&.Mui-focused .MuiOutlinedInput-notchedOutline': {
borderColor: 'rgba(233,64,205,0.65)',
borderWidth: '2px',
},
'& .MuiSelect-icon': {
color: 'rgba(255,255,255,0.75)',
},
}}
>
{availableServers.map((ip) => (
<MenuItem key={ip} value={ip}>
{translateServer(`Server ${ip}`)}
</MenuItem>
))}
</Select>
</FormControl>
)}
<Typography
variant="h6"
sx={{
@ -463,6 +529,9 @@ export default function Inventory() {
</Box>
{/* GRID */}
{loading ? (
<FullScreenLoader fullScreen={false} message="Загрузка инвентаря..." />
) : (
<Grid container spacing={2}>
{Array.from({ length: 28 }).map((_, index) => {
const item = slots[index];
@ -694,6 +763,7 @@ export default function Inventory() {
);
})}
</Grid>
)}
{draggedItemId && dragPos && (() => {
const draggedItem = items.find(i => i.id === draggedItemId);
if (!draggedItem) return null;