Skip to content

Commit

Permalink
convert vending unit UI to TGUI (#8257)
Browse files Browse the repository at this point in the history
* add machine TGYU state

* update TGUI-related icon utility proc

* add component for displaying byond icons

* fix unused UI code

* remove old template file

* fix user details

* convert vending unit UI to TGUI

* update TGUI bundle

* Update tgui/packages/tgui/interfaces/common/UserDetails.tsx

Co-authored-by: Firefox13 <[email protected]>

* probably fix linters

* probably fix linters yet again

* add TGUI bundle

* remove lack of prettier, i guess

---------

Co-authored-by: Firefox13 <[email protected]>
  • Loading branch information
intercepti0n and Firefox13 authored Aug 18, 2023
1 parent 42a1d03 commit b31bdd9
Show file tree
Hide file tree
Showing 15 changed files with 506 additions and 629 deletions.
1 change: 1 addition & 0 deletions cev_eris.dme
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,7 @@
#include "code\modules\tgui\tgui.dm"
#include "code\modules\tgui\tgui_window.dm"
#include "code\modules\tgui\states\always.dm"
#include "code\modules\tgui\states\machinery.dm"
#include "code\modules\tips_and_tricks\gameplay.dm"
#include "code\modules\tips_and_tricks\jobs.dm"
#include "code\modules\tips_and_tricks\mobs.dm"
Expand Down
41 changes: 19 additions & 22 deletions code/__HELPERS/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,10 @@ proc/get_average_color(var/icon, var/icon_state, var/image_dir)
/proc/generate_asset_name(file)
return "asset.[md5(fcopy_rsc(file))]"

/proc/path2icon(path, dir = SOUTH, frame = 1, moving)
var/atom/A = path
return icon(initial(A.icon), initial(A.icon_state), dir, frame, moving)

/**
* Converts an icon to base64. Operates by putting the icon in the iconCache savefile,
* exporting it as text, and then parsing the base64 from that.
Expand Down Expand Up @@ -1150,37 +1154,30 @@ proc/get_average_color(var/icon, var/icon_state, var/image_dir)
return "<img class='[extra_classes] icon icon-[icon_state]' src='[SSassets.transport.get_asset_url(key)]'>"

/proc/icon2base64html(thing)
if (!thing)
return
var/static/list/bicon_cache = list()
if (isicon(thing))
var/icon/I = thing
var/icon_base64 = icon2base64(I)

if (I.Height() > world.icon_size || I.Width() > world.icon_size)
var/icon_md5 = md5(icon_base64)
icon_base64 = bicon_cache[icon_md5]
if (!icon_base64) // Doesn't exist yet, make it.
bicon_cache[icon_md5] = icon_base64 = icon2base64(I)
ASSERT(thing)

if(ispath(thing))
var/atom/A = thing
var/key = "[initial(A.icon)]:[initial(A.icon_state)]"
var/cached = bicon_cache[key]

return "<img class='icon icon-misc' src='data:image/png;base64,[icon_base64]'>"
if(!cached)
bicon_cache[key] = cached = icon2base64(path2icon(A))

// Either an atom or somebody fucked up and is gonna get a runtime, which I'm fine with.
var/atom/A = thing
var/key = "[istype(A.icon, /icon) ? "[REF(A.icon)]" : A.icon]:[A.icon_state]"
return "<img class='game-icon' src='data:image/png;base64,[cached]'>"

if(isicon(thing))
var/key = REF(thing)
var/cached = bicon_cache[key]

if (!bicon_cache[key]) // Doesn't exist, make it.
var/icon/I = icon(A.icon, A.icon_state, SOUTH, 1)
if (ishuman(thing)) // Shitty workaround for a BYOND issue.
var/icon/temp = I
I = icon()
I.Insert(temp, dir = SOUTH)
if(!cached)
bicon_cache[key] = cached = icon2base64(thing)

bicon_cache[key] = icon2base64(I)
return "<img class='game-icon' src='data:image/png;base64,[cached]'>"

return "<img class='icon icon-[A.icon_state]' src='data:image/png;base64,[bicon_cache[key]]'>"
CRASH("[thing] must be a path or an icon")

//Costlier version of icon2html() that uses getFlatIcon() to account for overlays, underlays, etc. Use with extreme moderation, ESPECIALLY on mobs.
/proc/costly_icon2html(thing, target, sourceonly = FALSE)
Expand Down
3 changes: 3 additions & 0 deletions code/game/machinery/machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@
/obj/machinery/proc/inoperable(var/additional_flags = 0)
return (stat & (NOPOWER|BROKEN|additional_flags))

/obj/machinery/ui_state(mob/user)
return GLOB.machinery_state

/obj/machinery/CanUseTopic(mob/user)
if(stat & BROKEN)
return STATUS_CLOSE
Expand Down
Loading

0 comments on commit b31bdd9

Please sign in to comment.