-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSAAdventureWindowController.m
More file actions
1576 lines (1448 loc) · 70.4 KB
/
DSAAdventureWindowController.m
File metadata and controls
1576 lines (1448 loc) · 70.4 KB
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* All rights reserved */
#import "DSAAdventureWindowController.h"
#import "DSAAdventureDocument.h"
#import "DSACharacterDocument.h"
#import "DSACharacterPortraitView.h"
#import "DSACharacter.h"
#import "DSAAventurianDate.h"
#import "DSAAventurianCalendar.h"
#import "DSAAdventureClock.h"
#import "DSAClockAnimationView.h"
#import "DSAAdventure.h"
#import "DSAAdventureGroup.h"
#import "Utils.h"
#import "DSAActionIcon.h"
#import "DSALocation.h"
#import "DSALocations.h"
#import "DSAPricingEngine.h"
#import "DSADialog.h"
#import "DSADialogManager.h"
#import "DSAConversationDialogSheetController.h"
#import "DSAActionChoiceQuestionController.h"
#import "DSAMapViewController.h"
#import "DSAMapCoordinate.h"
#import "DSAAdventureMainImageView.h"
#import "DSAShopViewController.h"
#import "DSAShoppingCart.h"
#import "DSAConversationController.h"
#import "DSAShopBargainController.h"
#import "DSAActionResult.h"
#import "DSAInventoryManager.h"
extern NSString * const DSACharacterHighlightedNotification;
extern NSString * const DSALocalMapTileBuildingInnTypeHerberge;
extern NSString * const DSALocalMapTileBuildingInnTypeHerbergeMitTaverne;
extern NSString * const DSALocalMapTileBuildingInnTypeTaverne;
@implementation DSAAdventureWindowController
- (DSAAdventureWindowController *)init
{
NSLog(@"DSAAdventureWindowController: init called");
self = [super init];
if (self)
{
}
return self;
}
- (void)dealloc {
NSLog(@"DSAAdventureWindowController is being deallocated.");
[[NSNotificationCenter defaultCenter] removeObserver:self];
NSLog(@"removing observer of DSAAdventureDocument!");
[(DSAAdventureDocument *)self.document removeObserver:self forKeyPath:@"selectedCharacterDocument"];
NSLog(@"DSAAdventureWindowController finished with dealloc");
}
- (void)close {
NSLog(@"Window is being closed manually, cleaning up.");
[self.window close]; // This ensures the window is properly closed
[self.clockAnimationView removeFromSuperview]; // Manually remove the view
self.clockAnimationView = nil; // Set the reference to nil
}
- (void)windowWillClose:(NSNotification *)notification {
// Remove observer before window closes
NSLog(@"DSAAdventureWindowController windowWillClose: removing observer of DSAAdventureDocument!");
if (self.document) {
[self.document removeObserver:self forKeyPath:@"selectedCharacterDocument"];
}
[self.clockAnimationView removeFromSuperview];
[self.clockAnimationView.gameClock.gameTimer invalidate];
self.clockAnimationView.gameClock.gameTimer = nil;
[self.clockAnimationView.updateTimer invalidate];
self.clockAnimationView.updateTimer = nil;
self.clockAnimationView = nil;
[self.clockAnimationView removeFromSuperview];
self.window.contentView = nil; // Force the window to release views
//[super windowWillClose:notification];
}
- (DSAAdventureWindowController *)initWithWindowNibName:(NSString *)nibNameOrNil
{
NSLog(@"DSAAdventureWindowController initWithWindowNibName %@", nibNameOrNil);
self = [super initWithWindowNibName:nibNameOrNil];
if (self)
{
NSLog(@"DSAAdventureWindowController initialized with nib: %@", nibNameOrNil);
}
else
{
NSLog(@"DSAAdventureWindowController had trouble initializing");
}
return self;
}
- (void)awakeFromNib
{
[super awakeFromNib];
NSLog(@"DSAAdventureWindowController: awakeFromNib called, Adding observers...");
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleCharacterChanges)
name:@"DSAAdventureCharactersUpdated"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateActionIcons:)
name:@"DSAAdventureLocationUpdated"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleTravelDidBegin:)
name:DSAAdventureTravelDidBeginNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleTravelResting:)
name:DSAAdventureTravelRestingNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateActionIcons:)
name:DSAAdventureTravelDidEndNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleLogsMessage:)
name:@"DSACharacterEventLog"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onEncounterTriggered:)
name: DSAEncounterTriggeredNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(replaceMainImage:)
name: DSAUpdateMainImageViewNotification
object:nil];
DSAAdventureDocument *adventureDoc = (DSAAdventureDocument *)self.document;
[adventureDoc addObserver:self
forKeyPath:@"selectedCharacterDocument"
options:NSKeyValueObservingOptionNew
context:nil];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"Ranke_1" ofType:@"jpg"];
NSImage *image = imagePath ? [[NSImage alloc] initWithContentsOfFile:imagePath] : nil;
self.imageHorizontalRuler0.image = image;
self.imageHorizontalRuler1.image = image;
[self.imageHorizontalRuler0 setImageScaling:NSImageScaleAxesIndependently];
[self.imageHorizontalRuler1 setImageScaling:NSImageScaleAxesIndependently];
imagePath = [[NSBundle mainBundle] pathForResource:@"Ranke_2" ofType:@"jpg"];
image = imagePath ? [[NSImage alloc] initWithContentsOfFile:imagePath] : nil;
self.imageVerticalRuler0.image = image;
[self.imageVerticalRuler0 setImageScaling:NSImageScaleAxesIndependently];
imagePath = [[NSBundle mainBundle] pathForResource:@"DSA-Fanprojekt-Logo-gross" ofType:@"png"];
image = imagePath ? [[NSImage alloc] initWithContentsOfFile:imagePath] : nil;
self.imageLogo.image = image;
[self.imageLogo setImageScaling:NSImageScaleAxesIndependently];
CGFloat width = self.imageHorizontalRuler0.frame.size.width;
CGFloat height = self.imageHorizontalRuler0.frame.size.height;
NSLog(@"imageHorizontalRuler0 dimensions: %.2f x %.2f", width, height);
width = self.imageVerticalRuler0.frame.size.width;
height = self.imageVerticalRuler0.frame.size.height;
NSLog(@"imageVerticalRuler0 dimensions: %.2f x %.2f", width, height);
[self updateMainImageView: nil];
[self handleCharacterChanges];
[self setupActionIcons: nil];
[self updateActionIcons: nil];
}
- (DSAActionIcon *)clearActionIcon:(DSAActionIcon *)oldIcon {
NSRect frame = oldIcon.frame;
DSAActionIcon *emptyIcon = [[DSAActionIcon alloc] initWithFrame:frame];
[emptyIcon setImageFrameStyle:NSImageFramePhoto];
[self replaceView:oldIcon withView:emptyIcon];
return emptyIcon;
}
- (void) setupActionIcons: (NSNotification *) notification
{
NSDictionary *userInfo = notification.userInfo;
DSAAdventure *adventure = [DSAAdventureManager sharedManager].currentAdventure;
DSAAdventureGroup *activeGroup = adventure.activeGroup;
DSAPosition *currentPosition = activeGroup.position;
DSALocation *currentLocation = [[DSALocations sharedInstance] locationWithName: currentPosition.localLocationName ofType:@"local"];
DSALocation *globalLocation = [[DSALocations sharedInstance] locationWithName: currentPosition.globalLocationName ofType:@"global"];
NSLog(@"DSAAdventureWindowController setupActionIcons called!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
if (!currentLocation && !globalLocation)
{
NSLog(@"DSAAdventureWindowController setupActionIcons : Fehlende Location-Daten");
return;
}
if (!currentLocation) // we only have a global location
{
if ([currentPosition.context isEqualToString: DSAActionContextTravel])
{
NSLog(@"DSAAdventureWindowController setupActionIcons for global location in travel context not yet implemented!");
if ([self.imageActionIcon0 isKindOfClass: [DSAActionIconRest class]])
{
[self.imageActionIcon0 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"rest" andSize:@"128x128"];
[self replaceView:self.imageActionIcon0 withView:newIcon];
self.imageActionIcon0 = newIcon;
[self.imageActionIcon0 updateAppearance];
}
if ([self.imageActionIcon1 isKindOfClass: [DSAActionIconMap class]])
{
[self.imageActionIcon1 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"map" andSize:@"128x128"];
[self replaceView:self.imageActionIcon1 withView:newIcon];
self.imageActionIcon1 = newIcon;
[self.imageActionIcon1 updateAppearance];
}
if ([self.imageActionIcon2 isKindOfClass: [DSAActionIconChangeRoute class]])
{
[self.imageActionIcon2 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"changeRoute" andSize:@"128x128"];
[self replaceView:self.imageActionIcon2 withView:newIcon];
self.imageActionIcon2 = newIcon;
[self.imageActionIcon2 updateAppearance];
}
self.imageActionIcon3 = [self clearActionIcon:self.imageActionIcon3];
self.imageActionIcon4 = [self clearActionIcon:self.imageActionIcon4];
self.imageActionIcon5 = [self clearActionIcon:self.imageActionIcon5];
self.imageActionIcon6 = [self clearActionIcon:self.imageActionIcon6];
self.imageActionIcon7 = [self clearActionIcon:self.imageActionIcon7];
self.imageActionIcon8 = [self clearActionIcon:self.imageActionIcon8];
}
else if ([currentPosition.context isEqualToString: DSAActionContextResting])
{
if ([self.imageActionIcon0 isKindOfClass: [DSAActionIconChat class]])
{
[self.imageActionIcon0 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"chat" andSize:@"128x128"];
[self replaceView:self.imageActionIcon0 withView:newIcon];
self.imageActionIcon0 = newIcon;
[self.imageActionIcon0 updateAppearance];
}
if ([self.imageActionIcon1 isKindOfClass: [DSAActionIconGuardSelection class]])
{
[self.imageActionIcon1 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"selectGuards" andSize:@"128x128"];
[self replaceView:self.imageActionIcon1 withView:newIcon];
self.imageActionIcon1 = newIcon;
[self.imageActionIcon1 updateAppearance];
}
if ([self.imageActionIcon2 isKindOfClass: [DSAActionIconSleep class]])
{
[self.imageActionIcon2 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"sleep" andSize:@"128x128"];
[self replaceView:self.imageActionIcon2 withView:newIcon];
self.imageActionIcon2 = newIcon;
[self.imageActionIcon2 updateAppearance];
}
if ([self.imageActionIcon3 isKindOfClass: [DSAActionIconTalent class]])
{
[self.imageActionIcon3 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"useTalent" andSize:@"128x128"];
[self replaceView:self.imageActionIcon3 withView:newIcon];
self.imageActionIcon3 = newIcon;
[self.imageActionIcon3 updateAppearance];
}
if ([self.imageActionIcon4 isKindOfClass: [DSAActionIconMagic class]])
{
[self.imageActionIcon4 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"useMagic" andSize:@"128x128"];
[self replaceView:self.imageActionIcon4 withView:newIcon];
self.imageActionIcon4 = newIcon;
[self.imageActionIcon4 updateAppearance];
}
if ([self.imageActionIcon5 isKindOfClass: [DSAActionIconRitual class]])
{
[self.imageActionIcon5 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"useRitual" andSize:@"128x128"];
[self replaceView:self.imageActionIcon5 withView:newIcon];
self.imageActionIcon5 = newIcon;
[self.imageActionIcon5 updateAppearance];
}
if ([self.imageActionIcon6 isKindOfClass: [DSAActionIconSwitchActiveGroup class]])
{
[self.imageActionIcon6 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"switchActiveGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon6 withView:newIcon];
self.imageActionIcon6 = newIcon;
[self.imageActionIcon6 updateAppearance];
}
if ([self.imageActionIcon7 isKindOfClass: [DSAActionIconHunt class]])
{
[self.imageActionIcon7 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"hunt" andSize:@"128x128"];
[self replaceView:self.imageActionIcon7 withView:newIcon];
self.imageActionIcon7 = newIcon;
[self.imageActionIcon7 updateAppearance];
}
if ([self.imageActionIcon8 isKindOfClass: [DSAActionIconCollectHerbs class]])
{
[self.imageActionIcon8 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"collectHerbs" andSize:@"128x128"];
[self replaceView:self.imageActionIcon8 withView:newIcon];
self.imageActionIcon8 = newIcon;
[self.imageActionIcon8 updateAppearance];
}
}
else if ([currentPosition.context isEqualToString: DSAActionContextTravelEncounter])
{
DSAEncounterType encounterType = [userInfo[@"encounterType"] integerValue];
switch (encounterType) {
case DSAEncounterTypeMerchant: [self setupActionIconsForShop]; break;
default:
NSLog(@"DSAAdventureWindowController setupActionIcons: unhandledEncounterType: %@, aborting", @(encounterType));
abort();
}
}
else
{
NSLog(@"DSAAdventureWindowController setupActionIcons: unknown global position context: %@, aborting", currentPosition.context);
abort();
}
return;
}
// Local map tiles related action icons
if ([currentLocation isKindOfClass: [DSALocalMapLocation class]])
{
DSALocalMapLocation *lml = (DSALocalMapLocation *)currentLocation;
DSALocalMapTile *currentTile = [lml tileAtCoordinate: currentPosition.mapCoordinate];
if ([currentTile isKindOfClass: [DSALocalMapTileBuildingShop class]])
{
if ([self.imageActionIcon0 isKindOfClass: [DSAActionIconChat class]])
{
[self.imageActionIcon0 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"chat" andSize:@"128x128"];
[self replaceView:self.imageActionIcon0 withView:newIcon];
self.imageActionIcon0 = newIcon;
[self.imageActionIcon0 updateAppearance];
}
if ([self.imageActionIcon1 isKindOfClass: [DSAActionIconBuy class]])
{
[self.imageActionIcon1 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"buy" andSize:@"128x128"];
[self replaceView:self.imageActionIcon1 withView:newIcon];
self.imageActionIcon1 = newIcon;
[self.imageActionIcon1 updateAppearance];
}
if ([self.imageActionIcon2 isKindOfClass: [DSAActionIconSell class]])
{
[self.imageActionIcon2 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"sell" andSize:@"128x128"];
[self replaceView:self.imageActionIcon2 withView:newIcon];
self.imageActionIcon2 = newIcon;
[self.imageActionIcon2 updateAppearance];
}
self.imageActionIcon3 = [self clearActionIcon:self.imageActionIcon3];
self.imageActionIcon4 = [self clearActionIcon:self.imageActionIcon4];
self.imageActionIcon5 = [self clearActionIcon:self.imageActionIcon5];
if ([self.imageActionIcon6 isKindOfClass: [DSAActionIconSwitchActiveGroup class]])
{
[self.imageActionIcon6 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"switchActiveGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon6 withView:newIcon];
self.imageActionIcon6 = newIcon;
[self.imageActionIcon6 updateAppearance];
}
self.imageActionIcon7 = [self clearActionIcon:self.imageActionIcon7];
if ([self.imageActionIcon8 isKindOfClass: [DSAActionIconLeave class]])
{
[self.imageActionIcon8 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"leave" andSize:@"128x128"];
[self replaceView:self.imageActionIcon8 withView:newIcon];
self.imageActionIcon8 = newIcon;
[self.imageActionIcon8 updateAppearance];
}
}
else if ([currentTile isKindOfClass: [DSALocalMapTileBuildingInn class]])
{
NSString *tileType = [(DSALocalMapTileBuildingInn*)currentTile type];
NSLog(@"DSAAdventureWindowController setupActionIcons: I'm on DSALocalMapTileBuildingInn: currentPosition: %@", currentPosition);
if ([self.imageActionIcon0 isKindOfClass: [DSAActionIconChat class]])
{
[self.imageActionIcon0 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"chat" andSize:@"128x128"];
[self replaceView:self.imageActionIcon0 withView:newIcon];
self.imageActionIcon0 = newIcon;
[self.imageActionIcon0 updateAppearance];
}
if ([tileType isEqualToString: DSALocalMapTileBuildingInnTypeHerberge] ||
[tileType isEqualToString: DSALocalMapTileBuildingInnTypeHerbergeMitTaverne])
{
if ([currentPosition.context isEqualToString: DSAActionContextReception])
{
if ([self.imageActionIcon1 isKindOfClass: [DSAActionIconRoom class]])
{
[self.imageActionIcon1 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"rentRoom" andSize:@"128x128"];
[self replaceView:self.imageActionIcon1 withView:newIcon];
self.imageActionIcon1 = newIcon;
[self.imageActionIcon1 updateAppearance];
}
}
else if ([currentPosition.context isEqualToString: DSAActionContextPrivateRoom])
{
if ([self.imageActionIcon1 isKindOfClass: [DSAActionIconSleep class]])
{
[self.imageActionIcon1 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"sleep" andSize:@"128x128"];
[self replaceView:self.imageActionIcon1 withView:newIcon];
self.imageActionIcon1 = newIcon;
[self.imageActionIcon1 updateAppearance];
}
}
else
{
NSLog(@"DSAAdventureWindowController setupActionIcons current tile class: DSALocalMapTileBuildingInn unknown context: %@", currentPosition.context);
}
}
else
{
self.imageActionIcon1 = [self clearActionIcon:self.imageActionIcon1];
}
if ([self.imageActionIcon2 isKindOfClass: [DSAActionIconMeal class]])
{
[self.imageActionIcon2 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"orderMeal" andSize:@"128x128"];
[self replaceView:self.imageActionIcon2 withView:newIcon];
self.imageActionIcon2 = newIcon;
[self.imageActionIcon2 updateAppearance];
}
if (([tileType isEqualToString: DSALocalMapTileBuildingInnTypeHerberge] ||
[tileType isEqualToString: DSALocalMapTileBuildingInnTypeHerbergeMitTaverne]) &&
[currentPosition.context isEqualToString: DSAActionContextPrivateRoom])
{
if ([self.imageActionIcon3 isKindOfClass: [DSAActionIconRitual class]])
{
[self.imageActionIcon3 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"useRitual" andSize:@"128x128"];
[self replaceView:self.imageActionIcon3 withView:newIcon];
self.imageActionIcon3 = newIcon;
[self.imageActionIcon3 updateAppearance];
}
}
else
{
self.imageActionIcon3 = [self clearActionIcon:self.imageActionIcon3];
}
if ((([tileType isEqualToString: DSALocalMapTileBuildingInnTypeHerberge] ||
[tileType isEqualToString: DSALocalMapTileBuildingInnTypeHerbergeMitTaverne]) &&
[currentPosition.context isEqualToString: DSAActionContextPrivateRoom]) ||
[tileType isEqualToString: DSALocalMapTileBuildingInnTypeTaverne] ||
([tileType isEqualToString: DSALocalMapTileBuildingInnTypeHerbergeMitTaverne] &&
[currentPosition.context isEqualToString: DSAActionContextTavern]))
{
if ([self.imageActionIcon4 isKindOfClass: [DSAActionIconTalent class]])
{
[self.imageActionIcon4 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"useTalent" andSize:@"128x128"];
[self replaceView:self.imageActionIcon4 withView:newIcon];
self.imageActionIcon4 = newIcon;
[self.imageActionIcon4 updateAppearance];
}
if ([self.imageActionIcon5 isKindOfClass: [DSAActionIconMagic class]])
{
[self.imageActionIcon5 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"useMagic" andSize:@"128x128"];
[self replaceView:self.imageActionIcon5 withView:newIcon];
self.imageActionIcon5 = newIcon;
[self.imageActionIcon5 updateAppearance];
}
}
else
{
self.imageActionIcon4 = [self clearActionIcon:self.imageActionIcon4];
self.imageActionIcon5 = [self clearActionIcon:self.imageActionIcon5];
}
if ([self.imageActionIcon6 isKindOfClass: [DSAActionIconSwitchActiveGroup class]])
{
[self.imageActionIcon6 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"switchActiveGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon6 withView:newIcon];
self.imageActionIcon6 = newIcon;
[self.imageActionIcon6 updateAppearance];
}
self.imageActionIcon7 = [self clearActionIcon:self.imageActionIcon7];
if ([self.imageActionIcon8 isKindOfClass: [DSAActionIconLeave class]])
{
[self.imageActionIcon8 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"leave" andSize:@"128x128"];
[self replaceView:self.imageActionIcon8 withView:newIcon];
self.imageActionIcon8 = newIcon;
[self.imageActionIcon8 updateAppearance];
}
}
else if ([currentTile isKindOfClass: [DSALocalMapTileBuildingHealer class]])
{
if ([self.imageActionIcon0 isKindOfClass: [DSAActionIconChat class]])
{
[self.imageActionIcon0 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"chat" andSize:@"128x128"];
[self replaceView:self.imageActionIcon0 withView:newIcon];
self.imageActionIcon0 = newIcon;
[self.imageActionIcon0 updateAppearance];
}
self.imageActionIcon1 = [self clearActionIcon:self.imageActionIcon1];
self.imageActionIcon2 = [self clearActionIcon:self.imageActionIcon2];
self.imageActionIcon3 = [self clearActionIcon:self.imageActionIcon3];
self.imageActionIcon4 = [self clearActionIcon:self.imageActionIcon4];
self.imageActionIcon5 = [self clearActionIcon:self.imageActionIcon5];
if ([self.imageActionIcon6 isKindOfClass: [DSAActionIconSwitchActiveGroup class]])
{
[self.imageActionIcon6 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"switchActiveGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon6 withView:newIcon];
self.imageActionIcon6 = newIcon;
[self.imageActionIcon6 updateAppearance];
}
self.imageActionIcon7 = [self clearActionIcon:self.imageActionIcon7];
if ([self.imageActionIcon8 isKindOfClass: [DSAActionIconLeave class]])
{
[self.imageActionIcon8 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"leave" andSize:@"128x128"];
[self replaceView:self.imageActionIcon8 withView:newIcon];
self.imageActionIcon8 = newIcon;
[self.imageActionIcon8 updateAppearance];
}
}
else if ([currentTile isKindOfClass: [DSALocalMapTileBuildingSmith class]])
{
if ([self.imageActionIcon0 isKindOfClass: [DSAActionIconChat class]])
{
[self.imageActionIcon0 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"chat" andSize:@"128x128"];
[self replaceView:self.imageActionIcon0 withView:newIcon];
self.imageActionIcon0 = newIcon;
[self.imageActionIcon0 updateAppearance];
}
self.imageActionIcon1 = [self clearActionIcon:self.imageActionIcon1];
self.imageActionIcon2 = [self clearActionIcon:self.imageActionIcon2];
self.imageActionIcon3 = [self clearActionIcon:self.imageActionIcon3];
self.imageActionIcon4 = [self clearActionIcon:self.imageActionIcon4];
self.imageActionIcon5 = [self clearActionIcon:self.imageActionIcon5];
if ([self.imageActionIcon6 isKindOfClass: [DSAActionIconSwitchActiveGroup class]])
{
[self.imageActionIcon6 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"switchActiveGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon6 withView:newIcon];
self.imageActionIcon6 = newIcon;
[self.imageActionIcon6 updateAppearance];
}
self.imageActionIcon7 = [self clearActionIcon:self.imageActionIcon7];
if ([self.imageActionIcon8 isKindOfClass: [DSAActionIconLeave class]])
{
[self.imageActionIcon8 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"leave" andSize:@"128x128"];
[self replaceView:self.imageActionIcon8 withView:newIcon];
self.imageActionIcon8 = newIcon;
[self.imageActionIcon8 updateAppearance];
}
}
else if ([currentTile isKindOfClass: [DSALocalMapTileBuildingTemple class]])
{
if ([self.imageActionIcon0 isKindOfClass: [DSAActionIconChat class]])
{
[self.imageActionIcon0 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"chat" andSize:@"128x128"];
[self replaceView:self.imageActionIcon0 withView:newIcon];
self.imageActionIcon0 = newIcon;
[self.imageActionIcon0 updateAppearance];
}
if ([self.imageActionIcon1 isKindOfClass: [DSAActionIconAddToGroup class]])
{
[self.imageActionIcon1 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"donate" andSize:@"128x128"];
[self replaceView:self.imageActionIcon1 withView:newIcon];
self.imageActionIcon1 = newIcon;
[self.imageActionIcon1 updateAppearance];
}
if ([self.imageActionIcon2 isKindOfClass: [DSAActionIconAddToGroup class]])
{
[self.imageActionIcon2 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"pray" andSize:@"128x128"];
[self replaceView:self.imageActionIcon2 withView:newIcon];
self.imageActionIcon2 = newIcon;
[self.imageActionIcon2 updateAppearance];
}
if ([self.imageActionIcon3 isKindOfClass: [DSAActionIconAddToGroup class]])
{
[self.imageActionIcon3 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"addToGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon3 withView:newIcon];
self.imageActionIcon3 = newIcon;
[self.imageActionIcon3 updateAppearance];
}
if ([self.imageActionIcon4 isKindOfClass: [DSAActionIconRemoveFromGroup class]])
{
[self.imageActionIcon4 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"removeFromGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon4 withView:newIcon];
self.imageActionIcon4 = newIcon;
[self.imageActionIcon4 updateAppearance];
}
self.imageActionIcon5 = [self clearActionIcon:self.imageActionIcon5];
if ([self.imageActionIcon6 isKindOfClass: [DSAActionIconSwitchActiveGroup class]])
{
[self.imageActionIcon6 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"switchActiveGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon6 withView:newIcon];
self.imageActionIcon6 = newIcon;
[self.imageActionIcon6 updateAppearance];
}
self.imageActionIcon7 = [self clearActionIcon:self.imageActionIcon7];
if ([self.imageActionIcon8 isKindOfClass: [DSAActionIconLeave class]])
{
[self.imageActionIcon8 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"leave" andSize:@"128x128"];
[self replaceView:self.imageActionIcon8 withView:newIcon];
self.imageActionIcon8 = newIcon;
[self.imageActionIcon8 updateAppearance];
}
}
else if ([currentTile isMemberOfClass: [DSALocalMapTileStreet class]] ||
[currentTile isMemberOfClass: [DSALocalMapTileGreen class]])
{
if ([self.imageActionIcon0 isKindOfClass: [DSAActionIconSplitGroup class]])
{
[self.imageActionIcon0 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"splitGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon0 withView:newIcon];
self.imageActionIcon0 = newIcon;
[self.imageActionIcon0 updateAppearance];
}
if ([self.imageActionIcon1 isKindOfClass: [DSAActionIconJoinGroups class]])
{
[self.imageActionIcon1 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"joinGroups" andSize:@"128x128"];
[self replaceView:self.imageActionIcon1 withView:newIcon];
self.imageActionIcon1 = newIcon;
[self.imageActionIcon1 updateAppearance];
}
self.imageActionIcon2 = [self clearActionIcon:self.imageActionIcon2];
self.imageActionIcon3 = [self clearActionIcon:self.imageActionIcon3];
self.imageActionIcon4 = [self clearActionIcon:self.imageActionIcon4];
self.imageActionIcon5 = [self clearActionIcon:self.imageActionIcon5];
if ([self.imageActionIcon6 isKindOfClass: [DSAActionIconSwitchActiveGroup class]])
{
[self.imageActionIcon6 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"switchActiveGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon6 withView:newIcon];
self.imageActionIcon6 = newIcon;
[self.imageActionIcon6 updateAppearance];
}
if ([self.imageActionIcon7 isKindOfClass: [DSAActionIconSwitchActiveGroup class]])
{
[self.imageActionIcon7 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"map" andSize:@"128x128"];
[self replaceView:self.imageActionIcon7 withView:newIcon];
self.imageActionIcon7 = newIcon;
[self.imageActionIcon7 updateAppearance];
}
self.imageActionIcon8 = [self clearActionIcon:self.imageActionIcon8];
}
}
}
-(void) setupActionIconsForShop {
if ([self.imageActionIcon0 isKindOfClass: [DSAActionIconChat class]])
{
[self.imageActionIcon0 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"chat" andSize:@"128x128"];
[self replaceView:self.imageActionIcon0 withView:newIcon];
self.imageActionIcon0 = newIcon;
[self.imageActionIcon0 updateAppearance];
}
if ([self.imageActionIcon1 isKindOfClass: [DSAActionIconBuy class]])
{
[self.imageActionIcon1 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"buy" andSize:@"128x128"];
[self replaceView:self.imageActionIcon1 withView:newIcon];
self.imageActionIcon1 = newIcon;
[self.imageActionIcon1 updateAppearance];
}
if ([self.imageActionIcon2 isKindOfClass: [DSAActionIconSell class]])
{
[self.imageActionIcon2 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"sell" andSize:@"128x128"];
[self replaceView:self.imageActionIcon2 withView:newIcon];
self.imageActionIcon2 = newIcon;
[self.imageActionIcon2 updateAppearance];
}
self.imageActionIcon3 = [self clearActionIcon:self.imageActionIcon3];
self.imageActionIcon4 = [self clearActionIcon:self.imageActionIcon4];
self.imageActionIcon5 = [self clearActionIcon:self.imageActionIcon5];
if ([self.imageActionIcon6 isKindOfClass: [DSAActionIconSwitchActiveGroup class]])
{
[self.imageActionIcon6 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"switchActiveGroup" andSize:@"128x128"];
[self replaceView:self.imageActionIcon6 withView:newIcon];
self.imageActionIcon6 = newIcon;
[self.imageActionIcon6 updateAppearance];
}
self.imageActionIcon7 = [self clearActionIcon:self.imageActionIcon7];
if ([self.imageActionIcon8 isKindOfClass: [DSAActionIconLeave class]])
{
[self.imageActionIcon8 updateAppearance];
}
else
{
DSAActionIcon *newIcon = [DSAActionIcon iconWithAction:@"leave" andSize:@"128x128"];
[self replaceView:self.imageActionIcon8 withView:newIcon];
self.imageActionIcon8 = newIcon;
[self.imageActionIcon8 updateAppearance];
}
}
- (void) handleTravelDidBegin: (NSNotification *)notification
{
NSLog(@"DSAAdventureWindowController handleTravelDidBegin called");
[self updateMainImageView: notification];
[self setupActionIcons: notification];
}
- (void) handleTravelResting: (NSNotification *)notification
{
NSLog(@"DSAAdventureWindowController handleTravelResting called");
[self updateMainImageView: notification];
[self setupActionIcons: notification];
}
- (void) updateActionIcons: (NSNotification *)notification
{
NSLog(@"DSAAdventureWindowController updateActionIcons called!!!!");
[self setupActionIcons: notification];
[self updateMainImageView: notification];
}
- (void)replaceView:(NSView *)oldView withView:(NSView *)newView {
NSView *superview = oldView.superview;
NSRect frame = oldView.frame;
newView.frame = frame;
[oldView removeFromSuperview];
[superview addSubview:newView positioned:NSWindowAbove relativeTo:nil];
}
- (void) handleCharacterChanges {
// Ensure we have a valid adventure document
NSLog(@"DSAAdventureWindowController updatePartyPortraits called!!!");
DSAAdventureDocument *adventureDoc = (DSAAdventureDocument *)self.document;
if (!adventureDoc) return;
//NSLog(@"DSAAdventureWindowController updatePartyPortraits before the NSArray imageViews!!!");
NSArray *imageViews = @[
self.imagePartyMember0,
self.imagePartyMember1,
self.imagePartyMember2,
self.imagePartyMember3,
self.imagePartyMember4,
self.imagePartyMember5
];
NSArray *characters = adventureDoc.characterDocuments;
// Loop through up to 6 characters and assign portraits
for (NSInteger i = 0; i < imageViews.count; i++) {
DSACharacterPortraitView *imageView = imageViews[i];
if (i < characters.count) {
DSACharacterDocument *charDoc = characters[i];
DSACharacter *character = charDoc.model;
imageView.characterDocument = charDoc;
imageView.image = [character portrait]; // Get portrait from model
if ([adventureDoc.model.activeGroup.partyMembers containsObject: character.modelID])
{
imageView.alphaValue = 1.0;
[imageView setNeedsDisplay:YES];
}
else
{
imageView.alphaValue = 0.4;
[imageView setNeedsDisplay:YES];
}
imageView.toolTip = [imageView toolTip];
[imageView updateCharacterNameLabel];
} else {
imageView.image = nil; // Clear unused slots
imageView.characterDocument = nil;
imageView.toolTip = @"";
[imageView updateCharacterNameLabel];
}
}
[self updateActionIcons: nil];
}
- (void)replaceMainImage: (NSNotification *)notification
{
NSDictionary *userInfo = notification.userInfo;
NSString *imageName = userInfo[@"imageName"];
//DSAAdventure *adventure = [DSAAdventureManager sharedManager].currentAdventure;
NSLog (@"DSAAdventureWindowController replaceMainImage called, with image name: %@", imageName);
if (imageName) {
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:nil];
if (imagePath) {
NSImage *image = [[NSImage alloc] initWithContentsOfFile:imagePath];
[self.imageMain setImage:image];
// not every encounter types handled, it'll abort()
//[self.imageMain updateLocationLabel: [adventure locationInfoForMainImageView]];
} else {
NSLog(@"DSAAdventureWindowController replaceMainImage: Bild nicht gefunden im Bundle: %@", imageName);
}
} else {
NSLog(@"DSAAdventureWindowController replaceMainImage: Keine passenden Bilder gefunden für Key: %@", imageName);
}
}
- (void)updateMainImageView: (NSNotification *)notification
{
BOOL showBuildingDialog = NO;
BOOL showRouteDialog = NO;
NSDictionary *userInfo = notification.userInfo;
DSAAdventure *adventure = [DSAAdventureManager sharedManager].currentAdventure;
DSAAdventureGroup *activeGroup = adventure.activeGroup;
DSAPosition *currentPosition = activeGroup.position;
DSALocation *currentLocation = [[DSALocations sharedInstance] locationWithName: currentPosition.localLocationName ofType:@"local"];
DSALocation *globalLocation = [[DSALocations sharedInstance] locationWithName: currentPosition.globalLocationName ofType:@"global"];
NSLog(@"DSAAdventureWindowController updateMainImageView called!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
if (!currentLocation && !globalLocation) {
NSLog(@"DSAAdventureWindowController updateMainImageView : Fehlende Location-Daten");
return;
}
if (!currentLocation) // we only have a global location
{
NSString *selectedKey;
NSString *seed;
if ([currentPosition.context isEqualToString: DSAActionContextTravel])
{
selectedKey = @"Reisen_Strasse";
}
else if ([currentPosition.context isEqualToString: DSAActionContextResting])
{
selectedKey = @"Lagerfeuer";
}
else if ([currentPosition.context isEqualToString: DSAActionContextTravelEncounter])