Submit Your Article Guild Wars 2 Forum RPG Maker VX.com
 
RPG Maker
 

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > Window_SaveFile

Window_SaveFile


Inherits from: Window_Base

Description: This window shows the status of an individual save file within the Save or Load scenes.

Code


class Window_SaveFile < Window_Base
# ------------------------------------
 attr_reader   :filename
 attr_reader   :selected
# ------------------------------------
  def initialize(file_index, filename)
    super(0, 64 + file_index % 4 * 104, 640, 104)
    self.contents = Bitmap.new(width - 32, height - 32)
    @file_index = file_index
    @filename = "Save#{@file_index + 1}.rxdata"
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      @characters = Marshal.load(file)
      @frame_count = Marshal.load(file)
      @game_system = Marshal.load(file)
      @game_switches = Marshal.load(file)
      @game_variables = Marshal.load(file)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
    refresh
    @selected = false
  end
# ------------------------------------ 
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    name = "File #{@file_index + 1}"
    self.contents.draw_text(4, 0, 600, 32, name)
    @name_width = contents.text_size(name).width
    if @file_exist
      for i in 0...@characters.size
        bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
        cw = bitmap.rect.width / 4
        ch = bitmap.rect.height / 4
        src_rect = Rect.new(0, 0, cw, ch)
        x = 300 - @characters.size * 32 + i * 64 - cw / 2
        self.contents.blt(x, 68 - ch, bitmap, src_rect)
      end
      hour = @total_sec / 60 / 60
      min = @total_sec / 60 % 60
      sec = @total_sec % 60
      time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
      self.contents.font.color = normal_color
      self.contents.draw_text(4, 8, 600, 32, time_string, 2)
      self.contents.font.color = normal_color
      time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
      self.contents.draw_text(4, 40, 600, 32, time_string, 2)
    end
  end
# ------------------------------------
  def selected=(selected)
    @selected = selected
    update_cursor_rect
  end
# ------------------------------------
  def update_cursor_rect
    if @selected
      self.cursor_rect.set(0, 0, @name_width + 8, 32)
    else
      self.cursor_rect.empty
    end
  end
end

Properties


File_Index: The index of the save file to which this window points, where index 0 is the first save file.

Filename: The filename of the save file to which this window points, by default, this is the string "Save", plus the file index + 1, plus ".rxdata".

Time_Stamp: The time at which the file to which this window points was last saved.

File_Exist: This flag is set to true if the file to which this winodw points exists.

Characters: An array of the characters in the party at the time the file to which this window points was last saved.

Frame_Count: The total number of frames that had been shown at the time the file to which this window points was last saved.

Game_System: Not used in this class, as far as I can tell.

Game_Switches: Not used in this class, as far as I can tell.

Game_Variables: Not used in this class, as far as I can tell.

Total_Sec: The total number of seconds elapsed since the start of the saved game to which this window points. Found by taking the value of @frame_count and dividing it by the current frame rate.

Selected: This flag is set to true if the user has selected this window on the save or load screen to which this window belongs.

Name_Width: The width of the string "File [number]". Used to determine the width of the cursor when the window is selected.

Methods


Initialize

Arguments:
File_Index: The index of the save file to which this window points, where index 0 is the first save file.
Filename: The filename of the save file to which this window points, by default, this is the string "Save", plus the file index + 1, plus ".rxdata".
Local Variables: None

How it Works: This method initializes the window. The window's x coordinate is set to 0, its y coordinate is set to 64, plus the file's index multiplied by 104. The width of the window is set to 640, and the height is set to 104. The value of @file_index is set to the index of the save file to which this window points, with the first file being index 0. @filename instance variable is initialized to the name of the save file to which this window points. The @time_stamp instance variable is initialized to a dummy value for now, since it's not know at this point whether the file to which the window points exists. The @file_exist flag is set to true if the file "Save[n].rxdata" exists, where n is the file index, plus one. The next part of the method is only executed if the @file_exist flag is set. The file is opened, and the @time_stamp instance variable is set to the time at which the file was last modified. The next few statements load various instance variables. I'm not certain why the system, switches, and variables from the file are loaded, since they don't appear to be used in this class. @characters is used to determine which character graphics to show in the window, and @frame_count is used to determine the total number of seconds played by dividing it by the current frame rate. Note that because of this calculation method, the play time shown may differ from the actual play time if the current frame rate differs from the average frame rate while playing the saved game. Once the play time is determined, the file is closed and the window's contents are drawn using the refresh method.

Refresh

Arguments: None
Local Variables: None

How it Works: This method draws the window's contents. The contents of the window are first cleared, and the font color is changed to the normal color. The name is then set to be "File n", where n is the index of the file to which this window points, plus one. This name is then drawn at x coordinate 4 and y coordinate 0. The value of @name_width is set to the width of the string "File n", in pixels. This is used to determine the width of the cursor in the update_cursor_rect method. The rest of the method is only executed if the @file_exist flag is true. For each character in the @characters array, the character's sprite is stored in the bitmap variable. The next two statments isolate the down-facing stationary frame from the group of sixteen animations within the character set file. The x coordinate of the bitmap is set to be 300, minus 32 times the size of the character array, plus the index times 64, minus the width of the animation divided by 2. The sprite bitmap is then drawn at the x coordinate determined above, and the y coordinate equal to 68 minus the character height. Next, the total seconds of play time for the save file is split into hours, minutes, and seconds for display purposes. The number of hours is the total seconds divided by 3600. The number of minutes is the total seconds divided by 60, modded by 60. The number of seconds is the total number of seconds modded by 60. These values are formatted into a string by the time_string = sprintf("%02d:%02d:%02d", hour, min, sec) statement. The formatted string is in the format xx:yy:zz, where xx is the number of hours, yy is the number of minutes, and zz is the number of seconds. This string is drawn in the normal color at x coordinate 4 and y coordinate 8 with a width of 600, and a height of 32. The optional argument "2" in the draw_text statement means that the string will be drawn right-aligned in its bounding box, so the string will appear on the right side of the window, despite its low x coordinate. The time string is then set to be @time_stamp.strftime("%Y/%m/%d %H:%M"). The "strf" in "strftime" means "string formatted". In this case, the value will look like "yy/mm/dd hh:mm", where yy is the year in which the file was last saved, mm is the month, dd is the day, hh is the hour, and mm is the minute. This string is drawn at x coordinate 4 and y coordinate 40, with the same bounding box and alignment as the first time string. Thus, the last save date will appear directly underneath the play time for this file.

Selected=

Arguments:
Selected: The new value of the @selected instance variable.
Local Variables: None

How it Works: This method sets the value of the @selected instance variable to the value passed to this method, and then calls the update_cursor_rect method to reflect this change.

Update_Cursor_Rect

Arguments: None
Local Variables: None

How it Works: This method updates the cursor rectangle. If the @selected instance variable is true, then the cursor rectangle's position is drawn at x and y coordinates 0. The width of the rectangle is equal to the value of @name_width as determined in the refresh method. If @selected is false, then the cursor rectangle is set to be empty (invisible). 
Syntax
@
@@
$
alias
[array index]
attr_accessor
attr_reader
attr_writer
class
def
do
ensure
for
if
[iterator]
key => value
new
next
nil
redo
require
return
rescue
self
super
undef
unless
until
while
yield

Classes
Arrow_Actor
Arrow_Base
Arrow_Enemy
Game_Actor
Game_Actors
Game_BattleAct
Game_Battler
Game_Character
Game_Common
Game_Enemy
Game_Event
Game_Map
Game_Party
Game_Picture
Game_Player
Game_Screen
Game_SlfSwitch
Game_Switches
Game_System
Game_Troop
Game_Variables
Interpreter
Scene_Debug
Scene_End
Scene_Equip
Scene_File
Scene_Gameover
Scene_Item
Scene_Load
Scene_Map
Scene_Menu
Scene_Name
Scene_Save
Scene_Shop
Scene_Skill
Scene_Status
Scene_Title
Sprite_Battler
Sprite_Character
Sprite_Picture
Sprite_Timer
Spriteset_Battle
Spriteset_Map
Window_Base
Window_Battleresult
Window_Battlestatus
Window_Command
Window_DebugLeft
Window_DebugRight
Window_EquipItem
Window_EquipLeft
Window_EquipRight
Window_Gold
Window_Help
Window_InputNumb
Window_Item
Window_MenuStatus
Window_Message
Window_NameEdit
Window_NameInput
Window_PartyCom
Window_PlayTime
Window_SaveFile
Window_Selectable
Window_ShopBuy
Window_ShopCom
Window_ShopNum
Window_ShopSell
Window_ShopStatus
Window_Skill
Window_SkillStatus
Window_Status
Window_Steps
Window_Target

Other
Class Hierarchy
Global Variables


RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

RPG RPG Revolution is an Privacy Policy and Legal