GimelBot/src/Scripts/Textbox/log_update.gml

53 lines
1.7 KiB
Plaintext
Raw Normal View History

2021-10-16 18:00:39 -05:00
// log_update(str,width)
//
// str - string to append to the log
// width - width of area (in pixels) log will be displayed
var str, logw, i, loop;
str=argument0;
logw=argument1;
loop=true;
while (loop){
if(string_width(str)>logw){
// The string is too long to be displayed on one line.
if(string_pos(" ",str)&&(string_width(string_copy(str,1,string_pos(" ",str)))<logw)){
// There's a space before str exceeds the display width
i=string_length(str);
repeat(string_length(str)){
if((string_char_at(str,i)==" ")&&(string_width(string_copy(str,1,i))<logw)){
chatLog=chatLog+string_replace_all(string_copy(str,1,i-1),"#","\#")+EOL;
str=string_delete(str,1,i);
break;
}
i-=1;
}
} else {
// No space before str exceeds the display width
i=string_length(str);
repeat(string_length(str)){
if(string_width(string_copy(str,1,i))<logw){
str=string_insert("-",str,i-1);
chatLog=chatLog+string_replace_all(string_copy(str,1,i-1),"#","\#")+EOL;
str=string_delete(str,1,i);
break;
}
i-=1;
}
}
} else {
// The string will fit, just add it to the log.
chatLog=chatLog+string_replace_all(str,"#","\#")+EOL;
loop=false;
}
// Update the Scrollbar
if(get_scrollbarvalue(chatScrollbar)==string_count(EOL,chatLog)-2){
global.___sb[chatScrollbar,1]+=1;
}
}