Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port: tgui loadout + tgui color picker #6280

Open
wants to merge 11 commits into
base: master220
Choose a base branch
from
57 changes: 35 additions & 22 deletions code/__HELPERS/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,48 @@
GLOB.pai_software_by_key[P.id] = P

// Setup loadout gear
for(var/geartype in subtypesof(/datum/gear))
var/datum/gear/G = geartype
for(var/datum/gear/gear as anything in subtypesof(/datum/gear))

var/use_name = initial(G.display_name)
var/use_category = initial(G.sort_category)
if(gear == gear.path)
continue

if(G == initial(G.subtype_path))
if(gear == gear.subtype_path)
continue

if(!use_name)
error("Loadout - Missing display name: [G]")
if(!gear.index_name)
stack_trace("Loadout - Missing index name: [gear]")
continue
if(!initial(G.cost))
error("Loadout - Missing cost: [G]")
if(!gear.cost)
stack_trace("Loadout - Missing cost: [gear]")
continue
if(!initial(G.path))
error("Loadout - Missing path definition: [G]")
if(!gear.path)
stack_trace("Loadout - Missing path definition: [gear]")
continue

if(!GLOB.loadout_categories[use_category])
GLOB.loadout_categories[use_category] = new /datum/loadout_category(use_category)
var/datum/loadout_category/LC = GLOB.loadout_categories[use_category]
GLOB.gear_datums[use_name] = new geartype
LC.gear[use_name] = GLOB.gear_datums[use_name]

GLOB.loadout_categories = sortAssoc(GLOB.loadout_categories)
for(var/loadout_category in GLOB.loadout_categories)
var/datum/loadout_category/LC = GLOB.loadout_categories[loadout_category]
LC.gear = sortAssoc(LC.gear)
gear = new gear
var/obj/gear_item = gear.path
var/list/tweaks = list()
for(var/datum/gear_tweak/tweak as anything in gear.gear_tweaks)
tweaks[tweak.type] += list(list(
"name" = tweak.display_type,
"icon" = tweak.fa_icon,
"tooltip" = tweak.info,
))

GLOB.gear_tgui_info[gear.sort_category] += list(
"[gear]" = list(
"name" = ((gear.display_name == /datum/gear::display_name)? gear_item.name : gear.display_name) ,
"index_name" = gear.index_name,
"desc" = gear.description,
"icon" = gear_item.icon,
"icon_state" = gear_item.icon_state,
"cost" = gear.cost,
"gear_tier" = gear.donator_tier,
"allowed_roles" = gear.allowed_roles,
"tweaks" = tweaks,
)
)

GLOB.gear_datums[gear.index_name] = gear


// Setup a list of robolimbs
Expand Down
1 change: 1 addition & 0 deletions code/_globalvars/_regexes.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
GLOBAL_DATUM_INIT(is_http_protocol, /regex, regex("^https?://"))
GLOBAL_DATUM_INIT(filename_forbidden_chars, /regex, regex(@{""|[\\\n\t/?%*:|<>]|\.\."}, "g"))
GLOBAL_DATUM_INIT(is_color, /regex, regex("^#\[0-9a-fA-F]{6}$"))
GLOBAL_PROTECT(filename_forbidden_chars)
12 changes: 6 additions & 6 deletions code/game/jobs/job/job.dm
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
continue

if(G.slot)
if(H.equip_to_slot_or_del(G.spawn_item(H, H.client.prefs.loadout_gear[G.display_name]), G.slot))
if(H.equip_to_slot_or_del(G.spawn_item(H, H.client.prefs.get_gear_metadata(G)), G.slot, TRUE))
to_chat(H, "<span class='notice'>Equipping you with [G.display_name]!</span>")
else
gear_leftovers += G
Expand All @@ -239,19 +239,19 @@

if(gear_leftovers.len)
for(var/datum/gear/G in gear_leftovers)
var/obj/item/placed_in = G.spawn_item(get_turf(H), H.client.prefs.loadout_gear[G.display_name])
var/obj/item/placed_in = G.spawn_item(null, H.client.prefs.get_gear_metadata(G))
if(placed_in.equip_to_best_slot(H))
to_chat(H, "<span class='notice'>Placing [G.display_name] in your inventory!</span>")
to_chat(H, span_notice("Placing [G.display_name] in your inventory!"))
continue
if(H.put_in_hands(placed_in))
to_chat(H, "<span class='notice'>Placing [G.display_name] in your hands!</span>")
to_chat(H, span_notice("Placing [G.display_name] in your hands!"))
continue
to_chat(H, "<span class='danger'>Failed to locate a storage object on your mob, either you spawned with no hands free and no backpack or this is a bug.</span>")
to_chat(H, span_danger("Failed to locate a storage object on your mob, either you spawned with no hands free and no backpack or this is a bug."))
qdel(placed_in)

qdel(gear_leftovers)

return 1
return TRUE

/datum/outfit/job/proc/imprint_idcard(mob/living/carbon/human/H)
var/datum/job/J = SSjobs.GetJobType(jobtype)
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/dye_generator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
..()
if(stat & (BROKEN|NOPOWER))
return
var/temp = input(usr, "Choose a dye color", "Dye Color") as color|null
if(!temp)
var/temp = tgui_input_color(usr, "Choose a dye color", "Dye Color")
if(isnull(temp))
return
set_light_color(temp)

Expand Down
9 changes: 7 additions & 2 deletions code/game/objects/items/crayons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@
if(!Adjacent(usr) || usr.incapacitated())
return
if(href_list["color"])
var/temp = input(usr, "Please select colour.", "Crayon colour") as color
var/temp = tgui_input_color(usr, "Please select colour.", "Crayon colour")
if(isnull(temp))
return
colour = temp
update_window(usr)
else
Expand Down Expand Up @@ -303,7 +305,10 @@
if("Change Drawing")
..()
if("Change Color")
colour = input(user,"Choose Color") as color
var/new_color = tgui_input_color(user, "Choose Color")
if(isnull(new_color))
return
colour = new_color
update_icon()

/obj/item/toy/crayon/spraycan/afterattack(atom/target, mob/user, proximity, params)
Expand Down
5 changes: 4 additions & 1 deletion code/game/objects/items/devices/window_painter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
mode = "pipette"
if("Choose Color")
mode = "paint"
colour = input(user,"Choose Color") as color
var/new_color = tgui_input_color(user, "Choose Color")
if(isnull(new_color))
return
colour = new_color
update_icon(UPDATE_OVERLAYS)
if("Color Presets")
mode = "paint"
Expand Down
5 changes: 4 additions & 1 deletion code/game/objects/structures/curtains.dm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@

if(istype(I, /obj/item/toy/crayon))
add_fingerprint(user)
color = input(user, "Choose Color") as color
var/new_color = tgui_input_color(user, "Choose Color")
if(isnull(new_color))
return ATTACK_CHAIN_PROCEED
color = new_color
return ATTACK_CHAIN_PROCEED_SUCCESS

return ..()
Expand Down
8 changes: 4 additions & 4 deletions code/game/objects/structures/dresser.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
if(new_underwear)
var/datum/sprite_accessory/underwear/uwear = GLOB.underwear_list[new_underwear]
if(uwear.allow_change_color)
var/new_underwear_color = input(user, "Choose your underwear color, else color will be white:", "Changing", "#ffffff") as color|null
H.color_underwear = new_underwear_color || "#ffffff"
var/new_underwear_color = tgui_input_color(user, "Choose your underwear color, else color will be white:", "Changing", "#ffffff")
H.color_underwear = isnull(new_underwear_color) ? "#ffffff" : new_underwear_color
H.underwear = new_underwear

if("Undershirt")
Expand All @@ -49,8 +49,8 @@
if(new_undershirt)
var/datum/sprite_accessory/undershirt/ushirt = GLOB.undershirt_list[new_undershirt]
if(ushirt.allow_change_color)
var/new_undershirt_color = input(user, "Choose your undershirt color, else color will be white:", "Changing", "#ffffff") as color|null
H.color_undershirt = new_undershirt_color || "#ffffff"
var/new_undershirt_color = tgui_input_color(user, "Choose your undershirt color, else color will be white:", "Changing", "#ffffff")
H.color_undershirt = isnull(new_undershirt_color) ? "#ffffff" : new_undershirt_color
H.undershirt = new_undershirt

if("Socks")
Expand Down
4 changes: 2 additions & 2 deletions code/modules/admin/admin_verbs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1264,8 +1264,8 @@ GLOBAL_LIST_INIT(view_runtimes_verbs, list(
return
message = strip_html(message, 500)

var/message_color = input(src, "Input your message color:", "Color Selector") as color|null
if(!message_color)
var/message_color = tgui_input_color(src, "Input your message color:", "Color Selector")
if(isnull(message_color))
return

var/alert_type2 = alert(src, "Do you wish to change speed of an admin alert to? (No - default speed)",,"Yes", "No")
Expand Down
4 changes: 2 additions & 2 deletions code/modules/antagonists/space_dragon/space_dragon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@
* If an invalid color is given, will re-prompt the dragon until a proper color is chosen.
*/
/mob/living/simple_animal/hostile/space_dragon/proc/color_selection()
chosen_color = input(src,"Какого цвета вы хотите быть?","Выбор цвета", COLOR_WHITE) as color|null
if(!chosen_color) //redo proc until we get a color
chosen_color = tgui_input_color(src,"Какого цвета вы хотите быть?","Выбор цвета", COLOR_WHITE)
if(isnull(chosen_color)) //redo proc until we get a color
to_chat(src, span_warning("Этот цвет некорректен, попробуйте еще раз."))
color_selection()
return
Expand Down
30 changes: 30 additions & 0 deletions code/modules/asset_cache/asset_list.dm
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,34 @@ GLOBAL_LIST_EMPTY(asset_datums)
/datum/asset/simple/namespaced/proc/get_htmlloader(filename)
return URL2HTMLLOADER(SSassets.transport.get_asset_url(filename, assets[filename]))


/// A subtype to generate a JSON file from a list
/datum/asset/json
_abstract = /datum/asset/json
/// The filename, will be suffixed with ".json"
var/name


/datum/asset/json/send(client)
return SSassets.transport.send_assets(client, "[name].json")


/datum/asset/json/get_url_mappings()
return list(
"[name].json" = SSassets.transport.get_asset_url("[name].json"),
)


/datum/asset/json/register()
var/filename = "data/[name].json"
fdel(filename)
text2file(json_encode(generate()), filename)
SSassets.transport.register_asset("[name].json", fcopy_rsc(filename))
fdel(filename)

/// Returns the data that will be JSON encoded
/datum/asset/json/proc/generate()
SHOULD_CALL_PARENT(FALSE)
CRASH("generate() not implemented for [type]!")

#undef ASSET_CROSS_ROUND_CACHE_DIRECTORY
24 changes: 24 additions & 0 deletions code/modules/asset_cache/assets/asset_icon_ref_map.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// Maps icon names to ref values
/datum/asset/json/icon_ref_map
name = "icon_ref_map"
early = TRUE

/datum/asset/json/icon_ref_map/generate()
var/list/data = list() //"icons/obj/drinks.dmi" => "[0xc000020]"
//var/start = "0xc000000"
var/value = 0
while(TRUE)
value += 1
var/ref = "\[0xc[num2text(value,6,16)]\]"
var/mystery_meat = locate(ref)
if(isicon(mystery_meat))
if(!isfile(mystery_meat)) // Ignore the runtime icons for now
continue
var/path = get_icon_dmi_path(mystery_meat) //Try to get the icon path
if(path)
data[path] = ref
else if(mystery_meat)
continue; //Some other non-icon resource, ogg/json/whatever
else //Out of resources end this, could also try to end this earlier as soon as runtime generated icons appear but eh
break;
return data
Loading
Loading