Heartbreak61

[SIMPLE STUPID] Exit & Overwrite Confirmation ver.0.61

Jan 5th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.64 KB | None | 0 0
  1. #==============================================================================
  2. # SIMPLE STUPID EXIT & OVERWRITE CONFIRMATION ver.0.61
  3. # by HBK
  4. # Requires: N/A
  5. # Rewrites method (if Confirmation enabled):
  6. #   Scene_End.command_to_title
  7. #   Scene_End.command_shutdown
  8. #   Scene_Save.on_savefile_ok
  9. # Aliases method: N/A
  10. #==============================================================================
  11. # CHANGELOG
  12. # - ver0.61   2012.01.03    starting script and finished
  13. #==============================================================================
  14. # INTRODUCTION
  15. # - Script ini memberikan warning kepada player saat akan balik ke title menu,
  16. #   exit game, dan overwrite save file yang telah ada
  17. #==============================================================================
  18. # INSTRUCTION
  19. # - Utak atik aja module HBK.
  20. # - Bisa jadi ini script konflik KALAU konfirmasi enabled = true dan
  21. #   ada script lain yang juga me-rewrite 3 method yang sudah saya sebut di atas.
  22. #==============================================================================
  23.  
  24. module HBK
  25.   # Ganti jadi false buat bagian yang dirasa ga perlu konfirmasi
  26.   ENABLE_TITLE_CONFIRMATION      = true
  27.   ENABLE_SHUTDOWN_CONFIRMATION   = true
  28.   ENABLE_OVERWRITE_CONFIRMATION  = true
  29.   # Atur lebar judul menu konfirmasi
  30.   CONFIRM_TITLE_WIDTH            = 220
  31.   module VOCAB
  32.     CONFIRM_TO_TITLE    = "Back to Title?"
  33.     CONFIRM_SHUTDOWN    = "Exit Game?"
  34.     CONFIRM_OVERWRITE   = "Overwrite Data?"
  35.   end
  36. end
  37.  
  38. # Jangan dirubah kecuali anda yakin dengan apa yang anda lakukan :P
  39. #==============================================================================
  40. class Scene_Base; include HBK;end
  41. class Window_Base; include HBK;end
  42.  
  43. class Scene_End < Scene_MenuBase
  44.   alias hbk_sseoc_command_to_title command_to_title
  45.   def command_to_title
  46.     if HBK::ENABLE_TITLE_CONFIRMATION
  47.       SceneManager.call(Scene_ConfirmTitle)
  48.     else
  49.       hbk_sseoc_command_to_title
  50.     end
  51.   end
  52.   alias hbk_sseoc_command_shutdown command_shutdown
  53.   def command_shutdown
  54.     if HBK::ENABLE_SHUTDOWN_CONFIRMATION
  55.       SceneManager.call(Scene_ConfirmShutdown)
  56.     else
  57.       hbk_sseoc_command_shutdown
  58.     end
  59.   end
  60. end
  61.  
  62. class Scene_Save < Scene_File
  63.   alias hbk_sseoc_on_savefile_ok on_savefile_ok
  64.   def on_savefile_ok
  65.     @index < 9 ? str = "0" + (@index+1).to_s : str = (@index+1).to_s
  66.     if HBK::ENABLE_OVERWRITE_CONFIRMATION && !Dir.glob("Save"+str+".rvdata2").empty?
  67.       SceneManager.call(Scene_ConfirmSave)
  68.     else
  69.       hbk_sseoc_on_savefile_ok
  70.     end
  71.   end
  72. end
  73.  
  74. class Scene_ConfirmSave < Scene_Save
  75.   def start
  76.     super
  77.     create_background
  78.     create_command_window
  79.   end
  80.   def pre_terminate
  81.     super
  82.     close_command_window
  83.   end
  84.   def terminate
  85.     super
  86.     dispose_background
  87.   end
  88.   def create_background
  89.     @background_sprite = Sprite.new
  90.     @background_sprite.bitmap = SceneManager.background_bitmap
  91.     @background_sprite.color.set(16, 16, 16, 128)
  92.   end
  93.   def dispose_background
  94.     @background_sprite.dispose
  95.   end
  96.   def create_command_window
  97.     @command_window = Window_ConfirmOverwrite.new
  98.     @command_window.set_handler(:overwrite, method(:command_overwrite))
  99.     @command_window.set_handler(:cancel,   method(:return_scene))
  100.     @title_window = Window_ConfirmOverwriteTitle.new
  101.   end
  102.   def close_command_window
  103.     @command_window.close
  104.     update until @command_window.close?
  105.   end
  106.   def command_overwrite
  107.     if DataManager.save_game(@index)
  108.       on_save_success
  109.     else
  110.       Sound.play_buzzer
  111.     end
  112.   end
  113. end
  114.  
  115. class Window_ConfirmOverwriteTitle < Window_Base
  116.   def initialize
  117.     super(0,0,window_width,fitting_height(1))
  118.     refresh
  119.   end
  120.   def window_width;return HBK::CONFIRM_TITLE_WIDTH;end
  121.   def refresh
  122.     contents.clear
  123.     self.x = (Graphics.width - width) / 2
  124.     self.y = (Graphics.height - height) / 2 - fitting_height(2)
  125.     draw_title(4,0,contents.width-8)
  126.   end
  127.   def draw_title(x,y,width)
  128.     text=HBK::VOCAB::CONFIRM_OVERWRITE
  129.     draw_text(x,y,width,line_height,text,1)
  130.   end
  131.   def open;refresh;super;end
  132. end
  133.  
  134. class Window_ConfirmOverwrite < Window_Command
  135.   def initialize
  136.     super(0,0)
  137.     update_placement
  138.   end
  139.   def window_width;return 80;end
  140.   def update_placement
  141.     self.x = (Graphics.width - width) / 2
  142.     self.y = (Graphics.height - height) / 2
  143.   end
  144.   def make_command_list
  145.     add_command("Yes", :overwrite)
  146.     add_command("No", :cancel)
  147.   end
  148. end
  149.  
  150. class Scene_ConfirmTitle < Scene_End
  151.   def create_command_window
  152.     @command_window = Window_ConfirmTitle.new
  153.     @command_window.set_handler(:to_title, method(:command_to_title))
  154.     @command_window.set_handler(:cancel,   method(:return_scene))
  155.     @title_window = Window_ConfirmTitleTitle.new
  156.   end
  157.   def command_to_title
  158.     close_command_window
  159.     fadeout_all
  160.     SceneManager.goto(Scene_Title)
  161.   end
  162. end
  163.  
  164. class Scene_ConfirmShutdown < Scene_End
  165.   def create_command_window
  166.     @command_window = Window_ConfirmShutdown.new
  167.     @command_window.set_handler(:shutdown, method(:command_shutdown))
  168.     @command_window.set_handler(:cancel,   method(:return_scene))
  169.     @title_window = Window_ConfirmShutdownTitle.new
  170.   end
  171.   def command_shutdown
  172.     close_command_window
  173.     fadeout_all
  174.     SceneManager.exit
  175.   end
  176. end
  177.  
  178. class Window_ConfirmTitleTitle < Window_Base
  179.   def initialize
  180.     super(0,0,window_width,fitting_height(1))
  181.     refresh
  182.   end
  183.   def window_width;return HBK::CONFIRM_TITLE_WIDTH;end
  184.   def refresh
  185.     contents.clear
  186.     self.x = (Graphics.width - width) / 2
  187.     self.y = (Graphics.height - height) / 2 - fitting_height(2)
  188.     draw_title(4,0,contents.width-8)
  189.   end
  190.   def draw_title(x,y,width)
  191.     text=HBK::VOCAB::CONFIRM_TO_TITLE
  192.     draw_text(x,y,width,line_height,text,1)
  193.   end
  194.   def open;refresh;super;end
  195. end
  196.  
  197. class Window_ConfirmShutdownTitle < Window_Base
  198.   def initialize
  199.     super(0,0,window_width,fitting_height(1))
  200.     refresh
  201.   end
  202.   def window_width;return HBK::CONFIRM_TITLE_WIDTH;end
  203.   def refresh
  204.     contents.clear
  205.     self.x = (Graphics.width - width) / 2
  206.     self.y = (Graphics.height - height) / 2 - fitting_height(2)
  207.     draw_title(4,0,contents.width-8)
  208.   end
  209.   def draw_title(x,y,width)
  210.     text=HBK::VOCAB::CONFIRM_SHUTDOWN
  211.     draw_text(x,y,width,line_height,text,1)
  212.   end
  213.   def open;refresh;super;end
  214. end
  215.  
  216. class Window_ConfirmTitle < Window_GameEnd
  217.   def window_width;return 80;end
  218.   def make_command_list
  219.     add_command("Yes", :to_title)
  220.     add_command("No", :cancel)
  221.   end
  222. end
  223.  
  224. class Window_ConfirmShutdown < Window_GameEnd
  225.   def window_width;return 80;end
  226.   def make_command_list
  227.     add_command("Yes", :shutdown)
  228.     add_command("No", :cancel)
  229.   end
  230. end
Advertisement
Add Comment
Please, Sign In to add comment