class Core::GUI::ContextMenu
Small menu available by rightclicking on the map
Public Class Methods
new(x, y, obj=nil)
click to toggle source
Calls superclass method
Core::GUI::Element::new
# File lib/gui/context_menu.rb, line 6 def initialize(x, y, obj=nil) super(x, y, 128, items(obj) * 24) @zoff = 10000 if @x + @w > 1024 @x = 1024 - @w end @buttons = {} setup_defaults(obj) @buttons.each_value { |but| but.zoff = @zoff } end
Public Instance Methods
draw()
click to toggle source
# File lib/gui/context_menu.rb, line 24 def draw @buttons.each_value { |but| but.draw } end
update()
click to toggle source
Calls superclass method
Core::GUI::Element#update
# File lib/gui/context_menu.rb, line 18 def update super @buttons.each_value { |but| but.update } end
Private Instance Methods
in_window?()
click to toggle source
# File lib/gui/context_menu.rb, line 40 def in_window? Core.window.state.osd.each_value { |w| if Core.inside?(@x, @y, w.x, w.y, w.x+w.w, w.y+w.h) return true end } return false end
items(obj)
click to toggle source
# File lib/gui/context_menu.rb, line 32 def items(obj) if obj return 3 else return 2 end end
magic_window(p)
click to toggle source
# File lib/gui/context_menu.rb, line 49 def magic_window(p) Core.window.state.osd.store(:magic, Core::Game::OSD::Magic.new(@x-320, @y-240, p, p)); end
setup_defaults(obj)
click to toggle source
# File lib/gui/context_menu.rb, line 53 def setup_defaults(obj) if in_window? return end npc = player = false if obj if obj.class == Core::Game::MapNPC label = obj.gamename npc = true elsif obj.class == Core::Game::Player player = true label = Core::Trans.menu(:you) else label = obj.name end else label = Core::Trans.menu(:ground) end p = Core.window.state.player @buttons.store(:label, Textfield.new(@x, @y, @w, 24, label, 24)) x = @x - Core.window.state.map.xoff y = @y - Core.window.state.map.yoff if !player if npc @buttons.store(:talk_to, Button.new(@x, @y+(@buttons.size*24), @w, 24, Core::Trans.menu(:talk_to), lambda { puts("STUB: talk_to"); p.find_path_to(x.to_i/32, (y.to_i/32) - (p.y < obj.y ? 1 : -1)); @remove = true }, true, :left)) else @buttons.store(:move, Button.new(@x, @y+(@buttons.size*24), @w, 24, Core::Trans.menu(:walk_here), lambda { p.find_path_to(x.to_i/32, y.to_i/32); @remove = true }, true, :left)) if !Core.window.state.map.current.passable?(x, y) or (obj and !obj.through) # TODO left/right if !obj obj = [x, y] # i <3 ruby end # a* cant find a path to a blocked tile, so shift the position away a bit @buttons[:move].proc = lambda { p.find_path_to(x.to_i/32, (y.to_i/32) - (p.y < obj.y ? 1 : -1)); @remove = true } # TODO check again if it works, the player *must* move end end end if !Core.window.state.osd.has_key?(:magic) @buttons.store(:magic, Button.new(@x, @y+(@buttons.size*24), @w, 24, Core::Trans.menu(:magic), lambda { magic_window(p); @remove = true}, true, :left)) if npc @buttons[:magic].proc = lambda { puts("STUB: othermagic"); @remove = true } end end if $DEBUG and obj @buttons.store(:debug_inspect, Button.new(@x, @y+(@buttons.size*24), @w, 24, "inspect", lambda { awesome_print(obj); @remove = true }, true, :left)) end end