IceDragon200

IEX - VariablePictures

Aug 25th, 2011
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.17 KB | None | 0 0
  1. #==============================================================================#
  2. # Variable Pictures
  3. # Created By IceDragon
  4. # Date Created : 01/16/2011
  5. # Date Modified: 06/09/2011
  6. # Version : BETA-1
  7. #==============================================================================#
  8. ($imported ||= {})["IEX_VarPics-BETA"] = true
  9. #==============================================================================#
  10. module IEX
  11.   module VariablePictures
  12. #==============================================================================#
  13. #                           Start Primary Customization
  14. #------------------------------------------------------------------------------#
  15. #==============================================================================#
  16.     # Hosting Location
  17.     # 0 - Apart of the Spriteset_Map (Recommended)
  18.     # 1 - Solo (Directly on the Scene_Map) (Not Recommended)
  19.     HOST_MODE = 0
  20.     # Image handling mode
  21.     # 0 - Self
  22.     # 1 - Game_Picture (Only Recommended, when paired with YEM Restored Functions)
  23.     MODE = 0
  24.    
  25.     # If using mode 1, this is used to designate what pictures
  26.     # should be used for this script, by giving it a start position
  27.     # Note the number of pictures used is equal to the number of variables
  28.     # stated in the VARIABLE_PICTURES
  29.     START_PICTURE = 21
  30.    
  31.     VARIABLE_SWITCHES = {
  32.     # Variable_ID => Switch_ID
  33.       0 => nil,
  34.       61 => 63,   # Stuff Layer
  35.     } # Do not Remove
  36.    
  37.     VARIABLE_PICTURES = {}
  38.     # Currently this is how it works
  39.     # VARIABLE_PICTURES[variable_id] = {
  40.     #  variable_value => "filename"}
  41.    
  42. #===============================================================================
  43.  
  44.     VARIABLE_PICTURES[61] = {
  45.       0 => "picture1",
  46.       1 => "picture2",
  47.     }
  48.    
  49. #==============================================================================
  50.     # As you already know, from the help file.
  51.     # 0 - Is for below character
  52.     # 50 - Same as character
  53.     # 100 - Above Character
  54.     # You can use any value above or even between these
  55.     # Note this is only effective with mode 0
  56.    
  57.     VARIABLE_PRIORITY = {
  58.       0 => nil,
  59.       61 => 0,
  60.     } # Do not Remove
  61. #==============================================================================#
  62. #                           End Primary Customization
  63. #------------------------------------------------------------------------------#
  64. #==============================================================================#  
  65.   end
  66. end
  67.  
  68. #==============================================================================#
  69. # Spriteset_VarPic
  70. #==============================================================================#
  71. class Spriteset_VarPic
  72.  
  73.   include IEX::VariablePictures
  74.  
  75.   #--------------------------------------------------------------------------#
  76.   # * Public Instance Variables
  77.   #--------------------------------------------------------------------------#  
  78.   attr_accessor :sprites
  79.  
  80.   #--------------------------------------------------------------------------#
  81.   # * overwrite method :initialize
  82.   #--------------------------------------------------------------------------#  
  83.   def initialize(viewport = nil)    
  84.     @viewport = viewport
  85.     case MODE
  86.     when 0
  87.       @sprites      = {} # The key is the variable ID, the value is a sprite
  88.       @last_values  = [] # The key is the variable ID, the value is the variable's value
  89.       count = 0
  90.       for key in VARIABLE_PICTURES.keys
  91.         @sprites[key] = Sprite.new(@viewport)
  92.         @sprites[key].bitmap = Bitmap.new(24, 24)
  93.         az = 1+count; az = VARIABLE_PRIORITY[key] if VARIABLE_PRIORITY.has_key?(key)
  94.         @sprites[key].z = az
  95.         count += 1
  96.       end
  97.     when 1
  98.       @used_pictures = {} # The key is the variable ID, the value is the Picture ID
  99.       @last_values   = {} # The key is the variable ID, the value is the variable's value
  100.       pid = START_PICTURE
  101.       for key in VARIABLE_PICTURES.keys
  102.         @used_pictures[key] = pid
  103.         pid += 1
  104.       end  
  105.     end  
  106.     update()
  107.   end
  108.  
  109.   #--------------------------------------------------------------------------#
  110.   # * new method :dispose
  111.   #--------------------------------------------------------------------------#  
  112.   def dispose()
  113.     case MODE
  114.     when 0
  115.       for key in @sprites.keys
  116.         next if @sprites[key].nil?()
  117.         @sprites[key].dispose()
  118.         @sprites[key] = nil
  119.       end
  120.       @sprites.clear
  121.       @sprites = nil
  122.     when 1
  123.       for key in @used_pictures.keys
  124.         pid = @used_pictures[key]
  125.         $game_map.screen.pictures[pid].erase
  126.       end  
  127.     end  
  128.   end
  129.  
  130.   #--------------------------------------------------------------------------#
  131.   # * new method :update
  132.   #--------------------------------------------------------------------------#  
  133.   def update()
  134.     case MODE
  135.     when 0 # Self Mode
  136.       for key in @sprites.keys
  137.         vis = true
  138.         hask = VARIABLE_SWITCHES.has_key?(key)
  139.         if hask
  140.           vis = $game_switches[VARIABLE_SWITCHES[key]] if !VARIABLE_SWITCHES[key].nil?
  141.         else
  142.           vis = $game_switches[VARIABLE_SWITCHES[0]] if !VARIABLE_SWITCHES[0].nil?
  143.         end
  144.         @sprites[key].visible = vis
  145.         next unless @sprites[key].visible
  146.         if hask
  147.           if @last_values[key] != $game_variables[key]
  148.             #@sprites[key].bitmap.dispose
  149.             nam = VARIABLE_PICTURES[key][$game_variables[key]]
  150.             @sprites[key].bitmap = Cache.picture(nam.to_s)
  151.             @last_values[key] = $game_variables[key]
  152.           end
  153.         end  
  154.         @sprites[key].update
  155.       end
  156.     when 1
  157.       for key in @used_pictures.keys
  158.         pid = @used_pictures[key]
  159.         vis = true
  160.         if VARIABLE_SWITCHES.has_key?(key)
  161.           vis = $game_switches[VARIABLE_SWITCHES[key]] if !VARIABLE_SWITCHES[key].nil?
  162.         else
  163.           vis = $game_switches[VARIABLE_SWITCHES[0]] if !VARIABLE_SWITCHES[0].nil?
  164.         end
  165.         if vis
  166.           if VARIABLE_PICTURES.has_key?(key)
  167.             if @last_values[key] != $game_variables[key]
  168.               $game_map.screen.pictures[pid].erase
  169.               x = 0
  170.               y = 0
  171.               nam = VARIABLE_PICTURES[key][$game_variables[key]]
  172.               $game_map.screen.pictures[pid].show(nam.to_s,
  173.               # Origin, x, y, zoomx, zoomy, opacity, blend_type
  174.               0, x, y, 100, 100, 255, 0)
  175.               @last_values[key] = $game_variables[key]
  176.             end
  177.           end
  178.         else
  179.           if $game_map.screen.pictures[pid].name != ""
  180.             $game_map.screen.pictures[pid].erase
  181.             @last_values[key].clear
  182.           end  
  183.         end # End if vis
  184.       end # End for  
  185.     end # End case
  186.   end
  187.  
  188. end  
  189.  
  190. #==============================================================================#
  191. # Spriteset_Map
  192. #==============================================================================#
  193. class Spriteset_Map
  194.  
  195.   #--------------------------------------------------------------------------#
  196.   # * Public Instance Variables
  197.   #--------------------------------------------------------------------------#  
  198.   attr_accessor :varpic_spriteset
  199.  
  200.   #--------------------------------------------------------------------------#
  201.   # * alias method :initialize
  202.   #--------------------------------------------------------------------------#  
  203.   alias iex_varpic_spmp_initialize initialize unless $@
  204.   def initialize()
  205.     iex_varpic_spmp_initialize()
  206.     @varpic_spriteset = Spriteset_VarPic.new( @viewport1 )
  207.   end
  208.  
  209.   #--------------------------------------------------------------------------#
  210.   # * alias method :dispose
  211.   #--------------------------------------------------------------------------#  
  212.   alias iex_varpic_spmp_dispose dispose unless $@
  213.   def dispose()
  214.     @varpic_spriteset.dispose unless @varpic_spriteset.nil?
  215.     iex_varpic_spmp_dispose()
  216.   end
  217.  
  218.   #--------------------------------------------------------------------------#
  219.   # * alias method :update
  220.   #--------------------------------------------------------------------------#  
  221.   alias iex_varpic_spmp_update update unless $@
  222.   def update()
  223.     iex_varpic_spmp_update()
  224.     @varpic_spriteset.update unless @varpic_spriteset.nil?
  225.   end
  226.  
  227. end  
  228.  
  229. #==============================================================================#
  230. # Scene_Map
  231. #==============================================================================#
  232. class Scene_Map < Scene_Base
  233.  
  234.   #--------------------------------------------------------------------------#
  235.   # * alias method :start
  236.   #--------------------------------------------------------------------------#  
  237.   alias iex_varpic_scmp_start start unless $@
  238.   def start()
  239.     iex_varpic_scmp_start()
  240.     if IEX::VariablePictures::HOST_MODE == 1 # // You know I should kick myself
  241.       @varpic_spriteset = Spriteset_VarPic.new()
  242.     end  
  243.   end
  244.  
  245.   #--------------------------------------------------------------------------#
  246.   # * alias method :terminate
  247.   #--------------------------------------------------------------------------#  
  248.   alias :iex_varpic_scmp_terminate :terminate unless $@
  249.   def terminate()
  250.     iex_varpic_scmp_terminate()
  251.     @varpic_spriteset.dispose() unless @varpic_spriteset.nil?()
  252.     @varpic_spriteset = nil
  253.   end
  254.  
  255.   #--------------------------------------------------------------------------#
  256.   # * alias method :update
  257.   #--------------------------------------------------------------------------#  
  258.   alias :iex_varpic_scmp_update :update unless $@
  259.   def update()
  260.     iex_varpic_scmp_update()
  261.     @varpic_spriteset.update unless @varpic_spriteset.nil?()
  262.   end
  263.  
  264.   #--------------------------------------------------------------------------#
  265.   # * new method :varpic_spriteset
  266.   #--------------------------------------------------------------------------#  
  267.   def varpic_spriteset()
  268.     case IEX::VariablePictures::HOST_MODE
  269.     when 0; return @varpic_spriteset
  270.     when 1; return @spriteset.varpic_spriteset
  271.     else; return nil
  272.     end  
  273.   end
  274.  
  275. end
  276.  
  277. #=*==========================================================================*=#
  278. # ** END OF FILE
  279. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment