1/* 2 Project: GShisen 3 4 Copyright (C) 2003-2009 The GNUstep Application Project 5 6 Author: Enrico Sersale, Riccardo Mottola 7 8 Main Application 9 10 This application is free software; you can redistribute it and/or 11 modify it under the terms of the GNU General Public 12 License as published by the Free Software Foundation; either 13 version 2 of the License, or (at your option) any later version. 14 15 This application is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 Library General Public License for more details. 19 20 You should have received a copy of the GNU General Public 21 License along with this library; if not, write to the Free 22 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 23 */ 24 25#import "gshisen.h" 26 27static GShisen *sharedshisen = nil; 28 29@implementation GShisen 30 31+ (GShisen *)sharedshisen 32{ 33 if(!sharedshisen) { 34 NS_DURING 35 { 36 sharedshisen = [[self alloc] init]; 37 } 38 NS_HANDLER 39 { 40 [localException raise]; 41 } 42 NS_ENDHANDLER 43 } 44 return sharedshisen; 45} 46 47- (id)init 48{ 49 sharedshisen = self; 50 return sharedshisen; 51} 52 53- (void)dealloc 54{ 55 [board release]; 56 [win release]; 57 [super dealloc]; 58} 59 60- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 61{ 62 [win center]; 63 [win display]; 64 [win orderFront:nil]; 65} 66 67- (BOOL)applicationShouldTerminate:(id)sender 68{ 69 return YES; 70} 71 72- (void)newGame:(id)sender 73{ 74 [board newGame]; 75} 76 77- (void)pause:(id)sender 78{ 79 [board pause]; 80} 81 82- (void)undo:(id)sender 83{ 84 [board undo]; 85} 86 87- (void)getHint:(id)sender 88{ 89 [board getHint]; 90} 91 92- (NSString *)getUserName 93{ 94 NSString *username; 95 96 [[NSApplication sharedApplication] runModalForWindow:askNamePanel]; 97 username = [nameField stringValue]; 98 99 return username; 100} 101 102- (IBAction)buttonOk:(id)sender 103{ 104 [askNamePanel orderOut: self]; 105 [[NSApplication sharedApplication] stopModal]; 106} 107 108- (void)showHallOfFame:(id)sender 109{ 110 NSMutableArray *scores; 111 NSDictionary *scoresEntry; 112 NSString *userName, *minutes, *seconds, *totTime; 113 NSRect myRect = {{0, 0}, {150, 300}}; 114 NSRect matrixRect = {{0, 0}, {150, 300}}; 115 int i; 116 NSButtonCell *buttonCell; 117 NSScrollView *scoresScroll; 118 119 scores = [board scores]; 120 if ([scores count] >= 20) { 121 matrixRect.size.height = [scores count] * 15; 122 } 123 124 [hallOfFamePanel makeKeyAndOrderFront:self]; 125 myView = [[NSView alloc] initWithFrame: [hallOfFamePanel frame]]; 126 [hallOfFamePanel setContentView: myView]; 127 128 129 buttonCell = [[NSButtonCell new] autorelease]; 130 [buttonCell setButtonType: NSPushOnPushOffButton]; 131 [buttonCell setBordered:NO]; 132 [buttonCell setAlignment:NSLeftTextAlignment]; 133 // NSLog(@"Height: %d", [buttonCell cellSize].height); 134 135 scoresMatrix = [[NSMatrix alloc] initWithFrame:matrixRect mode:NSRadioModeMatrix 136 prototype:buttonCell 137 numberOfRows:[scores count] 138 numberOfColumns:2]; 139 140 [scoresMatrix setAutoresizingMask: NSViewWidthSizable]; 141 142 scoresScroll = [[NSScrollView alloc] initWithFrame: myRect]; 143 [scoresScroll setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; 144 [scoresScroll setHasVerticalScroller: YES]; 145 [scoresScroll setHasHorizontalScroller: NO]; 146 147 for(i = 0; i < [scores count]; i++) { 148 scoresEntry = [scores objectAtIndex: i]; 149 userName = [scoresEntry objectForKey: @"username"]; 150 minutes = [scoresEntry objectForKey: @"minutes"]; 151 seconds = [scoresEntry objectForKey: @"seconds"]; 152 totTime = [NSString stringWithFormat:@"%@:%@", minutes, seconds]; 153 // [scoresMatrix addRow]; 154 [[scoresMatrix cellAtRow:i column:0] setTitle: userName]; 155 [[scoresMatrix cellAtRow:i column:1] setTitle: totTime]; 156 } 157 158 [scoresScroll setDocumentView: scoresMatrix]; 159 [myView addSubview: scoresScroll]; 160 161 [hallOfFamePanel makeKeyAndOrderFront:self]; 162} 163 164 165@end 166 167