Advertisement
neonblack

Picture Variables v1.0

Dec 25th, 2012
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.20 KB | None | 0 0
  1. ##------
  2. # Picture Variables v1.0
  3. # Created by Neon Black at request of Celianna
  4. # Started 12.23.2012 - Completed 12.24.2012
  5. # For non-commercial use; commercial use at request only
  6. ##------
  7. module CP
  8. module VPICS
  9.  
  10. ## Links variables to switches.  If the switch is turned off, the picture
  11. ## vanishes and will reset once turned back on.
  12. ## Uses syntax "variable ID => switch ID,".
  13. VARIABLE_SWITCHES ={
  14. 1 => 1,
  15. 2 => 1,
  16. 3 => 1,
  17. }
  18.  
  19. ## Viewport used by the pictures.  Viewport 0 will display under all map data.
  20. ## Viewport 1 is the viewport used by map data, events, characters, etc.
  21. ## Viewport 2 is used by weather and flashes and displays above the map.
  22. ## Viewport 3 is above all other viewports.  If no viewport is defined, 3 is
  23. ## used instead.  Uses syntax "variable ID => viewport ID,".
  24. PICTURE_VIEWPORT ={
  25. 1 => 1,
  26. 2 => 2,
  27. 3 => 2,
  28. }
  29.  
  30. ## Adjusts the Z position of pictures in similar viewports.  Higher numbers will
  31. ## display above lower numbers in the same viewport.  If no number is defined,
  32. ## a value of 100 is used.  Uses syntax "variable ID => Z position,".
  33. PICTURE_Z ={
  34. 1 => 1,
  35. 2 => 101,
  36. 3 => 100,
  37. }
  38.  
  39. ## Do not touch these lines.--
  40. Pictures ={} ##---------------
  41. ##----------------------------
  42.  
  43. ## The following lines link pictures to variables.  To use, first add a line
  44. ## "Pictures[ID] ={" without quotes where "ID" is the variable ID.  Afterwards
  45. ## add the names of pictures to use when the variable is set to a particular
  46. ## amount.  Uses syntax "number => 'picture name',".  Finally, enclose the
  47. ## entire structure with a right bracket symbol '}'.
  48.  
  49. Pictures[1] ={
  50. 0 => nil,
  51. 1 => "test1",
  52. 2 => "test2",
  53. }
  54.  
  55. Pictures[2] ={
  56. 0 => nil,
  57. 1 => "test1",
  58. 2 => "test2",
  59. }
  60.  
  61. Pictures[3] ={
  62. 0 => nil,
  63. 1 => "test1",
  64. 2 => "test2",
  65. }
  66.  
  67. ## This section sets whether pictures are fixed to the map or fixed to the
  68. ## screen.  A value of "true" fixes the picture to the map, while "false"
  69. ## will fix it to the screen.  Uses syntax "variable ID => true/false,".
  70. FIX_MAP ={
  71. 1 => true,
  72. 2 => false,
  73. 3 => false,
  74. }
  75.  
  76. ## Determines if the picture tints with the "Tint Screen" event command.  Note
  77. ## that pictures set to viewport 1 will ALWAYS tint to the screen no matter
  78. ## what this value is set to, and pictures in viewport 2 are affected by
  79. ## such things as weather than "Flash Screen" commands.
  80. ## Uses syntax "variable ID => true/false,".
  81. TINT_MAP ={
  82. 1 => true,
  83. 2 => false,
  84. 3 => false,
  85. }
  86.  
  87. ##------------------------------------------------------------------------------
  88. ## End of configuration settings.
  89. ##------------------------------------------------------------------------------
  90.  
  91. end
  92. end
  93.  
  94. ## Sets up variables for the system.  This allows them to be saved when the game
  95. ## is saved.
  96. class Game_System
  97.   attr_accessor :vpics
  98.   attr_accessor :gpics
  99.   attr_accessor :picvar
  100. end
  101.  
  102. ## New class that holds the variable style picture.  This stores and allows
  103. ## access to some additional information.
  104. class Game_VariablePic < Game_Picture
  105.   attr_accessor :num
  106.   attr_accessor :name
  107.   attr_reader :xo
  108.   attr_reader :yo
  109.  
  110.   def initialize(num)
  111.     super(-1)  ## Changes the default blend type, sets the ID, sets the map set.
  112.     @blend_type = 0
  113.     @num = num
  114.     @xo = $game_map.display_x * 32
  115.     @yo = $game_map.display_y * 32
  116.   end
  117. end
  118.  
  119. ## New class that is used to actually display the picture.  Changes a bit
  120. ## about how pictures work.
  121. class Sprite_VariablePic < Sprite_Picture
  122.   def initialize(num, viewport, picture)
  123.     @num = num  ## Stores the picture's number.
  124.     super(viewport, picture)
  125.   end
  126.  
  127.   ## Allows the picture to be easily changed.
  128.   def change_value(id)
  129.     return self.dispose if id.nil?
  130.     name = CP::VPICS::Pictures[@num][id]
  131.     return self.dispose if name.nil?
  132.     @picture.name = name
  133.     update
  134.   end
  135.  
  136.   ## Changes how the picture is updated to allow map scrolling.
  137.   def update_position
  138.     self.x = CP::VPICS::FIX_MAP[@num] ? -$game_map.display_x * 32 + @picture.xo : 0
  139.     self.y = CP::VPICS::FIX_MAP[@num] ? -$game_map.display_y * 32 + @picture.yo : 0
  140.     self.z = CP::VPICS::PICTURE_Z[@num] ? CP::VPICS::PICTURE_Z[@num] : 100
  141.   end
  142.  
  143.   ## Allows the screen tone to update properly.
  144.   def update_other
  145.     self.opacity = @picture.opacity
  146.     self.blend_type = @picture.blend_type
  147.     self.angle = @picture.angle
  148.     self.tone.set(CP::VPICS::TINT_MAP[@num] ? $game_map.screen.tone : Tone.new)
  149.   end
  150. end
  151.  
  152. ## Modifies some methods on the map just for funnies.
  153. class Spriteset_Map
  154.   alias cp_vpic_update update
  155.   def update
  156.     cp_vpic_update
  157.     update_vpic
  158.   end
  159.  
  160.   ## Holy sh-...  This sucker hangs on to picture and
  161.   def update_vpic
  162.     $game_system.vpics = {} if $game_system.vpics.nil?
  163.     $game_system.gpics = {} if $game_system.gpics.nil?
  164.     $game_system.picvar = {} if $game_system.picvar.nil?
  165.     CP::VPICS::Pictures.each do |id, pics|
  166.       next if id.nil?
  167.       if $game_switches[id]
  168.         next if $game_system.picvar[id] == $game_variables[id]
  169.         if $game_system.gpics[id].nil?
  170.           $game_system.gpics[id] = Game_VariablePic.new(id)
  171.         end
  172.         if $game_system.vpics[id].nil?
  173.           vp = CP::VPICS::PICTURE_VIEWPORT[id]
  174.           if vp < 1
  175.             port = nil
  176.           elsif vp == 1
  177.             port = @viewport1
  178.           elsif vp == 2
  179.             port = @viewport2
  180.           elsif vp >= 3
  181.             port = @viewport3
  182.           else
  183.             port = @viewport3
  184.           end
  185.           $game_system.vpics[id] = Sprite_VariablePic.new(id, port,
  186.                                                          $game_system.gpics[id])
  187.         end
  188.         $game_system.vpics[id].change_value($game_variables[id])
  189.       else
  190.         next unless $game_system.vpics[id]
  191.         $game_system.vpics[id].dispose
  192.         $game_system.vpics[id] = nil
  193.         $game_system.picvar[id] = nil
  194.         $game_system.gpics[id] = nil
  195.       end
  196.     end
  197.   end
  198.  
  199.   ## Disposes the pictures.
  200.   alias cp_vpic_dispose dispose
  201.   def dispose
  202.     cp_vpic_dispose
  203.     dispose_vpic
  204.   end
  205.  
  206.   ## Does what I said up there.
  207.   def dispose_vpic
  208.     return unless @vpics
  209.     @vpics.values do |array|
  210.       next if array.nil?
  211.       next if array[0].nil?
  212.       array[0].dispose
  213.     end
  214.   end
  215. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement