From 75ce411c3b2d9727e79c156b449e0f47e072f7b4 Mon Sep 17 00:00:00 2001
From: zxaber <37497534+zxaber@users.noreply.github.com>
Date: Tue, 29 Sep 2020 19:23:18 -0700
Subject: [PATCH] Fixes borg flashlight color picker not working (#53996)
---
.../computers/item/computer.dm | 32 +++++++++++++++
.../computers/item/computer_ui.dm | 12 +-----
.../computers/item/tablet.dm | 41 ++++++-------------
3 files changed, 47 insertions(+), 38 deletions(-)
diff --git a/code/modules/modular_computers/computers/item/computer.dm b/code/modules/modular_computers/computers/item/computer.dm
index 5ea983f1e0a..3ee4d456bcc 100644
--- a/code/modules/modular_computers/computers/item/computer.dm
+++ b/code/modules/modular_computers/computers/item/computer.dm
@@ -346,6 +346,38 @@
enabled = 0
update_icon()
+/**
+ * Toggles the computer's flashlight, if it has one.
+ *
+ * Called from ui_act(), does as the name implies.
+ * It is seperated from ui_act() to be overwritten as needed.
+*/
+/obj/item/modular_computer/proc/toggle_flashlight()
+ if(!has_light)
+ return FALSE
+ set_light_on(!light_on)
+ if(light_on)
+ set_light(comp_light_luminosity, 1, comp_light_color)
+ else
+ set_light(0)
+ return TRUE
+
+/**
+ * Sets the computer's light color, if it has a light.
+ *
+ * Called from ui_act(), this proc takes a color string and applies it.
+ * It is seperated from ui_act() to be overwritten as needed.
+ * Arguments:
+ ** color is the string that holds the color value that we should use. Proc auto-fails if this is null.
+*/
+/obj/item/modular_computer/proc/set_flashlight_color(color)
+ if(!has_light || !color)
+ return FALSE
+ comp_light_color = color
+ set_light_color(color)
+ update_light()
+ return TRUE
+
/obj/item/modular_computer/screwdriver_act(mob/user, obj/item/tool)
if(!all_components.len)
to_chat(user, "This device doesn't have any components installed.")
diff --git a/code/modules/modular_computers/computers/item/computer_ui.dm b/code/modules/modular_computers/computers/item/computer_ui.dm
index 433159dc6a8..bf73d2d42bc 100644
--- a/code/modules/modular_computers/computers/item/computer_ui.dm
+++ b/code/modules/modular_computers/computers/item/computer_ui.dm
@@ -167,12 +167,7 @@
return 1
if("PC_toggle_light")
- set_light_on(!light_on)
- if(light_on)
- set_light(comp_light_luminosity, 1, comp_light_color)
- else
- set_light(0)
- return TRUE
+ return toggle_flashlight()
if("PC_light_color")
var/mob/user = usr
@@ -184,10 +179,7 @@
if(color_hex2num(new_color) < 200) //Colors too dark are rejected
to_chat(user, "That color is too dark! Choose a lighter one.")
new_color = null
- comp_light_color = new_color
- set_light_color(new_color)
- update_light()
- return TRUE
+ return set_flashlight_color(new_color)
if("PC_Eject_Disk")
var/param = params["name"]
diff --git a/code/modules/modular_computers/computers/item/tablet.dm b/code/modules/modular_computers/computers/item/tablet.dm
index 273e0ec5222..9675e203200 100644
--- a/code/modules/modular_computers/computers/item/tablet.dm
+++ b/code/modules/modular_computers/computers/item/tablet.dm
@@ -114,35 +114,20 @@
.["light_on"] = borgo?.lamp_enabled
.["comp_light_color"] = borgo?.lamp_color
-//Overrides the ui_act to make the flashlight controls link to the borg instead
-/obj/item/modular_computer/tablet/integrated/ui_act(action, params)
- . = ..()
- if(.)
- return
+//Makes the flashlight button affect the borg rather than the tablet
+/obj/item/modular_computer/tablet/integrated/toggle_flashlight()
+ if(!borgo || QDELETED(borgo))
+ return FALSE
+ borgo.toggle_headlamp()
+ return TRUE
- switch(action)
- if("PC_toggle_light")
- if(!borgo)
- return FALSE
- borgo.toggle_headlamp()
- return TRUE
-
- if("PC_light_color")
- if(!borgo)
- return FALSE
- var/mob/user = usr
- var/new_color
- while(!new_color)
- new_color = input(user, "Choose a new color for [src]'s flashlight.", "Light Color",light_color) as color|null
- if(!new_color || QDELETED(borgo))
- return
- if(color_hex2num(new_color) < 200) //Colors too dark are rejected
- to_chat(user, "That color is too dark! Choose a lighter one.")
- new_color = null
- borgo.lamp_color = new_color
- borgo.toggle_headlamp(FALSE, TRUE)
- return TRUE
- return ..()
+//Makes the flashlight color setting affect the borg rather than the tablet
+/obj/item/modular_computer/tablet/integrated/set_flashlight_color(color)
+ if(!borgo || QDELETED(borgo) || !color)
+ return FALSE
+ borgo.lamp_color = color
+ borgo.toggle_headlamp(FALSE, TRUE)
+ return TRUE
/obj/item/modular_computer/tablet/integrated/syndicate
icon_state = "tablet-silicon-syndicate"