Skip to content

Usage example

Beelzebub edited this page Oct 31, 2022 · 3 revisions

Simple chatbox that shows features of emoji.lua. you can also call this code via lib.Debug()

surface.CreateFont("Emoji.lua", {
	size = 20,
	font = "Roboto",
	extended = true,
	antialias = true
})

surface.CreateFont("Emoji.lua/Entry", {
	size = 16,
	font = "Roboto",
	extended = true,
	antialias = true
})

coroutine.wrap(function()
	local collection = Emoji:Collection()
	:Add(Emoji("Be1zebub/Emoji.lua", "emoji", "emoji/noto"))
	:Add(Emoji("Be1zebub/Emoji.lua", "elite-pepe"))
	:Add(Emoji("Be1zebub/Emoji.lua", "elite-gorgeous"))
	:Add(Emoji("Be1zebub/Emoji.lua", "elite-roflan"))

	local menu = vgui.Create("DFrame")
	menu:SetSize(440, 300)
	menu:Center()
	menu:MakePopup()
	menu:SetTitle("Emoji.lua v".. (math.floor(self._VERSION) == self._VERSION and self._VERSION ..".0" or self._VERSION))
	menu:DockPadding(11, 26 + 11, 11, 11)
	menu.Paint = function(me, w, h)
		surface.SetDrawColor(54, 57, 63)
		surface.DrawRect(0, 0, w, h)

		surface.SetDrawColor(32, 34, 37)
		surface.DrawRect(0, 0, w, 26)
	end

	local scroll = menu:Add("DScrollPanel")
	scroll:Dock(FILL)
	scroll.AddText = function(me, text)
		local msg = me:Add("EditablePanel")
		msg:Dock(TOP)
		msg:DockMargin(0, 8, 0, 0)

		coroutine.wrap(function()
			for _, part in ipairs(collection:Parse(text)) do
				if part.IsEmoji then
					if inc_ui then
						local img = msg:Add("inc_ui/material")
						img:Dock(LEFT)
						img:SetWide(msg:GetTall())
						img:SetIcon(part:URL())
					else
						local img = msg:Add("DImage")
						img:Dock(LEFT)
						img:SetWide(msg:GetTall())
						img:SetMaterial(part:Material(nil, "smooth mips"))
					end
				else
					local txt = msg:Add("DLabel")
					txt:Dock(LEFT)
					txt:SetText(part)
					txt:SetFont("Emoji.lua")
					txt:SizeToContents()
				end
			end
		end)()
	end

	local entry = menu:Add("DTextEntry")
	entry:Dock(BOTTOM)
	entry:SetTall(32)
	entry:SetTextColor(Color(235, 235, 235))
	entry:SetCursorColor(Color(220, 220, 220))
	entry:SetFont("Emoji.lua/Entry")
	entry.OnEnter = function(me)
		scroll:AddText(me:GetValue())
	end
	entry.Paint = function(me, w, h)
		draw.RoundedBox(6, 0, 0, w, h, Color(64, 68, 75))
		me:DrawTextEntryText(me:GetTextColor(), me:GetHighlightColor(), me:GetCursorColor())
	end

	scroll:AddText(":wtf: Gorgeous freeman :pleasure: emote pack :not_bad:")
	scroll:AddText(":wave: world! I love :new_moon_with_face:")
	scroll:AddText("i have :medal_sports:, because im cool :owo:")
	scroll:AddText(":hmm: hmm, seems good :very_dovolen:")
end)()
Clone this wiki locally