Skip to content

Commit

Permalink
Merge pull request #3440 from MistakeNot4892/equip_mouseover
Browse files Browse the repository at this point in the history
Mousing over an inventory slot will now show you whether or not your current active item can be equipped.
  • Loading branch information
out-of-phaze authored Oct 15, 2023
2 parents a5a3445 + 391570e commit 9a1d8db
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 16 deletions.
1 change: 0 additions & 1 deletion code/_onclick/hud/gun_mode.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/obj/screen/gun
name = "gun"
icon = 'icons/mob/screen1.dmi'
master = null
dir = SOUTH

/obj/screen/gun/Click(location, control, params)
Expand Down
16 changes: 7 additions & 9 deletions code/_onclick/hud/hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,16 @@
inv_box = existing_box
break
if(!inv_box)
inv_box = new /obj/screen/inventory()
inv_box = new /obj/screen/inventory(null, mymob)
inv_box.SetName(hand_tag)
inv_box.icon = ui_style
inv_box.icon_state = "hand_base"

inv_box.cut_overlays()
inv_box.add_overlay("hand_[hand_tag]")
inv_box.add_overlay("hand_[hand_tag]", TRUE)
if(inv_slot.ui_label)
inv_box.add_overlay("hand_[inv_slot.ui_label]")
if(mymob.get_active_held_item_slot() == hand_tag)
inv_box.add_overlay("hand_selected")
inv_box.compile_overlays()
inv_box.add_overlay("hand_[inv_slot.ui_label]", TRUE)
inv_box.update_icon()

inv_box.slot_id = hand_tag
inv_box.color = ui_color
Expand Down Expand Up @@ -236,7 +234,7 @@
if(gear_slot in held_slots)
continue

inv_box = new /obj/screen/inventory()
inv_box = new /obj/screen/inventory(null, mymob)
inv_box.icon = ui_style
inv_box.color = ui_color
inv_box.alpha = ui_alpha
Expand Down Expand Up @@ -287,7 +285,7 @@
var/list/held_slots = mymob.get_held_item_slots()
if(length(held_slots) > 1)

using = new /obj/screen/inventory()
using = new /obj/screen/inventory(null, mymob)
using.SetName("hand")
using.icon = ui_style
using.icon_state = "hand1"
Expand All @@ -296,7 +294,7 @@
src.adding += using
LAZYADD(swaphand_hud_objects, using)

using = new /obj/screen/inventory()
using = new /obj/screen/inventory(null, mymob)
using.SetName("hand")
using.icon = ui_style
using.icon_state = "hand2"
Expand Down
84 changes: 78 additions & 6 deletions code/_onclick/hud/screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
layer = HUD_BASE_LAYER
appearance_flags = NO_CLIENT_COLOR
unacidable = 1
var/obj/master = null //A reference to the object in the slot. Grabs or items, generally.
var/globalscreen = FALSE //Global screens are not qdeled when the holding mob is destroyed.

/obj/screen/receive_mouse_drop(atom/dropping, mob/user)
Expand All @@ -22,10 +21,6 @@
/obj/screen/check_mousedrop_interactivity(var/mob/user)
return user.client && (src in user.client.screen)

/obj/screen/Destroy()
master = null
return ..()

/obj/screen/text
icon = null
icon_state = null
Expand All @@ -34,13 +29,84 @@
maptext_height = 480
maptext_width = 480


/obj/screen/inventory
var/slot_id //The indentifier for the slot. It has nothing to do with ID cards.
var/weakref/mouse_over_atom_ref
var/weakref/owner_ref

/obj/screen/inventory/Initialize(var/ml, var/mob/_owner)
if(!istype(_owner))
PRINT_STACK_TRACE("Inventory screen object supplied a non-mob owner!")
owner_ref = weakref(_owner)
return ..()

/obj/screen/inventory/MouseDrop()
. = ..()
mouse_over_atom_ref = null
update_icon()

/obj/screen/inventory/Click()
. = ..()
mouse_over_atom_ref = null
update_icon()

/obj/screen/inventory/MouseEntered(location, control, params)
. = ..()
if(!slot_id || !usr)
return
var/equipped_item = usr.get_active_hand()
if(equipped_item)
var/new_mouse_over_atom = weakref(equipped_item)
if(new_mouse_over_atom != mouse_over_atom_ref)
mouse_over_atom_ref = new_mouse_over_atom
update_icon()

/obj/screen/inventory/MouseExited(location, control, params)
. = ..()
if(mouse_over_atom_ref)
mouse_over_atom_ref = null
update_icon()

/obj/screen/inventory/on_update_icon()

cut_overlays()

// Validate our owner still exists.
var/mob/owner = owner_ref?.resolve()
if(!istype(owner) || QDELETED(owner) || !(src in owner.client?.screen))
return

// Mark our selected hand.
if(owner.get_active_held_item_slot() == slot_id)
add_overlay("hand_selected")

// Mark anything we're potentially trying to equip.
var/obj/item/mouse_over_atom = mouse_over_atom_ref?.resolve()
if(istype(mouse_over_atom) && !QDELETED(mouse_over_atom) && !usr.get_equipped_item(slot_id))
var/mutable_appearance/MA = new /mutable_appearance(mouse_over_atom)
MA.layer = HUD_ABOVE_ITEM_LAYER
MA.plane = HUD_PLANE
MA.alpha = 80
MA.color = mouse_over_atom.mob_can_equip(owner, slot_id, TRUE) ? COLOR_GREEN : COLOR_RED
MA.pixel_x = mouse_over_atom.default_pixel_x
MA.pixel_y = mouse_over_atom.default_pixel_y
MA.pixel_w = mouse_over_atom.default_pixel_w
MA.pixel_z = mouse_over_atom.default_pixel_z
add_overlay(MA)
else
mouse_over_atom_ref = null

// UI needs to be responsive so avoid the subsecond update delay.
compile_overlays()

/obj/screen/close
name = "close"
// A reference to the storage item this atom is associated with.
var/obj/master

/obj/screen/close/Destroy()
master = null
return ..()

/obj/screen/close/Click()
if(master)
Expand Down Expand Up @@ -113,6 +179,12 @@

/obj/screen/storage
name = "storage"
// A reference to the storage item this atom is associated with.
var/obj/master

/obj/screen/storage/Destroy()
master = null
return ..()

/obj/screen/storage/Click()
if(!usr.canClick())
Expand Down

0 comments on commit 9a1d8db

Please sign in to comment.