Files
Aurora.3/code/modules/nano/modules/lighting_ctrl.dm
Lohikar 7375af6c19 Minor Nightmode Fixes (#1305)
bugfix: "Global nightmode toggle no longer affects security as was originally intended."
tweak: "Manually turning on nightmode will prevent the automatic system from turning it off."
2016-12-26 01:42:40 +02:00

54 lines
1.7 KiB
Plaintext

/datum/nano_module/lighting_ctrl
name = "Lighting Control"
var/context = "pub"
var/lstate = "full"
var/mob/lusr = null // for admin logs
/datum/nano_module/lighting_ctrl/New()
..()
lstate = nl_ctrl.is_active() ? "dark" : "full"
/datum/nano_module/lighting_ctrl/proc/update_lighting()
if (!config.night_lighting)
return
// whether to only select areas explicitly marked for nightlighting
var/wl_only = context == "all" ? 0 : 1
if (!wl_only && lstate == "dark")
nl_ctrl.manual_override = 1
else if (!wl_only)
nl_ctrl.manual_override = 0
if (lstate == "dark")
log_and_message_admins("enabled night-mode [wl_only ? "in public areas" : "globally"].", lusr)
nl_ctrl.activate(wl_only)
else if (lstate == "full")
log_and_message_admins("disabled night-mode [wl_only ? "in public areas" : "globally"].", lusr)
nl_ctrl.deactivate(wl_only)
/datum/nano_module/lighting_ctrl/Topic(href, href_list)
if(..())
return 1
if (href_list["context"])
context = href_list["context"]
if (href_list["mode"])
lstate = href_list["mode"]
if (href_list["set"])
update_lighting()
/datum/nano_module/lighting_ctrl/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/topic_state/state = default_state)
lusr = user
var/list/data = host.initial_data()
data["context"] = context
data["status"] = lstate
ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "lighting_ctrl.tmpl", "Lighting Control", 800, 500, state = state)
if(host.update_layout()) // This is necessary to ensure the status bar remains updated along with rest of the UI.
ui.auto_update_layout = 1
ui.set_initial_data(data)
ui.open()
ui.set_auto_update(1)