Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================#
- # Variable Pictures
- # Created By IceDragon
- # Date Created : 01/16/2011
- # Date Modified: 06/09/2011
- # Version : BETA-1
- #==============================================================================#
- ($imported ||= {})["IEX_VarPics-BETA"] = true
- #==============================================================================#
- module IEX
- module VariablePictures
- #==============================================================================#
- # Start Primary Customization
- #------------------------------------------------------------------------------#
- #==============================================================================#
- # Hosting Location
- # 0 - Apart of the Spriteset_Map (Recommended)
- # 1 - Solo (Directly on the Scene_Map) (Not Recommended)
- HOST_MODE = 0
- # Image handling mode
- # 0 - Self
- # 1 - Game_Picture (Only Recommended, when paired with YEM Restored Functions)
- MODE = 0
- # If using mode 1, this is used to designate what pictures
- # should be used for this script, by giving it a start position
- # Note the number of pictures used is equal to the number of variables
- # stated in the VARIABLE_PICTURES
- START_PICTURE = 21
- VARIABLE_SWITCHES = {
- # Variable_ID => Switch_ID
- 0 => nil,
- 61 => 63, # Stuff Layer
- } # Do not Remove
- VARIABLE_PICTURES = {}
- # Currently this is how it works
- # VARIABLE_PICTURES[variable_id] = {
- # variable_value => "filename"}
- #===============================================================================
- VARIABLE_PICTURES[61] = {
- 0 => "picture1",
- 1 => "picture2",
- }
- #==============================================================================
- # As you already know, from the help file.
- # 0 - Is for below character
- # 50 - Same as character
- # 100 - Above Character
- # You can use any value above or even between these
- # Note this is only effective with mode 0
- VARIABLE_PRIORITY = {
- 0 => nil,
- 61 => 0,
- } # Do not Remove
- #==============================================================================#
- # End Primary Customization
- #------------------------------------------------------------------------------#
- #==============================================================================#
- end
- end
- #==============================================================================#
- # Spriteset_VarPic
- #==============================================================================#
- class Spriteset_VarPic
- include IEX::VariablePictures
- #--------------------------------------------------------------------------#
- # * Public Instance Variables
- #--------------------------------------------------------------------------#
- attr_accessor :sprites
- #--------------------------------------------------------------------------#
- # * overwrite method :initialize
- #--------------------------------------------------------------------------#
- def initialize(viewport = nil)
- @viewport = viewport
- case MODE
- when 0
- @sprites = {} # The key is the variable ID, the value is a sprite
- @last_values = [] # The key is the variable ID, the value is the variable's value
- count = 0
- for key in VARIABLE_PICTURES.keys
- @sprites[key] = Sprite.new(@viewport)
- @sprites[key].bitmap = Bitmap.new(24, 24)
- az = 1+count; az = VARIABLE_PRIORITY[key] if VARIABLE_PRIORITY.has_key?(key)
- @sprites[key].z = az
- count += 1
- end
- when 1
- @used_pictures = {} # The key is the variable ID, the value is the Picture ID
- @last_values = {} # The key is the variable ID, the value is the variable's value
- pid = START_PICTURE
- for key in VARIABLE_PICTURES.keys
- @used_pictures[key] = pid
- pid += 1
- end
- end
- update()
- end
- #--------------------------------------------------------------------------#
- # * new method :dispose
- #--------------------------------------------------------------------------#
- def dispose()
- case MODE
- when 0
- for key in @sprites.keys
- next if @sprites[key].nil?()
- @sprites[key].dispose()
- @sprites[key] = nil
- end
- @sprites.clear
- @sprites = nil
- when 1
- for key in @used_pictures.keys
- pid = @used_pictures[key]
- $game_map.screen.pictures[pid].erase
- end
- end
- end
- #--------------------------------------------------------------------------#
- # * new method :update
- #--------------------------------------------------------------------------#
- def update()
- case MODE
- when 0 # Self Mode
- for key in @sprites.keys
- vis = true
- hask = VARIABLE_SWITCHES.has_key?(key)
- if hask
- vis = $game_switches[VARIABLE_SWITCHES[key]] if !VARIABLE_SWITCHES[key].nil?
- else
- vis = $game_switches[VARIABLE_SWITCHES[0]] if !VARIABLE_SWITCHES[0].nil?
- end
- @sprites[key].visible = vis
- next unless @sprites[key].visible
- if hask
- if @last_values[key] != $game_variables[key]
- #@sprites[key].bitmap.dispose
- nam = VARIABLE_PICTURES[key][$game_variables[key]]
- @sprites[key].bitmap = Cache.picture(nam.to_s)
- @last_values[key] = $game_variables[key]
- end
- end
- @sprites[key].update
- end
- when 1
- for key in @used_pictures.keys
- pid = @used_pictures[key]
- vis = true
- if VARIABLE_SWITCHES.has_key?(key)
- vis = $game_switches[VARIABLE_SWITCHES[key]] if !VARIABLE_SWITCHES[key].nil?
- else
- vis = $game_switches[VARIABLE_SWITCHES[0]] if !VARIABLE_SWITCHES[0].nil?
- end
- if vis
- if VARIABLE_PICTURES.has_key?(key)
- if @last_values[key] != $game_variables[key]
- $game_map.screen.pictures[pid].erase
- x = 0
- y = 0
- nam = VARIABLE_PICTURES[key][$game_variables[key]]
- $game_map.screen.pictures[pid].show(nam.to_s,
- # Origin, x, y, zoomx, zoomy, opacity, blend_type
- 0, x, y, 100, 100, 255, 0)
- @last_values[key] = $game_variables[key]
- end
- end
- else
- if $game_map.screen.pictures[pid].name != ""
- $game_map.screen.pictures[pid].erase
- @last_values[key].clear
- end
- end # End if vis
- end # End for
- end # End case
- end
- end
- #==============================================================================#
- # Spriteset_Map
- #==============================================================================#
- class Spriteset_Map
- #--------------------------------------------------------------------------#
- # * Public Instance Variables
- #--------------------------------------------------------------------------#
- attr_accessor :varpic_spriteset
- #--------------------------------------------------------------------------#
- # * alias method :initialize
- #--------------------------------------------------------------------------#
- alias iex_varpic_spmp_initialize initialize unless $@
- def initialize()
- iex_varpic_spmp_initialize()
- @varpic_spriteset = Spriteset_VarPic.new( @viewport1 )
- end
- #--------------------------------------------------------------------------#
- # * alias method :dispose
- #--------------------------------------------------------------------------#
- alias iex_varpic_spmp_dispose dispose unless $@
- def dispose()
- @varpic_spriteset.dispose unless @varpic_spriteset.nil?
- iex_varpic_spmp_dispose()
- end
- #--------------------------------------------------------------------------#
- # * alias method :update
- #--------------------------------------------------------------------------#
- alias iex_varpic_spmp_update update unless $@
- def update()
- iex_varpic_spmp_update()
- @varpic_spriteset.update unless @varpic_spriteset.nil?
- end
- end
- #==============================================================================#
- # Scene_Map
- #==============================================================================#
- class Scene_Map < Scene_Base
- #--------------------------------------------------------------------------#
- # * alias method :start
- #--------------------------------------------------------------------------#
- alias iex_varpic_scmp_start start unless $@
- def start()
- iex_varpic_scmp_start()
- if IEX::VariablePictures::HOST_MODE == 1 # // You know I should kick myself
- @varpic_spriteset = Spriteset_VarPic.new()
- end
- end
- #--------------------------------------------------------------------------#
- # * alias method :terminate
- #--------------------------------------------------------------------------#
- alias :iex_varpic_scmp_terminate :terminate unless $@
- def terminate()
- iex_varpic_scmp_terminate()
- @varpic_spriteset.dispose() unless @varpic_spriteset.nil?()
- @varpic_spriteset = nil
- end
- #--------------------------------------------------------------------------#
- # * alias method :update
- #--------------------------------------------------------------------------#
- alias :iex_varpic_scmp_update :update unless $@
- def update()
- iex_varpic_scmp_update()
- @varpic_spriteset.update unless @varpic_spriteset.nil?()
- end
- #--------------------------------------------------------------------------#
- # * new method :varpic_spriteset
- #--------------------------------------------------------------------------#
- def varpic_spriteset()
- case IEX::VariablePictures::HOST_MODE
- when 0; return @varpic_spriteset
- when 1; return @spriteset.varpic_spriteset
- else; return nil
- end
- end
- end
- #=*==========================================================================*=#
- # ** END OF FILE
- #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment