Advertisement
Archeia

Modified Picture Variables

Dec 24th, 2014
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.37 KB | None | 0 0
  1. ##----------------------------------------------------------------------------##
  2. ## Picture Variables v2.0
  3. ## Created by Neon Black at request of Celianna
  4. ##
  5. ## For both commercial and non-commercial use as long as credit is given to
  6. ## Neon Black and any additional authors.  Licensed under Creative Commons
  7. ## CC BY 3.0 - http://creativecommons.org/licenses/by/3.0/.
  8. ##----------------------------------------------------------------------------##
  9.                                                                               ##
  10. ##----------------------------------------------------------------------------##
  11. ##    Revision Info:
  12. ## v2.0 - 8.14.2013
  13. ##  Complete overhaul of how pictures are displayed
  14. ##  Numerous bugfixes
  15. ## v1.0 - 12.24.2012
  16. ##  Finished main script
  17. ##----------------------------------------------------------------------------##
  18.                                                                               ##
  19. $imported ||= {}                                                              ##
  20. $imported["CP_PIC_VARS"] = 2.0                                                ##
  21.                                                                               ##
  22. ##----------------------------------------------------------------------------##
  23. ##    Instructions:
  24. ## Place this script in the script editor below "Materials" and above "Main".
  25. ## This script allows you to set pictures from the "Graphics/Pictures" folder
  26. ## to show up when a switch is turned on and a variable is set to a certain
  27. ## value.  This pictures can appear on any of the map's viewports and at any Z
  28. ## position.  This allows the script to be useful for parallax mapping as well
  29. ## as any form of HUD.
  30. ##----------------------------------------------------------------------------##
  31.                                                                               ##
  32. module CPVPics  # Do not touch this line.                                     ##
  33.                                                                               ##
  34. ##----------------------------------------------------------------------------##
  35. ##    Config:
  36. ## The following is a hash containing the images assigned to a variable.  Each
  37. ## variable has several options that apply to all image in it as follows.
  38. ##
  39. ## :comment
  40. ##   A comment used to help identify the use of the variable.  Not read by the
  41. ##   script for anything.
  42. ## :files
  43. ##   A hash of image names for certain variable settings.  Each contains a
  44. ##   value on the left and a file name on the right.
  45. ## :z
  46. ##   The z position of the image.  Higher Z values appear above lower values.
  47. ## :sw
  48. ##   The switch that must be turned on for the picture to appear.  If the
  49. ##   switch is turned off the picture will dissappear.
  50. ## :map_mode
  51. ##   Determines how the picture will follow the map.
  52. ##   0 - The picture will snap it's top left corner to the top left position
  53. ##       of the screen and stay there.
  54. ##   1 - The picture will snap it's top left corner to the top left position
  55. ##       of the screen, but will scroll as the map scrolls.
  56. ##   2 - The picture will snap it's top left corner to the top left position
  57. ##       of the MAP and will scroll with the map.  Most useful for parallax
  58. ##       mapping.
  59. ## :viewport
  60. ##   The Spriteset_Map viewport for the picture to appear in.
  61. ##   1 - Used by all map objects/tilesets/events.  Any picture in this
  62. ##       viewport will tint with the screen.  As a general rule of thumb for
  63. ##       z values in this viewport, 0 = below events, 100 = same as events,
  64. ##       200 = over events.
  65. ##   2 - Viewport used by the default game pictures.
  66. ##   3 - Viewport used by weather.
  67. ##   Any other value assigned to this will cause the picture to not use a
  68. ##   viewport.
  69. ## :loop
  70. ##   Another feature useful for parallax mapping.  If this value is set to
  71. ##   true the picture will tile across the screen.  If it is set to false only
  72. ##   a single picture will be displayed based on the other parameters.  Set
  73. ##   this value to true when using a picture for a parallax map and having a
  74. ##   map that loops.
  75. ##----------------------------------------------------------------------------##
  76.  
  77. ##----------------------------------------------------------------------------##
  78.  
  79. Pictures ={
  80.  
  81. ##----------------------------------------------------------------------------##
  82. ## Variable 101 is (by default, change the number in the other script "Variable
  83. ## Map ID") used to instantly display the correct map overlay, so that there is
  84. ## no need to use the show image option in an event. All the player has to do,
  85. ## is walk into the map, and it should change accordingly.
  86.  
  87. ## NOTE: both variables can only work if switch 100 is turned on!
  88. ##----------------------------------------------------------------------------##
  89.  
  90. 101 =>{  ## <- This number is the variable the picture is assigned to.
  91.   :comment => "Map Overlay", ## <- just a comment, for organization
  92.   :files =>{
  93.   3 => "parallaxmap_top",
  94.   4 => "parallax_inn_top",
  95. },
  96.   :z  => 200,
  97.   :sw => 100, ## <- switch needed to turn on the images
  98.   :map_mode => 2,
  99.   :viewport => 1,
  100.   :loop => false,
  101.   },
  102.  
  103. 100 =>{
  104.   :comment => "Parallax Map",
  105.   :files =>{
  106.   3 => "parallaxmap_bottom",
  107.   2 => "hud_day_02",
  108. },
  109.   :z  => 0,
  110.   :sw => 100,
  111.   :map_mode => 2,
  112.   :viewport => 1,
  113.   :loop => false,
  114.   },
  115.  
  116. } #Pictures
  117.  
  118.  
  119. ##------------------------------------------------------------------------------
  120. ## End of configuration settings.
  121. ##------------------------------------------------------------------------------
  122.  
  123. end
  124.  
  125. module ARCHEIA_VAR
  126.   VARIABLE_BOTTOM = 100
  127.   VARIABLE_TOP = 101
  128. end # end module
  129.  
  130. ## Sets up variables for the system.  This allows them to be saved when the game
  131. ## is saved.
  132. class Game_System
  133.   attr_accessor :vpics
  134. end
  135.  
  136. ## New class that holds the variable style picture.  This stores and allows
  137. ## access to some additional information.
  138. class Game_VariablePic < Game_Picture
  139.   attr_accessor :num
  140.   attr_reader :xo
  141.   attr_reader :yo
  142.  
  143.   def initialize(num)
  144.     super(-1)  ## Changes the default blend type, sets the ID, sets the map set.
  145.     @blend_type = 0
  146.     @num = num
  147.     @xo = $game_map.display_x * 32
  148.     @yo = $game_map.display_y * 32
  149.   end
  150.  
  151.   def name
  152.     return "" unless @num
  153.     return info[:files][$game_variables[@num]] || ""
  154.   end
  155.  
  156.   def info
  157.     CPVPics::Pictures[@num]
  158.   end
  159. end
  160.  
  161.  
  162. class Game_Map  
  163.   alias nap_map_var_setup_events setup_events
  164.   def setup_events
  165.     $game_variables[ARCHEIA_VAR::VARIABLE_BOTTOM] = @map_id
  166.     $game_variables[ARCHEIA_VAR::VARIABLE_TOP] = @map_id
  167.     nap_map_var_setup_events
  168.   end
  169. end
  170.  
  171. ## New class that is used to actually display the picture.  Changes a bit
  172. ## about how pictures work.
  173. class Sprite_VariablePic < Sprite_Picture
  174.   def initialize(num, viewport, picture)
  175.     @num = num  ## Stores the picture's number.
  176.     super(viewport, picture)
  177.   end
  178.  
  179.   ## Changes how the picture is updated to allow map scrolling.
  180.   def update_position
  181.     case @picture.info[:map_mode]
  182.     when 1
  183.       self.x = -$game_map.display_x * 32 + @picture.xo
  184.       self.y = -$game_map.display_y * 32 + @picture.yo
  185.     when 2
  186.       self.x = -$game_map.display_x * 32
  187.       self.y = -$game_map.display_y * 32
  188.     else
  189.       self.x = self.y = 0
  190.     end
  191.     self.z = @picture.info[:z] ? @picture.info[:z] : 100
  192.   end
  193. end
  194.  
  195. ## Replicates the Sprite_Picture class as a plane.
  196. class Sprite_VariablePln < Plane
  197.   def initialize(num, viewport, picture)
  198.     @num = num
  199.     @picture = picture
  200.     super(viewport)
  201.     update
  202.   end
  203.  
  204.   def dispose
  205.     bitmap.dispose if bitmap
  206.     super
  207.   end
  208.  
  209.   def update
  210.     update_bitmap
  211.     update_position
  212.     update_zoom
  213.     update_other
  214.   end
  215.  
  216.   def update_bitmap
  217.     if @picture.name.empty?
  218.       self.bitmap = nil
  219.     else
  220.       self.bitmap = Cache.picture(@picture.name)
  221.     end
  222.   end
  223.  
  224.   def update_position
  225.     case @picture.info[:map_mode]
  226.     when 1
  227.       self.ox = $game_map.display_x * 32 + @picture.xo
  228.       self.oy = $game_map.display_y * 32 + @picture.yo
  229.     when 2
  230.       self.ox = $game_map.display_x * 32
  231.       self.oy = $game_map.display_y * 32
  232.     else
  233.       self.ox = self.oy = 0
  234.     end
  235.     self.z = @picture.info[:z] ? @picture.info[:z] : 100
  236.   end
  237.  
  238.   def update_zoom
  239.     self.zoom_x = @picture.zoom_x / 100.0
  240.     self.zoom_y = @picture.zoom_y / 100.0
  241.   end
  242.  
  243.   def update_other
  244.     self.opacity = @picture.opacity
  245.     self.blend_type = @picture.blend_type
  246.     self.tone.set(@picture.tone)
  247.   end
  248. end
  249.  
  250. ## Modifies some methods on the map just for funnies.
  251. class Spriteset_Map
  252.   alias :cp_vpic_create_pictures :create_pictures
  253.   def create_pictures
  254.     cp_vpic_create_pictures
  255.     create_vpics
  256.   end
  257.  
  258.   def create_vpics
  259.     $game_system.vpics = []
  260.     @var_pictures = []
  261.   end
  262.  
  263.   alias :cp_vpic_update :update
  264.   def update
  265.     cp_vpic_update
  266.     update_vpic
  267.   end
  268.  
  269.   ## This sucker hangs on to pictures.
  270.   def update_vpic
  271.     CPVPics::Pictures.each do |var, info|
  272.       if $game_switches[info[:sw]]
  273.         bitmap = info[:files][$game_variables[var]]
  274.         next unless bitmap
  275.         unless $game_system.vpics[var]
  276.           $game_system.vpics[var] = Game_VariablePic.new(var)
  277.           case info[:viewport]
  278.           when 1; vp = @viewport1
  279.           when 2; vp = @viewport2
  280.           when 3; vp = @viewport3
  281.           else; vp = nil
  282.           end
  283.           values = [var, vp, $game_system.vpics[var]]
  284.           if info[:loop]
  285.             @var_pictures[var] = Sprite_VariablePln.new(*values)
  286.           else
  287.             @var_pictures[var] = Sprite_VariablePic.new(*values)
  288.           end
  289.         end
  290.       else
  291.         if $game_system.vpics[var]
  292.           @var_pictures[var].dispose
  293.           @var_pictures.delete_at(var)
  294.           $game_system.vpics.delete_at(var)
  295.         end
  296.       end
  297.     end
  298.     @var_pictures.each do |pic|
  299.       next unless pic
  300.       pic.update
  301.     end
  302.   end
  303.  
  304.   ## Disposes the pictures.
  305.   alias :cp_vpic_dispose :dispose
  306.   def dispose
  307.     cp_vpic_dispose
  308.     dispose_vpic
  309.   end
  310.  
  311.   ## Does what I said up there.
  312.   def dispose_vpic
  313.     return unless @var_pictures
  314.     @var_pictures.each do |pic|
  315.       next if pic.nil?
  316.       pic.dispose
  317.     end
  318.   end
  319. end
  320.  
  321.  
  322. ##-----------------------------------------------------------------------------
  323. ## End of script.
  324. ##-----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement