Advertisement
roninator2

Kid Friendly Basic Quest - Save Menu

Dec 14th, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 24.68 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: KFBQ Save Menu Functions     ║  Version: 1.00     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║   FFMQ Style Save Screens           ║    09 Mar 2023     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║                                                          ║
  12. # ║  Set the Windows to look like FFMQ.                      ║
  13. # ║                                                          ║
  14. # ╚══════════════════════════════════════════════════════════╝
  15. # ╔══════════════════════════════════════════════════════════╗
  16. # ║ Terms of use:                                            ║
  17. # ║ Free for all uses in RPG Maker - Except nudity           ║
  18. # ╚══════════════════════════════════════════════════════════╝
  19.  
  20. #==============================================================================
  21. # ** DataManager
  22. #==============================================================================
  23. module DataManager
  24.   #--------------------------------------------------------------------------
  25.   # * Maximum Number of Save Files
  26.   #--------------------------------------------------------------------------
  27.   def self.savefile_max
  28.     return 3
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # * Create Save Header
  32.   #--------------------------------------------------------------------------
  33.   class << self
  34.     alias r2_make_save_header make_save_header
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # Make Save Header
  38.   #--------------------------------------------------------------------------
  39.   def self.make_save_header
  40.     header = r2_make_save_header
  41.     header[:save_data] = $game_party.data_for_savefile
  42.     header[:map] = $game_map.display_name
  43.     header[:control] = $game_system.autobattle?
  44.     header
  45.   end
  46. end
  47.  
  48. #==============================================================================
  49. # ** Game_Party
  50. #==============================================================================
  51. class Game_Party
  52.   def data_for_savefile
  53.     battle_members.collect { |actor| [actor.id, actor.level, actor.name, actor.hp, actor.equips[0].id] }
  54.   end
  55. end
  56.  
  57. #==============================================================================
  58. # ■ Window Kid Friendly Basic Quest Save Blank
  59. #==============================================================================
  60. class Window_KFBQSaveBlank < Window_Base
  61.   #--------------------------------------------------------------------------
  62.   # * Object Initialization
  63.   #--------------------------------------------------------------------------
  64.   def initialize(x, y, w, h)
  65.     hgt = line_height * h
  66.     super(x, y, w, hgt)
  67.     self.back_opacity = 0
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # * Get Line Height
  71.   #--------------------------------------------------------------------------
  72.   def line_height
  73.     return 21
  74.   end  
  75. end
  76.  
  77. #==============================================================================
  78. # ** Window_SaveFile
  79. #==============================================================================
  80. class Window_SaveFile < Window_Base
  81.   #--------------------------------------------------------------------------
  82.   # * Public Instance Variables
  83.   #--------------------------------------------------------------------------
  84.   attr_reader   :selected                 # selected
  85.   #--------------------------------------------------------------------------
  86.   # * Object Initialization
  87.   #     index : index of save files
  88.   #--------------------------------------------------------------------------
  89.   def initialize(height, index)
  90.     super(0, index * height, Graphics.width, height)
  91.     @file_index = index
  92.     @height = height
  93.     self.back_opacity = 0
  94.     refresh
  95.     @selected = false
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # * Dispose
  99.   #--------------------------------------------------------------------------
  100.   def dispose
  101.     frame_dispose
  102.     contents.dispose unless disposed?
  103.     super unless disposed?
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # * Frame Dispose
  107.   #--------------------------------------------------------------------------
  108.   def frame_dispose
  109.     if @index_window1; @index_window1.dispose unless disposed?; end
  110.     if @index_window2; @index_window2.dispose unless disposed?; end
  111.     if @map_window; @map_window.dispose unless disposed?; end
  112.     if @no_actor; @no_actor.bitmap.dispose unless disposed?; end
  113.     if @no_actor; @no_actor.dispose  unless disposed?; end
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   # * Window Frames for Screen
  117.   #--------------------------------------------------------------------------
  118.   def window_frames
  119.     frame_dispose
  120.     @index_window1 = Window_KFBQSaveBlank.new(0, @file_index * @height + 90, Graphics.width / 2, 4)
  121.     @index_window1.z = 1
  122.     @index_window2 = Window_KFBQSaveBlank.new(Graphics.width / 2, @file_index * @height + 90, Graphics.width / 2, 4)
  123.     @index_window2.z = 1
  124.     @map_window = Window_KFBQSaveBlank.new(Graphics.width / 4, @file_index * @height + 50, Graphics.width / 2, 2)
  125.     @map_window.z = 1
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # * Refresh
  129.   #--------------------------------------------------------------------------
  130.   def refresh
  131.     contents.clear
  132.     change_color(normal_color)
  133.     draw_empty_slot
  134.     draw_data
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # * Draw Party Characters
  138.   #--------------------------------------------------------------------------
  139.   def draw_empty_slot
  140.     header = DataManager.load_header(@file_index)
  141.     if header
  142.       window_frames
  143.     else
  144.       name = "Empty!"
  145.       @name_width = text_size(name).width
  146.       draw_text((Graphics.width - @name_width) / 2, 0, 200, line_height, name)
  147.     end
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # * Draw Actor Hud HP
  151.   #--------------------------------------------------------------------------
  152.   def draw_actor_hud_hp(actor, x, y, width = 130)
  153.     if $game_system.life_indicator?
  154.       draw_text(x, y + 5, contents.width/2, line_height, "LIFE", 0)
  155.       draw_text(x + 10, y + 25, 62, line_height, actor.hp, 2)
  156.       draw_text(x + 80, y + 25, 12, line_height, "/", 2)
  157.       draw_text(x + 90, y + 25, 62, line_height, actor.mhp, 2)
  158.     else
  159.       draw_gauge(actor, x, y + 10, width, hp_rate(actor), text_color(17), text_color(17))
  160.     end
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # * HP Rate
  164.   #--------------------------------------------------------------------------
  165.   def hp_rate(actor)
  166.     if actor.mhp > @barhp
  167.       a = (actor.hp / @barhp).to_i
  168.       b = a * @barhp
  169.       c = actor.hp - b
  170.       d = c == 0 ? @barhp : c
  171.       d.to_f / @barhp
  172.     else
  173.       actor.hp.to_f / actor.mhp
  174.     end
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * Draw Gauge
  178.   #--------------------------------------------------------------------------
  179.   def draw_gauge(actor, x, y, width, rate, color1, color2)
  180.     fill_w = (width * rate).to_i
  181.     gauge_y = y + line_height - 8
  182.     height = 20
  183.     height = 10 if actor.level > R2_Hud_Data::Level
  184.     contents.fill_rect(x, gauge_y, width, height, text_color(18))
  185.     contents.gradient_fill_rect(x, gauge_y, fill_w, height, color1, color2)
  186.     bitmap1 = Cache.system(R2_Hud_Data::Base_File)
  187.     bitmap2 = Cache.system(R2_Hud_Data::HP_File)
  188.     rect1 = Rect.new(0, 0, bitmap1.width, bitmap1.height)
  189.     rect2 = Rect.new(0, 0, bitmap2.width, bitmap2.height)
  190.     # find how many health bars to show
  191.     mhp_value = (actor.mhp / @barhp).to_i - 1
  192.     a = (actor.hp / @barhp).to_i
  193.     b = a * @barhp
  194.     c = actor.hp - b
  195.     d = c > 0 ? 1 : 0
  196.     hp_value = d + a - 1
  197.     # Draw Base
  198.     if (actor.level > 1) && (actor.level < (R2_Hud_Data::Level + 1))
  199.       mhp_value.times do |i|
  200.         p = i*7
  201.         contents.blt(x+p, 70, bitmap1, rect1, 255)
  202.       end
  203.     elsif actor.level > (R2_Hud_Data::Level)
  204.       row2 = mhp_value - (R2_Hud_Data::Level - 1)
  205.       row2 = (R2_Hud_Data::Level - 1) if (actor.level > (R2_Hud_Data::Level * 2 - 1))
  206.       row1 = R2_Hud_Data::Level - 1
  207.       row1.times do |i|
  208.         p = i*7
  209.         contents.blt(x+p, 60, bitmap1, rect1, 255)
  210.       end
  211.       row2.times do |i|
  212.         p = i*7
  213.         contents.blt(x+p, 70, bitmap1, rect1, 255)
  214.       end
  215.     end
  216.     # Draw Health
  217.     if (actor.level > 1) && (actor.level < (R2_Hud_Data::Level + 1))
  218.       hp_value.times do |i|
  219.         p = i*7
  220.         contents.blt(x+p, 70, bitmap2, rect2, 255)
  221.       end
  222.     elsif actor.level > (R2_Hud_Data::Level)
  223.       row4 = [0, hp_value - (R2_Hud_Data::Level - 1)].max
  224.       row4 = (R2_Hud_Data::Level - 1) if hp_value >= (R2_Hud_Data::Level * 2 - 1)
  225.       row3 = 0
  226.       row3 = [hp_value, (R2_Hud_Data::Level - 1)].min if hp_value >= 1
  227.       return if row3 == 0
  228.       row3.times do |i|
  229.         p = i*7
  230.         contents.blt(x+p, 60, bitmap2, rect2, 255)
  231.       end
  232.       row4.times do |i|
  233.         p = i*7
  234.         contents.blt(x+p, 70, bitmap2, rect2, 255)
  235.       end
  236.     end
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # * Draw Data
  240.   #--------------------------------------------------------------------------
  241.   def draw_data
  242.     header = DataManager.load_header(@file_index)
  243.     return unless header
  244.     self.contents.clear
  245.     change_color(normal_color)
  246.     width = Graphics.width / 2
  247.     actor1 = header[:save_data][0]
  248.     # id, level, name, hp, weapon
  249.     @actor1 = Game_Actor.new(actor1[0])
  250.     @actcln = @actor1.clone
  251.     @actcln.level = 1
  252.     @barhp = @actcln.mhp
  253.     @actor1.level = actor1[1]
  254.     @actor1.name = actor1[2]
  255.     @actor1.hp = actor1[3]
  256.     weapon = actor1[4]
  257.     draw_actor_name(@actor1, 10, 0)
  258.     draw_actor_hud_hp(@actor1, 0, 20, 150)
  259.     draw_actor_weapon(0, weapon)
  260.     draw_level(0, @actor1)
  261.     actor2 = nil
  262.     actor2 = header[:save_data][1] if !header[:save_data][1].nil?
  263.     if actor2
  264.       @actor2 = Game_Actor.new(actor2[0])
  265.       @actcln = @actor2.clone
  266.       @actcln.level = 1
  267.       @barhp = @actcln.mhp
  268.       @actor2.level = actor2[1]
  269.       @actor2.name = actor2[2]
  270.       @actor2.hp = actor2[3]
  271.       weapon = actor2[4]
  272.       draw_actor_name(@actor2, Graphics.width / 2 + 160, 0)
  273.       draw_actor_hud_hp(@actor2, Graphics.width / 2, 20, 150)
  274.       draw_actor_weapon(Graphics.width / 2, weapon)
  275.       draw_level(Graphics.width / 2, @actor2)
  276.       draw_control(header[:control])
  277.     else
  278.       @no_actor = Sprite.new
  279.       @no_actor.bitmap = Cache.system("Save_Actor")
  280.       @no_actor.x = Graphics.width / 2
  281.       @no_actor.y = @file_index * @height + 90
  282.       @no_actor.z = 2
  283.     end
  284.     draw_map(header[:map])
  285.     header[:characters].each_with_index do |data, i|
  286.       draw_character(data[0], data[1], 160 + i * (Graphics.width / 2), 100)
  287.     end
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # * Draw Actor Level
  291.   #--------------------------------------------------------------------------
  292.   def draw_level(x, actor)
  293.     name = "LEVEL"
  294.     draw_text(x + 5, 90, contents.width, line_height, name, 0)
  295.     draw_text(x + 90, 90, contents.width, line_height, actor.level, 0)
  296.   end
  297.   #--------------------------------------------------------------------------
  298.   # * Draw Map Name
  299.   #--------------------------------------------------------------------------
  300.   def draw_map(name)
  301.     change_color(system_color)
  302.     draw_text(0, 0, contents.width, line_height, name, 1)
  303.   end
  304.   #--------------------------------------------------------------------------
  305.   # * Draw Actor Control
  306.   #--------------------------------------------------------------------------
  307.   def draw_control(control)
  308.     name = control ? " AUTO" : " MANUAL"
  309.     contents.font.size -= 8
  310.     draw_text(Graphics.width - 110, 35, 80, line_height, name, 1)
  311.     reset_font_settings
  312.   end
  313.   #--------------------------------------------------------------------------
  314.   # * Draw Actor Weapon
  315.   #--------------------------------------------------------------------------
  316.   def draw_actor_weapon(x, id)
  317.     bitmap = Cache.system("Weapons\\Weapon" + id.to_s)
  318.     rect = Rect.new(0, 0, bitmap.width, bitmap.height)
  319.     contents.blt(x + 180, 50, bitmap, rect, 255)
  320.   end
  321.   #--------------------------------------------------------------------------
  322.   # * Set Selected
  323.   #--------------------------------------------------------------------------
  324.   def selected=(selected)
  325.     @selected = selected
  326.     update_cursor
  327.   end
  328.   #--------------------------------------------------------------------------
  329.   # * Calculate Height of Window Contents
  330.   #--------------------------------------------------------------------------
  331.   def standard_padding
  332.     return 8
  333.   end
  334.   #--------------------------------------------------------------------------
  335.   # * Update Cursor
  336.   #--------------------------------------------------------------------------
  337.   def update_cursor
  338.     if @selected
  339.       cursor_rect.set(0, 0, Graphics.width - 15, @height - 15)
  340.     else
  341.       cursor_rect.empty
  342.     end
  343.   end
  344. end
  345.  
  346. #==============================================================================
  347. # ** Window_Help
  348. #==============================================================================
  349. class Window_File_Help < Window_Base
  350.   #--------------------------------------------------------------------------
  351.   # * Object Initialization
  352.   #--------------------------------------------------------------------------
  353.   def initialize(pos, line_number)
  354.     if pos == 0
  355.       super(0, 0, Graphics.width / 2, fitting_height(line_number))
  356.     else
  357.       super(Graphics.width / 2, 0, Graphics.width / 2, fitting_height(line_number))
  358.     end
  359.   end
  360.   def dispose
  361.     contents.dispose unless disposed?
  362.     super unless disposed?
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # * Set Text
  366.   #--------------------------------------------------------------------------
  367.   def set_text(text)
  368.     if text != @text
  369.       @text = text
  370.       refresh
  371.     end
  372.   end
  373.   #--------------------------------------------------------------------------
  374.   # * Clear
  375.   #--------------------------------------------------------------------------
  376.   def clear
  377.     set_text("")
  378.   end
  379.   #--------------------------------------------------------------------------
  380.   # * Set Item
  381.   #     item : Skills and items etc.
  382.   #--------------------------------------------------------------------------
  383.   def set_item(item)
  384.     set_text(item ? item.description : "")
  385.   end
  386.   #--------------------------------------------------------------------------
  387.   # * Refresh
  388.   #--------------------------------------------------------------------------
  389.   def refresh
  390.     contents.clear
  391.     change_color(crisis_color)
  392.     draw_text(-20, 0, Graphics.width / 2, line_height, @text, 1)
  393.     change_color(normal_color)
  394.   end
  395. end
  396.  
  397. #==============================================================================
  398. # ** Window_New_Game
  399. #==============================================================================
  400. class Window_New_Game < Window_Base
  401.   attr_reader   :selected
  402.   #--------------------------------------------------------------------------
  403.   # Initialize
  404.   #--------------------------------------------------------------------------
  405.   def initialize(height, index)
  406.     super(0, 0, 160, fitting_height(1))
  407.     @file_index = 0
  408.     refresh
  409.     @selected = false
  410.   end
  411.   #--------------------------------------------------------------------------
  412.   # dispose
  413.   #--------------------------------------------------------------------------
  414.   def dispose
  415.     contents.dispose unless disposed?
  416.     super unless disposed?
  417.   end
  418.   #--------------------------------------------------------------------------
  419.   # refresh
  420.   #--------------------------------------------------------------------------
  421.   def refresh
  422.     contents.clear
  423.     change_color(normal_color)
  424.     name = "New Game"
  425.     @name_width = text_size(name).width
  426.     draw_text(4, 0, 200, line_height, name)
  427.   end
  428.   #--------------------------------------------------------------------------
  429.   # Selected Item
  430.   #--------------------------------------------------------------------------
  431.   def selected=(selected)
  432.     @selected = selected
  433.     update_cursor
  434.   end
  435.   #--------------------------------------------------------------------------
  436.   # Update Cursor
  437.   #--------------------------------------------------------------------------
  438.   def update_cursor
  439.     if @selected
  440.       cursor_rect.set(0, 0, @name_width + 8, line_height)
  441.     else
  442.       cursor_rect.empty
  443.     end
  444.   end
  445. end
  446.  
  447. #==============================================================================
  448. # ** Scene_File
  449. #==============================================================================
  450. class Scene_File < Scene_MenuBase
  451.   #--------------------------------------------------------------------------
  452.   # * Start Processing
  453.   #--------------------------------------------------------------------------
  454.   def start
  455.     super
  456.     create_help_window
  457.     create_savefile_viewport
  458.     create_savefile_windows
  459.     create_save_complete_window
  460.     create_new_game if SceneManager.scene_is?(Scene_Load)
  461.     init_selection
  462.   end
  463.   #--------------------------------------------------------------------------
  464.   # * Create Help Window
  465.   #--------------------------------------------------------------------------
  466.   def create_help_window
  467.     @help_window = Window_File_Help.new(1,1)
  468.     @help_window.set_text(help_window_text)
  469.   end
  470.   #--------------------------------------------------------------------------
  471.   # * Create Save Complete Window
  472.   #--------------------------------------------------------------------------
  473.   def create_save_complete_window
  474.     @saved_window = Window_File_Help.new(0,1)
  475.     @saved_window.set_text(save_window_text)
  476.     @saved_window.hide
  477.   end
  478.   #--------------------------------------------------------------------------
  479.   # * Get Help Window Text
  480.   #--------------------------------------------------------------------------
  481.   def help_window_text
  482.     return ""
  483.   end
  484.   #--------------------------------------------------------------------------
  485.   # * Get Save Window Text
  486.   #--------------------------------------------------------------------------
  487.   def save_window_text
  488.     return ""
  489.   end
  490.   #--------------------------------------------------------------------------
  491.   # * Create Save File Viewport
  492.   #--------------------------------------------------------------------------
  493.   def create_savefile_viewport
  494.     @savefile_viewport = Viewport.new
  495.     @savefile_viewport.rect.y = @help_window.height
  496.     @savefile_viewport.rect.height -= @help_window.height
  497.     @newfile_viewport = Viewport.new
  498.     @newfile_viewport.rect.y = 0
  499.     @newfile_viewport.rect.height = 48
  500.     @newfile_viewport.rect.x = 0
  501.   end
  502.   #--------------------------------------------------------------------------
  503.   # * Create Save File Window
  504.   #--------------------------------------------------------------------------
  505.   def create_savefile_windows
  506.     @savefile_windows = Array.new(item_max) do |i|
  507.       Window_SaveFile.new(savefile_height, i)
  508.     end
  509.     @savefile_windows.each {|window| window.viewport = @savefile_viewport }
  510.   end
  511.   #--------------------------------------------------------------------------
  512.   # * Create Save File Window
  513.   #--------------------------------------------------------------------------
  514.   def create_new_game
  515.     i = @savefile_windows.size
  516.     @savefile_windows << Window_New_Game.new(@newfile_viewport.rect.height, i)
  517.     @savefile_windows[i].viewport = @newfile_viewport
  518.   end
  519.   #--------------------------------------------------------------------------
  520.   # * Get Number of Save Files to Show on Screen
  521.   #--------------------------------------------------------------------------
  522.   def visible_max
  523.     return 3
  524.   end
  525. end
  526.  
  527. #==============================================================================
  528. # ** Scene_Save
  529. #==============================================================================
  530. class Scene_Save < Scene_File
  531.   #--------------------------------------------------------------------------
  532.   # * Get Help Window Text
  533.   #--------------------------------------------------------------------------
  534.   def help_window_text
  535.     return "Save"
  536.   end
  537.   #--------------------------------------------------------------------------
  538.   # * Get Save Window Text
  539.   #--------------------------------------------------------------------------
  540.   def save_window_text
  541.     return "Save Completed"
  542.   end
  543.   #--------------------------------------------------------------------------
  544.   # * Processing When Save Is Successful
  545.   #--------------------------------------------------------------------------
  546.   def on_save_success
  547.     Sound.play_save
  548.     @savefile_windows.each {|window| window.refresh }
  549.     @saved_window.show
  550.   end
  551.   #--------------------------------------------------------------------------
  552.   # * Move Cursor Down
  553.   #--------------------------------------------------------------------------
  554.   alias r2_cursor_down_close_window cursor_down
  555.   def cursor_down(wrap)
  556.     r2_cursor_down_close_window(wrap)
  557.     @saved_window.hide
  558.   end
  559.   #--------------------------------------------------------------------------
  560.   # * Move Cursor Up
  561.   #--------------------------------------------------------------------------
  562.   alias r2_cursor_up_close_window cursor_up
  563.   def cursor_up(wrap)
  564.     r2_cursor_up_close_window(wrap)
  565.     @saved_window.hide
  566.   end
  567. end
  568.  
  569. #==============================================================================
  570. # ** Scene_Load
  571. #==============================================================================
  572. class Scene_Load < Scene_File
  573.   #--------------------------------------------------------------------------
  574.   # * Get Help Window Text
  575.   #--------------------------------------------------------------------------
  576.   def help_window_text
  577.     return "Load"
  578.   end
  579.   #--------------------------------------------------------------------------
  580.   # * Get Save Window Text
  581.   #--------------------------------------------------------------------------
  582.   def save_window_text
  583.     return ""
  584.   end
  585.   #--------------------------------------------------------------------------
  586.   # * Confirm Save File
  587.   #--------------------------------------------------------------------------
  588.   def on_savefile_ok
  589.     super
  590.     if @index == 3
  591.       DataManager.setup_new_game
  592.       fadeout_all
  593.       $game_map.autoplay
  594.       SceneManager.goto(Scene_Map)
  595.     elsif DataManager.load_game(@index)
  596.       on_load_success
  597.     else
  598.       Sound.play_buzzer
  599.     end
  600.   end
  601.   #--------------------------------------------------------------------------
  602.   # * Move Cursor Down
  603.   #--------------------------------------------------------------------------
  604.   def cursor_down(wrap)
  605.     @index = (@index + 1) % (item_max + 1) if @index < item_max - 1 || wrap
  606.     ensure_cursor_visible
  607.   end
  608.   #--------------------------------------------------------------------------
  609.   # * Move Cursor Up
  610.   #--------------------------------------------------------------------------
  611.   def cursor_up(wrap)
  612.     @index = (@index + item_max) % (item_max + 1) if @index > 0 || wrap
  613.     ensure_cursor_visible
  614.   end
  615. end
  616.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement