-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
175 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
class TimerHud < Hud | ||
|
||
def init | ||
super.tap do | ||
@layout = TimerHudLayout.new | ||
self.window = @layout.window | ||
self.window.delegate = self | ||
|
||
@label = @layout.get(:label) | ||
end | ||
end | ||
|
||
def game_start | ||
@label.text = nil | ||
@player_mulligan = @opponent_mulligan = false | ||
end | ||
|
||
def game_end | ||
@label.text = nil | ||
if @timer | ||
@timer.invalidate | ||
end | ||
end | ||
|
||
def mulligan_done(who) | ||
who == :player ? @player_mulligan = true : @opponent_mulligan = true | ||
end | ||
|
||
def restart(player) | ||
return unless Configuration.show_timer | ||
|
||
@current_player = player | ||
|
||
if @timer | ||
@timer.invalidate | ||
end | ||
@seconds = 90 | ||
@timer = NSTimer.scheduledTimerWithTimeInterval(1, | ||
target: self, | ||
selector: 'fire:', | ||
userInfo: nil, | ||
repeats: true) | ||
|
||
if (!@player_mulligan and @opponent_mulligan) or (!@opponent_mulligan and @player_mulligan) or (!@player_mulligan and !@opponent_mulligan and @seconds < 85) | ||
@opponent_mulligan = @player_mulligan = true | ||
end | ||
|
||
end | ||
|
||
private | ||
def fire(_) | ||
return if !@player_mulligan and !@opponent_mulligan | ||
|
||
@seconds -= 1 if @seconds > 0 | ||
|
||
seconds = 90 - @seconds | ||
if @seconds < 10 | ||
@label.flash | ||
end | ||
|
||
@label.text = '%02d:%02d' % [(seconds / 60) % 60, seconds % 60] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class TimerHudLayout < MK::WindowLayout | ||
|
||
def layout | ||
wframe = [[400, 120], [200, 80]] | ||
frame = NSUserDefaults.standardUserDefaults.objectForKey 'HSTimer' | ||
if frame | ||
wframe = NSRectFromString(frame) | ||
end | ||
|
||
frame(wframe) | ||
identifier 'HSTimer' | ||
title 'Timer'._ | ||
|
||
# transparent all the things \o| | ||
opaque false | ||
has_shadow false | ||
background_color :black.nscolor(Configuration.window_transparency) | ||
|
||
locked = Configuration.windows_locked | ||
|
||
if locked | ||
mask = NSBorderlessWindowMask | ||
else | ||
mask = NSTitledWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask | NSBorderlessWindowMask | ||
end | ||
style_mask mask | ||
level NSScreenSaverWindowLevel | ||
|
||
add TextHud, :label do | ||
font_size 28 | ||
constraints do | ||
width.equals(:superview).minus(10) | ||
height.equals(:superview).minus(10) | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ def options | |
end | ||
} | ||
}, | ||
:show_timer => 'Show timers'._ | ||
} | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters