示例#1
0
文件: messages.c 项目: lubing521/uTox
_Bool messages_mdown(MESSAGES *m)
{
    m->idown = MSG_IDX_MAX;
    if(m->iover != MSG_IDX_MAX) {
        MESSAGE *msg = m->data->data[m->iover];
        switch(msg->msg_type) {
        case MSG_TYPE_TEXT:
        case MSG_TYPE_ACTION_TEXT: {
            if(m->urlover != STRING_IDX_MAX) {
                m->urlmdown = 1;
            }

            m->data->istart = m->data->iend = m->idown = m->iover;
            m->data->start = m->data->end = m->down = m->over;
            m->select = 1;
            break;
        }

        case MSG_TYPE_IMAGE: {
            MSG_IMG *img = (void*)msg;
            if(m->over) {
                if(!img->zoom) {
                    img->zoom = 1;
                    message_updateheight(m, msg, m->data);
                } else {
                    m->idown = m->iover;
                }
            }
            break;
        }

        case MSG_TYPE_FILE: {
            MSG_FILE *file = (void*)msg;
            if(m->over == 0) {
                break;
            }

            switch(file->status) {
            case FILE_TRANSFER_STATUS_NONE: {
                if(!msg->author) {
                    if(m->over == 2) {
                        savefilerecv(m->data->id, file);
                    } else if(m->over == 1) {
                        //decline
                        tox_postmessage(TOX_FILE_INCOMING_CANCEL, m->data->id, file->filenumber, NULL);
                    }
                } else if(m->over == 1) {
                    //cancel
                    tox_postmessage(TOX_FILE_OUTGOING_CANCEL, m->data->id, file->filenumber, NULL);
                }


                break;
            }

            case FILE_TRANSFER_STATUS_ACTIVE: {
                if(m->over == 2) {
                    //pause
                    tox_postmessage((msg->author ? TOX_FILE_OUTGOING_PAUSE : TOX_FILE_INCOMING_PAUSE), m->data->id, file->filenumber, NULL);
                } else if(m->over == 1) {
                    //cancel
                    tox_postmessage((msg->author ? TOX_FILE_OUTGOING_CANCEL : TOX_FILE_INCOMING_CANCEL), m->data->id, file->filenumber, NULL);
                }
                break;
            }

            case FILE_TRANSFER_STATUS_PAUSED_US: {
                if(m->over == 2) {
                    //resume
                    tox_postmessage((msg->author ? TOX_FILE_OUTGOING_RESUME : TOX_FILE_INCOMING_RESUME), m->data->id, file->filenumber, NULL);
                } else if(m->over == 1) {
                    //cancel
                    tox_postmessage((msg->author ? TOX_FILE_OUTGOING_CANCEL : TOX_FILE_INCOMING_CANCEL), m->data->id, file->filenumber, NULL);
                }
                break;
            }

            case FILE_TRANSFER_STATUS_PAUSED_THEM:
            case FILE_TRANSFER_STATUS_BROKEN: {
                //cancel
                if(m->over == 1) {
                    tox_postmessage((msg->author ? TOX_FILE_OUTGOING_CANCEL : TOX_FILE_INCOMING_CANCEL), m->data->id, file->filenumber, NULL);
                }
                break;
            }

            case FILE_TRANSFER_STATUS_COMPLETED: {
                if(m->over) {
                    if(file->inline_png) {
                        savefiledata(file);
                    } else {
                        openurl(file->path);
                    }
                }
                break;
            }
            }
            break;
        }
        }

        return 1;
    } else {
        if(m->data->istart != m->data->iend || m->data->start != m->data->end) {
            m->data->istart = 0;
            m->data->iend = 0;
            m->data->start = 0;
            m->data->end = 0;
            return 1;
        }
    }

    return 0;
}
示例#2
0
void menu_option(unsigned char number)
{
  FILE *savefile;
  FILE *optionfile;
  char filename[12], savepos;
  char oldinv; //holds options.inverted when entering setup
  int move_count;
  struct postype pos, newpos;

  switch (number)
  {
	case 100: //avcount=avtotal/avcount;
				 if (g_path.move[0].f>0)
					showstats(nodes,g_seconds,g_depth,g_path); break;
	case 101: rival_help(70); break;
	case 119: rival_help(19); break;
	case 120: options.chessset++; if (options.chessset==3) options.chessset=0; break;
	case 109: options.whiteplayer=USER;
				 options.blackplayer=USER;
				 if (game.movenum>1)
				 {
					 game.movenum=game.movenum-1;
					 pos=game.firstpos;
					 for (move_count=1; move_count<=game.movenum; move_count++)
					 {
						  alter(&pos,game.previous_moves[move_count],&newpos);
						  pos=newpos;
					 }
					 current=newpos;
				 } else
				 {
					 game.movenum=0;
					 current=game.firstpos;
				 }
				 movepointer=game.movenum;
				 no_more_openings=FALSE;
				 break;
	case 110: if (game.lastmove==0)
				 {
					 current=game.firstpos;
				 } else
				 {
					 pos=game.firstpos;
					 for (move_count=1; move_count<=game.lastmove; move_count++)
					 {
						 alter(&pos, game.previous_moves[move_count], &newpos);
						 pos=newpos;
					 }
					 current=newpos;
				 }
				 game.movenum=game.lastmove;
				 movepointer=game.movenum;
				 break;
	case 111: current=game.firstpos; game.movenum=0;
				 movepointer=game.movenum;
				 no_more_openings=FALSE;
				 options.whiteplayer=USER;
				 options.blackplayer=USER;
				 break;
	case 112: if ((savepos=get_savepos('w'))!=0)
				 {
					 strcpy(filename,"RIVAL\0");
					 if (savepos<10)
					 {
						 filename[5]=savepos+48;
						 filename[6]='\0';
					 } else
					 {
						 filename[5]=savepos/10+48;
						 filename[6]=savepos%10+48;
						 filename[7]='\0';
					 }
					 strcat(filename,".SAV");
					 if (confirmation("SAVE GAME"))
					 {
						 savefile=fopen(filename,"w");
						 if (savefile!=NULL)
						 {
							  savefiledata(savefile);
						 } else // if savefile!=NULL
						 {
							  printf("ERROR! SAVE FAILED");
						 }
						 fclose(savefile);
					 } // if confirmation
				 }
				 break;
	case 113: if ((savepos=get_savepos('r'))!=0)
		  {
		     strcpy(filename,"RIVAL\0");
		     if (savepos<10)
		     {
			filename[5]=savepos+48;
			filename[6]='\0';
		     } else
		     {
			filename[5]=savepos/10+48;
			filename[6]=savepos%10+48;
			filename[7]='\0';
		     }
		     strcat(filename, ".SAV");
		     if (((savefile=fopen(filename,"r"))!=NULL) && (confirmation("LOAD GAME")))
		     {
			readfiledata(savefile);
			if (game.movenum==0)
			{
			   current=game.firstpos;
			   movepointer=0;
			} else
			{
			   pos=game.firstpos;
			   for (move_count=1; move_count<=game.movenum; move_count++)
			   {
			     alter(&pos, game.previous_moves[move_count], &newpos);
			     pos=newpos;
			   }
			   current=newpos;
			}
			FLAGnewstart=1;
			movepointer=game.movenum;
		     } //movepointer=game.movenum;
		     fclose(savefile);
		  }
		  break;
	case 107: variant_select(); break;
	case 106: time_select(); break;
	case 127: options.deep_thought=!options.deep_thought; break;
	case 133: break;
	case 118: options.library=!options.library; break;
	case 108: if (game.movenum<game.lastmove)
				 {
					 game.movenum=game.movenum+1;
					 pos=current;
					 alter(&pos,game.previous_moves[game.movenum],&current);
				 }
				 movepointer=game.movenum;
				 break;
	case 103: oldinv=options.inverted;
		  options.inverted=0;
		  enter_setup();
		  options.inverted=oldinv;
		  break;
	case 117: options.analysis=!options.analysis; break;
	case 102: options.inverted=!options.inverted; break;
	case 104: options.whiteplayer=!options.whiteplayer;
				 if (options.whiteplayer==PROGRAM)
					  if (current.mvr=='w')
						  FLAGnewstart=1;
				 break;
	case 105: options.blackplayer=!options.blackplayer;
				 if (options.blackplayer==PROGRAM)
					  if (current.mvr=='b')
						  FLAGnewstart=1;
				 break;
	case 114: if (confirmation("NEW GAME")) initialise(startbrd); no_more_openings=FALSE; break;
	case 115: iconmenu=1; break;
	case 116: iconmenu=0; break;
	case 129: switch (options.sensitivity)
				 {
					 case LOWSENS : options.sensitivity=MEDSENS; break;
					 case MEDSENS : options.sensitivity=HISENS; break;
					 case  HISENS : options.sensitivity=LOWSENS; break;
				 }
				 break;
	case 124: options=doptions; break;
	case 125: optionfile=fopen("options.riv","w");
				 fwrite(&options, sizeof(struct optiontype), 1, optionfile);
				 fclose(optionfile);
				 break;
	case 121: if (options.so<7) options.so+=1; else options.so=0; break;
	case 122: if (options.wo<35) options.wo+=5; else options.wo=0;
				 if (options.wo==options.bo) if (options.wo<35) options.wo+=5; else options.wo=0;
				 break;
	case 123: if (options.bo<35) options.bo+=5; else options.bo=0;
				 if (options.wo==options.bo) if (options.bo<35) options.bo+=5; else options.bo=0;
				 break;
	case 128: solvey(); break;
	case 130: break;
	case 148: options.game=0; break;
	case 126: options.pieceslide=!options.pieceslide; break;
	case 131: if (confirmation("QUIT RIVAL"))
				 {
					 SetTextMode();
					 printf("See you later!");
					 quit=1;
				 }
				 break;
	case 200: if (movepointer>0) movepointer--; break;
	case 201: if (movepointer<game.movenum) movepointer++; break;
	default: break;
  }
}