Advertisement
mjshi

More Informative Saves v1.01

Dec 4th, 2015
2,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.84 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. #- More Informative Saves v1.01
  3. #-- Customizable save slots capable of holding all sorts of data
  4. #-- By mjshi
  5. #-- OK for use in all projects with credit
  6. #-------------------------------------------------------------------------------
  7. # Installation: Put above Main.
  8. # Changelog: Added support for showing equipment icons.
  9. #-------------------------------------------------------------------------------
  10. module MISav
  11.   #-----------------------------------------------------------------------------
  12.   # **CONFIGURATION**
  13.   #-----------------------------------------------------------------------------
  14.   # Save Menu Configuration
  15.   #
  16.   FileName = "File"
  17.   ShiftX = 0
  18.   ShiftY = 0
  19.   Window_Width = Graphics.width #100% width
  20.   Max_Savefiles = 12
  21.   # Number of savefiles to show at once
  22.   Number_Viewable = 4
  23.   #
  24.   # Show save/load messages? (true/false)
  25.   Show_Msg = true
  26.   MsgWindow_ShiftX = ShiftX #makes the msgwindow move with the savefiles
  27.   MsgWindow_ShiftY = ShiftY #makes the msgwindow move with the savefiles
  28.   MsgWindow_Width = Graphics.width #100% width
  29.   #
  30.   SaveMsg = "Save to which file?"
  31.   LoadMsg = "Load which file?"
  32.   #
  33.   #-----------------------------------------------------------------------------
  34.   # Should we show the player's party on the save file?
  35.   #
  36.   Show_Party = true
  37.   #
  38.   # Where should we show the party members?
  39.   PARTY_X = 152
  40.   PARTY_Y = 58
  41.   PARTY_SPACING = 12 #default is 12
  42.   #
  43.   #-----------------------------------------------------------------------------
  44.   # Should we show the player's face images on the save file?
  45.   #
  46.   Show_Faces = false
  47.   FACE_X = 0
  48.   FACE_Y = 0
  49.   FACE_SPACING = 10
  50.   #
  51.   #-----------------------------------------------------------------------------
  52.   # Should we show the party's equipped items?
  53.   #
  54.   Show_Equipment = false
  55.   # If nothing is equipped in the slot, do not show blank space for it
  56.   Equipment_Collapse = false
  57.   #
  58.   EQUIP_X = 0
  59.   EQUIP_Y = 0
  60.   # Spacing between equipment of the same character (e.g. A A A)
  61.   EQUIP_SPACING = 1
  62.   # Spacing between equipment of different characters (e.g. AAA BBB CCC)
  63.   EQUIP_SET_SPACING = 5
  64.   #
  65.   TEXT = [
  66.   #-----------------------------------------------------------------------------
  67.   # Text to show on the save/load screen.
  68.   # Format:
  69.   # ["text", x position or align, line number],
  70.   #-----------------------------------------------------------------------------
  71.   #-"text" is what you want to display
  72.   #-align can be 0 (left), 1 (center), or 2 (right). Anything larger than a 2
  73.   # will be treated as a specific x coordinate.
  74.   #-line number can range from 0 to 2, 0 is the first line, 2 is the last,
  75.   # and decimals are OK.
  76.   #-----------------------------------------------------------------------------
  77.   # Put a # in front of the ones you don't want to show
  78.   # **Don't forget the comma after each []!**
  79.  
  80.   ["Some Text Here", 300, 0.5],
  81.  
  82.   ]
  83.   THINGS = [
  84.   #-----------------------------------------------------------------------------
  85.   # Variables to show on the save/load screen.
  86.   # Format:
  87.   # ["name", "value", x position or align, line number],
  88.   #-----------------------------------------------------------------------------
  89.   #-"name" can be called whatever you want, as long as there are no spaces.
  90.   # I'd recommend naming it something useful so you know what it is, and to
  91.   # put "_s" (for save) at the end so there are no conflicts with other things.
  92.   #-"value" is any bit of game data that you want to show up on the save.
  93.   #-----------------------------------------------------------------------------
  94.   # Put a # in front of the ones you don't want to show
  95.   # **Don't forget the comma after each []!**
  96.  
  97.   ["playtime_s", "$game_system.playtime_s", 2, 0],
  98.   ["location_s", "$game_map.display_name", 2, 1],
  99.   #["gamevariable1", "$game_variables[1]", 2, 2],
  100.  
  101.   ]
  102.   #
  103.   # These are safety locks to make sure that nothing goes offscreen. Comment
  104.   # them out if you'd rather not have them.
  105.   if (Window_Width + ShiftX) > Graphics.width
  106.     Window_Width -= ShiftX
  107.   end
  108.   if (MsgWindow_Width + MsgWindow_ShiftX) > Graphics.width
  109.     MsgWindow_Width -= MsgWindow_ShiftX
  110.   end
  111.   #-----------------------------------------------------------------------------
  112.   # **END OF CONFIGURATION**
  113.   #-----------------------------------------------------------------------------
  114. end
  115.  
  116. #--------------------------------------------------------------------#
  117. # !!! Beware of crashes and errors if you edit beyond this point !!! #
  118. #--------------------------------------------------------------------#
  119.  
  120. module DataManager
  121.  
  122.   def self.make_save_header
  123.     header = {}
  124.     header[:faces] = $game_party.faces_for_savefile
  125.     header[:characters] = $game_party.characters_for_savefile
  126.     header[:equipicons] = $game_party.equippedicons_for_savefile
  127.    
  128.     MISav::THINGS.each do |item|
  129.       header[item[0].to_sym] = eval item[1]
  130.     end
  131.     header
  132.    
  133.   end
  134.  
  135.   def self.savefile_max
  136.     return MISav::Max_Savefiles
  137.   end
  138.  
  139. end
  140.  
  141. module Vocab
  142.   SaveMessage     = MISav::SaveMsg
  143.   LoadMessage     = MISav::LoadMsg
  144.   File            = MISav::FileName
  145. end
  146.  
  147. class Game_Party
  148.   def faces_for_savefile
  149.     battle_members.collect do |actor|
  150.       [actor.face_name, actor.face_index]
  151.     end
  152.   end
  153.  
  154.   def equippedicons_for_savefile
  155.     battle_members.collect do |actor|
  156.       equipped = []
  157.       actor.equips.each do |item|
  158.         if defined? item.icon_index
  159.           equipped.push(item.icon_index)
  160.         else
  161.           equipped.push(0)
  162.         end
  163.       end
  164.       equipped
  165.     end
  166.   end
  167.  
  168. end
  169.  
  170. class Window_SaveFile
  171.  
  172.   def initialize(height, index)
  173.     super(MISav::ShiftX, index * height + MISav::ShiftY, MISav::Window_Width, height)
  174.     @file_index = index
  175.     refresh
  176.     @selected = false
  177.   end
  178.  
  179.   def refresh
  180.     contents.clear
  181.     draw_party_characters(MISav::PARTY_X, MISav::PARTY_Y, MISav::PARTY_SPACING) if MISav::Show_Party
  182.     draw_face_characters(MISav::FACE_X, MISav::FACE_Y, MISav::FACE_SPACING) if MISav::Show_Faces
  183.     draw_custom_items
  184.     draw_equipped(MISav::EQUIP_X, MISav::EQUIP_Y, MISav::EQUIP_SPACING, MISav::EQUIP_SET_SPACING) if MISav::Show_Equipment
  185.     change_color(normal_color)
  186.     name = Vocab::File + " #{@file_index + 1}"
  187.     draw_text(4, 0, 200, line_height, name)
  188.     @name_width = text_size(name).width
  189.   end
  190.  
  191.   def draw_party_characters(x, y, spacing)
  192.     header = DataManager.load_header(@file_index)
  193.     return unless header
  194.     header[:characters].each_with_index do |data, i|
  195.       draw_character(data[0], data[1], x + i * (32 + spacing), y)
  196.     end
  197.   end
  198.  
  199.   def draw_face_characters(x, y, spacing)
  200.     header = DataManager.load_header(@file_index)
  201.     return unless header && header[:faces]
  202.     header[:faces].each_with_index do |data, i|
  203.       draw_face(data[0], data[1], x + i * (96 + spacing), y)
  204.     end
  205.   end
  206.  
  207.   def draw_equipped(x, y, space, set_space)
  208.   header = DataManager.load_header(@file_index)
  209.   return unless header && header[:equipicons]
  210.  
  211.   header[:equipicons].each_with_index do |equips, set|
  212.     if MISav::Equipment_Collapse
  213.       one = 0
  214.       equips.each do |icon_index|
  215.         if icon_index != 0
  216.           draw_icon(icon_index, x + (set * (24 + set_space) * 4) + (one * (24 + space)), y)
  217.           one += 1
  218.         end
  219.       end
  220.     else
  221.     equips.each_with_index do |icon_index, one|
  222.       draw_icon(icon_index, x + (set * (24 + set_space) * 4) + (one * (24 + space)), y) if icon_index != 0
  223.     end
  224.     end
  225.   end
  226.   end
  227.  
  228.   def draw_custom_items
  229.     header = DataManager.load_header(@file_index)
  230.     return unless header
  231.    
  232.     MISav::TEXT.each do |item|
  233.       if item[1] > 2
  234.         draw_text(item[1], line_height*item[2], contents.width - 4, line_height, item[0])
  235.       else
  236.         draw_text(0, line_height*item[2], contents.width - 4, line_height, item[0], item[1])
  237.       end
  238.     end
  239.    
  240.     MISav::THINGS.each do |item|
  241.       if item[2] > 2
  242.         draw_text(item[2], line_height*item[3], contents.width - 4, line_height, header[item[0].to_sym])
  243.       else
  244.         draw_text(0, line_height*item[3], contents.width - 4, line_height, header[item[0].to_sym], item[2])
  245.       end
  246.     end
  247.   end
  248. end
  249.  
  250. class Scene_File
  251.  
  252.   def start
  253.     super
  254.     create_help_window if MISav::Show_Msg
  255.     create_savefile_viewport
  256.     create_savefile_windows
  257.     init_selection
  258.   end
  259.  
  260.   def create_help_window
  261.     @help_window = Window_Help.new(1)
  262.     @help_window.set_text(help_window_text)
  263.     @help_window.x = MISav::MsgWindow_ShiftX
  264.     @help_window.y = MISav::MsgWindow_ShiftY
  265.     @help_window.width = MISav::MsgWindow_Width
  266.   end
  267.  
  268.   def visible_max
  269.     return MISav::Number_Viewable
  270.   end
  271.  
  272.   def savefile_height
  273.     @savefile_viewport.rect.height/visible_max - MISav::ShiftY/visible_max
  274.   end
  275.  
  276. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement