From 02732711699aa44d3e1e7b698335106c052874aa Mon Sep 17 00:00:00 2001 From: Isilkor Date: Wed, 9 Mar 2016 02:16:42 +0100 Subject: [PATCH] Borgs: Keep tools in the module hud when equipping Removing the tool from the module hud would alter its ordering and make things confusing. Instead, we'll just always show all tools and make the ones that are already equipped non-interactable and grayed out. This involves a bunch of updates all across the code because BYOND doesn't support displaying an atom in multiple places in the UI, so we have to send icon change notifications from all objs that are (potentially) part of a borg module. --- code/atom.dm | 11 +++- code/datums/chemistry/Chemistry-Holder.dm | 2 +- code/datums/chemistry/Chemistry-Machinery.dm | 6 +- code/datums/chemistry/tools/beakers.dm | 2 + code/datums/chemistry/tools/bottles.dm | 1 + code/datums/chemistry/tools/droppers.dm | 4 +- code/datums/chemistry/tools/extinguisher.dm | 4 +- code/datums/chemistry/tools/food_and_drink.dm | 5 +- code/datums/chemistry/tools/hyposprays.dm | 2 + code/datums/chemistry/tools/iv_drips.dm | 1 + code/datums/chemistry/tools/patches.dm | 1 + code/datums/chemistry/tools/syringes.dm | 2 + code/datums/hud/robot.dm | 60 ++++++++++++++----- code/mob/living/silicon/robot.dm | 4 ++ code/obj/item/cable_coil.dm | 4 +- code/obj/item/cigarette.dm | 6 +- code/obj/item/device/flash.dm | 10 ++-- code/obj/item/device/flashlight.dm | 3 +- code/obj/item/device/scanners.dm | 8 +-- code/obj/item/gun/energy.dm | 2 +- code/obj/item/hydroponics.dm | 2 +- code/obj/item/satchel.dm | 2 + code/obj/item/stun_baton.dm | 4 +- code/obj/item/surgery_tools.dm | 6 +- code/obj/item/tools.dm | 8 +-- code/obj/mining.dm | 2 + code/obj/railway.dm | 8 +-- code/obj/submachine/seed.dm | 2 +- 28 files changed, 117 insertions(+), 55 deletions(-) diff --git a/code/atom.dm b/code/atom.dm index 3c9f6948..fba756d5 100644 --- a/code/atom.dm +++ b/code/atom.dm @@ -273,7 +273,12 @@ boutput(user, "You transfer [T] units into [A].") return - proc/handle_event(var/event) //This is sort of like a version of Topic that is not for browsing. + proc/signal_event(var/event) + // Right now, we only signal our container + if(src.loc) + src.loc.handle_event(event, src) + + proc/handle_event(var/event, var/sender) //This is sort of like a version of Topic that is not for browsing. return //Called AFTER the material of the object was changed. @@ -359,6 +364,10 @@ obj /atom/proc/HasProximity(atom/movable/AM as mob|obj) return + +/atom/proc/set_icon_state(var/new_state) + src.icon_state = new_state + signal_event("icon_updated") /* /atom/MouseEntered() usr << output("[src.name]", "atom_label") diff --git a/code/datums/chemistry/Chemistry-Holder.dm b/code/datums/chemistry/Chemistry-Holder.dm index eb5d4fec..daee80a1 100644 --- a/code/datums/chemistry/Chemistry-Holder.dm +++ b/code/datums/chemistry/Chemistry-Holder.dm @@ -347,7 +347,7 @@ datum src.add_reagent(C.result, speed,, src.total_temperature) if(my_atom && my_atom.loc) //We might be inside a thing, let's tell it we updated our reagents. - my_atom.loc.handle_event("reagent_holder_update") + my_atom.loc.handle_event("reagent_holder_update", src) defer_reactions = 0 if (deferred_reaction_checks) diff --git a/code/datums/chemistry/Chemistry-Machinery.dm b/code/datums/chemistry/Chemistry-Machinery.dm index ffc800bd..fcd32004 100644 --- a/code/datums/chemistry/Chemistry-Machinery.dm +++ b/code/datums/chemistry/Chemistry-Machinery.dm @@ -59,7 +59,7 @@ src.updateUsrDialog() src.update_icon() - handle_event(var/event) + handle_event(var/event, var/sender) if (event == "reagent_holder_update") src.update_icon() src.updateUsrDialog() @@ -322,7 +322,7 @@ attack_hand(user) src.update_icon() - handle_event(var/event) + handle_event(var/event, var/sender) if (event == "reagent_holder_update") src.updateUsrDialog() @@ -599,7 +599,7 @@ qdel(src) return - handle_event(var/event) + handle_event(var/event, var/sender) if (event == "reagent_holder_update") src.updateUsrDialog() diff --git a/code/datums/chemistry/tools/beakers.dm b/code/datums/chemistry/tools/beakers.dm index b7400d75..e6c65a70 100644 --- a/code/datums/chemistry/tools/beakers.dm +++ b/code/datums/chemistry/tools/beakers.dm @@ -38,6 +38,8 @@ var/obj/item/assembly/A = src.master A.c_state(1) + signal_event("icon_updated") + attackby(obj/A as obj, mob/user as mob) if (istype(A, /obj/item/assembly/time_ignite) && !(A:status)) var/obj/item/assembly/time_ignite/W = A diff --git a/code/datums/chemistry/tools/bottles.dm b/code/datums/chemistry/tools/bottles.dm index 442d797a..8589c25b 100644 --- a/code/datums/chemistry/tools/bottles.dm +++ b/code/datums/chemistry/tools/bottles.dm @@ -33,6 +33,7 @@ var/datum/color/average = reagents.get_average_color() fluid_image.color = average.to_rgba() src.underlays += src.fluid_image + signal_event("icon_updated") /* =================================================== */ /* -------------------- Sub-Types -------------------- */ diff --git a/code/datums/chemistry/tools/droppers.dm b/code/datums/chemistry/tools/droppers.dm index 2bceb8dc..cb77cdba 100644 --- a/code/datums/chemistry/tools/droppers.dm +++ b/code/datums/chemistry/tools/droppers.dm @@ -39,9 +39,9 @@ return if (src.reagents.total_volume) - src.icon_state = src.icon_filled + set_icon_state(src.icon_filled) else - src.icon_state = src.icon_empty + set_icon_state(src.icon_empty) return diff --git a/code/datums/chemistry/tools/extinguisher.dm b/code/datums/chemistry/tools/extinguisher.dm index 00c43b9a..1a52f484 100644 --- a/code/datums/chemistry/tools/extinguisher.dm +++ b/code/datums/chemistry/tools/extinguisher.dm @@ -137,12 +137,12 @@ /obj/item/extinguisher/attack_self(mob/user as mob) if (safety) - src.icon_state = "fire_extinguisher1" + set_icon_state("fire_extinguisher1") src.desc = "The safety is off." boutput(user, "The safety is off.") safety = 0 else - src.icon_state = "fire_extinguisher0" + set_icon_state("fire_extinguisher0") src.desc = "The safety is on." boutput(user, "The safety is on.") safety = 1 diff --git a/code/datums/chemistry/tools/food_and_drink.dm b/code/datums/chemistry/tools/food_and_drink.dm index 28ececbc..79d4f08c 100644 --- a/code/datums/chemistry/tools/food_and_drink.dm +++ b/code/datums/chemistry/tools/food_and_drink.dm @@ -488,7 +488,7 @@ if (src.label) bottle_image.icon_state = "label-[label]" src.overlays += bottle_image - return + signal_event("icon_updated") attackby(obj/item/W as obj, mob/user as mob) if (istype(W, /obj/item/pen) && !src.labeled) @@ -590,6 +590,9 @@ if (wedge) var/wedge_icon = icon('icons/obj/drink.dmi', "[glass_style]-[wedge]") src.overlays += image("icon" = wedge_icon, "layer" = FLOAT_LAYER + 1) + + signal_event("icon_updated") + return attackby(obj/item/W as obj, mob/user as mob) diff --git a/code/datums/chemistry/tools/hyposprays.dm b/code/datums/chemistry/tools/hyposprays.dm index 3f29b3e6..be600cb8 100644 --- a/code/datums/chemistry/tools/hyposprays.dm +++ b/code/datums/chemistry/tools/hyposprays.dm @@ -65,6 +65,8 @@ var/global/list/chem_whitelist = list("antihol", "charcoal", "epinephrine", "ins src.name = "hypospray" src.UpdateOverlays(null, "fluid") + signal_event("icon_updated") + on_reagent_change(add) if (src.safe && add) src.check_whitelist() // we only need to purge bad chems if new chems have been added diff --git a/code/datums/chemistry/tools/iv_drips.dm b/code/datums/chemistry/tools/iv_drips.dm index 8f90849b..7c273189 100644 --- a/code/datums/chemistry/tools/iv_drips.dm +++ b/code/datums/chemistry/tools/iv_drips.dm @@ -48,6 +48,7 @@ src.name = "\improper IV drip" if (ismob(src.loc)) src.overlays += src.mode ? "inject" : "draw" + signal_event("icon_updated") is_open_container() return 1 diff --git a/code/datums/chemistry/tools/patches.dm b/code/datums/chemistry/tools/patches.dm index 3afe6c32..67cb36c0 100644 --- a/code/datums/chemistry/tools/patches.dm +++ b/code/datums/chemistry/tools/patches.dm @@ -279,6 +279,7 @@ if (P) src.overlays += image(P.icon, P.icon_state) name = "[initial(src.name)] ([P.name]; [patches.len] patches)" + signal_event("icon_updated") else name = initial(src.name) diff --git a/code/datums/chemistry/tools/syringes.dm b/code/datums/chemistry/tools/syringes.dm index 2d8e936a..ee969d71 100644 --- a/code/datums/chemistry/tools/syringes.dm +++ b/code/datums/chemistry/tools/syringes.dm @@ -196,6 +196,8 @@ src.fluid_image.color = average.to_rgba() src.underlays += src.fluid_image + signal_event("icon_updated") + #undef S_DRAW #undef S_INJECT diff --git a/code/datums/hud/robot.dm b/code/datums/hud/robot.dm index 7dd0580c..427735ec 100644 --- a/code/datums/hud/robot.dm +++ b/code/datums/hud/robot.dm @@ -1,3 +1,6 @@ +#define COLOR_MATRIX_IDENTITY list(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1) +#define COLOR_MATRIX_GRAYSCALE list(0.2126,0.2126,0.2126,0, 0.7152,0.7152,0.7152,0, 0.0722,0.0722,0.0722,0, 0,0,0,1) + /datum/hud/robot var/obj/screen/hud mod1 @@ -58,8 +61,8 @@ var x = 1, y = 10, sx = 1, sy = 10 if (!boxes) return - if (items_screen + 6 > master.module.contents.len) - items_screen = max(master.module.contents.len - 6, 1) + if (items_screen + 6 > master.module.modules.len) + items_screen = max(master.module.modules.len - 6, 1) if (items_screen < 1) items_screen = 1 boxes.screen_loc = "[x], [y] to [x+sx-1], [y-sy+1]" @@ -82,28 +85,46 @@ if (items_screen > 1) prev.icon_state = "up" + prev.color = COLOR_MATRIX_IDENTITY else prev.icon_state = "up_dis" + prev.color = COLOR_MATRIX_GRAYSCALE var/sid = 1 var/i_max = items_screen + 7 - if (i_max <= master.module.contents.len) + if (i_max <= master.module.modules.len) next.icon_state = "down" + next.color = COLOR_MATRIX_IDENTITY else next.icon_state = "down_dis" + next.color = COLOR_MATRIX_GRAYSCALE for (var/i = items_screen, i < i_max, i++) - if (i > master.module.contents.len) + if (i > master.module.modules.len) break - var/obj/item/I = master.module.contents[i] + var/obj/item/I = master.module.modules[i] var/obj/screen/S = screen_tools[sid] - S.name = I.name - S.icon = I.icon - S.icon_state = I.icon_state - S.overlays = I.overlays.Copy() - S.underlays = I.underlays.Copy() - S.color = I.color - S.alpha = I.alpha + if (!I) + // if the item has been deleted, just show an empty slot. + S.name = null + S.icon = 0 + S.icon_state = null + S.overlays = null + S.underlays = null + S.color = COLOR_MATRIX_IDENTITY + S.alpha = 255 + else + S.name = I.name + S.icon = I.icon + S.icon_state = I.icon_state + S.overlays = I.overlays.Copy() + S.underlays = I.underlays.Copy() + if (I.loc == master.module) + S.color = I.color + else + // If the tool is already equipped, set grayscale + S.color = COLOR_MATRIX_GRAYSCALE + S.alpha = I.alpha S.screen_loc = "[x], [y - sid]" add_screen(S) sid++ @@ -116,9 +137,11 @@ update_equipment() return var/content_id = items_screen + i - 1 - if (content_id > master.module.contents.len || content_id < 1) + if (content_id > master.module.modules.len || content_id < 1) boutput(usr, "An error occurred. Please notify Marquesas immediately. (Content ID: [content_id].)") - var/obj/item/O = master.module.contents[content_id] + var/obj/item/O = master.module.modules[content_id] + if(!O || O.loc != master.module) + return if(!master.module_states[1] && istype(master.part_arm_l,/obj/item/parts/robot_parts/arm/)) master.module_states[1] = O O.loc = master @@ -426,3 +449,12 @@ add_object(upgrade, HUD_LAYER+2, "CENTER+[startx+i]:24, SOUTH+1:4") i++ last_upgrades = master.upgrades.Copy() + + proc/handle_event(var/event, var/sender) + . = ..(event, sender) + if (event == "icon_updated") + // this is only ever emitted by atoms + var/atom/senderAtom = sender + if (senderAtom.loc != master.module) + // An equipped tool has changed its icon; refresh module display + update_equipment() diff --git a/code/mob/living/silicon/robot.dm b/code/mob/living/silicon/robot.dm index 138be728..14c27c80 100644 --- a/code/mob/living/silicon/robot.dm +++ b/code/mob/living/silicon/robot.dm @@ -2895,6 +2895,10 @@ else return ..() +/mob/living/silicon/robot/handle_event(var/event, var/sender) + // the HUD will handle icon_updated events, so proxy those + hud.handle_event(event, sender) + /////////////////////////////////////////////////// // Specific instances of robots can go down here // diff --git a/code/obj/item/cable_coil.dm b/code/obj/item/cable_coil.dm index 596ebac9..9ee01290 100644 --- a/code/obj/item/cable_coil.dm +++ b/code/obj/item/cable_coil.dm @@ -103,10 +103,10 @@ if (amount <= 0) qdel(src) else if (amount >= 1 && amount <= 4) - icon_state = "coil[amount]" + set_icon_state("coil[amount]") base_name = "cable piece" else - icon_state = "coil" + set_icon_state("coil") base_name = "cable coil" updateName() diff --git a/code/obj/item/cigarette.dm b/code/obj/item/cigarette.dm index a56bfe3d..da5ecd43 100644 --- a/code/obj/item/cigarette.dm +++ b/code/obj/item/cigarette.dm @@ -691,7 +691,7 @@ user.show_text("Out of fuel.", "red") return src.lit = 1 - src.icon_state = src.icon_open + set_icon_state(src.icon_open) src.item_state = "zippoon" user.visible_message("Without even breaking stride, [user] flips open and lights the [src] in one smooth movement.") @@ -701,7 +701,7 @@ processing_items.Add(src) else src.lit = 0 - src.icon_state = src.icon_closed + set_icon_state(src.icon_closed) src.item_state = "zippo" user.visible_message("You hear a quiet click, as [user] shuts off the [src] without even looking what they're doing. Wow.") @@ -787,7 +787,7 @@ T.hotspot_expose(700,5) if (fuel == 0) src.lit = 0 - src.icon_state = src.icon_closed + set_icon_state(src.icon_closed) src.item_state = "zippo" light.disable() diff --git a/code/obj/item/device/flash.dm b/code/obj/item/device/flash.dm index ed740de3..7b2a5f5d 100644 --- a/code/obj/item/device/flash.dm +++ b/code/obj/item/device/flash.dm @@ -155,7 +155,7 @@ status = 0 src.cell.use(min(src.cell.charge, max_flash_power)) boutput(user, "The bulb has burnt out!") - src.icon_state = "turboflash3" + set_icon_state("turboflash3") src.name = "depleted flash/cell assembly" else @@ -226,7 +226,7 @@ status = 0 src.cell.use(min(src.cell.charge, max_flash_power)) boutput(user, "The bulb has burnt out!") - src.icon_state = "turboflash3" + set_icon_state("turboflash3") src.name = "depleted flash/cell assembly" else src.use++ @@ -238,7 +238,7 @@ if (prob(max(0,(use*2) + burn_mod))) status = 0 boutput(user, "The bulb has burnt out!") - icon_state = "flash3" + set_icon_state("flash3") name = "depleted flash" return @@ -252,7 +252,7 @@ W.set_loc(T) if(!src.status) - T.icon_state = "turboflash3" + T.set_icon_state("turboflash3") T.status = 0 qdel(src) @@ -327,7 +327,7 @@ var/obj/item/device/flash/F = new /obj/item/device/flash( get_turf(src) ) if(!src.status) F.status = 0 - F.icon_state = "flash3" + F.set_icon_state("flash3") qdel(src) else if (istype(W, /obj/item/screwdriver)) boutput(user, "You [src.secure ? "unscrew" : "secure"] the access panel.") diff --git a/code/obj/item/device/flashlight.dm b/code/obj/item/device/flashlight.dm index a5eaa6f4..956d227d 100644 --- a/code/obj/item/device/flashlight.dm +++ b/code/obj/item/device/flashlight.dm @@ -26,7 +26,8 @@ attack_self(mob/user) on = !on - icon_state = "flight[on]" + set_icon_state("flight[on]") + if (on) light.enable() diff --git a/code/obj/item/device/scanners.dm b/code/obj/item/device/scanners.dm index f548055a..74de170d 100644 --- a/code/obj/item/device/scanners.dm +++ b/code/obj/item/device/scanners.dm @@ -27,7 +27,7 @@ Contains: /obj/item/device/t_scanner/attack_self(mob/user) on = !on - icon_state = "t-ray[on]" + set_icon_state("t-ray[on]") if(on && !(src in processing_items)) processing_items.Add(src) @@ -224,11 +224,11 @@ Contains: if (!isnull(A.reagents)) if (A.reagents.reagent_list.len > 0) - src.icon_state = "reagentscan-results" + set_icon_state("reagentscan-results") else - src.icon_state = "reagentscan-no" + set_icon_state("reagentscan-no") else - src.icon_state = "reagentscan-no" + set_icon_state("reagentscan-no") if (isnull(src.scan_results)) boutput(user, "\The [src] encounters an error and crashes!") diff --git a/code/obj/item/gun/energy.dm b/code/obj/item/gun/energy.dm index 0f5476b7..6e952107 100644 --- a/code/obj/item/gun/energy.dm +++ b/code/obj/item/gun/energy.dm @@ -136,7 +136,7 @@ if(cell) var/ratio = min(1, src.cell.charge / src.cell.max_charge) ratio = round(ratio, 0.25) * 100 - src.icon_state = "taser[ratio]" + set_icon_state("taser[ratio]") return borg diff --git a/code/obj/item/hydroponics.dm b/code/obj/item/hydroponics.dm index ae2be95b..52a0ef94 100644 --- a/code/obj/item/hydroponics.dm +++ b/code/obj/item/hydroponics.dm @@ -66,7 +66,7 @@ return proc/update_icon() - icon_state = "[src.base_state][src.active ? null : "_off"]" + set_icon_state("[src.base_state][src.active ? null : "_off"]") return // Fixed a couple of bugs and cleaned code up a little bit (Convair880). diff --git a/code/obj/item/satchel.dm b/code/obj/item/satchel.dm index 1bed9770..48260dc9 100644 --- a/code/obj/item/satchel.dm +++ b/code/obj/item/satchel.dm @@ -95,6 +95,8 @@ if (100 to INFINITY) src.overlays += image('icons/obj/items.dmi', "satcounter5") + signal_event("icon_updated") + /obj/item/satchel/hydro name = "produce satchel" desc = "A leather bag. It holds 0/50 items of produce." diff --git a/code/obj/item/stun_baton.dm b/code/obj/item/stun_baton.dm index 0b1db08c..9b01288c 100644 --- a/code/obj/item/stun_baton.dm +++ b/code/obj/item/stun_baton.dm @@ -97,9 +97,9 @@ return if (src.status) - icon_state = src.icon_on + set_icon_state(src.icon_on) else - icon_state = src.icon_off + set_icon_state(src.icon_off) return diff --git a/code/obj/item/surgery_tools.dm b/code/obj/item/surgery_tools.dm index ed4efec8..078b5f13 100644 --- a/code/obj/item/surgery_tools.dm +++ b/code/obj/item/surgery_tools.dm @@ -329,12 +329,12 @@ BODY BAG return if (src.defibrillate(M, user, src.emagged, src.makeshift, src.cell)) src.charged = 0 - src.icon_state = "[src.icon_base]-shock" + set_icon_state("[src.icon_base]-shock") spawn(10) - src.icon_state = "[src.icon_base]-off" + set_icon_state("[src.icon_base]-off") spawn(src.charge_time) src.charged = 1 - src.icon_state = "[src.icon_base]-on" + set_icon_state("[src.icon_base]-on") playsound(user.loc, "sound/weapons/flash.ogg", 75, 1) disposing() diff --git a/code/obj/item/tools.dm b/code/obj/item/tools.dm index 60e329b7..535352d7 100644 --- a/code/obj/item/tools.dm +++ b/code/obj/item/tools.dm @@ -246,7 +246,7 @@ MATERIAL COLLECTOR src.welding = 0 src.force = 3 src.damtype = "brute" - src.icon_state = "welder" + set_icon_state("welder") user.update_inhands() var/turf/location = user.loc @@ -307,14 +307,14 @@ MATERIAL COLLECTOR boutput(user, "You will now weld when you attack.") src.force = 15 src.damtype = "fire" - src.icon_state = "welder1" + set_icon_state("welder1") if (!(src in processing_items)) processing_items.Add(src) else boutput(user, "Not welding anymore.") src.force = 3 src.damtype = "brute" - src.icon_state = "welder" + set_icon_state("welder") user.update_inhands() return @@ -338,7 +338,7 @@ MATERIAL COLLECTOR welding = 0 force = 3 damtype = "brute" - src.icon_state = "welder" + set_icon_state("welder") processing_items.Remove(src) return diff --git a/code/obj/mining.dm b/code/obj/mining.dm index f2d40faf..bd2de6ca 100644 --- a/code/obj/mining.dm +++ b/code/obj/mining.dm @@ -1225,12 +1225,14 @@ src.status = 1 if (powered_overlay) src.overlays += powered_overlay + signal_event("icon_updated") return proc/power_down() src.status = 0 if (powered_overlay) src.overlays = null + signal_event("icon_updated") return obj/item/clothing/gloves/concussive diff --git a/code/obj/railway.dm b/code/obj/railway.dm index 27faad0a..563eb8c1 100644 --- a/code/obj/railway.dm +++ b/code/obj/railway.dm @@ -49,7 +49,7 @@ if (R) R.adapt(0) - this.set_icon_state() + this.update_icon_state() /obj/railway @@ -79,8 +79,8 @@ proc/entering(var/obj/railway_vehicle/V) - proc/set_icon_state() - icon_state = "[dir1]-[dir2]" + proc/update_icon_state() + set_icon_state("[dir1]-[dir2]") onVarChanged(variable, oldVal, val) ..() @@ -89,7 +89,7 @@ var/D = dir2 dir2 = dir1 dir1 = D - set_icon_state() + update_icon_state() else if (variable == "icon_state") setup_dirs() diff --git a/code/obj/submachine/seed.dm b/code/obj/submachine/seed.dm index a5c9bee1..ee8707bf 100644 --- a/code/obj/submachine/seed.dm +++ b/code/obj/submachine/seed.dm @@ -694,7 +694,7 @@ user << browse(dat, "window=rextractor;size=370x500") onclose(user, "rextractor") - handle_event(var/event) + handle_event(var/event, var/sender) if (event == "reagent_holder_update") src.updateUsrDialog()