From 27f3ab0d5d263bfe6b17a95ab3ce9a2b5e8b81f3 Mon Sep 17 00:00:00 2001 From: Watermelon914 <37270891+Watermelon914@users.noreply.github.com> Date: Fri, 30 Jul 2021 06:26:48 +0100 Subject: [PATCH] Refactors UI code of integrated circuits completely into separate folders and adds dragndrop functionality for the UI (#60514) Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com> --- .../packages/tgui/components/InfinitePlane.js | 46 +- .../IntegratedCircuit/BasicInput.js | 27 + .../IntegratedCircuit/Connections.js | 57 ++ .../IntegratedCircuit/DisplayName.js | 60 ++ .../IntegratedCircuit/FundamentalTypes.js | 84 ++ .../IntegratedCircuit/ObjectComponent.js | 221 ++++++ .../tgui/interfaces/IntegratedCircuit/Port.js | 111 +++ .../interfaces/IntegratedCircuit/constants.js | 5 + .../interfaces/IntegratedCircuit/index.js | 745 ++++-------------- 9 files changed, 760 insertions(+), 596 deletions(-) create mode 100644 tgui/packages/tgui/interfaces/IntegratedCircuit/BasicInput.js create mode 100644 tgui/packages/tgui/interfaces/IntegratedCircuit/Connections.js create mode 100644 tgui/packages/tgui/interfaces/IntegratedCircuit/DisplayName.js create mode 100644 tgui/packages/tgui/interfaces/IntegratedCircuit/FundamentalTypes.js create mode 100644 tgui/packages/tgui/interfaces/IntegratedCircuit/ObjectComponent.js create mode 100644 tgui/packages/tgui/interfaces/IntegratedCircuit/Port.js create mode 100644 tgui/packages/tgui/interfaces/IntegratedCircuit/constants.js diff --git a/tgui/packages/tgui/components/InfinitePlane.js b/tgui/packages/tgui/components/InfinitePlane.js index 55273137bbe..7d15a37e382 100644 --- a/tgui/packages/tgui/components/InfinitePlane.js +++ b/tgui/packages/tgui/components/InfinitePlane.js @@ -27,6 +27,8 @@ export class InfinitePlane extends Component { this.handleMouseDown = this.handleMouseDown.bind(this); this.handleMouseMove = this.handleMouseMove.bind(this); + this.handleZoomIncrease = this.handleZoomIncrease.bind(this); + this.handleZoomDecrease = this.handleZoomDecrease.bind(this); this.onMouseUp = this.onMouseUp.bind(this); this.doOffsetMouse = this.doOffsetMouse.bind(this); @@ -70,14 +72,46 @@ export class InfinitePlane extends Component { }); } + handleZoomIncrease(event) { + const { onZoomChange } = this.props; + const { zoom } = this.state; + const newZoomValue = Math.min(zoom+ZOOM_INCREMENT, ZOOM_MAX_VAL); + this.setState({ + zoom: newZoomValue, + }); + if (onZoomChange) { + onZoomChange(newZoomValue); + } + } + + handleZoomDecrease(event) { + const { onZoomChange } = this.props; + const { zoom } = this.state; + const newZoomValue = Math.max(zoom-ZOOM_INCREMENT, ZOOM_MIN_VAL); + this.setState({ + zoom: newZoomValue, + }); + + if (onZoomChange) { + onZoomChange(newZoomValue); + } + } + handleMouseMove(event) { + const { onBackgroundMoved } = this.props; if (this.state.mouseDown) { + let newX, newY; this.setState((state) => { + newX = event.clientX - state.lastLeft; + newY = event.clientY - state.lastTop; return { - left: event.clientX - state.lastLeft, - top: event.clientY - state.lastTop, + left: newX, + top: newY, }; }); + if (onBackgroundMoved) { + onBackgroundMoved(newX, newY); + } } } @@ -140,9 +174,7 @@ export class InfinitePlane extends Component { + )) + || port.name} + + + + {port.type || 'any'} + + + + + ); +}; diff --git a/tgui/packages/tgui/interfaces/IntegratedCircuit/FundamentalTypes.js b/tgui/packages/tgui/interfaces/IntegratedCircuit/FundamentalTypes.js new file mode 100644 index 00000000000..1374fea1e99 --- /dev/null +++ b/tgui/packages/tgui/interfaces/IntegratedCircuit/FundamentalTypes.js @@ -0,0 +1,84 @@ +import { BasicInput } from './BasicInput'; +import { NumberInput, Button, Stack, Input } from '../../components'; + +export const FUNDAMENTAL_DATA_TYPES = { + 'string': (props, context) => { + const { name, value, setValue, color } = props; + return ( + + setValue(val)} + /> + + ); + }, + 'number': (props, context) => { + const { name, value, setValue, color } = props; + return ( + + setValue(val)} + unit={name} + /> + + ); + }, + 'entity': (props, context) => { + const { name, setValue, color } = props; + return ( + - )) - || port.name} - - - - {port.type || 'any'} - - - - - ); -};