Advertisement
AngryPacman

PAC Save Scene

Jul 29th, 2011
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 24.20 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Pacman Advanced Creative (PAC) Engine - Save Scene
  4. # Date 23/7/2011
  5. # Type: Menu
  6. # Installation: Simple configuration.
  7. # Level: Average, Difficult
  8. # With: Dargor (TDS), Yeyinde.
  9. #
  10. #===============================================================================
  11. #
  12. # Description:
  13. # This is the comprehensive save scene of the PAC, displaying gold, party
  14. # members, an option to overwrite or load, a screenshot of the saved map, time,
  15. # and filename. There is pretty much unlimited files as well.
  16. #
  17. #===============================================================================
  18. #
  19. # Instructions
  20. # INSTALLATION
  21. # Paste above main, below materials. Remember to save.
  22. # CONFIGURATION
  23. # Follow the instructions set at each line in the PAC SAVE module.
  24. #
  25. #===============================================================================
  26. #
  27. # EDITING BEGINS AT LINE 33. DO NOT TOUCH LINE 31.
  28. #
  29. #===============================================================================
  30.  
  31. module Vocab  # AAAAGH!
  32.  
  33.   SaveMessage = "Save to which file?" # Query during save option.
  34.   LoadMessage = "Load which file?"  # Query during load option.
  35.   File =        'File'  # Name of savefiles, i.e. File 1, File 2 if File.
  36.   NoFile =      'Empty' # Name displayed if slot is empty.
  37.   FileConfirm = 'Are you sure you want to %s this file?'  # Overwrite prompt.
  38.  
  39. end # Do not touch this line.
  40.  
  41. module PAC  # Or this line.
  42.   module SAVE # Not even this one.
  43.    
  44.     Max_Files = 80  # Maximum number of files.
  45.     Name = 'Save' # Name of files in the Save directory.
  46.     Extension = 'rvdata'  # File extension.
  47.     Directory = 'Save'  # File directory (creates if inexistant).
  48.     Confirmation = true # Use file confirmation?
  49.     Smooth_Scroll = true  # Use sexy Smooth Scroll?
  50.     Scroll_Speed = 30 # Speed of Smooth Scroll.
  51.     # Use a picture for location name instead of text? The picture must be named
  52.     # the same as the map and in the pictures folder.
  53.     Location_Name_Picture = false
  54.  
  55. #===============================================================================
  56. #
  57. # DO NOT EDIT THIS UNLESS YOU HAVE ANY IDEA WHAT'S GOING ON.
  58. #
  59. #===============================================================================
  60.  
  61.   end
  62. end
  63.  
  64. #==============================================================================
  65. # ** Font
  66. #------------------------------------------------------------------------------
  67. # The font class. Font is a property of the Bitmap class.
  68. #==============================================================================
  69.  
  70. class Font
  71.   #--------------------------------------------------------------------------
  72.   # * Marshal Dump
  73.   #--------------------------------------------------------------------------
  74.   def marshal_dump;end
  75.   #--------------------------------------------------------------------------
  76.   # * Marshal Load
  77.   #--------------------------------------------------------------------------
  78.   def marshal_load(obj);end
  79. end
  80.  
  81. #==============================================================================
  82. # ** Bitmap
  83. #------------------------------------------------------------------------------
  84. # The bitmap class. Bitmaps are expressions of so-called graphics.
  85. # Sprites (Sprite) and other objects must be used to display bitmaps on the
  86. # screen.
  87. #==============================================================================
  88.  
  89. class Bitmap
  90.   #--------------------------------------------------------------------------
  91.   # Win32API
  92.   #--------------------------------------------------------------------------
  93.   RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
  94.   RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')
  95.   #--------------------------------------------------------------------------
  96.   # * Dump
  97.   #--------------------------------------------------------------------------
  98.   def _dump(limit)
  99.     data = "rgba" * width * height
  100.     RtlMoveMemory_pi.call(data, address, data.length)
  101.     [width, height, Zlib::Deflate.deflate(data)].pack("LLa*")
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # * Loas
  105.   #--------------------------------------------------------------------------
  106.   def self._load(str)
  107.     w, h, zdata = str.unpack("LLa*"); b = new(w, h)
  108.     RtlMoveMemory_ip.call(b.address, Zlib::Inflate.inflate(zdata), w * h * 4); b
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # * Address
  112.   #--------------------------------------------------------------------------
  113.   def address
  114.     buffer, ad = "xxxx", object_id * 2 + 16
  115.     RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 8
  116.     RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 16
  117.     RtlMoveMemory_pi.call(buffer, ad, 4); return buffer.unpack("L")[0]
  118.   end
  119. end
  120.  
  121. #==============================================================================
  122. # ** Game_System
  123. #------------------------------------------------------------------------------
  124. #  This class handles system-related data. Also manages vehicles and BGM, etc.
  125. # The instance of this class is referenced by $game_system.
  126. #==============================================================================
  127.  
  128. class Game_System
  129.   #--------------------------------------------------------------------------
  130.   # * Public Instance Variables
  131.   #--------------------------------------------------------------------------
  132.   attr_accessor :background_bitmap
  133.   attr_accessor :map_name
  134.   #--------------------------------------------------------------------------
  135.   # alias Listing
  136.   #--------------------------------------------------------------------------
  137.   alias pac_save_gsys_ini initialize
  138.   #--------------------------------------------------------------------------
  139.   # * Object Initialization
  140.   #--------------------------------------------------------------------------
  141.   def initialize
  142.     pac_save_gsys_ini
  143.     @background_bitmap = nil
  144.     @map_name = ''
  145.   end
  146. end
  147.  
  148. #==============================================================================
  149. # ** Game_Map
  150. #------------------------------------------------------------------------------
  151. #  This class handles maps. It includes scrolling and passage determination
  152. # functions. The instance of this class is referenced by $game_map.
  153. #==============================================================================
  154.  
  155. class Game_Map
  156.   #--------------------------------------------------------------------------
  157.   # * Get Map ID
  158.   #--------------------------------------------------------------------------
  159.   def name
  160.     map_infos = load_data("Data/MapInfos.rvdata")
  161.     name = map_infos[@map_id].name
  162.     return name
  163.   end
  164. end
  165.  
  166. #==============================================================================
  167. # ** Window_MapDisplay
  168. #------------------------------------------------------------------------------
  169. #  This window displays a map preview in the file screen.
  170. #==============================================================================
  171.  
  172. class Window_MapDisplay < Window_Base
  173.   #--------------------------------------------------------------------------
  174.   # * Object Initialization
  175.   #--------------------------------------------------------------------------
  176.   def initialize
  177.     super(272, 202, 272, 214)
  178.     self.visible = false
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # * Load Game Data
  182.   #--------------------------------------------------------------------------
  183.   def load_gamedata(filename)
  184.     @filename = filename
  185.     @time_stamp = Time.at(0)
  186.     @file_exist = FileTest.exist?(@filename)
  187.     if @file_exist
  188.       file = File.open(@filename, "r")
  189.       @time_stamp = file.mtime
  190.       begin
  191.         @characters     = Marshal.load(file)
  192.         @frame_count    = Marshal.load(file)
  193.         @last_bgm       = Marshal.load(file)
  194.         @last_bgs       = Marshal.load(file)
  195.         @game_system    = Marshal.load(file)
  196.         @game_message   = Marshal.load(file)
  197.         @game_switches  = Marshal.load(file)
  198.         @game_variables = Marshal.load(file)
  199.         @game_self_switches  = Marshal.load(file)
  200.         @game_actors         = Marshal.load(file)
  201.         @game_party          = Marshal.load(file)
  202.         @game_troop          = Marshal.load(file)
  203.         @game_map            = Marshal.load(file)
  204.         @game_player         = Marshal.load(file)
  205.         @total_sec = @frame_count / Graphics.frame_rate
  206.       rescue
  207.         @file_exist = false
  208.       ensure
  209.         file.close
  210.       end
  211.     end
  212.     refresh
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # * Refresh
  216.   #--------------------------------------------------------------------------
  217.   def refresh
  218.     self.contents.clear
  219.     return unless @file_exist
  220.     name = @game_system.map_name
  221.     if PAC::SAVE::Location_Name_Picture
  222.       bitmap = Cache.picture(name)
  223.       self.contents.blt(4,4,bitmap,bitmap.rect)
  224.     else
  225.       self.contents.draw_text(4,4,272,WLH,name)
  226.     end
  227.     self.contents.blt(4, 32, @game_system.background_bitmap,
  228.       Rect.new(160, 128, 224, 128))
  229.   end
  230. end
  231.  
  232. #==============================================================================
  233. # ** Window_FileDetail
  234. #------------------------------------------------------------------------------
  235. #  This window displays file details in the File screen.
  236. #==============================================================================
  237.  
  238. class Window_FileDetail < Window_Base
  239.   #--------------------------------------------------------------------------
  240.   # * Object Initialization
  241.   #--------------------------------------------------------------------------
  242.   def initialize
  243.     super(0,202,272,214)
  244.     self.visible = false
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # * Load Game Data
  248.   #--------------------------------------------------------------------------
  249.   def load_gamedata(filename)
  250.     @filename = filename
  251.     @time_stamp = Time.at(0)
  252.     @file_exist = FileTest.exist?(@filename)
  253.     if @file_exist
  254.       file = File.open(@filename, "r")
  255.       @time_stamp = file.mtime
  256.       begin
  257.         @characters     = Marshal.load(file)
  258.         @frame_count    = Marshal.load(file)
  259.         @last_bgm       = Marshal.load(file)
  260.         @last_bgs       = Marshal.load(file)
  261.         @game_system    = Marshal.load(file)
  262.         @game_message   = Marshal.load(file)
  263.         @game_switches  = Marshal.load(file)
  264.         @game_variables = Marshal.load(file)
  265.         @game_self_switches  = Marshal.load(file)
  266.         @game_actors         = Marshal.load(file)
  267.         @game_party          = Marshal.load(file)
  268.         @game_troop          = Marshal.load(file)
  269.         @game_map            = Marshal.load(file)
  270.         @game_player         = Marshal.load(file)
  271.         @total_sec = @frame_count / Graphics.frame_rate
  272.       rescue
  273.         @file_exist = false
  274.       ensure
  275.         file.close
  276.       end
  277.     end
  278.     refresh
  279.   end
  280.   #--------------------------------------------------------------------------
  281.   # * Refresh
  282.   #--------------------------------------------------------------------------
  283.   def refresh
  284.     self.contents.clear
  285.     return unless @file_exist
  286.     for i in 0...@game_party.members.size
  287.       member = @game_party.members[i]
  288.       draw_actor_name(member,4,i * WLH)
  289.       draw_actor_hp(member,96,i * WLH)
  290.       draw_currency_value(@game_party.gold, 96, 150, 120)
  291.     end
  292.   end
  293. end
  294.  
  295. #==============================================================================
  296. # ** Window_SaveFile
  297. #------------------------------------------------------------------------------
  298. #  This window displays save files on the save and load screens.
  299. #==============================================================================
  300.  
  301. class Window_SaveFile < Window_Base
  302.   #--------------------------------------------------------------------------
  303.   # Max File setting
  304.   #--------------------------------------------------------------------------
  305.   MAX_FILES = PAC::SAVE::Max_Files
  306.   #--------------------------------------------------------------------------
  307.   # * Public Instance Variables
  308.   #--------------------------------------------------------------------------
  309.   attr_reader :file_index
  310.   #--------------------------------------------------------------------------
  311.   # alias Listing
  312.   #--------------------------------------------------------------------------
  313.   alias pac_save_winfl_refresh refresh
  314.   #--------------------------------------------------------------------------
  315.   # * Object Initialization
  316.   #     file_index : save file index (0-3)
  317.   #     filename   : filename
  318.   #--------------------------------------------------------------------------
  319.   def initialize(file_index, filename)
  320.     super(0, file_index % MAX_FILES * 90, 544, 90)
  321.     @file_index = file_index
  322.     @filename = filename
  323.     load_gamedata
  324.     refresh
  325.     @selected = false
  326.   end
  327.   #--------------------------------------------------------------------------
  328.   # * Refresh
  329.   #--------------------------------------------------------------------------
  330.   def refresh
  331.     pac_save_winfl_refresh
  332.     unless @file_exist
  333.       y = (self.height / 2)-(WLH / 2)
  334.       self.contents.draw_text(0,y,508,WLH,Vocab::NoFile,2)
  335.     end
  336.   end
  337. end
  338.  
  339. #==============================================================================
  340. # ** Scene_Title
  341. #------------------------------------------------------------------------------
  342. #  This class performs the title screen processing.
  343. #==============================================================================
  344.  
  345. class Scene_Title < Scene_Base
  346.   #--------------------------------------------------------------------------
  347.   # * Determine if Continue is Enabled
  348.   #--------------------------------------------------------------------------
  349.   def check_continue
  350.     name = PAC::SAVE::Name; extension = PAC::SAVE::Extension
  351.     directory = PAC::SAVE::Directory
  352.     unless FileTest.directory?(directory)
  353.       Dir.mkdir(directory)
  354.     end
  355.     @continue_enabled =(Dir.glob("#{directory}/#{name}*.#{extension}").size > 0)
  356.   end
  357. end
  358.  
  359. #==============================================================================
  360. # ** Scene_File
  361. #------------------------------------------------------------------------------
  362. #  This class performs the save and load screen processing.
  363. #==============================================================================
  364.  
  365. class Scene_File < Scene_Base
  366.   #--------------------------------------------------------------------------
  367.   # Max File setting
  368.   #--------------------------------------------------------------------------
  369.   MAX_FILES = PAC::SAVE::Max_Files
  370.   #--------------------------------------------------------------------------
  371.   # alias Listing
  372.   #--------------------------------------------------------------------------
  373.   alias pac_save_scnfl_start start
  374.   alias pac_save_scnfl_terminate terminate
  375.   alias pac_save_scnfl_update update
  376.   alias pac_save_scfl_update_savefile_window update_savefile_windows
  377.   #--------------------------------------------------------------------------
  378.   # * Create Save File Window
  379.   #--------------------------------------------------------------------------
  380.   def create_savefile_windows
  381.     @savefile_windows = []
  382.     @file_viewport = Viewport.new(0,56,544,416)
  383.     @file_viewport.z = 500
  384.     @old_top_row = 0
  385.     @speed = 0
  386.     for i in 0...MAX_FILES
  387.       @savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
  388.       @savefile_windows[i].viewport = @file_viewport
  389.     end
  390.     @item_max = MAX_FILES
  391.   end
  392.   #--------------------------------------------------------------------------
  393.   # * Start Processing
  394.   #--------------------------------------------------------------------------
  395.   def start
  396.     pac_save_scnfl_start
  397.     create_command_window
  398.     @detail_window = Window_FileDetail.new
  399.     @map_window = Window_MapDisplay.new
  400.   end
  401.   #--------------------------------------------------------------------------
  402.   # * Terminate Processing
  403.   #--------------------------------------------------------------------------
  404.   def terminate
  405.     pac_save_scnfl_terminate
  406.     @command_window.dispose
  407.     @detail_window.dispose
  408.     @map_window.dispose
  409.   end
  410.   #--------------------------------------------------------------------------
  411.   # * Create Command Window
  412.   #--------------------------------------------------------------------------
  413.   def create_command_window
  414.     @command_window = Window_Command.new(544,['Yes','No'],2)
  415.     @command_window.active = false
  416.     @command_window.visible = false
  417.     @command_window.y = 56
  418.     @command_window.z = 501
  419.   end
  420.   #--------------------------------------------------------------------------
  421.   # * Frame Update
  422.   #--------------------------------------------------------------------------
  423.   def update
  424.     @command_window.update
  425.     @detail_window.update
  426.     @map_window.update
  427.     @detail_window.visible = @command_window.visible
  428.     @map_window.visible = @command_window.visible
  429.     if @command_window.active
  430.       update_command_window
  431.       return
  432.     end
  433.     pac_save_scnfl_update
  434.   end
  435.   #--------------------------------------------------------------------------
  436.   # * Frame Update (Command Window)
  437.   #--------------------------------------------------------------------------
  438.   def update_command_window
  439.     unless $game_map.nil?
  440.       @spriteset.update unless @spriteset.nil?
  441.     end
  442.     if Input.trigger?(Input::C)
  443.       case @command_window.index
  444.       when 0
  445.         if @saving
  446.           Sound.play_save
  447.           do_save
  448.         else
  449.           Sound.play_load
  450.           do_load
  451.         end
  452.       when 1
  453.         Sound.play_cancel
  454.         close_confirmation_window
  455.       end
  456.     elsif Input.trigger?(Input::B)
  457.       Sound.play_cancel
  458.       close_confirmation_window
  459.     end
  460.   end
  461.   #--------------------------------------------------------------------------
  462.   # * Open Confirmation Window
  463.   #--------------------------------------------------------------------------
  464.   def open_confirmation_window
  465.     window_to_top
  466.     for window in @savefile_windows
  467.       window.visible = false unless window.file_index == @index
  468.     end
  469.     mode = @saving ? 'overwrite' : 'load'
  470.     text = sprintf(Vocab::FileConfirm, mode)
  471.     @help_window.set_text(text)
  472.     @detail_window.load_gamedata(@savefile_windows[@index].filename)
  473.     @map_window.load_gamedata(@savefile_windows[@index].filename)
  474.     @command_window.visible = true
  475.     @command_window.active = true
  476.   end
  477.   #--------------------------------------------------------------------------
  478.   # * Close Confirmation Window
  479.   #--------------------------------------------------------------------------
  480.   def close_confirmation_window
  481.     self.top_row = @old_top_row
  482.     for window in @savefile_windows
  483.       window.visible = true
  484.     end
  485.     if @saving
  486.       text = Vocab::SaveMessage
  487.     else
  488.       text = Vocab::LoadMessage
  489.     end
  490.     @help_window.set_text(text)
  491.     @command_window.visible = false
  492.     @command_window.active = false
  493.   end
  494.   #--------------------------------------------------------------------------
  495.   # * Get Top Row
  496.   #--------------------------------------------------------------------------
  497.   def top_row
  498.     return @file_viewport.oy / 90
  499.   end
  500.   #--------------------------------------------------------------------------
  501.   # * Set Top Row
  502.   #--------------------------------------------------------------------------
  503.   def top_row=(index)
  504.     @file_viewport.oy = index * 90
  505.   end
  506.   #--------------------------------------------------------------------------
  507.   # * Get Bottom Row
  508.   #--------------------------------------------------------------------------
  509.   def bottom_row
  510.     return top_row + 3
  511.   end
  512.   #--------------------------------------------------------------------------
  513.   # * Send to top
  514.   #--------------------------------------------------------------------------
  515.   def window_to_top
  516.     @file_viewport.oy = @index * 90
  517.     @file_viewport.oy -= 56
  518.   end
  519.   #--------------------------------------------------------------------------
  520.   # * Confirm Save File
  521.   #--------------------------------------------------------------------------
  522.   def determine_savefile
  523.     if @saving
  524.       if @savefile_windows[@index].file_exist
  525.         if PAC::SAVE::Confirmation
  526.           Sound.play_decision
  527.           open_confirmation_window
  528.         else
  529.           Sound.play_save
  530.           do_save
  531.         end
  532.       else
  533.         Sound.play_save
  534.         do_save
  535.       end
  536.     else
  537.       if @savefile_windows[@index].file_exist
  538.         if PAC::SAVE::Confirmation
  539.           Sound.play_decision
  540.           open_confirmation_window
  541.         else
  542.           Sound.play_load
  543.           do_load
  544.         end
  545.       else
  546.         Sound.play_buzzer
  547.         return
  548.       end
  549.     end
  550.     $game_temp.last_file_index = @index
  551.   end
  552.   #--------------------------------------------------------------------------
  553.   # * Update Save File Window
  554.   #--------------------------------------------------------------------------
  555.   def update_savefile_windows
  556.     pac_save_scfl_update_savefile_window
  557.     if @index < top_row
  558.       if PAC::SAVE::Smooth_Scroll
  559.         loop do
  560.           Graphics.update
  561.           Input.update
  562.           if Graphics.frame_count % 30 == 0
  563.             @speed = [[@speed + 1, 6].min, 0].max
  564.           end
  565.           dist = 5 * (PAC::SAVE::Scroll_Speed + @speed)
  566.           @file_viewport.oy = [[@file_viewport.oy - dist, MAX_FILES * 90].min,
  567.            @index * 90].max
  568.           break if @file_viewport.oy == @index * 90
  569.         end
  570.       else
  571.         @file_viewport.oy = @index * 90
  572.       end
  573.     elsif @index > bottom_row
  574.       if PAC::SAVE::Smooth_Scroll
  575.         loop do
  576.           Graphics.update
  577.           Input.update
  578.           if Graphics.frame_count % 30 == 0
  579.             @speed = [[@speed + 1, 6].min, 0].max
  580.           end
  581.           dist = 5 * (PAC::SAVE::Scroll_Speed + @speed)
  582.           @file_viewport.oy = [[@file_viewport.oy + dist, 0].max,
  583.            (@index - 3) * 90].min
  584.           break if @file_viewport.oy  == (@index - 3) * 90
  585.         end
  586.       else
  587.         @file_viewport.oy  = (@index - 3) * 90
  588.       end
  589.     else
  590.       @speed = [[@speed - 1, 0].max, 6].min
  591.     end
  592.   end
  593.   #--------------------------------------------------------------------------
  594.   # * Create Filename
  595.   #     file_index : save file index (0-3)
  596.   #--------------------------------------------------------------------------
  597.   def make_filename(file_index)
  598.     name = PAC::SAVE::Name
  599.     extension = PAC::SAVE::Extension
  600.     directory = PAC::SAVE::Directory
  601.     unless FileTest.directory?(directory)
  602.       Dir.mkdir(directory)
  603.     end
  604.     return "#{directory}/#{name}#{file_index + 1}.#{extension}"
  605.   end
  606. end
  607.  
  608. #==============================================================================
  609. # ** Scene_Map
  610. #------------------------------------------------------------------------------
  611. #  This class performs the map screen processing.
  612. #==============================================================================
  613.  
  614. class Scene_Map
  615.   #--------------------------------------------------------------------------
  616.   # * Alias Listing
  617.   #--------------------------------------------------------------------------
  618.   alias pac_save_scmp_call_menu call_menu
  619.   alias pac_save_scmp_call_save call_save
  620.   #--------------------------------------------------------------------------
  621.   # * Switch to Menu Screen
  622.   #--------------------------------------------------------------------------
  623.   def call_menu
  624.     $game_system.background_bitmap = Graphics.snap_to_bitmap
  625.     $game_system.map_name = $game_map.name
  626.     pac_save_scmp_call_menu
  627.   end
  628.   #--------------------------------------------------------------------------
  629.   # * Switch to Menu Screen
  630.   #--------------------------------------------------------------------------
  631.   def call_save
  632.     $game_system.background_bitmap = Graphics.snap_to_bitmap
  633.     $game_system.map_name = $game_map.name
  634.     pac_save_scmp_call_save
  635.   end
  636. end
  637.  
  638. #===============================================================================
  639. #
  640. # END OF SCRIPT
  641. #
  642. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement