mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-28 07:38:05 +01:00
TGUI and asset cache sending improvements (#43090)
Pills are now two spreadsheets instead of individual icons. This reduces assets sent by about 19-20. Furthermore tgui has been extended with a new proc ui_base_html which allows a user to customise the html sent as the base for a tgui window. This allows someone to provide custom spritesheet css as links in a specific tgui window without having to add it to the global html.
This commit is contained in:
@@ -232,6 +232,10 @@ GLOBAL_LIST_INIT(transit_tube_recipes, list(
|
||||
playsound(get_turf(user), 'sound/items/deconstruct.ogg', 50, 1)
|
||||
return(BRUTELOSS)
|
||||
|
||||
/obj/item/pipe_dispenser/ui_base_html(html)
|
||||
var/datum/asset/spritesheet/assets = get_asset_datum(/datum/asset/spritesheet/pipes)
|
||||
. = replacetext(html, "<!--customheadhtml-->", assets.css_tag())
|
||||
|
||||
/obj/item/pipe_dispenser/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, \
|
||||
datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state)
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
|
||||
@@ -562,7 +562,8 @@ GLOBAL_LIST_EMPTY(asset_datums)
|
||||
"none_button.png" = 'html/none_button.png',
|
||||
)
|
||||
|
||||
/datum/asset/simple/pills
|
||||
/datum/asset/spritesheet/simple/pills
|
||||
name ="pills"
|
||||
assets = list(
|
||||
"pill1" = 'icons/UI_Icons/Pills/pill1.png',
|
||||
"pill2" = 'icons/UI_Icons/Pills/pill2.png',
|
||||
|
||||
@@ -20,9 +20,20 @@
|
||||
var/screen = "home"
|
||||
var/analyzeVars[0]
|
||||
var/useramount = 30 // Last used amount
|
||||
var/list/pillStyles = null
|
||||
|
||||
/obj/machinery/chem_master/Initialize()
|
||||
create_reagents(100)
|
||||
|
||||
//Calculate the span tags and ids fo all the available pill icons
|
||||
var/datum/asset/spritesheet/simple/assets = get_asset_datum(/datum/asset/spritesheet/simple/pills)
|
||||
pillStyles = list()
|
||||
for (var/x in 1 to PILL_STYLE_COUNT)
|
||||
var/list/SL = list()
|
||||
SL["id"] = x
|
||||
SL["htmltag"] = assets.icon_tag("pill[x]")
|
||||
pillStyles += list(SL)
|
||||
|
||||
. = ..()
|
||||
|
||||
/obj/machinery/chem_master/Destroy()
|
||||
@@ -132,13 +143,17 @@
|
||||
datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state)
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if(!ui)
|
||||
var/datum/asset/assets = get_asset_datum(/datum/asset/simple/pills)
|
||||
var/datum/asset/assets = get_asset_datum(/datum/asset/spritesheet/simple/pills)
|
||||
assets.send(user)
|
||||
|
||||
ui = new(user, src, ui_key, "chem_master", name, 500, 550, master_ui, state)
|
||||
ui.open()
|
||||
|
||||
|
||||
//Insert our custom spritesheet css link into the html
|
||||
/obj/machinery/chem_master/ui_base_html(html)
|
||||
var/datum/asset/spritesheet/simple/assets = get_asset_datum(/datum/asset/spritesheet/simple/pills)
|
||||
. = replacetext(html, "<!--customheadhtml-->", assets.css_tag())
|
||||
|
||||
/obj/machinery/chem_master/ui_data(mob/user)
|
||||
var/list/data = list()
|
||||
data["isBeakerLoaded"] = beaker ? 1 : 0
|
||||
@@ -166,11 +181,8 @@
|
||||
for(var/datum/reagent/N in reagents.reagent_list)
|
||||
bufferContents.Add(list(list("name" = N.name, "id" = N.id, "volume" = N.volume))) // ^
|
||||
data["bufferContents"] = bufferContents
|
||||
var/list/pillStyles = list()
|
||||
for (var/x in 1 to PILL_STYLE_COUNT)
|
||||
var/list/SL = list()
|
||||
SL["id"] = x
|
||||
pillStyles += list(SL)
|
||||
|
||||
//Calculated at init time as it never changes
|
||||
data["pillStyles"] = pillStyles
|
||||
return data
|
||||
|
||||
|
||||
@@ -49,6 +49,20 @@
|
||||
if(!ui || ui.status != UI_INTERACTIVE)
|
||||
return 1 // If UI is not interactive or usr calling Topic is not the UI user, bail.
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Called on an object when a tgui object is being created, allowing you to customise the html
|
||||
* For example: inserting a custom stylesheet that you need in the head
|
||||
*
|
||||
* For this purpose, some tags are available in the html, to be parsed out with replacetext
|
||||
* (customheadhtml) - Additions to the head tag
|
||||
*
|
||||
* required html the html base text
|
||||
*
|
||||
**/
|
||||
/datum/proc/ui_base_html(html)
|
||||
return html
|
||||
|
||||
/**
|
||||
* private
|
||||
|
||||
@@ -198,11 +198,19 @@
|
||||
**/
|
||||
/datum/tgui/proc/get_html(var/inline)
|
||||
var/html
|
||||
html = SStgui.basehtml
|
||||
|
||||
//Allow the src object to override the html if needed
|
||||
html = src_object.ui_base_html(html)
|
||||
//Strip out any remaining custom tags that are used in ui_base_html
|
||||
html = replacetext(html, "<!--customheadhtml-->", "")
|
||||
|
||||
// Poplate HTML with JSON if we're supposed to inline.
|
||||
if(inline)
|
||||
html = replacetextEx(SStgui.basehtml, "{}", get_json(initial_data))
|
||||
else
|
||||
html = SStgui.basehtml
|
||||
html = replacetextEx(html, "{}", get_json(initial_data))
|
||||
|
||||
|
||||
//Setup for tgui stuff, including styles
|
||||
html = replacetextEx(html, "\[ref]", "[REF(src)]")
|
||||
html = replacetextEx(html, "\[style]", style)
|
||||
return html
|
||||
|
||||
File diff suppressed because one or more lines are too long
+13
-13
File diff suppressed because one or more lines are too long
@@ -51,7 +51,7 @@
|
||||
{{#if !data.condi}}
|
||||
<ui-display title='Pills, Bottles and Patches' >
|
||||
{{#each data.pillStyles}}
|
||||
<ui-button state='{{id==data.chosenPillStyle ? "selected" : null}}' action='pillStyle' params='{"id": "{{id}}"}'><img src='pill{{id}}'></ui-button>
|
||||
<ui-button state='{{id==data.chosenPillStyle ? "selected" : null}}' action='pillStyle' params='{"id": "{{id}}"}'>{{{htmltag}}}</ui-button>
|
||||
{{/each}}
|
||||
<br>
|
||||
{{#if data.isPillBottleLoaded}}
|
||||
|
||||
+2
-1
@@ -16,7 +16,8 @@
|
||||
};
|
||||
</script>
|
||||
<link rel='stylesheet' href='tgui.css'/>
|
||||
<link rel='stylesheet' href='spritesheet_pipes.css'/>
|
||||
<!-- This is processed in byond, so interfaces can override the html head if needed, for custom sheets of style etc -->
|
||||
<!--customheadhtml-->
|
||||
<script id='data' type='application/json' data-ref='[ref]'>{}</script>
|
||||
<script defer src='tgui.js'></script>
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user