Skip to content

Commit

Permalink
Ports enhanced Reflector TGUI menu from aetherstation (#10248)
Browse files Browse the repository at this point in the history
* reflected

* prettierx

* string

* Update code/game/objects/structures/reflector.dm

Co-authored-by: PowerfulBacon <[email protected]>

* crash()

* unreachable code

* Revert "unreachable code"

This reverts commit 7d7a021.

* Revert "crash()"

This reverts commit 54f7cc2.

* log_href

* Update code/game/objects/structures/reflector.dm

Co-authored-by: PowerfulBacon <[email protected]>

---------

Co-authored-by: PowerfulBacon <[email protected]>
  • Loading branch information
Tsar-Salat and PowerfulBacon authored Dec 10, 2023
1 parent 9d8e288 commit 8f8d817
Show file tree
Hide file tree
Showing 2 changed files with 292 additions and 9 deletions.
64 changes: 55 additions & 9 deletions code/game/objects/structures/reflector.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
. += "It is set to [rotation_angle] degrees, and the rotation is [can_rotate ? "unlocked" : "locked"]."
if(!admin)
if(can_rotate)
. += "<span class='notice'>Alt-click to adjust its direction.</span>"
. += "<span class='notice'>Use your <b>hand</b> to adjust its direction.</span>"
. += "<span class='notice'>Use a <b>screwdriver</b> to lock the rotation.</span>"
else
. += "<span class='notice'>Use screwdriver to unlock the rotation.</span>"
. += "<span class='notice'>Use <b>screwdriver</b> to unlock the rotation.</span>"

/obj/structure/reflector/proc/setAngle(new_angle, force_rotate = FALSE)
if(can_rotate || force_rotate)
Expand Down Expand Up @@ -170,13 +171,6 @@
setAngle(SIMPLIFY_DEGREES(new_angle))
return TRUE

/obj/structure/reflector/AltClick(mob/user)
if(!user.canUseTopic(src, BE_CLOSE, ismonkey(user)))
return
else if(finished)
rotate(user)


//TYPES OF REFLECTORS, SINGLE, DOUBLE, BOX

//SINGLE
Expand Down Expand Up @@ -265,3 +259,55 @@
return
else
return ..()

// tgui menu

/obj/structure/reflector/ui_interact(mob/user, datum/tgui/ui)
if(!finished)
user.balloon_alert(user, "nothing to rotate!")
return
if(!can_rotate)
user.balloon_alert(user, "can't rotate!")
return
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Reflector")
ui.open()

/obj/structure/reflector/attack_robot(mob/user)
ui_interact(user)
return

/obj/structure/reflector/ui_state(mob/user)
return GLOB.physical_state //Prevents borgs from adjusting this at range

/obj/structure/reflector/ui_data(mob/user)
var/list/data = list()
data["rotation_angle"] = rotation_angle
data["reflector_name"] = name

return data

/obj/structure/reflector/ui_act(action, params)
. = ..()
if(.)
return
switch(action)
if("rotate")
if (!can_rotate || admin)
return FALSE
var/new_angle = text2num(params["rotation_angle"])
if(isnull(new_angle))
log_href_exploit(usr, " inputted a string to [src] instead of a number while interacting with the rotate UI, somehow.")
return FALSE
setAngle(SIMPLIFY_DEGREES(new_angle))
return TRUE
if("calculate")
if (!can_rotate || admin)
return FALSE
var/new_angle = rotation_angle + text2num(params["rotation_angle"])
if(isnull(new_angle))
log_href_exploit(usr, " inputted a string to [src] instead of a number while interacting with the calculate UI, somehow.")
return FALSE
setAngle(SIMPLIFY_DEGREES(new_angle))
return TRUE
237 changes: 237 additions & 0 deletions tgui/packages/tgui/interfaces/Reflector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
import { useBackend } from '../backend';
import { Box, Button, Stack, Icon, LabeledControls, Section, NumberInput, Table } from '../components';
import { Window } from '../layouts';

type Data = {
reflector_name: string;
rotation_angle: number;
};
export const Reflector = (props, context) => {
const { act, data } = useBackend<Data>(context);
const { reflector_name, rotation_angle } = data;
return (
<Window title={reflector_name} height={200} width={219}>
<Window.Content>
<Stack>
<Stack.Item>
<Section title="Presets" textAlign="center" fill>
<Table mt={3.5}>
<Table.Cell>
<Table.Row>
<Button
icon="arrow-left"
iconRotation={45}
mb={1}
onClick={() =>
act('rotate', {
rotation_angle: 315,
})
}
/>
</Table.Row>
<Table.Row>
<Button
icon="arrow-left"
mb={1}
onClick={() =>
act('rotate', {
rotation_angle: 270,
})
}
/>
</Table.Row>
<Table.Row>
<Button
icon="arrow-left"
iconRotation={-45}
mb={1}
onClick={() =>
act('rotate', {
rotation_angle: 225,
})
}
/>
</Table.Row>
</Table.Cell>
<Table.Cell>
<Table.Row>
<Button
icon="arrow-up"
mb={1}
onClick={() =>
act('rotate', {
rotation_angle: 0,
})
}
/>
</Table.Row>
<Table.Row>
<Box px={0.75}>
<Icon name="angle-double-up" size={1.66} rotation={rotation_angle} mb={1} />
</Box>
</Table.Row>
<Table.Row>
<Button
icon="arrow-down"
mb={1}
onClick={() =>
act('rotate', {
rotation_angle: 180,
})
}
/>
</Table.Row>
</Table.Cell>
<Table.Cell>
<Table.Row>
<Button
icon="arrow-right"
iconRotation={-45}
mb={1}
onClick={() =>
act('rotate', {
rotation_angle: 45,
})
}
/>
</Table.Row>
<Table.Row>
<Button
icon="arrow-right"
mb={1}
onClick={() =>
act('rotate', {
rotation_angle: 90,
})
}
/>
</Table.Row>
<Table.Row>
<Button
icon="arrow-right"
iconRotation={45}
mb={1}
onClick={() =>
act('rotate', {
rotation_angle: 135,
})
}
/>
</Table.Row>
</Table.Cell>
</Table>
</Section>
</Stack.Item>
<Stack>
<Section title="Angle" textAlign="center" fill>
<LabeledControls>
<LabeledControls.Item ml={0.5} label="Set rotation">
<NumberInput
value={rotation_angle}
unit="degrees"
minValue={0}
maxValue={359}
step={1}
stepPixelSize={1}
onDrag={(e, value) =>
act('rotate', {
rotation_angle: value,
})
}
/>
</LabeledControls.Item>
</LabeledControls>
<Stack fill>
<Stack fill vertical>
<Stack.Item>
<Button
fluid
icon="undo-alt"
content="-5"
mb={1}
onClick={() =>
act('calculate', {
rotation_angle: -5,
})
}
/>
</Stack.Item>
<Stack>
<Button
fluid
icon="undo-alt"
content="-10"
mb={1}
onClick={() =>
act('calculate', {
rotation_angle: -10,
})
}
/>
</Stack>
<Stack>
<Button
fluid
icon="undo-alt"
content="-15"
mb={1}
onClick={() =>
act('calculate', {
rotation_angle: -15,
})
}
/>
</Stack>
</Stack>
<Stack vertical>
<Stack.Item>
<Button
fluid
icon="redo-alt"
iconPosition="right"
content="+5"
mb={1}
onClick={() =>
act('calculate', {
rotation_angle: 5,
})
}
/>
</Stack.Item>
<Stack>
<Button
fluid
icon="redo-alt"
iconPosition="right"
content="+10"
mb={1}
onClick={() =>
act('calculate', {
rotation_angle: 10,
})
}
/>
</Stack>
<Stack>
<Button
fluid
icon="redo-alt"
iconPosition="right"
content="+15"
mb={1}
onClick={() =>
act('calculate', {
rotation_angle: 15,
})
}
/>
</Stack>
</Stack>
</Stack>
</Section>
</Stack>
</Stack>
</Window.Content>
</Window>
);
};

0 comments on commit 8f8d817

Please sign in to comment.