Changeset 248

Show
Ignore:
Timestamp:
04/12/08 18:01:39 (1 month ago)
Author:
timo
Message:

fix and improve the game selection and game configuration dialogs - added dir dialog, using GtkComboBox? (added support for GtkComboBox? too)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • GtkRadiant/branches/ZeroRadiant/libs/str.h

    r183 r248  
    5959#define __StrDup Q_StrDup 
    6060 
    61 inline char* Q_StrDup(char* pStr) 
    62 
    63   if (pStr == NULL) 
    64     pStr = ""; 
    65  
    66   return strcpy(new char[strlen(pStr)+1], pStr);  
     61inline char* Q_StrDup( char* _pStr ) { 
     62        const char* pStr = _pStr; 
     63        if ( pStr == NULL ) {            
     64                pStr = ""; 
     65        } 
     66 
     67        return strcpy( new char[ strlen( pStr ) + 1 ], pStr ); 
    6768} 
    6869 
    69 inline char* Q_StrDup(const char* pStr) 
    70 {  
    71   if (pStr == NULL) 
    72     pStr = ""; 
    73  
    74   return strcpy(new char[strlen(pStr)+1], pStr);  
     70inline char* Q_StrDup( const char* pStr ) { 
     71        if ( pStr == NULL ) { 
     72                pStr = ""; 
     73        } 
     74 
     75        return strcpy( new char[strlen(pStr)+1], pStr ); 
    7576} 
    7677 
     
    287288    else 
    288289    { 
    289       g_pStrWork = ""; 
    290290      g_pStrWork = new char[1]; 
    291291      g_pStrWork[0] = '\0'; 
     
    328328    else 
    329329    { 
    330       g_pStrWork = ""; 
    331330      g_pStrWork = new char[1]; 
    332331      g_pStrWork[0] = '\0'; 
  • GtkRadiant/branches/ZeroRadiant/radiant/dialog.cpp

    r197 r248  
    197197            i++; 
    198198            } 
    199           }     break; 
     199          } 
     200                  break; 
     201                case DLG_COMBO_BOX_INT: { 
     202                        *(int*)data->buffer = gtk_combo_box_get_active( GTK_COMBO_BOX( data->object ) ); 
     203                } 
     204                        break; 
     205 
    200206        } 
    201207      } 
     
    242248          gtk_adjustment_set_value (GTK_ADJUSTMENT (data->object), (*(int*)data->buffer)); 
    243249          break; 
    244         case DLG_COMBO_INT: 
    245           { 
     250        case DLG_COMBO_INT: { 
    246251          GList *lst = GTK_LIST (GTK_COMBO (data->object)->list)->children; 
    247252          char *entry = ""; 
     
    255260           
    256261          gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (data->object)->entry), entry); 
    257           }     break; 
     262          } 
     263                  break; 
     264                case DLG_COMBO_BOX_INT: { 
     265                        gtk_combo_box_set_active( GTK_COMBO_BOX( data->object ), *(int*)data->buffer ); 
     266                } 
     267                        break; 
    258268        } 
    259269      } 
  • GtkRadiant/branches/ZeroRadiant/radiant/dialog.h

    r192 r248  
    3737  DLG_SPIN_INT, 
    3838  DLG_ADJ_INT, 
    39   DLG_COMBO_INT 
     39  DLG_COMBO_INT, 
     40  DLG_COMBO_BOX_INT, 
    4041} DLG_DATA_TYPE; 
    4142 
  • GtkRadiant/branches/ZeroRadiant/radiant/preferences.cpp

    r240 r248  
    967967  strGlobalPref += "global.pref"; 
    968968   
    969   if (!mGlobalPrefs.WriteXMLFile(strGlobalPref.GetBuffer())) 
     969  if ( !mGlobalPrefs.WriteXMLFile( strGlobalPref.GetBuffer() ) ) { 
    970970    Sys_FPrintf(SYS_ERR, "Error occured while saving global prefs file '%s'\n", strGlobalPref.GetBuffer()); 
     971  } 
    971972} 
    972973 
    973974void CGameDialog::DoGameInstall() { 
     975        // make sure console logging is on whenever we enter the installation loop 
     976    g_PrefsDlg.mGamesDialog.m_bLogConsole = true; 
     977        Sys_LogFile(); 
    974978        mGameInstall.Run(); 
    975979} 
     
    981985                m_bDoGameInstall = false; 
    982986 
    983                 DoModal(); 
     987                if ( DoModal() == IDCANCEL ) { 
     988                        Error( "game selection dialog canceled, cannot continue" ); 
     989                        return; 
     990                } 
    984991                 
    985992                if ( m_bDoGameInstall ) { 
     
    10191026  gtk_box_pack_start( GTK_BOX( vbox ), text, FALSE, FALSE, 0 ); 
    10201027 
    1021   combo = gtk_combo_new(); 
     1028  combo = gtk_combo_box_new_text(); 
    10221029  gtk_widget_show( combo ); 
    10231030  gtk_box_pack_start( GTK_BOX( vbox ), combo, FALSE, FALSE, 0 ); 
    1024  
    1025   // fill in with the game descriptions 
    1026   GList *combo_list = (GList*)NULL; 
    1027   list<CGameDescription *>::iterator iGame; 
    1028   for( iGame = mGames.begin(); iGame != mGames.end(); iGame++ ) { 
    1029           combo_list = g_list_append( combo_list, (void *)(*iGame)->mGameName.GetBuffer() ); 
    1030   } 
    1031   gtk_combo_set_popdown_strings( GTK_COMBO( combo ), combo_list ); 
    1032   g_list_free( combo_list ); 
    1033  
    1034   AddDialogData( combo, &m_nComboSelect, DLG_COMBO_INT ); 
     1031  AddDialogData( combo, &m_nComboSelect, DLG_COMBO_BOX_INT ); 
     1032  mGameCombo = GTK_COMBO_BOX( combo ); 
     1033 
     1034  UpdateGameCombo(); 
    10351035 
    10361036  check = gtk_check_button_new_with_label( "Auto load selected game on startup" ); 
     
    11261126        gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 ); 
    11271127        AddModalButton( button, IDOK ); 
     1128 
     1129        button = gtk_button_new_with_label( "Cancel" ); 
     1130        gtk_widget_show( button ); 
     1131        gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 ); 
     1132        AddModalButton( button, IDCANCEL ); 
    11281133         
    11291134        gtk_widget_set_usize( button, 60, -2 ); 
     1135} 
     1136 
     1137void CGameDialog::UpdateGameCombo() { 
     1138  // fill in with the game descriptions 
     1139  list<CGameDescription *>::iterator iGame; 
     1140 
     1141  if ( mGameCombo == NULL ) { 
     1142          Sys_Printf( "mGameCombo == NULL\n" ); 
     1143          return; 
     1144  } 
     1145 
     1146  // clear whatever is in - wtf no way to know how many text entries? 
     1147  // use set/get active to track  
     1148  gtk_combo_box_set_active( mGameCombo, 0 ); 
     1149  while ( gtk_combo_box_get_active( mGameCombo ) == 0 ) { 
     1150          gtk_combo_box_remove_text( mGameCombo, 0 ); 
     1151          gtk_combo_box_set_active( mGameCombo, 0 ); 
     1152  } 
     1153   
     1154  for ( iGame = mGames.begin(); iGame != mGames.end(); iGame++ ) { 
     1155          gtk_combo_box_append_text( mGameCombo, (*iGame)->mGameName.GetBuffer() ); 
     1156  } 
     1157  gtk_combo_box_set_active( mGameCombo, 0 ); 
    11301158} 
    11311159 
     
    11911219      } 
    11921220 
    1193       g_free(dirlist); 
     1221      g_free( dirlist ); 
    11941222    } 
    1195     g_dir_close (dir); 
    1196   } 
     1223    g_dir_close( dir ); 
     1224  } 
     1225 
     1226  // entries in the combo need to be updated 
     1227  UpdateGameCombo(); 
    11971228} 
    11981229 
     
    12011232  list<CGameDescription *>::iterator iGame; 
    12021233  int i=0; 
    1203   for(iGame=mGames.begin(); iGame!=mGames.end(); iGame++,i++) 
    1204   { 
    1205     if (i == m_nComboSelect) 
    1206     { 
     1234  for( iGame = mGames.begin(); iGame != mGames.end(); iGame++,i++ ) { 
     1235    if ( i == m_nComboSelect ) { 
    12071236      return (*iGame); 
    12081237    } 
     
    31393168} 
    31403169 
     3170static void CGameInstall::OnBtnBrowseEngine( GtkWidget *widget, gpointer data ) { 
     3171        Sys_Printf( "OnBtnBrowseEngine\n" ); 
     3172 
     3173        CGameInstall* i = static_cast<CGameInstall*>( data ); 
     3174        char *dir = dir_dialog( widget, "Select game directory", NULL ); 
     3175 
     3176        i->UpdateData( TRUE ); 
     3177 
     3178        if ( dir != NULL ) { 
     3179                i->m_strEngine = dir; 
     3180                i->UpdateData( FALSE ); 
     3181                free( dir ); 
     3182        } 
     3183} 
     3184 
     3185static void CGameInstall::OnGameSelectChanged( GtkWidget *widget, gpointer data ) { 
     3186        Sys_Printf( "OnGameSelectChanged\n" ); 
     3187 
     3188        CGameInstall* i = static_cast<CGameInstall*>( data ); 
     3189        i->UpdateData( TRUE );   
     3190        i->m_strName = gtk_combo_box_get_active_text( GTK_COMBO_BOX( widget ) ); 
     3191        i->UpdateData( FALSE ); 
     3192} 
     3193 
    31413194void CGameInstall::BuildDialog() { 
    3142         GtkWidget *dlg, *vbox1, *button, *text, *combo, *entry
     3195        GtkWidget *dlg, *vbox1, *button, *text, *combo, *entry, *hbox
    31433196         
    31443197        dlg = m_pWidget; 
     
    31533206        gtk_box_pack_start( GTK_BOX( vbox1 ), text, FALSE, FALSE, 0 ); 
    31543207 
    3155         combo = gtk_combo_new(); 
     3208        combo = gtk_combo_box_new_text(); 
    31563209        gtk_widget_show( combo ); 
    31573210        gtk_box_pack_start( GTK_BOX( vbox1 ), combo, FALSE, FALSE, 0 ); 
    31583211 
    3159         GList *combo_list = NULL; 
     3212        //     GList *combo_list = NULL; 
    31603213        int iGame = 0; 
    31613214        while ( m_availGames[ iGame ] != GAME_NONE ) { 
    31623215                switch ( m_availGames[ iGame ] ) { 
    31633216                case GAME_Q2: 
    3164                         combo_list = g_list_append( combo_list, "Quake II" ); 
     3217                        gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), "Quake II" ); 
    31653218                        break; 
    31663219                case GAME_Q3: 
    3167                         combo_list = g_list_append( combo_list, "Quake III Arena (including mods)" ); 
     3220                        gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), "Quake III Arena and mods" ); 
    31683221                        break; 
    31693222                case GAME_URT: 
    3170                         combo_list = g_list_append( combo_list, "Urban Terror (standalone)" ); 
     3223                        gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), "Urban Terror (standalone)" ); 
    31713224                        break; 
    31723225                case GAME_UFOAI: 
    3173                         combo_list = g_list_append( combo_list, "UFO: Alien Invasion" ); 
     3226                        gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), "UFO: Alien Invasion" ); 
    31743227                        break; 
    31753228                case GAME_Q2W: 
    3176                         combo_list = g_list_append( combo_list, "Quake2World" ); 
     3229                        gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), "Quake2World" ); 
    31773230                        break; 
    31783231                case GAME_WARSOW: 
    3179                         combo_list = g_list_append( combo_list, "Warsow" ); 
     3232                        gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), "Warsow" ); 
    31803233                        break; 
    31813234                case GAME_NEXUIZ: 
    3182                         combo_list = g_list_append( combo_list, "Nexuiz" ); 
     3235                        gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), "Nexuiz" ); 
    31833236                        break; 
    31843237                } 
    31853238                iGame++; 
    31863239        } 
    3187         gtk_combo_set_popdown_strings( GTK_COMBO( combo ), combo_list ); 
    3188         g_list_free( combo_list ); 
    3189         AddDialogData( combo, &m_nComboSelect, DLG_COMBO_INT ); 
     3240        AddDialogData( combo, &m_nComboSelect, DLG_COMBO_BOX_INT ); 
     3241        gtk_signal_connect( GTK_OBJECT( combo ), "changed", G_CALLBACK( OnGameSelectChanged ), this ); 
     3242        gtk_combo_box_set_active( GTK_COMBO_BOX( combo ), 0 ); // NOTE: will trigger signal 
    31903243 
    31913244        text = gtk_label_new( "Name:" ); 
     
    32013254        gtk_widget_show( text ); 
    32023255        gtk_box_pack_start( GTK_BOX( vbox1 ), text, FALSE, FALSE, 0 ); 
     3256 
     3257        hbox = gtk_hbox_new( FALSE, 0 ); 
     3258        gtk_widget_show( hbox ); 
     3259        gtk_box_pack_start( GTK_BOX( vbox1 ), hbox, FALSE, FALSE, 0 ); 
    32033260         
    32043261        entry = gtk_entry_new(); 
    32053262        gtk_widget_show( entry ); 
    3206         gtk_box_pack_start( GTK_BOX( vbox1 ), entry, FALSE, FALSE, 0 ); 
     3263        gtk_box_pack_start( GTK_BOX( hbox ), entry, FALSE, FALSE, 0 ); 
    32073264        AddDialogData( entry, &m_strEngine, DLG_ENTRY_TEXT ); 
     3265 
     3266        button = gtk_button_new_with_label ("..."); 
     3267        gtk_widget_show( button ); 
     3268        gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( OnBtnBrowseEngine ), this ); 
     3269        gtk_box_pack_start( GTK_BOX( hbox ), button, FALSE, FALSE, 0 ); 
    32083270 
    32093271        // this gets done in the project stuff atm 
     
    32243286        AddModalButton( button, IDOK ); 
    32253287 
     3288        button = gtk_button_new_with_label( "Cancel" ); 
     3289        gtk_widget_show( button ); 
     3290        gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 ); 
     3291        AddModalButton( button, IDCANCEL ); 
     3292 
    32263293        gtk_widget_set_usize( button, 60, -2 ); 
    32273294} 
     
    32293296void CGameInstall::Run() { 
    32303297        ScanGames(); 
    3231         DoModal(); 
     3298        if ( DoModal() == IDCANCEL ) { 
     3299                Sys_Printf( "game dialog cancelled\n" ); 
     3300                return; 
     3301        } 
    32323302        Sys_Printf( "combo: %d name: %s engine: %s mod: %s\n", m_nComboSelect, m_strName.GetBuffer(), m_strEngine.GetBuffer(), m_strMod.GetBuffer() ); 
    32333303 
     
    32483318        switch ( m_availGames[ m_nComboSelect ] ) { 
    32493319        case GAME_Q2: { 
    3250                 fprintf( fg, "  gametools=\"%sgames/quake2\"\n", g_strAppPath.GetBuffer() ); 
     3320                fprintf( fg, "  gametools=\"%sinstalls/Quake2Pack/game\"\n", g_strAppPath.GetBuffer() ); 
    32513321                fprintf( fg, "  prefix=\".quake2\"\n" ); 
    32523322                Str source = g_strAppPath.GetBuffer(); 
    32533323                source += "installs/"; 
    32543324                source += Q2_PACK; 
     3325                source += "/install/"; 
    32553326                Str dest = m_strEngine.GetBuffer(); 
    32563327                CopyTree( source.GetBuffer(), dest.GetBuffer() ); 
     
    32593330        } 
    32603331        case GAME_Q3: { 
    3261                 fprintf( fg, "  gametools=\"%sgames/quake3\"\n", g_strAppPath.GetBuffer() ); 
     3332                fprintf( fg, "  gametools=\"%sinstalls/Q3Pack/game\"\n", g_strAppPath.GetBuffer() ); 
    32623333                fprintf( fg, "  prefix=\".q3a\"\n" ); 
    32633334                Str source = g_strAppPath.GetBuffer(); 
    32643335                source += "installs/"; 
    32653336                source += Q3_PACK; 
     3337                source += "/install/"; 
    32663338                Str dest = m_strEngine.GetBuffer(); 
    32673339                CopyTree( source.GetBuffer(), dest.GetBuffer() ); 
     
    32703342        } 
    32713343        case GAME_URT: { 
    3272                 fprintf( fg, "  gametools=\"%sgames/q3ut4\"\n", g_strAppPath.GetBuffer() ); 
     3344                fprintf( fg, "  gametools=\"%sinstalls/UrTPack/game\"\n", g_strAppPath.GetBuffer() ); 
    32733345                fprintf( fg, "  prefix=\".q3a\"\n" ); 
    32743346                Str source = g_strAppPath.GetBuffer(); 
    32753347                source += "installs/"; 
    32763348                source += URT_PACK; 
     3349                source += "/install/"; 
    32773350                Str dest = m_strEngine.GetBuffer(); 
    32783351                CopyTree( source.GetBuffer(), dest.GetBuffer() ); 
     
    32813354        } 
    32823355        case GAME_UFOAI: { 
    3283                 fprintf( fg, "  gametools=\"%sgames/ufoai\"\n", g_strAppPath.GetBuffer() ); 
     3356                fprintf( fg, "  gametools=\"%sinstalls/UFOAIPack/game\"\n", g_strAppPath.GetBuffer() ); 
    32843357                fprintf( fg, "  prefix=\".ufoai\"\n" ); 
    32853358                Str source = g_strAppPath.GetBuffer(); 
    32863359                source += "installs/"; 
    32873360                source += UFOAI_PACK; 
     3361                source += "/install/"; 
    32883362                Str dest = m_strEngine.GetBuffer(); 
    32893363                CopyTree( source.GetBuffer(), dest.GetBuffer() ); 
     
    32923366        } 
    32933367        case GAME_Q2W: { 
    3294                 fprintf( fg, "  gametools=\"%sgames/q2w\"\n", g_strAppPath.GetBuffer() ); 
     3368                fprintf( fg, "  gametools=\"%sinstalls/Q2WPack/game\"\n", g_strAppPath.GetBuffer() ); 
    32953369                fprintf( fg, "  prefix=\".quake2world\"\n" ); 
    32963370                Str source = g_strAppPath.GetBuffer(); 
    32973371                source += "installs/"; 
    32983372                source += Q2W_PACK; 
     3373                source += "/install/"; 
    32993374                Str dest = m_strEngine.GetBuffer(); 
    33003375                CopyTree( source.GetBuffer(), dest.GetBuffer() ); 
     
    33033378        } 
    33043379        case GAME_WARSOW: { 
    3305                 fprintf( fg, "  gametools=\"%sgames/warsow\"\n", g_strAppPath.GetBuffer() ); 
     3380                fprintf( fg, "  gametools=\"%installs/WarsowPack/game\"\n", g_strAppPath.GetBuffer() ); 
    33063381                fprintf( fg, "  prefix=\".warsow\"\n" ); 
    33073382                Str source = g_strAppPath.GetBuffer(); 
    33083383                source += "installs/"; 
    33093384                source += WARSOW_PACK; 
     3385                source += "/install/"; 
    33103386                Str dest = m_strEngine.GetBuffer(); 
    33113387                CopyTree( source.GetBuffer(), dest.GetBuffer() ); 
     
    33143390        } 
    33153391        case GAME_NEXUIZ: { 
    3316                 fprintf( fg, "  gametools=\"%sgames/nexuiz\"\n", g_strAppPath.GetBuffer() ); 
     3392                fprintf( fg, "  gametools=\"%sinstalls/NexuizPack/game\"\n", g_strAppPath.GetBuffer() ); 
    33173393                fprintf( fg, "  prefix=\".nexuiz\"\n" ); 
    33183394                Str source = g_strAppPath.GetBuffer(); 
    33193395                source += "installs/"; 
    33203396                source += NEXUIZ_PACK; 
     3397                source += "/install/"; 
    33213398                Str dest = m_strEngine.GetBuffer(); 
    33223399                CopyTree( source.GetBuffer(), dest.GetBuffer() ); 
  • GtkRadiant/branches/ZeroRadiant/radiant/preferences.h

    r237 r248  
    214214        void BuildDialog(); 
    215215 
     216        static void OnBtnBrowseEngine( GtkWidget *widget, gpointer data ); 
     217        static void OnGameSelectChanged( GtkWidget *widget, gpointer data ); 
     218 
    216219        enum gameType_e { 
    217220                GAME_NONE = 0, 
     
    244247  GtkWidget *mTopBox; ///< top level box used to store the dialog frame, must unhook after modal use 
    245248 
     249  GtkComboBox   *mGameCombo;    // combo box holds the selection of available game 
    246250 
    247251  /*! 
     
    311315          m_bForceLogConsole = false; 
    312316          m_bDoGameInstall = true;      // go through DoModal at least once 
     317          mGameCombo = NULL; 
    313318  } 
    314319  virtual ~CGameDialog();  
     
    398403  */ 
    399404  static void SInstallCallback( GtkWidget *widget, gpointer data ); 
     405 
     406  void UpdateGameCombo(); 
    400407}; 
    401408