Raised This Month: $102 Target: $400
 25% 

[Panels] New line not getting processed


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thresh0ld
Senior Member
Join Date: Sep 2009
Location: Hell
Old 06-20-2019 , 07:10   [Panels] New line not getting processed
Reply With Quote #1

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:

thresh0ld is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-20-2019 , 10:10   Re: [Panels] New line not getting processed
Reply With Quote #2

Set the escape sequences to true.

PHP Code:
kv.SetEscapeSequences(true); 
https://sm.alliedmods.net/new-api/ke...scapeSequences
__________________
xines is offline
thresh0ld
Senior Member
Join Date: Sep 2009
Location: Hell
Old 06-20-2019 , 10:16   Re: [Panels] New line not getting processed
Reply With Quote #3

Quote:
Originally Posted by xines View Post
Set the escape sequences to true.

PHP Code:
kv.SetEscapeSequences(true); 
https://sm.alliedmods.net/new-api/ke...scapeSequences
Ahhh thank you!
thresh0ld is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:34.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode