Merge pull request #8555 from Ghommie/Ghommie-cit32
Updates radials, makes RCD and RCL use em.
This commit is contained in:
+58
-17
@@ -1,4 +1,7 @@
|
||||
#define NEXT_PAGE_ID "__next__"
|
||||
#define DEFAULT_CHECK_DELAY 20
|
||||
|
||||
GLOBAL_LIST_EMPTY(radial_menus)
|
||||
|
||||
/obj/screen/radial
|
||||
icon = 'icons/mob/radial.dmi'
|
||||
@@ -10,14 +13,19 @@
|
||||
icon_state = "radial_slice"
|
||||
var/choice
|
||||
var/next_page = FALSE
|
||||
var/tooltips = FALSE
|
||||
|
||||
/obj/screen/radial/slice/MouseEntered(location, control, params)
|
||||
. = ..()
|
||||
icon_state = "radial_slice_focus"
|
||||
if(tooltips)
|
||||
openToolTip(usr, src, params, title = name)
|
||||
|
||||
/obj/screen/radial/slice/MouseExited(location, control, params)
|
||||
. = ..()
|
||||
icon_state = "radial_slice"
|
||||
if(tooltips)
|
||||
closeToolTip(usr)
|
||||
|
||||
/obj/screen/radial/slice/Click(location, control, params)
|
||||
if(usr.client == parent.current_user)
|
||||
@@ -30,6 +38,14 @@
|
||||
name = "Close Menu"
|
||||
icon_state = "radial_center"
|
||||
|
||||
/obj/screen/radial/center/MouseEntered(location, control, params)
|
||||
. = ..()
|
||||
icon_state = "radial_center_focus"
|
||||
|
||||
/obj/screen/radial/center/MouseExited(location, control, params)
|
||||
. = ..()
|
||||
icon_state = "radial_center"
|
||||
|
||||
/obj/screen/radial/center/Click(location, control, params)
|
||||
if(usr.client == parent.current_user)
|
||||
parent.finished = TRUE
|
||||
@@ -48,6 +64,9 @@
|
||||
var/atom/anchor
|
||||
var/image/menu_holder
|
||||
var/finished = FALSE
|
||||
var/datum/callback/custom_check_callback
|
||||
var/next_check = 0
|
||||
var/check_delay = DEFAULT_CHECK_DELAY
|
||||
|
||||
var/radius = 32
|
||||
var/starting_angle = 0
|
||||
@@ -57,7 +76,7 @@
|
||||
var/max_elements
|
||||
var/pages = 1
|
||||
var/current_page = 1
|
||||
|
||||
|
||||
var/hudfix_method = TRUE //TRUE to change anchor to user, FALSE to shift by py_shift
|
||||
var/py_shift = 0
|
||||
var/entry_animation = TRUE
|
||||
@@ -75,7 +94,7 @@
|
||||
restrict_to_dir(NORTH) //I was going to parse screen loc here but that's more effort than it's worth.
|
||||
|
||||
//Sets defaults
|
||||
//These assume 45 deg min_angle
|
||||
//These assume 45 deg min_angle
|
||||
/datum/radial_menu/proc/restrict_to_dir(dir)
|
||||
switch(dir)
|
||||
if(NORTH)
|
||||
@@ -91,18 +110,19 @@
|
||||
starting_angle = 180
|
||||
ending_angle = 45
|
||||
|
||||
/datum/radial_menu/proc/setup_menu()
|
||||
/datum/radial_menu/proc/setup_menu(use_tooltips)
|
||||
if(ending_angle > starting_angle)
|
||||
zone = ending_angle - starting_angle
|
||||
else
|
||||
zone = 360 - starting_angle + ending_angle
|
||||
|
||||
|
||||
max_elements = round(zone / min_angle)
|
||||
var/paged = max_elements < choices.len
|
||||
if(elements.len < max_elements)
|
||||
var/elements_to_add = max_elements - elements.len
|
||||
for(var/i in 1 to elements_to_add) //Create all elements
|
||||
var/obj/screen/radial/new_element = new /obj/screen/radial/slice
|
||||
var/obj/screen/radial/slice/new_element = new /obj/screen/radial/slice
|
||||
new_element.tooltips = use_tooltips
|
||||
new_element.parent = src
|
||||
elements += new_element
|
||||
|
||||
@@ -163,7 +183,7 @@
|
||||
else
|
||||
E.pixel_y = py
|
||||
E.pixel_x = px
|
||||
|
||||
|
||||
//Visuals
|
||||
E.alpha = 255
|
||||
E.mouse_opacity = MOUSE_OPACITY_ICON
|
||||
@@ -183,7 +203,7 @@
|
||||
E.next_page = FALSE
|
||||
if(choices_icons[choice_id])
|
||||
E.add_overlay(choices_icons[choice_id])
|
||||
|
||||
|
||||
/datum/radial_menu/New()
|
||||
close_button = new
|
||||
close_button.parent = src
|
||||
@@ -200,7 +220,7 @@
|
||||
/datum/radial_menu/proc/get_next_id()
|
||||
return "c_[choices.len]"
|
||||
|
||||
/datum/radial_menu/proc/set_choices(list/new_choices)
|
||||
/datum/radial_menu/proc/set_choices(list/new_choices, use_tooltips)
|
||||
if(choices.len)
|
||||
Reset()
|
||||
for(var/E in new_choices)
|
||||
@@ -211,7 +231,7 @@
|
||||
var/I = extract_image(new_choices[E])
|
||||
if(I)
|
||||
choices_icons[id] = I
|
||||
setup_menu()
|
||||
setup_menu(use_tooltips)
|
||||
|
||||
|
||||
/datum/radial_menu/proc/extract_image(E)
|
||||
@@ -220,7 +240,7 @@
|
||||
MA.layer = ABOVE_HUD_LAYER
|
||||
MA.appearance_flags |= RESET_TRANSFORM
|
||||
return MA
|
||||
|
||||
|
||||
|
||||
/datum/radial_menu/proc/next_page()
|
||||
if(pages > 1)
|
||||
@@ -243,28 +263,49 @@
|
||||
if(current_user)
|
||||
current_user.images -= menu_holder
|
||||
|
||||
/datum/radial_menu/proc/wait()
|
||||
/datum/radial_menu/proc/wait(atom/user, atom/anchor, require_near = FALSE)
|
||||
while (current_user && !finished && !selected_choice)
|
||||
if(require_near && !in_range(anchor, user))
|
||||
return
|
||||
if(custom_check_callback && next_check < world.time)
|
||||
if(!custom_check_callback.Invoke())
|
||||
return
|
||||
else
|
||||
next_check = world.time + check_delay
|
||||
stoplag(1)
|
||||
|
||||
/datum/radial_menu/Destroy()
|
||||
Reset()
|
||||
hide()
|
||||
QDEL_NULL(custom_check_callback)
|
||||
. = ..()
|
||||
|
||||
/*
|
||||
Presents radial menu to user anchored to anchor (or user if the anchor is currently in users screen)
|
||||
Presents radial menu to user anchored to anchor (or user if the anchor is currently in users screen)
|
||||
Choices should be a list where list keys are movables or text used for element names and return value
|
||||
and list values are movables/icons/images used for element icons
|
||||
*/
|
||||
/proc/show_radial_menu(mob/user,atom/anchor,list/choices)
|
||||
/proc/show_radial_menu(mob/user, atom/anchor, list/choices, uniqueid, radius, datum/callback/custom_check, require_near = FALSE, tooltips = FALSE)
|
||||
if(!user || !anchor || !length(choices))
|
||||
return
|
||||
if(!uniqueid)
|
||||
uniqueid = "defmenu_[REF(user)]_[REF(anchor)]"
|
||||
|
||||
if(GLOB.radial_menus[uniqueid])
|
||||
return
|
||||
|
||||
var/datum/radial_menu/menu = new
|
||||
if(!user)
|
||||
user = usr
|
||||
GLOB.radial_menus[uniqueid] = menu
|
||||
if(radius)
|
||||
menu.radius = radius
|
||||
if(istype(custom_check))
|
||||
menu.custom_check_callback = custom_check
|
||||
menu.anchor = anchor
|
||||
menu.check_screen_border(user) //Do what's needed to make it look good near borders or on hud
|
||||
menu.set_choices(choices)
|
||||
menu.set_choices(choices, tooltips)
|
||||
menu.show_to(user)
|
||||
menu.wait()
|
||||
menu.wait(user, anchor, require_near)
|
||||
var/answer = menu.selected_choice
|
||||
qdel(menu)
|
||||
GLOB.radial_menus -= uniqueid
|
||||
return answer
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
A derivative of radial menu which persists onscreen until closed and invokes a callback each time an element is clicked
|
||||
*/
|
||||
|
||||
/obj/screen/radial/persistent/center
|
||||
name = "Close Menu"
|
||||
icon_state = "radial_center"
|
||||
|
||||
/obj/screen/radial/persistent/center/Click(location, control, params)
|
||||
if(usr.client == parent.current_user)
|
||||
parent.element_chosen(null,usr)
|
||||
|
||||
/obj/screen/radial/persistent/center/MouseEntered(location, control, params)
|
||||
. = ..()
|
||||
icon_state = "radial_center_focus"
|
||||
|
||||
/obj/screen/radial/persistent/center/MouseExited(location, control, params)
|
||||
. = ..()
|
||||
icon_state = "radial_center"
|
||||
|
||||
|
||||
|
||||
/datum/radial_menu/persistent
|
||||
var/uniqueid
|
||||
var/datum/callback/select_proc_callback
|
||||
|
||||
/datum/radial_menu/persistent/New()
|
||||
close_button = new /obj/screen/radial/persistent/center
|
||||
close_button.parent = src
|
||||
|
||||
|
||||
/datum/radial_menu/persistent/element_chosen(choice_id,mob/user)
|
||||
select_proc_callback.Invoke(choices_values[choice_id])
|
||||
|
||||
|
||||
/datum/radial_menu/persistent/proc/change_choices(list/newchoices, tooltips)
|
||||
if(!newchoices.len)
|
||||
return
|
||||
Reset()
|
||||
set_choices(newchoices,tooltips)
|
||||
|
||||
/datum/radial_menu/persistent/Destroy()
|
||||
QDEL_NULL(select_proc_callback)
|
||||
GLOB.radial_menus -= uniqueid
|
||||
Reset()
|
||||
hide()
|
||||
. = ..()
|
||||
|
||||
/*
|
||||
Creates a persistent radial menu and shows it to the user, anchored to anchor (or user if the anchor is currently in users screen).
|
||||
Choices should be a list where list keys are movables or text used for element names and return value
|
||||
and list values are movables/icons/images used for element icons
|
||||
Select_proc is the proc to be called each time an element on the menu is clicked, and should accept the chosen element as its final argument
|
||||
Clicking the center button will return a choice of null
|
||||
*/
|
||||
/proc/show_radial_menu_persistent(mob/user, atom/anchor, list/choices, datum/callback/select_proc, uniqueid, radius, tooltips = FALSE)
|
||||
if(!user || !anchor || !length(choices) || !select_proc)
|
||||
return
|
||||
if(!uniqueid)
|
||||
uniqueid = "defmenu_[REF(user)]_[REF(anchor)]"
|
||||
|
||||
if(GLOB.radial_menus[uniqueid])
|
||||
return
|
||||
|
||||
var/datum/radial_menu/persistent/menu = new
|
||||
menu.uniqueid = uniqueid
|
||||
GLOB.radial_menus[uniqueid] = menu
|
||||
if(radius)
|
||||
menu.radius = radius
|
||||
menu.select_proc_callback = select_proc
|
||||
menu.anchor = anchor
|
||||
menu.check_screen_border(user) //Do what's needed to make it look good near borders or on hud
|
||||
menu.set_choices(choices, tooltips)
|
||||
menu.show_to(user)
|
||||
return menu
|
||||
|
||||
Reference in New Issue
Block a user