Class: CountdownWindow

Inherits:
Curses::Window
  • Object
show all
Defined in:
lib/profanity_fe/countdown_window.rb

Constant Summary collapse

@@list =
Array.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CountdownWindow

Returns a new instance of CountdownWindow.



11
12
13
14
15
16
17
18
19
20
# File 'lib/profanity_fe/countdown_window.rb', line 11

def initialize(*args)
	@label = String.new
	@fg = [ ]
	@bg = [ nil, 'ff0000', '0000ff' ]
	@active = nil
	@end_time = 0
	@secondary_end_time = 0
	@@list.push(self)
	super(*args)
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



2
3
4
# File 'lib/profanity_fe/countdown_window.rb', line 2

def active
  @active
end

#bgObject

Returns the value of attribute bg.



2
3
4
# File 'lib/profanity_fe/countdown_window.rb', line 2

def bg
  @bg
end

#end_timeObject

Returns the value of attribute end_time.



2
3
4
# File 'lib/profanity_fe/countdown_window.rb', line 2

def end_time
  @end_time
end

#fgObject

Returns the value of attribute fg.



2
3
4
# File 'lib/profanity_fe/countdown_window.rb', line 2

def fg
  @fg
end

#labelObject

Returns the value of attribute label.



2
3
4
# File 'lib/profanity_fe/countdown_window.rb', line 2

def label
  @label
end

#layoutObject

Returns the value of attribute layout.



2
3
4
# File 'lib/profanity_fe/countdown_window.rb', line 2

def layout
  @layout
end

#secondary_end_timeObject

Returns the value of attribute secondary_end_time.



2
3
4
# File 'lib/profanity_fe/countdown_window.rb', line 2

def secondary_end_time
  @secondary_end_time
end

#secondary_valueObject (readonly)

Returns the value of attribute secondary_value.



3
4
5
# File 'lib/profanity_fe/countdown_window.rb', line 3

def secondary_value
  @secondary_value
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/profanity_fe/countdown_window.rb', line 3

def value
  @value
end

Class Method Details

.listObject



7
8
9
# File 'lib/profanity_fe/countdown_window.rb', line 7

def CountdownWindow.list
	@@list
end

Instance Method Details

#updateObject



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
# File 'lib/profanity_fe/countdown_window.rb', line 21

def update
	old_value, old_secondary_value = @value, @secondary_value
	@value = [(@end_time.to_f - Time.now.to_f + $server_time_offset.to_f - 0.2).ceil, 0].max
	@secondary_value = [(@secondary_end_time.to_f - Time.now.to_f + $server_time_offset.to_f - 0.2).ceil, 0].max
	if (old_value != @value) or (old_secondary_value != @secondary_value) or (@old_active != @active)
		str = "#{@label}#{[ @value, @secondary_value ].max.to_s.rjust(self.maxx - @label.length)}"
		setpos(0, 0)
		if ((@value == 0) and (@secondary_value == 0)) or (@active == false)
			if @active
				str = "#{@label}#{'?'.rjust(self.maxx - @label.length)}"
				left_background_str = str[0,1].to_s
				right_background_str = str[(left_background_str.length),(@label.length + (self.maxx - @label.length))].to_s
				attron(color_pair(get_color_pair_id(@fg[1], @bg[1]))|Curses::A_NORMAL) {
					addstr left_background_str
				}
				attron(color_pair(get_color_pair_id(@fg[2], @bg[2]))|Curses::A_NORMAL) {
					addstr right_background_str
				}
			else
				attron(color_pair(get_color_pair_id(@fg[0], @bg[0]))|Curses::A_NORMAL) {
					addstr str
				}
			end
		else
			left_background_str = str[0,@value].to_s
			secondary_background_str = str[left_background_str.length,(@secondary_value - @value)].to_s
			right_background_str = str[(left_background_str.length + secondary_background_str.length),(@label.length + (self.maxx - @label.length))].to_s
			if left_background_str.length > 0
				attron(color_pair(get_color_pair_id(@fg[1], @bg[1]))|Curses::A_NORMAL) {
					addstr left_background_str
				}
			end
			if secondary_background_str.length > 0
				attron(color_pair(get_color_pair_id(@fg[2], @bg[2]))|Curses::A_NORMAL) {
					addstr secondary_background_str
				}
			end
			if right_background_str.length > 0
				attron(color_pair(get_color_pair_id(@fg[3], @bg[3]))|Curses::A_NORMAL) {
					addstr right_background_str
				}
			end
		end
		@old_active = @active
		noutrefresh
		true
	else
		false
	end
end