ModMenu icon indicating copy to clipboard operation
ModMenu copied to clipboard

Formatted Text Capabilities

Open Darkhax opened this issue 4 years ago • 2 comments

I would really like the ability to define formatted text in my summary/description. By formatted text I basically mean a text component with support for things like fonts, sub components, links, click events, etc.

To give a use case I have a mod which registers a new vanilla compatible font. I would like to include a message written in this font inside my description. This would serve as a showcase of the font and also provide a very effective way to verify that the font is registered and working.

This could ideally be implemented using Text.Serializer's deserializer method which would support the full feature range via json objects. No idea where this would fit into the spec though.

Darkhax avatar Feb 03 '21 17:02 Darkhax

Hmm, perhaps doing this should be something for the API? I feel like it might get a bit out of hand if I serialize json texts from localization strings or something.

Prospector avatar Feb 03 '21 17:02 Prospector

I was thinking it would be something in the fabric file rather than a translation. Text components include support for translation of sub components as well.

"custom": {
	"modmenu:clientsideOnly": true,
	"modmenu": {
		"links": {
			"modmenu.discord": "https://discord.darkhax.net"
		},
		"summary": {
			"translate": "mod.runelic.summary",
			"font": "runelic:runelic"
		},
		"description": ["", {
				"text": "This text is green and ",
				"color": "dark_green"
			}, {
				"text": "obfuscated",
				"obfuscated": true,
				"color": "dark_green"
			}, {
				"text": ". ",
				"color": "dark_green"
			}, {
				"text": "This is also a tooltip",
				"color": "dark_green",
				"hoverEvent": {
					"action": "show_text",
					"contents": "You found the hidden text!"
				}
			}, {
				"text": ".",
				"color": "dark_green"
			},
			{
				"text": " This is in a different font.",
				"font": "runelic:runelic"
			}
		]
	}
}

In this example the summary is a translated string using a custom font, in the description example that is a complex text component which uses multiple colors, styling, fonts, and has a hover/tooltip effect. These are all part of the Text component and it's JSON deserializer.

Darkhax avatar Feb 03 '21 17:02 Darkhax