TextBoxPlus - Flashy text and colourful effects epicness

Maybe not so epic…

RELEASE - TextBoxPlus for the vgui module!

LATEST VERSION - 1.0

DOWNLOAD - http://www.garrysmod.org/downloads/?a=view&id=81199

PURPOSE -

After some extensive lua coding for an up coming final fantasy mod (lol plug) I had a need to have different parts of my textbox be different colours. Normal textbox doesnt support this, so after about a day’s work and then 2 weeks of slow tinkering. I finally finished it and its ready to go. TextBoxPlus allows coders to create colourful text on a vgui panel quickly and easily using a similar format to normal textbox.

What it can do:
Change colours to whole/part of your text.
Scroll text vertically.
Add different effects. (flash colours, shift alpha, scrolling)
When operators in the text change, the change is instant.

What it can’t do:
Text can only be changed with LUA, not by the user. (Might be added in later)
You can’t get your string back with textbox:GetValue()

EXAMPLE -

I made this example as a test



function showThing()
	local frame = vgui.Create("DFrame")
		frame:Center()
		frame:SetSize(200,200)
		frame:MakePopup()
		frame:SetTitle("")
	local textbox = vgui.Create("TextBoxPlus",frame)
		textbox:SetBackgroundColor(Color(0,0,0,0))
		textbox:SetBorderColor(Color(0,0,0,0))
		textbox:SetPos(20,0)
		textbox:SetText("[phase]lol[/]lol[/][blink]lol[lol]")
	local textbox2 = vgui.Create("TextBoxPlus",frame)
		textbox2:AddColorTable(1,Color(0,0,255,128))
		textbox2:AddColorTable(1,Color(255,0,0,128))
		textbox2:SetPos(5,50)
		textbox2:SetSize(190,50)
		textbox2:SetText("[rainbow,1,1]/[text] /[text] 
text text[/] ")
	local textbox3 = vgui.Create("TextBoxPlus",frame)
		textbox3:SetPos(5,110)
		textbox3:SetSize(190,50)
		textbox3:SetText("[orange]orange
[/][green]green
[/][cyan]cyan[/]")
end
concommand.Add("showthing",showThing)


Just so you get a better understanding of how to use it.


textbox:SetText("[phase]lol[/]lol[/][blink]lol[lol]")

This like will add “lollollol” to the string. The first “lol” will fade in and out as red. The second “lol” will be static and red. The final “lol” will blink black (the default colour)

How the system works is simple. Pretty much the same as forum tag codes.

NOTE: <n> are optional fields, arguments are explained

[:colour:] - Change following text to a specific colour (colours listed below)

[#,#,#,#] - Custom colour, # stands for a number between 0 - 255, usual RGBA format

[########] - Web designers can use HEX variation of the above command (NOTE: Both commands
only work when there is exactly 4 numbers and 8 digits to their respective commands)

[blink,<n>] - Blink makes the following text blink on/off. ‘n’ is optional, its the rate the blink occurs

[phase,<n>] - Phase makes text phase in and out, like blink, but its slower and fades. Instead of being straight on and off. ‘n’ is rate

[rainbow,<type,id,n>] - Make text flash random colours. ‘type’ is what mode to flash colours.
1 - Letter (Default)
2 - Word
3 - Whole text (until [/] )
‘id’ is what colour table to use. Colour tables are added with AddColourTable() command. If no table id is specified, the default table is used. To use default table id is 0 (Zero)
‘n’ is yet again, rate.

[scroll,<w,n>] - Text scrolls from right to left inside a small box ‘w’ characters wide. (Default 5). n = rate.

[alpha,#] - Make following text transparent, # in required and this is the ‘a’ channel 0-255

[/] - Close off current running operator

/ - No this isnt a typo. If you want to have in your text (usually this is concidered a command and therefore; cut from your string.) place a ‘/’ before the bracket to force TextBoxPlus to actually draw it.

  • New line

Available colour codes are:
“red”,“blue”,“green”,“orange”,“yellow”,“purple”,“cyan”,“pink”,“black” and “white”
This is also the order the default [rainbow] colours flash.

LUA SIDE COMMANDS -
There are some extra commands to use on the lua client side as well as just the text entry.

panel:SetColor(Color) - Sets the default text colour
panel:SetBackgroundColor(Color) - Background
panel:SetBorderColor(Color) - Border
panel:SetFont(FontString) - Default font
panel:SetAddColorTable(TableID,Color,[pos]) - This makes a table of colours that the [rainbow] command works with. TableID must be an integer greater then 0, and pos is optional.

COMING SOON -
There are a couple more things I want to add before calling this simple arse project finished.

panel:DelColorTable(TableID,[pos]) - Remove colours from the colour table.

[Underline]
[font,s] - Change fonts
[tab] - auto adjusting tabbing

requests:

  • Text appending
  • Word wrapping
  • Horizontal scroll bar
  • Custom font possibility without messing up anything
  • Text copying/selecting

BUGS -
This list might get added too if I get any feedback from you guys. Feel free to comment.

FINAL NOTE -

Honestly though I never really tested this, or benchmarked. So there are probably limitations I didnt think of, comment about them here if you encounter any.

One last thing. I really dont care if someone steals my work, they probably could do a better job coding it then me XD This was just a quick thing I needed to do and really didnt put too much effort or work into it.
If you want to take it and re-release it claiming it to be your work…go for it. (though I cant say admins will think the same)

Came in here expecting something epic.

Left disappointed.

agreed

What should we do with this? I kind of agree with Defcon.

Not bad, if it would do all these I would be more than happy

  • Text appending
  • Word wrapping
  • Horizontal scroll bar
  • Custom font possibility without messing up anything
  • Find text tool
  • Alpha colors in text
  • Define text colors while settings text
  • Text copying/selecting

Oh god we need RichText control or similar to garry’s mod.

Came in here expecting something epic.

Saw something new and useful.

Left satisfied.

Yeah ok well I did exaggerate a bit. Its not epic. But useful-ish.

  • Find text tool (lolwhut?)
  • Alpha colors in text <----- See [alpha]
  • Define text colors while settings text <----- Thats generally why this was made…It does support changing text colours inside the text.

I’ll probably implement this into my chatbox, and let the players use the tags.

Looks really cool! :stuck_out_tongue:

I made something exactly like this for my chatbox.

a really small amount of parsing would give you tags, if you just want this in a chatbox.

Nice job, the people who were sad obviously need to read.

Wow, this is sweet. Nice work.

Rather useful. Thanks.

This really isnt ment for chat boxes anyway. You can still use it yes, but really its a basic text box structure. I imagine it being used for other details. Say like in RP you have a display of a persons money balance, display debts in red and credits in green. Same goes for stats if you have some sort of rpg like mod.