Advertisement
TheSixth

PC Clock HUD by Sixth

Sep 2nd, 2015
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.90 KB | None | 0 0
  1. #===============================================================================
  2. # * [ACE] PC Clock Display
  3. #===============================================================================
  4. # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
  5. # * Version: 1.5
  6. # * Updated: 21/10/2016
  7. # * Requires: -------
  8. #-------------------------------------------------------------------------------
  9. # * < Change Log >
  10. #-------------------------------------------------------------------------------
  11. # * Version 0.1 (04/02/2015)
  12. #   - Initial release (Alpha version).
  13. # * Version 1.0 (04/02/2015)
  14. #   - Increased efficiency of the update methods (performance fix).
  15. #   - Added the clock for the menu.
  16. #   - Added button trigger to hide/show the timer on the map.
  17. #   - Added background image option for the map timer.
  18. # * Version 1.1 (05/02/2015)
  19. #   - Removed some dead code bits.
  20. #   - Added a script call to change the background image during the game.
  21. # * Version 1.2 (07/02/2015)
  22. #   - Added compatibility for (Venka+Dekita)'s Resolution Selection script.
  23. #     The resolution change will be recognized even if it is done with that
  24. #     script, so you can use Graphics.width and Graphics.height in the position
  25. #     settings, but in a different format. Read more at the settings.
  26. # * Version 1.3 (19/02/2015)
  27. #   - Now you can show the full date and the name of the current day too.
  28. #     Configurations for setting up your own date format.
  29. #   - Text position options are added too.
  30. # * Version 1.4 (17/10/2016)
  31. #   - Changed the visibility toggle switches to operate the opposite way.
  32. #     Now when they are ON, the clock HUD is shown, otherwise it's hidden.
  33. # * Version 1.5 (21/10/2016)
  34. #   - Reworked some code, fixed some descriptions.
  35. #   - Compatibility with my Global Setting Addon for Yanfly's System Options.
  36. #     You must update this script if you use the above mentioned script!
  37. #-------------------------------------------------------------------------------
  38. # * < Description >
  39. #-------------------------------------------------------------------------------
  40. # * This script makes a real-time clock (based on PC time) on the map HUD as
  41. #   well as on the main menu scene.
  42. # * Visual settings can be changed easily, some of them even during the game.
  43. # * 12/24 hours format available and can be changed at will even during the game.
  44. # * Show/hide switch available, as well as a button trigger to toggle the timer.
  45. #-------------------------------------------------------------------------------
  46. # * < Script Calls >
  47. #-------------------------------------------------------------------------------
  48. # rtime_pos(x,y)     - Changes the position of the map timer window.
  49. # rtime_color(color) - Changes the color of the timer text both for the map and
  50. #                      for the menu window.
  51. #                      Same rules apply for the color as in the script settings.
  52. # rtime_skin(skin)   - Changes the windowskin used for the map window.
  53. #                      Same rules and same format as in the script settings.
  54. # rtime_back(img)    - Changes the background used for the map window.
  55. #                      Same rules and same format as in the script settings.
  56. #-------------------------------------------------------------------------------
  57. # * < Installation >
  58. #-------------------------------------------------------------------------------
  59. # * Place this script below Materials but above Main!
  60. # * If you will use my YF System Options Addon script too, you will need to put
  61. #   this script above Yanfly's System Options and above my addon script also!
  62. #-------------------------------------------------------------------------------
  63. # * < Compatibility Info >
  64. #-------------------------------------------------------------------------------
  65. # * No known incompatibilities.
  66. #-------------------------------------------------------------------------------
  67. # * < Known Issues >
  68. #-------------------------------------------------------------------------------
  69. # * No known issues.
  70. #-------------------------------------------------------------------------------
  71. # * < Terms of Use >
  72. #-------------------------------------------------------------------------------
  73. # * Free to use for whatever purposes you want.
  74. # * Credit me (Sixth) in your game, pretty please! :P
  75. # * Posting modified versions of this script is allowed as long as you notice me
  76. #   about it with a link to it!
  77. #===============================================================================
  78. $imported = {} if $imported.nil?
  79. $imported["SixthPCTimerDisplay"] = true
  80. #===============================================================================
  81. # Settings:
  82. #===============================================================================
  83. module Sixth_RTime_HUD
  84.   #-----------------------------------------------------------------------------
  85.   # Window Setup (Map HUD):
  86.   #-----------------------------------------------------------------------------
  87.   # :pos = The position of the window. Format: [x,y].
  88.   # - Extra options (only effective for the map HUD timer!):
  89.   # 1. If you want to use Graphics.width or Graphics.height in the position
  90.   #    setup, you will need to put the x or y value you have set up in an array,
  91.   #    and the value you set up in the array will be added to Graphics.width or
  92.   #    Graphics.height respectively. So if you want to position the window to the
  93.   #    top right corner, the setup would look like this:
  94.   #     :pos => [[-150],0],
  95.   #    The value used (150) is the width of the timer window, and minus, because
  96.   #    we want that much subtracted from Graphics.width.
  97.   # 2. If you want to center the window depending on the resolution of the game,
  98.   #    you simply need to set :center to the value of X and Y position, like this:
  99.   #     :pos => [:center,[-48]],
  100.   #    This will put the window to the bottom of the game screen and will be
  101.   #    centered horizontally.
  102.   # :size = The size of the window. Format: [width,height].
  103.   # :skin = The windowskin used for the window.
  104.   #         The windowskin image must be in /Graphics/System/ folder.
  105.   # :opacity = The opacity of the window shown.
  106.   #            Valid values: 0-255.
  107.   # :z = The z value of the window.
  108.   #-----------------------------------------------------------------------------
  109.   Window_Setup_Map = { # <-- No touchy-touchy!
  110.     :pos => [0,0],
  111.     :size => [160,96],
  112.     :skin => "Window",
  113.     :opacity => 255,
  114.     :z => 200,
  115.   } # <-- No touchy-touchy!
  116.  
  117.   #-----------------------------------------------------------------------------
  118.   # Background Setup (Map HUD):
  119.   #-----------------------------------------------------------------------------
  120.   # :enable = Enable/disable the background feature here.
  121.   #           true = enabled, false = disabled.
  122.   # :graphic = The file name of the image used for the background.
  123.   #            The images used must be in /Graphics/Pictures/ folder!
  124.   # :offset = The offset values for X and Y positions relative to the window's
  125.   #           position.
  126.   # :opacity = The opacity of the background image.
  127.   # :z = The z value of the background image.
  128.   #      Should be smaller than the z value of the window!
  129.   #-----------------------------------------------------------------------------
  130.   BackImg_Map = { # <-- No touchy-touchy!
  131.     :enable => false,
  132.     :graphic => "timerbackv1",
  133.     :offset => [0,0],
  134.     :opacity => 255,
  135.     :z => 199,
  136.   } # <-- No touchy-touchy!
  137.  
  138.   #-----------------------------------------------------------------------------
  139.   # Window Setup (Menu):
  140.   #-----------------------------------------------------------------------------
  141.   # The settings are the same as for the on-map window.
  142.   # The y position is rigged, the window will always appear below the command
  143.   # window, so the setup for that one is not relevant here.
  144.   # Additional setting:
  145.   # :enable = Set it to true to show the time window in the main menu.
  146.   #           Set it to false to disable the time window in the main menu.
  147.   #-----------------------------------------------------------------------------
  148.   Window_Setup_Menu = { # <-- No touchy-touchy!
  149.     :enable => true,
  150.     :pos => [0,192],
  151.     :size => [160,96],
  152.     :skin => "Window",
  153.     :opacity => 255,
  154.     :z => 200,
  155.   } # <-- No touchy-touchy!
  156.  
  157.   #-----------------------------------------------------------------------------
  158.   # Text Settings:
  159.   #-----------------------------------------------------------------------------
  160.   # Adjust the general properties of the font used in the timer windows here.
  161.   # You can also adjust the positions of each data displayed in the window.
  162.   #
  163.   # The :general settings will adjust the font used for the windows.
  164.   #
  165.   #  :color = The color of the font. Use an integer number to get the color from
  166.   #           the windowskin, use an array of 4 numbers to get the color from an
  167.   #           RGBA value (red, green, blue, alpha (opacity)).
  168.   #   :size = The size of the text.
  169.   #   :font = The font type used for the text.
  170.   #  :align = The alignment used for the text in the window.
  171.   #
  172.   # The :time setup will adjust the position of the time display in the windows.
  173.   # The :date setup will adjust the position of the date display in the windows.
  174.   # The :day setup will adjust the position of the day display in the windows.
  175.   #
  176.   # The :time, :date and :day settings all got the same format.
  177.   #
  178.   #   :pos => [x,y],
  179.   # The X and Y position of the text in the window.
  180.   #
  181.   #   :size => [width,height],
  182.   # The reserved width and height for the text in the window.
  183.   #
  184.   #   :align => value,
  185.   # The alignment of the text inside the window.
  186.   # 0 = left, 1 = middle, 2 = right.
  187.   #-----------------------------------------------------------------------------
  188.   Text_Setup = { # <-- No touchy-touchy!
  189.     :general => {:color => 17, :size => 24, :font => ["Monotype Corsiva","Arial"]},
  190.     :time    => {:pos => [0, 0], :size => [136,24], :align => 1},
  191.     :date    => {:pos => [0,24], :size => [136,24], :align => 1},
  192.     :day     => {:pos => [0,48], :size => [136,24], :align => 1},
  193.   } # <-- No touchy-touchy!
  194.  
  195.   #-----------------------------------------------------------------------------
  196.   # Date Format Settings:
  197.   #-----------------------------------------------------------------------------
  198.   # These are the settings for the format of the date.
  199.   # You got several options for each settings:
  200.   #
  201.   #   :day => format,
  202.   # The format of the day displayed. Can be:
  203.   #   "%A" = Displays the full name of the current day (Monday,Tuesday,etc).
  204.   #   "%a" = Displays the short name of the current day (Mon,Tue,etc).
  205.   # This affects the separate day name display, not the day display in the date!
  206.   #
  207.   #   :month => format,
  208.   # The format of the month displayed. Can be:
  209.   #   "%B" = Displays the full name of the current month (January,February,etc).
  210.   #   "%b" = Displays the short name of the current month (Jan,Feb,etc).
  211.   #   "%m" = Displays the current month in numbers (1,2,etc).
  212.   #
  213.   #   :year => format,
  214.   # The format of the year displayed. Can be:
  215.   #   "%Y" = Displays the year with 4 digits (2014,2015,etc).
  216.   #   "%y" = Displays the year with 2 digits (14,15,etc).
  217.   #
  218.   #   :after => ["text1","text2","text3"],
  219.   # The texts displayed after the day, month and year.
  220.   # So, you can end up with a date display like these:
  221.   # - 19.02.2015.
  222.   # - 19. February 2015.
  223.   # - 19/02/'15
  224.   # And so on.
  225.   # The 1st text goes after the first data displayed, the 2nd goes after the 2nd,
  226.   # and the 3rd goes after the 3rd.
  227.   #-----------------------------------------------------------------------------
  228.   Date_Format = { # <-- No touchy-touchy!
  229.     :day   => "%A", # %a or %A
  230.     :month => "%b", # %b or %B or %m
  231.     :year  => "%Y", # %y or %Y
  232.     :after => [". "," ","."],
  233.   } # <-- No touchy-touchy!
  234.  
  235.   #-----------------------------------------------------------------------------
  236.   # Date Display Order Settings:
  237.   #-----------------------------------------------------------------------------
  238.   # You can setup the order of the displayed data for the date here.
  239.   # You can choose to show only the day and month, or you can choose to show all
  240.   # but with a different order.
  241.   # It should be obvious what the symbols do in the below array, so I won't
  242.   # explain them.
  243.   # The order how you arrange them here will be the display order used in the
  244.   # window. You can remove some of them if you want too.
  245.   #-----------------------------------------------------------------------------
  246.   Date_Arrange = [:day,:month,:year]
  247.  
  248.   #-----------------------------------------------------------------------------
  249.   # Switch Settings:
  250.   #-----------------------------------------------------------------------------
  251.   # Switch used to control the format of the time in the game.
  252.   Format_Switch = 33 # ON = 24-hour, OFF = 12-hour.
  253.  
  254.   # Switch used to toggle the timer window's visibility in the game.
  255.   Enable_Switch_Map  = 134 # For the map window. ON = enabled, OFF = disabled.
  256.   Enable_Switch_Menu = 135 # For the menu window. ON = enabled, OFF = disabled.
  257.  
  258.   #-----------------------------------------------------------------------------
  259.   # Button Settings:
  260.   #-----------------------------------------------------------------------------
  261.   # Button trigger for showing/hiding the timer display on the map.
  262.   # Use nil to disable it!
  263.   #-----------------------------------------------------------------------------
  264.   ShowHide_Button = :CTRL
  265.  
  266. end # <-- No touchy-touchy!
  267. #===============================================================================
  268. # End of Settings! Editing anything below may lead to... You know what, right?
  269. #===============================================================================
  270.  
  271. class Game_Interpreter
  272.  
  273.   def rtime_pos(x,y)
  274.     $game_system.rtime_pos = [x,y]
  275.   end
  276.  
  277.   def rtime_color(color)
  278.     $game_system.rtime_color = color
  279.   end
  280.  
  281.   def rtime_skin(skin)
  282.     $game_system.rtime_skin = skin
  283.   end
  284.  
  285.   def rtime_back(img)
  286.     $game_system.rtime_back = img
  287.   end
  288.  
  289. end
  290.  
  291. class Game_System
  292.  
  293.   attr_accessor  :rtime_pos, :rtime_color, :rtime_skin, :rtime_back
  294.    
  295.   def rtime_pos
  296.     @rtime_pos = Sixth_RTime_HUD::Window_Setup_Map[:pos] if @rtime_pos.nil?
  297.     return @rtime_pos
  298.   end
  299.  
  300.   def rtime_color
  301.     @rtime_color = Sixth_RTime_HUD::Text_Setup[:general][:color] if @rtime_color.nil?
  302.     return @rtime_color
  303.   end
  304.  
  305.   def rtime_skin
  306.     @rtime_skin = Sixth_RTime_HUD::Window_Setup_Map[:skin] if @rtime_skin.nil?
  307.     return @rtime_skin
  308.   end
  309.  
  310.   def rtime_back
  311.     @rtime_back = Sixth_RTime_HUD::BackImg_Map[:graphic] if @rtime_back.nil?
  312.     return @rtime_back
  313.   end
  314.  
  315. end
  316.  
  317. class Scene_Map < Scene_Base
  318.  
  319.   alias sixth_rtimehud1222 create_all_windows
  320.   def create_all_windows
  321.     sixth_rtimehud1222
  322.     create_rtime_window
  323.     create_rtime_window_background if Sixth_RTime_HUD::BackImg_Map[:enable] == true
  324.   end
  325.  
  326.   def create_rtime_window
  327.     @rtime = Window_RTime.new
  328.     @rtime.z = Sixth_RTime_HUD::Window_Setup_Map[:z]
  329.     @hidden = $game_switches[Sixth_RTime_HUD::Enable_Switch_Map]
  330.     @rtime.visible = @hidden
  331.   end
  332.  
  333.   def create_rtime_window_background
  334.     @rtback = Sprite.new
  335.     @rtback.bitmap = Cache.picture($game_system.rtime_back)
  336.     @rtback.x = @rtime.x + Sixth_RTime_HUD::BackImg_Map[:offset][0]
  337.     @rtback.y = @rtime.y + Sixth_RTime_HUD::BackImg_Map[:offset][1]
  338.     @rtback.opacity = Sixth_RTime_HUD::BackImg_Map[:opacity]
  339.     @rtback.z = Sixth_RTime_HUD::BackImg_Map[:z]
  340.     @rtback.visible = @hidden
  341.   end
  342.  
  343.   alias sixth_rtimeupdate2231 update
  344.   def update
  345.     sixth_rtimeupdate2231
  346.     update_rtime_changes
  347.   end
  348.        
  349.   def update_rtime_changes
  350.     if Input.trigger?(Sixth_RTime_HUD::ShowHide_Button)
  351.       $game_switches[Sixth_RTime_HUD::Enable_Switch_Map] =
  352.                          !$game_switches[Sixth_RTime_HUD::Enable_Switch_Map]
  353.     end
  354.     if @hidden != $game_switches[Sixth_RTime_HUD::Enable_Switch_Map]
  355.       @hidden = $game_switches[Sixth_RTime_HUD::Enable_Switch_Map]
  356.       @rtime.visible = @hidden
  357.       @rtback.visible = @hidden if @rtback      
  358.     end
  359.   end
  360.  
  361.   alias sixth_rtime_disp1334 dispose_spriteset
  362.   def dispose_spriteset
  363.     if @rtback
  364.       @rtback.bitmap.dispose
  365.       @rtback.dispose
  366.     end
  367.     sixth_rtime_disp1334
  368.   end
  369.  
  370. end
  371.  
  372. class Scene_Menu < Scene_MenuBase
  373.  
  374.   alias sixth_rtime_start1112 start
  375.   def start
  376.     sixth_rtime_start1112
  377.     create_rtime_window if Sixth_RTime_HUD::Window_Setup_Menu[:enable]
  378.   end
  379.    
  380.   def create_rtime_window
  381.     if $game_switches[Sixth_RTime_HUD::Enable_Switch_Menu]
  382.       @rtimer = Window_RTime_Menu.new
  383.       @rtimer.y = @command_window.y + @command_window.height
  384.       @rtimer.z = Sixth_RTime_HUD::Window_Setup_Menu[:z]
  385.     end
  386.   end
  387.  
  388. end
  389.  
  390. class Window_Base < Window
  391.  
  392.   def get_color_sixth(color)
  393.     if color.is_a?(Integer)
  394.       return text_color(color)
  395.     else
  396.       return Color.new(*color)
  397.     end
  398.   end
  399.  
  400.   def change_the_font(type,size)
  401.     contents.font.name = type
  402.     contents.font.size = size
  403.   end
  404.  
  405. end
  406.  
  407. class Window_RTime < Window_Base
  408.   include Sixth_RTime_HUD
  409.  
  410.   def initialize
  411.     pos = $game_system.rtime_pos; size = Window_Setup_Map[:size]
  412.     if pos[0] == :center
  413.       x = (Graphics.width-Window_Setup_Map[:size][0])/2
  414.     else
  415.       x = pos[0].is_a?(Array) ? Graphics.width+pos[0][0] : pos[0]
  416.     end
  417.     if pos[1] == :center
  418.       y = (Graphics.height-Window_Setup_Map[:size][1])/2
  419.     else
  420.       y = pos[1].is_a?(Array) ? Graphics.height+pos[1][0] : pos[1]
  421.     end
  422.     super(x,y,size[0],size[1])
  423.     self.windowskin = Cache.system($game_system.rtime_skin)
  424.     self.opacity = Window_Setup_Map[:opacity]
  425.     @timr = Time.now.sec
  426.     refresh
  427.   end
  428.  
  429.   def refresh
  430.     contents.clear
  431.     t = Time.now
  432.     change_color(get_color_sixth($game_system.rtime_color))
  433.     change_the_font(Text_Setup[:general][:font],Text_Setup[:general][:size])
  434.     if $game_switches[Format_Switch] == true
  435.       txt1 = "#{t.strftime("%H")}:#{t.strftime("%M")}:#{t.strftime("%S")}"
  436.     else
  437.       txt1 = "#{t.strftime("%I")}:#{t.strftime("%M")}:#{t.strftime("%S")} #{t.strftime("%p")}"
  438.     end
  439.     txt2 = "#{t.strftime(Date_Format[:day])}"
  440.     txt3 = ""
  441.     Date_Arrange.each_with_index do |d,i|
  442.       case d
  443.       when :day
  444.         txt3 += "#{t.strftime("%d")}"
  445.       when :month
  446.         txt3 += "#{t.strftime(Date_Format[:month])}"
  447.       when :year
  448.         txt3 += "#{t.strftime(Date_Format[:year])}"
  449.       end
  450.       txt3 += Date_Format[:after][i]
  451.     end
  452.     p1 = Text_Setup[:time][:pos]; p2 = Text_Setup[:date][:pos]; p3 = Text_Setup[:day][:pos]
  453.     s1 = Text_Setup[:time][:size]; s2 = Text_Setup[:date][:size]; s3 = Text_Setup[:day][:size]
  454.     draw_text(p1[0],p1[1],s1[0],s1[1],txt1,Text_Setup[:time][:align])
  455.     draw_text(p2[0],p2[1],s2[0],s2[1],txt3,Text_Setup[:date][:align])
  456.     draw_text(p3[0],p3[1],s3[0],s3[1],txt2,Text_Setup[:day][:align])
  457.   end  
  458.    
  459.   def update
  460.     super
  461.     update_rtimer if @timr != Time.now.sec
  462.   end
  463.  
  464.   def update_rtimer
  465.     refresh
  466.     @timr = Time.now.sec
  467.   end
  468.  
  469. end
  470.  
  471. class Window_RTime_Menu < Window_Base
  472.   include Sixth_RTime_HUD
  473.  
  474.   def initialize
  475.     pos = Window_Setup_Menu[:pos]; size = Window_Setup_Menu[:size]
  476.     super(pos[0],pos[1],size[0],size[1])
  477.     self.windowskin = Cache.system(Window_Setup_Menu[:skin])
  478.     self.opacity = Window_Setup_Menu[:opacity]
  479.     @timr = Time.now.sec
  480.     refresh
  481.   end
  482.  
  483.   def refresh
  484.     contents.clear
  485.     t = Time.now
  486.     change_color(get_color_sixth($game_system.rtime_color))
  487.     change_the_font(Text_Setup[:general][:font],Text_Setup[:general][:size])
  488.     if $game_switches[Format_Switch] == true
  489.       txt1 = "#{t.strftime("%H")}:#{t.strftime("%M")}:#{t.strftime("%S")}"
  490.     else
  491.       txt1 = "#{t.strftime("%I")}:#{t.strftime("%M")}:#{t.strftime("%S")} #{t.strftime("%p")}"
  492.     end
  493.     txt2 = "#{t.strftime(Date_Format[:day])}"
  494.     txt3 = ""
  495.     Date_Arrange.each_with_index do |d,i|
  496.       case d
  497.       when :day
  498.         txt3 += "#{t.strftime("%d")}"
  499.       when :month
  500.         txt3 += "#{t.strftime(Date_Format[:month])}"
  501.       when :year
  502.         txt3 += "#{t.strftime(Date_Format[:year])}"
  503.       end
  504.       txt3 += Date_Format[:after][i]
  505.     end
  506.     p1 = Text_Setup[:time][:pos]; p2 = Text_Setup[:date][:pos]; p3 = Text_Setup[:day][:pos]
  507.     s1 = Text_Setup[:time][:size]; s2 = Text_Setup[:date][:size]; s3 = Text_Setup[:day][:size]
  508.     draw_text(p1[0],p1[1],s1[0],s1[1],txt1,Text_Setup[:time][:align])
  509.     draw_text(p2[0],p2[1],s2[0],s2[1],txt3,Text_Setup[:date][:align])
  510.     draw_text(p3[0],p3[1],s3[0],s3[1],txt2,Text_Setup[:day][:align])
  511.   end  
  512.    
  513.   def update
  514.     return if self.disposed?
  515.     super
  516.     update_rtimer if @timr != Time.now.sec
  517.   end
  518.  
  519.   def update_rtimer
  520.     refresh
  521.     @timr = Time.now.sec
  522.   end
  523.  
  524. end
  525. #==============================================================================
  526. # !!END OF SCRIPT - OHH, NOES!!
  527. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement