Snippet ColorIt

WolfieeifloW

WEHZ Helper
Reaction score
372
ColorIt v1.0
By: Wolfie[NoCT]


Introduction:
A cool little library made by me.
All you do is input a color and the string you want to color.
There's two different versions (Blue and Red) .


Usage:
JASS:
function ColorIt takes string Color, string Word returns string Colored

It takes a color and the word you want colored.

So in your function, for example:
JASS:
private function Warning takes nothing returns nothing
    call BJDebugMsg(ColorIt("red", "WARNING!"))
endfunction

Where "red" is the color and "WARNING!" is the word you want colored.
That BJDebugMsg() would result in:
Code:
[color=red]WARNING![/color]

An example of ColorIt in action:
JASS:
scope TestColor initializer TCInit

    private function TCActions takes nothing returns nothing
        call DisplayTextToPlayer(Player(0), 0, 0, "Player " + ColorIt("gold", GetPlayerName(GetTriggerPlayer())) + " has asked for " + ColorIt("red", "help") + "!")
        //Display to 'Player 1 (Red)' that the triggering player needs help;
        //The players name will be colored "gold" because of   ColorIt("gold", GetPlayerName(GetTriggerPlayer()))
        //        Tells ColorIt you want the players name colored gold --^                ^-- Tells ColorIt you want the triggering players name colored
        
        //The text "help" will be colored "red" because of     ColorIt("red", "help")
        //                Tells ColorIt you want your text colored red --^      ^-- Tell ColorIt you want the text "help" colored
    endfunction
        
//====================================================================================================
    private function TCInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
           call TriggerRegisterPlayerChatEvent(t, Player(i), "-help", true) //Register if a player types "-help"
           set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddAction(t, function TCActions)
    endfunction

endscope



Code:
ColorIt Blue:
JASS:
// +------------------------------------------------------------+
// |                                                            |
// |                  -=-=- ColorIt Blue -=-=-                  |
// |                -=-=- By Wolfie[NoCT] -=-=-                 |
// |                    Requires Jass NewGen                    |
// |                                                            |
// +------------------------------------------------------------+
// |                                                            |
// |   ColorIt Blue;                                            |
// |      - Provides an easier way to manage colors             |
// |      - Uses a loop to check for a valid color              |
// |                                                            |
// +------------------------------------------------------------+
library ColorItBlue initializer CIBInit

// +---------------------------------+
// |     -=-=- MODIFY HERE -=-=-     |
// |     -=-=- MODIFY HERE -=-=-     |
// |     -=-=- MODIFY HERE -=-=-     |
// +---------------------------------+
    globals
        constant integer COLORSNUM = 40
        //Change this to the number of array slots used
        
        constant string DEFAULT = "ffffff"
        //Change this to the color you want strings to
        //Default to if users enter an invalid color
        
        //Don't touch these!
        string array COLORNAME//Don't touch these!
        string array COLORCODE//Don't touch these!
        //Don't touch these!
    endglobals
    
// +--------------------------------------------------------------+
// |            Set the colors name into COLORNAME[]              |
// |        Set the hexcode of the color into COLORCODE[]         |
// |   Remember to change COLORSNUM to the number of slot used!   |
// +--------------------------------------------------------------+
    function CIBActions takes nothing returns nothing
        set COLORNAME[0] = "aqua"
        set COLORCODE[0] = "00ffff"
        set COLORNAME[1] = "azure"
        set COLORCODE[1] = "f0ffff"
        set COLORNAME[2] = "beige"
        set COLORCODE[2] = "f5f5dc"
        set COLORNAME[3] = "black"
        set COLORCODE[3] = "000000"
        set COLORNAME[4] = "blue"
        set COLORCODE[4] = "0000ff"
        set COLORNAME[5] = "brown"
        set COLORCODE[5] = "a52a2a"
        set COLORNAME[6] = "coral"
        set COLORCODE[6] = "ff7f50"
        set COLORNAME[7] = "crimson"
        set COLORCODE[7] = "dc143c"
        set COLORNAME[8] = "cyan"
        set COLORCODE[8] = "99b4d1"
        set COLORNAME[9] = "darkblue"
        set COLORCODE[9] = "00008b"
        set COLORNAME[10] = "darkgreen"
        set COLORCODE[10] = "006400"
        set COLORNAME[11] = "darkorange"
        set COLORCODE[11] = "ff8c00"
        set COLORNAME[12] = "darkred"
        set COLORCODE[12] = "8b0000"
        set COLORNAME[13] = "gold"
        set COLORCODE[13] = "ffd700"
        set COLORNAME[14] = "grey"
        set COLORCODE[14] = "808080"
        set COLORNAME[15] = "green"
        set COLORCODE[15] = "008000"
        set COLORNAME[16] = "hotpink"
        set COLORCODE[16] = "ff0099"
        set COLORNAME[17] = "indigo"
        set COLORCODE[17] = "4b0082"
        set COLORNAME[18] = "lavender"
        set COLORCODE[18] = "e6e6fa"
        set COLORNAME[19] = "lightblue"
        set COLORCODE[19] = "add8e6"
        set COLORNAME[20] = "lime"
        set COLORCODE[20] = "00ff00"
        set COLORNAME[21] = "magenta"
        set COLORCODE[21] = "ff00ff"
        set COLORNAME[22] = "maroon"
        set COLORCODE[22] = "800000"
        set COLORNAME[23] = "navy"
        set COLORCODE[23] = "000080"
        set COLORNAME[24] = "olive"
        set COLORCODE[24] = "808000"
        set COLORNAME[25] = "orange"
        set COLORCODE[25] = "ffa500"
        set COLORNAME[26] = "orchid"
        set COLORCODE[26] = "da70d6"
        set COLORNAME[27] = "pink"
        set COLORCODE[27] = "ffc0cb"
        set COLORNAME[28] = "plum"
        set COLORCODE[28] = "dda0dd"
        set COLORNAME[29] = "purple"
        set COLORCODE[29] = "800080"
        set COLORNAME[30] = "red"
        set COLORCODE[30] = "ff0000"
        set COLORNAME[31] = "salmon"
        set COLORCODE[31] = "fa8072"
        set COLORNAME[32] = "silver"
        set COLORCODE[32] = "c0c0c0"
        set COLORNAME[33] = "snow"
        set COLORCODE[33] = "fffafa"
        set COLORNAME[34] = "tan"
        set COLORCODE[34] = "d2b48c"
        set COLORNAME[35] = "teal"
        set COLORCODE[35] = "008080"
        set COLORNAME[36] = "tomato"
        set COLORCODE[36] = "ff6347"
        set COLORNAME[37] = "turquoise"
        set COLORCODE[37] = "40e0d0"
        set COLORNAME[38] = "violet"
        set COLORCODE[38] = "ee82ee"
        set COLORNAME[39] = "yellow"
        set COLORCODE[39] = "ffff00"
        //set COLORNAME[40] = "ColorName"
        //set COLORCODE[40] = "ColorCode"
        //[...]
    endfunction
    
// +------------------------------------------+
// |     -=-=- NO TOUCHIE PAST HERE -=-=-     |
// |     -=-=- NO TOUCHIE PAST HERE -=-=-     |
// |     -=-=- NO TOUCHIE PAST HERE -=-=-     |
// +------------------------------------------+
    function ColorIt takes string Color, string Word returns string Colored
        local integer i = 0
        local boolean cc = false
        
        loop
        exitwhen i == COLORSNUM
            if (Color != COLORNAME<i>) then
                set cc = false
            else
                return (&quot;|cff&quot; + COLORCODE<i> + Word + &quot;|r&quot;)
            endif
            set i = i + 1
        endloop
        return (&quot;|cff&quot; + DEFAULT + Word + &quot;|r&quot;)
    endfunction
    
//====================================================================================================
    private function CIBInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call TriggerRegisterTimerEvent(t, 0.01, false)
        call TriggerAddAction(t, function CIBActions)
    endfunction
    
endlibrary</i></i>

ColorIt Red:
JASS:
// +------------------------------------------------------------+
// |                                                            |
// |                  -=-=- ColorIt Red -=-=-                   |
// |                -=-=- By Wolfie[NoCT] -=-=-                 |
// |                    Requires Jass NewGen                    |
// |                                                            |
// +------------------------------------------------------------+
// |                                                            |
// |   ColorIt Red;                                             |
// |      - A more advanced version                             |
// |      - Utilizes Elseif&#039;s to return values                  |
// |                                                            |
// +------------------------------------------------------------+
library ColorItRed

    globals
        constant string DEFAULT = &quot;|cffffffff&quot;
    endglobals

    function ColorIt takes string Color, string Word returns string Colored
        if (Color == &quot;aqua&quot;) then
            return (&quot;|cff00ffff&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;azure&quot;) then
            return (&quot;|cfff0ffff&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;beige&quot;) then
            return (&quot;|cfff5f5dc&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;black&quot;) then
            return (&quot;|cff000000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;blue&quot;) then
            return (&quot;|cff0000ff&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;brown&quot;) then
            return (&quot;|cffa52a2a&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;coral&quot;) then
            return (&quot;|cffff7f50&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;crimson&quot;) then
            return (&quot;|cffdc143c&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;cyan&quot;) then
            return (&quot;|cff99b4d1&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;darkblue&quot;) then
            return (&quot;|cff00008b&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;darkgreen&quot;) then
            return (&quot;|cff006400&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;darkorange&quot;) then
            return (&quot;|cffff8c00&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;darkred&quot;) then
            return (&quot;|cff8b0000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;gold&quot;) then
            return (&quot;|cffffd700&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;grey&quot; or Color == &quot;gray&quot;) then
            return (&quot;|cff808080&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;green&quot;) then
            return (&quot;|cff008000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;hotpink&quot;) then
            return (&quot;|cffff0099&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;indigo&quot;) then
            return (&quot;|cff4b0082&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;lavender&quot;) then
            return (&quot;|cffe6e6fa&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;lightblue&quot;) then
            return (&quot;|cffadd8e6&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;lime&quot;) then
            return (&quot;|cff00ff00&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;magenta&quot;) then
            return (&quot;|cffff00ff&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;maroon&quot;) then
            return (&quot;|cff800000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;navy&quot;) then
            return (&quot;|cff000080&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;olive&quot;) then
            return (&quot;|cff808000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;orange&quot;) then
            return (&quot;|cffffa500&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;orchid&quot;) then
            return (&quot;|cffda70d6&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;pink&quot;) then
            return (&quot;|cffffc0cb&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;plum&quot;) then
            return (&quot;|cffdda0dd&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;purple&quot;) then
            return (&quot;|cff800080&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;red&quot;) then
            return (&quot;|cffff0000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;salmon&quot;) then
            return (&quot;|cfffa8072&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;silver&quot;) then
            return (&quot;|cffc0c0c0&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;snow&quot;) then
            return (&quot;|cfffffafa&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;tan&quot;) then
            return (&quot;|cffd2b48c&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;teal&quot;) then
            return (&quot;|cff008080&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;tomato&quot;) then
            return (&quot;|cffff6347&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;turquoise&quot;) then
            return (&quot;|cff40e0d0&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;violet&quot;) then
            return (&quot;|cffee82ee&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;yellow&quot;) then
            return (&quot;|cffffff00&quot; + Word + &quot;|r&quot;)
        //elseif (Color == &quot;ColorName&quot;) then
            //return (&quot;ColorCode&quot; + Word + &quot;|r&quot;)
        else
            return (DEFAULT + Word + &quot;|r&quot;)
        endif
    endfunction
    
endlibrary



NOTE: If someone can make a Hexcode converter for this that would be awesome;
Eg. The user types in "red" and the converter retrieves "|cffff0000".
 

Attachments

  • opt-Color_It_v10.w3m
    14.6 KB · Views: 243
I wouldn't want to have to implement another system just to use this one?
I think the arrays are fine;
It's not hard to add more colors and I don't think anyone if going to add 8190 colors.
 
Then you'd have 39 constants in your trigger instead of adding in a library though?

Sorry if I'm misunderstanding;
I'm still new to JASS.
 
You should make a better documentation.

Also there is lots of other things that do the same thing, isn't?
 
Constants are indeed a better idea. If you're taking colors from player chat, however, Table is what you need.
 
You don't need to learn structs to learn Table.

JASS:
globals
    private Table lol
endglobals

private function What takes nothing returns nothing
    set lol[&quot;MyString&quot;] = //Integer
    //Attaching.
    return lol[&quot;MyString&quot;]
    //Retrieving.
endfunction

private function Init takes nothing returns nothing
     set lol = Table.create()
endfunction
 
JASS:
set lol[&quot;MyString&quot;] =

:confused: ?
Should it be like:
JASS:
set lol[&quot;MyString&quot;] = &quot;|cffffffff&quot;

Or something?
 
Did you not see //Integer? It accepts integers only. Like an array index, possibly. Complicates things a bit, I suppose.

JASS:
set lol[&quot;red&quot;] = 0
//Attach.
return ColorStringArray[lol[&quot;red&quot;]]
//Retrieve.


EDIT: Oh wait, nevermind. You need a StringTable. Tables only take integers. :p
 
Bah;
I don't see how this would help though?
Don't I still have to set red to the hexcode?
And then set all the "lol[]"s to their colors?
 
Yes. But retrieving them is faster. And retrieving is where speed matters.
 
I guess you never saw my Adv Strings system :p

http://www.thehelper.net/forums/showthread.php?t=102161

JASS:
call BJDebugMsg(red + &quot;Error: &quot;+ end + green + &quot;Invalid target chosen for &quot; + end + blue + &quot;Sacrifice!&quot; + end)


It just seems to be more readable to me when you have the colors spaced out like a sentence.

I don't think you're going to have tons of colors being used in a map, so it seems to make sense to have it as an add-as-you-need basis as I did in mine. The only real problem I see with mine is the ugly "end" you have to add to *end* a color (though one might consider that an easy way to distinguish the ending of one color to the beginning of another).
 
> it won't compile:
You mean, it shouldn't compile.
That does compile, but I do suggest you fix that anyway, Wolfie.

Oh, and the red version is somewhat useless when you can use arrays or table.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top