KyoWatch VX 1.0.1.1

KyoWatch XP / VX
Version: 1.0.1.1
By: Kyonides
alias Kyonides-Arkanthos, Shadowball

Introduction

It allows the player to set a clock, configure a calendar (made of simple text sprites for now), so the player may think the game has its own clock for calculating when any event might happen and it may not be affected by the OS clock / calendar at all and even so the data will
look realistic. Well, the clock on the menu screen will show its hands once the clock is set. It should show / update the current time correctly.

Features
<Post a bulleted list of features here. This section is optional.>
  • Digital Clock
  • Analog Clock
  • Calendar with correct data about dates (including leap year calculation)

[*]Can set the time from event via script call

Screenshots

For later, but you can download the demo and the script in a separate file if you like.

Demo

http://www.mediafire.com/?sharekey=ac292e67d6ccc98200d27174b47c6657c42aadd10fc9ba8af1940a51b339e393

Script

script Spoiler
  1. #   KyoWatch VX
  2. #   v 1.0.1.0 - 12.27.2009
  3. #   v 1.0.0.1 - 12.22.2009
  4. #   by Kyonides-Arkanthos alias Kyonides, Shadowball
  5.  
  6. #   Plug and Play script
  7.  
  8. #   Basic Instructions
  9.  
  10. #   If $game_kyowatch.no_reset is false, you may set the clock and setup the
  11. #   calendar options. Otherwise you will hear a Buzzer telling you the clock
  12. #   settings cannot be modified.
  13.  
  14. #   You may create a script call like this one
  15. #
  16. #   $game_kyowatch.no_reset = true
  17. #
  18. #   to prevent the player to change the clock / calendar settings at any time.
  19.  
  20. #   YearRangeMIN and YearRangeMAX are the minimal and maximal limits for the
  21. #   current year settings. Any other value is unavailable but you may modify
  22. #   these Constants at will before you play the game.
  23.  
  24. #   KyoX and KyoY are the default values for the clock graphic X and Y
  25. #   coordinates. You may also change this values as needed.
  26.  
  27. #   The rest of the script, except for the Constants for the graphic filenames,
  28. #   should stay as it is. I mean, you should leave the rest of the script alone
  29. #   especially if you are no scripter. This will prevent any malfunctioning
  30. #   from ever happening.
  31.  
  32. #   For any bugs you may contact me at anytime by sending a PM or an email.
  33.  
  34. class Object
  35.   def par?
  36.     return true  if self % 2 == 0
  37.     return false if self % 2 != 0
  38.   end
  39. end
  40. # Module where you can setup the values for the pictures you want
  41. # to load during the game while running the Watch script
  42. module KyoVocab
  43.   KyoX, KyoY = 200, 168
  44.   YearRangeMIN = 1990
  45.   YearRangeMAX = 2020
  46.     PokeballSh   = 'pokeballbg'
  47.     KyoClock     = 'clock'     #
  48.     KyoMin       = 'clockmin'  # Clock minute hand
  49.     KyoHour      = 'clockhour' # Clock hour hand
  50.   KyoWatchBack = 'watchback'
  51.   KyoSun       = 'sun'
  52.   KyoMoon      = 'full_moon'
  53.   KyoDay       = { 'AM' => [6,7,8,9,10,11], 'PM' => [1,2,3,4,5,12] }
  54.   KyoDayFullNames = {
  55.       nil => '---------', 0 => 'Sunday',    1 => 'Monday',  
  56.       2 => 'Tuesday',     3 => 'Wednesday', 4 => 'Thursday',
  57.       5 => 'Friday',      6 => 'Saturday'
  58.     }
  59.   KyoDayPartialNames = {
  60.       nil => '---', 0 => 'SUN', 1 => 'MON', 2 => 'TUE',
  61.       3 => 'WED',   4 => 'THU', 5 => 'FRI', 6 => 'SAT'
  62.     }
  63.   KyoMonthFullNames = { 0 => '----------',
  64.        1 => 'January',  2 => 'February',  3 => 'March',
  65.        4 => 'April',    5 => 'May',       6 => 'June',
  66.        7 => 'July',     8 => 'August',    9 => 'September',
  67.       10 => 'October', 11 => 'November', 12 => 'December'
  68.     }
  69.   KyoMonthPartialNames = { 0 => '---',
  70.        1 => 'JAN',  2 => 'FEB',  3 => 'MAR',
  71.        4 => 'APR',  5 => 'MAY',  6 => 'JUN',
  72.        7 => 'JUL',  8 => 'AUG',  9 => 'SEP',
  73.       10 => 'OCT', 11 => 'NOV', 12 => 'DEC'
  74.     }
  75.   REGYEAR  = [nil,31,28,31,30,31,30,31,31,30,31,30,31]
  76.   LEAPYEAR = [nil,31,29,31,30,31,30,31,31,30,31,30,31]
  77.   REGYEARMOD  = {
  78.     1 => 0, 2 => 3, 3 => 3, 4 => 6, 5 => 1, 6 => 4,
  79.     7 => 6, 8 => 2, 9 => 5, 10=> 0, 11=> 3, 12=> 5
  80.     }
  81.   LEAPYEARMOD = {
  82.     1 => 0, 2 => 3, 3 => 4, 4 => 0, 5 => 2, 6 => 5,
  83.     7 => 0, 8 => 3, 9 => 6, 10=> 1, 11=> 4, 12=> 6
  84.     }
  85. end
  86.  
  87. class Game_Player
  88.   def refresh # Do not show a character based on the party leader
  89.     @character_name  = 'Trainers'
  90.     @character_index = 2
  91.   end
  92. end
  93.  
  94. class Game_KyoWatch
  95.   include KyoVocab
  96.   attr_accessor :kyoclock, :time_now, :frame_count, :no_clocktime
  97.   attr_accessor :year, :mon, :day, :hour, :min, :full_mnames
  98.   attr_accessor :no_reset, :disable_24H, :weekday, :month_name
  99.   def initialize
  100.     @kyoclock = [YearRangeMIN,1,1,12,0,'??',0]
  101.     @time_now = []
  102.     @frame_count = 0
  103.     @no_clocktime = true
  104.     @full_mnames = false
  105.     @no_reset    = false
  106.     @disable_24H = true # Disable 24 Hours Format
  107.     @weekday    = KyoDayPartialNames
  108.     @month_name = KyoMonthPartialNames
  109.   end
  110.  
  111.   def update_clock
  112.     @total_sec = (Graphics.frame_count-@frame_count) / Graphics.frame_rate
  113.     m    = @total_sec / 60 % 60
  114.     h    = @total_sec / 60 / 60 % 24
  115.     d    = @total_sec / 60 / 60 / 24 % 30
  116.     mon  = @total_sec / 60 / 60 / 24 / 30 % 12
  117.     year = @total_sec / 60 / 60 / 24 / 30 / 12
  118.     total_min    = @kyoclock[4] + m
  119.     total_hours  = @kyoclock[3] + h + (total_min / 60)
  120.     total_days   = @kyoclock[2] + d + (total_hours / 24)
  121.     total_months = @kyoclock[1] + mon + (total_days / 30)
  122.     total_years  = @kyoclock[0] + year + (total_months / 12)
  123.     @min  = total_min % 60
  124.     @hour = total_hours % 24
  125.     max = !leap?(total_years) ? REGYEAR[total_months] : LEAPYEAR[total_months]
  126.     @day  = total_days % max
  127.     @mon  = total_months % 12
  128.     @year = total_years
  129.     meridian_indicator(@hour, @min)
  130.     @time_now = [@year, @mon, @day, @hour, @min, @kyoclock[5], @kyoclock[6]]
  131.   end
  132.  
  133.   def leap?(year)
  134.     year % 4 == 0 && year % 100 != 0 || year % 400 == 0
  135.   end
  136.  
  137.   def day_name(year, month, daynum)
  138.     @y = year-1
  139.     @a = (@y % 7)
  140.     @b = (  (@y/4) - ( 3*( ( (@y/100)+1 ) /4 ) )  ) % 7
  141.     @mod = REGYEARMOD[month]  if !leap?(year)
  142.     @mod = LEAPYEARMOD[month] if leap?(year)
  143.     @d = daynum % 7
  144.     @day_name = (@a + @b + @mod + @d) % 7
  145.     return @day_name
  146.   end
  147.  
  148.   def minutes
  149.     return @time_now[4]
  150.   end
  151.  
  152.   def hours
  153.     hour = @disable_24H ? @time_now[3]%12 : @time_now[3]
  154.     hour = 12 if @disable_24H and @time_now[3]%12 == 0
  155.     return hour
  156.   end
  157.  
  158.   def meridian_indicator(hour, min)
  159.     @kyoclock[5] = 'AM' if hour >=  0 and min >= 0
  160.     @kyoclock[5] = 'PM' if hour >= 12 and min >= 0
  161.   end
  162.  
  163.   def set_time(values={})
  164.     values = {:year  => @kyoclock[0],
  165.               :month => @kyoclock[1],
  166.               :day   => @kyoclock[2],
  167.               :hour  => @kyoclock[3],
  168.               :min   => @kyoclock[4],}.merge(values)
  169.     @kyoclock[6] = day_name(values[:year], values[:month], values[:day])
  170.     meridian_indicator(@kyoclock[3], @kyoclock[4])
  171.     @frame_count = Graphics.frame_count
  172.   end
  173. end
  174.  
  175. class Sprite_KyoPicture < Sprite # Class to show a picture that may rotate
  176.   def initialize(name, center=true, viewport=nil)
  177.     @viewport = Viewport.new(0,0,544,416) if viewport == nil
  178.     @viewport = viewport if viewport != nil
  179.     super(@viewport)
  180.     self.bitmap = Cache.picture(name)
  181.     @width = self.bitmap.width/2
  182.     self.x, self.y, self.z = 0, 0, 1000
  183.     self.ox, self.oy = @width, @width if center
  184.     self.ox, self.oy = 0, 0 if !center
  185.   end
  186.  
  187.   def update(value)
  188.     if Input.trigger?(Input::UP) or Input.repeat?(Input::UP)
  189.       self.angle -= value
  190.         elsif Input.trigger?(Input::DOWN) or Input.repeat?(Input::DOWN)
  191.       self.angle += value
  192.         end
  193.   end
  194.  
  195.   def rotate(value)
  196.     self.angle -= value
  197.   end
  198.  
  199.   def refresh(name,x=0,y=0,center=true)
  200.     self.bitmap = Cache.picture(name)
  201.     @width = self.bitmap.width/2
  202.     self.x, self.y, self.z = x, y, 1000
  203.     self.ox, self.oy = @width, @width if center
  204.     self.ox, self.oy = 0, 0 if !center
  205.   end
  206. end
  207.  
  208. class Sprite_PlayTime < Sprite # Just A PlayTime Script
  209.   def initialize(x=0,y=0)
  210.     @viewport = Viewport.new(0,0,544,416)
  211.     super(@viewport)
  212.     self.bitmap = Bitmap.new(140, 48)
  213.     self.bitmap.font.name = 'Digital-7'
  214.     self.bitmap.font.size = 32
  215.     self.bitmap.font.bold = true
  216.     self.x, self.y, self.z, self.visible = x, y, 1000, true
  217.         update
  218.     end
  219.    
  220.   def refresh
  221.     self.bitmap.clear
  222.     @total_sec = Graphics.frame_count / Graphics.frame_rate
  223.     hour = @total_sec / 60 / 60
  224.     min = @total_sec / 60 % 60
  225.     sec = @total_sec % 60
  226.     text = sprintf("%02d:%02d:%02d", hour, min, sec)
  227.     self.bitmap.font.color.set(255, 255, 255)
  228.     self.bitmap.draw_text(self.bitmap.rect, text)
  229.   end
  230.  
  231.   def update
  232.     super
  233.     if Graphics.frame_count / Graphics.frame_rate != @total_sec
  234.       refresh
  235.     end
  236.   end
  237. end
  238.  
  239. class Sprite_KyoWatch < Sprite
  240.   def initialize(x=0,y=0)
  241.     @viewport = Viewport.new(0,0,544,416)
  242.     super(@viewport)
  243.     self.bitmap = Bitmap.new(156, 48)
  244.     self.bitmap.font.name = 'Digital-7'
  245.     self.bitmap.font.size = 32
  246.     self.bitmap.font.bold = true
  247.     self.x, self.y, self.z, self.visible = x, y, 1000, true
  248.     @time_now = []
  249.     @clock = $game_kyowatch
  250.     update
  251.   end
  252.  
  253.   def update
  254.     super
  255.     if @clock.time_now != @time_now
  256.       refresh
  257.     end
  258.   end
  259.  
  260.   def refresh
  261.     self.bitmap.clear
  262.     @clock.update_clock
  263.     c = @clock.time_now
  264.     text = sprintf("%02d %02d:%02d", c[2], @clock.hours, c[4])
  265.     ampm = @clock.disable_24H ? ' '[email hidden]_now[5] : ''
  266.     self.bitmap.font.color.set(255, 255, 255)
  267.     self.bitmap.draw_text(self.bitmap.rect, text + ampm)
  268.     @time_now = @clock.time_now
  269.   end
  270. end
  271.  
  272. class Sprite_KyoYear < Sprite#_KyoWatch
  273.   attr_accessor :year
  274.   def initialize(x=0,y=0)
  275.     @viewport = Viewport.new(0,0,544,416)
  276.     super(@viewport)
  277.     self.bitmap = Bitmap.new(156, 48)
  278.     self.bitmap.font.name = 'Digital-7'
  279.     self.bitmap.font.size = 32
  280.     self.bitmap.font.bold = true
  281.     self.x, self.y, self.z, self.visible = x, y, 1000, true
  282.     @clock = $game_kyowatch
  283.     @year  = @clock.kyoclock[0]
  284.     @value = 0
  285.     update
  286.   end
  287.  
  288.   def update
  289.     refresh if @year != @value
  290.   end
  291.  
  292.   def refresh
  293.     self.bitmap.clear
  294.     @clock.update_clock
  295.     self.bitmap.font.color.set(255, 255, 255)
  296.     self.bitmap.draw_text(self.bitmap.rect, @year.to_s)
  297.     @value = @year
  298.   end
  299. end
  300.  
  301. class Sprite_KyoDay < Sprite
  302.   attr_accessor :day
  303.   def initialize(x=0,y=0)
  304.     @viewport = Viewport.new(0,0,544,416)
  305.     super(@viewport)
  306.     self.bitmap = Bitmap.new(92, 48)
  307.     self.bitmap.font.name = 'Digital-7'
  308.     self.bitmap.font.size = 32
  309.     self.bitmap.font.bold = true
  310.     self.x, self.y, self.z, self.visible = x, y, 1000, true
  311.     @clock = $game_kyowatch
  312.     @time_now = []
  313.     @day = @clock.kyoclock[2]
  314.     update
  315.   end
  316.  
  317.   def update
  318.     super
  319.     @clock.update_clock
  320.     if @clock.time_now != @time_now
  321.       refresh
  322.     end
  323.   end
  324.  
  325.   def refresh
  326.     self.bitmap.clear
  327.     @clock.update_clock
  328.     self.bitmap.font.color.set(255, 255, 255)
  329.     self.bitmap.draw_text(self.bitmap.rect, @day.to_s)
  330.     @time_now = @clock.time_now
  331.   end
  332. end
  333.  
  334. class Sprite_KyoWatchSys < Sprite # Make the Clock hands rotate
  335.   attr_accessor :hour, :min, :ampm, :active
  336.   def initialize(x=0,y=0,f1=false,f2=false,f3=false)
  337.     @viewport = Viewport.new(0,0,544,416)
  338.     super(@viewport)
  339.     self.bitmap = Bitmap.new(116, 48)
  340.     self.bitmap.font.name = 'Digital-7'
  341.     self.bitmap.font.size = 32
  342.     self.bitmap.font.bold = true
  343.     self.x, self.y, self.z, self.visible = x, y, 1000, true
  344.     @active = false
  345.     @clock = $game_kyowatch.kyoclock
  346.     @hour, @min, @ampm = @clock[3]%12, @clock[4], @clock[5]
  347.     update(f1,f2,f3) if @active
  348.   end
  349.  
  350.   def update(hour_flag, min_flag, ampm_flag)
  351.     if @active
  352.       @hour_flag, @min_flag, @ampm_flag = hour_flag, min_flag, ampm_flag
  353.       update_hour   if !@hour_flag
  354.       update_minute if @hour_flag and !@min_flag
  355.       update_ampm   if @hour_flag and @min_flag and !@ampm_flag
  356.     end
  357.     refresh
  358.   end
  359.  
  360.   def update_hour
  361.     @hour = 12  if @hour == 0
  362.     @hour -= 12 if @hour >= 13
  363.     if Input.trigger?(Input::UP) or Input.repeat?(Input::UP)
  364.       @hour += 1 if @hour >= 0 and @hour <= 12
  365.       @hour =  1 if @hour == 13
  366.     elsif Input.trigger?(Input::DOWN) or Input.repeat?(Input::DOWN)
  367.       @hour -= 1 if @hour >= 0 and @hour <= 12
  368.       @hour = 12 if @hour == 0
  369.     end
  370.   end
  371.  
  372.   def update_minute
  373.     if Input.trigger?(Input::UP) or Input.repeat?(Input::UP)
  374.       @min  += 1 if @min >= 0 and @min <= 60
  375.       @min  = 0  if @min == 60
  376.     elsif Input.trigger?(Input::DOWN) or Input.repeat?(Input::DOWN)
  377.       @min  -= 1 if @min >= 0 and @min <= 60
  378.       @min  = 59 if @min == -1
  379.     end
  380.   end
  381.  
  382.   def update_ampm
  383.     if Input.trigger?(Input::DOWN) or Input.trigger?(Input::LEFT)
  384.       @ampm = 'AM'
  385.     elsif Input.trigger?(Input::UP) or Input.trigger?(Input::RIGHT)
  386.       @ampm = 'PM'
  387.     end
  388.   end
  389.  
  390.   def refresh
  391.     self.bitmap.clear
  392.     text = sprintf("%02d:%02d", @hour, @min)
  393.     self.bitmap.font.color.set(255, 255, 255)
  394.     self.bitmap.draw_text(self.bitmap.rect, text+' '+@ampm, 1)
  395.   end
  396. end
  397.  
  398. class Sprite_KyoCalendarSys < Sprite_KyoWatchSys # Setup the current date
  399.   include KyoVocab
  400.   attr_accessor :year, :month, :day, :day_name, :update_sprite, :on_screen
  401.   alias :kyon_skcs_init :initialize
  402.   def initialize(x=0,y=0,f1=false,f2=false,f3=false,f4=false)
  403.     kyon_skcs_init(x=0,y=0,f1=false,f2=false,f3=false)
  404.     @clock_req = $game_kyowatch
  405.     @year, @month, @day = @clock[0], @clock[1], @clock[2]
  406.     @day_name = @clock[6]
  407.     @update_sprite = nil
  408.     @on_screen = false
  409.     update(f1,f2,f3,f4) if @active
  410.   end
  411.  
  412.   def update(year_flag, month_flag, day_flag, day_name_flag)
  413.     if @active
  414.       @year_flag, @month_flag   = year_flag, month_flag
  415.       @day_flag, @day_name_flag = day_flag, day_name_flag
  416.       update_year     if !@year_flag
  417.       update_month    if @year_flag and !@month_flag
  418.       update_day      if @year_flag and @month_flag and !@day_flag
  419.       update_day_name if @day_flag and !@day_name_flag and !@on_screen
  420.     end
  421.     refresh(@update_sprite)
  422.   end
  423.  
  424.   def update_year
  425.     if Input.trigger?(Input::UP) or Input.repeat?(Input::UP)
  426.       @year += 1 if @year >= YearRangeMIN  and @year <= YearRangeMAX
  427.       @year  = YearRangeMIN if @year == YearRangeMAX+1
  428.     elsif Input.trigger?(Input::DOWN) or Input.repeat?(Input::DOWN)
  429.       @year -= 1 if @year >= YearRangeMIN  and @year <= YearRangeMAX
  430.       @year  = YearRangeMAX if @year == YearRangeMIN-1
  431.     end
  432.   end
  433.  
  434.   def update_month
  435.     if Input.trigger?(Input::UP) or Input.repeat?(Input::UP)
  436.       @month += 1 if @month >= 1 and @month <= 12
  437.       @month = 1  if @month == 13 or @month == 0
  438.     elsif Input.trigger?(Input::DOWN) or Input.repeat?(Input::DOWN)
  439.       @month -= 1 if @month >= 1 and @month <= 12
  440.       @month = 12 if @month == 0
  441.     end
  442.   end
  443.  
  444.   def update_day
  445.     if Input.trigger?(Input::UP) or Input.repeat?(Input::UP)
  446.       if !@clock_req.leap? @year
  447.         @day += 1 if @day >= 1 and @day <= REGYEAR[@month]
  448.         @day =  1 if @day == 0 or @day > REGYEAR[@month]
  449.       elsif @clock_req.leap? @year
  450.         @day += 1 if @day >= 1 and @day <= LEAPYEAR[@month]
  451.         @day =  1 if @day == 0 or @day > LEAPYEAR[@month]
  452.       end
  453.     elsif Input.trigger?(Input::DOWN) or Input.repeat?(Input::DOWN)
  454.       if !@clock_req.leap? @year
  455.         @day -= 1 if @day >= 1 and @day <= REGYEAR[@month]
  456.         @day = REGYEAR[@month] if @day == 0 or @day > REGYEAR[@month]
  457.       elsif @clock_req.leap? @year
  458.         @day -= 1 if @day >= 1 and @day <= LEAPYEAR[@month]
  459.         @day = LEAPYEAR[@month] if @day == 0 or @day > LEAPYEAR[@month]
  460.       end
  461.     end
  462.   end
  463.  
  464.   def update_day_name
  465.     @day_name = @clock_req.day_name(@year,@month,@day)
  466.     print @month_flag, @day_flag, @day_name_flag, @on_screen
  467.     @on_screen = true
  468.   end
  469.  
  470.   def refresh(target_sprite=nil) # A Sprite as argument
  471.     @target_sprite = target_sprite
  472.     if @target_sprite != nil and @target_sprite.is_a? Sprite
  473.       # Current target is KyoYear
  474.       if !@year_flag and !@month_flag
  475.         @this_year = @target_sprite
  476.         @this_year.year = @year
  477.         @this_year.refresh
  478.       # Current target is KyoMonthName
  479.       elsif @year_flag and !@month_flag and !@day_flag
  480.         @this_month = @target_sprite
  481.         @this_month.mname = @month
  482.         @this_month.refresh
  483.       # Current target is KyoDay
  484.       elsif @year_flag and @month_flag and !@day_flag
  485.         @todaynum = @target_sprite
  486.         @todaynum.day = @day
  487.         @todaynum.refresh
  488.       elsif @month_flag and @day_flag and !@day_name_flag
  489.         @today = @target_sprite
  490.         @today.dname = @day_name
  491.         @today.refresh
  492.       end
  493.     end
  494.   end
  495. end
  496.  
  497. class Sprite_KyoDayName < Sprite
  498.   include KyoVocab
  499.   attr_accessor :dname, :mname
  500.   def initialize(x=0,y=0,full_name=false)
  501.     @viewport = Viewport.new(0,0,544,416)
  502.     super(@viewport)
  503.     self.bitmap = Bitmap.new(168, 48)
  504.     self.bitmap.font.name = 'Digital-7'
  505.     self.bitmap.font.size = 32
  506.     self.bitmap.font.bold = true
  507.     self.x, self.y, self.z, self.visible = x, y, 1000, true
  508.     @time_now = []
  509.     @clock = $game_kyowatch
  510.     @clock.full_mnames = full_name
  511.     @dname = @clock.kyoclock[6]
  512.     @mname = @clock.kyoclock[1]
  513.     update
  514.   end
  515.  
  516.   def update
  517.     super
  518.     @clock.update_clock
  519.     if @clock.time_now != @time_now
  520.       refresh
  521.     end
  522.   end
  523.  
  524.   def refresh
  525.     self.bitmap.clear
  526.     @clock.update_clock
  527.     c = @clock.time_now
  528.     @clock.weekday = KyoDayFullNames    if @clock.full_mnames
  529.     @clock.weekday = KyoDayPartialNames if [email protected]_mnames
  530.     text = @clock.weekday[@dname]
  531.     self.bitmap.font.color.set(255, 255, 255)
  532.     self.bitmap.draw_text(self.bitmap.rect, text)
  533.     @time_now = @clock.time_now
  534.   end
  535. end
  536.  
  537. class Sprite_KyoMonthName < Sprite_KyoDayName
  538.   def refresh
  539.     self.bitmap.clear
  540.     @clock.update_clock
  541.     c = @clock.time_now
  542.     @clock.month_name = KyoMonthFullNames    if @clock.full_mnames
  543.     @clock.month_name = KyoMonthPartialNames if [email protected]_mnames
  544.     text = @clock.month_name[@mname]
  545.     self.bitmap.font.color.set(255, 255, 255)
  546.     self.bitmap.draw_text(self.bitmap.rect, text)
  547.     @time_now = @clock.time_now
  548.   end
  549. end
  550.  
  551. class Scene_Menu < Scene_Base
  552.     include KyoVocab
  553.   def initialize(menu_index=0)
  554.     @menu_index = menu_index
  555.     @clock      = $game_kyowatch # Call Watch script
  556.     @minutes    = @clock.minutes * 6 if [email protected]_clocktime
  557.     @hours      = @clock.hours * 30  if [email protected]_clocktime
  558.   end
  559.  
  560.   def start
  561.     super
  562.     create_menu_background
  563.     create_command_window
  564.     @gold_window = Window_Gold.new(384, @kyon_options.size*24+32)
  565.     @pokeball = Sprite_KyoPicture.new(PokeballSh)
  566.     @pokeball.x, @pokeball.y = 542, 360
  567.     @clockpic = Sprite_KyoPicture.new(KyoClock)
  568.     @clockpic.x, @clockpic.y = KyoX, KyoY
  569.     @clockmin = Sprite_KyoPicture.new(KyoMin)
  570.     @clockmin.x, @clockmin.y, @clockmin.z = KyoX, KyoY, 1000
  571.     @clockmin.rotate(@clock.minutes*6) if [email protected]_clocktime
  572.     @clockhour = Sprite_KyoPicture.new(KyoHour)
  573.     @clockhour.x, @clockhour.y, @clockhour.z = KyoX, KyoY, 2000
  574.     @clockhour.rotate(@clock.hours*30) if [email protected]_clocktime
  575.         @playtime = Sprite_PlayTime.new(392,336)
  576.     @watch    = Sprite_KyoWatch.new(392,368) if [email protected]_clocktime
  577.     @weekday  = Sprite_KyoDayName.new(328,368) if [email protected]_clocktime
  578.   end
  579.  
  580.   def terminate
  581.     super
  582.     dispose_menu_background
  583.         [@command_window,@gold_window,@pokeball,@playtime].each {|s| s.dispose}
  584.     [@clockpic, @clockmin, @clockhour, @watch, @weekday].each do |s|
  585.       s.dispose if [email protected]_clocktime
  586.     end
  587.   end
  588.  
  589.   def update
  590.     super
  591.     update_menu_background
  592.     @command_window.update
  593.     if [email protected]_clocktime
  594.       @clockmin.rotate(@clock.minutes*6-@minutes)
  595.       @clockhour.rotate(@clock.hours*30-@hours)
  596.       @minutes = @clock.minutes*6
  597.       @hours   = @clock.hours*30
  598.     end
  599.     @pokeball.update(45)
  600.     @gold_window.update
  601.         @playtime.update
  602.     @watch.update if [email protected]_clocktime
  603.     @weekday.update if [email protected]_clocktime
  604.     update_command_selection if @command_window.active
  605.   end
  606.  
  607.   def create_command_window
  608.     s1 = 'Bestiary'
  609.     s2 = 'Party'
  610.     s3 = Vocab::item
  611.     s4 = 'Map'
  612.     s5 = 'Watch'
  613.     s6 = 'Achievements'
  614.     s7 = Vocab::save
  615.     s8 = 'Options'
  616.     s9 = Vocab::game_end
  617.     @kyon_options = [s1,s2,s3,s4,s5,s6,s7,s8,s9]
  618.     @command_window = Window_Command.new(160, @kyon_options)
  619.     @command_window.x = 384
  620.     @command_window.index = @menu_index
  621.     if $game_system.save_disabled         # If save is forbidden
  622.       @command_window.draw_item(6, false) # Disable save
  623.     end
  624.   end
  625.  
  626.   def update_command_selection
  627.     if Input.trigger?(Input::B)
  628.       Sound.play_cancel
  629.       $scene = Scene_Map.new
  630.     elsif Input.trigger?(Input::C)
  631.       if $game_system.save_disabled and @command_window.index == 4
  632.         Sound.play_buzzer
  633.         return
  634.       end
  635.       Sound.play_decision
  636.       case @command_window.index
  637.       when 0 # Bestiary
  638.         #$scene = Scene_KyoBestiary.new
  639.       when 1 # Party Members
  640.         #$scene = Scene_KyoMembers.new
  641.       when 2 # Items / Bag
  642.         #$scene = Scene_KyoItems.new
  643.       when 3 # Map
  644.         #$scene = Scene_KyoMapViewer.new
  645.       when 4 # Watch
  646.         $scene = Scene_KyoWatch.new if !$game_kyowatch.no_reset
  647.       when 5 # Achievements
  648.         #$scene = Scene_KyoMadeIt.new
  649.       when 6 # Save
  650.         $scene = Scene_File.new(true, false, false)
  651.       when 7 # Options
  652.         #$scene = Scene_KyoWinSkin.new
  653.       when 8 # End Game
  654.         $scene = Scene_End.new
  655.       end
  656.     end
  657.   end
  658. end
  659.  
  660. class Scene_KyoWatch < Scene_Base
  661.   include KyoVocab
  662.   def initialize
  663.     @clock = $game_kyowatch
  664.   end
  665.  
  666.   def start
  667.     super
  668.     create_menu_background
  669.     create_command_window
  670.     @help_window = Window_Help.new
  671.     @watch_back = Sprite_KyoPicture.new(KyoWatchBack)
  672.     @watch_back.x, @watch_back.y = 200, 360
  673.     @watch = Sprite_KyoWatchSys.new(KyoX-64, KyoY+108)
  674.     @watch.update(@kyon_fixed_hour, @kyon_fixed_min, @kyon_fixed_ampm)
  675.     @clockpic = Sprite_KyoPicture.new(KyoClock)
  676.     @clockpic.x, @clockpic.y = KyoX, KyoY
  677.     @clockmin = Sprite_KyoPicture.new(KyoMin)
  678.     @clockmin.x, @clockmin.y, @clockmin.z = KyoX, KyoY, 1000
  679.     @clockmin.rotate(@watch.min*6)
  680.     @clockhour = Sprite_KyoPicture.new(KyoHour)
  681.     @clockhour.x, @clockhour.y, @clockhour.z = KyoX, KyoY, 2000
  682.     @clockhour.rotate(@watch.hour*30)
  683.     @this_year  = Sprite_KyoYear.new(440, 60)
  684.     @this_month = Sprite_KyoMonthName.new(276, 60, true)
  685.     @todaynum   = Sprite_KyoDay.new(440,96)
  686.     @today      = Sprite_KyoDayName.new(296, 96, true)
  687.     @calendar = Sprite_KyoCalendarSys.new(0,0)
  688.     sun_moon_settings
  689.     @sun_moon = Sprite_KyoPicture.new(@picture)
  690.     @sun_moon.y = 140
  691.   end
  692.  
  693.   def create_command_window
  694.     @command_window = Window_Command.new(160, ['Clock', 'Calendar'], 1)
  695.     @command_window.x = (544-@command_window.width) / 2
  696.     @command_window.y = 56
  697.     @command_window.index = 0
  698.   end
  699.  
  700.   def sun_moon_settings # Should the Sun or the Moon picture appear?
  701.     @am_pm = @watch.ampm # Load picture depending on current daytime
  702.     @hour  = @watch.hour
  703.     if @am_pm == 'AM' or @am_pm == 'PM' # Check the Daytime Hash
  704.       @picture = KyoSun  if KyoDay[@am_pm].include?(@hour)
  705.       @picture = KyoMoon if !KyoDay[@am_pm].include?(@hour)
  706.     elsif @am_pm == '??'
  707.       @picture = KyoSun
  708.     end
  709.   end
  710.  
  711.   def terminate
  712.     super
  713.     dispose_menu_background
  714.     things = [@clockhour, @clockmin, @watch_back, @help_window, @sun_moon]
  715.     things.push @clockpic, @watch, @command_window, @calendar
  716.     things.push @this_year, @this_month, @todaynum, @today
  717.     things.each {|s| s.dispose}
  718.   end
  719.  
  720.   def update
  721.     super
  722.     update_menu_background
  723.     @command_window.update
  724.     @help_window.update
  725.     if @command_window.active
  726.       update_command
  727.     elsif !@command_window.active
  728.       # Set the clock if index == 0
  729.       if @command_window.index == 0
  730.         @watch.update(@kyon_fixed_hour, @kyon_fixed_min, @kyon_fixed_ampm)
  731.         if !@kyon_fixed_hour and @kyon_set_flags and !@kyon_exit
  732.           update_hour
  733.         elsif @kyon_fixed_hour and !@kyon_fixed_min
  734.           update_min
  735.         elsif @kyon_fixed_hour and @kyon_fixed_min and !@kyon_fixed_ampm
  736.           update_ampm
  737.         elsif @kyon_fixed_min and @kyon_fixed_ampm and !@kyon_exit
  738.           update_exit_current_setup # Show confirmation message
  739.         end
  740.       # Setup the calendar if index == 1
  741.       elsif @command_window.index == 1
  742.         @calendar.update(@kyon_fixed_year, @kyon_fixed_month,
  743.           @kyon_fixed_day, @kyon_fixed_day_name)
  744.         if !@kyon_fixed_year and !@kyon_fixed_month
  745.           update_year
  746.         elsif @kyon_fixed_year and !@kyon_fixed_month
  747.           update_month
  748.         elsif @kyon_fixed_year and @kyon_fixed_month and !@kyon_fixed_day
  749.           update_day
  750.         elsif @kyon_fixed_year and @kyon_fixed_month and @kyon_fixed_day and
  751.           !@kyon_fixed_day_name
  752.           update_day_name
  753.         elsif @kyon_fixed_day and @kyon_fixed_day_name and @calendar.on_screen
  754.           update_exit_current_setup # Show confirmation message
  755.         end
  756.       end
  757.     end
  758.   end
  759.  
  760.   def update_command
  761.     @help_window.set_text('KyoWatch VX version 1.0', 1)
  762.     if Input.trigger?(Input::B)
  763.       if @kyon_set_flags
  764.         Sound.play_buzzer
  765.         return
  766.       else
  767.         Sound.play_cancel
  768.         $scene = Scene_Map.new
  769.       end
  770.     elsif Input.trigger?(Input::C)
  771.       Sound.play_decision
  772.       @index = @command_window.index
  773.       case @index
  774.       when 0, 1
  775.         kyon_reset_flags
  776.         @kyon_exit = false # Need to set the clock
  777.         @command_window.active  = false
  778.         @command_window.visible = false
  779.         @calendar.update_sprite = @this_year if @index == 1
  780.         @watch.active    = true if @index == 0
  781.         @calendar.active = true if @index == 1
  782.       end
  783.     end
  784.   end
  785.  
  786.   def update_hour
  787.     @help_window.set_text('Please set the current hour.', 1)
  788.     @clockhour.update(30) if !@kyon_fixed_hour
  789.     if Input.trigger?(Input::C)
  790.       @kyon_fixed_hour = true if !@kyon_fixed_hour
  791.     end
  792.   end
  793.  
  794.   def update_min
  795.     @help_window.set_text('Please set the current minutes.', 1)
  796.     @clockmin.update(6) if @kyon_fixed_hour and !@kyon_fixed_min
  797.     if Input.trigger?(Input::C)
  798.       @kyon_fixed_min = true if !@kyon_fixed_min
  799.     end
  800.   end
  801.  
  802.   def update_ampm
  803.     @help_window.set_text('Is it AM or PM?', 1)
  804.     if Input.trigger?(Input::C)
  805.       if !@kyon_fixed_ampm and @watch.ampm != '??'
  806.         @kyon_fixed_ampm = true
  807.       else
  808.         return
  809.       end
  810.       sun_moon_settings
  811.       @sun_moon.refresh(@picture,0,140)
  812.           # Clock does not handle 24 hours, check how many hours passed
  813.           # and calculate the time in 24 hour format if needed
  814.       if @watch.hour > 0 and @watch.hour < 12 and @watch.ampm == 'PM'
  815.         hour = @watch.hour + 12
  816.       elsif @watch.hour == 12 and @watch.ampm == 'AM'
  817.         hour = 0
  818.       else
  819.         hour = @watch.hour
  820.       end
  821.       h_min_ampm = [hour, @watch.min, @watch.ampm]
  822.           @clock.kyoclock[3,3] = h_min_ampm
  823.       @clock.frame_count = Graphics.frame_count
  824.       @clock.update_clock
  825.       @clock.no_clocktime = false
  826.     end
  827.   end
  828.  
  829.   def update_year
  830.     @help_window.set_text('And the current year is...', 1)
  831.     if Input.trigger?(Input::C)
  832.       if !@kyon_fixed_year and @calendar.year >= YearRangeMIN
  833.         @kyon_fixed_year = true
  834.         @calendar.update_sprite = @this_month
  835.       end
  836.     end
  837.   end
  838.  
  839.   def update_month
  840.     @help_window.set_text('What about the current month?', 1)
  841.     if Input.trigger?(Input::C)
  842.       if !@kyon_fixed_month
  843.         @kyon_fixed_month = true
  844.         @calendar.update_sprite = @todaynum
  845.       end
  846.     end
  847.   end
  848.  
  849.   def update_day
  850.     @help_window.set_text('What day is it?', 1)
  851.     if Input.trigger?(Input::C)
  852.       if !@kyon_fixed_day
  853.         @kyon_fixed_day = true
  854.         @calendar.update_sprite = @today
  855.       @today.refresh
  856.       end
  857.     end
  858.   end
  859.  
  860.   def update_day_name
  861.     @help_window.set_text('Now you should see the name of the day', 1)
  862.     if Input.trigger?(Input::C)
  863.       return if @kyon_fixed_day_name
  864.       @kyon_fixed_day_name = true
  865.       year_month_day = [@calendar.year, @calendar.month, @calendar.day]
  866.       @clock.kyoclock[6] = @calendar.day_name if @kyon_set_flags
  867.       @clock.kyoclock[0,3] = year_month_day   if @kyon_set_flags
  868.     end
  869.   end
  870.  
  871.   def update_exit_current_setup
  872.     text = 'Ready! Now press Enter to exit to the selection menu'
  873.     @help_window.set_text(text, 1)
  874.     if Input.trigger?(Input::C)
  875.       @kyon_set_flags  = false if @kyon_set_flags
  876.       @watch.active    = false if @watch.active
  877.       @calendar.active = false if @calendar.active
  878.       @command_window.visible = true
  879.       @command_window.active  = true
  880.     end
  881.   end
  882.  
  883.   def kyon_reset_flags
  884.     if @command_window.index == 0
  885.       @kyon_fixed_hour, @kyon_fixed_ampm, @kyon_fixed_min = false, false, false
  886.     elsif @command_window.index == 1
  887.       @kyon_fixed_year, @kyon_fixed_month = false, false
  888.       @kyon_fixed_day, @kyon_fixed_day_name = false, false
  889.     end
  890.     @kyon_set_flags = true # Need to set hour, minutes and AM / PM or setup date
  891.   end
  892. end
  893.  
  894. class Scene_Title
  895.   alias kyon_title_cgo create_game_objects
  896.   alias kyon_title_cng command_new_game
  897.  
  898.   def create_game_objects
  899.     kyon_title_cgo
  900.     $game_kyowatch = Game_KyoWatch.new # Call system script
  901.   end
  902.  
  903.   def command_new_game
  904.     $game_kyowatch.frame_count = 0 # Reset frame count before
  905.     kyon_title_cng # setting up the clocktime for the first time
  906.   end
  907. end
  908.  
  909. class Scene_File
  910.   def return_scene
  911.     if @from_title
  912.       $scene = Scene_Title.new
  913.     elsif @from_event
  914.       $scene = Scene_Map.new
  915.     else
  916.       $scene = Scene_Menu.new(6) # Save option current position
  917.     end
  918.   end
  919.  
  920.   alias kyon_sf_wsd write_save_data
  921.   def write_save_data(file)
  922.     kyon_sf_wsd(file) # Do not forget to save the System script
  923.     Marshal.dump($game_kyowatch, file)
  924.   end
  925.  
  926.   def read_save_data(file)
  927.     characters           = Marshal.load(file)
  928.     Graphics.frame_count = Marshal.load(file)
  929.     @last_bgm            = Marshal.load(file)
  930.     @last_bgs            = Marshal.load(file)
  931.     $game_system         = Marshal.load(file)
  932.     $game_message        = Marshal.load(file)
  933.     $game_switches       = Marshal.load(file)
  934.     $game_variables      = Marshal.load(file)
  935.     $game_self_switches  = Marshal.load(file)
  936.     $game_actors         = Marshal.load(file)
  937.     $game_party          = Marshal.load(file)
  938.     $game_troop          = Marshal.load(file)
  939.     $game_map            = Marshal.load(file)
  940.     $game_player         = Marshal.load(file)
  941.     # Load Watch System script data
  942.     $game_kyowatch     = Marshal.load(file) if !file.eof?
  943.     $game_kyowatch     = Game_Kyowatch.new if file.eof?
  944.     if $game_system.version_id != $data_system.version_id
  945.       $game_map.setup($game_map.map_id)
  946.       $game_player.center($game_player.x, $game_player.y)
  947.     end
  948.   end
  949. end
Expand to see the code.


Instructions

The script includes a menu screen that already includes an option to enter the Clock and Calendar scene. You may need to add that option manually to any other menu like a Ring Menu script.

You may call the script like this

$scene = Scene_KyoWatch.new

To enable or disable access to the scene, use this line at any time

$game_kyowatch.no_reset = true (or false if needed)

Take a look at the Constants inside the KyoVocab module, there you can edit any graphic configuration related to the script, but there are a lot of things you may leave alone to make sure the script will work properly.

BTW, the Scene_File script was modified to include my script while saving or loading data from the save data file. Don't ever forget that! Of course, I modified the Scene_Title scene, too, to load the Game class I added named Game_KyoWatch.

Bugs

There was a little bug in a previous version that was solved in the current one (1.0.0.1). I just forgot to include an if statement twice in lines 540 and 541, I think, so the clock does not start spinning right away but just after the player set the clock at least once.

The Demo and the Script were updated.

FAQ

None yet.

Compatibility

Not sure if it's SDK compliant, maybe not, gotta check it out.

Credits and Thanks

Well, the clock graphic (except for the clock hands) are not mine but from a guy that made it for KDE (a Linux OS GUI).

Author's Notes

Now you can also get the XP version of this script!

I wished the Maker included the DateTime class... it would make it a bit easier to develop it. Thanks GlitchFinder for letting me know it was a need to make the script compatible with old saved games data.

Terms and Conditions

Not intended for Commercial Use.

I should be credited for the script if included in any project or game.
I have a few things to say about this script. First off, it is looking like at least some of the code was taken from Poccil's Pokemon Starter Kit. The reason I say this first becomes evident on line 45, which reads as follows:

  1.    PokeballSh   = 'pokeballbg'
Expand to see the code.


As far as I know, Poccil is the only scripter around who not only uses those atrocious naming conventions, but also has a significant body of Pokemon-related coding.

The next comment I had was regarding your edit to the load file method. Specifically, the fact that you introduced an unnecessary fatal error to the script, by removing compatibility with older save files. When adding new things to save files, you should always make sure you check for an end of file error before trying to load that new data, so as to make sure that the game doesn't crash when you try to load a save file from before the script was installed. The method could easily be rewritten as follows:

  1.   def read_save_data(file)
  2.     characters           = Marshal.load(file)
  3.     Graphics.frame_count = Marshal.load(file)
  4.     @last_bgm            = Marshal.load(file)
  5.     @last_bgs            = Marshal.load(file)
  6.     $game_system         = Marshal.load(file)
  7.     $game_message        = Marshal.load(file)
  8.     $game_switches       = Marshal.load(file)
  9.     $game_variables      = Marshal.load(file)
  10.     $game_self_switches  = Marshal.load(file)
  11.     $game_actors         = Marshal.load(file)
  12.     $game_party          = Marshal.load(file)
  13.     $game_troop          = Marshal.load(file)
  14.     $game_map            = Marshal.load(file)
  15.     $game_player         = Marshal.load(file)
  16.     if file.eof?
  17.       $game_kyowatch     = Game_KyoWatch.new
  18.     else
  19.       $game_kyowatch     = Marshal.load(file) # Load System Script data
  20.     end
  21.     if $game_system.version_id != $data_system.version_id
  22.       $game_map.setup($game_map.map_id)
  23.       $game_player.center($game_player.x, $game_player.y)
  24.     end
  25.   end
Expand to see the code.


Aside from these, I can't really give much commentary without actually testing the script. I do have to commend you for creating such a large script, since this was apparently quite the undertaking.

Also, please don't take the commentary the wrong way. Although my wording may have had a bit of an edge, both things I pointed out are valid concerns for your script, for very different reasons.
Well, the reason why I chose that naming convention for the pokeball shadow that was place on the lower right corner is that I was planning to develop a simple Pokemon project on my own for a Spanish speaking audience, but once the project itself was looking more and more like a clock / calendar script, I decided it was time to devote all my free time to develop it and see if I was already capable of creating it or not, because for me it was a challenge to develop something more different that my very first scripts. (I was thinking I should also remove all Pokemon influence to make the script look more impartial, more generic...)

I didn't like the first script I ever posted because it was a ridiculously simple PlayTime script that didn't include any features I now included in my KyoWatch script. So the script above is the result of my devotion / obsession of making a major effort to get something I could consider more valuable, even if I'm still an amateur scripter that has just about two years experience with RGSS with some not so extended periods of scripting obscurantism included. I know I'm far away from where renown scripters are, but learning RGSS and also Ruby (and wxRuby and FXRuby) makes me feel the need, the urge of creating better and more complicated scripts... but it takes a lot of time, patience and headaches. :) I guess it's not so easy to change your way of thinking suddenly.

By the way, I haven't seen Poccil's coding but if I find his or hers scripts for developing a PKMN project, well, I'd give up making my own scripts and would start adapting it for any Pokemon game I might develop. That's because I'd become too lazy to do something on my own (that's why I avoid downloading such stuff so I don't lose any inspiration and some valuable learning experience on the way).

I didn't know I could check the end of file while calling Marshal.load. Thanks for the tip, it's pretty helpful.

That makes me remember the time I was afraid of scripting long back ago when RM2K3 was still considered fresh but could be easily beaten by the newcomer XP that showed up in the market a few months later.

And yes, I know you call yourself the glitchfinder, so I guess it's normal for you to point those things out once they started bugging you. And thanks, I'll know avoid those atrocious naming conventions from now on.

Anyway, this kind of script was intended to be used in games where a clock is required like Pokemon, Harvest Moon and any other similar games.
Updated the script to include a set time feature that uses a Hash to set the new values for days, hours, minutes or anything else related to my watch script.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=68980