mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-22 11:37:40 +01:00
TGUI Color Picker (#26326)
* Init * Implements `tgui_input_color` * Implements most color wheel conversions to TGUI * Iteration two, went over titles and made sure most color inputs are functional. * Implements preferences for large buttons, swapped buttons, and disabled TGUI * Iteration three... the weird ones. (as null|color) * Removes `as color|null` and `as null|color` * Merge conflict resolution, again. * Color input bundle and panel bundle * CSLint being picky. * Picky `while ()` instead of `while()` * Apply suggestions from code review Co-authored-by: Aylong <69762909+AyIong@users.noreply.github.com> Signed-off-by: Spaghetti-bit <yumyumkillkill@gmail.com> * WIP * de-bri'ish colour into color Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> Signed-off-by: Spaghetti-bit <yumyumkillkill@gmail.com> * Aylong review applied. - Removed an extra space in machine.dm - UI_STATE + Runechat color now uses TGUI_INPUT_COLOR * Apply suggestions from code review Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com> Signed-off-by: Spaghetti-bit <yumyumkillkill@gmail.com> * Removes an unintentional space to `paradise.scss` * Update code/modules/tgui/tgui_input/color_input.dm Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com> Signed-off-by: Spaghetti-bit <yumyumkillkill@gmail.com> * Adds "is_color" regex from TG * Fixes a few conflicting files * TGUI Merge conflict moment v3 * V4? * V5.... * God please don't explode. Builds TGUI like the linter wants. * Update code/modules/tgui/tgui_input/color_input.dm Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com> Signed-off-by: Spaghetti-bit <yumyumkillkill@gmail.com> * Rebuilds TGUI, again <3 * Lint be damned --------- Signed-off-by: Spaghetti-bit <yumyumkillkill@gmail.com> Co-authored-by: Aylong <69762909+AyIong@users.noreply.github.com> Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> Co-authored-by: Contrabang <91113370+Contrabang@users.noreply.github.com>
This commit is contained in:
co-authored by
Contrabang
Aylong
Burzah
parent
d0dc432024
commit
afd52f006a
@@ -72,8 +72,8 @@
|
||||
|
||||
if("skin_color")
|
||||
if(can_change_skin_color())
|
||||
var/new_skin = input(usr, "Choose your character's skin colour: ", "Skin Color", owner.skin_colour) as color|null
|
||||
if(new_skin && (!..()) && owner.change_skin_color(new_skin))
|
||||
var/new_skin = tgui_input_color(usr, "Choose your character's skin colour: ", "Skin Color", owner.skin_colour)
|
||||
if(!isnull(new_skin) && (!..()) && owner.change_skin_color(new_skin))
|
||||
update_dna()
|
||||
|
||||
if("hair")
|
||||
@@ -83,32 +83,32 @@
|
||||
|
||||
if("hair_color")
|
||||
if(can_change(APPEARANCE_HAIR_COLOR))
|
||||
var/new_hair = input("Please select hair color.", "Hair Color", head_organ.hair_colour) as color|null
|
||||
if(new_hair && (!..()) && owner.change_hair_color(new_hair))
|
||||
var/new_hair = tgui_input_color(usr, "Please select hair color.", "Hair Color", head_organ.hair_colour)
|
||||
if(!isnull(new_hair) && (!..()) && owner.change_hair_color(new_hair))
|
||||
update_dna()
|
||||
|
||||
if("secondary_hair_color")
|
||||
if(can_change(APPEARANCE_SECONDARY_HAIR_COLOR))
|
||||
var/new_hair = input("Please select secondary hair color.", "Secondary Hair Color", head_organ.sec_hair_colour) as color|null
|
||||
if(new_hair && (!..()) && owner.change_hair_color(new_hair, 1))
|
||||
var/new_hair = tgui_input_color(usr, "Please select secondary hair color.", "Secondary Hair Color", head_organ.sec_hair_colour)
|
||||
if(!isnull(new_hair) && (!..()) && owner.change_hair_color(new_hair, 1))
|
||||
update_dna()
|
||||
|
||||
if("hair_gradient")
|
||||
if(can_change(APPEARANCE_HAIR) && length(valid_hairstyles))
|
||||
var/new_style = tgui_input_list(usr, "Please select gradient style", "Hair Gradient", GLOB.hair_gradients_list)
|
||||
if(new_style)
|
||||
if(!isnull(new_style))
|
||||
owner.change_hair_gradient(style = new_style)
|
||||
|
||||
if("hair_gradient_offset")
|
||||
if(can_change(APPEARANCE_HAIR) && length(valid_hairstyles))
|
||||
var/new_offset = input("Please enter gradient offset as a comma-separated value (x,y). Example:\n0,0 (no offset)\n5,0 (5 pixels to the right)", "Hair Gradient", "[head_organ.h_grad_offset_x],[head_organ.h_grad_offset_y]") as null|text
|
||||
if(new_offset)
|
||||
if(!isnull(new_offset))
|
||||
owner.change_hair_gradient(offset_raw = new_offset)
|
||||
|
||||
if("hair_gradient_colour")
|
||||
if(can_change(APPEARANCE_HAIR) && length(valid_hairstyles))
|
||||
var/new_color = input("Please select gradient color.", "Hair Gradient", head_organ.h_grad_colour) as null|color
|
||||
if(new_color)
|
||||
var/new_color = tgui_input_color(usr, "Please select gradient color.", "Hair Gradient", head_organ.h_grad_colour)
|
||||
if(!isnull(new_color))
|
||||
owner.change_hair_gradient(color = new_color)
|
||||
|
||||
if("hair_gradient_alpha")
|
||||
@@ -124,26 +124,26 @@
|
||||
|
||||
if("facial_hair_color")
|
||||
if(can_change(APPEARANCE_FACIAL_HAIR_COLOR))
|
||||
var/new_facial = input("Please select facial hair color.", "Facial Hair Color", head_organ.facial_colour) as color|null
|
||||
if(new_facial && (!..()) && owner.change_facial_hair_color(new_facial))
|
||||
var/new_facial = tgui_input_color(usr, "Please select facial hair color.", "Facial Hair Color", head_organ.facial_colour)
|
||||
if(!isnull(new_facial) && (!..()) && owner.change_facial_hair_color(new_facial))
|
||||
update_dna()
|
||||
|
||||
if("secondary_facial_hair_color")
|
||||
if(can_change(APPEARANCE_SECONDARY_FACIAL_HAIR_COLOR))
|
||||
var/new_facial = input("Please select secondary facial hair color.", "Secondary Facial Hair Color", head_organ.sec_facial_colour) as color|null
|
||||
if(new_facial && (!..()) && owner.change_facial_hair_color(new_facial, 1))
|
||||
var/new_facial = tgui_input_color(usr, "Please select secondary facial hair color.", "Secondary Facial Hair Color", head_organ.sec_facial_colour)
|
||||
if(!isnull(new_facial) && (!..()) && owner.change_facial_hair_color(new_facial, 1))
|
||||
update_dna()
|
||||
|
||||
if("eye_color")
|
||||
if(can_change(APPEARANCE_EYE_COLOR))
|
||||
var/obj/item/organ/internal/eyes/eyes_organ = owner.get_int_organ(/obj/item/organ/internal/eyes)
|
||||
var/new_eyes = input("Please select eye color.", "Eye Color", eyes_organ.eye_color) as color|null
|
||||
if(new_eyes && (!..()) && owner.change_eye_color(new_eyes))
|
||||
var/new_eyes = tgui_input_color(usr, "Please select eye color.", "Eye Color", eyes_organ.eye_color)
|
||||
if(!isnull(new_eyes) && (!..()) && owner.change_eye_color(new_eyes))
|
||||
update_dna()
|
||||
|
||||
if("runechat_color")
|
||||
var/new_runechat_color = input("Please select runechat color.", "Runechat Color", owner.dna.chat_color) as color|null
|
||||
if(new_runechat_color && (!..()))
|
||||
var/new_runechat_color = tgui_input_color("Please select runechat color.", "Runechat Color", owner.dna.chat_color)
|
||||
if(!isnull(new_runechat_color) && (!..()))
|
||||
owner.change_runechat_color(new_runechat_color)
|
||||
|
||||
if("head_accessory")
|
||||
@@ -153,8 +153,8 @@
|
||||
|
||||
if("head_accessory_color")
|
||||
if(can_change_head_accessory())
|
||||
var/new_head_accessory = input("Please select head accessory color.", "Head Accessory Color", head_organ.headacc_colour) as color|null
|
||||
if(new_head_accessory && (!..()) && owner.change_head_accessory_color(new_head_accessory))
|
||||
var/new_head_accessory = tgui_input_color(usr, "Please select head accessory color.", "Head Accessory Color", head_organ.headacc_colour)
|
||||
if(!isnull(new_head_accessory) && (!..()) && owner.change_head_accessory_color(new_head_accessory))
|
||||
update_dna()
|
||||
|
||||
if("head_marking")
|
||||
@@ -164,7 +164,7 @@
|
||||
|
||||
if("head_marking_color")
|
||||
if(can_change_markings("head"))
|
||||
var/new_markings = input("Please select head marking color.", "Marking Color", owner.m_colours["head"]) as color|null
|
||||
var/new_markings = tgui_input_color(usr, "Please select head marking color.", "Marking Color", owner.m_colours["head"])
|
||||
if(new_markings && (!..()) && owner.change_marking_color(new_markings, "head"))
|
||||
update_dna()
|
||||
|
||||
@@ -175,7 +175,7 @@
|
||||
|
||||
if("body_marking_color")
|
||||
if(can_change_markings("body"))
|
||||
var/new_markings = input("Please select body marking color.", "Marking Color", owner.m_colours["body"]) as color|null
|
||||
var/new_markings = tgui_input_color(usr, "Please select body marking color.", "Marking Color", owner.m_colours["body"])
|
||||
if(new_markings && (!..()) && owner.change_marking_color(new_markings, "body"))
|
||||
update_dna()
|
||||
|
||||
@@ -186,7 +186,7 @@
|
||||
|
||||
if("tail_marking_color")
|
||||
if(can_change_markings("tail"))
|
||||
var/new_markings = input("Please select tail marking color.", "Marking Color", owner.m_colours["tail"]) as color|null
|
||||
var/new_markings = tgui_input_color(usr, "Please select tail marking color.", "Marking Color", owner.m_colours["tail"])
|
||||
if(new_markings && (!..()) && owner.change_marking_color(new_markings, "tail"))
|
||||
update_dna()
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Creates a TGUI color picker window and returns the user's response.
|
||||
*
|
||||
* This proc should be used to create a color picker that the caller will wait for a response from.
|
||||
* Arguments:
|
||||
* * user - The user to show the picker to.
|
||||
* * title - The of the picker modal, shown on the top of the TGUI window.
|
||||
* * timeout - The timeout of the picker, after which the modal will close and qdel itself. Set to zero for no timeout.
|
||||
* * autofocus - The bool that controls if this picker should grab window focus.
|
||||
*/
|
||||
/proc/tgui_input_color(mob/user, message, title, default = "#000000", timeout = 0, autofocus = TRUE, ui_state = GLOB.always_state)
|
||||
if(!user)
|
||||
user = usr
|
||||
if(!istype(user))
|
||||
if(!isclient(user))
|
||||
CRASH("We passed something that wasn't a user/client in a TGUI Input Color! The passed thing was [user]!")
|
||||
var/client/client = user
|
||||
user = client.mob
|
||||
|
||||
if(isnull(user.client))
|
||||
return
|
||||
|
||||
// Client does NOT have tgui_input on: Returns regular input
|
||||
if(user.client?.prefs?.toggles2 & PREFTOGGLE_2_DISABLE_TGUI_INPUT)
|
||||
return input(user, message, title, default) as color|null
|
||||
|
||||
var/datum/tgui_input_color/picker = new(user, message, title, default, timeout, autofocus, ui_state)
|
||||
picker.ui_interact(user)
|
||||
picker.wait()
|
||||
if(picker)
|
||||
. = picker.choice
|
||||
qdel(picker)
|
||||
|
||||
/**
|
||||
* tgui_input_color
|
||||
*
|
||||
* Datum used for instantiating and using a TGUI-controlled color picker.
|
||||
*/
|
||||
/datum/tgui_input_color
|
||||
/// The title of the TGUI window
|
||||
var/title
|
||||
/// The message to show the user
|
||||
var/message
|
||||
/// The default choice, used if there is an existing value
|
||||
var/default
|
||||
/// The color the user selected, null if no selection has been made
|
||||
var/choice
|
||||
/// The time at which the tgui_input_color was created, for displaying timeout progress.
|
||||
var/start_time
|
||||
/// The lifespan of the tgui_input_color, after which the window will close and delete itself.
|
||||
var/timeout
|
||||
/// The bool that controls if this modal should grab window focus
|
||||
var/autofocus
|
||||
/// Boolean field describing if the tgui_input_color was closed by the user.
|
||||
var/closed
|
||||
/// The attached timer that handles this objects timeout deletion
|
||||
var/deletion_timer
|
||||
/// The TGUI UI state that will be returned in ui_state(). Default: always_state
|
||||
var/datum/ui_state/state
|
||||
|
||||
/datum/tgui_input_color/New(mob/user, message, title, default, timeout, autofocus, ui_state)
|
||||
src.autofocus = autofocus
|
||||
src.title = title
|
||||
src.default = default
|
||||
src.message = message
|
||||
src.state = ui_state
|
||||
|
||||
if(timeout)
|
||||
src.timeout = timeout
|
||||
start_time = world.time
|
||||
deletion_timer = QDEL_IN(src, timeout)
|
||||
|
||||
/datum/tgui_input_color/Destroy(force, ...)
|
||||
SStgui.close_uis(src)
|
||||
state = null
|
||||
deltimer(deletion_timer)
|
||||
return ..()
|
||||
|
||||
/**
|
||||
* Waits for a user's response to the tgui_input_color's prompt before returning. Returns early if
|
||||
* the window was closed by the user.
|
||||
*/
|
||||
/datum/tgui_input_color/proc/wait()
|
||||
while(!choice && !closed && !QDELETED(src))
|
||||
stoplag(1)
|
||||
|
||||
/datum/tgui_input_color/ui_interact(mob/user, datum/tgui/ui)
|
||||
ui = SStgui.try_update_ui(user, src, ui)
|
||||
if(!ui)
|
||||
ui = new(user, src, "ColorPickerModal")
|
||||
ui.open()
|
||||
ui.set_autoupdate(timeout > 0)
|
||||
|
||||
/datum/tgui_input_color/ui_close(mob/user)
|
||||
closed = TRUE
|
||||
|
||||
/datum/tgui_input_color/ui_state(mob/user)
|
||||
return state
|
||||
|
||||
/datum/tgui_input_color/ui_static_data(mob/user)
|
||||
var/list/data = list()
|
||||
data["autofocus"] = autofocus
|
||||
data["large_buttons"] = !user.client?.prefs || (user.client.prefs.toggles2 & PREFTOGGLE_2_LARGE_INPUT_BUTTONS)
|
||||
data["swapped_buttons"] = !user.client?.prefs || (user.client.prefs.toggles2 & PREFTOGGLE_2_SWAP_INPUT_BUTTONS)
|
||||
data["title"] = title
|
||||
data["default_color"] = default
|
||||
data["message"] = message
|
||||
return data
|
||||
|
||||
/datum/tgui_input_color/ui_data(mob/user)
|
||||
var/list/data = list()
|
||||
if(timeout)
|
||||
data["timeout"] = CLAMP01((timeout - (world.time - start_time) - 1 SECONDS) / (timeout - 1 SECONDS))
|
||||
return data
|
||||
|
||||
/datum/tgui_input_color/ui_act(action, list/params)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
|
||||
switch(action)
|
||||
if("submit")
|
||||
if(!findtext(params["entry"], GLOB.is_color))
|
||||
return
|
||||
choice = params["entry"]
|
||||
closed = TRUE
|
||||
SStgui.close_uis(src)
|
||||
return TRUE
|
||||
if("cancel")
|
||||
closed = TRUE
|
||||
SStgui.close_uis(src)
|
||||
return TRUE
|
||||
Reference in New Issue
Block a user