forked from farktronix/freegoban
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGobanMoveInspector.m
205 lines (171 loc) · 6.41 KB
/
GobanMoveInspector.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*$Id: GobanMoveInspector.m,v 1.5 2001/10/04 16:13:54 phink Exp $*/
// This is Goban, a Go program for Mac OS X. Contact goban@sente.ch,
// or see http://www.sente.ch/software/goban for more information.
//
// Copyright (c) 1997-2001, Sen:te (Sente SA). All rights reserved.
//
// 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 - version 2.
//
// 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 in file COPYING
// 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, USA.
#import "GobanMoveInspector.h"
#import "GobanGameDocument.h"
#import <GoGame/GoGame.h>
#import <GoGame/GoSymbol.h>
#import <GoGame/GoMove.h>
#import <GoGame/GoPoint.h>
#import <SenFoundation/SenFoundation.h>
@interface GoGameNode (HumanRepresentation)
- (NSString *) humanRepresentation;
@end
#define JAPANESE_STYLE 1
@implementation GoMove (HumanRepresentation)
- (NSArray *) xLabels
{
int labelingStyle = [[NSUserDefaults standardUserDefaults] integerForKey:@"LabelingStyle"];
if (labelingStyle == JAPANESE_STYLE) {
return [[NSUserDefaults standardUserDefaults] objectForKey:@"ArabicLabels"];
}
else {
return [[NSUserDefaults standardUserDefaults] objectForKey:@"RomanLabels"];
}
}
- (NSArray *) yLabels
{
int labelingStyle = [[NSUserDefaults standardUserDefaults] integerForKey:@"LabelingStyle"];
if (labelingStyle == JAPANESE_STYLE) {
return [[NSUserDefaults standardUserDefaults] objectForKey:@"KanjiLabels"];
}
else {
return [[NSUserDefaults standardUserDefaults] objectForKey:@"ArabicLabels"];
}
}
- (NSString *) humanRepresentation
{
if ([self isPass]) {
return NSLocalizedString(@"pass", @"");
}
else {
int labelingStyle = [[NSUserDefaults standardUserDefaults] integerForKey:@"LabelingStyle"];
if (labelingStyle == JAPANESE_STYLE) {
return [NSString stringWithFormat:@"%@%@",
[[[NSUserDefaults standardUserDefaults] objectForKey:@"KanjiLabels"] objectAtIndex:[[self point] y]],
[[[NSUserDefaults standardUserDefaults] objectForKey:@"ArabicLabels"] objectAtIndex:[[self point] x]]];
}
else {
return [NSString stringWithFormat:@"%@%@",
[[[NSUserDefaults standardUserDefaults] objectForKey:@"RomanLabels"] objectAtIndex:[[self point] x]],
[[[NSUserDefaults standardUserDefaults] objectForKey:@"ArabicLabels"] objectAtIndex:[[self point] y]]];
}
}
}
@end
@implementation GobanMoveInspector
- (void) setEmpty
{
}
- (void) redisplay
{
GoGame *game = [inspectedDocument game];
NSString *comments = [[game currentMove] comments];
int index = [[game currentLineOfPlay] indexOfObject:[game currentMove]];
[outlineView reloadData];
if (index != NSNotFound) {
[outlineView selectRow:index byExtendingSelection:NO];
[outlineView scrollRowToVisible:index];
}
if (!isNilOrEmpty (comments)) {
[commentView setString:comments];
}
else {
[commentView setString:@""];
}
}
- (void) setInspected:(GobanGameDocument *) aGobanDocument
{
if (inspectedDocument != aGobanDocument) {
[[NSNotificationCenter defaultCenter] removeObserver:self];
ASSIGN (inspectedDocument, aGobanDocument);
if (inspectedDocument != nil) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gameDidChange:) name:nil object:[inspectedDocument game]];
[self redisplay];
}
else {
[self setEmpty];
}
}
}
// textDidChange never called
- (BOOL) textView:(NSTextView *) aTextView shouldChangeTextInRange:(NSRange) affectedCharRange replacementString:(NSString *) replacementString
{
[[[inspectedDocument game] currentMove] setComments:[aTextView string]];
return YES;
}
- (void) gameDidChange:(NSNotification *) aNotification
{
[self redisplay];
}
- (BOOL) outlineView:(NSOutlineView *) anOutlineView isItemExpandable:(id) anItem
{
return NO;
}
- (int) outlineView:(NSOutlineView *) anOutlineView numberOfChildrenOfItem:(id) anItem
{
return (anItem == nil) ? [[[inspectedDocument game] currentLineOfPlay] count] : 0;
}
- (id) outlineView:(NSOutlineView *) anOutlineView child:(int)index ofItem:(id) anItem
{
return (anItem == nil) ? [[[inspectedDocument game] currentLineOfPlay] objectAtIndex:index] : nil;
}
- (id) outlineView:(NSOutlineView *) anOutlineView objectValueForTableColumn:(NSTableColumn *) tableColumn byItem:(id) anItem
{
if ([[tableColumn identifier] isEqualToString:@"Number"]) {
return [NSString stringWithFormat:@"%d", 1 + [anOutlineView rowForItem:anItem]];
}
else if ([[tableColumn identifier] isEqualToString:@"Description"]) {
return [anItem humanRepresentation];
}
return nil;
}
- (void) outlineView:(NSOutlineView *) anOutlineView willDisplayCell:(id) cell forTableColumn:(NSTableColumn *) tableColumn item:(id) anItem
{
GoMove *move = (GoMove *) anItem;
if ([move color] == [GoSymbol black]) {
[cell setBackgroundColor:[NSColor colorWithCalibratedWhite:0.9 alpha:1.0]];
[cell setDrawsBackground:YES];
}
else {
[cell setBackgroundColor:[NSColor whiteColor]];
}
}
- (IBAction) selectMove:(id) sender
{
int selectedRow = [sender selectedRow];
if (selectedRow >= 0) {
GoGame *game = [inspectedDocument game];
[game gotoMoveAtIndex:selectedRow];
}
}
#ifdef NEVER_CALLED
- (void) outlineViewSelectionDidChange:(NSNotification *)notification
//- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
{
int selectedRow = [outlineView selectedRow];
SEN_TRACE;
if (selectedRow >= 0) {
GoGame *game = [inspectedDocument game];
[game gotoMoveAtIndex:selectedRow];
}
}
#endif
@end