Class: MarsBase10::ActionBar
- Inherits:
-
Object
- Object
- MarsBase10::ActionBar
- Defined in:
- lib/mars_base_10/action_bar.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
Class Method Summary collapse
Instance Method Summary collapse
- #actions_first_col ⇒ Object
- #actions_width ⇒ Object
- #add_action(a_hash) ⇒ Object
- #display_on(viewport:) ⇒ Object
- #draw ⇒ Object
- #first_col ⇒ Object
- #first_row ⇒ Object
- #height ⇒ Object
-
#initialize(actions:) ⇒ ActionBar
constructor
A new instance of ActionBar.
- #remove_actions(keys) ⇒ Object
- #width ⇒ Object
- #window ⇒ Object
Constructor Details
#initialize(actions:) ⇒ ActionBar
Returns a new instance of ActionBar.
7 8 9 10 11 |
# File 'lib/mars_base_10/action_bar.rb', line 7 def initialize(actions:) @actions = actions @viewport = nil @win = nil end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
5 6 7 |
# File 'lib/mars_base_10/action_bar.rb', line 5 def actions @actions end |
Class Method Details
Instance Method Details
#actions_first_col ⇒ Object
17 18 19 |
# File 'lib/mars_base_10/action_bar.rb', line 17 def actions_first_col (self.width - self.actions_width)/2 end |
#actions_width ⇒ Object
21 22 23 |
# File 'lib/mars_base_10/action_bar.rb', line 21 def actions_width self.actions.values.inject(0) {|acc, item| acc += (3 + 2 + item.length + 2)} end |
#add_action(a_hash) ⇒ Object
25 26 27 28 |
# File 'lib/mars_base_10/action_bar.rb', line 25 def add_action(a_hash) self.actions = Hash[@actions.merge!(a_hash).sort] self end |
#display_on(viewport:) ⇒ Object
47 48 49 |
# File 'lib/mars_base_10/action_bar.rb', line 47 def display_on(viewport:) @viewport = end |
#draw ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mars_base_10/action_bar.rb', line 30 def draw self.window.attron(Curses.color_pair(2)) self.window.setpos(0, 0) self.window.addstr("Actions:") self.window.addstr(" " * (self.actions_first_col - 8)) self.actions.each do |key, value| self.window.attron(Curses::A_REVERSE) self.window.addstr(" #{key} ") self.window.attroff(Curses::A_REVERSE) # if item == self.index self.window.addstr(" #{value} ") end self.window.addstr(" " * (self.width - (self.actions_first_col + self.actions_width))) self.window.attroff(Curses.color_pair(2)) end |
#first_col ⇒ Object
51 52 53 |
# File 'lib/mars_base_10/action_bar.rb', line 51 def first_col 0 end |
#first_row ⇒ Object
55 56 57 |
# File 'lib/mars_base_10/action_bar.rb', line 55 def first_row @viewport.max_rows end |
#height ⇒ Object
59 60 61 |
# File 'lib/mars_base_10/action_bar.rb', line 59 def height 1 end |
#remove_actions(keys) ⇒ Object
63 64 65 66 |
# File 'lib/mars_base_10/action_bar.rb', line 63 def remove_actions(keys) self.actions.delete_if {|k, v| keys.include? k} self end |
#width ⇒ Object
68 69 70 |
# File 'lib/mars_base_10/action_bar.rb', line 68 def width @viewport.max_cols end |
#window ⇒ Object
72 73 74 75 |
# File 'lib/mars_base_10/action_bar.rb', line 72 def window return @win if @win @win = Curses::Window.new(self.height, self.width, self.first_row, self.first_col) end |