Advertisement
Vlue

Advanced Game Time

Aug 7th, 2012
14,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 28.53 KB | None | 0 0
  1. #Advanced Game Time + Night/Day v1.6e
  2. #----------#
  3. #Features: Provides a series of functions to set and recall current game time
  4. #          as well customizable tints based on current game time to give the
  5. #          appearance of night and day in an advanced and customizable way.
  6. #
  7. #Usage:   Script calls:
  8. #           GameTime.sec?                      #current second
  9. #           GameTime.min?                      #current minute
  10. #           GameTime.hour?                     #current hour
  11. #           GameTime.hour_nom?                 #current hour (12-hour)
  12. #           GameTime.day?                      #current day of month
  13. #           GameTime.day_week?                 #current day of the week
  14. #           GameTime.day_year?                 #current day of the year
  15. #           GameTime.month?                    #current month
  16. #           GameTime.year?                     #current year
  17. #           GameTime.year_post("set")          #changes the year post to set
  18. #           GameTime.pause_tint(true/false)    #pauses/unpauses tint
  19. #           GameTime.notime(true/false)        #stops time based on true/false
  20. #           GameTime.change(s,m,h,d,dw,mn,y)      #manually set the time
  21. #                                    seconds,minutes,hours,days,weekday,months,years
  22. #                                              any can be nil to not be changed
  23. #           GameTime.set("handle",n)           #increases a certain time portion
  24. #                                             valid arguments are:
  25. #                                               addsec,addmin,addhour,addday
  26. #                                               addmonth,addyear
  27. #                                             and:
  28. #                                               remsec,remmin,remhour,remday
  29. #                                               remmonth,remyear
  30. #           GameTime.clock?(true/false)        #hides/shows the clock
  31. #           GameTime.save_time                 #saves the current time
  32. #           GameTime.load_time                 #loads the saved time
  33. #
  34. #         Message Codes:
  35. #           GTSEC    #Inputs the current second
  36. #           GTMIN    #Inputs the current minute
  37. #           GTHOUR   #Inputs the current hour
  38. #           GTMERI   #Inputs AM/PM depending
  39. #           GTDAYN   #Inputs the day of the month
  40. #           GTDAYF   #Inputs the day of the week (full)
  41. #           GTDAYA   #Inputs the day of the week (abbreviated)
  42. #           GTMONN   #Inputs the month of the year
  43. #           GTMONF   #Inputs the name of the month (full)
  44. #           GTMONA   #Inputs the name of the month (abbreviated)
  45. #           GTYEAR   #Inputs the current year
  46. #
  47. #         Map Note Tags: (These go in the note box of Map Properties)
  48. #           Notint   #These maps will not tint!
  49. #           Notime   #Stops time from moving in that map
  50. #        
  51. #Customization: Set below, in comments.
  52. #
  53. #Examples: GameTime.pause_tint(false)
  54. #          GameTime.change(nil,30,4,1,1,1,2012)
  55. #          GameTime.set("addyear",5)
  56. #          GameTime.clock?(true)
  57. #
  58. #----------#
  59. #-- Script by: V.M of D.T
  60. #
  61. #- Questions or comments can be:
  62. #    given by email: sumptuaryspade@live.ca
  63. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  64. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  65. #
  66. #--- Free to use in any project, commercial or non-commercial, with credit given
  67. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  68.  
  69. #_# BEGIN_CUSTOMIZATION #_#
  70.  
  71.  
  72. #What time a new game starts at: [sec, min, hour, day, month, year]
  73. START_TIME = [0,0,0,0,0,0]
  74. #Wether or not to set time to PC (Real) Time
  75. $USE_REAL_TIME = false
  76. #Time does not increase while the message window is visible:
  77. NOTIMEMESSAGE = false
  78. #Time does not increase unless you are on the map
  79. PAUSE_IN_MENUS = true
  80. #Time does not increase if you are in battle
  81. NOBATTLETIME = false
  82. #Clock is shown
  83. USECLOCK = true
  84. #Set to true to have the clock show up in the menu!
  85. USECLOCK_MENU = false
  86. #Set the format for the clock both in and out of menu
  87. #1. hh:mm am/pm
  88. #2. Sun dd hh:mm am/pm
  89. #3. Custom clock, see below
  90. CLOCK_FORMAT = 3
  91. MENU_CLOCK_FORMAT = 3
  92. #Set to true for a Twenty four hour clock
  93. TF_HOUR_CLOCK = false
  94. #Clock window background opacity
  95. CLOCK_BACK = 75
  96. #Whether to use a special image for the back of the clock or not (Picture folder)
  97. CUSTOM_CLOCK_BACKGROUND = false
  98. #The name of the special image to use
  99. CUSTOM_CLOCK_BACKGROUND_IMAGE = "Spider"
  100. #The offset of the image on the x-axis
  101. CUSTOM_CLOCK_BACKGROUND_X = 0
  102. #The offset of the image on the y-axis
  103. CUSTOM_CLOCK_BACKGROUND_Y = 0
  104. #Button to be used to toggle the clock
  105. CLOCK_TOGGLE = :SHIFT
  106. #Toggle Options - :off, :hour12, :hour24
  107. CLOCK_TOGGLE_OPTIONS = [:off,:hour12,:hour24]
  108. #X and Y position of clock
  109. CLOCK_X = Graphics.width - 175
  110. CLOCK_Y = Graphics.height - 48 - 24 - 12
  111. #Finetune the width of the clock window here:
  112. CLOCK_WIDTH = 175
  113. #Whether or not those little dots on the clock blink
  114. USE_BLINK = true
  115. #The speed at which they blink
  116. BLINK_SPEED = 120
  117. #Here is where you would insert the array of commands for the custom clock:
  118. CUSTOM_CLOCK = ["weekshort"," ","day"," ","year","yearp"]
  119. CUSTOM_CLOCK2 = ["hourtog","blinky","min"," ","meri"]
  120. #Available commands for CUSTOM_CLOCK:
  121. # "sec" - seconds         "min" - minutes
  122. # "hour" - hour (24)      "hour12" - hour (12)
  123. # "hourtog" - hour toggle (12, 24)
  124. # "meri" - AM/PM          "day" - day of the month
  125. # "weekshort" - day of the week abbr
  126. # "weeklong" - day of the week long
  127. # "month" - month         "monthshort" - month name abbr
  128. # "monthlong" - month name
  129. # "year" - year           "yearp" - year post
  130. # "blinky" - those blinky dots
  131.  
  132.  
  133. #Using KHAS lighting effects script? Turn this on to use that tint
  134. USE_KHAS = false
  135. #Using Victor Engine Light effects? Turn this on to use that tint
  136. USE_VICTOR = false
  137. #Variables that count down each gametime second/minute
  138. TIMER_VARIABLES = []
  139.  
  140. #Use Tint in the Battles
  141. BATTLE_TINT = false
  142.  
  143. #Time it takes for a second (or minute) to pass, in frames by default
  144. #(Frame rate is 60 frames per second)
  145. DEFAULT_TIMELAPSE = 60
  146. #Variable ID containing the current speed of time!
  147. TIMELAPSE_VARIABLE = 80
  148. #Whether to use seconds or not
  149. NOSECONDS = true
  150. #Number of seconds in a minute
  151. SECONDSINMIN = 60
  152. #Number of minutes in an hour
  153. MINUTESINHOUR = 60
  154. #Number of hours in a day
  155. HOURSINDAY = 24
  156. #Names of the days (As little or as many days in the week as you want)
  157. DAYNAMES = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
  158. #Day name abbreviations
  159. DAYNAMESABBR = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]
  160. #Number of days in each month (Also represents number of months in a year)
  161. MONTHS = [31,28,31,30,31,30,31,31,30,31,30,31]
  162. #Names of the months
  163. MONTHNAMES = ["January","February","March","April","May","June",
  164.               "July","August","September","October","November","December"]
  165. #Abrreviated names of the months
  166. MONTHNAMESABBR = ["Jan","Feb","Mar","Apr","May","Jun",
  167.                   "Jul","Aug","Sep","Oct","Nov","Dec"]
  168. #The default letters to be posted before the year in dates
  169. DEFAULT_YEAR_POST = "AD"
  170. #NOT YET IMPLEMENTED *IGNORE*
  171. USE_PERIODS = true
  172.                  
  173. #Gradual tint effects! (The hardest part)
  174. #It may look daunting, and it is, but here is where you put the tint
  175. #to be shown at each hour (the actual tint is usually somewhere in between)
  176. #The number of Color.new objects here must equal the number of hours in a day
  177. #Starts from hour 0 (or 12am)
  178. #A color object is -> Color.new(r,g,b,a)
  179. # Where r is red,g is green,b is blue,and a is opacity and all are (0-255)
  180. TINTS = [Color.new(30,0,40,155),
  181.          Color.new(20,0,30,135),
  182.          Color.new(20,0,30,135),
  183.          Color.new(10,0,30,135),
  184.          Color.new(10,0,20,125),
  185.          Color.new(0,0,20,125),
  186.          Color.new(80,20,20,125),
  187.          Color.new(130,40,10,105),
  188.          Color.new(80,20,10,85),
  189.          Color.new(0,0,0,65),
  190.          Color.new(0,0,0,35),
  191.          Color.new(0,0,0,15),
  192.          Color.new(0,0,0,0),
  193.          Color.new(0,0,0,0),
  194.          Color.new(0,0,0,5),
  195.          Color.new(0,0,0,15),
  196.          Color.new(0,0,0,25),
  197.          Color.new(0,0,10,55),
  198.          Color.new(80,20,20,85),
  199.          Color.new(130,40,30,105),
  200.          Color.new(80,20,40,125),
  201.          Color.new(10,0,50,135),
  202.          Color.new(20,0,60,135),
  203.          Color.new(30,0,70,155)]
  204.  
  205. #NOT YET IMPLEMENTED *IGNORE*
  206. PERIODS = [["Night",0,5],
  207.            ["Morning",6,11],
  208.            ["Afternoon",12,17],
  209.            ["Evening",18,23]]
  210.          
  211. $gametimeclockvisible = false
  212. #_# END CUSTOMIZATION #_#
  213.          
  214. module GameTime
  215.   def self.run
  216.     $game_time = Current_Time.new
  217.     $game_time_tint = Sprite_TimeTint.new
  218.   end
  219.   def self.update
  220.     return if $game_message.busy? and NOTIMEMESSAGE
  221.     if !SceneManager.scene.is_a?(Scene_Map) and PAUSE_IN_MENUS
  222.       return $game_time_tint.update if SceneManager.scene.is_a?(Scene_Title)
  223.       return $game_time_tint.update if SceneManager.scene.is_a?(Scene_File)
  224.       return unless SceneManager.scene.is_a?(Scene_Battle) and !NOBATTLETIME
  225.     end
  226.     $game_time.update
  227.     $game_time_tint = Sprite_TimeTint.new if $game_time_tint.disposed?
  228.     update_tint
  229.   end
  230.   def self.update_tint
  231.     $game_time_tint.update unless @pause_tint
  232.   end
  233.   def self.sec?
  234.     return $game_time.sec
  235.   end
  236.   def self.min?
  237.     return $game_time.min
  238.   end
  239.   def self.mint?
  240.     return $game_time.min if $game_time.min > 9
  241.     return "0" + $game_time.min.to_s
  242.   end
  243.   def self.hour?
  244.     return $game_time.hour
  245.   end
  246.   def self.hour_nom?
  247.     hour = $game_time.hour
  248.     hour -= 12 if hour > 11
  249.     hour = 12 if hour == 0
  250.     return hour
  251.   end
  252.   def self.meri?
  253.     return "AM" if $game_time.hour < 12
  254.     return "PM"
  255.   end
  256.   def self.day?
  257.     return $game_time.day if $USE_REAL_TIME
  258.     return $game_time.day + 1
  259.   end
  260.   def self.day_week?
  261.     return $game_time.dayweek
  262.   end
  263.   def self.day_year?
  264.     month = month? - 1
  265.     day = day?
  266.     while month > 0
  267.       day += MONTHS[month]
  268.       month -= 1
  269.     end
  270.     day
  271.   end
  272.   def self.day_name
  273.     return DAYNAMES[$game_time.dayweek-1] if $USE_REAL_TIME
  274.     return DAYNAMES[$game_time.dayweek]
  275.   end
  276.   def self.day_name_abbr
  277.     return DAYNAMESABBR[$game_time.dayweek-1] if $USE_REAL_TIME
  278.     return DAYNAMESABBR[$game_time.dayweek]
  279.   end
  280.   def self.month_name_abbr
  281.     return MONTHNAMESABBR[$game_time.month-1] if $USE_REAL_TIME
  282.     return MONTHNAMESABBR[$game_time.month]
  283.   end
  284.   def self.month?
  285.     return $game_time.month if $USE_REAL_TIME
  286.     return $game_time.month + 1
  287.   end
  288.   def self.month_name
  289.     return MONTHNAMES[$game_time.month-1] if $USE_REAL_TIME
  290.     return MONTHNAMES[$game_time.month]
  291.   end
  292.   def self.year?
  293.     return $game_time.year
  294.   end
  295.   def self.pause_tint(set)
  296.     @pause_tint = set
  297.     $game_time_tint.visible = false if @pause_tint
  298.     $game_time_tint.force_update if !@pause_tint
  299.   end
  300.   def self.tint_paused?
  301.     @pause_tint
  302.   end
  303.   def self.change(s = nil,m = nil,h = nil,d = nil,dw = nil, mn = nil,y = nil)
  304.     $game_time.manual(s,m,h,d,dw,mn,y)
  305.   end
  306.   def self.set(handle,n)
  307.     $game_time.forward(handle,n)
  308.   end
  309.   def self.clock?(set)
  310.     SceneManager.scene.clock_visible?(set)
  311.   end
  312.   def self.year_post(set)
  313.     $game_time.year_post = set
  314.   end
  315.   def self.save_time
  316.     $saved_game_time = $game_time.dup
  317.   end
  318.   def self.load_time
  319.     $game_time = $saved_game_time.dup
  320.   end
  321.   def self.no_time_map
  322.     note = $game_map.map_note
  323.     /Notime/ =~ note
  324.     return false unless $~
  325.     return true
  326.   end
  327.   def self.notime(set)
  328.     $game_time.notime = set
  329.   end
  330.  
  331.   class Current_Time
  332.    
  333.     attr_reader     :sec
  334.     attr_reader     :min
  335.     attr_reader     :hour
  336.     attr_reader     :day
  337.     attr_reader     :dayweek
  338.     attr_reader     :month
  339.     attr_reader     :year
  340.     attr_accessor   :year_post
  341.     attr_accessor   :notime
  342.     attr_accessor   :toggle
  343.     attr_accessor   :hour24
  344.    
  345.     def initialize
  346.       reset_all_values
  347.     end
  348.     def reset_all_values
  349.       @sec = START_TIME[0]
  350.       @min = START_TIME[1]
  351.       @hour = START_TIME[2]
  352.       @day = START_TIME[3]
  353.       @dayweek = 0
  354.       @month = START_TIME[4]
  355.       @year = START_TIME[5]
  356.       @notime = false
  357.       @year_post = DEFAULT_YEAR_POST
  358.       @toggle = 0
  359.     end
  360.     def update
  361.       return realtime if $USE_REAL_TIME
  362.       return if GameTime.no_time_map or @notime
  363.       $game_variables[TIMELAPSE_VARIABLE] = DEFAULT_TIMELAPSE if $game_variables[TIMELAPSE_VARIABLE] <= 0
  364.       return unless Graphics.frame_count % $game_variables[TIMELAPSE_VARIABLE] == 0
  365.       NOSECONDS ? addmin(1) : addsec(1)
  366.       update_timers
  367.     end
  368.     def update_timers
  369.       return unless TIMER_VARIABLES.size > 0
  370.       for i in TIMER_VARIABLES
  371.         $game_variables[i] -= 1 unless $game_variables[i] == 0
  372.       end
  373.     end
  374.     def get_next_toggle
  375.       @toggle = 0 unless @toggle
  376.       @toggle += 1
  377.       @toggle = 0 if @toggle == CLOCK_TOGGLE_OPTIONS.size
  378.       return CLOCK_TOGGLE_OPTIONS[@toggle]
  379.     end
  380.     def set_hour24(value)
  381.       @hour24 = value
  382.     end
  383.     def realtime
  384.       @sec = Time.now.sec
  385.       @sec = 0 if @sec == 60
  386.       @min = Time.now.min
  387.       @hour = Time.now.hour
  388.       @day = Time.now.day
  389.       @dayweek = Time.now.wday
  390.       @month = Time.now.month
  391.       @year = Time.now.year
  392.       0
  393.     end
  394.     def addsec(s)
  395.       @sec += s
  396.       return unless @sec == SECONDSINMIN
  397.       @sec = 0
  398.       addmin(1)
  399.     end
  400.     def addmin(m)
  401.       @min += m
  402.       return unless @min == MINUTESINHOUR
  403.       @min = 0
  404.       addhour(1)
  405.     end
  406.     def addhour(h)
  407.       @hour += h
  408.       return unless @hour == HOURSINDAY
  409.       @hour = 0
  410.       addday(1)
  411.     end
  412.     def addday(d)
  413.       @day += d
  414.       @dayweek += d
  415.       @dayweek = 0 if @dayweek == DAYNAMES.size
  416.       return unless @day == MONTHS[@month]
  417.       @day = 0
  418.       addmonth(1)
  419.     end
  420.     def addmonth(mn)
  421.       @month += mn
  422.       return unless @month == MONTHS.size
  423.       @month = 0
  424.       addyear(1)
  425.     end
  426.     def addyear(y)
  427.       @year += y
  428.     end
  429.     def manual(s = nil,m = nil,h = nil,d = nil,dw = nil,mn = nil,y = nil)
  430.       @sec = s if !s.nil?
  431.       @sec = SECONDSINMIN - 1 if @sec >= SECONDSINMIN
  432.       @min = m if !m.nil?
  433.       @min = MINUTESINHOUR - 1 if @min >= MINUTESINHOUR
  434.       @hour = h if !h.nil?
  435.       @hour = HOURSINDAY - 1 if @hour >= HOURSINDAY
  436.       @day = d if !d.nil?
  437.       @day = MONTHS[@month] - 1 if @day >= MONTHS[@month]
  438.       @dayweek = dw if !dw.nil?
  439.       @dayweek = 0 if @dayweek >= DAYNAMES.size
  440.       @month = mn if !mn.nil?
  441.       @month = MONTHS.size - 1 if @month >= MONTHS.size
  442.       @year = y if !y.nil?
  443.     end
  444.     def forward(handle,n)
  445.       handle = handle.to_s + "(1)"
  446.       n.times do |s| eval(handle) end
  447.     end
  448.     def remsec(s)
  449.       @sec -= s
  450.       return unless @sec == -1
  451.       @sec = SECONDSINMIN
  452.       remmin(1)
  453.     end
  454.     def remmin(m)
  455.       @min -= m
  456.       return unless @min == -1
  457.       @min = MINUTESINHOUR
  458.       remhour(1)
  459.     end
  460.     def remhour(h)
  461.       @hour -= h
  462.       return unless @hour == -1
  463.       @hour = HOURSINDAY - 1
  464.       remday(1)
  465.     end
  466.     def remday(d)
  467.       @day -= d
  468.       @dayweek -= d
  469.       @dayweek = DAYNAMES.size - 1 if @dayweek == -1
  470.       return unless @day == -1
  471.       @day = MONTHS[@month] - 1
  472.       remmonth(1)
  473.     end
  474.     def remmonth(mn)
  475.       @month -= mn
  476.       return unless @month == -1
  477.       @month = MONTHS.size - 1
  478.       remyear(1)
  479.     end
  480.     def remyear(y)
  481.       @year -= y
  482.     end
  483.   end
  484.  
  485.   class Sprite_TimeTint < Sprite_Base
  486.     def initialize(viewport = nil)
  487.       super(viewport)
  488.       self.z = 10
  489.       create_contents
  490.       update
  491.       @old_tint = [0,0,0,0]
  492.       @old_time = -1
  493.     end
  494.     def create_contents
  495.       self.bitmap = Bitmap.new(Graphics.width,Graphics.height)
  496.       self.visible = false
  497.     end
  498.     def force_update
  499.       @old_time = -1
  500.       @old_tint = [0,0,0,0]
  501.       update
  502.     end
  503.     def update
  504.       return true if GameTime.tint_paused?
  505.       return use_default if SceneManager.scene.is_a?(Scene_Battle) and BATTLE_TINT
  506.       return use_khas if USE_KHAS
  507.       return use_victor if USE_VICTOR
  508.       return use_default
  509.     end
  510.     def use_default
  511.       return if self.disposed?
  512.       create_contents if self.bitmap.height != Graphics.height
  513.       create_contents if self.bitmap.width != Graphics.width
  514.       self.visible = SceneManager.scene.is_a?(Scene_Map)
  515.       self.visible = true if SceneManager.scene.is_a?(Scene_Battle) and BATTLE_TINT
  516.       self.visible = false if SceneManager.scene.is_a?(Scene_Title)
  517.       self.visible = false if no_tint
  518.       return unless self.visible
  519.       min = $game_time.min
  520.       return if min == @old_time
  521.       @old_time = min
  522.       rgba = get_new_tint(min)
  523.       return if rgba == @old_tint
  524.       @old_tint = rgba
  525.       self.bitmap.clear
  526.       self.bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(rgba[0],rgba[1],rgba[2],rgba[3]))
  527.     end
  528.     def use_khas      
  529.       begin
  530.       temp = $game_map.light_surface.opacity
  531.       rescue
  532.       return
  533.       end
  534.       self.visible = false
  535.       if no_tint
  536.         $game_map.effect_surface.set_color(0,0,0)
  537.         $game_map.effect_surface.set_alpha(0)
  538.       end
  539.       return if no_tint
  540.       min = $game_time.min
  541.       return if min == @old_time
  542.       @old_time = min
  543.       rgba = get_new_tint(min)
  544.       return if rgba == @old_tint
  545.       @old_tint = rgba
  546.       $game_map.effect_surface.set_color(rgba[0],rgba[1],rgba[2])
  547.       $game_map.effect_surface.set_alpha(rgba[3])
  548.     end
  549.     def no_tint
  550.       return if $game_map.nil?
  551.       note = $game_map.map_note
  552.       /Notint/ =~ note
  553.       return false unless $~
  554.       return true
  555.     end
  556.     def use_victor
  557.       return if $game_map.nil?
  558.       self.visible = false
  559.       $game_map.screen.shade.change_color(0,0,0,0) if no_tint
  560.       $game_map.screen.shade.change_opacity(0) if no_tint
  561.       return if no_tint
  562.       $game_map.screen.shade.show if !$game_map.screen.shade.visible
  563.       min = $game_time.min
  564.       return if min == @old_time
  565.       @old_time = min
  566.       rgba = get_new_tint(min)
  567.       return if rgba == @old_tint
  568.       @old_tint = rgba
  569.       $game_map.screen.shade.change_color(rgba[0],rgba[1],rgba[2],0)
  570.       $game_map.screen.shade.change_opacity(rgba[3],0)
  571.     end
  572.     def get_new_tint(min)
  573.       ctint = TINTS[$game_time.hour]
  574.       ntint = TINTS[$game_time.hour + 1] unless $game_time.hour + 1 == HOURSINDAY
  575.       ntint = TINTS[0] if $game_time.hour + 1 == HOURSINDAY
  576.       r = ctint.red.to_f - ((ctint.red.to_f - ntint.red) * (min.to_f / MINUTESINHOUR))
  577.       g = ctint.green.to_f - ((ctint.green.to_f - ntint.green) * (min.to_f / MINUTESINHOUR))
  578.       b = ctint.blue.to_f - ((ctint.blue.to_f - ntint.blue) * (min.to_f / MINUTESINHOUR))
  579.       a = ctint.alpha.to_f - ((ctint.alpha.to_f - ntint.alpha) * (min.to_f / MINUTESINHOUR))
  580.       return [r,g,b,a]
  581.     end
  582.   end
  583.  
  584.   class Window_GameClock < Window_Base
  585.     def initialize
  586.       super(CLOCK_X,CLOCK_Y,CLOCK_WIDTH,clock_height)
  587.       self.opacity = CLOCK_BACK unless SceneManager.scene.is_a?(Scene_Menu)
  588.       update
  589.       self.visible = $gametimeclockvisible unless SceneManager.scene.is_a?(Scene_Menu)
  590.     end
  591.     def clock_height
  592.       return 80 if !CUSTOM_CLOCK2.nil? and CLOCK_FORMAT == 3 and SceneManager.scene.is_a?(Scene_Map)
  593.       return 80 if !CUSTOM_CLOCK2.nil? and MENU_CLOCK_FORMAT == 3 and SceneManager.scene.is_a?(Scene_Menu)
  594.       return 56
  595.     end
  596.     def update
  597.       if NOSECONDS && @set_minute == $game_time.min
  598.         if Graphics.frame_count % BLINK_SPEED / 2 == 0 && USE_BLINK
  599.           return
  600.         end
  601.       end
  602.       contents.clear
  603.       @set_minute = $game_time.min if NOSECONDS
  604.       if SceneManager.scene.is_a?(Scene_Map)
  605.         v = CLOCK_FORMAT
  606.       else
  607.         v = MENU_CLOCK_FORMAT
  608.       end
  609.       bon = TF_HOUR_CLOCK ? 2 : 0
  610.       if $game_time.hour24
  611.         bon = $game_time.hour24 ? 2 : 0
  612.       end
  613.       string = normal_clock if v + bon == 1
  614.       string = dated_clock if v + bon == 2
  615.       string = military_clock if v + bon == 3
  616.       string = dated_military_clock if v + bon == 4
  617.       string = custom(CUSTOM_CLOCK) if v == 3
  618.       string2 = custom(CUSTOM_CLOCK2) if !CUSTOM_CLOCK2.nil? and v == 3
  619.       contents.draw_text(0,0,contents.width,24,string,1)
  620.       contents.draw_text(0,24,contents.width,24,string2,1) if !CUSTOM_CLOCK2.nil? and v == 3
  621.     end
  622.     def military_clock
  623.       hour = $game_time.hour
  624.       minute = $game_time.min
  625.       if hour < 10 then hour = " " + hour.to_s else hour.to_s end
  626.       if minute < 10 then minute = "0" + minute.to_s else minute.to_s end
  627.       string =  hour.to_s + blinky + minute.to_s
  628.       return string
  629.     end
  630.     def dated_military_clock
  631.       hour = $game_time.hour
  632.       minute = $game_time.min
  633.       dayweek = DAYNAMESABBR[$game_time.dayweek]
  634.       day = $game_time.day
  635.       day += 1 unless $USE_REAL_TIME
  636.       if hour < 10 then hour = " " + hour.to_s else hour.to_s end
  637.       if minute < 10 then minute = "0" + minute.to_s else minute.to_s end
  638.       if day < 10 then day = " " + day.to_s end
  639.       string = dayweek.to_s + " " + day.to_s + " "
  640.       string += hour.to_s + blinky + minute.to_s
  641.       return string
  642.     end
  643.     def normal_clock
  644.       meri = "AM"
  645.       hour = $game_time.hour
  646.       minute = $game_time.min
  647.       if hour > 11 then meri = "PM" end
  648.       if hour == 0 then hour = 12; meri = "AM" end
  649.       if hour > 12 then hour -= 12 end
  650.       if hour < 10 then hour = " " + hour.to_s else hour.to_s end
  651.       if minute < 10 then minute = "0" + minute.to_s else minute.to_s end
  652.       string =  hour.to_s + blinky + minute.to_s + " " + meri
  653.       return string
  654.     end
  655.     def dated_clock
  656.       meri = "AM"
  657.       hour = $game_time.hour
  658.       minute = $game_time.min
  659.       dayweek = DAYNAMESABBR[$game_time.dayweek]
  660.       day = $game_time.day
  661.       day += 1 unless $USE_REAL_TIME
  662.       if hour > 11 then meri = "PM" end
  663.       if hour == 0 then hour = 12; meri = "AM" end
  664.       if hour > 12 then hour -= 12 end
  665.       if hour < 10 then hour = " " + hour.to_s else hour.to_s end
  666.       if minute < 10 then minute = "0" + minute.to_s else minute.to_s end
  667.       if day < 10 then day = " " + day.to_s end
  668.       string = dayweek.to_s + " " + day.to_s + " "
  669.       string += hour.to_s + blinky + minute.to_s + " " + meri
  670.       return string
  671.     end
  672.     def blinky
  673.       return ":" unless USE_BLINK
  674.       return " " if Graphics.frame_count % BLINK_SPEED > (BLINK_SPEED / 2)
  675.       return ":"
  676.     end
  677.     def custom(array)
  678.       array = array.clone
  679.       if array.include?("hourtog")
  680.         bon = TF_HOUR_CLOCK
  681.         bon = $game_time.hour24 if $game_time.hour24
  682.         index = array.index("hourtog")
  683.         array[index] = bon ? "hour" : "hour12"
  684.       end
  685.       string = ""
  686.       for command in array
  687.         case command
  688.         when "sec"
  689.           sec = $game_time.sec
  690.           sec = "0" + sec.to_s if sec < 10
  691.           string += sec.to_s
  692.         when "min"
  693.           minute = $game_time.min
  694.           minute = "0" + minute.to_s if minute < 10
  695.           string += minute.to_s
  696.         when "hour"
  697.           hour = $game_time.hour
  698.           hour >= 12 ? meri = "PM" : meri = "AM"
  699.           hour = " " + hour.to_s if hour < 10
  700.           string += hour.to_s
  701.         when "hour12"
  702.           hour12 = $game_time.hour
  703.           hour12 -= 12 if hour12 > 12
  704.           hour12 = 12 if hour12 == 0
  705.           string += hour12.to_s
  706.         when "meri"
  707.           hour = $game_time.hour
  708.           hour >= 12 ? meri = "PM" : meri = "AM"
  709.           string += meri.to_s
  710.         when "weekshort"
  711.           dayweek = DAYNAMESABBR[$game_time.dayweek]
  712.           string += dayweek.to_s
  713.         when "weeklong"
  714.           dayweekn = DAYNAMES[$game_time.dayweek]
  715.           string += dayweekn.to_s
  716.         when "day"
  717.           day = $game_time.day
  718.           day += 1 unless $USE_REAL_TIME
  719.           string += day.to_s
  720.         when "month"
  721.           month = $game_time.month
  722.           month += 1 unless $USE_REAL_TIME
  723.           string += month.to_s
  724.         when "monthshort"
  725.           monthna = MONTHNAMESABBR[$game_time.month]
  726.           string += monthna.to_s
  727.         when "monthlong"
  728.           monthn = MONTHNAMES[$game_time.month]
  729.           string += monthn.to_s
  730.         when "year"
  731.           year = $game_time.year
  732.           string += year.to_s
  733.         when "yearp"
  734.           string += $game_time.year_post
  735.         when "blinky"
  736.           string += blinky
  737.         else
  738.           string += command.to_s
  739.         end
  740.       end
  741.       return string
  742.     end
  743.   end
  744.  
  745. end
  746.  
  747. GameTime.run
  748.  
  749. class Window_Base < Window
  750.   alias game_time_convert_escape_characters convert_escape_characters
  751.   def convert_escape_characters(text)
  752.     result = game_time_convert_escape_characters(text)
  753.     result.gsub!(/GTSEC/) { GameTime.sec? }
  754.     result.gsub!(/GTMIN/) { GameTime.mint? }
  755.     result.gsub!(/GTHOUR/) { GameTime.hour? }
  756.     result.gsub!(/GTMERI/) { GameTime.meri? }
  757.     result.gsub!(/GTDAYN/) { GameTime.day? }
  758.     result.gsub!(/GTDAYF/) { GameTime.day_name }
  759.     result.gsub!(/GTDAYA/) { GameTime.day_name_abbr }
  760.     result.gsub!(/GTMONF/) { GameTime.month? }
  761.     result.gsub!(/GTMONN/) { GameTime.month_name }
  762.     result.gsub!(/GTMONA/) { GameTime.month_name_abbr }
  763.     result.gsub!(/GTYEAR/) { GameTime.year? }
  764.     result
  765.   end
  766. end
  767.  
  768. class Scene_Base
  769.   alias game_time_update update
  770.   def update
  771.     game_time_update
  772.     GameTime.update
  773.   end
  774.   def clock_visible?(set)
  775.     return
  776.   end
  777. end
  778.  
  779. class Scene_Map
  780.   alias game_time_post_transfer post_transfer
  781.   alias game_time_init create_all_windows
  782.   alias game_time_map_update update
  783.   alias game_time_start start
  784.   def start
  785.     game_time_start
  786.     GameTime.update_tint
  787.   end
  788.   def create_all_windows
  789.     game_time_init
  790.     @gametimeclock = GameTime::Window_GameClock.new if USECLOCK
  791.     if CUSTOM_CLOCK_BACKGROUND
  792.       @clockbackground = Sprite.new(@gametimeclock.viewport)
  793.       @clockbackground.bitmap = Cache.picture(CUSTOM_CLOCK_BACKGROUND_IMAGE)
  794.       @clockbackground.x = @gametimeclock.x
  795.       @clockbackground.x += CUSTOM_CLOCK_BACKGROUND_X
  796.       @clockbackground.y = @gametimeclock.y
  797.       @clockbackground.y += CUSTOM_CLOCK_BACKGROUND_Y
  798.       @clockbackground.visible = @gametimeclock.visible
  799.     end
  800.   end
  801.   def post_transfer
  802.     $game_time_tint.force_update
  803.     game_time_post_transfer
  804.   end
  805.   def update
  806.     game_time_map_update
  807.     return unless USECLOCK
  808.     @gametimeclock.update unless SceneManager.scene != self
  809.     if Input.trigger?(CLOCK_TOGGLE) and @gametimeclock.nil? == false
  810.       option = $game_time.get_next_toggle
  811.       if option == :off
  812.         @gametimeclock.visible = false
  813.       else
  814.         @gametimeclock.visible = true
  815.       end
  816.       if option == :hour12
  817.         $game_time.set_hour24(false)
  818.       elsif option == :hour24
  819.         $game_time.set_hour24(true)
  820.       end
  821.       $gametimeclockvisible = @gametimeclock.visible
  822.       @clockbackground.visible = @gametimeclock.visible if @clockbackground
  823.     end
  824.   end
  825.   def clock_visible?(set)
  826.     @gametimeclock.visible = set
  827.     @clockbackground.visible = @gametimeclock.visible if @clockbackground
  828.     $gametimeclockvisible = set
  829.   end
  830.   def update_encounter
  831.     if $game_player.encounter
  832.       $game_time_tint.use_default if BATTLE_TINT
  833.       SceneManager.call(Scene_Battle)
  834.     end
  835.   end
  836. end
  837.  
  838. class Game_Map
  839.   def map_note
  840.     return @map.note unless @map.nil?
  841.   end
  842. end
  843.  
  844. class Scene_Menu
  845.   alias gt_start start
  846.   alias gt_update update
  847.   def start
  848.     gt_start
  849.     @clock = GameTime::Window_GameClock.new if USECLOCK_MENU
  850.     return if @clock.nil?
  851.     @clock.x = 0
  852.     @clock.y = @gold_window.y - @clock.height
  853.     @clock.width = @gold_window.width
  854.     @clock.create_contents
  855.   end
  856.   def update
  857.     gt_update
  858.     @clock.update unless @clock.nil?
  859.     @clock.contents.clear if SceneManager.scene != self and !@clock.nil?
  860.   end
  861. end
  862.  
  863. class Scene_Battle
  864.   alias gametime_pre_terminate pre_terminate
  865.   def pre_terminate
  866.     gametime_pre_terminate
  867.     $game_time_tint.update
  868.   end
  869. end
  870.  
  871. module DataManager
  872.   class << self
  873.   alias gametime_msc make_save_contents
  874.   alias gametime_esc extract_save_contents
  875.   alias gametime_sng setup_new_game
  876.   end
  877.   def self.make_save_contents
  878.     contents = gametime_msc
  879.     contents[:gametime] = $game_time
  880.     contents
  881.   end
  882.   def self.extract_save_contents(contents)
  883.     gametime_esc(contents)
  884.     $game_time = contents[:gametime]
  885.   end
  886.   def self.setup_new_game
  887.     gametime_sng
  888.     $game_time = GameTime::Current_Time.new
  889.   end
  890. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement