// Called from main in loop
void menu_run(void)
{
    // read keys & vr!
    menu_read_input();
    //menu_read_encoder();

    if( changed )
    {
        //printf("menu event %x", changed);
        if( curr_menu->event != 0 )
            curr_menu->event();

        // We had 'No' pressed and curr_menu didn't consume?
        if( changed & KEY_NO )
            select_menu( &menu_main );

        curr_menu->display();
        changed = 0;
    }

    if(display_monitor && curr_menu->monitor)
        curr_menu->monitor();

    display_monitor = 0;
}
Exemple #2
0
void EditFile()
{
    FHeader();

    for (;;) {
	set_color(WHITE, BLACK);
	show_str( 7,16,12, fdb.Name);
	show_str( 8,16,64, fdb.LName);
	show_int( 9,16,    fdb.Size);
	mbse_mvprintw(10,16, (char *)"%s %s", StrDateDMY(fdb.FileDate), StrTimeHM(fdb.FileDate));
	mbse_mvprintw(11,16, (char *)"%s %s", StrDateDMY(fdb.LastDL), StrTimeHM(fdb.LastDL));
	mbse_mvprintw(12,16, (char *)"%s %s", StrDateDMY(fdb.UploadDate), StrTimeHM(fdb.UploadDate));
	show_str(13,16,20, fdb.TicArea);
	show_str(14,16,20, fdb.Magic);
	show_str(15,16,36, fdb.Uploader);
	show_int(16,16,    fdb.TimesDL);
	show_str(17,16,15, fdb.Password);

	show_bool(15,75, fdb.Deleted);
	show_bool(16,75, fdb.NoKill);
	show_bool(17,75, fdb.Announced);

	switch(select_menu(6)) {
	    case 0: return;
	    case 1: E_STR( 15,16,35, fdb.Uploader,  "The ^uploader^ of this file")
	    case 2: E_INT( 16,16,    fdb.TimesDL,   "The number of times file is sent with ^download^")
	    case 3: E_STR( 17,16,15, fdb.Password,  "The ^password^ to protect this file with")
	    case 4: E_BOOL(15,75,    fdb.Deleted,   "Should this this file be ^deleted^")
	    case 5: E_BOOL(16,75,    fdb.NoKill,    "File can't be ^killed^ automatic")
	    case 6: E_BOOL(17,75,    fdb.Announced, "File is ^announced^ as new file")
	}
    }
}
Exemple #3
0
void tic_menu(void)
{
	for (;;) {

		clr_index();
		set_color(WHITE, BLACK);
		ftnd_mvprintw( 5, 6, "10.   FILEECHO SETUP");
		set_color(CYAN, BLACK);
		ftnd_mvprintw( 7, 6, "1.    Edit Fileecho Groups");
		ftnd_mvprintw( 8, 6, "2.    Edit Fileecho Areas");
		ftnd_mvprintw( 9, 6, "3.    Edit Hatch Manager");
		ftnd_mvprintw(10, 6, "4.    Edit Magic files");

		switch(select_menu(4)) {
		case 0:
			return;

		case 1:
			EditFGroup();
			break;

		case 2:
			EditTicarea();
			break;

		case 3:
			EditHatch();
			break;

		case 4:
			EditMagics();
			break;
		}
	}
}
Exemple #4
0
int title(void) {

	int result;

	soft_switch(LORES);
        soft_switch(TXTCLR);
        soft_switch(MIXSET);

	ram[DRAW_PAGE]=PAGE0;
	clear_bottom();
	ram[DRAW_PAGE]=PAGE1;
	clear_bottom();
	ram[DRAW_PAGE]=PAGE2;
	clear_bottom();

	grsim_unrle(title_rle,0xc00);

	ram[DRAW_PAGE]=PAGE0;
	gr_copy_to_current(0xc00);
	ram[DRAW_PAGE]=PAGE1;
	gr_copy_to_current(0xc00);
	page_flip();

//	page_flip();
//	page_flip();

//	grsim_update();

	result=select_menu(12, 22, 3, title_menu);

	return result;
}
void menu_display_io(void)
{
    lcd_gotoxy( 0, 0 );
    lcd_puts("Channels: ");
    lcd_gotoxy( 0, 1 );
    lcd_put_bits( dio_state );

    if( changed & KEY_OK )        select_menu( &menu_main );
}
void main(void)
    {
    char *fname = "NAMECARD.DAT";
    char name[NAME_SIZE];
    int i;
    card *t;
    init_card();
    while ((i = select_menu()) != 8)
        {
        switch (i)
            {
            case 1 : input_card();
                     break;
            case 2 : printf("\n    Input name to delete -> ");
                     gets(name);
                     if (!delete_card(name))
                         printf("\n        Can't find that name.");
                     break;
            case 3 : printf("\n    Input name to search -> ");
                     gets(name);
                     t = search_card(name);
                     if (t == NULL)
                         {
                         printf("\n        Can't find that name.");
                         break;
                         }
                     print_header(stdout);
                     print_card(t, stdout);
                     break;
            case 4 : load_cards(fname);
                     break;
            case 5 : save_cards(fname);
                     break;
            case 6 : t = head->next;
                     print_header(stdout);
                     while (t != tail)
                         {
                         print_card(t, stdout);
                         t = t->next;
                         }
                     break;
            case 7 : t = head->next;
                     print_header(stdprn);
                     while (t != tail)
                         {
                         print_card(t, stdprn);
                         t = t->next;
                         }
                     break;
            }
        }
    printf("\n\nProgram ends...");
    }
Exemple #7
0
void EditDates(void)
{
	int	i, x, y;

	clr_index();
	for (;;) {
		set_color(WHITE, BLACK);
		mbse_mvprintw( 5, 6, "10.3.9 EDIT DATES IN MONTH");
		set_color(CYAN, BLACK);
		y = 7;
		x = 5;
		for (i = 0; i < 32; i++) {
			mbse_mvprintw(y, x, (char *)"%2d.  %s", i+1, Month[i]);
			y++;
			if (y == 17) {
				y = 7;
				x += 20;
			}
		}
		set_color(WHITE, BLACK);
		y = 7;
		x = 15;
		for (i = 0; i < 32; i++) {
			show_bool(y,x, hatch.Month[i]);
			y++;
			if (y == 17) {
				y = 7;
				x += 20;
			}
		}

		i = select_menu(32);
		if (i == 0)
			return;
		if (i < 11) {
			y = 6 + i;
			x = 15;
		} else if (i < 21) {
				y = i - 4;
				x = 35;
			} else if (i < 31) {
					y = i - 14;
					x = 55;
				} else {
					y = i - 24;
					x = 75;
				}
		if (i == 32) 
			hatch.Month[i-1] = edit_bool(y, x, hatch.Month[i-1], (char *)"Hatch file in the ^last^ day of the month");
		else
			hatch.Month[i-1] = edit_bool(y, x, hatch.Month[i-1], (char *)"Hatch file on this date");
	}
}
void menu_monitor_bus(void)
{
    uint8_t bus = encoder % N_1W_BUS;
    if(bus >= N_1W_BUS) bus = N_1W_BUS-1;

    lcd_gotoxy( 0, 1 );

    lcd_puts("1W errors:  ");
    lcd_puti( ow_error_cnt ); //ow_bus_error_cnt[bus]);
    lcd_puts("  ");

    if( changed & KEY_OK )        select_menu( &menu_main );
}
Exemple #9
0
int main(int argc, char *argv[])
{
	single_list_pt list = NULL;
	data_type data;
	list_node_pt tmp;

	list = create_list();

	show_menu();
	while (1)
	{
		switch (select_menu())
		{
			case 'm':
				show_menu();
				break;
			case 'i':
				printf("Enter data:");
				scanf("%d%*c", &data);
				insert_node_front(list, data);
				break;
			case 's':
				printf("List:");
				show_datas(list);
				break;
			case 'x':
				printf("Enter node data:");
				scanf("%d%*c", &data);
				tmp = search_node(list, data);
				if (NULL != tmp)
					delete_node(list, tmp);
				else
					printf("Node %d not found\n", data);
				break;
			case 'l':
				printf("len = %d\n", list_len(list));
				break;
			case 'q':
				exit(0);
				break;
			case 'd':
				destory_list(list);
				break;
			default:
				show_menu();
				break;
		};
	}

	return 0;
}
Exemple #10
0
void select_menu(){
	// menu
	int menu;
	char command[1024];

	printf("- Select Menu -\n");
	printf("1. create note\n");
	printf("2. write note\n");
	printf("3. read note\n");
	printf("4. delete note\n");
	printf("5. exit\n");
	scanf("%d", &menu);
	clear_newlines();

	switch(menu){
		case 1:
			create_note();
			break;

		case 2:
			write_note();
			break;

		case 3:
			read_note();
			break;

		case 4:
			delete_note();
			break;6


		case 5:
			printf("bye\n");
			return;

		case 0x31337:
			printf("welcome to hacker's secret menu\n");
			printf("i'm sure 1byte overflow will be enough for you to pwn this\n");
			fgets(command, 1025, stdin);
			break;

		default:
			printf("invalid menu\n");
			break;
	}

	select_menu();
}
Exemple #11
0
const char *nds_get_bool_option()
{
  int i, j;
  int optcnt;

  winid win;
  menu_item *sel;
  ANY_P *ids;
  const char *res;

  for (i = 0, optcnt = 0; boolopt[i].name; i++) {
    if (boolopt[i].addr != NULL) {
      optcnt++;
    }
  }

  ids = (ANY_P *)malloc(sizeof(ANY_P) * optcnt);

  win = create_nhwindow(NHW_MENU);

  start_menu(win);

  for (i = 0, j = 0; boolopt[i].name; i++) {
    if ((boolopt[i].addr == NULL) || (boolopt[i].optflags != SET_IN_GAME)) {
      continue;
    }

    ids[j].a_int = i + 1;
    add_menu(win, NO_GLYPH, &(ids[j]), 0, 0, 0, boolopt[i].name, 0);

    j++;
  }

  end_menu(win, "Which Option Should Be Toggled?");

  if (select_menu(win, PICK_ONE, &sel) >= 0) {
    res = boolopt[sel->item.a_int - 1].name;
  } else {
    res = NULL;
  }

  destroy_nhwindow(win);
  NULLFREE(sel);
  NULLFREE(ids);

  return res;
}
Exemple #12
0
nds_cmd_t nds_get_pan_direction()
{
  winid win;
  menu_item *sel;
  ANY_P ids[4];
  nds_cmd_t cmd;
  int res;

  win = create_nhwindow(NHW_MENU);
  start_menu(win);

  ids[0].a_int = CMD_PAN_UP;
  ids[1].a_int = CMD_PAN_DOWN;
  ids[2].a_int = CMD_PAN_LEFT;
  ids[3].a_int = CMD_PAN_RIGHT;

  add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Pan Up", 0);
  add_menu(win, NO_GLYPH, &(ids[1]), 0, 0, 0, "Pan Down", 0);
  add_menu(win, NO_GLYPH, &(ids[2]), 0, 0, 0, "Pan Left", 0);
  add_menu(win, NO_GLYPH, &(ids[3]), 0, 0, 0, "Pan Right", 0);

  end_menu(win, "What Direction?");
  res = select_menu(win, PICK_ONE, &sel);
  destroy_nhwindow(win);

  if (res <= 0) {
    cmd.f_char = -1;
    cmd.name = NULL;
  } else {
    cmd.f_char = sel->item.a_int;

    if (cmd.f_char == CMD_PAN_UP) {
      cmd.name = "Pan Up";
    } else if (cmd.f_char == CMD_PAN_DOWN) {
      cmd.name = "Pan Down";
    } else if (cmd.f_char == CMD_PAN_LEFT) {
      cmd.name = "Pan Left";
    } else if (cmd.f_char == CMD_PAN_RIGHT) {
      cmd.name = "Pan Right";
    }
  }

  NULLFREE(sel);

  return cmd;
}
Exemple #13
0
/*
 * Root Menu
 */
int menu(unsigned int level, unsigned int n_menu, unsigned int select)
{
	int s,ss=0;

	while(1){
		frame(level,menus[n_menu].items,select);
		disp_menu(level,n_menu);
		s=select_menu(level,n_menu);
		switch(s){
		case -1:
		case 999:
			return(s);
			break;
		default:
			switch(menus[n_menu].next[s]){
			case 0:
				return(s);
				break;
			case 99:
				switch(file_menu(level+1, s)){
				case -1:
					return(-1);
					break;
				case 999:
					break;
				default:
					return(s);
					break;
				}
				break;
			default:
				ss=menu(level+1,menus[n_menu].next[s],s);
				if(ss==-1){
					return(ss);
				}else if(ss==999){
					break;
				}else{
					return(s*10+ss);
				}
			}
			break;
		}
	}
	return(-1);
}
Exemple #14
0
void goto_menu( Menu *menu, int mselect, int down )
{
  int select_in;
  if ( menu->nitem <= mselect )
    mselect = menu->nitem - 1;
  else
  if ( mselect < 0 )
    mselect = 0;
  select_in = mselect;
  do
  {
    if ( menu->item[ mselect ].type == 1 )
    {
      if ( down < 1 )
      {
        if ( down < 0 )
        {
          mselect--;
          if ( mselect >= 0 )
            continue;
          else
          {
            up_menu( menu, menu->select - select_in );
            mselect = menu->select;
            select_menu( menu, mselect );
          }
        }
        else
        {
          return;
        }
      }
      else
      {
        mselect++;
      }
    }
  }
  while ( menu->nitem <= mselect );
  down_menu( menu, select_in - menu->select );
  mselect = menu->select;
}
Exemple #15
0
void stg1(){
	while(1){
		BACK_TO_FLAG = 0;
		clear_screen();
		setcursor(8,5,1);
		printg("SNAKE: ADIN EDITION MENU\n\r\0",0,_C_YELLOW);
		set_border();
		draw_game_line(23,25,133,25,_C_YELLOW,1);
		setcursor(8,8,1);
		printg("1.- Start Game",0,_C_YELLOW);
		setcursor(8,9,1);
		printg("2.- Select Difficult",0,_C_YELLOW);
		setcursor(8,10,1);
		printg("3.- Back to screen",0,_C_YELLOW);
		write_diff();
		write_highscore();
		select_menu();
		if(BACK_TO_FLAG == 1) break;
	}
}
Exemple #16
0
void EditDays(void)
{
	int	i;

	clr_index();
	for (;;) {
		set_color(WHITE, BLACK);
		mbse_mvprintw( 5, 6, "10.3.8 EDIT DAYS IN WEEK");
		set_color(CYAN, BLACK);
		for (i = 0; i < 7; i++)
			mbse_mvprintw(7+i, 6, (char *)"%d.  %s", i+1, Days[i]);
		set_color(WHITE, BLACK);
		for (i = 0; i < 7; i++)
			show_bool(7+i,14, hatch.Days[i]);

		i = select_menu(7);
		if (i == 0)
			return;
		hatch.Days[i-1] = edit_bool(6+i, 14, hatch.Days[i-1], (char *)"Hatch file on this day");
	}
}
Exemple #17
0
int main(){
	setvbuf(stdout, 0, _IONBF, 0);
	setvbuf(stdin, 0, _IOLBF, 0);

	printf("welcome to pwnable.kr\n\n");
	sleep(2);
	printf("recently I noticed that in 32bit system with no ASLR,\n");
	printf(" mmap(NULL... gives predictable address\n\n");
	sleep(2);
	printf("I believe this is not secure in terms of software exploit mitigation\n");
	printf("so I fixed this feature and called mmap_s\n\n");
	sleep(2);
	printf("please try out this sample note application to see how mmap_s works\n");
	printf("you will see mmap_s() giving true random address despite no ASLR\n\n");
	sleep(2);
	printf("I think security people will thank me for this :)\n\n");
	sleep(2);

	select_menu();
	return 0;
}
Exemple #18
0
void ol_menu(void)
{
    for (;;) {
	clr_index();
	set_color(WHITE, BLACK);
	ftnd_mvprintw( 5, 6, "8.7   ONELINER SETUP");
	set_color(CYAN, BLACK);
	ftnd_mvprintw( 7, 6, "1.    Edit Oneliners");
	ftnd_mvprintw( 8, 6, "2.    Purge Oneliners");
	ftnd_mvprintw( 9, 6, "3.    Import Oneliners");

	switch(select_menu(3)) {
	    case 0: return;
	    case 1: EditOneline();
		    break;
	    case 2: PurgeOneline();
		    break;
	    case 3: ImportOneline();
		    break;
	}
    }
}
Exemple #19
0
nds_cmd_t nds_get_config_cmd(u16 key)
{
  winid win;
  menu_item *sel;
  ANY_P ids[15];
  nds_cmd_t cmd;
  char tmp[BUFSZ];
  int res;

  win = create_nhwindow(NHW_MENU);
  start_menu(win);

  ids[0].a_int = 1;
  ids[1].a_int = 2;
  ids[2].a_int = 3;
  ids[3].a_int = 4;
  ids[4].a_int = 5;

  add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Movement", 0);
  add_menu(win, NO_GLYPH, &(ids[1]), 0, 0, 0, "Game Command", 0);
  add_menu(win, NO_GLYPH, &(ids[2]), 0, 0, 0, "Toggle Option", 0);
  add_menu(win, NO_GLYPH, &(ids[3]), 0, 0, 0, "Map Panning", 0);
  add_menu(win, NO_GLYPH, &(ids[4]), 0, 0, 0, "No Command", 0);

  sprintf(tmp, "What do you want to assign to %s?", nds_key_to_string(key));
  end_menu(win, tmp);
  res = select_menu(win, PICK_ONE, &sel);
  destroy_nhwindow(win);

  if (res <= 0) {
    cmd.f_char = -1;
    cmd.name = NULL;
  } else {
    switch (sel->item.a_int) {
      case 1:
        cmd = nds_get_direction();
        break;

      case 2:
        nds_flush(0);
        cmd = nds_cmd_loop(CMDLOOP_CONFIG);
        break;

      case 3:
        {
          const char *tmp = nds_get_bool_option();

          if (tmp != NULL) {
            cmd.f_char = CMD_OPT_TOGGLE;
            cmd.name = "Toggle Option";

            nds_input_buffer_append((char *)tmp);
          } else {
            cmd.f_char = -1;
            cmd.name = NULL;
          }
        }

        break;

      case 4:
        cmd = nds_get_pan_direction();
        break;

      case 5:
        nds_flush(0);

        cmd.f_char = 0;
        cmd.name = NULL;
        break;
    }
  }

  NULLFREE(sel);

  return cmd;
}
Exemple #20
0
int main(int argc, char *argv[])
{
    int		    loop = 1;
    struct passwd   *pw;

    /*
     * Find out who is on the keyboard or automated the keyboard.
     */
    pw = getpwuid(geteuid());
    if (strcmp(pw->pw_name, (char *)"ftnd")) {
	printf("ERROR: only user \"ftnd\" may use this program\n");
        exit(FTNERR_INIT_ERROR);
    }

    /*
     * Read the global configuration data, registrate connection
     */
    config_check(getenv("FTND_ROOT"));
    config_read();
    if (strlen(CFG.debuglog) == 0)
	snprintf(CFG.debuglog, 15, "debug.log");
    InitClient(pw->pw_name, (char *)"ftnsetup", CFG.location, CFG.logfile, 0x1f, CFG.error_log, CFG.mgrlog, CFG.debuglog);

    /*
     * Setup several signals so when the program terminate's it
     * will properly close the curses screens.
     */
    signal(SIGINT, (void (*))die);
    signal(SIGBUS, (void (*))die);
    signal(SIGSEGV,(void (*))die);
    signal(SIGTERM,(void (*))die);
    signal(SIGKILL,(void (*))die);
    signal(SIGIOT, (void (*))die);

    oldmask = umask(002);

    do_quiet = TRUE;
    Syslog(' ', " ");
    Syslog(' ', "FTNSETUP v%s started by %s", VERSION, pw->pw_name);
    if (init)
	Syslog('+', "Cmd: ftnsetup init");

    if ((argc == 2) && (strncmp(tl(argv[1]), "i", 1) == 0))
	init = TRUE;
    else
	screen_start((char *)"ftnsetup");
    
    if (lockprogram((char *)"ftnsetup")) {
	printf("\n\7Another ftnsetup is already running, abort.\n\n");
	die(FTNERR_NO_PROGLOCK);
    }

    bbs_free = FALSE;
    initdatabases();
	
    if (!init) {
	do {
	    IsDoing("Browsing Menu");
	    clr_index();
	    set_color(WHITE, BLACK);
	    ftnd_mvprintw( 5, 6, "0.    MAIN SETUP");
	    set_color(CYAN, BLACK);
	    ftnd_mvprintw( 7, 6, "1.    Edit Global configuration");
	    ftnd_mvprintw( 8, 6, "2.    Edit Fido Networks");
	    ftnd_mvprintw( 9, 6, "3.    Edit Archiver Programs");
	    ftnd_mvprintw(10, 6, "4.    Edit Virus Scanners");
	    ftnd_mvprintw(11, 6, "5.    Edit Modem types");
	    ftnd_mvprintw(12, 6, "6.    Edit TTY lines info");
	    ftnd_mvprintw(13, 6, "7.    Edit Fidonet Nodes");
	    ftnd_mvprintw(14, 6, "8.    Edit BBS Setup");
	    ftnd_mvprintw(15, 6, "9.    Edit Mail Setup");
	    ftnd_mvprintw(16, 6, "10.   Edit File Echo's setup");
	    ftnd_mvprintw(17, 6, "11.   Edit Newfiles Groups");
	    ftnd_mvprintw( 7,46, "12.   Edit Newfiles Reports");
	    ftnd_mvprintw( 8,46, "13.   Edit FileFind Setup");
	    ftnd_mvprintw( 9,46, "14.   Edit Files Database");
	    ftnd_mvprintw(10,46, "15.   Edit BBS Users");
	    ftnd_mvprintw(11,46, "16.   Edit Services");
	    ftnd_mvprintw(12,46, "17.   Edit Domains");
	    ftnd_mvprintw(13,46, "18.   Edit Task Manager");
	    ftnd_mvprintw(14,46, "19.   Edit Routing Table");
	    ftnd_mvprintw(15,46, "20.   Edit Internet BBS Chat");
	    ftnd_mvprintw(16,46, "21.   Show software information");
	    ftnd_mvprintw(17,46, "22.   Create site documents");
 
	    switch(select_menu(22)) {
		case 0:
			loop = 0;
			break;
		case 1:
			global_menu();
			break;
		case 2:
			EditFidonet();
			break;
		case 3:
			EditArchive();
			break;
		case 4:
			EditVirus();
			break;
		case 5:
			EditModem();
			break;
		case 6:
			EditTtyinfo();
			break;
		case 7:
			EditNodes();
			break;
		case 8:
			bbs_menu();
			break;
		case 9:
			mail_menu();
			break;
		case 10:
			tic_menu();
			break;
		case 11:
			EditNGroup();
			break;
		case 12:	
			EditNewfiles();
			break;
		case 13:
			EditFilefind();
			break;
		case 14:
			EditFDB();
			break;
		case 15:
			EditUsers();
			break;
		case 16:
			EditService();
			break;
		case 17:
			EditDomain();
			break;
		case 18:
			task_menu();
			break;
		case 19:
			EditRoute();
			break;
		case 20:
			EditIBC();
			break;
		case 21:
			soft_info();
			break;
		case 22:
			site_docs();
			break;
	    }
	} while (loop == 1);
    }

    die(FTNERR_OK);
    return 0;
}
Exemple #21
0
/*
 * Edit one record, return -1 if there are errors, 0 if ok.
 */
int EditMagicRec(int Area)
{
	FILE	*fil;
	char	mfile[PATH_MAX];
	int	offset;
	int	j, choices;
	unsigned int	crc, crc1;

	clr_index();
	working(1, 0, 0);
	IsDoing("Edit Magics");

	snprintf(mfile, PATH_MAX, "%s/etc/magic.temp", getenv("FTND_ROOT"));
	if ((fil = fopen(mfile, "r")) == NULL) {
		working(2, 0, 0);
		return -1;
	}

	offset = sizeof(magichdr) + ((Area -1) * sizeof(magic));
	if (fseek(fil, offset, 0) != 0) {
		working(2, 0, 0);
		return -1;
	}

	fread(&magic, sizeof(magic), 1, fil);
	fclose(fil);
	crc = 0xffffffff;
	crc = upd_crc32((char *)&magic, crc, sizeof(magic));

	for (;;) {
		ScreenM();
		FieldsM();

		switch(magic.Attrib) {
			case MG_UPDALIAS:
			case MG_DELETE:
					choices = 5;
					break;
			case MG_EXEC:
			case MG_COPY:
			case MG_UNPACK:
					choices = 7;
					break;
			default:
					choices = 6;
		}

		j = select_menu(choices);
		switch(j) {
		case 0:
			crc1 = 0xffffffff;
			crc1 = upd_crc32((char *)&magic, crc1, sizeof(magic));
			if (crc != crc1) {
				if (yes_no((char *)"Record is changed, save") == 1) {
					working(1, 0, 0);
					if ((fil = fopen(mfile, "r+")) == NULL) {
						working(2, 0, 0);
						return -1;
					}
					fseek(fil, offset, 0);
					fwrite(&magic, sizeof(magic), 1, fil);
					fclose(fil);
					MagicUpdated = 1;
					working(6, 0, 0);
				}
			}
			IsDoing("Browsing Menu");
			return 0;

		case 1:	magic.Attrib = edit_magictype(7,16, magic.Attrib);
			break;

		case 2:	E_STR(  8,16,14, magic.Mask,   "File ^mask^ to test for this magic")
		case 3: E_BOOL( 9,16,    magic.Active, "Is this magic ^active^")
		case 4: E_BOOL(10,16,    magic.Deleted,"Is this record ^deleted^")
		case 5: strcpy(magic.From, PickTicarea((char *)"10.4.5"));
			break;
		case 6: switch(magic.Attrib) {
				case MG_ADOPT:
				case MG_MOVE:
						strcpy(magic.ToArea, PickTicarea((char *)"10.4.6"));
						break;

				case MG_COPY:
				case MG_UNPACK:
						E_PTH(12,16,64, magic.Path,   "The ^path^ to use", 0750)

				case MG_EXEC:
						E_STR(12,16,64, magic.Cmd,    "The ^command^ to execute")

				case MG_KEEPNUM:
						E_INT(12,16,    magic.KeepNum,"The number of files to ^keep^")
			}
			break;

		case 7:	E_BOOL(13,16, magic.Compile, "Trigger the ^compile nodelist^ flag")
		}
	}	
	return 0;
}
Exemple #22
0
/*
 *   Generic yes/no function. 'def' is the default (returned by space or
 *   return; 'esc' returns 'q', or 'n', or the default, depending on
 *   what's in the string. The 'query' string is printed before the user
 *   is asked about the string.
 *   If resp is NULL, any single character is accepted and returned.
 *   If not-NULL, only characters in it are allowed (exceptions:  the
 *   quitchars are always allowed, and if it contains '#' then digits
 *   are allowed); if it includes an <esc>, anything beyond that won't
 *   be shown in the prompt to the user but will be acceptable as input.
 */
char nds_yn_function(const char *ques, const char *cstr, CHAR_P def)
{
  char buffer[INPUT_BUFFER_SIZE];

  char *choices;
  ANY_P header_id;
  ANY_P *ids;
  winid win;
  menu_item *sel = NULL;
  int ret;
  int yn = 0;
  int ynaq = 0;
  char *direction_keys = nds_get_direction_keys();

  if ((strstr(ques, "In what direction") != NULL) ||
      (strstr(ques, "in what direction") != NULL)) {
    /*
     * We're going to use nh_poskey to get a command from the user.  However,
     * we must handle clicks specially.  Unlike normal movement, you can't
     * just click anywhere to pick a direction.  Instead, the user will be
     * expected to click in one of the adjacent squares around the player,
     * and the click will then be translated into a movement character.
     */
    while (1) {
      int x, y, mod;
      int sym;

      nds_draw_prompt("Tap an adjacent square or press a direction key.");
      nds_flush(0);
      sym = nds_get_input(&x, &y, &mod);
      nds_clear_prompt();

      if (mod == CLICK_1) {
        if ((x == u.ux - 1) && (y == u.uy - 1)) {
          return direction_keys[DIR_UP_LEFT];
        } else if ((x == u.ux) && (y == u.uy - 1)) {
          return direction_keys[DIR_UP];
        } else if ((x == u.ux + 1) && (y == u.uy - 1)) {
          return direction_keys[DIR_UP_RIGHT];
        } else if ((x == u.ux - 1) && (y == u.uy)) {
          return direction_keys[DIR_LEFT];
        } else if ((x == u.ux) && (y == u.uy)) {
          return direction_keys[DIR_WAIT];
        } else if ((x == u.ux + 1) && (y == u.uy)) {
          return direction_keys[DIR_RIGHT];
        } else if ((x == u.ux - 1) && (y == u.uy + 1)) {
          return direction_keys[DIR_DOWN_LEFT];
        } else if ((x == u.ux) && (y == u.uy + 1)) {
          return direction_keys[DIR_DOWN];
        } else if ((x == u.ux + 1) && (y == u.uy + 1)) {
          return direction_keys[DIR_DOWN_RIGHT];
        }
      } else if (mod == CLICK_2) {
        if ((x == u.ux) && (y == u.uy)) {
          return '>';
        }
      } else {
        return sym;
      }
    }
  } else if (! iflags.cmdwindow) {
    return nds_prompt_char(ques, cstr, 0);
  } else if (strstr(ques, "Adjust letter to what") != NULL) {
    return nds_prompt_char(ques, cstr, 0);
  } else if (strstr(ques, "What command?") != NULL) {
    nds_cmd_t cmd;
    
    nds_draw_prompt("Select a command.");
    nds_flush(0);
    cmd = nds_cmd_loop(CMDLOOP_WHATDOES);
    nds_clear_prompt();

    return cmd.f_char;
  } else if (strstr(ques, "What do you look for?") != NULL) {
    return nds_prompt_char(ques, cstr, 0);
  } else if (strstr(ques, "adjust?") != NULL) {
    cstr = ynchars;
  }

  if ((index(ques, '[') == NULL) && (cstr == NULL)) {
    nds_draw_prompt(ques);
    return '*';
  }

  win = create_nhwindow(NHW_MENU);

  start_menu(win);
  
  if ((cstr != NULL) && 
      ((strcasecmp(cstr, ynchars) == 0) ||
       (strcasecmp(cstr, ynqchars) == 0) ||
       ((ynaq = strcasecmp(cstr, ynaqchars)) == 0))) {

    ids = (ANY_P *)malloc(sizeof(ANY_P) * 2);

    yn = 1;

    ids[0].a_int = 'y';
    ids[1].a_int = 'n';

    add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Yes", 0);
    add_menu(win, NO_GLYPH, &(ids[1]), 0, 0, 0, "No", 0);

    if (ynaq) {
      ids[2].a_int = 'a';

      add_menu(win, NO_GLYPH, &(ids[2]), 0, 0, 0, "All", 0);
    }
  } else if ((cstr != NULL) && (strcasecmp(cstr, "rl") == 0)) {

    ids = (ANY_P *)malloc(sizeof(ANY_P) * 2);

    ids[0].a_int = 'r';
    ids[1].a_int = 'l';

    add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Right Hand", 0);
    add_menu(win, NO_GLYPH, &(ids[1]), 0, 0, 0, "Left Hand", 0);
  } else {
    int i;
    char curclass = -1;

    choices = _nds_parse_choices(ques);

    ids = (ANY_P *)malloc(sizeof(ANY_P) * strlen(choices));
    header_id.a_int = 0;

    for (i = 0; i < strlen(choices); i++) {

      ids[i].a_int = choices[i];

      if (choices[i] == ' ') {
        add_menu(win, NO_GLYPH, &(header_id), 0, 0, 0, "Other", 0);
      } else if (choices[i] == '*') {
        add_menu(win, NO_GLYPH, &(ids[i]), 0, 0, 0, "Something from your inventory", 0);
      } else if ((choices[i] == '-') || (choices[i] == '.')) {
        add_menu(win, NO_GLYPH, &(ids[i]), 0, 0, 0, "Nothing/your finger", 0);
      } else if (choices[i] == '?') {
        continue;
      } else {
        int oclass;
        char oname[BUFSZ];

        if (choices[i] == '$') {
          oclass = COIN_CLASS;
          sprintf(oname, "%ld gold piece%s", u.ugold, plur(u.ugold));
        } else {
          struct obj *otmp = obj_for_let(choices[i]);

          oclass = otmp->oclass;
          strcpy(oname, doname(otmp));
        }

        if (oclass != curclass) {
          add_menu(win, NO_GLYPH, &(header_id), 0, 0, 0, let_to_name(oclass, FALSE), 0);

          curclass = oclass;
        } 

        add_menu(win, NO_GLYPH, &(ids[i]), 0, 0, 0, oname, 0);
      }
    }
  }

  end_menu(win, ques);

  int mode = ((cstr == NULL) || (index(cstr, '#') != NULL)) ? PICK_ONE_TYPE : PICK_ONE;
  int cnt = select_menu(win, mode, &sel);

  if (cnt <= 0) {
    ret = yn ? 'n' : '\033';
  } else if ((mode == PICK_ONE) || (sel->count < 0)) {
    ret = sel->item.a_int;
  } else if (mode == PICK_ONE_TYPE) {
    sprintf(buffer, "%d%c", sel->count, sel->item.a_int);

    nds_input_buffer_append(buffer + 1);
    ret = *buffer;
  }

  if (sel != NULL) {
    free(sel);
  }

  free(ids);

  destroy_nhwindow(win);

  return ret;
}
Exemple #23
0
void nds_player_selection()
{
  int i, k, n;
  char pick4u = 'n', thisch, lastch = 0;
  char pbuf[PROMPT_LAYER_WIDTH], plbuf[PROMPT_LAYER_WIDTH];
  winid win;
  anything any;
  menu_item *selected = 0;

  /* prevent an unnecessary prompt */
  rigid_role_checks();

  /* Should we randomly pick for the player? */
  if (!flags.randomall &&
      (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE ||
       flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE)) {

    char *prompt = build_plselection_prompt(pbuf, PROMPT_LAYER_WIDTH, flags.initrole,
                                            flags.initrace, flags.initgend, flags.initalign);
    int res = _nds_display_yes_no_prompt(prompt);

    if (res < 0) {
give_up:
      return;
    }

    if (res) {
      pick4u = 'y';
    }
  }

  root_plselection_prompt(plbuf, PROMPT_LAYER_WIDTH - 1,
                          flags.initrole, flags.initrace, flags.initgend, flags.initalign);

  /* Select a role, if necessary */
  /* we'll try to be compatible with pre-selected race/gender/alignment,
   * but may not succeed */

  if (flags.initrole < 0) {
    char rolenamebuf[PROMPT_LAYER_WIDTH];

    /* Process the choice */
    if (pick4u == 'y' || flags.initrole == ROLE_RANDOM || flags.randomall) {
      /* Pick a random role */
      flags.initrole = pick_role(flags.initrace, flags.initgend,
                                 flags.initalign, PICK_RANDOM);
      if (flags.initrole < 0) {
        iprintf("Incompatible role!");

        flags.initrole = randrole();
      }
    } else {
      /* Prompt for a role */

      win = create_nhwindow(NHW_MENU);
      start_menu(win);

      any.a_void = 0;         /* zero out all bits */

      for (i = 0; roles[i].name.m; i++) {
        if (ok_role(i, flags.initrace, flags.initgend,
                    flags.initalign)) {

          any.a_int = i+1;	/* must be non-zero */
          thisch = lowc(roles[i].name.m[0]);

          if (thisch == lastch) thisch = highc(thisch);

          if (flags.initgend != ROLE_NONE && flags.initgend != ROLE_RANDOM) {
            if (flags.initgend == 1  && roles[i].name.f)
              Strcpy(rolenamebuf, roles[i].name.f);
            else
              Strcpy(rolenamebuf, roles[i].name.m);
          } else {
            if (roles[i].name.f) {
              Strcpy(rolenamebuf, roles[i].name.m);
              Strcat(rolenamebuf, "/");
              Strcat(rolenamebuf, roles[i].name.f);
            } else 
              Strcpy(rolenamebuf, roles[i].name.m);
          }	

          add_menu(win, NO_GLYPH, &any, thisch,
                   0, ATR_NONE, an(rolenamebuf), MENU_UNSELECTED);

          lastch = thisch;
        }
      }

      any.a_int = pick_role(flags.initrace, flags.initgend,
                            flags.initalign, PICK_RANDOM)+1;

      if (any.a_int == 0)	/* must be non-zero */
        any.a_int = randrole()+1;

      add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
               "Random", MENU_UNSELECTED);

      any.a_int = i+1;	/* must be non-zero */

      add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
               "Quit", MENU_UNSELECTED);

      Sprintf(pbuf, "Pick a role for your %s", plbuf);

      end_menu(win, pbuf);

      n = select_menu(win, PICK_ONE, &selected);

      destroy_nhwindow(win);

      /* Process the choice */
      if (n != 1 || selected[0].item.a_int == any.a_int)
        goto give_up;		/* Selected quit */

      flags.initrole = selected[0].item.a_int - 1;
      free((genericptr_t) selected),	selected = 0;
    }

    (void)  root_plselection_prompt(plbuf, PROMPT_LAYER_WIDTH - 1,
                                    flags.initrole, flags.initrace, flags.initgend, flags.initalign);
  }

  /* Select a race, if necessary */
  /* force compatibility with role, try for compatibility with
   * pre-selected gender/alignment */

  if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) {
    /* pre-selected race not valid */

    if (pick4u == 'y' || flags.initrace == ROLE_RANDOM || flags.randomall) {
      flags.initrace = pick_race(flags.initrole, flags.initgend,
                                 flags.initalign, PICK_RANDOM);
      if (flags.initrace < 0) {
        iprintf("Incompatible race!");
        flags.initrace = randrace(flags.initrole);
      }
    } else {	/* pick4u == 'n' */
      /* Count the number of valid races */
      n = 0;	/* number valid */
      k = 0;	/* valid race */

      for (i = 0; races[i].noun; i++) {
        if (ok_race(flags.initrole, i, flags.initgend,
                    flags.initalign)) {
          n++;
          k = i;
        }
      }

      if (n == 0) {
        for (i = 0; races[i].noun; i++) {
          if (validrace(flags.initrole, i)) {
            n++;
            k = i;
          }
        }
      }

      /* Permit the user to pick, if there is more than one */
      if (n > 1) {
        win = create_nhwindow(NHW_MENU);

        start_menu(win);
        any.a_void = 0;         /* zero out all bits */

        for (i = 0; races[i].noun; i++)
          if (ok_race(flags.initrole, i, flags.initgend,
                      flags.initalign)) {
            any.a_int = i+1;	/* must be non-zero */
            add_menu(win, NO_GLYPH, &any, races[i].noun[0],
                     0, ATR_NONE, races[i].noun, MENU_UNSELECTED);
          }

        any.a_int = pick_race(flags.initrole, flags.initgend,
                              flags.initalign, PICK_RANDOM)+1;

        if (any.a_int == 0)	/* must be non-zero */
          any.a_int = randrace(flags.initrole)+1;

        add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
                 "Random", MENU_UNSELECTED);

        any.a_int = i+1;	/* must be non-zero */

        add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
                 "Quit", MENU_UNSELECTED);

        Sprintf(pbuf, "Pick the race of your %s", plbuf);
        end_menu(win, pbuf);

        n = select_menu(win, PICK_ONE, &selected);
        destroy_nhwindow(win);

        if (n != 1 || selected[0].item.a_int == any.a_int)
          goto give_up;		/* Selected quit */

        k = selected[0].item.a_int - 1;
        free((genericptr_t) selected),	selected = 0;
      }

      flags.initrace = k;
    }

    (void)  root_plselection_prompt(plbuf, PROMPT_LAYER_WIDTH - 1,
                                    flags.initrole, flags.initrace, flags.initgend, flags.initalign);
  }

  /* Select a gender, if necessary */
  /* force compatibility with role/race, try for compatibility with
   * pre-selected alignment */
  if (flags.initgend < 0 || !validgend(flags.initrole, flags.initrace,
                                       flags.initgend)) {
    /* pre-selected gender not valid */
    if (pick4u == 'y' || flags.initgend == ROLE_RANDOM || flags.randomall) {
      flags.initgend = pick_gend(flags.initrole, flags.initrace,
                                 flags.initalign, PICK_RANDOM);
      if (flags.initgend < 0) {
        iprintf("Incompatible gender!");
        flags.initgend = randgend(flags.initrole, flags.initrace);
      }
    } else {	/* pick4u == 'n' */
      /* Count the number of valid genders */
      n = 0;	/* number valid */
      k = 0;	/* valid gender */

      for (i = 0; i < ROLE_GENDERS; i++) {
        if (ok_gend(flags.initrole, flags.initrace, i,
                    flags.initalign)) {
          n++;
          k = i;
        }
      }

      if (n == 0) {
        for (i = 0; i < ROLE_GENDERS; i++) {
          if (validgend(flags.initrole, flags.initrace, i)) {
            n++;
            k = i;
          }
        }
      }

      /* Permit the user to pick, if there is more than one */
      if (n > 1) {
        win = create_nhwindow(NHW_MENU);
        start_menu(win);

        any.a_void = 0;         /* zero out all bits */

        for (i = 0; i < ROLE_GENDERS; i++)
          if (ok_gend(flags.initrole, flags.initrace, i,
                      flags.initalign)) {
            any.a_int = i+1;
            add_menu(win, NO_GLYPH, &any, genders[i].adj[0],
                     0, ATR_NONE, genders[i].adj, MENU_UNSELECTED);
          }

        any.a_int = pick_gend(flags.initrole, flags.initrace,
                              flags.initalign, PICK_RANDOM)+1;

        if (any.a_int == 0)	/* must be non-zero */
          any.a_int = randgend(flags.initrole, flags.initrace)+1;

        add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
                 "Random", MENU_UNSELECTED);

        any.a_int = i+1;	/* must be non-zero */

        add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
                 "Quit", MENU_UNSELECTED);

        Sprintf(pbuf, "Pick the gender of your %s", plbuf);
        end_menu(win, pbuf);

        n = select_menu(win, PICK_ONE, &selected);
        destroy_nhwindow(win);

        if (n != 1 || selected[0].item.a_int == any.a_int)
          goto give_up;		/* Selected quit */

        k = selected[0].item.a_int - 1;
        free((genericptr_t) selected),	selected = 0;
      }

      flags.initgend = k;
    }

    (void)  root_plselection_prompt(plbuf, PROMPT_LAYER_WIDTH - 1,
                                    flags.initrole, flags.initrace, flags.initgend, flags.initalign);
  }

  /* Select an alignment, if necessary */
  /* force compatibility with role/race/gender */
  if (flags.initalign < 0 || !validalign(flags.initrole, flags.initrace,
                                         flags.initalign)) {
    /* pre-selected alignment not valid */
    if (pick4u == 'y' || flags.initalign == ROLE_RANDOM || flags.randomall) {
      flags.initalign = pick_align(flags.initrole, flags.initrace,
                                   flags.initgend, PICK_RANDOM);
      if (flags.initalign < 0) {
        iprintf("Incompatible alignment!");
        flags.initalign = randalign(flags.initrole, flags.initrace);
      }
    } else {	/* pick4u == 'n' */
      /* Count the number of valid alignments */
      n = 0;	/* number valid */
      k = 0;	/* valid alignment */

      for (i = 0; i < ROLE_ALIGNS; i++) {
        if (ok_align(flags.initrole, flags.initrace, flags.initgend,
                     i)) {
          n++;
          k = i;
        }
      }

      if (n == 0) {
        for (i = 0; i < ROLE_ALIGNS; i++) {
          if (validalign(flags.initrole, flags.initrace, i)) {
            n++;
            k = i;
          }
        }
      }

      /* Permit the user to pick, if there is more than one */
      if (n > 1) {
        win = create_nhwindow(NHW_MENU);
        start_menu(win);

        any.a_void = 0;         /* zero out all bits */

        for (i = 0; i < ROLE_ALIGNS; i++)
          if (ok_align(flags.initrole, flags.initrace,
                       flags.initgend, i)) {
            any.a_int = i+1;
            add_menu(win, NO_GLYPH, &any, aligns[i].adj[0],
                     0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED);
          }

        any.a_int = pick_align(flags.initrole, flags.initrace,
                               flags.initgend, PICK_RANDOM)+1;

        if (any.a_int == 0)	/* must be non-zero */
          any.a_int = randalign(flags.initrole, flags.initrace)+1;

        add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
                 "Random", MENU_UNSELECTED);

        any.a_int = i+1;	/* must be non-zero */

        add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
                 "Quit", MENU_UNSELECTED);

        Sprintf(pbuf, "Pick the alignment of your %s", plbuf);
        end_menu(win, pbuf);

        n = select_menu(win, PICK_ONE, &selected);
        destroy_nhwindow(win);

        if (n != 1 || selected[0].item.a_int == any.a_int)
          goto give_up;		/* Selected quit */

        k = selected[0].item.a_int - 1;
        free((genericptr_t) selected),	selected = 0;
      }

      flags.initalign = k;
    }
  }
}
Exemple #24
0
/*
 * Edit one record, return -1 if there are errors, 0 if ok.
 */
int EditNGrpRec(int Area)
{
	FILE	*fil;
	char	mfile[PATH_MAX];
	int	offset;
	int	j;
	unsigned int	crc, crc1;

	clr_index();
	working(1, 0, 0);
	IsDoing("Edit NewfileGroup");

	snprintf(mfile, PATH_MAX, "%s/etc/ngroups.temp", getenv("FTND_ROOT"));
	if ((fil = fopen(mfile, "r")) == NULL) {
		working(2, 0, 0);
		return -1;
	}

	offset = sizeof(ngrouphdr) + ((Area -1) * sizeof(ngroup));
	if (fseek(fil, offset, 0) != 0) {
		working(2, 0, 0);
		return -1;
	}

	fread(&ngroup, sizeof(ngroup), 1, fil);
	fclose(fil);
	crc = 0xffffffff;
	crc = upd_crc32((char *)&ngroup, crc, sizeof(ngroup));
	NgScreen();
	
	for (;;) {
		set_color(WHITE, BLACK);
		show_str(  7,18,12, ngroup.Name);
		show_str(  8,18,55, ngroup.Comment);
		show_bool( 9,18,    ngroup.Active);
		show_bool(10,18,    ngroup.Deleted);

		j = select_menu(4);
		switch(j) {
		case 0:
			crc1 = 0xffffffff;
			crc1 = upd_crc32((char *)&ngroup, crc1, sizeof(ngroup));
			if (crc != crc1) {
				if (yes_no((char *)"Record is changed, save") == 1) {
					working(1, 0, 0);
					if ((fil = fopen(mfile, "r+")) == NULL) {
						working(2, 0, 0);
						return -1;
					}
					fseek(fil, offset, 0);
					fwrite(&ngroup, sizeof(ngroup), 1, fil);
					fclose(fil);
					NGrpUpdated = 1;
					working(6, 0, 0);
				}
			}
			IsDoing("Browsing Menu");
			return 0;
		case 1: E_UPS( 7,18,12,ngroup.Name,"The ^name^ for this message group")
		case 2: E_STR( 8,18,55,ngroup.Comment,"The ^desription^ for this message group")
		case 3: E_BOOL(9,18,   ngroup.Active, "Is this message group ^active^")
		case 4: E_BOOL(10,18,  ngroup.Deleted, "Is this group ^Deleted^")
		}
	}

	return 0;
}
Exemple #25
0
// Main loop of the program
int main(void)
{
    //
    // Set the clocking to run directly from the crystal. 8Mhz
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    delay(500);
    LED_init();
    delay(500);
    ADC_init(); //init the adc
    delay(500);
    timer0_init(); //init the first timer
    delay(500);
    timer1_init(); //second timer
    delay(500);
    key_init(); //keypad
    display_init();
    CPUcpsie(); //turn on cpu inttrupts

    //init all prices and indexes
    int upDownIndex = 0; 
    int currDollars = 0;
    int currCents = 0;
    int leftRightIndex = 0;
    display_on(1,1); 
    print_welcome(); //print initial welcome menu
 
     /*
    handles key inputs
    User can toggle through display menus (welcome menu, food menu,...) 
    using LEFT and RIGHT
    While on the food menu, user can toggle through food options using UP 
    and DOWN and select food items using SELECT.
    */
    while(1)
    {
      int currentKey = keymaster();
      if (!readKey) { //if we have not read the key since it has been updated
        switch (currentKey) //main control flow loop
        {
          case UP:
            if (upDownIndex) {
              upDownIndex--; //de-inc the vertical index
              print_menu(upDownIndex, currDollars, currCents);
            }
            break;
          case DOWN:
            if (upDownIndex < maxUpDownIndex) {
              upDownIndex++; //inc the vertical index
              print_menu(upDownIndex, currDollars, currCents);
            }
            break;
          case RIGHT:
            if (leftRightIndex < maxLeftRightIndex) {
              leftRightIndex++; //inc the left right index
              select_menu(&leftRightIndex, upDownIndex, currDollars, currCents);
            }
            break;
          case LEFT:
            if (leftRightIndex) {
              leftRightIndex--; //de-inc the left right index
              select_menu(&leftRightIndex, upDownIndex, currDollars, currCents);
            }
            break;
          case SELECT:
            currDollars += dollars[upDownIndex]; //update the total costs
            currCents += cents[upDownIndex];
            if (currCents >= 100) {
              currDollars += 1;
              currCents -= 100;
            }
            print_menu(upDownIndex, currDollars, currCents);
            break;
        }
      }
      readKey = 1; //tell timer 0 we have read the key
      //Reset the totals for the costs
      if (leftRightIndex == 0) {
        currDollars = 0;
        currCents = 0;
      }
    }

}
Exemple #26
0
/**
   Runs before player selection, and is used to determine which game
   mode to play in. If the choice is to continue or start a new game, it
   sets the character name to determine which (currently unused name for
   the player = new game, currently used name = continue that game);
   otherwise, it implements the choice itself then either loops or
   exits.

   This is based on the tty code, except that it uses a menu rather
   than rendering the game mode selection by hand.
*/
void
Sdlgl_game_mode_selection()
{
  int c;
  char** saved;
  char** sp;
  int plname_in_saved = 0;
  int plname_was_explicit = !!*plname;
  (void) plname_was_explicit; /* TODO: use this */

  winid menuwin;
  int n;
  menu_item *selected;
  anything any;

  saved = get_saved_games();

  if (*plname && saved && *saved) {
    for (sp = saved; *sp; sp++) {
      /* Note that this means that public servers need to prevent two
         users with the same name but different capitalisation. (If
         they aren't, it's likely to cause problems anyway...) */
      if (!strcmpi(plname, *sp)) {
        plname_in_saved = 1;
        /* Fix capitalisation of the name to match the saved game. */
        strncpy(plname, *sp, sizeof(plname)-1);
      }
    }
  } else if (*plname) {
    set_savefile_name();
    /* Let's just try to open the savefile directly to see if it exists */
    plname_in_saved = verify_savefile();
  }

retry_mode_selection:;
reread_char:
  menuwin = create_nhwindow(NHW_MENU);
  any.a_void = 0;
  start_menu(menuwin);

  any.a_int = 'c';
  add_menu(menuwin, NO_GLYPH, &any, 'c', 0, ATR_NONE,
           "Continue game", MENU_UNSELECTED);
  any.a_int = 'n';
  add_menu(menuwin, NO_GLYPH, &any, 'n', 0, ATR_NONE,
           "New game", MENU_UNSELECTED);
  any.a_int = 't';
  add_menu(menuwin, NO_GLYPH, &any, 't', 0, ATR_NONE,
           "Tutorial", MENU_UNSELECTED);
  any.a_int = 'm';
  add_menu(menuwin, NO_GLYPH, &any, 'm', 0, ATR_NONE,
           "Other modes", MENU_UNSELECTED);

  any.a_void = 0;
  add_menu(menuwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", FALSE);

  any.a_int = 's';
  add_menu(menuwin, NO_GLYPH, &any, 's', 0, ATR_NONE,
           "Continue game", MENU_UNSELECTED);
  any.a_int = 'o';
  add_menu(menuwin, NO_GLYPH, &any, 'o', 0, ATR_NONE,
           "New game", MENU_UNSELECTED);
  any.a_int = '?';
  add_menu(menuwin, NO_GLYPH, &any, '?', 0, ATR_NONE,
           "Tutorial", MENU_UNSELECTED);
  any.a_int = 'q';
  add_menu(menuwin, NO_GLYPH, &any, 'q', 0, ATR_NONE,
           "Other modes", MENU_UNSELECTED);

  end_menu(menuwin, "Welcome to AceHack!");
  n = select_menu(menuwin, PICK_ONE, &selected);
  destroy_nhwindow(menuwin);

  if (n > 0) {
    c = selected[0].item.a_int;
    free((genericptr_t)selected);
  } else goto retry_mode_selection;

#if 0
  /* TODO: This is tty code for graying out unavailable options;
     we should do that in SDL/GL code too */
  {
    if (c == 1) { /* gray out if there's no game to continue */
      if (!*plname && (!saved || !*saved)) xputs("\033[31m");
      else if (*plname && !plname_in_saved) xputs("\033[31m");
      /* and bold if there is */
      else xputs("\033[1m");
    }
    else if (c == 2) { /* gray out if a game must be continued */
      if (*plname && plname_in_saved) xputs("\033[31m");
    }
    else xputc(c); /* low-level as codes are in the file itself */
  }
#endif

  switch (c) {
  case 'c': /* continue game */
    if (*plname && plname_in_saved) break; /* just load by name */
    if (!saved || !*saved) goto reread_char;
    if (*plname && !plname_in_saved) goto reread_char;
    if (!saved[1]) {
      /* only one game to continue */
      (void) strncpy(plname, *saved, sizeof(plname)-1);
    } else {
      /* we'll have to ask which game to continue */
      winid win;
      win = create_nhwindow(NHW_MENU);
      start_menu(win);
      any.a_void = 0;
      for (sp = saved; *sp; sp++) {
        any.a_void = (void*) *sp;
        add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, *sp, MENU_UNSELECTED);
      }
      end_menu(win, "Continue which saved game?");
      c = select_menu(win, PICK_ONE, &selected);
      destroy_nhwindow(win);
      if (c != 1) {
        free((genericptr_t) selected);
        goto retry_mode_selection;
      }
      (void) strncpy(plname, (char*)selected[0].item.a_void, sizeof(plname)-1);
      free((genericptr_t) selected);
    }
    break;
  case 'n': case 't': case 'm': /* the new game options */
    /* if the name is forced by the -u option, don't give an option to
       start a new game, as we're forced onto the existing game */
    if (*plname && plname_in_saved) goto reread_char;
    if (!*plname) {
      Sdlgl_askname();
      if (saved)
        for (sp = saved; *sp; sp++) {
          if (!strcmpi(plname, *sp)) {
            pline("A game is running with that name already.");
            Sdlgl_dismiss_nhwindow(NHW_MESSAGE); /* force a --More-- */
            *plname = 0;
            goto retry_mode_selection;
          }
        }
    }
    if (c == 'm') {
      pline("TODO: implement game mode selection here");
      goto retry_mode_selection;
      do {
        c = 0; /* read from keyboard */
        switch(c) {
          /* -D, -X on command line are overriden by selecting a normal game
             explicitly */
        case 'n': wizard = FALSE; discover = FALSE; break;
        case 't': break;
        case 'd':
#ifdef WIZARD
          /* The rules here are a little complex:
             - with no -u (local play, private server play), anyone
               can enter debug mode;
             - with -u set (generally public server play), only an
               authorized user can enter debug mode.
             Thus people can enter it freely in their own compiles,
             but on public servers likely only the admin can enter it,
             as only they can tweak the command line. (-D works too
             to enter wizmode, whatever the -u option, as if it's
             given the player has control over the command line anyway.) */
          if (plname_was_explicit && strcmpi(plname,WIZARD)) {
            extern int wiz_error_flag; /* from unixmain.c */
            wiz_error_flag = TRUE;
          } else {
            wizard = TRUE;
            c = 'n';
            break;
          }
          /*FALLTHRU*/
#endif /* otherwise fall through, as debug mode isn't compiled in */
        case 'x': discover = TRUE; c = 'n'; break;
        case 's': solo = TRUE; c = 'n'; break;
        case '\033': goto retry_mode_selection;
        default: continue;
        }
      } while (c != 'n' && c != 't');
    }
    if (c == 't') flags.tutorial = 1;
    break;
  case 's': /* show high score list */
    prscore_interactive();
    goto retry_mode_selection;
  case 'o': /* options */
    doset();
    goto retry_mode_selection;
  case '?': /* help */
    dohelp();
    Sdlgl_dismiss_nhwindow(NHW_MESSAGE); /* force a --More-- */
    goto retry_mode_selection;
  case 'q': case '\033': /* exit */
    /* This is the standard Sdlgl method of exiting. */
    Sdlgl_exit_nhwindows(0);
    terminate(EXIT_SUCCESS);
    /*NOTREACHED*/
  default:
    goto reread_char;
  }

  if (saved) free_saved_games(saved);
}
void menu_event_saved(void)
{
    if( changed & KEY_OK )
        select_menu( &menu_main );
}
Exemple #28
0
nds_cmd_t nds_get_direction()
{
  winid win;
  menu_item *sel;
  ANY_P ids[25];
  nds_cmd_t cmd;
  int i, j, k;
  int res;

  char tmp[2];
  char *direction_keys = nds_get_direction_keys();

  win = create_nhwindow(NHW_MENU);
  start_menu(win);

  ids[0].a_int = 0;

  for (i = 0, j = 1; i < 3; i++) {
    switch (i) {
      case 0:
        add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Walk", 0);
        break;

      case 1:
        add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Run", 0);
        break;

      case 2:
        add_menu(win, NO_GLYPH, &(ids[0]), 0, 0, 0, "Fight", 0);
        break;
    }

    for (k = 0; k < 8; j++, k++) {
      tmp[0] = direction_keys[k];
      tmp[1] = '\0';

      ids[j].a_int = j;

      add_menu(win, NO_GLYPH, &(ids[j]), 0, 0, 0, nds_command_to_string(tmp), 0);
    }
  }

  end_menu(win, "What Type of Movement?");
  res = select_menu(win, PICK_ONE, &sel);
  destroy_nhwindow(win);

  if (res <= 0) {
    cmd.f_char = -1;
    cmd.name = NULL;
  } else if (sel->item.a_int < 9) {
    tmp[0] = direction_keys[sel->item.a_int - 1];
    tmp[1] = '\0';

    cmd.f_char = direction_keys[sel->item.a_int - 1];
    cmd.name = nds_command_to_string(tmp);
  } else if (sel->item.a_int < 17) {
    nds_input_buffer_push(direction_keys[sel->item.a_int - 9]);

    cmd.f_char = 'g';
    cmd.name = nds_command_to_string(nds_input_buffer_shiftall());
  } else {
    nds_input_buffer_push(direction_keys[sel->item.a_int - 17]);

    cmd.f_char = 'F';
    cmd.name = nds_command_to_string(nds_input_buffer_shiftall());
  }

  NULLFREE(sel);

  return cmd;
}
Exemple #29
0
/*-------------------------------------------------------------------------*/
void ActivateCell(HWND hWnd, int cell)
{
	PNHCmdWindow data;
	PNHCmdPadCell p_cell_data;
	int i;

	data = (PNHCmdWindow)GetWindowLong(hWnd, GWL_USERDATA);
	if( !data ) return;
	p_cell_data = nhcmdlayout_cell_direct(data->layout_current, cell);

	/* act depending on the cell type:
		CAPS - change layout 
		CTRL - modify CTRL status
		REG  - place keyboard event on the nethack input queue
	*/
	switch( p_cell_data->type ) {
	case NH_CELL_REG: 
		if( data->is_ctrl ) {
			PushNethackCommand(p_cell_data->f_char, 1);

			data->is_ctrl = 0;
			for( i=0; i<nhcmdlayout_rows(data->layout_current)*nhcmdlayout_columns(data->layout_current); i++ ) {
				if( nhcmdlayout_cell_direct(data->layout_current, i)->type == NH_CELL_CTRL ) {
					HighlightCell(hWnd, i, data->is_ctrl);
				}
			}
		} else {
			PushNethackCommand(p_cell_data->f_char, 0);
		}
		HighlightCell(hWnd, cell, FALSE);

		// select a new layout if present
		i = (int)p_cell_data->data;
		if( i==-1 ) {
			if( data->layout_save ) SetCmdWindowLayout(hWnd, data->layout_save);
			data->layout_save = NULL;
		} else {
			if( !data->layout_save ) data->layout_save = data->layout_current;
			SetCmdWindowLayout(hWnd, nhcmdset_get(nhcmdset_current, i));
		}

		if( !data->is_shift ) break;
		// else fall through and reset the shift

	case NH_CELL_SHIFT:
		data->is_shift = !data->is_shift;
		SetCmdWindowLayout(
			hWnd,
			(data->is_shift ^ data->is_caps)? nhcmdset_get(nhcmdset_current, 1) : nhcmdset_get(nhcmdset_current, 0)
		);
		data->cells[cell].state = data->is_shift? NH_CST_CHECKED : 0;
		InvalidateRect(hWnd, NULL, TRUE);
		break;

	case NH_CELL_CTRL:
		data->is_ctrl = !data->is_ctrl;
		HighlightCell(hWnd, cell, data->is_ctrl);
		break;

	case NH_CELL_CAP:
		data->is_caps = !data->is_caps;
		SetCmdWindowLayout(
			hWnd,
			(data->is_shift ^ data->is_caps)? nhcmdset_get(nhcmdset_current, 1) : nhcmdset_get(nhcmdset_current, 0)
		);
		data->cells[cell].state = data->is_caps? NH_CST_CHECKED : 0;
		InvalidateRect(hWnd, NULL, TRUE);
		break;

	case NH_CELL_LAYOUT_NEW: {
		PNHCmdLayout pLayout;

		HighlightCell(hWnd, cell, FALSE);

		pLayout = (PNHCmdLayout)p_cell_data->data;
		if( pLayout ) {
			SetCmdWindowLayout(hWnd, pLayout);
		}
	} break;
	
	case NH_CELL_LAYOUT_MENU: {
		winid wid;
		int i;
		anything any;
		menu_item* selected = 0;
		PNHCmdSet pSet;

		HighlightCell(hWnd, cell, FALSE);

		pSet = (PNHCmdSet)p_cell_data->data;
		if( !pSet ) pSet = nhcmdset_default;

		wid = mswin_create_nhwindow(NHW_MENU);
		mswin_start_menu(wid);
		for( i=0; i<nhcmdset_count(pSet); i++ ) {
			any.a_void = nhcmdset_get(pSet, i);
			mswin_add_menu(wid, NO_GLYPH, &any, 'a'+i, 0, ATR_NONE, 
				nhcmdset_get_name(pSet, i), FALSE);
		}
		mswin_end_menu(wid, "Select keypad layout");
	    i = select_menu(wid, PICK_ONE, &selected);
	    mswin_destroy_nhwindow(wid);

		if( i==1 ) {
#if defined(WIN_CE_SMARTPHONE)
			data->layout_selected = (PNHCmdLayout)selected[0].item.a_void;
#endif
			SetCmdWindowLayout(hWnd, (PNHCmdLayout)selected[0].item.a_void );
		}
	} break;
	
	}
}
void menu_event_main(void)
{
    if( changed & KEY_OK )
        select_menu( menu + menu_curr );
}