Skip to content

Commit

Permalink
ТСММ
Browse files Browse the repository at this point in the history
  • Loading branch information
AyIong committed Sep 27, 2023
1 parent e4a899d commit 341dac5
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions tgui/packages/tgui/components/NanoMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import { LabeledList } from './LabeledList';
import { Slider } from './Slider';
import { getBoundingBox } from "./ByondUi";

const pauseEvent = e => {
if (e.stopPropagation) { e.stopPropagation(); }
if (e.preventDefault) { e.preventDefault(); }
const pauseEvent = (e) => {
if (e.stopPropagation) {
e.stopPropagation();
}
if (e.preventDefault) {
e.preventDefault();
}
e.cancelBubble = true;
e.returnValue = false;
return false;
Expand All @@ -32,7 +36,7 @@ export class NanoMap extends Component {
};

// Dragging
this.handleDragStart = e => {
this.handleDragStart = (e) => {
this.ref = e.target;
this.setState({
dragging: false,
Expand All @@ -44,8 +48,8 @@ export class NanoMap extends Component {
pauseEvent(e);
};

this.handleDragMove = e => {
this.setState(prevState => {
this.handleDragMove = (e) => {
this.setState((prevState) => {
const state = { ...prevState };
const newOffsetX = e.screenX - state.originX;
const newOffsetY = e.screenY - state.originY;
Expand All @@ -62,7 +66,7 @@ export class NanoMap extends Component {
pauseEvent(e);
};

this.handleDragEnd = e => {
this.handleDragEnd = (e) => {
this.setState({
dragging: false,
originX: null,
Expand All @@ -74,7 +78,7 @@ export class NanoMap extends Component {
};

this.handleZoom = (_e, value) => {
this.setState(state => {
this.setState((state) => {
const newZoom = Math.min(Math.max(value, 1), 8);
const zoomDiff = newZoom / state.zoom;
if (zoomDiff === 1) {
Expand Down Expand Up @@ -106,32 +110,30 @@ export class NanoMap extends Component {
const { dragging, offsetX, offsetY, zoom = 1 } = this.state;
const { children } = this.props;

const mapUrl = config.map + "_nanomap_z1.png";
const mapSize = (510 * zoom) + 'px';
const mapUrl = config.map + '_nanomap_z1.png';
const mapSize = 510 * zoom + 'px';
const newStyle = {
width: mapSize,
height: mapSize,
"margin-top": offsetY + "px",
"margin-left": offsetX + "px",
"overflow": "hidden",
"position": "relative",
"background-image": "url(" + mapUrl + ")",
"background-size": "cover",
"background-repeat": "no-repeat",
"border": '1px solid rgba(0, 0, 0, .3)',
"text-align": "center",
"cursor": dragging ? "move" : "auto",
'margin-top': offsetY + 'px',
'margin-left': offsetX + 'px',
'overflow': 'hidden',
'position': 'relative',
'background-image': 'url(' + mapUrl + ')',
'background-size': 'cover',
'background-repeat': 'no-repeat',
'text-align': 'center',
'cursor': dragging ? 'move' : 'auto',
};

return (
<Box className="NanoMap__container">
<Box
style={newStyle}
textAlign="center"
onMouseDown={this.handleDragStart}>
<Box>
{children}
</Box>
onMouseDown={this.handleDragStart}
>
<Box>{children}</Box>
</Box>
<NanoMapZoomer zoom={zoom} onZoom={this.handleZoom} />
</Box>
Expand All @@ -150,8 +152,8 @@ const NanoMapMarker = props => {
onClick,
size = 6,
} = props;
const rx = ((x * 2 * zoom) - zoom) - 3;
const ry = ((y * 2 * zoom) - zoom) - 3;
const rx = x * 2 * zoom - zoom - 3;
const ry = y * 2 * zoom - zoom - 3;
return (
<div>
<Box
Expand Down Expand Up @@ -230,7 +232,7 @@ const NanoMapZoomer = props => {
minValue="1"
maxValue="8"
stepPixelSize="10"
format={v => v + "x"}
format={(v) => v + 'x'}
value={props.zoom}
onDrag={(e, v) => props.onZoom(e, v)}
/>
Expand Down

0 comments on commit 341dac5

Please sign in to comment.