Advertisement
mikini

Code

Jul 27th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.99 KB | None | 0 0
  1. @screen = Win32API.new 'screenshot', 'Screenshot', %w(l l l l p l l), ''
  2. @readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
  3. @findwindow = Win32API.new 'user32', 'FindWindowA', %w(p p), 'l'
  4. module_function
  5.  
  6. def self.shot(file_name)
  7. case IMAGE_FILETYPE
  8. when '.bmp'; typid = 0
  9. when '.jpg'; typid = 1
  10. when '.png'; typid = 2
  11. end
  12.  
  13. # Get Screenshot
  14. filename = file_name + IMAGE_FILETYPE
  15. @screen.call(0, 0, Graphics.width, Graphics.height, filename, self.handel,
  16. typid)
  17. end
  18.  
  19. def self.handel
  20. game_name = "\0" * 256
  21. @readini.call('Game','Title','',game_name,255,".\\Game.ini")
  22. game_name.delete!("\0")
  23.  
  24. return @findwindow.call('RGSS Player',game_name)
  25. end
  26. end
  27.  
  28. class Scene_File < Scene_Base
  29. include Wora_NSS
  30. attr_reader :window_slotdetail
  31.  
  32. #-------------------------------------------------------------------------
  33. # * Start processing
  34. #-------------------------------------------------------------------------
  35. def start
  36. super
  37.  
  38. create_menu_background
  39.  
  40. if NSS_IMAGE_BG != ''
  41. @bg = Sprite.new
  42. @bg.bitmap = Cache.picture(NSS_IMAGE_BG)
  43. @bg.opacity = NSS_IMAGE_BG_OPACITY
  44. end
  45.  
  46. @help_window = Window_Help.new
  47. command = []
  48.  
  49. (1..MAX_SAVE_SLOT).each do |i|
  50. command << SLOT_NAME.clone.gsub!(/\{ID\}/i) { i.to_s }
  51. end
  52.  
  53. @window_slotdetail = Window_NSS_SlotDetail.new
  54. @window_slotlist = Window_SlotList.new(160, command)
  55. @window_slotlist.y = @help_window.height
  56. @window_slotlist.height = Graphics.height - @help_window.height
  57.  
  58. if !OPACITY_DEFAULT
  59. @help_window.opacity = NSS_WINDOW_OPACITY
  60. @window_slotdetail.opacity = @window_slotlist.opacity = NSS_WINDOW_OPACITY
  61. end
  62.  
  63. # Create folder for save file
  64. if SAVE_PATH != ''
  65. Dir.mkdir(SAVE_PATH) if !FileTest.directory?(SAVE_PATH)
  66. end
  67.  
  68. if @saving
  69. @index = $game_temp.last_file_index
  70. @help_window.set_text(Vocab::SaveMessage)
  71. else
  72. @index = self.latest_file_index
  73. @help_window.set_text(Vocab::LoadMessage)
  74.  
  75. (1..MAX_SAVE_SLOT).each do |i|
  76. @window_slotlist.draw_item(i-1, false) if !@window_slotdetail.file_exist?(i)
  77. end
  78. end
  79.  
  80. @window_slotlist.index = @index
  81.  
  82. # Draw information
  83. @last_slot_index = @window_slotlist.index
  84. @window_slotdetail.draw_data(@last_slot_index + 1)
  85. end
  86.  
  87. #--------------------------------------------------------------------------
  88. # * Termination Processing
  89. #--------------------------------------------------------------------------
  90. def terminate
  91. super
  92.  
  93. dispose_menu_background
  94.  
  95. unless @bg.nil?
  96. @bg.bitmap.dispose
  97. @bg.dispose
  98. end
  99.  
  100. @window_slotlist.dispose
  101. @window_slotdetail.dispose
  102. @help_window.dispose
  103. end
  104.  
  105. #--------------------------------------------------------------------------
  106. # * Frame Update
  107. #--------------------------------------------------------------------------
  108. def update
  109. super
  110.  
  111. if !@confirm_window.nil?
  112. @confirm_window.update
  113.  
  114. if Input.trigger?(Input::C)
  115. if @confirm_window.index == 0
  116. determine_savefile
  117. @confirm_window.dispose
  118. @confirm_window = nil
  119. else
  120. Sound.play_cancel
  121. @confirm_window.dispose
  122. @confirm_window = nil
  123. end
  124. elsif Input.trigger?(Input::B)
  125. Sound.play_cancel
  126. @confirm_window.dispose
  127. @confirm_window = nil
  128. end
  129. else
  130. update_menu_background
  131. @window_slotlist.update
  132.  
  133. if @window_slotlist.index != @last_slot_index
  134. @last_slot_index = @window_slotlist.index
  135. @window_slotdetail.draw_data(@last_slot_index + 1)
  136. end
  137.  
  138. @help_window.update
  139. update_savefile_selection
  140. end
  141. end
  142.  
  143. #--------------------------------------------------------------------------
  144. # * Update Save File Selection
  145. #--------------------------------------------------------------------------
  146. def update_savefile_selection
  147. if Input.trigger?(Input::C)
  148. if @saving and @window_slotdetail.file_exist?(@last_slot_index + 1)
  149. Sound.play_decision
  150. text1 = SFC_Text_Confirm
  151. text2 = SFC_Text_Cancel
  152. @confirm_window = Window_Command.new(SFC_Window_Width,[text1,text2])
  153. @confirm_window.x = ((544 - @confirm_window.width) / 2) + SFC_Window_X_Offset
  154. @confirm_window.y = ((416 - @confirm_window.height) / 2) + SFC_Window_Y_Offset
  155. else
  156. determine_savefile
  157. end
  158. elsif Input.trigger?(Input::B)
  159. Sound.play_cancel
  160. return_scene
  161. end
  162. end
  163.  
  164. #--------------------------------------------------------------------------
  165. # * Execute Save
  166. #--------------------------------------------------------------------------
  167. def do_save
  168. if SCREENSHOT_IMAGE
  169. File.rename(SAVE_PATH + 'temp' + IMAGE_FILETYPE,
  170. make_filename(@last_slot_index).gsub(/\..*$/){ '_ss' } + IMAGE_FILETYPE)
  171. end
  172.  
  173. file = File.open(make_filename(@last_slot_index), "wb")
  174. write_save_data(file)
  175. file.close
  176.  
  177. # Alter the scene after the saving is done
  178. if SCENE_CHANGE
  179. $scene = Scene_Map.new
  180. else
  181. $scene = Scene_File.new(true, false, false)
  182. end
  183. end
  184.  
  185. #--------------------------------------------------------------------------
  186. # * Execute Load
  187. #--------------------------------------------------------------------------
  188. def do_load
  189. file = File.open(make_filename(@last_slot_index), "rb")
  190. read_save_data(file)
  191. file.close
  192. $scene = Scene_Map.new
  193. RPG::BGM.fade(1500)
  194. Graphics.fadeout(60)
  195. Graphics.wait(40)
  196. @last_bgm.play
  197. @last_bgs.play
  198. end
  199.  
  200. #--------------------------------------------------------------------------
  201. # * Confirm Save File
  202. #--------------------------------------------------------------------------
  203. def determine_savefile
  204. if @saving
  205. Sound.play_save
  206. do_save
  207. else
  208. if @window_slotdetail.file_exist?(@last_slot_index + 1)
  209. Sound.play_load
  210. do_load
  211. else
  212. Sound.play_buzzer
  213. return
  214. end
  215. end
  216.  
  217. $game_temp.last_file_index = @last_slot_index
  218. end
  219.  
  220. #--------------------------------------------------------------------------
  221. # * Create Filename
  222. # file_index : save file index (0-3)
  223. #--------------------------------------------------------------------------
  224. def make_filename(file_index)
  225. return SAVE_PATH + SAVE_FILE_NAME.gsub(/\{ID\}/i) { (file_index + 1).to_s }
  226. end
  227.  
  228. #--------------------------------------------------------------------------
  229. # * Select File With Newest Timestamp
  230. #--------------------------------------------------------------------------
  231. def latest_file_index
  232. latest_index = 0
  233. latest_time = Time.at(0)
  234.  
  235. (1..MAX_SAVE_SLOT).each do |i|
  236. file_name = make_filename(i - 1)
  237. next if !@window_slotdetail.file_exist?(i)
  238. file_time = File.mtime(file_name)
  239.  
  240. if file_time > latest_time
  241. latest_time = file_time
  242. latest_index = i - 1
  243. end
  244. end
  245.  
  246. return latest_index
  247. end
  248.  
  249. class Window_SlotList < Window_Command
  250. #--------------------------------------------------------------------------
  251. # * Draw Item
  252. #--------------------------------------------------------------------------
  253. def draw_item(index, enabled = true)
  254. rect = item_rect(index)
  255. rect.x += 4
  256. rect.width -= 8
  257. icon_index = 0
  258. self.contents.clear_rect(rect)
  259.  
  260. if $scene.window_slotdetail.file_exist?(index + 1)
  261. icon_index = Wora_NSS::SAVED_SLOT_ICON
  262. else
  263. icon_index = Wora_NSS::EMPTY_SLOT_ICON
  264. end
  265.  
  266. if !icon_index.nil?
  267. rect.x -= 4
  268. draw_icon(icon_index, rect.x, rect.y, enabled) # Draw Icon
  269. rect.x += 26
  270. rect.width -= 20
  271. end
  272.  
  273. self.contents.clear_rect(rect)
  274. self.contents.font.color = normal_color
  275. self.contents.font.color.alpha = enabled ? 255 : 128
  276. self.contents.draw_text(rect, @commands[index])
  277. end
  278.  
  279. def cursor_down(wrap = false)
  280. if @index < @item_max - 1 or wrap
  281. @index = (@index + 1) % @item_max
  282. end
  283. end
  284.  
  285. def cursor_up(wrap = false)
  286. if @index > 0 or wrap
  287. @index = (@index - 1 + @item_max) % @item_max
  288. end
  289. end
  290. end
  291.  
  292. #-----------------------------------------------------
  293.  
  294. class Window_NSS_SlotDetail < Window_Base
  295. include Wora_NSS
  296.  
  297. def initialize
  298. super(160, 56, 480, 424)
  299. #160 = X1, 56 = Y1, 480 = X2, 424 = Y2 (Bottom Right)
  300.  
  301. @data = []
  302. @exist_list = []
  303. @bitmap_list = {}
  304. @map_name = []
  305. end
  306.  
  307. def dispose
  308. dispose_tilemap
  309. super
  310. end
  311.  
  312. def draw_data(slot_id)
  313. contents.clear # 352, 328
  314. dispose_tilemap
  315.  
  316. load_save_data(slot_id) if @data[slot_id].nil?
  317. if @exist_list[slot_id]
  318. save_data = @data[slot_id]
  319. contents.fill_rect(0,30,352,152, MAP_BORDER)
  320.  
  321. if PREMADE_IMAGE
  322. bitmap = get_bitmap("Graphics/Save/" + @data[slot_id]['map_name'] + IMAGE_FILETYPE)
  323. rect = Rect.new((Graphics.width-348)/2,(Graphics.height-156)/2,348,156)
  324. contents.blt(2,32,bitmap,rect)
  325. elsif SCREENSHOT_IMAGE and save_data['ss']
  326. bitmap = get_bitmap(save_data['ss_path'])
  327. rect = Rect.new((Graphics.width-348)/2,(Graphics.height-156)/2,348,156)
  328. contents.blt(2,32,bitmap,rect)
  329. elsif SWAP_TILE and $game_switches[SWAP_TILE_SWITCH]
  330. create_swaptilemap(save_data['gamemap'].data, save_data['gamemap'].display_x,
  331. save_data['gamemap'].display_y)
  332. else
  333. create_tilemap(save_data['gamemap'].data, save_data['gamemap'].display_x,
  334. save_data['gamemap'].display_y)
  335. end
  336.  
  337. if DRAW_GOLD
  338. gold_textsize = contents.text_size(save_data['gamepar'].gold).width
  339. goldt_textsize = contents.text_size(GOLD_TEXT).width
  340. contents.font.color = system_color
  341. contents.draw_text(0, 0, goldt_textsize, WLH, GOLD_TEXT)
  342. contents.font.color = normal_color
  343. contents.draw_text(goldt_textsize, 0, gold_textsize, WLH, save_data['gamepar'].gold)
  344.  
  345. if DRAW_TEXT_GOLD
  346. contents.draw_text(goldt_textsize + gold_textsize, 0, 200, WLH, Vocab::gold)
  347.  
  348. else
  349. gold_textsize = 0
  350. goldt_textsize = 0
  351. end
  352. end
  353.  
  354. if DRAW_PLAYTIME
  355. hour = save_data['total_sec'] / 60 / 60
  356. min = save_data['total_sec'] / 60 % 60
  357. sec = save_data['total_sec'] % 60
  358. time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  359. pt_textsize = contents.text_size(PLAYTIME_TEXT).width
  360. ts_textsize = contents.text_size(time_string).width
  361. contents.font.color = system_color
  362. contents.draw_text(contents.width - ts_textsize - pt_textsize, 0,
  363. pt_textsize, WLH, PLAYTIME_TEXT)
  364. contents.draw_text(goldt_textsize + gold_textsize,0,200,WLH, Vocab::gold)
  365. contents.font.color = normal_color
  366. contents.draw_text(0, 0, contents.width, WLH, time_string, 2)
  367. end
  368.  
  369. if DRAW_LOCATION
  370. lc_textsize = contents.text_size(LOCATION_TEXT).width
  371. mn_textsize = contents.text_size(save_data['map_name']).width
  372. contents.font.color = system_color
  373. contents.draw_text(0, 190, contents.width, WLH, LOCATION_TEXT)
  374. contents.font.color = normal_color
  375. contents.draw_text(lc_textsize, 190, contents.width, WLH, save_data['map_name'])
  376. end
  377.  
  378. # Draw level & name
  379. save_data['gamepar'].members.each_index do |i|
  380. actor = save_data['gameactor'][save_data['gamepar'].members[i].id]
  381. face_x_base = (i*80) + (i*8)
  382. face_y_base = 216
  383. lvn_y_plus = 10
  384. lv_textsize = contents.text_size(actor.level).width
  385. lvt_textsize = contents.text_size(LV_TEXT).width
  386.  
  387. if DRAW_FACE
  388. contents.fill_rect(face_x_base, face_y_base, 84, 84, FACE_BORDER)
  389. draw_face(actor.face_name, actor.face_index, face_x_base + 2,
  390. face_y_base + 2, 80)
  391. end
  392.  
  393. if DRAW_LEVEL
  394. contents.font.color = system_color
  395. contents.draw_text(face_x_base + 2 + 80 - lv_textsize - lvt_textsize,
  396. face_y_base + 2 + 80 - WLH + lvn_y_plus, lvt_textsize, WLH, LV_TEXT)
  397. contents.font.color = normal_color
  398. contents.draw_text(face_x_base + 2 + 80 - lv_textsize,
  399. face_y_base + 2 + 80 - WLH + lvn_y_plus, lv_textsize, WLH, actor.level)
  400. end
  401.  
  402. if DRAW_NAME
  403. contents.draw_text(face_x_base, face_y_base + 2 + 80 + lvn_y_plus - 6, 84,
  404. WLH, actor.name, 1)
  405. end
  406. end
  407. else
  408. contents.draw_text(0,0, contents.width, contents.height - WLH, EMPTY_SLOT_TEXT, 1)
  409. end
  410. end
  411.  
  412. def load_save_data(slot_id)
  413. file_name = make_filename(slot_id)
  414.  
  415. if file_exist?(slot_id) or FileTest.exist?(file_name)
  416. @exist_list[slot_id] = true
  417. @data[slot_id] = {}
  418.  
  419. # Start load data
  420. file = File.open(file_name, "r")
  421. @data[slot_id]['time'] = file.mtime
  422. @data[slot_id]['char'] = Marshal.load(file)
  423. @data[slot_id]['frame'] = Marshal.load(file)
  424. @data[slot_id]['last_bgm'] = Marshal.load(file)
  425. @data[slot_id]['last_bgs'] = Marshal.load(file)
  426. @data[slot_id]['gamesys'] = Marshal.load(file)
  427. @data[slot_id]['gamemes'] = Marshal.load(file)
  428. @data[slot_id]['gameswi'] = Marshal.load(file)
  429. @data[slot_id]['gamevar'] = Marshal.load(file)
  430. @data[slot_id]['gameselfvar'] = Marshal.load(file)
  431. @data[slot_id]['gameactor'] = Marshal.load(file)
  432. @data[slot_id]['gamepar'] = Marshal.load(file)
  433. @data[slot_id]['gametro'] = Marshal.load(file)
  434. @data[slot_id]['gamemap'] = Marshal.load(file)
  435. @data[slot_id]['total_sec'] = @data[slot_id]['frame'] / Graphics.frame_rate
  436.  
  437. # Save the image
  438. if SCREENSHOT_IMAGE
  439. @data[slot_id]['ss_path'] = file_name.gsub(/\..*$/){'_ss'} + IMAGE_FILETYPE
  440. @data[slot_id]['ss'] = FileTest.exist?(@data[slot_id]['ss_path'])
  441. end
  442.  
  443. @data[slot_id]['map_name'] = get_mapname(@data[slot_id]['gamemap'].map_id)
  444. file.close
  445. else
  446. @exist_list[slot_id] = false
  447. @data[slot_id] = -1
  448. end
  449. end
  450.  
  451. def make_filename(file_index)
  452. return SAVE_PATH + SAVE_FILE_NAME.gsub(/\{ID\}/i) { (file_index).to_s }
  453. end
  454.  
  455. def file_exist?(slot_id)
  456. return @exist_list[slot_id] if !@exist_list[slot_id].nil?
  457.  
  458. @exist_list[slot_id] = FileTest.exist?(make_filename(slot_id))
  459.  
  460. return @exist_list[slot_id]
  461. end
  462.  
  463. def get_bitmap(path)
  464. if !@bitmap_list.include?(path)
  465. @bitmap_list[path] = Bitmap.new(path)
  466. end
  467.  
  468. return @bitmap_list[path]
  469. end
  470.  
  471. def get_mapname(map_id)
  472. if @map_data.nil?
  473. @map_data = load_data("Data/MapInfos.rvdata")
  474. end
  475.  
  476. if @map_name[map_id].nil?
  477. if MAP_NO_NAME_LIST.include?(map_id) and $game_switches[MAP_NO_NAME_SWITCH]
  478. if $game_variables[map_id] == 0 or !MAP_NO_NAME_VARIABLE
  479. @map_name[map_id] = MAP_NO_NAME
  480. else
  481. @map_name[map_id] = @map_data[map_id].name
  482. end
  483. else
  484. @map_name[map_id] = @map_data[map_id].name
  485. end
  486.  
  487. MAP_NAME_TEXT_SUB.each_index do |i|
  488. @map_name[map_id].sub!(MAP_NAME_TEXT_SUB[i], '')
  489. @mapname = @map_name[map_id]
  490. end
  491. end
  492.  
  493. return @map_name[map_id]
  494. end
  495.  
  496. def create_tilemap(map_data, ox, oy)
  497. @viewport = Viewport.new(self.x + 2 + 16, self.y + 32 + 16, 348,156)
  498. @viewport.z = self.z
  499. @tilemap = Tilemap.new(@viewport)
  500. @tilemap.bitmaps[0] = Cache.system("TileA1")
  501. @tilemap.bitmaps[1] = Cache.system("TileA2")
  502. @tilemap.bitmaps[2] = Cache.system("TileA3")
  503. @tilemap.bitmaps[3] = Cache.system("TileA4")
  504. @tilemap.bitmaps[4] = Cache.system("TileA5")
  505. @tilemap.bitmaps[5] = Cache.system("TileB")
  506. @tilemap.bitmaps[6] = Cache.system("TileC")
  507. @tilemap.bitmaps[7] = Cache.system("TileD")
  508. @tilemap.bitmaps[8] = Cache.system("TileE")
  509. @tilemap.map_data = map_data
  510. @tilemap.ox = ox / 8 + 99
  511. @tilemap.oy = oy / 8 + 90
  512. end
  513.  
  514. def create_swaptilemap(map_data, ox, oy)
  515. @viewport = Viewport.new(self.x + 2 + 16, self.y + 32 + 16, 348,156)
  516. @viewport.z = self.z
  517. @tilemap = Tilemap.new(@viewport)
  518.  
  519. tile1 = Cache_Swap_Tiles.swap($tileA1 + ".png") rescue nil
  520. tile2 = Cache_Swap_Tiles.swap($tileA2 + ".png") rescue nil
  521. tile3 = Cache_Swap_Tiles.swap($tileA3 + ".png") rescue nil
  522. tile4 = Cache_Swap_Tiles.swap($tileA4 + ".png") rescue nil
  523. tile5 = Cache_Swap_Tiles.swap($tileA5 + ".png") rescue nil
  524. tile6 = Cache_Swap_Tiles.swap($tileB + ".png") rescue nil
  525. tile7 = Cache_Swap_Tiles.swap($tileC + ".png") rescue nil
  526. tile8 = Cache_Swap_Tiles.swap($tileD + ".png") rescue nil
  527. tile9 = Cache_Swap_Tiles.swap($tileE + ".png") rescue nil
  528.  
  529. if $tileA1 != nil
  530. @tilemap.bitmaps[0] = tile1
  531. else
  532. @tilemap.bitmaps[0] = Cache.system("TileA1")
  533. end
  534.  
  535. if $tileA2 != nil
  536. @tilemap.bitmaps[1] = tile2
  537. else
  538. @tilemap.bitmaps[1] = Cache.system("TileA2")
  539. end
  540.  
  541. if $tileA3 != nil
  542. @tilemap.bitmaps[2] = tile3
  543. else
  544. @tilemap.bitmaps[2] = Cache.system("TileA3")
  545. end
  546.  
  547. if $tileA4 != nil
  548. @tilemap.bitmaps[3] = tile4
  549. else
  550. @tilemap.bitmaps[3] = Cache.system("TileA4")
  551. end
  552.  
  553. if $tileA5 != nil
  554. @tilemap.bitmaps[4] = tile5
  555. else
  556. @tilemap.bitmaps[4] = Cache.system("TileA5")
  557. end
  558.  
  559. if $tileB != nil
  560. @tilemap.bitmaps[5] = tile6
  561. else
  562. @tilemap.bitmaps[5] = Cache.system("TileB")
  563. end
  564.  
  565. if $tileC != nil
  566. @tilemap.bitmaps[6] = tile7
  567. else
  568. @tilemap.bitmaps[6] = Cache.system("TileC")
  569. end
  570.  
  571. if $tileD != nil
  572. @tilemap.bitmaps[7] = tile8
  573. else
  574. @tilemap.bitmaps[7] = Cache.system("TileD")
  575. end
  576.  
  577. if $tileE != nil
  578. @tilemap.bitmaps[8] = tile9
  579. else
  580. @tilemap.bitmaps[8] = Cache.system("TileE")
  581. end
  582.  
  583. @tilemap.map_data = map_data
  584. @tilemap.ox = ox / 8 + 99
  585. @tilemap.oy = oy / 8 + 90
  586. end
  587.  
  588. def dispose_tilemap
  589. unless @tilemap.nil?
  590. @tilemap.dispose
  591. @tilemap = nil
  592. end
  593. end
  594. end
  595. end
  596.  
  597. class Scene_Title < Scene_Base
  598. def check_continue
  599. file_name = Wora_NSS::SAVE_PATH + Wora_NSS::SAVE_FILE_NAME.gsub(/\{ID\}/i) { '*' }
  600. @continue_enabled = (Dir.glob(file_name).size > 0)
  601. end
  602. end
  603.  
  604. class Scene_Map < Scene_Base
  605. alias wora_nss_scemap_ter terminate
  606.  
  607. def terminate
  608. Wora_NSS.shot(Wora_NSS::SAVE_PATH + 'temp')
  609. wora_nss_scemap_ter
  610. end
  611. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement