/
CharacterSheetController.m
504 lines (416 loc) · 13.1 KB
/
CharacterSheetController.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/*
This file is part of Mac Eve Tools.
Mac Eve Tools 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 3 of the License, or
(at your option) any later version.
Mac Eve Tools 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 Mac Eve Tools. If not, see <http://www.gnu.org/licenses/>.
Copyright Matt Tyson, 2009.
*/
#import "CharacterSheetController.h"
#import "XmlFetcher.h"
#import "GlobalData.h"
#import "Character.h"
#import "Account.h"
#import "SkillTree.h"
#import "Helpers.h"
#import "MTSkillProgressCell.h"
#import "Skill.h"
#import "SkillDetailsWindowController.h"
#import "MTEveSkillCell.h"
#import "MTEveSkillQueueHeader.h"
#import "SkillPlan.h"
@interface CharacterSheetController (CharacterSheetPrivate)
-(void) showCharDetails:(Character*)character;
-(void) clearCharDetails; /*null out everything on error*/
-(void) clearCharTrainingDetails;
-(void) timerTick;
@end
@implementation CharacterSheetController (CharacterSheetPrivate)
-(void) timerTick
{
if(trainingSkill != nil){
[skillTree reloadItem:trainingSkill];
}
}
-(void) clearCharDetails
{
[charName setObjectValue:nil];
[charRace setObjectValue:nil];
[charInt setObjectValue:nil];
[charPerc setObjectValue:nil];
[charChar setObjectValue:nil];
[charWill setObjectValue:nil];
[charMem setObjectValue:nil];
[charIsk setObjectValue:nil];
[charSP setObjectValue:nil];
[charKnownSkills setObjectValue:nil];
[skillTree setDataSource:nil];
[trainingRate setObjectValue:nil];
}
-(void) clearCharTrainingDetails
{
[trainingRate setObjectValue:nil];
[charTraining setObjectValue:nil];
[timeRemaining deactivate];
[timeRemaining setVisible:NO];
trainingSkill = nil;
}
-(void) clearCharTrainingQueue
{
[queueHeader setSkillPlan:nil];
[queueHeader setCharacter:nil];
[queueHeader setNeedsDisplay:YES];;
}
-(void) showCharTrainingQueue:(Character*)character
{
if(currentCharacter != character){
return;
}
SkillPlan *plan = [character trainingQueue];
[queueHeader setCharacter:character];
[queueHeader setSkillPlan:plan];
[queueHeader setNeedsDisplay:YES];
}
-(void) showCharDetails:(Character*)character
{
if([character charSheetError]){
return;
}
[charName setStringValue:[character stringForKey:CHAR_NAME]];
[charRace setStringValue:[NSString stringWithFormat:@"%@ %@",
[character stringForKey:CHAR_RACE],
[character stringForKey:CHAR_BLOODLINE]]];
[charName sizeToFit];
[charRace sizeToFit];
[charInt setStringValue:[character getAttributeString:ATTR_INTELLIGENCE]];
[charPerc setStringValue:[character getAttributeString:ATTR_PERCEPTION]];
[charChar setStringValue:[character getAttributeString:ATTR_CHARISMA]];
[charWill setStringValue:[character getAttributeString:ATTR_WILLPOWER]];
[charMem setStringValue:[character getAttributeString:ATTR_MEMORY]];
[charInt sizeToFit];
[charPerc sizeToFit];
[charChar sizeToFit];
[charWill sizeToFit];
[charMem sizeToFit];
[charIsk setObjectValue:[NSDecimalNumber decimalNumberWithString:[character stringForKey:CHAR_BALANCE]]];
[charIsk sizeToFit];
NSInteger clonePoints = [character integerForKey:CHAR_CLONE_SP];
NSInteger charPoints = [character skillPointTotal];
NSInteger threshold = (CGFloat)clonePoints * 0.95;
if((clonePoints < charPoints) || (threshold < charPoints)){
//clone is not up to date, make clone SP red to alert the user
[cloneSP setTextColor:[NSColor redColor]];
}else{
[cloneSP setTextColor:[NSColor textColor]];
}
[cloneSP setObjectValue:[NSNumber numberWithInteger:clonePoints]];
[cloneSP sizeToFit];
[charSP setObjectValue:[NSNumber numberWithInteger:charPoints]];
[charSP sizeToFit];
NSString *knownSkills = [NSString stringWithFormat:@"%ld (%ld at V)",[character skillsKnown],[character skillsAtV]];
[charKnownSkills setStringValue:knownSkills];
[charKnownSkills sizeToFit];
NSString *formattedSP = [SPFormatter stringFromNumber:[NSNumber numberWithInteger:charPoints]];
NSString *headerCell = [NSString stringWithFormat:@"Current skills: %ld (skill points %@)",
[character skillsKnown],formattedSP];
[[[[skillTree tableColumns]objectAtIndex:0]headerCell]setStringValue:headerCell];
}
-(void) showCharTrainingDetails:(Character*)character
{
if([character trainingSheetError]){
return;
}
NSInteger isTraining = [character integerForKey:CHAR_TRAINING_SKILLTRAINING];
if(isTraining == 0){
/*not training.*/
[charTraining setStringValue:@"Not Training"];
[charTraining sizeToFit];
[timeRemaining deactivate];
[trainingRate setObjectValue:nil];
[timeRemaining setHidden:YES];
[trainingRate setHidden:YES];
[queueHeader setHidden:YES];
[titleRate setHidden:YES];
[titleRemaining setHidden:YES];
trainingSkill = nil;
return;
}
[timeRemaining setHidden:NO];
[trainingRate setHidden:NO];
[queueHeader setHidden:NO];
[titleRate setHidden:NO];
[titleRemaining setHidden:NO];
[timeRemaining setVisible:YES];
NSString *typeID = [character stringForKey:CHAR_TRAINING_TYPEID];
NSNumber *key = [NSNumber numberWithInteger:[typeID integerValue]];
Skill *s = [[[GlobalData sharedInstance]skillTree] skillForId:key];
if(s == nil){
NSLog(@"Skill was null for skill id %@",key);
return;
}
NSString *training = [NSString stringWithFormat:@"%@ %@",[s skillName],
romanForString([character stringForKey:CHAR_TRAINING_LEVEL])];
[charTraining setStringValue:training];
[charTraining sizeToFit];
NSString *endTime = [NSString stringWithFormat:@"%@ +0000",[character stringForKey:CHAR_TRAINING_END]];
NSDate *finishDate = [NSDate dateWithString:endTime];
NSTimeInterval timeDiff = [finishDate timeIntervalSinceNow];
[timeRemaining setInterval:timeDiff];
[timeRemaining activate];
/*this needs the character sheet to calculate, and also needs the training sheet to know if it should be displayed*/
NSInteger sphr = [character spPerHour];
[trainingRate setStringValue:[NSString stringWithFormat:@"%ld SP/hr",sphr]];
[trainingRate sizeToFit];
trainingSkill = [[character st]skillForId:[character trainingSkill]];
}
-(void) characterDidUpdate:(Character*)character didSucceed:(BOOL)success docPath:(NSString*)docPath
{
if(currentCharacter != character){ //if the character being updated is not the current character, return.
return;
}
if([docPath isEqualToString:XMLAPI_CHAR_SHEET]){
if(!success){
NSLog(@"Error fetching character data for %@",[character characterName]);
[self clearCharDetails];
return;
}
[skillTree setDataSource:character];
[skillTree reloadData];
[self showCharDetails:character];
if([character isTraining]){
[self showCharTrainingQueue:character];
}
}else if([docPath isEqualToString:XMLAPI_CHAR_TRAINING]){
if(!success){
NSLog(@"Error fetching character training data for %@",[character characterName]);
[self clearCharTrainingDetails];
return;
}
[self showCharTrainingDetails:character];
}else if([docPath isEqualToString:PORTRAIT]){
if(!success){
NSLog(@"Error fetching character portrait for %@",[character characterName]);
return;
}
NSImage *pic = [character portrait];
if(pic != nil){
[portrait setImage:pic];
}
}else if([docPath isEqualToString:XMLAPI_CHAR_QUEUE]){
if(!success){
NSLog(@"Error fetching character portrait for %@",[character characterName]);
[self clearCharTrainingQueue];
return;
}
[self showCharTrainingQueue:character];
}
}
@end
@implementation CharacterSheetController
-(Character*) character
{
return currentCharacter;
}
-(void) setCharacter:(Character*)c;
{
if(c == nil){
return;
}
if(currentCharacter == c){
return;
}
if(currentCharacter != nil){
[currentCharacter release];
}
[self clearCharDetails];
[self clearCharTrainingDetails];
[self clearCharTrainingQueue];
currentCharacter = [c retain];
[self showCharDetails:currentCharacter];
[self showCharTrainingDetails:currentCharacter];
[self showCharTrainingQueue:currentCharacter];
[portrait setImage:[currentCharacter portrait]];
[skillTree setDataSource:currentCharacter];
}
-(void) viewIsActive
{
[queueHeader setNeedsDisplay:YES];
}
/*window is now inactive, clear instance variables of datasources and stuff*/
-(void) viewIsInactive
{
[skillTree setDataSource:nil];
[portrait setImage:nil];
[self clearCharDetails];
[self clearCharTrainingDetails];
[self clearCharTrainingQueue];
if(currentCharacter != nil){
[currentCharacter release];
currentCharacter = nil;
}
}
-(void) viewWillBeDeactivated
{
}
-(void) viewWillBeActivated
{
}
/*not implemeted*/
-(NSMenuItem*) menuItems
{
return nil;
}
-(NSView*) view
{
return [super view];
}
-(void) dealloc
{
if(currentCharacter != nil){
[currentCharacter release];
}
[super dealloc];
}
-(CharacterSheetController*) init
{
if((self = [super initWithNibName:@"CharacterSheet" bundle:nil])){
currentCharacter = nil;
}
return self;
}
-(void) awakeFromNib
{
NSLog(@"Awoken from nib");
/*Number formatter for the characters balance*/
NSNumberFormatter *f = [[NSNumberFormatter alloc]init];
[f setFormatterBehavior:NSNumberFormatterBehavior10_4];
[f setDecimalSeparator:@"."];
[f setMinimumFractionDigits:2];
[f setGeneratesDecimalNumbers:YES];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
[f setPositiveSuffix:@" ISK"];
[f setNegativeSuffix:@" ISK"];
[charIsk setFormatter:f];
[f release];
/*formatter for skill points*/
f = [[NSNumberFormatter alloc]init];
[f setFormatterBehavior:NSNumberFormatterBehavior10_4];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
[f setPositiveSuffix:@" SP"];
[charSP setFormatter:f];
[cloneSP setFormatter:f];
[f release];
SPFormatter = [[NSNumberFormatter alloc]init];
[SPFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[SPFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[skillTree setDoubleAction:@selector(skillTreeDoubleClick:)];
[skillTree setAction:@selector(skillTreeSingleClick:)];
[skillTree setTarget:self];
[skillTree setDelegate:self];
/*set up the cell for drawing skills*/
MTEveSkillCell *cell = [[skillTree tableColumnWithIdentifier:COL_SKILL_NAME]dataCell];
[cell setTarget:self];
[queueHeader setHidden:YES];
}
-(void) skillTreeDoubleClick:(id)sender
{
id item = [sender itemAtRow:[sender selectedRow]];
if(![item isKindOfClass:[Skill class]]){
return;
}
[SkillDetailsWindowController displayWindowForSkill:item forCharacter:currentCharacter];
}
-(void) skillTreeSingleClick:(id)sender
{
NSPoint mouse = [[sender window] convertScreenToBase:[NSEvent mouseLocation]];
mouse = [(NSOutlineView*)sender convertPoint:mouse fromView:nil];
NSInteger row = [sender rowAtPoint:mouse];
if(row == -1){
return;
}
id item = [sender itemAtRow:row];
if([item isKindOfClass:[SkillGroup class]]){
if([sender isItemExpanded:item]){
[sender collapseItem:item];
}else{
[sender expandItem:item];
}
}
}
-(void) infoButtonAction:(NSOutlineView*)sender
{
NSInteger row = [sender clickedRow];
[SkillDetailsWindowController displayWindowForSkill:
[sender itemAtRow:row] forCharacter:currentCharacter];
}
- (void)outlineView:(NSOutlineView *)outlineView
willDisplayOutlineCell:(id)cell
forTableColumn:(NSTableColumn *)tableColumn
item:(id)item
{
if(![cell isKindOfClass:[MTEveSkillCell class]]){
return;
}
MTEveSkillCell *eveCell = cell;
if([[tableColumn identifier]isEqualToString:COL_SKILL_NAME]){
if([item isKindOfClass:[Skill class]]){
[eveCell setMode:Mode_Skill];
[eveCell setSkill:item];
[eveCell setSkillInfoButtonAction:@selector(infoButtonAction:)];
if([item skillLevel] == 5){
[eveCell setTimeLeft:0];
[eveCell setPercentCompleted:0];
[eveCell setCurrentSP:[item skillPoints]];
}else{
NSInteger skillLevel = [item skillLevel];
/*set the percentage completed bar*/
[eveCell setPercentCompleted:
[currentCharacter percentCompleted:[item typeID]
fromLevel:skillLevel
toLevel:skillLevel+1]
];
/*set the remaining training time*/
[eveCell setTimeLeft:
[currentCharacter trainingTimeInSeconds:[item typeID]
fromLevel:skillLevel
toLevel:skillLevel+1
accountForTrainingSkill:YES]
];
if([currentCharacter isTraining] &&
[[currentCharacter trainingSkill]isEqualToNumber:[item typeID]])
{
[eveCell setCurrentSP:[currentCharacter currentSPForTrainingSkill]];
}else{
[eveCell setCurrentSP:[item skillPoints]];
}
}
}else{
[eveCell setMode:Mode_Group];
[eveCell setGroup:item];
}
}
}
- (void)outlineView:(NSOutlineView *)outlineView
willDisplayCell:(id)cell
forTableColumn:(NSTableColumn *)tableColumn
item:(id)item
{
[self outlineView:outlineView
willDisplayOutlineCell:cell
forTableColumn:tableColumn
item:item];
}
- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item
{
if([item isKindOfClass:[Skill class]]){
return 36.0;
}
return [outlineView rowHeight];
}
@end