lfnetwork.com mark read register faq members calendar

Thread: Auto Wrap is still bugged.
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 03-19-2006, 11:00 PM   #1
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
Auto Wrap is still bugged.

Here's a fix, because if you try this with your text auto wrap func it will not show up correctly:
^7Capture the Flag,\n^1All kills legal^7!\n\n^3www^7.^3WildJedi^7.^3com^7

You will see:

Capture the Flag,
All kills
legal

www.WildJedi.com

its a pretty easy fix just add this function:

Code:
// replaces all occurances of "\n" with '\n'
char *Q_AddCR(char *s)
{
	char *copy, *place, *start;

	if(!*s) return s;
	start = s;
	while(*s) {
		if(*s == '\\') {
			copy = s;
			place = s;
			*s++;
			if(*s && *s == 'n') {
				*copy = '\n';
				while(*++s) {
					*++copy = *s;
				}
				*++copy = '\0';
				s = place;
				continue;
			}
		}
		*s++;
	}
	return start;
}
Also, the auto lose color on new line bug is fixed in here as well as adding the Q_AddCR() to the TextWrapCenterPrint:

Code:
//[AdminSys]
void TextWrapCenterPrint(char orgtext[CENTERPRINT_MAXSTRING], char output[CENTERPRINT_MAXSTRING])
{//this function auto text wraps a centersay message so that it will display correctly on clients that aren't 
	//running OJP.  Clients running OJP do this text wrapping on the client side.
	//scan thru print text and add new lines where needed.
	int orgIndex, outputIndex, charCounter;
	char lastColor = '7';

	Q_AddCR(orgtext);
	for(orgIndex = 0, outputIndex = 0, charCounter = 0;
		orgIndex < CENTERPRINT_MAXSTRING && outputIndex < CENTERPRINT_MAXSTRING; 
		orgIndex++, charCounter++, outputIndex++)
	{
		if(orgtext[orgIndex] == '\n')
		{//manual newline, reset charCounter
			charCounter = -1;
		}

		if(charCounter == 50)
		{//this line is too long for the basejka client, add a line break.
			if( !BG_IsWhiteSpace(orgtext[orgIndex]) && !BG_IsWhiteSpace(orgtext[orgIndex-1]) )
			{//we might have cut a word off, attempt to find a spot where we won't cut words off at.
				int savedOrgIndex = orgIndex;
				int savedOutputIndex = outputIndex;

				for(; orgIndex >= 0; orgIndex--, outputIndex--)
				{
					if(BG_IsWhiteSpace(orgtext[orgIndex]))
					{//this location is whitespace, line break from this position
						//advance the orgIndex back to the first letter of the word that we're going to
						//wrap to the next line.
						orgIndex++;
						break;
					}
				}
				if(orgIndex < 0)
				{//couldn't find a break in the text, just go ahead and cut off the word mid-word.
					orgIndex = savedOrgIndex;
					outputIndex = savedOutputIndex;
				}
			}
	
			//add line break at proper position.
			output[outputIndex] = '\n';

			//reset charCounter, set to -1 to account for autoincrement
			charCounter = -1;

			//decrement orgtext index so we'll try to recopy this char on the next pass.
			orgIndex--;
			continue;
		}

		//line isn't too long yet, just straight copy this char to the output.
		output[outputIndex] = orgtext[orgIndex];

		if(output[outputIndex] == '\0')
		{//we're done
			break;
		}
		
		if(output[outputIndex] == '^' && orgtext[orgIndex+1] != '^') {
			charCounter -= 2;
		}
	}
	
	for( orgIndex=0; orgIndex < outputIndex; orgIndex++ ) {
		if(output[orgIndex] == '^' && ( output[orgIndex+1] >= '0' && output[orgIndex+1] <= '7' ))
			lastColor = output[orgIndex+1];
		else if(output[orgIndex] == '\n') {
			Com_sprintf(output+orgIndex+1,CENTERPRINT_MAXSTRING-orgIndex-1,"%c%c%s",'^',lastColor,output+orgIndex+1);
			orgIndex += 2;
		}
	}
}
//[/AdminSys]
i forgot there is also a fix but it really didnt seem to be the problem of what was fixed above:
you forgot to clear the line ("i") when there is a new line.

Code:
void CG_CenterPrint( const char *str, int y, int charWidth ) {
	char	*s;
	//[BugFix19]
	int		i = 0;
	//[/BugFix19]

	Q_strncpyz( cg.centerPrint, str, sizeof(cg.centerPrint) );

	cg.centerPrintTime = cg.time;
	cg.centerPrintY = y;
	cg.centerPrintCharWidth = charWidth;

	// count the number of lines for centering
	cg.centerPrintLines = 1;
	s = cg.centerPrint;
	while( *s ) 
	{
		//[BugFix19]
		i++;
		if(i >= 50)
		{//maxed out a line of text, this will make the line spill over onto another line.
			i = 0;
			cg.centerPrintLines++;
		}
		else if (*s == '\n') {
		//if (*s == '\n')
		//[/BugFix19]
			i = 0;
			cg.centerPrintLines++;
		}
		s++;
	}
}
also a fix for blank names which can occur if you try something like name "^1 ". it also doesnt allow clients to use ^8 and ^9 since they really are not colors:

The following originally goes to MasterHex who did xMod but it had a bug that wouldnt allow ^'s in the text. The fix for that here though goes to me and dumbledore.

Code:
void RealCleanName(char *name, char *out, int outlen)
{
	qboolean valid = qfalse;

	char *wp = out, *rp, *rap;    //write, read, and readahead

	for(rp = name; *rp == ' '; rp++);   //eat leading spaces

	while(*rp)
	{
		if (*rp == '^') //oh no, we have a color code
		{
			for(rap = rp; *rap && *++rap == '^';*wp++ = '^');  //find the first non^

			if (*rap <= '7' && *rap >= '0')  //if it's a valid color code (between 7 and 1 and 0)
//			if (*rap <= '7' && *rap >= '0' + !rs_blacknames.integer)  //if it's a valid color code (between 7 and 1 if rs_blacknames.integer is 0, 7 and 0 otherwise)
			{
				if (wp - out < outlen) *wp++ = *rp; //copy one ^
				if (wp - out < outlen) *wp++ = *rap;//as well as the number
			} else if (*rap != '8' && *rap != '9') {
				if (wp - out < outlen) *wp++ = *rp; //copy one ^
				if (wp - out < outlen) *wp++ = *rap;//as well as the letter
			}

			rp = rap;   //skip the color string... it has been written if it's a valid one
		}
		else
		{
			if (wp - out < outlen) *wp++ = *rp; //length checking... just to make sure we don't run over the edge of the out string and crash the server... o_O
		}

		if (*rp) rp++;  //read the next one if there is a next one... (a bad color string at the end will cause rp to point to the ending null char)
	}

	while(*--wp == ' ');	//from the end of the line, look backwards for the first non-space.
	*++wp = 0;				//go back to the space and make a null character (this clips trailing spaces)

	rp = out;
	while(*rp)
	{
		if (*rp != ' ' && *rp != '^') valid = qtrue;
		if (*rp == '^') rp++;
		if (*rp) rp++;
	}
	if (!valid) strcpy(out, "Padawan");		//if, after all that, we're left with nothing, name them Padawan
}
just call that function instead of ClientCleanName


iojamp project lead / coder

Last edited by ensiform; 04-24-2006 at 05:09 PM.
ensiform is offline   you may: quote & reply,
Old 03-20-2006, 01:08 AM   #2
JRHockney*
Moderator
 
JRHockney*'s Avatar
 
Join Date: Jan 2006
Posts: 1,255
Hot Topic Starter LFN Staff Member 
Hey! I can actually understand alot of that. And I only know some Java!........Hooray!


Game screen name: Master Jon Hoc Ni

UDM Quote: in singapore, gangsters are...skinny jacka**es who think they can 0wn you. they hurl insults at u, and then lose in a fight. n00bs
JRHockney* is offline   you may: quote & reply,
Old 03-20-2006, 03:44 PM   #3
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
lol and i thought java was weird. i prefer c and c++ much better.


iojamp project lead / coder
ensiform is offline   you may: quote & reply,
Old 03-20-2006, 06:52 PM   #4
razorace
Impressive, Terran!
 
razorace's Avatar
 
Join Date: May 2002
Posts: 9,172
Ok, thanks for the fixes Ensiform. However, please make sure that you compiled/tested code before you post it, there's a minor typo in the first code snippet.


---Jedi Guardian of the Newbie Questions
---Masters of the Force Team Leader / Creator
---Open Jedi Project Lead Moderator / Co-Founder
razorace is offline   you may: quote & reply,
Old 03-20-2006, 07:37 PM   #5
razorace
Impressive, Terran!
 
razorace's Avatar
 
Join Date: May 2002
Posts: 9,172
Say, is it really nessicary to preserve the line color between newlines? Does the game do that normally?


---Jedi Guardian of the Newbie Questions
---Masters of the Force Team Leader / Creator
---Open Jedi Project Lead Moderator / Co-Founder
razorace is offline   you may: quote & reply,
Old 03-21-2006, 08:29 AM   #6
Lathain Valtiel
Ex-Angel
 
Lathain Valtiel's Avatar
 
Join Date: Jul 2002
Posts: 929
LFN Staff Member 
Technically, no. That said, it's very convienent and if it's not resource draining I request that it remain in.


Kurgan's Meatgrinder (JA Server: 72.5.248.212:29070)

Player tested, Valtiel approved.

Valtiel approved downloads for Meatgrinder: http://strategy.jediknight.net/jka/downloads.shtml
Lathain Valtiel is offline   you may: quote & reply,
Old 03-21-2006, 08:12 PM   #7
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
well its supposed to and there was a fix for it for CG_DrawStringExt but JKA doesnt use that for centerprint drawing and CG_Text_Paint is an engine trap call so i cant really fix it that way and + this makes it so that ppl without client can use it.


o rly? it works just fine here. which did u think was the typo?


iojamp project lead / coder
ensiform is offline   you may: quote & reply,
Old 04-22-2006, 06:10 AM   #8
razorace
Impressive, Terran!
 
razorace's Avatar
 
Join Date: May 2002
Posts: 9,172
Quote:
Com_sprintf(output+orgIndex+1,CENTERPRINT_MAXSTRIN G-orgIndex-1,"%c%c%s",'^',lastColor,output+orgIndex+1);
The "CENTERPRINT_MAXSTRIN G" has to be a typo.

Anyway, sorry to zombie this thread but I finally had some time and I was going over your cp_color_fix.txt file that you sent me. What was the point of it again? I don't understand why you're setting setColor to color.


---Jedi Guardian of the Newbie Questions
---Masters of the Force Team Leader / Creator
---Open Jedi Project Lead Moderator / Co-Founder
razorace is offline   you may: quote & reply,
Old 04-22-2006, 11:54 AM   #9
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
ah well that doesnt even work with jka for cp anyway, the CP doesn't use drawext. i had fixed it for q3 and et. so the auto putting the color code on next line is done now and its server side so ppl without clients can notice the change.

LOL! i just noticed it, and it only appears in the code thingy here, its normal in my code its even normal when i click edit to fix it here


iojamp project lead / coder
ensiform is offline   you may: quote & reply,
Old 04-22-2006, 05:21 PM   #10
razorace
Impressive, Terran!
 
razorace's Avatar
 
Join Date: May 2002
Posts: 9,172
So, the cp_color_fix.txt stuff wasn't actually needed then?


---Jedi Guardian of the Newbie Questions
---Masters of the Force Team Leader / Creator
---Open Jedi Project Lead Moderator / Co-Founder
razorace is offline   you may: quote & reply,
Old 04-22-2006, 10:09 PM   #11
ensiform
The Stig
 
ensiform's Avatar
 
Join Date: Nov 2004
Location: Sawtooth Cauldron
Posts: 1,241
Current Game: Borderlands 2
no it wasn't. the textwrapcenterprint above fixes the lose color on new line prob.

prolly should send u these in aim or something cuz this board seems to have some weird cut-off values or something.


iojamp project lead / coder
ensiform is offline   you may: quote & reply,
Old 04-23-2006, 12:58 AM   #12
razorace
Impressive, Terran!
 
razorace's Avatar
 
Join Date: May 2002
Posts: 9,172
That would be great.


---Jedi Guardian of the Newbie Questions
---Masters of the Force Team Leader / Creator
---Open Jedi Project Lead Moderator / Co-Founder
razorace is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > JediKnight Series > Community > Hosted Forums > Open Jedi Project (OJP) > Auto Wrap is still bugged.

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 Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:58 AM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.