SAFERHANGUP win32gui (from <Someone>)
This commit is contained in:
@@ -57,12 +57,13 @@
|
|||||||
|
|
||||||
#ifdef WIN32CON
|
#ifdef WIN32CON
|
||||||
#define PORT_DEBUG /* include ability to debug international keyboard issues */
|
#define PORT_DEBUG /* include ability to debug international keyboard issues */
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SAFERHANGUP /* Define SAFERHANGUP to delay hangup processing
|
#define SAFERHANGUP /* Define SAFERHANGUP to delay hangup processing
|
||||||
* until the main command loop. 'safer' because it
|
* until the main command loop. 'safer' because it
|
||||||
* avoids certain cheats and also avoids losing
|
* avoids certain cheats and also avoids losing
|
||||||
* objects being thrown when the hangup occurs.
|
* objects being thrown when the hangup occurs.
|
||||||
*/
|
*/
|
||||||
#endif
|
|
||||||
|
|
||||||
/* The following is needed for prototypes of certain functions */
|
/* The following is needed for prototypes of certain functions */
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
|||||||
@@ -33,7 +33,12 @@ void mswin_nh_input_init(void)
|
|||||||
/* check for input */
|
/* check for input */
|
||||||
int mswin_have_input()
|
int mswin_have_input()
|
||||||
{
|
{
|
||||||
return (nhi_read_pos!=nhi_write_pos);
|
return
|
||||||
|
#ifdef SAFERHANGUP
|
||||||
|
/* we always have input (ESC) if hangup was requested */
|
||||||
|
program_state.done_hup ||
|
||||||
|
#endif
|
||||||
|
(nhi_read_pos!=nhi_write_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add event to the queue */
|
/* add event to the queue */
|
||||||
@@ -57,6 +62,16 @@ PMSNHEvent mswin_input_pop()
|
|||||||
{
|
{
|
||||||
PMSNHEvent retval;
|
PMSNHEvent retval;
|
||||||
|
|
||||||
|
#ifdef SAFERHANGUP
|
||||||
|
/* always return ESC when hangup was requested */
|
||||||
|
if( program_state.done_hup ) {
|
||||||
|
static MSNHEvent hangup_event;
|
||||||
|
hangup_event.type = NHEVENT_CHAR;
|
||||||
|
hangup_event.kbd.ch = '\033';
|
||||||
|
return &hangup_event;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if( !nhi_init_input ) mswin_nh_input_init();
|
if( !nhi_init_input ) mswin_nh_input_init();
|
||||||
|
|
||||||
if( nhi_read_pos!=nhi_write_pos ) {
|
if( nhi_read_pos!=nhi_write_pos ) {
|
||||||
@@ -74,6 +89,16 @@ PMSNHEvent mswin_input_peek()
|
|||||||
{
|
{
|
||||||
PMSNHEvent retval;
|
PMSNHEvent retval;
|
||||||
|
|
||||||
|
#ifdef SAFERHANGUP
|
||||||
|
/* always return ESC when hangup was requested */
|
||||||
|
if( program_state.done_hup ) {
|
||||||
|
static MSNHEvent hangup_event;
|
||||||
|
hangup_event.type = NHEVENT_CHAR;
|
||||||
|
hangup_event.kbd.ch = '\033';
|
||||||
|
return &hangup_event;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if( !nhi_init_input ) mswin_nh_input_init();
|
if( !nhi_init_input ) mswin_nh_input_init();
|
||||||
|
|
||||||
if( nhi_read_pos!=nhi_write_pos ) {
|
if( nhi_read_pos!=nhi_write_pos ) {
|
||||||
|
|||||||
@@ -496,8 +496,21 @@ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* prompt user for action */
|
||||||
switch (NHMessageBox(hWnd, TEXT("Save?"), MB_YESNOCANCEL | MB_ICONQUESTION)) {
|
switch (NHMessageBox(hWnd, TEXT("Save?"), MB_YESNOCANCEL | MB_ICONQUESTION)) {
|
||||||
case IDYES: NHEVENT_KBD('y'); dosave(); break;
|
case IDYES:
|
||||||
|
#ifdef SAFERHANGUP
|
||||||
|
/* destroy popup window - it has its own loop and we need to
|
||||||
|
return control to NetHack core at this point */
|
||||||
|
if( IsWindow( GetNHApp()->hPopupWnd ) )
|
||||||
|
SendMessage( GetNHApp()->hPopupWnd, WM_COMMAND, IDCANCEL, 0);
|
||||||
|
|
||||||
|
/* tell NetHack core that "hangup" is requested */
|
||||||
|
hangup(1);
|
||||||
|
#else
|
||||||
|
NHEVENT_KBD('y'); dosave();
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
case IDNO: NHEVENT_KBD('q'); done(QUIT); break;
|
case IDNO: NHEVENT_KBD('q'); done(QUIT); break;
|
||||||
case IDCANCEL: break;
|
case IDCANCEL: break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user