TheoAllen

Theo - Quick save and load

May 3rd, 2013
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.08 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Quick save and load
  3. # Version : 1.1
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_Quick] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # - 2013.05.11 - Nambahin switch id
  12. # - 2013.05.04 - Script selesai
  13. # =============================================================================
  14. =begin
  15.  
  16.   PERKENALAN :
  17.   Script ini untuk memungkinkan player untuk save game dengan cara menekan
  18.   tombol tertentu. Save file akan disimpan dalam index tertentu juga
  19.  
  20.   CARA PENGGUNAAN :
  21.   Pasang script ini diatas main namun dibawah material
  22.   edit konfigurasinya dibawah:
  23.  
  24.   TERMS OF USE :
  25.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  26.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  27.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  28.  
  29. =end
  30. # =============================================================================
  31. # KONFIGURASI :
  32. # =============================================================================
  33. module THEO
  34.   module SAVE
  35.    
  36.     SAVE_BUTTON = :F5   # Tombol untuk save game
  37.     LOAD_BUTTON = :F8   # Tombol untuk load game
  38.    
  39.     INDEX = 0 # Index untuk save game (dimulai dari 0)
  40.    
  41.     SHOW_COUNT  = 150 # Lamanya notify diliatin (default : 150)
  42.     FADEIN      = 16  # Kecepatan fadein notify (default : 16)
  43.     FADEOUT     = 16  # Kecepatan fadeout notify (default : 16)
  44.    
  45.     SAVE_NOTIFY = "Game Saved"
  46.     # Untuk text notify pas save
  47.    
  48.     LOAD_NOTIFY = "Game Loaded"
  49.     # Untuk text notify pas load
  50.    
  51.     SAVE_SWITCH_ID  = 1
  52.     LOAD_SWITCH_ID  = 1
  53.     # Untuk keperluan enable ama disable ini dengan menggunakan switch (*NEW)
  54.    
  55.   end
  56. end
  57. # =============================================================================
  58. # Batas konfigurasi. Setelah line ini ga perlu diedit
  59. # =============================================================================
  60. class Window_Notify < Window_Base
  61.  
  62.   def initialize
  63.     super(Graphics.width - window_width, 0, window_width, fitting_height(1))
  64.     self.opacity = 0
  65.     self.contents_opacity = 0
  66.     @show_count = 0
  67.     refresh
  68.   end
  69.  
  70.   def update_fadein
  71.     self.contents_opacity += THEO::SAVE::FADEIN
  72.   end
  73.  
  74.   def update_fadeout
  75.     self.contents_opacity -= THEO::SAVE::FADEOUT
  76.   end
  77.  
  78.   def refresh
  79.     contents.clear
  80.     draw_background(contents.rect)
  81.     draw_text(0,0,contents.width,contents.height,@notify,1)
  82.   end
  83.  
  84.   def show=(text)
  85.     @notify = text
  86.     open
  87.   end
  88.  
  89.   def window_width
  90.     return 240
  91.   end
  92.  
  93.   def update
  94.     super
  95.     if @show_count > 0
  96.       update_fadein
  97.       @show_count -= 1
  98.     else
  99.       update_fadeout
  100.     end
  101.   end
  102.  
  103.   def open
  104.     refresh
  105.     @show_count = THEO::SAVE::SHOW_COUNT
  106.     self.contents_opacity = 0
  107.     self
  108.   end
  109.  
  110.   def close
  111.     @show_count = 0
  112.     self
  113.   end
  114.  
  115.   def draw_background(rect)
  116.     temp_rect = rect.clone
  117.     temp_rect.width /= 2
  118.     contents.gradient_fill_rect(temp_rect, back_color2, back_color1)
  119.     temp_rect.x = temp_rect.width
  120.     contents.gradient_fill_rect(temp_rect, back_color1, back_color2)
  121.   end
  122.  
  123.   def back_color1
  124.     Color.new(0, 0, 0, 192)
  125.   end
  126.  
  127.   def back_color2
  128.     Color.new(0, 0, 0, 0)
  129.   end
  130. end
  131.  
  132.  
  133. class Scene_Map < Scene_Base
  134.  
  135.   alias start_quick_save_load start
  136.   def start
  137.     start_quick_save_load
  138.     create_notify
  139.     show_load_notify if $game_system.quick_load
  140.   end
  141.  
  142.   def create_notify
  143.     @notify_window = Window_Notify.new
  144.     @notify_window.viewport = @viewport
  145.   end
  146.  
  147.   alias quick_save_load_update update
  148.   def update
  149.     quick_save_load_update
  150.     save_file if input_save?
  151.     load_file if input_load?
  152.   end
  153.  
  154.   def save_file
  155.     @notify_window.close
  156.     $game_system.on_before_save
  157.     DataManager.save_game(THEO::SAVE::INDEX)
  158.     show_save_notify
  159.   end
  160.  
  161.   def load_file
  162.     @notify_window.close
  163.     DataManager.load_game(THEO::SAVE::INDEX)
  164.     $game_system.on_after_load
  165.     SceneManager.goto(Scene_Map)
  166.     $game_system.quick_load = true
  167.   end
  168.  
  169.   def show_save_notify
  170.     @notify_window.show = THEO::SAVE::SAVE_NOTIFY
  171.   end
  172.  
  173.   def show_load_notify
  174.     @notify_window.show = THEO::SAVE::LOAD_NOTIFY
  175.     $game_system.quick_load = false
  176.   end
  177.  
  178.   def input_save?
  179.     id = THEO::SAVE::SAVE_SWITCH_ID
  180.     Input.trigger?(THEO::SAVE::SAVE_BUTTON) && (id > 0 ? $game_switches[id] : true)
  181.   end
  182.  
  183.   def input_load?
  184.     id = THEO::SAVE::LOAD_SWITCH_ID
  185.     Input.trigger?(THEO::SAVE::LOAD_BUTTON) && (id > 0 ? $game_switches[id] : true)
  186.   end
  187.  
  188. end
  189.  
  190. class Game_System
  191.   attr_accessor :quick_load
  192.  
  193.   alias pre_quick_init initialize
  194.   def initialize
  195.     pre_quick_init
  196.     @quick_load = false
  197.   end
  198.  
  199. end
Advertisement
Add Comment
Please, Sign In to add comment