//Written Specifically for 3DGS 7
//MUST BE INCLUDED AFTER adll.h to function.
class NG_InputBox {
public:
NG_InputBox(var x,var y,STRING* Label,var maxlen,var layer);
void ProcessKeys();
void NG_InputBox::SetPos(var x,var y);
TEXT* tInput;
bool allow_space;
STRING* entrytxt;
STRING* entrytxt2;
var MaxLen;
PANEL* pIB;
TEXT* tInputLabel;
int entry;
//Detour Loop
var typerate;
};
NG_InputBox::NG_InputBox(var x,var y,STRING* Label,var maxlen,var layer) {
allow_space = 1; //Set to zero for NO SPACES (ie: usernames, email addresses, etc.. :) duh
entry = 1;
typerate = 0;
entrytxt=str_create(" ");
entrytxt2=str_create(" ");
str_cpy(entrytxt,"");
MaxLen = maxlen;
tInputLabel = txt_create(_VAR(1),layer);
tInput = txt_create(_VAR(1),layer);
tInputLabel->pos_x = x ;
tInputLabel->pos_y = y + _VAR(8);
tInput->pos_x = x + 8 * (str_len(_chr(Label))-3);
tInput->pos_y = y + _VAR(8);
str_cpy(tInputLabel->pstring[0],_chr(Label));
pIB = pan_create("bmap = ng_Dialog.bmp;",1);
pIB->flags |= VISIBLE;
pIB->flags |= OVERLAY;
tInputLabel->flags |= VISIBLE;
tInput->flags |= VISIBLE;
pIB->pos_x = x;
pIB->pos_y = y;
pIB->scale_x = (_VAR(8) * (str_len(_chr(Label)) + maxlen)) / bmap_width(pIB->bmap);
pIB->scale_y = _VAR(0.05);
};
void NG_InputBox::SetPos(var x,var y) {
pIB->pos_x = x;
pIB->pos_y = y;
tInputLabel->pos_x = x ;
tInputLabel->pos_y = y + _VAR(8);
tInput->pos_x = x + 8 * (str_len(_chr(tInputLabel->pstring[0]))-3);
tInput->pos_y = y + _VAR(8);
}
void NG_InputBox::ProcessKeys() {
typerate += v(time_step);
if (entry == 1 && v(key_any) ) {
str_cpy(entrytxt2,_chr(entrytxt));
if (v(key_lastpressed) != _VAR(78) && v(key_lastpressed) != _VAR(76) && v(key_lastpressed) != _VAR(53) && v(key_lastpressed) != _VAR(55) && v(key_lastpressed) != _VAR(74)) {
entrytxt=str_for_key(NULL,v(key_lastpressed));
} else {
entrytxt=str_for_key(NULL,_VAR(41));
}
if (str_cmp(entrytxt,_chr(entrytxt2)) && typerate <= (v(time_step) * 200) ) {
//str_cpy(tDebug->pstring[0],"TYPERATE/TIME_STEP ");
//str_cat_num(tDebug->pstring[0],"= %f",typerate);
//str_cat_num(tDebug->pstring[0],"/%f",v(time_step));
} else {
typerate = v(time_step);
if (str_len(_chr(entrytxt)) < _VAR(2) && str_len(_chr(entrytxt)) > _VAR(0)) {
if (str_len(_chr(tInput->pstring[0])) < MaxLen) {
str_cat(tInput->pstring[0],_chr(entrytxt));
} else {
//str_cpy(tDebug->pstring[1],"MAXIMUM LENGTH REACHED!");
}
} else {
if (str_cmp(entrytxt,"bksp")){
//str_cpy(tDebug->pstring[0],"");
if (str_len(_chr(tInput->pstring[0])) > _VAR(0)) {
str_trunc(tInput->pstring[0],_VAR(1));
}
} else if (str_cmp(entrytxt,"space")){
if(allow_space){ //if
str_cat(tInput->pstring[0]," "); //do it
} else {
//umm... dont
}
//str_cpy(tDebug->pstring[1],"NO SPACES PLEASE");
} else {
//str_cpy(tDebug->pstring[1],"Discarded KeyStr : ");
//str_cat(tDebug->pstring[1],_chr(entrytxt));
}
}
}
}
}