Merge pull request #5095 from tigercat2000/ACTION_BUTTONS

Action Button Update
This commit is contained in:
Fox McCloud
2016-07-19 23:40:51 -04:00
committed by GitHub
97 changed files with 1237 additions and 1022 deletions
-315
View File
@@ -1,315 +0,0 @@
#define AB_ITEM 1
#define AB_SPELL 2
#define AB_INNATE 3
#define AB_GENERIC 4
#define AB_CHECK_RESTRAINED 1
#define AB_CHECK_STUNNED 2
#define AB_CHECK_LYING 4
#define AB_CHECK_ALIVE 8
#define AB_CHECK_INSIDE 16
/datum/action
var/name = "Generic Action"
var/action_type = AB_ITEM
var/procname = null
var/atom/movable/target = null
var/check_flags = 0
var/processing = 0
var/active = 0
var/obj/screen/movable/action_button/button = null
var/button_icon = 'icons/mob/actions.dmi'
var/button_icon_state = "default"
var/background_icon_state = "bg_default"
var/mob/living/owner
/datum/action/New(var/Target)
target = Target
/datum/action/Destroy()
if(owner)
Remove(owner)
if(target)
target = null
return ..()
/datum/action/proc/Grant(mob/living/T)
if(owner)
if(owner == T)
return
Remove(owner)
owner = T
owner.actions.Add(src)
owner.update_action_buttons()
return
/datum/action/proc/Remove(mob/living/T)
if(button)
if(T.client)
T.client.screen -= button
qdel(button)
button = null
if(T.actions)
T.actions.Remove(src)
T.update_action_buttons()
owner = null
return
/datum/action/proc/Trigger()
if(!Checks())
return
switch(action_type)
if(AB_ITEM)
if(target)
var/obj/item/item = target
item.ui_action_click()
if(AB_SPELL)
if(target)
var/obj/effect/proc_holder/spell = target
spell.Click()
if(AB_INNATE)
if(!active)
Activate()
else
Deactivate()
if(AB_GENERIC)
if(target && procname)
call(target,procname)(usr)
return
/datum/action/proc/Activate()
return
/datum/action/proc/Deactivate()
return
/datum/action/proc/Process()
return
/datum/action/proc/CheckRemoval(mob/living/user) // 1 if action is no longer valid for this mob and should be removed
return 0
/datum/action/proc/IsAvailable()
return Checks()
/datum/action/proc/Checks()// returns 1 if all checks pass
if(!owner)
return 0
if(check_flags & AB_CHECK_RESTRAINED)
if(owner.restrained())
return 0
if(check_flags & AB_CHECK_STUNNED)
if(owner.stunned)
return 0
if(check_flags & AB_CHECK_LYING)
if(owner.lying)
return 0
if(check_flags & AB_CHECK_ALIVE)
if(owner.stat)
return 0
if(check_flags & AB_CHECK_INSIDE)
if(!(target in owner))
return 0
return 1
/datum/action/proc/UpdateName()
return name
/obj/screen/movable/action_button
var/datum/action/owner
screen_loc = "WEST,NORTH"
/obj/screen/movable/action_button/Click(location,control,params)
var/list/modifiers = params2list(params)
if(modifiers["shift"])
moved = 0
return 1
if(usr.next_move >= world.time) // Is this needed ?
return
owner.Trigger()
return 1
/obj/screen/movable/action_button/proc/UpdateIcon()
if(!owner)
return
icon = owner.button_icon
icon_state = owner.background_icon_state
overlays.Cut()
var/image/img
if(owner.action_type == AB_ITEM && owner.target)
var/obj/item/I = owner.target
img = image(I.icon, src , I.icon_state)
else if(owner.button_icon && owner.button_icon_state)
img = image(owner.button_icon,src,owner.button_icon_state)
img.pixel_x = 0
img.pixel_y = 0
overlays += img
if(!owner.IsAvailable())
color = rgb(128,0,0,128)
else
color = rgb(255,255,255,255)
//Hide/Show Action Buttons ... Button
/obj/screen/movable/action_button/hide_toggle
name = "Hide Buttons"
icon = 'icons/mob/actions.dmi'
icon_state = "bg_default"
var/hidden = 0
/obj/screen/movable/action_button/hide_toggle/Click()
usr.hud_used.action_buttons_hidden = !usr.hud_used.action_buttons_hidden
hidden = usr.hud_used.action_buttons_hidden
if(hidden)
name = "Show Buttons"
else
name = "Hide Buttons"
UpdateIcon()
usr.update_action_buttons()
/obj/screen/movable/action_button/hide_toggle/proc/InitialiseIcon(var/mob/living/user)
if(isalien(user))
icon_state = "bg_alien"
else
icon_state = "bg_default"
UpdateIcon()
return
/obj/screen/movable/action_button/hide_toggle/UpdateIcon()
overlays.Cut()
var/image/img = image(icon,src,hidden?"show":"hide")
overlays += img
return
//This is the proc used to update all the action buttons. Properly defined in /mob/living/
/mob/proc/update_action_buttons()
return
#define AB_WEST_OFFSET 4
#define AB_NORTH_OFFSET 26
#define AB_MAX_COLUMNS 10
/datum/hud/proc/ButtonNumberToScreenCoords(var/number) // TODO : Make this zero-indexed for readabilty
var/row = round((number-1)/AB_MAX_COLUMNS)
var/col = ((number - 1)%(AB_MAX_COLUMNS)) + 1
var/coord_col = "+[col-1]"
var/coord_col_offset = 4+2*col
var/coord_row = "[-1 - row]"
var/coord_row_offset = 26
return "WEST[coord_col]:[coord_col_offset],NORTH[coord_row]:[coord_row_offset]"
/datum/hud/proc/SetButtonCoords(var/obj/screen/button,var/number)
var/row = round((number-1)/AB_MAX_COLUMNS)
var/col = ((number - 1)%(AB_MAX_COLUMNS)) + 1
var/x_offset = 32*(col-1) + 4 + 2*col
var/y_offset = -32*(row+1) + 26
var/matrix/M = matrix()
M.Translate(x_offset,y_offset)
button.transform = M
//Presets for item actions
/datum/action/item_action
check_flags = AB_CHECK_RESTRAINED|AB_CHECK_STUNNED|AB_CHECK_LYING|AB_CHECK_ALIVE|AB_CHECK_INSIDE
/datum/action/item_action/CheckRemoval(mob/living/user)
return get(target, /mob/living) != user
/datum/action/item_action/hands_free
check_flags = AB_CHECK_ALIVE|AB_CHECK_INSIDE
// for clothing accessories like holsters
/datum/action/item_action/accessory
check_flags = AB_CHECK_RESTRAINED|AB_CHECK_STUNNED|AB_CHECK_LYING|AB_CHECK_ALIVE
/datum/action/item_action/accessory/Checks()
. = ..()
if(!.)
return 0
if(target.loc == owner)
return 1
if(istype(target.loc, /obj/item/clothing/under) && target.loc.loc == owner)
return 1
return 0
///prset for organ actions
/datum/action/item_action/organ_action
check_flags = AB_CHECK_ALIVE
/datum/action/item_action/organ_action/CheckRemoval(mob/living/carbon/user)
if(!iscarbon(user))
return 1
if(target in user.internal_organs)
return 0
return 1
/datum/action/item_action/organ_action/IsAvailable()
var/obj/item/organ/internal/I = target
if(!I.owner)
return 0
return ..()
//Preset for spells
/datum/action/spell_action
action_type = AB_SPELL
check_flags = 0
background_icon_state = "bg_spell"
/datum/action/spell_action/UpdateName()
var/obj/effect/proc_holder/spell/spell = target
if(!spell)
return 0
return spell.name
/datum/action/spell_action/IsAvailable()
if(!target)
return 0
var/obj/effect/proc_holder/spell/spell = target
if(usr)
return spell.can_cast(usr)
else
if(owner)
return spell.can_cast(owner)
return 1
/datum/action/spell_action/CheckRemoval()
if(owner.mind)
if(target in owner.mind.spell_list)
return 0
return !(target in owner.spell_list)
//Action button controlling a mob's research examine ability.
/datum/action/scan_mode
name = "Toggle Research Scanner"
button_icon_state = "scan_mode"
check_flags = AB_CHECK_RESTRAINED|AB_CHECK_STUNNED|AB_CHECK_ALIVE
action_type = AB_INNATE
var/devices = 0 //How may enabled scanners the mob has
/datum/action/scan_mode/Activate()
active = 1
owner.research_scanner = 1
to_chat(owner, "<span class='notice'> Research analyzer is now active.</span>")
/datum/action/scan_mode/Deactivate()
active = 0
owner.research_scanner = 0
to_chat(owner, "<span class='notice'> Research analyzer deactivated.</span>")
/datum/action/scan_mode/Grant(mob/living/T)
devices += 1
..(T)
/datum/action/scan_mode/CheckRemoval(mob/living/user)
if(devices)
return 0
return 1
/datum/action/scan_mode/Remove(mob/living/T)
owner.research_scanner = 0
..(T)
+127
View File
@@ -0,0 +1,127 @@
/obj/screen/movable/action_button
var/datum/action/linked_action
screen_loc = null
/obj/screen/movable/action_button/Click(location,control,params)
var/list/modifiers = params2list(params)
if(modifiers["shift"])
moved = 0
usr.update_action_buttons() //redraw buttons that are no longer considered "moved"
return 1
if(usr.next_move >= world.time) // Is this needed ?
return
linked_action.Trigger()
return 1
//Hide/Show Action Buttons ... Button
/obj/screen/movable/action_button/hide_toggle
name = "Hide Buttons"
icon = 'icons/mob/actions.dmi'
icon_state = "bg_default"
var/hidden = 0
/obj/screen/movable/action_button/hide_toggle/Click(location,control,params)
var/list/modifiers = params2list(params)
if(modifiers["shift"])
moved = 0
return 1
usr.hud_used.action_buttons_hidden = !usr.hud_used.action_buttons_hidden
hidden = usr.hud_used.action_buttons_hidden
if(hidden)
name = "Show Buttons"
else
name = "Hide Buttons"
UpdateIcon()
usr.update_action_buttons()
/obj/screen/movable/action_button/hide_toggle/proc/InitialiseIcon(mob/living/user)
if(isalien(user))
icon_state = "bg_alien"
else
icon_state = "bg_default"
UpdateIcon()
/obj/screen/movable/action_button/hide_toggle/proc/UpdateIcon()
overlays.Cut()
var/image/img = image(icon, src, hidden ? "show" : "hide")
overlays += img
/obj/screen/movable/action_button/MouseEntered(location,control,params)
openToolTip(usr,src,params,title = name,content = desc)
/obj/screen/movable/action_button/MouseExited()
closeToolTip(usr)
/mob/proc/update_action_buttons_icon()
for(var/X in actions)
var/datum/action/A = X
A.UpdateButtonIcon()
//This is the proc used to update all the action buttons.
/mob/proc/update_action_buttons(reload_screen)
if(!hud_used || !client)
return
if(hud_used.hud_shown != HUD_STYLE_STANDARD)
return
var/button_number = 0
if(hud_used.action_buttons_hidden)
for(var/datum/action/A in actions)
A.button.screen_loc = null
if(reload_screen)
client.screen += A.button
else
for(var/datum/action/A in actions)
button_number++
A.UpdateButtonIcon()
var/obj/screen/movable/action_button/B = A.button
if(!B.moved)
B.screen_loc = hud_used.ButtonNumberToScreenCoords(button_number)
else
B.screen_loc = B.moved
if(reload_screen)
client.screen += B
if(!button_number)
hud_used.hide_actions_toggle.screen_loc = null
return
if(!hud_used.hide_actions_toggle.moved)
hud_used.hide_actions_toggle.screen_loc = hud_used.ButtonNumberToScreenCoords(button_number+1)
else
hud_used.hide_actions_toggle.screen_loc = hud_used.hide_actions_toggle.moved
if(reload_screen)
client.screen += hud_used.hide_actions_toggle
#define AB_MAX_COLUMNS 10
/datum/hud/proc/ButtonNumberToScreenCoords(number) // TODO : Make this zero-indexed for readabilty
var/row = round((number - 1)/AB_MAX_COLUMNS)
var/col = ((number - 1)%(AB_MAX_COLUMNS)) + 1
var/coord_col = "+[col-1]"
var/coord_col_offset = 4 + 2 * col
var/coord_row = "[row ? -row : "+0"]"
return "WEST[coord_col]:[coord_col_offset],NORTH[coord_row]:-6"
/datum/hud/proc/SetButtonCoords(obj/screen/button,number)
var/row = round((number-1)/AB_MAX_COLUMNS)
var/col = ((number - 1)%(AB_MAX_COLUMNS)) + 1
var/x_offset = 32*(col-1) + 4 + 2*col
var/y_offset = -32*(row+1) + 26
var/matrix/M = matrix()
M.Translate(x_offset,y_offset)
button.transform = M
+8 -2
View File
@@ -36,12 +36,16 @@
var/obj/screen/movable/action_button/hide_toggle/hide_actions_toggle
var/action_buttons_hidden = 0
var/obj/screen/internals
/mob/proc/create_mob_hud()
if(client && !hud_used)
hud_used = new /datum/hud(src)
/datum/hud/New(mob/owner)
mymob = owner
hide_actions_toggle = new
hide_actions_toggle.InitialiseIcon(mymob)
/datum/hud/Destroy()
if(mymob.hud_used == src)
@@ -79,7 +83,6 @@
//clear mob refs to screen objects
mymob.throw_icon = null
mymob.internals = null
mymob.healths = null
mymob.healthdoll = null
mymob.pullin = null
@@ -92,6 +95,7 @@
alien_plasma_display = null
vampire_blood_display = null
nightvisionicon = null
internals = null
mymob = null
return ..()
@@ -122,6 +126,8 @@
if(infodisplay.len)
mymob.client.screen += infodisplay
mymob.client.screen += hide_actions_toggle
if(action_intent)
action_intent.screen_loc = initial(action_intent.screen_loc) //Restore intent selection to the original position
@@ -158,7 +164,7 @@
hud_version = display_hud_version
persistant_inventory_update()
mymob.update_action_buttons()
mymob.update_action_buttons(1)
reorganize_alerts()
reload_fullscreen()
+2 -2
View File
@@ -305,8 +305,8 @@
mymob.throw_icon.alpha = ui_alpha
hotkeybuttons += mymob.throw_icon
mymob.internals = new /obj/screen/internals()
infodisplay += mymob.internals
internals = new /obj/screen/internals()
infodisplay += internals
mymob.healths = new /obj/screen/healths()
infodisplay += mymob.healths
+2 -2
View File
@@ -96,8 +96,8 @@
mymob.throw_icon.alpha = ui_alpha
hotkeybuttons += mymob.throw_icon
mymob.internals = new /obj/screen/internals()
infodisplay += mymob.internals
internals = new /obj/screen/internals()
infodisplay += internals
mymob.healths = new /obj/screen/healths()
infodisplay += mymob.healths
+1 -1
View File
@@ -43,7 +43,7 @@
var/pix_Y = text2num(screen_loc_Y[2]) - 16
screen_loc = "[screen_loc_X[1]]:[pix_X],[screen_loc_Y[1]]:[pix_Y]"
moved = TRUE
moved = screen_loc
//Debug procs
+82 -97
View File
@@ -96,114 +96,99 @@
screen_loc = ui_internal
/obj/screen/internals/Click()
if(iscarbon(usr))
var/mob/living/carbon/C = usr
if(!C.stat && !C.stunned && !C.paralysis && !C.restrained())
if(C.internal)
C.internal = null
to_chat(C, "<span class='notice'>No longer running on internals.</span>")
if(C.internals)
C.internals.icon_state = "internal0"
else
if(!iscarbon(usr))
return
var/mob/living/carbon/C = usr
if(C.incapacitated())
return
var/no_mask
if(!(C.wear_mask && C.wear_mask.flags & AIRTIGHT))
if(ishuman(C))
var/mob/living/carbon/human/H = C
if(!(H.head && H.head.flags & AIRTIGHT))
no_mask = 1
if(C.internal)
C.internal = null
to_chat(C, "<span class='notice'>No longer running on internals.</span>")
icon_state = "internal0"
else
var/no_mask = FALSE
if(!C.wear_mask || !(C.wear_mask.flags & AIRTIGHT))
if(ishuman(C))
var/mob/living/carbon/human/H = C
if(!H.head || !(H.head.flags & AIRTIGHT))
no_mask = TRUE
if(no_mask)
to_chat(C, "<span class='notice'>You are not wearing a suitable mask or helmet.</span>")
return 1
else
var/list/nicename = null
var/list/tankcheck = null
var/breathes = "oxygen" //default, we'll check later
var/list/contents = list()
var/from = "on"
if(no_mask)
to_chat(C, "<span class='notice'>You are not wearing a suitable mask or helmet.</span>")
return
if(ishuman(C))
var/mob/living/carbon/human/H = C
breathes = H.species.breath_type
nicename = list ("suit", "back", "belt", "right hand", "left hand", "left pocket", "right pocket")
tankcheck = list (H.s_store, C.back, H.belt, C.r_hand, C.l_hand, H.l_store, H.r_store)
else
nicename = list("right hand", "left hand", "back")
tankcheck = list(C.r_hand, C.l_hand, C.back)
var/list/nicename = null
var/list/tankcheck = null
var/breathes = "oxygen"
var/list/contents = list()
var/from = "on"
// Rigs are a fucking pain since they keep an air tank in nullspace.
if(istype(C.back,/obj/item/weapon/rig))
var/obj/item/weapon/rig/rig = C.back
if(rig.air_supply)
from = "in"
nicename |= "hardsuit"
tankcheck |= rig.air_supply
for(var/i=1, i<tankcheck.len+1, ++i)
if(istype(tankcheck[i], /obj/item/weapon/tank))
var/obj/item/weapon/tank/t = tankcheck[i]
/* if(!isnull(t.manipulated_by) && t.manipulated_by != C.real_name && findtext(t.desc,breathes))
contents.Add(t.air_contents.total_moles) Someone messed with the tank and put unknown gasses
continue in it, so we're going to believe the tank is what it says it is*/
switch(breathes)
//These tanks we're sure of their contents
if("nitrogen") //So we're a bit more picky about them.
if(t.air_contents.nitrogen && !t.air_contents.oxygen)
contents.Add(t.air_contents.nitrogen)
else
contents.Add(0)
if("oxygen")
if(t.air_contents.oxygen && !t.air_contents.toxins)
contents.Add(t.air_contents.oxygen)
else
contents.Add(0)
// No races breath this, but never know about downstream servers.
if("carbon dioxide")
if(t.air_contents.carbon_dioxide && !t.air_contents.toxins)
contents.Add(t.air_contents.carbon_dioxide)
else
contents.Add(0)
// ACK ACK ACK Plasmen
if("plasma")
if(t.air_contents.toxins)
contents.Add(t.air_contents.toxins)
else
contents.Add(0)
if(ishuman(C))
var/mob/living/carbon/human/H = C
breathes = H.species.breath_type
nicename = list("suit", "back", "belt", "right hand", "left hand", "left pocket", "right pocket")
tankcheck = list(H.s_store, C.back, H.belt, C.r_hand, C.l_hand, H.l_store, H.r_store)
else
nicename = list("right hand", "left hand", "back")
tankcheck = list(C.r_hand, C.l_hand, C.back)
// Rigs are a fucking pain since they keep an air tank in nullspace.
if(istype(C.back,/obj/item/weapon/rig))
var/obj/item/weapon/rig/rig = C.back
if(rig.air_supply)
from = "in"
nicename |= "hardsuit"
tankcheck |= rig.air_supply
for(var/i = 1, i < tankcheck.len + 1, ++i)
if(istype(tankcheck[i], /obj/item/weapon/tank))
var/obj/item/weapon/tank/t = tankcheck[i]
switch(breathes)
if("nitrogen")
if(t.air_contents.nitrogen && !t.air_contents.oxygen)
contents.Add(t.air_contents.nitrogen)
else
//no tank so we set contents to 0
contents.Add(0)
if("oxygen")
if(t.air_contents.oxygen && !t.air_contents.toxins)
contents.Add(t.air_contents.oxygen)
else
contents.Add(0)
if("carbon dioxide")
if(t.air_contents.carbon_dioxide && !t.air_contents.toxins)
contents.Add(t.air_contents.carbon_dioxide)
else
contents.Add(0)
if("plasma")
if(t.air_contents.toxins)
contents.Add(t.air_contents.toxins)
else
contents.Add(0)
else
//no tank so we set contents to 0
contents.Add(0)
//Alright now we know the contents of the tanks so we have to pick the best one.
//Alright now we know the contents of the tanks so we have to pick the best one.
var/best = 0
var/bestcontents = 0
for(var/i=1, i < contents.len + 1 , ++i)
if(!contents[i])
continue
if(contents[i] > bestcontents)
best = i
bestcontents = contents[i]
//We've determined the best container now we set it as our internals
if(best)
to_chat(C, "<span class='notice'>You are now running on internals from [tankcheck[best]] [from] your [nicename[best]].</span>")
C.internal = tankcheck[best]
var/best = 0
var/bestcontents = 0
for(var/i=1, i < contents.len + 1 , ++i)
if(!contents[i])
continue
if(contents[i] > bestcontents)
best = i
bestcontents = contents[i]
if(C.internal)
icon_state = "internal1"
else
to_chat(C, "<span class='notice'>You don't have a[breathes == "oxygen" ? "n oxygen" : addtext(" ",breathes)] tank.</span>")
//We've determined the best container now we set it as our internals
if(best)
to_chat(C, "<span class='notice'>You are now running on internals from [tankcheck[best]] [from] your [nicename[best]].</span>")
C.internal = tankcheck[best]
if(C.internal)
if(C.internals)
C.internals.icon_state = "internal1"
else
to_chat(C, "<span class='notice'>You don't have a[breathes=="oxygen" ? "n oxygen" : addtext(" ",breathes)] tank.</span>")
C.update_action_buttons_icon()
/obj/screen/mov_intent
name = "run/walk toggle"