2014-07-24 14:01:44 +00:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#include "compat.h"
|
|
|
|
#include "baselayer.h"
|
|
|
|
#include "build.h"
|
|
|
|
|
2015-08-15 21:27:27 +00:00
|
|
|
static struct
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
int fullscreen;
|
|
|
|
int xdim3d, ydim3d, bpp3d;
|
|
|
|
int forcesetup;
|
|
|
|
} settings;
|
|
|
|
|
|
|
|
@interface StartupWinController : NSWindowController
|
|
|
|
{
|
|
|
|
NSMutableArray *modeslist3d;
|
|
|
|
|
|
|
|
IBOutlet NSButton *alwaysShowButton;
|
|
|
|
IBOutlet NSButton *fullscreenButton;
|
|
|
|
IBOutlet NSTextView *messagesView;
|
|
|
|
IBOutlet NSTabView *tabView;
|
|
|
|
IBOutlet NSPopUpButton *videoMode3DPUButton;
|
|
|
|
|
|
|
|
IBOutlet NSButton *cancelButton;
|
|
|
|
IBOutlet NSButton *startButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc;
|
|
|
|
- (void)populateVideoModes:(BOOL)firstTime;
|
|
|
|
|
|
|
|
- (IBAction)alwaysShowClicked:(id)sender;
|
|
|
|
- (IBAction)fullscreenClicked:(id)sender;
|
|
|
|
|
|
|
|
- (IBAction)cancel:(id)sender;
|
|
|
|
- (IBAction)start:(id)sender;
|
|
|
|
|
|
|
|
- (void)setupRunMode;
|
|
|
|
- (void)setupMessagesMode;
|
|
|
|
- (void)putsMessage:(NSString *)str;
|
|
|
|
- (void)setTitle:(NSString *)str;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation StartupWinController
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[modeslist3d release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)populateVideoModes:(BOOL)firstTime
|
|
|
|
{
|
|
|
|
int i, mode3d, fullscreen = ([fullscreenButton state] == NSOnState);
|
|
|
|
int idx3d = -1;
|
2016-05-23 04:46:37 +00:00
|
|
|
int xdim = 0, ydim = 0, bpp = 0;
|
2014-07-24 14:01:44 +00:00
|
|
|
|
2015-08-15 21:27:27 +00:00
|
|
|
if (firstTime)
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
xdim = settings.xdim3d;
|
|
|
|
ydim = settings.ydim3d;
|
|
|
|
bpp = settings.bpp3d;
|
2015-08-15 21:27:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
mode3d = [[modeslist3d objectAtIndex:[videoMode3DPUButton indexOfSelectedItem]] intValue];
|
2015-08-15 21:27:27 +00:00
|
|
|
if (mode3d >= 0)
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
xdim = validmode[mode3d].xdim;
|
|
|
|
ydim = validmode[mode3d].ydim;
|
|
|
|
bpp = validmode[mode3d].bpp;
|
|
|
|
}
|
|
|
|
}
|
2016-05-23 04:46:37 +00:00
|
|
|
|
2014-07-24 14:01:44 +00:00
|
|
|
mode3d = checkvideomode(&xdim, &ydim, bpp, fullscreen, 1);
|
2015-08-15 21:27:27 +00:00
|
|
|
if (mode3d < 0)
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
int i, cd[] = { 32, 24, 16, 15, 8, 0 };
|
|
|
|
for (i=0; cd[i]; ) { if (cd[i] >= bpp) i++; else break; }
|
2015-08-15 21:27:27 +00:00
|
|
|
for (; cd[i]; i++)
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
mode3d = checkvideomode(&xdim, &ydim, cd[i], fullscreen, 1);
|
|
|
|
if (mode3d < 0) continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[modeslist3d release];
|
|
|
|
[videoMode3DPUButton removeAllItems];
|
|
|
|
|
|
|
|
modeslist3d = [[NSMutableArray alloc] init];
|
|
|
|
|
2015-08-15 21:27:27 +00:00
|
|
|
for (i = 0; i < validmodecnt; i++)
|
|
|
|
{
|
|
|
|
if (fullscreen == validmode[i].fs)
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
if (i == mode3d) idx3d = [modeslist3d count];
|
|
|
|
[modeslist3d addObject:[NSNumber numberWithInt:i]];
|
|
|
|
[videoMode3DPUButton addItemWithTitle:[NSString stringWithFormat:@"%d %C %d %d-bpp",
|
2015-08-15 21:27:27 +00:00
|
|
|
validmode[i].xdim, 0xd7, validmode[i].ydim, validmode[i].bpp]];
|
2014-07-24 14:01:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idx3d >= 0) [videoMode3DPUButton selectItemAtIndex:idx3d];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)alwaysShowClicked:(id)sender
|
|
|
|
{
|
2016-05-23 04:46:37 +00:00
|
|
|
UNREFERENCED_PARAMETER(sender);
|
2014-07-24 14:01:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)fullscreenClicked:(id)sender
|
|
|
|
{
|
|
|
|
[self populateVideoModes:NO];
|
2016-05-23 04:46:37 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(sender);
|
2014-07-24 14:01:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)cancel:(id)sender
|
|
|
|
{
|
|
|
|
[NSApp abortModal];
|
2016-05-23 04:46:37 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(sender);
|
2014-07-24 14:01:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)start:(id)sender
|
|
|
|
{
|
|
|
|
int mode = [[modeslist3d objectAtIndex:[videoMode3DPUButton indexOfSelectedItem]] intValue];
|
2015-08-15 21:27:27 +00:00
|
|
|
if (mode >= 0)
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
settings.xdim3d = validmode[mode].xdim;
|
|
|
|
settings.ydim3d = validmode[mode].ydim;
|
|
|
|
settings.bpp3d = validmode[mode].bpp;
|
|
|
|
settings.fullscreen = validmode[mode].fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.forcesetup = [alwaysShowButton state] == NSOnState;
|
|
|
|
|
|
|
|
[NSApp stopModal];
|
2016-05-23 04:46:37 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(sender);
|
2014-07-24 14:01:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setupRunMode
|
|
|
|
{
|
|
|
|
getvalidmodes();
|
|
|
|
|
|
|
|
[fullscreenButton setState: (settings.fullscreen ? NSOnState : NSOffState)];
|
|
|
|
[alwaysShowButton setState: (settings.forcesetup ? NSOnState : NSOffState)];
|
|
|
|
[self populateVideoModes:YES];
|
|
|
|
|
|
|
|
// enable all the controls on the Configuration page
|
|
|
|
NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator];
|
|
|
|
NSControl *control;
|
|
|
|
while (control = [enumerator nextObject]) [control setEnabled:true];
|
|
|
|
|
|
|
|
[cancelButton setEnabled:true];
|
|
|
|
[startButton setEnabled:true];
|
|
|
|
|
|
|
|
[tabView selectTabViewItemAtIndex:0];
|
|
|
|
[NSCursor unhide]; // Why should I need to do this?
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setupMessagesMode
|
|
|
|
{
|
|
|
|
[tabView selectTabViewItemAtIndex:1];
|
|
|
|
|
|
|
|
// disable all the controls on the Configuration page except "always show", so the
|
|
|
|
// user can enable it if they want to while waiting for something else to happen
|
|
|
|
NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator];
|
|
|
|
NSControl *control;
|
2015-08-15 21:27:27 +00:00
|
|
|
while (control = [enumerator nextObject])
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
if (control == alwaysShowButton) continue;
|
|
|
|
[control setEnabled:false];
|
|
|
|
}
|
|
|
|
|
|
|
|
[cancelButton setEnabled:false];
|
|
|
|
[startButton setEnabled:false];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)putsMessage:(NSString *)str
|
|
|
|
{
|
|
|
|
NSRange end;
|
|
|
|
NSTextStorage *text = [messagesView textStorage];
|
|
|
|
BOOL shouldAutoScroll;
|
|
|
|
|
|
|
|
shouldAutoScroll = ((int)NSMaxY([messagesView bounds]) == (int)NSMaxY([messagesView visibleRect]));
|
|
|
|
|
|
|
|
end.location = [text length];
|
|
|
|
end.length = 0;
|
|
|
|
|
|
|
|
[text beginEditing];
|
|
|
|
[messagesView replaceCharactersInRange:end withString:str];
|
|
|
|
[text endEditing];
|
|
|
|
|
2015-08-15 21:27:27 +00:00
|
|
|
if (shouldAutoScroll)
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
end.location = [text length];
|
|
|
|
end.length = 0;
|
|
|
|
[messagesView scrollRangeToVisible:end];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTitle:(NSString *)str
|
|
|
|
{
|
|
|
|
[[self window] setTitle:str];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
static StartupWinController *startwin = nil;
|
|
|
|
|
|
|
|
int startwin_open(void)
|
|
|
|
{
|
|
|
|
if (startwin != nil) return 1;
|
|
|
|
|
|
|
|
startwin = [[StartupWinController alloc] initWithWindowNibName:@"startwin.game"];
|
|
|
|
if (startwin == nil) return -1;
|
|
|
|
|
|
|
|
[startwin setupMessagesMode];
|
|
|
|
[startwin showWindow:nil];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int startwin_close(void)
|
|
|
|
{
|
|
|
|
if (startwin == nil) return 1;
|
|
|
|
|
|
|
|
[startwin close];
|
|
|
|
[startwin release];
|
|
|
|
startwin = nil;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int startwin_puts(const char *s)
|
|
|
|
{
|
|
|
|
NSString *ns;
|
|
|
|
|
|
|
|
if (!s) return -1;
|
|
|
|
if (startwin == nil) return 1;
|
|
|
|
|
2016-05-23 04:46:37 +00:00
|
|
|
ns = [[NSString alloc] initWithUTF8String:s];
|
2014-07-24 14:01:44 +00:00
|
|
|
[startwin putsMessage:ns];
|
|
|
|
[ns release];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int startwin_settitle(const char *s)
|
|
|
|
{
|
|
|
|
NSString *ns;
|
|
|
|
|
|
|
|
if (!s) return -1;
|
|
|
|
if (startwin == nil) return 1;
|
|
|
|
|
2016-05-23 04:46:37 +00:00
|
|
|
ns = [[NSString alloc] initWithUTF8String:s];
|
2014-07-24 14:01:44 +00:00
|
|
|
[startwin setTitle:ns];
|
|
|
|
[ns release];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int startwin_idle(void *v)
|
|
|
|
{
|
|
|
|
if (startwin) [[startwin window] displayIfNeeded];
|
2016-05-23 04:46:37 +00:00
|
|
|
UNREFERENCED_PARAMETER(v);
|
2014-07-24 14:01:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int xdimgame, ydimgame, bppgame, forcesetup;
|
|
|
|
|
|
|
|
int startwin_run(void)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (startwin == nil) return 0;
|
|
|
|
|
|
|
|
settings.fullscreen = fullscreen;
|
|
|
|
settings.xdim3d = xdimgame;
|
|
|
|
settings.ydim3d = ydimgame;
|
|
|
|
settings.bpp3d = bppgame;
|
|
|
|
settings.forcesetup = forcesetup;
|
|
|
|
|
|
|
|
[startwin setupRunMode];
|
|
|
|
|
2015-08-15 21:27:27 +00:00
|
|
|
switch ([NSApp runModalForWindow:[startwin window]])
|
|
|
|
{
|
2015-10-10 06:57:46 +00:00
|
|
|
#ifdef MAC_OS_X_VERSION_10_9
|
|
|
|
case NSModalResponseStop: retval = 1; break;
|
|
|
|
case NSModalResponseAbort: retval = 0; break;
|
|
|
|
#else
|
2015-08-15 21:27:27 +00:00
|
|
|
case NSRunStoppedResponse: retval = 1; break;
|
|
|
|
case NSRunAbortedResponse: retval = 0; break;
|
2015-10-10 06:57:46 +00:00
|
|
|
#endif
|
2015-08-15 21:27:27 +00:00
|
|
|
default: retval = -1;
|
2014-07-24 14:01:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[startwin setupMessagesMode];
|
|
|
|
|
2015-08-15 21:27:27 +00:00
|
|
|
if (retval)
|
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
fullscreen = settings.fullscreen;
|
|
|
|
xdimgame = settings.xdim3d;
|
|
|
|
ydimgame = settings.ydim3d;
|
|
|
|
bppgame = settings.bpp3d;
|
|
|
|
forcesetup = settings.forcesetup;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|