AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [Panels] New line not getting processed (https://forums.alliedmods.net/showthread.php?t=316973)

thresh0ld 06-20-2019 07:10

[Panels] New line not getting processed
 
Noticed something strange. On the first two examples, the special character '\n' is processed and a new line is inserted on the panel. On the last example, the string now is retrieved from a configuration file (key value) then passed to the function, it does not get processed. Why is this?


First Example (Gets Processed):

Code:

panel.DrawText("Test\nHeader");
Second Example (Gets Processed):

Code:

char tmpHeader[255];
Format(tmpHeader, sizeof(tmpHeader), "Test\nHeader");
panel.DrawText(tmpHeader);

Third Example (Does not get processed):

Note: g_StatPanelTitleMenuHeader1 would contain the text "Test\nHeader"

Code:

char g_StatPanelTitleMenuHeader1[255];

void LoadConfigData() {
        //....................
       
        //Extract
        kv.GetString("title_menu_header_1", g_StatPanelTitleMenuHeader1, sizeof(g_StatPanelTitleMenuHeader1));
        if (strcmp(g_StatPanelTitleMenuHeader1, "", false) == 0) {
                Debug("Config 'title_menu_header_1' is empty. Using default");
                FormatEx(g_StatPanelTitleMenuHeader1, sizeof(g_StatPanelTitleMenuHeader1), DEFAULT_TITLE_STAT_PANEL_MENU_HEADER);
        }
       
        //..............
}

bool DrawPanelHeader(Panel & panel, const char[] headerFormat, StringMap & map = null) {
        char header[255];
        ParseTitle(headerFormat, header, sizeof(header));
       
        if (map != null) {
                float totalPoints = 0.0;
                char name[MAX_NAME_LENGTH];
                int rankNum;
               
                //Perform some replacements
                if (map.GetValue(STATS_TOTAL_POINTS, totalPoints)) {
                        char sTotalPoints[64];
                        PSFormat(sTotalPoints, sizeof(sTotalPoints), "{f}", totalPoints);
                        ReplaceString(header, sizeof(header), "{points}", sTotalPoints, false);
                }
               
                if (map.GetString(STATS_LAST_KNOWN_ALIAS, name, sizeof(name))) {
                        ReplaceString(header, sizeof(header), "{name}", name, false);
                }
               
                if (map.GetValue(STATS_RANK, rankNum)) {
                        char sRankNum[32];
                        IntToString(rankNum, sRankNum, sizeof(sRankNum));
                        if (totalPoints <= 0)
                                ReplaceString(header, sizeof(header), "{rank}", "N/A", false);
                        else
                                ReplaceString(header, sizeof(header), "{rank}", sRankNum, false);
                }
        }
       
        if (!StringBlank(header)) {
                panel.DrawText(header);
                return true;
        }
       
        return false;
}


Example usage:

Code:

LoadConfigData();

StringMap map = new StringMap();

//populate map entries...

//Draw header
DrawPanelHeader(panel, g_StatPanelTitleMenuHeader1, map);



Output:

https://i.imgur.com/MWo1Npg.png

xines 06-20-2019 10:10

Re: [Panels] New line not getting processed
 
Set the escape sequences to true.

PHP Code:

kv.SetEscapeSequences(true); 

https://sm.alliedmods.net/new-api/ke...scapeSequences

thresh0ld 06-20-2019 10:16

Re: [Panels] New line not getting processed
 
Quote:

Originally Posted by xines (Post 2656095)
Set the escape sequences to true.

PHP Code:

kv.SetEscapeSequences(true); 

https://sm.alliedmods.net/new-api/ke...scapeSequences

Ahhh thank you!


All times are GMT -4. The time now is 13:23.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.