Changeset - r4548:6a33e364fba5
[Not reviewed]
master
0 8 0
rubidium - 18 years ago 2006-09-04 17:30:30
rubidium@openttd.org
(svn r6380) -Codechange: unify all ways to quit OTTD.
This means that in the intro menu the 'Quit' button immediatelly quits
and the 'Quit' in the menu of the normal game and scenario editor
immediatelly quits when the 'autosave_on_exit' patch is turned on.
This is the same way as the OS/window manager initiated quits, like
alt-F4 and the 'x' in the (OS/window manager drawn) title bar of OTTD.
8 files changed with 23 insertions and 49 deletions:
0 comments (0 inline, 0 general)
functions.h
Show inline comments
 
@@ -224,17 +224,18 @@ void ShowSaveLoadDialog(int mode);
 
// callback from drivers that is called if the game size changes dynamically
 
void GameSizeChanged(void);
 
bool FileExists(const char *filename);
 
bool ReadLanguagePack(int index);
 
void InitializeLanguagePacks(void);
 
const char *GetCurrentLocale(const char *param);
 
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
 

	
 
void LoadFromConfig(void);
 
void SaveToConfig(void);
 
void CheckConfig(void);
 
int ttd_main(int argc, char* argv[]);
 
void HandleExitGameRequest(void);
 

	
 
void DeterminePaths(void);
 

	
 
void CSleep(int milliseconds);
 
#endif /* FUNCTIONS_H */
intro_gui.c
Show inline comments
 
@@ -68,25 +68,25 @@ static void SelectGameWndProc(Window *w,
 
				ShowNetworkGameWindow();
 
			}
 
#else
 
			ShowErrorMessage(INVALID_STRING_ID ,STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
 
#endif
 
			break;
 
		case 8: case 9: case 10: case 11:
 
			SetNewLandscapeType(e->click.widget - 8);
 
			break;
 
		case 12: ShowGameOptions(); break;
 
		case 13: ShowGameDifficulty(); break;
 
		case 14: ShowPatchesSelection(); break;
 
		case 15: AskExitGame(); break;
 
		case 15: HandleExitGameRequest(); break;
 
		}
 
		break;
 

	
 
		case WE_ON_EDIT_TEXT: HandleOnEditText(e); break;
 
	}
 
}
 

	
 
static const WindowDesc _select_game_desc = {
 
	WDP_CENTER, WDP_CENTER, 336, 177,
 
	WC_SELECT_GAME,0,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
 
	_select_game_widgets,
main_gui.c
Show inline comments
 
@@ -161,32 +161,32 @@ static void MenuClickSettings(int index)
 
		case 12: _display_opt ^= DO_TRANS_SIGNS;        break;
 
	}
 
	MarkWholeScreenDirty();
 
}
 

	
 
static void MenuClickSaveLoad(int index)
 
{
 
	if (_game_mode == GM_EDITOR) {
 
		switch (index) {
 
			case 0: ShowSaveLoadDialog(SLD_SAVE_SCENARIO); break;
 
			case 1: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
 
			case 2: AskExitToGameMenu();                   break;
 
			case 4: AskExitGame();                         break;
 
			case 4: HandleExitGameRequest();               break;
 
		}
 
	} else {
 
		switch (index) {
 
			case 0: ShowSaveLoadDialog(SLD_SAVE_GAME); break;
 
			case 1: ShowSaveLoadDialog(SLD_LOAD_GAME); break;
 
			case 2: AskExitToGameMenu();               break;
 
			case 3: AskExitGame();                     break;
 
			case 3: HandleExitGameRequest();           break;
 
		}
 
	}
 
}
 

	
 
static void MenuClickMap(int index)
 
{
 
	switch (index) {
 
		case 0: ShowSmallMap();            break;
 
		case 1: ShowExtraViewPortWindow(); break;
 
		case 2: ShowSignList();            break;
 
	}
 
}
 
@@ -2217,25 +2217,25 @@ static void MainWindowWndProc(Window *w,
 
			DrawSprite(SPR_OTTD_C, off_x + 447, 50);
 
			DrawSprite(SPR_OTTD_O, off_x + 478, 50);
 
			DrawSprite(SPR_OTTD_O, off_x + 509, 50);
 
			DrawSprite(SPR_OTTD_N, off_x + 541, 50);
 
			*/
 
		}
 
		break;
 

	
 
	case WE_KEYPRESS:
 
		switch (e->keypress.keycode) {
 
			case 'Q' | WKC_CTRL:
 
			case 'Q' | WKC_META:
 
				AskExitGame();
 
				HandleExitGameRequest();
 
				break;
 
		}
 

	
 
		/* Disable all key shortcuts, except quit shortcuts when
 
		 * generating the world, otherwise they create threading
 
		 * problem during the generating, resulting in random
 
		 * assertions that are hard to trigger and debug */
 
		if (IsGeneratingWorld()) break;
 

	
 
		if (e->keypress.keycode == WKC_BACKQUOTE) {
 
			IConsoleSwitch();
 
			e->keypress.cont = false;
openttd.c
Show inline comments
 
@@ -528,24 +528,37 @@ int ttd_main(int argc, char *argv[])
 
	UnInitializeDynamicVariables();
 

	
 
	/* stop the AI */
 
	AI_Uninitialize();
 

	
 
	/* Close all and any open filehandles */
 
	FioCloseAll();
 
	UnInitializeGame();
 

	
 
	return 0;
 
}
 

	
 
void HandleExitGameRequest(void)
 
{
 
	if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
 
		_exit_game = true;
 
	} else if (_patches.autosave_on_exit) {
 
		DoExitSave();
 
		_exit_game = true;
 
	} else {
 
		AskExitGame();
 
	}
 
}
 

	
 

	
 
/** Mutex so that only one thread can communicate with the main program
 
 * at any given time */
 
static ThreadMsg _message = MSG_OTTD_NO_MESSAGE;
 

	
 
static inline void OTTD_ReleaseMutex(void) {_message = MSG_OTTD_NO_MESSAGE;}
 
static inline ThreadMsg OTTD_PollThreadEvent(void) {return _message;}
 

	
 
/** Called by running thread to execute some action in the main game.
 
 * It will stall as long as the mutex is not freed (handled) by the game */
 
void OTTD_SendThreadMessage(ThreadMsg msg)
 
{
 
	if (_exit_game) return;
saveload.h
Show inline comments
 
@@ -11,24 +11,25 @@ typedef enum SaveOrLoadResult {
 

	
 
typedef enum SaveOrLoadMode {
 
	SL_INVALID  = -1,
 
	SL_LOAD     =  0,
 
	SL_SAVE     =  1,
 
	SL_OLD_LOAD =  2,
 
	SL_PNG      =  3,
 
	SL_BMP      =  4,
 
} SaveOrLoadMode;
 

	
 
SaveOrLoadResult SaveOrLoad(const char *filename, int mode);
 
void WaitTillSaved(void);
 
void DoExitSave(void);
 

	
 

	
 
typedef void ChunkSaveLoadProc(void);
 
typedef void AutolengthProc(void *arg);
 

	
 
typedef struct {
 
	uint32 id;
 
	ChunkSaveLoadProc *save_proc;
 
	ChunkSaveLoadProc *load_proc;
 
	uint32 flags;
 
} ChunkHandler;
 

	
video/cocoa_v.m
Show inline comments
 
@@ -188,40 +188,24 @@ static uint32 GetTick(void)
 
}
 

	
 
static void QZ_CheckPaletteAnim(void)
 
{
 
	if (_pal_last_dirty != -1) {
 
		QZ_UpdatePalette(_pal_first_dirty, _pal_last_dirty - _pal_first_dirty + 1);
 
		_pal_last_dirty = -1;
 
	}
 
}
 

	
 

	
 

	
 
extern void DoExitSave(void);
 

	
 
static void QZ_AskQuit(void)
 
{
 
	if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
 
		_exit_game = true;
 
	} else if (_patches.autosave_on_exit) {
 
		DoExitSave();
 
		_exit_game = true;
 
	} else {
 
		AskExitGame();
 
	}
 
}
 

	
 

	
 

	
 
typedef struct VkMapping {
 
	unsigned short vk_from;
 
	byte map_to;
 
} VkMapping;
 

	
 
#define AS(x, z) {x, z}
 

	
 
static const VkMapping _vk_mapping[] = {
 
	AS(QZ_BACKQUOTE,  WKC_BACKQUOTE), // key left of '1'
 
	AS(QZ_BACKQUOTE2, WKC_BACKQUOTE), // some keyboards have it on another scancode
 

	
 
	// Pageup stuff + up/down
 
@@ -912,25 +896,25 @@ static void QZ_SetPortAlphaOpaque(void)
 

	
 
	[ [ NSNotificationCenter defaultCenter ] addObserver:self
 
	selector:@selector(appWillUnhide:) name:NSApplicationWillUnhideNotification object:NSApp ];
 

	
 
	return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ];
 
}
 

	
 
@end
 

	
 
@implementation OTTD_QuartzWindowDelegate
 
- (BOOL)windowShouldClose:(id)sender
 
{
 
	QZ_AskQuit();
 
	HandleExitGameRequest();
 

	
 
	return NO;
 
}
 

	
 
- (void)windowDidBecomeKey:(NSNotification*)aNotification
 
{
 
	_cocoa_video_data.active = true;
 
}
 

	
 
- (void)windowDidResignKey:(NSNotification*)aNotification
 
{
 
	_cocoa_video_data.active = false;
video/sdl_v.c
Show inline comments
 
@@ -294,26 +294,24 @@ static uint32 ConvertSdlKeyIntoMy(SDL_ke
 
	if (sym->mod & KMOD_META)  key |= WKC_META;
 
	if (sym->mod & KMOD_SHIFT) key |= WKC_SHIFT;
 
	if (sym->mod & KMOD_CTRL)  key |= WKC_CTRL;
 
	if (sym->mod & KMOD_ALT)   key |= WKC_ALT;
 
	// these two lines really help porting hotkey combos. Uncomment to use -- Bjarni
 
#if 0
 
	printf("scancode character pressed %d\n", sym->scancode);
 
	printf("unicode character pressed %d\n", sym->unicode);
 
#endif
 
	return (key << 16) + sym->unicode;
 
}
 

	
 
extern void DoExitSave(void);
 

	
 
static int PollEvent(void)
 
{
 
	SDL_Event ev;
 

	
 
	if (!SDL_CALL SDL_PollEvent(&ev)) return -2;
 

	
 
	switch (ev.type) {
 
		case SDL_MOUSEMOTION:
 
			if (_cursor.fix_at) {
 
				int dx = ev.motion.x - _cursor.pos.x;
 
				int dy = ev.motion.y - _cursor.pos.y;
 
				if (dx != 0 || dy != 0) {
 
@@ -367,39 +365,27 @@ static int PollEvent(void)
 

	
 
		case SDL_ACTIVEEVENT:
 
			if (!(ev.active.state & SDL_APPMOUSEFOCUS)) break;
 

	
 
			if (ev.active.gain) { // mouse entered the window, enable cursor
 
				_cursor.in_window = true;
 
			} else {
 
				UndrawMouseCursor(); // mouse left the window, undraw cursor
 
				_cursor.in_window = false;
 
			}
 
			break;
 

	
 
		case SDL_QUIT:
 
			// do not ask to quit on the main screen
 
			if (_game_mode != GM_MENU) {
 
				if (_patches.autosave_on_exit) {
 
					DoExitSave();
 
					return 0;
 
				} else {
 
					AskExitGame();
 
				}
 
			} else {
 
				return 0;
 
			}
 
			break;
 
		case SDL_QUIT: HandleExitGameRequest(); break;
 

	
 
			case SDL_KEYDOWN: /* Toggle full-screen on ALT + ENTER/F */
 
		case SDL_KEYDOWN: /* Toggle full-screen on ALT + ENTER/F */
 
			if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) &&
 
					(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) {
 
				ToggleFullScreen(!_fullscreen);
 
			} else {
 
				_pressed_key = ConvertSdlKeyIntoMy(&ev.key.keysym);
 
			}
 

	
 
			break;
 

	
 
		case SDL_VIDEORESIZE: {
 
			int w = clamp(ev.resize.w, 64, MAX_SCREEN_WIDTH);
 
			int h = clamp(ev.resize.h, 64, MAX_SCREEN_HEIGHT);
 
@@ -439,26 +425,24 @@ static void SdlVideoMainLoop(void)
 
	uint32 next_tick = SDL_CALL SDL_GetTicks() + 30;
 
	uint32 cur_ticks;
 
	uint32 pal_tick = 0;
 
	int i;
 
	uint32 mod;
 
	int numkeys;
 
	Uint8 *keys;
 

	
 
	for (;;) {
 
		InteractiveRandom(); // randomness
 

	
 
		while ((i = PollEvent()) == -1) {}
 
		if (i >= 0) return;
 

	
 
		if (_exit_game) return;
 

	
 
		mod = SDL_CALL SDL_GetModState();
 
		keys = SDL_CALL SDL_GetKeyState(&numkeys);
 
#if defined(_DEBUG)
 
		if (_shift_pressed)
 
#else
 
		if (keys[SDLK_TAB])
 
#endif
 
		{
 
			if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
 
		} else if (_fast_forward & 2) {
video/win32_v.c
Show inline comments
 
@@ -142,26 +142,24 @@ static void ClientSizeChanged(int w, int
 
		_pal_first_dirty = 0;
 
		_pal_last_dirty = 255;
 
		GameSizeChanged();
 

	
 
		// redraw screen
 
		if (_wnd.running) {
 
			_screen.dst_ptr = _wnd.buffer_bits;
 
			UpdateWindows();
 
		}
 
	}
 
}
 

	
 
extern void DoExitSave(void);
 

	
 
#ifdef _DEBUG
 
// Keep this function here..
 
// It allows you to redraw the screen from within the MSVC debugger
 
int RedrawScreenDebug(void)
 
{
 
	HDC dc,dc2;
 
	static int _fooctr;
 
	HBITMAP old_bmp;
 
	HPALETTE old_palette;
 

	
 
	_screen.dst_ptr = _wnd.buffer_bits;
 
	UpdateWindows();
 
@@ -247,32 +245,25 @@ static LRESULT CALLBACK WndProcGdi(HWND 
 
		case WM_QUERYNEWPALETTE: {
 
			HDC hDC = GetWindowDC(hwnd);
 
			HPALETTE hOldPalette = SelectPalette(hDC, _wnd.gdi_palette, FALSE);
 
			UINT nChanged = RealizePalette(hDC);
 

	
 
			SelectPalette(hDC, hOldPalette, TRUE);
 
			ReleaseDC(hwnd, hDC);
 
			if (nChanged) InvalidateRect(hwnd, NULL, FALSE);
 
			return 0;
 
		}
 

	
 
		case WM_CLOSE:
 
			if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
 
				_exit_game = true;
 
			} else if (_patches.autosave_on_exit) {
 
				DoExitSave();
 
				_exit_game = true;
 
			} else {
 
				AskExitGame();
 
			}
 
			HandleExitGameRequest();
 
			_window_maximize = IsZoomed(_wnd.main_wnd);
 
			return 0;
 

	
 
		case WM_LBUTTONDOWN:
 
			SetCapture(hwnd);
 
			_left_button_down = true;
 
			return 0;
 

	
 
		case WM_LBUTTONUP:
 
			ReleaseCapture();
 
			_left_button_down = false;
 
			_left_button_clicked = false;
0 comments (0 inline, 0 general)