Merge pull request #15494 from SandPoot/custom-shuttle-ui

TGUIzes the Custom Shuttle
This commit is contained in:
silicons
2022-02-04 07:55:23 -08:00
committed by GitHub
2 changed files with 175 additions and 43 deletions
+39 -43
View File
@@ -35,67 +35,63 @@
. = ..()
. += distance_multiplier < 1 ? "Bluespace shortcut module installed. Route is [distance_multiplier]x the original length." : ""
/obj/machinery/computer/custom_shuttle/ui_interact(mob/user)
/obj/machinery/computer/custom_shuttle/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "CustomShuttleConsole", name)
ui.open()
/obj/machinery/computer/custom_shuttle/ui_data(mob/user)
var/list/data = list()
var/list/options = params2list(possible_destinations)
var/obj/docking_port/mobile/M = SSshuttle.getShuttle(shuttleId)
var/dat = "[M ? "Current Location : [M.getStatusText()]" : "Shuttle link required."]<br><br>"
data["docked_location"] = M ? M.get_status_text_tgui() : null
if(M)
dat += "<A href='?src=[REF(src)];calculate=1'>Run Flight Calculations</A><br>"
dat += "<b>Shuttle Data</b><hr>"
dat += "Shuttle Mass: [calculated_mass/10]tons<br>"
dat += "Engine Force: [calculated_dforce]kN ([calculated_engine_count] engines)<br>"
dat += "Sublight Speed: [calculated_speed]ms<sup>-1</sup><br>"
dat += calculated_speed < 1 ? "<b>INSUFFICIENT ENGINE POWER</b><br>" : ""
dat += calculated_non_operational_thrusters > 0 ? "<b>Warning: [calculated_non_operational_thrusters] thrusters offline.</b><br>" : ""
dat += "Fuel Consumption: [calculated_consumption]units per distance<br>"
dat += "Engine Cooldown: [calculated_cooldown]s<hr>"
var/destination_found
calculateStats(FALSE, 0, TRUE)
data["ship_name"] = M.area_type ? M.area_type:name : "ERROR"
data["shuttle_mass"] = calculated_mass/10
data["engine_force"] = calculated_dforce
data["engines"] = calculated_engine_count
data["calculated_speed"] = calculated_speed
data["damaged_engines"] = calculated_non_operational_thrusters
data["calculated_consumption"] = calculated_consumption
data["calculated_cooldown"] = calculated_cooldown
data["locations"] = list()
for(var/obj/docking_port/stationary/S in SSshuttle.stationary)
if(!options.Find(S.id))
continue
if(!M.check_dock(S, silent=TRUE))
if(!M.check_dock(S, silent = TRUE))
continue
if(calculated_speed == 0)
break
destination_found = TRUE
var/dist = round(calculateDistance(S))
dat += "<A href='?src=[REF(src)];setloc=[S.id]'>Target [S.name] (Dist: [dist] | Fuel Cost: [round(dist * calculated_consumption)] | Time: [round(dist / calculated_speed)])</A><br>"
if(!destination_found)
dat += "<B>No valid destinations</B><br>"
dat += "<hr>[targetLocation ? "Target Location : [targetLocation]" : "No Target Location"]"
dat += "<hr><A href='?src=[REF(src)];fly=1'>Initate Flight</A><br>"
dat += "<A href='?src=[REF(user)];mach_close=computer'>Close</a>"
var/list/location_data = list(
id = S.id,
name = S.name,
dist = round(calculateDistance(S))
)
data["locations"] += list(location_data)
data["destination"] = targetLocation
return data
popup = new(user, "computer", M ? M.name : "shuttle", 350, 450)
popup.set_content("<center>[dat]</center>")
popup.open()
/obj/machinery/computer/custom_shuttle/Topic(href, href_list)
if(..())
/obj/machinery/computer/custom_shuttle/ui_act(action, params)
. = ..()
if(.)
return
usr.set_machine(src)
src.add_fingerprint(usr)
if(!allowed(usr))
to_chat(usr, "<span class='danger'>Access denied.</span>")
return
if(href_list["calculate"])
calculateStats()
ui_interact(usr)
return
var/obj/docking_port/mobile/M = SSshuttle.getShuttle(shuttleId)
if(!M)
to_chat(usr, "<span class='danger'>Shuttle Link Required.</span>")
return
if(M.launch_status == ENDGAME_LAUNCHED)
return
if(href_list["setloc"])
SetTargetLocation(href_list["setloc"])
ui_interact(usr)
return
else if(href_list["fly"])
Fly()
ui_interact(usr)
return
switch(action)
if("setloc")
SetTargetLocation(params["setloc"])
if("fly")
Fly()
return
/obj/machinery/computer/custom_shuttle/proc/calculateDistance(var/obj/docking_port/stationary/port)
var/deltaX = port.x - x
@@ -0,0 +1,136 @@
/* eslint-disable react/jsx-closing-tag-location */
import { useBackend } from '../backend';
import { Box, Button, Flex, Icon, LabeledList, Modal, Section, Table, Tooltip } from '../components';
import { Window } from '../layouts';
export const CustomShuttleConsole = (props, context) => {
const { act, data } = useBackend(context);
const {
docked_location,
ship_name = "ERROR",
shuttle_mass = 0,
engine_force = 0,
engines = 0,
calculated_speed = 0,
calculated_non_operational_thrusters = 0,
calculated_consumption = 0,
calculated_cooldown = 0,
locations = [],
destination = null,
} = data;
return (
<Window
width={385}
height={475}>
<Window.Content overflow="auto">
<Section fluid fill grow={1}>
{!docked_location ? (
<Modal
ml={1}
mt={1}
width={26}
height={12}
fontSize="28px"
fontFamily="monospace"
textAlign="center">
<Flex>
<Flex.Item mt={8} ml={3}>
<Icon
name="minus-circle" />
</Flex.Item>
<Flex.Item
mt={5}
ml={2}
color="yellow">
{"Shuttle Link Required."}
</Flex.Item>
</Flex>
</Modal>
) : (
<>
<font size="+3"><center>{ship_name}</center></font>
<Section title="Info">
<LabeledList>
<LabeledList.Item label="Current Location">
{docked_location}
</LabeledList.Item>
<LabeledList.Item label="Shuttle Mass">
{shuttle_mass / 10}ton{shuttle_mass !== 1 ? "s" : null}
</LabeledList.Item>
<LabeledList.Item label="Engine Force">
{engine_force}Kn ({engines} engine{engines !== 1 ? "s" : null})
</LabeledList.Item>
<LabeledList.Item label="Sublight speed">
{calculated_speed}ms{<sup>-1</sup>} {calculated_speed < 1 ? <Tooltip content="INSUFFICIENT ENGINE POWER"><Icon name="exclamation-triangle" color="yellow" /></Tooltip> : null}
</LabeledList.Item>
{calculated_non_operational_thrusters.len
? <LabeledList.Item label="Warning">
{calculated_non_operational_thrusters} thruster{calculated_non_operational_thrusters !== 1 ? "s are" : " is"} not operational.
</LabeledList.Item>
: null}
<LabeledList.Item label="Fuel Consumption">
{calculated_consumption} unit{calculated_consumption !== 1 ? "s" : null} per travel
</LabeledList.Item>
<LabeledList.Item label="Engine Cooldown">
{calculated_cooldown}s
</LabeledList.Item>
</LabeledList>
</Section>
<Section title="Destinations">
{locations.length===0 && (
<Box
mb={1.7}
color="bad">
No valid destinations
</Box>
) || (
<Table>
{locations.map(location => (
<tr class="Table__row candystripe" key={location.id}>
{location.name} <td>({location.dist}m)</td>
<td>
<Button
icon="crosshairs"
selected={location.id === destination}
onClick={() => act("setloc", {
setloc: location.id,
})} />
</td>
</tr>
))}
</Table>
)}
</Section>
<Section>
<Button
content="Initiate Flight"
icon="rocket"
disabled={calculated_speed < 1 || !destination}
onClick={() => act('fly')}
fluid />
</Section>
</>
)}
</Section>
</Window.Content>
</Window>
);
};
const getLocationNameById = (locations, id) => {
return locations?.find(location => location.id === id)?.name;
};
const getLocationIdByName = (locations, name) => {
return locations?.find(location => location.name === name)?.id;
};
const STATUS_COLOR_KEYS = {
"In Transit": "good",
"Idle": "average",
"Igniting": "average",
"Recharging": "average",
"Missing": "bad",
"Unauthorized Access": "bad",
"Locked": "bad",
};