Jump to content

Colorcodes in Labels


BriGhtx3

Recommended Posts

I know there is no way to use color codes in labels. But i want to set colors for different texts.

I know I can use dxtext but is there no other way? Like creating a display or something like this for a GUI?

Ill freak out when someone says you cant use color codes in labels -.-

Link to comment
i don't know mybe this will work :

https://wiki.multitheftauto.com/wiki/GuiSetProperty

guiSetProperty(label, "labelTextColour", "FFA0A0A0") 

That would change the label colour, same as guiLabelSetColor.

Lol :D

I knew that but it is very difficult to create 100 labels -.-

And the users add the texts via color codes.

Just create a function which will create as many labels as many colours you have in the string. There is a similar function for DX text on the forum somewhere, just search the forum, I'm sure you'll find it easily. Then just modify the function to work GUI labels instead of DX text.

Link to comment

easy

the original code was for dxdrawcolortext

and i made this for colored label

  
--- by UAEpro 
function guiCreateColorLabel(ax, ay, bx, by,str, parent, bool) 
      local pat = "(.-)#(%x%x%x%x%x%x)" 
      local s, e, cap, col = str:find(pat, 1) 
      local last = 1 
      while s do 
        if cap == "" and col then r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end 
        if s ~= 1 or cap ~= "" then 
        local w = dxGetTextWidth(cap) 
         avc321 = guiCreateLabel(ax, ay, ax + w, by,cap,parent, bool) 
         if r == nil then r = 255 end 
         if g == nil then g = 255 end 
         if b == nil then b = 255 end 
                guiLabelSetColor(avc321,r,g,b) 
          ax = ax + w 
          r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) 
        end 
        last = e + 1 
        s, e, cap, col = str:find(pat, last) 
      end 
      if last <= #str then 
        cap = str:sub(last) 
        local w = dxGetTextWidth(cap) 
        avc123 = guiCreateLabel(ax, ay, ax + w, by,cap,parent, bool) 
                guiLabelSetColor(avc123,r,g,b) 
                 
     end 
    end 
  

Link to comment
  • 1 month later...
function guiCreateColorLabel(ax, ay, bx, by,str, bool, parent) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find(pat, 1) 
    local last = 1 
    while s do 
        if cap == "" and col then r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth(cap) 
            avc321 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) 
            if r == nil then r = 255 end 
            if g == nil then g = 255 end 
            if b == nil then b = 255 end 
            guiLabelSetColor(avc321,r,g,b) 
            ax = ax + w 
        r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) 
        end 
    last = e + 1 
    s, e, cap, col = str:find(pat, last) 
    end 
    if last <= #str then 
        cap = str:sub(last) 
        local w = dxGetTextWidth(cap) 
        avc123 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) 
        guiLabelSetColor(avc123,r,g,b) 
        return avc123 
    end 
end 

Can anyone help with this :lol:

Link to comment
    function guiCreateColorLabel(ax, ay, bx, by,str, bool, parent) 
        local pat = "(.-)#(%x%x%x%x%x%x)" 
        local s, e, cap, col = str:find(pat, 1) 
        local last = 1 
        while s do 
            if cap == "" and col then r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) end 
            if s ~= 1 or cap ~= "" then 
                local w = dxGetTextWidth(cap) 
                avc321 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) 
                if r == nil then r = 255 end 
                if g == nil then g = 255 end 
                if b == nil then b = 255 end 
                guiLabelSetColor(avc321,r,g,b) 
                ax = ax + w 
            r,g,b = tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)) 
            end 
        last = e + 1 
        s, e, cap, col = str:find(pat, last) 
        end 
        if last <= #str then 
            cap = str:sub(last) 
            local w = dxGetTextWidth(cap) 
            avc123 = guiCreateLabel(ax, ay, ax + w, by,cap,bool,parent) 
            guiLabelSetColor(avc123,r,g,b) 
            return avc123 
        end 
    end 

I get error on guiLabelSetColor(avc123,r,g,b) I know that its because r,g,b is not defined but I don't remember nothing how to solve this '-'

Link to comment
function guiCreateColorLabel( ax, ay, bx, by,str, bool, parent ) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find( pat, 1 ) 
    local last = 1 
    local r,g,b 
    while s do 
        if cap == "" and col then r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth( cap ) 
            avc321 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) 
            if not r then r = 255 end 
            if not g then g = 255 end 
            if not b then b = 255 end 
            guiLabelSetColor( avc321,r,g,b ) 
            ax = ax + w 
            r,g,b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), tonumber( "0x"..col:sub( 5, 6 ) ) 
        end 
        last = e + 1 
        s, e, cap, col = str:find( pat, last ) 
    end 
    if last <= #str then 
        local cap = str:sub( last ) 
        local w = dxGetTextWidth( cap ) 
        local avc123 = guiCreateLabel( ax, ay, ax + w, by,cap,bool,parent ) 
        guiLabelSetColor( avc123,r or 255,g or 255,b or 255 ) 
        return avc123 
    end 
end 

Link to comment

I get no error but It don't work... It appear with color codes. And no colors :S

I tried with:

function guiCreateColorLabel ( ax, ay, bx, by, str, relative, parent ) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find(pat, 1) 
    local last = 1 
    while s do 
        if cap == "" and col then r, g, b = tonumber( "0x"..col:sub( 1, 2 ) ), tonumber( "0x"..col:sub( 3, 4 ) ), 
        tonumber( "0x"..col:sub( 5, 6 ) ) 
        end 
        last = e + 1 
        s, e, cap, col = str:find( pat, last ) 
    end 
    if r == nil then r = 255 end 
    if g == nil then g = 255 end 
    if b == nil then b = 255 end 
    if last <= #str then 
        cap = str:sub( last ) 
        label = guiCreateLabel ( ax, ay, bx, by, cap, relative, parent ) 
        guiLabelSetColor ( label, r, g, b ) 
        return label 
    end 
end 

But I get error on guiLabelSetColor. I don't know why I get expected number, colors don't have to be numbers? oO

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...