# File: ContainerEdit.rb
# Author: Craig Smith
# This source code copyright (C) 2009 Craig Smith
# All rights reserved.
#
# Released under the terms of the GNU Public License
# See COPYING file for additional information.
#
require 'olc/oedit'
require 'utility/log'
# Conatiner Editor OLC
class ContainerEdit < Oedit
logger 'DEBUG'
attr_accessor :cont_hash, :cont_types
def initialize(id, oid, args=nil)
self.title = "Container Editor" if not title
if not obj and not oid
self.obj = Container.new(args, id, nil) if not oid
self.newobj = true
end
super(id,oid,args)
self.cont_types = [ "Food", "Liquid", "Battery", "GameObject" ]
self.cont_hash = { "max_amt" => [ 1, 2, 3, 4, 5, 10, 15, 20, 30, 50 ],
"max_weight" => [ 5, 10, 20, 25, 40, 55, 75, 100, 120, 150 ],
"powered_from" => nil,
"filled_with" => nil
}
self.default_hash.merge!(cont_hash)
end
# Checks if the object is valid
def is_valid?(obj)
return true if obj.kind_of? Container
false
end
def setup_main(m=nil)
super(m)
menu.add_text_option(nil,"Container Types",self,:setup_types_menu, obj.types)
end
def setup_types_menu(m=nil)
smenu = olc_basemenu("Container Types", self, :setup_types_menu, m)
smenu.default_array = cont_types
smenu.set_array = obj.types
smenu.add_toggled_numbered_options(self,:add_type);
submenu(smenu, m)
end
def add_type(m=nil)
if m=~/(\d+)/
idx = m.to_i
if idx > 0 and idx <= cont_types.size
if obj.has_type?(cont_types[idx-1])
obj.del_type(cont_types[idx-1])
else
obj.add_type(cont_types[idx-1])
end
end
end
end
def set_weight(m)
weight = m.to_i
obj.initial_weight = weight if weight > 0
show_menu
obj.initial_weight
end
end