LiTTleDRAgo

[RGSS] Drago - Custom Resolution

Jan 18th, 2014
732
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Drago - Custom Resolution
  3. # Version : 1.51
  4. # Contact : littledrago.blogspot.com / forum.chaos-project.com
  5. #==============================================================================
  6. ($imported ||= {})[:drg_custom_resolution] = 1.51
  7. #==============================================================================
  8. #
  9. # Introduction :
  10. #
  11. #   I created this script based on the idea I get from F0's Custom Resolution.
  12. #   There is no tilemap rewrite involved in this script.
  13. #
  14. # Issue :
  15. #  
  16. #  - Normal transition didn't work
  17. #  - Fullscreen is disabled
  18. #  - May cause glitch if using resolution lower than 640x480
  19. #  - Custom menu system will require an edit to match the new resolution
  20. #  - Anything that modify Sprite_Character & Spriteset_Map will require an edit
  21. #
  22. # Links :
  23. #
  24. #  - Fantasist's Transitions Pack
  25. #    http://forum.chaos-project.com/index.php/topic,1390.0.html
  26. #  - ForeverZer0's Add-ons
  27. #    http://forum.chaos-project.com/index.php/topic,7862.0.html
  28. #  - ThallionDarkshine's Add-ons
  29. #    http://forum.chaos-project.com/index.php/topic,12655.0.html
  30. #  - Drago Transition Pack
  31. #    http://forum.chaos-project.com/index.php/topic,13488.0.html
  32. #
  33. #  - Adjust Menu Position
  34. #    http://forum.chaos-project.com/index.php/topic,13781.0.html
  35. #
  36. #  - ThallionDarkshine's F12 Fix
  37. #    http://forum.chaos-project.com/index.php/topic,13629.0.html
  38. #  - Zeriab's F12 Pause with images
  39. #    http://forum.chaos-project.com/index.php/topic,3613.0.html
  40. #
  41. # Special Thanks :
  42. #  
  43. # - ForeverZer0 for his original Custom Resolution
  44. # - KK20 for his update in F0's Custom Resolution v0.96
  45. #
  46. #==============================================================================
  47. module LiTTleDRAgo
  48.  
  49.   SCREEN_SIZE = [1024,580]
  50.   # Define the resolution of the game screen. These values can be anything
  51.   # within reason. Centering, viewports, etc. will all be taken care of, but it
  52.   # is recommended that you use values divisible by 32 for best results.
  53.   CONTROL_SCREEN_SIZE = true
  54.   # If true, you can change the screen size with mouse
  55.  
  56. end
  57.  
  58.  
  59. core = "This script needs Drago - Core Engine ver 1.58 or above"
  60. rmxp = "This script is RGSS1 only"
  61. ($imported[:drg_core_engine] || 0) >= 1.58 || raise(core)
  62. (LiTTleDRAgo::RGSS3 or LiTTleDRAgo::RGSS2) && raise(rmxp)
  63. #==============================================================================
  64. # ** Graphics
  65. #------------------------------------------------------------------------------
  66. #  This module handles all Graphics
  67. #==============================================================================
  68.  
  69. class << Graphics
  70.   #-------------------------------------------------------------------------
  71.   # * Alias Listing
  72.   #-------------------------------------------------------------------------
  73.   alias_sec_method :zer0_graphics_transition,            :transition
  74.   alias_sec_method :drg_resolution_change_resize_screen, :resize_screen
  75.   alias_sec_method :drg_resolution_change_update,        :update
  76.   #-------------------------------------------------------------------------
  77.   # * Aliased method: resize_screen
  78.   #-------------------------------------------------------------------------
  79.   def resize_screen(width, height)
  80.     width  = (width / 32.0).ceil * 32
  81.     height = (height / 32.0).ceil * 32
  82.     drg_resolution_change_resize_screen(width, height)
  83.     refresh_scene
  84.   end
  85.   #-------------------------------------------------------------------------
  86.   # * Aliased method: transition
  87.   #-------------------------------------------------------------------------
  88.   def transition(duration = 8, *args)
  89.     if width <= 640 && height <= 480
  90.       return zer0_graphics_transition(duration, *args)
  91.     elsif duration > 0
  92.       viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  93.       sprite  = Sprite.new(viewport)
  94.       sprite.bitmap = Graphics.snap_to_bitmap
  95.       sprite2 = Sprite.new(viewport)
  96.       sprite2.z = sprite.z - 10
  97.       sprite2.blend_type = 1
  98.       zer0_graphics_transition(0)
  99.       fade = 255 / duration
  100.       if (file = args.at(0)).is_a?(String)
  101.         bitmap = Bitmap.new(file)
  102.         sprite2.bitmap = bitmap.stretch(width,height)
  103.         bitmap.dispose
  104.       end
  105.       duration.times { [sprite,sprite2].each {|s|s.opacity -= fade} && update }
  106.       [sprite.bitmap, sprite2.bitmap, sprite, sprite2, viewport].dispose
  107.     end
  108.     zer0_graphics_transition(0)
  109.   end
  110.   #-------------------------------------------------------------------------
  111.   # * Aliased method: update
  112.   #-------------------------------------------------------------------------
  113.   def update
  114.     drg_resolution_change_update
  115.     if @_width != width || @_height != height
  116.       @_width  = width
  117.       @_height = height
  118.       resize_screen(@_width, @_height)
  119.     end
  120.   end
  121.   #-------------------------------------------------------------------------
  122.   # * Overwriten method: fullscreen
  123.   #-------------------------------------------------------------------------
  124.   def fullscreen
  125.     @fullscreen = true
  126.     Graphics.fill_monitor
  127.     LiTTleDRAgo.hide_borders
  128.     control_screen_size(false)
  129.     refresh_scene
  130.   end
  131.   #-------------------------------------------------------------------------
  132.   # * Overwriten method: window
  133.   #-------------------------------------------------------------------------
  134.   def window
  135.     @fullscreen = false
  136.     LiTTleDRAgo.show_borders
  137.     control_screen_size(LiTTleDRAgo::CONTROL_SCREEN_SIZE)
  138.     Graphics.resize_screen(*LiTTleDRAgo::SCREEN_SIZE)
  139.   end
  140.   #-------------------------------------------------------------------------
  141.   # * Overwriten method: fullscreen?
  142.   #-------------------------------------------------------------------------
  143.   def fullscreen?
  144.     @fullscreen == true
  145.   end
  146.   #-------------------------------------------------------------------------
  147.   # * New method: refresh_scene
  148.   #-------------------------------------------------------------------------
  149.   def refresh_scene
  150.     if $scene.is_a?(Scene_Map)
  151.       $scene = $scene.class.new
  152.       $game_player.center($game_player.x,$game_player.y)
  153.     end
  154.   end
  155. end
  156.  
  157. Graphics.window
  158. Graphics.disable_alt_enter
  159. #==============================================================================
  160. # ** Game_Map
  161. #------------------------------------------------------------------------------
  162. #  This class handles the map. It includes scrolling and passable determining
  163. #  functions. Refer to "$game_map" for the instance of this class.
  164. #==============================================================================
  165.  
  166. class Game_Map
  167.   #-------------------------------------------------------------------------
  168.   # * Alias Listing
  169.   #-------------------------------------------------------------------------
  170.   alias_sec_method(:drg_scroll_right_adjust, :scroll_right)
  171.   alias_sec_method(:drg_scroll_down_adjust,  :scroll_down)
  172.   alias_sec_method(:drg_width_adjust,        :width)
  173.   alias_sec_method(:drg_height_adjust,       :height)
  174.   #-------------------------------------------------------------------------
  175.   # * Aliased method: width / height
  176.   #-------------------------------------------------------------------------
  177.   define_method(:width)             {  @map ? drg_width_adjust  : 0  }
  178.   define_method(:height)            {  @map ? drg_height_adjust : 0  }
  179.   #-------------------------------------------------------------------------
  180.   # * Aliased method: scroll_right
  181.   #-------------------------------------------------------------------------
  182.   def scroll_right(distance)
  183.     result = [@display_x + distance, map_edge_x].min
  184.     drg_scroll_right_adjust(distance)
  185.     @display_x = result
  186.   end
  187.   #-------------------------------------------------------------------------
  188.   # * Aliased method: scroll_down
  189.   #-------------------------------------------------------------------------
  190.   def scroll_down(distance)
  191.     result = [@display_y + distance, map_edge_y].min
  192.     drg_scroll_down_adjust(distance)
  193.     @display_y = result
  194.   end
  195.   #-------------------------------------------------------------------------
  196.   # * New method: tile_size
  197.   #-------------------------------------------------------------------------
  198.   define_method(:tile_size_x) {(Graphics.width  / 32.0).ceil}
  199.   define_method(:tile_size_y) {(Graphics.height / 32.0).ceil}
  200.   define_method(:map_edge_x) {[(width  - tile_size_x) * 128, 0].max}
  201.   define_method(:map_edge_y) {[(height - tile_size_y) * 128, 0].max}
  202. end
  203.  
  204. #==============================================================================
  205. # ** Game_Player
  206. #------------------------------------------------------------------------------
  207. #  This class handles the player. Its functions include event starting
  208. #  determinants and map scrolling. Refer to "$game_player" for the one
  209. #  instance of this class.
  210. #==============================================================================
  211. class Game_Player
  212.   #-------------------------------------------------------------------------
  213.   # * Alias Listing
  214.   #-------------------------------------------------------------------------
  215.   alias_sec_method(:drg_adjust_viewport_center, :center)
  216.   #-------------------------------------------------------------------------
  217.   # * Aliased method: center
  218.   #-------------------------------------------------------------------------
  219.   def center(x, y)
  220.     drg_adjust_viewport_center(x, y)
  221.     if $game_map.width < $game_map.tile_size_x
  222.       Game_Player.const_set(:CENTER_X, $game_map.width * 128)
  223.     else
  224.       Game_Player.const_set(:CENTER_X, (($game_map.tile_size_x*32/2)-16)*4)
  225.     end
  226.     if $game_map.height < $game_map.tile_size_y
  227.       Game_Player.const_set(:CENTER_Y, $game_map.height * 128)
  228.     else
  229.       Game_Player.const_set(:CENTER_Y, (($game_map.tile_size_y*32/2)-16)*4)
  230.     end
  231.     max_x = $game_map.map_edge_x
  232.     max_y = $game_map.map_edge_y
  233.     $game_map.display_x = [0, [(x * 32*4) - CENTER_X, max_x].min].max
  234.     $game_map.display_y = [0, [(y * 32*4) - CENTER_Y, max_y].min].max
  235.   end  
  236. end
  237.  
  238. #==============================================================================
  239. # ** Spriteset_Map
  240. #------------------------------------------------------------------------------
  241. #  This class brings together map screen sprites, tilemaps, etc.
  242. #  It's used within the Scene_Map class.
  243. #==============================================================================
  244. class Spriteset_Map
  245.   #--------------------------------------------------------------------------
  246.   # * Public Instance Variables
  247.   #--------------------------------------------------------------------------
  248.   attr_sec_reader :tilemap_ex,   'Array.new'
  249.   attr_sec_reader :layer_sprite, 'Array.new'
  250.   #--------------------------------------------------------------------------
  251.   # * Alias Listing
  252.   #--------------------------------------------------------------------------
  253.   alias_method(:initialize_tilemap_ex, :initialize)
  254.   #--------------------------------------------------------------------------
  255.   # * Object Initialization
  256.   #--------------------------------------------------------------------------
  257.   def initialize
  258.     if Graphics.width > 640 || Graphics.height > 480
  259.       @sprite_black = Sprite.new
  260.       @sprite_black.z = 0x3FFFFFFF
  261.       @sprite_black.bitmap = Graphics.snap_to_bitmap
  262.       @sprite_black.bitmap.full_fill(Color.black)
  263.     end
  264.     @tx_character_sprite = []
  265.     if $game_map.width < $game_map.tile_size_x
  266.       x = ($game_map.tile_size_x * 32 - $game_map.width * 32) / 2
  267.     else
  268.       x = 0
  269.     end
  270.     if $game_map.height < $game_map.tile_size_y
  271.       y = ($game_map.tile_size_y * 32 - $game_map.height * 32) / 2
  272.     else
  273.       y = 0
  274.     end
  275.     w = [$game_map.width  * 32, $game_map.tile_size_x * 32].min
  276.     h = [$game_map.height * 32, $game_map.tile_size_y * 32].min
  277.     @offsets = [x,y,w,h]
  278.     initialize_tilemap_ex
  279.     update_tilemap_ex(true)
  280.   end
  281.   #--------------------------------------------------------------------------
  282.   # * New method : create_tilemap
  283.   #--------------------------------------------------------------------------
  284.   def refresh_tilemap
  285.     @tilemap.priorities = $game_map.priorities
  286.     data = $game_map.data.clone
  287.     (0...data.zsize).each do |z|
  288.       (0...data.ysize).each do |y|
  289.         (0...data.xsize).each do |x|
  290.           data[x,y,z] = 0 if @tilemap.priorities[data[x,y,z]] > 0
  291.         end
  292.       end
  293.     end
  294.     @tilemap.map_data = data
  295.   end
  296.   #--------------------------------------------------------------------------
  297.   # * New method : create_data_layer
  298.   #--------------------------------------------------------------------------
  299.   def create_data_layer(data, priorities, layer = true)
  300.     content = []
  301.     (0...data.zsize).each do |z|
  302.       (0...data.ysize).each do |y|
  303.         skip = []
  304.         (0...data.xsize).each do |x|
  305.           next if skip.include?(x)
  306.           next if (_data = data[x,y,z]) < 384
  307.           next if layer && priorities[_data] == 0
  308.           next if !layer && priorities[_data] > 0
  309.           hash = {}
  310.           hash[:pos] = [[(_x = x),y,z]]
  311.           hash[:data] = [_data]
  312.           hash[:priorities] = priorities[_data]
  313.           while (_x + 1) < data.xsize &&  
  314.             (_data2 = data[_x+1,y,z]) != 0 &&
  315.             priorities[_data] == priorities[_data2]
  316.             skip.push(_x = _x + 1)
  317.             hash[:pos].push([_x,y,z])
  318.             hash[:data].push(data[_x,y,z])
  319.           end
  320.           content.push(hash)
  321.         end
  322.       end
  323.     end
  324.     content
  325.   end
  326.   #--------------------------------------------------------------------------
  327.   # * New method : refresh_tilemap_ex
  328.   #--------------------------------------------------------------------------
  329.   def refresh_tilemap_ex
  330.     tilemap_ex.dispose
  331.     tilemap_ex.clear
  332.     _ex = @offsets[2] <= 640 ? 1 : (Graphics.width / 640.0).ceil
  333.     _ey = @offsets[3] <= 480 ? 1 : (Graphics.height/ 480.0).ceil
  334.     @data_layer = create_data_layer($game_map.data, $game_map.priorities)
  335.     refresh_tilemap
  336.     refresh_layer
  337.     viewport = @viewport1,@viewport2,@viewport3
  338.     viewport.resize(*@offsets)
  339.     _ex.times do |x|
  340.       _ey.times do |y|
  341.         next if x + y == 0
  342.         ex, ey = x * 640, y * 480
  343.         viewport = Viewport.new(ex,ey,640,480)
  344.         viewport.z = @tilemap.viewport.z - 1
  345.         viewport.resize(ex + @offsets[0], ey + @offsets[1],
  346.           (Graphics.width  - ex) - (@offsets[0] * 2) + 8,
  347.           (Graphics.height - ey) - (@offsets[1] * 2) + 8)
  348.         @tilemap.viewport.children.push(viewport)
  349.         tilemap_ex[(s = tilemap_ex.size)] = @tilemap.class.new(viewport)
  350.         tilemap_ex[s].tileset = @tilemap.tileset
  351.         7.times { |i| tilemap_ex[s].autotiles[i] = @tilemap.autotiles[i] }
  352.         tilemap_ex[s].map_data = @tilemap.map_data
  353.         tilemap_ex[s].priorities = @tilemap.priorities
  354.       end
  355.     end
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # * Refresh
  359.   #--------------------------------------------------------------------------
  360.   def refresh_layer
  361.     return unless @data_layer
  362.     layer_sprite.dispose
  363.     layer_sprite.clear
  364.     @data_layer.each do |layer|
  365.       sprite = RPG::Sprite.new(@viewport1)
  366.       sprite.instance_variable_set(:@data_layer,layer)
  367.       if LiTTleDRAgo.cache.include?(layer[:data])
  368.         bitmap = LiTTleDRAgo.cache.get_cache(layer[:data])
  369.       else
  370.         bitmap = Bitmap.new(32*layer[:data].size,32)
  371.         layer[:data].each_with_index do |tile_id,index|
  372.           x = (tile_id - 384) % 8 * 32
  373.           y = (tile_id - 384) / 8 * 32
  374.           rect = Rect.new(x, y, 32, 32)
  375.           bitmap.blt(32*index, 0, @tilemap.tileset, rect)
  376.         end
  377.         LiTTleDRAgo.cache.add_cache(layer[:data],bitmap)
  378.       end
  379.       sprite.bitmap = bitmap
  380.       layer_sprite.push(sprite)
  381.     end
  382.     update_layer
  383.   end
  384.   #--------------------------------------------------------------------------
  385.   # * Frame Update
  386.   #--------------------------------------------------------------------------
  387.   define_post_alias(:update) do
  388.     if (sb = @sprite_black) && sb.not.disposed?
  389.       sb.opacity > 0 ? (sb.opacity -= 10) : sb.dispose
  390.     end
  391.     update_tilemap_ex
  392.   end    
  393.   #--------------------------------------------------------------------------
  394.   # * New method : update_tilemap_ex
  395.   #--------------------------------------------------------------------------
  396.   def update_tilemap_ex(refresh = false)
  397.     refresh_tilemap_ex if refresh
  398.     tilemap_ex.each do |ex|
  399.       ex.ox = @tilemap.ox + ex.viewport.x - @viewport1.x
  400.       ex.oy = @tilemap.oy + ex.viewport.y - @viewport1.y
  401.     end
  402.     tilemap_ex.update
  403.     update_layer
  404.   end
  405.   #--------------------------------------------------------------------------
  406.   # * Overwritten method : update_viewport_size_change
  407.   #--------------------------------------------------------------------------
  408.   def update_viewport_size_change()  end
  409.   #--------------------------------------------------------------------------
  410.   # * Overwritten method : update_layer
  411.   #--------------------------------------------------------------------------
  412.   def update_layer
  413.     layer_sprite.each do |sprite|
  414.       return refresh_layer if sprite.nil?
  415.       data_layer = sprite.instance_variable_get(:@data_layer)
  416.       sprite.x = (data_layer[:pos][0][0] * 32) - $game_map.display_x / 4
  417.       sprite.y = (data_layer[:pos][0][1] * 32) - $game_map.display_y / 4
  418.       case (z = data_layer[:priorities])
  419.       when -1
  420.         sprite.z = 0
  421.       else
  422.         sprite.z = sprite.y + 16 + 32 * (z + 1)
  423.       end
  424.     end
  425.   end
  426.   #--------------------------------------------------------------------------
  427.   # * Dispose
  428.   #--------------------------------------------------------------------------
  429.   define_post_alias(:dispose) do
  430.     tilemap_ex.dispose
  431.     layer_sprite.dispose
  432.     @sprite_black.dispose if @sprite_black && !@sprite_black.disposed?
  433.   end
  434. end
  435.  
  436.  
  437. #==============================================================================
  438. # ** Viewport
  439. #------------------------------------------------------------------------------
  440. #  
  441. #==============================================================================
  442. class Viewport
  443.   #--------------------------------------------------------------------------
  444.   # * Public Instance Variables
  445.   #--------------------------------------------------------------------------
  446.   attr_sec_reader  :children, 'Array.new'
  447.   attr_sec_accessor :offset_x, :offset_y, 0
  448.   #--------------------------------------------------------------------------
  449.   # * Alias Listing
  450.   #--------------------------------------------------------------------------
  451.   alias_sec_method(:flash_resolution,  :flash)
  452.   alias_sec_method(:set_trigger_vp_ox, :"ox=")
  453.   alias_sec_method(:set_trigger_vp_oy, :"oy=")
  454.   alias_sec_method(:tone_resolution,   :tone=)
  455.   #--------------------------------------------------------------------------
  456.   # * Frame Update, Frame Dispose
  457.   #--------------------------------------------------------------------------
  458.   define_post_alias(:update)   { children.update     }
  459.   define_post_alias(:dispose)  { children.dispose    }
  460.   define_sec_method(:parent?)  { children.not.empty? }
  461.   #-------------------------------------------------------------------------
  462.   # * New method: resize
  463.   #-------------------------------------------------------------------------
  464.   def resize(*args)
  465.     # Resize the viewport. Can call with (X, Y, WIDTH, HEIGHT) or (RECT).
  466.     if args[0].is_a?(Rect)
  467.       args[0].x += offset_x
  468.       args[0].y += offset_y
  469.       self.rect = args[0]
  470.     else
  471.       args[0] += offset_x
  472.       args[1] += offset_y
  473.       self.rect = Rect.new(*args)
  474.     end
  475.   end
  476.   #-------------------------------------------------------------------------
  477.   # * Aliased method: resize
  478.   #-------------------------------------------------------------------------
  479.   alias_method(:resize_trigger, :resize)
  480.   def resize(*args)
  481.     children.each do |child|
  482.       if args[0].is_a?(Rect)
  483.         rect = args[0]
  484.         new_args = Rect.new(rect.x,rect.y,child.rect.width,child.rect.height)
  485.       else
  486.         new_args = [args[0],args[1]]
  487.         new_args[2] = child.rect.width
  488.         new_args[3] = child.rect.height
  489.       end
  490.       child.resize_trigger(*new_args)
  491.     end
  492.     resize_trigger(*args)
  493.   end
  494.   #-------------------------------------------------------------------------
  495.   # * Aliased method: flash
  496.   #-------------------------------------------------------------------------
  497.   def flash(color, duration)
  498.     send(:flash_resolution, color, duration)
  499.   end
  500.   #-------------------------------------------------------------------------
  501.   # * Aliased method: ox=
  502.   #-------------------------------------------------------------------------
  503.   def ox=(nx)
  504.     return if self.ox == nx
  505.     ([self] + children).each {|child| child.set_trigger_vp_ox(nx)}
  506.   end
  507.   #-------------------------------------------------------------------------
  508.   # * Aliased method: oy=
  509.   #-------------------------------------------------------------------------
  510.   def oy=(ny)
  511.     return if self.oy == ny
  512.     ([self] + children).each {|child| child.set_trigger_vp_oy(ny)}
  513.   end
  514.   #-------------------------------------------------------------------------
  515.   # * Aliased method: tone=
  516.   #-------------------------------------------------------------------------
  517.   def tone=(t)
  518.     send(:tone_resolution,t)
  519.   end
  520. end
  521.  
  522. #==============================================================================
  523. # ** Plane
  524. #------------------------------------------------------------------------------
  525. #  
  526. #==============================================================================
  527. class Plane
  528.   #--------------------------------------------------------------------------
  529.   # * Public Instance Variables
  530.   #--------------------------------------------------------------------------
  531.   attr_sec_reader  :children, 'Array.new'
  532.   attr_sec_accessor :offset_x, :offset_y, 0
  533.   #--------------------------------------------------------------------------
  534.   # * Alias Listing
  535.   #--------------------------------------------------------------------------
  536.   alias_method(:resolution_initialize,     :initialize)
  537.   alias_sec_method(:zoom_x_resolution,     :'zoom_x=')
  538.   alias_sec_method(:zoom_y_resolution,     :'zoom_y=')
  539.   alias_sec_method(:ox_resolution,         :'ox=')
  540.   alias_sec_method(:oy_resolution,         :'oy=')
  541.   alias_sec_method(:bitmap_resolution,     :'bitmap=')
  542.   alias_sec_method(:setvisible_resolution, :'visible=')
  543.   alias_sec_method(:getvisible_resolution, :'visible')
  544.   alias_sec_method(:z_resolution,          :'z=')
  545.   alias_sec_method(:opacity_resolution,    :'opacity=')
  546.   alias_sec_method(:color_resolution,      :'color=')
  547.   alias_sec_method(:blend_type_resolution, :'blend_type=')
  548.   alias_sec_method(:tone_resolution,       :'tone=')
  549.   #--------------------------------------------------------------------------
  550.   # * Frame Dispose
  551.   #--------------------------------------------------------------------------
  552.   define_post_alias(:dispose)  { children.dispose }
  553.   define_sec_method(:parent?)  { children.not.empty? }
  554.   #--------------------------------------------------------------------------
  555.   # * Object Initialization
  556.   #--------------------------------------------------------------------------
  557.   def initialize(viewport=nil,parent=true)
  558.     @parent = parent
  559.     resolution_initialize(viewport)
  560.     # If the parent Plane object; but don't make more children if already have
  561.     # some. This occurs in Spriteset_Map when initializing the Panorama and Fog
  562.     if @parent && self.viewport
  563.       create_children
  564.     end
  565.   end
  566.   #-------------------------------------------------------------------------
  567.   # * Aliased method: create_children
  568.   #-------------------------------------------------------------------------
  569.   def create_children
  570.     if $scene.is_a?(Scene_Map)
  571.       gw = [Graphics.width,  $game_map.width * 32].min
  572.       gh = [Graphics.height, $game_map.height * 32].min
  573.     else
  574.       gw, gh = Graphics.width, Graphics.height
  575.     end
  576.     w = (gw - 1) / 640
  577.     h = (gh - 1) / 480
  578.     for y in 0..h
  579.       for x in 0..w
  580.         # This is the top-left default/parent Plane, so skip it
  581.         # next if x + y == 0
  582.         # Create viewport unless it already exists
  583.         width  = w > 0 && x == w ? gw - 640 : 640
  584.         height = h > 0 && y == h ? gh - 480 : 480
  585.         vp = Viewport.new(x * 640,y * 480,width,height)
  586.         vp.offset_x = x * 640
  587.         vp.offset_y = y * 480
  588.         self.viewport.children.push(vp)
  589.         # Have to do this in order to prevent overlapping with the parent
  590.         # (for Spriteset_Map viewport1 mainly)
  591.         vp.z = self.viewport.z
  592.         self.viewport.children.push(vp)
  593.         # Create the child Plane
  594.         plane = Plane.new(vp,false)
  595.         plane.offset_x = x * 640
  596.         plane.offset_y = y * 480
  597.         plane.ox = 0
  598.         plane.oy = 0
  599.         # Push to array
  600.         children.push(plane)
  601.       end
  602.     end
  603.     setvisible_resolution(false) if parent?
  604.   end
  605.   # For the remaining properties, if the parent changes, so do its children
  606.   #-------------------------------------------------------------------------
  607.   # * Aliased method: zoom_x=
  608.   #-------------------------------------------------------------------------
  609.   def zoom_x=(new_val)
  610.     ([self] + children).each {|child| child.zoom_x_resolution(new_val)}
  611.   end
  612.   #-------------------------------------------------------------------------
  613.   # * Aliased method: zoom_y=
  614.   #-------------------------------------------------------------------------
  615.   def zoom_y=(new_val)
  616.     ([self] + children).each {|child| child.zoom_y_resolution(new_val)}
  617.   end
  618.   #-------------------------------------------------------------------------
  619.   # * Aliased method: ox=
  620.   #-------------------------------------------------------------------------
  621.   def ox=(new_val)
  622.     children.each {|child| child.ox = new_val}
  623.     ox_resolution(new_val + offset_x)
  624.   end
  625.   #-------------------------------------------------------------------------
  626.   # * Aliased method: oy=
  627.   #-------------------------------------------------------------------------
  628.   def oy=(new_val)
  629.     children.each{|child| child.oy = new_val}
  630.     oy_resolution(new_val + offset_y)
  631.   end
  632.   #-------------------------------------------------------------------------
  633.   # * Aliased method: bitmap=
  634.   #-------------------------------------------------------------------------
  635.   def bitmap=(new_val)
  636.     ([self] + children).each {|child| child.bitmap_resolution(new_val)}
  637.   end
  638.   #-------------------------------------------------------------------------
  639.   # * Aliased method: visible=
  640.   #-------------------------------------------------------------------------
  641.   def visible=(new_val)
  642.     if parent?
  643.       children.send(:setvisible_resolution,new_val)
  644.       setvisible_resolution(false)
  645.     else
  646.       setvisible_resolution(new_val)
  647.     end
  648.   end
  649.   #-------------------------------------------------------------------------
  650.   # * Aliased method: visible
  651.   #-------------------------------------------------------------------------
  652.   def visible
  653.     (parent? ? children.at(0) : self).getvisible_resolution
  654.   end
  655.   #-------------------------------------------------------------------------
  656.   # * Aliased method: z=
  657.   #-------------------------------------------------------------------------
  658.   def z=(new_val)
  659.     # Because the children spawn new Viewports, they have to be lower than the
  660.     # parent's viewport to prevent drawing OVER the parent...unless the Plane's
  661.     # z-value is more than zero, in which case the children viewports NEED to be
  662.     # higher than the parent's. By doing this, we can have panoramas be below
  663.     # the tilemap and fogs be over the tilemap.
  664.     unless children.empty?
  665.       child = @children[0]
  666.       if new_val > 0 && child.viewport.z < self.viewport.z
  667.         @children.each{|child| child.viewport.z += 1}
  668.       elsif new_val <= 0 && child.viewport.z >= self.viewport.z
  669.         @children.each{|child| child.viewport.z -= 1}
  670.       end
  671.       children.each{|child| child.z_resolution(new_val)}
  672.     end
  673.     z_resolution(new_val)
  674.   end
  675.   #-------------------------------------------------------------------------
  676.   # * Aliased method: opacity=
  677.   #-------------------------------------------------------------------------
  678.   def opacity=(new_val)
  679.     ([self] + children).each {|child| child.opacity_resolution(new_val)}
  680.   end
  681.   #-------------------------------------------------------------------------
  682.   # * Aliased method: color=
  683.   #-------------------------------------------------------------------------
  684.   def color=(new_val)
  685.     (parent? ? children : self).send(:color_resolution,new_val)
  686.   end
  687.   #-------------------------------------------------------------------------
  688.   # * Aliased method: blend_type=
  689.   #-------------------------------------------------------------------------
  690.   def blend_type=(new_val)
  691.     ([self] + children).each {|child| child.blend_type_resolution(new_val)}
  692.   end
  693.   #-------------------------------------------------------------------------
  694.   # * Aliased method: tone=
  695.   #-------------------------------------------------------------------------
  696.   def tone=(new_val)
  697.     (parent? ? children : self).send(:tone_resolution,new_val)
  698.   end
  699. end
  700.  
  701.  
  702. #==============================================================================
  703. # ** RPG::Cache
  704. #==============================================================================
  705. ModCache = LiTTleDRAgo.cache
  706. class << ModCache
  707.   #--------------------------------------------------------------------------
  708.   # * New method: include?
  709.   #--------------------------------------------------------------------------
  710.   unless method_defined?(:include?)
  711.     def include?(key)
  712.       @cache[key] && !@cache[key].disposed?
  713.     end
  714.   end
  715.  
  716.   def add_cache(key,bitmap)
  717.     @cache[key].dispose if include?(key)
  718.     @cache[key] = bitmap
  719.   end
  720.  
  721.   def get_cache(key)
  722.     @cache[key] if include?(key)
  723.   end
  724. end
RAW Paste Data