consoleblinkdelay = 0;
consoleblink = 0;
consoleselected = 0;
- memset(togglekey, 0, sizeof(togglekey));
- memset(togglekeydelay, 0, sizeof(togglekeydelay));
+// memset(togglekey, 0, sizeof(togglekey));
+// memset(togglekeydelay, 0, sizeof(togglekeydelay));
registernow = 0;
autocam = 0;
OPENAL_Sample_SetMinMaxDistance(samp[sound], 8.0f, 2000.0f);
}
-void Game::inputText() {
- waiting=true;
- params_thread* data = new params_thread;
- data->game = this;
- data->method = &Game::inputText_thread;
- SDL_Thread* thread = SDL_CreateThread(Game::thread, data);
- if ( thread == NULL ) {
- fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());
- waiting=false;
- return;
- }
-}
-
-void Game::inputText_thread() {
+void Game::inputText(char* str, int* charselected, int* nb_chars) {
SDL_Event evenement;
- SDL_EnableKeyRepeat(400, 40);
- SDL_EnableUNICODE(true);
-
- while(waiting) {
- int i;
- SDL_WaitEvent(&evenement);
-
- switch(evenement.type) {
- case SDL_KEYDOWN:
- if(evenement.key.keysym.sym == SDLK_ESCAPE) {
- for(i=0;i<255;i++){
- displaytext[0][i]=' ';
- }
- displaychars[0]=0;
- displayselected=0;
- mainmenutogglekeydown=1;
- waiting=false;
- } else if(evenement.key.keysym.sym==SDLK_BACKSPACE&&displayselected!=0){
- for(i=displayselected-1;i<255;i++){
- displaytext[0][i]=displaytext[0][i+1];
- }
- displaytext[0][255]=' ';
- displayselected--;
- displaychars[0]--;
- } else if(evenement.key.keysym.sym==SDLK_DELETE&&displayselected!=0){
- for(i=displayselected;i<255;i++){
- displaytext[0][i]=displaytext[0][i+1];
- }
- displaytext[0][255]=' ';
- displaychars[0]--;
- } else if(evenement.key.keysym.sym==SDLK_LEFT&&displayselected!=0){
- displayselected--;
- } else if(evenement.key.keysym.sym==SDLK_RIGHT&&displayselected<displaychars[0]){
- displayselected++;
- } else if(evenement.key.keysym.sym==SDLK_RETURN) {
- if(displaychars[0]){
- accountactive = Account::add(string(displaytext[0]));
-
- mainmenu=8;
-
- flash();
-
- fireSound(firestartsound);
-
- for(i=0;i<255;i++){
- displaytext[0][i]=' ';
- }
- displaychars[0]=0;
+ int i;
+
+ if(!waiting) {
+ waiting=true;
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
+ SDL_EnableUNICODE(true);
+ }
- displayselected=0;
- }
- waiting=false;
- } else if(evenement.key.keysym.unicode&&displaychars[0]<60) {
- for(i=255;i>=displayselected+1;i--){
- displaytext[0][i]=displaytext[0][i-1];
+ SDL_PollEvent(&evenement);
+
+ switch(evenement.type) {
+ case SDL_KEYDOWN:
+ if(evenement.key.keysym.sym == SDLK_ESCAPE) {
+ for(i=0;i<255;i++){
+ str[i]=' ';
+ }
+ *nb_chars=0;
+ *charselected=0;
+ waiting=false;
+ } else if(evenement.key.keysym.sym==SDLK_BACKSPACE){
+ if((*charselected)!=0) {
+ for(i=(*charselected)-1;i<255;i++){
+ str[i]=str[i+1];
}
- displaytext[0][displayselected]=evenement.key.keysym.unicode;
- displayselected++;
- displaychars[0]++;
- printf("%c\n",evenement.key.keysym.unicode);
+ str[255]=' ';
+ (*charselected)--;
+ (*nb_chars)--;
}
- break;
- }
+ } else if(evenement.key.keysym.sym==SDLK_DELETE){
+ for(i=(*charselected);i<255;i++){
+ str[i]=str[i+1];
+ }
+ str[255]=' ';
+ (*nb_chars)--;
+ } else if(evenement.key.keysym.sym==SDLK_LEFT){
+ if((*charselected)!=0)
+ (*charselected)--;
+ } else if(evenement.key.keysym.sym==SDLK_RIGHT){
+ if((*charselected)<(*nb_chars))
+ (*charselected)++;
+ } else if(evenement.key.keysym.sym==SDLK_RETURN) {
+ waiting=false;
+ } else if((evenement.key.keysym.unicode<127)&&((*nb_chars)<60)&&(evenement.key.keysym.sym!=SDLK_LSHIFT)&&(evenement.key.keysym.sym!=SDLK_RSHIFT)) {
+ for(i=255;i>=(*charselected)+1;i--){
+ str[i]=str[i-1];
+ }
+ str[*charselected]=evenement.key.keysym.unicode;
+ (*charselected)++;
+ (*nb_chars)++;
+ }
+ break;
+ }
+
+ if(!waiting) {
+ SDL_EnableKeyRepeat(0,0); // disable key repeat
+ SDL_EnableUNICODE(false);
}
- entername=0;
- SDL_EnableKeyRepeat(0,0); // disable key repeat
- SDL_EnableUNICODE(false);
}
void Game::setKeySelected() {
if(keycode != SDLK_ESCAPE) {
fireSound();
switch(keyselect) {
- case 0:forwardkey=keycode;
+ case 0: forwardkey=keycode;
break;
- case 1:backkey=keycode;
+ case 1: backkey=keycode;
break;
- case 2:leftkey=keycode;
+ case 2: leftkey=keycode;
break;
- case 3:rightkey=keycode;
+ case 3: rightkey=keycode;
break;
- case 4:crouchkey=keycode;
+ case 4: crouchkey=keycode;
break;
- case 5:jumpkey=keycode;
+ case 5: jumpkey=keycode;
break;
- case 6:drawkey=keycode;
+ case 6: drawkey=keycode;
break;
- case 7:throwkey=keycode;
+ case 7: throwkey=keycode;
break;
- case 8:attackkey=keycode;
+ case 8: attackkey=keycode;
break;
default:
break;
float consoleblinkdelay;
bool consoleblink;
int consoleselected;
- int togglekey[140];
- float togglekeydelay[140];
+ //int togglekey[140];
+ //float togglekeydelay[140];
bool registernow;
bool autocam;
private:
void setKeySelected_thread();
static int thread(void *data);
- void inputText();
- void inputText_thread();
+ void inputText(char* str, int* charselected, int* nb_chars);
void flash();
bool waiting;
bool mainmenutogglekeydown;
OPENAL_SetFrequency(channels[stream_music3], 22050);
if(entername) {
- if(!waiting) inputText();
+ inputText(displaytext[0],&displayselected,&displaychars[0]);
+ if(!waiting) { // the input as finished
+ if(displaychars[0]){ // with enter
+ accountactive = Account::add(string(displaytext[0]));
+
+ mainmenu=8;
+
+ flash();
+
+ fireSound(firestartsound);
+
+ for(i=0;i<255;i++){
+ displaytext[0][i]=' ';
+ }
+ displaychars[0]=0;
+
+ displayselected=0;
+ } else { // with escape or empty
+ mainmenutogglekeydown=1;
+ }
+ entername=0;
+ }
displayblinkdelay-=multiplier;
if(displayblinkdelay<=0){
if(Input::isKeyDown(chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
chatting=1;
chattogglekeydown=1;
- togglekey[chatkey]=1;
- togglekeydelay[chatkey]=-20;
}
if(!Input::isKeyDown(chatkey)){
}
if(chatting){
- for(i=0;i<140;i++){
- if(Input::isKeyDown(i)){
- togglekeydelay[i]+=multiplier;
- if(togglekeydelay[i]>.4){
- togglekey[i]=0;
- togglekeydelay[i]=.36;
+ inputText(displaytext[0],&displayselected,&displaychars[0]);
+ if(!waiting) {
+ if(displaychars[0]){
+ for(int j=0;j<255;j++){
+ displaytext[0][j]=' ';
}
- if(!togglekey[i]){
- if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
- for(j=255;j>=displayselected+1;j--){
- displaytext[0][j]=displaytext[0][j-1];
- }
- displaytext[0][displayselected]=KeyToSingleChar(i);
- if(Input::isKeyDown(SDLK_LSHIFT))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
- displayselected++;
- displaychars[0]++;
- }
- if(i==SDLK_DELETE&&displayselected!=0){
- for(j=displayselected-1;j<255;j++){
- displaytext[0][j]=displaytext[0][j+1];
- }
- displaytext[0][255]=' ';
- displayselected--;
- displaychars[0]--;
- }
- if(i==SDLK_LEFT&&displayselected!=0){
- displayselected--;
- }
- if(i==SDLK_RIGHT&&displayselected<displaychars[0]){
- displayselected++;
- }
- if(i==SDLK_RETURN){
- if(displaychars[0]){
- /*for(j=0;j<displaychars[0];j++){
- talkname[j]=displaytext[0][j];
- }
- talkname[displaychars[0]]='\0';
- sprintf (chatname, "%s: %s",playerName,talkname);
- //NetworkSendInformation(chatname);
- */
- for(j=0;j<255;j++){
- displaytext[0][j]=' ';
- }
- displaychars[0]=0;
- displayselected=0;
- chatting=0;
- }
- }
- }
- togglekey[i]=1;
- }
- else {
- togglekey[i]=0;
- togglekeydelay[i]=0;
- }
+ displaychars[0]=0;
+ displayselected=0;
+ }
+ chatting=0;
}
displayblinkdelay-=multiplier;
if(Input::isKeyDown(SDLK_BACKQUOTE)&&!consoletogglekeydown&&debugmode){
console=1-console;
- if(!console)freeze=0;
if(console){
OPENAL_SetFrequency(OPENAL_ALL, 0.001);
+ } else {
+ freeze=0;
+ waiting=false;
}
consoletogglekeydown=1;
}
if(console)freeze=1;
if(console&&!Input::isKeyDown(SDLK_LMETA)){
- for(i=0;i<140;i++){
- if(Input::isKeyDown(i)){
- togglekeydelay[i]+=multiplier;
- if(togglekeydelay[i]>.4){
- togglekey[i]=0;
- togglekeydelay[i]=.36;
- }
- if(!togglekey[i]){
- if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
- for(j=255;j>=consoleselected+1;j--){
- consoletext[0][j]=consoletext[0][j-1];
- }
- consoletext[0][consoleselected]=KeyToSingleChar(i);
- if(Input::isKeyDown(SDLK_LSHIFT))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
- consoleselected++;
- consolechars[0]++;
- }
- else if(i==SDLK_RETURN){
- for(j=255;j>=consoleselected+1;j--){
- consoletext[0][j]=consoletext[0][j-1];
- }
- consoletext[0][consoleselected]='\n';
- consoleselected++;
- consolechars[0]++;
- }
- if(i==SDLK_DELETE&&consoleselected!=0){
- for(j=consoleselected-1;j<255;j++){
- consoletext[0][j]=consoletext[0][j+1];
- }
- consoletext[0][255]=' ';
- consoleselected--;
- consolechars[0]--;
- }
- if(i==SDLK_UP){
- if(archiveselected<14)archiveselected++;
- for(j=0;j<255;j++){
- consolechars[0]=consolechars[archiveselected];
- consoletext[0][j]=consoletext[archiveselected][j];
- consoleselected=consolechars[0];
- }
- }
- if(i==SDLK_DOWN){
- if(archiveselected>0)archiveselected--;
- for(j=0;j<255;j++){
- consolechars[0]=consolechars[archiveselected];
- consoletext[0][j]=consoletext[archiveselected][j];
- consoleselected=consolechars[0];
- }
- }
- if(i==SDLK_LEFT&&consoleselected!=0){
- consoleselected--;
- }
- if(i==SDLK_RIGHT&&consoleselected<consolechars[0]){
- consoleselected++;
- }
- if(i==SDLK_RETURN){
- archiveselected=0;
- cmd_dispatch(this, consoletext[0]);
-
- if(consolechars[0]>0){
- for(k=14;k>=1;k--){
- for(j=0;j<255;j++){
- consoletext[k][j]=consoletext[k-1][j];
- }
- consolechars[k]=consolechars[k-1];
- }
- for(j=0;j<255;j++){
- consoletext[0][j]=' ';
- }
- consolechars[0]=0;
- consoleselected=0;
- }
+ inputText(consoletext[0],&consoleselected,&consolechars[0]);
+ if(!waiting) {
+ archiveselected=0;
+ cmd_dispatch(this, consoletext[0]);
+ if(consolechars[0]>0){
+
+ for(k=14;k>=1;k--){
+ for(j=0;j<255;j++){
+ consoletext[k][j]=consoletext[k-1][j];
}
+ consolechars[k]=consolechars[k-1];
}
- togglekey[i]=1;
- }
- else {
- togglekey[i]=0;
- togglekeydelay[i]=0;
+ for(j=0;j<255;j++){
+ consoletext[0][j]=' ';
+ }
+ consolechars[0]=0;
+ consoleselected=0;
}
}
}
return SDLK_LAST;
}
-
-char KeyToSingleChar(unsigned short which)
-{
- static int i;
-
- if(which==SDLK_a){
- return 'a';
- }
- if(which==SDLK_b){
- return 'b';
- }
- if(which==SDLK_c){
- return 'c';
- }
- if(which==SDLK_d){
- return 'd';
- }
- if(which==SDLK_e){
- return 'e';
- }
- if(which==SDLK_f){
- return 'f';
- }
- if(which==SDLK_g){
- return 'g';
- }
- if(which==SDLK_h){
- return 'h';
- }
- if(which==SDLK_i){
- return 'i';
- }
- if(which==SDLK_j){
- return 'j';
- }
- if(which==SDLK_k){
- return 'k';
- }
- if(which==SDLK_m){
- return 'm';
- }
- if(which==SDLK_n){
- return 'n';
- }
- if(which==SDLK_o){
- return 'o';
- }
- if(which==SDLK_p){
- return 'p';
- }
- if(which==SDLK_q){
- return 'q';
- }
- if(which==SDLK_s){
- return 's';
- }
- if(which==SDLK_u){
- return 'u';
- }
- if(which==SDLK_v){
- return 'v';
- }
- if(which==SDLK_x){
- return 'x';
- }
- if(which==SDLK_z){
- return 'z';
- }
- if(which==SDLK_KP1){
- return '1';
- }
- if(which==SDLK_KP2){
- return '2';
- }
- if(which==SDLK_KP3){
- return '3';
- }
- if(which==SDLK_KP4){
- return '4';
- }
- if(which==SDLK_KP5){
- return '5';
- }
- if(which==SDLK_KP6){
- return '6';
- }
- if(which==SDLK_KP7){
- return '7';
- }
- if(which==SDLK_KP8){
- return '8';
- }
- if(which==SDLK_KP9){
- return '9';
- }
- if(which==SDLK_KP0){
- return '0';
- }
- if(which==SDLK_1){
- return '1';
- }
- if(which==SDLK_2){
- return '2';
- }
- if(which==SDLK_3){
- return '3';
- }
- if(which==SDLK_4){
- return '4';
- }
- if(which==SDLK_5){
- return '5';
- }
- if(which==SDLK_6){
- return '6';
- }
- if(which==SDLK_7){
- return '7';
- }
- if(which==SDLK_8){
- return '8';
- }
- if(which==SDLK_9){
- return '9';
- }
- if(which==SDLK_0){
- return '0';
- }
- if(which==SDLK_SPACE){
- return ' ';
- }
- return '\0';
-}
-
-char Shift(char which)
-{
- static int i;
-
- if(which=='a'){
- return 'A';
- }
- if(which=='b'){
- return 'B';
- }
- if(which=='c'){
- return 'C';
- }
- if(which=='d'){
- return 'D';
- }
- if(which=='e'){
- return 'E';
- }
- if(which=='f'){
- return 'F';
- }
- if(which=='g'){
- return 'G';
- }
- if(which=='h'){
- return 'H';
- }
- if(which=='e'){
- return 'E';
- }
- if(which=='f'){
- return 'F';
- }
- if(which=='g'){
- return 'G';
- }
- if(which=='h'){
- return 'H';
- }
- if(which=='i'){
- return 'I';
- }
- if(which=='j'){
- return 'J';
- }
- if(which=='k'){
- return 'K';
- }
- if(which=='l'){
- return 'L';
- }
- if(which=='m'){
- return 'M';
- }
- if(which=='n'){
- return 'N';
- }
- if(which=='o'){
- return 'O';
- }
- if(which=='p'){
- return 'P';
- }
- if(which=='q'){
- return 'Q';
- }
- if(which=='r'){
- return 'R';
- }
- if(which=='s'){
- return 'S';
- }
- if(which=='t'){
- return 'T';
- }
- if(which=='u'){
- return 'U';
- }
- if(which=='v'){
- return 'V';
- }
- if(which=='w'){
- return 'W';
- }
- if(which=='x'){
- return 'X';
- }
- if(which=='y'){
- return 'Y';
- }
- if(which=='z'){
- return 'Z';
- }
- if(which=='1'){
- return '!';
- }
- if(which=='2'){
- return '@';
- }
- if(which=='3'){
- return '#';
- }
- if(which=='4'){
- return '$';
- }
- if(which=='5'){
- return '%';
- }
- if(which=='6'){
- return '^';
- }
- if(which=='7'){
- return '&';
- }
- if(which=='8'){
- return '*';
- }
- if(which=='9'){
- return '(';
- }
- if(which=='0'){
- return ')';
- }
- if(which=='-'){
- return '_';
- }
- if(which=='='){
- return '+';
- }
- if(which=='['){
- return '{';
- }
- if(which==']'){
- return '}';
- }
- if(which=='\\'){
- return '|';
- }
- if(which=='.'){
- return '>';
- }
- if(which==','){
- return '<';
- }
- if(which=='/'){
- return '?';
- }
- if(which==';'){
- return ':';
- }
- if(which=='\''){
- return '\"';
- }
- return which;
-}
void RefreshMouse(Point *mouseloc);
void DisposeMouse();
unsigned short CharToKey(const char* which);
-char KeyToSingleChar(unsigned short which);
-char Shift(char which);
Boolean Button();