Guest User

Untitled

a guest
Feb 21st, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.65 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # Yanfly 6 - Overzeal Save Menu
  4. # --- Last Date Updated: 2011.10.26
  5. # --- Level: Normal
  6. # Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported == nil
  11. $imported["Y6-OZSaveMenu"] = true
  12.  
  13. #==============================================================================
  14. # Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # o 2011.10.26 - Started Script and Finished.
  17. #
  18. #==============================================================================
  19. # Introduction
  20. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  21. # This is Overzeal's special save menu! You can save, load, and even delete
  22. # saves from the menu itself. Note that this system doesn't use confirmation
  23. # choices for loading and saving because I think those are annoying.
  24. #
  25. #==============================================================================
  26. # Instructions
  27. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  28. # To install this script, open up your script editor and copy/paste this script
  29. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  30. #
  31. # Save the chapter images under the Graphics\Pictures\ directory.
  32. #
  33. #==============================================================================
  34. # Compatibility
  35. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  36. # Note: This script may not work with former Yanfly Engine scripts.
  37. # Use Yanfly Engine 6 scripts to work with this if available.
  38. #==============================================================================
  39.  
  40. module Y6
  41. module SAVE
  42.  
  43. #--------------------------------------------------------------------------
  44. # - Save Window Text -
  45. #--------------------------------------------------------------------------
  46. # These are the settings used for the save window text.
  47. #--------------------------------------------------------------------------
  48. SLOT = "Slot %d"
  49. MAX_SLOTS = 100
  50. NO_FILE_ICON = 73
  51. YES_FILE_ICON = 72
  52. SAVE_VOCAB = "Save"
  53. LOAD_VOCAB = "Load"
  54. DELETE_VOCAB = "Delete"
  55. DELETE_SOUND = "Drop"
  56.  
  57. #--------------------------------------------------------------------------
  58. # - Chapter Settings -
  59. #--------------------------------------------------------------------------
  60. # Here, you can adjust the chapter settings that appear. Save images go
  61. # under Graphics\Pictures\ directory. For no-save settings, use chapter 0.
  62. #--------------------------------------------------------------------------
  63. CHAPTER_VARIABLE = 22
  64. CHAPTER_SETTINGS ={
  65. # ChapterNo. => ["Title", "ImageFilename"]
  66. 0 => ["------", "Game0"],
  67. 1 => ["Game 1: Hiding and Seeking", "Game1"],
  68. 2 => ["Game 2: Old Maid", "Game1"],
  69. 3 => ["Game 3: Cat's Cradle", "Game1"],
  70. 4 => ["Game 4: Candy Land", "Game1"],
  71. 5 => ["Game 5: Hopscotch", "Game1"],
  72. 6 => ["Game 6: Mother May I?", "Game1"],
  73. 7 => ["Game 7: Seven Up", "Game1"],
  74. 8 => ["Game 8: Hot and Cold", "Game1"],
  75. 9 => ["Game 9: Thumb War", "Game1"],
  76. 10 => ["Last Game: Follow the Leader", "Game1"],
  77. 11 => ["Post Game: Overzeal", "Game1"],
  78. } # Do not remove this.
  79.  
  80. end # SAVE
  81. end # Y6
  82.  
  83. #==============================================================================
  84. # Editting anything past this point may potentially result in causing computer
  85. # damage, incontinence, explosion of user's head, coma, death, and/or halitosis
  86. # so edit at your own risk.
  87. #==============================================================================
  88.  
  89. #==============================================================================
  90. # ** Window_File_Small
  91. #==============================================================================
  92.  
  93. class Window_File_Small < Window_Base
  94.  
  95. #--------------------------------------------------------------------------
  96. # initialize
  97. #--------------------------------------------------------------------------
  98. def initialize
  99. super(0, 0, Graphics.width, 56)
  100. end
  101.  
  102. #--------------------------------------------------------------------------
  103. # change
  104. #--------------------------------------------------------------------------
  105. def change(file_index, filename)
  106. @file_index = file_index
  107. @filename = filename
  108. load_gamedata
  109. refresh
  110. end
  111.  
  112. #--------------------------------------------------------------------------
  113. # load_gamedata
  114. #--------------------------------------------------------------------------
  115. def load_gamedata
  116. @time_stamp = Time.at(0)
  117. @file_exist = FileTest.exist?(@filename)
  118. if @file_exist
  119. file = File.open(@filename, "r")
  120. @time_stamp = file.mtime
  121. begin
  122. @characters = Marshal.load(file)
  123. @frame_count = Marshal.load(file)
  124. @last_bgm = Marshal.load(file)
  125. @last_bgs = Marshal.load(file)
  126. @game_system = Marshal.load(file)
  127. @game_message = Marshal.load(file)
  128. @game_switches = Marshal.load(file)
  129. @game_variables = Marshal.load(file)
  130. @total_sec = @frame_count / Graphics.frame_rate
  131. rescue
  132. @file_exist = false
  133. ensure
  134. file.close
  135. end
  136. end
  137. end
  138.  
  139. #--------------------------------------------------------------------------
  140. # refresh
  141. #--------------------------------------------------------------------------
  142. def refresh
  143. contents.clear
  144. contents.font.color = normal_color
  145. contents.font.color.alpha = @file_exist ? 255 : 128
  146. draw_file_icon
  147. draw_file_number
  148. draw_chapter_name
  149. draw_play_time
  150. end
  151.  
  152. #--------------------------------------------------------------------------
  153. # draw_file_icon
  154. #--------------------------------------------------------------------------
  155. def draw_file_icon
  156. if @file_exist
  157. draw_icon(Y6::SAVE::YES_FILE_ICON, 0, 0)
  158. else
  159. draw_icon(Y6::SAVE::NO_FILE_ICON, 0, 0, false)
  160. end
  161. end
  162.  
  163. #--------------------------------------------------------------------------
  164. # draw_file_number
  165. #--------------------------------------------------------------------------
  166. def draw_file_number
  167. text = sprintf(Y6::SAVE::SLOT, @file_index + 1)
  168. contents.draw_text(24, 0, 96, WLH, text)
  169. end
  170.  
  171. #--------------------------------------------------------------------------
  172. # draw_chapter_name
  173. #--------------------------------------------------------------------------
  174. def draw_chapter_name
  175. if @file_exist
  176. chapter_number = [@game_variables[Y6::SAVE::CHAPTER_VARIABLE], 1].max
  177. text = Y6::SAVE::CHAPTER_SETTINGS[chapter_number][0]
  178. else
  179. text = Y6::SAVE::CHAPTER_SETTINGS[0][0]
  180. end
  181. contents.draw_text(120, 0, contents.width-240, WLH, text)
  182. end
  183.  
  184. #--------------------------------------------------------------------------
  185. # draw_play_time
  186. #--------------------------------------------------------------------------
  187. def draw_play_time
  188. if @file_exist
  189. hour = @total_sec / 60 / 60
  190. min = @total_sec / 60 % 60
  191. sec = @total_sec % 60
  192. time_string = sprintf("%d:%02d:%02d", hour, min, sec)
  193. else
  194. time_string = "0:00:00"
  195. end
  196. contents.draw_text(contents.width-120, 0, 120, WLH, time_string, 2)
  197. end
  198.  
  199. end # Window_File_Small
  200.  
  201. #==============================================================================
  202. # ** Window_File_Big
  203. #==============================================================================
  204.  
  205. class Window_File_Big < Window_Selectable
  206.  
  207. #--------------------------------------------------------------------------
  208. # * Public Instance Variables
  209. #--------------------------------------------------------------------------
  210. attr_accessor :filename
  211. attr_accessor :file_exist
  212.  
  213. #--------------------------------------------------------------------------
  214. # initialize
  215. #--------------------------------------------------------------------------
  216. def initialize(from_title)
  217. super(0, 0, Graphics.width, Graphics.height-56*4)
  218. @from_title = from_title
  219. @column_max = 3
  220. @item_max = 3
  221. self.index = @from_title ? 1 : 0
  222. end
  223.  
  224. #--------------------------------------------------------------------------
  225. # change
  226. #--------------------------------------------------------------------------
  227. def change(file_index, filename)
  228. @file_index = file_index
  229. @filename = filename
  230. load_gamedata
  231. refresh
  232. end
  233.  
  234. #--------------------------------------------------------------------------
  235. # load_gamedata
  236. #--------------------------------------------------------------------------
  237. def load_gamedata
  238. @time_stamp = Time.at(0)
  239. @file_exist = FileTest.exist?(@filename)
  240. if @file_exist
  241. file = File.open(@filename, "r")
  242. @time_stamp = file.mtime
  243. begin
  244. @characters = Marshal.load(file)
  245. @frame_count = Marshal.load(file)
  246. @last_bgm = Marshal.load(file)
  247. @last_bgs = Marshal.load(file)
  248. @game_system = Marshal.load(file)
  249. @game_message = Marshal.load(file)
  250. @game_switches = Marshal.load(file)
  251. @game_variables = Marshal.load(file)
  252. @total_sec = @frame_count / Graphics.frame_rate
  253. rescue
  254. @file_exist = false
  255. ensure
  256. file.close
  257. end
  258. end
  259. end
  260.  
  261. #--------------------------------------------------------------------------
  262. # refresh
  263. #--------------------------------------------------------------------------
  264. def refresh
  265. contents.clear
  266. contents.font.color = normal_color
  267. contents.font.color.alpha = @file_exist ? 255 : 128
  268. draw_game_picture
  269. draw_file_icon
  270. draw_file_number
  271. draw_chapter_name
  272. draw_play_time
  273. draw_options
  274. end
  275.  
  276. #--------------------------------------------------------------------------
  277. # draw_game_picture
  278. #--------------------------------------------------------------------------
  279. def draw_game_picture
  280. if @file_exist
  281. chapter_number = [@game_variables[Y6::SAVE::CHAPTER_VARIABLE], 1].max
  282. else
  283. chapter_number = 0
  284. end
  285. image = Y6::SAVE::CHAPTER_SETTINGS[chapter_number][1]
  286. bitmap = Cache.picture(image)
  287. rect = Rect.new(0, 0, contents.width, contents.height)
  288. contents.blt(0, 0, bitmap, rect)
  289. bitmap.dispose
  290. end
  291.  
  292. #--------------------------------------------------------------------------
  293. # draw_file_icon
  294. #--------------------------------------------------------------------------
  295. def draw_file_icon
  296. if @file_exist
  297. draw_icon(Y6::SAVE::YES_FILE_ICON, 0, 0)
  298. else
  299. draw_icon(Y6::SAVE::NO_FILE_ICON, 0, 0, false)
  300. end
  301. end
  302.  
  303. #--------------------------------------------------------------------------
  304. # draw_file_number
  305. #--------------------------------------------------------------------------
  306. def draw_file_number
  307. text = sprintf(Y6::SAVE::SLOT, @file_index + 1)
  308. contents.draw_text(24, 0, 96, WLH, text)
  309. end
  310.  
  311. #--------------------------------------------------------------------------
  312. # draw_chapter_name
  313. #--------------------------------------------------------------------------
  314. def draw_chapter_name
  315. if @file_exist
  316. chapter_number = [@game_variables[Y6::SAVE::CHAPTER_VARIABLE], 1].max
  317. text = Y6::SAVE::CHAPTER_SETTINGS[chapter_number][0]
  318. else
  319. text = Y6::SAVE::CHAPTER_SETTINGS[0][0]
  320. end
  321. contents.draw_text(120, 0, contents.width-240, WLH, text)
  322. end
  323.  
  324. #--------------------------------------------------------------------------
  325. # draw_play_time
  326. #--------------------------------------------------------------------------
  327. def draw_play_time
  328. if @file_exist
  329. hour = @total_sec / 60 / 60
  330. min = @total_sec / 60 % 60
  331. sec = @total_sec % 60
  332. time_string = sprintf("%d:%02d:%02d", hour, min, sec)
  333. else
  334. time_string = "0:00:00"
  335. end
  336. contents.draw_text(contents.width-120, 0, 120, WLH, time_string, 2)
  337. end
  338.  
  339. #--------------------------------------------------------------------------
  340. # draw_options
  341. #--------------------------------------------------------------------------
  342. def draw_options
  343. #---
  344. rect = item_rect(2)
  345. text = Y6::SAVE::DELETE_VOCAB
  346. contents.draw_text(rect, text, 1)
  347. #---
  348. rect = item_rect(1)
  349. text = Y6::SAVE::LOAD_VOCAB
  350. contents.draw_text(rect, text, 1)
  351. #---
  352. rect = item_rect(0)
  353. contents.font.color.alpha = @from_title ? 128 : 255
  354. text = Y6::SAVE::SAVE_VOCAB
  355. contents.draw_text(rect, text, 1)
  356. #---
  357. end
  358.  
  359. #--------------------------------------------------------------------------
  360. # item_rect
  361. #--------------------------------------------------------------------------
  362. def item_rect(index)
  363. rect = Rect.new(0, 0, 0, 0)
  364. rect.width = contents.width/3 - 48
  365. rect.height = WLH
  366. rect.x = index * contents.width/3 + 24
  367. rect.y = contents.height - WLH
  368. return rect
  369. end
  370.  
  371. end # Window_File_Big
  372.  
  373. #==============================================================================
  374. # ** Scene_File
  375. #==============================================================================
  376.  
  377. class Scene_File < Scene_Base
  378.  
  379. #--------------------------------------------------------------------------
  380. # overwrite method: start
  381. #--------------------------------------------------------------------------
  382. def start
  383. super
  384. create_menu_background
  385. @index = @saving ? $game_temp.last_file_index : latest_file_index
  386. create_savefile_windows
  387. end
  388.  
  389. #--------------------------------------------------------------------------
  390. # overwrite method: latest_file_index
  391. #--------------------------------------------------------------------------
  392. def latest_file_index
  393. index = 0
  394. latest_time = Time.at(0)
  395. for i in 1..Y6::SAVE::MAX_SLOTS
  396. file_name = make_filename(i - 1)
  397. next unless FileTest.exist?(file_name)
  398. file_time = File.mtime(file_name)
  399. if file_time > latest_time
  400. latest_time = file_time
  401. latest_index = i - 1
  402. index = latest_index
  403. end
  404. end
  405. return index
  406. end
  407.  
  408. #--------------------------------------------------------------------------
  409. # overwrite method: terminate
  410. #--------------------------------------------------------------------------
  411. def terminate
  412. super
  413. dispose_menu_background
  414. dispose_item_windows
  415. end
  416.  
  417. #--------------------------------------------------------------------------
  418. # overwrite method: update
  419. #--------------------------------------------------------------------------
  420. def update
  421. super
  422. update_menu_background
  423. organize_savefile_locations
  424. update_savefile_windows
  425. if Input.trigger?(Input::UP)
  426. Sound.play_cursor
  427. if @index == 0
  428. @index = Y6::SAVE::MAX_SLOTS - 1
  429. else
  430. @index = [@index - 1, 0].max
  431. end
  432. elsif Input.trigger?(Input::DOWN)
  433. Sound.play_cursor
  434. if @index == Y6::SAVE::MAX_SLOTS - 1
  435. @index = 0
  436. else
  437. @index = [@index + 1, Y6::SAVE::MAX_SLOTS - 1].min
  438. end
  439. elsif Input.repeat?(Input::UP)
  440. last_index = @index
  441. @index = [@index - 1, 0].max
  442. Sound.play_cursor if last_index != @index
  443. elsif Input.repeat?(Input::L)
  444. last_index = @index
  445. @index = [@index - 5, 0].max
  446. Sound.play_cursor if last_index != @index
  447. elsif Input.repeat?(Input::DOWN)
  448. last_index = @index
  449. @index = [@index + 1, Y6::SAVE::MAX_SLOTS - 1].min
  450. Sound.play_cursor if last_index != @index
  451. elsif Input.repeat?(Input::R)
  452. last_index = @index
  453. @index = [@index + 5, Y6::SAVE::MAX_SLOTS - 1].min
  454. Sound.play_cursor if last_index != @index
  455. elsif Input.trigger?(Input::B)
  456. Sound.play_cancel
  457. return_scene
  458. elsif Input.trigger?(Input::C)
  459. command_input
  460. end
  461. end
  462.  
  463. #--------------------------------------------------------------------------
  464. # overwrite method: create_savefile_windows
  465. #--------------------------------------------------------------------------
  466. def create_savefile_windows
  467. @savefile_windows = []
  468. for i in 0..3
  469. @savefile_windows.push(Window_File_Small.new)
  470. end
  471. @item_max = Y6::SAVE::MAX_SLOTS
  472. @savefile_big = Window_File_Big.new(@from_title)
  473. organize_savefile_locations
  474. update_savefile_windows
  475. end
  476.  
  477. #--------------------------------------------------------------------------
  478. # overwrite method: dispose_item_windows
  479. #--------------------------------------------------------------------------
  480. def dispose_item_windows
  481. for window in @savefile_windows; window.dispose; end
  482. @savefile_big.dispose
  483. end
  484.  
  485. #--------------------------------------------------------------------------
  486. # new method: update_savefile_windows
  487. #--------------------------------------------------------------------------
  488. def update_savefile_windows
  489. @savefile_big.update
  490. @savefile_windows[0].update
  491. @savefile_windows[1].update
  492. @savefile_windows[2].update
  493. @savefile_windows[3].update
  494. end
  495.  
  496. #--------------------------------------------------------------------------
  497. # new method: organize_savefile_locations
  498. #--------------------------------------------------------------------------
  499. def organize_savefile_locations
  500. return if @last_index == @index
  501. @last_index = @index
  502. if @index == 0
  503. @savefile_big.y = 0
  504. @savefile_big.change(@index, make_filename(@index))
  505. @savefile_windows[0].y = Graphics.height-56*4
  506. @savefile_windows[0].change(@index+1, make_filename(@index+1))
  507. @savefile_windows[1].y = Graphics.height-56*3
  508. @savefile_windows[1].change(@index+2, make_filename(@index+2))
  509. @savefile_windows[2].y = Graphics.height-56*2
  510. @savefile_windows[2].change(@index+3, make_filename(@index+3))
  511. @savefile_windows[3].y = Graphics.height-56*1
  512. @savefile_windows[3].change(@index+4, make_filename(@index+4))
  513. elsif @index == 1
  514. @savefile_windows[0].y = 56*0
  515. @savefile_windows[0].change(@index-1, make_filename(@index-1))
  516. @savefile_big.y = 56*1
  517. @savefile_big.change(@index, make_filename(@index))
  518. @savefile_windows[1].y = Graphics.height-56*3
  519. @savefile_windows[1].change(@index+1, make_filename(@index+1))
  520. @savefile_windows[2].y = Graphics.height-56*2
  521. @savefile_windows[2].change(@index+2, make_filename(@index+2))
  522. @savefile_windows[3].y = Graphics.height-56*1
  523. @savefile_windows[3].change(@index+3, make_filename(@index+3))
  524. elsif @index == Y6::SAVE::MAX_SLOTS - 2
  525. @savefile_windows[0].y = 56*0
  526. @savefile_windows[0].change(@index-3, make_filename(@index-3))
  527. @savefile_windows[1].y = 56*1
  528. @savefile_windows[1].change(@index-2, make_filename(@index-2))
  529. @savefile_windows[2].y = 56*2
  530. @savefile_windows[2].change(@index-1, make_filename(@index-1))
  531. @savefile_big.y = 56*3
  532. @savefile_big.change(@index, make_filename(@index))
  533. @savefile_windows[3].y = Graphics.height-56*1
  534. @savefile_windows[3].change(@index+1, make_filename(@index+1))
  535. elsif @index == Y6::SAVE::MAX_SLOTS - 1
  536. @savefile_windows[0].y = 56*0
  537. @savefile_windows[0].change(@index-4, make_filename(@index-4))
  538. @savefile_windows[1].y = 56*1
  539. @savefile_windows[1].change(@index-3, make_filename(@index-3))
  540. @savefile_windows[2].y = 56*2
  541. @savefile_windows[2].change(@index-2, make_filename(@index-2))
  542. @savefile_windows[3].y = 56*3
  543. @savefile_windows[3].change(@index-1, make_filename(@index-1))
  544. @savefile_big.y = 56*4
  545. @savefile_big.change(@index, make_filename(@index))
  546. else
  547. @savefile_windows[0].y = 56*0
  548. @savefile_windows[0].change(@index-2, make_filename(@index-2))
  549. @savefile_windows[1].y = 56*1
  550. @savefile_windows[1].change(@index-1, make_filename(@index-1))
  551. @savefile_big.y = 56*2
  552. @savefile_big.change(@index, make_filename(@index))
  553. @savefile_windows[2].y = Graphics.height-56*2
  554. @savefile_windows[2].change(@index+1, make_filename(@index+1))
  555. @savefile_windows[3].y = Graphics.height-56*1
  556. @savefile_windows[3].change(@index+2, make_filename(@index+2))
  557. end
  558. end
  559.  
  560. #--------------------------------------------------------------------------
  561. # new method: command_input
  562. #--------------------------------------------------------------------------
  563. def command_input
  564. case @savefile_big.index
  565. when 0 # Save
  566. if @from_title
  567. Sound.play_buzzer
  568. else
  569. Sound.play_save
  570. do_save
  571. end
  572. when 1 # Load
  573. if @savefile_big.file_exist
  574. Sound.play_load
  575. do_load
  576. else
  577. Sound.play_buzzer
  578. end
  579. else # Delete
  580. if @savefile_big.file_exist
  581. RPG::SE.new(Y6::SAVE::DELETE_SOUND, 100).play
  582. do_delete
  583. else
  584. Sound.play_buzzer
  585. end
  586. end
  587. end
  588.  
  589. #--------------------------------------------------------------------------
  590. # overwrite method: do_save
  591. #--------------------------------------------------------------------------
  592. def do_save
  593. $game_temp.last_file_index = @index
  594. file = File.open(@savefile_big.filename, "wb")
  595. write_save_data(file)
  596. file.close
  597. @savefile_big.change(@index, make_filename(@index))
  598. end
  599.  
  600. #--------------------------------------------------------------------------
  601. # overwrite method: do_load
  602. #--------------------------------------------------------------------------
  603. def do_load
  604. return unless FileTest.exist?(@savefile_big.filename)
  605. $game_temp.last_file_index = @index
  606. file = File.open(@savefile_big.filename, "rb")
  607. read_save_data(file)
  608. file.close
  609. $scene = Scene_Map.new
  610. RPG::BGM.fade(1500)
  611. Graphics.fadeout(60)
  612. @last_bgm.play
  613. @last_bgs.play
  614. end
  615.  
  616. #--------------------------------------------------------------------------
  617. # overwrite method: do_delete
  618. #--------------------------------------------------------------------------
  619. def do_delete
  620. filename = @savefile_big.filename
  621. File.delete(filename) if FileTest.exist?(filename)
  622. @savefile_big.change(@index, make_filename(@index))
  623. end
  624.  
  625. end # Scene_File
  626.  
  627. #===============================================================================
  628. #
  629. # END OF FILE
  630. #
  631. #===============================================================================
Add Comment
Please, Sign In to add comment