Clean up saved games dialogs, and remove (temporarily) controls that

won't do anything for b2.  Rename a couple of structs.
This commit is contained in:
ehouse 2008-04-13 17:14:16 +00:00
parent 536de24e1d
commit d7d8c054b2
3 changed files with 102 additions and 64 deletions

View file

@ -26,21 +26,20 @@
#include "ceutil.h" #include "ceutil.h"
#include "cedebug.h" #include "cedebug.h"
typedef struct SaveGameNameState { typedef struct CeSaveGameNameState {
CEAppGlobals* globals; CEAppGlobals* globals;
/* HWND hDlg; */
wchar_t* buf; wchar_t* buf;
XP_U16 buflen; XP_U16 buflen;
XP_Bool cancelled; XP_Bool cancelled;
XP_Bool inited; XP_Bool inited;
} SaveGameNameState; } CeSaveGameNameState;
static void /* static void */
notImpl( CEAppGlobals* globals ) /* notImpl( CEAppGlobals* globals ) */
{ /* { */
messageBoxChar( globals, "To be implemented soon....", /* messageBoxChar( globals, "To be implemented soon....", */
L"Notice", MB_OK ); /* L"Notice", MB_OK ); */
} /* } */
static XP_Bool static XP_Bool
ceFileExists( const wchar_t* name ) ceFileExists( const wchar_t* name )
@ -58,7 +57,8 @@ makeUniqueName( wchar_t* buf, XP_U16 bufLen )
{ {
XP_U16 ii; XP_U16 ii;
for ( ii = 1; ii < 100; ++ii ) { for ( ii = 1; ii < 100; ++ii ) {
swprintf( buf, L"Untitled%d", ii ); int len = swprintf( buf, L"Untitled%d", ii );
XP_ASSERT( len < bufLen );
if ( !ceFileExists( buf ) ) { if ( !ceFileExists( buf ) ) {
break; break;
} }
@ -70,14 +70,14 @@ makeUniqueName( wchar_t* buf, XP_U16 bufLen )
static LRESULT CALLBACK static LRESULT CALLBACK
SaveNameDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) SaveNameDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{ {
SaveGameNameState* state; CeSaveGameNameState* state;
XP_U16 wid; XP_U16 wid;
BOOL result = FALSE; BOOL result = FALSE;
if ( message == WM_INITDIALOG ) { if ( message == WM_INITDIALOG ) {
SetWindowLong( hDlg, GWL_USERDATA, lParam ); SetWindowLong( hDlg, GWL_USERDATA, lParam );
state = (SaveGameNameState*)lParam; state = (CeSaveGameNameState*)lParam;
state->cancelled = XP_TRUE; state->cancelled = XP_TRUE;
state->inited = XP_FALSE; state->inited = XP_FALSE;
@ -85,11 +85,11 @@ SaveNameDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
result = TRUE; result = TRUE;
} else { } else {
state = (SaveGameNameState*)GetWindowLong( hDlg, GWL_USERDATA ); state = (CeSaveGameNameState*)GetWindowLong( hDlg, GWL_USERDATA );
if ( !!state ) { if ( !!state ) {
if ( !state->inited ) { if ( !state->inited ) {
(void)SetDlgItemText( hDlg, IDC_SVGN_EDIT, state->buf );
state->inited = XP_TRUE; state->inited = XP_TRUE;
(void)SetDlgItemText( hDlg, IDC_SVGN_EDIT, state->buf );
} }
switch (message) { switch (message) {
@ -119,12 +119,12 @@ SaveNameDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
} }
} }
return result; return result;
} } /* SaveNameDlg */
XP_Bool XP_Bool
ceConfirmUniqueName( CEAppGlobals* globals, wchar_t* buf, XP_U16 buflen ) ceConfirmUniqueName( CEAppGlobals* globals, wchar_t* buf, XP_U16 buflen )
{ {
SaveGameNameState state; CeSaveGameNameState state;
LOG_FUNC(); LOG_FUNC();
@ -141,21 +141,22 @@ ceConfirmUniqueName( CEAppGlobals* globals, wchar_t* buf, XP_U16 buflen )
return !state.cancelled; return !state.cancelled;
} /* ceConfirmUniqueName */ } /* ceConfirmUniqueName */
typedef struct SavedGamesState { typedef struct CeSavedGamesState {
CEAppGlobals* globals; CEAppGlobals* globals;
HWND hDlg; HWND hDlg;
wchar_t* buf; wchar_t* buf;
XP_U16 buflen; XP_U16 buflen;
XP_S16 sel; XP_S16 sel;
wchar_t curName[128]; wchar_t curName[128];
XP_U16 nItems;
/* wchar_t** names; */ /* wchar_t** names; */
/* XP_U16 nNamesUsed; */ /* XP_U16 nNamesUsed; */
/* XP_U16 nNamesAllocd; */ /* XP_U16 nNamesAllocd; */
XP_Bool cancelled; XP_Bool opened;
XP_Bool inited; XP_Bool inited;
} SavedGamesState; } CeSavedGamesState;
/* Probably belongs as a utility */ /* Probably belongs as a utility */
static void static void
@ -171,18 +172,26 @@ getCBText( HWND hDlg, XP_U16 id, XP_U16 sel, wchar_t* buf, XP_U16* lenp )
} /* getCBText */ } /* getCBText */
static void static void
setEditFromSel( SavedGamesState* state ) setEditFromSel( CeSavedGamesState* XP_UNUSED(state) )
{ {
wchar_t buf[64]; /* wchar_t buf[64]; */
XP_U16 len = VSIZE(buf); /* XP_U16 len = VSIZE(buf); */
getCBText( state->hDlg, IDC_SVGM_GAMELIST, state->sel, buf, &len ); /* getCBText( state->hDlg, IDC_SVGM_GAMELIST, state->sel, buf, &len ); */
if ( len <= VSIZE(buf) ) { /* if ( len <= VSIZE(buf) ) { */
(void)SetDlgItemText( state->hDlg, IDC_SVGM_EDIT, buf ); /* (void)SetDlgItemText( state->hDlg, IDC_SVGM_EDIT, buf ); */
} /* } */
} /* */ } /* */
static void static void
initSavedGamesData( SavedGamesState* state ) setButtons( CeSavedGamesState* state )
{
/* Open button disabled by default in case no games */
ceEnOrDisable( state->hDlg, IDC_SVGM_OPEN, state->nItems > 0 );
/* ceEnOrDisable( state->hDlg, IDC_SVGM_DEL, state->nItems > 0 ); */
}
static void
initSavedGamesData( CeSavedGamesState* state )
{ {
HANDLE fileH; HANDLE fileH;
WIN32_FIND_DATA data; WIN32_FIND_DATA data;
@ -208,6 +217,8 @@ initSavedGamesData( SavedGamesState* state )
SendDlgItemMessage( state->hDlg, IDC_SVGM_GAMELIST, ADDSTRING, SendDlgItemMessage( state->hDlg, IDC_SVGM_GAMELIST, ADDSTRING,
0, (LPARAM)data.cFileName ); 0, (LPARAM)data.cFileName );
++state->nItems;
if ( !FindNextFile( fileH, &data ) ) { if ( !FindNextFile( fileH, &data ) ) {
XP_ASSERT( GetLastError() == ERROR_NO_MORE_FILES ); XP_ASSERT( GetLastError() == ERROR_NO_MORE_FILES );
break; break;
@ -218,29 +229,51 @@ initSavedGamesData( SavedGamesState* state )
state->sel = curSel; state->sel = curSel;
setEditFromSel( state ); setEditFromSel( state );
setButtons( state );
LOG_RETURN_VOID(); LOG_RETURN_VOID();
} /* initSavedGamesData */ } /* initSavedGamesData */
/* static void */
/* deleteSelected( CeSavedGamesState* state ) */
/* { */
/* wchar_t buf[128]; */
/* wchar_t path[128]; */
/* XP_U16 len = VSIZE(buf); */
/* /\* confirm first!!!! *\/ */
/* getCBText( state->hDlg, IDC_SVGM_GAMELIST, state->sel, buf, &len ); */
/* swprintf( path, DEFAULT_DIR_NAME L"\\%s.xwg", buf ); */
/* DeleteFile( path ); */
/* SendDlgItemMessage( state->hDlg, IDC_SVGM_GAMELIST, DELETESTRING, */
/* state->sel, 0L ); */
/* --state->nItems; */
/* setButtons( state ); */
/* } */
static LRESULT CALLBACK static LRESULT CALLBACK
SavedGamesDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) SavedGamesDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{ {
SavedGamesState* state; CeSavedGamesState* state;
XP_U16 wid; XP_U16 wid;
BOOL result = FALSE; BOOL result = FALSE;
if ( message == WM_INITDIALOG ) { if ( message == WM_INITDIALOG ) {
SetWindowLong( hDlg, GWL_USERDATA, lParam ); SetWindowLong( hDlg, GWL_USERDATA, lParam );
state = (SavedGamesState*)lParam; state = (CeSavedGamesState*)lParam;
state->hDlg = hDlg; state->hDlg = hDlg;
state->cancelled = XP_TRUE;
state->inited = XP_FALSE; state->inited = XP_FALSE;
ceDlgSetup( state->globals, hDlg ); ceDlgSetup( state->globals, hDlg );
result = TRUE; result = TRUE;
} else { } else {
state = (SavedGamesState*)GetWindowLong( hDlg, GWL_USERDATA ); state = (CeSavedGamesState*)GetWindowLong( hDlg, GWL_USERDATA );
if ( !!state ) { if ( !!state ) {
if ( !state->inited ) { if ( !state->inited ) {
@ -278,25 +311,26 @@ SavedGamesDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
} }
break; break;
case IDC_SVGM_DUP: /* case IDC_SVGM_DUP: */
case IDC_SVGM_DEL: /* case IDC_SVGM_CHANGE: */
case IDC_SVGM_CHANGE: /* notImpl( state->globals ); */
notImpl( state->globals ); /* break; */
break; /* case IDC_SVGM_DEL: */
/* deleteSelected( state ); */
/* break; */
case IDC_SVGM_OPEN: { case IDC_SVGM_OPEN: {
wchar_t buf[128]; wchar_t buf[128];
XP_U16 len = sizeof(buf); XP_U16 len = VSIZE(buf);
getCBText( state->hDlg, IDC_SVGM_GAMELIST, state->sel, getCBText( state->hDlg, IDC_SVGM_GAMELIST, state->sel,
buf, &len ); buf, &len );
swprintf( state->buf, DEFAULT_DIR_NAME L"\\%s.xwg", buf ); swprintf( state->buf, DEFAULT_DIR_NAME L"\\%s.xwg", buf );
XP_LOGW( "returning", state->buf ); XP_LOGW( "returning", state->buf );
state->opened = XP_TRUE;
} }
/* fallthrough */ /* fallthrough */
case IDOK: case IDOK:
state->cancelled = XP_FALSE;
/* fallthrough */ /* fallthrough */
case IDCANCEL: case IDCANCEL:
EndDialog(hDlg, wid); EndDialog(hDlg, wid);
result = TRUE; result = TRUE;
@ -313,7 +347,7 @@ XP_Bool
ceSavedGamesDlg( CEAppGlobals* globals, const XP_UCHAR* curPath, ceSavedGamesDlg( CEAppGlobals* globals, const XP_UCHAR* curPath,
wchar_t* buf, XP_U16 buflen ) wchar_t* buf, XP_U16 buflen )
{ {
SavedGamesState state; CeSavedGamesState state;
LOG_FUNC(); LOG_FUNC();
@ -341,5 +375,5 @@ ceSavedGamesDlg( CEAppGlobals* globals, const XP_UCHAR* curPath,
XP_LOGW( __func__, buf ); XP_LOGW( __func__, buf );
return !state.cancelled; return state.opened;
} /*ceSavedGamesDlg */ } /*ceSavedGamesDlg */

View file

@ -162,11 +162,12 @@
#define IDC_SVGM_SELLAB 1109 #define IDC_SVGM_SELLAB 1109
#define IDC_SVGM_GAMELIST 1110 #define IDC_SVGM_GAMELIST 1110
#define IDC_SVGM_EDITLAB 1111 /* Let's remove these until they're implemented */
#define IDC_SVGM_CHANGE 1112 /* #define IDC_SVGM_EDITLAB 1111 */
#define IDC_SVGM_EDIT 1113 /* #define IDC_SVGM_CHANGE 1112 */
#define IDC_SVGM_DUP 1114 /* #define IDC_SVGM_EDIT 1113 */
#define IDC_SVGM_DEL 1115 /* #define IDC_SVGM_DUP 1114 */
/* #define IDC_SVGM_DEL 1115 */
#define IDC_SVGM_OPEN 1116 #define IDC_SVGM_OPEN 1116
#define IDC_SVGN_SELLAB 1117 #define IDC_SVGN_SELLAB 1117

View file

@ -378,13 +378,13 @@ CAPTION "Game name"
FONT 8, "System" FONT 8, "System"
BEGIN BEGIN
LTEXT "To save this game, give it a name. (You can change the name later using the Saved games dialog.)", LTEXT "To save this game, give it a name. (You can change the name later using the Saved games dialog.)",
IDC_SVGN_SELLAB,SVGN_LEFT_COL,SVGN_ROW_1,90,40 IDC_SVGN_SELLAB,SVGN_LEFT_COL,SVGN_ROW_1,86,40
EDITTEXT IDC_SVGN_EDIT,SVGN_LEFT_COL,SVGN_ROW_2,80,12, EDITTEXT IDC_SVGN_EDIT,SVGN_LEFT_COL,SVGN_ROW_2,86,12,
ES_AUTOHSCROLL ES_AUTOHSCROLL
#ifndef _WIN32_WCE #ifndef _WIN32_WCE
DEFPUSHBUTTON "OK",IDOK,SVGN_LEFT_COL,SVGN_ROW_3,REPOS_BUTTON_WIDTH, DEFPUSHBUTTON "OK",IDOK,SVGN_LEFT_COL+10,SVGN_ROW_3,REPOS_BUTTON_WIDTH,
BUTTON_HT BUTTON_HT
PUSHBUTTON "Cancel",IDCANCEL,SVGN_LEFT_COL+REPOS_BUTTON_WIDTH+10, PUSHBUTTON "Cancel",IDCANCEL,SVGN_LEFT_COL+10+REPOS_BUTTON_WIDTH+10,
SVGN_ROW_3,REPOS_BUTTON_WIDTH, BUTTON_HT SVGN_ROW_3,REPOS_BUTTON_WIDTH, BUTTON_HT
#endif #endif
END END
@ -393,11 +393,14 @@ END
#define SVGM_ROW_1 2 #define SVGM_ROW_1 2
#define SVGM_ROW_2 (SVGM_ROW_1+22) #define SVGM_ROW_2 (SVGM_ROW_1+22)
#define SVGM_ROW_3 (SVGM_ROW_2+23) #define SVGM_ROW_3 (SVGM_ROW_2+23)
#define SVGM_ROW_4 (SVGM_ROW_3+30) /* #define SVGM_ROW_4 (SVGM_ROW_3+30) */
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
# define SVGM_DLG_HT (SVGM_ROW_4) # define SVGM_DLG_HT (SVGM_ROW_3)
/* # define SVGM_DLG_HT (SVGM_ROW_4) */
#else #else
# define SVGM_DLG_HT (SVGM_ROW_4 + 18) # define SVGM_ROW_OK (SVGM_ROW_2 + 18)
# define SVGM_DLG_HT (SVGM_ROW_OK + 18)
/* # define SVGM_DLG_HT (SVGM_ROW_4 + 18) */
#endif #endif
@ -420,21 +423,21 @@ BEGIN
CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
#endif #endif
PUSHBUTTON "Dup.",IDC_SVGM_DUP,SVGM_LEFT_COL,SVGM_ROW_2,20,14,WS_DISABLED /* PUSHBUTTON "Dup.",IDC_SVGM_DUP,SVGM_LEFT_COL,SVGM_ROW_2,20,14,WS_DISABLED */
PUSHBUTTON "Delete",IDC_SVGM_DEL,SVGM_LEFT_COL+22,SVGM_ROW_2,25,14,WS_DISABLED /* PUSHBUTTON "Delete",IDC_SVGM_DEL,SVGM_LEFT_COL+22,SVGM_ROW_2,25,14,WS_DISABLED */
PUSHBUTTON "Open",IDC_SVGM_OPEN,SVGM_LEFT_COL+54,SVGM_ROW_2,25,14 PUSHBUTTON "Open",IDC_SVGM_OPEN,SVGM_LEFT_COL+54,SVGM_ROW_2,25,14,WS_DISABLED
LTEXT "Edit its name",IDC_SVGM_EDITLAB,SVGM_LEFT_COL,SVGM_ROW_3, /* LTEXT "Edit its name",IDC_SVGM_EDITLAB,SVGM_LEFT_COL,SVGM_ROW_3, */
45,12 /* 45,12 */
PUSHBUTTON "Rename",IDC_SVGM_CHANGE,SVGM_LEFT_COL+46,SVGM_ROW_3,32,12,WS_DISABLED /* PUSHBUTTON "Rename",IDC_SVGM_CHANGE,SVGM_LEFT_COL+46,SVGM_ROW_3,32,12,WS_DISABLED */
EDITTEXT IDC_SVGM_EDIT,SVGM_LEFT_COL+5,SVGM_ROW_3+15,70,12, /* EDITTEXT IDC_SVGM_EDIT,SVGM_LEFT_COL+5,SVGM_ROW_3+15,70,12, */
ES_AUTOHSCROLL /* ES_AUTOHSCROLL */
#ifndef _WIN32_WCE #ifndef _WIN32_WCE
DEFPUSHBUTTON "OK",IDOK,SVGM_LEFT_COL,SVGM_ROW_4,REPOS_BUTTON_WIDTH, DEFPUSHBUTTON "OK",IDOK,SVGM_LEFT_COL+10,SVGM_ROW_OK,REPOS_BUTTON_WIDTH,
BUTTON_HT BUTTON_HT
PUSHBUTTON "Cancel",IDCANCEL,SVGM_LEFT_COL+REPOS_BUTTON_WIDTH+10, PUSHBUTTON "Cancel",IDCANCEL,SVGM_LEFT_COL+10+REPOS_BUTTON_WIDTH+10,
SVGM_ROW_4,REPOS_BUTTON_WIDTH, BUTTON_HT SVGM_ROW_OK,REPOS_BUTTON_WIDTH, BUTTON_HT
#endif #endif
END END