Skip to content

Commit

Permalink
Add option to toggle arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
daylen committed Jan 29, 2015
1 parent ccf080b commit b4dc5cd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Stockfish/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14C81f" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
Expand Down Expand Up @@ -161,6 +161,12 @@
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="View" id="HyV-fh-RgO">
<items>
<menuItem title="Show Arrows" id="DO8-UC-n47">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleShowArrows:" target="-1" id="Fzv-jI-NKO"/>
</connections>
</menuItem>
<menuItem title="Flip Board" keyEquivalent="f" id="5zt-BF-g52">
<connections>
<action selector="flipBoard:" target="-1" id="gET-4O-ZRD"/>
Expand Down
3 changes: 3 additions & 0 deletions Stockfish/SFMUserDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@
+ (NSData *)sandboxBookmarkData;
+ (void)setSandboxBookmarkData:(NSData *)data;

+ (BOOL)arrowsEnabled;
+ (void)setArrowsEnabled:(BOOL)enabled;

@end
12 changes: 12 additions & 0 deletions Stockfish/SFMUserDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define UCI_CONTEMPT @"uci_contempt"
#define UCI_SKILL_LEVEL @"uci_skill_level"
#define SANDBOX_BOOKMARK_DATA @"sandbox_bookmark_data"
#define ARROWS_ENABLED @"arrows_enabled"

@implementation SFMUserDefaults

Expand Down Expand Up @@ -60,4 +61,15 @@ + (void)setSandboxBookmarkData:(NSData *)data {
[[NSUserDefaults standardUserDefaults] setObject:data forKey:SANDBOX_BOOKMARK_DATA];
}

+ (BOOL)arrowsEnabled {
if (![[NSUserDefaults standardUserDefaults] objectForKey:ARROWS_ENABLED]) {
[SFMUserDefaults setArrowsEnabled:YES];
}
return [[NSUserDefaults standardUserDefaults] boolForKey:ARROWS_ENABLED];
}

+ (void)setArrowsEnabled:(BOOL)enabled {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:ARROWS_ENABLED];
}

@end
11 changes: 10 additions & 1 deletion Stockfish/SFMWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "SFMMove.h"
#import "SFMUCILine.h"
#import "SFMPosition.h"
#import "SFMUserDefaults.h"

@interface SFMWindowController ()

Expand Down Expand Up @@ -115,6 +116,12 @@ - (IBAction)increaseVariations:(id)sender {
- (IBAction)decreaseVariations:(id)sender {
self.engine.multipv--;
}
- (IBAction)toggleShowArrows:(id)sender {
[SFMUserDefaults setArrowsEnabled:![SFMUserDefaults arrowsEnabled]];
if (![SFMUserDefaults arrowsEnabled]) {
self.boardView.arrows = nil;
}
}

#pragma mark - Helper methods
- (void)syncToViewsAndEngine
Expand Down Expand Up @@ -216,6 +223,8 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
return ![self.currentGame atEnd];
} else if ([menuItem action] == @selector(decreaseVariations:)) {
return self.engine.multipv != 1;
} else if ([menuItem action] == @selector(toggleShowArrows:)) {
[menuItem setState:[SFMUserDefaults arrowsEnabled] ? NSOnState : NSOffState];
}
return YES;
}
Expand Down Expand Up @@ -264,7 +273,7 @@ - (void)uciEngine:(SFMUCIEngine *)engine didGetNewLine:(NSDictionary *)lines {
[self uciEngine:engine didGetNewCurrentMove:nil number:0 depth:pv.depth];

// Draw an arrow
if ([pv.moves count] > 0) {
if ([pv.moves count] > 0 && [SFMUserDefaults arrowsEnabled]) {
self.boardView.arrows = @[[pv.moves firstObject]];
}
}
Expand Down

0 comments on commit b4dc5cd

Please sign in to comment.