Adding Markup - wofsauge/External-Item-Descriptions GitHub Wiki

Icons

Icons are small sprites that can be rendered at any position inside a text.

Function Structure

EID:addIcon(shortcut, animationName, animationFrame, width, height, leftOffset, topOffset, spriteObject)

  • shortcut : String that identifies this Markup object like: {{MyIcon}}
  • animationName : Name of the Animation to be played. Refers to the name used in the given .anm2 file
  • animationFrame : Specific frame that should be played when displaying icon. Use -1 to play it as an animation
  • width : Width of the icon
  • height : Height of the icon
  • leftOffset : left Offset of the icon. Default: -1
  • topOffset : Top Offset of the icon. Default: 0
  • spriteObject : Sprite() Object that contains the loaded .anm2 file of the animation.

Example:

This will render an animated icon with markup {{MyIcon}} that displays all the possible heart-icons

local mySprite = Sprite()
mySprite:Load("gfx/eid_inline_icons.anm2", true)
EID:addIcon("MyIcon", "hearts", -1, 9, 9, -1, 0, mySprite)

Colors

Color Markup works just the same as the Icon Markup. It is a specific string encased in {{...}}.

Markup colors either need to reference a KColor object, or a function that returns a KColor object.

Functions take one argument, which contains the "current" color as a KColor object.

Function Structure

EID:addColor(Shortcut, KColor, Callback)

  • Shortcut : String that identifies this Markup object like: {{MyColor}}
  • KColor : KColor Object that this color should represent. Argument will be ignored when a callback is defined
  • Callback (Optional) : Function that should be called when this markup is called.

Examples:

Adds color markup {{ColorTwitterBlue}} that looks like the blue of the Twitter logo

EID:addColor("ColorTwitterBlue", KColor(0, 0.671875, 0.9296875, 1))

Adds color markup {{ColorBlackBlink}} that alters the text color every half second between white and black, while also keeping the Alpha value of the previously used color.

EID:addColor("ColorBlackBlink", nil, function(color)
		local maxAnimTime = 30
		local animTime = Game():GetFrameCount() % maxAnimTime
		color = EID:copyKColor(color) or EID:getTextColor()
		if animTime < maxAnimTime / 2 then
			color = KColor(0, 0, 0, 1 * color.Alpha)
		else
			color = KColor(1, 1, 1, 1 * color.Alpha)
		end
		return color
	end
)

Shortcuts

Shortcuts are short strings that represent longer strings. Before rendering any line, the text will be preprocessed by replacing all shortcuts with their full-text representation.

Example: will be replaced with {{ArrowUp}} before any processing wll be done.

Adding a new Shortcut

All shortcuts are stored in the EID.TextReplacementPairs table, which contains pairs of "Shortcut" and "Long-Text" strings.

Adding new shortcuts is only recommended, if you know what you are doing!

Example:

table.insert(EID.TextReplacementPairs, {"Shortcut","long representation"})

This will turn this description this text has a Shortcut into this text has a long representation