From 6921f30a44e0bdf1c3a2f8982e4a8cd290c22462 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 4 Jan 2010 22:01:32 +0000 Subject: Import OS X launcher code to trunk. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1784 --- pkg/osx/IWADController.m | 329 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 329 insertions(+) create mode 100644 pkg/osx/IWADController.m (limited to 'pkg/osx/IWADController.m') diff --git a/pkg/osx/IWADController.m b/pkg/osx/IWADController.m new file mode 100644 index 00000000..f1860301 --- /dev/null +++ b/pkg/osx/IWADController.m @@ -0,0 +1,329 @@ +/* ... */ +//----------------------------------------------------------------------------- +// +// Copyright(C) 2009 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +//----------------------------------------------------------------------------- + +#include +#include +#include +#include "IWADController.h" +#include "IWADLocation.h" + +typedef enum +{ + IWAD_DOOM1, + IWAD_DOOM2, + IWAD_TNT, + IWAD_PLUTONIA, + IWAD_CHEX, + NUM_IWAD_TYPES +} IWAD; + +static NSString *IWADLabels[NUM_IWAD_TYPES] = +{ + @"Doom", + @"Doom II: Hell on Earth", + @"Final Doom: TNT: Evilution", + @"Final Doom: Plutonia Experiment", + @"Chex Quest" +}; + +static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] = +{ + @"doom.wad", + @"doom2.wad", + @"tnt.wad", + @"plutonia.wad", + @"chex.wad", + @"undefined" +}; + +@implementation IWADController + +- (void) getIWADList: (IWADLocation **) iwadList +{ + iwadList[IWAD_DOOM1] = self->doom1; + iwadList[IWAD_DOOM2] = self->doom2; + iwadList[IWAD_TNT] = self->tnt; + iwadList[IWAD_PLUTONIA] = self->plutonia; + iwadList[IWAD_CHEX] = self->chex; +} + +- (IWAD) getSelectedIWAD +{ + unsigned int i; + + for (i=0; iiwadSelector titleOfSelectedItem] == IWADLabels[i]) + { + return i; + } + } + + return NUM_IWAD_TYPES; +} + +// Get the location of the selected IWAD. + +- (NSString *) getIWADLocation +{ + IWAD selectedIWAD; + IWADLocation *iwadList[NUM_IWAD_TYPES]; + + selectedIWAD = [self getSelectedIWAD]; + + if (selectedIWAD == NUM_IWAD_TYPES) + { + return nil; + } + else + { + [self getIWADList: iwadList]; + + return [iwadList[selectedIWAD] getLocation]; + } +} + +- (void) setIWADConfig +{ + IWADLocation *iwadList[NUM_IWAD_TYPES]; + NSUserDefaults *defaults; + NSString *key; + NSString *value; + unsigned int i; + + [self getIWADList: iwadList]; + + // Load IWAD filename paths + + defaults = [NSUserDefaults standardUserDefaults]; + + for (i=0; iiwadSelector selectItemWithTitle:IWADLabels[i]]; + break; + } + } +} + +// Set the dropdown list to include an entry for each IWAD that has +// been configured. Returns true if at least one IWAD is configured. + +- (BOOL) setDropdownList +{ + IWADLocation *iwadList[NUM_IWAD_TYPES]; + BOOL have_wads; + id location; + unsigned int i; + unsigned int enabled_wads; + + // Build the new list. + + [self getIWADList: iwadList]; + [self->iwadSelector removeAllItems]; + + enabled_wads = 0; + + for (i=0; i 0) + { + [self->iwadSelector addItemWithTitle: IWADLabels[i]]; + ++enabled_wads; + } + } + + // Enable/disable the dropdown depending on whether there + // were any configured IWADs. + + have_wads = enabled_wads > 0; + [self->iwadSelector setEnabled: have_wads]; + + // Restore the old selection. + + [self setDropdownSelection]; + + return have_wads; +} + +- (void) saveConfig +{ + IWADLocation *iwadList[NUM_IWAD_TYPES]; + IWAD selectedIWAD; + NSUserDefaults *defaults; + NSString *key; + NSString *value; + unsigned int i; + + [self getIWADList: iwadList]; + + // Store all IWAD locations to user defaults. + + defaults = [NSUserDefaults standardUserDefaults]; + + for (i=0; iconfigWindow isVisible]) + { + [self->configWindow makeKeyAndOrderFront: sender]; + } +} + +// Callback method invoked when the close button is clicked. + +- (void) closeConfigWindow: (id)sender +{ + [self->configWindow orderOut: sender]; + [self saveConfig]; + [self setDropdownList]; +} + +- (void) awakeFromNib +{ + // Set configuration for all IWADs from configuration file. + + [self setIWADConfig]; + + // Populate the dropdown IWAD list, and open the configuration + // dialog if not yet configured. + + if ([self setDropdownList]) + { + [self setDropdownSelection]; + } + else + { + [self openConfigWindow: nil]; + } +} + +// Set the DOOMWADPATH environment variable to contain the path to each +// of the configured IWAD files. + +- (void) setEnvironment +{ + IWADLocation *iwadList[NUM_IWAD_TYPES]; + NSString *location; + unsigned int i; + unsigned int len; + BOOL first; + char *env; + + [self getIWADList: iwadList]; + + // Calculate length of environment string. + + len = 30; + + for (i=0; i 0) + { + len += [location length] + 1; + } + } + + // Build string. + + env = malloc(len); + strcpy(env, "DOOMWADPATH="); + + first = YES; + + for (i=0; i 0) + { + if (!first) + { + strcat(env, ":"); + } + + strcat(env, [location UTF8String]); + first = NO; + } + } + + // Load into environment: + + putenv(env); + + //free(env); +} + +@end + -- cgit v1.2.3 From cd8cf5f1c8c0e6a86ddc3322f33acc29698009f5 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 15 Jan 2010 18:51:35 +0000 Subject: Center the launcher window and config window on startup. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1815 --- pkg/osx/IWADController.m | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pkg/osx/IWADController.m') diff --git a/pkg/osx/IWADController.m b/pkg/osx/IWADController.m index f1860301..783ee38f 100644 --- a/pkg/osx/IWADController.m +++ b/pkg/osx/IWADController.m @@ -250,6 +250,8 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] = - (void) awakeFromNib { + [self->configWindow center]; + // Set configuration for all IWADs from configuration file. [self setIWADConfig]; -- cgit v1.2.3 From 6e0df0d01676cec59caaafa2cea3910c5a9b51e0 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 15 Jan 2010 19:29:28 +0000 Subject: Don't open the configuration window when the launcher is first run; display an error message if the user tries to launch the game without an IWAD selected. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1817 --- pkg/osx/IWADController.m | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'pkg/osx/IWADController.m') diff --git a/pkg/osx/IWADController.m b/pkg/osx/IWADController.m index 783ee38f..a7730cc7 100644 --- a/pkg/osx/IWADController.m +++ b/pkg/osx/IWADController.m @@ -256,17 +256,12 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] = [self setIWADConfig]; - // Populate the dropdown IWAD list, and open the configuration - // dialog if not yet configured. + // Populate the dropdown IWAD list. if ([self setDropdownList]) { [self setDropdownSelection]; } - else - { - [self openConfigWindow: nil]; - } } // Set the DOOMWADPATH environment variable to contain the path to each -- cgit v1.2.3 From bf8974e63b988ae1b5d2fdb0492dfe0bb3613680 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 23 Jan 2010 23:06:45 +0000 Subject: Add menu item to launcher to open a terminal window that can be used to start the game. Add missing 'edit' menu. Set svn:ignore property for osx directory. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1824 --- pkg/osx/IWADController.m | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'pkg/osx/IWADController.m') diff --git a/pkg/osx/IWADController.m b/pkg/osx/IWADController.m index a7730cc7..3c596850 100644 --- a/pkg/osx/IWADController.m +++ b/pkg/osx/IWADController.m @@ -264,10 +264,10 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] = } } -// Set the DOOMWADPATH environment variable to contain the path to each -// of the configured IWAD files. +// Generate a value to set for the DOOMWADPATH environment variable +// that contains each of the configured IWAD files. -- (void) setEnvironment +- (char *) doomWadPath { IWADLocation *iwadList[NUM_IWAD_TYPES]; NSString *location; @@ -280,7 +280,7 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] = // Calculate length of environment string. - len = 30; + len = 0; for (i=0; i