Class: Fidgit::MenuPane

Inherits:
Composite show all
Extended by:
Forwardable
Defined in:
lib/fidgit/elements/menu_pane.rb

Defined Under Namespace

Classes: Item, Separator

Constant Summary

Constants inherited from Composite

Composite::DEBUG_BORDER_COLOR

Constants inherited from Element

Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V

Instance Attribute Summary

Attributes inherited from Packer

#spacing_h, #spacing_v

Attributes inherited from Element

#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z

Instance Method Summary collapse

Methods inherited from Container

#add, #button, #clear, #color_picker, #color_well, #combo_box, #file_browser, #grid, #group, #hit_element, #horizontal, #image_frame, #insert, #label, #list, #radio_button, #remove, #scroll_area, #scroll_window, #slider, #text_area, #to_s, #toggle_button, #update, #vertical, #write_tree

Methods inherited from Element

#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #to_s, #update, #width, #width=, #with, #x, #y

Methods included from Event

#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe

Constructor Details

#initialize(options = {}, &block) ⇒ MenuPane

Returns a new instance of MenuPane.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :x (Float) — default: cursor x, if in a GuiState
  • :y (Float) — default: cursor y, if in a GuiState
  • :show (Boolean) — default: true

    Whether to show immediately (show later with #show).



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
# File 'lib/fidgit/elements/menu_pane.rb', line 77

def initialize(options = {}, &block)
  options = {
    background_color: default(:color),
    z: Float::INFINITY,
    show: true,
  }.merge! options

  state = $window.current_game_state
  if state.is_a? GuiState
    cursor = $window.current_game_state.cursor
    options = {
      x: cursor.x,
      y: cursor.y,
    }.merge! options
  end

  @items = nil

  super(options)

  @items = vertical spacing: 0, padding: 0

  if options[:show] and state.is_a? GuiState
    show
  end
end

Instance Method Details

#find(value) ⇒ Object



104
105
106
# File 'lib/fidgit/elements/menu_pane.rb', line 104

def find(value)
  @items.find {|c| c.value == value }
end

#index(value) ⇒ Object



69
# File 'lib/fidgit/elements/menu_pane.rb', line 69

def index(value); @items.index find(value); end

#item(text, value, options = {}, &block) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/fidgit/elements/menu_pane.rb', line 114

def item(text, value, options = {}, &block)
  options = options.merge({
     parent: @items,
     z: z,
  })
  item = Item.new(text, value, options, &block)

  item.subscribe :left_mouse_button, method(:item_selected)
  item.subscribe :right_mouse_button, method(:item_selected)

  item
end

#item_selected(sender, x, y) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/fidgit/elements/menu_pane.rb', line 127

def item_selected(sender, x, y)
  publish(:selected, sender.value)

  $window.game_state_manager.current_game_state.hide_menu

  nil
end

#separator(options = {}) ⇒ Object



108
109
110
111
112
# File 'lib/fidgit/elements/menu_pane.rb', line 108

def separator(options = {})
  options[:z] = z

  Separator.new({ parent: @items }.merge!(options))
end

#showObject



135
136
137
138
# File 'lib/fidgit/elements/menu_pane.rb', line 135

def show
  $window.game_state_manager.current_game_state.show_menu self
  nil
end

#x=(value) ⇒ Object



70
# File 'lib/fidgit/elements/menu_pane.rb', line 70

def x=(value); super(value); recalc; end

#y=(value) ⇒ Object



71
# File 'lib/fidgit/elements/menu_pane.rb', line 71

def y=(value); super(value); recalc; end