Files
Aurora.3/tgui/docs/chat-embedded-components.md
Matt Atlas 31956c7eb0 Rock the UI Away - Removes VueUI and adds TGUI (#16509)
* tgui the beginning

* binaries and the like

* Bring in the last of it

* Example radio UI

* delete example

* NTOS Main Menu, start on manifest, tgui states

* tasks.json

* gunnery ui pt 1

* okay

* fix everything

* scss update

* oops

* manifest gigablast

* downloader part 1

* download prt 2

* NTOSDownloader final

* mfw committing to_worlds

* gunnery console pt2

* i cooked

* targeting (finished)

* one vueui down

* voting ui almost done

* MY MIND FEELS LIKE AN ARCH ENEMYYYY

* voting ui down

* photocopier

* ntos config + download fixes

* photocopier 2

* refactor define

* NTOS client manager + fixes

* fax machine final (it also uses toner now)

* marching forwards... left behind...

* ntnrc part 1

* canister

* add quotes

* portable pumps pt1 + more backgrounds

* oops

* finish the portable pump

* freezers

so I'll keep on pushing forward... you haven't seen the last of me... oooooooh...

* doors ui pt1

* finish doors UI (forgive me wildkins it's a bit of shitcode)

* vitals monitor, make things use labeled lists, new backgrounds

* mais j'envoyé aucun mayday...

* maglock pt1

* pour ça je me suis perdu...

* infrared

* fix that

* prox sensor pt1

* prox sensor

* signaler (this was actually pretty hard)

* atmos control pt1

* atmos control pt1.1

* atmos pt 2

* fuel injector

* multitool UI

* jammer

* list viewer

* APC

* portgen

* targeting console updates + SMES ui

* new themes, shield generator

* supermatter

* Add ore detector and (shitty) NTNet Relay

* orderterminal pt1

* orderterminal pt2

* smartfridge

* Add (air-)tank GUI update ore detector size

* Adds Transfer Valves

* Add AtmoScrubber

* analyzer pt1

* weapons analyzer pt2

* bodyscanner pt1

* bodyscanner pt2

* fix this shitcode

* seed storage

* appearance changer

* appearance changer final

* sleeper pt1

* sleeper

* gps

* vehicles

* chem dispenser

* lily request

* holopad

* tgui modules pt1

* ppanel

* damage menu

* fixes

* im here too now

* follow menu, search bars

* quikpay

* quikpay fixes

* circuit printer

* ppanel

* ppanel updates

* pai

* turret controls (i want to kill myself)

* tweak

* remove the boardgame

* guntracker

* implant tracker

* penal mechs

come close to me, come close to me

* chem codex

* pai radio

* doorjack

* pai directives

* signaler removal, sensors

* ghost spawner

* spawnpoint

* fixes

* teleporter

* one more to the chopping block

* account database

* remove divider

* scanner, atmos

* latejoin ui pt1

* latejoin

* records pt1

* RECORDS UI DONE

* delete interpreter & records

* CHAT FUCKING CLIENT

* data updates

* fix some things

* final UI, log

* basic nanoui fix

* antag panel

* remove vueui

* atm update

* vending update

* warrants, cameras

* ntmonitor

* time comes for all

* preserve this legacy

* bring that back (oops)

* rcon, ui auto update for computer UIs, remove rcon computers

* alarm monitoring (a bit broke and also todo: add custom alarm monitoring programs to a few consoles)

* A LIKE SUPREME

* a

* power monitor

* lights on

* fuck this code, fuck nanoui modules, and fuck nanoui

* LEAVE IT OH SO FAR BEHIND

* fix alarm monitoring for synths

* I SAW IN YOU WHAT LIFE WAS MISSING

* comms console

* idcard and record updates

* turn the light on

* arcade

* pt2

* news browser

* static

* crusher

* f

* COULD I JUST SLEIGH THE GOLD FROM THE BALLS? I'M SO FRUSTRATED OH COULD YOU TELL? IF I HEAR ONE MORE VUEUI OR ONE NANOUI I'M GONNA LOSE IT SO LET ME GOOOOOOOOOOOOOOOOO

* codeowners & suit sensors

* html ui style removal

* make lint happy

* resist and disorder

* i slowly get up and turn off the noise, already fed up...

* pleaseeeeeeeeeeeeeee

* THE CREDIT LARP IS NECESSARY

* i hold the keys

* RISE UP

* fix that?

* harry's suggestions xoxo

* runtime fix pt2

* You are the only thing that I still care about

* adds build workflow

* Update update_tgui.yml

* adds some needed steps

* ATM

* misc fixes and tweaks

* fixes 2

* make newscasters usable and fix use power on freezers

* turret control is clearer

---------

Co-authored-by: John Wildkins <john.wildkins@gmail.com>
Co-authored-by: Matt Atlas <liermattia@gmail.com>
Co-authored-by: harryob <55142896+harryob@users.noreply.github.com>
Co-authored-by: Werner <Arrow768@users.noreply.github.com>
Co-authored-by: Geeves <ggrobler447@gmail.com>
Co-authored-by: harryob <me@harryob.live>
2023-06-25 19:03:33 +02:00

3.2 KiB

Chat Embedded Components

Have you ever embedded html into tgui chat? Maybe just css stuff like <span class='alien'> </span>? Have you ever wanted to embed tgui components instead? For styling or ease of use of course.

Well we have a system for that! You can pass component information in via html attributes, and it'll be rendered in chat. How? Let's get into it.

How it works

Here's a sample span that embeds a tooltip around the wrapped text.

<span data-component=\"Tooltip\" data-content=\"Hey it works!\">Does it work?</span>

There's two components here, let's break them down.

Targeting a component

Telling tgui chat what component you want to render is really simple. You just embed its name in the data-component attribute.

You saw it before, but for reference, <div data-component=\"Tooltip\"></div> this tells the div to render a tooltip.

There is a bit of nuance here however.

We can't embed components that haven't been prewhitelisted.

This isn't because of security concerns or anything, we just can't lookup components by their name without creating a lookup table. You can find that in tgui chat's renderer under the name TGUI_CHAT_COMPONENTS

Adding a new component is simple, just add it's name to the dictionary, and import it into the file.

Sending props

Ok, so we know how to render a component, but that's nearly useless unless we also know how to send extra info alongside it.

So how's that work?

The syntax is similar to sending a component, but has a bit more caveats. We have two bits of info to contend with. The name of the prop, and it's value. First then, how do you send the name of a prop?

Sending a prop's name

<span {component setting} data-content={value}></span

It's really simple, just another data attribute, with the name you want to refer to the property by.

Something important to note here, data attribute names cannot contain any upper case chars, or anything that isn't XML compatible.

Because of this, we need to do another map of sent name -> intended name. This can also be found in the renderer file with the name TGUI_CHAT_ATTRIBUTES_TO_PROPS

Sending a prop's value

Setting a prop's value is as simple as giving the data-content attribute a string value.

This does mean that we can only send strings to javascript. Because of this, we do some parsing js side to pull out other values you may want to send.

There's three supported datatypes.

Booleans

Booleans are send by sending a string in the form data-bool=\"$true\" and "data-bool=\"$false\" The $ char is included to allow you to send the string "true" without breaking anything.

Please keep this restriction in mind.

Numbers

Numbers are simpler then the above. If you send a string with no whitespace that can be parsed as an int or float, it will be.

So data-int=\"-10\" will be parsed as -10

data-float=\"10.2\" will also be correctly handled, treated as 10.2

Strings

Strings are the most simple. If a value is passed to an html attribute, and it doesn't meet any of the above requirements, it will be

data-string=\"hey man, it works!\"