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: