Poulet trizo Lv.3
Age : 32 Inscrit le : 18/11/2009 Messages : 42
| Sujet: Re: Script de sauvegarde ultime Mar 11 Mai 2010 - 17:17 | |
| Tout est là: - Spoiler:
- Code:
-
=begin ############################# Aza Razore's file menu Author: Azuma-01 Version: 1.0 Date: 11 / 05 / 2010 Last Update: -- / -- / ---- =end ############################## #----------------------------------------------------------- Instructions ------------------------------------------------------------ # Dimension des images: 200 x 284 pixel # Q et W pour déplacer la fenêtre des acteurs # Programmer le module à votre goût # #---------------------------------------------------------------------------------------------------------------------------------------- module Aza module Ra_File #=============================================# # ● BEGIN Customization ● # #=============================================# Save_Path = "" # Dossier où se trouve les sauvegardes ("" pour aucun dossier) Save_Name = "Save" # nom des fichiers de sauvegarde Max_Save = 4 # Nombre de fichier maximal
Map_Hide = [] # map où le nom est inconnue Map_Name_Hide = "????????" # Nom quand la map est inconnue Map_Picture = { # Les images doivent être dans le dossier Picture #--------------------- # map_id => "Nom de l'image", 1 => "", 2 => "", #--------------------- } # do not remove Backgroound_Picture = "" # Image de fond ("" pour aucune image) No_Picture_Color = Color.new(32, 32, 64, 255) # Color.new(rouge, vert, bleu, alpha) ## alpha = 0 pour désactiver Delete_Sound = "Explosion7" # Son lors de la suppression d'un fichier Window_Text = { # Tous les textes du menu :save => "Sauvegarder", :load => "Charger", :delete => "Supprimer", :location => "Localisation", :gold => "Or:", :playtime => "Temps de jeu:", :name => "Nom:", :exp => "Exp", :delete_text1 => "Êtes vous sûr de vouloir supprimer ce fichier?", :delete_text2 => "Les données ne pourront être récupérées.", :no => "Non", :yes => "Oui", } #============================================# # ● END Customization ● # #============================================# end end
$AzaScritps ||= {} $AzaScritps["Azuma-01_File_Menu_For_Razore"] = true #============================================================================== # ■ Game Actor #============================================================================== class Game_Actor #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :exp_list end
#============================================================================== # ■ Window Save File #============================================================================== class Window_Save_File < Window_Base #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :filename # filename attr_reader :file_exist # file existence flag attr_reader :time_stamp # timestamp attr_reader :selected # selected attr_reader :party # actor in party attr_reader :gold # party gold attr_reader :map_id # map id attr_reader :active attr_reader :index #-------------------------------------------------------------------------- # * Object Initialization # file_index : save file index (0-3) # filename : filename #-------------------------------------------------------------------------- def initialize(file_index, filename, saving) super(0, file_index * 104, 100, 104) self.z = 300 @file_index = file_index @filename = filename @saving = saving @index = 0 load_gamedata refresh @selected = false @@map_info ||= load_data("Data/MapInfos.rvdata") end #-------------------------------------------------------------------------- # * Load Partial Game Data # By default, switches and variables are not used #-------------------------------------------------------------------------- def load_gamedata @time_stamp = Time.at(0) @file_exist = FileTest.exist?(@filename) if @file_exist file = File.open(@filename, "rb") @time_stamp = file.mtime begin @party = Marshal.load(file) gold_map_id = Marshal.load(file) @frame_count = Marshal.load(file) @last_bgm = Marshal.load(file) @last_bgs = Marshal.load(file) @game_system = Marshal.load(file) @game_message = Marshal.load(file) @game_switches = Marshal.load(file) @game_variables = Marshal.load(file) @gold = gold_map_id[0] @map_id = gold_map_id[1] @total_sec = @frame_count / Graphics.frame_rate rescue @file_exist = false ensure file.close end end end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh self.contents.clear self.contents.font.color = normal_color name = Vocab::File + " #{@file_index + 1}" self.contents.draw_text(0, 0, 68, WLH, name) @name_width = contents.text_size(name).width if @active Aza::Ra_File::Window_Text[:save] action = @saving ? Aza::Ra_File::Window_Text[:save] : Aza::Ra_File::Window_Text[:load] self.contents.draw_text(0, 24, 68, WLH, action) self.contents.draw_text(0, 48, 68, WLH, Aza::Ra_File::Window_Text[:delete]) end end #-------------------------------------------------------------------------- # * Get Play Time #-------------------------------------------------------------------------- def playtime return if @total_sec == nil hour = @total_sec / 3600 min = @total_sec / 60 % 60 sec = @total_sec % 60 if hour > 999 hour = 999 min = 59 sec = 59 end return sprintf("%02dh %02dm %02ds", hour, min, sec) end #-------------------------------------------------------------------------- # * Get Map Name #-------------------------------------------------------------------------- def map_name return if @map_id == 0 or @map_id == nil return Aza::Ra_File::Map_Name_Hide if Aza::Ra_File::Map_Hide.include?(@map_id) return @@map_info[@map_id].name end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super return if !@active move_cursor if Input.trigger?(Input::DOWN) or Input.trigger?(Input::UP) end #-------------------------------------------------------------------------- # * Active Action #-------------------------------------------------------------------------- def active=(value) @active = value @index = 0 @index = 1 if value refresh update_cursor end #-------------------------------------------------------------------------- # * Move Cursor #-------------------------------------------------------------------------- def move_cursor @index = (@index % 2) + 1 Sound.play_cursor update_cursor end #-------------------------------------------------------------------------- # * Set Selected # selected : new selected (true = selected, false = unselected) #-------------------------------------------------------------------------- def selected=(selected) @selected = selected @index = 0 update_cursor end #-------------------------------------------------------------------------- # * Update cursor #-------------------------------------------------------------------------- def update_cursor if @selected self.cursor_rect.set(-4, @index * 24, 72 , WLH) else self.cursor_rect.empty end end end
#============================================================================== # ■ Window Save File #============================================================================== class Window_Save_Info < Window_Base #-------------------------------------------------------------------------- # * Object Initialization # map_name : Map name # gold : Total gold # playtime : Time played #-------------------------------------------------------------------------- def initialize(map_name, gold, playtime) super(112,0, 432, 100) refresh(map_name, gold, playtime) end #-------------------------------------------------------------------------- # * Refresh # map_name : Map name # gold : Total gold # playtime : Time played #-------------------------------------------------------------------------- def refresh(map_name, gold, playtime) self.contents.clear self.contents.font.color = normal_color self.contents.draw_text(0, 0, 400, WLH, Aza::Ra_File::Window_Text[:location], 1) self.contents.draw_text(0, 48, 400, WLH, Aza::Ra_File::Window_Text[:gold]) self.contents.draw_text(165, 48, 125, WLH, Aza::Ra_File::Window_Text[:playtime]) self.contents.font.color = normal_color self.contents.draw_text(0, 24, 400, WLH, map_name, 1) self.contents.draw_text(40, 48, 125, WLH, gold) self.contents.draw_text(0, 48, 400, WLH, playtime,2) end end #============================================================================== # ■ Window Save File #============================================================================== class Window_Save_Actor < Window_Base #-------------------------------------------------------------------------- # * Object Initialization # party : Party member # map_id : Map id #-------------------------------------------------------------------------- def initialize(party, map_id) super(112,100, 432, 316) refresh(party, map_id) end #-------------------------------------------------------------------------- # * Refresh # party : Party member # map_id : Map id #-------------------------------------------------------------------------- def refresh(party, map_id) self.contents.clear create_contents(party.size) rescue create_contents self.oy = 0 return if party.nil? self.contents.font.size = 16 party.each_with_index{|actor, i| y = 94 * i self.contents.font.color = normal_color self.contents.draw_text(0, y, 75, WLH, Aza::Ra_File::Window_Text[:name]) draw_actor_name(actor, 50, y) draw_actor_graphic(actor, 150, y + 37) draw_actor_hp(actor, 0, y + 20, 130) draw_actor_mp(actor, 0, y + 40, 130) draw_actor_exp(actor, 0, y + 60) self.contents.font.color = normal_color } end #-------------------------------------------------------------------------- # * Create Window Contents #-------------------------------------------------------------------------- def create_contents(size = 0) self.contents.dispose h = (size / 3.to_f) == (size/3) ? [size / 3, 1].max : ((size / 3) + 1) self.contents = Bitmap.new(width - 32, 282 * h) end #-------------------------------------------------------------------------- # * Draw EXP # actor : actor # x : draw spot x-coordinate # y : draw spot y-coordinate # width : Width #-------------------------------------------------------------------------- def draw_actor_exp(actor, x, y, width = 130) draw_actor_exp_gauge(actor, x, y, width) self.contents.font.color = system_color self.contents.draw_text(x, y, 40, WLH, Aza::Ra_File::Window_Text[:exp]) self.contents.font.color = hp_color(actor) last_font_size = self.contents.font.size xr = x + width self.contents.draw_text(xr - 54, y, 54, WLH, actor.exp, 2) end #-------------------------------------------------------------------------- # * Draw EXP gauge # actor : actor # x : draw spot x-coordinate # y : draw spot y-coordinate # width : Width #-------------------------------------------------------------------------- def draw_actor_exp_gauge(actor, x, y, width = 120) total = actor.exp_list[actor.level] == 0 ? actor.exp == 0 ? 1 : actor.exp : actor.exp_list[actor.level] gw = width * actor.exp / total gc1 = text_color(25) gc2 = text_color(18) self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color) self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2) end end
#============================================================================== # ■ Window Delete #============================================================================== class Window_Delete < Window_Selectable #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize super(0,0, 544, 104) self.x = (Graphics.width - width) / 2 self.y = (Graphics.height - height) / 2 self.contents.draw_text(0, 0, 512, WLH, Aza::Ra_File::Window_Text[:delete_text1], 1) self.contents.draw_text(0, 24, 512, WLH, Aza::Ra_File::Window_Text[:delete_text2], 1) self.contents.draw_text(166, 48, 75, WLH, Aza::Ra_File::Window_Text[:no]) self.contents.draw_text(271, 48, 75, WLH, Aza::Ra_File::Window_Text[:yes]) self.z = 500 @item_max = 2 self.index = 0 self.openness = 0 self.active = false end #-------------------------------------------------------------------------- # * Update cursor #-------------------------------------------------------------------------- def update_cursor if @index < 0 self.cursor_rect.empty else x = @index == 0 ? 166 : 271 self.cursor_rect.set(x - 23, 46, 81, 26) end end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super if cursor_movable? last_index = @index if Input.repeat?(Input::RIGHT) cursor_down(Input.trigger?(Input::RIGHT)) end if Input.repeat?(Input::LEFT) cursor_up(Input.trigger?(Input::LEFT)) end if @index != last_index Sound.play_cursor end end update_cursor call_update_help end end
#============================================================================== # ■ Create Save Directory #============================================================================== if Aza::Ra_File::Save_Path.to_s != "" and !FileTest.directory?(Aza::Ra_File::Save_Path) Dir.mkdir(Aza::Ra_File::Save_Path) exit end
#============================================================================== # ■ Scene File #============================================================================== class Scene_File < Scene_Base #-------------------------------------------------------------------------- # * Object Initialization # saving : save flag (if false, load screen) # from_title : flag: it was called from "Continue" on the title screen # from_event : flag: it was called from the "Call Save Screen" event # menu_index : Menu index for return #-------------------------------------------------------------------------- def initialize(saving, from_title, from_event, menu_index = 4) @saving = saving @from_title = from_title @from_event = from_event @menu_index = menu_index end #-------------------------------------------------------------------------- # * Start processing #-------------------------------------------------------------------------- def start super create_menu_background create_savefile_windows if @saving @index = $game_temp.last_file_index else @index = self.latest_file_index end @delete_window = Window_Delete.new window = @savefile_windows[@index] @info_window = Window_Save_Info.new(window.map_name, window.gold, window.playtime) @actor_window = Window_Save_Actor.new(window.party, window.map_id) window.selected = true window.x = 25 make_picture show_window(@index) end #-------------------------------------------------------------------------- # * Termination Processing #-------------------------------------------------------------------------- def terminate super dispose_menu_background @actor_window.dispose @info_window.dispose @delete_window.dispose @picture.bitmap.dispose @picture.dispose dispose_item_windows end #-------------------------------------------------------------------------- # * Return to Original Screen #-------------------------------------------------------------------------- def return_scene if @from_title $scene = Scene_Title.new elsif @from_event $scene = Scene_Map.new else $scene = Scene_Menu.new(@menu_index) end end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super update_menu_background @info_window.update @actor_window.update @delete_window.update @picture.update update_savefile_windows if Input.repeat?(Input::L) @actor_window.oy = [@actor_window.oy -= 282, 0].max elsif Input.repeat?(Input::R) @actor_window.oy = [@actor_window.oy += 282, @actor_window.contents.height - 282].min end if @savefile_windows[@index].active update_window_selection else update_savefile_selection end end #-------------------------------------------------------------------------- # * Create Menu Background #-------------------------------------------------------------------------- def create_menu_background if Aza::Ra_File::Backgroound_Picture.to_s != "" @menuback_sprite = Sprite.new @menuback_sprite.bitmap = Cache.picture(Aza::Ra_File::Backgroound_Picture.to_s) else super end end #-------------------------------------------------------------------------- # * Make_Picture #-------------------------------------------------------------------------- def make_picture map_id = @savefile_windows[@index].map_id picture = Aza::Ra_File::Map_Picture[map_id] if picture.to_s != "" bitmap = Cache.picture(picture) else bitmap = Bitmap.new(200,284) bitmap.fill_rect(0, 0, 200, 284, Aza::Ra_File::No_Picture_Color) end @picture = Sprite.new @picture.bitmap = bitmap @picture.x = 328 @picture.y = 116 @picture.z = 400 end #-------------------------------------------------------------------------- # * Refresh The Picture #-------------------------------------------------------------------------- def refresh_picture map_id = @savefile_windows[@index].map_id picture = Aza::Ra_File::Map_Picture[map_id] if picture.to_s != "" bitmap = Cache.picture(picture) else bitmap = Bitmap.new(200,284) bitmap.fill_rect(0, 0, 200, 284, Aza::Ra_File::No_Picture_Color) end @picture.bitmap = bitmap end #-------------------------------------------------------------------------- # * Create Save File Window #-------------------------------------------------------------------------- def create_savefile_windows @savefile_windows = [] for i in 0...Aza::Ra_File::Max_Save @savefile_windows.push(Window_Save_File.new(i, make_filename(i), @saving)) end @savefile_windows.each{|window| if window.y > 415 or window.y < 0 window.visible = false end } @item_max = @savefile_windows.size end #-------------------------------------------------------------------------- # * Dispose of Save File Window #-------------------------------------------------------------------------- def dispose_item_windows for window in @savefile_windows window.dispose end end #-------------------------------------------------------------------------- # * Update Save File Window #-------------------------------------------------------------------------- def update_savefile_windows for window in @savefile_windows window.update end end #-------------------------------------------------------------------------- # * Update Save File Selection #-------------------------------------------------------------------------- def update_savefile_selection if Input.trigger?(Input::C) Sound.play_decision @savefile_windows[@index].active = true elsif Input.trigger?(Input::B) Sound.play_cancel return_scene else last_index = @index if Input.repeat?(Input::DOWN) cursor_down(Input.trigger?(Input::DOWN)) elsif Input.repeat?(Input::UP) cursor_up(Input.trigger?(Input::UP)) end if @index != last_index Sound.play_cursor @savefile_windows[last_index].selected = false @savefile_windows[@index].selected = true window = @savefile_windows[@index] @info_window.refresh(window.map_name, window.gold, window.playtime) @actor_window.refresh(window.party, window.map_id) refresh_picture while window.x < 25 window.x += 5 @savefile_windows[last_index].x -= 5 Graphics.update end end end end #-------------------------------------------------------------------------- # * Update Window Selection #-------------------------------------------------------------------------- def update_window_selection if Input.trigger?(Input::C) case @savefile_windows[@index].index when 1; determine_savefile when 2; delete_save? end elsif Input.trigger?(Input::B) Sound.play_cancel @savefile_windows[@index].active = false end end #-------------------------------------------------------------------------- # * Confirm Save File #-------------------------------------------------------------------------- def determine_savefile if @saving Sound.play_save do_save else if @savefile_windows[@index].file_exist Sound.play_load do_load else Sound.play_buzzer return end end $game_temp.last_file_index = @index end #-------------------------------------------------------------------------- # * Confirm Delete Option #-------------------------------------------------------------------------- def delete_save? if @savefile_windows[@index].file_exist Sound.play_decision @delete_window.active = true @delete_window.index = 0 @delete_window.open while @delete_window.active Graphics.update Input.update @delete_window.update if Input.trigger?(Input::C) case @delete_window.index when 0 Sound.play_decision @delete_window.active = false when 1 delete_file end elsif Input.trigger?(Input::B) Sound.play_cancel @delete_window.active = false end end @delete_window.close else Sound.play_buzzer end end #-------------------------------------------------------------------------- # * Delete The File #-------------------------------------------------------------------------- def delete_file RPG::SE.new(Aza::Ra_File::Delete_Sound.to_s).play i = @index File.delete(make_filename(i)) @savefile_windows[i].dispose @savefile_windows[i] = Window_Save_File.new(i, make_filename(i), @saving) window = @savefile_windows[i] if i > 0 window.y = @savefile_windows[i - 1].y + 104 else window.y = @savefile_windows[i + 1].y - 104 end window.visible = true window.selected = true window.x = 25 @info_window.refresh(window.map_name, window.gold, window.playtime) @actor_window.refresh(window.party, window.map_id) refresh_picture @delete_window.active = false end #-------------------------------------------------------------------------- # * Move cursor down # wrap : Wraparound allowed #-------------------------------------------------------------------------- def cursor_down(wrap) if @index < @item_max - 1 or wrap @index = (@index + 1) % @item_max end return if @savefile_windows[@index].visible show_window(@index) end #-------------------------------------------------------------------------- # * Move cursor up # wrap : Wraparound allowed #-------------------------------------------------------------------------- def cursor_up(wrap) if @index > 0 or wrap @index = (@index - 1 + @item_max) % @item_max end return if @savefile_windows[@index].visible show_window(@index) end #-------------------------------------------------------------------------- # * Move Windows Untill Actor's Window Is Visible # index : actor index #-------------------------------------------------------------------------- def show_window(index) loop do y = @savefile_windows[index].y if y < 0 @savefile_windows.each{|window| window.y += 104 if window.y < 0 or window.y > 415 window.visible = false else; window.visible = true end } elsif y > 415 @savefile_windows.each{|window| window.y -= 104 if window.y < 0 or window.y > 415 window.visible = false else; window.visible = true end } end break if @savefile_windows[index].visible end end #-------------------------------------------------------------------------- # * Create Filename # file_index : save file index (0-3) #-------------------------------------------------------------------------- def make_filename(file_index) path = Aza::Ra_File::Save_Path path = path == "" ? "" : path + "/" name = Aza::Ra_File::Save_Name return path + name + "#{file_index + 1}.rvdata" end #-------------------------------------------------------------------------- # * Execute Save #-------------------------------------------------------------------------- def do_save file = File.open(@savefile_windows[@index].filename, "wb") write_save_data(file) file.close return_scene end #-------------------------------------------------------------------------- # * Execute Load #-------------------------------------------------------------------------- def do_load file = File.open(@savefile_windows[@index].filename, "rb") read_save_data(file) file.close $scene = Scene_Map.new RPG::BGM.fade(1500) Graphics.fadeout(60) Graphics.wait(40) @last_bgm.play @last_bgs.play end #-------------------------------------------------------------------------- # * Write Save Data # file : write file object (opened) #-------------------------------------------------------------------------- def write_save_data(file) $game_system.save_count += 1 $game_system.version_id = $data_system.version_id @last_bgm = RPG::BGM::last @last_bgs = RPG::BGS::last Marshal.dump($game_party.members, file) Marshal.dump([$game_party.gold, $game_map.map_id], file) Marshal.dump(Graphics.frame_count, file) Marshal.dump(@last_bgm, file) Marshal.dump(@last_bgs, file) Marshal.dump($game_system, file) Marshal.dump($game_message, file) Marshal.dump($game_switches, file) Marshal.dump($game_variables, file) Marshal.dump($game_self_switches, file) Marshal.dump($game_actors, file) Marshal.dump($game_party, file) Marshal.dump($game_troop, file) Marshal.dump($game_map, file) Marshal.dump($game_player, file) end #-------------------------------------------------------------------------- # * Read Save Data # file : file object for reading (opened) #-------------------------------------------------------------------------- def read_save_data(file) player = Marshal.load(file) gold_map_id = Marshal.load(file) Graphics.frame_count = Marshal.load(file) @last_bgm = Marshal.load(file) @last_bgs = Marshal.load(file) $game_system = Marshal.load(file) $game_message = Marshal.load(file) $game_switches = Marshal.load(file) $game_variables = Marshal.load(file) $game_self_switches = Marshal.load(file) $game_actors = Marshal.load(file) $game_party = Marshal.load(file) $game_troop = Marshal.load(file) $game_map = Marshal.load(file) $game_player = Marshal.load(file) if $game_system.version_id != $data_system.version_id $game_map.setup($game_map.map_id) $game_player.center($game_player.x, $game_player.y) end end end
#============================================================================== # ■ Scene Title #============================================================================== class Scene_Title #-------------------------------------------------------------------------- # * Determine if Continue is Enabled (Overwrite) #-------------------------------------------------------------------------- def check_continue path = Aza::Ra_File::Save_Path path = path == "" ? "" : path + "/" name = Aza::Ra_File::Save_Name @continue_enabled = (Dir.glob(path + name + "*.rvdata").size > 0) end end
Suis le bloque instruction. Ps: Les anciennes sauvegarde ne sont pas compatible. |
|