#============================================================================== # ** Scene_Menu #------------------------------------------------------------------------------ # This class performs the menu screen processing. #============================================================================== module MENU_CONFIG Item_List = "Backpack" Skill_Screen = "Magic" Equip_Screen = "Equipment" Player_Status = "Overview" Monstiary = "Monstiary" Tele_Cube = "TeleCube" Options = "Options" Sub_Menu = "Save/Load" Save_Game = "Save" Load_Game = "Load" #End_Game = "End Game" end class Scene_Menu < Scene_Base #-------------------------------------------------------------------------- # * Object Initialization # menu_index : command cursor's initial position #-------------------------------------------------------------------------- def initialize(menu_index = 0) @menu_index = menu_index end #-------------------------------------------------------------------------- # * Start processing #-------------------------------------------------------------------------- def start super create_menu_background create_command_window @command_window.x = 384 @command_window.y = 0 @status_window = Window_MenuStatus.new(0, 0) @gold_window = Window_Gold.new(222, 0) @location_window = Window_location.new(222, 360) @time_window = Window_Time.new(222, 304) end #-------------------------------------------------------------------------- # * Termination Processing #-------------------------------------------------------------------------- def terminate super dispose_menu_background @command_window.dispose @gold_window.dispose @status_window.dispose @location_window.dispose @time_window.dispose end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super update_menu_background @command_window.update @gold_window.update @location_window.update @time_window.update @status_window.update if @command_window.active update_command_selection elsif @status_window.active update_actor_selection end end #-------------------------------------------------------------------------- # * Create Command Window #-------------------------------------------------------------------------- def create_command_window s1 = MENU_CONFIG::Item_List s2 = MENU_CONFIG::Skill_Screen s3 = MENU_CONFIG::Equip_Screen s4 = MENU_CONFIG::Player_Status s5 = MENU_CONFIG::Monstiary s6 = MENU_CONFIG::Tele_Cube s7 = MENU_CONFIG::Options s8 = MENU_CONFIG::Sub_Menu @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6, s7, s8]) @command_window.index = @menu_index if $game_party.members.size == 0 # If number of party members is 0 @command_window.draw_item(0, false) # Disable item @command_window.draw_item(1, false) # Disable skill @command_window.draw_item(2, false) # Disable equipment @command_window.draw_item(3, false) # Disable status end if $game_system.save_disabled # If save is forbidden @command_window.draw_item(4, false) # Disable save end end #-------------------------------------------------------------------------- # * Update Command Selection #-------------------------------------------------------------------------- def update_command_selection if Input.trigger?(Input::B) && $game_switches [3] == true Sound.play_cancel $scene = Scene_Map.new elsif Input.trigger?(Input::C) if $game_party.members.size == 0 and @command_window.index < 4 Sound.play_buzzer return elsif $game_system.save_disabled and @command_window.index == 4 Sound.play_buzzer return end Sound.play_decision case @command_window.index when 0 # Item $scene = Scene_Item.new when 1,2,3 # Skill, equipment, status start_actor_selection when 4 # Monstiary print 'This option is not for this game. ~Resource Dragon' when 5 # TeleCube print 'This option is not for this game. ~Resource Dragon' when 6 # Options print 'This option is not for this game. ~Resource Dragon' when 7 # Sub Menu $scene = Scene_Sub_Menu.new end end end #-------------------------------------------------------------------------- # * Start Actor Selection #-------------------------------------------------------------------------- def start_actor_selection @command_window.active = false @status_window.active = true if $game_party.last_actor_index < @status_window.item_max @status_window.index = $game_party.last_actor_index else @status_window.index = 0 end end #-------------------------------------------------------------------------- # * End Actor Selection #-------------------------------------------------------------------------- def end_actor_selection @command_window.active = true @status_window.active = false @status_window.index = -1 end #-------------------------------------------------------------------------- # * Update Actor Selection #-------------------------------------------------------------------------- def update_actor_selection if Input.trigger?(Input::B) Sound.play_cancel end_actor_selection elsif Input.trigger?(Input::C) $game_party.last_actor_index = @status_window.index Sound.play_decision case @command_window.index when 1 # skill $scene = Scene_Skill.new(@status_window.index) when 2 # equipment $scene = Scene_Equip.new(@status_window.index) when 3 # status $scene = Scene_Status.new(@status_window.index) end end end end #============================================================================== # ** Scene_File #------------------------------------------------------------------------------ # Edited to return to the menu properly when loading #============================================================================== class Scene_File alias return_scene_original return_scene def return_scene if @from_title $scene = Scene_Title.new elsif @from_event $scene = Scene_Map.new else if @saving $scene = Scene_Menu.new(5) else $scene = Scene_Menu.new(6) end end end end #===================================================# #| | B E G I N W I N D O W S | |# #===================================================# #============================================================================== # ** Window_Location #------------------------------------------------------------------------------ # This class shows the current map name. #============================================================================== class Window_location < Window_Base #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(x, y) super(x, y, 322, WLH + 32) self.contents = Bitmap.new(width - 32, height - 32) refresh end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh self.contents.clear $maps = load_data("Data/MapInfos.rvdata") @map_id = $game_map.map_id @currmap = $maps[@map_id].name self.contents.font.color = system_color self.contents.font.color = normal_color # self.contents.draw_text(0, -4+WLH, 128, 32, @currmap, 1) self.contents.draw_text(0, -4, 228, 32, @currmap, 1) end end #============================================================================== # ** Window_Gold #------------------------------------------------------------------------------ # This window displays the amount of gold. #============================================================================== class Window_Gold < Window_Base #-------------------------------------------------------------------------- # * Object Initialization # x : window X coordinate # y : window Y coordinate #-------------------------------------------------------------------------- def initialize(x, y) super(x, y, 162, WLH + 32) refresh end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh self.contents.clear draw_currency_value($game_party.gold, 4, 0, 120) end end #============================================================================== # ** Window_Time #------------------------------------------------------------------------------ # This window displays playtime on the menu screen. #============================================================================== class Window_Time < Window_Base #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(x, y) super(x, y, 322, WLH + 32) refresh end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh self.contents.clear @time = Graphics.frame_count / Graphics.frame_rate hour = @time / 60 / 60 min = @time / 60 % 60 sec = @time % 60 text = sprintf("Time Played: %02d:%02d:%02d", hour, min, sec) self.contents.font.color = normal_color self.contents.draw_text(0, 0, 240, self.height / 2, text, 1) end end #===================================================# #| | B E G I N S T A T U S M E N U | |# #===================================================# #============================================================================== # ** Window_MenuStatus #------------------------------------------------------------------------------ # This window displays party member status on the menu screen. #============================================================================== class Window_MenuStatus < Window_Selectable #-------------------------------------------------------------------------- # * Object Initialization # x : window X coordinate # y : window Y coordinate #-------------------------------------------------------------------------- def initialize(x, y) super(x, y, 222, 416) refresh self.active = false self.index = -1 end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh self.contents.clear @item_max = $game_party.members.size for actor in $game_party.members x = 92 y = actor.index * 130 + WLH / 2 draw_actor_graphic(actor, 156, y + 42) draw_actor_name(actor, x - 80, y - 16) draw_actor_class(actor, x -80, y + 60) draw_actor_level(actor, x + 16, y - 16) draw_actor_state(actor, x, y) draw_actor_hp(actor, x - 80, y) draw_actor_mp(actor, x - 80, y + 20) draw_actor_exp(actor, x - 80, y + 40) end end #-------------------------------------------------------------------------- # * Update cursor #-------------------------------------------------------------------------- def update_cursor if @index < 0 # No cursor self.cursor_rect.empty elsif @index < @item_max # Normal self.cursor_rect.set(0, @index * 128, contents.width, 128) elsif @index >= 100 # Self self.cursor_rect.set(0, (@index - 100) * 128, contents.width, 128) else # All self.cursor_rect.set(0, 0, contents.width, @item_max * 128) end end end class Scene_Sub_Menu < Scene_Base #----------------------------------------------------------------------------- # * Start Processing #----------------------------------------------------------------------------- def start super create_menu_background create_command_window end #----------------------------------------------------------------------------- # * Termination Processing #----------------------------------------------------------------------------- def terminate super @command_window.dispose dispose_menu_background end #----------------------------------------------------------------------------- # * Frame Update #----------------------------------------------------------------------------- def update super update_menu_background @command_window.update if Input.trigger?(Input::B) Sound.play_cancel $scene = Scene_Menu.new(7) elsif Input.trigger?(Input::C) case @command_window.index when 0 # Save Game $scene = Scene_File.new(true, false, false) when 1 # Load Game $scene = Scene_File.new(false, false, false) end end end def create_command_window s1 = "Save Game" s2 = "Load Game" @command_window = Window_Command.new(160, [s1, s2]) @command_window.x = (Graphics.width/2) - (@command_window.width/2) @command_window.y = (Graphics.height/2) - (@command_window.height/2) end end #===================================================# #| | B E G I N E X P C O D E | |# #===================================================# WLH = 32 #-------------------------------------------------------------------------- # * Draw HP gauge # vertical : draw bar vertically #-------------------------------------------------------------------------- def draw_actor_hp_gauge(actor, x, y, width = 120, vertical = false) $rate = actor.hp.to_f / actor.maxhp gw = width * actor.hp / actor.maxhp w = vertical ? 6 : width; h = vertical ? width : 6 self.contents.cogwheel_fill_rect(x, y + WLH - 8, gw, w, h, BAR::hpcolor1, BAR::hpcolor2, vertical) end #-------------------------------------------------------------------------- # * Draw Exp # actor : actor # x : draw spot x-coordinate # y : draw spot y-coordinate # width : Width # hide_bar : draw Parameters without gauge #-------------------------------------------------------------------------- def draw_actor_exp(actor, x, y, width = 120, hide_bar = false) self.contents.font.color = system_color self.contents.draw_text(x, y, 45, WLH, "Next Level") self.contents.font.color = normal_color xr = x + width if width < 170 self.contents.draw_text(xr - 60, y, 60, WLH, actor.next_rest_exp_s, 2) else self.contents.draw_text(xr - 131, y, 60, WLH, actor.exp_s, 2) self.contents.draw_text(xr - 71, y, 11, WLH, "/", 2) self.contents.draw_text(xr - 60, y, 60, WLH, actor.next_exp_s, 2) end end #============================================================================== # ** Scene_File #------------------------------------------------------------------------------ # This class performs the save and load screen processing. #============================================================================== 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 #-------------------------------------------------------------------------- def initialize(saving, from_title, from_event) @saving = saving @from_title = from_title @from_event = from_event end #-------------------------------------------------------------------------- # * Start processing #-------------------------------------------------------------------------- def start super create_menu_background @help_window = Window_Help.new create_savefile_windows if @saving @index = $game_temp.last_file_index @help_window.set_text(Vocab::SaveMessage) else @index = self.latest_file_index @help_window.set_text(Vocab::LoadMessage) end @savefile_windows[@index].selected = true end #-------------------------------------------------------------------------- # * Termination Processing #-------------------------------------------------------------------------- def terminate super dispose_menu_background @help_window.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_Sub_Menu.new end end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super update_menu_background @help_window.update update_savefile_windows update_savefile_selection end #-------------------------------------------------------------------------- # * Create Save File Window #-------------------------------------------------------------------------- def create_savefile_windows @savefile_windows = [] for i in 0..2 @savefile_windows.push(Window_SaveFile.new(i, make_filename(i))) end @item_max = 3 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) determine_savefile 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)) end if 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 end 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 #-------------------------------------------------------------------------- # * Move cursor down # wrap : Wraparound allowed #-------------------------------------------------------------------------- def cursor_down(wrap) if @index < @item_max - 1 or wrap @index = (@index + 1) % @item_max end end #-------------------------------------------------------------------------- # * Move cursor up # wrap : Wraparound allowed #-------------------------------------------------------------------------- def cursor_up(wrap) if @index > 0 or wrap @index = (@index - 1 + @item_max) % @item_max end end #-------------------------------------------------------------------------- # * Create Filename # file_index : save file index (0-3) #-------------------------------------------------------------------------- def make_filename(file_index) return "SaveData#{file_index + 1}.rvdata" end #-------------------------------------------------------------------------- # * Select File With Newest Timestamp #-------------------------------------------------------------------------- def latest_file_index index = 0 latest_time = Time.at(0) for i in 0...@savefile_windows.size if @savefile_windows[i].time_stamp > latest_time latest_time = @savefile_windows[i].time_stamp index = i end end return index 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) characters = [] for actor in $game_party.members characters.push([actor.character_name, actor.character_index]) end $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(characters, 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) characters = 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