예제 #1
0
boolean nh_exit_game(int exit_type)
{
    boolean log_disabled = iflags.disable_log;
    
    if (!api_entry_checkpoint()) { /* not sure anything in here can actually call panic */
	iflags.disable_log = log_disabled;
	return TRUE; /* terminate was called, so exit is successful */
    }
    
    program_state.forced_exit = TRUE;
    
    /* clean up after viewing a game replay */
    if (program_state.viewing)
	nh_view_replay_finish();
	
    xmalloc_cleanup();
    iflags.disable_log = TRUE;
    if (program_state.game_running) {
	switch (exit_type) {
	    case EXIT_REQUEST_SAVE:
		dosave(); /* will ask "really save?" and, if 'y', eventually call terminate. */
		break;
		
	    case EXIT_FORCE_SAVE:
		dosave0(TRUE);
		terminate();
		break;
		
	    case EXIT_REQUEST_QUIT:
		done2();
		break;
		    
	    case EXIT_FORCE_QUIT:
		done(QUIT);
		break; /* not reached */
		
	    case EXIT_PANIC:
		/* freeing things should be safe */
		freedynamicdata();
		dlb_cleanup();
		panic("UI problem.");
		break;
	}
	
	iflags.disable_log = log_disabled;
	api_exit();
	return FALSE;
    }
    
    iflags.disable_log = log_disabled;
    /* calling terminate() will get us out of nested contexts safely, eg:
     * UI_cmdloop -> nh_command -> UI_update_screen (problem happens here) -> nh_exit_game
     * will jump all the way back to UI_cmdloop */
    terminate();
    
    api_exit(); /* not reached */
    return TRUE;
}
예제 #2
0
/* show a main menu with common options when the user presses esc */
void vulture_show_mainmenu()
{
	int winid, n;
	anything any;
	menu_item *selected;

	winid = vulture_create_nhwindow(NHW_MENU);
	vulture_start_menu(winid);
	
	any.a_int = 1;
	vulture_add_menu(winid, NO_GLYPH, &any, 'h', 0, ATR_BOLD,
					"Help", MENU_UNSELECTED);
	any.a_int = 2;
	vulture_add_menu(winid, NO_GLYPH, &any, 'O', 0, ATR_BOLD,
					"Options", MENU_UNSELECTED);
	any.a_int = 3;
	vulture_add_menu(winid, NO_GLYPH, &any, 'I', 0, ATR_BOLD,
					"Interface options", MENU_UNSELECTED);
	any.a_int = 4;
	vulture_add_menu(winid, NO_GLYPH, &any, 'S', 0, ATR_BOLD,
					"Save & Quit", MENU_UNSELECTED);
	any.a_int = 5;
	vulture_add_menu(winid, NO_GLYPH, &any, 'Q', 0, ATR_BOLD,
					"Quit", MENU_UNSELECTED);

	vulture_end_menu(winid, "Main menu");
	n = vulture_select_menu(winid, PICK_ONE, &selected);
	vulture_destroy_nhwindow(winid);

	if (n < 1)
		return;

	switch(selected[0].item.a_int)
	{
		case 1: dohelp(); break;
		case 2: doset(); break;
		case 3: vulture_iface_opts(); break;
		case 4: dosave(); break;
		case 5: done2(); break;
	}
}
예제 #3
0
LRESULT
onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PNHMainWindow data;

    data = (PNHMainWindow) GetWindowLong(hWnd, GWL_USERDATA);
    wmId = LOWORD(wParam);
    wmEvent = HIWORD(wParam);

    // process the menu selections:
    switch (wmId) {
    case IDM_ABOUT:
        DialogBox(GetNHApp()->hApp, (LPCTSTR) IDD_ABOUTBOX, hWnd,
                  (DLGPROC) About);
        break;

    case IDM_EXIT:
        done2();
        break;

    case IDM_SAVE:
        dosave();
        break;

    case IDM_MAP_TILES:
    case IDM_MAP_ASCII4X6:
    case IDM_MAP_ASCII6X8:
    case IDM_MAP_ASCII8X8:
    case IDM_MAP_ASCII16X8:
    case IDM_MAP_ASCII7X12:
    case IDM_MAP_ASCII8X12:
    case IDM_MAP_ASCII12X16:
    case IDM_MAP_ASCII16X12:
    case IDM_MAP_ASCII10X18:
        mswin_select_map_mode(menuid2mapmode(wmId));
        break;

    case IDM_MAP_FIT_TO_SCREEN:
        if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) {
            mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode)
                                      ? data->mapAcsiiModeSave
                                      : MAP_MODE_TILES);
        } else {
            mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode)
                                      ? MAP_MODE_ASCII_FIT_TO_SCREEN
                                      : MAP_MODE_TILES_FIT_TO_SCREEN);
        }
        break;

    case IDM_VIEW_KEYPAD:
        GetNHApp()->bCmdPad = !GetNHApp()->bCmdPad;
        CheckMenuItem(
            _get_main_menu(ID_VIEW), IDM_VIEW_KEYPAD,
            MF_BYCOMMAND | (GetNHApp()->bCmdPad ? MF_CHECKED : MF_UNCHECKED));
        mswin_layout_main_window(GetNHApp()->hCmdWnd);
        break;

    case IDM_VIEW_OPTIONS:
        doset();
        break;

    case IDM_DIRECT_COMMAND: /* SmartPhone: display dialog to type in arbitary
                                command text */
        mswin_direct_command();
        break;

    case IDM_HELP_LONG:
        display_file(HELP, TRUE);
        break;

    case IDM_HELP_COMMANDS:
        display_file(SHELP, TRUE);
        break;

    case IDM_HELP_HISTORY:
        (void) dohistory();
        break;

    case IDM_HELP_INFO_CHAR:
        (void) dowhatis();
        break;

    case IDM_HELP_INFO_KEY:
        (void) dowhatdoes();
        break;

    case IDM_HELP_OPTIONS:
        option_help();
        break;

    case IDM_HELP_OPTIONS_LONG:
        display_file(OPTIONFILE, TRUE);
        break;

    case IDM_HELP_EXTCMD:
        (void) doextlist();
        break;

    case IDM_HELP_LICENSE:
        display_file(LICENSE, TRUE);
        break;

    case IDM_HELP_MENU:
        dohelp();
        break;

    default:
        return 1;
    }
    return 0;
}
예제 #4
0
int vultures_handle_global_event(SDL_Event * event)
{
	static int quitting = 0;
	static int need_kludge = 0;
	static point actual_winsize = {0,0};
	
	/* blarg. see the SDL_VIDEORESIZE case */
	if (need_kludge &&
		(actual_winsize.x != vultures_opts.width ||
		actual_winsize.y != vultures_opts.height))
	{
		vultures_screen = SDL_SetVideoMode(vultures_opts.width, vultures_opts.height, 32,
										SDL_SWSURFACE | SDL_RESIZABLE | SDL_ASYNCBLIT);
		vultures_win_resize(vultures_opts.width, vultures_opts.height);
		actual_winsize.x = vultures_opts.width;
		actual_winsize.y = vultures_opts.height;
		need_kludge = 0;
	}

	switch (event->type)
	{
		case SDL_ACTIVEEVENT:
			if (event->active.gain && event->active.state == SDL_APPACTIVE)
				vultures_refresh();
			else if (event->active.state == SDL_APPMOUSEFOCUS)
				have_mouse_focus = event->active.gain;
			break;

		case SDL_VIDEOEXPOSE:
			vultures_refresh();
			break;

		case SDL_QUIT:
			if (quitting)
				break;

			/* prevent recursive quit dialogs... */
			quitting++;

			/* exit gracefully */
			if (program_state.gameover)
			{
				/* assume the user really meant this, as the game is already over... */
				/* to make sure we still save bones, just set stop printing flag */
				program_state.stopprint++;
				/* and send keyboard input as if user pressed ESC */
				vultures_eventstack_add('\033', -1, -1, V_RESPOND_POSKEY); 
			}
			else if (!program_state.something_worth_saving)
			{
				/* User exited before the game started, e.g. during splash display */
				/* Just get out. */
				vultures_bail(NULL);
			}
			else
			{
				switch (vultures_yn_function("Save and quit?", "yn", 'n'))
				{
					case 'y':
						vultures_eventstack_add('y', -1 , -1, V_RESPOND_CHARACTER);
						dosave();
						break;
					case 'n':
						vultures_eventstack_add('\033', -1, -1, V_RESPOND_CHARACTER);
						break;
					default:
						break;
				}
			}
			quitting--;
			break;

		case SDL_MOUSEMOTION:
			vultures_set_mouse_pos(event->motion.x, event->motion.y);
			break;

		case SDL_KEYDOWN:
			if (event->key.keysym.sym == SDLK_TAB && (event->key.keysym.mod & KMOD_ALT) && vultures_opts.fullscreen)
			{
				/* go out of fullscreen for alt + tab */
				vultures_opts.fullscreen = 0;
				vultures_set_windowed();
				if (!vultures_opts.fullscreen && !fs_message_printed++)
					/* This gets displayed only once */
					pline("You have left fullscreen mode. Press ALT+RETURN to reenter it.");

				event->type = 0; /* we don't want to leave the event loop for this */
				return 1;
			}
			else if(event->key.keysym.sym == SDLK_RETURN && (event->key.keysym.mod & KMOD_ALT))
			{
				/* toggle fullscreen with ctrl + enter */
				if (vultures_opts.fullscreen)
				{
					vultures_opts.fullscreen = 0;
					vultures_set_windowed();
				}
				else
				{
					vultures_opts.fullscreen = 1;
					vultures_set_fullscreen();
				}
				event->type = 0; /* we don't want to leave the event loop for this */
				return 1;
			}
			else if(event->key.keysym.sym == SDLK_SYSREQ ||
					event->key.keysym.sym == SDLK_PRINT ||
					event->key.keysym.sym == SDLK_F12)
			{
				vultures_save_screenshot();
				event->type = 0; /* we don't want to leave the event loop for this */
				return 1;
			}
			/* magic tileconfig reload key */
			else if (event->key.keysym.sym == SDLK_F11 &&
					(event->key.keysym.mod & KMOD_ALT) &&
					(event->key.keysym.mod & KMOD_SHIFT))
			{
				vultures_unload_gametiles();
				vultures_load_gametiles();
				levwin->force_redraw();
				ROOTWIN->draw_windows();
				pline("tileconfig reloaded!");
			}

			/* object highlight */
			if (vultures_map_highlight_objects == 0 &&
				((event->key.keysym.mod & KMOD_RCTRL) ||
				event->key.keysym.sym == SDLK_RCTRL))
			{
				/* enable highlighting */
				vultures_map_highlight_objects = 1;

				/* set the max clipping rect */
				levwin->force_redraw();

				/* redraw with the object highlight */
				ROOTWIN->draw_windows();

				/* the mouse got painted over, restore it */
				vultures_mouse_draw();

				/* bring the buffer onto the screen */
				vultures_refresh_window_region();

				/* make sure no after-images of the mouse are left over */
				vultures_mouse_restore_bg();
			}

			break;

		case SDL_KEYUP:
			if (vultures_map_highlight_objects == 1)
			{
				/* disable highlighting */
				vultures_map_highlight_objects = 0;

				/* set the max clipping rect */
				levwin->force_redraw();

				/* redraw without the object highlight */
				ROOTWIN->draw_windows();

				/* the mouse got painted over, restore it */
				vultures_mouse_draw();

				/* bring the buffer onto the screen */
				vultures_refresh_window_region();

				/* make sure no after-images of the mouse are left over */
				vultures_mouse_restore_bg();
			}
			break;

		case SDL_VIDEORESIZE:
			actual_winsize.x = event->resize.w;
			actual_winsize.y = event->resize.h;

			vultures_opts.width = event->resize.w;
			if (event->resize.w < 540)
			{
				need_kludge = 1;
				vultures_opts.width = 540;
			}
			vultures_opts.height = event->resize.h;
			if (event->resize.h < 300)
			{
				need_kludge = 1;
				vultures_opts.height = 300;
			}

			/* SDL will not actually change the size of the window here, only the size of the buffer.
			* therefore we may need_kludge to call SDL_SetVideoMode AGAIN to set the window size. */
			vultures_screen = SDL_SetVideoMode(vultures_opts.width, vultures_opts.height, 32,
										SDL_SWSURFACE | SDL_RESIZABLE | SDL_ASYNCBLIT);
			vultures_win_resize(vultures_opts.width, vultures_opts.height);
			break;
	}

	return 0;
}