Make it possible to see comms dialog in read-only mode when role

selector is disabled (for game info use of new game dialog.)
This commit is contained in:
ehouse 2009-02-21 17:03:30 +00:00
parent ae0b8211fe
commit 7248ee8ad9
5 changed files with 64 additions and 27 deletions

View file

@ -23,6 +23,7 @@ PLATFORM = wince
TARGET_OS ?= win32 TARGET_OS ?= win32
#TARGET_OS = wince #TARGET_OS = wince
#NO_DRAW = -DNO_DRAW
# The preferred build environment for wince is now cegcc. Debian's # The preferred build environment for wince is now cegcc. Debian's
# pocketpc-sdk works in combination with the mingw projects headers, # pocketpc-sdk works in combination with the mingw projects headers,
@ -81,7 +82,6 @@ else # ifeq ($(TARGET_OS),wince)
ifeq ($(TARGET_OS),win32) ifeq ($(TARGET_OS),win32)
#STANDALONE = -DXWFEATURE_STANDALONE_ONLY #STANDALONE = -DXWFEATURE_STANDALONE_ONLY
STANDALONE = -DPREV_WAS_STANDALONE_ONLY STANDALONE = -DPREV_WAS_STANDALONE_ONLY
# NO_DRAW = -DNO_DRAW
#BLUETOOTH = -DXWFEATURE_BLUETOOTH #BLUETOOTH = -DXWFEATURE_BLUETOOTH
#SMS = -DXWFEATURE_SMS #SMS = -DXWFEATURE_SMS
RELAY = -DXWFEATURE_RELAY -DUSE_BUFQUEUE RELAY = -DXWFEATURE_RELAY -DUSE_BUFQUEUE

View file

@ -36,6 +36,7 @@ typedef struct _CeConnDlgState {
XP_U16 connComboId; XP_U16 connComboId;
ConnDlgPair* types; ConnDlgPair* types;
XP_Bool userCancelled; XP_Bool userCancelled;
XP_Bool forShowOnly;
} CeConnDlgState; } CeConnDlgState;
static CommsConnType indexToConType( const CeConnDlgState* state, static CommsConnType indexToConType( const CeConnDlgState* state,
@ -180,6 +181,8 @@ ceControlsFromAddrRec( HWND hDlg, const CeConnDlgState* state )
XP_U16 ii; XP_U16 ii;
CEAppGlobals* globals = state->dlgHdr.globals; CEAppGlobals* globals = state->dlgHdr.globals;
CommsConnType conType; CommsConnType conType;
XP_U16 ids[32];
XP_S16 nIds = 0;
for ( ii = 0; ; ++ii ) { for ( ii = 0; ; ++ii ) {
ConnDlgPair* type = &state->types[ii]; ConnDlgPair* type = &state->types[ii];
@ -194,37 +197,53 @@ ceControlsFromAddrRec( HWND hDlg, const CeConnDlgState* state )
SendDlgItemMessage( hDlg, state->connComboId, SETCURSEL(globals), SendDlgItemMessage( hDlg, state->connComboId, SETCURSEL(globals),
conTypeToIndex(state, state->addrRec.conType), 0L ); conTypeToIndex(state, state->addrRec.conType), 0L );
ids[nIds++] = state->connComboId;
conType = state->addrRec.conType; conType = state->addrRec.conType;
if ( state->addrRec.conType == COMMS_CONN_RELAY ) { if ( state->addrRec.conType == COMMS_CONN_RELAY ) {
#ifdef XWFEATURE_RELAY #ifdef XWFEATURE_RELAY
ceSetDlgItemText( hDlg, RELAYNAME_EDIT, ceSetDlgItemText( hDlg, RELAYNAME_EDIT,
state->addrRec.u.ip_relay.hostName ); state->addrRec.u.ip_relay.hostName );
ids[nIds++] = RELAYNAME_EDIT;
ceSetDlgItemNum( hDlg, RELAYPORT_EDIT, ceSetDlgItemNum( hDlg, RELAYPORT_EDIT,
state->addrRec.u.ip_relay.port ); state->addrRec.u.ip_relay.port );
ids[nIds++] = RELAYPORT_EDIT;
ceSetDlgItemText( hDlg, COOKIE_EDIT, ceSetDlgItemText( hDlg, COOKIE_EDIT,
state->addrRec.u.ip_relay.cookie ); state->addrRec.u.ip_relay.cookie );
ids[nIds++] = COOKIE_EDIT;
#endif #endif
} else if ( state->addrRec.conType == COMMS_CONN_IP_DIRECT ) { } else if ( state->addrRec.conType == COMMS_CONN_IP_DIRECT ) {
#ifdef XWFEATURE_IP_DIRECT #ifdef XWFEATURE_IP_DIRECT
ceSetDlgItemText( hDlg, IPNAME_EDIT, state->addrRec.u.ip.hostName_ip ); ceSetDlgItemText( hDlg, IPNAME_EDIT, state->addrRec.u.ip.hostName_ip );
ids[nIds++] = IPNAME_EDIT;
#endif #endif
} else if ( state->addrRec.conType == COMMS_CONN_BT ) { } else if ( state->addrRec.conType == COMMS_CONN_BT ) {
#ifdef XWFEATURE_BLUETOOTH #ifdef XWFEATURE_BLUETOOTH
if ( state->role == SERVER_ISCLIENT ) { if ( state->role == SERVER_ISCLIENT ) {
ceSetDlgItemText( hDlg, IDC_BLUET_ADDR_EDIT, ceSetDlgItemText( hDlg, IDC_BLUET_ADDR_EDIT,
state->addrRec.u.bt.hostName ); state->addrRec.u.bt.hostName );
ids[nIds++] = IDC_BLUET_ADDR_EDIT;
} }
#endif #endif
} else if ( state->addrRec.conType == COMMS_CONN_SMS ) { } else if ( state->addrRec.conType == COMMS_CONN_SMS ) {
#ifdef XWFEATURE_SMS #ifdef XWFEATURE_SMS
ceSetDlgItemText( hDlg, IDC_SMS_PHONE_EDIT, state->addrRec.u.sms.phone ); ceSetDlgItemText( hDlg, IDC_SMS_PHONE_EDIT, state->addrRec.u.sms.phone );
ids[nIds++] = IDC_SMS_PHONE_EDIT;
ceSetDlgItemNum( hDlg, IDC_SMS_PORT_EDIT, state->addrRec.u.sms.port ); ceSetDlgItemNum( hDlg, IDC_SMS_PORT_EDIT, state->addrRec.u.sms.port );
ids[nIds++] = IDC_SMS_PORT_EDIT;
#endif #endif
} else { } else {
XP_ASSERT(0); XP_ASSERT(0);
} }
}
XP_ASSERT( nIds < VSIZE(ids) );
if ( state->forShowOnly ) {
while ( nIds-- > 0 ) {
ceEnOrDisable( hDlg, ids[nIds], XP_FALSE );
}
}
} /* ceControlsFromAddrRec */
static LRESULT CALLBACK static LRESULT CALLBACK
ConnsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) ConnsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
@ -283,7 +302,7 @@ ConnsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
XP_Bool XP_Bool
WrapConnsDlg( HWND hDlg, CEAppGlobals* globals, const CommsAddrRec* addrRecIn, WrapConnsDlg( HWND hDlg, CEAppGlobals* globals, const CommsAddrRec* addrRecIn,
CommsAddrRec* addrRecOut, DeviceRole role ) CommsAddrRec* addrRecOut, DeviceRole role, XP_Bool isNewGame )
{ {
XP_Bool result; XP_Bool result;
CeConnDlgState state; CeConnDlgState state;
@ -305,12 +324,13 @@ WrapConnsDlg( HWND hDlg, CEAppGlobals* globals, const CommsAddrRec* addrRecIn,
state.dlgHdr.globals = globals; state.dlgHdr.globals = globals;
state.types = types; state.types = types;
state.role = role; state.role = role;
state.forShowOnly = !isNewGame;
XP_MEMCPY( &state.addrRec, addrRecIn, sizeof(state.addrRec) ); XP_MEMCPY( &state.addrRec, addrRecIn, sizeof(state.addrRec) );
DialogBoxParam( globals->hInst, (LPCTSTR)IDD_CONNSSDLG, hDlg, DialogBoxParam( globals->hInst, (LPCTSTR)IDD_CONNSSDLG, hDlg,
(DLGPROC)ConnsDlg, (long)&state ); (DLGPROC)ConnsDlg, (long)&state );
result = !state.userCancelled; result = isNewGame && !state.userCancelled;
if ( result ) { if ( result ) {
XP_MEMCPY( addrRecOut, &state.addrRec, sizeof(*addrRecOut) ); XP_MEMCPY( addrRecOut, &state.addrRec, sizeof(*addrRecOut) );

View file

@ -26,7 +26,7 @@
#include "ceutil.h" #include "ceutil.h"
XP_Bool WrapConnsDlg( HWND hDlg, CEAppGlobals* globals, XP_Bool WrapConnsDlg( HWND hDlg, CEAppGlobals* globals,
const CommsAddrRec* addrRecIn, const CommsAddrRec* addrRecIn, CommsAddrRec* addrRecOut,
CommsAddrRec* addrRecOut, DeviceRole role ); DeviceRole role, XP_Bool isNewGame );
#endif #endif

View file

@ -89,6 +89,7 @@ messageToStr( UINT message )
CASE_STR( WM_EXITMENULOOP ); CASE_STR( WM_EXITMENULOOP );
CASE_STR( WM_INITMENUPOPUP ); CASE_STR( WM_INITMENUPOPUP );
CASE_STR( WM_CANCELMODE ); CASE_STR( WM_CANCELMODE );
CASE_STR( WM_ENTERIDLE );
default: default:
str = "<unknown>"; str = "<unknown>";
} }

View file

@ -325,9 +325,11 @@ handlePrefsButton( HWND hDlg, CEAppGlobals* globals, GameInfoState* state )
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
static void static void
handleConnOptionsButton( HWND hDlg, CEAppGlobals* globals, handleConnOptionsButton( GameInfoState* state, DeviceRole role )
DeviceRole role, GameInfoState* state )
{ {
HWND hDlg = state->dlgHdr.hDlg;
CEAppGlobals* globals = state->dlgHdr.globals;
if ( role == SERVER_STANDALONE ) { if ( role == SERVER_STANDALONE ) {
NGValue value; NGValue value;
role = (DeviceRole)SendDlgItemMessage( hDlg, role = (DeviceRole)SendDlgItemMessage( hDlg,
@ -338,17 +340,15 @@ handleConnOptionsButton( HWND hDlg, CEAppGlobals* globals,
newg_attrChanged( state->newGameCtx, NG_ATTR_ROLE, value ); newg_attrChanged( state->newGameCtx, NG_ATTR_ROLE, value );
} }
if ( role != state->lastRole ) { state->lastRole = role;
state->lastRole = role; if ( role != SERVER_STANDALONE) {
if ( WrapConnsDlg( hDlg, globals, &state->prefsPrefs.addrRec,
if ( role != SERVER_STANDALONE) { &state->prefsPrefs.addrRec, role,
if ( WrapConnsDlg( hDlg, globals, &state->prefsPrefs.addrRec, state->isNewGame ) ) {
&state->prefsPrefs.addrRec, role ) ) { state->addrChanged = XP_TRUE;
state->addrChanged = XP_TRUE;
}
} }
} }
} } /* handleConnOptionsButton */
#endif #endif
static XP_U16 static XP_U16
@ -582,11 +582,26 @@ checkUpdateCombo( GameInfoState* state, XP_U16 id )
} }
} else if ( id == state->roleComboId ) { } else if ( id == state->roleComboId ) {
XP_ASSERT( SERVER_STANDALONE == 0 ); XP_ASSERT( SERVER_STANDALONE == 0 );
handleConnOptionsButton( hDlg, state->dlgHdr.globals, handleConnOptionsButton( state, SERVER_STANDALONE );
SERVER_STANDALONE, state );
} }
} /* checkUpdateCombo */ } /* checkUpdateCombo */
/* If we're mid-game and can't change role, click on role dropdown should
* still bring up conns dialog in read-only mode.
*/
static void
checkRoleClick( GameInfoState* state, XP_U16 xx, XP_U16 yy )
{
RECT rect;
ceGetItemRect( state->dlgHdr.hDlg, state->roleComboId, &rect );
/* Isn't there API for PtInRect? */
if ( xx > rect.left && xx < rect.right
&& yy > rect.top && yy < rect.bottom ) {
handleConnOptionsButton( state, state->lastRole );
}
} /* checkRoleClick */
LRESULT CALLBACK LRESULT CALLBACK
GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ {
@ -659,6 +674,12 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
} }
break; break;
case WM_LBUTTONUP:
if ( !state->isNewGame ) {
checkRoleClick( state, LOWORD(lParam), HIWORD(lParam) );
}
break;
case WM_COMMAND: case WM_COMMAND:
result = TRUE; result = TRUE;
id = LOWORD(wParam); id = LOWORD(wParam);
@ -690,14 +711,9 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
case IDC_ROLECOMBO: case IDC_ROLECOMBO:
case IDC_ROLECOMBO_PPC: case IDC_ROLECOMBO_PPC:
if ( HIWORD(wParam) == CBN_SELCHANGE ) { if ( HIWORD(wParam) == CBN_SELCHANGE ) {
if ( state->isNewGame ) { /* ignore if in info /* If we've switched to a state where we'll be
mode */ connecting */
/* If we've switched to a state where we'll be handleConnOptionsButton( state, SERVER_STANDALONE );
connecting */
handleConnOptionsButton( hDlg, globals,
SERVER_STANDALONE,
state );
}
} }
break; break;
#endif #endif