Author Topic: procedure TextBox(...);  (Read 1386 times)

0 Members and 1 Guest are viewing this topic.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
procedure TextBox(...);
« on: February 09, 2011, 04:28:56 pm »
Hello, i have recently recoded my TextBox function to eliminate dynamic arrays, because they suck in the sh*tcore. Well, here it is, use it as you wish, just dont claim it as your own.

Features:
Per-line alignment, right and center align, left exists just to be consistent, no alignment token = left aligned.
Allows for both in-game and in-console output. (if the ID is not between 0 and 32 then it will output to the console instead)

Code: [Select]
procedure TextBox(ID: byte; title,input,delim: string; wallx,wally,corner: char; color: longint);
var i,lines,lines2,max,tempint,delimlen: integer; output,tempstr: string;
begin
output := '';
max := length(title);
delimlen := length(delim);
i := 0;
lines := 1;
for i := 1 to length(input) do if copy(input,i,delimlen) = delim then lines := lines + 1;
lines2 := lines;
for i := 0 to lines-1 do begin
tempstr := getpiece(input,delim,i);
tempint := length(tempstr);
if tempint > max then max := tempint;
end;
tempint := ((max-length(title)) div 2);
output := output + corner + replicate(wallx,tempint) + title + replicate(wallx,max-(tempint+length(title))) + corner + delim;
for i := 0 to lines-1 do begin
tempstr := getpiece(input,delim,i);
if tempstr = nil then begin
lines2 := lines2 - 1;
continue;
end;
tempint := length(tempstr);
output := output + wally;
case copy(tempstr,1,3) of
'[r]': output := output + replicate(' ',max-(tempint-3)) + copy(tempstr,4,tempint-3);
'[l]': output := output + copy(tempstr,4,tempint-3) + replicate(' ',max-(tempint-3));
'[c]': output := output + replicate(' ',(max-(tempint-3)) div 2) + copy(tempstr,4,tempint-3) + replicate(' ',max-(tempint-3+(max-(tempint-3)) div 2));
else output := output + tempstr + replicate(' ',max-tempint);
end;
output := output + wally + delim;
end;
output := output + corner + replicate(wallx,max) + corner;
for i := 0 to lines2+1 do begin
tempstr := getpiece(output,delim,i);
if ((ID >= 0) AND (ID <= 32)) then
writeconsole(ID,tempstr,color)
else
writeln(tempstr);
end;
end;

Argument List:
ID: ID of player to see the textbox, 0 for all players, 255 for serverconsole
title: title of the textbox
input: string containing the data to be arranged inside the textbox
delim: the delimiter that splits the lines within the input, i recommend #6
wallx: the character used on the top and bottom of the textbox
wally: the character used on the sides of the textbox
corner: the character used on the corners of the textbox
color: the color of the textox, not used in consoleoutput

Example Usage:
Code: [Select]
procedure TextBoxTest();
var buffer: string;
begin
buffer := '';
buffer := buffer + 'line one is normal' + #6;
buffer := buffer + '[c]centered' + #6;
buffer := buffer + '[r]right alligned' + #6;
buffer := buffer + 'this   is   a   test' + #6;
textbox(0,' Title ',buffer,#6,'_','|','+',$ff000000);
end;
Could also be used inline like this:
Code: [Select]
textbox(0,' Title ', 'line one is normal'#6'[c]centered'#6'[r]right alligned'#6'this   is   a   test',#6,'_','|','+',$ff000000);
Result:


You should be able to directly feed a readfile() into it and use the delimiter (#13+#10) to show the file inside the box.

If you want to see a live test, i use this ALOT on my server: 204.80.93.33:23333