From 0a244dc7b7c79a3d1a0bd74e0a24d2a31075f3ad Mon Sep 17 00:00:00 2001 From: Aranclanos Date: Sun, 7 Jul 2013 02:03:58 -0300 Subject: [PATCH] The item_action buttons will now recycle themselves, instead of getting deleting each tick to generate new ones. These buttons are the ones top left of the human screen, usually toggling on and off certain items. I expect to reduce 50% the amount of atom/movable/Del() calls with this. --- code/datums/hud.dm | 2 +- code/modules/mob/living/carbon/human/hud.dm | 26 ++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/code/datums/hud.dm b/code/datums/hud.dm index 4d251c0cdca..047a42e31ba 100644 --- a/code/datums/hud.dm +++ b/code/datums/hud.dm @@ -175,7 +175,7 @@ var/datum/global_hud/global_hud = new() var/list/other var/list/obj/screen/hotkeybuttons - var/list/obj/screen/item_action/item_action_list //Used for the item action ui buttons. + var/list/obj/screen/item_action/item_action_list = list() //Used for the item action ui buttons. datum/hud/New(mob/owner) diff --git a/code/modules/mob/living/carbon/human/hud.dm b/code/modules/mob/living/carbon/human/hud.dm index 58a1d4f672b..e2514d64150 100644 --- a/code/modules/mob/living/carbon/human/hud.dm +++ b/code/modules/mob/living/carbon/human/hud.dm @@ -330,23 +330,29 @@ return client.screen -= hud_used.item_action_list - hud_used.item_action_list = list() for(var/obj/item/I in src) if(I.action_button_name) - var/obj/screen/item_action/A = new(hud_used) + if(hud_used.item_action_list.len < num) + var/obj/screen/item_action/N = new(hud_used) + hud_used.item_action_list += N + + var/obj/screen/item_action/A = hud_used.item_action_list[num] + A.icon = ui_style2icon(client.prefs.UI_style) A.icon_state = "template" - var/image/img = image(I.icon, I.icon_state) + + A.overlays = list() + var/image/img = image(I.icon, A, I.icon_state) img.pixel_x = 0 img.pixel_y = 0 A.overlays += img - if(I.action_button_name) - A.name = I.action_button_name - else - A.name = "Use [I.name]" + + A.name = I.action_button_name A.owner = I - hud_used.item_action_list += A + + client.screen += hud_used.item_action_list[num] + switch(num) if(1) A.screen_loc = ui_action_slot1 @@ -359,6 +365,4 @@ if(5) A.screen_loc = ui_action_slot5 break //5 slots available, so no more can be added. - num++ - - client.screen += hud_used.item_action_list \ No newline at end of file + num++ \ No newline at end of file