class SDK::Scene_Base attr_accessor :parent # Parent scene. Scene_ or nil attr_accessor :layers # An array of layers on top of this scene attr_accessor :active # Activity determines parent updates #-------------------------------------------------------------------------- # * Initialize : Start the scene if it is layered on top of another, since # def main will not be called #-------------------------------------------------------------------------- def initialize(parent = nil) @parent = parent.kind_of?(SDK::Scene_Base) ? parent : nil @previous_scene = @parent == nil ? $scene.class : @parent.class return if @parent == nil # Return if this class is not a layer main_begin # Main Begin main_layer # Main Layer Initialization main_variable # Main Variable Initialization main_spriteset # Main Spriteset Initialization main_sprite # Main Sprite Initialization main_window # Main Window Initialization main_audio # Main Audio Initialization make_layer # Make this a layer main_transition # Main Transition end #-------------------------------------------------------------------------- # * Main Processing #-------------------------------------------------------------------------- def main main_begin # Main Begin main_layer # Main Layer Initialization main_variable # Main Variable Initialization main_spriteset # Main Spriteset Initialization main_sprite # Main Sprite Initialization main_window # Main Window Initialization main_audio # Main Audio Initialization main_transition # Main Transition loop do # Scene Loop main_loop # Main Loop break if main_break? # Break If Breakloop Test end # End Scene Loop end #-------------------------------------------------------------------------- # * Main Processing : Begin Transition #-------------------------------------------------------------------------- def main_begin Graphics.freeze if @parent != nil end #-------------------------------------------------------------------------- # * Main Processing : Layering initialization #-------------------------------------------------------------------------- def main_layer @disable_dispose = true @disable_update = true @active = true @animating = true @disposed = false @break_loop = false @layers = [] @newlayers = [] end #-------------------------------------------------------------------------- # * Main Processing : Variable Initialization #-------------------------------------------------------------------------- def main_variable ; end #-------------------------------------------------------------------------- # * Main Processing : Spriteset Initialization #-------------------------------------------------------------------------- def main_spriteset ; end #-------------------------------------------------------------------------- # * Main Processing : Sprite Initialization #-------------------------------------------------------------------------- def main_sprite ; end #-------------------------------------------------------------------------- # * Main Processing : Window Initialization #-------------------------------------------------------------------------- def main_window ; end #-------------------------------------------------------------------------- # * Main Processing : Audio Initialization #-------------------------------------------------------------------------- def main_audio ; end #-------------------------------------------------------------------------- # * Main Processing : Transition #-------------------------------------------------------------------------- def main_transition Graphics.transition end #-------------------------------------------------------------------------- # * Main Processing : Loop #-------------------------------------------------------------------------- def main_loop if @parent == nil Graphics.update # Update game screen Input.update # Update input information end main_update # Update scene objects if disposing? # Animation loops main_out_animation_loop # Make the out animation return elsif animating? main_animation_loop # Make the introductory animation return end update_background # Update background processes update if !has_layers? and self.active # Update Processing end #-------------------------------------------------------------------------- # * Main Processing : Update #-------------------------------------------------------------------------- def main_update # Update each of @layers if it exists and hasn't been disposed @layers.each do |layer| layer.main_loop if layer.kind_of?(SDK::Scene_Base) && !layer.disposed? end # Passes Through All Instance Variables self.instance_variables.each do |object_name| # Evaluates Object object = eval object_name # Pass Object To Auto Update auto_update(object) unless (has_layers? or !self.active) and object.kind_of?(Window_Selectable) end end #-------------------------------------------------------------------------- # * Animation Loop #-------------------------------------------------------------------------- def main_animation_loop if main_animation_done? @animating = false end end #----------------------------------------------------------------------------- # * Animation done? #----------------------------------------------------------------------------- def main_animation_done? return true end #-------------------------------------------------------------------------- # * Out animation loop #-------------------------------------------------------------------------- def main_out_animation_loop if main_out_animation_done? dispose @newlayers.each do |layer| @parent.layers.push(layer) if layer.kind_of?(SDK::Scene_Base) end @newlayers.clear @break_loop = true end end #----------------------------------------------------------------------------- # * Animation done? #----------------------------------------------------------------------------- def main_out_animation_done? return true end #-------------------------------------------------------------------------- # * Update functions #-------------------------------------------------------------------------- def update_background ; end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update ; end #-------------------------------------------------------------------------- # * Main Processing : Break Loop Test #-------------------------------------------------------------------------- def main_break? return @break_loop end #-------------------------------------------------------------------------- # * Disposal #-------------------------------------------------------------------------- def dispose main_out_transition # Prepare for transition main_dispose # Main Dispose main_end # Main End @parent.layers.delete(self) if @parent != nil @disposed = true end #-------------------------------------------------------------------------- # * Main Processing : Transition #-------------------------------------------------------------------------- def main_out_transition Graphics.freeze end #-------------------------------------------------------------------------- # * Main Processing : Disposal #-------------------------------------------------------------------------- def main_dispose # Passes Through All Instance Variables self.instance_variables.each do |object_name| # Evaluates Object object = eval object_name # Pass Object To Auto Dispose auto_dispose(object) end # Dispose each of @layers if it exists and hasn't been disposed # This is because the layers have disabled dispose, so that this doesn't # affect the @newlayers or the @parent @layers.each do |layer| layer.dispose if layer.kind_of?(SDK::Scene_Base) && !layer.disposed? end end #-------------------------------------------------------------------------- # * Main Processing : Ending #-------------------------------------------------------------------------- def main_end Graphics.transition if @parent != nil end #-------------------------------------------------------------------------- # * Make this scene a layer #-------------------------------------------------------------------------- def make_layer return if @parent == nil # Make the Z values of all objects greater than those of the parent's parent_z_max = @parent.z_max z_difference = parent_z_max - self.z_min(parent_z_max) + 100 # Passes Through All Instance Variables self.instance_variables.each do |object_name| # Evaluates Object object = eval object_name if object.is_a?(Hash) object.each do |key, value| # Set the back opacity of all windows to 4/5 original opacity key.back_opacity *= 4.0 / 5.0 if key.kind_of?(Window) value.back_opacity *= 4.0 / 5.0 if value.kind_of?(Window) # Increase the z value of all objects beyond those of the parent key.z += z_difference if z_difference > 0 && key.respond_to?(:z=) value.z += z_difference if z_difference > 0 && value.respond_to?(:z=) end end if object.is_a?(Array) object.each do |obj| if obj.respond_to?(:z) and obj.z.kind_of?(Numeric) # Set the back opacity of all windows to 4/5 original opacity obj.back_opacity *= 4.0 / 5.0 if obj.kind_of?(Window) # Increase the z value of all objects beyond those of the parent obj.z += z_difference if z_difference > 0 && obj.respond_to?(:z=) end end end # Set the back opacity of all windows to 4/5 original opacity object.back_opacity *= 4.0 / 5.0 if object.kind_of?(Window) # Increase the z value of all objects beyond those of the parent object.z += z_difference if z_difference > 0 && object.respond_to?(:z=) end end #-------------------------------------------------------------------------- # * Maximum Z value of all instance variables #-------------------------------------------------------------------------- def z_max output = 0 # Passes Through All Instance Variables self.instance_variables.each do |object_name| # Evaluates Object object = eval object_name next if object.is_a?(Game_Mouse) if object.is_a?(Hash) object.each do |key, value| if key.respond_to?(:z) and key.z.kind_of?(Numeric) output = [output, key.z].max end if value.respond_to?(:z) and value.z.kind_of?(Numeric) output = [output, value.z].max end end end if object.is_a?(Array) object.each do |obj| if obj.respond_to?(:z) and obj.z.kind_of?(Numeric) output = [output, obj.z].max end end end if object.respond_to?(:z) and object.z.kind_of?(Numeric) output = [output, object.z].max end end return output end #-------------------------------------------------------------------------- # * Minimum Z value of all instance variables #-------------------------------------------------------------------------- def z_min(max = 9999) output = max # Passes Through All Instance Variables self.instance_variables.each do |object_name| # Evaluates Object object = eval object_name next if object.is_a?(Game_Mouse) if object.is_a?(Hash) object.each do |key, value| if key.respond_to?(:z) and key.z.kind_of?(Numeric) output = [output, key.z].min end if value.respond_to?(:z) and value.z.kind_of?(Numeric) output = [output, value.z].min end end end if object.is_a?(Array) object.each do |obj| if obj.respond_to?(:z) and obj.z.kind_of?(Numeric) output = [output, obj.z].min end end end if object.respond_to?(:z) and object.z.kind_of?(Numeric) output = [output, object.z].min end end return output end #-------------------------------------------------------------------------- # * Main Processing : Auto Update #-------------------------------------------------------------------------- def auto_update(object) # Return If Object isn't a Hash, Array or Respond to Update return unless object.is_a?(Hash) || object.is_a?(Array) || object.respond_to?(:update) # If Hash Object if object.is_a?(Hash) object.each do |key, value| # Pass Key & Value to Auto Update auto_update(key) ; auto_update(value) end return end # If Array Object if object.is_a?(Array) # Pass All Object to Auto Update object.each {|obj| auto_update(obj)} return end # If Responds to Dispose if object.respond_to?(:dispose) # If Responds to Disposed? && is Disposed or Responds to Disable # Dispose and dispose is disabled if (object.respond_to?(:disposed?) && object.disposed?) || (object.respond_to?(:disable_dispose?) && object.disable_dispose?) # Return return end end # If Responds to Update if object.respond_to?(:update) # If Responds to Disable Update & Update Disabled if object.respond_to?(:disable_update?) && object.disable_update? # Return return end # Update Object object.update end end #-------------------------------------------------------------------------- # * Main Processing : Auto Dispose #-------------------------------------------------------------------------- def auto_dispose(object) # Return If Object isn't a Hash, Array or Respond to Dispose return unless object.is_a?(Hash) || object.is_a?(Array) || object.respond_to?(:dispose) # If Hash Object if object.is_a?(Hash) object.each do |key, value| # Pass Key & Value to Auto Dispose auto_dispose(key) ; auto_dispose(value) end return end # If Array Object if object.is_a?(Array) # Pass All Object to Auto Dispose object.each {|obj| auto_dispose(obj)} return end # If Responds to Dispose if object.respond_to?(:dispose) # If Responds to Disposed? && is Disposed or Responds to Disable # Dispose and dispose is disabled if (object.respond_to?(:disposed?) && object.disposed?) || (object.respond_to?(:disable_dispose?) && object.disable_dispose?) # Return return end # Dispose Object object.dispose end end #-------------------------------------------------------------------------- # * Replace the current class; different if a layer or not #-------------------------------------------------------------------------- def new_scene(object, *args) object = eval(object) if object.is_a?(String) # If this is the top layer if @parent == nil args.insert(0, nil) # Make the new scene as the described class $scene = object == nil ? nil : object.new(*args) else # If we're trying to dispose of this class if object == nil || object == @parent.class @newlayers.push(nil) else # Insert the parent into the array of arguments args.insert(0, @parent) # Replace this layer with the described class @newlayers.push(object.new(*args)) end end end #-------------------------------------------------------------------------- # * Create a new layer on top of this class #-------------------------------------------------------------------------- def new_layer(object, *args) return if object == nil object = eval(object) if object.is_a?(String) # Insert self as the parent into the array of arguments args.insert(0, self) # Add the described class as a layer @layers.push(object.new(*args)) end #-------------------------------------------------------------------------- # * Delete a specific layer #-------------------------------------------------------------------------- def delete_layer(layer_name) @layers.each do |layer| layer.new_scene(nil) if layer.class == layer_name end end #-------------------------------------------------------------------------- # * Clear all of this scene's layers #-------------------------------------------------------------------------- def clear_layers @layers.each {|layer| layer.new_scene(nil)} end #-------------------------------------------------------------------------- # * Find and return the root parent #-------------------------------------------------------------------------- def root # If this is the top layer if @parent == nil return self else return @parent.root end end #-------------------------------------------------------------------------- # * Has layers? (that prevent updating) #-------------------------------------------------------------------------- def has_layers? for layer in @layers return true if layer.kind_of?(SDK::Scene_Base) && layer.active end return false end #-------------------------------------------------------------------------- # * Animating? #-------------------------------------------------------------------------- def animating? @animating end #-------------------------------------------------------------------------- # * Disposing? (aka, out animating) #-------------------------------------------------------------------------- def disposing? # When not a layer, if scene changes; when a layer, if there's a new layer # or if the parent is disposing return @parent == nil ? $scene != self : (!(@newlayers.empty?) or @parent.disposing?) end #-------------------------------------------------------------------------- # * Disposed? #-------------------------------------------------------------------------- def disposed? @disposed end end